Index: ui/base/resource/resource_bundle_unittest.cc |
diff --git a/ui/base/resource/resource_bundle_unittest.cc b/ui/base/resource/resource_bundle_unittest.cc |
index 1d72785f2fb24d771e0d82258e545b78f700243c..fe7b632e7e479dcc02553b45414fb55af9f39f76 100644 |
--- a/ui/base/resource/resource_bundle_unittest.cc |
+++ b/ui/base/resource/resource_bundle_unittest.cc |
@@ -12,6 +12,7 @@ |
#include "base/scoped_temp_dir.h" |
#include "base/utf_string_conversions.h" |
#include "testing/gmock/include/gmock/gmock.h" |
+#include "ui/base/resource/resource_handle.h" |
#include "testing/gtest/include/gtest/gtest.h" |
#include "third_party/skia/include/core/SkBitmap.h" |
@@ -25,6 +26,10 @@ namespace ui { |
extern const char kSamplePakContents[]; |
extern const size_t kSamplePakSize; |
+extern const char kSamplePakContents2x[]; |
+extern const size_t kSamplePakSize2x; |
+extern const char kEmptyPakContents[]; |
+extern const size_t kEmptyPakSize; |
namespace { |
@@ -44,12 +49,14 @@ class MockResourceBundleDelegate : public ui::ResourceBundle::Delegate { |
MOCK_METHOD2(GetNativeImageNamed, |
gfx::Image(int resource_id, |
ui::ResourceBundle::ImageRTL rtl)); |
- MOCK_METHOD1(LoadDataResourceBytes, |
- base::RefCountedStaticMemory*(int resource_id)); |
- MOCK_METHOD1(GetRawDataResourceMock, base::StringPiece(int resource_id)); |
+ MOCK_METHOD2(LoadDataResourceBytes, |
+ base::RefCountedStaticMemory*(int resource_id, float scale_factor)); |
+ MOCK_METHOD2(GetRawDataResourceMock, base::StringPiece(int resource_id, |
+ float scale_factor)); |
virtual bool GetRawDataResource(int resource_id, |
+ float scale_factor, |
base::StringPiece* value) OVERRIDE { |
- *value = GetRawDataResourceMock(resource_id); |
+ *value = GetRawDataResourceMock(resource_id, scale_factor); |
return true; |
} |
MOCK_METHOD1(GetLocalizedStringMock, string16(int message_id)); |
@@ -152,13 +159,14 @@ TEST(ResourceBundle, DelegateLoadDataResourceBytes) { |
new base::RefCountedStaticMemory(data, sizeof(data))); |
int resource_id = 5; |
+ float scale_factor = ResourceHandle::kScaleFactorNone; |
- EXPECT_CALL(delegate, LoadDataResourceBytes(resource_id)) |
+ EXPECT_CALL(delegate, LoadDataResourceBytes(resource_id, scale_factor)) |
.Times(1) |
.WillOnce(Return(static_memory)); |
scoped_refptr<base::RefCountedStaticMemory> result = |
- resource_bundle.LoadDataResourceBytes(resource_id); |
+ resource_bundle.LoadDataResourceBytes(resource_id, scale_factor); |
EXPECT_EQ(static_memory, result); |
} |
@@ -172,11 +180,13 @@ TEST(ResourceBundle, DelegateGetRawDataResource) { |
int resource_id = 5; |
- EXPECT_CALL(delegate, GetRawDataResourceMock(resource_id)) |
+ EXPECT_CALL(delegate, GetRawDataResourceMock( |
+ resource_id, ResourceHandle::kScaleFactorNone)) |
.Times(1) |
.WillOnce(Return(string_piece)); |
- base::StringPiece result = resource_bundle.GetRawDataResource(resource_id); |
+ base::StringPiece result = resource_bundle.GetRawDataResource( |
+ resource_id, ResourceHandle::kScaleFactorNone); |
EXPECT_EQ(string_piece.data(), result.data()); |
} |
@@ -232,16 +242,58 @@ TEST(ResourceBundle, LoadDataResourceBytes) { |
static_cast<int>(kSamplePakSize)); |
// Create a resource bundle from the file. |
- resource_bundle.LoadTestResources(data_path); |
+ resource_bundle.LoadTestResources(data_path, data_path); |
const int kUnfoundResourceId = 10000; |
- EXPECT_EQ(NULL, resource_bundle.LoadDataResourceBytes(kUnfoundResourceId)); |
+ EXPECT_EQ(NULL, resource_bundle.LoadDataResourceBytes( |
+ kUnfoundResourceId, ResourceHandle::kScaleFactorNone)); |
// Give a .pak file that doesn't exist so we will fail to load it. |
resource_bundle.AddDataPack( |
FilePath(FILE_PATH_LITERAL("non-existant-file.pak")), |
1.0); |
- EXPECT_EQ(NULL, resource_bundle.LoadDataResourceBytes(kUnfoundResourceId)); |
+ EXPECT_EQ(NULL, resource_bundle.LoadDataResourceBytes( |
+ kUnfoundResourceId, ResourceHandle::kScaleFactorNone)); |
+ } |
+} |
+ |
+TEST(ResourceBundle, GetRawDataResource) { |
+ |
+ // On Windows, the default data is compiled into the binary so this does |
+ // nothing. |
+ ScopedTempDir dir; |
+ ASSERT_TRUE(dir.CreateUniqueTempDir()); |
+ FilePath locale_path = dir.path().Append(FILE_PATH_LITERAL("empty.pak")); |
+ FilePath data_path = dir.path().Append(FILE_PATH_LITERAL("sample.pak")); |
+ FilePath data_2x_path = dir.path().Append(FILE_PATH_LITERAL("sample_2x.pak")); |
+ |
+ { |
+ ResourceBundle resource_bundle(NULL); |
+ // Dump contents into the pak files. |
+ ASSERT_EQ(file_util::WriteFile(locale_path, kEmptyPakContents, |
+ kEmptyPakSize), static_cast<int>(kEmptyPakSize)); |
+ ASSERT_EQ(file_util::WriteFile(data_path, kSamplePakContents, |
+ kSamplePakSize), static_cast<int>(kSamplePakSize)); |
+ ASSERT_EQ(file_util::WriteFile(data_2x_path, kSamplePakContents2x, |
+ kSamplePakSize2x), static_cast<int>(kSamplePakSize2x)); |
+ |
+ // Load the regular and 2x pak files. |
+ resource_bundle.LoadTestResources(data_path, locale_path); |
+ resource_bundle.AddDataPack(data_2x_path, ResourceHandle::kScaleFactor200x); |
+ |
+ // Resource ID 4 exists in both 1x and 2x paks, so we expect a different |
+ // result when requesting the 2x scale. |
+ EXPECT_EQ("this is id 4", resource_bundle.GetRawDataResource(4, |
+ ResourceHandle::kScaleFactor100x)); |
+ EXPECT_EQ("this is id 4 2x", resource_bundle.GetRawDataResource(4, |
+ ResourceHandle::kScaleFactor200x)); |
+ |
+ // Resource ID 6 only exists in the 1x pak so we expect the same resource |
+ // for both scale factor requests. |
+ EXPECT_EQ("this is id 6", resource_bundle.GetRawDataResource(6, |
+ ResourceHandle::kScaleFactor100x)); |
+ EXPECT_EQ("this is id 6", resource_bundle.GetRawDataResource(6, |
+ ResourceHandle::kScaleFactor200x)); |
} |
} |