OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/memory/singleton.h" | 6 #include "base/memory/singleton.h" |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "base/strings/string_split.h" | 8 #include "base/strings/string_split.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 #endif | 446 #endif |
447 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, MAYBE_EmbedderSameAfterNav) { | 447 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, MAYBE_EmbedderSameAfterNav) { |
448 const char kEmbedderURL[] = "/browser_plugin_embedder.html"; | 448 const char kEmbedderURL[] = "/browser_plugin_embedder.html"; |
449 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string()); | 449 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string()); |
450 WebContentsImpl* embedder_web_contents = test_embedder()->web_contents(); | 450 WebContentsImpl* embedder_web_contents = test_embedder()->web_contents(); |
451 | 451 |
452 // Navigate to another page in same host and port, so RenderViewHost swap | 452 // Navigate to another page in same host and port, so RenderViewHost swap |
453 // does not happen and existing embedder doesn't change in web_contents. | 453 // does not happen and existing embedder doesn't change in web_contents. |
454 GURL test_url_new(embedded_test_server()->GetURL( | 454 GURL test_url_new(embedded_test_server()->GetURL( |
455 "/browser_plugin_title_change.html")); | 455 "/browser_plugin_title_change.html")); |
456 const string16 expected_title = ASCIIToUTF16("done"); | 456 const base::string16 expected_title = ASCIIToUTF16("done"); |
457 content::TitleWatcher title_watcher(shell()->web_contents(), expected_title); | 457 content::TitleWatcher title_watcher(shell()->web_contents(), expected_title); |
458 NavigateToURL(shell(), test_url_new); | 458 NavigateToURL(shell(), test_url_new); |
459 VLOG(0) << "Start waiting for title"; | 459 VLOG(0) << "Start waiting for title"; |
460 string16 actual_title = title_watcher.WaitAndGetTitle(); | 460 base::string16 actual_title = title_watcher.WaitAndGetTitle(); |
461 EXPECT_EQ(expected_title, actual_title); | 461 EXPECT_EQ(expected_title, actual_title); |
462 VLOG(0) << "Done navigating to second page"; | 462 VLOG(0) << "Done navigating to second page"; |
463 | 463 |
464 TestBrowserPluginEmbedder* test_embedder_after_nav = | 464 TestBrowserPluginEmbedder* test_embedder_after_nav = |
465 static_cast<TestBrowserPluginEmbedder*>( | 465 static_cast<TestBrowserPluginEmbedder*>( |
466 embedder_web_contents->GetBrowserPluginEmbedder()); | 466 embedder_web_contents->GetBrowserPluginEmbedder()); |
467 // Embedder must not change in web_contents. | 467 // Embedder must not change in web_contents. |
468 ASSERT_EQ(test_embedder_after_nav, test_embedder()); | 468 ASSERT_EQ(test_embedder_after_nav, test_embedder()); |
469 } | 469 } |
470 | 470 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, ReloadEmbedder) { | 529 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, ReloadEmbedder) { |
530 const char kEmbedderURL[] = "/browser_plugin_embedder.html"; | 530 const char kEmbedderURL[] = "/browser_plugin_embedder.html"; |
531 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string()); | 531 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string()); |
532 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 532 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
533 test_embedder()->web_contents()->GetRenderViewHost()); | 533 test_embedder()->web_contents()->GetRenderViewHost()); |
534 | 534 |
535 // Change the title of the page to 'modified' so that we know that | 535 // Change the title of the page to 'modified' so that we know that |
536 // the page has successfully reloaded when it goes back to 'embedder' | 536 // the page has successfully reloaded when it goes back to 'embedder' |
537 // in the next step. | 537 // in the next step. |
538 { | 538 { |
539 const string16 expected_title = ASCIIToUTF16("modified"); | 539 const base::string16 expected_title = ASCIIToUTF16("modified"); |
540 content::TitleWatcher title_watcher(test_embedder()->web_contents(), | 540 content::TitleWatcher title_watcher(test_embedder()->web_contents(), |
541 expected_title); | 541 expected_title); |
542 | 542 |
543 ExecuteSyncJSFunction(rvh, | 543 ExecuteSyncJSFunction(rvh, |
544 base::StringPrintf("SetTitle('%s');", "modified")); | 544 base::StringPrintf("SetTitle('%s');", "modified")); |
545 | 545 |
546 string16 actual_title = title_watcher.WaitAndGetTitle(); | 546 base::string16 actual_title = title_watcher.WaitAndGetTitle(); |
547 EXPECT_EQ(expected_title, actual_title); | 547 EXPECT_EQ(expected_title, actual_title); |
548 } | 548 } |
549 | 549 |
550 // Reload the embedder page, and verify that the reload was successful. | 550 // Reload the embedder page, and verify that the reload was successful. |
551 // Then navigate the guest to verify that the browser process does not crash. | 551 // Then navigate the guest to verify that the browser process does not crash. |
552 { | 552 { |
553 const string16 expected_title = ASCIIToUTF16("embedder"); | 553 const base::string16 expected_title = ASCIIToUTF16("embedder"); |
554 content::TitleWatcher title_watcher(test_embedder()->web_contents(), | 554 content::TitleWatcher title_watcher(test_embedder()->web_contents(), |
555 expected_title); | 555 expected_title); |
556 | 556 |
557 test_embedder()->web_contents()->GetController().Reload(false); | 557 test_embedder()->web_contents()->GetController().Reload(false); |
558 string16 actual_title = title_watcher.WaitAndGetTitle(); | 558 base::string16 actual_title = title_watcher.WaitAndGetTitle(); |
559 EXPECT_EQ(expected_title, actual_title); | 559 EXPECT_EQ(expected_title, actual_title); |
560 | 560 |
561 ExecuteSyncJSFunction( | 561 ExecuteSyncJSFunction( |
562 test_embedder()->web_contents()->GetRenderViewHost(), | 562 test_embedder()->web_contents()->GetRenderViewHost(), |
563 base::StringPrintf("SetSrc('%s');", kHTMLForGuest)); | 563 base::StringPrintf("SetSrc('%s');", kHTMLForGuest)); |
564 test_guest_manager()->WaitForGuestAdded(); | 564 test_guest_manager()->WaitForGuestAdded(); |
565 | 565 |
566 const TestBrowserPluginGuestManager::GuestInstanceMap& instance_map = | 566 const TestBrowserPluginGuestManager::GuestInstanceMap& instance_map = |
567 test_guest_manager()->guest_web_contents_for_testing(); | 567 test_guest_manager()->guest_web_contents_for_testing(); |
568 WebContentsImpl* test_guest_web_contents = static_cast<WebContentsImpl*>( | 568 WebContentsImpl* test_guest_web_contents = static_cast<WebContentsImpl*>( |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 | 611 |
612 DropData drop_data; | 612 DropData drop_data; |
613 GURL url = GURL("https://www.domain.com/index.html"); | 613 GURL url = GURL("https://www.domain.com/index.html"); |
614 drop_data.url = url; | 614 drop_data.url = url; |
615 | 615 |
616 // Pretend that the URL is being dragged over the embedder. Start the drag | 616 // Pretend that the URL is being dragged over the embedder. Start the drag |
617 // from outside the plugin, then move the drag inside the plugin and drop. | 617 // from outside the plugin, then move the drag inside the plugin and drop. |
618 // This should trigger appropriate messages from the embedder to the guest, | 618 // This should trigger appropriate messages from the embedder to the guest, |
619 // and end with a drop on the guest. The guest changes title when a drop | 619 // and end with a drop on the guest. The guest changes title when a drop |
620 // happens. | 620 // happens. |
621 const string16 expected_title = ASCIIToUTF16("DROPPED"); | 621 const base::string16 expected_title = ASCIIToUTF16("DROPPED"); |
622 content::TitleWatcher title_watcher(test_guest()->web_contents(), | 622 content::TitleWatcher title_watcher(test_guest()->web_contents(), |
623 expected_title); | 623 expected_title); |
624 | 624 |
625 rvh->DragTargetDragEnter(drop_data, gfx::Point(start_x, start_y), | 625 rvh->DragTargetDragEnter(drop_data, gfx::Point(start_x, start_y), |
626 gfx::Point(start_x, start_y), blink::WebDragOperationEvery, 0); | 626 gfx::Point(start_x, start_y), blink::WebDragOperationEvery, 0); |
627 rvh->DragTargetDragOver(gfx::Point(end_x, end_y), gfx::Point(end_x, end_y), | 627 rvh->DragTargetDragOver(gfx::Point(end_x, end_y), gfx::Point(end_x, end_y), |
628 blink::WebDragOperationEvery, 0); | 628 blink::WebDragOperationEvery, 0); |
629 rvh->DragTargetDrop(gfx::Point(end_x, end_y), gfx::Point(end_x, end_y), 0); | 629 rvh->DragTargetDrop(gfx::Point(end_x, end_y), gfx::Point(end_x, end_y), 0); |
630 | 630 |
631 string16 actual_title = title_watcher.WaitAndGetTitle(); | 631 base::string16 actual_title = title_watcher.WaitAndGetTitle(); |
632 EXPECT_EQ(expected_title, actual_title); | 632 EXPECT_EQ(expected_title, actual_title); |
633 } | 633 } |
634 | 634 |
635 // This test verifies that round trip postMessage works as expected. | 635 // This test verifies that round trip postMessage works as expected. |
636 // 1. The embedder posts a message 'testing123' to the guest. | 636 // 1. The embedder posts a message 'testing123' to the guest. |
637 // 2. The guest receives and replies to the message using the event object's | 637 // 2. The guest receives and replies to the message using the event object's |
638 // source object: event.source.postMessage('foobar', '*') | 638 // source object: event.source.postMessage('foobar', '*') |
639 // 3. The embedder receives the message and uses the event's source | 639 // 3. The embedder receives the message and uses the event's source |
640 // object to do one final reply: 'stop' | 640 // object to do one final reply: 'stop' |
641 // 4. The guest receives the final 'stop' message. | 641 // 4. The guest receives the final 'stop' message. |
642 // 5. The guest acks the 'stop' message with a 'stop_ack' message. | 642 // 5. The guest acks the 'stop' message with a 'stop_ack' message. |
643 // 6. The embedder changes its title to 'main guest' when it sees the 'stop_ack' | 643 // 6. The embedder changes its title to 'main guest' when it sees the 'stop_ack' |
644 // message. | 644 // message. |
645 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, PostMessage) { | 645 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, PostMessage) { |
646 const char* kTesting = "testing123"; | 646 const char* kTesting = "testing123"; |
647 const char* kEmbedderURL = "/browser_plugin_embedder.html"; | 647 const char* kEmbedderURL = "/browser_plugin_embedder.html"; |
648 const char* kGuestURL = "/browser_plugin_post_message_guest.html"; | 648 const char* kGuestURL = "/browser_plugin_post_message_guest.html"; |
649 StartBrowserPluginTest(kEmbedderURL, kGuestURL, false, std::string()); | 649 StartBrowserPluginTest(kEmbedderURL, kGuestURL, false, std::string()); |
650 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 650 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
651 test_embedder()->web_contents()->GetRenderViewHost()); | 651 test_embedder()->web_contents()->GetRenderViewHost()); |
652 { | 652 { |
653 const string16 expected_title = ASCIIToUTF16("main guest"); | 653 const base::string16 expected_title = ASCIIToUTF16("main guest"); |
654 content::TitleWatcher title_watcher(test_embedder()->web_contents(), | 654 content::TitleWatcher title_watcher(test_embedder()->web_contents(), |
655 expected_title); | 655 expected_title); |
656 | 656 |
657 // By the time we get here 'contentWindow' should be ready because the | 657 // By the time we get here 'contentWindow' should be ready because the |
658 // guest has completed loading. | 658 // guest has completed loading. |
659 ExecuteSyncJSFunction( | 659 ExecuteSyncJSFunction( |
660 rvh, base::StringPrintf("PostMessage('%s, false');", kTesting)); | 660 rvh, base::StringPrintf("PostMessage('%s, false');", kTesting)); |
661 | 661 |
662 // The title will be updated to "main guest" at the last stage of the | 662 // The title will be updated to "main guest" at the last stage of the |
663 // process described above. | 663 // process described above. |
664 string16 actual_title = title_watcher.WaitAndGetTitle(); | 664 base::string16 actual_title = title_watcher.WaitAndGetTitle(); |
665 EXPECT_EQ(expected_title, actual_title); | 665 EXPECT_EQ(expected_title, actual_title); |
666 } | 666 } |
667 } | 667 } |
668 | 668 |
669 // This is the same as BrowserPluginHostTest.PostMessage but also | 669 // This is the same as BrowserPluginHostTest.PostMessage but also |
670 // posts a message to an iframe. | 670 // posts a message to an iframe. |
671 // TODO(fsamuel): This test should replace the previous test once postMessage | 671 // TODO(fsamuel): This test should replace the previous test once postMessage |
672 // iframe targeting is fixed (see http://crbug.com/153701). | 672 // iframe targeting is fixed (see http://crbug.com/153701). |
673 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, DISABLED_PostMessageToIFrame) { | 673 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, DISABLED_PostMessageToIFrame) { |
674 const char* kTesting = "testing123"; | 674 const char* kTesting = "testing123"; |
675 const char* kEmbedderURL = "/browser_plugin_embedder.html"; | 675 const char* kEmbedderURL = "/browser_plugin_embedder.html"; |
676 const char* kGuestURL = "/browser_plugin_post_message_guest.html"; | 676 const char* kGuestURL = "/browser_plugin_post_message_guest.html"; |
677 StartBrowserPluginTest(kEmbedderURL, kGuestURL, false, std::string()); | 677 StartBrowserPluginTest(kEmbedderURL, kGuestURL, false, std::string()); |
678 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 678 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
679 test_embedder()->web_contents()->GetRenderViewHost()); | 679 test_embedder()->web_contents()->GetRenderViewHost()); |
680 { | 680 { |
681 const string16 expected_title = ASCIIToUTF16("main guest"); | 681 const base::string16 expected_title = ASCIIToUTF16("main guest"); |
682 content::TitleWatcher title_watcher(test_embedder()->web_contents(), | 682 content::TitleWatcher title_watcher(test_embedder()->web_contents(), |
683 expected_title); | 683 expected_title); |
684 | 684 |
685 ExecuteSyncJSFunction( | 685 ExecuteSyncJSFunction( |
686 rvh, base::StringPrintf("PostMessage('%s, false');", kTesting)); | 686 rvh, base::StringPrintf("PostMessage('%s, false');", kTesting)); |
687 | 687 |
688 // The title will be updated to "main guest" at the last stage of the | 688 // The title will be updated to "main guest" at the last stage of the |
689 // process described above. | 689 // process described above. |
690 string16 actual_title = title_watcher.WaitAndGetTitle(); | 690 base::string16 actual_title = title_watcher.WaitAndGetTitle(); |
691 EXPECT_EQ(expected_title, actual_title); | 691 EXPECT_EQ(expected_title, actual_title); |
692 } | 692 } |
693 { | 693 { |
694 content::TitleWatcher ready_watcher(test_embedder()->web_contents(), | 694 content::TitleWatcher ready_watcher(test_embedder()->web_contents(), |
695 ASCIIToUTF16("ready")); | 695 ASCIIToUTF16("ready")); |
696 | 696 |
697 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( | 697 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( |
698 test_guest()->web_contents()->GetRenderViewHost()); | 698 test_guest()->web_contents()->GetRenderViewHost()); |
699 GURL test_url = embedded_test_server()->GetURL( | 699 GURL test_url = embedded_test_server()->GetURL( |
700 "/browser_plugin_post_message_guest.html"); | 700 "/browser_plugin_post_message_guest.html"); |
701 ExecuteSyncJSFunction( | 701 ExecuteSyncJSFunction( |
702 guest_rvh, | 702 guest_rvh, |
703 base::StringPrintf( | 703 base::StringPrintf( |
704 "CreateChildFrame('%s');", test_url.spec().c_str())); | 704 "CreateChildFrame('%s');", test_url.spec().c_str())); |
705 | 705 |
706 string16 actual_title = ready_watcher.WaitAndGetTitle(); | 706 base::string16 actual_title = ready_watcher.WaitAndGetTitle(); |
707 EXPECT_EQ(ASCIIToUTF16("ready"), actual_title); | 707 EXPECT_EQ(ASCIIToUTF16("ready"), actual_title); |
708 | 708 |
709 content::TitleWatcher iframe_watcher(test_embedder()->web_contents(), | 709 content::TitleWatcher iframe_watcher(test_embedder()->web_contents(), |
710 ASCIIToUTF16("iframe")); | 710 ASCIIToUTF16("iframe")); |
711 ExecuteSyncJSFunction( | 711 ExecuteSyncJSFunction( |
712 rvh, base::StringPrintf("PostMessage('%s', true);", kTesting)); | 712 rvh, base::StringPrintf("PostMessage('%s', true);", kTesting)); |
713 | 713 |
714 // The title will be updated to "iframe" at the last stage of the | 714 // The title will be updated to "iframe" at the last stage of the |
715 // process described above. | 715 // process described above. |
716 actual_title = iframe_watcher.WaitAndGetTitle(); | 716 actual_title = iframe_watcher.WaitAndGetTitle(); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
804 // Attempt a navigation to chrome-guest://abc123, which is a valid URL. But it | 804 // Attempt a navigation to chrome-guest://abc123, which is a valid URL. But it |
805 // should be blocked because the scheme isn't web-safe or a pseudo-scheme. | 805 // should be blocked because the scheme isn't web-safe or a pseudo-scheme. |
806 ExecuteSyncJSFunction( | 806 ExecuteSyncJSFunction( |
807 test_embedder()->web_contents()->GetRenderViewHost(), | 807 test_embedder()->web_contents()->GetRenderViewHost(), |
808 base::StringPrintf("SetSrc('%s://abc123');", kGuestScheme)); | 808 base::StringPrintf("SetSrc('%s://abc123');", kGuestScheme)); |
809 EXPECT_TRUE(delegate->load_aborted()); | 809 EXPECT_TRUE(delegate->load_aborted()); |
810 EXPECT_TRUE(delegate->load_aborted_url().is_valid()); | 810 EXPECT_TRUE(delegate->load_aborted_url().is_valid()); |
811 } | 811 } |
812 | 812 |
813 } // namespace content | 813 } // namespace content |
OLD | NEW |