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 28ab5b1fa0f31994a83b17081990ecaad16f0529..d9dafdacca6dab0a2ef14c491a21f8ab367c6947 100644 |
--- a/content/browser/browser_plugin/browser_plugin_host_browsertest.cc |
+++ b/content/browser/browser_plugin/browser_plugin_host_browsertest.cc |
@@ -702,4 +702,85 @@ IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadRedirect) { |
EXPECT_EQ(test_server()->GetURL("files/title1.html").spec().c_str(), result); |
} |
+// This test verifies that round trip postMessage works as expected. |
+// 1. The embedder posts a message to the guest. |
Charlie Reis
2012/10/12 00:31:43
These descriptions are great, but too general give
Fady Samuel
2012/10/12 18:07:53
Done.
|
+// 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 'main guest' message. |
Charlie Reis
2012/10/12 00:31:43
There's no "main guest" in this message, is there?
Fady Samuel
2012/10/12 18:07:53
Done.
|
+// 6. The embedder changes its title to 'main guest' when it sees the string. |
+IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, PostMessage) { |
+ const char* kTesting = "testing123"; |
+ const char* kEmbedderURL = "files/browser_plugin_embedder.html"; |
+ const char* kGuestURL = "files/browser_plugin_post_message_guest.html"; |
+ StartBrowserPluginTest(kEmbedderURL, kGuestURL, false, ""); |
+ RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
+ test_embedder()->web_contents()->GetRenderViewHost()); |
+ { |
+ const string16 expected_title = ASCIIToUTF16("main guest"); |
+ content::TitleWatcher title_watcher(test_embedder()->web_contents(), |
+ expected_title); |
+ |
+ rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16( |
+ StringPrintf("PostMessage('%s, false');", kTesting))); |
Charlie Reis
2012/10/12 00:31:43
Just a sanity check: are we waiting long enough th
Fady Samuel
2012/10/12 18:07:53
Done.
|
+ |
+ // 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); |
+ } |
+} |
+ |
+// This is the same as BrowserPluginHostTest.PostMessage but also |
+// posts a message to an iframe. |
+// TODO(fsamuel): This test should replace the previous test once postMessage |
+// iframe targeting is fixed (see http://crbug.com/153701). |
+IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, DISABLED_PostMessageToIFrame) { |
+ const char* kTesting = "testing123"; |
+ const char* kEmbedderURL = "files/browser_plugin_embedder.html"; |
+ const char* kGuestURL = "files/browser_plugin_post_message_guest.html"; |
+ StartBrowserPluginTest(kEmbedderURL, kGuestURL, false, ""); |
+ RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
+ test_embedder()->web_contents()->GetRenderViewHost()); |
+ { |
+ const string16 expected_title = ASCIIToUTF16("main guest"); |
+ content::TitleWatcher title_watcher(test_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(test_embedder()->web_contents(), |
+ ASCIIToUTF16("ready")); |
+ |
+ RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( |
+ test_guest()->web_contents()->GetRenderViewHost()); |
+ GURL test_url = test_server()->GetURL( |
+ "files/browser_plugin_post_message_guest.html"); |
+ 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(test_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 |