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

Unified 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, 11 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/blocked_content/popup_blocker_browsertest.cc
diff --git a/chrome/browser/ui/blocked_content/popup_blocker_browsertest.cc b/chrome/browser/ui/blocked_content/popup_blocker_browsertest.cc
index fe3685670fdfa63c85d1a3b29c602f02afc1cf41..c890d6adf0883cc09662d1348b59af92edc4be29 100644
--- a/chrome/browser/ui/blocked_content/popup_blocker_browsertest.cc
+++ b/chrome/browser/ui/blocked_content/popup_blocker_browsertest.cc
@@ -31,10 +31,12 @@
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/omnibox/autocomplete_match.h"
#include "components/omnibox/autocomplete_result.h"
+#include "content/public/browser/native_web_keyboard_event.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/render_frame_host.h"
+#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/common/url_constants.h"
@@ -43,8 +45,10 @@
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/events/keycodes/dom4/keycode_converter.h"
using content::WebContents;
+using content::NativeWebKeyboardEvent;
namespace {
@@ -589,4 +593,87 @@ IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, ModalPopUnder) {
popup_browser->host_desktop_type()));
}
+void BuildSimpleWebKeyEvent(blink::WebInputEvent::Type type,
+ ui::KeyboardCode key_code,
+ int native_key_code,
+ int modifiers,
+ NativeWebKeyboardEvent* event) {
+ event->nativeKeyCode = native_key_code;
+ event->windowsKeyCode = key_code;
+ event->setKeyIdentifierFromWindowsKeyCode();
+ event->type = type;
+ event->modifiers = modifiers;
+ event->isSystemKey = false;
+ event->timeStampSeconds = base::Time::Now().ToDoubleT();
+ event->skip_in_browser = true;
+
+ if (type == blink::WebInputEvent::Char ||
+ type == blink::WebInputEvent::RawKeyDown) {
+ event->text[0] = key_code;
+ event->unmodifiedText[0] = key_code;
+ }
+}
+
+void InjectRawKeyEvent(WebContents* web_contents,
+ blink::WebInputEvent::Type type,
+ ui::KeyboardCode key_code,
+ int native_key_code,
+ int modifiers) {
+ NativeWebKeyboardEvent event;
+ BuildSimpleWebKeyEvent(type, key_code, native_key_code, modifiers, &event);
+ web_contents->GetRenderViewHost()->ForwardKeyboardEvent(event);
+}
+
+// Tests that Ctrl+Enter/Cmd+Enter keys on a link open the backgournd tab.
+IN_PROC_BROWSER_TEST_F(PopupBlockerBrowserTest, CtrlEnterKey) {
+ WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
+
+ GURL url(embedded_test_server()->GetURL(
+ "/popup_blocker/popup-simulated-click-on-anchor.html"));
+ ui_test_utils::NavigateToURL(browser(), url);
+
+ content::WindowedNotificationObserver wait_for_new_tab(
+ chrome::NOTIFICATION_TAB_ADDED,
+ content::NotificationService::AllSources());
+
+#if defined(OS_MACOSX)
+ int modifiers = blink::WebInputEvent::MetaKey;
+ InjectRawKeyEvent(tab, blink::WebInputEvent::RawKeyDown, ui::VKEY_COMMAND,
+ ui::KeycodeConverter::CodeToNativeKeycode("OSLeft"),
+ modifiers);
+#else
+ int modifiers = blink::WebInputEvent::ControlKey;
+ InjectRawKeyEvent(tab, blink::WebInputEvent::RawKeyDown, ui::VKEY_CONTROL,
+ ui::KeycodeConverter::CodeToNativeKeycode("ControlLeft"),
+ modifiers);
+#endif
+
+ InjectRawKeyEvent(tab, blink::WebInputEvent::RawKeyDown, ui::VKEY_RETURN,
+ ui::KeycodeConverter::CodeToNativeKeycode(NULL), modifiers);
+
+ InjectRawKeyEvent(tab, blink::WebInputEvent::Char, ui::VKEY_RETURN,
+ ui::KeycodeConverter::CodeToNativeKeycode(NULL), modifiers);
+
+ InjectRawKeyEvent(tab, blink::WebInputEvent::KeyUp, ui::VKEY_RETURN,
+ ui::KeycodeConverter::CodeToNativeKeycode(NULL), modifiers);
+
+#if defined(OS_MACOSX)
+ InjectRawKeyEvent(tab, blink::WebInputEvent::KeyUp, ui::VKEY_COMMAND,
+ ui::KeycodeConverter::CodeToNativeKeycode("OSLeft"),
+ modifiers);
+#else
+ InjectRawKeyEvent(tab, blink::WebInputEvent::KeyUp, ui::VKEY_CONTROL,
+ ui::KeycodeConverter::CodeToNativeKeycode("ControlLeft"),
+ modifiers);
+#endif
+
+ wait_for_new_tab.Wait();
+
+ ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile(),
+ browser()->host_desktop_type()));
+ ASSERT_EQ(2, browser()->tab_strip_model()->count());
+ // Check that we create the background tab.
+ ASSERT_EQ(0, browser()->tab_strip_model()->active_index());
+}
+
} // namespace
« 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