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 "chrome/browser/themes/browser_theme_pack.h" | 5 #include "chrome/browser/themes/browser_theme_pack.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/json/json_file_value_serializer.h" | 10 #include "base/json/json_file_value_serializer.h" |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 // they're included in the theme pack, they were autogenerated and | 241 // they're included in the theme pack, they were autogenerated and |
242 // therefore shouldn't show up when calling HasCustomImage(). | 242 // therefore shouldn't show up when calling HasCustomImage(). |
243 EXPECT_FALSE(pack->HasCustomImage(IDR_THEME_FRAME_INACTIVE)); | 243 EXPECT_FALSE(pack->HasCustomImage(IDR_THEME_FRAME_INACTIVE)); |
244 EXPECT_FALSE(pack->HasCustomImage(IDR_THEME_FRAME_INCOGNITO)); | 244 EXPECT_FALSE(pack->HasCustomImage(IDR_THEME_FRAME_INCOGNITO)); |
245 EXPECT_FALSE(pack->HasCustomImage(IDR_THEME_FRAME_INCOGNITO_INACTIVE)); | 245 EXPECT_FALSE(pack->HasCustomImage(IDR_THEME_FRAME_INCOGNITO_INACTIVE)); |
246 #if !defined(OS_MACOSX) | 246 #if !defined(OS_MACOSX) |
247 EXPECT_FALSE(pack->HasCustomImage(IDR_THEME_TAB_BACKGROUND_INCOGNITO)); | 247 EXPECT_FALSE(pack->HasCustomImage(IDR_THEME_TAB_BACKGROUND_INCOGNITO)); |
248 #endif | 248 #endif |
249 | 249 |
250 // Make sure we don't have phantom data. | 250 // Make sure we don't have phantom data. |
251 EXPECT_FALSE(pack->GetColor(ThemeProperties::COLOR_CONTROL_BACKGROUND, | |
252 &color)); | |
253 EXPECT_FALSE(pack->GetTint(ThemeProperties::TINT_FRAME, &actual)); | 251 EXPECT_FALSE(pack->GetTint(ThemeProperties::TINT_FRAME, &actual)); |
254 } | 252 } |
255 | 253 |
256 void VerifyHiDpiTheme(BrowserThemePack* pack) { | 254 void VerifyHiDpiTheme(BrowserThemePack* pack) { |
257 // The high DPI theme defines the following images: | 255 // The high DPI theme defines the following images: |
258 EXPECT_TRUE(pack->HasCustomImage(IDR_THEME_FRAME)); | 256 EXPECT_TRUE(pack->HasCustomImage(IDR_THEME_FRAME)); |
259 EXPECT_TRUE(pack->HasCustomImage(IDR_THEME_FRAME_INACTIVE)); | 257 EXPECT_TRUE(pack->HasCustomImage(IDR_THEME_FRAME_INACTIVE)); |
260 EXPECT_TRUE(pack->HasCustomImage(IDR_THEME_FRAME_INCOGNITO)); | 258 EXPECT_TRUE(pack->HasCustomImage(IDR_THEME_FRAME_INCOGNITO)); |
261 EXPECT_TRUE(pack->HasCustomImage(IDR_THEME_FRAME_INCOGNITO_INACTIVE)); | 259 EXPECT_TRUE(pack->HasCustomImage(IDR_THEME_FRAME_INCOGNITO_INACTIVE)); |
262 EXPECT_TRUE(pack->HasCustomImage(IDR_THEME_TOOLBAR)); | 260 EXPECT_TRUE(pack->HasCustomImage(IDR_THEME_TOOLBAR)); |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 LoadColorJSON(color_json); | 426 LoadColorJSON(color_json); |
429 | 427 |
430 std::map<int, SkColor> colors = GetDefaultColorMap(); | 428 std::map<int, SkColor> colors = GetDefaultColorMap(); |
431 colors[ThemeProperties::COLOR_NTP_HEADER] = SkColorSetRGB(120, 120, 120); | 429 colors[ThemeProperties::COLOR_NTP_HEADER] = SkColorSetRGB(120, 120, 120); |
432 colors[ThemeProperties::COLOR_NTP_SECTION] = SkColorSetRGB(190, 190, 190); | 430 colors[ThemeProperties::COLOR_NTP_SECTION] = SkColorSetRGB(190, 190, 190); |
433 VerifyColorMap(colors); | 431 VerifyColorMap(colors); |
434 } | 432 } |
435 | 433 |
436 TEST_F(BrowserThemePackTest, SupportsAlpha) { | 434 TEST_F(BrowserThemePackTest, SupportsAlpha) { |
437 std::string color_json = | 435 std::string color_json = |
438 "{ \"toolbar\": [0, 20, 40, 1], " | 436 "{ \"toolbar\": [0, 20, 40, 0.7], " |
439 " \"tab_text\": [60, 80, 100, 1], " | 437 " \"tab_text\": [60, 80, 100, 1], " |
440 " \"tab_background_text\": [120, 140, 160, 0.0], " | 438 " \"tab_background_text\": [120, 140, 160, 0.0], " |
441 " \"bookmark_text\": [180, 200, 220, 1.0], " | 439 " \"bookmark_text\": [180, 200, 220, 1.0], " |
| 440 " \"ntp_background\": [20, 50, 140, 0.2], " |
442 " \"ntp_text\": [240, 255, 0, 0.5] }"; | 441 " \"ntp_text\": [240, 255, 0, 0.5] }"; |
443 LoadColorJSON(color_json); | 442 LoadColorJSON(color_json); |
444 | 443 |
445 std::map<int, SkColor> colors = GetDefaultColorMap(); | 444 std::map<int, SkColor> colors = GetDefaultColorMap(); |
446 // Verify that valid alpha values are parsed correctly. | 445 // Verify that valid alpha values are parsed correctly. |
447 // The toolbar color's alpha value is intentionally ignored by theme provider. | |
448 colors[ThemeProperties::COLOR_TOOLBAR] = SkColorSetARGB(255, 0, 20, 40); | |
449 colors[ThemeProperties::COLOR_TAB_TEXT] = SkColorSetARGB(255, 60, 80, 100); | 446 colors[ThemeProperties::COLOR_TAB_TEXT] = SkColorSetARGB(255, 60, 80, 100); |
450 colors[ThemeProperties::COLOR_BACKGROUND_TAB_TEXT] = | 447 colors[ThemeProperties::COLOR_BACKGROUND_TAB_TEXT] = |
451 SkColorSetARGB(0, 120, 140, 160); | 448 SkColorSetARGB(0, 120, 140, 160); |
452 colors[ThemeProperties::COLOR_BOOKMARK_TEXT] = | 449 colors[ThemeProperties::COLOR_BOOKMARK_TEXT] = |
453 SkColorSetARGB(255, 180, 200, 220); | 450 SkColorSetARGB(255, 180, 200, 220); |
454 colors[ThemeProperties::COLOR_NTP_TEXT] = SkColorSetARGB(128, 240, 255, 0); | 451 colors[ThemeProperties::COLOR_NTP_TEXT] = SkColorSetARGB(128, 240, 255, 0); |
| 452 // The theme machinery forces these colors to be opaque. |
| 453 colors[ThemeProperties::COLOR_NTP_BACKGROUND] = SkColorSetRGB(20, 50, 140); |
| 454 colors[ThemeProperties::COLOR_TOOLBAR] = SkColorSetRGB(0, 20, 40); |
455 VerifyColorMap(colors); | 455 VerifyColorMap(colors); |
456 } | 456 } |
457 | 457 |
458 TEST_F(BrowserThemePackTest, OutOfRangeColors) { | 458 TEST_F(BrowserThemePackTest, OutOfRangeColors) { |
459 // Ensure colors with out-of-range values are simply ignored. | 459 // Ensure colors with out-of-range values are simply ignored. |
460 std::string color_json = "{ \"toolbar\": [0, 20, 40, -1], " | 460 std::string color_json = "{ \"toolbar\": [0, 20, 40, -1], " |
461 " \"tab_text\": [60, 80, 100, 2], " | 461 " \"tab_text\": [60, 80, 100, 2], " |
462 " \"tab_background_text\": [120, 140, 160, 47.6], " | 462 " \"tab_background_text\": [120, 140, 160, 47.6], " |
463 " \"bookmark_text\": [256, 0, 0], " | 463 " \"bookmark_text\": [256, 0, 0], " |
464 " \"ntp_text\": [0, -100, 100] }"; | 464 " \"ntp_text\": [0, -100, 100] }"; |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 } | 652 } |
653 | 653 |
654 // Part 2: Try to read back the data pack that we just wrote to disk. | 654 // Part 2: Try to read back the data pack that we just wrote to disk. |
655 { | 655 { |
656 scoped_refptr<BrowserThemePack> pack = | 656 scoped_refptr<BrowserThemePack> pack = |
657 BrowserThemePack::BuildFromDataPack(file, "gllekhaobjnhgeag"); | 657 BrowserThemePack::BuildFromDataPack(file, "gllekhaobjnhgeag"); |
658 ASSERT_TRUE(pack.get()); | 658 ASSERT_TRUE(pack.get()); |
659 VerifyHiDpiTheme(pack.get()); | 659 VerifyHiDpiTheme(pack.get()); |
660 } | 660 } |
661 } | 661 } |
OLD | NEW |