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 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 instance_map.begin()->second); | 602 instance_map.begin()->second); |
603 TestBrowserPluginGuest* new_test_guest = | 603 TestBrowserPluginGuest* new_test_guest = |
604 static_cast<TestBrowserPluginGuest*>( | 604 static_cast<TestBrowserPluginGuest*>( |
605 test_guest_web_contents->GetBrowserPluginGuest()); | 605 test_guest_web_contents->GetBrowserPluginGuest()); |
606 | 606 |
607 // Wait for the guest to send an UpdateRectMsg, meaning it is ready. | 607 // Wait for the guest to send an UpdateRectMsg, meaning it is ready. |
608 new_test_guest->WaitForUpdateRectMsg(); | 608 new_test_guest->WaitForUpdateRectMsg(); |
609 } | 609 } |
610 } | 610 } |
611 | 611 |
| 612 // This test verifies that round trip postMessage works as expected. |
| 613 // 1. The embedder posts a message to the guest. |
| 614 // 2. The guest receives and replies to the message using the event object's |
| 615 // source object: event.source.postMessage(...) |
| 616 // 3. The embedder receives the message and uses the event object's source |
| 617 // object to do one final reply. |
| 618 // 4. The guest receives the final 'stop' message. |
| 619 // 5. The guest acks the 'stop' message with a 'main guest' message. |
| 620 // 6. The embedder changes its title to 'main guest' when it sees the string. |
| 621 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, PostMessage) { |
| 622 const char* kTesting = "testing123"; |
| 623 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; |
| 624 const char* kGuestURL = "files/browser_plugin_post_message_guest.html"; |
| 625 StartBrowserPluginTest(kEmbedderURL, kGuestURL, false, ""); |
| 626 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
| 627 test_embedder()->web_contents()->GetRenderViewHost()); |
| 628 { |
| 629 const string16 expected_title = ASCIIToUTF16("main guest"); |
| 630 content::TitleWatcher title_watcher(test_embedder()->web_contents(), |
| 631 expected_title); |
| 632 |
| 633 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16( |
| 634 StringPrintf("PostMessage('%s, false');", kTesting))); |
| 635 |
| 636 // The title will be updated to "main guest" at the last stage of the |
| 637 // process described above. |
| 638 string16 actual_title = title_watcher.WaitAndGetTitle(); |
| 639 EXPECT_EQ(expected_title, actual_title); |
| 640 } |
| 641 } |
| 642 |
| 643 // This is the same as BrowserPluginHostTest.PostMessage but also |
| 644 // posts a message to an iframe. |
| 645 // TODO(fsamuel): This test should replace the previous test once postMessage |
| 646 // iframe targeting is fixed (see http://crbug.com/153701). |
| 647 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, DISABLED_PostMessageToIFrame) { |
| 648 const char* kTesting = "testing123"; |
| 649 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; |
| 650 const char* kGuestURL = "files/browser_plugin_post_message_guest.html"; |
| 651 StartBrowserPluginTest(kEmbedderURL, kGuestURL, false, ""); |
| 652 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
| 653 test_embedder()->web_contents()->GetRenderViewHost()); |
| 654 { |
| 655 const string16 expected_title = ASCIIToUTF16("main guest"); |
| 656 content::TitleWatcher title_watcher(test_embedder()->web_contents(), |
| 657 expected_title); |
| 658 |
| 659 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16( |
| 660 StringPrintf("PostMessage('%s, false');", kTesting))); |
| 661 |
| 662 // The title will be updated to "main guest" at the last stage of the |
| 663 // process described above. |
| 664 string16 actual_title = title_watcher.WaitAndGetTitle(); |
| 665 EXPECT_EQ(expected_title, actual_title); |
| 666 } |
| 667 { |
| 668 content::TitleWatcher ready_watcher(test_embedder()->web_contents(), |
| 669 ASCIIToUTF16("ready")); |
| 670 |
| 671 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( |
| 672 test_guest()->web_contents()->GetRenderViewHost()); |
| 673 GURL test_url = test_server()->GetURL( |
| 674 "files/browser_plugin_post_message_guest.html"); |
| 675 guest_rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16( |
| 676 StringPrintf("CreateChildFrame('%s');", test_url.spec().c_str()))); |
| 677 |
| 678 string16 actual_title = ready_watcher.WaitAndGetTitle(); |
| 679 EXPECT_EQ(ASCIIToUTF16("ready"), actual_title); |
| 680 |
| 681 content::TitleWatcher iframe_watcher(test_embedder()->web_contents(), |
| 682 ASCIIToUTF16("iframe")); |
| 683 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16( |
| 684 StringPrintf("PostMessage('%s', true);", kTesting))); |
| 685 |
| 686 // The title will be updated to "iframe" at the last stage of the |
| 687 // process described above. |
| 688 actual_title = iframe_watcher.WaitAndGetTitle(); |
| 689 EXPECT_EQ(ASCIIToUTF16("iframe"), actual_title); |
| 690 } |
| 691 } |
| 692 |
612 } // namespace content | 693 } // namespace content |
OLD | NEW |