OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/base/resource/resource_bundle.h" | 5 #include "ui/base/resource/resource_bundle.h" |
6 | 6 |
7 #include "base/base_paths.h" | 7 #include "base/base_paths.h" |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/memory/ref_counted_memory.h" | 10 #include "base/memory/ref_counted_memory.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 FilePath pack_path(FILE_PATH_LITERAL("/path/to/test_path.pak")); | 82 FilePath pack_path(FILE_PATH_LITERAL("/path/to/test_path.pak")); |
83 ui::ScaleFactor pack_scale_factor = ui::SCALE_FACTOR_200P; | 83 ui::ScaleFactor pack_scale_factor = ui::SCALE_FACTOR_200P; |
84 | 84 |
85 EXPECT_CALL(delegate, | 85 EXPECT_CALL(delegate, |
86 GetPathForResourcePack( | 86 GetPathForResourcePack( |
87 Property(&FilePath::value, pack_path.value()), | 87 Property(&FilePath::value, pack_path.value()), |
88 pack_scale_factor)) | 88 pack_scale_factor)) |
89 .Times(1) | 89 .Times(1) |
90 .WillOnce(Return(pack_path)); | 90 .WillOnce(Return(pack_path)); |
91 | 91 |
92 resource_bundle.AddDataPack(pack_path, pack_scale_factor); | 92 resource_bundle.AddDataPackFromPath(pack_path, pack_scale_factor); |
93 } | 93 } |
94 | 94 |
95 TEST(ResourceBundle, DelegateGetPathForLocalePack) { | 95 TEST(ResourceBundle, DelegateGetPathForLocalePack) { |
96 MockResourceBundleDelegate delegate; | 96 MockResourceBundleDelegate delegate; |
97 ResourceBundle resource_bundle(&delegate); | 97 ResourceBundle resource_bundle(&delegate); |
98 | 98 |
99 std::string locale = "en-US"; | 99 std::string locale = "en-US"; |
100 | 100 |
101 // Cancel the load. | 101 // Cancel the load. |
102 EXPECT_CALL(delegate, GetPathForLocalePack(_, locale)) | 102 EXPECT_CALL(delegate, GetPathForLocalePack(_, locale)) |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 static_cast<int>(kSamplePakSize)); | 244 static_cast<int>(kSamplePakSize)); |
245 | 245 |
246 // Create a resource bundle from the file. | 246 // Create a resource bundle from the file. |
247 resource_bundle.LoadTestResources(data_path, data_path); | 247 resource_bundle.LoadTestResources(data_path, data_path); |
248 | 248 |
249 const int kUnfoundResourceId = 10000; | 249 const int kUnfoundResourceId = 10000; |
250 EXPECT_EQ(NULL, resource_bundle.LoadDataResourceBytes( | 250 EXPECT_EQ(NULL, resource_bundle.LoadDataResourceBytes( |
251 kUnfoundResourceId, ui::SCALE_FACTOR_NONE)); | 251 kUnfoundResourceId, ui::SCALE_FACTOR_NONE)); |
252 | 252 |
253 // Give a .pak file that doesn't exist so we will fail to load it. | 253 // Give a .pak file that doesn't exist so we will fail to load it. |
254 resource_bundle.AddDataPack( | 254 resource_bundle.AddDataPackFromPath( |
255 FilePath(FILE_PATH_LITERAL("non-existant-file.pak")), | 255 FilePath(FILE_PATH_LITERAL("non-existant-file.pak")), |
256 ui::SCALE_FACTOR_NONE); | 256 ui::SCALE_FACTOR_NONE); |
257 EXPECT_EQ(NULL, resource_bundle.LoadDataResourceBytes( | 257 EXPECT_EQ(NULL, resource_bundle.LoadDataResourceBytes( |
258 kUnfoundResourceId, ui::SCALE_FACTOR_NONE)); | 258 kUnfoundResourceId, ui::SCALE_FACTOR_NONE)); |
259 } | 259 } |
260 } | 260 } |
261 | 261 |
262 TEST(ResourceBundle, GetRawDataResource) { | 262 TEST(ResourceBundle, GetRawDataResource) { |
263 | 263 |
264 // On Windows, the default data is compiled into the binary so this does | 264 // On Windows, the default data is compiled into the binary so this does |
265 // nothing. | 265 // nothing. |
266 ScopedTempDir dir; | 266 ScopedTempDir dir; |
267 ASSERT_TRUE(dir.CreateUniqueTempDir()); | 267 ASSERT_TRUE(dir.CreateUniqueTempDir()); |
268 FilePath locale_path = dir.path().Append(FILE_PATH_LITERAL("empty.pak")); | 268 FilePath locale_path = dir.path().Append(FILE_PATH_LITERAL("empty.pak")); |
269 FilePath data_path = dir.path().Append(FILE_PATH_LITERAL("sample.pak")); | 269 FilePath data_path = dir.path().Append(FILE_PATH_LITERAL("sample.pak")); |
270 FilePath data_2x_path = dir.path().Append(FILE_PATH_LITERAL("sample_2x.pak")); | 270 FilePath data_2x_path = dir.path().Append(FILE_PATH_LITERAL("sample_2x.pak")); |
271 | 271 |
272 { | 272 { |
273 ResourceBundle resource_bundle(NULL); | 273 ResourceBundle resource_bundle(NULL); |
274 // Dump contents into the pak files. | 274 // Dump contents into the pak files. |
275 ASSERT_EQ(file_util::WriteFile(locale_path, kEmptyPakContents, | 275 ASSERT_EQ(file_util::WriteFile(locale_path, kEmptyPakContents, |
276 kEmptyPakSize), static_cast<int>(kEmptyPakSize)); | 276 kEmptyPakSize), static_cast<int>(kEmptyPakSize)); |
277 ASSERT_EQ(file_util::WriteFile(data_path, kSamplePakContents, | 277 ASSERT_EQ(file_util::WriteFile(data_path, kSamplePakContents, |
278 kSamplePakSize), static_cast<int>(kSamplePakSize)); | 278 kSamplePakSize), static_cast<int>(kSamplePakSize)); |
279 ASSERT_EQ(file_util::WriteFile(data_2x_path, kSamplePakContents2x, | 279 ASSERT_EQ(file_util::WriteFile(data_2x_path, kSamplePakContents2x, |
280 kSamplePakSize2x), static_cast<int>(kSamplePakSize2x)); | 280 kSamplePakSize2x), static_cast<int>(kSamplePakSize2x)); |
281 | 281 |
282 // Load the regular and 2x pak files. | 282 // Load the regular and 2x pak files. |
283 resource_bundle.LoadTestResources(data_path, locale_path); | 283 resource_bundle.LoadTestResources(data_path, locale_path); |
284 resource_bundle.AddDataPack(data_2x_path, SCALE_FACTOR_200P); | 284 resource_bundle.AddDataPackFromPath(data_2x_path, SCALE_FACTOR_200P); |
285 | 285 |
286 // Resource ID 4 exists in both 1x and 2x paks, so we expect a different | 286 // Resource ID 4 exists in both 1x and 2x paks, so we expect a different |
287 // result when requesting the 2x scale. | 287 // result when requesting the 2x scale. |
288 EXPECT_EQ("this is id 4", resource_bundle.GetRawDataResource(4, | 288 EXPECT_EQ("this is id 4", resource_bundle.GetRawDataResource(4, |
289 SCALE_FACTOR_100P)); | 289 SCALE_FACTOR_100P)); |
290 EXPECT_EQ("this is id 4 2x", resource_bundle.GetRawDataResource(4, | 290 EXPECT_EQ("this is id 4 2x", resource_bundle.GetRawDataResource(4, |
291 SCALE_FACTOR_200P)); | 291 SCALE_FACTOR_200P)); |
292 | 292 |
293 // Resource ID 6 only exists in the 1x pak so we expect the same resource | 293 // Resource ID 6 only exists in the 1x pak so we expect the same resource |
294 // for both scale factor requests. | 294 // for both scale factor requests. |
295 EXPECT_EQ("this is id 6", resource_bundle.GetRawDataResource(6, | 295 EXPECT_EQ("this is id 6", resource_bundle.GetRawDataResource(6, |
296 SCALE_FACTOR_100P)); | 296 SCALE_FACTOR_100P)); |
297 EXPECT_EQ("this is id 6", resource_bundle.GetRawDataResource(6, | 297 EXPECT_EQ("this is id 6", resource_bundle.GetRawDataResource(6, |
298 SCALE_FACTOR_200P)); | 298 SCALE_FACTOR_200P)); |
299 } | 299 } |
300 } | 300 } |
301 | 301 |
302 TEST(ResourceBundle, LocaleDataPakExists) { | 302 TEST(ResourceBundle, LocaleDataPakExists) { |
303 ResourceBundle resource_bundle(NULL); | 303 ResourceBundle resource_bundle(NULL); |
304 | 304 |
305 // Check that ResourceBundle::LocaleDataPakExists returns the correct results. | 305 // Check that ResourceBundle::LocaleDataPakExists returns the correct results. |
306 EXPECT_TRUE(resource_bundle.LocaleDataPakExists("en-US")); | 306 EXPECT_TRUE(resource_bundle.LocaleDataPakExists("en-US")); |
307 EXPECT_FALSE(resource_bundle.LocaleDataPakExists("not_a_real_locale")); | 307 EXPECT_FALSE(resource_bundle.LocaleDataPakExists("not_a_real_locale")); |
308 } | 308 } |
309 | 309 |
310 } // namespace ui | 310 } // namespace ui |
OLD | NEW |