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 "base/base_paths.h" | 7 #include "base/base_paths.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 | 491 |
492 // The image rep for 2x should be available. It should be resized to the | 492 // The image rep for 2x should be available. It should be resized to the |
493 // proper 2x size. | 493 // proper 2x size. |
494 gfx::ImageSkiaRep image_rep = | 494 gfx::ImageSkiaRep image_rep = |
495 image_skia->GetRepresentation(ui::SCALE_FACTOR_200P); | 495 image_skia->GetRepresentation(ui::SCALE_FACTOR_200P); |
496 EXPECT_EQ(ui::SCALE_FACTOR_200P, image_rep.scale_factor()); | 496 EXPECT_EQ(ui::SCALE_FACTOR_200P, image_rep.scale_factor()); |
497 EXPECT_EQ(20, image_rep.pixel_width()); | 497 EXPECT_EQ(20, image_rep.pixel_width()); |
498 EXPECT_EQ(20, image_rep.pixel_height()); | 498 EXPECT_EQ(20, image_rep.pixel_height()); |
499 } | 499 } |
500 | 500 |
| 501 #if defined(OS_WIN) |
| 502 // Tests GetImageNamed() behaves properly when the size of a scaled image |
| 503 // requires rounding as a result of using a non-integer scale factor. |
| 504 // Scale factors of 140 and 1805 are Windows specific. |
| 505 TEST_F(ResourceBundleImageTest, GetImageNamedFallback1xRounding) { |
| 506 base::FilePath data_path = dir_path().AppendASCII("sample.pak"); |
| 507 base::FilePath data_140P_path = dir_path().AppendASCII("sample_140P.pak"); |
| 508 base::FilePath data_180P_path = dir_path().AppendASCII("sample_180P.pak"); |
| 509 |
| 510 CreateDataPackWithSingleBitmap(data_path, 8, base::StringPiece()); |
| 511 // Mark 140% and 180% images as requiring 1x fallback. |
| 512 CreateDataPackWithSingleBitmap(data_140P_path, 8, base::StringPiece( |
| 513 reinterpret_cast<const char*>(kPngScaleChunk), |
| 514 arraysize(kPngScaleChunk))); |
| 515 CreateDataPackWithSingleBitmap(data_180P_path, 8, base::StringPiece( |
| 516 reinterpret_cast<const char*>(kPngScaleChunk), |
| 517 arraysize(kPngScaleChunk))); |
| 518 |
| 519 ResourceBundle* resource_bundle = CreateResourceBundleWithEmptyLocalePak(); |
| 520 resource_bundle->AddDataPackFromPath(data_path, SCALE_FACTOR_100P); |
| 521 resource_bundle->AddDataPackFromPath(data_140P_path, SCALE_FACTOR_140P); |
| 522 resource_bundle->AddDataPackFromPath(data_180P_path, SCALE_FACTOR_180P); |
| 523 |
| 524 // Non-integer dimensions should be rounded up. |
| 525 gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3); |
| 526 gfx::ImageSkiaRep image_rep = |
| 527 image_skia->GetRepresentation(ui::SCALE_FACTOR_140P); |
| 528 EXPECT_EQ(12, image_rep.pixel_width()); |
| 529 image_rep = image_skia->GetRepresentation(ui::SCALE_FACTOR_180P); |
| 530 EXPECT_EQ(15, image_rep.pixel_width()); |
| 531 } |
| 532 #endif |
| 533 |
501 TEST_F(ResourceBundleImageTest, FallbackToNone) { | 534 TEST_F(ResourceBundleImageTest, FallbackToNone) { |
502 base::FilePath data_default_path = dir_path().AppendASCII("sample.pak"); | 535 base::FilePath data_default_path = dir_path().AppendASCII("sample.pak"); |
503 | 536 |
504 // Create the pak files. | 537 // Create the pak files. |
505 CreateDataPackWithSingleBitmap(data_default_path, 10, base::StringPiece()); | 538 CreateDataPackWithSingleBitmap(data_default_path, 10, base::StringPiece()); |
506 | 539 |
507 // Load the regular pak files only. | 540 // Load the regular pak files only. |
508 ResourceBundle* resource_bundle = CreateResourceBundleWithEmptyLocalePak(); | 541 ResourceBundle* resource_bundle = CreateResourceBundleWithEmptyLocalePak(); |
509 resource_bundle->AddDataPackFromPath(data_default_path, SCALE_FACTOR_NONE); | 542 resource_bundle->AddDataPackFromPath(data_default_path, SCALE_FACTOR_NONE); |
510 | 543 |
511 gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3); | 544 gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3); |
512 EXPECT_EQ(1u, image_skia->image_reps().size()); | 545 EXPECT_EQ(1u, image_skia->image_reps().size()); |
513 EXPECT_EQ(ui::SCALE_FACTOR_100P, | 546 EXPECT_EQ(ui::SCALE_FACTOR_100P, |
514 image_skia->image_reps()[0].scale_factor()); | 547 image_skia->image_reps()[0].scale_factor()); |
515 } | 548 } |
516 | 549 |
517 } // namespace ui | 550 } // namespace ui |
OLD | NEW |