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

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

Issue 1996723002: Switch ResourceBundle LoadDataResourceBytes to return RefCountedMemory. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update to address newly added use 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_ios.mm ('k') | no next file » | 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 9
10 #include "base/base_paths.h" 10 #include "base/base_paths.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 ~MockResourceBundleDelegate() override { 67 ~MockResourceBundleDelegate() override {
68 } 68 }
69 69
70 MOCK_METHOD2(GetPathForResourcePack, base::FilePath( 70 MOCK_METHOD2(GetPathForResourcePack, base::FilePath(
71 const base::FilePath& pack_path, ui::ScaleFactor scale_factor)); 71 const base::FilePath& pack_path, ui::ScaleFactor scale_factor));
72 MOCK_METHOD2(GetPathForLocalePack, base::FilePath( 72 MOCK_METHOD2(GetPathForLocalePack, base::FilePath(
73 const base::FilePath& pack_path, const std::string& locale)); 73 const base::FilePath& pack_path, const std::string& locale));
74 MOCK_METHOD1(GetImageNamed, gfx::Image(int resource_id)); 74 MOCK_METHOD1(GetImageNamed, gfx::Image(int resource_id));
75 MOCK_METHOD1(GetNativeImageNamed, gfx::Image(int resource_id)); 75 MOCK_METHOD1(GetNativeImageNamed, gfx::Image(int resource_id));
76 MOCK_METHOD2(LoadDataResourceBytes, 76 MOCK_METHOD2(LoadDataResourceBytes,
77 base::RefCountedStaticMemory*(int resource_id, 77 base::RefCountedMemory*(int resource_id, ui::ScaleFactor scale_factor));
78 ui::ScaleFactor scale_factor));
79 MOCK_METHOD2(GetRawDataResourceMock, base::StringPiece( 78 MOCK_METHOD2(GetRawDataResourceMock, base::StringPiece(
80 int resource_id, 79 int resource_id,
81 ui::ScaleFactor scale_factor)); 80 ui::ScaleFactor scale_factor));
82 bool GetRawDataResource(int resource_id, 81 bool GetRawDataResource(int resource_id,
83 ui::ScaleFactor scale_factor, 82 ui::ScaleFactor scale_factor,
84 base::StringPiece* value) override { 83 base::StringPiece* value) override {
85 *value = GetRawDataResourceMock(resource_id, scale_factor); 84 *value = GetRawDataResourceMock(resource_id, scale_factor);
86 return true; 85 return true;
87 } 86 }
88 MOCK_METHOD1(GetLocalizedStringMock, base::string16(int message_id)); 87 MOCK_METHOD1(GetLocalizedStringMock, base::string16(int message_id));
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 unsigned char data[] = "My test data"; 258 unsigned char data[] = "My test data";
260 scoped_refptr<base::RefCountedStaticMemory> static_memory( 259 scoped_refptr<base::RefCountedStaticMemory> static_memory(
261 new base::RefCountedStaticMemory(data, sizeof(data))); 260 new base::RefCountedStaticMemory(data, sizeof(data)));
262 261
263 int resource_id = 5; 262 int resource_id = 5;
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::RefCountedStaticMemory> 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, DelegateGetRawDataResource) { 273 TEST_F(ResourceBundleTest, DelegateGetRawDataResource) {
275 MockResourceBundleDelegate delegate; 274 MockResourceBundleDelegate delegate;
276 ResourceBundle* resource_bundle = CreateResourceBundle(&delegate); 275 ResourceBundle* resource_bundle = CreateResourceBundle(&delegate);
277 276
278 // Create the string piece for testing purposes. 277 // Create the string piece for testing purposes.
279 char data[] = "My test data"; 278 char data[] = "My test data";
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 resource_bundle->AddDataPackFromPath(data_default_path, SCALE_FACTOR_NONE); 703 resource_bundle->AddDataPackFromPath(data_default_path, SCALE_FACTOR_NONE);
705 704
706 gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3); 705 gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3);
707 EXPECT_EQ(1u, image_skia->image_reps().size()); 706 EXPECT_EQ(1u, image_skia->image_reps().size());
708 EXPECT_TRUE(image_skia->image_reps()[0].unscaled()); 707 EXPECT_TRUE(image_skia->image_reps()[0].unscaled());
709 EXPECT_EQ(ui::SCALE_FACTOR_100P, 708 EXPECT_EQ(ui::SCALE_FACTOR_100P,
710 GetSupportedScaleFactor(image_skia->image_reps()[0].scale())); 709 GetSupportedScaleFactor(image_skia->image_reps()[0].scale()));
711 } 710 }
712 711
713 } // namespace ui 712 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/resource/resource_bundle_ios.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698