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 29 matching lines...) Expand all Loading... |
40 public DevToolsAgentHostClient { | 40 public DevToolsAgentHostClient { |
41 public: | 41 public: |
42 DevToolsProtocolTest() | 42 DevToolsProtocolTest() |
43 : last_sent_id_(0), | 43 : last_sent_id_(0), |
44 waiting_for_command_result_id_(0), | 44 waiting_for_command_result_id_(0), |
45 in_dispatch_(false) { | 45 in_dispatch_(false) { |
46 } | 46 } |
47 | 47 |
48 protected: | 48 protected: |
49 void SendCommand(const std::string& method, | 49 void SendCommand(const std::string& method, |
50 scoped_ptr<base::DictionaryValue> params) { | 50 std::unique_ptr<base::DictionaryValue> params) { |
51 SendCommand(method, std::move(params), true); | 51 SendCommand(method, std::move(params), true); |
52 } | 52 } |
53 | 53 |
54 void SendCommand(const std::string& method, | 54 void SendCommand(const std::string& method, |
55 scoped_ptr<base::DictionaryValue> params, | 55 std::unique_ptr<base::DictionaryValue> params, |
56 bool wait) { | 56 bool wait) { |
57 in_dispatch_ = true; | 57 in_dispatch_ = true; |
58 base::DictionaryValue command; | 58 base::DictionaryValue command; |
59 command.SetInteger(kIdParam, ++last_sent_id_); | 59 command.SetInteger(kIdParam, ++last_sent_id_); |
60 command.SetString(kMethodParam, method); | 60 command.SetString(kMethodParam, method); |
61 if (params) | 61 if (params) |
62 command.Set(kParamsParam, params.release()); | 62 command.Set(kParamsParam, params.release()); |
63 | 63 |
64 std::string json_command; | 64 std::string json_command; |
65 base::JSONWriter::Write(command, &json_command); | 65 base::JSONWriter::Write(command, &json_command); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 agent_host_->DetachClient(); | 108 agent_host_->DetachClient(); |
109 agent_host_ = nullptr; | 109 agent_host_ = nullptr; |
110 } | 110 } |
111 } | 111 } |
112 | 112 |
113 void WaitForNotification(const std::string& notification) { | 113 void WaitForNotification(const std::string& notification) { |
114 waiting_for_notification_ = notification; | 114 waiting_for_notification_ = notification; |
115 RunMessageLoop(); | 115 RunMessageLoop(); |
116 } | 116 } |
117 | 117 |
118 scoped_ptr<base::DictionaryValue> result_; | 118 std::unique_ptr<base::DictionaryValue> result_; |
119 scoped_refptr<DevToolsAgentHost> agent_host_; | 119 scoped_refptr<DevToolsAgentHost> agent_host_; |
120 int last_sent_id_; | 120 int last_sent_id_; |
121 std::vector<int> result_ids_; | 121 std::vector<int> result_ids_; |
122 std::vector<std::string> notifications_; | 122 std::vector<std::string> notifications_; |
123 | 123 |
124 private: | 124 private: |
125 void DispatchProtocolMessage(DevToolsAgentHost* agent_host, | 125 void DispatchProtocolMessage(DevToolsAgentHost* agent_host, |
126 const std::string& message) override { | 126 const std::string& message) override { |
127 scoped_ptr<base::DictionaryValue> root(static_cast<base::DictionaryValue*>( | 127 std::unique_ptr<base::DictionaryValue> root( |
128 base::JSONReader::Read(message).release())); | 128 static_cast<base::DictionaryValue*>( |
| 129 base::JSONReader::Read(message).release())); |
129 int id; | 130 int id; |
130 if (root->GetInteger("id", &id)) { | 131 if (root->GetInteger("id", &id)) { |
131 result_ids_.push_back(id); | 132 result_ids_.push_back(id); |
132 base::DictionaryValue* result; | 133 base::DictionaryValue* result; |
133 ASSERT_TRUE(root->GetDictionary("result", &result)); | 134 ASSERT_TRUE(root->GetDictionary("result", &result)); |
134 result_.reset(result->DeepCopy()); | 135 result_.reset(result->DeepCopy()); |
135 in_dispatch_ = false; | 136 in_dispatch_ = false; |
136 if (id && id == waiting_for_command_result_id_) { | 137 if (id && id == waiting_for_command_result_id_) { |
137 waiting_for_command_result_id_ = 0; | 138 waiting_for_command_result_id_ = 0; |
138 base::MessageLoop::current()->QuitNow(); | 139 base::MessageLoop::current()->QuitNow(); |
(...skipping 17 matching lines...) Expand all Loading... |
156 int waiting_for_command_result_id_; | 157 int waiting_for_command_result_id_; |
157 bool in_dispatch_; | 158 bool in_dispatch_; |
158 }; | 159 }; |
159 | 160 |
160 class SyntheticKeyEventTest : public DevToolsProtocolTest { | 161 class SyntheticKeyEventTest : public DevToolsProtocolTest { |
161 protected: | 162 protected: |
162 void SendKeyEvent(const std::string& type, | 163 void SendKeyEvent(const std::string& type, |
163 int modifier, | 164 int modifier, |
164 int windowsKeyCode, | 165 int windowsKeyCode, |
165 int nativeKeyCode) { | 166 int nativeKeyCode) { |
166 scoped_ptr<base::DictionaryValue> params(new base::DictionaryValue()); | 167 std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue()); |
167 params->SetString("type", type); | 168 params->SetString("type", type); |
168 params->SetInteger("modifiers", modifier); | 169 params->SetInteger("modifiers", modifier); |
169 params->SetInteger("windowsVirtualKeyCode", windowsKeyCode); | 170 params->SetInteger("windowsVirtualKeyCode", windowsKeyCode); |
170 params->SetInteger("nativeVirtualKeyCode", nativeKeyCode); | 171 params->SetInteger("nativeVirtualKeyCode", nativeKeyCode); |
171 SendCommand("Input.dispatchKeyEvent", std::move(params)); | 172 SendCommand("Input.dispatchKeyEvent", std::move(params)); |
172 } | 173 } |
173 }; | 174 }; |
174 | 175 |
175 IN_PROC_BROWSER_TEST_F(SyntheticKeyEventTest, KeyEventSynthesizeKeyIdentifier) { | 176 IN_PROC_BROWSER_TEST_F(SyntheticKeyEventTest, KeyEventSynthesizeKeyIdentifier) { |
176 NavigateToURLBlockUntilNavigationsComplete(shell(), GURL("about:blank"), 1); | 177 NavigateToURLBlockUntilNavigationsComplete(shell(), GURL("about:blank"), 1); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 int old_width; | 257 int old_width; |
257 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( | 258 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( |
258 shell()->web_contents(), | 259 shell()->web_contents(), |
259 "domAutomationController.send(window.innerWidth)", &old_width)); | 260 "domAutomationController.send(window.innerWidth)", &old_width)); |
260 | 261 |
261 int old_height; | 262 int old_height; |
262 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( | 263 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( |
263 shell()->web_contents(), | 264 shell()->web_contents(), |
264 "domAutomationController.send(window.innerHeight)", &old_height)); | 265 "domAutomationController.send(window.innerHeight)", &old_height)); |
265 | 266 |
266 scoped_ptr<base::DictionaryValue> params(new base::DictionaryValue()); | 267 std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue()); |
267 params->SetInteger("x", old_width / 2); | 268 params->SetInteger("x", old_width / 2); |
268 params->SetInteger("y", old_height / 2); | 269 params->SetInteger("y", old_height / 2); |
269 params->SetDouble("scaleFactor", 2.0); | 270 params->SetDouble("scaleFactor", 2.0); |
270 SendCommand("Input.synthesizePinchGesture", std::move(params)); | 271 SendCommand("Input.synthesizePinchGesture", std::move(params)); |
271 | 272 |
272 int new_width; | 273 int new_width; |
273 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( | 274 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( |
274 shell()->web_contents(), | 275 shell()->web_contents(), |
275 "domAutomationController.send(window.innerWidth)", &new_width)); | 276 "domAutomationController.send(window.innerWidth)", &new_width)); |
276 ASSERT_DOUBLE_EQ(2.0, static_cast<double>(old_width) / new_width); | 277 ASSERT_DOUBLE_EQ(2.0, static_cast<double>(old_width) / new_width); |
277 | 278 |
278 int new_height; | 279 int new_height; |
279 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( | 280 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( |
280 shell()->web_contents(), | 281 shell()->web_contents(), |
281 "domAutomationController.send(window.innerHeight)", &new_height)); | 282 "domAutomationController.send(window.innerHeight)", &new_height)); |
282 ASSERT_DOUBLE_EQ(2.0, static_cast<double>(old_height) / new_height); | 283 ASSERT_DOUBLE_EQ(2.0, static_cast<double>(old_height) / new_height); |
283 } | 284 } |
284 | 285 |
285 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, DISABLED_SynthesizeScrollGesture) { | 286 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, DISABLED_SynthesizeScrollGesture) { |
286 GURL test_url = GetTestUrl("devtools", "synthetic_gesture_tests.html"); | 287 GURL test_url = GetTestUrl("devtools", "synthetic_gesture_tests.html"); |
287 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 1); | 288 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 1); |
288 Attach(); | 289 Attach(); |
289 | 290 |
290 int scroll_top; | 291 int scroll_top; |
291 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( | 292 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( |
292 shell()->web_contents(), | 293 shell()->web_contents(), |
293 "domAutomationController.send(document.body.scrollTop)", &scroll_top)); | 294 "domAutomationController.send(document.body.scrollTop)", &scroll_top)); |
294 ASSERT_EQ(0, scroll_top); | 295 ASSERT_EQ(0, scroll_top); |
295 | 296 |
296 scoped_ptr<base::DictionaryValue> params(new base::DictionaryValue()); | 297 std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue()); |
297 params->SetInteger("x", 0); | 298 params->SetInteger("x", 0); |
298 params->SetInteger("y", 0); | 299 params->SetInteger("y", 0); |
299 params->SetInteger("xDistance", 0); | 300 params->SetInteger("xDistance", 0); |
300 params->SetInteger("yDistance", -100); | 301 params->SetInteger("yDistance", -100); |
301 SendCommand("Input.synthesizeScrollGesture", std::move(params)); | 302 SendCommand("Input.synthesizeScrollGesture", std::move(params)); |
302 | 303 |
303 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( | 304 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( |
304 shell()->web_contents(), | 305 shell()->web_contents(), |
305 "domAutomationController.send(document.body.scrollTop)", &scroll_top)); | 306 "domAutomationController.send(document.body.scrollTop)", &scroll_top)); |
306 ASSERT_EQ(100, scroll_top); | 307 ASSERT_EQ(100, scroll_top); |
307 } | 308 } |
308 | 309 |
309 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, DISABLED_SynthesizeTapGesture) { | 310 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, DISABLED_SynthesizeTapGesture) { |
310 GURL test_url = GetTestUrl("devtools", "synthetic_gesture_tests.html"); | 311 GURL test_url = GetTestUrl("devtools", "synthetic_gesture_tests.html"); |
311 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 1); | 312 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 1); |
312 Attach(); | 313 Attach(); |
313 | 314 |
314 int scroll_top; | 315 int scroll_top; |
315 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( | 316 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( |
316 shell()->web_contents(), | 317 shell()->web_contents(), |
317 "domAutomationController.send(document.body.scrollTop)", &scroll_top)); | 318 "domAutomationController.send(document.body.scrollTop)", &scroll_top)); |
318 ASSERT_EQ(0, scroll_top); | 319 ASSERT_EQ(0, scroll_top); |
319 | 320 |
320 scoped_ptr<base::DictionaryValue> params(new base::DictionaryValue()); | 321 std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue()); |
321 params->SetInteger("x", 16); | 322 params->SetInteger("x", 16); |
322 params->SetInteger("y", 16); | 323 params->SetInteger("y", 16); |
323 params->SetString("gestureSourceType", "touch"); | 324 params->SetString("gestureSourceType", "touch"); |
324 SendCommand("Input.synthesizeTapGesture", std::move(params)); | 325 SendCommand("Input.synthesizeTapGesture", std::move(params)); |
325 | 326 |
326 // The link that we just tapped should take us to the bottom of the page. The | 327 // The link that we just tapped should take us to the bottom of the page. The |
327 // new value of |document.body.scrollTop| will depend on the screen dimensions | 328 // new value of |document.body.scrollTop| will depend on the screen dimensions |
328 // of the device that we're testing on, but in any case it should be greater | 329 // of the device that we're testing on, but in any case it should be greater |
329 // than 0. | 330 // than 0. |
330 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( | 331 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( |
331 shell()->web_contents(), | 332 shell()->web_contents(), |
332 "domAutomationController.send(document.body.scrollTop)", &scroll_top)); | 333 "domAutomationController.send(document.body.scrollTop)", &scroll_top)); |
333 ASSERT_GT(scroll_top, 0); | 334 ASSERT_GT(scroll_top, 0); |
334 } | 335 } |
335 #endif // defined(OS_ANDROID) | 336 #endif // defined(OS_ANDROID) |
336 | 337 |
337 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, NavigationPreservesMessages) { | 338 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, NavigationPreservesMessages) { |
338 ASSERT_TRUE(embedded_test_server()->Start()); | 339 ASSERT_TRUE(embedded_test_server()->Start()); |
339 GURL test_url = embedded_test_server()->GetURL("/devtools/navigation.html"); | 340 GURL test_url = embedded_test_server()->GetURL("/devtools/navigation.html"); |
340 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 1); | 341 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 1); |
341 Attach(); | 342 Attach(); |
342 SendCommand("Page.enable", nullptr, false); | 343 SendCommand("Page.enable", nullptr, false); |
343 | 344 |
344 scoped_ptr<base::DictionaryValue> params(new base::DictionaryValue()); | 345 std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue()); |
345 test_url = GetTestUrl("devtools", "navigation.html"); | 346 test_url = GetTestUrl("devtools", "navigation.html"); |
346 params->SetString("url", test_url.spec()); | 347 params->SetString("url", test_url.spec()); |
347 TestNavigationObserver navigation_observer(shell()->web_contents()); | 348 TestNavigationObserver navigation_observer(shell()->web_contents()); |
348 SendCommand("Page.navigate", std::move(params), true); | 349 SendCommand("Page.navigate", std::move(params), true); |
349 navigation_observer.Wait(); | 350 navigation_observer.Wait(); |
350 | 351 |
351 bool enough_results = result_ids_.size() >= 2u; | 352 bool enough_results = result_ids_.size() >= 2u; |
352 EXPECT_TRUE(enough_results); | 353 EXPECT_TRUE(enough_results); |
353 if (enough_results) { | 354 if (enough_results) { |
354 EXPECT_EQ(1, result_ids_[0]); // Page.enable | 355 EXPECT_EQ(1, result_ids_[0]); // Page.enable |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 gfx::Size()); | 485 gfx::Size()); |
485 WaitForLoadStop(window->web_contents()); | 486 WaitForLoadStop(window->web_contents()); |
486 Attach(); | 487 Attach(); |
487 SendCommand("Page.reload", nullptr, false); | 488 SendCommand("Page.reload", nullptr, false); |
488 // Should not crash at this point. | 489 // Should not crash at this point. |
489 } | 490 } |
490 | 491 |
491 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, EvaluateInBlankPage) { | 492 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, EvaluateInBlankPage) { |
492 NavigateToURLBlockUntilNavigationsComplete(shell(), GURL("about:blank"), 1); | 493 NavigateToURLBlockUntilNavigationsComplete(shell(), GURL("about:blank"), 1); |
493 Attach(); | 494 Attach(); |
494 scoped_ptr<base::DictionaryValue> params(new base::DictionaryValue()); | 495 std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue()); |
495 params->SetString("expression", "window"); | 496 params->SetString("expression", "window"); |
496 SendCommand("Runtime.evaluate", std::move(params), true); | 497 SendCommand("Runtime.evaluate", std::move(params), true); |
497 bool wasThrown = true; | 498 bool wasThrown = true; |
498 EXPECT_TRUE(result_->GetBoolean("wasThrown", &wasThrown)); | 499 EXPECT_TRUE(result_->GetBoolean("wasThrown", &wasThrown)); |
499 EXPECT_FALSE(wasThrown); | 500 EXPECT_FALSE(wasThrown); |
500 } | 501 } |
501 | 502 |
502 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, | 503 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, |
503 EvaluateInBlankPageAfterNavigation) { | 504 EvaluateInBlankPageAfterNavigation) { |
504 ASSERT_TRUE(embedded_test_server()->Start()); | 505 ASSERT_TRUE(embedded_test_server()->Start()); |
505 GURL test_url = embedded_test_server()->GetURL("/devtools/navigation.html"); | 506 GURL test_url = embedded_test_server()->GetURL("/devtools/navigation.html"); |
506 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 1); | 507 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 1); |
507 Attach(); | 508 Attach(); |
508 NavigateToURLBlockUntilNavigationsComplete(shell(), GURL("about:blank"), 1); | 509 NavigateToURLBlockUntilNavigationsComplete(shell(), GURL("about:blank"), 1); |
509 scoped_ptr<base::DictionaryValue> params(new base::DictionaryValue()); | 510 std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue()); |
510 params->SetString("expression", "window"); | 511 params->SetString("expression", "window"); |
511 SendCommand("Runtime.evaluate", std::move(params), true); | 512 SendCommand("Runtime.evaluate", std::move(params), true); |
512 bool wasThrown = true; | 513 bool wasThrown = true; |
513 EXPECT_TRUE(result_->GetBoolean("wasThrown", &wasThrown)); | 514 EXPECT_TRUE(result_->GetBoolean("wasThrown", &wasThrown)); |
514 EXPECT_FALSE(wasThrown); | 515 EXPECT_FALSE(wasThrown); |
515 } | 516 } |
516 | 517 |
517 } // namespace content | 518 } // namespace content |
OLD | NEW |