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..a77101b1ce3c97786f873c9f42140a1751a466b9 100644 |
--- a/content/browser/browser_plugin/browser_plugin_host_browsertest.cc |
+++ b/content/browser/browser_plugin/browser_plugin_host_browsertest.cc |
@@ -30,7 +30,7 @@ using content::BrowserPluginEmbedder; |
using content::BrowserPluginGuest; |
using content::BrowserPluginHostFactory; |
-namespace content { |
+namespace { |
const char* kHTMLForGuest = |
"data:text/html,<html><body>hello world</body></html>"; |
@@ -40,6 +40,20 @@ const char* kHTMLForGuestInfiniteLoop = |
" setTimeout(function () {while (true) {} }, 0);" |
"}" |
"</script></head><body></body></html>"; |
+const char* kHTMLForGuestWithTitle = |
+ "data:text/html," |
+ "<html><head><title>%s</title></head>" |
+ "<body>hello world</body>"; |
+ "</html>"; |
+ |
+std::string GetHTMLForGuestWithTitle(const std::string& title) { |
+ return StringPrintf(kHTMLForGuestWithTitle, title.c_str()); |
+} |
+ |
+} // namespace |
+ |
+namespace content { |
+ |
// Test factory for creating test instances of BrowserPluginEmbedder and |
// BrowserPluginGuest. |
@@ -480,4 +494,103 @@ IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, VisibilityChanged) { |
test_guest->WaitUntilHidden(); |
} |
+IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, Renavigate) { |
+ 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');", GetHTMLForGuestWithTitle("P1").c_str()))); |
+ |
+ // 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()); |
+ |
+ // Wait for the guest to send an UpdateRectMsg, meaning it is ready. |
+ test_guest->WaitForUpdateRectMsg(); |
lazyboy
2012/09/20 20:05:42
See below: navigate back and forward here too, and
Fady Samuel
2012/09/21 15:21:56
While I'm not against more test coverage, I feel t
|
+ |
+ // Navigate to P2 and verify that the navigation occurred. |
+ { |
+ const string16 expected_title = ASCIIToUTF16("P2"); |
+ content::TitleWatcher title_watcher(test_guest_web_contents, |
+ expected_title); |
+ |
+ rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16( |
+ StringPrintf("SetSrc('%s');", GetHTMLForGuestWithTitle("P2").c_str()))); |
+ |
+ string16 actual_title = title_watcher.WaitAndGetTitle(); |
+ EXPECT_EQ(expected_title, actual_title); |
+ } |
+ |
+ // Navigate to P3 and verify that the navigation occurred. |
+ { |
+ const string16 expected_title = ASCIIToUTF16("P3"); |
+ content::TitleWatcher title_watcher(test_guest_web_contents, |
+ expected_title); |
+ |
+ rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16( |
+ StringPrintf("SetSrc('%s');", GetHTMLForGuestWithTitle("P3").c_str()))); |
+ |
+ string16 actual_title = title_watcher.WaitAndGetTitle(); |
+ EXPECT_EQ(expected_title, actual_title); |
+ } |
+ |
+ // Go back and verify that we're back at P2. |
+ { |
+ const string16 expected_title = ASCIIToUTF16("P2"); |
+ content::TitleWatcher title_watcher(test_guest_web_contents, |
+ expected_title); |
+ |
+ rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16("Back();")); |
+ |
+ string16 actual_title = title_watcher.WaitAndGetTitle(); |
+ EXPECT_EQ(expected_title, actual_title); |
+ } |
+ |
+ // Go forward and verify that we're back at P3. |
+ { |
+ const string16 expected_title = ASCIIToUTF16("P3"); |
+ content::TitleWatcher title_watcher(test_guest_web_contents, |
+ expected_title); |
+ |
+ rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16("Forward();")); |
+ |
+ string16 actual_title = title_watcher.WaitAndGetTitle(); |
lazyboy
2012/09/20 20:05:42
same as below, try to go one step further forward.
Fady Samuel
2012/09/21 15:21:56
ditto, I'm not convinced this actually improves te
|
+ EXPECT_EQ(expected_title, actual_title); |
+ } |
+ |
+ // Go back two entries and verify that we're back at P1. |
+ { |
+ const string16 expected_title = ASCIIToUTF16("P1"); |
+ content::TitleWatcher title_watcher(test_guest_web_contents, |
+ expected_title); |
+ |
+ rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16("Go(-2);")); |
lazyboy
2012/09/20 20:05:42
A test to see if we try to go back further and sta
Fady Samuel
2012/09/21 15:21:56
ditto.
|
+ |
+ string16 actual_title = title_watcher.WaitAndGetTitle(); |
+ EXPECT_EQ(expected_title, actual_title); |
+ } |
+} |
+ |
} // namespace content |