Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Side by Side Diff: chrome/browser/ui/blocked_content/popup_blocker_browsertest.cc

Issue 877513002: Add a test for a simulated click on a link. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/test/data/popup_blocker/popup-simulated-click-on-anchor.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/files/file_path.h" 6 #include "base/files/file_path.h"
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/chrome_notification_types.h" 10 #include "chrome/browser/chrome_notification_types.h"
(...skipping 13 matching lines...) Expand all
24 #include "chrome/common/chrome_paths.h" 24 #include "chrome/common/chrome_paths.h"
25 #include "chrome/common/chrome_switches.h" 25 #include "chrome/common/chrome_switches.h"
26 #include "chrome/test/base/in_process_browser_test.h" 26 #include "chrome/test/base/in_process_browser_test.h"
27 #include "chrome/test/base/test_switches.h" 27 #include "chrome/test/base/test_switches.h"
28 #include "chrome/test/base/ui_test_utils.h" 28 #include "chrome/test/base/ui_test_utils.h"
29 #include "components/app_modal/javascript_app_modal_dialog.h" 29 #include "components/app_modal/javascript_app_modal_dialog.h"
30 #include "components/app_modal/native_app_modal_dialog.h" 30 #include "components/app_modal/native_app_modal_dialog.h"
31 #include "components/content_settings/core/browser/host_content_settings_map.h" 31 #include "components/content_settings/core/browser/host_content_settings_map.h"
32 #include "components/omnibox/autocomplete_match.h" 32 #include "components/omnibox/autocomplete_match.h"
33 #include "components/omnibox/autocomplete_result.h" 33 #include "components/omnibox/autocomplete_result.h"
34 #include "content/public/browser/native_web_keyboard_event.h"
34 #include "content/public/browser/navigation_controller.h" 35 #include "content/public/browser/navigation_controller.h"
35 #include "content/public/browser/notification_registrar.h" 36 #include "content/public/browser/notification_registrar.h"
36 #include "content/public/browser/notification_service.h" 37 #include "content/public/browser/notification_service.h"
37 #include "content/public/browser/render_frame_host.h" 38 #include "content/public/browser/render_frame_host.h"
39 #include "content/public/browser/render_view_host.h"
38 #include "content/public/browser/web_contents.h" 40 #include "content/public/browser/web_contents.h"
39 #include "content/public/browser/web_contents_observer.h" 41 #include "content/public/browser/web_contents_observer.h"
40 #include "content/public/common/url_constants.h" 42 #include "content/public/common/url_constants.h"
41 #include "content/public/test/browser_test_utils.h" 43 #include "content/public/test/browser_test_utils.h"
42 #include "content/public/test/test_navigation_observer.h" 44 #include "content/public/test/test_navigation_observer.h"
43 #include "net/dns/mock_host_resolver.h" 45 #include "net/dns/mock_host_resolver.h"
44 #include "net/test/embedded_test_server/embedded_test_server.h" 46 #include "net/test/embedded_test_server/embedded_test_server.h"
45 #include "testing/gtest/include/gtest/gtest.h" 47 #include "testing/gtest/include/gtest/gtest.h"
48 #include "ui/events/keycodes/dom4/keycode_converter.h"
46 49
47 using content::WebContents; 50 using content::WebContents;
51 using content::NativeWebKeyboardEvent;
48 52
49 namespace { 53 namespace {
50 54
51 // Counts the number of RenderViewHosts created. 55 // Counts the number of RenderViewHosts created.
52 class CountRenderViewHosts : public content::NotificationObserver { 56 class CountRenderViewHosts : public content::NotificationObserver {
53 public: 57 public:
54 CountRenderViewHosts() 58 CountRenderViewHosts()
55 : count_(0) { 59 : count_(0) {
56 registrar_.Add(this, 60 registrar_.Add(this,
57 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, 61 content::NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 js_dialog->native_dialog()->AcceptAppModalDialog(); 586 js_dialog->native_dialog()->AcceptAppModalDialog();
583 587
584 if (popup_browser != chrome::FindLastActiveWithHostDesktopType( 588 if (popup_browser != chrome::FindLastActiveWithHostDesktopType(
585 popup_browser->host_desktop_type())) { 589 popup_browser->host_desktop_type())) {
586 activation_observer.WaitForActivation(); 590 activation_observer.WaitForActivation();
587 } 591 }
588 ASSERT_EQ(popup_browser, chrome::FindLastActiveWithHostDesktopType( 592 ASSERT_EQ(popup_browser, chrome::FindLastActiveWithHostDesktopType(
589 popup_browser->host_desktop_type())); 593 popup_browser->host_desktop_type()));
590 } 594 }
591 595
596 void BuildSimpleWebKeyEvent(blink::WebInputEvent::Type type,
597 ui::KeyboardCode key_code,
598 int native_key_code,
599 int modifiers,
600 NativeWebKeyboardEvent* event) {
601 event->nativeKeyCode = native_key_code;
602 event->windowsKeyCode = key_code;
603 event->setKeyIdentifierFromWindowsKeyCode();
604 event->type = type;
605 event->modifiers = modifiers;
606 event->isSystemKey = false;
607 event->timeStampSeconds = base::Time::Now().ToDoubleT();
608 event->skip_in_browser = true;
609
610 if (type == blink::WebInputEvent::Char ||
611 type == blink::WebInputEvent::RawKeyDown) {
612 event->text[0] = key_code;
613 event->unmodifiedText[0] = key_code;
614 }
615 }
616
617 void InjectRawKeyEvent(WebContents* web_contents,
618 blink::WebInputEvent::Type type,
619 ui::KeyboardCode key_code,
620 int native_key_code,
621 int modifiers) {
622 NativeWebKeyboardEvent event;
623 BuildSimpleWebKeyEvent(type, key_code, native_key_code, modifiers, &event);
624 web_contents->GetRenderViewHost()->ForwardKeyboardEvent(event);
625 }
626
627 // Tests that Ctrl+Enter/Cmd+Enter keys on a link open the backgournd tab.
628 IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, CtrlEnterKey) {
629 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
630
631 GURL url(embedded_test_server()->GetURL(
632 "/popup_blocker/popup-simulated-click-on-anchor.html"));
633 ui_test_utils::NavigateToURL(browser(), url);
634
635 content::WindowedNotificationObserver wait_for_new_tab(
636 chrome::NOTIFICATION_TAB_ADDED,
637 content::NotificationService::AllSources());
638
639 #if defined(OS_MACOSX)
640 int modifiers = blink::WebInputEvent::MetaKey;
641 InjectRawKeyEvent(tab, blink::WebInputEvent::RawKeyDown, ui::VKEY_COMMAND,
642 ui::KeycodeConverter::CodeToNativeKeycode("OSLeft"),
643 modifiers);
644 #else
645 int modifiers = blink::WebInputEvent::ControlKey;
646 InjectRawKeyEvent(tab, blink::WebInputEvent::RawKeyDown, ui::VKEY_CONTROL,
647 ui::KeycodeConverter::CodeToNativeKeycode("ControlLeft"),
648 modifiers);
649 #endif
650
651 InjectRawKeyEvent(tab, blink::WebInputEvent::RawKeyDown, ui::VKEY_RETURN,
652 ui::KeycodeConverter::CodeToNativeKeycode(NULL), modifiers);
653
654 InjectRawKeyEvent(tab, blink::WebInputEvent::Char, ui::VKEY_RETURN,
655 ui::KeycodeConverter::CodeToNativeKeycode(NULL), modifiers);
656
657 InjectRawKeyEvent(tab, blink::WebInputEvent::KeyUp, ui::VKEY_RETURN,
658 ui::KeycodeConverter::CodeToNativeKeycode(NULL), modifiers);
659
660 #if defined(OS_MACOSX)
661 InjectRawKeyEvent(tab, blink::WebInputEvent::KeyUp, ui::VKEY_COMMAND,
662 ui::KeycodeConverter::CodeToNativeKeycode("OSLeft"),
663 modifiers);
664 #else
665 InjectRawKeyEvent(tab, blink::WebInputEvent::KeyUp, ui::VKEY_CONTROL,
666 ui::KeycodeConverter::CodeToNativeKeycode("ControlLeft"),
667 modifiers);
668 #endif
669
670 wait_for_new_tab.Wait();
671
672 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile(),
673 browser()->host_desktop_type()));
674 ASSERT_EQ(2, browser()->tab_strip_model()->count());
675 // Check that we create the background tab.
676 ASSERT_EQ(0, browser()->tab_strip_model()->active_index());
677 }
678
592 } // namespace 679 } // namespace
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/popup_blocker/popup-simulated-click-on-anchor.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698