| Index: content/browser/devtools/protocol/devtools_protocol_browsertest.cc
|
| diff --git a/content/browser/devtools/protocol/devtools_protocol_browsertest.cc b/content/browser/devtools/protocol/devtools_protocol_browsertest.cc
|
| index 025f6bde7541cd133d795fd085a2020b6460472d..7944e1e415528fb458943e56d1b9cd96786413d1 100644
|
| --- a/content/browser/devtools/protocol/devtools_protocol_browsertest.cc
|
| +++ b/content/browser/devtools/protocol/devtools_protocol_browsertest.cc
|
| @@ -186,13 +186,16 @@ class DevToolsProtocolTest : public ContentBrowserTest,
|
| agent_host_->DispatchProtocolMessage(this, json_command);
|
| // Some messages are dispatched synchronously.
|
| // Only run loop if we are not finished yet.
|
| - if (in_dispatch_ && wait) {
|
| - waiting_for_command_result_id_ = last_sent_id_;
|
| - base::RunLoop().Run();
|
| - }
|
| + if (in_dispatch_ && wait)
|
| + WaitForResponse();
|
| in_dispatch_ = false;
|
| }
|
|
|
| + void WaitForResponse() {
|
| + waiting_for_command_result_id_ = last_sent_id_;
|
| + base::RunLoop().Run();
|
| + }
|
| +
|
| bool HasValue(const std::string& path) {
|
| base::Value* value = 0;
|
| return result_->Get(path, &value);
|
| @@ -409,14 +412,26 @@ class SyntheticKeyEventTest : public DevToolsProtocolTest {
|
| int modifier,
|
| int windowsKeyCode,
|
| int nativeKeyCode,
|
| - const std::string& key) {
|
| + const std::string& key,
|
| + bool wait) {
|
| std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue());
|
| params->SetString("type", type);
|
| params->SetInteger("modifiers", modifier);
|
| params->SetInteger("windowsVirtualKeyCode", windowsKeyCode);
|
| params->SetInteger("nativeVirtualKeyCode", nativeKeyCode);
|
| params->SetString("key", key);
|
| - SendCommand("Input.dispatchKeyEvent", std::move(params));
|
| + SendCommand("Input.dispatchKeyEvent", std::move(params), wait);
|
| + }
|
| +};
|
| +
|
| +class SyntheticMouseEventTest : public DevToolsProtocolTest {
|
| + protected:
|
| + void SendMouseEvent(const std::string& type, int x, int y, bool wait) {
|
| + std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue());
|
| + params->SetString("type", type);
|
| + params->SetInteger("x", x);
|
| + params->SetInteger("y", y);
|
| + SendCommand("Input.dispatchMouseEvent", std::move(params), wait);
|
| }
|
| };
|
|
|
| @@ -435,8 +450,8 @@ IN_PROC_BROWSER_TEST_F(SyntheticKeyEventTest, KeyEventSynthesizeKey) {
|
| DOMMessageQueue dom_message_queue;
|
|
|
| // Send enter (keycode 13).
|
| - SendKeyEvent("rawKeyDown", 0, 13, 13, "Enter");
|
| - SendKeyEvent("keyUp", 0, 13, 13, "Enter");
|
| + SendKeyEvent("rawKeyDown", 0, 13, 13, "Enter", true);
|
| + SendKeyEvent("keyUp", 0, 13, 13, "Enter", true);
|
|
|
| std::string key;
|
| ASSERT_TRUE(dom_message_queue.WaitForMessage(&key));
|
| @@ -445,8 +460,8 @@ IN_PROC_BROWSER_TEST_F(SyntheticKeyEventTest, KeyEventSynthesizeKey) {
|
| EXPECT_EQ("\"Enter\"", key);
|
|
|
| // Send escape (keycode 27).
|
| - SendKeyEvent("rawKeyDown", 0, 27, 27, "Escape");
|
| - SendKeyEvent("keyUp", 0, 27, 27, "Escape");
|
| + SendKeyEvent("rawKeyDown", 0, 27, 27, "Escape", true);
|
| + SendKeyEvent("keyUp", 0, 27, 27, "Escape", true);
|
|
|
| ASSERT_TRUE(dom_message_queue.WaitForMessage(&key));
|
| EXPECT_EQ("\"Escape\"", key);
|
| @@ -454,6 +469,54 @@ IN_PROC_BROWSER_TEST_F(SyntheticKeyEventTest, KeyEventSynthesizeKey) {
|
| EXPECT_EQ("\"Escape\"", key);
|
| }
|
|
|
| +IN_PROC_BROWSER_TEST_F(SyntheticKeyEventTest, KeyboardEventAck) {
|
| + GURL test_url = GetTestUrl("devtools", "input_ack_tests.html");
|
| + NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 1);
|
| + Attach();
|
| +
|
| + DOMMessageQueue dom_message_queue;
|
| + scoped_refptr<InputMsgWatcher> filter = new InputMsgWatcher(
|
| + RenderWidgetHostImpl::From(
|
| + shell()->web_contents()->GetRenderViewHost()->GetWidget()),
|
| + blink::WebInputEvent::RawKeyDown);
|
| +
|
| + // Call Input.dispatchKeyEvent, but don't wait for a response.
|
| + SendKeyEvent("rawKeyDown", 0, 13, 13, "Enter", false);
|
| + // Make sure we've entered the page's keydown event listener.
|
| + std::string message;
|
| + ASSERT_TRUE(dom_message_queue.WaitForMessage(&message));
|
| + EXPECT_EQ("\"KeyboardEvent listener\"", message);
|
| + // Check that an ack was not received before the response.
|
| + ASSERT_FALSE(filter->HasReceivedAck());
|
| + // Check that an ack is received after the response.
|
| + WaitForResponse();
|
| + ASSERT_EQ(INPUT_EVENT_ACK_STATE_NOT_CONSUMED, filter->WaitForAck());
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(SyntheticMouseEventTest, MouseEventAck) {
|
| + GURL test_url = GetTestUrl("devtools", "input_ack_tests.html");
|
| + NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 1);
|
| + Attach();
|
| +
|
| + DOMMessageQueue dom_message_queue;
|
| + scoped_refptr<InputMsgWatcher> filter = new InputMsgWatcher(
|
| + RenderWidgetHostImpl::From(
|
| + shell()->web_contents()->GetRenderViewHost()->GetWidget()),
|
| + blink::WebInputEvent::MouseMove);
|
| +
|
| + // Call Input.dispatchMouseEvent, but don't wait for a response.
|
| + SendMouseEvent("mouseMoved", 15, 15, false);
|
| + // Make sure we've entered the page's keydown event listener.
|
| + std::string message;
|
| + ASSERT_TRUE(dom_message_queue.WaitForMessage(&message));
|
| + EXPECT_EQ("\"MouseEvent listener\"", message);
|
| + // Check that an ack was not received before the response.
|
| + ASSERT_FALSE(filter->HasReceivedAck());
|
| + // Check that an ack is received after the response.
|
| + WaitForResponse();
|
| + ASSERT_EQ(INPUT_EVENT_ACK_STATE_CONSUMED, filter->WaitForAck());
|
| +}
|
| +
|
| namespace {
|
| bool DecodePNG(std::string base64_data, SkBitmap* bitmap) {
|
| std::string png_data;
|
|
|