Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 815 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 826 rvh->DragTargetDragEnter(drop_data, gfx::Point(start_x, start_y), | 826 rvh->DragTargetDragEnter(drop_data, gfx::Point(start_x, start_y), |
| 827 gfx::Point(start_x, start_y), WebKit::WebDragOperationEvery, 0); | 827 gfx::Point(start_x, start_y), WebKit::WebDragOperationEvery, 0); |
| 828 rvh->DragTargetDragOver(gfx::Point(end_x, end_y), gfx::Point(end_x, end_y), | 828 rvh->DragTargetDragOver(gfx::Point(end_x, end_y), gfx::Point(end_x, end_y), |
| 829 WebKit::WebDragOperationEvery, 0); | 829 WebKit::WebDragOperationEvery, 0); |
| 830 rvh->DragTargetDrop(gfx::Point(end_x, end_y), gfx::Point(end_x, end_y), 0); | 830 rvh->DragTargetDrop(gfx::Point(end_x, end_y), gfx::Point(end_x, end_y), 0); |
| 831 | 831 |
| 832 string16 actual_title = title_watcher.WaitAndGetTitle(); | 832 string16 actual_title = title_watcher.WaitAndGetTitle(); |
| 833 EXPECT_EQ(expected_title, actual_title); | 833 EXPECT_EQ(expected_title, actual_title); |
| 834 } | 834 } |
| 835 | 835 |
| 836 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadStop) { | |
| 837 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | |
| 838 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, ""); | |
| 839 | |
| 840 const string16 expected_title = ASCIIToUTF16("loadStop"); | |
| 841 content::TitleWatcher title_watcher( | |
| 842 test_embedder()->web_contents(), expected_title); | |
| 843 // Renavigate the guest to |kHTMLForGuest|. | |
| 844 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | |
| 845 test_embedder()->web_contents()->GetRenderViewHost()); | |
| 846 ExecuteSyncJSFunction(rvh, ASCIIToUTF16( | |
| 847 StringPrintf("SetSrc('%s');", kHTMLForGuest))); | |
| 848 | |
| 849 string16 actual_title = title_watcher.WaitAndGetTitle(); | |
| 850 EXPECT_EQ(expected_title, actual_title); | |
| 851 } | |
| 852 | |
| 853 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadCommit) { | |
| 854 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | |
| 855 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, ""); | |
| 856 | |
| 857 const string16 expected_title = ASCIIToUTF16( | |
| 858 StringPrintf("loadCommit:%s", kHTMLForGuest)); | |
| 859 content::TitleWatcher title_watcher( | |
| 860 test_embedder()->web_contents(), expected_title); | |
| 861 // Renavigate the guest to |kHTMLForGuest|. | |
| 862 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | |
| 863 test_embedder()->web_contents()->GetRenderViewHost()); | |
| 864 ExecuteSyncJSFunction(rvh, ASCIIToUTF16( | |
| 865 StringPrintf("SetSrc('%s');", kHTMLForGuest))); | |
| 866 | |
| 867 string16 actual_title = title_watcher.WaitAndGetTitle(); | |
| 868 EXPECT_EQ(expected_title, actual_title); | |
| 869 scoped_ptr<base::Value> is_top_level(rvh->ExecuteJavascriptAndGetValue( | |
| 870 string16(), ASCIIToUTF16("commitIsTopLevel"))); | |
| 871 bool top_level_bool = false; | |
| 872 EXPECT_TRUE(is_top_level->GetAsBoolean(&top_level_bool)); | |
| 873 EXPECT_EQ(true, top_level_bool); | |
| 874 } | |
| 875 | |
| 876 // This test verifies that round trip postMessage works as expected. | |
|
Charlie Reis
2012/10/17 21:27:08
All of this below is from a merge conflict. (It w
irobert
2012/10/18 01:42:25
Done.
| |
| 877 // 1. The embedder posts a message 'testing123' to the guest. | |
| 878 // 2. The guest receives and replies to the message using the event object's | |
| 879 // source object: event.source.postMessage('foobar', '*') | |
| 880 // 3. The embedder receives the message and uses the event's source | |
| 881 // object to do one final reply: 'stop' | |
| 882 // 4. The guest receives the final 'stop' message. | |
| 883 // 5. The guest acks the 'stop' message with a 'stop_ack' message. | |
| 884 // 6. The embedder changes its title to 'main guest' when it sees the 'stop_ack' | |
| 885 // message. | |
| 886 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, PostMessage) { | |
| 887 const char* kTesting = "testing123"; | |
| 888 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | |
| 889 const char* kGuestURL = "files/browser_plugin_post_message_guest.html"; | |
| 890 StartBrowserPluginTest(kEmbedderURL, kGuestURL, false, ""); | |
| 891 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | |
| 892 test_embedder()->web_contents()->GetRenderViewHost()); | |
| 893 { | |
| 894 const string16 expected_title = ASCIIToUTF16("main guest"); | |
| 895 content::TitleWatcher title_watcher(test_embedder()->web_contents(), | |
| 896 expected_title); | |
| 897 | |
| 898 // By the time we get here 'contentWindow' should be ready because the | |
| 899 // guest has begun sending pixels to the embedder. This happens after | |
| 900 // the browser process sends the guest_routing_id to the embedder via | |
| 901 // BrowserPluginMsg_GuestContentWindowReady and after the browser process | |
| 902 // issues a ViewMsg_New to create the swapped out guest in the embedder's | |
| 903 // render process. | |
| 904 ExecuteSyncJSFunction(rvh, | |
| 905 ASCIIToUTF16(StringPrintf("PostMessage('%s, false');", kTesting))); | |
| 906 | |
| 907 // The title will be updated to "main guest" at the last stage of the | |
| 908 // process described above. | |
| 909 string16 actual_title = title_watcher.WaitAndGetTitle(); | |
| 910 EXPECT_EQ(expected_title, actual_title); | |
| 911 } | |
| 912 } | |
| 913 | |
| 914 // This is the same as BrowserPluginHostTest.PostMessage but also | |
| 915 // posts a message to an iframe. | |
| 916 // TODO(fsamuel): This test should replace the previous test once postMessage | |
| 917 // iframe targeting is fixed (see http://crbug.com/153701). | |
| 918 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, DISABLED_PostMessageToIFrame) { | |
| 919 const char* kTesting = "testing123"; | |
| 920 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | |
| 921 const char* kGuestURL = "files/browser_plugin_post_message_guest.html"; | |
| 922 StartBrowserPluginTest(kEmbedderURL, kGuestURL, false, ""); | |
| 923 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | |
| 924 test_embedder()->web_contents()->GetRenderViewHost()); | |
| 925 { | |
| 926 const string16 expected_title = ASCIIToUTF16("main guest"); | |
| 927 content::TitleWatcher title_watcher(test_embedder()->web_contents(), | |
| 928 expected_title); | |
| 929 | |
| 930 ExecuteSyncJSFunction(rvh, | |
| 931 ASCIIToUTF16(StringPrintf("PostMessage('%s, false');", kTesting))); | |
| 932 | |
| 933 // The title will be updated to "main guest" at the last stage of the | |
| 934 // process described above. | |
| 935 string16 actual_title = title_watcher.WaitAndGetTitle(); | |
| 936 EXPECT_EQ(expected_title, actual_title); | |
| 937 } | |
| 938 { | |
| 939 content::TitleWatcher ready_watcher(test_embedder()->web_contents(), | |
| 940 ASCIIToUTF16("ready")); | |
| 941 | |
| 942 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( | |
| 943 test_guest()->web_contents()->GetRenderViewHost()); | |
| 944 GURL test_url = test_server()->GetURL( | |
| 945 "files/browser_plugin_post_message_guest.html"); | |
| 946 ExecuteSyncJSFunction(guest_rvh, | |
| 947 ASCIIToUTF16(StringPrintf("CreateChildFrame('%s');", | |
| 948 test_url.spec().c_str()))); | |
| 949 | |
| 950 string16 actual_title = ready_watcher.WaitAndGetTitle(); | |
| 951 EXPECT_EQ(ASCIIToUTF16("ready"), actual_title); | |
| 952 | |
| 953 content::TitleWatcher iframe_watcher(test_embedder()->web_contents(), | |
| 954 ASCIIToUTF16("iframe")); | |
| 955 ExecuteSyncJSFunction(rvh, | |
| 956 ASCIIToUTF16(StringPrintf("PostMessage('%s', true);", kTesting))); | |
| 957 | |
| 958 // The title will be updated to "iframe" at the last stage of the | |
| 959 // process described above. | |
| 960 actual_title = iframe_watcher.WaitAndGetTitle(); | |
| 961 EXPECT_EQ(ASCIIToUTF16("iframe"), actual_title); | |
| 962 } | |
| 963 } | |
| 964 | |
| 836 } // namespace content | 965 } // namespace content |
| OLD | NEW |