| 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 |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 ui::ScaleFactor scale_factor = ui::SCALE_FACTOR_NONE; | 264 ui::ScaleFactor scale_factor = ui::SCALE_FACTOR_NONE; |
| 265 | 265 |
| 266 EXPECT_CALL(delegate, LoadDataResourceBytes(resource_id, scale_factor)) | 266 EXPECT_CALL(delegate, LoadDataResourceBytes(resource_id, scale_factor)) |
| 267 .Times(1).WillOnce(Return(static_memory.get())); | 267 .Times(1).WillOnce(Return(static_memory.get())); |
| 268 | 268 |
| 269 scoped_refptr<base::RefCountedMemory> result = | 269 scoped_refptr<base::RefCountedMemory> result = |
| 270 resource_bundle->LoadDataResourceBytesForScale(resource_id, scale_factor); | 270 resource_bundle->LoadDataResourceBytesForScale(resource_id, scale_factor); |
| 271 EXPECT_EQ(static_memory, result); | 271 EXPECT_EQ(static_memory, result); |
| 272 } | 272 } |
| 273 | 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 kCompressedEntryPakContents[] = { | |
| 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 compressed_entry_pak_size = sizeof(kCompressedEntryPakContents); | |
| 295 | |
| 296 // Dump contents into the pak file. | |
| 297 ASSERT_EQ(base::WriteFile(data_path, kCompressedEntryPakContents, | |
| 298 compressed_entry_pak_size), static_cast<int>(compressed_entry_pak_size)); | |
| 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 | |
| 312 TEST_F(ResourceBundleTest, DelegateGetRawDataResource) { | 274 TEST_F(ResourceBundleTest, DelegateGetRawDataResource) { |
| 313 MockResourceBundleDelegate delegate; | 275 MockResourceBundleDelegate delegate; |
| 314 ResourceBundle* resource_bundle = CreateResourceBundle(&delegate); | 276 ResourceBundle* resource_bundle = CreateResourceBundle(&delegate); |
| 315 | 277 |
| 316 // Create the string piece for testing purposes. | 278 // Create the string piece for testing purposes. |
| 317 char data[] = "My test data"; | 279 char data[] = "My test data"; |
| 318 base::StringPiece string_piece(data); | 280 base::StringPiece string_piece(data); |
| 319 | 281 |
| 320 int resource_id = 5; | 282 int resource_id = 5; |
| 321 | 283 |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 resource_bundle->AddDataPackFromPath(data_default_path, SCALE_FACTOR_NONE); | 704 resource_bundle->AddDataPackFromPath(data_default_path, SCALE_FACTOR_NONE); |
| 743 | 705 |
| 744 gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3); | 706 gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3); |
| 745 EXPECT_EQ(1u, image_skia->image_reps().size()); | 707 EXPECT_EQ(1u, image_skia->image_reps().size()); |
| 746 EXPECT_TRUE(image_skia->image_reps()[0].unscaled()); | 708 EXPECT_TRUE(image_skia->image_reps()[0].unscaled()); |
| 747 EXPECT_EQ(ui::SCALE_FACTOR_100P, | 709 EXPECT_EQ(ui::SCALE_FACTOR_100P, |
| 748 GetSupportedScaleFactor(image_skia->image_reps()[0].scale())); | 710 GetSupportedScaleFactor(image_skia->image_reps()[0].scale())); |
| 749 } | 711 } |
| 750 | 712 |
| 751 } // namespace ui | 713 } // namespace ui |
| OLD | NEW |