Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #import "chrome/browser/ui/cocoa/tabs/tab_strip_background_view.h" | |
| 6 | |
| 7 #import "chrome/browser/ui/cocoa/test/cocoa_test_helper.h" | |
| 8 #include "ui/base/default_theme_provider.h" | |
| 9 | |
| 10 @class NSVisualEffectView; | |
| 11 | |
| 12 namespace { | |
| 13 | |
| 14 bool ContainsViewOfClass(NSView* view, Class cls) { | |
| 15 if ([view isKindOfClass:cls]) | |
| 16 return true; | |
| 17 for (NSView* subview in view.subviews) { | |
| 18 if (ContainsViewOfClass(subview, cls)) | |
| 19 return true; | |
| 20 } | |
| 21 return false; | |
| 22 } | |
| 23 | |
| 24 class TabStripBackgroundViewTest : public CocoaTest { | |
| 25 protected: | |
| 26 const base::scoped_nsobject<TabStripBackgroundView> | |
| 27 tab_strip_background_view_{ | |
| 28 [[TabStripBackgroundView alloc] initWithFrame:NSZeroRect]}; | |
| 29 }; | |
| 30 | |
| 31 class MockThemeProvider : public ui::DefaultThemeProvider { | |
| 32 public: | |
| 33 bool UsingSystemTheme() const override { return using_system_theme_; } | |
| 34 | |
| 35 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.
| |
| 36 using_system_theme_ = usingSystemTheme; | |
| 37 } | |
| 38 | |
| 39 private: | |
| 40 bool using_system_theme_ = true; | |
| 41 }; | |
| 42 | |
| 43 } // namespace | |
| 44 | |
| 45 @interface TabStripBackgroundViewTestWindow : NSWindow | |
| 46 @property(nonatomic) const ui::ThemeProvider* themeProvider; | |
| 47 @end | |
| 48 | |
| 49 @implementation TabStripBackgroundViewTestWindow | |
| 50 @synthesize themeProvider = themeProvider_; | |
| 51 @end | |
| 52 | |
| 53 TEST_F(TabStripBackgroundViewTest, TestVisualEffectView) { | |
| 54 // 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.
| |
| 55 // Skip this test when running on an OS without NSVisualEffectView. | |
| 56 if (![NSVisualEffectView class]) | |
| 57 return; | |
| 58 | |
| 59 auto has_visual_effect_view = [&]() { | |
| 60 return ContainsViewOfClass(tab_strip_background_view_, | |
| 61 [NSVisualEffectView class]); | |
| 62 }; | |
| 63 | |
| 64 EXPECT_FALSE(has_visual_effect_view()); | |
| 65 | |
| 66 TabStripBackgroundViewTestWindow* window = | |
| 67 [[[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).
| |
| 68 MockThemeProvider theme_provider; | |
| 69 window.themeProvider = &theme_provider; | |
| 70 | |
| 71 [window.contentView addSubview:tab_strip_background_view_]; | |
| 72 | |
| 73 [window makeKeyAndOrderFront:nil]; | |
| 74 [tab_strip_background_view_ windowDidChangeActive]; | |
| 75 EXPECT_TRUE(has_visual_effect_view()); | |
| 76 | |
| 77 window.styleMask |= NSFullScreenWindowMask; | |
| 78 EXPECT_FALSE(has_visual_effect_view()); | |
| 79 | |
| 80 window.styleMask &= ~NSFullScreenWindowMask; | |
| 81 EXPECT_TRUE(has_visual_effect_view()); | |
| 82 | |
| 83 theme_provider.SetUsingSystemTheme(false); | |
| 84 [tab_strip_background_view_ windowDidChangeTheme]; | |
| 85 EXPECT_FALSE(has_visual_effect_view()); | |
| 86 | |
| 87 theme_provider.SetUsingSystemTheme(true); | |
| 88 [tab_strip_background_view_ windowDidChangeTheme]; | |
| 89 EXPECT_TRUE(has_visual_effect_view()); | |
| 90 } | |
| OLD | NEW |