Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(185)

Side by Side Diff: chrome/browser/apps/web_view_interactive_browsertest.cc

Issue 558813002: <webview>: Fix an issue with destroying an opener that has unattached guests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add tests for attach/discard call after opener destruction Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/strings/stringprintf.h" 5 #include "base/strings/stringprintf.h"
6 #include "base/strings/utf_string_conversions.h" 6 #include "base/strings/utf_string_conversions.h"
7 #include "chrome/app/chrome_command_ids.h" 7 #include "chrome/app/chrome_command_ids.h"
8 #include "chrome/browser/apps/app_browsertest_util.h" 8 #include "chrome/browser/apps/app_browsertest_util.h"
9 #include "chrome/browser/chrome_content_browser_client.h" 9 #include "chrome/browser/chrome_content_browser_client.h"
10 #include "chrome/browser/extensions/extension_test_message_listener.h" 10 #include "chrome/browser/extensions/extension_test_message_listener.h"
(...skipping 19 matching lines...) Expand all
30 #include "net/test/embedded_test_server/embedded_test_server.h" 30 #include "net/test/embedded_test_server/embedded_test_server.h"
31 #include "ui/base/ime/composition_text.h" 31 #include "ui/base/ime/composition_text.h"
32 #include "ui/base/ime/text_input_client.h" 32 #include "ui/base/ime/text_input_client.h"
33 #include "ui/base/test/ui_controls.h" 33 #include "ui/base/test/ui_controls.h"
34 #include "ui/events/keycodes/keyboard_codes.h" 34 #include "ui/events/keycodes/keyboard_codes.h"
35 35
36 using extensions::AppWindow; 36 using extensions::AppWindow;
37 37
38 class TestGuestViewManager : public extensions::GuestViewManager { 38 class TestGuestViewManager : public extensions::GuestViewManager {
39 public: 39 public:
40 explicit TestGuestViewManager(content::BrowserContext* context) : 40 explicit TestGuestViewManager(content::BrowserContext* context)
41 GuestViewManager(context), 41 : GuestViewManager(context),
42 web_contents_(NULL) {} 42 guest_add_count_(0),
43 guest_remove_count_(0),
44 web_contents_(NULL) {}
43 45
44 content::WebContents* WaitForGuestCreated() { 46 content::WebContents* WaitForGuestAdded() {
45 if (web_contents_) 47 if (web_contents_)
46 return web_contents_; 48 return web_contents_;
47 49
48 message_loop_runner_ = new content::MessageLoopRunner; 50 add_message_loop_runner_ = new content::MessageLoopRunner;
49 message_loop_runner_->Run(); 51 add_message_loop_runner_->Run();
50 return web_contents_; 52 return web_contents_;
51 } 53 }
52 54
55 // Waits so that at least |expected_remove_count| guests' creation
56 // has been seen by this manager.
57 void WaitForGuestRemoved(size_t expected_remove_count) {
58 if (guest_remove_count_ >= expected_remove_count)
59 return;
60
61 remove_message_loop_runner_ = new content::MessageLoopRunner;
62 remove_message_loop_runner_->Run();
63 }
64
65 size_t guest_add_count() { return guest_add_count_; }
66
53 private: 67 private:
54 // GuestViewManager override: 68 // GuestViewManager override:
55 virtual void AddGuest(int guest_instance_id, 69 virtual void AddGuest(int guest_instance_id,
56 content::WebContents* guest_web_contents) OVERRIDE{ 70 content::WebContents* guest_web_contents) OVERRIDE{
57 GuestViewManager::AddGuest(guest_instance_id, guest_web_contents); 71 GuestViewManager::AddGuest(guest_instance_id, guest_web_contents);
58 web_contents_ = guest_web_contents; 72 web_contents_ = guest_web_contents;
73 ++guest_add_count_;
59 74
60 if (message_loop_runner_.get()) 75 if (add_message_loop_runner_.get())
61 message_loop_runner_->Quit(); 76 add_message_loop_runner_->Quit();
62 } 77 }
63 78
79 virtual void RemoveGuest(int guest_instance_id) OVERRIDE {
80 GuestViewManager::RemoveGuest(guest_instance_id);
81 ++guest_remove_count_;
82
83 if (remove_message_loop_runner_.get())
84 remove_message_loop_runner_->Quit();
85 }
86
87 size_t guest_add_count_;
88 size_t guest_remove_count_;
64 content::WebContents* web_contents_; 89 content::WebContents* web_contents_;
65 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; 90 scoped_refptr<content::MessageLoopRunner> add_message_loop_runner_;
91 scoped_refptr<content::MessageLoopRunner> remove_message_loop_runner_;
66 }; 92 };
67 93
68 // Test factory for creating test instances of GuestViewManager. 94 // Test factory for creating test instances of GuestViewManager.
69 class TestGuestViewManagerFactory : public extensions::GuestViewManagerFactory { 95 class TestGuestViewManagerFactory : public extensions::GuestViewManagerFactory {
70 public: 96 public:
71 TestGuestViewManagerFactory() : 97 TestGuestViewManagerFactory() :
72 test_guest_view_manager_(NULL) {} 98 test_guest_view_manager_(NULL) {}
73 99
74 virtual ~TestGuestViewManagerFactory() {} 100 virtual ~TestGuestViewManagerFactory() {}
75 101
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 const std::string& app_location, 277 const std::string& app_location,
252 TestServer test_server) { 278 TestServer test_server) {
253 content::WebContents* embedder_web_contents = NULL; 279 content::WebContents* embedder_web_contents = NULL;
254 scoped_ptr<ExtensionTestMessageListener> done_listener( 280 scoped_ptr<ExtensionTestMessageListener> done_listener(
255 RunAppHelper( 281 RunAppHelper(
256 test_name, app_location, test_server, &embedder_web_contents)); 282 test_name, app_location, test_server, &embedder_web_contents));
257 283
258 ASSERT_TRUE(done_listener); 284 ASSERT_TRUE(done_listener);
259 ASSERT_TRUE(done_listener->WaitUntilSatisfied()); 285 ASSERT_TRUE(done_listener->WaitUntilSatisfied());
260 286
261 guest_web_contents_ = GetGuestViewManager()->WaitForGuestCreated(); 287 guest_web_contents_ = GetGuestViewManager()->WaitForGuestAdded();
262 } 288 }
263 289
264 void RunTest(const std::string& app_name) { 290 void RunTest(const std::string& app_name) {
265 } 291 }
266 void SetupTest(const std::string& app_name, 292 void SetupTest(const std::string& app_name,
267 const std::string& guest_url_spec) { 293 const std::string& guest_url_spec) {
268 ASSERT_TRUE(StartEmbeddedTestServer()); 294 ASSERT_TRUE(StartEmbeddedTestServer());
269 GURL::Replacements replace_host; 295 GURL::Replacements replace_host;
270 std::string host_str("localhost"); // Must stay in scope with replace_host. 296 std::string host_str("localhost"); // Must stay in scope with replace_host.
271 replace_host.SetHostStr(host_str); 297 replace_host.SetHostStr(host_str);
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 // Flush any pending events to make sure we start with a clean slate. 752 // Flush any pending events to make sure we start with a clean slate.
727 content::RunAllPendingInMessageLoop(); 753 content::RunAllPendingInMessageLoop();
728 754
729 ExtensionTestMessageListener start_of_line_listener("StartOfLine", false); 755 ExtensionTestMessageListener start_of_line_listener("StartOfLine", false);
730 SendStartOfLineKeyPressToPlatformApp(); 756 SendStartOfLineKeyPressToPlatformApp();
731 // Wait for the guest to receive a 'copy' edit command. 757 // Wait for the guest to receive a 'copy' edit command.
732 ASSERT_TRUE(start_of_line_listener.WaitUntilSatisfied()); 758 ASSERT_TRUE(start_of_line_listener.WaitUntilSatisfied());
733 } 759 }
734 760
735 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, 761 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest,
762 NewWindow_AttachAfterOpenerDestroyed) {
763 TestHelper("testNewWindowAttachAfterOpenerDestroyed",
764 "web_view/newwindow",
765 NEEDS_TEST_SERVER);
766 }
767
768 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest,
736 NewWindow_NewWindowNameTakesPrecedence) { 769 NewWindow_NewWindowNameTakesPrecedence) {
737 TestHelper("testNewWindowNameTakesPrecedence", 770 TestHelper("testNewWindowNameTakesPrecedence",
738 "web_view/newwindow", 771 "web_view/newwindow",
739 NEEDS_TEST_SERVER); 772 NEEDS_TEST_SERVER);
740 } 773 }
741 774
742 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, 775 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest,
743 NewWindow_WebViewNameTakesPrecedence) { 776 NewWindow_WebViewNameTakesPrecedence) {
744 TestHelper("testWebViewNameTakesPrecedence", 777 TestHelper("testNewWindowWebViewNameTakesPrecedence",
745 "web_view/newwindow", 778 "web_view/newwindow",
746 NEEDS_TEST_SERVER); 779 NEEDS_TEST_SERVER);
747 } 780 }
748 781
749 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, NewWindow_NoName) { 782 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, NewWindow_NoName) {
750 TestHelper("testNoName", 783 TestHelper("testNewWindowNoName",
751 "web_view/newwindow", 784 "web_view/newwindow",
752 NEEDS_TEST_SERVER); 785 NEEDS_TEST_SERVER);
753 } 786 }
754 787
755 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, NewWindow_Redirect) { 788 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, NewWindow_Redirect) {
756 TestHelper("testNewWindowRedirect", 789 TestHelper("testNewWindowRedirect",
757 "web_view/newwindow", 790 "web_view/newwindow",
758 NEEDS_TEST_SERVER); 791 NEEDS_TEST_SERVER);
759 } 792 }
760 793
(...skipping 15 matching lines...) Expand all
776 NEEDS_TEST_SERVER); 809 NEEDS_TEST_SERVER);
777 } 810 }
778 811
779 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, 812 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest,
780 NewWindow_DeclarativeWebRequest) { 813 NewWindow_DeclarativeWebRequest) {
781 TestHelper("testNewWindowDeclarativeWebRequest", 814 TestHelper("testNewWindowDeclarativeWebRequest",
782 "web_view/newwindow", 815 "web_view/newwindow",
783 NEEDS_TEST_SERVER); 816 NEEDS_TEST_SERVER);
784 } 817 }
785 818
819 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest,
820 NewWindow_DiscardAfterOpenerDestroyed) {
821 TestHelper("testNewWindowDiscardAfterOpenerDestroyed",
822 "web_view/newwindow",
823 NEEDS_TEST_SERVER);
824 }
825
786 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, NewWindow_WebRequest) { 826 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, NewWindow_WebRequest) {
787 TestHelper("testNewWindowWebRequest", 827 TestHelper("testNewWindowWebRequest",
788 "web_view/newwindow", 828 "web_view/newwindow",
789 NEEDS_TEST_SERVER); 829 NEEDS_TEST_SERVER);
790 } 830 }
791 831
792 // A custom elements bug needs to be addressed to enable this test: 832 // A custom elements bug needs to be addressed to enable this test:
793 // See http://crbug.com/282477 for more information. 833 // See http://crbug.com/282477 for more information.
794 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, 834 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest,
795 DISABLED_NewWindow_WebRequestCloseWindow) { 835 DISABLED_NewWindow_WebRequestCloseWindow) {
(...skipping 28 matching lines...) Expand all
824 #else 864 #else
825 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync( 865 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
826 GetPlatformAppWindow(), ui::VKEY_RETURN, 866 GetPlatformAppWindow(), ui::VKEY_RETURN,
827 true /* ctrl */, false, false, false)); 867 true /* ctrl */, false, false, false));
828 #endif 868 #endif
829 869
830 // Wait for the embedder to receive a 'newwindow' event. 870 // Wait for the embedder to receive a 'newwindow' event.
831 ASSERT_TRUE(done_listener->WaitUntilSatisfied()); 871 ASSERT_TRUE(done_listener->WaitUntilSatisfied());
832 } 872 }
833 873
874 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest,
875 NewWindow_OpenerDestroyedWhileUnattached) {
876 TestHelper("testNewWindowOpenerDestroyedWhileUnattached",
877 "web_view/newwindow",
878 NEEDS_TEST_SERVER);
879 ASSERT_EQ(2u, GetGuestViewManager()->guest_add_count());
880
881 // We have two guests in this test, one is the intial one, the other
882 // is the newwindow one.
883 // Before the embedder goes away, both the guests should go away.
884 // This ensures that unattached guests are gone if opener is gone.
885 GetGuestViewManager()->WaitForGuestRemoved(2u);
886 }
834 887
835 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, ExecuteCode) { 888 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, ExecuteCode) {
836 ASSERT_TRUE(RunPlatformAppTestWithArg( 889 ASSERT_TRUE(RunPlatformAppTestWithArg(
837 "platform_apps/web_view/common", "execute_code")) << message_; 890 "platform_apps/web_view/common", "execute_code")) << message_;
838 } 891 }
839 892
840 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, PopupPositioningBasic) { 893 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, PopupPositioningBasic) {
841 TestHelper("testBasic", "web_view/popup_positioning", NO_TEST_SERVER); 894 TestHelper("testBasic", "web_view/popup_positioning", NO_TEST_SERVER);
842 ASSERT_TRUE(guest_web_contents()); 895 ASSERT_TRUE(guest_web_contents());
843 PopupTestHelper(gfx::Point()); 896 PopupTestHelper(gfx::Point());
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
1107 1160
1108 // Now verify that the selection text propagates properly to RWHV. 1161 // Now verify that the selection text propagates properly to RWHV.
1109 content::RenderWidgetHostView* guest_rwhv = 1162 content::RenderWidgetHostView* guest_rwhv =
1110 guest_web_contents()->GetRenderWidgetHostView(); 1163 guest_web_contents()->GetRenderWidgetHostView();
1111 ASSERT_TRUE(guest_rwhv); 1164 ASSERT_TRUE(guest_rwhv);
1112 std::string selected_text = base::UTF16ToUTF8(guest_rwhv->GetSelectedText()); 1165 std::string selected_text = base::UTF16ToUTF8(guest_rwhv->GetSelectedText());
1113 ASSERT_TRUE(selected_text.size() >= 10u); 1166 ASSERT_TRUE(selected_text.size() >= 10u);
1114 ASSERT_EQ("AAAAAAAAAA", selected_text.substr(0, 10)); 1167 ASSERT_EQ("AAAAAAAAAA", selected_text.substr(0, 10));
1115 } 1168 }
1116 #endif 1169 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698