| 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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 base::scoped_nsobject<MenuWatcher> menuWatcher( | 523 base::scoped_nsobject<MenuWatcher> menuWatcher( |
| 524 [[MenuWatcher alloc] initWithController:appMenuController()]); | 524 [[MenuWatcher alloc] initWithController:appMenuController()]); |
| 525 [menuWatcher setOpenClosure: | 525 [menuWatcher setOpenClosure: |
| 526 base::Bind(&AddExtensionWithMenuOpen, | 526 base::Bind(&AddExtensionWithMenuOpen, |
| 527 base::Unretained(toolbarController()), extension_service(), | 527 base::Unretained(toolbarController()), extension_service(), |
| 528 runLoop.QuitClosure())]; | 528 runLoop.QuitClosure())]; |
| 529 ui_controls::SendMouseEvents(ui_controls::LEFT, | 529 ui_controls::SendMouseEvents(ui_controls::LEFT, |
| 530 ui_controls::DOWN | ui_controls::UP); | 530 ui_controls::DOWN | ui_controls::UP); |
| 531 runLoop.Run(); | 531 runLoop.Run(); |
| 532 } | 532 } |
| 533 |
| 534 // Test that activating an action that doesn't want to run on the page via the |
| 535 // mouse and the keyboard works. |
| 536 IN_PROC_BROWSER_TEST_F(BrowserActionButtonUiTest, |
| 537 OpenMenuOnDisabledActionWithMouseOrKeyboard) { |
| 538 // Add an extension with a page action. |
| 539 scoped_refptr<const extensions::Extension> extension = |
| 540 extensions::extension_action_test_util::CreateActionExtension( |
| 541 "page action", extensions::extension_action_test_util::PAGE_ACTION); |
| 542 extension_service()->AddExtension(extension.get()); |
| 543 ASSERT_EQ(1u, model()->toolbar_items().size()); |
| 544 |
| 545 BrowserActionsController* actionsController = |
| 546 [toolbarController() browserActionsController]; |
| 547 BrowserActionButton* actionButton = [actionsController buttonWithIndex:0]; |
| 548 ASSERT_TRUE(actionButton); |
| 549 |
| 550 // Stub out the action button's normal context menu with a fake one so we |
| 551 // can track when it opens. |
| 552 base::scoped_nsobject<NSMenu> testContextMenu( |
| 553 [[NSMenu alloc] initWithTitle:@""]); |
| 554 base::scoped_nsobject<MenuHelper> menuHelper([[MenuHelper alloc] init]); |
| 555 [testContextMenu setDelegate:menuHelper.get()]; |
| 556 [actionButton setTestContextMenu:testContextMenu.get()]; |
| 557 |
| 558 // The button should be attached. |
| 559 EXPECT_TRUE([actionButton superview]); |
| 560 |
| 561 // Move the mouse and click on the button. The menu should open. |
| 562 MoveMouseToCenter(actionButton); |
| 563 { |
| 564 EXPECT_FALSE([menuHelper menuOpened]); |
| 565 base::RunLoop runLoop; |
| 566 ui_controls::SendMouseEventsNotifyWhenDone( |
| 567 ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, |
| 568 runLoop.QuitClosure()); |
| 569 runLoop.Run(); |
| 570 EXPECT_TRUE([menuHelper menuOpened]); |
| 571 } |
| 572 |
| 573 // Reset the menu helper so we can use it again. |
| 574 [menuHelper setMenuOpened:NO]; |
| 575 |
| 576 // Send the 'space' key to the button with it as the first responder. The menu |
| 577 // should open. |
| 578 [[actionButton window] makeFirstResponder:actionButton]; |
| 579 EXPECT_TRUE([[actionButton window] firstResponder] == actionButton); |
| 580 { |
| 581 EXPECT_FALSE([menuHelper menuOpened]); |
| 582 base::RunLoop runLoop; |
| 583 ui_controls::SendKeyPressNotifyWhenDone([actionButton window], |
| 584 ui::VKEY_SPACE, false, false, false, |
| 585 false, runLoop.QuitClosure()); |
| 586 runLoop.Run(); |
| 587 EXPECT_TRUE([menuHelper menuOpened]); |
| 588 } |
| 589 } |
| OLD | NEW |