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