OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/strings/string_split.h" | 9 #include "base/strings/string_split.h" |
10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 "</body></html>"; | 88 "</body></html>"; |
89 const char kHTMLForGuestWithSize[] = | 89 const char kHTMLForGuestWithSize[] = |
90 "data:text/html," | 90 "data:text/html," |
91 "<html>" | 91 "<html>" |
92 "<body style=\"margin: 0px;\">" | 92 "<body style=\"margin: 0px;\">" |
93 "<img style=\"width: 100%; height: 400px;\"/>" | 93 "<img style=\"width: 100%; height: 400px;\"/>" |
94 "</body>" | 94 "</body>" |
95 "</html>"; | 95 "</html>"; |
96 | 96 |
97 std::string GetHTMLForGuestWithTitle(const std::string& title) { | 97 std::string GetHTMLForGuestWithTitle(const std::string& title) { |
98 return StringPrintf(kHTMLForGuestWithTitle, title.c_str()); | 98 return base::StringPrintf(kHTMLForGuestWithTitle, title.c_str()); |
99 } | 99 } |
100 | 100 |
101 } // namespace | 101 } // namespace |
102 | 102 |
103 namespace content { | 103 namespace content { |
104 | 104 |
105 // Test factory for creating test instances of BrowserPluginEmbedder and | 105 // Test factory for creating test instances of BrowserPluginEmbedder and |
106 // BrowserPluginGuest. | 106 // BrowserPluginGuest. |
107 class TestBrowserPluginHostFactory : public BrowserPluginHostFactory { | 107 class TestBrowserPluginHostFactory : public BrowserPluginHostFactory { |
108 public: | 108 public: |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 rvh->Focus(); | 320 rvh->Focus(); |
321 | 321 |
322 // Allow the test to do some operations on the embedder before we perform | 322 // Allow the test to do some operations on the embedder before we perform |
323 // the first navigation of the guest. | 323 // the first navigation of the guest. |
324 if (!embedder_code.empty()) | 324 if (!embedder_code.empty()) |
325 ExecuteSyncJSFunction(rvh, embedder_code); | 325 ExecuteSyncJSFunction(rvh, embedder_code); |
326 | 326 |
327 if (!is_guest_data_url) { | 327 if (!is_guest_data_url) { |
328 test_url = test_server()->GetURL(guest_url); | 328 test_url = test_server()->GetURL(guest_url); |
329 ExecuteSyncJSFunction( | 329 ExecuteSyncJSFunction( |
330 rvh, StringPrintf("SetSrc('%s');", test_url.spec().c_str())); | 330 rvh, base::StringPrintf("SetSrc('%s');", test_url.spec().c_str())); |
331 } else { | 331 } else { |
332 ExecuteSyncJSFunction( | 332 ExecuteSyncJSFunction( |
333 rvh, StringPrintf("SetSrc('%s');", guest_url.c_str())); | 333 rvh, base::StringPrintf("SetSrc('%s');", guest_url.c_str())); |
334 } | 334 } |
335 | 335 |
336 // Wait to make sure embedder is created/attached to WebContents. | 336 // Wait to make sure embedder is created/attached to WebContents. |
337 TestBrowserPluginHostFactory::GetInstance()->WaitForGuestManagerCreation(); | 337 TestBrowserPluginHostFactory::GetInstance()->WaitForGuestManagerCreation(); |
338 | 338 |
339 test_embedder_ = static_cast<TestBrowserPluginEmbedder*>( | 339 test_embedder_ = static_cast<TestBrowserPluginEmbedder*>( |
340 embedder_web_contents->GetBrowserPluginEmbedder()); | 340 embedder_web_contents->GetBrowserPluginEmbedder()); |
341 ASSERT_TRUE(test_embedder_); | 341 ASSERT_TRUE(test_embedder_); |
342 | 342 |
343 test_guest_manager_ = static_cast<TestBrowserPluginGuestManager*>( | 343 test_guest_manager_ = static_cast<TestBrowserPluginGuestManager*>( |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuestBusyLoop, true, ""); | 390 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuestBusyLoop, true, ""); |
391 // Wait until the busy loop starts. | 391 // Wait until the busy loop starts. |
392 { | 392 { |
393 const string16 expected_title = ASCIIToUTF16("start"); | 393 const string16 expected_title = ASCIIToUTF16("start"); |
394 content::TitleWatcher title_watcher(test_guest()->web_contents(), | 394 content::TitleWatcher title_watcher(test_guest()->web_contents(), |
395 expected_title); | 395 expected_title); |
396 // Hang the guest for a length of time. | 396 // Hang the guest for a length of time. |
397 int spin_time = 10 * TestTimeouts::tiny_timeout().InMilliseconds(); | 397 int spin_time = 10 * TestTimeouts::tiny_timeout().InMilliseconds(); |
398 ExecuteSyncJSFunction( | 398 ExecuteSyncJSFunction( |
399 test_guest()->web_contents()->GetRenderViewHost(), | 399 test_guest()->web_contents()->GetRenderViewHost(), |
400 StringPrintf("StartPauseMs(%d);", spin_time).c_str()); | 400 base::StringPrintf("StartPauseMs(%d);", spin_time).c_str()); |
401 | 401 |
402 string16 actual_title = title_watcher.WaitAndGetTitle(); | 402 string16 actual_title = title_watcher.WaitAndGetTitle(); |
403 EXPECT_EQ(expected_title, actual_title); | 403 EXPECT_EQ(expected_title, actual_title); |
404 } | 404 } |
405 { | 405 { |
406 const string16 expected_title = ASCIIToUTF16("done"); | 406 const string16 expected_title = ASCIIToUTF16("done"); |
407 content::TitleWatcher title_watcher(test_embedder()->web_contents(), | 407 content::TitleWatcher title_watcher(test_embedder()->web_contents(), |
408 expected_title); | 408 expected_title); |
409 | 409 |
410 // Send a mouse event to the guest. | 410 // Send a mouse event to the guest. |
(...skipping 21 matching lines...) Expand all Loading... |
432 } | 432 } |
433 | 433 |
434 // This test ensures that if guest isn't there and we resize the guest (from | 434 // This test ensures that if guest isn't there and we resize the guest (from |
435 // js), it remembers the size correctly. | 435 // js), it remembers the size correctly. |
436 // | 436 // |
437 // Initially we load an embedder with a guest without a src attribute (which has | 437 // Initially we load an embedder with a guest without a src attribute (which has |
438 // dimension 640x480), resize it to 100x200, and then we set the source to a | 438 // dimension 640x480), resize it to 100x200, and then we set the source to a |
439 // sample guest. In the end we verify that the correct size has been set. | 439 // sample guest. In the end we verify that the correct size has been set. |
440 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, NavigateAfterResize) { | 440 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, NavigateAfterResize) { |
441 const gfx::Size nxt_size = gfx::Size(100, 200); | 441 const gfx::Size nxt_size = gfx::Size(100, 200); |
442 const std::string embedder_code = | 442 const std::string embedder_code = base::StringPrintf( |
443 StringPrintf("SetSize(%d, %d);", nxt_size.width(), nxt_size.height()); | 443 "SetSize(%d, %d);", nxt_size.width(), nxt_size.height()); |
444 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; | 444 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; |
445 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, embedder_code); | 445 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, embedder_code); |
446 | 446 |
447 // Wait for the guest to receive a damage buffer of size 100x200. | 447 // Wait for the guest to receive a damage buffer of size 100x200. |
448 // This means the guest will be painted properly at that size. | 448 // This means the guest will be painted properly at that size. |
449 test_guest()->WaitForDamageBufferWithSize(nxt_size); | 449 test_guest()->WaitForDamageBufferWithSize(nxt_size); |
450 } | 450 } |
451 | 451 |
452 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, AdvanceFocus) { | 452 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, AdvanceFocus) { |
453 const char kEmbedderURL[] = "files/browser_plugin_focus.html"; | 453 const char kEmbedderURL[] = "files/browser_plugin_focus.html"; |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
619 test_embedder()->web_contents()->GetRenderViewHost()); | 619 test_embedder()->web_contents()->GetRenderViewHost()); |
620 | 620 |
621 // Navigate to P2 and verify that the navigation occurred. | 621 // Navigate to P2 and verify that the navigation occurred. |
622 { | 622 { |
623 const string16 expected_title = ASCIIToUTF16("P2"); | 623 const string16 expected_title = ASCIIToUTF16("P2"); |
624 content::TitleWatcher title_watcher(test_guest()->web_contents(), | 624 content::TitleWatcher title_watcher(test_guest()->web_contents(), |
625 expected_title); | 625 expected_title); |
626 | 626 |
627 ExecuteSyncJSFunction( | 627 ExecuteSyncJSFunction( |
628 rvh, | 628 rvh, |
629 StringPrintf("SetSrc('%s');", GetHTMLForGuestWithTitle("P2").c_str())); | 629 base::StringPrintf( |
| 630 "SetSrc('%s');", GetHTMLForGuestWithTitle("P2").c_str())); |
630 | 631 |
631 string16 actual_title = title_watcher.WaitAndGetTitle(); | 632 string16 actual_title = title_watcher.WaitAndGetTitle(); |
632 EXPECT_EQ(expected_title, actual_title); | 633 EXPECT_EQ(expected_title, actual_title); |
633 } | 634 } |
634 | 635 |
635 // Navigate to P3 and verify that the navigation occurred. | 636 // Navigate to P3 and verify that the navigation occurred. |
636 { | 637 { |
637 const string16 expected_title = ASCIIToUTF16("P3"); | 638 const string16 expected_title = ASCIIToUTF16("P3"); |
638 content::TitleWatcher title_watcher(test_guest()->web_contents(), | 639 content::TitleWatcher title_watcher(test_guest()->web_contents(), |
639 expected_title); | 640 expected_title); |
640 | 641 |
641 ExecuteSyncJSFunction( | 642 ExecuteSyncJSFunction( |
642 rvh, | 643 rvh, |
643 StringPrintf("SetSrc('%s');", GetHTMLForGuestWithTitle("P3").c_str())); | 644 base::StringPrintf( |
| 645 "SetSrc('%s');", GetHTMLForGuestWithTitle("P3").c_str())); |
644 | 646 |
645 string16 actual_title = title_watcher.WaitAndGetTitle(); | 647 string16 actual_title = title_watcher.WaitAndGetTitle(); |
646 EXPECT_EQ(expected_title, actual_title); | 648 EXPECT_EQ(expected_title, actual_title); |
647 } | 649 } |
648 | 650 |
649 // Go back and verify that we're back at P2. | 651 // Go back and verify that we're back at P2. |
650 { | 652 { |
651 const string16 expected_title = ASCIIToUTF16("P2"); | 653 const string16 expected_title = ASCIIToUTF16("P2"); |
652 content::TitleWatcher title_watcher(test_guest()->web_contents(), | 654 content::TitleWatcher title_watcher(test_guest()->web_contents(), |
653 expected_title); | 655 expected_title); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
712 test_embedder()->web_contents()->GetRenderViewHost()); | 714 test_embedder()->web_contents()->GetRenderViewHost()); |
713 | 715 |
714 // Change the title of the page to 'modified' so that we know that | 716 // Change the title of the page to 'modified' so that we know that |
715 // the page has successfully reloaded when it goes back to 'embedder' | 717 // the page has successfully reloaded when it goes back to 'embedder' |
716 // in the next step. | 718 // in the next step. |
717 { | 719 { |
718 const string16 expected_title = ASCIIToUTF16("modified"); | 720 const string16 expected_title = ASCIIToUTF16("modified"); |
719 content::TitleWatcher title_watcher(test_embedder()->web_contents(), | 721 content::TitleWatcher title_watcher(test_embedder()->web_contents(), |
720 expected_title); | 722 expected_title); |
721 | 723 |
722 ExecuteSyncJSFunction(rvh, StringPrintf("SetTitle('%s');", "modified")); | 724 ExecuteSyncJSFunction(rvh, |
| 725 base::StringPrintf("SetTitle('%s');", "modified")); |
723 | 726 |
724 string16 actual_title = title_watcher.WaitAndGetTitle(); | 727 string16 actual_title = title_watcher.WaitAndGetTitle(); |
725 EXPECT_EQ(expected_title, actual_title); | 728 EXPECT_EQ(expected_title, actual_title); |
726 } | 729 } |
727 | 730 |
728 // Reload the embedder page, and verify that the reload was successful. | 731 // Reload the embedder page, and verify that the reload was successful. |
729 // Then navigate the guest to verify that the browser process does not crash. | 732 // Then navigate the guest to verify that the browser process does not crash. |
730 { | 733 { |
731 const string16 expected_title = ASCIIToUTF16("embedder"); | 734 const string16 expected_title = ASCIIToUTF16("embedder"); |
732 content::TitleWatcher title_watcher(test_embedder()->web_contents(), | 735 content::TitleWatcher title_watcher(test_embedder()->web_contents(), |
733 expected_title); | 736 expected_title); |
734 | 737 |
735 test_embedder()->web_contents()->GetController().Reload(false); | 738 test_embedder()->web_contents()->GetController().Reload(false); |
736 string16 actual_title = title_watcher.WaitAndGetTitle(); | 739 string16 actual_title = title_watcher.WaitAndGetTitle(); |
737 EXPECT_EQ(expected_title, actual_title); | 740 EXPECT_EQ(expected_title, actual_title); |
738 | 741 |
739 ExecuteSyncJSFunction( | 742 ExecuteSyncJSFunction( |
740 test_embedder()->web_contents()->GetRenderViewHost(), | 743 test_embedder()->web_contents()->GetRenderViewHost(), |
741 StringPrintf("SetSrc('%s');", kHTMLForGuest)); | 744 base::StringPrintf("SetSrc('%s');", kHTMLForGuest)); |
742 test_guest_manager()->WaitForGuestAdded(); | 745 test_guest_manager()->WaitForGuestAdded(); |
743 | 746 |
744 const TestBrowserPluginGuestManager::GuestInstanceMap& instance_map = | 747 const TestBrowserPluginGuestManager::GuestInstanceMap& instance_map = |
745 test_guest_manager()->guest_web_contents_for_testing(); | 748 test_guest_manager()->guest_web_contents_for_testing(); |
746 WebContentsImpl* test_guest_web_contents = static_cast<WebContentsImpl*>( | 749 WebContentsImpl* test_guest_web_contents = static_cast<WebContentsImpl*>( |
747 instance_map.begin()->second); | 750 instance_map.begin()->second); |
748 TestBrowserPluginGuest* new_test_guest = | 751 TestBrowserPluginGuest* new_test_guest = |
749 static_cast<TestBrowserPluginGuest*>( | 752 static_cast<TestBrowserPluginGuest*>( |
750 test_guest_web_contents->GetBrowserPluginGuest()); | 753 test_guest_web_contents->GetBrowserPluginGuest()); |
751 ASSERT_TRUE(new_test_guest != NULL); | 754 ASSERT_TRUE(new_test_guest != NULL); |
(...skipping 25 matching lines...) Expand all Loading... |
777 test_embedder()->web_contents()->GetRenderViewHost()); | 780 test_embedder()->web_contents()->GetRenderViewHost()); |
778 | 781 |
779 // Navigate to P2 and verify that the navigation occurred. | 782 // Navigate to P2 and verify that the navigation occurred. |
780 { | 783 { |
781 const string16 expected_title = ASCIIToUTF16("P2"); | 784 const string16 expected_title = ASCIIToUTF16("P2"); |
782 content::TitleWatcher title_watcher(test_guest()->web_contents(), | 785 content::TitleWatcher title_watcher(test_guest()->web_contents(), |
783 expected_title); | 786 expected_title); |
784 | 787 |
785 ExecuteSyncJSFunction( | 788 ExecuteSyncJSFunction( |
786 rvh, | 789 rvh, |
787 StringPrintf("SetSrc('%s');", GetHTMLForGuestWithTitle("P2").c_str())); | 790 base::StringPrintf( |
| 791 "SetSrc('%s');", GetHTMLForGuestWithTitle("P2").c_str())); |
788 | 792 |
789 string16 actual_title = title_watcher.WaitAndGetTitle(); | 793 string16 actual_title = title_watcher.WaitAndGetTitle(); |
790 EXPECT_EQ(expected_title, actual_title); | 794 EXPECT_EQ(expected_title, actual_title); |
791 } | 795 } |
792 // Kill the guest. | 796 // Kill the guest. |
793 ExecuteSyncJSFunction(rvh, "document.getElementById('plugin').terminate()"); | 797 ExecuteSyncJSFunction(rvh, "document.getElementById('plugin').terminate()"); |
794 | 798 |
795 // Expect the guest to report that it crashed. | 799 // Expect the guest to report that it crashed. |
796 test_guest()->WaitForExit(); | 800 test_guest()->WaitForExit(); |
797 // Go back and verify that we're back at P1. | 801 // Go back and verify that we're back at P1. |
(...skipping 16 matching lines...) Expand all Loading... |
814 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadStart) { | 818 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadStart) { |
815 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; | 819 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; |
816 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, ""); | 820 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, ""); |
817 | 821 |
818 const string16 expected_title = ASCIIToUTF16(kHTMLForGuest); | 822 const string16 expected_title = ASCIIToUTF16(kHTMLForGuest); |
819 content::TitleWatcher title_watcher(test_embedder()->web_contents(), | 823 content::TitleWatcher title_watcher(test_embedder()->web_contents(), |
820 expected_title); | 824 expected_title); |
821 // Renavigate the guest to |kHTMLForGuest|. | 825 // Renavigate the guest to |kHTMLForGuest|. |
822 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 826 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
823 test_embedder()->web_contents()->GetRenderViewHost()); | 827 test_embedder()->web_contents()->GetRenderViewHost()); |
824 ExecuteSyncJSFunction(rvh, StringPrintf("SetSrc('%s');", kHTMLForGuest)); | 828 ExecuteSyncJSFunction(rvh, |
| 829 base::StringPrintf("SetSrc('%s');", kHTMLForGuest)); |
825 | 830 |
826 string16 actual_title = title_watcher.WaitAndGetTitle(); | 831 string16 actual_title = title_watcher.WaitAndGetTitle(); |
827 EXPECT_EQ(expected_title, actual_title); | 832 EXPECT_EQ(expected_title, actual_title); |
828 } | 833 } |
829 | 834 |
830 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadAbort) { | 835 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadAbort) { |
831 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; | 836 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; |
832 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, ""); | 837 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, ""); |
833 | 838 |
834 { | 839 { |
835 // Navigate the guest to "close-socket". | 840 // Navigate the guest to "close-socket". |
836 const string16 expected_title = ASCIIToUTF16("ERR_EMPTY_RESPONSE"); | 841 const string16 expected_title = ASCIIToUTF16("ERR_EMPTY_RESPONSE"); |
837 content::TitleWatcher title_watcher(test_embedder()->web_contents(), | 842 content::TitleWatcher title_watcher(test_embedder()->web_contents(), |
838 expected_title); | 843 expected_title); |
839 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 844 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
840 test_embedder()->web_contents()->GetRenderViewHost()); | 845 test_embedder()->web_contents()->GetRenderViewHost()); |
841 GURL test_url = test_server()->GetURL("close-socket"); | 846 GURL test_url = test_server()->GetURL("close-socket"); |
842 ExecuteSyncJSFunction( | 847 ExecuteSyncJSFunction( |
843 rvh, StringPrintf("SetSrc('%s');", test_url.spec().c_str())); | 848 rvh, base::StringPrintf("SetSrc('%s');", test_url.spec().c_str())); |
844 string16 actual_title = title_watcher.WaitAndGetTitle(); | 849 string16 actual_title = title_watcher.WaitAndGetTitle(); |
845 EXPECT_EQ(expected_title, actual_title); | 850 EXPECT_EQ(expected_title, actual_title); |
846 } | 851 } |
847 | 852 |
848 { | 853 { |
849 // Navigate the guest to an illegal chrome:// URL. | 854 // Navigate the guest to an illegal chrome:// URL. |
850 const string16 expected_title = ASCIIToUTF16("ERR_INVALID_URL"); | 855 const string16 expected_title = ASCIIToUTF16("ERR_INVALID_URL"); |
851 content::TitleWatcher title_watcher(test_embedder()->web_contents(), | 856 content::TitleWatcher title_watcher(test_embedder()->web_contents(), |
852 expected_title); | 857 expected_title); |
853 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 858 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
854 test_embedder()->web_contents()->GetRenderViewHost()); | 859 test_embedder()->web_contents()->GetRenderViewHost()); |
855 GURL test_url("chrome://newtab"); | 860 GURL test_url("chrome://newtab"); |
856 ExecuteSyncJSFunction( | 861 ExecuteSyncJSFunction( |
857 rvh, StringPrintf("SetSrc('%s');", test_url.spec().c_str())); | 862 rvh, base::StringPrintf("SetSrc('%s');", test_url.spec().c_str())); |
858 string16 actual_title = title_watcher.WaitAndGetTitle(); | 863 string16 actual_title = title_watcher.WaitAndGetTitle(); |
859 EXPECT_EQ(expected_title, actual_title); | 864 EXPECT_EQ(expected_title, actual_title); |
860 } | 865 } |
861 | 866 |
862 { | 867 { |
863 // Navigate the guest to an illegal file:// URL. | 868 // Navigate the guest to an illegal file:// URL. |
864 const string16 expected_title = ASCIIToUTF16("ERR_ABORTED"); | 869 const string16 expected_title = ASCIIToUTF16("ERR_ABORTED"); |
865 content::TitleWatcher title_watcher(test_embedder()->web_contents(), | 870 content::TitleWatcher title_watcher(test_embedder()->web_contents(), |
866 expected_title); | 871 expected_title); |
867 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 872 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
868 test_embedder()->web_contents()->GetRenderViewHost()); | 873 test_embedder()->web_contents()->GetRenderViewHost()); |
869 GURL test_url("file://foo"); | 874 GURL test_url("file://foo"); |
870 ExecuteSyncJSFunction( | 875 ExecuteSyncJSFunction( |
871 rvh, StringPrintf("SetSrc('%s');", test_url.spec().c_str())); | 876 rvh, base::StringPrintf("SetSrc('%s');", test_url.spec().c_str())); |
872 string16 actual_title = title_watcher.WaitAndGetTitle(); | 877 string16 actual_title = title_watcher.WaitAndGetTitle(); |
873 EXPECT_EQ(expected_title, actual_title); | 878 EXPECT_EQ(expected_title, actual_title); |
874 } | 879 } |
875 } | 880 } |
876 | 881 |
877 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadRedirect) { | 882 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadRedirect) { |
878 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; | 883 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; |
879 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, ""); | 884 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, ""); |
880 | 885 |
881 const string16 expected_title = ASCIIToUTF16("redirected"); | 886 const string16 expected_title = ASCIIToUTF16("redirected"); |
882 content::TitleWatcher title_watcher(test_embedder()->web_contents(), | 887 content::TitleWatcher title_watcher(test_embedder()->web_contents(), |
883 expected_title); | 888 expected_title); |
884 | 889 |
885 // Navigate with a redirect and wait until the title changes. | 890 // Navigate with a redirect and wait until the title changes. |
886 GURL redirect_url(test_server()->GetURL( | 891 GURL redirect_url(test_server()->GetURL( |
887 "server-redirect?files/title1.html")); | 892 "server-redirect?files/title1.html")); |
888 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 893 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
889 test_embedder()->web_contents()->GetRenderViewHost()); | 894 test_embedder()->web_contents()->GetRenderViewHost()); |
890 ExecuteSyncJSFunction( | 895 ExecuteSyncJSFunction( |
891 rvh, StringPrintf("SetSrc('%s');", redirect_url.spec().c_str())); | 896 rvh, base::StringPrintf("SetSrc('%s');", redirect_url.spec().c_str())); |
892 | 897 |
893 string16 actual_title = title_watcher.WaitAndGetTitle(); | 898 string16 actual_title = title_watcher.WaitAndGetTitle(); |
894 EXPECT_EQ(expected_title, actual_title); | 899 EXPECT_EQ(expected_title, actual_title); |
895 | 900 |
896 // Verify that we heard a loadRedirect during the navigation. | 901 // Verify that we heard a loadRedirect during the navigation. |
897 scoped_ptr<base::Value> value = | 902 scoped_ptr<base::Value> value = |
898 content::ExecuteScriptAndGetValue(rvh, "redirectOldUrl"); | 903 content::ExecuteScriptAndGetValue(rvh, "redirectOldUrl"); |
899 std::string result; | 904 std::string result; |
900 EXPECT_TRUE(value->GetAsString(&result)); | 905 EXPECT_TRUE(value->GetAsString(&result)); |
901 EXPECT_EQ(redirect_url.spec().c_str(), result); | 906 EXPECT_EQ(redirect_url.spec().c_str(), result); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
976 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 981 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
977 test_embedder()->web_contents()->GetRenderViewHost()); | 982 test_embedder()->web_contents()->GetRenderViewHost()); |
978 { | 983 { |
979 const string16 expected_title = ASCIIToUTF16("main guest"); | 984 const string16 expected_title = ASCIIToUTF16("main guest"); |
980 content::TitleWatcher title_watcher(test_embedder()->web_contents(), | 985 content::TitleWatcher title_watcher(test_embedder()->web_contents(), |
981 expected_title); | 986 expected_title); |
982 | 987 |
983 // By the time we get here 'contentWindow' should be ready because the | 988 // By the time we get here 'contentWindow' should be ready because the |
984 // guest has completed loading. | 989 // guest has completed loading. |
985 ExecuteSyncJSFunction( | 990 ExecuteSyncJSFunction( |
986 rvh, StringPrintf("PostMessage('%s, false');", kTesting)); | 991 rvh, base::StringPrintf("PostMessage('%s, false');", kTesting)); |
987 | 992 |
988 // The title will be updated to "main guest" at the last stage of the | 993 // The title will be updated to "main guest" at the last stage of the |
989 // process described above. | 994 // process described above. |
990 string16 actual_title = title_watcher.WaitAndGetTitle(); | 995 string16 actual_title = title_watcher.WaitAndGetTitle(); |
991 EXPECT_EQ(expected_title, actual_title); | 996 EXPECT_EQ(expected_title, actual_title); |
992 } | 997 } |
993 } | 998 } |
994 | 999 |
995 // This is the same as BrowserPluginHostTest.PostMessage but also | 1000 // This is the same as BrowserPluginHostTest.PostMessage but also |
996 // posts a message to an iframe. | 1001 // posts a message to an iframe. |
997 // TODO(fsamuel): This test should replace the previous test once postMessage | 1002 // TODO(fsamuel): This test should replace the previous test once postMessage |
998 // iframe targeting is fixed (see http://crbug.com/153701). | 1003 // iframe targeting is fixed (see http://crbug.com/153701). |
999 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, DISABLED_PostMessageToIFrame) { | 1004 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, DISABLED_PostMessageToIFrame) { |
1000 const char* kTesting = "testing123"; | 1005 const char* kTesting = "testing123"; |
1001 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 1006 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; |
1002 const char* kGuestURL = "files/browser_plugin_post_message_guest.html"; | 1007 const char* kGuestURL = "files/browser_plugin_post_message_guest.html"; |
1003 StartBrowserPluginTest(kEmbedderURL, kGuestURL, false, ""); | 1008 StartBrowserPluginTest(kEmbedderURL, kGuestURL, false, ""); |
1004 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 1009 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
1005 test_embedder()->web_contents()->GetRenderViewHost()); | 1010 test_embedder()->web_contents()->GetRenderViewHost()); |
1006 { | 1011 { |
1007 const string16 expected_title = ASCIIToUTF16("main guest"); | 1012 const string16 expected_title = ASCIIToUTF16("main guest"); |
1008 content::TitleWatcher title_watcher(test_embedder()->web_contents(), | 1013 content::TitleWatcher title_watcher(test_embedder()->web_contents(), |
1009 expected_title); | 1014 expected_title); |
1010 | 1015 |
1011 ExecuteSyncJSFunction( | 1016 ExecuteSyncJSFunction( |
1012 rvh, StringPrintf("PostMessage('%s, false');", kTesting)); | 1017 rvh, base::StringPrintf("PostMessage('%s, false');", kTesting)); |
1013 | 1018 |
1014 // The title will be updated to "main guest" at the last stage of the | 1019 // The title will be updated to "main guest" at the last stage of the |
1015 // process described above. | 1020 // process described above. |
1016 string16 actual_title = title_watcher.WaitAndGetTitle(); | 1021 string16 actual_title = title_watcher.WaitAndGetTitle(); |
1017 EXPECT_EQ(expected_title, actual_title); | 1022 EXPECT_EQ(expected_title, actual_title); |
1018 } | 1023 } |
1019 { | 1024 { |
1020 content::TitleWatcher ready_watcher(test_embedder()->web_contents(), | 1025 content::TitleWatcher ready_watcher(test_embedder()->web_contents(), |
1021 ASCIIToUTF16("ready")); | 1026 ASCIIToUTF16("ready")); |
1022 | 1027 |
1023 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( | 1028 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( |
1024 test_guest()->web_contents()->GetRenderViewHost()); | 1029 test_guest()->web_contents()->GetRenderViewHost()); |
1025 GURL test_url = test_server()->GetURL( | 1030 GURL test_url = test_server()->GetURL( |
1026 "files/browser_plugin_post_message_guest.html"); | 1031 "files/browser_plugin_post_message_guest.html"); |
1027 ExecuteSyncJSFunction( | 1032 ExecuteSyncJSFunction( |
1028 guest_rvh, | 1033 guest_rvh, |
1029 StringPrintf("CreateChildFrame('%s');", test_url.spec().c_str())); | 1034 base::StringPrintf( |
| 1035 "CreateChildFrame('%s');", test_url.spec().c_str())); |
1030 | 1036 |
1031 string16 actual_title = ready_watcher.WaitAndGetTitle(); | 1037 string16 actual_title = ready_watcher.WaitAndGetTitle(); |
1032 EXPECT_EQ(ASCIIToUTF16("ready"), actual_title); | 1038 EXPECT_EQ(ASCIIToUTF16("ready"), actual_title); |
1033 | 1039 |
1034 content::TitleWatcher iframe_watcher(test_embedder()->web_contents(), | 1040 content::TitleWatcher iframe_watcher(test_embedder()->web_contents(), |
1035 ASCIIToUTF16("iframe")); | 1041 ASCIIToUTF16("iframe")); |
1036 ExecuteSyncJSFunction( | 1042 ExecuteSyncJSFunction( |
1037 rvh, StringPrintf("PostMessage('%s', true);", kTesting)); | 1043 rvh, base::StringPrintf("PostMessage('%s', true);", kTesting)); |
1038 | 1044 |
1039 // The title will be updated to "iframe" at the last stage of the | 1045 // The title will be updated to "iframe" at the last stage of the |
1040 // process described above. | 1046 // process described above. |
1041 actual_title = iframe_watcher.WaitAndGetTitle(); | 1047 actual_title = iframe_watcher.WaitAndGetTitle(); |
1042 EXPECT_EQ(ASCIIToUTF16("iframe"), actual_title); | 1048 EXPECT_EQ(ASCIIToUTF16("iframe"), actual_title); |
1043 } | 1049 } |
1044 } | 1050 } |
1045 | 1051 |
1046 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadStop) { | 1052 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadStop) { |
1047 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 1053 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; |
1048 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, ""); | 1054 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, ""); |
1049 | 1055 |
1050 const string16 expected_title = ASCIIToUTF16("loadStop"); | 1056 const string16 expected_title = ASCIIToUTF16("loadStop"); |
1051 content::TitleWatcher title_watcher( | 1057 content::TitleWatcher title_watcher( |
1052 test_embedder()->web_contents(), expected_title); | 1058 test_embedder()->web_contents(), expected_title); |
1053 // Renavigate the guest to |kHTMLForGuest|. | 1059 // Renavigate the guest to |kHTMLForGuest|. |
1054 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 1060 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
1055 test_embedder()->web_contents()->GetRenderViewHost()); | 1061 test_embedder()->web_contents()->GetRenderViewHost()); |
1056 ExecuteSyncJSFunction(rvh, StringPrintf("SetSrc('%s');", kHTMLForGuest)); | 1062 ExecuteSyncJSFunction(rvh, |
| 1063 base::StringPrintf("SetSrc('%s');", kHTMLForGuest)); |
1057 | 1064 |
1058 string16 actual_title = title_watcher.WaitAndGetTitle(); | 1065 string16 actual_title = title_watcher.WaitAndGetTitle(); |
1059 EXPECT_EQ(expected_title, actual_title); | 1066 EXPECT_EQ(expected_title, actual_title); |
1060 } | 1067 } |
1061 | 1068 |
1062 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadCommit) { | 1069 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadCommit) { |
1063 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 1070 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; |
1064 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, ""); | 1071 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, ""); |
1065 | 1072 |
1066 const string16 expected_title = ASCIIToUTF16( | 1073 const string16 expected_title = ASCIIToUTF16( |
1067 StringPrintf("loadCommit:%s", kHTMLForGuest)); | 1074 base::StringPrintf("loadCommit:%s", kHTMLForGuest)); |
1068 content::TitleWatcher title_watcher( | 1075 content::TitleWatcher title_watcher( |
1069 test_embedder()->web_contents(), expected_title); | 1076 test_embedder()->web_contents(), expected_title); |
1070 // Renavigate the guest to |kHTMLForGuest|. | 1077 // Renavigate the guest to |kHTMLForGuest|. |
1071 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 1078 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
1072 test_embedder()->web_contents()->GetRenderViewHost()); | 1079 test_embedder()->web_contents()->GetRenderViewHost()); |
1073 ExecuteSyncJSFunction(rvh, StringPrintf("SetSrc('%s');", kHTMLForGuest)); | 1080 ExecuteSyncJSFunction(rvh, |
| 1081 base::StringPrintf("SetSrc('%s');", kHTMLForGuest)); |
1074 | 1082 |
1075 string16 actual_title = title_watcher.WaitAndGetTitle(); | 1083 string16 actual_title = title_watcher.WaitAndGetTitle(); |
1076 EXPECT_EQ(expected_title, actual_title); | 1084 EXPECT_EQ(expected_title, actual_title); |
1077 scoped_ptr<base::Value> is_top_level = | 1085 scoped_ptr<base::Value> is_top_level = |
1078 content::ExecuteScriptAndGetValue(rvh, "commitIsTopLevel"); | 1086 content::ExecuteScriptAndGetValue(rvh, "commitIsTopLevel"); |
1079 bool top_level_bool = false; | 1087 bool top_level_bool = false; |
1080 EXPECT_TRUE(is_top_level->GetAsBoolean(&top_level_bool)); | 1088 EXPECT_TRUE(is_top_level->GetAsBoolean(&top_level_bool)); |
1081 EXPECT_EQ(true, top_level_bool); | 1089 EXPECT_EQ(true, top_level_bool); |
1082 } | 1090 } |
1083 | 1091 |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1252 // Turn off autoSize and verify that the guest resizes to fit the container. | 1260 // Turn off autoSize and verify that the guest resizes to fit the container. |
1253 ExecuteSyncJSFunction( | 1261 ExecuteSyncJSFunction( |
1254 rvh, "document.getElementById('plugin').autosize = null;"); | 1262 rvh, "document.getElementById('plugin').autosize = null;"); |
1255 test_guest()->WaitForViewSize(gfx::Size(640, 480)); | 1263 test_guest()->WaitForViewSize(gfx::Size(640, 480)); |
1256 } | 1264 } |
1257 } | 1265 } |
1258 | 1266 |
1259 // Test for regression http://crbug.com/162961. | 1267 // Test for regression http://crbug.com/162961. |
1260 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, GetRenderViewHostAtPositionTest) { | 1268 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, GetRenderViewHostAtPositionTest) { |
1261 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; | 1269 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; |
1262 const std::string embedder_code = StringPrintf("SetSize(%d, %d);", 100, 100); | 1270 const std::string embedder_code = |
| 1271 base::StringPrintf("SetSize(%d, %d);", 100, 100); |
1263 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuestWithSize, true, | 1272 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuestWithSize, true, |
1264 embedder_code); | 1273 embedder_code); |
1265 // Check for render view host at position (150, 150) that is outside the | 1274 // Check for render view host at position (150, 150) that is outside the |
1266 // bounds of our guest, so this would respond with the render view host of the | 1275 // bounds of our guest, so this would respond with the render view host of the |
1267 // embedder. | 1276 // embedder. |
1268 test_embedder()->WaitForRenderViewHostAtPosition(150, 150); | 1277 test_embedder()->WaitForRenderViewHostAtPosition(150, 150); |
1269 ASSERT_EQ(test_embedder()->web_contents()->GetRenderViewHost(), | 1278 ASSERT_EQ(test_embedder()->web_contents()->GetRenderViewHost(), |
1270 test_embedder()->last_rvh_at_position_response()); | 1279 test_embedder()->last_rvh_at_position_response()); |
1271 } | 1280 } |
1272 | 1281 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1382 const string16 expected_title = ASCIIToUTF16("AutoSize(640, 480)"); | 1391 const string16 expected_title = ASCIIToUTF16("AutoSize(640, 480)"); |
1383 content::TitleWatcher title_watcher(test_embedder()->web_contents(), | 1392 content::TitleWatcher title_watcher(test_embedder()->web_contents(), |
1384 expected_title); | 1393 expected_title); |
1385 RemoveAttributes(rvh, "maxwidth"); | 1394 RemoveAttributes(rvh, "maxwidth"); |
1386 string16 actual_title = title_watcher.WaitAndGetTitle(); | 1395 string16 actual_title = title_watcher.WaitAndGetTitle(); |
1387 EXPECT_EQ(expected_title, actual_title); | 1396 EXPECT_EQ(expected_title, actual_title); |
1388 } | 1397 } |
1389 } | 1398 } |
1390 | 1399 |
1391 } // namespace content | 1400 } // namespace content |
OLD | NEW |