Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(449)

Side by Side Diff: ui/base/resource/resource_bundle_unittest.cc

Issue 2969123002: Add deduplication logic to .pak files (Closed)
Patch Set: sizeof() Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/base/resource/data_pack_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
26 #include "ui/gfx/codec/png_codec.h" 27 #include "ui/gfx/codec/png_codec.h"
27 #include "ui/gfx/font_list.h" 28 #include "ui/gfx/font_list.h"
28 #include "ui/gfx/image/image_skia.h" 29 #include "ui/gfx/image/image_skia.h"
29 30
30 #if defined(OS_WIN) 31 #if defined(OS_WIN)
31 #include "ui/display/win/dpi.h" 32 #include "ui/display/win/dpi.h"
32 #endif 33 #endif
33 34
34 using ::testing::_; 35 using ::testing::_;
35 using ::testing::Between; 36 using ::testing::Between;
36 using ::testing::Property; 37 using ::testing::Property;
37 using ::testing::Return; 38 using ::testing::Return;
38 using ::testing::ReturnArg; 39 using ::testing::ReturnArg;
39 40
40 namespace ui { 41 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
49 namespace { 42 namespace {
50 43
51 const unsigned char kPngMagic[8] = { 0x89, 'P', 'N', 'G', 13, 10, 26, 10 }; 44 const unsigned char kPngMagic[8] = { 0x89, 'P', 'N', 'G', 13, 10, 26, 10 };
52 const size_t kPngChunkMetadataSize = 12; 45 const size_t kPngChunkMetadataSize = 12;
53 const unsigned char kPngIHDRChunkType[4] = { 'I', 'H', 'D', 'R' }; 46 const unsigned char kPngIHDRChunkType[4] = { 'I', 'H', 'D', 'R' };
54 47
55 // Custom chunk that GRIT adds to PNG to indicate that it could not find a 48 // Custom chunk that GRIT adds to PNG to indicate that it could not find a
56 // bitmap at the requested scale factor and fell back to 1x. 49 // bitmap at the requested scale factor and fell back to 1x.
57 const unsigned char kPngScaleChunk[12] = { 0x00, 0x00, 0x00, 0x00, 50 const unsigned char kPngScaleChunk[12] = { 0x00, 0x00, 0x00, 0x00,
58 'c', 's', 'C', 'l', 51 'c', 's', 'C', 'l',
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 EXPECT_EQ(NULL, resource_bundle->LoadDataResourceBytes( 402 EXPECT_EQ(NULL, resource_bundle->LoadDataResourceBytes(
410 kUnfoundResourceId)); 403 kUnfoundResourceId));
411 } 404 }
412 405
413 TEST_F(ResourceBundleImageTest, GetRawDataResource) { 406 TEST_F(ResourceBundleImageTest, GetRawDataResource) {
414 base::FilePath data_path = dir_path().Append(FILE_PATH_LITERAL("sample.pak")); 407 base::FilePath data_path = dir_path().Append(FILE_PATH_LITERAL("sample.pak"));
415 base::FilePath data_2x_path = 408 base::FilePath data_2x_path =
416 dir_path().Append(FILE_PATH_LITERAL("sample_2x.pak")); 409 dir_path().Append(FILE_PATH_LITERAL("sample_2x.pak"));
417 410
418 // Dump contents into the pak files. 411 // Dump contents into the pak files.
419 ASSERT_EQ(base::WriteFile(data_path, kSamplePakContents, 412 ASSERT_EQ(base::WriteFile(data_path, kSamplePakContentsV4, kSamplePakSizeV4),
420 kSamplePakSize), static_cast<int>(kSamplePakSize)); 413 static_cast<int>(kSamplePakSizeV4));
421 ASSERT_EQ(base::WriteFile(data_2x_path, kSamplePakContents2x, 414 ASSERT_EQ(base::WriteFile(data_2x_path, kSamplePakContents2x,
422 kSamplePakSize2x), static_cast<int>(kSamplePakSize2x)); 415 kSamplePakSize2x), static_cast<int>(kSamplePakSize2x));
423 416
424 // Load the regular and 2x pak files. 417 // Load the regular and 2x pak files.
425 ResourceBundle* resource_bundle = CreateResourceBundleWithEmptyLocalePak(); 418 ResourceBundle* resource_bundle = CreateResourceBundleWithEmptyLocalePak();
426 resource_bundle->AddDataPackFromPath(data_path, SCALE_FACTOR_100P); 419 resource_bundle->AddDataPackFromPath(data_path, SCALE_FACTOR_100P);
427 resource_bundle->AddDataPackFromPath(data_2x_path, SCALE_FACTOR_200P); 420 resource_bundle->AddDataPackFromPath(data_2x_path, SCALE_FACTOR_200P);
428 421
429 // Resource ID 4 exists in both 1x and 2x paks, so we expect a different 422 // Resource ID 4 exists in both 1x and 2x paks, so we expect a different
430 // result when requesting the 2x scale. 423 // result when requesting the 2x scale.
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 resource_bundle->AddDataPackFromPath(data_default_path, SCALE_FACTOR_NONE); 586 resource_bundle->AddDataPackFromPath(data_default_path, SCALE_FACTOR_NONE);
594 587
595 gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3); 588 gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3);
596 EXPECT_EQ(1u, image_skia->image_reps().size()); 589 EXPECT_EQ(1u, image_skia->image_reps().size());
597 EXPECT_TRUE(image_skia->image_reps()[0].unscaled()); 590 EXPECT_TRUE(image_skia->image_reps()[0].unscaled());
598 EXPECT_EQ(ui::SCALE_FACTOR_100P, 591 EXPECT_EQ(ui::SCALE_FACTOR_100P,
599 GetSupportedScaleFactor(image_skia->image_reps()[0].scale())); 592 GetSupportedScaleFactor(image_skia->image_reps()[0].scale()));
600 } 593 }
601 594
602 } // namespace ui 595 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/resource/data_pack_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698