Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / apps / guest_view / web_view_interactive_browsertest.cc
blob734fb35696bb1c78349c824d3ebf3409b4f1ed35
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/location.h"
6 #include "base/single_thread_task_runner.h"
7 #include "base/strings/stringprintf.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "base/thread_task_runner_handle.h"
10 #include "chrome/app/chrome_command_ids.h"
11 #include "chrome/browser/apps/app_browsertest_util.h"
12 #include "chrome/browser/chrome_content_browser_client.h"
13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/renderer_context_menu/render_view_context_menu_browsertest_util.h"
15 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_util.h"
16 #include "chrome/test/base/interactive_test_utils.h"
17 #include "chrome/test/base/test_launcher_utils.h"
18 #include "chrome/test/base/ui_test_utils.h"
19 #include "components/guest_view/browser/guest_view_base.h"
20 #include "components/guest_view/browser/guest_view_manager.h"
21 #include "components/guest_view/browser/guest_view_manager_factory.h"
22 #include "components/guest_view/browser/test_guest_view_manager.h"
23 #include "content/public/browser/notification_service.h"
24 #include "content/public/browser/render_process_host.h"
25 #include "content/public/browser/render_view_host.h"
26 #include "content/public/browser/render_widget_host_iterator.h"
27 #include "content/public/browser/render_widget_host_view.h"
28 #include "content/public/browser/web_contents.h"
29 #include "content/public/common/content_switches.h"
30 #include "content/public/test/browser_test_utils.h"
31 #include "extensions/browser/app_window/app_window.h"
32 #include "extensions/browser/app_window/app_window_registry.h"
33 #include "extensions/browser/guest_view/extensions_guest_view_manager_delegate.h"
34 #include "extensions/test/extension_test_message_listener.h"
35 #include "net/test/embedded_test_server/embedded_test_server.h"
36 #include "ui/base/ime/composition_text.h"
37 #include "ui/base/ime/text_input_client.h"
38 #include "ui/base/test/ui_controls.h"
39 #include "ui/events/keycodes/keyboard_codes.h"
41 using extensions::AppWindow;
42 using extensions::ExtensionsGuestViewManagerDelegate;
43 using guest_view::GuestViewBase;
44 using guest_view::GuestViewManager;
45 using guest_view::TestGuestViewManager;
46 using guest_view::TestGuestViewManagerFactory;
48 class WebViewInteractiveTest
49 : public extensions::PlatformAppBrowserTest {
50 public:
51 WebViewInteractiveTest()
52 : guest_web_contents_(NULL),
53 embedder_web_contents_(NULL),
54 corner_(gfx::Point()),
55 mouse_click_result_(false),
56 first_click_(true) {
57 GuestViewManager::set_factory_for_testing(&factory_);
60 TestGuestViewManager* GetGuestViewManager() {
61 TestGuestViewManager* manager = static_cast<TestGuestViewManager*>(
62 TestGuestViewManager::FromBrowserContext(browser()->profile()));
63 // TestGuestViewManager::WaitForSingleGuestCreated may and will get called
64 // before a guest is created.
65 if (!manager) {
66 manager = static_cast<TestGuestViewManager*>(
67 GuestViewManager::CreateWithDelegate(
68 browser()->profile(),
69 scoped_ptr<guest_view::GuestViewManagerDelegate>(
70 new ExtensionsGuestViewManagerDelegate(
71 browser()->profile()))));
73 return manager;
76 void MoveMouseInsideWindowWithListener(gfx::Point point,
77 const std::string& message) {
78 ExtensionTestMessageListener move_listener(message, false);
79 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(
80 gfx::Point(corner_.x() + point.x(), corner_.y() + point.y())));
81 ASSERT_TRUE(move_listener.WaitUntilSatisfied());
84 void SendMouseClickWithListener(ui_controls::MouseButton button,
85 const std::string& message) {
86 ExtensionTestMessageListener listener(message, false);
87 SendMouseClick(button);
88 ASSERT_TRUE(listener.WaitUntilSatisfied());
91 void SendMouseClick(ui_controls::MouseButton button) {
92 SendMouseEvent(button, ui_controls::DOWN);
93 SendMouseEvent(button, ui_controls::UP);
96 void MoveMouseInsideWindow(const gfx::Point& point) {
97 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(
98 gfx::Point(corner_.x() + point.x(), corner_.y() + point.y())));
101 gfx::NativeWindow GetPlatformAppWindow() {
102 const extensions::AppWindowRegistry::AppWindowList& app_windows =
103 extensions::AppWindowRegistry::Get(browser()->profile())->app_windows();
104 return (*app_windows.begin())->GetNativeWindow();
107 void SendKeyPressToPlatformApp(ui::KeyboardCode key) {
108 ASSERT_EQ(1U, GetAppWindowCount());
109 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
110 GetPlatformAppWindow(), key, false, false, false, false));
113 void SendCopyKeyPressToPlatformApp() {
114 ASSERT_EQ(1U, GetAppWindowCount());
115 #if defined(OS_MACOSX)
116 // Send Cmd+C on MacOSX.
117 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
118 GetPlatformAppWindow(), ui::VKEY_C, false, false, false, true));
119 #else
120 // Send Ctrl+C on Windows and Linux/ChromeOS.
121 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
122 GetPlatformAppWindow(), ui::VKEY_C, true, false, false, false));
123 #endif
126 void SendStartOfLineKeyPressToPlatformApp() {
127 #if defined(OS_MACOSX)
128 // Send Cmd+Left on MacOSX.
129 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
130 GetPlatformAppWindow(), ui::VKEY_LEFT, false, false, false, true));
131 #else
132 // Send Ctrl+Left on Windows and Linux/ChromeOS.
133 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
134 GetPlatformAppWindow(), ui::VKEY_LEFT, true, false, false, false));
135 #endif
138 void SendBackShortcutToPlatformApp() {
139 #if defined(OS_MACOSX)
140 // Send Cmd+[ on MacOSX.
141 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
142 GetPlatformAppWindow(), ui::VKEY_OEM_4, false, false, false, true));
143 #else
144 // Send browser back key on Linux/Windows.
145 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
146 GetPlatformAppWindow(), ui::VKEY_BROWSER_BACK,
147 false, false, false, false));
148 #endif
151 void SendForwardShortcutToPlatformApp() {
152 #if defined(OS_MACOSX)
153 // Send Cmd+] on MacOSX.
154 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
155 GetPlatformAppWindow(), ui::VKEY_OEM_6, false, false, false, true));
156 #else
157 // Send browser back key on Linux/Windows.
158 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
159 GetPlatformAppWindow(), ui::VKEY_BROWSER_FORWARD,
160 false, false, false, false));
161 #endif
164 void SendMouseEvent(ui_controls::MouseButton button,
165 ui_controls::MouseButtonState state) {
166 if (first_click_) {
167 mouse_click_result_ = ui_test_utils::SendMouseEventsSync(button,
168 state);
169 first_click_ = false;
170 } else {
171 ASSERT_EQ(mouse_click_result_, ui_test_utils::SendMouseEventsSync(
172 button, state));
176 enum TestServer {
177 NEEDS_TEST_SERVER,
178 NO_TEST_SERVER
181 scoped_ptr<ExtensionTestMessageListener> RunAppHelper(
182 const std::string& test_name,
183 const std::string& app_location,
184 TestServer test_server,
185 content::WebContents** embedder_web_contents) {
186 // For serving guest pages.
187 if ((test_server == NEEDS_TEST_SERVER) && !StartEmbeddedTestServer()) {
188 LOG(ERROR) << "FAILED TO START TEST SERVER.";
189 return scoped_ptr<ExtensionTestMessageListener>();
192 LoadAndLaunchPlatformApp(app_location.c_str(), "Launched");
193 if (!ui_test_utils::ShowAndFocusNativeWindow(GetPlatformAppWindow())) {
194 LOG(ERROR) << "UNABLE TO FOCUS TEST WINDOW.";
195 return scoped_ptr<ExtensionTestMessageListener>();
198 // Flush any pending events to make sure we start with a clean slate.
199 content::RunAllPendingInMessageLoop();
201 *embedder_web_contents = GetFirstAppWindowWebContents();
203 scoped_ptr<ExtensionTestMessageListener> done_listener(
204 new ExtensionTestMessageListener("TEST_PASSED", false));
205 done_listener->set_failure_message("TEST_FAILED");
206 if (!content::ExecuteScript(
207 *embedder_web_contents,
208 base::StringPrintf("runTest('%s')", test_name.c_str()))) {
209 LOG(ERROR) << "UNABLE TO START TEST";
210 return scoped_ptr<ExtensionTestMessageListener>();
213 return done_listener.Pass();
216 void TestHelper(const std::string& test_name,
217 const std::string& app_location,
218 TestServer test_server) {
219 content::WebContents* embedder_web_contents = NULL;
220 scoped_ptr<ExtensionTestMessageListener> done_listener(
221 RunAppHelper(
222 test_name, app_location, test_server, &embedder_web_contents));
224 ASSERT_TRUE(done_listener);
225 ASSERT_TRUE(done_listener->WaitUntilSatisfied());
227 guest_web_contents_ = GetGuestViewManager()->WaitForSingleGuestCreated();
230 void SetupTest(const std::string& app_name,
231 const std::string& guest_url_spec) {
232 ASSERT_TRUE(StartEmbeddedTestServer());
233 GURL::Replacements replace_host;
234 replace_host.SetHostStr("localhost");
236 GURL guest_url = embedded_test_server()->GetURL(guest_url_spec);
237 guest_url = guest_url.ReplaceComponents(replace_host);
239 ui_test_utils::UrlLoadObserver guest_observer(
240 guest_url, content::NotificationService::AllSources());
242 LoadAndLaunchPlatformApp(app_name.c_str(), "connected");
244 guest_observer.Wait();
245 content::Source<content::NavigationController> source =
246 guest_observer.source();
247 EXPECT_TRUE(source->GetWebContents()->GetRenderProcessHost()->
248 IsForGuestsOnly());
250 guest_web_contents_ = source->GetWebContents();
251 embedder_web_contents_ =
252 GuestViewBase::FromWebContents(guest_web_contents_)->
253 embedder_web_contents();
255 gfx::Rect offset = embedder_web_contents_->GetContainerBounds();
256 corner_ = gfx::Point(offset.x(), offset.y());
258 const testing::TestInfo* const test_info =
259 testing::UnitTest::GetInstance()->current_test_info();
260 const char* prefix = "DragDropWithinWebView";
261 if (!strncmp(test_info->name(), prefix, strlen(prefix))) {
262 // In the drag drop test we add 20px padding to the page body because on
263 // windows if we get too close to the edge of the window the resize cursor
264 // appears and we start dragging the window edge.
265 corner_.Offset(20, 20);
269 content::WebContents* guest_web_contents() {
270 return guest_web_contents_;
273 content::WebContents* embedder_web_contents() {
274 return embedder_web_contents_;
277 gfx::Point corner() {
278 return corner_;
281 void SimulateRWHMouseClick(content::RenderWidgetHost* rwh,
282 blink::WebMouseEvent::Button button,
283 int x,
284 int y) {
285 blink::WebMouseEvent mouse_event;
286 mouse_event.button = button;
287 mouse_event.x = mouse_event.windowX = x;
288 mouse_event.y = mouse_event.windowY = y;
289 mouse_event.modifiers = 0;
291 mouse_event.type = blink::WebInputEvent::MouseDown;
292 rwh->ForwardMouseEvent(mouse_event);
293 mouse_event.type = blink::WebInputEvent::MouseUp;
294 rwh->ForwardMouseEvent(mouse_event);
297 class PopupCreatedObserver {
298 public:
299 PopupCreatedObserver()
300 : initial_widget_count_(0),
301 last_render_widget_host_(NULL) {}
303 ~PopupCreatedObserver() {}
305 void Wait() {
306 if (CountWidgets() == initial_widget_count_ + 1) {
307 gfx::Rect popup_bounds =
308 last_render_widget_host_->GetView()->GetViewBounds();
309 if (!popup_bounds.size().IsEmpty()) {
310 if (message_loop_.get())
311 message_loop_->Quit();
312 return;
316 // If we haven't seen any new widget or we get 0 size widget, we need to
317 // schedule waiting.
318 ScheduleWait();
320 if (!message_loop_.get()) {
321 message_loop_ = new content::MessageLoopRunner;
322 message_loop_->Run();
326 void Init() { initial_widget_count_ = CountWidgets(); }
328 // Returns the last widget created.
329 content::RenderWidgetHost* last_render_widget_host() {
330 return last_render_widget_host_;
333 private:
334 void ScheduleWait() {
335 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
336 FROM_HERE,
337 base::Bind(&PopupCreatedObserver::Wait, base::Unretained(this)),
338 base::TimeDelta::FromMilliseconds(200));
341 size_t CountWidgets() {
342 scoped_ptr<content::RenderWidgetHostIterator> widgets(
343 content::RenderWidgetHost::GetRenderWidgetHosts());
344 size_t num_widgets = 0;
345 while (content::RenderWidgetHost* widget = widgets->GetNextHost()) {
346 if (widget->IsRenderView())
347 continue;
348 ++num_widgets;
349 last_render_widget_host_ = widget;
351 return num_widgets;
354 size_t initial_widget_count_;
355 content::RenderWidgetHost* last_render_widget_host_;
356 scoped_refptr<content::MessageLoopRunner> message_loop_;
357 bool seen_new_widget_;
359 DISALLOW_COPY_AND_ASSIGN(PopupCreatedObserver);
362 void PopupTestHelper(const gfx::Point& padding) {
363 PopupCreatedObserver popup_observer;
364 popup_observer.Init();
365 // Press alt+DOWN to open popup.
366 bool alt = true;
367 content::SimulateKeyPress(
368 guest_web_contents(), ui::VKEY_DOWN, false, false, alt, false);
369 popup_observer.Wait();
371 content::RenderWidgetHost* popup_rwh =
372 popup_observer.last_render_widget_host();
373 gfx::Rect popup_bounds = popup_rwh->GetView()->GetViewBounds();
375 content::RenderViewHost* embedder_rvh =
376 GetFirstAppWindowWebContents()->GetRenderViewHost();
377 gfx::Rect embedder_bounds = embedder_rvh->GetView()->GetViewBounds();
378 gfx::Vector2d diff = popup_bounds.origin() - embedder_bounds.origin();
379 LOG(INFO) << "DIFF: x = " << diff.x() << ", y = " << diff.y();
381 const int left_spacing = 40 + padding.x(); // div.style.paddingLeft = 40px.
382 // div.style.paddingTop = 50px + (input box height = 26px).
383 const int top_spacing = 50 + 26 + padding.y();
385 // If the popup is placed within |threshold_px| of the expected position,
386 // then we consider the test as a pass.
387 const int threshold_px = 10;
389 EXPECT_LE(std::abs(diff.x() - left_spacing), threshold_px);
390 EXPECT_LE(std::abs(diff.y() - top_spacing), threshold_px);
392 // Close the popup.
393 content::SimulateKeyPress(
394 guest_web_contents(), ui::VKEY_ESCAPE, false, false, false, false);
397 void DragTestStep1() {
398 // Move mouse to start of text.
399 MoveMouseInsideWindow(gfx::Point(45, 8));
400 MoveMouseInsideWindow(gfx::Point(45, 9));
401 SendMouseEvent(ui_controls::LEFT, ui_controls::DOWN);
403 MoveMouseInsideWindow(gfx::Point(74, 12));
404 MoveMouseInsideWindow(gfx::Point(78, 12));
406 // Now wait a bit before moving mouse to initiate drag/drop.
407 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
408 FROM_HERE, base::Bind(&WebViewInteractiveTest::DragTestStep2,
409 base::Unretained(this)),
410 base::TimeDelta::FromMilliseconds(200));
413 void DragTestStep2() {
414 // Drag source over target.
415 MoveMouseInsideWindow(gfx::Point(76, 76));
417 // Create a second mouse over the source to trigger the drag over event.
418 MoveMouseInsideWindow(gfx::Point(76, 77));
420 // Release mouse to drop.
421 SendMouseEvent(ui_controls::LEFT, ui_controls::UP);
422 SendMouseClick(ui_controls::LEFT);
424 quit_closure_.Run();
426 // Note that following ExtensionTestMessageListener and ExecuteScript*
427 // call must be after we quit |quit_closure_|. Otherwise the class
428 // here won't be able to receive messages sent by chrome.test.sendMessage.
429 // This is because of the nature of drag and drop code (esp. the
430 // MessageLoop) in it.
432 // Now check if we got a drop and read the drop data.
433 embedder_web_contents_ = GetFirstAppWindowWebContents();
434 ExtensionTestMessageListener drop_listener("guest-got-drop", false);
435 EXPECT_TRUE(content::ExecuteScript(embedder_web_contents_,
436 "window.checkIfGuestGotDrop()"));
437 EXPECT_TRUE(drop_listener.WaitUntilSatisfied());
439 std::string last_drop_data;
440 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
441 embedder_web_contents_,
442 "window.domAutomationController.send(getLastDropData())",
443 &last_drop_data));
445 last_drop_data_ = last_drop_data;
448 void FullscreenTestHelper(const std::string& test_name,
449 const std::string& test_dir) {
450 TestHelper(test_name, test_dir, NO_TEST_SERVER);
451 content::WebContents* embedder_web_contents =
452 GetFirstAppWindowWebContents();
453 ASSERT_TRUE(embedder_web_contents);
454 ASSERT_TRUE(guest_web_contents());
455 // Click the guest to request fullscreen.
456 ExtensionTestMessageListener passed_listener(
457 "FULLSCREEN_STEP_PASSED", false);
458 passed_listener.set_failure_message("TEST_FAILED");
459 content::SimulateMouseClickAt(guest_web_contents(),
461 blink::WebMouseEvent::ButtonLeft,
462 gfx::Point(20, 20));
463 ASSERT_TRUE(passed_listener.WaitUntilSatisfied());
466 protected:
467 TestGuestViewManagerFactory factory_;
468 content::WebContents* guest_web_contents_;
469 content::WebContents* embedder_web_contents_;
470 gfx::Point corner_;
471 bool mouse_click_result_;
472 bool first_click_;
473 // Only used in drag/drop test.
474 base::Closure quit_closure_;
475 std::string last_drop_data_;
478 // ui_test_utils::SendMouseMoveSync doesn't seem to work on OS_MACOSX, and
479 // likely won't work on many other platforms as well, so for now this test
480 // is for Windows and Linux only. As of Sept 17th, 2013 this test is disabled
481 // on Windows due to flakines, see http://crbug.com/293445.
483 // Disabled on Linux Aura because pointer lock does not work on Linux Aura.
484 // crbug.com/341876
486 #if defined(OS_LINUX)
487 // flaky http://crbug.com/412086
488 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, DISABLED_PointerLock) {
489 SetupTest("web_view/pointer_lock",
490 "/extensions/platform_apps/web_view/pointer_lock/guest.html");
492 // Move the mouse over the Lock Pointer button.
493 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(
494 gfx::Point(corner().x() + 75, corner().y() + 25)));
496 // Click the Lock Pointer button. The first two times the button is clicked
497 // the permission API will deny the request (intentional).
498 ExtensionTestMessageListener exception_listener("request exception", false);
499 SendMouseClickWithListener(ui_controls::LEFT, "lock error");
500 ASSERT_TRUE(exception_listener.WaitUntilSatisfied());
501 SendMouseClickWithListener(ui_controls::LEFT, "lock error");
503 // Click the Lock Pointer button, locking the mouse to lockTarget1.
504 SendMouseClickWithListener(ui_controls::LEFT, "locked");
506 // Attempt to move the mouse off of the lock target, and onto lockTarget2,
507 // (which would trigger a test failure).
508 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(
509 gfx::Point(corner().x() + 74, corner().y() + 74)));
510 MoveMouseInsideWindowWithListener(gfx::Point(75, 75), "mouse-move");
512 #if defined(OS_WIN)
513 // When the mouse is unlocked on win aura, sending a test mouse click clicks
514 // where the mouse moved to while locked. I was unable to figure out why, and
515 // since the issue only occurs with the test mouse events, just fix it with
516 // a simple workaround - moving the mouse back to where it should be.
517 // TODO(mthiesse): Fix Win Aura simulated mouse events while mouse locked.
518 MoveMouseInsideWindowWithListener(gfx::Point(75, 25), "mouse-move");
519 #endif
521 ExtensionTestMessageListener unlocked_listener("unlocked", false);
522 // Send a key press to unlock the mouse.
523 SendKeyPressToPlatformApp(ui::VKEY_ESCAPE);
525 // Wait for page to receive (successful) mouse unlock response.
526 ASSERT_TRUE(unlocked_listener.WaitUntilSatisfied());
528 // After the second lock, guest.js sends a message to main.js to remove the
529 // webview object. main.js then removes the div containing the webview, which
530 // should unlock, and leave the mouse over the mousemove-capture-container
531 // div. We then move the mouse over that div to ensure the mouse was properly
532 // unlocked and that the div receieves the message.
533 ExtensionTestMessageListener move_captured_listener("move-captured", false);
534 move_captured_listener.set_failure_message("timeout");
536 // Mouse should already be over lock button (since we just unlocked), so send
537 // click to re-lock the mouse.
538 SendMouseClickWithListener(ui_controls::LEFT, "deleted");
540 // A mousemove event is triggered on the mousemove-capture-container element
541 // when we delete the webview container (since the mouse moves onto the
542 // element), but just in case, send an explicit mouse movement to be safe.
543 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(
544 gfx::Point(corner().x() + 50, corner().y() + 10)));
546 // Wait for page to receive second (successful) mouselock response.
547 bool success = move_captured_listener.WaitUntilSatisfied();
548 if (!success) {
549 fprintf(stderr, "TIMEOUT - retrying\n");
550 // About 1 in 40 tests fail to detect mouse moves at this point (why?).
551 // Sending a right click seems to fix this (why?).
552 ExtensionTestMessageListener move_listener2("move-captured", false);
553 SendMouseClick(ui_controls::RIGHT);
554 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(
555 gfx::Point(corner().x() + 51, corner().y() + 11)));
556 ASSERT_TRUE(move_listener2.WaitUntilSatisfied());
560 // flaky http://crbug.com/412086
561 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, DISABLED_PointerLockFocus) {
562 SetupTest("web_view/pointer_lock_focus",
563 "/extensions/platform_apps/web_view/pointer_lock_focus/guest.html");
565 // Move the mouse over the Lock Pointer button.
566 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(
567 gfx::Point(corner().x() + 75, corner().y() + 25)));
569 // Click the Lock Pointer button, locking the mouse to lockTarget.
570 // This will also change focus to another element
571 SendMouseClickWithListener(ui_controls::LEFT, "locked");
573 // Try to unlock the mouse now that the focus is outside of the BrowserPlugin
574 ExtensionTestMessageListener unlocked_listener("unlocked", false);
575 // Send a key press to unlock the mouse.
576 SendKeyPressToPlatformApp(ui::VKEY_ESCAPE);
578 // Wait for page to receive (successful) mouse unlock response.
579 ASSERT_TRUE(unlocked_listener.WaitUntilSatisfied());
582 #endif // defined(OS_LINUX)
584 // Tests that if a <webview> is focused before navigation then the guest starts
585 // off focused.
586 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, Focus_FocusBeforeNavigation) {
587 TestHelper("testFocusBeforeNavigation", "web_view/focus", NO_TEST_SERVER);
590 // Tests that setting focus on the <webview> sets focus on the guest.
591 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, Focus_FocusEvent) {
592 TestHelper("testFocusEvent", "web_view/focus", NO_TEST_SERVER);
595 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, Focus_FocusTracksEmbedder) {
596 content::WebContents* embedder_web_contents = NULL;
598 scoped_ptr<ExtensionTestMessageListener> done_listener(
599 RunAppHelper("testFocusTracksEmbedder", "web_view/focus", NO_TEST_SERVER,
600 &embedder_web_contents));
601 done_listener->WaitUntilSatisfied();
603 ExtensionTestMessageListener next_step_listener("TEST_STEP_PASSED", false);
604 next_step_listener.set_failure_message("TEST_STEP_FAILED");
605 EXPECT_TRUE(content::ExecuteScript(
606 embedder_web_contents,
607 "window.runCommand('testFocusTracksEmbedderRunNextStep');"));
609 // Blur the embedder.
610 embedder_web_contents->GetRenderViewHost()->Blur();
611 // Ensure that the guest is also blurred.
612 ASSERT_TRUE(next_step_listener.WaitUntilSatisfied());
615 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, Focus_AdvanceFocus) {
616 content::WebContents* embedder_web_contents = NULL;
619 scoped_ptr<ExtensionTestMessageListener> done_listener(
620 RunAppHelper("testAdvanceFocus", "web_view/focus", NO_TEST_SERVER,
621 &embedder_web_contents));
622 done_listener->WaitUntilSatisfied();
626 ExtensionTestMessageListener listener("button1-focused", false);
627 listener.set_failure_message("TEST_FAILED");
628 SimulateRWHMouseClick(embedder_web_contents->GetRenderViewHost(),
629 blink::WebMouseEvent::ButtonLeft, 200, 20);
630 content::SimulateKeyPress(embedder_web_contents, ui::VKEY_TAB,
631 false, false, false, false);
632 ASSERT_TRUE(listener.WaitUntilSatisfied());
636 // Wait for button1 to be focused again, this means we were asked to
637 // move the focus to the next focusable element.
638 ExtensionTestMessageListener listener("button1-advance-focus", false);
639 listener.set_failure_message("TEST_FAILED");
640 // TODO(fsamuel): A third Tab key press should not be necessary.
641 // The <webview> will take keyboard focus but it will not focus an initial
642 // element. The initial element is dependent upon tab direction which blink
643 // does not propagate to the plugin.
644 // See http://crbug.com/147644.
645 content::SimulateKeyPress(embedder_web_contents, ui::VKEY_TAB,
646 false, false, false, false);
647 content::SimulateKeyPress(embedder_web_contents, ui::VKEY_TAB,
648 false, false, false, false);
649 content::SimulateKeyPress(embedder_web_contents, ui::VKEY_TAB,
650 false, false, false, false);
651 ASSERT_TRUE(listener.WaitUntilSatisfied());
655 // Tests that blurring <webview> also blurs the guest.
656 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, Focus_BlurEvent) {
657 TestHelper("testBlurEvent", "web_view/focus", NO_TEST_SERVER);
660 // Tests that guests receive edit commands and respond appropriately.
661 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, EditCommands) {
662 LoadAndLaunchPlatformApp("web_view/edit_commands", "connected");
664 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(
665 GetPlatformAppWindow()));
667 // Flush any pending events to make sure we start with a clean slate.
668 content::RunAllPendingInMessageLoop();
670 ExtensionTestMessageListener copy_listener("copy", false);
671 SendCopyKeyPressToPlatformApp();
673 // Wait for the guest to receive a 'copy' edit command.
674 ASSERT_TRUE(copy_listener.WaitUntilSatisfied());
677 // Tests that guests receive edit commands and respond appropriately.
678 // http://crbug.com/417892
679 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, DISABLED_EditCommandsNoMenu) {
680 SetupTest("web_view/edit_commands_no_menu",
681 "/extensions/platform_apps/web_view/edit_commands_no_menu/"
682 "guest.html");
684 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(
685 GetPlatformAppWindow()));
687 // Flush any pending events to make sure we start with a clean slate.
688 content::RunAllPendingInMessageLoop();
690 ExtensionTestMessageListener start_of_line_listener("StartOfLine", false);
691 SendStartOfLineKeyPressToPlatformApp();
692 // Wait for the guest to receive a 'copy' edit command.
693 ASSERT_TRUE(start_of_line_listener.WaitUntilSatisfied());
696 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest,
697 NewWindow_AttachAfterOpenerDestroyed) {
698 TestHelper("testNewWindowAttachAfterOpenerDestroyed",
699 "web_view/newwindow",
700 NEEDS_TEST_SERVER);
703 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest,
704 NewWindow_NewWindowNameTakesPrecedence) {
705 TestHelper("testNewWindowNameTakesPrecedence",
706 "web_view/newwindow",
707 NEEDS_TEST_SERVER);
710 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest,
711 NewWindow_WebViewNameTakesPrecedence) {
712 TestHelper("testNewWindowWebViewNameTakesPrecedence",
713 "web_view/newwindow",
714 NEEDS_TEST_SERVER);
717 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, NewWindow_NoName) {
718 TestHelper("testNewWindowNoName",
719 "web_view/newwindow",
720 NEEDS_TEST_SERVER);
723 // Flaky on win_chromium_rel_ng. https://crbug.com/504054
724 #if defined(OS_WIN)
725 #define MAYBE_NewWindow_Redirect DISABLED_NewWindow_Redirect
726 #else
727 #define MAYBE_NewWindow_Redirect NewWindow_Redirect
728 #endif
729 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, MAYBE_NewWindow_Redirect) {
730 TestHelper("testNewWindowRedirect",
731 "web_view/newwindow",
732 NEEDS_TEST_SERVER);
735 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, NewWindow_Close) {
736 TestHelper("testNewWindowClose",
737 "web_view/newwindow",
738 NEEDS_TEST_SERVER);
741 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, NewWindow_DeferredAttachment) {
742 TestHelper("testNewWindowDeferredAttachment",
743 "web_view/newwindow",
744 NEEDS_TEST_SERVER);
747 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, NewWindow_ExecuteScript) {
748 TestHelper("testNewWindowExecuteScript",
749 "web_view/newwindow",
750 NEEDS_TEST_SERVER);
753 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest,
754 NewWindow_DeclarativeWebRequest) {
755 TestHelper("testNewWindowDeclarativeWebRequest",
756 "web_view/newwindow",
757 NEEDS_TEST_SERVER);
760 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest,
761 NewWindow_DiscardAfterOpenerDestroyed) {
762 TestHelper("testNewWindowDiscardAfterOpenerDestroyed",
763 "web_view/newwindow",
764 NEEDS_TEST_SERVER);
767 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, NewWindow_WebRequest) {
768 TestHelper("testNewWindowWebRequest",
769 "web_view/newwindow",
770 NEEDS_TEST_SERVER);
773 // A custom elements bug needs to be addressed to enable this test:
774 // See http://crbug.com/282477 for more information.
775 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest,
776 DISABLED_NewWindow_WebRequestCloseWindow) {
777 TestHelper("testNewWindowWebRequestCloseWindow",
778 "web_view/newwindow",
779 NEEDS_TEST_SERVER);
782 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest,
783 NewWindow_WebRequestRemoveElement) {
784 TestHelper("testNewWindowWebRequestRemoveElement",
785 "web_view/newwindow",
786 NEEDS_TEST_SERVER);
789 // There is a problem of missing keyup events with the command key after
790 // the NSEvent is sent to NSApplication in ui/base/test/ui_controls_mac.mm .
791 // This test is disabled on only the Mac until the problem is resolved.
792 // See http://crbug.com/425859 for more information.
793 #if !defined(OS_MACOSX)
794 // Tests that Ctrl+Click/Cmd+Click on a link fires up the newwindow API.
795 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, NewWindow_OpenInNewTab) {
796 content::WebContents* embedder_web_contents = NULL;
798 ExtensionTestMessageListener loaded_listener("Loaded", false);
799 scoped_ptr<ExtensionTestMessageListener> done_listener(
800 RunAppHelper("testNewWindowOpenInNewTab",
801 "web_view/newwindow",
802 NEEDS_TEST_SERVER,
803 &embedder_web_contents));
805 loaded_listener.WaitUntilSatisfied();
806 #if defined(OS_MACOSX)
807 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
808 GetPlatformAppWindow(), ui::VKEY_RETURN,
809 false, false, false, true /* cmd */));
810 #else
811 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
812 GetPlatformAppWindow(), ui::VKEY_RETURN,
813 true /* ctrl */, false, false, false));
814 #endif
816 // Wait for the embedder to receive a 'newwindow' event.
817 ASSERT_TRUE(done_listener->WaitUntilSatisfied());
819 #endif
821 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest,
822 NewWindow_OpenerDestroyedWhileUnattached) {
823 TestHelper("testNewWindowOpenerDestroyedWhileUnattached",
824 "web_view/newwindow",
825 NEEDS_TEST_SERVER);
826 ASSERT_EQ(2u, GetGuestViewManager()->num_guests_created());
828 // We have two guests in this test, one is the intial one, the other
829 // is the newwindow one.
830 // Before the embedder goes away, both the guests should go away.
831 // This ensures that unattached guests are gone if opener is gone.
832 GetGuestViewManager()->WaitForAllGuestsDeleted();
835 // Tests whether <webview> context menu sees <webview> local coordinates
836 // in its RenderViewContextMenu params.
837 // Local coordinates are required for plugin actions to work properly.
838 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, ContextMenuParamCoordinates) {
839 TestHelper("testCoordinates", "web_view/context_menus/coordinates",
840 NO_TEST_SERVER);
841 ASSERT_TRUE(guest_web_contents());
843 ContextMenuWaiter menu_observer(content::NotificationService::AllSources());
844 SimulateRWHMouseClick(guest_web_contents()->GetRenderViewHost(),
845 blink::WebMouseEvent::ButtonRight, 10, 20);
846 // Wait until the context menu is opened and closed.
847 menu_observer.WaitForMenuOpenAndClose();
848 ASSERT_EQ(10, menu_observer.params().x);
849 ASSERT_EQ(20, menu_observer.params().y);
852 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, ExecuteCode) {
853 ASSERT_TRUE(RunPlatformAppTestWithArg(
854 "platform_apps/web_view/common", "execute_code")) << message_;
857 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, PopupPositioningBasic) {
858 TestHelper("testBasic", "web_view/popup_positioning", NO_TEST_SERVER);
859 ASSERT_TRUE(guest_web_contents());
860 PopupTestHelper(gfx::Point());
862 // TODO(lazyboy): Move the embedder window to a random location and
863 // make sure we keep rendering popups correct in webview.
866 // Tests that moving browser plugin (without resize/UpdateRects) correctly
867 // repositions popup.
868 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, PopupPositioningMoved) {
869 TestHelper("testMoved", "web_view/popup_positioning", NO_TEST_SERVER);
870 ASSERT_TRUE(guest_web_contents());
871 PopupTestHelper(gfx::Point(20, 0));
874 // Drag and drop inside a webview is currently only enabled for linux and mac,
875 // but the tests don't work on anything except chromeos for now. This is because
876 // of simulating mouse drag code's dependency on platforms.
877 #if defined(OS_CHROMEOS) && !defined(USE_OZONE)
878 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, DragDropWithinWebView) {
879 LoadAndLaunchPlatformApp("web_view/dnd_within_webview", "connected");
880 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(GetPlatformAppWindow()));
882 embedder_web_contents_ = GetFirstAppWindowWebContents();
883 gfx::Rect offset = embedder_web_contents_->GetContainerBounds();
884 corner_ = gfx::Point(offset.x(), offset.y());
886 // In the drag drop test we add 20px padding to the page body because on
887 // windows if we get too close to the edge of the window the resize cursor
888 // appears and we start dragging the window edge.
889 corner_.Offset(20, 20);
891 // Flush any pending events to make sure we start with a clean slate.
892 content::RunAllPendingInMessageLoop();
893 for (;;) {
894 base::RunLoop run_loop;
895 quit_closure_ = run_loop.QuitClosure();
896 base::MessageLoop::current()->PostTask(
897 FROM_HERE,
898 base::Bind(&WebViewInteractiveTest::DragTestStep1,
899 base::Unretained(this)));
900 run_loop.Run();
902 if (last_drop_data_ == "Drop me")
903 break;
905 LOG(INFO) << "Drag was cancelled in interactive_test, restarting drag";
907 // Reset state for next try.
908 ExtensionTestMessageListener reset_listener("resetStateReply", false);
909 EXPECT_TRUE(content::ExecuteScript(embedder_web_contents_,
910 "window.resetState()"));
911 ASSERT_TRUE(reset_listener.WaitUntilSatisfied());
913 ASSERT_EQ("Drop me", last_drop_data_);
915 #endif // (defined(OS_CHROMEOS))
917 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, Navigation) {
918 TestHelper("testNavigation", "web_view/navigation", NO_TEST_SERVER);
921 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, Navigation_BackForwardKeys) {
922 LoadAndLaunchPlatformApp("web_view/navigation", "Launched");
923 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(
924 GetPlatformAppWindow()));
925 // Flush any pending events to make sure we start with a clean slate.
926 content::RunAllPendingInMessageLoop();
928 content::WebContents* embedder_web_contents = GetFirstAppWindowWebContents();
929 ASSERT_TRUE(embedder_web_contents);
931 ExtensionTestMessageListener done_listener(
932 "TEST_PASSED", false);
933 done_listener.set_failure_message("TEST_FAILED");
934 ExtensionTestMessageListener ready_back_key_listener(
935 "ReadyForBackKey", false);
936 ExtensionTestMessageListener ready_forward_key_listener(
937 "ReadyForForwardKey", false);
939 EXPECT_TRUE(content::ExecuteScript(
940 embedder_web_contents,
941 "runTest('testBackForwardKeys')"));
943 ASSERT_TRUE(ready_back_key_listener.WaitUntilSatisfied());
944 SendBackShortcutToPlatformApp();
946 ASSERT_TRUE(ready_forward_key_listener.WaitUntilSatisfied());
947 SendForwardShortcutToPlatformApp();
949 ASSERT_TRUE(done_listener.WaitUntilSatisfied());
952 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest,
953 PointerLock_PointerLockLostWithFocus) {
954 TestHelper("testPointerLockLostWithFocus",
955 "web_view/pointerlock",
956 NO_TEST_SERVER);
959 // Disable this on mac, throws an assertion failure on teardown which
960 // will result in flakiness:
962 // "not is fullscreen state"
963 // "*** Assertion failure in -[_NSWindowFullScreenTransition
964 // transitionedWindowFrame],"
965 // See similar bug: http://crbug.com/169820.
967 // In addition to the above, these tests are flaky on many platforms:
968 // http://crbug.com/468660
969 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest,
970 DISABLED_FullscreenAllow_EmbedderHasPermission) {
971 FullscreenTestHelper("testFullscreenAllow",
972 "web_view/fullscreen/embedder_has_permission");
975 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest,
976 DISABLED_FullscreenDeny_EmbedderHasPermission) {
977 FullscreenTestHelper("testFullscreenDeny",
978 "web_view/fullscreen/embedder_has_permission");
981 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest,
982 DISABLED_FullscreenAllow_EmbedderHasNoPermission) {
983 FullscreenTestHelper("testFullscreenAllow",
984 "web_view/fullscreen/embedder_has_no_permission");
987 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest,
988 DISABLED_FullscreenDeny_EmbedderHasNoPermission) {
989 FullscreenTestHelper("testFullscreenDeny",
990 "web_view/fullscreen/embedder_has_no_permission");
993 // This test exercies the following scenario:
994 // 1. An <input> in guest has focus.
995 // 2. User takes focus to embedder by clicking e.g. an <input> in embedder.
996 // 3. User brings back the focus directly to the <input> in #1.
998 // Now we need to make sure TextInputTypeChanged fires properly for the guest's
999 // view upon step #3. We simply read the input type's state after #3 to
1000 // make sure it's not TEXT_INPUT_TYPE_NONE.
1001 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, Focus_FocusRestored) {
1002 TestHelper("testFocusRestored", "web_view/focus", NO_TEST_SERVER);
1003 content::WebContents* embedder_web_contents = GetFirstAppWindowWebContents();
1004 ASSERT_TRUE(embedder_web_contents);
1005 ASSERT_TRUE(guest_web_contents());
1007 // 1) We click on the guest so that we get a focus event.
1008 ExtensionTestMessageListener next_step_listener("TEST_STEP_PASSED", false);
1009 next_step_listener.set_failure_message("TEST_STEP_FAILED");
1011 content::SimulateMouseClickAt(guest_web_contents(),
1013 blink::WebMouseEvent::ButtonLeft,
1014 gfx::Point(10, 10));
1015 EXPECT_TRUE(content::ExecuteScript(
1016 embedder_web_contents,
1017 "window.runCommand('testFocusRestoredRunNextStep', 1);"));
1019 // Wait for the next step to complete.
1020 ASSERT_TRUE(next_step_listener.WaitUntilSatisfied());
1022 // 2) We click on the embedder so the guest's focus goes away and it observes
1023 // a blur event.
1024 next_step_listener.Reset();
1026 content::SimulateMouseClickAt(embedder_web_contents,
1028 blink::WebMouseEvent::ButtonLeft,
1029 gfx::Point(200, 20));
1030 EXPECT_TRUE(content::ExecuteScript(
1031 embedder_web_contents,
1032 "window.runCommand('testFocusRestoredRunNextStep', 2);"));
1034 // Wait for the next step to complete.
1035 ASSERT_TRUE(next_step_listener.WaitUntilSatisfied());
1037 // 3) We click on the guest again to bring back focus directly to the previous
1038 // input element, then we ensure text_input_type is properly set.
1039 next_step_listener.Reset();
1041 content::SimulateMouseClickAt(guest_web_contents(),
1043 blink::WebMouseEvent::ButtonLeft,
1044 gfx::Point(10, 10));
1045 EXPECT_TRUE(content::ExecuteScript(
1046 embedder_web_contents,
1047 "window.runCommand('testFocusRestoredRunNextStep', 3)"));
1049 // Wait for the next step to complete.
1050 ASSERT_TRUE(next_step_listener.WaitUntilSatisfied());
1052 // |text_input_client| is not available for mac and android.
1053 #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
1054 ui::TextInputClient* text_input_client =
1055 embedder_web_contents->GetRenderViewHost()->GetView()
1056 ->GetTextInputClient();
1057 ASSERT_TRUE(text_input_client);
1058 ASSERT_TRUE(text_input_client->GetTextInputType() !=
1059 ui::TEXT_INPUT_TYPE_NONE);
1060 #endif
1063 // ui::TextInputClient is NULL for mac and android.
1064 #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
1065 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, DISABLED_Focus_InputMethod) {
1066 content::WebContents* embedder_web_contents = NULL;
1067 scoped_ptr<ExtensionTestMessageListener> done_listener(
1068 RunAppHelper("testInputMethod", "web_view/focus", NO_TEST_SERVER,
1069 &embedder_web_contents));
1070 ASSERT_TRUE(done_listener->WaitUntilSatisfied());
1072 ui::TextInputClient* text_input_client =
1073 embedder_web_contents->GetRenderViewHost()->GetView()
1074 ->GetTextInputClient();
1075 ASSERT_TRUE(text_input_client);
1077 ExtensionTestMessageListener next_step_listener("TEST_STEP_PASSED", false);
1078 next_step_listener.set_failure_message("TEST_STEP_FAILED");
1080 // An input element inside the <webview> gets focus and is given some
1081 // user input via IME.
1083 ui::CompositionText composition;
1084 composition.text = base::UTF8ToUTF16("InputTest123");
1085 text_input_client->SetCompositionText(composition);
1086 EXPECT_TRUE(content::ExecuteScript(
1087 embedder_web_contents,
1088 "window.runCommand('testInputMethodRunNextStep', 1);"));
1090 // Wait for the next step to complete.
1091 ASSERT_TRUE(next_step_listener.WaitUntilSatisfied());
1094 // A composition is committed via IME.
1096 next_step_listener.Reset();
1098 ui::CompositionText composition;
1099 composition.text = base::UTF8ToUTF16("InputTest456");
1100 text_input_client->SetCompositionText(composition);
1101 text_input_client->ConfirmCompositionText();
1102 EXPECT_TRUE(content::ExecuteScript(
1103 embedder_web_contents,
1104 "window.runCommand('testInputMethodRunNextStep', 2);"));
1106 // Wait for the next step to complete.
1107 ASSERT_TRUE(next_step_listener.WaitUntilSatisfied());
1110 // TODO(lazyboy): http://crbug.com/457007, Add a step or a separate test to
1111 // check the following, currently it turns this test to be flaky:
1112 // If we move the focus from the first <input> to the second one after we
1113 // have some composition text set but *not* committed (by calling
1114 // text_input_client->SetCompositionText()), then it would cause IME cancel
1115 // and the onging composition is committed in the first <input> in the
1116 // <webview>, not the second one.
1118 // Tests ExtendSelectionAndDelete message works in <webview>.
1120 next_step_listener.Reset();
1122 // At this point we have set focus on first <input> in the <webview>,
1123 // and the value it contains is 'InputTest456' with caret set after 'T'.
1124 // Now we delete 'Test' in 'InputTest456', as the caret is after 'T':
1125 // delete before 1 character ('T') and after 3 characters ('est').
1126 text_input_client->ExtendSelectionAndDelete(1, 3);
1127 EXPECT_TRUE(content::ExecuteScript(
1128 embedder_web_contents,
1129 "window.runCommand('testInputMethodRunNextStep', 3);"));
1131 // Wait for the next step to complete.
1132 ASSERT_TRUE(next_step_listener.WaitUntilSatisfied());
1135 #endif
1137 #if defined(OS_MACOSX)
1138 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, TextSelection) {
1139 SetupTest("web_view/text_selection",
1140 "/extensions/platform_apps/web_view/text_selection/guest.html");
1141 ASSERT_TRUE(guest_web_contents());
1142 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(
1143 GetPlatformAppWindow()));
1145 // Wait until guest sees a context menu, select an arbitrary item (copy).
1146 ExtensionTestMessageListener ctx_listener("MSG_CONTEXTMENU", false);
1147 ContextMenuNotificationObserver menu_observer(IDC_CONTENT_CONTEXT_COPY);
1148 SimulateRWHMouseClick(guest_web_contents()->GetRenderViewHost(),
1149 blink::WebMouseEvent::ButtonRight, 20, 20);
1150 ASSERT_TRUE(ctx_listener.WaitUntilSatisfied());
1152 // Now verify that the selection text propagates properly to RWHV.
1153 content::RenderWidgetHostView* guest_rwhv =
1154 guest_web_contents()->GetRenderWidgetHostView();
1155 ASSERT_TRUE(guest_rwhv);
1156 std::string selected_text = base::UTF16ToUTF8(guest_rwhv->GetSelectedText());
1157 ASSERT_TRUE(selected_text.size() >= 10u);
1158 ASSERT_EQ("AAAAAAAAAA", selected_text.substr(0, 10));
1160 #endif