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

Side by Side Diff: chrome/browser/ui/cocoa/toolbar/toolbar_controller_unittest.mm

Issue 1305143008: [Mac] Implement LocationBarViewMac::UpdateLocationBarVisibility() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing reviewer feedback Created 5 years, 2 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 #import <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 6
7 #import "base/mac/scoped_nsobject.h" 7 #import "base/mac/scoped_nsobject.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "chrome/app/chrome_command_ids.h" 10 #include "chrome/app/chrome_command_ids.h"
11 #include "chrome/browser/command_updater.h" 11 #include "chrome/browser/command_updater.h"
12 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/browser_command_controller.h" 13 #include "chrome/browser/ui/browser_command_controller.h"
14 #include "chrome/browser/ui/browser_commands.h" 14 #include "chrome/browser/ui/browser_commands.h"
15 #include "chrome/browser/ui/browser_list.h" 15 #include "chrome/browser/ui/browser_list.h"
16 #include "chrome/browser/ui/browser_list_observer.h" 16 #include "chrome/browser/ui/browser_list_observer.h"
17 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" 17 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h"
18 #import "chrome/browser/ui/cocoa/image_button_cell.h" 18 #import "chrome/browser/ui/cocoa/image_button_cell.h"
19 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" 19 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
20 #import "chrome/browser/ui/cocoa/view_resizer_pong.h"
20 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
21 #include "chrome/test/base/testing_profile.h" 22 #include "chrome/test/base/testing_profile.h"
22 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
23 #import "testing/gtest_mac.h" 24 #import "testing/gtest_mac.h"
24 #include "testing/platform_test.h" 25 #include "testing/platform_test.h"
25 26
26 // An NSView that fakes out hitTest:. 27 // An NSView that fakes out hitTest:.
27 @interface HitView : NSView { 28 @interface HitView : NSView {
28 id hitTestReturn_; 29 id hitTestReturn_;
29 } 30 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 // |-toolbarViews| method. 72 // |-toolbarViews| method.
72 enum { 73 enum {
73 kBackIndex, kForwardIndex, kReloadIndex, kHomeIndex, 74 kBackIndex, kForwardIndex, kReloadIndex, kHomeIndex,
74 kWrenchIndex, kLocationIndex, kBrowserActionContainerViewIndex 75 kWrenchIndex, kLocationIndex, kBrowserActionContainerViewIndex
75 }; 76 };
76 77
77 void SetUp() override { 78 void SetUp() override {
78 CocoaProfileTest::SetUp(); 79 CocoaProfileTest::SetUp();
79 ASSERT_TRUE(browser()); 80 ASSERT_TRUE(browser());
80 81
82 resizeDelegate_.reset([[ViewResizerPong alloc] init]);
83
81 CommandUpdater* updater = 84 CommandUpdater* updater =
82 browser()->command_controller()->command_updater(); 85 browser()->command_controller()->command_updater();
83 // The default state for the commands is true, set a couple to false to 86 // The default state for the commands is true, set a couple to false to
84 // ensure they get picked up correct on initialization 87 // ensure they get picked up correct on initialization
85 updater->UpdateCommandEnabled(IDC_BACK, false); 88 updater->UpdateCommandEnabled(IDC_BACK, false);
86 updater->UpdateCommandEnabled(IDC_FORWARD, false); 89 updater->UpdateCommandEnabled(IDC_FORWARD, false);
87 bar_.reset([[TestToolbarController alloc] 90 bar_.reset([[TestToolbarController alloc]
88 initWithCommands:browser()->command_controller()->command_updater() 91 initWithCommands:browser()->command_controller()->command_updater()
89 profile:profile() 92 profile:profile()
90 browser:browser()]); 93 browser:browser()
94 resizeDelegate:resizeDelegate_.get()]);
91 EXPECT_TRUE([bar_ view]); 95 EXPECT_TRUE([bar_ view]);
92 NSView* parent = [test_window() contentView]; 96 NSView* parent = [test_window() contentView];
93 [parent addSubview:[bar_ view]]; 97 [parent addSubview:[bar_ view]];
94 } 98 }
95 99
96 void TearDown() override { 100 void TearDown() override {
97 bar_.reset(); // browser() must outlive the ToolbarController. 101 bar_.reset(); // browser() must outlive the ToolbarController.
98 CocoaProfileTest::TearDown(); 102 CocoaProfileTest::TearDown();
99 } 103 }
100 104
101 // Make sure the enabled state of the view is the same as the corresponding 105 // Make sure the enabled state of the view is the same as the corresponding
102 // command in the updater. The views are in the declaration order of outlets. 106 // command in the updater. The views are in the declaration order of outlets.
103 void CompareState(CommandUpdater* updater, NSArray* views) { 107 void CompareState(CommandUpdater* updater, NSArray* views) {
104 EXPECT_EQ(updater->IsCommandEnabled(IDC_BACK), 108 EXPECT_EQ(updater->IsCommandEnabled(IDC_BACK),
105 [[views objectAtIndex:kBackIndex] isEnabled] ? true : false); 109 [[views objectAtIndex:kBackIndex] isEnabled] ? true : false);
106 EXPECT_EQ(updater->IsCommandEnabled(IDC_FORWARD), 110 EXPECT_EQ(updater->IsCommandEnabled(IDC_FORWARD),
107 [[views objectAtIndex:kForwardIndex] isEnabled] ? true : false); 111 [[views objectAtIndex:kForwardIndex] isEnabled] ? true : false);
108 EXPECT_EQ(updater->IsCommandEnabled(IDC_RELOAD), 112 EXPECT_EQ(updater->IsCommandEnabled(IDC_RELOAD),
109 [[views objectAtIndex:kReloadIndex] isEnabled] ? true : false); 113 [[views objectAtIndex:kReloadIndex] isEnabled] ? true : false);
110 EXPECT_EQ(updater->IsCommandEnabled(IDC_HOME), 114 EXPECT_EQ(updater->IsCommandEnabled(IDC_HOME),
111 [[views objectAtIndex:kHomeIndex] isEnabled] ? true : false); 115 [[views objectAtIndex:kHomeIndex] isEnabled] ? true : false);
112 } 116 }
113 117
118 base::scoped_nsobject<ViewResizerPong> resizeDelegate_;
114 base::scoped_nsobject<TestToolbarController> bar_; 119 base::scoped_nsobject<TestToolbarController> bar_;
115 }; 120 };
116 121
117 TEST_VIEW(ToolbarControllerTest, [bar_ view]) 122 TEST_VIEW(ToolbarControllerTest, [bar_ view])
118 123
119 // Test the initial state that everything is sync'd up 124 // Test the initial state that everything is sync'd up
120 TEST_F(ToolbarControllerTest, InitialState) { 125 TEST_F(ToolbarControllerTest, InitialState) {
121 CommandUpdater* updater = browser()->command_controller()->command_updater(); 126 CommandUpdater* updater = browser()->command_controller()->command_updater();
122 CompareState(updater, [bar_ toolbarViews]); 127 CompareState(updater, [bar_ toolbarViews]);
123 } 128 }
124 129
125 // Make sure a "titlebar only" toolbar with location bar works. 130 // Make sure a "titlebar only" toolbar with location bar works.
126 TEST_F(ToolbarControllerTest, TitlebarOnly) { 131 TEST_F(ToolbarControllerTest, TitlebarOnly) {
127 NSView* view = [bar_ view]; 132 NSView* view = [bar_ view];
128 133
129 [bar_ setHasToolbar:NO hasLocationBar:YES]; 134 [bar_ setHasToolbar:NO hasLocationBar:YES];
130 EXPECT_NE(view, [bar_ view]); 135 EXPECT_EQ(view, [bar_ view]);
131 136
132 // Simulate a popup going fullscreen and back by performing the reparenting 137 // Simulate a popup going fullscreen and back by performing the reparenting
tapted 2015/10/20 06:31:09 Make sure you test this to ensure it still behaves
dominickn 2015/10/26 02:53:04 This should now be unaffected by the showLocationB
tapted 2015/10/26 04:40:55 So did you open site that does HTML5 fullscreen in
dominickn 2015/10/26 06:42:42 I tested a site with HTML5 fullscreen in a popup a
133 // that happens during fullscreen transitions 138 // that happens during fullscreen transitions
134 NSView* superview = [view superview]; 139 NSView* superview = [view superview];
135 [view removeFromSuperview]; 140 [view removeFromSuperview];
136 [superview addSubview:view]; 141 [superview addSubview:view];
137 142
138 [bar_ setHasToolbar:YES hasLocationBar:YES]; 143 [bar_ setHasToolbar:YES hasLocationBar:YES];
139 EXPECT_EQ(view, [bar_ view]); 144 EXPECT_EQ(view, [bar_ view]);
140 145
141 // Leave it off to make sure that's fine 146 // Leave it off to make sure that's fine
142 [bar_ setHasToolbar:NO hasLocationBar:YES]; 147 [bar_ setHasToolbar:NO hasLocationBar:YES];
143 } 148 }
144 149
150 // Test updateVisibility with location bar only; this method is used by bookmark
151 // apps, and should never be called when the toolbar is enabled. Ensure that the
152 // buttons remain in the correct state.
153 TEST_F(ToolbarControllerTest, UpdateVisibility) {
154 NSView* view = [bar_ view];
155 [bar_ setHasToolbar:NO hasLocationBar:YES];
tapted 2015/10/20 06:31:09 Before calling this, EXPECT_FOO the button visibil
dominickn 2015/10/26 02:53:04 Done.
tapted 2015/10/26 04:40:55 Ping
dominickn 2015/10/26 06:42:42 Oops. Done.
156 EXPECT_FALSE([view isHidden]);
157 EXPECT_FALSE([[[bar_ toolbarViews] objectAtIndex:kLocationIndex] isHidden]);
tapted 2015/10/20 06:31:09 This is a lot of repetition. Since bar_ is a data
dominickn 2015/10/26 02:53:04 Done.
158 EXPECT_TRUE([[[bar_ toolbarViews] objectAtIndex:kBackIndex] isHidden]);
159 EXPECT_TRUE([[[bar_ toolbarViews] objectAtIndex:kForwardIndex] isHidden]);
160 EXPECT_TRUE([[[bar_ toolbarViews] objectAtIndex:kReloadIndex] isHidden]);
161 EXPECT_TRUE([[[bar_ toolbarViews] objectAtIndex:kWrenchIndex] isHidden]);
162 EXPECT_TRUE([[[bar_ toolbarViews] objectAtIndex:kHomeIndex] isHidden]);
163
164 // Maintain visible state.
165 [bar_ updateVisibility:YES withAnimation:NO];
166 EXPECT_GT([[bar_ view] frame].size.height, 0);
167 EXPECT_FALSE([view isHidden]);
168 EXPECT_FALSE([[[bar_ toolbarViews] objectAtIndex:kLocationIndex] isHidden]);
169 EXPECT_TRUE([[[bar_ toolbarViews] objectAtIndex:kBackIndex] isHidden]);
170 EXPECT_TRUE([[[bar_ toolbarViews] objectAtIndex:kForwardIndex] isHidden]);
171 EXPECT_TRUE([[[bar_ toolbarViews] objectAtIndex:kReloadIndex] isHidden]);
172 EXPECT_TRUE([[[bar_ toolbarViews] objectAtIndex:kWrenchIndex] isHidden]);
173 EXPECT_TRUE([[[bar_ toolbarViews] objectAtIndex:kHomeIndex] isHidden]);
tapted 2015/10/20 06:31:09 what about the browser action container?
dominickn 2015/10/26 02:53:04 I believe that for popup and bookmark app windows
tapted 2015/10/26 04:40:55 Can we include it in the test?
dominickn 2015/10/26 06:42:42 Done.
174
175 // Hide the toolbar and ensure it is not visible.
176 [bar_ updateVisibility:NO withAnimation:NO];
177 EXPECT_TRUE([view isHidden]);
178 EXPECT_EQ(0, [resizeDelegate_ height]);
179 EXPECT_EQ(0, [[bar_ view] frame].size.height);
180
181 // Try to show the home button.
182 [bar_ showOptionalHomeButton];
183
184 // Re-show the bar. Buttons should remain hidden, including the home button.
185 [bar_ updateVisibility:YES withAnimation:NO];
186 EXPECT_GT([resizeDelegate_ height], 0);
187 EXPECT_GT([[bar_ view] frame].size.height, 0);
188 EXPECT_FALSE([view isHidden]);
189 EXPECT_FALSE([[[bar_ toolbarViews] objectAtIndex:kLocationIndex] isHidden]);
190 EXPECT_TRUE([[[bar_ toolbarViews] objectAtIndex:kBackIndex] isHidden]);
191 EXPECT_TRUE([[[bar_ toolbarViews] objectAtIndex:kForwardIndex] isHidden]);
192 EXPECT_TRUE([[[bar_ toolbarViews] objectAtIndex:kReloadIndex] isHidden]);
193 EXPECT_TRUE([[[bar_ toolbarViews] objectAtIndex:kWrenchIndex] isHidden]);
194 EXPECT_TRUE([[[bar_ toolbarViews] objectAtIndex:kHomeIndex] isHidden]);
195 }
196
145 // Make sure it works in the completely undecorated case. 197 // Make sure it works in the completely undecorated case.
146 TEST_F(ToolbarControllerTest, NoLocationBar) { 198 TEST_F(ToolbarControllerTest, NoLocationBar) {
147 NSView* view = [bar_ view]; 199 NSView* view = [bar_ view];
148 200
149 [bar_ setHasToolbar:NO hasLocationBar:NO]; 201 [bar_ setHasToolbar:NO hasLocationBar:NO];
150 EXPECT_NE(view, [bar_ view]);
151 EXPECT_TRUE([[bar_ view] isHidden]); 202 EXPECT_TRUE([[bar_ view] isHidden]);
152 203
153 // Simulate a popup going fullscreen and back by performing the reparenting 204 // Simulate a popup going fullscreen and back by performing the reparenting
154 // that happens during fullscreen transitions 205 // that happens during fullscreen transitions
155 NSView* superview = [view superview]; 206 NSView* superview = [view superview];
156 [view removeFromSuperview]; 207 [view removeFromSuperview];
157 [superview addSubview:view]; 208 [superview addSubview:view];
158 } 209 }
159 210
160 // Make some changes to the enabled state of a few of the buttons and ensure 211 // Make some changes to the enabled state of a few of the buttons and ensure
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 BrowserRemovedObserver observer; 349 BrowserRemovedObserver observer;
299 // This is normally called by BrowserWindowController, but since |bar_| is not 350 // This is normally called by BrowserWindowController, but since |bar_| is not
300 // owned by one, call it here. 351 // owned by one, call it here.
301 [bar_ browserWillBeDestroyed]; 352 [bar_ browserWillBeDestroyed];
302 CloseBrowserWindow(); 353 CloseBrowserWindow();
303 observer.WaitUntilBrowserRemoved(); 354 observer.WaitUntilBrowserRemoved();
304 // |bar_| is released in TearDown(). 355 // |bar_| is released in TearDown().
305 } 356 }
306 357
307 } // namespace 358 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698