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 "base/base64.h" | 5 #include "base/base64.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "content/public/browser/devtools_agent_host.h" | 10 #include "content/public/browser/devtools_agent_host.h" |
(...skipping 11 matching lines...) Expand all Loading... | |
22 namespace { | 22 namespace { |
23 | 23 |
24 const char kIdParam[] = "id"; | 24 const char kIdParam[] = "id"; |
25 const char kMethodParam[] = "method"; | 25 const char kMethodParam[] = "method"; |
26 const char kParamsParam[] = "params"; | 26 const char kParamsParam[] = "params"; |
27 | 27 |
28 } | 28 } |
29 | 29 |
30 class DevToolsProtocolTest : public ContentBrowserTest, | 30 class DevToolsProtocolTest : public ContentBrowserTest, |
31 public DevToolsAgentHostClient { | 31 public DevToolsAgentHostClient { |
32 public: | |
33 DevToolsProtocolTest() : has_dispatched_command(false) {} | |
34 | |
32 protected: | 35 protected: |
33 void SendCommand(const std::string& method, | 36 void SendCommand(const std::string& method, |
34 scoped_ptr<base::DictionaryValue> params) { | 37 scoped_ptr<base::DictionaryValue> params) { |
35 base::DictionaryValue command; | 38 base::DictionaryValue command; |
39 has_dispatched_command = false; | |
36 command.SetInteger(kIdParam, 1); | 40 command.SetInteger(kIdParam, 1); |
37 command.SetString(kMethodParam, method); | 41 command.SetString(kMethodParam, method); |
38 if (params) | 42 if (params) |
39 command.Set(kParamsParam, params.release()); | 43 command.Set(kParamsParam, params.release()); |
40 | 44 |
41 std::string json_command; | 45 std::string json_command; |
42 base::JSONWriter::Write(command, &json_command); | 46 base::JSONWriter::Write(command, &json_command); |
43 agent_host_->DispatchProtocolMessage(json_command); | 47 agent_host_->DispatchProtocolMessage(json_command); |
44 base::MessageLoop::current()->Run(); | 48 // Some messages are dispatched synchronously. |
49 // Only run loop if we are not finished yet. | |
50 if (!has_dispatched_command) | |
51 base::MessageLoop::current()->Run(); | |
45 } | 52 } |
46 | 53 |
47 bool HasValue(const std::string& path) { | 54 bool HasValue(const std::string& path) { |
48 base::Value* value = 0; | 55 base::Value* value = 0; |
49 return result_->Get(path, &value); | 56 return result_->Get(path, &value); |
50 } | 57 } |
51 | 58 |
52 bool HasListItem(const std::string& path_to_list, | 59 bool HasListItem(const std::string& path_to_list, |
53 const std::string& name, | 60 const std::string& name, |
54 const std::string& value) { | 61 const std::string& value) { |
(...skipping 28 matching lines...) Expand all Loading... | |
83 scoped_refptr<DevToolsAgentHost> agent_host_; | 90 scoped_refptr<DevToolsAgentHost> agent_host_; |
84 | 91 |
85 private: | 92 private: |
86 void DispatchProtocolMessage(DevToolsAgentHost* agent_host, | 93 void DispatchProtocolMessage(DevToolsAgentHost* agent_host, |
87 const std::string& message) override { | 94 const std::string& message) override { |
88 scoped_ptr<base::DictionaryValue> root( | 95 scoped_ptr<base::DictionaryValue> root( |
89 static_cast<base::DictionaryValue*>(base::JSONReader::Read(message))); | 96 static_cast<base::DictionaryValue*>(base::JSONReader::Read(message))); |
90 base::DictionaryValue* result; | 97 base::DictionaryValue* result; |
91 EXPECT_TRUE(root->GetDictionary("result", &result)); | 98 EXPECT_TRUE(root->GetDictionary("result", &result)); |
92 result_.reset(result->DeepCopy()); | 99 result_.reset(result->DeepCopy()); |
93 base::MessageLoop::current()->QuitNow(); | 100 if (base::MessageLoop::current()->is_running()) |
dgozman
2015/05/25 16:02:10
I probably don't understand something, but how cur
mharanczyk
2015/05/26 07:45:04
Those tests are executed from main thread startup
| |
101 base::MessageLoop::current()->QuitNow(); | |
102 has_dispatched_command = true; | |
94 } | 103 } |
95 | 104 |
96 void AgentHostClosed(DevToolsAgentHost* agent_host, bool replaced) override { | 105 void AgentHostClosed(DevToolsAgentHost* agent_host, bool replaced) override { |
97 EXPECT_TRUE(false); | 106 EXPECT_TRUE(false); |
98 } | 107 } |
108 | |
109 bool has_dispatched_command; | |
99 }; | 110 }; |
100 | 111 |
112 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, KeyEventsSynthesizeKeyIdentifier) { | |
113 GURL test_url = GetTestUrl("devtools", "synthetic_keyevent_test.html"); | |
114 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 1); | |
115 | |
116 // Send enter (keycode 13). | |
117 scoped_ptr<base::DictionaryValue> params(new base::DictionaryValue()); | |
118 params->SetString("type", "rawKeyDown"); | |
119 params->SetInteger("modifiers", 0); | |
120 params->SetInteger("windowsVirtualKeyCode", 13); | |
121 params->SetInteger("nativeVirtualKeyCode", 13); | |
122 SendCommand("Input.dispatchKeyEvent", params.Pass()); | |
123 | |
124 params.reset(new base::DictionaryValue()); | |
125 params->SetString("type", "keyUp"); | |
126 params->SetInteger("modifiers", 0); | |
127 params->SetInteger("windowsVirtualKeyCode", 13); | |
128 params->SetInteger("nativeVirtualKeyCode", 13); | |
129 SendCommand("Input.dispatchKeyEvent", params.Pass()); | |
130 | |
131 std::string keyIdentifier; | |
132 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | |
133 shell()->web_contents(), | |
134 "domAutomationController.send(" | |
135 "document.getElementById('keyDownOutput').value)", | |
136 &keyIdentifier)); | |
137 EXPECT_EQ("Enter", keyIdentifier); | |
138 | |
139 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | |
140 shell()->web_contents(), | |
141 "domAutomationController.send(" | |
142 "document.getElementById('keyUpOutput').value)", | |
143 &keyIdentifier)); | |
144 EXPECT_EQ("Enter", keyIdentifier); | |
145 | |
146 // Send escape (keycode 27). | |
147 params.reset(new base::DictionaryValue()); | |
148 params->SetString("type", "rawKeyDown"); | |
149 params->SetInteger("modifiers", 0); | |
150 params->SetInteger("windowsVirtualKeyCode", 27); | |
151 params->SetInteger("nativeVirtualKeyCode", 27); | |
152 SendCommand("Input.dispatchKeyEvent", params.Pass()); | |
153 | |
154 params.reset(new base::DictionaryValue()); | |
155 params->SetString("type", "keyUp"); | |
156 params->SetInteger("modifiers", 0); | |
157 params->SetInteger("windowsVirtualKeyCode", 27); | |
158 params->SetInteger("nativeVirtualKeyCode", 27); | |
159 SendCommand("Input.dispatchKeyEvent", params.Pass()); | |
160 | |
161 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | |
162 shell()->web_contents(), | |
163 "domAutomationController.send(" | |
164 "document.getElementById('keyDownOutput').value)", | |
165 &keyIdentifier)); | |
166 EXPECT_EQ("U+001B", keyIdentifier); | |
167 | |
168 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | |
169 shell()->web_contents(), | |
170 "domAutomationController.send(" | |
171 "document.getElementById('keyUpOutput').value)", | |
172 &keyIdentifier)); | |
173 EXPECT_EQ("U+001B", keyIdentifier); | |
174 } | |
175 | |
101 class CaptureScreenshotTest : public DevToolsProtocolTest { | 176 class CaptureScreenshotTest : public DevToolsProtocolTest { |
102 private: | 177 private: |
103 #if !defined(OS_ANDROID) | 178 #if !defined(OS_ANDROID) |
104 void SetUpCommandLine(base::CommandLine* command_line) override { | 179 void SetUpCommandLine(base::CommandLine* command_line) override { |
105 command_line->AppendSwitch(switches::kEnablePixelOutputInTests); | 180 command_line->AppendSwitch(switches::kEnablePixelOutputInTests); |
106 } | 181 } |
107 #endif | 182 #endif |
108 }; | 183 }; |
109 | 184 |
110 // Does not link on Android | 185 // Does not link on Android |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
255 // new value of |document.body.scrollTop| will depend on the screen dimensions | 330 // new value of |document.body.scrollTop| will depend on the screen dimensions |
256 // of the device that we're testing on, but in any case it should be greater | 331 // of the device that we're testing on, but in any case it should be greater |
257 // than 0. | 332 // than 0. |
258 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( | 333 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( |
259 shell()->web_contents(), | 334 shell()->web_contents(), |
260 "domAutomationController.send(document.body.scrollTop)", &scroll_top)); | 335 "domAutomationController.send(document.body.scrollTop)", &scroll_top)); |
261 ASSERT_GT(scroll_top, 0); | 336 ASSERT_GT(scroll_top, 0); |
262 } | 337 } |
263 | 338 |
264 } // namespace content | 339 } // namespace content |
OLD | NEW |