| 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/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 // bitmap at the requested scale factor and fell back to 1x. | 52 // bitmap at the requested scale factor and fell back to 1x. |
| 53 const unsigned char kPngScaleChunk[12] = { 0x00, 0x00, 0x00, 0x00, | 53 const unsigned char kPngScaleChunk[12] = { 0x00, 0x00, 0x00, 0x00, |
| 54 'c', 's', 'C', 'l', | 54 'c', 's', 'C', 'l', |
| 55 0xc1, 0x30, 0x60, 0x4d }; | 55 0xc1, 0x30, 0x60, 0x4d }; |
| 56 | 56 |
| 57 // Mock for the ResourceBundle::Delegate class. | 57 // Mock for the ResourceBundle::Delegate class. |
| 58 class MockResourceBundleDelegate : public ui::ResourceBundle::Delegate { | 58 class MockResourceBundleDelegate : public ui::ResourceBundle::Delegate { |
| 59 public: | 59 public: |
| 60 MockResourceBundleDelegate() { | 60 MockResourceBundleDelegate() { |
| 61 } | 61 } |
| 62 virtual ~MockResourceBundleDelegate() { | 62 ~MockResourceBundleDelegate() override { |
| 63 } | 63 } |
| 64 | 64 |
| 65 MOCK_METHOD2(GetPathForResourcePack, base::FilePath( | 65 MOCK_METHOD2(GetPathForResourcePack, base::FilePath( |
| 66 const base::FilePath& pack_path, ui::ScaleFactor scale_factor)); | 66 const base::FilePath& pack_path, ui::ScaleFactor scale_factor)); |
| 67 MOCK_METHOD2(GetPathForLocalePack, base::FilePath( | 67 MOCK_METHOD2(GetPathForLocalePack, base::FilePath( |
| 68 const base::FilePath& pack_path, const std::string& locale)); | 68 const base::FilePath& pack_path, const std::string& locale)); |
| 69 MOCK_METHOD1(GetImageNamed, gfx::Image(int resource_id)); | 69 MOCK_METHOD1(GetImageNamed, gfx::Image(int resource_id)); |
| 70 MOCK_METHOD2(GetNativeImageNamed, | 70 MOCK_METHOD2(GetNativeImageNamed, |
| 71 gfx::Image(int resource_id, | 71 gfx::Image(int resource_id, |
| 72 ui::ResourceBundle::ImageRTL rtl)); | 72 ui::ResourceBundle::ImageRTL rtl)); |
| 73 MOCK_METHOD2(LoadDataResourceBytes, | 73 MOCK_METHOD2(LoadDataResourceBytes, |
| 74 base::RefCountedStaticMemory*(int resource_id, | 74 base::RefCountedStaticMemory*(int resource_id, |
| 75 ui::ScaleFactor scale_factor)); | 75 ui::ScaleFactor scale_factor)); |
| 76 MOCK_METHOD2(GetRawDataResourceMock, base::StringPiece( | 76 MOCK_METHOD2(GetRawDataResourceMock, base::StringPiece( |
| 77 int resource_id, | 77 int resource_id, |
| 78 ui::ScaleFactor scale_factor)); | 78 ui::ScaleFactor scale_factor)); |
| 79 virtual bool GetRawDataResource(int resource_id, | 79 bool GetRawDataResource(int resource_id, |
| 80 ui::ScaleFactor scale_factor, | 80 ui::ScaleFactor scale_factor, |
| 81 base::StringPiece* value) override { | 81 base::StringPiece* value) override { |
| 82 *value = GetRawDataResourceMock(resource_id, scale_factor); | 82 *value = GetRawDataResourceMock(resource_id, scale_factor); |
| 83 return true; | 83 return true; |
| 84 } | 84 } |
| 85 MOCK_METHOD1(GetLocalizedStringMock, base::string16(int message_id)); | 85 MOCK_METHOD1(GetLocalizedStringMock, base::string16(int message_id)); |
| 86 virtual bool GetLocalizedString(int message_id, | 86 bool GetLocalizedString(int message_id, |
| 87 base::string16* value) override { | 87 base::string16* value) override { |
| 88 *value = GetLocalizedStringMock(message_id); | 88 *value = GetLocalizedStringMock(message_id); |
| 89 return true; | 89 return true; |
| 90 } | 90 } |
| 91 MOCK_METHOD1(GetFontMock, | 91 MOCK_METHOD1(GetFontMock, |
| 92 gfx::Font*(ui::ResourceBundle::FontStyle style)); | 92 gfx::Font*(ui::ResourceBundle::FontStyle style)); |
| 93 virtual scoped_ptr<gfx::Font> GetFont( | 93 scoped_ptr<gfx::Font> GetFont(ui::ResourceBundle::FontStyle style) override { |
| 94 ui::ResourceBundle::FontStyle style) override { | |
| 95 return make_scoped_ptr(GetFontMock(style)); | 94 return make_scoped_ptr(GetFontMock(style)); |
| 96 } | 95 } |
| 97 }; | 96 }; |
| 98 | 97 |
| 99 // Returns |bitmap_data| with |custom_chunk| inserted after the IHDR chunk. | 98 // Returns |bitmap_data| with |custom_chunk| inserted after the IHDR chunk. |
| 100 void AddCustomChunk(const base::StringPiece& custom_chunk, | 99 void AddCustomChunk(const base::StringPiece& custom_chunk, |
| 101 std::vector<unsigned char>* bitmap_data) { | 100 std::vector<unsigned char>* bitmap_data) { |
| 102 EXPECT_LT(arraysize(kPngMagic) + kPngChunkMetadataSize, bitmap_data->size()); | 101 EXPECT_LT(arraysize(kPngMagic) + kPngChunkMetadataSize, bitmap_data->size()); |
| 103 EXPECT_TRUE(std::equal( | 102 EXPECT_TRUE(std::equal( |
| 104 bitmap_data->begin(), | 103 bitmap_data->begin(), |
| (...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 resource_bundle->AddDataPackFromPath(data_default_path, SCALE_FACTOR_NONE); | 644 resource_bundle->AddDataPackFromPath(data_default_path, SCALE_FACTOR_NONE); |
| 646 | 645 |
| 647 gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3); | 646 gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3); |
| 648 EXPECT_EQ(1u, image_skia->image_reps().size()); | 647 EXPECT_EQ(1u, image_skia->image_reps().size()); |
| 649 EXPECT_TRUE(image_skia->image_reps()[0].unscaled()); | 648 EXPECT_TRUE(image_skia->image_reps()[0].unscaled()); |
| 650 EXPECT_EQ(ui::SCALE_FACTOR_100P, | 649 EXPECT_EQ(ui::SCALE_FACTOR_100P, |
| 651 GetSupportedScaleFactor(image_skia->image_reps()[0].scale())); | 650 GetSupportedScaleFactor(image_skia->image_reps()[0].scale())); |
| 652 } | 651 } |
| 653 | 652 |
| 654 } // namespace ui | 653 } // namespace ui |
| OLD | NEW |