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 <stddef.h> | 5 #include <stddef.h> |
6 #include <utility> | 6 #include <utility> |
7 | 7 |
8 #include "base/base64.h" | 8 #include "base/base64.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 std::string waiting_for_notification_; | 215 std::string waiting_for_notification_; |
216 int waiting_for_command_result_id_; | 216 int waiting_for_command_result_id_; |
217 bool in_dispatch_; | 217 bool in_dispatch_; |
218 }; | 218 }; |
219 | 219 |
220 class SyntheticKeyEventTest : public DevToolsProtocolTest { | 220 class SyntheticKeyEventTest : public DevToolsProtocolTest { |
221 protected: | 221 protected: |
222 void SendKeyEvent(const std::string& type, | 222 void SendKeyEvent(const std::string& type, |
223 int modifier, | 223 int modifier, |
224 int windowsKeyCode, | 224 int windowsKeyCode, |
225 int nativeKeyCode) { | 225 int nativeKeyCode, |
| 226 const std::string& key) { |
226 std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue()); | 227 std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue()); |
227 params->SetString("type", type); | 228 params->SetString("type", type); |
228 params->SetInteger("modifiers", modifier); | 229 params->SetInteger("modifiers", modifier); |
229 params->SetInteger("windowsVirtualKeyCode", windowsKeyCode); | 230 params->SetInteger("windowsVirtualKeyCode", windowsKeyCode); |
230 params->SetInteger("nativeVirtualKeyCode", nativeKeyCode); | 231 params->SetInteger("nativeVirtualKeyCode", nativeKeyCode); |
| 232 params->SetString("key", key); |
231 SendCommand("Input.dispatchKeyEvent", std::move(params)); | 233 SendCommand("Input.dispatchKeyEvent", std::move(params)); |
232 } | 234 } |
233 }; | 235 }; |
234 | 236 |
235 IN_PROC_BROWSER_TEST_F(SyntheticKeyEventTest, KeyEventSynthesizeKeyIdentifier) { | 237 IN_PROC_BROWSER_TEST_F(SyntheticKeyEventTest, KeyEventSynthesizeKey) { |
236 NavigateToURLBlockUntilNavigationsComplete(shell(), GURL("about:blank"), 1); | 238 NavigateToURLBlockUntilNavigationsComplete(shell(), GURL("about:blank"), 1); |
237 Attach(); | 239 Attach(); |
238 ASSERT_TRUE(content::ExecuteScript( | 240 ASSERT_TRUE(content::ExecuteScript( |
239 shell()->web_contents()->GetRenderViewHost(), | 241 shell()->web_contents()->GetRenderViewHost(), |
240 "function handleKeyEvent(event) {" | 242 "function handleKeyEvent(event) {" |
241 "domAutomationController.setAutomationId(0);" | 243 "domAutomationController.setAutomationId(0);" |
242 "domAutomationController.send(event.keyIdentifier);" | 244 "domAutomationController.send(event.key);" |
243 "}" | 245 "}" |
244 "document.body.addEventListener('keydown', handleKeyEvent);" | 246 "document.body.addEventListener('keydown', handleKeyEvent);" |
245 "document.body.addEventListener('keyup', handleKeyEvent);")); | 247 "document.body.addEventListener('keyup', handleKeyEvent);")); |
246 | 248 |
247 DOMMessageQueue dom_message_queue; | 249 DOMMessageQueue dom_message_queue; |
248 | 250 |
249 // Send enter (keycode 13). | 251 // Send enter (keycode 13). |
250 SendKeyEvent("rawKeyDown", 0, 13, 13); | 252 SendKeyEvent("rawKeyDown", 0, 13, 13, "Enter"); |
251 SendKeyEvent("keyUp", 0, 13, 13); | 253 SendKeyEvent("keyUp", 0, 13, 13, "Enter"); |
252 | 254 |
253 std::string key_identifier; | 255 std::string key; |
254 ASSERT_TRUE(dom_message_queue.WaitForMessage(&key_identifier)); | 256 ASSERT_TRUE(dom_message_queue.WaitForMessage(&key)); |
255 EXPECT_EQ("\"Enter\"", key_identifier); | 257 EXPECT_EQ("\"Enter\"", key); |
256 ASSERT_TRUE(dom_message_queue.WaitForMessage(&key_identifier)); | 258 ASSERT_TRUE(dom_message_queue.WaitForMessage(&key)); |
257 EXPECT_EQ("\"Enter\"", key_identifier); | 259 EXPECT_EQ("\"Enter\"", key); |
258 | 260 |
259 // Send escape (keycode 27). | 261 // Send escape (keycode 27). |
260 SendKeyEvent("rawKeyDown", 0, 27, 27); | 262 SendKeyEvent("rawKeyDown", 0, 27, 27, "Escape"); |
261 SendKeyEvent("keyUp", 0, 27, 27); | 263 SendKeyEvent("keyUp", 0, 27, 27, "Escape"); |
262 | 264 |
263 ASSERT_TRUE(dom_message_queue.WaitForMessage(&key_identifier)); | 265 ASSERT_TRUE(dom_message_queue.WaitForMessage(&key)); |
264 EXPECT_EQ("\"U+001B\"", key_identifier); | 266 EXPECT_EQ("\"Escape\"", key); |
265 ASSERT_TRUE(dom_message_queue.WaitForMessage(&key_identifier)); | 267 ASSERT_TRUE(dom_message_queue.WaitForMessage(&key)); |
266 EXPECT_EQ("\"U+001B\"", key_identifier); | 268 EXPECT_EQ("\"Escape\"", key); |
267 } | 269 } |
268 | 270 |
269 class CaptureScreenshotTest : public DevToolsProtocolTest { | 271 class CaptureScreenshotTest : public DevToolsProtocolTest { |
270 private: | 272 private: |
271 #if !defined(OS_ANDROID) | 273 #if !defined(OS_ANDROID) |
272 void SetUpCommandLine(base::CommandLine* command_line) override { | 274 void SetUpCommandLine(base::CommandLine* command_line) override { |
273 command_line->AppendSwitch(switches::kEnablePixelOutputInTests); | 275 command_line->AppendSwitch(switches::kEnablePixelOutputInTests); |
274 } | 276 } |
275 #endif | 277 #endif |
276 }; | 278 }; |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 shell()->web_contents()->SetDelegate(&dialog_manager); | 580 shell()->web_contents()->SetDelegate(&dialog_manager); |
579 SendCommand("Page.enable", nullptr, true); | 581 SendCommand("Page.enable", nullptr, true); |
580 std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue()); | 582 std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue()); |
581 params->SetString("expression", "alert('alert')"); | 583 params->SetString("expression", "alert('alert')"); |
582 SendCommand("Runtime.evaluate", std::move(params), false); | 584 SendCommand("Runtime.evaluate", std::move(params), false); |
583 WaitForNotification("Page.javascriptDialogOpening"); | 585 WaitForNotification("Page.javascriptDialogOpening"); |
584 dialog_manager.Handle(); | 586 dialog_manager.Handle(); |
585 } | 587 } |
586 | 588 |
587 } // namespace content | 589 } // namespace content |
OLD | NEW |