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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <string.h> | 9 #include <string.h> |
10 | 10 |
11 #include "base/base_paths.h" | 11 #include "base/base_paths.h" |
12 #include "base/big_endian.h" | 12 #include "base/big_endian.h" |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
15 #include "base/files/scoped_temp_dir.h" | 15 #include "base/files/scoped_temp_dir.h" |
16 #include "base/logging.h" | 16 #include "base/logging.h" |
17 #include "base/macros.h" | 17 #include "base/macros.h" |
18 #include "base/memory/ref_counted_memory.h" | 18 #include "base/memory/ref_counted_memory.h" |
19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
20 #include "build/build_config.h" | 20 #include "build/build_config.h" |
21 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
23 #include "third_party/skia/include/core/SkBitmap.h" | 23 #include "third_party/skia/include/core/SkBitmap.h" |
24 #include "ui/base/layout.h" | 24 #include "ui/base/layout.h" |
25 #include "ui/base/resource/data_pack.h" | 25 #include "ui/base/resource/data_pack.h" |
26 #include "ui/base/resource/data_pack_literal.h" | |
27 #include "ui/gfx/codec/png_codec.h" | 26 #include "ui/gfx/codec/png_codec.h" |
28 #include "ui/gfx/font_list.h" | 27 #include "ui/gfx/font_list.h" |
29 #include "ui/gfx/image/image_skia.h" | 28 #include "ui/gfx/image/image_skia.h" |
30 | 29 |
31 #if defined(OS_WIN) | 30 #if defined(OS_WIN) |
32 #include "ui/display/win/dpi.h" | 31 #include "ui/display/win/dpi.h" |
33 #endif | 32 #endif |
34 | 33 |
35 using ::testing::_; | 34 using ::testing::_; |
36 using ::testing::Between; | 35 using ::testing::Between; |
37 using ::testing::Property; | 36 using ::testing::Property; |
38 using ::testing::Return; | 37 using ::testing::Return; |
39 using ::testing::ReturnArg; | 38 using ::testing::ReturnArg; |
40 | 39 |
41 namespace ui { | 40 namespace ui { |
| 41 |
| 42 extern const char kSamplePakContents[]; |
| 43 extern const size_t kSamplePakSize; |
| 44 extern const char kSamplePakContents2x[]; |
| 45 extern const size_t kSamplePakSize2x; |
| 46 extern const char kEmptyPakContents[]; |
| 47 extern const size_t kEmptyPakSize; |
| 48 |
42 namespace { | 49 namespace { |
43 | 50 |
44 const unsigned char kPngMagic[8] = { 0x89, 'P', 'N', 'G', 13, 10, 26, 10 }; | 51 const unsigned char kPngMagic[8] = { 0x89, 'P', 'N', 'G', 13, 10, 26, 10 }; |
45 const size_t kPngChunkMetadataSize = 12; | 52 const size_t kPngChunkMetadataSize = 12; |
46 const unsigned char kPngIHDRChunkType[4] = { 'I', 'H', 'D', 'R' }; | 53 const unsigned char kPngIHDRChunkType[4] = { 'I', 'H', 'D', 'R' }; |
47 | 54 |
48 // Custom chunk that GRIT adds to PNG to indicate that it could not find a | 55 // Custom chunk that GRIT adds to PNG to indicate that it could not find a |
49 // bitmap at the requested scale factor and fell back to 1x. | 56 // bitmap at the requested scale factor and fell back to 1x. |
50 const unsigned char kPngScaleChunk[12] = { 0x00, 0x00, 0x00, 0x00, | 57 const unsigned char kPngScaleChunk[12] = { 0x00, 0x00, 0x00, 0x00, |
51 'c', 's', 'C', 'l', | 58 'c', 's', 'C', 'l', |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 EXPECT_EQ(NULL, resource_bundle->LoadDataResourceBytes( | 409 EXPECT_EQ(NULL, resource_bundle->LoadDataResourceBytes( |
403 kUnfoundResourceId)); | 410 kUnfoundResourceId)); |
404 } | 411 } |
405 | 412 |
406 TEST_F(ResourceBundleImageTest, GetRawDataResource) { | 413 TEST_F(ResourceBundleImageTest, GetRawDataResource) { |
407 base::FilePath data_path = dir_path().Append(FILE_PATH_LITERAL("sample.pak")); | 414 base::FilePath data_path = dir_path().Append(FILE_PATH_LITERAL("sample.pak")); |
408 base::FilePath data_2x_path = | 415 base::FilePath data_2x_path = |
409 dir_path().Append(FILE_PATH_LITERAL("sample_2x.pak")); | 416 dir_path().Append(FILE_PATH_LITERAL("sample_2x.pak")); |
410 | 417 |
411 // Dump contents into the pak files. | 418 // Dump contents into the pak files. |
412 ASSERT_EQ(base::WriteFile(data_path, kSamplePakContentsV4, kSamplePakSizeV4), | 419 ASSERT_EQ(base::WriteFile(data_path, kSamplePakContents, |
413 static_cast<int>(kSamplePakSizeV4)); | 420 kSamplePakSize), static_cast<int>(kSamplePakSize)); |
414 ASSERT_EQ(base::WriteFile(data_2x_path, kSamplePakContents2x, | 421 ASSERT_EQ(base::WriteFile(data_2x_path, kSamplePakContents2x, |
415 kSamplePakSize2x), static_cast<int>(kSamplePakSize2x)); | 422 kSamplePakSize2x), static_cast<int>(kSamplePakSize2x)); |
416 | 423 |
417 // Load the regular and 2x pak files. | 424 // Load the regular and 2x pak files. |
418 ResourceBundle* resource_bundle = CreateResourceBundleWithEmptyLocalePak(); | 425 ResourceBundle* resource_bundle = CreateResourceBundleWithEmptyLocalePak(); |
419 resource_bundle->AddDataPackFromPath(data_path, SCALE_FACTOR_100P); | 426 resource_bundle->AddDataPackFromPath(data_path, SCALE_FACTOR_100P); |
420 resource_bundle->AddDataPackFromPath(data_2x_path, SCALE_FACTOR_200P); | 427 resource_bundle->AddDataPackFromPath(data_2x_path, SCALE_FACTOR_200P); |
421 | 428 |
422 // Resource ID 4 exists in both 1x and 2x paks, so we expect a different | 429 // Resource ID 4 exists in both 1x and 2x paks, so we expect a different |
423 // result when requesting the 2x scale. | 430 // result when requesting the 2x scale. |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 resource_bundle->AddDataPackFromPath(data_default_path, SCALE_FACTOR_NONE); | 593 resource_bundle->AddDataPackFromPath(data_default_path, SCALE_FACTOR_NONE); |
587 | 594 |
588 gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3); | 595 gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3); |
589 EXPECT_EQ(1u, image_skia->image_reps().size()); | 596 EXPECT_EQ(1u, image_skia->image_reps().size()); |
590 EXPECT_TRUE(image_skia->image_reps()[0].unscaled()); | 597 EXPECT_TRUE(image_skia->image_reps()[0].unscaled()); |
591 EXPECT_EQ(ui::SCALE_FACTOR_100P, | 598 EXPECT_EQ(ui::SCALE_FACTOR_100P, |
592 GetSupportedScaleFactor(image_skia->image_reps()[0].scale())); | 599 GetSupportedScaleFactor(image_skia->image_reps()[0].scale())); |
593 } | 600 } |
594 | 601 |
595 } // namespace ui | 602 } // namespace ui |
OLD | NEW |