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_private.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) | |
|
spqchan
2017/01/11 19:33:56
nit: multiple statement for loops need curly brace
Sidney San Martín
2017/01/13 00:10:07
Done.
| |
| 18 if (ContainsViewOfClass(subview, cls)) | |
| 19 return true; | |
| 20 return false; | |
| 21 } | |
| 22 | |
| 23 class TabStripBackgroundViewTest : public CocoaTest { | |
| 24 protected: | |
| 25 const base::scoped_nsobject<TabStripBackgroundView> tabStripBackgroundView_{ | |
|
Robert Sesek
2017/01/11 19:23:40
naming: use under_scores_ in C++ members
Sidney San Martín
2017/01/13 00:10:07
Done.
| |
| 26 [[TabStripBackgroundView alloc] initWithFrame:NSZeroRect]}; | |
| 27 }; | |
| 28 | |
| 29 class MockThemeProvider : public ui::DefaultThemeProvider { | |
| 30 public: | |
| 31 bool UsingSystemTheme() const override { return _usingSystemTheme; } | |
| 32 | |
| 33 void SetUsingSystemTheme(bool usingSystemTheme) { | |
| 34 _usingSystemTheme = usingSystemTheme; | |
| 35 } | |
| 36 | |
| 37 private: | |
| 38 bool _usingSystemTheme = true; | |
|
Robert Sesek
2017/01/11 19:23:40
naming: under_scores_
Sidney San Martín
2017/01/13 00:10:07
Done.
| |
| 39 }; | |
| 40 | |
| 41 } // namespace | |
| 42 | |
| 43 @interface TabStripBackgroundViewTestWindow : NSWindow | |
| 44 @property(nonatomic) const ui::ThemeProvider* themeProvider; | |
| 45 @end | |
| 46 | |
| 47 @implementation TabStripBackgroundViewTestWindow | |
| 48 @synthesize themeProvider = _themeProvider; | |
|
Robert Sesek
2017/01/11 19:23:40
nit: Use trailing underscore.
Sidney San Martín
2017/01/13 00:10:07
Done.
| |
| 49 @end | |
| 50 | |
| 51 TEST_F(TabStripBackgroundViewTest, TestVisualEffectView) { | |
| 52 Class NSVisualEffectView_class = [NSVisualEffectView class]; | |
|
Robert Sesek
2017/01/11 19:23:40
Leave a comment explaining what this is doing.
Sidney San Martín
2017/01/13 00:10:07
Done.
| |
| 53 if (!NSVisualEffectView_class) | |
| 54 return; | |
| 55 | |
| 56 auto hasVisualEffectView = [&]() { | |
|
Robert Sesek
2017/01/11 19:23:40
naming: under_scores
Sidney San Martín
2017/01/13 00:10:07
Done.
| |
| 57 return ContainsViewOfClass(tabStripBackgroundView_, | |
| 58 NSVisualEffectView_class); | |
| 59 }; | |
| 60 | |
| 61 EXPECT_FALSE(hasVisualEffectView()); | |
| 62 | |
| 63 TabStripBackgroundViewTestWindow* window = | |
| 64 [[[TabStripBackgroundViewTestWindow alloc] init] autorelease]; | |
| 65 MockThemeProvider themeProvider; | |
|
Robert Sesek
2017/01/11 19:23:40
naming: under_scores
Sidney San Martín
2017/01/13 00:10:07
Done.
| |
| 66 window.themeProvider = &themeProvider; | |
| 67 | |
| 68 [window.contentView addSubview:tabStripBackgroundView_]; | |
| 69 | |
| 70 [window makeKeyAndOrderFront:nil]; | |
| 71 [tabStripBackgroundView_ windowDidChangeActive]; | |
| 72 EXPECT_TRUE(hasVisualEffectView()); | |
| 73 | |
| 74 window.styleMask |= NSFullScreenWindowMask; | |
| 75 EXPECT_FALSE(hasVisualEffectView()); | |
| 76 | |
| 77 window.styleMask &= ~NSFullScreenWindowMask; | |
| 78 EXPECT_TRUE(hasVisualEffectView()); | |
| 79 | |
| 80 themeProvider.SetUsingSystemTheme(false); | |
| 81 [tabStripBackgroundView_ windowDidChangeTheme]; | |
| 82 EXPECT_FALSE(hasVisualEffectView()); | |
| 83 | |
| 84 themeProvider.SetUsingSystemTheme(true); | |
| 85 [tabStripBackgroundView_ windowDidChangeTheme]; | |
| 86 EXPECT_TRUE(hasVisualEffectView()); | |
| 87 } | |
| OLD | NEW |