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

Side by Side 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: Merged with ToT. Addressed creis@'s comments 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/command_line.h" 5 #include "base/command_line.h"
6 #include "base/memory/singleton.h" 6 #include "base/memory/singleton.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/test/test_timeouts.h" 8 #include "base/test/test_timeouts.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "content/browser/browser_plugin/browser_plugin_guest.h" 10 #include "content/browser/browser_plugin/browser_plugin_guest.h"
(...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 rvh->DragTargetDragEnter(drop_data, gfx::Point(start_x, start_y), 783 rvh->DragTargetDragEnter(drop_data, gfx::Point(start_x, start_y),
784 gfx::Point(start_x, start_y), WebKit::WebDragOperationEvery, 0); 784 gfx::Point(start_x, start_y), WebKit::WebDragOperationEvery, 0);
785 rvh->DragTargetDragOver(gfx::Point(end_x, end_y), gfx::Point(end_x, end_y), 785 rvh->DragTargetDragOver(gfx::Point(end_x, end_y), gfx::Point(end_x, end_y),
786 WebKit::WebDragOperationEvery, 0); 786 WebKit::WebDragOperationEvery, 0);
787 rvh->DragTargetDrop(gfx::Point(end_x, end_y), gfx::Point(end_x, end_y), 0); 787 rvh->DragTargetDrop(gfx::Point(end_x, end_y), gfx::Point(end_x, end_y), 0);
788 788
789 string16 actual_title = title_watcher.WaitAndGetTitle(); 789 string16 actual_title = title_watcher.WaitAndGetTitle();
790 EXPECT_EQ(expected_title, actual_title); 790 EXPECT_EQ(expected_title, actual_title);
791 } 791 }
792 792
793 // This test verifies that round trip postMessage works as expected.
794 // 1. The embedder posts a message 'testing123' to the guest.
795 // 2. The guest receives and replies to the message using the event object's
796 // source object: event.source.postMessage('foobar', '*')
797 // 3. The embedder receives the message and uses the event's source
798 // object to do one final reply: 'stop'
799 // 4. The guest receives the final 'stop' message.
800 // 5. The guest acks the 'stop' message with a 'stop_ack' message.
801 // 6. The embedder changes its title to 'main guest' when it sees the 'stop_ack'
802 // message.
803 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, PostMessage) {
804 const char* kTesting = "testing123";
805 const char* kEmbedderURL = "files/browser_plugin_embedder.html";
806 const char* kGuestURL = "files/browser_plugin_post_message_guest.html";
807 StartBrowserPluginTest(kEmbedderURL, kGuestURL, false, "");
808 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(
809 test_embedder()->web_contents()->GetRenderViewHost());
810 {
811 const string16 expected_title = ASCIIToUTF16("main guest");
812 content::TitleWatcher title_watcher(test_embedder()->web_contents(),
813 expected_title);
814
815 // By the time we get here 'contentWindow' should be ready because the
816 // guest has begun sending pixels to the embedder. This happens after
817 // the browser process sends the guest_routing_id to the embedder via
818 // BrowserPluginMsg_GuestContentWindowReady and after the browser process
819 // issues a ViewMsg_New to create the swapped out guest in the embedder's
820 // render process.
821 ExecuteSyncJSFunction(rvh,
822 ASCIIToUTF16(StringPrintf("PostMessage('%s, false');", kTesting)));
823
824 // The title will be updated to "main guest" at the last stage of the
825 // process described above.
826 string16 actual_title = title_watcher.WaitAndGetTitle();
827 EXPECT_EQ(expected_title, actual_title);
828 }
829 }
830
831 // This is the same as BrowserPluginHostTest.PostMessage but also
832 // posts a message to an iframe.
833 // TODO(fsamuel): This test should replace the previous test once postMessage
834 // iframe targeting is fixed (see http://crbug.com/153701).
835 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, DISABLED_PostMessageToIFrame) {
836 const char* kTesting = "testing123";
837 const char* kEmbedderURL = "files/browser_plugin_embedder.html";
838 const char* kGuestURL = "files/browser_plugin_post_message_guest.html";
839 StartBrowserPluginTest(kEmbedderURL, kGuestURL, false, "");
840 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(
841 test_embedder()->web_contents()->GetRenderViewHost());
842 {
843 const string16 expected_title = ASCIIToUTF16("main guest");
844 content::TitleWatcher title_watcher(test_embedder()->web_contents(),
845 expected_title);
846
847 ExecuteSyncJSFunction(rvh,
848 ASCIIToUTF16(StringPrintf("PostMessage('%s, false');", kTesting)));
849
850 // The title will be updated to "main guest" at the last stage of the
851 // process described above.
852 string16 actual_title = title_watcher.WaitAndGetTitle();
853 EXPECT_EQ(expected_title, actual_title);
854 }
855 {
856 content::TitleWatcher ready_watcher(test_embedder()->web_contents(),
857 ASCIIToUTF16("ready"));
858
859 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>(
860 test_guest()->web_contents()->GetRenderViewHost());
861 GURL test_url = test_server()->GetURL(
862 "files/browser_plugin_post_message_guest.html");
863 ExecuteSyncJSFunction(guest_rvh,
864 ASCIIToUTF16(StringPrintf("CreateChildFrame('%s');",
865 test_url.spec().c_str())));
866
867 string16 actual_title = ready_watcher.WaitAndGetTitle();
868 EXPECT_EQ(ASCIIToUTF16("ready"), actual_title);
869
870 content::TitleWatcher iframe_watcher(test_embedder()->web_contents(),
871 ASCIIToUTF16("iframe"));
872 ExecuteSyncJSFunction(rvh,
873 ASCIIToUTF16(StringPrintf("PostMessage('%s', true);", kTesting)));
874
875 // The title will be updated to "iframe" at the last stage of the
876 // process described above.
877 actual_title = iframe_watcher.WaitAndGetTitle();
878 EXPECT_EQ(ASCIIToUTF16("iframe"), actual_title);
879 }
880 }
881
793 } // namespace content 882 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698