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/memory/singleton.h" | 5 #include "base/memory/singleton.h" |
6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
7 #include "base/test/test_timeouts.h" | 7 #include "base/test/test_timeouts.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "content/browser/browser_plugin/browser_plugin_guest.h" | 9 #include "content/browser/browser_plugin/browser_plugin_guest.h" |
10 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" | 10 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" |
(...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
788 content::TitleWatcher title_watcher(test_guest_web_contents, | 788 content::TitleWatcher title_watcher(test_guest_web_contents, |
789 expected_title); | 789 expected_title); |
790 | 790 |
791 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16("Go(-2);")); | 791 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16("Go(-2);")); |
792 | 792 |
793 string16 actual_title = title_watcher.WaitAndGetTitle(); | 793 string16 actual_title = title_watcher.WaitAndGetTitle(); |
794 EXPECT_EQ(expected_title, actual_title); | 794 EXPECT_EQ(expected_title, actual_title); |
795 } | 795 } |
796 } | 796 } |
797 | 797 |
798 // This test verifies that round trip postMessage works as expected. | |
799 // 1. The embedder posts a message to the guest. | |
800 // 2. The guest receives and replies to the message using the event object's | |
801 // source object: event.source.postMessage(...) | |
802 // 3. The embedder receives the message and uses the event object's source | |
803 // object to do one final reply. | |
804 // 4. The guest receives the final 'stop' message. | |
805 // 5. The guest acks the 'stop' message with a 'stop_ack' message. | |
806 // 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.
| |
807 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, PostMessage) { | |
808 const char* kTesting = "testing123"; | |
809 ASSERT_TRUE(test_server()->Start()); | |
810 | |
811 GURL test_url(test_server()->GetURL("files/browser_plugin_embedder.html")); | |
812 NavigateToURL(shell(), test_url); | |
813 | |
814 WebContentsImpl* embedder_web_contents = static_cast<WebContentsImpl*>( | |
815 shell()->web_contents()); | |
816 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | |
817 embedder_web_contents->GetRenderViewHost()); | |
818 | |
819 test_url = test_server()->GetURL( | |
820 "files/browser_plugin_post_message_guest.html"); | |
821 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16( | |
822 StringPrintf("SetSrc('%s');", test_url.spec().c_str()))); | |
823 | |
824 // Wait to make sure embedder is created/attached to WebContents. | |
825 TestBrowserPluginHostFactory::GetInstance()->WaitForEmbedderCreation(); | |
826 | |
827 TestBrowserPluginEmbedder* test_embedder = | |
828 static_cast<TestBrowserPluginEmbedder*>( | |
829 embedder_web_contents->GetBrowserPluginEmbedder()); | |
830 ASSERT_TRUE(test_embedder); | |
831 test_embedder->WaitForGuestAdded(); | |
832 | |
833 // Verify that we have exactly one guest. | |
834 const BrowserPluginEmbedder::ContainerInstanceMap& instance_map = | |
835 test_embedder->guest_web_contents_for_testing(); | |
836 EXPECT_EQ(1u, instance_map.size()); | |
837 | |
838 WebContentsImpl* test_guest_web_contents = static_cast<WebContentsImpl*>( | |
839 instance_map.begin()->second); | |
840 TestBrowserPluginGuest* test_guest = static_cast<TestBrowserPluginGuest*>( | |
841 test_guest_web_contents->GetBrowserPluginGuest()); | |
842 test_guest->WaitForUpdateRectMsg(); | |
843 | |
844 { | |
845 const string16 expected_title = ASCIIToUTF16("main guest"); | |
846 content::TitleWatcher title_watcher(embedder_web_contents, expected_title); | |
847 | |
848 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16( | |
849 StringPrintf("PostMessage('%s, false');", kTesting))); | |
850 | |
851 // The title will be updated to "main guest" at the last stage of the | |
852 // process described above. | |
853 string16 actual_title = title_watcher.WaitAndGetTitle(); | |
854 EXPECT_EQ(expected_title, actual_title); | |
855 } | |
856 { | |
857 content::TitleWatcher ready_watcher(embedder_web_contents, | |
858 ASCIIToUTF16("ready")); | |
859 | |
860 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( | |
861 test_guest_web_contents->GetRenderViewHost()); | |
862 guest_rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16( | |
863 StringPrintf("CreateChildFrame('%s');", test_url.spec().c_str()))); | |
864 | |
865 string16 actual_title = ready_watcher.WaitAndGetTitle(); | |
866 EXPECT_EQ(ASCIIToUTF16("ready"), actual_title); | |
867 | |
868 content::TitleWatcher iframe_watcher(embedder_web_contents, | |
869 ASCIIToUTF16("iframe")); | |
870 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16( | |
871 StringPrintf("PostMessage('%s', true);", kTesting))); | |
872 | |
873 // The title will be updated to "iframe" at the last stage of the | |
874 // process described above. | |
875 actual_title = iframe_watcher.WaitAndGetTitle(); | |
876 EXPECT_EQ(ASCIIToUTF16("iframe"), actual_title); | |
877 } | |
878 } | |
798 | 879 |
799 } // namespace content | 880 } // namespace content |
OLD | NEW |