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

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

Issue 1893733002: Add more tracing to a test to make it easier to track down failures. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2661
Patch Set: Created 4 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/command_line.h" 7 #include "base/command_line.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 // Check that the function which computes the separator color behaves as 415 // Check that the function which computes the separator color behaves as
416 // expected for a variety of inputs. We run in material design mode so we can 416 // expected for a variety of inputs. We run in material design mode so we can
417 // use the material normal and incognito color combinations, which differ from 417 // use the material normal and incognito color combinations, which differ from
418 // each other in ways that are interesting to test. 418 // each other in ways that are interesting to test.
419 TEST_F(ThemeServiceMaterialDesignTest, SeparatorColor) { 419 TEST_F(ThemeServiceMaterialDesignTest, SeparatorColor) {
420 // Ensure Windows 10 machines use the built-in default colors rather than the 420 // Ensure Windows 10 machines use the built-in default colors rather than the
421 // current system native colors. 421 // current system native colors.
422 base::CommandLine::ForCurrentProcess()->AppendSwitch( 422 base::CommandLine::ForCurrentProcess()->AppendSwitch(
423 switches::kDisableDwmComposition); 423 switches::kDisableDwmComposition);
424 424
425 // Check that the TOOLBAR_TOP_SEPARATOR color is the same whether we ask the 425 {
426 // theme provider or compute it manually. 426 const ui::ThemeProvider& theme_provider =
427 const ui::ThemeProvider& theme_provider = 427 ThemeService::GetThemeProviderForProfile(profile_.get());
428 ThemeService::GetThemeProviderForProfile(profile_.get()); 428 const SkColor frame_color =
429 SkColor frame_color = theme_provider.GetColor(ThemeProperties::COLOR_FRAME); 429 theme_provider.GetColor(ThemeProperties::COLOR_FRAME);
430 SkColor theme_color = AlphaBlend( 430 const SkColor tab_color =
431 theme_provider.GetColor(ThemeProperties::COLOR_TOOLBAR_TOP_SEPARATOR), 431 theme_provider.GetColor(ThemeProperties::COLOR_TOOLBAR);
432 frame_color); 432 SCOPED_TRACE(base::StringPrintf("Tab color: 0x%08X, frame color: 0x%08X",
433 SkColor tab_color = theme_provider.GetColor(ThemeProperties::COLOR_TOOLBAR); 433 tab_color, frame_color));
434 SkColor separator_color = GetSeparatorColor(tab_color, frame_color);
435 EXPECT_EQ(theme_color, separator_color);
436 434
437 // For the default theme, the separator should darken the frame. 435 // Check that the TOOLBAR_TOP_SEPARATOR color is the same whether we ask the
438 double frame_luminance = color_utils::GetRelativeLuminance(frame_color); 436 // theme provider or compute it manually.
439 EXPECT_LT(color_utils::GetRelativeLuminance(separator_color), 437 const SkColor theme_color = AlphaBlend(
440 frame_luminance); 438 theme_provider.GetColor(ThemeProperties::COLOR_TOOLBAR_TOP_SEPARATOR),
439 frame_color);
440 SkColor separator_color = GetSeparatorColor(tab_color, frame_color);
441 EXPECT_EQ(theme_color, separator_color);
441 442
442 // If we reverse the colors, the separator should darken the "frame" (which 443 // For the default theme, the separator should darken the frame.
443 // in this case is actually the tab color), since otherwise the contrast with 444 double frame_luminance = color_utils::GetRelativeLuminance(frame_color);
444 // the "frame" would be too minimal. It should also be darker than the "tab" 445 EXPECT_LT(color_utils::GetRelativeLuminance(separator_color),
445 // (frame color) since otherwise the contrast the contrast with the "tab 446 frame_luminance);
446 // color" would be too minimal.
447 separator_color = GetSeparatorColor(frame_color, tab_color);
448 double tab_luminance = color_utils::GetRelativeLuminance(tab_color);
449 double separator_luminance =
450 color_utils::GetRelativeLuminance(separator_color);
451 EXPECT_LT(separator_luminance, tab_luminance);
452 EXPECT_LT(separator_luminance, frame_luminance);
453 447
454 // When the frame color is black, the separator should lighten the frame, but 448 // If we reverse the colors, the separator should darken the "frame" (which
455 // it should still be darker than the tab color. 449 // in this case is actually the tab color), since otherwise the contrast
456 separator_color = GetSeparatorColor(tab_color, SK_ColorBLACK); 450 // with the "frame" would be too minimal. It should also be darker than the
457 separator_luminance = color_utils::GetRelativeLuminance(separator_color); 451 // "tab" (frame color) since otherwise the contrast the contrast with the
458 EXPECT_GT(separator_luminance, 0); 452 // "tab color" would be too minimal.
459 EXPECT_LT(separator_luminance, tab_luminance); 453 separator_color = GetSeparatorColor(frame_color, tab_color);
454 double tab_luminance = color_utils::GetRelativeLuminance(tab_color);
455 double separator_luminance =
456 color_utils::GetRelativeLuminance(separator_color);
457 EXPECT_LT(separator_luminance, tab_luminance);
458 EXPECT_LT(separator_luminance, frame_luminance);
460 459
461 // When the frame color is white, the separator should darken the frame; it 460 // When the frame color is black, the separator should lighten the frame,
462 // should also be lighter than the tab color since otherwise the contrast with 461 // but it should still be darker than the tab color.
463 // the tab would be too minimal. 462 separator_color = GetSeparatorColor(tab_color, SK_ColorBLACK);
464 separator_color = GetSeparatorColor(tab_color, SK_ColorWHITE); 463 separator_luminance = color_utils::GetRelativeLuminance(separator_color);
465 separator_luminance = color_utils::GetRelativeLuminance(separator_color); 464 EXPECT_GT(separator_luminance, 0);
466 EXPECT_LT(separator_luminance, 1); 465 EXPECT_LT(separator_luminance, tab_luminance);
467 EXPECT_LT(separator_luminance, tab_luminance); 466
467 // When the frame color is white, the separator should darken the frame; it
468 // should also be lighter than the tab color since otherwise the contrast
469 // with the tab would be too minimal.
470 separator_color = GetSeparatorColor(tab_color, SK_ColorWHITE);
471 separator_luminance = color_utils::GetRelativeLuminance(separator_color);
472 EXPECT_LT(separator_luminance, 1);
473 EXPECT_LT(separator_luminance, tab_luminance);
474 }
468 475
469 // Now make similar checks as above but for the incognito theme. 476 // Now make similar checks as above but for the incognito theme.
470 const ui::ThemeProvider& otr_provider = 477 {
471 ThemeService::GetThemeProviderForProfile( 478 const ui::ThemeProvider& otr_provider =
472 profile_->GetOffTheRecordProfile()); 479 ThemeService::GetThemeProviderForProfile(
473 frame_color = otr_provider.GetColor(ThemeProperties::COLOR_FRAME); 480 profile_->GetOffTheRecordProfile());
474 theme_color = AlphaBlend( 481 const SkColor frame_color =
475 otr_provider.GetColor(ThemeProperties::COLOR_TOOLBAR_TOP_SEPARATOR), 482 otr_provider.GetColor(ThemeProperties::COLOR_FRAME);
476 frame_color); 483 const SkColor tab_color =
477 tab_color = otr_provider.GetColor(ThemeProperties::COLOR_TOOLBAR); 484 otr_provider.GetColor(ThemeProperties::COLOR_TOOLBAR);
478 separator_color = GetSeparatorColor(tab_color, frame_color); 485 SCOPED_TRACE(base::StringPrintf("Tab color: 0x%08X, frame color: 0x%08X",
479 EXPECT_EQ(theme_color, separator_color); 486 tab_color, frame_color));
480 487
481 // For the default incognito theme, the separator should darken the frame. 488 const SkColor theme_color = AlphaBlend(
482 EXPECT_LT(color_utils::GetRelativeLuminance(separator_color), 489 otr_provider.GetColor(ThemeProperties::COLOR_TOOLBAR_TOP_SEPARATOR),
483 color_utils::GetRelativeLuminance(frame_color)); 490 frame_color);
491 SkColor separator_color = GetSeparatorColor(tab_color, frame_color);
492 EXPECT_EQ(theme_color, separator_color);
484 493
485 // And if we reverse the colors, the separator should lighten the "frame" 494 // For the default incognito theme, the separator should darken the frame.
486 // (tab color). 495 EXPECT_LT(color_utils::GetRelativeLuminance(separator_color),
487 separator_color = GetSeparatorColor(frame_color, tab_color); 496 color_utils::GetRelativeLuminance(frame_color));
488 tab_luminance = color_utils::GetRelativeLuminance(tab_color);
489 EXPECT_GT(color_utils::GetRelativeLuminance(separator_color), tab_luminance);
490 497
491 // When the frame color is black, the separator should lighten the frame; it 498 // And if we reverse the colors, the separator should lighten the "frame"
492 // should also be lighter than the tab color since otherwise the contrast with 499 // (tab color).
493 // the tab would be too minimal. 500 separator_color = GetSeparatorColor(frame_color, tab_color);
494 separator_color = GetSeparatorColor(tab_color, SK_ColorBLACK); 501 double tab_luminance = color_utils::GetRelativeLuminance(tab_color);
495 separator_luminance = color_utils::GetRelativeLuminance(separator_color); 502 EXPECT_GT(color_utils::GetRelativeLuminance(separator_color),
496 EXPECT_GT(separator_luminance, 0); 503 tab_luminance);
497 EXPECT_GT(separator_luminance, tab_luminance);
498 504
499 // When the frame color is white, the separator should darken the frame, but 505 // When the frame color is black, the separator should lighten the frame; it
500 // it should still be lighter than the tab color. 506 // should also be lighter than the tab color since otherwise the contrast
501 separator_color = GetSeparatorColor(tab_color, SK_ColorWHITE); 507 // with the tab would be too minimal.
502 separator_luminance = color_utils::GetRelativeLuminance(separator_color); 508 separator_color = GetSeparatorColor(tab_color, SK_ColorBLACK);
503 EXPECT_LT(separator_luminance, 1); 509 double separator_luminance =
504 EXPECT_GT(separator_luminance, tab_luminance); 510 color_utils::GetRelativeLuminance(separator_color);
511 EXPECT_GT(separator_luminance, 0);
512 EXPECT_GT(separator_luminance, tab_luminance);
513
514 // When the frame color is white, the separator should darken the frame, but
515 // it should still be lighter than the tab color.
516 separator_color = GetSeparatorColor(tab_color, SK_ColorWHITE);
517 separator_luminance = color_utils::GetRelativeLuminance(separator_color);
518 EXPECT_LT(separator_luminance, 1);
519 EXPECT_GT(separator_luminance, tab_luminance);
520 }
505 } 521 }
506 #endif // !defined(OS_MACOSX) 522 #endif // !defined(OS_MACOSX)
507 523
508 }; // namespace theme_service_internal 524 }; // namespace theme_service_internal
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698