| 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_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 ui::ScaleFactor scale_factor, | 76 ui::ScaleFactor scale_factor, |
| 77 base::StringPiece* value) OVERRIDE { | 77 base::StringPiece* value) OVERRIDE { |
| 78 *value = GetRawDataResourceMock(resource_id, scale_factor); | 78 *value = GetRawDataResourceMock(resource_id, scale_factor); |
| 79 return true; | 79 return true; |
| 80 } | 80 } |
| 81 MOCK_METHOD1(GetLocalizedStringMock, string16(int message_id)); | 81 MOCK_METHOD1(GetLocalizedStringMock, string16(int message_id)); |
| 82 virtual bool GetLocalizedString(int message_id, string16* value) OVERRIDE { | 82 virtual bool GetLocalizedString(int message_id, string16* value) OVERRIDE { |
| 83 *value = GetLocalizedStringMock(message_id); | 83 *value = GetLocalizedStringMock(message_id); |
| 84 return true; | 84 return true; |
| 85 } | 85 } |
| 86 MOCK_METHOD1(GetFontMock, gfx::Font*(ui::ResourceBundle::FontStyle style)); | 86 MOCK_METHOD1(GetFontListMock, |
| 87 virtual scoped_ptr<gfx::Font> GetFont( | 87 gfx::FontList*(ui::ResourceBundle::FontStyle style)); |
| 88 virtual scoped_ptr<gfx::FontList> GetFontList( |
| 88 ui::ResourceBundle::FontStyle style) OVERRIDE { | 89 ui::ResourceBundle::FontStyle style) OVERRIDE { |
| 89 return scoped_ptr<gfx::Font>(GetFontMock(style)); | 90 return scoped_ptr<gfx::FontList>(GetFontListMock(style)); |
| 90 } | 91 } |
| 91 }; | 92 }; |
| 92 | 93 |
| 93 // Returns |bitmap_data| with |custom_chunk| inserted after the IHDR chunk. | 94 // Returns |bitmap_data| with |custom_chunk| inserted after the IHDR chunk. |
| 94 void AddCustomChunk(const base::StringPiece& custom_chunk, | 95 void AddCustomChunk(const base::StringPiece& custom_chunk, |
| 95 std::vector<unsigned char>* bitmap_data) { | 96 std::vector<unsigned char>* bitmap_data) { |
| 96 EXPECT_LT(arraysize(kPngMagic) + kPngChunkMetadataSize, bitmap_data->size()); | 97 EXPECT_LT(arraysize(kPngMagic) + kPngChunkMetadataSize, bitmap_data->size()); |
| 97 EXPECT_TRUE(std::equal( | 98 EXPECT_TRUE(std::equal( |
| 98 bitmap_data->begin(), | 99 bitmap_data->begin(), |
| 99 bitmap_data->begin() + arraysize(kPngMagic), | 100 bitmap_data->begin() + arraysize(kPngMagic), |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 int resource_id = 5; | 301 int resource_id = 5; |
| 301 | 302 |
| 302 EXPECT_CALL(delegate, GetLocalizedStringMock(resource_id)) | 303 EXPECT_CALL(delegate, GetLocalizedStringMock(resource_id)) |
| 303 .Times(1) | 304 .Times(1) |
| 304 .WillOnce(Return(data)); | 305 .WillOnce(Return(data)); |
| 305 | 306 |
| 306 string16 result = resource_bundle->GetLocalizedString(resource_id); | 307 string16 result = resource_bundle->GetLocalizedString(resource_id); |
| 307 EXPECT_EQ(data, result); | 308 EXPECT_EQ(data, result); |
| 308 } | 309 } |
| 309 | 310 |
| 310 TEST_F(ResourceBundleTest, DelegateGetFont) { | 311 TEST_F(ResourceBundleTest, DelegateGetFontList) { |
| 311 MockResourceBundleDelegate delegate; | 312 MockResourceBundleDelegate delegate; |
| 312 ResourceBundle* resource_bundle = CreateResourceBundle(&delegate); | 313 ResourceBundle* resource_bundle = CreateResourceBundle(&delegate); |
| 313 | 314 |
| 314 // Should be called once for each font type. When we return NULL the default | 315 // Should be called once for each font type. When we return NULL the default |
| 315 // font will be created. | 316 // font list will be created. |
| 316 gfx::Font* test_font = NULL; | 317 gfx::FontList* test_font_list = NULL; |
| 317 EXPECT_CALL(delegate, GetFontMock(_)) | 318 EXPECT_CALL(delegate, GetFontListMock(_)) |
| 318 .Times(8) | 319 .Times(8) |
| 319 .WillRepeatedly(Return(test_font)); | 320 .WillRepeatedly(Return(test_font_list)); |
| 321 |
| 322 const gfx::FontList* font_list = |
| 323 &resource_bundle->GetFontList(ui::ResourceBundle::BaseFont); |
| 324 EXPECT_TRUE(font_list); |
| 320 | 325 |
| 321 const gfx::Font* font = | 326 const gfx::Font* font = |
| 322 &resource_bundle->GetFont(ui::ResourceBundle::BaseFont); | 327 &resource_bundle->GetFont(ui::ResourceBundle::BaseFont); |
| 323 EXPECT_TRUE(font); | 328 EXPECT_TRUE(font); |
| 324 } | 329 } |
| 325 | 330 |
| 326 TEST_F(ResourceBundleTest, LocaleDataPakExists) { | 331 TEST_F(ResourceBundleTest, LocaleDataPakExists) { |
| 327 ResourceBundle* resource_bundle = CreateResourceBundle(NULL); | 332 ResourceBundle* resource_bundle = CreateResourceBundle(NULL); |
| 328 | 333 |
| 329 // Check that ResourceBundle::LocaleDataPakExists returns the correct results. | 334 // Check that ResourceBundle::LocaleDataPakExists returns the correct results. |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 ResourceBundle* resource_bundle = CreateResourceBundleWithEmptyLocalePak(); | 544 ResourceBundle* resource_bundle = CreateResourceBundleWithEmptyLocalePak(); |
| 540 resource_bundle->AddDataPackFromPath(data_default_path, SCALE_FACTOR_NONE); | 545 resource_bundle->AddDataPackFromPath(data_default_path, SCALE_FACTOR_NONE); |
| 541 | 546 |
| 542 gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3); | 547 gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3); |
| 543 EXPECT_EQ(1u, image_skia->image_reps().size()); | 548 EXPECT_EQ(1u, image_skia->image_reps().size()); |
| 544 EXPECT_EQ(ui::SCALE_FACTOR_100P, | 549 EXPECT_EQ(ui::SCALE_FACTOR_100P, |
| 545 image_skia->image_reps()[0].scale_factor()); | 550 image_skia->image_reps()[0].scale_factor()); |
| 546 } | 551 } |
| 547 | 552 |
| 548 } // namespace ui | 553 } // namespace ui |
| OLD | NEW |