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

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

Issue 2028393003: [Merge to 2756] Revert "Compress .pak resources with new option: "type=GZIPPABLE_BINDATA"" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2756
Patch Set: Created 4 years, 6 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/resource_bundle.cc ('k') | ui/base/ui_base.gyp » ('j') | 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>
10 9
11 #include "base/base_paths.h" 10 #include "base/base_paths.h"
12 #include "base/big_endian.h" 11 #include "base/big_endian.h"
13 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
14 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
15 #include "base/files/scoped_temp_dir.h" 14 #include "base/files/scoped_temp_dir.h"
16 #include "base/logging.h" 15 #include "base/logging.h"
17 #include "base/macros.h" 16 #include "base/macros.h"
18 #include "base/memory/ref_counted_memory.h" 17 #include "base/memory/ref_counted_memory.h"
19 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 ui::ScaleFactor scale_factor = ui::SCALE_FACTOR_NONE; 263 ui::ScaleFactor scale_factor = ui::SCALE_FACTOR_NONE;
265 264
266 EXPECT_CALL(delegate, LoadDataResourceBytes(resource_id, scale_factor)) 265 EXPECT_CALL(delegate, LoadDataResourceBytes(resource_id, scale_factor))
267 .Times(1).WillOnce(Return(static_memory.get())); 266 .Times(1).WillOnce(Return(static_memory.get()));
268 267
269 scoped_refptr<base::RefCountedMemory> result = 268 scoped_refptr<base::RefCountedMemory> result =
270 resource_bundle->LoadDataResourceBytesForScale(resource_id, scale_factor); 269 resource_bundle->LoadDataResourceBytesForScale(resource_id, scale_factor);
271 EXPECT_EQ(static_memory, result); 270 EXPECT_EQ(static_memory, result);
272 } 271 }
273 272
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) { 273 TEST_F(ResourceBundleTest, DelegateGetRawDataResource) {
313 MockResourceBundleDelegate delegate; 274 MockResourceBundleDelegate delegate;
314 ResourceBundle* resource_bundle = CreateResourceBundle(&delegate); 275 ResourceBundle* resource_bundle = CreateResourceBundle(&delegate);
315 276
316 // Create the string piece for testing purposes. 277 // Create the string piece for testing purposes.
317 char data[] = "My test data"; 278 char data[] = "My test data";
318 base::StringPiece string_piece(data); 279 base::StringPiece string_piece(data);
319 280
320 int resource_id = 5; 281 int resource_id = 5;
321 282
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 resource_bundle->AddDataPackFromPath(data_default_path, SCALE_FACTOR_NONE); 703 resource_bundle->AddDataPackFromPath(data_default_path, SCALE_FACTOR_NONE);
743 704
744 gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3); 705 gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3);
745 EXPECT_EQ(1u, image_skia->image_reps().size()); 706 EXPECT_EQ(1u, image_skia->image_reps().size());
746 EXPECT_TRUE(image_skia->image_reps()[0].unscaled()); 707 EXPECT_TRUE(image_skia->image_reps()[0].unscaled());
747 EXPECT_EQ(ui::SCALE_FACTOR_100P, 708 EXPECT_EQ(ui::SCALE_FACTOR_100P,
748 GetSupportedScaleFactor(image_skia->image_reps()[0].scale())); 709 GetSupportedScaleFactor(image_skia->image_reps()[0].scale()));
749 } 710 }
750 711
751 } // namespace ui 712 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/resource/resource_bundle.cc ('k') | ui/base/ui_base.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698