Make castv2 performance test work.
[chromium-blink-merge.git] / chrome / browser / apps / guest_view / web_view_interactive_browsertest.cc
blob89a60997976470f8c1fc120b2984a3ea84c76637
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
3 // found in the LICENSE file.
5 #include "base/strings/stringprintf.h"
6 #include "base/strings/utf_string_conversions.h"
7 #include "chrome/app/chrome_command_ids.h"
8 #include "chrome/browser/apps/app_browsertest_util.h"
9 #include "chrome/browser/chrome_content_browser_client.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/renderer_context_menu/render_view_context_menu_browsertest_util.h"
12 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_util.h"
13 #include "chrome/test/base/interactive_test_utils.h"
14 #include "chrome/test/base/test_launcher_utils.h"
15 #include "chrome/test/base/ui_test_utils.h"
16 #include "content/public/browser/notification_service.h"
17 #include "content/public/browser/render_process_host.h"
18 #include "content/public/browser/render_view_host.h"
19 #include "content/public/browser/render_widget_host_iterator.h"
20 #include "content/public/browser/render_widget_host_view.h"
21 #include "content/public/browser/web_contents.h"
22 #include "content/public/common/content_switches.h"
23 #include "content/public/test/browser_test_utils.h"
24 #include "extensions/browser/app_window/app_window.h"
25 #include "extensions/browser/app_window/app_window_registry.h"
26 #include "extensions/browser/guest_view/guest_view_base.h"
27 #include "extensions/browser/guest_view/guest_view_manager.h"
28 #include "extensions/browser/guest_view/guest_view_manager_factory.h"
29 #include "extensions/test/extension_test_message_listener.h"
30 #include "net/test/embedded_test_server/embedded_test_server.h"
31 #include "ui/base/ime/composition_text.h"
32 #include "ui/base/ime/text_input_client.h"
33 #include "ui/base/test/ui_controls.h"
34 #include "ui/events/keycodes/keyboard_codes.h"
36 using extensions::AppWindow;
38 class TestGuestViewManager : public extensions::GuestViewManager {
39 public:
40 explicit TestGuestViewManager(content::BrowserContext* context)
41 : GuestViewManager(context),
42 guest_add_count_(0),
43 guest_remove_count_(0),
44 web_contents_(NULL) {}
46 content::WebContents* WaitForGuestAdded() {
47 if (web_contents_)
48 return web_contents_;
50 add_message_loop_runner_ = new content::MessageLoopRunner;
51 add_message_loop_runner_->Run();
52 return web_contents_;
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;
61 remove_message_loop_runner_ = new content::MessageLoopRunner;
62 remove_message_loop_runner_->Run();
65 size_t guest_add_count() { return guest_add_count_; }
67 private:
68 // GuestViewManager override:
69 void AddGuest(int guest_instance_id,
70 content::WebContents* guest_web_contents) override {
71 GuestViewManager::AddGuest(guest_instance_id, guest_web_contents);
72 web_contents_ = guest_web_contents;
73 ++guest_add_count_;
75 if (add_message_loop_runner_.get())
76 add_message_loop_runner_->Quit();
79 void RemoveGuest(int guest_instance_id) override {
80 GuestViewManager::RemoveGuest(guest_instance_id);
81 ++guest_remove_count_;
83 if (remove_message_loop_runner_.get())
84 remove_message_loop_runner_->Quit();
87 size_t guest_add_count_;
88 size_t guest_remove_count_;
89 content::WebContents* web_contents_;
90 scoped_refptr<content::MessageLoopRunner> add_message_loop_runner_;
91 scoped_refptr<content::MessageLoopRunner> remove_message_loop_runner_;
94 // Test factory for creating test instances of GuestViewManager.
95 class TestGuestViewManagerFactory : public extensions::GuestViewManagerFactory {
96 public:
97 TestGuestViewManagerFactory() :
98 test_guest_view_manager_(NULL) {}
100 ~TestGuestViewManagerFactory() override {}
102 extensions::GuestViewManager* CreateGuestViewManager(
103 content::BrowserContext* context) override {
104 return GetManager(context);
107 TestGuestViewManager* GetManager(content::BrowserContext* context) {
108 if (!test_guest_view_manager_) {
109 test_guest_view_manager_ = new TestGuestViewManager(context);
111 return test_guest_view_manager_;
114 private:
115 TestGuestViewManager* test_guest_view_manager_;
117 DISALLOW_COPY_AND_ASSIGN(TestGuestViewManagerFactory);
120 class WebViewInteractiveTest
121 : public extensions::PlatformAppBrowserTest {
122 public:
123 WebViewInteractiveTest()
124 : guest_web_contents_(NULL),
125 embedder_web_contents_(NULL),
126 corner_(gfx::Point()),
127 mouse_click_result_(false),
128 first_click_(true) {
129 extensions::GuestViewManager::set_factory_for_testing(&factory_);
132 TestGuestViewManager* GetGuestViewManager() {
133 return factory_.GetManager(browser()->profile());
136 void MoveMouseInsideWindowWithListener(gfx::Point point,
137 const std::string& message) {
138 ExtensionTestMessageListener move_listener(message, false);
139 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(
140 gfx::Point(corner_.x() + point.x(), corner_.y() + point.y())));
141 ASSERT_TRUE(move_listener.WaitUntilSatisfied());
144 void SendMouseClickWithListener(ui_controls::MouseButton button,
145 const std::string& message) {
146 ExtensionTestMessageListener listener(message, false);
147 SendMouseClick(button);
148 ASSERT_TRUE(listener.WaitUntilSatisfied());
151 void SendMouseClick(ui_controls::MouseButton button) {
152 SendMouseEvent(button, ui_controls::DOWN);
153 SendMouseEvent(button, ui_controls::UP);
156 void MoveMouseInsideWindow(const gfx::Point& point) {
157 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(
158 gfx::Point(corner_.x() + point.x(), corner_.y() + point.y())));
161 gfx::NativeWindow GetPlatformAppWindow() {
162 const extensions::AppWindowRegistry::AppWindowList& app_windows =
163 extensions::AppWindowRegistry::Get(browser()->profile())->app_windows();
164 return (*app_windows.begin())->GetNativeWindow();
167 void SendKeyPressToPlatformApp(ui::KeyboardCode key) {
168 ASSERT_EQ(1U, GetAppWindowCount());
169 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
170 GetPlatformAppWindow(), key, false, false, false, false));
173 void SendCopyKeyPressToPlatformApp() {
174 ASSERT_EQ(1U, GetAppWindowCount());
175 #if defined(OS_MACOSX)
176 // Send Cmd+C on MacOSX.
177 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
178 GetPlatformAppWindow(), ui::VKEY_C, false, false, false, true));
179 #else
180 // Send Ctrl+C on Windows and Linux/ChromeOS.
181 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
182 GetPlatformAppWindow(), ui::VKEY_C, true, false, false, false));
183 #endif
186 void SendStartOfLineKeyPressToPlatformApp() {
187 #if defined(OS_MACOSX)
188 // Send Cmd+Left on MacOSX.
189 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
190 GetPlatformAppWindow(), ui::VKEY_LEFT, false, false, false, true));
191 #else
192 // Send Ctrl+Left on Windows and Linux/ChromeOS.
193 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
194 GetPlatformAppWindow(), ui::VKEY_LEFT, true, false, false, false));
195 #endif
198 void SendBackShortcutToPlatformApp() {
199 #if defined(OS_MACOSX)
200 // Send Cmd+[ on MacOSX.
201 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
202 GetPlatformAppWindow(), ui::VKEY_OEM_4, false, false, false, true));
203 #else
204 // Send browser back key on Linux/Windows.
205 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
206 GetPlatformAppWindow(), ui::VKEY_BROWSER_BACK,
207 false, false, false, false));
208 #endif
211 void SendForwardShortcutToPlatformApp() {
212 #if defined(OS_MACOSX)
213 // Send Cmd+] on MacOSX.
214 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
215 GetPlatformAppWindow(), ui::VKEY_OEM_6, false, false, false, true));
216 #else
217 // Send browser back key on Linux/Windows.
218 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
219 GetPlatformAppWindow(), ui::VKEY_BROWSER_FORWARD,
220 false, false, false, false));
221 #endif
224 void SendMouseEvent(ui_controls::MouseButton button,
225 ui_controls::MouseButtonState state) {
226 if (first_click_) {
227 mouse_click_result_ = ui_test_utils::SendMouseEventsSync(button,
228 state);
229 first_click_ = false;
230 } else {
231 ASSERT_EQ(mouse_click_result_, ui_test_utils::SendMouseEventsSync(
232 button, state));
236 enum TestServer {
237 NEEDS_TEST_SERVER,
238 NO_TEST_SERVER
241 scoped_ptr<ExtensionTestMessageListener> RunAppHelper(
242 const std::string& test_name,
243 const std::string& app_location,
244 TestServer test_server,
245 content::WebContents** embedder_web_contents) {
246 // For serving guest pages.
247 if ((test_server == NEEDS_TEST_SERVER) && !StartEmbeddedTestServer()) {
248 LOG(ERROR) << "FAILED TO START TEST SERVER.";
249 return scoped_ptr<ExtensionTestMessageListener>();
252 LoadAndLaunchPlatformApp(app_location.c_str(), "Launched");
253 if (!ui_test_utils::ShowAndFocusNativeWindow(GetPlatformAppWindow())) {
254 LOG(ERROR) << "UNABLE TO FOCUS TEST WINDOW.";
255 return scoped_ptr<ExtensionTestMessageListener>();
258 // Flush any pending events to make sure we start with a clean slate.
259 content::RunAllPendingInMessageLoop();
261 *embedder_web_contents = GetFirstAppWindowWebContents();
263 scoped_ptr<ExtensionTestMessageListener> done_listener(
264 new ExtensionTestMessageListener("TEST_PASSED", false));
265 done_listener->set_failure_message("TEST_FAILED");
266 if (!content::ExecuteScript(
267 *embedder_web_contents,
268 base::StringPrintf("runTest('%s')", test_name.c_str()))) {
269 LOG(ERROR) << "UNABLE TO START TEST";
270 return scoped_ptr<ExtensionTestMessageListener>();
273 return done_listener.Pass();
276 void TestHelper(const std::string& test_name,
277 const std::string& app_location,
278 TestServer test_server) {
279 content::WebContents* embedder_web_contents = NULL;
280 scoped_ptr<ExtensionTestMessageListener> done_listener(
281 RunAppHelper(
282 test_name, app_location, test_server, &embedder_web_contents));
284 ASSERT_TRUE(done_listener);
285 ASSERT_TRUE(done_listener->WaitUntilSatisfied());
287 guest_web_contents_ = GetGuestViewManager()->WaitForGuestAdded();
290 void RunTest(const std::string& app_name) {
292 void SetupTest(const std::string& app_name,
293 const std::string& guest_url_spec) {
294 ASSERT_TRUE(StartEmbeddedTestServer());
295 GURL::Replacements replace_host;
296 replace_host.SetHostStr("localhost");
298 GURL guest_url = embedded_test_server()->GetURL(guest_url_spec);
299 guest_url = guest_url.ReplaceComponents(replace_host);
301 ui_test_utils::UrlLoadObserver guest_observer(
302 guest_url, content::NotificationService::AllSources());
304 LoadAndLaunchPlatformApp(app_name.c_str(), "connected");
306 guest_observer.Wait();
307 content::Source<content::NavigationController> source =
308 guest_observer.source();
309 EXPECT_TRUE(source->GetWebContents()->GetRenderProcessHost()->
310 IsIsolatedGuest());
312 guest_web_contents_ = source->GetWebContents();
313 embedder_web_contents_ =
314 extensions::GuestViewBase::FromWebContents(guest_web_contents_)->
315 embedder_web_contents();
317 gfx::Rect offset = embedder_web_contents_->GetContainerBounds();
318 corner_ = gfx::Point(offset.x(), offset.y());
320 const testing::TestInfo* const test_info =
321 testing::UnitTest::GetInstance()->current_test_info();
322 const char* prefix = "DragDropWithinWebView";
323 if (!strncmp(test_info->name(), prefix, strlen(prefix))) {
324 // In the drag drop test we add 20px padding to the page body because on
325 // windows if we get too close to the edge of the window the resize cursor
326 // appears and we start dragging the window edge.
327 corner_.Offset(20, 20);
331 content::WebContents* guest_web_contents() {
332 return guest_web_contents_;
335 content::WebContents* embedder_web_contents() {
336 return embedder_web_contents_;
339 gfx::Point corner() {
340 return corner_;
343 void SimulateRWHMouseClick(content::RenderWidgetHost* rwh,
344 blink::WebMouseEvent::Button button,
345 int x,
346 int y) {
347 blink::WebMouseEvent mouse_event;
348 mouse_event.button = button;
349 mouse_event.x = mouse_event.windowX = x;
350 mouse_event.y = mouse_event.windowY = y;
351 mouse_event.modifiers = 0;
353 mouse_event.type = blink::WebInputEvent::MouseDown;
354 rwh->ForwardMouseEvent(mouse_event);
355 mouse_event.type = blink::WebInputEvent::MouseUp;
356 rwh->ForwardMouseEvent(mouse_event);
359 class PopupCreatedObserver {
360 public:
361 PopupCreatedObserver()
362 : initial_widget_count_(0),
363 last_render_widget_host_(NULL),
364 seen_new_widget_(false) {}
366 ~PopupCreatedObserver() {}
368 void Wait() {
369 size_t current_widget_count = CountWidgets();
370 if (!seen_new_widget_ &&
371 current_widget_count == initial_widget_count_ + 1) {
372 seen_new_widget_ = true;
375 // If we haven't seen any new widget or we get 0 size widget, we need to
376 // schedule waiting.
377 bool needs_to_schedule_wait = true;
379 if (seen_new_widget_) {
380 gfx::Rect popup_bounds =
381 last_render_widget_host_->GetView()->GetViewBounds();
382 if (!popup_bounds.size().IsEmpty())
383 needs_to_schedule_wait = false;
386 if (needs_to_schedule_wait) {
387 ScheduleWait();
388 } else {
389 // We are done.
390 if (message_loop_.get())
391 message_loop_->Quit();
394 if (!message_loop_.get()) {
395 message_loop_ = new content::MessageLoopRunner;
396 message_loop_->Run();
400 void Init() { initial_widget_count_ = CountWidgets(); }
402 // Returns the last widget created.
403 content::RenderWidgetHost* last_render_widget_host() {
404 return last_render_widget_host_;
407 private:
408 void ScheduleWait() {
409 base::MessageLoop::current()->PostDelayedTask(
410 FROM_HERE,
411 base::Bind(&PopupCreatedObserver::Wait, base::Unretained(this)),
412 base::TimeDelta::FromMilliseconds(200));
415 size_t CountWidgets() {
416 scoped_ptr<content::RenderWidgetHostIterator> widgets(
417 content::RenderWidgetHost::GetRenderWidgetHosts());
418 size_t num_widgets = 0;
419 while (content::RenderWidgetHost* widget = widgets->GetNextHost()) {
420 if (widget->IsRenderView())
421 continue;
422 ++num_widgets;
423 last_render_widget_host_ = widget;
425 return num_widgets;
428 size_t initial_widget_count_;
429 content::RenderWidgetHost* last_render_widget_host_;
430 scoped_refptr<content::MessageLoopRunner> message_loop_;
431 bool seen_new_widget_;
433 DISALLOW_COPY_AND_ASSIGN(PopupCreatedObserver);
436 void WaitForTitle(const char* title) {
437 base::string16 expected_title(base::ASCIIToUTF16(title));
438 base::string16 error_title(base::ASCIIToUTF16("FAILED"));
439 content::TitleWatcher title_watcher(guest_web_contents(), expected_title);
440 title_watcher.AlsoWaitForTitle(error_title);
441 ASSERT_EQ(expected_title, title_watcher.WaitAndGetTitle());
444 void PopupTestHelper(const gfx::Point& padding) {
445 PopupCreatedObserver popup_observer;
446 popup_observer.Init();
447 // Press alt+DOWN to open popup.
448 bool alt = true;
449 content::SimulateKeyPress(
450 guest_web_contents(), ui::VKEY_DOWN, false, false, alt, false);
451 popup_observer.Wait();
453 content::RenderWidgetHost* popup_rwh =
454 popup_observer.last_render_widget_host();
455 gfx::Rect popup_bounds = popup_rwh->GetView()->GetViewBounds();
457 content::RenderViewHost* embedder_rvh =
458 GetFirstAppWindowWebContents()->GetRenderViewHost();
459 gfx::Rect embedder_bounds = embedder_rvh->GetView()->GetViewBounds();
460 gfx::Vector2d diff = popup_bounds.origin() - embedder_bounds.origin();
461 LOG(INFO) << "DIFF: x = " << diff.x() << ", y = " << diff.y();
463 const int left_spacing = 40 + padding.x(); // div.style.paddingLeft = 40px.
464 // div.style.paddingTop = 50px + (input box height = 26px).
465 const int top_spacing = 50 + 26 + padding.y();
467 // If the popup is placed within |threshold_px| of the expected position,
468 // then we consider the test as a pass.
469 const int threshold_px = 10;
471 EXPECT_LE(std::abs(diff.x() - left_spacing), threshold_px);
472 EXPECT_LE(std::abs(diff.y() - top_spacing), threshold_px);
474 // Close the popup.
475 content::SimulateKeyPress(
476 guest_web_contents(), ui::VKEY_ESCAPE, false, false, false, false);
479 void DragTestStep1() {
480 // Move mouse to start of text.
481 MoveMouseInsideWindow(gfx::Point(45, 8));
482 MoveMouseInsideWindow(gfx::Point(45, 9));
483 SendMouseEvent(ui_controls::LEFT, ui_controls::DOWN);
485 MoveMouseInsideWindow(gfx::Point(74, 12));
486 MoveMouseInsideWindow(gfx::Point(78, 12));
488 // Now wait a bit before moving mouse to initiate drag/drop.
489 base::MessageLoop::current()->PostDelayedTask(
490 FROM_HERE,
491 base::Bind(&WebViewInteractiveTest::DragTestStep2,
492 base::Unretained(this)),
493 base::TimeDelta::FromMilliseconds(200));
496 void DragTestStep2() {
497 // Drag source over target.
498 MoveMouseInsideWindow(gfx::Point(76, 76));
500 // Create a second mouse over the source to trigger the drag over event.
501 MoveMouseInsideWindow(gfx::Point(76, 77));
503 // Release mouse to drop.
504 SendMouseEvent(ui_controls::LEFT, ui_controls::UP);
505 SendMouseClick(ui_controls::LEFT);
507 quit_closure_.Run();
509 // Note that following ExtensionTestMessageListener and ExecuteScript*
510 // call must be after we quit |quit_closure_|. Otherwise the class
511 // here won't be able to receive messages sent by chrome.test.sendMessage.
512 // This is because of the nature of drag and drop code (esp. the
513 // MessageLoop) in it.
515 // Now check if we got a drop and read the drop data.
516 embedder_web_contents_ = GetFirstAppWindowWebContents();
517 ExtensionTestMessageListener drop_listener("guest-got-drop", false);
518 EXPECT_TRUE(content::ExecuteScript(embedder_web_contents_,
519 "window.checkIfGuestGotDrop()"));
520 EXPECT_TRUE(drop_listener.WaitUntilSatisfied());
522 std::string last_drop_data;
523 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
524 embedder_web_contents_,
525 "window.domAutomationController.send(getLastDropData())",
526 &last_drop_data));
528 last_drop_data_ = last_drop_data;
531 void FullscreenTestHelper(const std::string& test_name,
532 const std::string& test_dir) {
533 TestHelper(test_name, test_dir, NO_TEST_SERVER);
534 content::WebContents* embedder_web_contents =
535 GetFirstAppWindowWebContents();
536 ASSERT_TRUE(embedder_web_contents);
537 ASSERT_TRUE(guest_web_contents());
538 // Click the guest to request fullscreen.
539 ExtensionTestMessageListener passed_listener(
540 "FULLSCREEN_STEP_PASSED", false);
541 passed_listener.set_failure_message("TEST_FAILED");
542 content::SimulateMouseClickAt(guest_web_contents(),
544 blink::WebMouseEvent::ButtonLeft,
545 gfx::Point(20, 20));
546 ASSERT_TRUE(passed_listener.WaitUntilSatisfied());
549 protected:
550 TestGuestViewManagerFactory factory_;
551 content::WebContents* guest_web_contents_;
552 content::WebContents* embedder_web_contents_;
553 gfx::Point corner_;
554 bool mouse_click_result_;
555 bool first_click_;
556 // Only used in drag/drop test.
557 base::Closure quit_closure_;
558 std::string last_drop_data_;
561 // ui_test_utils::SendMouseMoveSync doesn't seem to work on OS_MACOSX, and
562 // likely won't work on many other platforms as well, so for now this test
563 // is for Windows and Linux only. As of Sept 17th, 2013 this test is disabled
564 // on Windows due to flakines, see http://crbug.com/293445.
566 // Disabled on Linux Aura because pointer lock does not work on Linux Aura.
567 // crbug.com/341876
569 #if defined(OS_LINUX)
570 // flaky http://crbug.com/412086
571 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, DISABLED_PointerLock) {
572 SetupTest("web_view/pointer_lock",
573 "/extensions/platform_apps/web_view/pointer_lock/guest.html");
575 // Move the mouse over the Lock Pointer button.
576 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(
577 gfx::Point(corner().x() + 75, corner().y() + 25)));
579 // Click the Lock Pointer button. The first two times the button is clicked
580 // the permission API will deny the request (intentional).
581 ExtensionTestMessageListener exception_listener("request exception", false);
582 SendMouseClickWithListener(ui_controls::LEFT, "lock error");
583 ASSERT_TRUE(exception_listener.WaitUntilSatisfied());
584 SendMouseClickWithListener(ui_controls::LEFT, "lock error");
586 // Click the Lock Pointer button, locking the mouse to lockTarget1.
587 SendMouseClickWithListener(ui_controls::LEFT, "locked");
589 // Attempt to move the mouse off of the lock target, and onto lockTarget2,
590 // (which would trigger a test failure).
591 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(
592 gfx::Point(corner().x() + 74, corner().y() + 74)));
593 MoveMouseInsideWindowWithListener(gfx::Point(75, 75), "mouse-move");
595 #if defined(OS_WIN)
596 // When the mouse is unlocked on win aura, sending a test mouse click clicks
597 // where the mouse moved to while locked. I was unable to figure out why, and
598 // since the issue only occurs with the test mouse events, just fix it with
599 // a simple workaround - moving the mouse back to where it should be.
600 // TODO(mthiesse): Fix Win Aura simulated mouse events while mouse locked.
601 MoveMouseInsideWindowWithListener(gfx::Point(75, 25), "mouse-move");
602 #endif
604 ExtensionTestMessageListener unlocked_listener("unlocked", false);
605 // Send a key press to unlock the mouse.
606 SendKeyPressToPlatformApp(ui::VKEY_ESCAPE);
608 // Wait for page to receive (successful) mouse unlock response.
609 ASSERT_TRUE(unlocked_listener.WaitUntilSatisfied());
611 // After the second lock, guest.js sends a message to main.js to remove the
612 // webview object. main.js then removes the div containing the webview, which
613 // should unlock, and leave the mouse over the mousemove-capture-container
614 // div. We then move the mouse over that div to ensure the mouse was properly
615 // unlocked and that the div receieves the message.
616 ExtensionTestMessageListener move_captured_listener("move-captured", false);
617 move_captured_listener.set_failure_message("timeout");
619 // Mouse should already be over lock button (since we just unlocked), so send
620 // click to re-lock the mouse.
621 SendMouseClickWithListener(ui_controls::LEFT, "deleted");
623 // A mousemove event is triggered on the mousemove-capture-container element
624 // when we delete the webview container (since the mouse moves onto the
625 // element), but just in case, send an explicit mouse movement to be safe.
626 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(
627 gfx::Point(corner().x() + 50, corner().y() + 10)));
629 // Wait for page to receive second (successful) mouselock response.
630 bool success = move_captured_listener.WaitUntilSatisfied();
631 if (!success) {
632 fprintf(stderr, "TIMEOUT - retrying\n");
633 // About 1 in 40 tests fail to detect mouse moves at this point (why?).
634 // Sending a right click seems to fix this (why?).
635 ExtensionTestMessageListener move_listener2("move-captured", false);
636 SendMouseClick(ui_controls::RIGHT);
637 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(
638 gfx::Point(corner().x() + 51, corner().y() + 11)));
639 ASSERT_TRUE(move_listener2.WaitUntilSatisfied());
643 // flaky http://crbug.com/412086
644 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, DISABLED_PointerLockFocus) {
645 SetupTest("web_view/pointer_lock_focus",
646 "/extensions/platform_apps/web_view/pointer_lock_focus/guest.html");
648 // Move the mouse over the Lock Pointer button.
649 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(
650 gfx::Point(corner().x() + 75, corner().y() + 25)));
652 // Click the Lock Pointer button, locking the mouse to lockTarget.
653 // This will also change focus to another element
654 SendMouseClickWithListener(ui_controls::LEFT, "locked");
656 // Try to unlock the mouse now that the focus is outside of the BrowserPlugin
657 ExtensionTestMessageListener unlocked_listener("unlocked", false);
658 // Send a key press to unlock the mouse.
659 SendKeyPressToPlatformApp(ui::VKEY_ESCAPE);
661 // Wait for page to receive (successful) mouse unlock response.
662 ASSERT_TRUE(unlocked_listener.WaitUntilSatisfied());
665 #endif // defined(OS_LINUX)
667 // Tests that if a <webview> is focused before navigation then the guest starts
668 // off focused.
669 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, Focus_FocusBeforeNavigation) {
670 TestHelper("testFocusBeforeNavigation", "web_view/focus", NO_TEST_SERVER);
673 // Tests that setting focus on the <webview> sets focus on the guest.
674 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, Focus_FocusEvent) {
675 TestHelper("testFocusEvent", "web_view/focus", NO_TEST_SERVER);
678 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, Focus_FocusTracksEmbedder) {
679 content::WebContents* embedder_web_contents = NULL;
681 scoped_ptr<ExtensionTestMessageListener> done_listener(
682 RunAppHelper("testFocusTracksEmbedder", "web_view/focus", NO_TEST_SERVER,
683 &embedder_web_contents));
684 done_listener->WaitUntilSatisfied();
686 ExtensionTestMessageListener next_step_listener("TEST_STEP_PASSED", false);
687 next_step_listener.set_failure_message("TEST_STEP_FAILED");
688 EXPECT_TRUE(content::ExecuteScript(
689 embedder_web_contents,
690 "window.runCommand('testFocusTracksEmbedderRunNextStep');"));
692 // Blur the embedder.
693 embedder_web_contents->GetRenderViewHost()->Blur();
694 // Ensure that the guest is also blurred.
695 ASSERT_TRUE(next_step_listener.WaitUntilSatisfied());
698 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, Focus_AdvanceFocus) {
699 content::WebContents* embedder_web_contents = NULL;
702 scoped_ptr<ExtensionTestMessageListener> done_listener(
703 RunAppHelper("testAdvanceFocus", "web_view/focus", NO_TEST_SERVER,
704 &embedder_web_contents));
705 done_listener->WaitUntilSatisfied();
709 ExtensionTestMessageListener listener("button1-focused", false);
710 listener.set_failure_message("TEST_FAILED");
711 SimulateRWHMouseClick(embedder_web_contents->GetRenderViewHost(),
712 blink::WebMouseEvent::ButtonLeft, 200, 20);
713 content::SimulateKeyPress(embedder_web_contents, ui::VKEY_TAB,
714 false, false, false, false);
715 ASSERT_TRUE(listener.WaitUntilSatisfied());
719 // Wait for button1 to be focused again, this means we were asked to
720 // move the focus to the next focusable element.
721 ExtensionTestMessageListener listener("button1-advance-focus", false);
722 listener.set_failure_message("TEST_FAILED");
723 // TODO(fsamuel): A third Tab key press should not be necessary.
724 // The <webview> will take keyboard focus but it will not focus an initial
725 // element. The initial element is dependent upon tab direction which blink
726 // does not propagate to the plugin.
727 // See http://crbug.com/147644.
728 content::SimulateKeyPress(embedder_web_contents, ui::VKEY_TAB,
729 false, false, false, false);
730 content::SimulateKeyPress(embedder_web_contents, ui::VKEY_TAB,
731 false, false, false, false);
732 content::SimulateKeyPress(embedder_web_contents, ui::VKEY_TAB,
733 false, false, false, false);
734 ASSERT_TRUE(listener.WaitUntilSatisfied());
738 // Tests that blurring <webview> also blurs the guest.
739 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, Focus_BlurEvent) {
740 TestHelper("testBlurEvent", "web_view/focus", NO_TEST_SERVER);
743 // Tests that guests receive edit commands and respond appropriately.
744 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, EditCommands) {
745 LoadAndLaunchPlatformApp("web_view/edit_commands", "connected");
747 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(
748 GetPlatformAppWindow()));
750 // Flush any pending events to make sure we start with a clean slate.
751 content::RunAllPendingInMessageLoop();
753 ExtensionTestMessageListener copy_listener("copy", false);
754 SendCopyKeyPressToPlatformApp();
756 // Wait for the guest to receive a 'copy' edit command.
757 ASSERT_TRUE(copy_listener.WaitUntilSatisfied());
760 // Tests that guests receive edit commands and respond appropriately.
761 // http://crbug.com/417892
762 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, DISABLED_EditCommandsNoMenu) {
763 SetupTest("web_view/edit_commands_no_menu",
764 "/extensions/platform_apps/web_view/edit_commands_no_menu/"
765 "guest.html");
767 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(
768 GetPlatformAppWindow()));
770 // Flush any pending events to make sure we start with a clean slate.
771 content::RunAllPendingInMessageLoop();
773 ExtensionTestMessageListener start_of_line_listener("StartOfLine", false);
774 SendStartOfLineKeyPressToPlatformApp();
775 // Wait for the guest to receive a 'copy' edit command.
776 ASSERT_TRUE(start_of_line_listener.WaitUntilSatisfied());
779 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest,
780 NewWindow_AttachAfterOpenerDestroyed) {
781 TestHelper("testNewWindowAttachAfterOpenerDestroyed",
782 "web_view/newwindow",
783 NEEDS_TEST_SERVER);
786 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest,
787 NewWindow_NewWindowNameTakesPrecedence) {
788 TestHelper("testNewWindowNameTakesPrecedence",
789 "web_view/newwindow",
790 NEEDS_TEST_SERVER);
793 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest,
794 NewWindow_WebViewNameTakesPrecedence) {
795 TestHelper("testNewWindowWebViewNameTakesPrecedence",
796 "web_view/newwindow",
797 NEEDS_TEST_SERVER);
800 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, NewWindow_NoName) {
801 TestHelper("testNewWindowNoName",
802 "web_view/newwindow",
803 NEEDS_TEST_SERVER);
806 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, NewWindow_Redirect) {
807 TestHelper("testNewWindowRedirect",
808 "web_view/newwindow",
809 NEEDS_TEST_SERVER);
812 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, NewWindow_Close) {
813 TestHelper("testNewWindowClose",
814 "web_view/newwindow",
815 NEEDS_TEST_SERVER);
818 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, NewWindow_DeferredAttachment) {
819 TestHelper("testNewWindowDeferredAttachment",
820 "web_view/newwindow",
821 NEEDS_TEST_SERVER);
824 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, NewWindow_ExecuteScript) {
825 TestHelper("testNewWindowExecuteScript",
826 "web_view/newwindow",
827 NEEDS_TEST_SERVER);
830 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest,
831 NewWindow_DeclarativeWebRequest) {
832 TestHelper("testNewWindowDeclarativeWebRequest",
833 "web_view/newwindow",
834 NEEDS_TEST_SERVER);
837 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest,
838 NewWindow_DiscardAfterOpenerDestroyed) {
839 TestHelper("testNewWindowDiscardAfterOpenerDestroyed",
840 "web_view/newwindow",
841 NEEDS_TEST_SERVER);
844 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, NewWindow_WebRequest) {
845 TestHelper("testNewWindowWebRequest",
846 "web_view/newwindow",
847 NEEDS_TEST_SERVER);
850 // A custom elements bug needs to be addressed to enable this test:
851 // See http://crbug.com/282477 for more information.
852 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest,
853 DISABLED_NewWindow_WebRequestCloseWindow) {
854 TestHelper("testNewWindowWebRequestCloseWindow",
855 "web_view/newwindow",
856 NEEDS_TEST_SERVER);
859 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest,
860 NewWindow_WebRequestRemoveElement) {
861 TestHelper("testNewWindowWebRequestRemoveElement",
862 "web_view/newwindow",
863 NEEDS_TEST_SERVER);
866 // There is a problem of missing keyup events with the command key after
867 // the NSEvent is sent to NSApplication in ui/base/test/ui_controls_mac.mm .
868 // This test is disabled on only the Mac until the problem is resolved.
869 // See http://crbug.com/425859 for more information.
870 #if !defined(OS_MACOSX)
871 // Tests that Ctrl+Click/Cmd+Click on a link fires up the newwindow API.
872 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, NewWindow_OpenInNewTab) {
873 content::WebContents* embedder_web_contents = NULL;
875 ExtensionTestMessageListener loaded_listener("Loaded", false);
876 scoped_ptr<ExtensionTestMessageListener> done_listener(
877 RunAppHelper("testNewWindowOpenInNewTab",
878 "web_view/newwindow",
879 NEEDS_TEST_SERVER,
880 &embedder_web_contents));
882 loaded_listener.WaitUntilSatisfied();
883 #if defined(OS_MACOSX)
884 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
885 GetPlatformAppWindow(), ui::VKEY_RETURN,
886 false, false, false, true /* cmd */));
887 #else
888 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
889 GetPlatformAppWindow(), ui::VKEY_RETURN,
890 true /* ctrl */, false, false, false));
891 #endif
893 // Wait for the embedder to receive a 'newwindow' event.
894 ASSERT_TRUE(done_listener->WaitUntilSatisfied());
896 #endif
898 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest,
899 NewWindow_OpenerDestroyedWhileUnattached) {
900 TestHelper("testNewWindowOpenerDestroyedWhileUnattached",
901 "web_view/newwindow",
902 NEEDS_TEST_SERVER);
903 ASSERT_EQ(2u, GetGuestViewManager()->guest_add_count());
905 // We have two guests in this test, one is the intial one, the other
906 // is the newwindow one.
907 // Before the embedder goes away, both the guests should go away.
908 // This ensures that unattached guests are gone if opener is gone.
909 GetGuestViewManager()->WaitForGuestRemoved(2u);
912 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, ExecuteCode) {
913 ASSERT_TRUE(RunPlatformAppTestWithArg(
914 "platform_apps/web_view/common", "execute_code")) << message_;
917 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, PopupPositioningBasic) {
918 TestHelper("testBasic", "web_view/popup_positioning", NO_TEST_SERVER);
919 ASSERT_TRUE(guest_web_contents());
920 PopupTestHelper(gfx::Point());
922 // TODO(lazyboy): Move the embedder window to a random location and
923 // make sure we keep rendering popups correct in webview.
926 // Tests that moving browser plugin (without resize/UpdateRects) correctly
927 // repositions popup.
928 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, PopupPositioningMoved) {
929 TestHelper("testMoved", "web_view/popup_positioning", NO_TEST_SERVER);
930 ASSERT_TRUE(guest_web_contents());
931 PopupTestHelper(gfx::Point(20, 0));
934 // Drag and drop inside a webview is currently only enabled for linux and mac,
935 // but the tests don't work on anything except chromeos for now. This is because
936 // of simulating mouse drag code's dependency on platforms.
937 #if defined(OS_CHROMEOS) && !defined(USE_OZONE)
938 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, DragDropWithinWebView) {
939 LoadAndLaunchPlatformApp("web_view/dnd_within_webview", "connected");
940 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(GetPlatformAppWindow()));
942 embedder_web_contents_ = GetFirstAppWindowWebContents();
943 gfx::Rect offset = embedder_web_contents_->GetContainerBounds();
944 corner_ = gfx::Point(offset.x(), offset.y());
946 // In the drag drop test we add 20px padding to the page body because on
947 // windows if we get too close to the edge of the window the resize cursor
948 // appears and we start dragging the window edge.
949 corner_.Offset(20, 20);
951 // Flush any pending events to make sure we start with a clean slate.
952 content::RunAllPendingInMessageLoop();
953 for (;;) {
954 base::RunLoop run_loop;
955 quit_closure_ = run_loop.QuitClosure();
956 base::MessageLoop::current()->PostTask(
957 FROM_HERE,
958 base::Bind(&WebViewInteractiveTest::DragTestStep1,
959 base::Unretained(this)));
960 run_loop.Run();
962 if (last_drop_data_ == "Drop me")
963 break;
965 LOG(INFO) << "Drag was cancelled in interactive_test, restarting drag";
967 // Reset state for next try.
968 ExtensionTestMessageListener reset_listener("resetStateReply", false);
969 EXPECT_TRUE(content::ExecuteScript(embedder_web_contents_,
970 "window.resetState()"));
971 ASSERT_TRUE(reset_listener.WaitUntilSatisfied());
973 ASSERT_EQ("Drop me", last_drop_data_);
975 #endif // (defined(OS_CHROMEOS))
977 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, Navigation) {
978 TestHelper("testNavigation", "web_view/navigation", NO_TEST_SERVER);
981 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, Navigation_BackForwardKeys) {
982 LoadAndLaunchPlatformApp("web_view/navigation", "Launched");
983 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(
984 GetPlatformAppWindow()));
985 // Flush any pending events to make sure we start with a clean slate.
986 content::RunAllPendingInMessageLoop();
988 content::WebContents* embedder_web_contents = GetFirstAppWindowWebContents();
989 ASSERT_TRUE(embedder_web_contents);
991 ExtensionTestMessageListener done_listener(
992 "TEST_PASSED", false);
993 done_listener.set_failure_message("TEST_FAILED");
994 ExtensionTestMessageListener ready_back_key_listener(
995 "ReadyForBackKey", false);
996 ExtensionTestMessageListener ready_forward_key_listener(
997 "ReadyForForwardKey", false);
999 EXPECT_TRUE(content::ExecuteScript(
1000 embedder_web_contents,
1001 "runTest('testBackForwardKeys')"));
1003 ASSERT_TRUE(ready_back_key_listener.WaitUntilSatisfied());
1004 SendBackShortcutToPlatformApp();
1006 ASSERT_TRUE(ready_forward_key_listener.WaitUntilSatisfied());
1007 SendForwardShortcutToPlatformApp();
1009 ASSERT_TRUE(done_listener.WaitUntilSatisfied());
1012 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest,
1013 PointerLock_PointerLockLostWithFocus) {
1014 TestHelper("testPointerLockLostWithFocus",
1015 "web_view/pointerlock",
1016 NO_TEST_SERVER);
1019 // Disable this on mac, throws an assertion failure on teardown which
1020 // will result in flakiness:
1022 // "not is fullscreen state"
1023 // "*** Assertion failure in -[_NSWindowFullScreenTransition
1024 // transitionedWindowFrame],"
1025 // See similar bug: http://crbug.com/169820.
1027 // In addition to the above, these tests are flaky on many platforms:
1028 // http://crbug.com/468660
1029 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest,
1030 DISABLED_FullscreenAllow_EmbedderHasPermission) {
1031 FullscreenTestHelper("testFullscreenAllow",
1032 "web_view/fullscreen/embedder_has_permission");
1035 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest,
1036 DISABLED_FullscreenDeny_EmbedderHasPermission) {
1037 FullscreenTestHelper("testFullscreenDeny",
1038 "web_view/fullscreen/embedder_has_permission");
1041 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest,
1042 DISABLED_FullscreenAllow_EmbedderHasNoPermission) {
1043 FullscreenTestHelper("testFullscreenAllow",
1044 "web_view/fullscreen/embedder_has_no_permission");
1047 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest,
1048 DISABLED_FullscreenDeny_EmbedderHasNoPermission) {
1049 FullscreenTestHelper("testFullscreenDeny",
1050 "web_view/fullscreen/embedder_has_no_permission");
1053 // This test exercies the following scenario:
1054 // 1. An <input> in guest has focus.
1055 // 2. User takes focus to embedder by clicking e.g. an <input> in embedder.
1056 // 3. User brings back the focus directly to the <input> in #1.
1058 // Now we need to make sure TextInputTypeChanged fires properly for the guest's
1059 // view upon step #3. We simply read the input type's state after #3 to
1060 // make sure it's not TEXT_INPUT_TYPE_NONE.
1061 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, Focus_FocusRestored) {
1062 TestHelper("testFocusRestored", "web_view/focus", NO_TEST_SERVER);
1063 content::WebContents* embedder_web_contents = GetFirstAppWindowWebContents();
1064 ASSERT_TRUE(embedder_web_contents);
1065 ASSERT_TRUE(guest_web_contents());
1067 // 1) We click on the guest so that we get a focus event.
1068 ExtensionTestMessageListener next_step_listener("TEST_STEP_PASSED", false);
1069 next_step_listener.set_failure_message("TEST_STEP_FAILED");
1071 content::SimulateMouseClickAt(guest_web_contents(),
1073 blink::WebMouseEvent::ButtonLeft,
1074 gfx::Point(10, 10));
1075 EXPECT_TRUE(content::ExecuteScript(
1076 embedder_web_contents,
1077 "window.runCommand('testFocusRestoredRunNextStep', 1);"));
1079 // Wait for the next step to complete.
1080 ASSERT_TRUE(next_step_listener.WaitUntilSatisfied());
1082 // 2) We click on the embedder so the guest's focus goes away and it observes
1083 // a blur event.
1084 next_step_listener.Reset();
1086 content::SimulateMouseClickAt(embedder_web_contents,
1088 blink::WebMouseEvent::ButtonLeft,
1089 gfx::Point(200, 20));
1090 EXPECT_TRUE(content::ExecuteScript(
1091 embedder_web_contents,
1092 "window.runCommand('testFocusRestoredRunNextStep', 2);"));
1094 // Wait for the next step to complete.
1095 ASSERT_TRUE(next_step_listener.WaitUntilSatisfied());
1097 // 3) We click on the guest again to bring back focus directly to the previous
1098 // input element, then we ensure text_input_type is properly set.
1099 next_step_listener.Reset();
1101 content::SimulateMouseClickAt(guest_web_contents(),
1103 blink::WebMouseEvent::ButtonLeft,
1104 gfx::Point(10, 10));
1105 EXPECT_TRUE(content::ExecuteScript(
1106 embedder_web_contents,
1107 "window.runCommand('testFocusRestoredRunNextStep', 3)"));
1109 // Wait for the next step to complete.
1110 ASSERT_TRUE(next_step_listener.WaitUntilSatisfied());
1112 // |text_input_client| is not available for mac and android.
1113 #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
1114 ui::TextInputClient* text_input_client =
1115 embedder_web_contents->GetRenderViewHost()->GetView()
1116 ->GetTextInputClient();
1117 ASSERT_TRUE(text_input_client);
1118 ASSERT_TRUE(text_input_client->GetTextInputType() !=
1119 ui::TEXT_INPUT_TYPE_NONE);
1120 #endif
1123 // ui::TextInputClient is NULL for mac and android.
1124 #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
1125 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, DISABLED_Focus_InputMethod) {
1126 content::WebContents* embedder_web_contents = NULL;
1127 scoped_ptr<ExtensionTestMessageListener> done_listener(
1128 RunAppHelper("testInputMethod", "web_view/focus", NO_TEST_SERVER,
1129 &embedder_web_contents));
1130 ASSERT_TRUE(done_listener->WaitUntilSatisfied());
1132 ui::TextInputClient* text_input_client =
1133 embedder_web_contents->GetRenderViewHost()->GetView()
1134 ->GetTextInputClient();
1135 ASSERT_TRUE(text_input_client);
1137 ExtensionTestMessageListener next_step_listener("TEST_STEP_PASSED", false);
1138 next_step_listener.set_failure_message("TEST_STEP_FAILED");
1140 // An input element inside the <webview> gets focus and is given some
1141 // user input via IME.
1143 ui::CompositionText composition;
1144 composition.text = base::UTF8ToUTF16("InputTest123");
1145 text_input_client->SetCompositionText(composition);
1146 EXPECT_TRUE(content::ExecuteScript(
1147 embedder_web_contents,
1148 "window.runCommand('testInputMethodRunNextStep', 1);"));
1150 // Wait for the next step to complete.
1151 ASSERT_TRUE(next_step_listener.WaitUntilSatisfied());
1154 // A composition is committed via IME.
1156 next_step_listener.Reset();
1158 ui::CompositionText composition;
1159 composition.text = base::UTF8ToUTF16("InputTest456");
1160 text_input_client->SetCompositionText(composition);
1161 text_input_client->ConfirmCompositionText();
1162 EXPECT_TRUE(content::ExecuteScript(
1163 embedder_web_contents,
1164 "window.runCommand('testInputMethodRunNextStep', 2);"));
1166 // Wait for the next step to complete.
1167 ASSERT_TRUE(next_step_listener.WaitUntilSatisfied());
1170 // TODO(lazyboy): http://crbug.com/457007, Add a step or a separate test to
1171 // check the following, currently it turns this test to be flaky:
1172 // If we move the focus from the first <input> to the second one after we
1173 // have some composition text set but *not* committed (by calling
1174 // text_input_client->SetCompositionText()), then it would cause IME cancel
1175 // and the onging composition is committed in the first <input> in the
1176 // <webview>, not the second one.
1178 // Tests ExtendSelectionAndDelete message works in <webview>.
1180 next_step_listener.Reset();
1182 // At this point we have set focus on first <input> in the <webview>,
1183 // and the value it contains is 'InputTest456' with caret set after 'T'.
1184 // Now we delete 'Test' in 'InputTest456', as the caret is after 'T':
1185 // delete before 1 character ('T') and after 3 characters ('est').
1186 text_input_client->ExtendSelectionAndDelete(1, 3);
1187 EXPECT_TRUE(content::ExecuteScript(
1188 embedder_web_contents,
1189 "window.runCommand('testInputMethodRunNextStep', 3);"));
1191 // Wait for the next step to complete.
1192 ASSERT_TRUE(next_step_listener.WaitUntilSatisfied());
1195 #endif
1197 #if defined(OS_MACOSX)
1198 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, TextSelection) {
1199 SetupTest("web_view/text_selection",
1200 "/extensions/platform_apps/web_view/text_selection/guest.html");
1201 ASSERT_TRUE(guest_web_contents());
1202 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(
1203 GetPlatformAppWindow()));
1205 // Wait until guest sees a context menu, select an arbitrary item (copy).
1206 ExtensionTestMessageListener ctx_listener("MSG_CONTEXTMENU", false);
1207 ContextMenuNotificationObserver menu_observer(IDC_CONTENT_CONTEXT_COPY);
1208 SimulateRWHMouseClick(guest_web_contents()->GetRenderViewHost(),
1209 blink::WebMouseEvent::ButtonRight, 20, 20);
1210 ASSERT_TRUE(ctx_listener.WaitUntilSatisfied());
1212 // Now verify that the selection text propagates properly to RWHV.
1213 content::RenderWidgetHostView* guest_rwhv =
1214 guest_web_contents()->GetRenderWidgetHostView();
1215 ASSERT_TRUE(guest_rwhv);
1216 std::string selected_text = base::UTF16ToUTF8(guest_rwhv->GetSelectedText());
1217 ASSERT_TRUE(selected_text.size() >= 10u);
1218 ASSERT_EQ("AAAAAAAAAA", selected_text.substr(0, 10));
1220 #endif