summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/app.gyp1
-rw-r--r--ui/base/resource/data_pack.cc1
-rw-r--r--ui/base/resource/resource_bundle.cc9
-rw-r--r--ui/base/resource/resource_bundle.h3
-rw-r--r--ui/base/resource/resource_bundle_unittest.cc38
-rw-r--r--ui/base/resource/resource_bundle_win.cc4
6 files changed, 52 insertions, 4 deletions
diff --git a/app/app.gyp b/app/app.gyp
index 1810938..b7b9aaa 100644
--- a/app/app.gyp
+++ b/app/app.gyp
@@ -40,6 +40,7 @@
'../ui/base/models/tree_node_iterator_unittest.cc',
'../ui/base/models/tree_node_model_unittest.cc',
'../ui/base/resource/data_pack_unittest.cc',
+ '../ui/base/resource/resource_bundle_unittest.cc',
'../ui/base/system_monitor/system_monitor_unittest.cc',
'../ui/base/test/data/resource.h',
'../ui/base/text/text_elider_unittest.cc',
diff --git a/ui/base/resource/data_pack.cc b/ui/base/resource/data_pack.cc
index 46fd4a0..d6e4e7b 100644
--- a/ui/base/resource/data_pack.cc
+++ b/ui/base/resource/data_pack.cc
@@ -73,6 +73,7 @@ bool DataPack::Load(const FilePath& path) {
DLOG(ERROR) << "Failed to mmap datapack";
UMA_HISTOGRAM_ENUMERATION("DataPack.Load", INIT_FAILED,
LOAD_ERRORS_COUNT);
+ mmap_.reset();
return false;
}
diff --git a/ui/base/resource/resource_bundle.cc b/ui/base/resource/resource_bundle.cc
index 56b3761..1b6fd11 100644
--- a/ui/base/resource/resource_bundle.cc
+++ b/ui/base/resource/resource_bundle.cc
@@ -272,17 +272,22 @@ void ResourceBundle::LoadedDataPack::Load() {
data_pack_.reset(new ui::DataPack);
bool success = data_pack_->Load(path_);
LOG_IF(ERROR, !success) << "Failed to load " << path_.value()
- << "\nYou will not be able to use the Bookmarks Manager or "
- << "about:net-internals.";
+ << "\nSome features may not be available.";
+ if (!success)
+ data_pack_.reset();
}
bool ResourceBundle::LoadedDataPack::GetStringPiece(
int resource_id, base::StringPiece* data) const {
+ if (!data_pack_.get())
+ return false;
return data_pack_->GetStringPiece(static_cast<uint32>(resource_id), data);
}
RefCountedStaticMemory* ResourceBundle::LoadedDataPack::GetStaticMemory(
int resource_id) const {
+ if (!data_pack_.get())
+ return NULL;
return data_pack_->GetStaticMemory(resource_id);
}
diff --git a/ui/base/resource/resource_bundle.h b/ui/base/resource/resource_bundle.h
index d973103..2598662 100644
--- a/ui/base/resource/resource_bundle.h
+++ b/ui/base/resource/resource_bundle.h
@@ -18,6 +18,7 @@
#include "base/basictypes.h"
#include "base/file_path.h"
+#include "base/gtest_prod_util.h"
#include "base/memory/ref_counted_memory.h"
#include "base/memory/scoped_ptr.h"
#include "base/string16.h"
@@ -177,6 +178,8 @@ class ResourceBundle {
static const SkColor toolbar_separator_color;
private:
+ FRIEND_TEST_ALL_PREFIXES(ResourceBundle, LoadDataResourceBytes);
+
// Helper class for managing data packs.
class LoadedDataPack {
public:
diff --git a/ui/base/resource/resource_bundle_unittest.cc b/ui/base/resource/resource_bundle_unittest.cc
new file mode 100644
index 0000000..9e4f12c
--- /dev/null
+++ b/ui/base/resource/resource_bundle_unittest.cc
@@ -0,0 +1,38 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/base/resource/resource_bundle.h"
+
+#include "base/base_paths.h"
+#include "base/file_path.h"
+#include "base/path_service.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace ui {
+
+TEST(ResourceBundle, LoadDataResourceBytes) {
+ // Verify that we don't crash when trying to load a resource that is not
+ // found. In some cases, we fail to mmap resources.pak, but try to keep
+ // going anyway.
+ ResourceBundle resource_bundle;
+
+ // On Windows, the default data is compiled into the binary so this does
+ // nothing.
+ FilePath data_path;
+ PathService::Get(base::DIR_SOURCE_ROOT, &data_path);
+ data_path = data_path.Append(
+ FILE_PATH_LITERAL("ui/base/test/data/data_pack_unittest/sample.pak"));
+
+ resource_bundle.LoadTestResources(data_path);
+
+ const int kUnfoundResourceId = 10000;
+ EXPECT_EQ(NULL, resource_bundle.LoadDataResourceBytes(kUnfoundResourceId));
+
+ // Give a .pak file that doesn't exist so we will fail to load it.
+ resource_bundle.AddDataPackToSharedInstance(FilePath(
+ FILE_PATH_LITERAL("non-existant-file.pak")));
+ EXPECT_EQ(NULL, resource_bundle.LoadDataResourceBytes(kUnfoundResourceId));
+}
+
+} // namespace ui
diff --git a/ui/base/resource/resource_bundle_win.cc b/ui/base/resource/resource_bundle_win.cc
index 36c35fe..9df6b0f 100644
--- a/ui/base/resource/resource_bundle_win.cc
+++ b/ui/base/resource/resource_bundle_win.cc
@@ -69,8 +69,8 @@ std::string ResourceBundle::LoadLocaleResources(
}
void ResourceBundle::LoadTestResources(const FilePath& path) {
- // ResourceBundle with test resources is only used on Linux test_sheel/DRT.
- NOTREACHED();
+ // On Windows, the test resources are normally compiled into the binary
+ // itself.
}
void ResourceBundle::UnloadLocaleResources() {