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

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

Issue 11301007: Load the resources for max scale factor first. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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
« no previous file with comments | « ui/base/resource/resource_bundle_mac.mm ('k') | ui/gfx/image/image_skia.cc » ('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 "base/base_paths.h" 7 #include "base/base_paths.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 // for both scale factor requests. 416 // for both scale factor requests.
417 EXPECT_EQ("this is id 6", resource_bundle->GetRawDataResourceForScale(6, 417 EXPECT_EQ("this is id 6", resource_bundle->GetRawDataResourceForScale(6,
418 SCALE_FACTOR_100P)); 418 SCALE_FACTOR_100P));
419 EXPECT_EQ("this is id 6", resource_bundle->GetRawDataResourceForScale(6, 419 EXPECT_EQ("this is id 6", resource_bundle->GetRawDataResourceForScale(6,
420 SCALE_FACTOR_200P)); 420 SCALE_FACTOR_200P));
421 } 421 }
422 422
423 // Test requesting image reps at various scale factors from the image returned 423 // Test requesting image reps at various scale factors from the image returned
424 // via ResourceBundle::GetImageNamed(). 424 // via ResourceBundle::GetImageNamed().
425 TEST_F(ResourceBundleImageTest, GetImageNamed) { 425 TEST_F(ResourceBundleImageTest, GetImageNamed) {
426 FilePath data_path = dir_path().Append(FILE_PATH_LITERAL("sample.pak")); 426 FilePath data_1x_path = dir_path().AppendASCII("sample_1x.pak");
427 FilePath data_2x_path = dir_path().Append(FILE_PATH_LITERAL("sample_2x.pak")); 427 FilePath data_2x_path = dir_path().AppendASCII("sample_2x.pak");
428 428
429 // Create the pak files. 429 // Create the pak files.
430 CreateDataPackWithSingleBitmap(data_path, 10, base::StringPiece()); 430 CreateDataPackWithSingleBitmap(data_1x_path, 10, base::StringPiece());
431 CreateDataPackWithSingleBitmap(data_2x_path, 20, base::StringPiece()); 431 CreateDataPackWithSingleBitmap(data_2x_path, 20, base::StringPiece());
432 432
433 // Load the regular and 2x pak files. 433 // Load the regular and 2x pak files.
434 ResourceBundle* resource_bundle = CreateResourceBundleWithEmptyLocalePak(); 434 ResourceBundle* resource_bundle = CreateResourceBundleWithEmptyLocalePak();
435 resource_bundle->AddDataPackFromPath(data_path, SCALE_FACTOR_100P); 435 resource_bundle->AddDataPackFromPath(data_1x_path, SCALE_FACTOR_100P);
436 resource_bundle->AddDataPackFromPath(data_2x_path, SCALE_FACTOR_200P); 436 resource_bundle->AddDataPackFromPath(data_2x_path, SCALE_FACTOR_200P);
437 437
438 EXPECT_EQ(SCALE_FACTOR_200P, resource_bundle->max_scale_factor());
439
438 gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3); 440 gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3);
439 441
442 #if defined(OS_CHROMEOS)
443 // ChromeOS loads highest scale factor first.
444 EXPECT_EQ(ui::SCALE_FACTOR_200P, image_skia->image_reps()[0].scale_factor());
445 #else
446 EXPECT_EQ(ui::SCALE_FACTOR_100P, image_skia->image_reps()[0].scale_factor());
447 #endif
448
440 // Resource ID 3 exists in both 1x and 2x paks. Image reps should be 449 // Resource ID 3 exists in both 1x and 2x paks. Image reps should be
441 // available for both scale factors in |image_skia|. 450 // available for both scale factors in |image_skia|.
442 gfx::ImageSkiaRep image_rep = 451 gfx::ImageSkiaRep image_rep =
443 image_skia->GetRepresentation(ui::SCALE_FACTOR_100P); 452 image_skia->GetRepresentation(ui::SCALE_FACTOR_100P);
444 EXPECT_EQ(ui::SCALE_FACTOR_100P, image_rep.scale_factor()); 453 EXPECT_EQ(ui::SCALE_FACTOR_100P, image_rep.scale_factor());
445 image_rep = image_skia->GetRepresentation(ui::SCALE_FACTOR_200P); 454 image_rep = image_skia->GetRepresentation(ui::SCALE_FACTOR_200P);
446 EXPECT_EQ(ui::SCALE_FACTOR_200P, image_rep.scale_factor()); 455 EXPECT_EQ(ui::SCALE_FACTOR_200P, image_rep.scale_factor());
447 456
448 // The 1.4x pack was not loaded. Requesting the 1.4x resource should return 457 // The 1.4x pack was not loaded. Requesting the 1.4x resource should return
449 // either the 1x or the 2x resource. 458 // either the 1x or the 2x resource.
(...skipping 25 matching lines...) Expand all
475 484
476 // The image rep for 2x should be available. It should be resized to the 485 // The image rep for 2x should be available. It should be resized to the
477 // proper 2x size. 486 // proper 2x size.
478 gfx::ImageSkiaRep image_rep = 487 gfx::ImageSkiaRep image_rep =
479 image_skia->GetRepresentation(ui::SCALE_FACTOR_200P); 488 image_skia->GetRepresentation(ui::SCALE_FACTOR_200P);
480 EXPECT_EQ(ui::SCALE_FACTOR_200P, image_rep.scale_factor()); 489 EXPECT_EQ(ui::SCALE_FACTOR_200P, image_rep.scale_factor());
481 EXPECT_EQ(20, image_rep.pixel_width()); 490 EXPECT_EQ(20, image_rep.pixel_width());
482 EXPECT_EQ(20, image_rep.pixel_height()); 491 EXPECT_EQ(20, image_rep.pixel_height());
483 } 492 }
484 493
494 TEST_F(ResourceBundleImageTest, FallbackToNone) {
495 FilePath data_default_path = dir_path().AppendASCII("sample.pak");
496
497 // Create the pak files.
498 CreateDataPackWithSingleBitmap(data_default_path, 10, base::StringPiece());
499
500 // Load the regular pak files only.
501 ResourceBundle* resource_bundle = CreateResourceBundleWithEmptyLocalePak();
502 resource_bundle->AddDataPackFromPath(data_default_path, SCALE_FACTOR_NONE);
503
504 gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3);
505 EXPECT_EQ(1u, image_skia->image_reps().size());
506 EXPECT_EQ(ui::SCALE_FACTOR_100P,
507 image_skia->image_reps()[0].scale_factor());
508 }
509
485 } // namespace ui 510 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/resource/resource_bundle_mac.mm ('k') | ui/gfx/image/image_skia.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698