OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 static_cast<app_modal::JavaScriptAppModalDialog*>(dialog); | 544 static_cast<app_modal::JavaScriptAppModalDialog*>(dialog); |
545 | 545 |
546 BrowserActivationObserver activation_observer; | 546 BrowserActivationObserver activation_observer; |
547 js_dialog->native_dialog()->AcceptAppModalDialog(); | 547 js_dialog->native_dialog()->AcceptAppModalDialog(); |
548 | 548 |
549 if (popup_browser != chrome::FindLastActive()) | 549 if (popup_browser != chrome::FindLastActive()) |
550 activation_observer.WaitForActivation(); | 550 activation_observer.WaitForActivation(); |
551 ASSERT_EQ(popup_browser, chrome::FindLastActive()); | 551 ASSERT_EQ(popup_browser, chrome::FindLastActive()); |
552 } | 552 } |
553 | 553 |
554 void BuildSimpleWebKeyEvent(blink::WebInputEvent::Type type, | |
555 ui::KeyboardCode key_code, | |
556 int native_key_code, | |
557 int modifiers, | |
558 NativeWebKeyboardEvent* event) { | |
559 event->nativeKeyCode = native_key_code; | |
560 event->windowsKeyCode = key_code; | |
561 event->setKeyIdentifierFromWindowsKeyCode(); | |
562 event->type = type; | |
563 event->modifiers = modifiers; | |
564 event->isSystemKey = false; | |
565 event->timeStampSeconds = | |
566 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF(); | |
567 event->skip_in_browser = true; | |
568 | |
569 if (type == blink::WebInputEvent::Char || | |
570 type == blink::WebInputEvent::RawKeyDown) { | |
571 event->text[0] = key_code; | |
572 event->unmodifiedText[0] = key_code; | |
573 } | |
574 } | |
575 | |
576 void InjectRawKeyEvent(WebContents* web_contents, | |
577 blink::WebInputEvent::Type type, | |
578 ui::KeyboardCode key_code, | |
579 int native_key_code, | |
580 int modifiers) { | |
581 NativeWebKeyboardEvent event; | |
582 BuildSimpleWebKeyEvent(type, key_code, native_key_code, modifiers, &event); | |
583 web_contents->GetRenderViewHost()->GetWidget()->ForwardKeyboardEvent(event); | |
584 } | |
585 | |
586 // Tests that Ctrl+Enter/Cmd+Enter keys on a link open the backgournd tab. | 554 // Tests that Ctrl+Enter/Cmd+Enter keys on a link open the backgournd tab. |
587 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, CtrlEnterKey) { | 555 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, CtrlEnterKey) { |
588 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); | 556 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); |
589 | 557 |
590 GURL url(embedded_test_server()->GetURL( | 558 GURL url(embedded_test_server()->GetURL( |
591 "/popup_blocker/popup-simulated-click-on-anchor.html")); | 559 "/popup_blocker/popup-simulated-click-on-anchor.html")); |
592 ui_test_utils::NavigateToURL(browser(), url); | 560 ui_test_utils::NavigateToURL(browser(), url); |
593 | 561 |
594 content::WindowedNotificationObserver wait_for_new_tab( | 562 content::WindowedNotificationObserver wait_for_new_tab( |
595 chrome::NOTIFICATION_TAB_ADDED, | 563 chrome::NOTIFICATION_TAB_ADDED, |
596 content::NotificationService::AllSources()); | 564 content::NotificationService::AllSources()); |
597 | 565 |
| 566 bool command = false; |
598 #if defined(OS_MACOSX) | 567 #if defined(OS_MACOSX) |
599 int modifiers = blink::WebInputEvent::MetaKey; | 568 command = true; |
600 InjectRawKeyEvent( | |
601 tab, blink::WebInputEvent::RawKeyDown, ui::VKEY_COMMAND, | |
602 ui::KeycodeConverter::DomCodeToNativeKeycode(ui::DomCode::META_LEFT), | |
603 modifiers); | |
604 #else | |
605 int modifiers = blink::WebInputEvent::ControlKey; | |
606 InjectRawKeyEvent( | |
607 tab, blink::WebInputEvent::RawKeyDown, ui::VKEY_CONTROL, | |
608 ui::KeycodeConverter::DomCodeToNativeKeycode(ui::DomCode::CONTROL_LEFT), | |
609 modifiers); | |
610 #endif | 569 #endif |
611 | 570 |
612 InjectRawKeyEvent(tab, blink::WebInputEvent::RawKeyDown, ui::VKEY_RETURN, | 571 SimulateKeyPress(tab, ui::DomKey::ENTER, ui::DomCode::ENTER, ui::VKEY_RETURN, |
613 ui::KeycodeConverter::InvalidNativeKeycode(), modifiers); | 572 !command, false, false, command); |
614 | 573 |
615 InjectRawKeyEvent(tab, blink::WebInputEvent::Char, ui::VKEY_RETURN, | |
616 ui::KeycodeConverter::InvalidNativeKeycode(), modifiers); | |
617 | |
618 InjectRawKeyEvent(tab, blink::WebInputEvent::KeyUp, ui::VKEY_RETURN, | |
619 ui::KeycodeConverter::InvalidNativeKeycode(), modifiers); | |
620 | |
621 #if defined(OS_MACOSX) | |
622 InjectRawKeyEvent( | |
623 tab, blink::WebInputEvent::KeyUp, ui::VKEY_COMMAND, | |
624 ui::KeycodeConverter::DomCodeToNativeKeycode(ui::DomCode::META_LEFT), | |
625 modifiers); | |
626 #else | |
627 InjectRawKeyEvent( | |
628 tab, blink::WebInputEvent::KeyUp, ui::VKEY_CONTROL, | |
629 ui::KeycodeConverter::DomCodeToNativeKeycode(ui::DomCode::CONTROL_LEFT), | |
630 modifiers); | |
631 #endif | |
632 wait_for_new_tab.Wait(); | 574 wait_for_new_tab.Wait(); |
633 | 575 |
634 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile())); | 576 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile())); |
635 ASSERT_EQ(2, browser()->tab_strip_model()->count()); | 577 ASSERT_EQ(2, browser()->tab_strip_model()->count()); |
636 // Check that we create the background tab. | 578 // Check that we create the background tab. |
637 ASSERT_EQ(0, browser()->tab_strip_model()->active_index()); | 579 ASSERT_EQ(0, browser()->tab_strip_model()->active_index()); |
638 } | 580 } |
639 | 581 |
640 // Tests that the tapping gesture with cntl/cmd key on a link open the | 582 // Tests that the tapping gesture with cntl/cmd key on a link open the |
641 // backgournd tab. | 583 // backgournd tab. |
(...skipping 17 matching lines...) Expand all Loading... |
659 | 601 |
660 wait_for_new_tab.Wait(); | 602 wait_for_new_tab.Wait(); |
661 | 603 |
662 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile())); | 604 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile())); |
663 ASSERT_EQ(2, browser()->tab_strip_model()->count()); | 605 ASSERT_EQ(2, browser()->tab_strip_model()->count()); |
664 // Check that we create the background tab. | 606 // Check that we create the background tab. |
665 ASSERT_EQ(0, browser()->tab_strip_model()->active_index()); | 607 ASSERT_EQ(0, browser()->tab_strip_model()->active_index()); |
666 } | 608 } |
667 | 609 |
668 } // namespace | 610 } // namespace |
OLD | NEW |