Chromium Code Reviews| Index: content/browser/browser_plugin/browser_plugin_host_browsertest.cc |
| diff --git a/content/browser/browser_plugin/browser_plugin_host_browsertest.cc b/content/browser/browser_plugin/browser_plugin_host_browsertest.cc |
| index d64c134e26a71284e965fdd23d0e9c84bc926663..8ddb05960e933cc9773fbc9573471e0caf87f476 100644 |
| --- a/content/browser/browser_plugin/browser_plugin_host_browsertest.cc |
| +++ b/content/browser/browser_plugin/browser_plugin_host_browsertest.cc |
| @@ -480,4 +480,88 @@ IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, VisibilityChanged) { |
| test_guest->WaitUntilHidden(); |
| } |
| +// This test verifies that calling the reload method reloads the guest. |
| +IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, ReloadGuest) { |
| + ASSERT_TRUE(test_server()->Start()); |
| + GURL test_url(test_server()->GetURL( |
| + "files/browser_plugin_embedder.html")); |
| + NavigateToURL(shell(), test_url); |
| + |
| + WebContentsImpl* embedder_web_contents = static_cast<WebContentsImpl*>( |
| + shell()->web_contents()); |
| + RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
| + embedder_web_contents->GetRenderViewHost()); |
| + |
| + rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16( |
| + StringPrintf("SetSrc('%s');", kHTMLForGuest))); |
| + |
| + // Wait to make sure embedder is created/attached to WebContents. |
| + TestBrowserPluginHostFactory::GetInstance()->WaitForEmbedderCreation(); |
| + |
| + TestBrowserPluginEmbedder* test_embedder = |
| + static_cast<TestBrowserPluginEmbedder*>( |
| + embedder_web_contents->GetBrowserPluginEmbedder()); |
| + ASSERT_TRUE(test_embedder); |
| + test_embedder->WaitForGuestAdded(); |
|
Charlie Reis
2012/09/19 22:17:09
Does this work if the guest has already been added
Fady Samuel
2012/09/19 23:29:20
Yes, this returns immediately if a guest has alrea
|
| + |
| + // Verify that we have exactly one guest. |
| + const BrowserPluginEmbedder::ContainerInstanceMap& instance_map = |
| + test_embedder->guest_web_contents_for_testing(); |
| + EXPECT_EQ(1u, instance_map.size()); |
| + |
| + WebContentsImpl* test_guest_web_contents = static_cast<WebContentsImpl*>( |
| + instance_map.begin()->second); |
| + TestBrowserPluginGuest* test_guest = static_cast<TestBrowserPluginGuest*>( |
| + test_guest_web_contents->GetBrowserPluginGuest()); |
| + test_guest->WaitForUpdateRectMsg(); |
| + test_guest->ResetUpdateRectCount(); |
| + |
| + rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16( |
| + "document.getElementById('plugin').reload()")); |
| + // A successful reload will force the page to repaint itself as well, and |
| + // thereby issue a ViewHostMsg_UpdateRect message. |
| + test_guest->WaitForUpdateRectMsg(); |
|
Charlie Reis
2012/09/19 22:17:09
Couldn't other things cause this message (like an
Fady Samuel
2012/09/19 23:29:20
Done. Implemented WaitForReload()
|
| +} |
| + |
| +// This test verifies that calling the stop method forwards the stop request |
| +// to the guest's WebContents. |
| +IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, StopGuest) { |
| + ASSERT_TRUE(test_server()->Start()); |
| + GURL test_url(test_server()->GetURL( |
| + "files/browser_plugin_embedder.html")); |
| + NavigateToURL(shell(), test_url); |
| + |
| + WebContentsImpl* embedder_web_contents = static_cast<WebContentsImpl*>( |
| + shell()->web_contents()); |
| + RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
| + embedder_web_contents->GetRenderViewHost()); |
| + |
| + rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16( |
| + StringPrintf("SetSrc('%s');", kHTMLForGuest))); |
| + |
| + // Wait to make sure embedder is created/attached to WebContents. |
| + TestBrowserPluginHostFactory::GetInstance()->WaitForEmbedderCreation(); |
| + |
| + TestBrowserPluginEmbedder* test_embedder = |
| + static_cast<TestBrowserPluginEmbedder*>( |
| + embedder_web_contents->GetBrowserPluginEmbedder()); |
| + ASSERT_TRUE(test_embedder); |
| + test_embedder->WaitForGuestAdded(); |
| + |
| + // Verify that we have exactly one guest. |
| + const BrowserPluginEmbedder::ContainerInstanceMap& instance_map = |
| + test_embedder->guest_web_contents_for_testing(); |
| + EXPECT_EQ(1u, instance_map.size()); |
| + |
| + WebContentsImpl* test_guest_web_contents = static_cast<WebContentsImpl*>( |
| + instance_map.begin()->second); |
| + TestBrowserPluginGuest* test_guest = static_cast<TestBrowserPluginGuest*>( |
| + test_guest_web_contents->GetBrowserPluginGuest()); |
| + test_guest->WaitForUpdateRectMsg(); |
| + |
| + rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16( |
| + "document.getElementById('plugin').stop()")); |
| + test_guest->WaitForStop(); |
| +} |
| + |
| } // namespace content |