| 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 "chrome/browser/ui/cocoa/extensions/browser_action_button.h" | 5 #import "chrome/browser/ui/cocoa/extensions/browser_action_button.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 } | 270 } |
| 271 | 271 |
| 272 // Verifies that the action is "popped out" of overflow; that is, it is visible | 272 // Verifies that the action is "popped out" of overflow; that is, it is visible |
| 273 // on the main bar, and is set as the popped out action on the controlling | 273 // on the main bar, and is set as the popped out action on the controlling |
| 274 // ToolbarActionsBar. | 274 // ToolbarActionsBar. |
| 275 void CheckActionIsPoppedOut(BrowserActionsController* actionsController, | 275 void CheckActionIsPoppedOut(BrowserActionsController* actionsController, |
| 276 BrowserActionButton* actionButton) { | 276 BrowserActionButton* actionButton) { |
| 277 EXPECT_EQ([actionsController containerView], [actionButton superview]); | 277 EXPECT_EQ([actionsController containerView], [actionButton superview]); |
| 278 EXPECT_EQ([actionButton viewController], | 278 EXPECT_EQ([actionButton viewController], |
| 279 [actionsController toolbarActionsBar]->popped_out_action()); | 279 [actionsController toolbarActionsBar]->popped_out_action()); |
| 280 // Since the button is popped out for a popup or context menu, it should be |
| 281 // highlighted. |
| 282 EXPECT_TRUE([actionButton isHighlighted]); |
| 280 } | 283 } |
| 281 | 284 |
| 282 // Test that opening a context menu works for both actions on the main bar and | 285 // Test that opening a context menu works for both actions on the main bar and |
| 283 // actions in the overflow menu. | 286 // actions in the overflow menu. |
| 284 IN_PROC_BROWSER_TEST_F(BrowserActionButtonUiTest, | 287 IN_PROC_BROWSER_TEST_F(BrowserActionButtonUiTest, |
| 285 ContextMenusOnMainAndOverflow) { | 288 ContextMenusOnMainAndOverflow) { |
| 286 // Add an extension with a browser action. | 289 // Add an extension with a browser action. |
| 287 scoped_refptr<const extensions::Extension> extension = | 290 scoped_refptr<const extensions::Extension> extension = |
| 288 extensions::extension_action_test_util::CreateActionExtension( | 291 extensions::extension_action_test_util::CreateActionExtension( |
| 289 "browser_action", | 292 "browser_action", |
| (...skipping 24 matching lines...) Expand all Loading... |
| 314 // No menu should yet be open. | 317 // No menu should yet be open. |
| 315 EXPECT_FALSE([menuHelper menuOpened]); | 318 EXPECT_FALSE([menuHelper menuOpened]); |
| 316 base::RunLoop runLoop; | 319 base::RunLoop runLoop; |
| 317 ui_controls::SendMouseEventsNotifyWhenDone( | 320 ui_controls::SendMouseEventsNotifyWhenDone( |
| 318 ui_controls::RIGHT, | 321 ui_controls::RIGHT, |
| 319 ui_controls::DOWN | ui_controls::UP, | 322 ui_controls::DOWN | ui_controls::UP, |
| 320 runLoop.QuitClosure()); | 323 runLoop.QuitClosure()); |
| 321 runLoop.Run(); | 324 runLoop.Run(); |
| 322 // The menu should have opened from the click. | 325 // The menu should have opened from the click. |
| 323 EXPECT_TRUE([menuHelper menuOpened]); | 326 EXPECT_TRUE([menuHelper menuOpened]); |
| 327 EXPECT_FALSE([actionButton isHighlighted]); |
| 324 } | 328 } |
| 325 | 329 |
| 326 // Reset the menu helper so we can use it again. | 330 // Reset the menu helper so we can use it again. |
| 327 [menuHelper setMenuOpened:NO]; | 331 [menuHelper setMenuOpened:NO]; |
| 328 [menuHelper setVerify:base::Bind( | 332 [menuHelper setVerify:base::Bind( |
| 329 CheckActionIsPoppedOut, actionsController, actionButton)]; | 333 CheckActionIsPoppedOut, actionsController, actionButton)]; |
| 330 | 334 |
| 331 // Shrink the visible count to be 0. This should hide the action button. | 335 // Shrink the visible count to be 0. This should hide the action button. |
| 332 model()->SetVisibleIconCount(0); | 336 model()->SetVisibleIconCount(0); |
| 333 EXPECT_EQ(nil, [actionButton superview]); | 337 EXPECT_EQ(nil, [actionButton superview]); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 349 base::Unretained(toolbarController()), | 353 base::Unretained(toolbarController()), |
| 350 runLoop.QuitClosure())]; | 354 runLoop.QuitClosure())]; |
| 351 ui_controls::SendMouseEvents(ui_controls::LEFT, | 355 ui_controls::SendMouseEvents(ui_controls::LEFT, |
| 352 ui_controls::DOWN | ui_controls::UP); | 356 ui_controls::DOWN | ui_controls::UP); |
| 353 runLoop.Run(); | 357 runLoop.Run(); |
| 354 | 358 |
| 355 // The menu should have opened. Note that the menu opened on the main bar's | 359 // The menu should have opened. Note that the menu opened on the main bar's |
| 356 // action button, not the overflow's. Since Cocoa doesn't support running | 360 // action button, not the overflow's. Since Cocoa doesn't support running |
| 357 // a menu-within-a-menu, this is what has to happen. | 361 // a menu-within-a-menu, this is what has to happen. |
| 358 EXPECT_TRUE([menuHelper menuOpened]); | 362 EXPECT_TRUE([menuHelper menuOpened]); |
| 363 EXPECT_FALSE([actionButton isHighlighted]); |
| 359 } | 364 } |
| 360 } | 365 } |
| 361 | 366 |
| 362 // Checks the layout of the overflow bar in the app menu. | 367 // Checks the layout of the overflow bar in the app menu. |
| 363 void CheckAppMenuLayout(ToolbarController* toolbarController, | 368 void CheckAppMenuLayout(ToolbarController* toolbarController, |
| 364 int overflowStartIndex, | 369 int overflowStartIndex, |
| 365 const std::string& error_message, | 370 const std::string& error_message, |
| 366 const base::Closure& closure) { | 371 const base::Closure& closure) { |
| 367 AppMenuController* appMenuController = | 372 AppMenuController* appMenuController = |
| 368 [toolbarController appMenuController]; | 373 [toolbarController appMenuController]; |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 { | 590 { |
| 586 EXPECT_FALSE([menuHelper menuOpened]); | 591 EXPECT_FALSE([menuHelper menuOpened]); |
| 587 base::RunLoop runLoop; | 592 base::RunLoop runLoop; |
| 588 ui_controls::SendKeyPressNotifyWhenDone([actionButton window], | 593 ui_controls::SendKeyPressNotifyWhenDone([actionButton window], |
| 589 ui::VKEY_SPACE, false, false, false, | 594 ui::VKEY_SPACE, false, false, false, |
| 590 false, runLoop.QuitClosure()); | 595 false, runLoop.QuitClosure()); |
| 591 runLoop.Run(); | 596 runLoop.Run(); |
| 592 EXPECT_TRUE([menuHelper menuOpened]); | 597 EXPECT_TRUE([menuHelper menuOpened]); |
| 593 } | 598 } |
| 594 } | 599 } |
| OLD | NEW |