Chromium Code Reviews| Index: chrome/browser/ui/cocoa/tabs/tab_strip_background_view_unittest.mm |
| diff --git a/chrome/browser/ui/cocoa/tabs/tab_strip_background_view_unittest.mm b/chrome/browser/ui/cocoa/tabs/tab_strip_background_view_unittest.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..643ef2a0abd241b2be48c3da8ff9db39c54dc7d9 |
| --- /dev/null |
| +++ b/chrome/browser/ui/cocoa/tabs/tab_strip_background_view_unittest.mm |
| @@ -0,0 +1,90 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#import "chrome/browser/ui/cocoa/tabs/tab_strip_background_view.h" |
| + |
| +#import "chrome/browser/ui/cocoa/test/cocoa_test_helper.h" |
| +#include "ui/base/default_theme_provider.h" |
| + |
| +@class NSVisualEffectView; |
| + |
| +namespace { |
| + |
| +bool ContainsViewOfClass(NSView* view, Class cls) { |
| + if ([view isKindOfClass:cls]) |
| + return true; |
| + for (NSView* subview in view.subviews) { |
| + if (ContainsViewOfClass(subview, cls)) |
| + return true; |
| + } |
| + return false; |
| +} |
| + |
| +class TabStripBackgroundViewTest : public CocoaTest { |
| + protected: |
| + const base::scoped_nsobject<TabStripBackgroundView> |
| + tab_strip_background_view_{ |
| + [[TabStripBackgroundView alloc] initWithFrame:NSZeroRect]}; |
| +}; |
| + |
| +class MockThemeProvider : public ui::DefaultThemeProvider { |
| + public: |
| + bool UsingSystemTheme() const override { return using_system_theme_; } |
| + |
| + void SetUsingSystemTheme(bool usingSystemTheme) { |
|
Robert Sesek
2017/01/13 19:39:42
naming: using_system_theme
Sidney San Martín
2017/01/13 20:05:17
Done.
|
| + using_system_theme_ = usingSystemTheme; |
| + } |
| + |
| + private: |
| + bool using_system_theme_ = true; |
| +}; |
| + |
| +} // namespace |
| + |
| +@interface TabStripBackgroundViewTestWindow : NSWindow |
| +@property(nonatomic) const ui::ThemeProvider* themeProvider; |
| +@end |
| + |
| +@implementation TabStripBackgroundViewTestWindow |
| +@synthesize themeProvider = themeProvider_; |
| +@end |
| + |
| +TEST_F(TabStripBackgroundViewTest, TestVisualEffectView) { |
| + // TODO: Remove once we no longer support 10.9 |
|
Robert Sesek
2017/01/13 19:39:41
nit: punctuation
Sidney San Martín
2017/01/13 20:05:17
Done.
|
| + // Skip this test when running on an OS without NSVisualEffectView. |
| + if (![NSVisualEffectView class]) |
| + return; |
| + |
| + auto has_visual_effect_view = [&]() { |
| + return ContainsViewOfClass(tab_strip_background_view_, |
| + [NSVisualEffectView class]); |
| + }; |
| + |
| + EXPECT_FALSE(has_visual_effect_view()); |
| + |
| + TabStripBackgroundViewTestWindow* window = |
| + [[[TabStripBackgroundViewTestWindow alloc] init] autorelease]; |
|
Robert Sesek
2017/01/13 19:39:42
Why not scoped_nsobject?
Sidney San Martín
2017/01/13 20:05:17
Because I can't use properties with scoped_nsobjec
Robert Sesek
2017/01/13 20:12:36
Hm. I'd probably do this (optional):
scoped_nsobj
Sidney San Martín
2017/01/13 20:30:41
Done (with slightly different naming).
|
| + MockThemeProvider theme_provider; |
| + window.themeProvider = &theme_provider; |
| + |
| + [window.contentView addSubview:tab_strip_background_view_]; |
| + |
| + [window makeKeyAndOrderFront:nil]; |
| + [tab_strip_background_view_ windowDidChangeActive]; |
| + EXPECT_TRUE(has_visual_effect_view()); |
| + |
| + window.styleMask |= NSFullScreenWindowMask; |
| + EXPECT_FALSE(has_visual_effect_view()); |
| + |
| + window.styleMask &= ~NSFullScreenWindowMask; |
| + EXPECT_TRUE(has_visual_effect_view()); |
| + |
| + theme_provider.SetUsingSystemTheme(false); |
| + [tab_strip_background_view_ windowDidChangeTheme]; |
| + EXPECT_FALSE(has_visual_effect_view()); |
| + |
| + theme_provider.SetUsingSystemTheme(true); |
| + [tab_strip_background_view_ windowDidChangeTheme]; |
| + EXPECT_TRUE(has_visual_effect_view()); |
| +} |