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 684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
695 std::string result; | 695 std::string result; |
696 EXPECT_TRUE(v->GetAsString(&result)); | 696 EXPECT_TRUE(v->GetAsString(&result)); |
697 EXPECT_EQ(redirect_url.spec().c_str(), result); | 697 EXPECT_EQ(redirect_url.spec().c_str(), result); |
698 | 698 |
699 v = rvh->ExecuteJavascriptAndGetValue( | 699 v = rvh->ExecuteJavascriptAndGetValue( |
700 string16(), ASCIIToUTF16("redirectNewUrl")); | 700 string16(), ASCIIToUTF16("redirectNewUrl")); |
701 EXPECT_TRUE(v->GetAsString(&result)); | 701 EXPECT_TRUE(v->GetAsString(&result)); |
702 EXPECT_EQ(test_server()->GetURL("files/title1.html").spec().c_str(), result); | 702 EXPECT_EQ(test_server()->GetURL("files/title1.html").spec().c_str(), result); |
703 } | 703 } |
704 | 704 |
705 // This test verifies that round trip postMessage works as expected. | |
706 // 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.
| |
707 // 2. The guest receives and replies to the message using the event object's | |
708 // source object: event.source.postMessage(...) | |
709 // 3. The embedder receives the message and uses the event object's source | |
710 // object to do one final reply. | |
711 // 4. The guest receives the final 'stop' message. | |
712 // 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.
| |
713 // 6. The embedder changes its title to 'main guest' when it sees the string. | |
714 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, PostMessage) { | |
715 const char* kTesting = "testing123"; | |
716 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | |
717 const char* kGuestURL = "files/browser_plugin_post_message_guest.html"; | |
718 StartBrowserPluginTest(kEmbedderURL, kGuestURL, false, ""); | |
719 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | |
720 test_embedder()->web_contents()->GetRenderViewHost()); | |
721 { | |
722 const string16 expected_title = ASCIIToUTF16("main guest"); | |
723 content::TitleWatcher title_watcher(test_embedder()->web_contents(), | |
724 expected_title); | |
725 | |
726 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16( | |
727 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.
| |
728 | |
729 // The title will be updated to "main guest" at the last stage of the | |
730 // process described above. | |
731 string16 actual_title = title_watcher.WaitAndGetTitle(); | |
732 EXPECT_EQ(expected_title, actual_title); | |
733 } | |
734 } | |
735 | |
736 // This is the same as BrowserPluginHostTest.PostMessage but also | |
737 // posts a message to an iframe. | |
738 // TODO(fsamuel): This test should replace the previous test once postMessage | |
739 // iframe targeting is fixed (see http://crbug.com/153701). | |
740 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, DISABLED_PostMessageToIFrame) { | |
741 const char* kTesting = "testing123"; | |
742 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | |
743 const char* kGuestURL = "files/browser_plugin_post_message_guest.html"; | |
744 StartBrowserPluginTest(kEmbedderURL, kGuestURL, false, ""); | |
745 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | |
746 test_embedder()->web_contents()->GetRenderViewHost()); | |
747 { | |
748 const string16 expected_title = ASCIIToUTF16("main guest"); | |
749 content::TitleWatcher title_watcher(test_embedder()->web_contents(), | |
750 expected_title); | |
751 | |
752 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16( | |
753 StringPrintf("PostMessage('%s, false');", kTesting))); | |
754 | |
755 // The title will be updated to "main guest" at the last stage of the | |
756 // process described above. | |
757 string16 actual_title = title_watcher.WaitAndGetTitle(); | |
758 EXPECT_EQ(expected_title, actual_title); | |
759 } | |
760 { | |
761 content::TitleWatcher ready_watcher(test_embedder()->web_contents(), | |
762 ASCIIToUTF16("ready")); | |
763 | |
764 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( | |
765 test_guest()->web_contents()->GetRenderViewHost()); | |
766 GURL test_url = test_server()->GetURL( | |
767 "files/browser_plugin_post_message_guest.html"); | |
768 guest_rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16( | |
769 StringPrintf("CreateChildFrame('%s');", test_url.spec().c_str()))); | |
770 | |
771 string16 actual_title = ready_watcher.WaitAndGetTitle(); | |
772 EXPECT_EQ(ASCIIToUTF16("ready"), actual_title); | |
773 | |
774 content::TitleWatcher iframe_watcher(test_embedder()->web_contents(), | |
775 ASCIIToUTF16("iframe")); | |
776 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16( | |
777 StringPrintf("PostMessage('%s', true);", kTesting))); | |
778 | |
779 // The title will be updated to "iframe" at the last stage of the | |
780 // process described above. | |
781 actual_title = iframe_watcher.WaitAndGetTitle(); | |
782 EXPECT_EQ(ASCIIToUTF16("iframe"), actual_title); | |
783 } | |
784 } | |
785 | |
705 } // namespace content | 786 } // namespace content |
OLD | NEW |