OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/extensions/extension_action_test_util.h" | 10 #include "chrome/browser/extensions/extension_action_test_util.h" |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 | 149 |
150 void TearDownOnMainThread() override { | 150 void TearDownOnMainThread() override { |
151 enable_redesign_.reset(); | 151 enable_redesign_.reset(); |
152 ToolbarActionsBar::disable_animations_for_testing_ = false; | 152 ToolbarActionsBar::disable_animations_for_testing_ = false; |
153 ExtensionBrowserTest::TearDownOnMainThread(); | 153 ExtensionBrowserTest::TearDownOnMainThread(); |
154 } | 154 } |
155 | 155 |
156 ToolbarController* toolbarController() { return toolbarController_; } | 156 ToolbarController* toolbarController() { return toolbarController_; } |
157 AppMenuController* appMenuController() { return appMenuController_; } | 157 AppMenuController* appMenuController() { return appMenuController_; } |
158 ToolbarActionsModel* model() { return model_; } | 158 ToolbarActionsModel* model() { return model_; } |
159 NSView* wrenchButton() { return [toolbarController_ wrenchButton]; } | 159 NSView* appMenuButton() { return [toolbarController_ appMenuButton]; } |
160 | 160 |
161 private: | 161 private: |
162 scoped_ptr<extensions::FeatureSwitch::ScopedOverride> enable_redesign_; | 162 scoped_ptr<extensions::FeatureSwitch::ScopedOverride> enable_redesign_; |
163 | 163 |
164 ToolbarController* toolbarController_ = nil; | 164 ToolbarController* toolbarController_ = nil; |
165 AppMenuController* appMenuController_ = nil; | 165 AppMenuController* appMenuController_ = nil; |
166 ToolbarActionsModel* model_ = nullptr; | 166 ToolbarActionsModel* model_ = nullptr; |
167 | 167 |
168 DISALLOW_COPY_AND_ASSIGN(BrowserActionButtonUiTest); | 168 DISALLOW_COPY_AND_ASSIGN(BrowserActionButtonUiTest); |
169 }; | 169 }; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 | 256 |
257 // Reset the menu helper so we can use it again. | 257 // Reset the menu helper so we can use it again. |
258 [menuHelper setMenuOpened:NO]; | 258 [menuHelper setMenuOpened:NO]; |
259 [menuHelper setVerify:base::Bind( | 259 [menuHelper setVerify:base::Bind( |
260 CheckActionIsPoppedOut, actionsController, actionButton)]; | 260 CheckActionIsPoppedOut, actionsController, actionButton)]; |
261 | 261 |
262 // Shrink the visible count to be 0. This should hide the action button. | 262 // Shrink the visible count to be 0. This should hide the action button. |
263 model()->SetVisibleIconCount(0); | 263 model()->SetVisibleIconCount(0); |
264 EXPECT_EQ(nil, [actionButton superview]); | 264 EXPECT_EQ(nil, [actionButton superview]); |
265 | 265 |
266 // Move the mouse over the app button. | 266 // Move the mouse over the app menu button. |
267 MoveMouseToCenter(wrenchButton()); | 267 MoveMouseToCenter(appMenuButton()); |
268 | 268 |
269 { | 269 { |
270 // No menu yet (on the browser action). | 270 // No menu yet (on the browser action). |
271 EXPECT_FALSE([menuHelper menuOpened]); | 271 EXPECT_FALSE([menuHelper menuOpened]); |
272 base::RunLoop runLoop; | 272 base::RunLoop runLoop; |
273 // Click on the app menu, and pass in a callback to continue the test in | 273 // Click on the app menu, and pass in a callback to continue the test in |
274 // ClickOnOverflowedAction (Due to the blocking nature of Cocoa menus, | 274 // ClickOnOverflowedAction (Due to the blocking nature of Cocoa menus, |
275 // passing in runLoop.QuitClosure() is not sufficient here.) | 275 // passing in runLoop.QuitClosure() is not sufficient here.) |
276 ui_controls::SendMouseEventsNotifyWhenDone( | 276 ui_controls::SendMouseEventsNotifyWhenDone( |
277 ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, | 277 ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, |
278 base::Bind(&ClickOnOverflowedAction, | 278 base::Bind(&ClickOnOverflowedAction, |
279 base::Unretained(toolbarController()), | 279 base::Unretained(toolbarController()), |
280 runLoop.QuitClosure())); | 280 runLoop.QuitClosure())); |
281 runLoop.Run(); | 281 runLoop.Run(); |
282 // The menu should have opened. Note that the menu opened on the main bar's | 282 // The menu should have opened. Note that the menu opened on the main bar's |
283 // action button, not the overflow's. Since Cocoa doesn't support running | 283 // action button, not the overflow's. Since Cocoa doesn't support running |
284 // a menu-within-a-menu, this is what has to happen. | 284 // a menu-within-a-menu, this is what has to happen. |
285 EXPECT_TRUE([menuHelper menuOpened]); | 285 EXPECT_TRUE([menuHelper menuOpened]); |
286 } | 286 } |
287 } | 287 } |
288 | 288 |
289 // Checks the layout of the overflow bar in the app menu. | 289 // Checks the layout of the overflow bar in the app menu. |
290 void CheckWrenchMenuLayout(ToolbarController* toolbarController, | 290 void CheckAppMenuLayout(ToolbarController* toolbarController, |
291 int overflowStartIndex, | 291 int overflowStartIndex, |
292 const std::string& error_message, | 292 const std::string& error_message, |
293 const base::Closure& closure) { | 293 const base::Closure& closure) { |
294 AppMenuController* appMenuController = | 294 AppMenuController* appMenuController = |
295 [toolbarController appMenuController]; | 295 [toolbarController appMenuController]; |
296 // The app menu should start as open (since that's where the overflowed | 296 // The app menu should start as open (since that's where the overflowed |
297 // actions are). | 297 // actions are). |
298 EXPECT_TRUE([appMenuController isMenuOpen]) << error_message; | 298 EXPECT_TRUE([appMenuController isMenuOpen]) << error_message; |
299 BrowserActionsController* overflowController = | 299 BrowserActionsController* overflowController = |
300 [appMenuController browserActionsController]; | 300 [appMenuController browserActionsController]; |
301 ASSERT_TRUE(overflowController) << error_message; | 301 ASSERT_TRUE(overflowController) << error_message; |
302 | 302 |
303 ToolbarActionsBar* overflowBar = [overflowController toolbarActionsBar]; | 303 ToolbarActionsBar* overflowBar = [overflowController toolbarActionsBar]; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 for (int i = 0; i < kNumExtensions; ++i) { | 363 for (int i = 0; i < kNumExtensions; ++i) { |
364 scoped_refptr<const extensions::Extension> extension = | 364 scoped_refptr<const extensions::Extension> extension = |
365 extensions::extension_action_test_util::CreateActionExtension( | 365 extensions::extension_action_test_util::CreateActionExtension( |
366 base::StringPrintf("extension%d", i), | 366 base::StringPrintf("extension%d", i), |
367 extensions::extension_action_test_util::BROWSER_ACTION); | 367 extensions::extension_action_test_util::BROWSER_ACTION); |
368 extension_service()->AddExtension(extension.get()); | 368 extension_service()->AddExtension(extension.get()); |
369 } | 369 } |
370 ASSERT_EQ(kNumExtensions, static_cast<int>(model()->toolbar_items().size())); | 370 ASSERT_EQ(kNumExtensions, static_cast<int>(model()->toolbar_items().size())); |
371 | 371 |
372 // A helper function to open the app menu and call the check function. | 372 // A helper function to open the app menu and call the check function. |
373 auto resizeAndActivateWrench = [this](int visible_count, | 373 auto resizeAndActivateAppMenu = [this](int visible_count, |
374 const std::string& error_message) { | 374 const std::string& error_message) { |
375 model()->SetVisibleIconCount(kNumExtensions - visible_count); | 375 model()->SetVisibleIconCount(kNumExtensions - visible_count); |
376 MoveMouseToCenter(wrenchButton()); | 376 MoveMouseToCenter(appMenuButton()); |
377 | 377 |
378 { | 378 { |
379 base::RunLoop runLoop; | 379 base::RunLoop runLoop; |
380 // Click on the app menu, and pass in a callback to continue the test in | 380 // Click on the app menu, and pass in a callback to continue the test in |
381 // CheckWrenchMenuLayout (due to the blocking nature of Cocoa menus, | 381 // CheckAppMenuLayout (due to the blocking nature of Cocoa menus, |
382 // passing in runLoop.QuitClosure() is not sufficient here.) | 382 // passing in runLoop.QuitClosure() is not sufficient here.) |
383 ui_controls::SendMouseEventsNotifyWhenDone( | 383 ui_controls::SendMouseEventsNotifyWhenDone( |
384 ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, | 384 ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, |
385 base::Bind(&CheckWrenchMenuLayout, | 385 base::Bind(&CheckAppMenuLayout, |
386 base::Unretained(toolbarController()), | 386 base::Unretained(toolbarController()), |
387 kNumExtensions - visible_count, | 387 kNumExtensions - visible_count, |
388 error_message, | 388 error_message, |
389 runLoop.QuitClosure())); | 389 runLoop.QuitClosure())); |
390 runLoop.Run(); | 390 runLoop.Run(); |
391 } | 391 } |
392 }; | 392 }; |
393 | 393 |
394 // Test the layout with gradually more extensions hidden. | 394 // Test the layout with gradually more extensions hidden. |
395 for (int i = 1; i <= kNumExtensions; ++i) | 395 for (int i = 1; i <= kNumExtensions; ++i) |
396 resizeAndActivateWrench(i, base::StringPrintf("Normal: %d", i)); | 396 resizeAndActivateAppMenu(i, base::StringPrintf("Normal: %d", i)); |
397 | 397 |
398 // Adding a global error adjusts the app menu size, and has been known to mess | 398 // Adding a global error adjusts the app menu size, and has been known to mess |
399 // up the overflow container's bounds (crbug.com/511326). | 399 // up the overflow container's bounds (crbug.com/511326). |
400 GlobalErrorService* error_service = | 400 GlobalErrorService* error_service = |
401 GlobalErrorServiceFactory::GetForProfile(profile()); | 401 GlobalErrorServiceFactory::GetForProfile(profile()); |
402 error_service->AddGlobalError(new MenuError()); | 402 error_service->AddGlobalError(new MenuError()); |
403 | 403 |
404 // It's probably excessive to test every level of the overflow here. Test | 404 // It's probably excessive to test every level of the overflow here. Test |
405 // having all actions overflowed, some actions overflowed, and one action | 405 // having all actions overflowed, some actions overflowed, and one action |
406 // overflowed. | 406 // overflowed. |
407 resizeAndActivateWrench(kNumExtensions, "GlobalError Full"); | 407 resizeAndActivateAppMenu(kNumExtensions, "GlobalError Full"); |
408 resizeAndActivateWrench(kNumExtensions / 2, "GlobalError Half"); | 408 resizeAndActivateAppMenu(kNumExtensions / 2, "GlobalError Half"); |
409 resizeAndActivateWrench(1, "GlobalError One"); | 409 resizeAndActivateAppMenu(1, "GlobalError One"); |
410 } | 410 } |
411 | 411 |
412 void AddExtensionWithMenuOpen(ToolbarController* toolbarController, | 412 void AddExtensionWithMenuOpen(ToolbarController* toolbarController, |
413 ExtensionService* extensionService, | 413 ExtensionService* extensionService, |
414 const base::Closure& closure) { | 414 const base::Closure& closure) { |
415 AppMenuController* appMenuController = | 415 AppMenuController* appMenuController = |
416 [toolbarController appMenuController]; | 416 [toolbarController appMenuController]; |
417 | 417 |
418 scoped_refptr<const extensions::Extension> extension = | 418 scoped_refptr<const extensions::Extension> extension = |
419 extensions::extension_action_test_util::CreateActionExtension( | 419 extensions::extension_action_test_util::CreateActionExtension( |
(...skipping 16 matching lines...) Expand all Loading... |
436 DISABLED_AddExtensionWithMenuOpen) { | 436 DISABLED_AddExtensionWithMenuOpen) { |
437 // Add an extension to ensure the overflow menu is present. | 437 // Add an extension to ensure the overflow menu is present. |
438 scoped_refptr<const extensions::Extension> extension = | 438 scoped_refptr<const extensions::Extension> extension = |
439 extensions::extension_action_test_util::CreateActionExtension( | 439 extensions::extension_action_test_util::CreateActionExtension( |
440 "original extension", | 440 "original extension", |
441 extensions::extension_action_test_util::BROWSER_ACTION); | 441 extensions::extension_action_test_util::BROWSER_ACTION); |
442 extension_service()->AddExtension(extension.get()); | 442 extension_service()->AddExtension(extension.get()); |
443 ASSERT_EQ(1, static_cast<int>(model()->toolbar_items().size())); | 443 ASSERT_EQ(1, static_cast<int>(model()->toolbar_items().size())); |
444 model()->SetVisibleIconCount(0); | 444 model()->SetVisibleIconCount(0); |
445 | 445 |
446 MoveMouseToCenter(wrenchButton()); | 446 MoveMouseToCenter(appMenuButton()); |
447 | 447 |
448 base::RunLoop runLoop; | 448 base::RunLoop runLoop; |
449 // Click on the app menu, and pass in a callback to continue the test in | 449 // Click on the app menu, and pass in a callback to continue the test in |
450 // AddExtensionWithMenuOpen (due to the blocking nature of Cocoa menus, | 450 // AddExtensionWithMenuOpen (due to the blocking nature of Cocoa menus, |
451 // passing in runLoop.QuitClosure() is not sufficient here.) | 451 // passing in runLoop.QuitClosure() is not sufficient here.) |
452 ui_controls::SendMouseEventsNotifyWhenDone( | 452 ui_controls::SendMouseEventsNotifyWhenDone( |
453 ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, | 453 ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, |
454 base::Bind(&AddExtensionWithMenuOpen, | 454 base::Bind(&AddExtensionWithMenuOpen, |
455 base::Unretained(toolbarController()), | 455 base::Unretained(toolbarController()), |
456 extension_service(), | 456 extension_service(), |
457 runLoop.QuitClosure())); | 457 runLoop.QuitClosure())); |
458 runLoop.Run(); | 458 runLoop.Run(); |
459 } | 459 } |
OLD | NEW |