Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1552)

Unified Diff: content/browser/browser_plugin/browser_plugin_host_browsertest.cc

Issue 10829225: Browser Plugin: Add HTML5-like postMessage support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge with ToT. Added subframe targeting + test. Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 d868e8f70820f021158778d0bed192bd9dc87623..ae872a2a2d2ce118aa0326ebc3c9bc8c753a06d2 100644
--- a/content/browser/browser_plugin/browser_plugin_host_browsertest.cc
+++ b/content/browser/browser_plugin/browser_plugin_host_browsertest.cc
@@ -795,5 +795,86 @@ IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, Renavigate) {
}
}
+// This test verifies that round trip postMessage works as expected.
+// 1. The embedder posts a message to the guest.
+// 2. The guest receives and replies to the message using the event object's
+// source object: event.source.postMessage(...)
+// 3. The embedder receives the message and uses the event object's source
+// object to do one final reply.
+// 4. The guest receives the final 'stop' message.
+// 5. The guest acks the 'stop' message with a 'stop_ack' message.
+// 6. The embedder changes its title to 'stop_ack' when it sees the string.
nasko 2012/10/02 17:52:31 It seems that the title is set to "main guest" or
Fady Samuel 2012/10/02 22:04:08 Stale comment. Updated.
+IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, PostMessage) {
+ const char* kTesting = "testing123";
+ 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());
+
+ test_url = test_server()->GetURL(
+ "files/browser_plugin_post_message_guest.html");
+ rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16(
+ StringPrintf("SetSrc('%s');", test_url.spec().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());
+ test_guest->WaitForUpdateRectMsg();
+
+ {
+ const string16 expected_title = ASCIIToUTF16("main guest");
+ content::TitleWatcher title_watcher(embedder_web_contents, expected_title);
+
+ rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16(
+ StringPrintf("PostMessage('%s, false');", kTesting)));
+
+ // The title will be updated to "main guest" at the last stage of the
+ // process described above.
+ string16 actual_title = title_watcher.WaitAndGetTitle();
+ EXPECT_EQ(expected_title, actual_title);
+ }
+ {
+ content::TitleWatcher ready_watcher(embedder_web_contents,
+ ASCIIToUTF16("ready"));
+
+ RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>(
+ test_guest_web_contents->GetRenderViewHost());
+ guest_rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16(
+ StringPrintf("CreateChildFrame('%s');", test_url.spec().c_str())));
+
+ string16 actual_title = ready_watcher.WaitAndGetTitle();
+ EXPECT_EQ(ASCIIToUTF16("ready"), actual_title);
+
+ content::TitleWatcher iframe_watcher(embedder_web_contents,
+ ASCIIToUTF16("iframe"));
+ rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16(
+ StringPrintf("PostMessage('%s', true);", kTesting)));
+
+ // The title will be updated to "iframe" at the last stage of the
+ // process described above.
+ actual_title = iframe_watcher.WaitAndGetTitle();
+ EXPECT_EQ(ASCIIToUTF16("iframe"), actual_title);
+ }
+}
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698