| 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/memory/singleton.h" | 5 #include "base/memory/singleton.h" |
| 6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
| 7 #include "base/test/test_timeouts.h" | 7 #include "base/test/test_timeouts.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "content/browser/browser_plugin/browser_plugin_guest.h" | 9 #include "content/browser/browser_plugin/browser_plugin_guest.h" |
| 10 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" | 10 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" |
| (...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 788 content::TitleWatcher title_watcher(test_guest_web_contents, | 788 content::TitleWatcher title_watcher(test_guest_web_contents, |
| 789 expected_title); | 789 expected_title); |
| 790 | 790 |
| 791 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16("Go(-2);")); | 791 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16("Go(-2);")); |
| 792 | 792 |
| 793 string16 actual_title = title_watcher.WaitAndGetTitle(); | 793 string16 actual_title = title_watcher.WaitAndGetTitle(); |
| 794 EXPECT_EQ(expected_title, actual_title); | 794 EXPECT_EQ(expected_title, actual_title); |
| 795 } | 795 } |
| 796 } | 796 } |
| 797 | 797 |
| 798 // This tests verifies that reloading the embedder does not crash the browser |
| 799 // and that the guest is reset. |
| 800 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, ReloadEmbedder) { |
| 801 ASSERT_TRUE(test_server()->Start()); |
| 802 GURL test_url(test_server()->GetURL( |
| 803 "files/browser_plugin_embedder.html")); |
| 804 NavigateToURL(shell(), test_url); |
| 805 |
| 806 WebContentsImpl* embedder_web_contents = static_cast<WebContentsImpl*>( |
| 807 shell()->web_contents()); |
| 808 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
| 809 embedder_web_contents->GetRenderViewHost()); |
| 810 |
| 811 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16( |
| 812 StringPrintf("SetSrc('%s');", kHTMLForGuest))); |
| 813 |
| 814 // Wait to make sure embedder is created/attached to WebContents. |
| 815 TestBrowserPluginHostFactory::GetInstance()->WaitForEmbedderCreation(); |
| 816 |
| 817 TestBrowserPluginEmbedder* test_embedder = |
| 818 static_cast<TestBrowserPluginEmbedder*>( |
| 819 embedder_web_contents->GetBrowserPluginEmbedder()); |
| 820 ASSERT_TRUE(test_embedder); |
| 821 test_embedder->WaitForGuestAdded(); |
| 822 |
| 823 // Verify that we have exactly one guest. |
| 824 const BrowserPluginEmbedder::ContainerInstanceMap& instance_map = |
| 825 test_embedder->guest_web_contents_for_testing(); |
| 826 EXPECT_EQ(1u, instance_map.size()); |
| 827 |
| 828 WebContentsImpl* test_guest_web_contents = static_cast<WebContentsImpl*>( |
| 829 instance_map.begin()->second); |
| 830 TestBrowserPluginGuest* test_guest = static_cast<TestBrowserPluginGuest*>( |
| 831 test_guest_web_contents->GetBrowserPluginGuest()); |
| 832 |
| 833 // Wait for the guest to send an UpdateRectMsg, meaning it is ready. |
| 834 test_guest->WaitForUpdateRectMsg(); |
| 835 |
| 836 // Change the title of the page to 'modified' so that we know that |
| 837 // the page has successfully reloaded when it goes back to 'embedder' |
| 838 // in the next step. |
| 839 { |
| 840 const string16 expected_title = ASCIIToUTF16("modified"); |
| 841 content::TitleWatcher title_watcher(embedder_web_contents, |
| 842 expected_title); |
| 843 |
| 844 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16( |
| 845 StringPrintf("SetTitle('%s');", "modified"))); |
| 846 |
| 847 string16 actual_title = title_watcher.WaitAndGetTitle(); |
| 848 EXPECT_EQ(expected_title, actual_title); |
| 849 } |
| 850 |
| 851 // Reload the embedder page, and verify that the reload was successful. |
| 852 // Then navigate the guest to verify that the browser process does not crash. |
| 853 { |
| 854 const string16 expected_title = ASCIIToUTF16("embedder"); |
| 855 content::TitleWatcher title_watcher(embedder_web_contents, |
| 856 expected_title); |
| 857 |
| 858 embedder_web_contents->GetController().Reload(false); |
| 859 string16 actual_title = title_watcher.WaitAndGetTitle(); |
| 860 EXPECT_EQ(expected_title, actual_title); |
| 861 |
| 862 embedder_web_contents->GetRenderViewHost()-> |
| 863 ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16( |
| 864 StringPrintf("SetSrc('%s');", kHTMLForGuest))); |
| 865 |
| 866 WebContentsImpl* test_guest_web_contents = static_cast<WebContentsImpl*>( |
| 867 instance_map.begin()->second); |
| 868 TestBrowserPluginGuest* test_guest = static_cast<TestBrowserPluginGuest*>( |
| 869 test_guest_web_contents->GetBrowserPluginGuest()); |
| 870 |
| 871 // Wait for the guest to send an UpdateRectMsg, meaning it is ready. |
| 872 test_guest->WaitForUpdateRectMsg(); |
| 873 } |
| 874 } |
| 875 |
| 798 | 876 |
| 799 } // namespace content | 877 } // namespace content |
| OLD | NEW |