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 | 9 |
10 #include "base/base_paths.h" | 10 #include "base/base_paths.h" |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 ui::ScaleFactor scale_factor = ui::SCALE_FACTOR_NONE; | 263 ui::ScaleFactor scale_factor = ui::SCALE_FACTOR_NONE; |
264 | 264 |
265 EXPECT_CALL(delegate, LoadDataResourceBytes(resource_id, scale_factor)) | 265 EXPECT_CALL(delegate, LoadDataResourceBytes(resource_id, scale_factor)) |
266 .Times(1).WillOnce(Return(static_memory.get())); | 266 .Times(1).WillOnce(Return(static_memory.get())); |
267 | 267 |
268 scoped_refptr<base::RefCountedMemory> result = | 268 scoped_refptr<base::RefCountedMemory> result = |
269 resource_bundle->LoadDataResourceBytesForScale(resource_id, scale_factor); | 269 resource_bundle->LoadDataResourceBytesForScale(resource_id, scale_factor); |
270 EXPECT_EQ(static_memory, result); | 270 EXPECT_EQ(static_memory, result); |
271 } | 271 } |
272 | 272 |
| 273 TEST_F(ResourceBundleTest, LoadDataResourceBytesGzip) { |
| 274 base::ScopedTempDir dir; |
| 275 ASSERT_TRUE(dir.CreateUniqueTempDir()); |
| 276 base::FilePath data_path = dir.path().Append(FILE_PATH_LITERAL("sample.pak")); |
| 277 |
| 278 char compressedEntryPakContents[] = { |
| 279 0x04, 0x00, 0x00, 0x00, // header(version |
| 280 0x01, 0x00, 0x00, 0x00, // no. entries |
| 281 0x01, // encoding) |
| 282 0x04, 0x00, 0x15, 0x00, 0x00, 0x00, // index entry 4 |
| 283 0x00, 0x00, 0x3b, 0x00, 0x00, 0x00, // extra entry for the size of last |
| 284 // Entry 4 is a compressed gzip file (with custom leading byte) saying: |
| 285 // "This is compressed\n" |
| 286 ResourceBundle::CUSTOM_GZIP_HEADER[0], 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, |
| 287 0x00, 0x00, 0x00, 0x03, 0x0b, 0xc9, 0xc8, 0x2c, 0x56, 0x00, 0xa2, 0xe4, |
| 288 0xfc, 0xdc, 0x82, 0xa2, 0xd4, 0xe2, 0xe2, 0xd4, 0x14, 0x2e, 0x00, 0xd9, |
| 289 0xf8, 0xc4, 0x6f, 0x13, 0x00, 0x00, 0x00}; |
| 290 |
| 291 size_t compressedEntryPakSize = sizeof(compressedEntryPakContents); |
| 292 |
| 293 // Dump contents into the pak file. |
| 294 ASSERT_EQ(base::WriteFile(data_path, compressedEntryPakContents, |
| 295 compressedEntryPakSize), static_cast<int>(compressedEntryPakSize)); |
| 296 |
| 297 ResourceBundle* resource_bundle = CreateResourceBundle(nullptr); |
| 298 resource_bundle->AddDataPackFromPath(data_path, SCALE_FACTOR_NONE); |
| 299 |
| 300 // Load the compressed resource. |
| 301 scoped_refptr<base::RefCountedMemory> result = |
| 302 resource_bundle->LoadDataResourceBytes(4); |
| 303 EXPECT_STREQ("This is compressed\n", |
| 304 reinterpret_cast<const char*>(result->front())); |
| 305 } |
| 306 |
273 TEST_F(ResourceBundleTest, DelegateGetRawDataResource) { | 307 TEST_F(ResourceBundleTest, DelegateGetRawDataResource) { |
274 MockResourceBundleDelegate delegate; | 308 MockResourceBundleDelegate delegate; |
275 ResourceBundle* resource_bundle = CreateResourceBundle(&delegate); | 309 ResourceBundle* resource_bundle = CreateResourceBundle(&delegate); |
276 | 310 |
277 // Create the string piece for testing purposes. | 311 // Create the string piece for testing purposes. |
278 char data[] = "My test data"; | 312 char data[] = "My test data"; |
279 base::StringPiece string_piece(data); | 313 base::StringPiece string_piece(data); |
280 | 314 |
281 int resource_id = 5; | 315 int resource_id = 5; |
282 | 316 |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
703 resource_bundle->AddDataPackFromPath(data_default_path, SCALE_FACTOR_NONE); | 737 resource_bundle->AddDataPackFromPath(data_default_path, SCALE_FACTOR_NONE); |
704 | 738 |
705 gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3); | 739 gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3); |
706 EXPECT_EQ(1u, image_skia->image_reps().size()); | 740 EXPECT_EQ(1u, image_skia->image_reps().size()); |
707 EXPECT_TRUE(image_skia->image_reps()[0].unscaled()); | 741 EXPECT_TRUE(image_skia->image_reps()[0].unscaled()); |
708 EXPECT_EQ(ui::SCALE_FACTOR_100P, | 742 EXPECT_EQ(ui::SCALE_FACTOR_100P, |
709 GetSupportedScaleFactor(image_skia->image_reps()[0].scale())); | 743 GetSupportedScaleFactor(image_skia->image_reps()[0].scale())); |
710 } | 744 } |
711 | 745 |
712 } // namespace ui | 746 } // namespace ui |
OLD | NEW |