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 "apps/app_window.h" | 5 #include "apps/app_window.h" |
6 #include "apps/app_window_registry.h" | 6 #include "apps/app_window_registry.h" |
7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/app/chrome_command_ids.h" | 9 #include "chrome/app/chrome_command_ids.h" |
10 #include "chrome/browser/apps/app_browsertest_util.h" | 10 #include "chrome/browser/apps/app_browsertest_util.h" |
11 #include "chrome/browser/chrome_content_browser_client.h" | 11 #include "chrome/browser/chrome_content_browser_client.h" |
12 #include "chrome/browser/extensions/extension_test_message_listener.h" | 12 #include "chrome/browser/extensions/extension_test_message_listener.h" |
13 #include "chrome/browser/guest_view/guest_view_base.h" | 13 #include "chrome/browser/guest_view/guest_view_base.h" |
| 14 #include "chrome/browser/guest_view/guest_view_manager.h" |
| 15 #include "chrome/browser/guest_view/guest_view_manager_factory.h" |
14 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/renderer_context_menu/render_view_context_menu_browsert
est_util.h" | 17 #include "chrome/browser/renderer_context_menu/render_view_context_menu_browsert
est_util.h" |
16 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti
l.h" | 18 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti
l.h" |
17 #include "chrome/test/base/interactive_test_utils.h" | 19 #include "chrome/test/base/interactive_test_utils.h" |
18 #include "chrome/test/base/test_launcher_utils.h" | 20 #include "chrome/test/base/test_launcher_utils.h" |
19 #include "chrome/test/base/ui_test_utils.h" | 21 #include "chrome/test/base/ui_test_utils.h" |
20 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
21 #include "content/public/browser/render_process_host.h" | 23 #include "content/public/browser/render_process_host.h" |
22 #include "content/public/browser/render_view_host.h" | 24 #include "content/public/browser/render_view_host.h" |
23 #include "content/public/browser/render_widget_host_iterator.h" | 25 #include "content/public/browser/render_widget_host_iterator.h" |
24 #include "content/public/browser/render_widget_host_view.h" | 26 #include "content/public/browser/render_widget_host_view.h" |
25 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
26 #include "content/public/common/content_switches.h" | 28 #include "content/public/common/content_switches.h" |
27 #include "content/public/test/browser_test_utils.h" | 29 #include "content/public/test/browser_test_utils.h" |
28 #include "net/test/embedded_test_server/embedded_test_server.h" | 30 #include "net/test/embedded_test_server/embedded_test_server.h" |
29 #include "ui/base/ime/composition_text.h" | 31 #include "ui/base/ime/composition_text.h" |
30 #include "ui/base/ime/text_input_client.h" | 32 #include "ui/base/ime/text_input_client.h" |
31 #include "ui/base/test/ui_controls.h" | 33 #include "ui/base/test/ui_controls.h" |
32 #include "ui/events/keycodes/keyboard_codes.h" | 34 #include "ui/events/keycodes/keyboard_codes.h" |
33 | 35 |
34 using apps::AppWindow; | 36 using apps::AppWindow; |
35 | 37 |
| 38 class TestGuestViewManager : public GuestViewManager { |
| 39 public: |
| 40 explicit TestGuestViewManager(content::BrowserContext* context) : |
| 41 GuestViewManager(context), |
| 42 web_contents_(NULL) {} |
| 43 |
| 44 content::WebContents* WaitForGuestCreated() { |
| 45 if (web_contents_) |
| 46 return web_contents_; |
| 47 |
| 48 message_loop_runner_ = new content::MessageLoopRunner; |
| 49 message_loop_runner_->Run(); |
| 50 return web_contents_; |
| 51 } |
| 52 |
| 53 private: |
| 54 // GuestViewManager override: |
| 55 virtual void AddGuest(int guest_instance_id, |
| 56 content::WebContents* guest_web_contents) OVERRIDE{ |
| 57 GuestViewManager::AddGuest(guest_instance_id, guest_web_contents); |
| 58 web_contents_ = guest_web_contents; |
| 59 |
| 60 if (message_loop_runner_) |
| 61 message_loop_runner_->Quit(); |
| 62 } |
| 63 |
| 64 content::WebContents* web_contents_; |
| 65 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
| 66 }; |
| 67 |
| 68 // Test factory for creating test instances of GuestViewManager. |
| 69 class TestGuestViewManagerFactory : public GuestViewManagerFactory { |
| 70 public: |
| 71 TestGuestViewManagerFactory() : |
| 72 test_guest_view_manager_(NULL) {} |
| 73 |
| 74 virtual ~TestGuestViewManagerFactory() {} |
| 75 |
| 76 virtual GuestViewManager* CreateGuestViewManager( |
| 77 content::BrowserContext* context) OVERRIDE { |
| 78 return GetManager(context); |
| 79 } |
| 80 |
| 81 TestGuestViewManager* GetManager(content::BrowserContext* context) { |
| 82 if (!test_guest_view_manager_) { |
| 83 test_guest_view_manager_ = new TestGuestViewManager(context); |
| 84 } |
| 85 return test_guest_view_manager_; |
| 86 } |
| 87 |
| 88 private: |
| 89 TestGuestViewManager* test_guest_view_manager_; |
| 90 |
| 91 DISALLOW_COPY_AND_ASSIGN(TestGuestViewManagerFactory); |
| 92 }; |
| 93 |
36 class WebViewInteractiveTest | 94 class WebViewInteractiveTest |
37 : public extensions::PlatformAppBrowserTest { | 95 : public extensions::PlatformAppBrowserTest { |
38 public: | 96 public: |
39 WebViewInteractiveTest() | 97 WebViewInteractiveTest() |
40 : guest_web_contents_(NULL), | 98 : guest_web_contents_(NULL), |
41 embedder_web_contents_(NULL), | 99 embedder_web_contents_(NULL), |
42 corner_(gfx::Point()), | 100 corner_(gfx::Point()), |
43 mouse_click_result_(false), | 101 mouse_click_result_(false), |
44 first_click_(true) {} | 102 first_click_(true) { |
| 103 GuestViewManager::set_factory_for_testing(&factory_); |
| 104 } |
| 105 |
| 106 TestGuestViewManager* GetGuestViewManager() { |
| 107 return factory_.GetManager(browser()->profile()); |
| 108 } |
45 | 109 |
46 void MoveMouseInsideWindowWithListener(gfx::Point point, | 110 void MoveMouseInsideWindowWithListener(gfx::Point point, |
47 const std::string& message) { | 111 const std::string& message) { |
48 ExtensionTestMessageListener move_listener(message, false); | 112 ExtensionTestMessageListener move_listener(message, false); |
49 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync( | 113 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync( |
50 gfx::Point(corner_.x() + point.x(), corner_.y() + point.y()))); | 114 gfx::Point(corner_.x() + point.x(), corner_.y() + point.y()))); |
51 ASSERT_TRUE(move_listener.WaitUntilSatisfied()); | 115 ASSERT_TRUE(move_listener.WaitUntilSatisfied()); |
52 } | 116 } |
53 | 117 |
54 void SendMouseClickWithListener(ui_controls::MouseButton button, | 118 void SendMouseClickWithListener(ui_controls::MouseButton button, |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 LOG(ERROR) << "UNABLE TO START TEST"; | 243 LOG(ERROR) << "UNABLE TO START TEST"; |
180 return scoped_ptr<ExtensionTestMessageListener>(); | 244 return scoped_ptr<ExtensionTestMessageListener>(); |
181 } | 245 } |
182 | 246 |
183 return done_listener.Pass(); | 247 return done_listener.Pass(); |
184 } | 248 } |
185 | 249 |
186 void TestHelper(const std::string& test_name, | 250 void TestHelper(const std::string& test_name, |
187 const std::string& app_location, | 251 const std::string& app_location, |
188 TestServer test_server) { | 252 TestServer test_server) { |
189 GuestContentBrowserClient new_client; | |
190 content::ContentBrowserClient* old_client = | |
191 SetBrowserClientForTesting(&new_client); | |
192 | |
193 content::WebContents* embedder_web_contents = NULL; | 253 content::WebContents* embedder_web_contents = NULL; |
194 scoped_ptr<ExtensionTestMessageListener> done_listener( | 254 scoped_ptr<ExtensionTestMessageListener> done_listener( |
195 RunAppHelper( | 255 RunAppHelper( |
196 test_name, app_location, test_server, &embedder_web_contents)); | 256 test_name, app_location, test_server, &embedder_web_contents)); |
197 | 257 |
198 ASSERT_TRUE(done_listener); | 258 ASSERT_TRUE(done_listener); |
199 ASSERT_TRUE(done_listener->WaitUntilSatisfied()); | 259 ASSERT_TRUE(done_listener->WaitUntilSatisfied()); |
200 | 260 |
201 guest_web_contents_ = new_client.WaitForGuestCreated(); | 261 guest_web_contents_ = GetGuestViewManager()->WaitForGuestCreated(); |
202 // Reset the browser client so that we do not notice any unexpected | |
203 // behavior. | |
204 SetBrowserClientForTesting(old_client); | |
205 } | 262 } |
206 | 263 |
207 void RunTest(const std::string& app_name) { | 264 void RunTest(const std::string& app_name) { |
208 } | 265 } |
209 void SetupTest(const std::string& app_name, | 266 void SetupTest(const std::string& app_name, |
210 const std::string& guest_url_spec) { | 267 const std::string& guest_url_spec) { |
211 ASSERT_TRUE(StartEmbeddedTestServer()); | 268 ASSERT_TRUE(StartEmbeddedTestServer()); |
212 GURL::Replacements replace_host; | 269 GURL::Replacements replace_host; |
213 std::string host_str("localhost"); // Must stay in scope with replace_host. | 270 std::string host_str("localhost"); // Must stay in scope with replace_host. |
214 replace_host.SetHostStr(host_str); | 271 replace_host.SetHostStr(host_str); |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 std::string last_drop_data; | 497 std::string last_drop_data; |
441 EXPECT_TRUE(content::ExecuteScriptAndExtractString( | 498 EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
442 embedder_web_contents_, | 499 embedder_web_contents_, |
443 "window.domAutomationController.send(getLastDropData())", | 500 "window.domAutomationController.send(getLastDropData())", |
444 &last_drop_data)); | 501 &last_drop_data)); |
445 | 502 |
446 last_drop_data_ = last_drop_data; | 503 last_drop_data_ = last_drop_data; |
447 } | 504 } |
448 | 505 |
449 protected: | 506 protected: |
| 507 TestGuestViewManagerFactory factory_; |
450 content::WebContents* guest_web_contents_; | 508 content::WebContents* guest_web_contents_; |
451 content::WebContents* embedder_web_contents_; | 509 content::WebContents* embedder_web_contents_; |
452 gfx::Point corner_; | 510 gfx::Point corner_; |
453 bool mouse_click_result_; | 511 bool mouse_click_result_; |
454 bool first_click_; | 512 bool first_click_; |
455 // Only used in drag/drop test. | 513 // Only used in drag/drop test. |
456 base::Closure quit_closure_; | 514 base::Closure quit_closure_; |
457 std::string last_drop_data_; | 515 std::string last_drop_data_; |
458 | |
459 private: | |
460 // Used to get notified when a guest is created. | |
461 class GuestContentBrowserClient : public chrome::ChromeContentBrowserClient { | |
462 public: | |
463 GuestContentBrowserClient() : web_contents_(NULL) {} | |
464 | |
465 content::WebContents* WaitForGuestCreated() { | |
466 if (web_contents_) | |
467 return web_contents_; | |
468 | |
469 message_loop_runner_ = new content::MessageLoopRunner; | |
470 message_loop_runner_->Run(); | |
471 return web_contents_; | |
472 } | |
473 | |
474 private: | |
475 // ChromeContentBrowserClient implementation: | |
476 virtual void GuestWebContentsAttached( | |
477 content::WebContents* guest_web_contents, | |
478 content::WebContents* embedder_web_contents, | |
479 const base::DictionaryValue& extra_params) OVERRIDE { | |
480 ChromeContentBrowserClient::GuestWebContentsAttached( | |
481 guest_web_contents, embedder_web_contents, extra_params); | |
482 web_contents_ = guest_web_contents; | |
483 | |
484 if (message_loop_runner_) | |
485 message_loop_runner_->Quit(); | |
486 } | |
487 | |
488 content::WebContents* web_contents_; | |
489 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | |
490 }; | |
491 }; | 516 }; |
492 | 517 |
493 // ui_test_utils::SendMouseMoveSync doesn't seem to work on OS_MACOSX, and | 518 // ui_test_utils::SendMouseMoveSync doesn't seem to work on OS_MACOSX, and |
494 // likely won't work on many other platforms as well, so for now this test | 519 // likely won't work on many other platforms as well, so for now this test |
495 // is for Windows and Linux only. As of Sept 17th, 2013 this test is disabled | 520 // is for Windows and Linux only. As of Sept 17th, 2013 this test is disabled |
496 // on Windows due to flakines, see http://crbug.com/293445. | 521 // on Windows due to flakines, see http://crbug.com/293445. |
497 | 522 |
498 // Disabled on Linux Aura because pointer lock does not work on Linux Aura. | 523 // Disabled on Linux Aura because pointer lock does not work on Linux Aura. |
499 // crbug.com/341876 | 524 // crbug.com/341876 |
500 | 525 |
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1054 | 1079 |
1055 // Now verify that the selection text propagates properly to RWHV. | 1080 // Now verify that the selection text propagates properly to RWHV. |
1056 content::RenderWidgetHostView* guest_rwhv = | 1081 content::RenderWidgetHostView* guest_rwhv = |
1057 guest_web_contents()->GetRenderWidgetHostView(); | 1082 guest_web_contents()->GetRenderWidgetHostView(); |
1058 ASSERT_TRUE(guest_rwhv); | 1083 ASSERT_TRUE(guest_rwhv); |
1059 std::string selected_text = base::UTF16ToUTF8(guest_rwhv->GetSelectedText()); | 1084 std::string selected_text = base::UTF16ToUTF8(guest_rwhv->GetSelectedText()); |
1060 ASSERT_TRUE(selected_text.size() >= 10u); | 1085 ASSERT_TRUE(selected_text.size() >= 10u); |
1061 ASSERT_EQ("AAAAAAAAAA", selected_text.substr(0, 10)); | 1086 ASSERT_EQ("AAAAAAAAAA", selected_text.substr(0, 10)); |
1062 } | 1087 } |
1063 #endif | 1088 #endif |
OLD | NEW |