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 | 10 |
10 #include "base/base_paths.h" | 11 #include "base/base_paths.h" |
11 #include "base/big_endian.h" | 12 #include "base/big_endian.h" |
12 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
13 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
14 #include "base/files/scoped_temp_dir.h" | 15 #include "base/files/scoped_temp_dir.h" |
15 #include "base/logging.h" | 16 #include "base/logging.h" |
16 #include "base/macros.h" | 17 #include "base/macros.h" |
17 #include "base/memory/ref_counted_memory.h" | 18 #include "base/memory/ref_counted_memory.h" |
18 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
263 ui::ScaleFactor scale_factor = ui::SCALE_FACTOR_NONE; | 264 ui::ScaleFactor scale_factor = ui::SCALE_FACTOR_NONE; |
264 | 265 |
265 EXPECT_CALL(delegate, LoadDataResourceBytes(resource_id, scale_factor)) | 266 EXPECT_CALL(delegate, LoadDataResourceBytes(resource_id, scale_factor)) |
266 .Times(1).WillOnce(Return(static_memory.get())); | 267 .Times(1).WillOnce(Return(static_memory.get())); |
267 | 268 |
268 scoped_refptr<base::RefCountedMemory> result = | 269 scoped_refptr<base::RefCountedMemory> result = |
269 resource_bundle->LoadDataResourceBytesForScale(resource_id, scale_factor); | 270 resource_bundle->LoadDataResourceBytesForScale(resource_id, scale_factor); |
270 EXPECT_EQ(static_memory, result); | 271 EXPECT_EQ(static_memory, result); |
271 } | 272 } |
272 | 273 |
274 TEST_F(ResourceBundleTest, LoadDataResourceBytesGzip) { | |
275 base::ScopedTempDir dir; | |
276 ASSERT_TRUE(dir.CreateUniqueTempDir()); | |
277 base::FilePath data_path = dir.path().Append(FILE_PATH_LITERAL("sample.pak")); | |
278 | |
279 char compressedEntryPakContents[] = { | |
sky
2016/05/31 18:09:14
kCompressed...
smaier
2016/05/31 21:44:17
Done.
| |
280 0x04u, 0x00u, 0x00u, 0x00u, // header(version | |
281 0x01u, 0x00u, 0x00u, 0x00u, // no. entries | |
282 0x01u, // encoding) | |
283 0x04u, 0x00u, 0x15u, 0x00u, 0x00u, 0x00u, // index entry 4 | |
284 0x00u, 0x00u, 0x3bu, 0x00u, 0x00u, | |
285 0x00u, // extra entry for the size of last | |
286 // Entry 4 is a compressed gzip file (with custom leading byte) saying: | |
287 // "This is compressed\n" | |
288 ResourceBundle::CUSTOM_GZIP_HEADER[0], 0x1fu, 0x8bu, 0x08u, 0x00u, 0x00u, | |
289 0x00u, 0x00u, 0x00u, 0x00u, 0x03u, 0x0bu, 0xc9u, 0xc8u, 0x2cu, 0x56u, | |
290 0x00u, 0xa2u, 0xe4u, 0xfcu, 0xdcu, 0x82u, 0xa2u, 0xd4u, 0xe2u, 0xe2u, | |
291 0xd4u, 0x14u, 0x2eu, 0x00u, 0xd9u, 0xf8u, 0xc4u, 0x6fu, 0x13u, 0x00u, | |
292 0x00u, 0x00u}; | |
293 | |
294 size_t compressedEntryPakSize = sizeof(compressedEntryPakContents); | |
sky
2016/05/31 18:09:14
compressed_entry_pak_size
smaier
2016/05/31 21:44:16
Done.
| |
295 | |
296 // Dump contents into the pak file. | |
297 ASSERT_EQ(base::WriteFile(data_path, compressedEntryPakContents, | |
298 compressedEntryPakSize), static_cast<int>(compressedEntryPakSize)); | |
299 | |
300 ResourceBundle* resource_bundle = CreateResourceBundle(nullptr); | |
301 resource_bundle->AddDataPackFromPath(data_path, SCALE_FACTOR_NONE); | |
302 | |
303 // Load the compressed resource. | |
304 scoped_refptr<base::RefCountedMemory> result = | |
305 resource_bundle->LoadDataResourceBytes(4); | |
306 EXPECT_EQ( | |
307 strncmp("This is compressed\n", | |
308 reinterpret_cast<const char*>(result->front()), result->size()), | |
309 0); | |
310 } | |
311 | |
273 TEST_F(ResourceBundleTest, DelegateGetRawDataResource) { | 312 TEST_F(ResourceBundleTest, DelegateGetRawDataResource) { |
274 MockResourceBundleDelegate delegate; | 313 MockResourceBundleDelegate delegate; |
275 ResourceBundle* resource_bundle = CreateResourceBundle(&delegate); | 314 ResourceBundle* resource_bundle = CreateResourceBundle(&delegate); |
276 | 315 |
277 // Create the string piece for testing purposes. | 316 // Create the string piece for testing purposes. |
278 char data[] = "My test data"; | 317 char data[] = "My test data"; |
279 base::StringPiece string_piece(data); | 318 base::StringPiece string_piece(data); |
280 | 319 |
281 int resource_id = 5; | 320 int resource_id = 5; |
282 | 321 |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
703 resource_bundle->AddDataPackFromPath(data_default_path, SCALE_FACTOR_NONE); | 742 resource_bundle->AddDataPackFromPath(data_default_path, SCALE_FACTOR_NONE); |
704 | 743 |
705 gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3); | 744 gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3); |
706 EXPECT_EQ(1u, image_skia->image_reps().size()); | 745 EXPECT_EQ(1u, image_skia->image_reps().size()); |
707 EXPECT_TRUE(image_skia->image_reps()[0].unscaled()); | 746 EXPECT_TRUE(image_skia->image_reps()[0].unscaled()); |
708 EXPECT_EQ(ui::SCALE_FACTOR_100P, | 747 EXPECT_EQ(ui::SCALE_FACTOR_100P, |
709 GetSupportedScaleFactor(image_skia->image_reps()[0].scale())); | 748 GetSupportedScaleFactor(image_skia->image_reps()[0].scale())); |
710 } | 749 } |
711 | 750 |
712 } // namespace ui | 751 } // namespace ui |
OLD | NEW |