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 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 | 308 |
309 #if defined(OS_ANDROID) | 309 #if defined(OS_ANDROID) |
310 // Disabled, see http://crbug.com/469947. | 310 // Disabled, see http://crbug.com/469947. |
311 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, DISABLED_SynthesizePinchGesture) { | 311 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, DISABLED_SynthesizePinchGesture) { |
312 GURL test_url = GetTestUrl("devtools", "synthetic_gesture_tests.html"); | 312 GURL test_url = GetTestUrl("devtools", "synthetic_gesture_tests.html"); |
313 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 1); | 313 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 1); |
314 Attach(); | 314 Attach(); |
315 | 315 |
316 int old_width; | 316 int old_width; |
317 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( | 317 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( |
318 shell()->web_contents(), | 318 shell(), "domAutomationController.send(window.innerWidth)", &old_width)); |
319 "domAutomationController.send(window.innerWidth)", &old_width)); | |
320 | 319 |
321 int old_height; | 320 int old_height; |
322 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( | 321 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( |
323 shell()->web_contents(), | 322 shell(), "domAutomationController.send(window.innerHeight)", |
324 "domAutomationController.send(window.innerHeight)", &old_height)); | 323 &old_height)); |
325 | 324 |
326 std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue()); | 325 std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue()); |
327 params->SetInteger("x", old_width / 2); | 326 params->SetInteger("x", old_width / 2); |
328 params->SetInteger("y", old_height / 2); | 327 params->SetInteger("y", old_height / 2); |
329 params->SetDouble("scaleFactor", 2.0); | 328 params->SetDouble("scaleFactor", 2.0); |
330 SendCommand("Input.synthesizePinchGesture", std::move(params)); | 329 SendCommand("Input.synthesizePinchGesture", std::move(params)); |
331 | 330 |
332 int new_width; | 331 int new_width; |
333 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( | 332 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( |
334 shell()->web_contents(), | 333 shell(), "domAutomationController.send(window.innerWidth)", &new_width)); |
335 "domAutomationController.send(window.innerWidth)", &new_width)); | |
336 ASSERT_DOUBLE_EQ(2.0, static_cast<double>(old_width) / new_width); | 334 ASSERT_DOUBLE_EQ(2.0, static_cast<double>(old_width) / new_width); |
337 | 335 |
338 int new_height; | 336 int new_height; |
339 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( | 337 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( |
340 shell()->web_contents(), | 338 shell(), "domAutomationController.send(window.innerHeight)", |
341 "domAutomationController.send(window.innerHeight)", &new_height)); | 339 &new_height)); |
342 ASSERT_DOUBLE_EQ(2.0, static_cast<double>(old_height) / new_height); | 340 ASSERT_DOUBLE_EQ(2.0, static_cast<double>(old_height) / new_height); |
343 } | 341 } |
344 | 342 |
345 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, DISABLED_SynthesizeScrollGesture) { | 343 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, DISABLED_SynthesizeScrollGesture) { |
346 GURL test_url = GetTestUrl("devtools", "synthetic_gesture_tests.html"); | 344 GURL test_url = GetTestUrl("devtools", "synthetic_gesture_tests.html"); |
347 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 1); | 345 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 1); |
348 Attach(); | 346 Attach(); |
349 | 347 |
350 int scroll_top; | 348 int scroll_top; |
351 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( | 349 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( |
352 shell()->web_contents(), | 350 shell(), "domAutomationController.send(document.body.scrollTop)", |
353 "domAutomationController.send(document.body.scrollTop)", &scroll_top)); | 351 &scroll_top)); |
354 ASSERT_EQ(0, scroll_top); | 352 ASSERT_EQ(0, scroll_top); |
355 | 353 |
356 std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue()); | 354 std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue()); |
357 params->SetInteger("x", 0); | 355 params->SetInteger("x", 0); |
358 params->SetInteger("y", 0); | 356 params->SetInteger("y", 0); |
359 params->SetInteger("xDistance", 0); | 357 params->SetInteger("xDistance", 0); |
360 params->SetInteger("yDistance", -100); | 358 params->SetInteger("yDistance", -100); |
361 SendCommand("Input.synthesizeScrollGesture", std::move(params)); | 359 SendCommand("Input.synthesizeScrollGesture", std::move(params)); |
362 | 360 |
363 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( | 361 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( |
364 shell()->web_contents(), | 362 shell(), "domAutomationController.send(document.body.scrollTop)", |
365 "domAutomationController.send(document.body.scrollTop)", &scroll_top)); | 363 &scroll_top)); |
366 ASSERT_EQ(100, scroll_top); | 364 ASSERT_EQ(100, scroll_top); |
367 } | 365 } |
368 | 366 |
369 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, DISABLED_SynthesizeTapGesture) { | 367 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, DISABLED_SynthesizeTapGesture) { |
370 GURL test_url = GetTestUrl("devtools", "synthetic_gesture_tests.html"); | 368 GURL test_url = GetTestUrl("devtools", "synthetic_gesture_tests.html"); |
371 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 1); | 369 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 1); |
372 Attach(); | 370 Attach(); |
373 | 371 |
374 int scroll_top; | 372 int scroll_top; |
375 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( | 373 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( |
376 shell()->web_contents(), | 374 shell(), "domAutomationController.send(document.body.scrollTop)", |
377 "domAutomationController.send(document.body.scrollTop)", &scroll_top)); | 375 &scroll_top)); |
378 ASSERT_EQ(0, scroll_top); | 376 ASSERT_EQ(0, scroll_top); |
379 | 377 |
380 std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue()); | 378 std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue()); |
381 params->SetInteger("x", 16); | 379 params->SetInteger("x", 16); |
382 params->SetInteger("y", 16); | 380 params->SetInteger("y", 16); |
383 params->SetString("gestureSourceType", "touch"); | 381 params->SetString("gestureSourceType", "touch"); |
384 SendCommand("Input.synthesizeTapGesture", std::move(params)); | 382 SendCommand("Input.synthesizeTapGesture", std::move(params)); |
385 | 383 |
386 // The link that we just tapped should take us to the bottom of the page. The | 384 // The link that we just tapped should take us to the bottom of the page. The |
387 // new value of |document.body.scrollTop| will depend on the screen dimensions | 385 // new value of |document.body.scrollTop| will depend on the screen dimensions |
388 // of the device that we're testing on, but in any case it should be greater | 386 // of the device that we're testing on, but in any case it should be greater |
389 // than 0. | 387 // than 0. |
390 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( | 388 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( |
391 shell()->web_contents(), | 389 shell(), "domAutomationController.send(document.body.scrollTop)", |
392 "domAutomationController.send(document.body.scrollTop)", &scroll_top)); | 390 &scroll_top)); |
393 ASSERT_GT(scroll_top, 0); | 391 ASSERT_GT(scroll_top, 0); |
394 } | 392 } |
395 #endif // defined(OS_ANDROID) | 393 #endif // defined(OS_ANDROID) |
396 | 394 |
397 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, NavigationPreservesMessages) { | 395 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, NavigationPreservesMessages) { |
398 ASSERT_TRUE(embedded_test_server()->Start()); | 396 ASSERT_TRUE(embedded_test_server()->Start()); |
399 GURL test_url = embedded_test_server()->GetURL("/devtools/navigation.html"); | 397 GURL test_url = embedded_test_server()->GetURL("/devtools/navigation.html"); |
400 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 1); | 398 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 1); |
401 Attach(); | 399 Attach(); |
402 SendCommand("Page.enable", nullptr, false); | 400 SendCommand("Page.enable", nullptr, false); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 host_resolver()->AddRule("*", "127.0.0.1"); | 460 host_resolver()->AddRule("*", "127.0.0.1"); |
463 ASSERT_TRUE(embedded_test_server()->Start()); | 461 ASSERT_TRUE(embedded_test_server()->Start()); |
464 content::SetupCrossSiteRedirector(embedded_test_server()); | 462 content::SetupCrossSiteRedirector(embedded_test_server()); |
465 | 463 |
466 NavigateToURLBlockUntilNavigationsComplete(shell(), | 464 NavigateToURLBlockUntilNavigationsComplete(shell(), |
467 embedded_test_server()->GetURL("A.com", "/devtools/navigation.html"), 1); | 465 embedded_test_server()->GetURL("A.com", "/devtools/navigation.html"), 1); |
468 Attach(); | 466 Attach(); |
469 SendCommand("Debugger.enable", nullptr); | 467 SendCommand("Debugger.enable", nullptr); |
470 | 468 |
471 ASSERT_TRUE(content::ExecuteScript( | 469 ASSERT_TRUE(content::ExecuteScript( |
472 shell()->web_contents(), | 470 shell(), |
473 "window.onbeforeunload = function() { debugger; return null; }")); | 471 "window.onbeforeunload = function() { debugger; return null; }")); |
474 | 472 |
475 shell()->LoadURL( | 473 shell()->LoadURL( |
476 embedded_test_server()->GetURL("B.com", "/devtools/navigation.html")); | 474 embedded_test_server()->GetURL("B.com", "/devtools/navigation.html")); |
477 WaitForNotification("Debugger.paused"); | 475 WaitForNotification("Debugger.paused"); |
478 TestNavigationObserver observer(shell()->web_contents(), 1); | 476 TestNavigationObserver observer(shell()->web_contents(), 1); |
479 SendCommand("Debugger.resume", nullptr); | 477 SendCommand("Debugger.resume", nullptr); |
480 observer.Wait(); | 478 observer.Wait(); |
481 } | 479 } |
482 | 480 |
483 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, InspectDuringFrameSwap) { | 481 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, InspectDuringFrameSwap) { |
484 host_resolver()->AddRule("*", "127.0.0.1"); | 482 host_resolver()->AddRule("*", "127.0.0.1"); |
485 ASSERT_TRUE(embedded_test_server()->Start()); | 483 ASSERT_TRUE(embedded_test_server()->Start()); |
486 content::SetupCrossSiteRedirector(embedded_test_server()); | 484 content::SetupCrossSiteRedirector(embedded_test_server()); |
487 | 485 |
488 GURL test_url1 = | 486 GURL test_url1 = |
489 embedded_test_server()->GetURL("A.com", "/devtools/navigation.html"); | 487 embedded_test_server()->GetURL("A.com", "/devtools/navigation.html"); |
490 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url1, 1); | 488 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url1, 1); |
491 | 489 |
492 ShellAddedObserver new_shell_observer; | 490 ShellAddedObserver new_shell_observer; |
493 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), | 491 EXPECT_TRUE(ExecuteScript(shell(), "window.open('about:blank','foo');")); |
494 "window.open('about:blank','foo');")); | |
495 Shell* new_shell = new_shell_observer.GetShell(); | 492 Shell* new_shell = new_shell_observer.GetShell(); |
496 EXPECT_TRUE(new_shell->web_contents()->HasOpener()); | 493 EXPECT_TRUE(new_shell->web_contents()->HasOpener()); |
497 | 494 |
498 agent_host_ = DevToolsAgentHost::GetOrCreateFor(new_shell->web_contents()); | 495 agent_host_ = DevToolsAgentHost::GetOrCreateFor(new_shell->web_contents()); |
499 agent_host_->AttachClient(this); | 496 agent_host_->AttachClient(this); |
500 | 497 |
501 GURL test_url2 = | 498 GURL test_url2 = |
502 embedded_test_server()->GetURL("B.com", "/devtools/navigation.html"); | 499 embedded_test_server()->GetURL("B.com", "/devtools/navigation.html"); |
503 | 500 |
504 // After this navigation, if the bug exists, the process will crash. | 501 // After this navigation, if the bug exists, the process will crash. |
505 NavigateToURLBlockUntilNavigationsComplete(new_shell, test_url2, 1); | 502 NavigateToURLBlockUntilNavigationsComplete(new_shell, test_url2, 1); |
506 | 503 |
507 // Ensure that the A.com process is still alive by executing a script in the | 504 // Ensure that the A.com process is still alive by executing a script in the |
508 // original tab. | 505 // original tab. |
509 // | 506 // |
510 // TODO(alexmos, nasko): A better way to do this is to navigate the original | 507 // TODO(alexmos, nasko): A better way to do this is to navigate the original |
511 // tab to another site, watch for process exit, and check whether there was a | 508 // tab to another site, watch for process exit, and check whether there was a |
512 // crash. However, currently there's no way to wait for process exit | 509 // crash. However, currently there's no way to wait for process exit |
513 // regardless of whether it's a crash or not. RenderProcessHostWatcher | 510 // regardless of whether it's a crash or not. RenderProcessHostWatcher |
514 // should be fixed to support waiting on both WATCH_FOR_PROCESS_EXIT and | 511 // should be fixed to support waiting on both WATCH_FOR_PROCESS_EXIT and |
515 // WATCH_FOR_HOST_DESTRUCTION, and then used here. | 512 // WATCH_FOR_HOST_DESTRUCTION, and then used here. |
516 bool success = false; | 513 bool success = false; |
517 EXPECT_TRUE(ExecuteScriptAndExtractBool(shell()->web_contents(), | 514 EXPECT_TRUE(ExecuteScriptAndExtractBool(shell(), |
518 "window.domAutomationController.send(" | 515 "window.domAutomationController.send(" |
519 " !!window.open('', 'foo'));", | 516 " !!window.open('', 'foo'));", |
520 &success)); | 517 &success)); |
521 EXPECT_TRUE(success); | 518 EXPECT_TRUE(success); |
522 | 519 |
523 GURL test_url3 = | 520 GURL test_url3 = |
524 embedded_test_server()->GetURL("A.com", "/devtools/navigation.html"); | 521 embedded_test_server()->GetURL("A.com", "/devtools/navigation.html"); |
525 | 522 |
526 // After this navigation, if the bug exists, the process will crash. | 523 // After this navigation, if the bug exists, the process will crash. |
527 NavigateToURLBlockUntilNavigationsComplete(new_shell, test_url3, 1); | 524 NavigateToURLBlockUntilNavigationsComplete(new_shell, test_url3, 1); |
528 | 525 |
529 // Ensure that the A.com process is still alive by executing a script in the | 526 // Ensure that the A.com process is still alive by executing a script in the |
530 // original tab. | 527 // original tab. |
531 success = false; | 528 success = false; |
532 EXPECT_TRUE(ExecuteScriptAndExtractBool(shell()->web_contents(), | 529 EXPECT_TRUE(ExecuteScriptAndExtractBool(shell(), |
533 "window.domAutomationController.send(" | 530 "window.domAutomationController.send(" |
534 " !!window.open('', 'foo'));", | 531 " !!window.open('', 'foo'));", |
535 &success)); | 532 &success)); |
536 EXPECT_TRUE(success); | 533 EXPECT_TRUE(success); |
537 } | 534 } |
538 | 535 |
539 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, ReloadBlankPage) { | 536 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, ReloadBlankPage) { |
540 Shell* window = Shell::CreateNewWindow( | 537 Shell* window = Shell::CreateNewWindow( |
541 shell()->web_contents()->GetBrowserContext(), | 538 shell()->web_contents()->GetBrowserContext(), |
542 GURL("javascript:x=1"), | 539 GURL("javascript:x=1"), |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 shell()->web_contents()->SetDelegate(&dialog_manager); | 578 shell()->web_contents()->SetDelegate(&dialog_manager); |
582 SendCommand("Page.enable", nullptr, true); | 579 SendCommand("Page.enable", nullptr, true); |
583 std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue()); | 580 std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue()); |
584 params->SetString("expression", "alert('alert')"); | 581 params->SetString("expression", "alert('alert')"); |
585 SendCommand("Runtime.evaluate", std::move(params), false); | 582 SendCommand("Runtime.evaluate", std::move(params), false); |
586 WaitForNotification("Page.javascriptDialogOpening"); | 583 WaitForNotification("Page.javascriptDialogOpening"); |
587 dialog_manager.Handle(); | 584 dialog_manager.Handle(); |
588 } | 585 } |
589 | 586 |
590 } // namespace content | 587 } // namespace content |
OLD | NEW |