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

Unified Diff: chrome/browser/themes/browser_theme_pack_unittest.cc

Issue 16977007: Only load theme images for the scale factors that use them (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: combine unit tests Created 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/themes/browser_theme_pack_unittest.cc
diff --git a/chrome/browser/themes/browser_theme_pack_unittest.cc b/chrome/browser/themes/browser_theme_pack_unittest.cc
index 1c8bd788e0117123027e457cbdd2e92e321dc9c2..5516ddcaae93852ca4e02402b579ac66c35d8ddf 100644
--- a/chrome/browser/themes/browser_theme_pack_unittest.cc
+++ b/chrome/browser/themes/browser_theme_pack_unittest.cc
@@ -189,7 +189,7 @@ class BrowserThemePackTest : public ::testing::Test {
}
test_path = test_path.AppendASCII("extensions");
test_path = test_path.AppendASCII("theme_hidpi");
- return base::FilePath(test_path);
+ return test_path;
}
// Verifies the data in star gazing. We do this multiple times for different
@@ -247,17 +247,18 @@ class BrowserThemePackTest : public ::testing::Test {
EXPECT_TRUE(pack->HasCustomImage(IDR_THEME_FRAME_INCOGNITO));
EXPECT_TRUE(pack->HasCustomImage(IDR_THEME_FRAME_INCOGNITO_INACTIVE));
EXPECT_TRUE(pack->HasCustomImage(IDR_THEME_TOOLBAR));
+ // TODO(sschmitz): uncomment next two lines when ntp test data available.
+ // EXPECT_TRUE(pack->HasCustomImage(IDR_THEME_NTP_BACKGROUND));
+ // EXPECT_TRUE(pack->HasCustomImage(IDR_THEME_NTP_ATTRIBUTION));
// The high DPI theme does not define the following images:
EXPECT_FALSE(pack->HasCustomImage(IDR_THEME_TAB_BACKGROUND));
EXPECT_FALSE(pack->HasCustomImage(IDR_THEME_TAB_BACKGROUND));
EXPECT_FALSE(pack->HasCustomImage(IDR_THEME_TAB_BACKGROUND_INCOGNITO));
EXPECT_FALSE(pack->HasCustomImage(IDR_THEME_TAB_BACKGROUND_V));
- EXPECT_FALSE(pack->HasCustomImage(IDR_THEME_NTP_BACKGROUND));
EXPECT_FALSE(pack->HasCustomImage(IDR_THEME_FRAME_OVERLAY));
EXPECT_FALSE(pack->HasCustomImage(IDR_THEME_FRAME_OVERLAY_INACTIVE));
EXPECT_FALSE(pack->HasCustomImage(IDR_THEME_BUTTON_BACKGROUND));
- EXPECT_FALSE(pack->HasCustomImage(IDR_THEME_NTP_ATTRIBUTION));
EXPECT_FALSE(pack->HasCustomImage(IDR_THEME_WINDOW_CONTROL_BACKGROUND));
// Compare some known pixel colors at know locations for a theme
@@ -350,6 +351,140 @@ class BrowserThemePackTest : public ::testing::Test {
rep4.sk_bitmap().unlockPixels();
}
+ void VerifyHiDpiNtpTheme(BrowserThemePack* pack) {
+ // The theme extension for this test uses the same image several times
+ // in the input (manifest.json).
+ // This (raw png) image has size 120x120. It has a black square
+ // starting at (6,6).
+ // For the NTP background this image is specified for scales: 100, 140
+ // and 200 percent.
+ // For the NTP attribution this image is specified only for scale: 150
+ // percent.
+ EXPECT_TRUE(pack->HasCustomImage(IDR_THEME_NTP_BACKGROUND));
+ EXPECT_TRUE(pack->HasCustomImage(IDR_THEME_NTP_ATTRIBUTION));
+
+ // The background image has the same png input for 100%, 140%, 200%.
+ int idr = IDR_THEME_NTP_BACKGROUND;
+ gfx::Image image = pack->GetImageNamed(idr);
+ EXPECT_FALSE(image.IsEmpty());
+ EXPECT_EQ(120, image.Size().width());
+ EXPECT_EQ(120, image.Size().height());
+
+ const gfx::ImageSkia* image_skia = image.ToImageSkia();
+ ASSERT_TRUE(image_skia);
+
+ // 100% was in input.
+ const gfx::ImageSkiaRep& rep100 = image_skia->GetRepresentation(
+ ui::SCALE_FACTOR_100P);
+ ASSERT_FALSE(rep100.is_null());
+ EXPECT_EQ(120, rep100.sk_bitmap().width());
+ EXPECT_EQ(120, rep100.sk_bitmap().height());
+ rep100.sk_bitmap().lockPixels();
+ EXPECT_EQ(SK_ColorWHITE, rep100.sk_bitmap().getColor(5, 5));
+ EXPECT_EQ(SK_ColorBLACK, rep100.sk_bitmap().getColor(6, 6));
+ rep100.sk_bitmap().unlockPixels();
+
+ // 133% not in input, was scaled from 200%.
+ const gfx::ImageSkiaRep& rep133 = image_skia->GetRepresentation(
+ ui::SCALE_FACTOR_133P);
+ ASSERT_FALSE(rep133.is_null());
+ EXPECT_EQ(80, rep133.sk_bitmap().width());
+ EXPECT_EQ(80, rep133.sk_bitmap().height());
+ rep133.sk_bitmap().lockPixels();
+ EXPECT_EQ(SK_ColorWHITE, rep133.sk_bitmap().getColor(3, 3));
+ EXPECT_EQ(SK_ColorBLACK, rep133.sk_bitmap().getColor(4, 4));
+ rep133.sk_bitmap().unlockPixels();
+
+ // 140% was in input.
+ const gfx::ImageSkiaRep& rep140 = image_skia->GetRepresentation(
+ ui::SCALE_FACTOR_140P);
+ ASSERT_FALSE(rep140.is_null());
+ EXPECT_EQ(120, rep140.sk_bitmap().width());
+ EXPECT_EQ(120, rep140.sk_bitmap().height());
+ rep140.sk_bitmap().lockPixels();
+ EXPECT_EQ(SK_ColorWHITE, rep140.sk_bitmap().getColor(5, 5));
+ EXPECT_EQ(SK_ColorBLACK, rep140.sk_bitmap().getColor(6, 6));
+ rep140.sk_bitmap().unlockPixels();
+
+ // 150% not in input, was scaled from 200%.
+ const gfx::ImageSkiaRep& rep150 = image_skia->GetRepresentation(
+ ui::SCALE_FACTOR_150P);
+ ASSERT_FALSE(rep150.is_null());
+ EXPECT_EQ(90, rep150.sk_bitmap().width());
+ EXPECT_EQ(90, rep150.sk_bitmap().height());
+ rep150.sk_bitmap().lockPixels();
+ EXPECT_EQ(SK_ColorWHITE, rep150.sk_bitmap().getColor(4, 4));
+ EXPECT_EQ(SK_ColorBLACK, rep150.sk_bitmap().getColor(5, 5));
+ rep150.sk_bitmap().unlockPixels();
+
+ // 180% not in input, was scaled from 200%.
+ const gfx::ImageSkiaRep& rep180 = image_skia->GetRepresentation(
+ ui::SCALE_FACTOR_180P);
+ ASSERT_FALSE(rep180.is_null());
+ EXPECT_EQ(108, rep180.sk_bitmap().width());
+ EXPECT_EQ(108, rep180.sk_bitmap().height());
+ rep180.sk_bitmap().lockPixels();
+ EXPECT_EQ(SK_ColorWHITE, rep180.sk_bitmap().getColor(4, 4));
+ EXPECT_EQ(SK_ColorBLACK, rep180.sk_bitmap().getColor(5, 5));
+ rep180.sk_bitmap().unlockPixels();
+
+ // 200% was in input.
+ const gfx::ImageSkiaRep& rep200 = image_skia->GetRepresentation(
+ ui::SCALE_FACTOR_200P);
+ ASSERT_FALSE(rep200.is_null());
+ EXPECT_EQ(120, rep200.sk_bitmap().width());
+ EXPECT_EQ(120, rep200.sk_bitmap().height());
+ rep200.sk_bitmap().lockPixels();
+ EXPECT_EQ(SK_ColorWHITE, rep200.sk_bitmap().getColor(5, 5));
+ EXPECT_EQ(SK_ColorBLACK, rep200.sk_bitmap().getColor(6, 6));
+ rep200.sk_bitmap().unlockPixels();
+
+ // Now process the image for NTP attribution.
+ // The attribution image has only an input for 150%.
+
+ idr = IDR_THEME_NTP_ATTRIBUTION;
+ image = pack->GetImageNamed(idr);
+ EXPECT_FALSE(image.IsEmpty());
+ EXPECT_EQ(80, image.Size().width());
+ EXPECT_EQ(80, image.Size().height());
+
+ image_skia = image.ToImageSkia();
+ ASSERT_TRUE(image_skia);
+
+ // 100% was not in input, scaled from 150
+ const gfx::ImageSkiaRep& rpr100 = image_skia->GetRepresentation(
+ ui::SCALE_FACTOR_100P);
+ ASSERT_FALSE(rpr100.is_null());
+ EXPECT_EQ(80, rpr100.sk_bitmap().width());
+ EXPECT_EQ(80, rpr100.sk_bitmap().height());
+ rpr100.sk_bitmap().lockPixels();
+ EXPECT_EQ(SK_ColorWHITE, rpr100.sk_bitmap().getColor(3, 3));
+ EXPECT_EQ(SK_ColorBLACK, rpr100.sk_bitmap().getColor(4, 4));
+ rpr100.sk_bitmap().unlockPixels();
+
+ // 150% was in input
+ const gfx::ImageSkiaRep& rpr150 = image_skia->GetRepresentation(
+ ui::SCALE_FACTOR_150P);
+ ASSERT_FALSE(rpr150.is_null());
+ EXPECT_EQ(120, rpr150.sk_bitmap().width());
+ EXPECT_EQ(120, rpr150.sk_bitmap().height());
+ rpr150.sk_bitmap().lockPixels();
+ EXPECT_EQ(SK_ColorWHITE, rpr150.sk_bitmap().getColor(5, 5));
+ EXPECT_EQ(SK_ColorBLACK, rpr150.sk_bitmap().getColor(6, 6));
+ rpr150.sk_bitmap().unlockPixels();
+
+ // 200% was not in input, scaled from 150
+ const gfx::ImageSkiaRep& rpr200 = image_skia->GetRepresentation(
+ ui::SCALE_FACTOR_200P);
+ ASSERT_FALSE(rpr200.is_null());
+ EXPECT_EQ(160, rpr200.sk_bitmap().width());
+ EXPECT_EQ(160, rpr200.sk_bitmap().height());
+ rpr200.sk_bitmap().lockPixels();
+ EXPECT_EQ(SK_ColorWHITE, rpr200.sk_bitmap().getColor(7, 7));
+ EXPECT_EQ(SK_ColorBLACK, rpr200.sk_bitmap().getColor(8, 8));
+ rpr200.sk_bitmap().unlockPixels();
+ }
+
base::MessageLoop message_loop;
content::TestBrowserThread fake_ui_thread;
content::TestBrowserThread fake_file_thread;
@@ -585,6 +720,10 @@ TEST_F(BrowserThemePackTest, CanBuildAndReadPack) {
TEST_F(BrowserThemePackTest, HiDpiThemeTest) {
std::vector<ui::ScaleFactor> scale_factors;
scale_factors.push_back(ui::SCALE_FACTOR_100P);
+ scale_factors.push_back(ui::SCALE_FACTOR_133P);
+ scale_factors.push_back(ui::SCALE_FACTOR_140P);
+ scale_factors.push_back(ui::SCALE_FACTOR_150P);
+ scale_factors.push_back(ui::SCALE_FACTOR_180P);
scale_factors.push_back(ui::SCALE_FACTOR_200P);
ui::test::ScopedSetSupportedScaleFactors test_scale_factors(scale_factors);
base::ScopedTempDir dir;
@@ -598,6 +737,8 @@ TEST_F(BrowserThemePackTest, HiDpiThemeTest) {
BuildFromUnpackedExtension(hidpi_path, pack);
ASSERT_TRUE(pack->WriteToDisk(file));
VerifyHiDpiTheme(pack.get());
+ // TODO(sschmitz): uncomment the next line when test data available.
+ // VerifyHiDpiNtpTheme(pack.get());
}
// Part 2: Try to read back the data pack that we just wrote to disk.
@@ -606,5 +747,7 @@ TEST_F(BrowserThemePackTest, HiDpiThemeTest) {
BrowserThemePack::BuildFromDataPack(file, "gllekhaobjnhgeag");
ASSERT_TRUE(pack.get());
VerifyHiDpiTheme(pack.get());
+ // TODO(sschmitz): uncomment the next line when test data available.
+ // VerifyHiDpiNtpTheme(pack.get());
}
}
« chrome/browser/themes/browser_theme_pack.cc ('K') | « chrome/browser/themes/browser_theme_pack.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698