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

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

Issue 145873006: ui/base/resource: Roll our own version of ReadBigEndian() function. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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 | Annotate | Revision Log
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 "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"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/ref_counted_memory.h" 12 #include "base/memory/ref_counted_memory.h"
13 #include "base/path_service.h" 13 #include "base/path_service.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "net/base/big_endian.h" 15 #include "grit/ui_resources.h"
16 #include "testing/gmock/include/gmock/gmock.h" 16 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "third_party/skia/include/core/SkBitmap.h" 18 #include "third_party/skia/include/core/SkBitmap.h"
19 #include "ui/base/layout.h" 19 #include "ui/base/layout.h"
20 #include "ui/base/resource/data_pack.h" 20 #include "ui/base/resource/data_pack.h"
21 #include "ui/gfx/codec/png_codec.h" 21 #include "ui/gfx/codec/png_codec.h"
22 #include "ui/gfx/image/image_skia.h" 22 #include "ui/gfx/image/image_skia.h"
23 23
24 #include "grit/ui_resources.h"
25
26 using ::testing::_; 24 using ::testing::_;
27 using ::testing::Between; 25 using ::testing::Between;
28 using ::testing::Property; 26 using ::testing::Property;
29 using ::testing::Return; 27 using ::testing::Return;
30 using ::testing::ReturnArg; 28 using ::testing::ReturnArg;
31 29
32 namespace ui { 30 namespace ui {
33 31
34 extern const char kSamplePakContents[]; 32 extern const char kSamplePakContents[];
35 extern const size_t kSamplePakSize; 33 extern const size_t kSamplePakSize;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 return true; 83 return true;
86 } 84 }
87 MOCK_METHOD1(GetFontMock, 85 MOCK_METHOD1(GetFontMock,
88 gfx::Font*(ui::ResourceBundle::FontStyle style)); 86 gfx::Font*(ui::ResourceBundle::FontStyle style));
89 virtual scoped_ptr<gfx::Font> GetFont( 87 virtual scoped_ptr<gfx::Font> GetFont(
90 ui::ResourceBundle::FontStyle style) OVERRIDE { 88 ui::ResourceBundle::FontStyle style) OVERRIDE {
91 return scoped_ptr<gfx::Font>(GetFontMock(style)); 89 return scoped_ptr<gfx::Font>(GetFontMock(style));
92 } 90 }
93 }; 91 };
94 92
93 uint32_t ReadBigEndian32(const void* ptr) {
94 const uint8_t* data = reinterpret_cast<const uint8_t*>(ptr);
95 return (data[3] << 0) | (data[2] << 8) | (data[1] << 16) | (data[0] << 24);
96 }
97
95 // Returns |bitmap_data| with |custom_chunk| inserted after the IHDR chunk. 98 // Returns |bitmap_data| with |custom_chunk| inserted after the IHDR chunk.
96 void AddCustomChunk(const base::StringPiece& custom_chunk, 99 void AddCustomChunk(const base::StringPiece& custom_chunk,
97 std::vector<unsigned char>* bitmap_data) { 100 std::vector<unsigned char>* bitmap_data) {
98 EXPECT_LT(arraysize(kPngMagic) + kPngChunkMetadataSize, bitmap_data->size()); 101 EXPECT_LT(arraysize(kPngMagic) + kPngChunkMetadataSize, bitmap_data->size());
99 EXPECT_TRUE(std::equal( 102 EXPECT_TRUE(std::equal(
100 bitmap_data->begin(), 103 bitmap_data->begin(),
101 bitmap_data->begin() + arraysize(kPngMagic), 104 bitmap_data->begin() + arraysize(kPngMagic),
102 kPngMagic)); 105 kPngMagic));
103 std::vector<unsigned char>::iterator ihdr_start = 106 std::vector<unsigned char>::iterator ihdr_start =
104 bitmap_data->begin() + arraysize(kPngMagic); 107 bitmap_data->begin() + arraysize(kPngMagic);
105 char ihdr_length_data[sizeof(uint32)]; 108 char ihdr_length_data[sizeof(uint32)];
106 for (size_t i = 0; i < sizeof(uint32); ++i) 109 for (size_t i = 0; i < sizeof(uint32); ++i)
107 ihdr_length_data[i] = *(ihdr_start + i); 110 ihdr_length_data[i] = *(ihdr_start + i);
108 uint32 ihdr_chunk_length = 0; 111 uint32 ihdr_chunk_length = ReadBigEndian32(ihdr_length_data);
109 net::ReadBigEndian(reinterpret_cast<char*>(ihdr_length_data),
110 &ihdr_chunk_length);
111 EXPECT_TRUE(std::equal( 112 EXPECT_TRUE(std::equal(
112 ihdr_start + sizeof(uint32), 113 ihdr_start + sizeof(uint32),
113 ihdr_start + sizeof(uint32) + sizeof(kPngIHDRChunkType), 114 ihdr_start + sizeof(uint32) + sizeof(kPngIHDRChunkType),
114 kPngIHDRChunkType)); 115 kPngIHDRChunkType));
115 116
116 bitmap_data->insert(ihdr_start + kPngChunkMetadataSize + ihdr_chunk_length, 117 bitmap_data->insert(ihdr_start + kPngChunkMetadataSize + ihdr_chunk_length,
117 custom_chunk.begin(), custom_chunk.end()); 118 custom_chunk.begin(), custom_chunk.end());
118 } 119 }
119 120
120 // Creates datapack at |path| with a single bitmap at resource ID 3 121 // Creates datapack at |path| with a single bitmap at resource ID 3
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 ResourceBundle* resource_bundle = CreateResourceBundleWithEmptyLocalePak(); 579 ResourceBundle* resource_bundle = CreateResourceBundleWithEmptyLocalePak();
579 resource_bundle->AddDataPackFromPath(data_default_path, SCALE_FACTOR_NONE); 580 resource_bundle->AddDataPackFromPath(data_default_path, SCALE_FACTOR_NONE);
580 581
581 gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3); 582 gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3);
582 EXPECT_EQ(1u, image_skia->image_reps().size()); 583 EXPECT_EQ(1u, image_skia->image_reps().size());
583 EXPECT_EQ(ui::SCALE_FACTOR_100P, 584 EXPECT_EQ(ui::SCALE_FACTOR_100P,
584 GetSupportedScaleFactor(image_skia->image_reps()[0].scale())); 585 GetSupportedScaleFactor(image_skia->image_reps()[0].scale()));
585 } 586 }
586 587
587 } // namespace ui 588 } // namespace ui
OLDNEW
« ui/base/resource/resource_bundle.cc ('K') | « ui/base/resource/resource_bundle.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698