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

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

Issue 322523002: Adding OverrideStringResource API to ResourceBundle. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
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 "base/base_paths.h" 7 #include "base/base_paths.h"
8 #include "base/big_endian.h" 8 #include "base/big_endian.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 int resource_id = 5; 301 int resource_id = 5;
302 302
303 EXPECT_CALL(delegate, GetLocalizedStringMock(resource_id)) 303 EXPECT_CALL(delegate, GetLocalizedStringMock(resource_id))
304 .Times(1) 304 .Times(1)
305 .WillOnce(Return(data)); 305 .WillOnce(Return(data));
306 306
307 base::string16 result = resource_bundle->GetLocalizedString(resource_id); 307 base::string16 result = resource_bundle->GetLocalizedString(resource_id);
308 EXPECT_EQ(data, result); 308 EXPECT_EQ(data, result);
309 } 309 }
310 310
311 TEST_F(ResourceBundleTest, OverrideStringResource) {
312 ResourceBundle* resource_bundle = CreateResourceBundle(NULL);
313
314 base::string16 data = base::ASCIIToUTF16("My test data");
315 int resource_id = 5;
316
317 base::string16 result = resource_bundle->GetLocalizedString(resource_id);
318 EXPECT_EQ(base::string16(), result);
319
320 resource_bundle->OverrideStringResource(resource_id, data);
321
322 result = resource_bundle->GetLocalizedString(resource_id);
323 EXPECT_EQ(data, result);
324 }
325
326 TEST_F(ResourceBundleTest, DelegateGetLocalizedStringWithOverride) {
327 MockResourceBundleDelegate delegate;
328 ResourceBundle* resource_bundle = CreateResourceBundle(&delegate);
329
330 base::string16 delegate_data = base::ASCIIToUTF16("My delegate data");
331 int resource_id = 5;
332
333 EXPECT_CALL(delegate, GetLocalizedStringMock(resource_id))
334 .Times(1)
335 .WillOnce(Return(delegate_data));
336
337 base::string16 override_data = base::ASCIIToUTF16("My override data");
338
339 base::string16 result = resource_bundle->GetLocalizedString(resource_id);
340 EXPECT_EQ(delegate_data, result);
341 }
342
311 #if defined(USE_OZONE) && !defined(USE_PANGO) 343 #if defined(USE_OZONE) && !defined(USE_PANGO)
312 #define MAYBE_DelegateGetFontList DISABLED_DelegateGetFontList 344 #define MAYBE_DelegateGetFontList DISABLED_DelegateGetFontList
313 #else 345 #else
314 #define MAYBE_DelegateGetFontList DelegateGetFontList 346 #define MAYBE_DelegateGetFontList DelegateGetFontList
315 #endif 347 #endif
316 348
317 TEST_F(ResourceBundleTest, MAYBE_DelegateGetFontList) { 349 TEST_F(ResourceBundleTest, MAYBE_DelegateGetFontList) {
318 MockResourceBundleDelegate delegate; 350 MockResourceBundleDelegate delegate;
319 ResourceBundle* resource_bundle = CreateResourceBundle(&delegate); 351 ResourceBundle* resource_bundle = CreateResourceBundle(&delegate);
320 352
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 // Create a temporary directory to write test resource bundles to. 385 // Create a temporary directory to write test resource bundles to.
354 ASSERT_TRUE(dir_.CreateUniqueTempDir()); 386 ASSERT_TRUE(dir_.CreateUniqueTempDir());
355 } 387 }
356 388
357 // Returns resource bundle which uses an empty data pak for locale data. 389 // Returns resource bundle which uses an empty data pak for locale data.
358 ui::ResourceBundle* CreateResourceBundleWithEmptyLocalePak() { 390 ui::ResourceBundle* CreateResourceBundleWithEmptyLocalePak() {
359 // Write an empty data pak for locale data. 391 // Write an empty data pak for locale data.
360 const base::FilePath& locale_path = dir_path().Append( 392 const base::FilePath& locale_path = dir_path().Append(
361 FILE_PATH_LITERAL("locale.pak")); 393 FILE_PATH_LITERAL("locale.pak"));
362 EXPECT_EQ(base::WriteFile(locale_path, kEmptyPakContents, 394 EXPECT_EQ(base::WriteFile(locale_path, kEmptyPakContents,
363 kEmptyPakSize), 395 kEmptyPakSize),
364 static_cast<int>(kEmptyPakSize)); 396 static_cast<int>(kEmptyPakSize));
365 397
366 ui::ResourceBundle* resource_bundle = CreateResourceBundle(NULL); 398 ui::ResourceBundle* resource_bundle = CreateResourceBundle(NULL);
367 399
368 // Load the empty locale data pak. 400 // Load the empty locale data pak.
369 resource_bundle->LoadTestResources(base::FilePath(), locale_path); 401 resource_bundle->LoadTestResources(base::FilePath(), locale_path);
370 return resource_bundle; 402 return resource_bundle;
371 } 403 }
372 404
373 // Returns the path of temporary directory to write test data packs into. 405 // Returns the path of temporary directory to write test data packs into.
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 resource_bundle->AddDataPackFromPath(data_default_path, SCALE_FACTOR_NONE); 615 resource_bundle->AddDataPackFromPath(data_default_path, SCALE_FACTOR_NONE);
584 616
585 gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3); 617 gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3);
586 EXPECT_EQ(1u, image_skia->image_reps().size()); 618 EXPECT_EQ(1u, image_skia->image_reps().size());
587 EXPECT_TRUE(image_skia->image_reps()[0].unscaled()); 619 EXPECT_TRUE(image_skia->image_reps()[0].unscaled());
588 EXPECT_EQ(ui::SCALE_FACTOR_100P, 620 EXPECT_EQ(ui::SCALE_FACTOR_100P,
589 GetSupportedScaleFactor(image_skia->image_reps()[0].scale())); 621 GetSupportedScaleFactor(image_skia->image_reps()[0].scale()));
590 } 622 }
591 623
592 } // namespace ui 624 } // namespace ui
OLDNEW
« ui/base/resource/resource_bundle.cc ('K') | « ui/base/resource/resource_bundle.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698