OLD | NEW |
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 Loading... |
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 void WaitForGuestRemoved(size_t expected_remove_count) { |
| 56 if (expected_remove_count == guest_remove_count_) |
| 57 return; |
| 58 |
| 59 remove_message_loop_runner_ = new content::MessageLoopRunner; |
| 60 remove_message_loop_runner_->Run(); |
| 61 } |
| 62 |
| 63 size_t guest_add_count() { return guest_add_count_; } |
| 64 |
53 private: | 65 private: |
54 // GuestViewManager override: | 66 // GuestViewManager override: |
55 virtual void AddGuest(int guest_instance_id, | 67 virtual void AddGuest(int guest_instance_id, |
56 content::WebContents* guest_web_contents) OVERRIDE{ | 68 content::WebContents* guest_web_contents) OVERRIDE{ |
57 GuestViewManager::AddGuest(guest_instance_id, guest_web_contents); | 69 GuestViewManager::AddGuest(guest_instance_id, guest_web_contents); |
58 web_contents_ = guest_web_contents; | 70 web_contents_ = guest_web_contents; |
| 71 ++guest_add_count_; |
59 | 72 |
60 if (message_loop_runner_.get()) | 73 if (add_message_loop_runner_.get()) |
61 message_loop_runner_->Quit(); | 74 add_message_loop_runner_->Quit(); |
62 } | 75 } |
63 | 76 |
| 77 virtual void RemoveGuest(int guest_instance_id) OVERRIDE { |
| 78 GuestViewManager::RemoveGuest(guest_instance_id); |
| 79 ++guest_remove_count_; |
| 80 |
| 81 if (remove_message_loop_runner_.get()) |
| 82 remove_message_loop_runner_->Quit(); |
| 83 } |
| 84 |
| 85 size_t guest_add_count_; |
| 86 size_t guest_remove_count_; |
64 content::WebContents* web_contents_; | 87 content::WebContents* web_contents_; |
65 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | 88 scoped_refptr<content::MessageLoopRunner> add_message_loop_runner_; |
| 89 scoped_refptr<content::MessageLoopRunner> remove_message_loop_runner_; |
66 }; | 90 }; |
67 | 91 |
68 // Test factory for creating test instances of GuestViewManager. | 92 // Test factory for creating test instances of GuestViewManager. |
69 class TestGuestViewManagerFactory : public extensions::GuestViewManagerFactory { | 93 class TestGuestViewManagerFactory : public extensions::GuestViewManagerFactory { |
70 public: | 94 public: |
71 TestGuestViewManagerFactory() : | 95 TestGuestViewManagerFactory() : |
72 test_guest_view_manager_(NULL) {} | 96 test_guest_view_manager_(NULL) {} |
73 | 97 |
74 virtual ~TestGuestViewManagerFactory() {} | 98 virtual ~TestGuestViewManagerFactory() {} |
75 | 99 |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 const std::string& app_location, | 275 const std::string& app_location, |
252 TestServer test_server) { | 276 TestServer test_server) { |
253 content::WebContents* embedder_web_contents = NULL; | 277 content::WebContents* embedder_web_contents = NULL; |
254 scoped_ptr<ExtensionTestMessageListener> done_listener( | 278 scoped_ptr<ExtensionTestMessageListener> done_listener( |
255 RunAppHelper( | 279 RunAppHelper( |
256 test_name, app_location, test_server, &embedder_web_contents)); | 280 test_name, app_location, test_server, &embedder_web_contents)); |
257 | 281 |
258 ASSERT_TRUE(done_listener); | 282 ASSERT_TRUE(done_listener); |
259 ASSERT_TRUE(done_listener->WaitUntilSatisfied()); | 283 ASSERT_TRUE(done_listener->WaitUntilSatisfied()); |
260 | 284 |
261 guest_web_contents_ = GetGuestViewManager()->WaitForGuestCreated(); | 285 guest_web_contents_ = GetGuestViewManager()->WaitForGuestAdded(); |
262 } | 286 } |
263 | 287 |
264 void RunTest(const std::string& app_name) { | 288 void RunTest(const std::string& app_name) { |
265 } | 289 } |
266 void SetupTest(const std::string& app_name, | 290 void SetupTest(const std::string& app_name, |
267 const std::string& guest_url_spec) { | 291 const std::string& guest_url_spec) { |
268 ASSERT_TRUE(StartEmbeddedTestServer()); | 292 ASSERT_TRUE(StartEmbeddedTestServer()); |
269 GURL::Replacements replace_host; | 293 GURL::Replacements replace_host; |
270 std::string host_str("localhost"); // Must stay in scope with replace_host. | 294 std::string host_str("localhost"); // Must stay in scope with replace_host. |
271 replace_host.SetHostStr(host_str); | 295 replace_host.SetHostStr(host_str); |
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
824 #else | 848 #else |
825 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync( | 849 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync( |
826 GetPlatformAppWindow(), ui::VKEY_RETURN, | 850 GetPlatformAppWindow(), ui::VKEY_RETURN, |
827 true /* ctrl */, false, false, false)); | 851 true /* ctrl */, false, false, false)); |
828 #endif | 852 #endif |
829 | 853 |
830 // Wait for the embedder to receive a 'newwindow' event. | 854 // Wait for the embedder to receive a 'newwindow' event. |
831 ASSERT_TRUE(done_listener->WaitUntilSatisfied()); | 855 ASSERT_TRUE(done_listener->WaitUntilSatisfied()); |
832 } | 856 } |
833 | 857 |
| 858 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, |
| 859 NewWindow_OpenerDestroyedBeforeAttach) { |
| 860 TestHelper("testNewWindowOpenerDestroyedBeforeAttach", |
| 861 "web_view/newwindow", |
| 862 NEEDS_TEST_SERVER); |
| 863 EXPECT_EQ(2u, GetGuestViewManager()->guest_add_count()); |
| 864 |
| 865 // We have two guests in this test, one is the intial one, the other |
| 866 // is the newwindow one. |
| 867 // Before the embedder goes away, both the guests should go away. |
| 868 // This ensures that unattached guests are gone if opener is gone. |
| 869 GetGuestViewManager()->WaitForGuestRemoved(2u); |
| 870 } |
834 | 871 |
835 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, ExecuteCode) { | 872 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, ExecuteCode) { |
836 ASSERT_TRUE(RunPlatformAppTestWithArg( | 873 ASSERT_TRUE(RunPlatformAppTestWithArg( |
837 "platform_apps/web_view/common", "execute_code")) << message_; | 874 "platform_apps/web_view/common", "execute_code")) << message_; |
838 } | 875 } |
839 | 876 |
840 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, PopupPositioningBasic) { | 877 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, PopupPositioningBasic) { |
841 TestHelper("testBasic", "web_view/popup_positioning", NO_TEST_SERVER); | 878 TestHelper("testBasic", "web_view/popup_positioning", NO_TEST_SERVER); |
842 ASSERT_TRUE(guest_web_contents()); | 879 ASSERT_TRUE(guest_web_contents()); |
843 PopupTestHelper(gfx::Point()); | 880 PopupTestHelper(gfx::Point()); |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1107 | 1144 |
1108 // Now verify that the selection text propagates properly to RWHV. | 1145 // Now verify that the selection text propagates properly to RWHV. |
1109 content::RenderWidgetHostView* guest_rwhv = | 1146 content::RenderWidgetHostView* guest_rwhv = |
1110 guest_web_contents()->GetRenderWidgetHostView(); | 1147 guest_web_contents()->GetRenderWidgetHostView(); |
1111 ASSERT_TRUE(guest_rwhv); | 1148 ASSERT_TRUE(guest_rwhv); |
1112 std::string selected_text = base::UTF16ToUTF8(guest_rwhv->GetSelectedText()); | 1149 std::string selected_text = base::UTF16ToUTF8(guest_rwhv->GetSelectedText()); |
1113 ASSERT_TRUE(selected_text.size() >= 10u); | 1150 ASSERT_TRUE(selected_text.size() >= 10u); |
1114 ASSERT_EQ("AAAAAAAAAA", selected_text.substr(0, 10)); | 1151 ASSERT_EQ("AAAAAAAAAA", selected_text.substr(0, 10)); |
1115 } | 1152 } |
1116 #endif | 1153 #endif |
OLD | NEW |