| 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/file_util.h" | 9 #include "base/file_util.h" | 
| 9 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" | 
| 10 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" | 
| 11 #include "base/logging.h" | 12 #include "base/logging.h" | 
| 12 #include "base/memory/ref_counted_memory.h" | 13 #include "base/memory/ref_counted_memory.h" | 
| 13 #include "base/path_service.h" | 14 #include "base/path_service.h" | 
| 14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" | 
| 15 #include "net/base/big_endian.h" | 16 #include "grit/ui_resources.h" | 
| 16 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" | 
| 17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" | 
| 18 #include "third_party/skia/include/core/SkBitmap.h" | 19 #include "third_party/skia/include/core/SkBitmap.h" | 
| 19 #include "ui/base/layout.h" | 20 #include "ui/base/layout.h" | 
| 20 #include "ui/base/resource/data_pack.h" | 21 #include "ui/base/resource/data_pack.h" | 
| 21 #include "ui/gfx/codec/png_codec.h" | 22 #include "ui/gfx/codec/png_codec.h" | 
| 22 #include "ui/gfx/image/image_skia.h" | 23 #include "ui/gfx/image/image_skia.h" | 
| 23 | 24 | 
| 24 #include "grit/ui_resources.h" |  | 
| 25 |  | 
| 26 using ::testing::_; | 25 using ::testing::_; | 
| 27 using ::testing::Between; | 26 using ::testing::Between; | 
| 28 using ::testing::Property; | 27 using ::testing::Property; | 
| 29 using ::testing::Return; | 28 using ::testing::Return; | 
| 30 using ::testing::ReturnArg; | 29 using ::testing::ReturnArg; | 
| 31 | 30 | 
| 32 namespace ui { | 31 namespace ui { | 
| 33 | 32 | 
| 34 extern const char kSamplePakContents[]; | 33 extern const char kSamplePakContents[]; | 
| 35 extern const size_t kSamplePakSize; | 34 extern const size_t kSamplePakSize; | 
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 99   EXPECT_TRUE(std::equal( | 98   EXPECT_TRUE(std::equal( | 
| 100       bitmap_data->begin(), | 99       bitmap_data->begin(), | 
| 101       bitmap_data->begin() + arraysize(kPngMagic), | 100       bitmap_data->begin() + arraysize(kPngMagic), | 
| 102       kPngMagic)); | 101       kPngMagic)); | 
| 103   std::vector<unsigned char>::iterator ihdr_start = | 102   std::vector<unsigned char>::iterator ihdr_start = | 
| 104       bitmap_data->begin() + arraysize(kPngMagic); | 103       bitmap_data->begin() + arraysize(kPngMagic); | 
| 105   char ihdr_length_data[sizeof(uint32)]; | 104   char ihdr_length_data[sizeof(uint32)]; | 
| 106   for (size_t i = 0; i < sizeof(uint32); ++i) | 105   for (size_t i = 0; i < sizeof(uint32); ++i) | 
| 107     ihdr_length_data[i] = *(ihdr_start + i); | 106     ihdr_length_data[i] = *(ihdr_start + i); | 
| 108   uint32 ihdr_chunk_length = 0; | 107   uint32 ihdr_chunk_length = 0; | 
| 109   net::ReadBigEndian(reinterpret_cast<char*>(ihdr_length_data), | 108   base::ReadBigEndian(reinterpret_cast<char*>(ihdr_length_data), | 
| 110                      &ihdr_chunk_length); | 109                       &ihdr_chunk_length); | 
| 111   EXPECT_TRUE(std::equal( | 110   EXPECT_TRUE(std::equal( | 
| 112       ihdr_start + sizeof(uint32), | 111       ihdr_start + sizeof(uint32), | 
| 113       ihdr_start + sizeof(uint32) + sizeof(kPngIHDRChunkType), | 112       ihdr_start + sizeof(uint32) + sizeof(kPngIHDRChunkType), | 
| 114       kPngIHDRChunkType)); | 113       kPngIHDRChunkType)); | 
| 115 | 114 | 
| 116   bitmap_data->insert(ihdr_start + kPngChunkMetadataSize + ihdr_chunk_length, | 115   bitmap_data->insert(ihdr_start + kPngChunkMetadataSize + ihdr_chunk_length, | 
| 117                       custom_chunk.begin(), custom_chunk.end()); | 116                       custom_chunk.begin(), custom_chunk.end()); | 
| 118 } | 117 } | 
| 119 | 118 | 
| 120 // Creates datapack at |path| with a single bitmap at resource ID 3 | 119 // Creates datapack at |path| with a single bitmap at resource ID 3 | 
| (...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 578   ResourceBundle* resource_bundle = CreateResourceBundleWithEmptyLocalePak(); | 577   ResourceBundle* resource_bundle = CreateResourceBundleWithEmptyLocalePak(); | 
| 579   resource_bundle->AddDataPackFromPath(data_default_path, SCALE_FACTOR_NONE); | 578   resource_bundle->AddDataPackFromPath(data_default_path, SCALE_FACTOR_NONE); | 
| 580 | 579 | 
| 581   gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3); | 580   gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3); | 
| 582   EXPECT_EQ(1u, image_skia->image_reps().size()); | 581   EXPECT_EQ(1u, image_skia->image_reps().size()); | 
| 583   EXPECT_EQ(ui::SCALE_FACTOR_100P, | 582   EXPECT_EQ(ui::SCALE_FACTOR_100P, | 
| 584             GetSupportedScaleFactor(image_skia->image_reps()[0].scale())); | 583             GetSupportedScaleFactor(image_skia->image_reps()[0].scale())); | 
| 585 } | 584 } | 
| 586 | 585 | 
| 587 }  // namespace ui | 586 }  // namespace ui | 
| OLD | NEW | 
|---|