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

Side by Side Diff: chrome/browser/themes/theme_service_unittest.cc

Issue 1785613004: Dynamically compute tab/frame separator color. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments Created 4 years, 9 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 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 "chrome/browser/themes/theme_service.h" 5 #include "chrome/browser/themes/theme_service.h"
6 6
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 11 matching lines...) Expand all
22 #include "chrome/test/base/testing_profile_manager.h" 22 #include "chrome/test/base/testing_profile_manager.h"
23 #include "content/public/browser/notification_observer.h" 23 #include "content/public/browser/notification_observer.h"
24 #include "content/public/browser/notification_registrar.h" 24 #include "content/public/browser/notification_registrar.h"
25 #include "content/public/test/test_utils.h" 25 #include "content/public/test/test_utils.h"
26 #include "extensions/browser/extension_registry.h" 26 #include "extensions/browser/extension_registry.h"
27 #include "extensions/browser/test_extension_registry_observer.h" 27 #include "extensions/browser/test_extension_registry_observer.h"
28 #include "extensions/browser/uninstall_reason.h" 28 #include "extensions/browser/uninstall_reason.h"
29 #include "extensions/common/extension.h" 29 #include "extensions/common/extension.h"
30 #include "testing/gtest/include/gtest/gtest.h" 30 #include "testing/gtest/include/gtest/gtest.h"
31 #include "ui/base/material_design/material_design_controller.h" 31 #include "ui/base/material_design/material_design_controller.h"
32 #include "ui/base/test/material_design_controller_test_api.h"
32 33
33 #if defined(ENABLE_SUPERVISED_USERS) 34 #if defined(ENABLE_SUPERVISED_USERS)
34 #include "chrome/browser/supervised_user/supervised_user_service.h" 35 #include "chrome/browser/supervised_user/supervised_user_service.h"
35 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" 36 #include "chrome/browser/supervised_user/supervised_user_service_factory.h"
36 #endif 37 #endif
37 38
38 using extensions::ExtensionRegistry; 39 using extensions::ExtensionRegistry;
39 40
40 namespace theme_service_internal { 41 namespace theme_service_internal {
41 42
42 class ThemeServiceTest : public extensions::ExtensionServiceTestBase { 43 class ThemeServiceTest : public extensions::ExtensionServiceTestBase {
43 public: 44 public:
44 ThemeServiceTest() : is_supervised_(false), 45 ThemeServiceTest() : is_supervised_(false),
45 registry_(NULL) {} 46 registry_(NULL) {}
46 ~ThemeServiceTest() override {} 47 ~ThemeServiceTest() override {}
47 48
49 void SetUp() override {
50 extensions::ExtensionServiceTestBase::SetUp();
51 extensions::ExtensionServiceTestBase::ExtensionServiceInitParams params =
52 CreateDefaultInitParams();
53 params.profile_is_supervised = is_supervised_;
54 InitializeExtensionService(params);
55 service_->Init();
56 registry_ = ExtensionRegistry::Get(profile_.get());
57 ASSERT_TRUE(registry_);
58 }
59
48 // Moves a minimal theme to |temp_dir_path| and unpacks it from that 60 // Moves a minimal theme to |temp_dir_path| and unpacks it from that
49 // directory. 61 // directory.
50 std::string LoadUnpackedThemeAt(const base::FilePath& temp_dir) { 62 std::string LoadUnpackedThemeAt(const base::FilePath& temp_dir) {
51 base::FilePath dst_manifest_path = temp_dir.AppendASCII("manifest.json"); 63 base::FilePath dst_manifest_path = temp_dir.AppendASCII("manifest.json");
52 base::FilePath test_data_dir; 64 base::FilePath test_data_dir;
53 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)); 65 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir));
54 base::FilePath src_manifest_path = 66 base::FilePath src_manifest_path =
55 test_data_dir.AppendASCII("extensions/theme_minimal/manifest.json"); 67 test_data_dir.AppendASCII("extensions/theme_minimal/manifest.json");
56 EXPECT_TRUE(base::CopyFile(src_manifest_path, dst_manifest_path)); 68 EXPECT_TRUE(base::CopyFile(src_manifest_path, dst_manifest_path));
57 69
(...skipping 27 matching lines...) Expand all
85 extensions::NOTIFICATION_EXTENSION_UPDATE_DISABLED, 97 extensions::NOTIFICATION_EXTENSION_UPDATE_DISABLED,
86 content::Source<Profile>(profile_.get())); 98 content::Source<Profile>(profile_.get()));
87 installer->Load(path); 99 installer->Load(path);
88 observer.Wait(); 100 observer.Wait();
89 } 101 }
90 102
91 // Let the ThemeService finish creating the theme pack. 103 // Let the ThemeService finish creating the theme pack.
92 base::MessageLoop::current()->RunUntilIdle(); 104 base::MessageLoop::current()->RunUntilIdle();
93 } 105 }
94 106
95 void SetUp() override {
96 extensions::ExtensionServiceTestBase::SetUp();
97 extensions::ExtensionServiceTestBase::ExtensionServiceInitParams params =
98 CreateDefaultInitParams();
99 params.profile_is_supervised = is_supervised_;
100 InitializeExtensionService(params);
101 service_->Init();
102 registry_ = ExtensionRegistry::Get(profile_.get());
103 ASSERT_TRUE(registry_);
104 }
105
106 const CustomThemeSupplier* get_theme_supplier(ThemeService* theme_service) { 107 const CustomThemeSupplier* get_theme_supplier(ThemeService* theme_service) {
107 return theme_service->get_theme_supplier(); 108 return theme_service->get_theme_supplier();
108 } 109 }
109 110
111 // Returns the separator color as the opaque result of blending it atop the
112 // frame color (which is the color we use when calculating the contrast of the
113 // separator with the tab and frame colors).
114 static SkColor GetSeparatorColor(SkColor tab_color, SkColor frame_color) {
115 const SkColor separator_color =
116 ThemeService::GetSeparatorColor(tab_color, frame_color);
117 return color_utils::AlphaBlend(SkColorSetA(separator_color, SK_AlphaOPAQUE),
118 frame_color, SkColorGetA(separator_color));
119 }
120
110 protected: 121 protected:
111 bool is_supervised_; 122 bool is_supervised_;
112 ExtensionRegistry* registry_; 123 ExtensionRegistry* registry_;
113 }; 124 };
114 125
115 // Installs then uninstalls a theme and makes sure that the ThemeService 126 // Installs then uninstalls a theme and makes sure that the ThemeService
116 // reverts to the default theme after the uninstall. 127 // reverts to the default theme after the uninstall.
117 TEST_F(ThemeServiceTest, ThemeInstallUninstall) { 128 TEST_F(ThemeServiceTest, ThemeInstallUninstall) {
118 ThemeService* theme_service = 129 ThemeService* theme_service =
119 ThemeServiceFactory::GetForProfile(profile_.get()); 130 ThemeServiceFactory::GetForProfile(profile_.get());
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 ThemeServiceFactory::GetForProfile(profile_.get()); 380 ThemeServiceFactory::GetForProfile(profile_.get());
370 theme_service->UseDefaultTheme(); 381 theme_service->UseDefaultTheme();
371 EXPECT_TRUE(theme_service->UsingDefaultTheme()); 382 EXPECT_TRUE(theme_service->UsingDefaultTheme());
372 EXPECT_TRUE(get_theme_supplier(theme_service)); 383 EXPECT_TRUE(get_theme_supplier(theme_service));
373 EXPECT_EQ(get_theme_supplier(theme_service)->get_theme_type(), 384 EXPECT_EQ(get_theme_supplier(theme_service)->get_theme_type(),
374 CustomThemeSupplier::SUPERVISED_USER_THEME); 385 CustomThemeSupplier::SUPERVISED_USER_THEME);
375 } 386 }
376 #endif // defined(OS_LINUX) && !defined(OS_CHROMEOS) 387 #endif // defined(OS_LINUX) && !defined(OS_CHROMEOS)
377 #endif // defined(ENABLE_SUPERVISED_USERS) 388 #endif // defined(ENABLE_SUPERVISED_USERS)
378 389
390 // Simple class to run tests in material design mode.
391 class ThemeServiceMaterialDesignTest : public ThemeServiceTest {
392 public:
393 void SetUp() override {
394 ThemeServiceTest::SetUp();
395 ui::test::MaterialDesignControllerTestAPI::SetMode(
396 ui::MaterialDesignController::MATERIAL_NORMAL);
397 }
398
399 void TearDown() override {
400 ThemeServiceTest::TearDown();
401 ui::test::MaterialDesignControllerTestAPI::UninitializeMode();
402 }
403 };
404
405 // Check that the function which computes the separator color behaves as
406 // expected for a variety of inputs. We run in material design mode so we can
407 // use the material normal and incognito color combinations, which differ from
408 // each other in ways that are interesting to test.
409 TEST_F(ThemeServiceMaterialDesignTest, SeparatorColor) {
410 // For the default theme, the separator should darken the frame.
411 SkColor tab_color =
412 ThemeProperties::GetDefaultColor(ThemeProperties::COLOR_TOOLBAR, false);
413 SkColor frame_color =
414 ThemeProperties::GetDefaultColor(ThemeProperties::COLOR_FRAME, false);
415 SkColor separator_color = GetSeparatorColor(tab_color, frame_color);
Evan Stade 2016/03/15 19:05:06 can you add a check to verify this matches what yo
Peter Kasting 2016/03/16 03:12:59 Sure.
416 double frame_luminance = color_utils::GetRelativeLuminance(frame_color);
417 EXPECT_LT(color_utils::GetRelativeLuminance(separator_color),
418 frame_luminance);
419
420 // If we reverse the colors, the separator should lighten the frame.
421 separator_color = GetSeparatorColor(frame_color, tab_color);
422 EXPECT_GT(color_utils::GetRelativeLuminance(separator_color),
423 frame_luminance);
424
425 // When the frame color is black, the separator should lighten the frame, but
426 // it should still be darker than the tab color.
427 separator_color = GetSeparatorColor(tab_color, SK_ColorBLACK);
428 double separator_luminance =
429 color_utils::GetRelativeLuminance(separator_color);
430 double tab_luminance = color_utils::GetRelativeLuminance(tab_color);
431 EXPECT_GT(separator_luminance, 0);
432 EXPECT_LT(separator_luminance, tab_luminance);
433
434 // When the frame color is white, the separator should darken the frame; it
435 // should also be lighter than the tab color since otherwise the contrast with
436 // the tab would be too minimal.
437 separator_color = GetSeparatorColor(tab_color, SK_ColorWHITE);
438 separator_luminance = color_utils::GetRelativeLuminance(separator_color);
439 EXPECT_LT(separator_luminance, 1);
440 EXPECT_LT(separator_luminance, tab_luminance);
441
442 // Likewise for the default incognito theme, the separator should darken the
443 // frame.
444 tab_color =
445 ThemeProperties::GetDefaultColor(ThemeProperties::COLOR_TOOLBAR, true);
446 frame_color =
447 ThemeProperties::GetDefaultColor(ThemeProperties::COLOR_FRAME, true);
448 separator_color = GetSeparatorColor(tab_color, frame_color);
449 frame_luminance = color_utils::GetRelativeLuminance(frame_color);
450 EXPECT_LT(color_utils::GetRelativeLuminance(separator_color),
451 frame_luminance);
452
453 // And if we reverse the colors, the separator should lighten the frame.
454 separator_color = GetSeparatorColor(frame_color, tab_color);
455 EXPECT_GT(color_utils::GetRelativeLuminance(separator_color),
456 frame_luminance);
457
458 // When the frame color is black, the separator should lighten the frame; it
459 // should also be lighter than the tab color since otherwise the contrast with
460 // the tab would be too minimal.
461 separator_color = GetSeparatorColor(tab_color, SK_ColorBLACK);
462 separator_luminance = color_utils::GetRelativeLuminance(separator_color);
463 tab_luminance = color_utils::GetRelativeLuminance(tab_color);
464 EXPECT_GT(separator_luminance, 0);
465 EXPECT_GT(separator_luminance, tab_luminance);
466
467 // When the frame color is white, the separator should darken the frame, but
468 // it should still be lighter than the tab color.
469 separator_color = GetSeparatorColor(tab_color, SK_ColorWHITE);
470 separator_luminance = color_utils::GetRelativeLuminance(separator_color);
471 EXPECT_LT(separator_luminance, 1);
472 EXPECT_GT(separator_luminance, tab_luminance);
473 }
474
379 }; // namespace theme_service_internal 475 }; // namespace theme_service_internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698