| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/strings/string_split.h" | 8 #include "base/strings/string_split.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 | 613 |
| 614 // Uninstalling the touch-handler in guest should cause the embedder to stop | 614 // Uninstalling the touch-handler in guest should cause the embedder to stop |
| 615 // listening for touch events. | 615 // listening for touch events. |
| 616 observer.ResetState(); | 616 observer.ResetState(); |
| 617 ExecuteSyncJSFunction(test_guest()->web_contents()->GetRenderViewHost(), | 617 ExecuteSyncJSFunction(test_guest()->web_contents()->GetRenderViewHost(), |
| 618 "UninstallTouchHandler();"); | 618 "UninstallTouchHandler();"); |
| 619 observer.WaitUntilMessageReceived(); | 619 observer.WaitUntilMessageReceived(); |
| 620 EXPECT_FALSE(rvh->has_touch_handler()); | 620 EXPECT_FALSE(rvh->has_touch_handler()); |
| 621 } | 621 } |
| 622 | 622 |
| 623 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, Renavigate) { | |
| 624 const char kEmbedderURL[] = "/browser_plugin_embedder.html"; | |
| 625 StartBrowserPluginTest( | |
| 626 kEmbedderURL, GetHTMLForGuestWithTitle("P1"), true, std::string()); | |
| 627 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | |
| 628 test_embedder()->web_contents()->GetRenderViewHost()); | |
| 629 | |
| 630 // Navigate to P2 and verify that the navigation occurred. | |
| 631 { | |
| 632 const string16 expected_title = ASCIIToUTF16("P2"); | |
| 633 content::TitleWatcher title_watcher(test_guest()->web_contents(), | |
| 634 expected_title); | |
| 635 | |
| 636 ExecuteSyncJSFunction( | |
| 637 rvh, | |
| 638 base::StringPrintf( | |
| 639 "SetSrc('%s');", GetHTMLForGuestWithTitle("P2").c_str())); | |
| 640 | |
| 641 string16 actual_title = title_watcher.WaitAndGetTitle(); | |
| 642 EXPECT_EQ(expected_title, actual_title); | |
| 643 } | |
| 644 | |
| 645 // Navigate to P3 and verify that the navigation occurred. | |
| 646 { | |
| 647 const string16 expected_title = ASCIIToUTF16("P3"); | |
| 648 content::TitleWatcher title_watcher(test_guest()->web_contents(), | |
| 649 expected_title); | |
| 650 | |
| 651 ExecuteSyncJSFunction( | |
| 652 rvh, | |
| 653 base::StringPrintf( | |
| 654 "SetSrc('%s');", GetHTMLForGuestWithTitle("P3").c_str())); | |
| 655 | |
| 656 string16 actual_title = title_watcher.WaitAndGetTitle(); | |
| 657 EXPECT_EQ(expected_title, actual_title); | |
| 658 } | |
| 659 | |
| 660 // Go back and verify that we're back at P2. | |
| 661 { | |
| 662 const string16 expected_title = ASCIIToUTF16("P2"); | |
| 663 content::TitleWatcher title_watcher(test_guest()->web_contents(), | |
| 664 expected_title); | |
| 665 | |
| 666 ExecuteSyncJSFunction(rvh, "Back();"); | |
| 667 string16 actual_title = title_watcher.WaitAndGetTitle(); | |
| 668 EXPECT_EQ(expected_title, actual_title); | |
| 669 | |
| 670 scoped_ptr<base::Value> value = | |
| 671 content::ExecuteScriptAndGetValue(rvh, "CanGoBack()"); | |
| 672 bool result = false; | |
| 673 ASSERT_TRUE(value->GetAsBoolean(&result)); | |
| 674 EXPECT_TRUE(result); | |
| 675 | |
| 676 value = content::ExecuteScriptAndGetValue(rvh, "CanGoForward()"); | |
| 677 result = false; | |
| 678 ASSERT_TRUE(value->GetAsBoolean(&result)); | |
| 679 EXPECT_TRUE(result); | |
| 680 } | |
| 681 | |
| 682 // Go forward and verify that we're back at P3. | |
| 683 { | |
| 684 const string16 expected_title = ASCIIToUTF16("P3"); | |
| 685 content::TitleWatcher title_watcher(test_guest()->web_contents(), | |
| 686 expected_title); | |
| 687 | |
| 688 ExecuteSyncJSFunction(rvh, "Forward();"); | |
| 689 string16 actual_title = title_watcher.WaitAndGetTitle(); | |
| 690 EXPECT_EQ(expected_title, actual_title); | |
| 691 | |
| 692 scoped_ptr<base::Value> value = | |
| 693 content::ExecuteScriptAndGetValue(rvh, "CanGoForward()"); | |
| 694 bool result = true; | |
| 695 ASSERT_TRUE(value->GetAsBoolean(&result)); | |
| 696 EXPECT_FALSE(result); | |
| 697 } | |
| 698 | |
| 699 // Go back two entries and verify that we're back at P1. | |
| 700 { | |
| 701 const string16 expected_title = ASCIIToUTF16("P1"); | |
| 702 content::TitleWatcher title_watcher(test_guest()->web_contents(), | |
| 703 expected_title); | |
| 704 | |
| 705 ExecuteSyncJSFunction(rvh, "Go(-2);"); | |
| 706 string16 actual_title = title_watcher.WaitAndGetTitle(); | |
| 707 EXPECT_EQ(expected_title, actual_title); | |
| 708 | |
| 709 scoped_ptr<base::Value> value = | |
| 710 content::ExecuteScriptAndGetValue(rvh, "CanGoBack()"); | |
| 711 bool result = true; | |
| 712 ASSERT_TRUE(value->GetAsBoolean(&result)); | |
| 713 EXPECT_FALSE(result); | |
| 714 } | |
| 715 } | |
| 716 | |
| 717 // This tests verifies that reloading the embedder does not crash the browser | 623 // This tests verifies that reloading the embedder does not crash the browser |
| 718 // and that the guest is reset. | 624 // and that the guest is reset. |
| 719 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, ReloadEmbedder) { | 625 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, ReloadEmbedder) { |
| 720 const char kEmbedderURL[] = "/browser_plugin_embedder.html"; | 626 const char kEmbedderURL[] = "/browser_plugin_embedder.html"; |
| 721 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string()); | 627 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string()); |
| 722 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 628 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
| 723 test_embedder()->web_contents()->GetRenderViewHost()); | 629 test_embedder()->web_contents()->GetRenderViewHost()); |
| 724 | 630 |
| 725 // Change the title of the page to 'modified' so that we know that | 631 // Change the title of the page to 'modified' so that we know that |
| 726 // the page has successfully reloaded when it goes back to 'embedder' | 632 // the page has successfully reloaded when it goes back to 'embedder' |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string()); | 678 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string()); |
| 773 | 679 |
| 774 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 680 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
| 775 test_embedder()->web_contents()->GetRenderViewHost()); | 681 test_embedder()->web_contents()->GetRenderViewHost()); |
| 776 ExecuteSyncJSFunction(rvh, "document.getElementById('plugin').terminate()"); | 682 ExecuteSyncJSFunction(rvh, "document.getElementById('plugin').terminate()"); |
| 777 | 683 |
| 778 // Expect the guest to crash. | 684 // Expect the guest to crash. |
| 779 test_guest()->WaitForExit(); | 685 test_guest()->WaitForExit(); |
| 780 } | 686 } |
| 781 | 687 |
| 782 // This test verifies that the guest is responsive after crashing and going back | |
| 783 // to a previous navigation entry. | |
| 784 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, BackAfterTerminateGuest) { | |
| 785 const char* kEmbedderURL = "/browser_plugin_embedder.html"; | |
| 786 StartBrowserPluginTest( | |
| 787 kEmbedderURL, GetHTMLForGuestWithTitle("P1"), true, std::string()); | |
| 788 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | |
| 789 test_embedder()->web_contents()->GetRenderViewHost()); | |
| 790 | |
| 791 // Navigate to P2 and verify that the navigation occurred. | |
| 792 { | |
| 793 const string16 expected_title = ASCIIToUTF16("P2"); | |
| 794 content::TitleWatcher title_watcher(test_guest()->web_contents(), | |
| 795 expected_title); | |
| 796 | |
| 797 ExecuteSyncJSFunction( | |
| 798 rvh, | |
| 799 base::StringPrintf( | |
| 800 "SetSrc('%s');", GetHTMLForGuestWithTitle("P2").c_str())); | |
| 801 | |
| 802 string16 actual_title = title_watcher.WaitAndGetTitle(); | |
| 803 EXPECT_EQ(expected_title, actual_title); | |
| 804 } | |
| 805 // Kill the guest. | |
| 806 ExecuteSyncJSFunction(rvh, "document.getElementById('plugin').terminate()"); | |
| 807 | |
| 808 // Expect the guest to report that it crashed. | |
| 809 test_guest()->WaitForExit(); | |
| 810 // Go back and verify that we're back at P1. | |
| 811 { | |
| 812 const string16 expected_title = ASCIIToUTF16("P1"); | |
| 813 content::TitleWatcher title_watcher(test_guest()->web_contents(), | |
| 814 expected_title); | |
| 815 | |
| 816 ExecuteSyncJSFunction(rvh, "Back();"); | |
| 817 | |
| 818 string16 actual_title = title_watcher.WaitAndGetTitle(); | |
| 819 EXPECT_EQ(expected_title, actual_title); | |
| 820 } | |
| 821 // Send an input event and verify that the guest receives the input. | |
| 822 SimulateMouseClick(test_embedder()->web_contents(), 0, | |
| 823 WebKit::WebMouseEvent::ButtonLeft); | |
| 824 test_guest()->WaitForInput(); | |
| 825 } | |
| 826 | |
| 827 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadStart) { | 688 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadStart) { |
| 828 const char kEmbedderURL[] = "/browser_plugin_embedder.html"; | 689 const char kEmbedderURL[] = "/browser_plugin_embedder.html"; |
| 829 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, std::string()); | 690 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, std::string()); |
| 830 | 691 |
| 831 const string16 expected_title = ASCIIToUTF16(kHTMLForGuest); | 692 const string16 expected_title = ASCIIToUTF16(kHTMLForGuest); |
| 832 content::TitleWatcher title_watcher(test_embedder()->web_contents(), | 693 content::TitleWatcher title_watcher(test_embedder()->web_contents(), |
| 833 expected_title); | 694 expected_title); |
| 834 // Renavigate the guest to |kHTMLForGuest|. | 695 // Renavigate the guest to |kHTMLForGuest|. |
| 835 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 696 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
| 836 test_embedder()->web_contents()->GetRenderViewHost()); | 697 test_embedder()->web_contents()->GetRenderViewHost()); |
| (...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1447 // in the guest. | 1308 // in the guest. |
| 1448 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, VerifyInputMethodActive) { | 1309 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, VerifyInputMethodActive) { |
| 1449 const char* kEmbedderURL = "/browser_plugin_embedder.html"; | 1310 const char* kEmbedderURL = "/browser_plugin_embedder.html"; |
| 1450 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string()); | 1311 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, std::string()); |
| 1451 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 1312 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
| 1452 test_guest()->web_contents()->GetRenderViewHost()); | 1313 test_guest()->web_contents()->GetRenderViewHost()); |
| 1453 EXPECT_TRUE(rvh->input_method_active()); | 1314 EXPECT_TRUE(rvh->input_method_active()); |
| 1454 } | 1315 } |
| 1455 | 1316 |
| 1456 } // namespace content | 1317 } // namespace content |
| OLD | NEW |