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/big_endian.h" | 8 #include "base/big_endian.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 int resource_id = 5; | 301 int resource_id = 5; |
302 | 302 |
303 EXPECT_CALL(delegate, GetLocalizedStringMock(resource_id)) | 303 EXPECT_CALL(delegate, GetLocalizedStringMock(resource_id)) |
304 .Times(1) | 304 .Times(1) |
305 .WillOnce(Return(data)); | 305 .WillOnce(Return(data)); |
306 | 306 |
307 base::string16 result = resource_bundle->GetLocalizedString(resource_id); | 307 base::string16 result = resource_bundle->GetLocalizedString(resource_id); |
308 EXPECT_EQ(data, result); | 308 EXPECT_EQ(data, result); |
309 } | 309 } |
310 | 310 |
| 311 TEST_F(ResourceBundleTest, OverrideStringResource) { |
| 312 ResourceBundle* resource_bundle = CreateResourceBundle(NULL); |
| 313 |
| 314 base::string16 data = base::ASCIIToUTF16("My test data"); |
| 315 int resource_id = 5; |
| 316 |
| 317 base::string16 result = resource_bundle->GetLocalizedString(resource_id); |
| 318 EXPECT_EQ(base::string16(), result); |
| 319 |
| 320 resource_bundle->OverrideLocaleStringResource(resource_id, data); |
| 321 |
| 322 result = resource_bundle->GetLocalizedString(resource_id); |
| 323 EXPECT_EQ(data, result); |
| 324 } |
| 325 |
| 326 TEST_F(ResourceBundleTest, DelegateGetLocalizedStringWithOverride) { |
| 327 MockResourceBundleDelegate delegate; |
| 328 ResourceBundle* resource_bundle = CreateResourceBundle(&delegate); |
| 329 |
| 330 base::string16 delegate_data = base::ASCIIToUTF16("My delegate data"); |
| 331 int resource_id = 5; |
| 332 |
| 333 EXPECT_CALL(delegate, GetLocalizedStringMock(resource_id)).Times(1).WillOnce( |
| 334 Return(delegate_data)); |
| 335 |
| 336 base::string16 override_data = base::ASCIIToUTF16("My override data"); |
| 337 |
| 338 base::string16 result = resource_bundle->GetLocalizedString(resource_id); |
| 339 EXPECT_EQ(delegate_data, result); |
| 340 } |
| 341 |
311 #if defined(USE_OZONE) && !defined(USE_PANGO) | 342 #if defined(USE_OZONE) && !defined(USE_PANGO) |
312 #define MAYBE_DelegateGetFontList DISABLED_DelegateGetFontList | 343 #define MAYBE_DelegateGetFontList DISABLED_DelegateGetFontList |
313 #else | 344 #else |
314 #define MAYBE_DelegateGetFontList DelegateGetFontList | 345 #define MAYBE_DelegateGetFontList DelegateGetFontList |
315 #endif | 346 #endif |
316 | 347 |
317 TEST_F(ResourceBundleTest, MAYBE_DelegateGetFontList) { | 348 TEST_F(ResourceBundleTest, MAYBE_DelegateGetFontList) { |
318 MockResourceBundleDelegate delegate; | 349 MockResourceBundleDelegate delegate; |
319 ResourceBundle* resource_bundle = CreateResourceBundle(&delegate); | 350 ResourceBundle* resource_bundle = CreateResourceBundle(&delegate); |
320 | 351 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 virtual void SetUp() OVERRIDE { | 383 virtual void SetUp() OVERRIDE { |
353 // Create a temporary directory to write test resource bundles to. | 384 // Create a temporary directory to write test resource bundles to. |
354 ASSERT_TRUE(dir_.CreateUniqueTempDir()); | 385 ASSERT_TRUE(dir_.CreateUniqueTempDir()); |
355 } | 386 } |
356 | 387 |
357 // Returns resource bundle which uses an empty data pak for locale data. | 388 // Returns resource bundle which uses an empty data pak for locale data. |
358 ui::ResourceBundle* CreateResourceBundleWithEmptyLocalePak() { | 389 ui::ResourceBundle* CreateResourceBundleWithEmptyLocalePak() { |
359 // Write an empty data pak for locale data. | 390 // Write an empty data pak for locale data. |
360 const base::FilePath& locale_path = dir_path().Append( | 391 const base::FilePath& locale_path = dir_path().Append( |
361 FILE_PATH_LITERAL("locale.pak")); | 392 FILE_PATH_LITERAL("locale.pak")); |
362 EXPECT_EQ(base::WriteFile(locale_path, kEmptyPakContents, | 393 EXPECT_EQ(base::WriteFile(locale_path, kEmptyPakContents, kEmptyPakSize), |
363 kEmptyPakSize), | |
364 static_cast<int>(kEmptyPakSize)); | 394 static_cast<int>(kEmptyPakSize)); |
365 | 395 |
366 ui::ResourceBundle* resource_bundle = CreateResourceBundle(NULL); | 396 ui::ResourceBundle* resource_bundle = CreateResourceBundle(NULL); |
367 | 397 |
368 // Load the empty locale data pak. | 398 // Load the empty locale data pak. |
369 resource_bundle->LoadTestResources(base::FilePath(), locale_path); | 399 resource_bundle->LoadTestResources(base::FilePath(), locale_path); |
370 return resource_bundle; | 400 return resource_bundle; |
371 } | 401 } |
372 | 402 |
373 // Returns the path of temporary directory to write test data packs into. | 403 // Returns the path of temporary directory to write test data packs into. |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 resource_bundle->AddDataPackFromPath(data_default_path, SCALE_FACTOR_NONE); | 613 resource_bundle->AddDataPackFromPath(data_default_path, SCALE_FACTOR_NONE); |
584 | 614 |
585 gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3); | 615 gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3); |
586 EXPECT_EQ(1u, image_skia->image_reps().size()); | 616 EXPECT_EQ(1u, image_skia->image_reps().size()); |
587 EXPECT_TRUE(image_skia->image_reps()[0].unscaled()); | 617 EXPECT_TRUE(image_skia->image_reps()[0].unscaled()); |
588 EXPECT_EQ(ui::SCALE_FACTOR_100P, | 618 EXPECT_EQ(ui::SCALE_FACTOR_100P, |
589 GetSupportedScaleFactor(image_skia->image_reps()[0].scale())); | 619 GetSupportedScaleFactor(image_skia->image_reps()[0].scale())); |
590 } | 620 } |
591 | 621 |
592 } // namespace ui | 622 } // namespace ui |
OLD | NEW |