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 "apps/app_window.h"
6 #include "apps/app_window_registry.h"
7 #include "base/strings/stringprintf.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/app/chrome_command_ids.h"
10 #include "chrome/browser/apps/app_browsertest_util.h"
11 #include "chrome/browser/extensions/extension_test_message_listener.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/renderer_context_menu/render_view_context_menu_browsertest_util.h"
14 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_util.h"
15 #include "chrome/test/base/interactive_test_utils.h"
16 #include "chrome/test/base/test_launcher_utils.h"
17 #include "chrome/test/base/ui_test_utils.h"
18 #include "content/public/browser/notification_service.h"
19 #include "content/public/browser/render_process_host.h"
20 #include "content/public/browser/render_view_host.h"
21 #include "content/public/browser/render_widget_host_view.h"
22 #include "content/public/browser/web_contents.h"
23 #include "content/public/common/content_switches.h"
24 #include "content/public/test/browser_test_utils.h"
25 #include "net/test/embedded_test_server/embedded_test_server.h"
26 #include "ui/base/test/ui_controls.h"
27 #include "ui/events/keycodes/keyboard_codes.h"
29 using apps::AppWindow
;
31 class WebViewInteractiveTest
32 : public extensions::PlatformAppBrowserTest
{
34 WebViewInteractiveTest()
35 : corner_(gfx::Point()),
36 mouse_click_result_(false),
39 void MoveMouseInsideWindowWithListener(gfx::Point point
,
40 const std::string
& message
) {
41 ExtensionTestMessageListener
move_listener(message
, false);
42 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(
43 gfx::Point(corner_
.x() + point
.x(), corner_
.y() + point
.y())));
44 ASSERT_TRUE(move_listener
.WaitUntilSatisfied());
47 void SendMouseClickWithListener(ui_controls::MouseButton button
,
48 const std::string
& message
) {
49 ExtensionTestMessageListener
listener(message
, false);
50 SendMouseClick(button
);
51 ASSERT_TRUE(listener
.WaitUntilSatisfied());
54 void SendMouseClick(ui_controls::MouseButton button
) {
55 SendMouseEvent(button
, ui_controls::DOWN
);
56 SendMouseEvent(button
, ui_controls::UP
);
59 void MoveMouseInsideWindow(const gfx::Point
& point
) {
60 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(
61 gfx::Point(corner_
.x() + point
.x(), corner_
.y() + point
.y())));
64 gfx::NativeWindow
GetPlatformAppWindow() {
65 const apps::AppWindowRegistry::AppWindowList
& app_windows
=
66 apps::AppWindowRegistry::Get(browser()->profile())->app_windows();
67 return (*app_windows
.begin())->GetNativeWindow();
70 void SendKeyPressToPlatformApp(ui::KeyboardCode key
) {
71 ASSERT_EQ(1U, GetAppWindowCount());
72 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
73 GetPlatformAppWindow(), key
, false, false, false, false));
76 void SendCopyKeyPressToPlatformApp() {
77 ASSERT_EQ(1U, GetAppWindowCount());
78 #if defined(OS_MACOSX)
79 // Send Cmd+C on MacOSX.
80 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
81 GetPlatformAppWindow(), ui::VKEY_C
, false, false, false, true));
83 // Send Ctrl+C on Windows and Linux/ChromeOS.
84 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
85 GetPlatformAppWindow(), ui::VKEY_C
, true, false, false, false));
89 void SendStartOfLineKeyPressToPlatformApp() {
90 #if defined(OS_MACOSX)
91 // Send Cmd+Left on MacOSX.
92 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
93 GetPlatformAppWindow(), ui::VKEY_LEFT
, false, false, false, true));
95 // Send Ctrl+Left on Windows and Linux/ChromeOS.
96 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
97 GetPlatformAppWindow(), ui::VKEY_LEFT
, true, false, false, false));
101 void SendBackShortcutToPlatformApp() {
102 #if defined(OS_MACOSX)
103 // Send Cmd+[ on MacOSX.
104 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
105 GetPlatformAppWindow(), ui::VKEY_OEM_4
, false, false, false, true));
107 // Send browser back key on Linux/Windows.
108 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
109 GetPlatformAppWindow(), ui::VKEY_BROWSER_BACK
,
110 false, false, false, false));
114 void SendForwardShortcutToPlatformApp() {
115 #if defined(OS_MACOSX)
116 // Send Cmd+] on MacOSX.
117 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
118 GetPlatformAppWindow(), ui::VKEY_OEM_6
, false, false, false, true));
120 // Send browser back key on Linux/Windows.
121 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
122 GetPlatformAppWindow(), ui::VKEY_BROWSER_FORWARD
,
123 false, false, false, false));
127 void SendMouseEvent(ui_controls::MouseButton button
,
128 ui_controls::MouseButtonState state
) {
130 mouse_click_result_
= ui_test_utils::SendMouseEventsSync(button
,
132 first_click_
= false;
134 ASSERT_EQ(mouse_click_result_
, ui_test_utils::SendMouseEventsSync(
144 scoped_ptr
<ExtensionTestMessageListener
> RunAppHelper(
145 const std::string
& test_name
,
146 const std::string
& app_location
,
147 TestServer test_server
,
148 content::WebContents
** embedder_web_contents
) {
149 // For serving guest pages.
150 if ((test_server
== NEEDS_TEST_SERVER
) && !StartEmbeddedTestServer()) {
151 LOG(ERROR
) << "FAILED TO START TEST SERVER.";
152 return scoped_ptr
<ExtensionTestMessageListener
>();
155 ExtensionTestMessageListener
launched_listener("Launched", false);
156 LoadAndLaunchPlatformApp(app_location
.c_str());
157 if (!launched_listener
.WaitUntilSatisfied()) {
158 LOG(ERROR
) << "TEST DID NOT LAUNCH.";
159 return scoped_ptr
<ExtensionTestMessageListener
>();
162 if (!ui_test_utils::ShowAndFocusNativeWindow(GetPlatformAppWindow())) {
163 LOG(ERROR
) << "UNABLE TO FOCUS TEST WINDOW.";
164 return scoped_ptr
<ExtensionTestMessageListener
>();
167 // Flush any pending events to make sure we start with a clean slate.
168 content::RunAllPendingInMessageLoop();
170 *embedder_web_contents
= GetFirstAppWindowWebContents();
172 scoped_ptr
<ExtensionTestMessageListener
> done_listener(
173 new ExtensionTestMessageListener("TEST_PASSED", false));
174 done_listener
->set_failure_message("TEST_FAILED");
175 if (!content::ExecuteScript(
176 *embedder_web_contents
,
177 base::StringPrintf("runTest('%s')", test_name
.c_str()))) {
178 LOG(ERROR
) << "UNABLE TO START TEST";
179 return scoped_ptr
<ExtensionTestMessageListener
>();
182 return done_listener
.Pass();
185 void TestHelper(const std::string
& test_name
,
186 const std::string
& app_location
,
187 TestServer test_server
) {
188 content::WebContents
* embedder_web_contents
= NULL
;
189 scoped_ptr
<ExtensionTestMessageListener
> done_listener(
191 test_name
, app_location
, test_server
, &embedder_web_contents
));
193 ASSERT_TRUE(done_listener
);
194 ASSERT_TRUE(done_listener
->WaitUntilSatisfied());
197 void RunTest(const std::string
& app_name
) {
199 void SetupTest(const std::string
& app_name
,
200 const std::string
& guest_url_spec
) {
201 ASSERT_TRUE(StartEmbeddedTestServer());
202 GURL::Replacements replace_host
;
203 std::string
host_str("localhost"); // Must stay in scope with replace_host.
204 replace_host
.SetHostStr(host_str
);
206 GURL guest_url
= embedded_test_server()->GetURL(guest_url_spec
);
207 guest_url
= guest_url
.ReplaceComponents(replace_host
);
209 ui_test_utils::UrlLoadObserver
guest_observer(
210 guest_url
, content::NotificationService::AllSources());
212 ExtensionTestMessageListener
guest_connected_listener("connected", false);
213 LoadAndLaunchPlatformApp(app_name
.c_str());
215 guest_observer
.Wait();
217 // Wait until the guest process reports that it has established a message
218 // channel with the app.
219 ASSERT_TRUE(guest_connected_listener
.WaitUntilSatisfied());
220 content::Source
<content::NavigationController
> source
=
221 guest_observer
.source();
222 EXPECT_TRUE(source
->GetWebContents()->GetRenderProcessHost()->IsGuest());
224 guest_web_contents_
= source
->GetWebContents();
225 embedder_web_contents_
= guest_web_contents_
->GetEmbedderWebContents();
227 gfx::Rect offset
= embedder_web_contents_
->GetContainerBounds();
228 corner_
= gfx::Point(offset
.x(), offset
.y());
230 const testing::TestInfo
* const test_info
=
231 testing::UnitTest::GetInstance()->current_test_info();
232 const char* prefix
= "DragDropWithinWebView";
233 if (!strncmp(test_info
->name(), prefix
, strlen(prefix
))) {
234 // In the drag drop test we add 20px padding to the page body because on
235 // windows if we get too close to the edge of the window the resize cursor
236 // appears and we start dragging the window edge.
237 corner_
.Offset(20, 20);
241 content::WebContents
* guest_web_contents() {
242 return guest_web_contents_
;
245 content::WebContents
* embedder_web_contents() {
246 return embedder_web_contents_
;
249 gfx::Point
corner() {
253 void SimulateRWHMouseClick(content::RenderWidgetHost
* rwh
,
254 blink::WebMouseEvent::Button button
,
257 blink::WebMouseEvent mouse_event
;
258 mouse_event
.button
= button
;
259 mouse_event
.x
= mouse_event
.windowX
= x
;
260 mouse_event
.y
= mouse_event
.windowY
= y
;
261 mouse_event
.modifiers
= 0;
263 mouse_event
.type
= blink::WebInputEvent::MouseDown
;
264 rwh
->ForwardMouseEvent(mouse_event
);
265 mouse_event
.type
= blink::WebInputEvent::MouseUp
;
266 rwh
->ForwardMouseEvent(mouse_event
);
269 // TODO(lazyboy): implement
270 class PopupCreatedObserver
{
272 PopupCreatedObserver() : created_(false), last_render_widget_host_(NULL
) {
274 virtual ~PopupCreatedObserver() {
282 message_loop_
= new content::MessageLoopRunner
;
283 message_loop_
->Run();
285 content::RenderWidgetHost
* last_render_widget_host() {
286 return last_render_widget_host_
;
290 scoped_refptr
<content::MessageLoopRunner
> message_loop_
;
292 content::RenderWidgetHost
* last_render_widget_host_
;
295 void WaitForTitle(const char* title
) {
296 base::string16
expected_title(base::ASCIIToUTF16(title
));
297 base::string16
error_title(base::ASCIIToUTF16("FAILED"));
298 content::TitleWatcher
title_watcher(guest_web_contents(), expected_title
);
299 title_watcher
.AlsoWaitForTitle(error_title
);
300 ASSERT_EQ(expected_title
, title_watcher
.WaitAndGetTitle());
303 void PopupTestHelper(const gfx::Point
& padding
) {
304 PopupCreatedObserver popup_created_observer
;
305 popup_created_observer
.Reset();
307 content::SimulateKeyPress(
308 guest_web_contents(),
309 ui::VKEY_C
, // C to autocomplete.
310 false, false, false, false);
312 WaitForTitle("PASSED1");
314 popup_created_observer
.Start();
316 content::RenderWidgetHost
* popup_rwh
= NULL
;
317 popup_rwh
= popup_created_observer
.last_render_widget_host();
318 // Popup must be present.
319 ASSERT_TRUE(popup_rwh
);
320 ASSERT_TRUE(!popup_rwh
->IsRenderView());
321 ASSERT_TRUE(popup_rwh
->GetView());
323 base::string16 expected_title
= base::ASCIIToUTF16("PASSED2");
324 base::string16 error_title
= base::ASCIIToUTF16("FAILED");
325 content::TitleWatcher
title_watcher(guest_web_contents(), expected_title
);
326 title_watcher
.AlsoWaitForTitle(error_title
);
327 EXPECT_TRUE(content::ExecuteScript(guest_web_contents(),
329 ASSERT_EQ(expected_title
, title_watcher
.WaitAndGetTitle());
331 gfx::Rect popup_bounds
= popup_rwh
->GetView()->GetViewBounds();
332 // (2, 2) is expected to lie on the first datalist element.
333 SimulateRWHMouseClick(popup_rwh
, blink::WebMouseEvent::ButtonLeft
, 2, 2);
335 content::RenderViewHost
* embedder_rvh
=
336 GetFirstAppWindowWebContents()->GetRenderViewHost();
337 gfx::Rect embedder_bounds
= embedder_rvh
->GetView()->GetViewBounds();
338 gfx::Vector2d diff
= popup_bounds
.origin() - embedder_bounds
.origin();
339 LOG(INFO
) << "DIFF: x = " << diff
.x() << ", y = " << diff
.y();
341 const int left_spacing
= 40 + padding
.x(); // div.style.paddingLeft = 40px.
342 // div.style.paddingTop = 50px + (input box height = 26px).
343 const int top_spacing
= 50 + 26 + padding
.y();
345 // If the popup is placed within |threshold_px| of the expected position,
346 // then we consider the test as a pass.
347 const int threshold_px
= 10;
349 EXPECT_LE(std::abs(diff
.x() - left_spacing
), threshold_px
);
350 EXPECT_LE(std::abs(diff
.y() - top_spacing
), threshold_px
);
352 WaitForTitle("PASSED3");
355 void DragTestStep1() {
356 // Move mouse to start of text.
357 MoveMouseInsideWindow(gfx::Point(45, 8));
358 MoveMouseInsideWindow(gfx::Point(45, 9));
359 SendMouseEvent(ui_controls::LEFT
, ui_controls::DOWN
);
361 MoveMouseInsideWindow(gfx::Point(74, 12));
362 MoveMouseInsideWindow(gfx::Point(78, 12));
364 // Now wait a bit before moving mouse to initiate drag/drop.
365 base::MessageLoop::current()->PostDelayedTask(
367 base::Bind(&WebViewInteractiveTest::DragTestStep2
,
368 base::Unretained(this)),
369 base::TimeDelta::FromMilliseconds(200));
372 void DragTestStep2() {
373 // Drag source over target.
374 MoveMouseInsideWindow(gfx::Point(76, 76));
376 // Create a second mouse over the source to trigger the drag over event.
377 MoveMouseInsideWindow(gfx::Point(76, 77));
379 // Release mouse to drop.
380 SendMouseEvent(ui_controls::LEFT
, ui_controls::UP
);
381 SendMouseClick(ui_controls::LEFT
);
385 // Note that following ExtensionTestMessageListener and ExecuteScript*
386 // call must be after we quit |quit_closure_|. Otherwise the class
387 // here won't be able to receive messages sent by chrome.test.sendMessage.
388 // This is because of the nature of drag and drop code (esp. the
389 // MessageLoop) in it.
391 // Now check if we got a drop and read the drop data.
392 embedder_web_contents_
= GetFirstAppWindowWebContents();
393 ExtensionTestMessageListener
drop_listener("guest-got-drop", false);
394 EXPECT_TRUE(content::ExecuteScript(embedder_web_contents_
,
395 "window.checkIfGuestGotDrop()"));
396 EXPECT_TRUE(drop_listener
.WaitUntilSatisfied());
398 std::string last_drop_data
;
399 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
400 embedder_web_contents_
,
401 "window.domAutomationController.send(getLastDropData())",
404 last_drop_data_
= last_drop_data
;
408 content::WebContents
* guest_web_contents_
;
409 content::WebContents
* embedder_web_contents_
;
411 bool mouse_click_result_
;
413 // Only used in drag/drop test.
414 base::Closure quit_closure_
;
415 std::string last_drop_data_
;
418 // ui_test_utils::SendMouseMoveSync doesn't seem to work on OS_MACOSX, and
419 // likely won't work on many other platforms as well, so for now this test
420 // is for Windows and Linux only. As of Sept 17th, 2013 this test is disabled
421 // on Windows due to flakines, see http://crbug.com/293445.
423 // Disabled on Linux Aura because pointer lock does not work on Linux Aura.
426 #if defined(OS_LINUX) && !defined(USE_AURA)
428 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest
, PointerLock
) {
429 SetupTest("web_view/pointer_lock",
430 "/extensions/platform_apps/web_view/pointer_lock/guest.html");
432 // Move the mouse over the Lock Pointer button.
433 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(
434 gfx::Point(corner().x() + 75, corner().y() + 25)));
436 // Click the Lock Pointer button. The first two times the button is clicked
437 // the permission API will deny the request (intentional).
438 ExtensionTestMessageListener
exception_listener("request exception", false);
439 SendMouseClickWithListener(ui_controls::LEFT
, "lock error");
440 ASSERT_TRUE(exception_listener
.WaitUntilSatisfied());
441 SendMouseClickWithListener(ui_controls::LEFT
, "lock error");
443 // Click the Lock Pointer button, locking the mouse to lockTarget1.
444 SendMouseClickWithListener(ui_controls::LEFT
, "locked");
446 // Attempt to move the mouse off of the lock target, and onto lockTarget2,
447 // (which would trigger a test failure).
448 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(
449 gfx::Point(corner().x() + 74, corner().y() + 74)));
450 MoveMouseInsideWindowWithListener(gfx::Point(75, 75), "mouse-move");
453 // When the mouse is unlocked on win aura, sending a test mouse click clicks
454 // where the mouse moved to while locked. I was unable to figure out why, and
455 // since the issue only occurs with the test mouse events, just fix it with
456 // a simple workaround - moving the mouse back to where it should be.
457 // TODO(mthiesse): Fix Win Aura simulated mouse events while mouse locked.
458 MoveMouseInsideWindowWithListener(gfx::Point(75, 25), "mouse-move");
461 ExtensionTestMessageListener
unlocked_listener("unlocked", false);
462 // Send a key press to unlock the mouse.
463 SendKeyPressToPlatformApp(ui::VKEY_ESCAPE
);
465 // Wait for page to receive (successful) mouse unlock response.
466 ASSERT_TRUE(unlocked_listener
.WaitUntilSatisfied());
468 // After the second lock, guest.js sends a message to main.js to remove the
469 // webview object. main.js then removes the div containing the webview, which
470 // should unlock, and leave the mouse over the mousemove-capture-container
471 // div. We then move the mouse over that div to ensure the mouse was properly
472 // unlocked and that the div receieves the message.
473 ExtensionTestMessageListener
move_captured_listener("move-captured", false);
474 move_captured_listener
.set_failure_message("timeout");
476 // Mouse should already be over lock button (since we just unlocked), so send
477 // click to re-lock the mouse.
478 SendMouseClickWithListener(ui_controls::LEFT
, "deleted");
480 // A mousemove event is triggered on the mousemove-capture-container element
481 // when we delete the webview container (since the mouse moves onto the
482 // element), but just in case, send an explicit mouse movement to be safe.
483 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(
484 gfx::Point(corner().x() + 50, corner().y() + 10)));
486 // Wait for page to receive second (successful) mouselock response.
487 bool success
= move_captured_listener
.WaitUntilSatisfied();
489 fprintf(stderr
, "TIMEOUT - retrying\n");
490 // About 1 in 40 tests fail to detect mouse moves at this point (why?).
491 // Sending a right click seems to fix this (why?).
492 ExtensionTestMessageListener
move_listener2("move-captured", false);
493 SendMouseClick(ui_controls::RIGHT
);
494 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(
495 gfx::Point(corner().x() + 51, corner().y() + 11)));
496 ASSERT_TRUE(move_listener2
.WaitUntilSatisfied());
500 #endif // defined(OS_LINUX) && !defined(USE_AURA)
502 // Tests that setting focus on the <webview> sets focus on the guest.
503 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest
, Focus_FocusEvent
) {
504 TestHelper("testFocusEvent", "web_view/focus", NO_TEST_SERVER
);
507 // Tests that setting focus on the <webview> sets focus on the guest.
508 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest
, Focus_BlurEvent
) {
509 TestHelper("testBlurEvent", "web_view/focus", NO_TEST_SERVER
);
512 // Tests that guests receive edit commands and respond appropriately.
513 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest
, EditCommands
) {
514 ExtensionTestMessageListener
guest_connected_listener("connected", false);
515 LoadAndLaunchPlatformApp("web_view/edit_commands");
516 // Wait until the guest process reports that it has established a message
517 // channel with the app.
518 ASSERT_TRUE(guest_connected_listener
.WaitUntilSatisfied());
520 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(
521 GetPlatformAppWindow()));
523 // Flush any pending events to make sure we start with a clean slate.
524 content::RunAllPendingInMessageLoop();
526 ExtensionTestMessageListener
copy_listener("copy", false);
527 SendCopyKeyPressToPlatformApp();
529 // Wait for the guest to receive a 'copy' edit command.
530 ASSERT_TRUE(copy_listener
.WaitUntilSatisfied());
533 // Tests that guests receive edit commands and respond appropriately.
534 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest
, EditCommandsNoMenu
) {
535 SetupTest("web_view/edit_commands_no_menu",
536 "/extensions/platform_apps/web_view/edit_commands_no_menu/"
539 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(
540 GetPlatformAppWindow()));
542 // Flush any pending events to make sure we start with a clean slate.
543 content::RunAllPendingInMessageLoop();
545 ExtensionTestMessageListener
start_of_line_listener("StartOfLine", false);
546 SendStartOfLineKeyPressToPlatformApp();
547 // Wait for the guest to receive a 'copy' edit command.
548 ASSERT_TRUE(start_of_line_listener
.WaitUntilSatisfied());
551 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest
,
552 NewWindow_NewWindowNameTakesPrecedence
) {
553 TestHelper("testNewWindowNameTakesPrecedence",
554 "web_view/newwindow",
558 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest
,
559 NewWindow_WebViewNameTakesPrecedence
) {
560 TestHelper("testWebViewNameTakesPrecedence",
561 "web_view/newwindow",
565 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest
, NewWindow_NoName
) {
566 TestHelper("testNoName",
567 "web_view/newwindow",
571 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest
, NewWindow_Redirect
) {
572 TestHelper("testNewWindowRedirect",
573 "web_view/newwindow",
577 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest
, NewWindow_Close
) {
578 TestHelper("testNewWindowClose",
579 "web_view/newwindow",
583 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest
, NewWindow_ExecuteScript
) {
584 TestHelper("testNewWindowExecuteScript",
585 "web_view/newwindow",
589 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest
,
590 NewWindow_DeclarativeWebRequest
) {
591 TestHelper("testNewWindowDeclarativeWebRequest",
592 "web_view/newwindow",
596 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest
, NewWindow_WebRequest
) {
597 TestHelper("testNewWindowWebRequest",
598 "web_view/newwindow",
602 // A custom elements bug needs to be addressed to enable this test:
603 // See http://crbug.com/282477 for more information.
604 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest
,
605 DISABLED_NewWindow_WebRequestCloseWindow
) {
606 TestHelper("testNewWindowWebRequestCloseWindow",
607 "web_view/newwindow",
611 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest
,
612 NewWindow_WebRequestRemoveElement
) {
613 TestHelper("testNewWindowWebRequestRemoveElement",
614 "web_view/newwindow",
618 // Tests that Ctrl+Click/Cmd+Click on a link fires up the newwindow API.
619 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest
, NewWindow_OpenInNewTab
) {
620 content::WebContents
* embedder_web_contents
= NULL
;
622 ExtensionTestMessageListener
loaded_listener("Loaded", false);
623 scoped_ptr
<ExtensionTestMessageListener
> done_listener(
624 RunAppHelper("testNewWindowOpenInNewTab",
625 "web_view/newwindow",
627 &embedder_web_contents
));
629 loaded_listener
.WaitUntilSatisfied();
630 #if defined(OS_MACOSX)
631 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
632 GetPlatformAppWindow(), ui::VKEY_RETURN
,
633 false, false, false, true /* cmd */));
635 ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
636 GetPlatformAppWindow(), ui::VKEY_RETURN
,
637 true /* ctrl */, false, false, false));
640 // Wait for the embedder to receive a 'newwindow' event.
641 ASSERT_TRUE(done_listener
->WaitUntilSatisfied());
645 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest
, ExecuteCode
) {
646 ASSERT_TRUE(RunPlatformAppTestWithArg(
647 "platform_apps/web_view/common", "execute_code")) << message_
;
650 // This test used the old Autofill UI, which has been removed.
651 // See crbug.com/259438
652 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest
, DISABLED_PopupPositioning
) {
654 "web_view/popup_positioning",
655 "/extensions/platform_apps/web_view/popup_positioning/guest.html");
656 ASSERT_TRUE(guest_web_contents());
658 PopupTestHelper(gfx::Point());
660 // moveTo a random location and run the steps again.
661 EXPECT_TRUE(content::ExecuteScript(embedder_web_contents(),
662 "window.moveTo(16, 20);"));
663 PopupTestHelper(gfx::Point());
666 // Tests that moving browser plugin (without resize/UpdateRects) correctly
667 // repositions popup.
668 // Started flakily failing after a Blink roll: http://crbug.com/245332
669 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest
, DISABLED_PopupPositioningMoved
) {
671 "web_view/popup_positioning_moved",
672 "/extensions/platform_apps/web_view/popup_positioning_moved"
674 ASSERT_TRUE(guest_web_contents());
676 PopupTestHelper(gfx::Point(20, 0));
679 // Drag and drop inside a webview is currently only enabled for linux and mac,
680 // but the tests don't work on anything except chromeos for now. This is because
681 // of simulating mouse drag code's dependency on platforms.
682 #if defined(OS_CHROMEOS)
683 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest
, DragDropWithinWebView
) {
684 ExtensionTestMessageListener
guest_connected_listener("connected", false);
685 LoadAndLaunchPlatformApp("web_view/dnd_within_webview");
686 ASSERT_TRUE(guest_connected_listener
.WaitUntilSatisfied());
688 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(GetPlatformAppWindow()));
690 embedder_web_contents_
= GetFirstAppWindowWebContents();
691 gfx::Rect offset
= embedder_web_contents_
->GetContainerBounds();
692 corner_
= gfx::Point(offset
.x(), offset
.y());
694 // In the drag drop test we add 20px padding to the page body because on
695 // windows if we get too close to the edge of the window the resize cursor
696 // appears and we start dragging the window edge.
697 corner_
.Offset(20, 20);
699 // Flush any pending events to make sure we start with a clean slate.
700 content::RunAllPendingInMessageLoop();
702 base::RunLoop run_loop
;
703 quit_closure_
= run_loop
.QuitClosure();
704 base::MessageLoop::current()->PostTask(
706 base::Bind(&WebViewInteractiveTest::DragTestStep1
,
707 base::Unretained(this)));
710 if (last_drop_data_
== "Drop me")
713 LOG(INFO
) << "Drag was cancelled in interactive_test, restarting drag";
715 // Reset state for next try.
716 ExtensionTestMessageListener
reset_listener("resetStateReply", false);
717 EXPECT_TRUE(content::ExecuteScript(embedder_web_contents_
,
718 "window.resetState()"));
719 ASSERT_TRUE(reset_listener
.WaitUntilSatisfied());
721 ASSERT_EQ("Drop me", last_drop_data_
);
723 #endif // (defined(OS_CHROMEOS))
725 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest
, Navigation
) {
726 TestHelper("testNavigation", "web_view/navigation", NO_TEST_SERVER
);
729 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest
, Navigation_BackForwardKeys
) {
730 ExtensionTestMessageListener
launched_listener("Launched", false);
731 LoadAndLaunchPlatformApp("web_view/navigation");
732 ASSERT_TRUE(launched_listener
.WaitUntilSatisfied());
734 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(
735 GetPlatformAppWindow()));
736 // Flush any pending events to make sure we start with a clean slate.
737 content::RunAllPendingInMessageLoop();
739 content::WebContents
* embedder_web_contents
= GetFirstAppWindowWebContents();
740 ASSERT_TRUE(embedder_web_contents
);
742 ExtensionTestMessageListener
done_listener(
743 "TEST_PASSED", false);
744 done_listener
.set_failure_message("TEST_FAILED");
745 ExtensionTestMessageListener
ready_back_key_listener(
746 "ReadyForBackKey", false);
747 ExtensionTestMessageListener
ready_forward_key_listener(
748 "ReadyForForwardKey", false);
750 EXPECT_TRUE(content::ExecuteScript(
751 embedder_web_contents
,
752 "runTest('testBackForwardKeys')"));
754 ASSERT_TRUE(ready_back_key_listener
.WaitUntilSatisfied());
755 SendBackShortcutToPlatformApp();
757 ASSERT_TRUE(ready_forward_key_listener
.WaitUntilSatisfied());
758 SendForwardShortcutToPlatformApp();
760 ASSERT_TRUE(done_listener
.WaitUntilSatisfied());
763 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest
,
764 PointerLock_PointerLockLostWithFocus
) {
765 TestHelper("testPointerLockLostWithFocus",
766 "web_view/pointerlock",
770 #if defined(OS_MACOSX)
771 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest
, TextSelection
) {
772 SetupTest("web_view/text_selection",
773 "/extensions/platform_apps/web_view/text_selection/guest.html");
774 ASSERT_TRUE(guest_web_contents());
775 ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(
776 GetPlatformAppWindow()));
778 // Wait until guest sees a context menu, select an arbitrary item (copy).
779 ExtensionTestMessageListener
ctx_listener("MSG_CONTEXTMENU", false);
780 ContextMenuNotificationObserver
menu_observer(IDC_CONTENT_CONTEXT_COPY
);
781 SimulateRWHMouseClick(guest_web_contents()->GetRenderViewHost(),
782 blink::WebMouseEvent::ButtonRight
, 20, 20);
783 ASSERT_TRUE(ctx_listener
.WaitUntilSatisfied());
785 // Now verify that the selection text propagates properly to RWHV.
786 content::RenderWidgetHostView
* guest_rwhv
=
787 guest_web_contents()->GetRenderWidgetHostView();
788 ASSERT_TRUE(guest_rwhv
);
789 std::string selected_text
= base::UTF16ToUTF8(guest_rwhv
->GetSelectedText());
790 ASSERT_TRUE(selected_text
.size() >= 10u);
791 ASSERT_EQ("AAAAAAAAAA", selected_text
.substr(0, 10));