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

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

Issue 659883002: Enable hidpi on Linux, refactor a bit on Windows to share Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: constants Created 6 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
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/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
11 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/ref_counted_memory.h" 13 #include "base/memory/ref_counted_memory.h"
14 #include "base/path_service.h" 14 #include "base/path_service.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "testing/gmock/include/gmock/gmock.h" 16 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "third_party/skia/include/core/SkBitmap.h" 18 #include "third_party/skia/include/core/SkBitmap.h"
19 #include "ui/base/layout.h" 19 #include "ui/base/layout.h"
20 #include "ui/base/resource/data_pack.h" 20 #include "ui/base/resource/data_pack.h"
21 #include "ui/gfx/codec/png_codec.h" 21 #include "ui/gfx/codec/png_codec.h"
22 #include "ui/gfx/dpi.h"
22 #include "ui/gfx/image/image_skia.h" 23 #include "ui/gfx/image/image_skia.h"
23 #include "ui/resources/grit/ui_resources.h" 24 #include "ui/resources/grit/ui_resources.h"
24 25
25 #if defined(OS_WIN)
26 #include "ui/gfx/win/dpi.h"
27 #endif
28
29 using ::testing::_; 26 using ::testing::_;
30 using ::testing::Between; 27 using ::testing::Between;
31 using ::testing::Property; 28 using ::testing::Property;
32 using ::testing::Return; 29 using ::testing::Return;
33 using ::testing::ReturnArg; 30 using ::testing::ReturnArg;
34 31
35 namespace ui { 32 namespace ui {
36 33
37 extern const char kSamplePakContents[]; 34 extern const char kSamplePakContents[];
38 extern const size_t kSamplePakSize; 35 extern const size_t kSamplePakSize;
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 // for both scale factor requests. 462 // for both scale factor requests.
466 EXPECT_EQ("this is id 6", resource_bundle->GetRawDataResourceForScale(6, 463 EXPECT_EQ("this is id 6", resource_bundle->GetRawDataResourceForScale(6,
467 SCALE_FACTOR_100P)); 464 SCALE_FACTOR_100P));
468 EXPECT_EQ("this is id 6", resource_bundle->GetRawDataResourceForScale(6, 465 EXPECT_EQ("this is id 6", resource_bundle->GetRawDataResourceForScale(6,
469 SCALE_FACTOR_200P)); 466 SCALE_FACTOR_200P));
470 } 467 }
471 468
472 // Test requesting image reps at various scale factors from the image returned 469 // Test requesting image reps at various scale factors from the image returned
473 // via ResourceBundle::GetImageNamed(). 470 // via ResourceBundle::GetImageNamed().
474 TEST_F(ResourceBundleImageTest, GetImageNamed) { 471 TEST_F(ResourceBundleImageTest, GetImageNamed) {
475 #if defined(OS_WIN) 472 #if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS))
476 gfx::ForceHighDPISupportForTesting(2.0); 473 gfx::ForceHighDPISupportForTesting(2.0);
477 #endif 474 #endif
478 std::vector<ScaleFactor> supported_factors; 475 std::vector<ScaleFactor> supported_factors;
479 supported_factors.push_back(SCALE_FACTOR_100P); 476 supported_factors.push_back(SCALE_FACTOR_100P);
480 supported_factors.push_back(SCALE_FACTOR_200P); 477 supported_factors.push_back(SCALE_FACTOR_200P);
481 test::ScopedSetSupportedScaleFactors scoped_supported(supported_factors); 478 test::ScopedSetSupportedScaleFactors scoped_supported(supported_factors);
482 base::FilePath data_1x_path = dir_path().AppendASCII("sample_1x.pak"); 479 base::FilePath data_1x_path = dir_path().AppendASCII("sample_1x.pak");
483 base::FilePath data_2x_path = dir_path().AppendASCII("sample_2x.pak"); 480 base::FilePath data_2x_path = dir_path().AppendASCII("sample_2x.pak");
484 481
485 // Create the pak files. 482 // Create the pak files.
486 CreateDataPackWithSingleBitmap(data_1x_path, 10, base::StringPiece()); 483 CreateDataPackWithSingleBitmap(data_1x_path, 10, base::StringPiece());
487 CreateDataPackWithSingleBitmap(data_2x_path, 20, base::StringPiece()); 484 CreateDataPackWithSingleBitmap(data_2x_path, 20, base::StringPiece());
488 485
489 // Load the regular and 2x pak files. 486 // Load the regular and 2x pak files.
490 ResourceBundle* resource_bundle = CreateResourceBundleWithEmptyLocalePak(); 487 ResourceBundle* resource_bundle = CreateResourceBundleWithEmptyLocalePak();
491 resource_bundle->AddDataPackFromPath(data_1x_path, SCALE_FACTOR_100P); 488 resource_bundle->AddDataPackFromPath(data_1x_path, SCALE_FACTOR_100P);
492 resource_bundle->AddDataPackFromPath(data_2x_path, SCALE_FACTOR_200P); 489 resource_bundle->AddDataPackFromPath(data_2x_path, SCALE_FACTOR_200P);
493 490
494 EXPECT_EQ(SCALE_FACTOR_200P, resource_bundle->GetMaxScaleFactor()); 491 EXPECT_EQ(SCALE_FACTOR_200P, resource_bundle->GetMaxScaleFactor());
495 492
496 gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3); 493 gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3);
497 494
498 #if defined(OS_CHROMEOS) || defined(OS_WIN) 495 #if defined(OS_CHROMEOS) || defined(OS_WIN) || defined(OS_LINUX)
499 // ChromeOS/Windows load highest scale factor first. 496 // ChromeOS/Windows load highest scale factor first.
500 EXPECT_EQ(ui::SCALE_FACTOR_200P, 497 EXPECT_EQ(ui::SCALE_FACTOR_200P,
501 GetSupportedScaleFactor(image_skia->image_reps()[0].scale())); 498 GetSupportedScaleFactor(image_skia->image_reps()[0].scale()));
502 #else 499 #else
503 EXPECT_EQ(ui::SCALE_FACTOR_100P, 500 EXPECT_EQ(ui::SCALE_FACTOR_100P,
504 GetSupportedScaleFactor(image_skia->image_reps()[0].scale())); 501 GetSupportedScaleFactor(image_skia->image_reps()[0].scale()));
505 #endif 502 #endif
506 503
507 // Resource ID 3 exists in both 1x and 2x paks. Image reps should be 504 // Resource ID 3 exists in both 1x and 2x paks. Image reps should be
508 // available for both scale factors in |image_skia|. 505 // available for both scale factors in |image_skia|.
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 resource_bundle->AddDataPackFromPath(data_default_path, SCALE_FACTOR_NONE); 618 resource_bundle->AddDataPackFromPath(data_default_path, SCALE_FACTOR_NONE);
622 619
623 gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3); 620 gfx::ImageSkia* image_skia = resource_bundle->GetImageSkiaNamed(3);
624 EXPECT_EQ(1u, image_skia->image_reps().size()); 621 EXPECT_EQ(1u, image_skia->image_reps().size());
625 EXPECT_TRUE(image_skia->image_reps()[0].unscaled()); 622 EXPECT_TRUE(image_skia->image_reps()[0].unscaled());
626 EXPECT_EQ(ui::SCALE_FACTOR_100P, 623 EXPECT_EQ(ui::SCALE_FACTOR_100P,
627 GetSupportedScaleFactor(image_skia->image_reps()[0].scale())); 624 GetSupportedScaleFactor(image_skia->image_reps()[0].scale()));
628 } 625 }
629 626
630 } // namespace ui 627 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698