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)); |
251 EXPECT_FALSE(pack->GetTint(ThemeProperties::TINT_FRAME, &actual)); | 253 EXPECT_FALSE(pack->GetTint(ThemeProperties::TINT_FRAME, &actual)); |
252 } | 254 } |
253 | 255 |
254 void VerifyHiDpiTheme(BrowserThemePack* pack) { | 256 void VerifyHiDpiTheme(BrowserThemePack* pack) { |
255 // The high DPI theme defines the following images: | 257 // The high DPI theme defines the following images: |
256 EXPECT_TRUE(pack->HasCustomImage(IDR_THEME_FRAME)); | 258 EXPECT_TRUE(pack->HasCustomImage(IDR_THEME_FRAME)); |
257 EXPECT_TRUE(pack->HasCustomImage(IDR_THEME_FRAME_INACTIVE)); | 259 EXPECT_TRUE(pack->HasCustomImage(IDR_THEME_FRAME_INACTIVE)); |
258 EXPECT_TRUE(pack->HasCustomImage(IDR_THEME_FRAME_INCOGNITO)); | 260 EXPECT_TRUE(pack->HasCustomImage(IDR_THEME_FRAME_INCOGNITO)); |
259 EXPECT_TRUE(pack->HasCustomImage(IDR_THEME_FRAME_INCOGNITO_INACTIVE)); | 261 EXPECT_TRUE(pack->HasCustomImage(IDR_THEME_FRAME_INCOGNITO_INACTIVE)); |
260 EXPECT_TRUE(pack->HasCustomImage(IDR_THEME_TOOLBAR)); | 262 EXPECT_TRUE(pack->HasCustomImage(IDR_THEME_TOOLBAR)); |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 LoadColorJSON(color_json); | 428 LoadColorJSON(color_json); |
427 | 429 |
428 std::map<int, SkColor> colors = GetDefaultColorMap(); | 430 std::map<int, SkColor> colors = GetDefaultColorMap(); |
429 colors[ThemeProperties::COLOR_NTP_HEADER] = SkColorSetRGB(120, 120, 120); | 431 colors[ThemeProperties::COLOR_NTP_HEADER] = SkColorSetRGB(120, 120, 120); |
430 colors[ThemeProperties::COLOR_NTP_SECTION] = SkColorSetRGB(190, 190, 190); | 432 colors[ThemeProperties::COLOR_NTP_SECTION] = SkColorSetRGB(190, 190, 190); |
431 VerifyColorMap(colors); | 433 VerifyColorMap(colors); |
432 } | 434 } |
433 | 435 |
434 TEST_F(BrowserThemePackTest, SupportsAlpha) { | 436 TEST_F(BrowserThemePackTest, SupportsAlpha) { |
435 std::string color_json = | 437 std::string color_json = |
436 "{ \"toolbar\": [0, 20, 40, 0.7], " | 438 "{ \"toolbar\": [0, 20, 40, 1], " |
437 " \"tab_text\": [60, 80, 100, 1], " | 439 " \"tab_text\": [60, 80, 100, 1], " |
438 " \"tab_background_text\": [120, 140, 160, 0.0], " | 440 " \"tab_background_text\": [120, 140, 160, 0.0], " |
439 " \"bookmark_text\": [180, 200, 220, 1.0], " | 441 " \"bookmark_text\": [180, 200, 220, 1.0], " |
440 " \"ntp_background\": [20, 50, 140, 0.2], " | |
441 " \"ntp_text\": [240, 255, 0, 0.5] }"; | 442 " \"ntp_text\": [240, 255, 0, 0.5] }"; |
442 LoadColorJSON(color_json); | 443 LoadColorJSON(color_json); |
443 | 444 |
444 std::map<int, SkColor> colors = GetDefaultColorMap(); | 445 std::map<int, SkColor> colors = GetDefaultColorMap(); |
445 // Verify that valid alpha values are parsed correctly. | 446 // 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); |
446 colors[ThemeProperties::COLOR_TAB_TEXT] = SkColorSetARGB(255, 60, 80, 100); | 449 colors[ThemeProperties::COLOR_TAB_TEXT] = SkColorSetARGB(255, 60, 80, 100); |
447 colors[ThemeProperties::COLOR_BACKGROUND_TAB_TEXT] = | 450 colors[ThemeProperties::COLOR_BACKGROUND_TAB_TEXT] = |
448 SkColorSetARGB(0, 120, 140, 160); | 451 SkColorSetARGB(0, 120, 140, 160); |
449 colors[ThemeProperties::COLOR_BOOKMARK_TEXT] = | 452 colors[ThemeProperties::COLOR_BOOKMARK_TEXT] = |
450 SkColorSetARGB(255, 180, 200, 220); | 453 SkColorSetARGB(255, 180, 200, 220); |
451 colors[ThemeProperties::COLOR_NTP_TEXT] = SkColorSetARGB(128, 240, 255, 0); | 454 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 |