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

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

Issue 334923002: Remove ContentBrowserClient::GuestWebContentsAttached (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove_adview
Patch Set: Added missing file Created 6 years, 6 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 "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_view.h" 25 #include "content/public/browser/render_widget_host_view.h"
24 #include "content/public/browser/web_contents.h" 26 #include "content/public/browser/web_contents.h"
25 #include "content/public/common/content_switches.h" 27 #include "content/public/common/content_switches.h"
26 #include "content/public/test/browser_test_utils.h" 28 #include "content/public/test/browser_test_utils.h"
27 #include "net/test/embedded_test_server/embedded_test_server.h" 29 #include "net/test/embedded_test_server/embedded_test_server.h"
28 #include "ui/base/ime/composition_text.h" 30 #include "ui/base/ime/composition_text.h"
29 #include "ui/base/ime/text_input_client.h" 31 #include "ui/base/ime/text_input_client.h"
30 #include "ui/base/test/ui_controls.h" 32 #include "ui/base/test/ui_controls.h"
31 #include "ui/events/keycodes/keyboard_codes.h" 33 #include "ui/events/keycodes/keyboard_codes.h"
32 34
33 using apps::AppWindow; 35 using apps::AppWindow;
34 36
37 class TestGuestViewManager : public GuestViewManager {
38 public:
39 explicit TestGuestViewManager(content::BrowserContext* context) :
40 GuestViewManager(context),
41 web_contents_(NULL) {}
42
43 content::WebContents* WaitForGuestCreated() {
44 if (web_contents_)
45 return web_contents_;
46
47 message_loop_runner_ = new content::MessageLoopRunner;
48 message_loop_runner_->Run();
49 return web_contents_;
50 }
51
52 private:
53 // GuestViewManager override:
54 virtual void AddGuest(int guest_instance_id,
55 content::WebContents* guest_web_contents) OVERRIDE{
56 GuestViewManager::AddGuest(guest_instance_id, guest_web_contents);
57 web_contents_ = guest_web_contents;
58
59 if (message_loop_runner_)
60 message_loop_runner_->Quit();
61 }
62
63 content::WebContents* web_contents_;
64 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
65 };
66
67 // Test factory for creating test instances of GuestViewManager.
68 class TestGuestViewManagerFactory : public GuestViewManagerFactory {
69 public:
70 TestGuestViewManagerFactory() :
71 test_guest_view_manager_(NULL) {}
72
73 virtual ~TestGuestViewManagerFactory() {}
74
75 virtual GuestViewManager* CreateGuestViewManager(
76 content::BrowserContext* context) OVERRIDE {
77 return GetManager(context);
78 }
79
80 TestGuestViewManager* GetManager(content::BrowserContext* context) {
81 if (!test_guest_view_manager_) {
82 test_guest_view_manager_ = new TestGuestViewManager(context);
83 }
84 return test_guest_view_manager_;
85 }
86
87 private:
88 TestGuestViewManager* test_guest_view_manager_;
89
90 DISALLOW_COPY_AND_ASSIGN(TestGuestViewManagerFactory);
91 };
lazyboy 2014/06/13 17:40:01 nit: add \n
Fady Samuel 2014/06/16 14:35:40 Done.
35 class WebViewInteractiveTest 92 class WebViewInteractiveTest
36 : public extensions::PlatformAppBrowserTest { 93 : public extensions::PlatformAppBrowserTest {
37 public: 94 public:
38 WebViewInteractiveTest() 95 WebViewInteractiveTest()
39 : corner_(gfx::Point()), 96 : corner_(gfx::Point()),
40 mouse_click_result_(false), 97 mouse_click_result_(false),
41 first_click_(true) {} 98 first_click_(true) {
99 GuestViewManager::set_factory_for_testing(&factory_);
100 }
101
102 TestGuestViewManager* GetGuestViewManager() {
103 return factory_.GetManager(browser()->profile());
104 }
42 105
43 void MoveMouseInsideWindowWithListener(gfx::Point point, 106 void MoveMouseInsideWindowWithListener(gfx::Point point,
44 const std::string& message) { 107 const std::string& message) {
45 ExtensionTestMessageListener move_listener(message, false); 108 ExtensionTestMessageListener move_listener(message, false);
46 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync( 109 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(
47 gfx::Point(corner_.x() + point.x(), corner_.y() + point.y()))); 110 gfx::Point(corner_.x() + point.x(), corner_.y() + point.y())));
48 ASSERT_TRUE(move_listener.WaitUntilSatisfied()); 111 ASSERT_TRUE(move_listener.WaitUntilSatisfied());
49 } 112 }
50 113
51 void SendMouseClickWithListener(ui_controls::MouseButton button, 114 void SendMouseClickWithListener(ui_controls::MouseButton button,
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 std::string last_drop_data; 468 std::string last_drop_data;
406 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 469 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
407 embedder_web_contents_, 470 embedder_web_contents_,
408 "window.domAutomationController.send(getLastDropData())", 471 "window.domAutomationController.send(getLastDropData())",
409 &last_drop_data)); 472 &last_drop_data));
410 473
411 last_drop_data_ = last_drop_data; 474 last_drop_data_ = last_drop_data;
412 } 475 }
413 476
414 protected: 477 protected:
478 TestGuestViewManagerFactory factory_;
415 content::WebContents* guest_web_contents_; 479 content::WebContents* guest_web_contents_;
416 content::WebContents* embedder_web_contents_; 480 content::WebContents* embedder_web_contents_;
417 gfx::Point corner_; 481 gfx::Point corner_;
418 bool mouse_click_result_; 482 bool mouse_click_result_;
419 bool first_click_; 483 bool first_click_;
420 // Only used in drag/drop test. 484 // Only used in drag/drop test.
421 base::Closure quit_closure_; 485 base::Closure quit_closure_;
422 std::string last_drop_data_; 486 std::string last_drop_data_;
423 }; 487 };
424 488
425 // Used to get notified when a guest is created.
426 class GuestContentBrowserClient : public chrome::ChromeContentBrowserClient {
427 public:
428 GuestContentBrowserClient() : web_contents_(NULL) {}
429
430 content::WebContents* WaitForGuestCreated() {
431 if (web_contents_)
432 return web_contents_;
433
434 message_loop_runner_ = new content::MessageLoopRunner;
435 message_loop_runner_->Run();
436 return web_contents_;
437 }
438
439 private:
440 // ChromeContentBrowserClient implementation:
441 virtual void GuestWebContentsAttached(
442 content::WebContents* guest_web_contents,
443 content::WebContents* embedder_web_contents,
444 const base::DictionaryValue& extra_params) OVERRIDE {
445 ChromeContentBrowserClient::GuestWebContentsAttached(
446 guest_web_contents, embedder_web_contents, extra_params);
447 web_contents_ = guest_web_contents;
448
449 if (message_loop_runner_)
450 message_loop_runner_->Quit();
451 }
452
453 content::WebContents* web_contents_;
454 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
455 };
456
457 // ui_test_utils::SendMouseMoveSync doesn't seem to work on OS_MACOSX, and 489 // ui_test_utils::SendMouseMoveSync doesn't seem to work on OS_MACOSX, and
458 // likely won't work on many other platforms as well, so for now this test 490 // likely won't work on many other platforms as well, so for now this test
459 // is for Windows and Linux only. As of Sept 17th, 2013 this test is disabled 491 // is for Windows and Linux only. As of Sept 17th, 2013 this test is disabled
460 // on Windows due to flakines, see http://crbug.com/293445. 492 // on Windows due to flakines, see http://crbug.com/293445.
461 493
462 // Disabled on Linux Aura because pointer lock does not work on Linux Aura. 494 // Disabled on Linux Aura because pointer lock does not work on Linux Aura.
463 // crbug.com/341876 495 // crbug.com/341876
464 496
465 #if defined(OS_LINUX) && !defined(USE_AURA) 497 #if defined(OS_LINUX) && !defined(USE_AURA)
466 498
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 906
875 // This test exercies the following scenario: 907 // This test exercies the following scenario:
876 // 1. An <input> in guest has focus. 908 // 1. An <input> in guest has focus.
877 // 2. User takes focus to embedder by clicking e.g. an <input> in embedder. 909 // 2. User takes focus to embedder by clicking e.g. an <input> in embedder.
878 // 3. User brings back the focus directly to the <input> in #1. 910 // 3. User brings back the focus directly to the <input> in #1.
879 // 911 //
880 // Now we need to make sure TextInputTypeChanged fires properly for the guest's 912 // Now we need to make sure TextInputTypeChanged fires properly for the guest's
881 // view upon step #3. We simply read the input type's state after #3 to 913 // view upon step #3. We simply read the input type's state after #3 to
882 // make sure it's not TEXT_INPUT_TYPE_NONE. 914 // make sure it's not TEXT_INPUT_TYPE_NONE.
883 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, Focus_FocusRestored) { 915 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, Focus_FocusRestored) {
884 GuestContentBrowserClient new_client;
885 content::ContentBrowserClient* old_client =
886 SetBrowserClientForTesting(&new_client);
887
888 content::WebContents* embedder_web_contents = NULL; 916 content::WebContents* embedder_web_contents = NULL;
889 scoped_ptr<ExtensionTestMessageListener> done_listener( 917 scoped_ptr<ExtensionTestMessageListener> done_listener(
890 RunAppHelper("testFocusRestored", "web_view/focus", NO_TEST_SERVER, 918 RunAppHelper("testFocusRestored", "web_view/focus", NO_TEST_SERVER,
891 &embedder_web_contents)); 919 &embedder_web_contents));
892 ASSERT_TRUE(done_listener->WaitUntilSatisfied()); 920 ASSERT_TRUE(done_listener->WaitUntilSatisfied());
893 content::WebContents* guest_web_contents = new_client.WaitForGuestCreated(); 921 content::WebContents* guest_web_contents =
894 // Reset the browser client so that we do not notice any unexpected behavior. 922 GetGuestViewManager()->WaitForGuestCreated();
895 SetBrowserClientForTesting(old_client);
896 ASSERT_TRUE(guest_web_contents); 923 ASSERT_TRUE(guest_web_contents);
897 924
898 // 1) We click on the guest so that we get a focus event. 925 // 1) We click on the guest so that we get a focus event.
899 ExtensionTestMessageListener next_step_listener("TEST_STEP_PASSED", false); 926 ExtensionTestMessageListener next_step_listener("TEST_STEP_PASSED", false);
900 next_step_listener.set_failure_message("TEST_STEP_FAILED"); 927 next_step_listener.set_failure_message("TEST_STEP_FAILED");
901 { 928 {
902 content::SimulateMouseClickAt(guest_web_contents, 929 content::SimulateMouseClickAt(guest_web_contents,
903 0, 930 0,
904 blink::WebMouseEvent::ButtonLeft, 931 blink::WebMouseEvent::ButtonLeft,
905 gfx::Point(10, 10)); 932 gfx::Point(10, 10));
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1049 1076
1050 // Now verify that the selection text propagates properly to RWHV. 1077 // Now verify that the selection text propagates properly to RWHV.
1051 content::RenderWidgetHostView* guest_rwhv = 1078 content::RenderWidgetHostView* guest_rwhv =
1052 guest_web_contents()->GetRenderWidgetHostView(); 1079 guest_web_contents()->GetRenderWidgetHostView();
1053 ASSERT_TRUE(guest_rwhv); 1080 ASSERT_TRUE(guest_rwhv);
1054 std::string selected_text = base::UTF16ToUTF8(guest_rwhv->GetSelectedText()); 1081 std::string selected_text = base::UTF16ToUTF8(guest_rwhv->GetSelectedText());
1055 ASSERT_TRUE(selected_text.size() >= 10u); 1082 ASSERT_TRUE(selected_text.size() >= 10u);
1056 ASSERT_EQ("AAAAAAAAAA", selected_text.substr(0, 10)); 1083 ASSERT_EQ("AAAAAAAAAA", selected_text.substr(0, 10));
1057 } 1084 }
1058 #endif 1085 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698