OLD | NEW |
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" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 | 65 |
66 namespace { | 66 namespace { |
67 | 67 |
68 class ToolbarControllerTest : public CocoaProfileTest { | 68 class ToolbarControllerTest : public CocoaProfileTest { |
69 public: | 69 public: |
70 | 70 |
71 // Indexes that match the ordering returned by the private ToolbarController | 71 // Indexes that match the ordering returned by the private ToolbarController |
72 // |-toolbarViews| method. | 72 // |-toolbarViews| method. |
73 enum SubviewIndex { | 73 enum SubviewIndex { |
74 kBackIndex, kForwardIndex, kReloadIndex, kHomeIndex, | 74 kBackIndex, kForwardIndex, kReloadIndex, kHomeIndex, |
75 kWrenchIndex, kLocationIndex, kBrowserActionContainerViewIndex | 75 kAppMenuIndex, kLocationIndex, kBrowserActionContainerViewIndex |
76 }; | 76 }; |
77 | 77 |
78 void SetUp() override { | 78 void SetUp() override { |
79 CocoaProfileTest::SetUp(); | 79 CocoaProfileTest::SetUp(); |
80 ASSERT_TRUE(browser()); | 80 ASSERT_TRUE(browser()); |
81 | 81 |
82 resizeDelegate_.reset([[ViewResizerPong alloc] init]); | 82 resizeDelegate_.reset([[ViewResizerPong alloc] init]); |
83 | 83 |
84 CommandUpdater* updater = | 84 CommandUpdater* updater = |
85 browser()->command_controller()->command_updater(); | 85 browser()->command_controller()->command_updater(); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 EXPECT_GT([[bar_ view] frame].size.height, 0); | 165 EXPECT_GT([[bar_ view] frame].size.height, 0); |
166 EXPECT_GT([[bar_ view] frame].size.height, | 166 EXPECT_GT([[bar_ view] frame].size.height, |
167 [GetSubviewAt(kLocationIndex) frame].size.height); | 167 [GetSubviewAt(kLocationIndex) frame].size.height); |
168 EXPECT_GT([[bar_ view] frame].size.width, | 168 EXPECT_GT([[bar_ view] frame].size.width, |
169 [GetSubviewAt(kLocationIndex) frame].size.width); | 169 [GetSubviewAt(kLocationIndex) frame].size.width); |
170 EXPECT_FALSE([view isHidden]); | 170 EXPECT_FALSE([view isHidden]); |
171 EXPECT_FALSE([GetSubviewAt(kLocationIndex) isHidden]); | 171 EXPECT_FALSE([GetSubviewAt(kLocationIndex) isHidden]); |
172 EXPECT_FALSE([GetSubviewAt(kBackIndex) isHidden]); | 172 EXPECT_FALSE([GetSubviewAt(kBackIndex) isHidden]); |
173 EXPECT_FALSE([GetSubviewAt(kForwardIndex) isHidden]); | 173 EXPECT_FALSE([GetSubviewAt(kForwardIndex) isHidden]); |
174 EXPECT_FALSE([GetSubviewAt(kReloadIndex) isHidden]); | 174 EXPECT_FALSE([GetSubviewAt(kReloadIndex) isHidden]); |
175 EXPECT_FALSE([GetSubviewAt(kWrenchIndex) isHidden]); | 175 EXPECT_FALSE([GetSubviewAt(kAppMenuIndex) isHidden]); |
176 EXPECT_TRUE([GetSubviewAt(kHomeIndex) isHidden]); | 176 EXPECT_TRUE([GetSubviewAt(kHomeIndex) isHidden]); |
177 EXPECT_TRUE([GetSubviewAt(kBrowserActionContainerViewIndex) isHidden]); | 177 EXPECT_TRUE([GetSubviewAt(kBrowserActionContainerViewIndex) isHidden]); |
178 | 178 |
179 // For NO/NO, only the top level toolbar view is hidden. | 179 // For NO/NO, only the top level toolbar view is hidden. |
180 [bar_ setHasToolbar:NO hasLocationBar:NO]; | 180 [bar_ setHasToolbar:NO hasLocationBar:NO]; |
181 EXPECT_TRUE([view isHidden]); | 181 EXPECT_TRUE([view isHidden]); |
182 EXPECT_FALSE([GetSubviewAt(kLocationIndex) isHidden]); | 182 EXPECT_FALSE([GetSubviewAt(kLocationIndex) isHidden]); |
183 EXPECT_FALSE([GetSubviewAt(kBackIndex) isHidden]); | 183 EXPECT_FALSE([GetSubviewAt(kBackIndex) isHidden]); |
184 EXPECT_FALSE([GetSubviewAt(kForwardIndex) isHidden]); | 184 EXPECT_FALSE([GetSubviewAt(kForwardIndex) isHidden]); |
185 EXPECT_FALSE([GetSubviewAt(kReloadIndex) isHidden]); | 185 EXPECT_FALSE([GetSubviewAt(kReloadIndex) isHidden]); |
186 EXPECT_FALSE([GetSubviewAt(kWrenchIndex) isHidden]); | 186 EXPECT_FALSE([GetSubviewAt(kAppMenuIndex) isHidden]); |
187 EXPECT_TRUE([GetSubviewAt(kHomeIndex) isHidden]); | 187 EXPECT_TRUE([GetSubviewAt(kHomeIndex) isHidden]); |
188 EXPECT_TRUE([GetSubviewAt(kBrowserActionContainerViewIndex) isHidden]); | 188 EXPECT_TRUE([GetSubviewAt(kBrowserActionContainerViewIndex) isHidden]); |
189 | 189 |
190 // Now test the inescapable state. | 190 // Now test the inescapable state. |
191 [bar_ setHasToolbar:NO hasLocationBar:YES]; | 191 [bar_ setHasToolbar:NO hasLocationBar:YES]; |
192 EXPECT_GT([[bar_ view] frame].size.height, 0); | 192 EXPECT_GT([[bar_ view] frame].size.height, 0); |
193 EXPECT_EQ([[bar_ view] frame].size.height, | 193 EXPECT_EQ([[bar_ view] frame].size.height, |
194 [GetSubviewAt(kLocationIndex) frame].size.height); | 194 [GetSubviewAt(kLocationIndex) frame].size.height); |
195 EXPECT_EQ([[bar_ view] frame].size.width, | 195 EXPECT_EQ([[bar_ view] frame].size.width, |
196 [GetSubviewAt(kLocationIndex) frame].size.width); | 196 [GetSubviewAt(kLocationIndex) frame].size.width); |
197 EXPECT_FALSE([view isHidden]); | 197 EXPECT_FALSE([view isHidden]); |
198 EXPECT_FALSE([GetSubviewAt(kLocationIndex) isHidden]); | 198 EXPECT_FALSE([GetSubviewAt(kLocationIndex) isHidden]); |
199 EXPECT_TRUE([GetSubviewAt(kBackIndex) isHidden]); | 199 EXPECT_TRUE([GetSubviewAt(kBackIndex) isHidden]); |
200 EXPECT_TRUE([GetSubviewAt(kForwardIndex) isHidden]); | 200 EXPECT_TRUE([GetSubviewAt(kForwardIndex) isHidden]); |
201 EXPECT_TRUE([GetSubviewAt(kReloadIndex) isHidden]); | 201 EXPECT_TRUE([GetSubviewAt(kReloadIndex) isHidden]); |
202 EXPECT_TRUE([GetSubviewAt(kWrenchIndex) isHidden]); | 202 EXPECT_TRUE([GetSubviewAt(kAppMenuIndex) isHidden]); |
203 EXPECT_TRUE([GetSubviewAt(kHomeIndex) isHidden]); | 203 EXPECT_TRUE([GetSubviewAt(kHomeIndex) isHidden]); |
204 EXPECT_TRUE([GetSubviewAt(kBrowserActionContainerViewIndex) isHidden]); | 204 EXPECT_TRUE([GetSubviewAt(kBrowserActionContainerViewIndex) isHidden]); |
205 | 205 |
206 // Maintain visible state. | 206 // Maintain visible state. |
207 [bar_ updateVisibility:YES withAnimation:NO]; | 207 [bar_ updateVisibility:YES withAnimation:NO]; |
208 EXPECT_GT([[bar_ view] frame].size.height, 0); | 208 EXPECT_GT([[bar_ view] frame].size.height, 0); |
209 EXPECT_EQ([[bar_ view] frame].size.height, | 209 EXPECT_EQ([[bar_ view] frame].size.height, |
210 [GetSubviewAt(kLocationIndex) frame].size.height); | 210 [GetSubviewAt(kLocationIndex) frame].size.height); |
211 EXPECT_EQ([[bar_ view] frame].size.width, | 211 EXPECT_EQ([[bar_ view] frame].size.width, |
212 [GetSubviewAt(kLocationIndex) frame].size.width); | 212 [GetSubviewAt(kLocationIndex) frame].size.width); |
213 EXPECT_FALSE([view isHidden]); | 213 EXPECT_FALSE([view isHidden]); |
214 EXPECT_FALSE([GetSubviewAt(kLocationIndex) isHidden]); | 214 EXPECT_FALSE([GetSubviewAt(kLocationIndex) isHidden]); |
215 EXPECT_TRUE([GetSubviewAt(kBackIndex) isHidden]); | 215 EXPECT_TRUE([GetSubviewAt(kBackIndex) isHidden]); |
216 EXPECT_TRUE([GetSubviewAt(kForwardIndex) isHidden]); | 216 EXPECT_TRUE([GetSubviewAt(kForwardIndex) isHidden]); |
217 EXPECT_TRUE([GetSubviewAt(kReloadIndex) isHidden]); | 217 EXPECT_TRUE([GetSubviewAt(kReloadIndex) isHidden]); |
218 EXPECT_TRUE([GetSubviewAt(kWrenchIndex) isHidden]); | 218 EXPECT_TRUE([GetSubviewAt(kAppMenuIndex) isHidden]); |
219 EXPECT_TRUE([GetSubviewAt(kHomeIndex) isHidden]); | 219 EXPECT_TRUE([GetSubviewAt(kHomeIndex) isHidden]); |
220 EXPECT_TRUE([GetSubviewAt(kBrowserActionContainerViewIndex) isHidden]); | 220 EXPECT_TRUE([GetSubviewAt(kBrowserActionContainerViewIndex) isHidden]); |
221 | 221 |
222 // Hide the toolbar and ensure it has height 0. | 222 // Hide the toolbar and ensure it has height 0. |
223 [bar_ updateVisibility:NO withAnimation:NO]; | 223 [bar_ updateVisibility:NO withAnimation:NO]; |
224 EXPECT_FALSE([view isHidden]); | 224 EXPECT_FALSE([view isHidden]); |
225 EXPECT_EQ(0, [resizeDelegate_ height]); | 225 EXPECT_EQ(0, [resizeDelegate_ height]); |
226 EXPECT_EQ(0, [[bar_ view] frame].size.height); | 226 EXPECT_EQ(0, [[bar_ view] frame].size.height); |
227 | 227 |
228 // Try to show the home button. | 228 // Try to show the home button. |
229 [bar_ showOptionalHomeButton]; | 229 [bar_ showOptionalHomeButton]; |
230 | 230 |
231 // Re-show the bar. Buttons should remain hidden, including the home button. | 231 // Re-show the bar. Buttons should remain hidden, including the home button. |
232 [bar_ updateVisibility:YES withAnimation:NO]; | 232 [bar_ updateVisibility:YES withAnimation:NO]; |
233 EXPECT_GT([resizeDelegate_ height], 0); | 233 EXPECT_GT([resizeDelegate_ height], 0); |
234 EXPECT_GT([[bar_ view] frame].size.height, 0); | 234 EXPECT_GT([[bar_ view] frame].size.height, 0); |
235 EXPECT_EQ([[bar_ view] frame].size.height, | 235 EXPECT_EQ([[bar_ view] frame].size.height, |
236 [GetSubviewAt(kLocationIndex) frame].size.height); | 236 [GetSubviewAt(kLocationIndex) frame].size.height); |
237 EXPECT_EQ([[bar_ view] frame].size.width, | 237 EXPECT_EQ([[bar_ view] frame].size.width, |
238 [GetSubviewAt(kLocationIndex) frame].size.width); | 238 [GetSubviewAt(kLocationIndex) frame].size.width); |
239 EXPECT_FALSE([view isHidden]); | 239 EXPECT_FALSE([view isHidden]); |
240 EXPECT_FALSE([GetSubviewAt(kLocationIndex) isHidden]); | 240 EXPECT_FALSE([GetSubviewAt(kLocationIndex) isHidden]); |
241 EXPECT_TRUE([GetSubviewAt(kBackIndex) isHidden]); | 241 EXPECT_TRUE([GetSubviewAt(kBackIndex) isHidden]); |
242 EXPECT_TRUE([GetSubviewAt(kForwardIndex) isHidden]); | 242 EXPECT_TRUE([GetSubviewAt(kForwardIndex) isHidden]); |
243 EXPECT_TRUE([GetSubviewAt(kReloadIndex) isHidden]); | 243 EXPECT_TRUE([GetSubviewAt(kReloadIndex) isHidden]); |
244 EXPECT_TRUE([GetSubviewAt(kWrenchIndex) isHidden]); | 244 EXPECT_TRUE([GetSubviewAt(kAppMenuIndex) isHidden]); |
245 EXPECT_TRUE([GetSubviewAt(kHomeIndex) isHidden]); | 245 EXPECT_TRUE([GetSubviewAt(kHomeIndex) isHidden]); |
246 EXPECT_TRUE([GetSubviewAt(kBrowserActionContainerViewIndex) isHidden]); | 246 EXPECT_TRUE([GetSubviewAt(kBrowserActionContainerViewIndex) isHidden]); |
247 } | 247 } |
248 | 248 |
249 // Make sure it works in the completely undecorated case. | 249 // Make sure it works in the completely undecorated case. |
250 TEST_F(ToolbarControllerTest, NoLocationBar) { | 250 TEST_F(ToolbarControllerTest, NoLocationBar) { |
251 NSView* view = [bar_ view]; | 251 NSView* view = [bar_ view]; |
252 | 252 |
253 [bar_ setHasToolbar:NO hasLocationBar:NO]; | 253 [bar_ setHasToolbar:NO hasLocationBar:NO]; |
254 EXPECT_TRUE([[bar_ view] isHidden]); | 254 EXPECT_TRUE([[bar_ view] isHidden]); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 void WaitUntilBrowserRemoved() { run_loop_.Run(); } | 392 void WaitUntilBrowserRemoved() { run_loop_.Run(); } |
393 void OnBrowserRemoved(Browser* browser) override { run_loop_.Quit(); } | 393 void OnBrowserRemoved(Browser* browser) override { run_loop_.Quit(); } |
394 | 394 |
395 private: | 395 private: |
396 base::RunLoop run_loop_; | 396 base::RunLoop run_loop_; |
397 | 397 |
398 DISALLOW_COPY_AND_ASSIGN(BrowserRemovedObserver); | 398 DISALLOW_COPY_AND_ASSIGN(BrowserRemovedObserver); |
399 }; | 399 }; |
400 | 400 |
401 } // namespace | 401 } // namespace |
OLD | NEW |