Home | History | Annotate | Download | only in extensions
      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.
      4 
      5 #include "apps/shell_window.h"
      6 #include "apps/shell_window_registry.h"
      7 #include "base/strings/stringprintf.h"
      8 #include "base/strings/utf_string_conversions.h"
      9 #include "chrome/browser/extensions/extension_test_message_listener.h"
     10 #include "chrome/browser/extensions/platform_app_browsertest_util.h"
     11 #include "chrome/test/base/interactive_test_utils.h"
     12 #include "chrome/test/base/test_launcher_utils.h"
     13 #include "chrome/test/base/ui_test_utils.h"
     14 #include "content/public/browser/notification_service.h"
     15 #include "content/public/browser/render_process_host.h"
     16 #include "content/public/browser/render_view_host.h"
     17 #include "content/public/browser/render_widget_host_view.h"
     18 #include "content/public/browser/web_contents.h"
     19 #include "content/public/browser/web_contents_view.h"
     20 #include "content/public/common/content_switches.h"
     21 #include "content/public/test/browser_test_utils.h"
     22 #include "net/test/embedded_test_server/embedded_test_server.h"
     23 #include "ui/base/keycodes/keyboard_codes.h"
     24 #include "ui/base/test/ui_controls.h"
     25 
     26 using apps::ShellWindow;
     27 
     28 class WebViewInteractiveTest
     29     : public extensions::PlatformAppBrowserTest {
     30  public:
     31   WebViewInteractiveTest()
     32       : corner_(gfx::Point()),
     33         mouse_click_result_(false),
     34         first_click_(true) {}
     35 
     36   void MoveMouseInsideWindowWithListener(gfx::Point point,
     37                                          const std::string& message) {
     38     ExtensionTestMessageListener move_listener(message, false);
     39     ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(
     40         gfx::Point(corner_.x() + point.x(), corner_.y() + point.y())));
     41     ASSERT_TRUE(move_listener.WaitUntilSatisfied());
     42   }
     43 
     44   void SendMouseClickWithListener(ui_controls::MouseButton button,
     45                                   const std::string& message) {
     46     ExtensionTestMessageListener listener(message, false);
     47     SendMouseClick(button);
     48     ASSERT_TRUE(listener.WaitUntilSatisfied());
     49   }
     50 
     51   void SendMouseClick(ui_controls::MouseButton button) {
     52     SendMouseEvent(button, ui_controls::DOWN);
     53     SendMouseEvent(button, ui_controls::UP);
     54   }
     55 
     56   void MoveMouseInsideWindow(const gfx::Point& point) {
     57     ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(
     58         gfx::Point(corner_.x() + point.x(), corner_.y() + point.y())));
     59   }
     60 
     61   gfx::NativeWindow GetPlatformAppWindow() {
     62     const apps::ShellWindowRegistry::ShellWindowList& shell_windows =
     63         apps::ShellWindowRegistry::Get(
     64             browser()->profile())->shell_windows();
     65     return (*shell_windows.begin())->GetNativeWindow();
     66   }
     67 
     68   void SendKeyPressToPlatformApp(ui::KeyboardCode key) {
     69     ASSERT_EQ(1U, GetShellWindowCount());
     70     ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
     71         GetPlatformAppWindow(), key, false, false, false, false));
     72   }
     73 
     74   void SendCopyKeyPressToPlatformApp() {
     75     ASSERT_EQ(1U, GetShellWindowCount());
     76 #if defined(OS_MACOSX)
     77     // Send Cmd+C on MacOSX.
     78     ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
     79         GetPlatformAppWindow(), ui::VKEY_C, false, false, false, true));
     80 #else
     81     // Send Ctrl+C on Windows and Linux/ChromeOS.
     82     ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
     83         GetPlatformAppWindow(), ui::VKEY_C, true, false, false, false));
     84 #endif
     85   }
     86 
     87   void SendStartOfLineKeyPressToPlatformApp() {
     88 #if defined(OS_MACOSX)
     89     // Send Cmd+Left on MacOSX.
     90     ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
     91         GetPlatformAppWindow(), ui::VKEY_LEFT, false, false, false, true));
     92 #else
     93     // Send Ctrl+Left on Windows and Linux/ChromeOS.
     94     ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
     95         GetPlatformAppWindow(), ui::VKEY_LEFT, true, false, false, false));
     96 #endif
     97   }
     98 
     99   void SendBackShortcutToPlatformApp() {
    100 #if defined(OS_MACOSX)
    101     // Send Cmd+[ on MacOSX.
    102     ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
    103         GetPlatformAppWindow(), ui::VKEY_OEM_4, false, false, false, true));
    104 #else
    105     // Send browser back key on Linux/Windows.
    106     ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
    107         GetPlatformAppWindow(), ui::VKEY_BROWSER_BACK,
    108         false, false, false, false));
    109 #endif
    110   }
    111 
    112   void SendForwardShortcutToPlatformApp() {
    113 #if defined(OS_MACOSX)
    114     // Send Cmd+] on MacOSX.
    115     ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
    116         GetPlatformAppWindow(), ui::VKEY_OEM_6, false, false, false, true));
    117 #else
    118     // Send browser back key on Linux/Windows.
    119     ASSERT_TRUE(ui_test_utils::SendKeyPressToWindowSync(
    120         GetPlatformAppWindow(), ui::VKEY_BROWSER_FORWARD,
    121         false, false, false, false));
    122 #endif
    123   }
    124 
    125   void SendMouseEvent(ui_controls::MouseButton button,
    126                       ui_controls::MouseButtonState state) {
    127     if (first_click_) {
    128       mouse_click_result_ = ui_test_utils::SendMouseEventsSync(button,
    129                                                                 state);
    130       first_click_ = false;
    131     } else {
    132       ASSERT_EQ(mouse_click_result_, ui_test_utils::SendMouseEventsSync(
    133           button, state));
    134     }
    135   }
    136 
    137   void TestHelper(const std::string& test_name,
    138                   const std::string& test_passed_msg,
    139                   const std::string& test_failed_msg,
    140                   const std::string& app_location) {
    141     ASSERT_TRUE(StartEmbeddedTestServer());  // For serving guest pages.
    142     ExtensionTestMessageListener launched_listener("Launched", false);
    143     LoadAndLaunchPlatformApp(app_location.c_str());
    144     ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
    145 
    146     ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(
    147         GetPlatformAppWindow()));
    148 
    149     // Flush any pending events to make sure we start with a clean slate.
    150     content::RunAllPendingInMessageLoop();
    151 
    152     content::WebContents* embedder_web_contents =
    153         GetFirstShellWindowWebContents();
    154     ASSERT_TRUE(embedder_web_contents);
    155 
    156     ExtensionTestMessageListener done_listener(test_passed_msg, false);
    157     done_listener.AlsoListenForFailureMessage(test_failed_msg);
    158     EXPECT_TRUE(content::ExecuteScript(
    159                     embedder_web_contents,
    160                     base::StringPrintf("runTest('%s')", test_name.c_str())));
    161     ASSERT_TRUE(done_listener.WaitUntilSatisfied());
    162   }
    163 
    164   void SetupTest(const std::string& app_name,
    165                  const std::string& guest_url_spec) {
    166     ASSERT_TRUE(StartEmbeddedTestServer());
    167     GURL::Replacements replace_host;
    168     std::string host_str("localhost");  // Must stay in scope with replace_host.
    169     replace_host.SetHostStr(host_str);
    170 
    171     GURL guest_url = embedded_test_server()->GetURL(guest_url_spec);
    172     guest_url = guest_url.ReplaceComponents(replace_host);
    173 
    174     ui_test_utils::UrlLoadObserver guest_observer(
    175         guest_url, content::NotificationService::AllSources());
    176 
    177     ExtensionTestMessageListener guest_connected_listener("connected", false);
    178     LoadAndLaunchPlatformApp(app_name.c_str());
    179 
    180     guest_observer.Wait();
    181 
    182     // Wait until the guest process reports that it has established a message
    183     // channel with the app.
    184     ASSERT_TRUE(guest_connected_listener.WaitUntilSatisfied());
    185     content::Source<content::NavigationController> source =
    186         guest_observer.source();
    187     EXPECT_TRUE(source->GetWebContents()->GetRenderProcessHost()->IsGuest());
    188 
    189     guest_web_contents_ = source->GetWebContents();
    190     embedder_web_contents_ = guest_web_contents_->GetEmbedderWebContents();
    191 
    192     gfx::Rect offset;
    193     embedder_web_contents_->GetView()->GetContainerBounds(&offset);
    194     corner_ = gfx::Point(offset.x(), offset.y());
    195 
    196     const testing::TestInfo* const test_info =
    197             testing::UnitTest::GetInstance()->current_test_info();
    198     const std::string& prefix = "DragDropWithinWebView";
    199     if (!strncmp(test_info->name(), prefix.c_str(), prefix.size())) {
    200       // In the drag drop test we add 20px padding to the page body because on
    201       // windows if we get too close to the edge of the window the resize cursor
    202       // appears and we start dragging the window edge.
    203       corner_.Offset(20, 20);
    204     }
    205   }
    206 
    207   content::WebContents* guest_web_contents() {
    208     return guest_web_contents_;
    209   }
    210 
    211   content::WebContents* embedder_web_contents() {
    212     return embedder_web_contents_;
    213   }
    214 
    215   gfx::Point corner() {
    216     return corner_;
    217   }
    218 
    219   void SimulateRWHMouseClick(content::RenderWidgetHost* rwh, int x, int y) {
    220     WebKit::WebMouseEvent mouse_event;
    221     mouse_event.button = WebKit::WebMouseEvent::ButtonLeft;
    222     mouse_event.x = mouse_event.windowX = x;
    223     mouse_event.y = mouse_event.windowY = y;
    224     mouse_event.modifiers = 0;
    225 
    226     mouse_event.type = WebKit::WebInputEvent::MouseDown;
    227     rwh->ForwardMouseEvent(mouse_event);
    228     mouse_event.type = WebKit::WebInputEvent::MouseUp;
    229     rwh->ForwardMouseEvent(mouse_event);
    230   }
    231 
    232   class PopupCreatedObserver {
    233    public:
    234     PopupCreatedObserver() : created_(false), last_render_widget_host_(NULL) {
    235       created_callback_ = base::Bind(
    236           &PopupCreatedObserver::CreatedCallback, base::Unretained(this));
    237       content::RenderWidgetHost::AddCreatedCallback(created_callback_);
    238     }
    239     virtual ~PopupCreatedObserver() {
    240       content::RenderWidgetHost::RemoveCreatedCallback(created_callback_);
    241     }
    242     void Reset() {
    243       created_ = false;
    244     }
    245     void Start() {
    246       if (created_)
    247         return;
    248       message_loop_ = new content::MessageLoopRunner;
    249       message_loop_->Run();
    250     }
    251     content::RenderWidgetHost* last_render_widget_host() {
    252       return last_render_widget_host_;
    253     }
    254 
    255    private:
    256     void CreatedCallback(content::RenderWidgetHost* rwh) {
    257       last_render_widget_host_ = rwh;
    258       if (message_loop_.get())
    259         message_loop_->Quit();
    260       else
    261         created_ = true;
    262     }
    263     content::RenderWidgetHost::CreatedCallback created_callback_;
    264     scoped_refptr<content::MessageLoopRunner> message_loop_;
    265     bool created_;
    266     content::RenderWidgetHost* last_render_widget_host_;
    267   };
    268 
    269   void WaitForTitle(const char* title) {
    270     string16 expected_title(ASCIIToUTF16(title));
    271     string16 error_title(ASCIIToUTF16("FAILED"));
    272     content::TitleWatcher title_watcher(guest_web_contents(), expected_title);
    273     title_watcher.AlsoWaitForTitle(error_title);
    274     ASSERT_EQ(expected_title, title_watcher.WaitAndGetTitle());
    275   }
    276 
    277   void PopupTestHelper(const gfx::Point& padding) {
    278     PopupCreatedObserver popup_created_observer;
    279     popup_created_observer.Reset();
    280 
    281     content::SimulateKeyPress(
    282         guest_web_contents(),
    283         ui::VKEY_C,  // C to autocomplete.
    284         false, false, false, false);
    285 
    286     WaitForTitle("PASSED1");
    287 
    288     popup_created_observer.Start();
    289 
    290     content::RenderWidgetHost* popup_rwh = NULL;
    291     popup_rwh = popup_created_observer.last_render_widget_host();
    292     // Popup must be present.
    293     ASSERT_TRUE(popup_rwh);
    294     ASSERT_TRUE(!popup_rwh->IsRenderView());
    295     ASSERT_TRUE(popup_rwh->GetView());
    296 
    297     string16 expected_title = ASCIIToUTF16("PASSED2");
    298     string16 error_title = ASCIIToUTF16("FAILED");
    299     content::TitleWatcher title_watcher(guest_web_contents(), expected_title);
    300     title_watcher.AlsoWaitForTitle(error_title);
    301     EXPECT_TRUE(content::ExecuteScript(guest_web_contents(),
    302                                        "changeTitle();"));
    303     ASSERT_EQ(expected_title, title_watcher.WaitAndGetTitle());
    304 
    305     gfx::Rect popup_bounds = popup_rwh->GetView()->GetViewBounds();
    306     // (2, 2) is expected to lie on the first datalist element.
    307     SimulateRWHMouseClick(popup_rwh, 2, 2);
    308 
    309     content::RenderViewHost* embedder_rvh =
    310         GetFirstShellWindowWebContents()->GetRenderViewHost();
    311     gfx::Rect embedder_bounds = embedder_rvh->GetView()->GetViewBounds();
    312     gfx::Vector2d diff = popup_bounds.origin() - embedder_bounds.origin();
    313     LOG(INFO) << "DIFF: x = " << diff.x() << ", y = " << diff.y();
    314 
    315     const int left_spacing = 40 + padding.x();  // div.style.paddingLeft = 40px.
    316     // div.style.paddingTop = 50px + (input box height = 26px).
    317     const int top_spacing = 50 + 26 + padding.y();
    318 
    319     // If the popup is placed within |threshold_px| of the expected position,
    320     // then we consider the test as a pass.
    321     const int threshold_px = 10;
    322 
    323     EXPECT_LE(std::abs(diff.x() - left_spacing), threshold_px);
    324     EXPECT_LE(std::abs(diff.y() - top_spacing), threshold_px);
    325 
    326     WaitForTitle("PASSED3");
    327   }
    328 
    329   void DragTestStep1() {
    330     // Move mouse to start of text.
    331     MoveMouseInsideWindow(gfx::Point(45, 8));
    332     SendMouseEvent(ui_controls::LEFT, ui_controls::DOWN);
    333     MoveMouseInsideWindow(gfx::Point(76, 12));
    334 
    335     // Now wait a bit before moving mouse to initiate drag/drop.
    336     base::MessageLoop::current()->PostDelayedTask(
    337         FROM_HERE,
    338         base::Bind(&WebViewInteractiveTest::DragTestStep2,
    339                    base::Unretained(this)),
    340         base::TimeDelta::FromMilliseconds(200));
    341   }
    342 
    343   void DragTestStep2() {
    344     // Drag source over target.
    345     MoveMouseInsideWindow(gfx::Point(76, 76));
    346 
    347     // Create a second mouse over the source to trigger the drag over event.
    348     MoveMouseInsideWindow(gfx::Point(76, 77));
    349 
    350     // Release mouse to drop.
    351     SendMouseEvent(ui_controls::LEFT, ui_controls::UP);
    352     SendMouseClick(ui_controls::LEFT);
    353 
    354     quit_closure_.Run();
    355 
    356     // Note that following ExtensionTestMessageListener and ExecuteScript*
    357     // call must be after we quit |quit_closure_|. Otherwise the class
    358     // here won't be able to receive messages sent by chrome.test.sendMessage.
    359     // This is because of the nature of drag and drop code (esp. the
    360     // MessageLoop) in it.
    361 
    362     // Now verify we got a drop and correct drop data.
    363     ExtensionTestMessageListener drop_listener("guest-got-drop", false);
    364     EXPECT_TRUE(content::ExecuteScript(guest_web_contents_,
    365                                        "window.pingEmbedder()"));
    366     EXPECT_TRUE(drop_listener.WaitUntilSatisfied());
    367 
    368     std::string last_drop_data;
    369     EXPECT_TRUE(content::ExecuteScriptAndExtractString(
    370         embedder_web_contents_,
    371         "window.domAutomationController.send(getLastDropData())",
    372         &last_drop_data));
    373     EXPECT_EQ(last_drop_data, "Drop me");
    374   }
    375 
    376  protected:
    377   virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
    378     command_line->AppendSwitch(switches::kEnableBrowserPluginDragDrop);
    379     extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line);
    380   }
    381 
    382   content::WebContents* guest_web_contents_;
    383   content::WebContents* embedder_web_contents_;
    384   gfx::Point corner_;
    385   bool mouse_click_result_;
    386   bool first_click_;
    387   // Only used in drag/drop test.
    388   base::Closure quit_closure_;
    389 };
    390 
    391 // ui_test_utils::SendMouseMoveSync doesn't seem to work on OS_MACOSX, and
    392 // likely won't work on many other platforms as well, so for now this test
    393 // is for Windows and Linux only.
    394 #if (defined(OS_WIN) || defined(OS_LINUX))
    395 
    396 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, PointerLock) {
    397   SetupTest("web_view/pointer_lock",
    398             "/extensions/platform_apps/web_view/pointer_lock/guest.html");
    399 
    400   // Move the mouse over the Lock Pointer button.
    401   ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(
    402       gfx::Point(corner().x() + 75, corner().y() + 25)));
    403 
    404   // Click the Lock Pointer button. The first two times the button is clicked
    405   // the permission API will deny the request (intentional).
    406   ExtensionTestMessageListener exception_listener("request exception", false);
    407   SendMouseClickWithListener(ui_controls::LEFT, "lock error");
    408   ASSERT_TRUE(exception_listener.WaitUntilSatisfied());
    409   SendMouseClickWithListener(ui_controls::LEFT, "lock error");
    410 
    411   // Click the Lock Pointer button, locking the mouse to lockTarget1.
    412   SendMouseClickWithListener(ui_controls::LEFT, "locked");
    413 
    414   // Attempt to move the mouse off of the lock target, and onto lockTarget2,
    415   // (which would trigger a test failure).
    416   ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(
    417       gfx::Point(corner().x() + 74, corner().y() + 74)));
    418   MoveMouseInsideWindowWithListener(gfx::Point(75, 75), "mouse-move");
    419 
    420 #if (defined(OS_WIN) && defined(USE_AURA))
    421   // When the mouse is unlocked on win aura, sending a test mouse click clicks
    422   // where the mouse moved to while locked. I was unable to figure out why, and
    423   // since the issue only occurs with the test mouse events, just fix it with
    424   // a simple workaround - moving the mouse back to where it should be.
    425   // TODO(mthiesse): Fix Win Aura simulated mouse events while mouse locked.
    426   MoveMouseInsideWindowWithListener(gfx::Point(75, 25), "mouse-move");
    427 #endif
    428 
    429   ExtensionTestMessageListener unlocked_listener("unlocked", false);
    430   // Send a key press to unlock the mouse.
    431   SendKeyPressToPlatformApp(ui::VKEY_ESCAPE);
    432 
    433   // Wait for page to receive (successful) mouse unlock response.
    434   ASSERT_TRUE(unlocked_listener.WaitUntilSatisfied());
    435 
    436   // After the second lock, guest.js sends a message to main.js to remove the
    437   // webview object. main.js then removes the div containing the webview, which
    438   // should unlock, and leave the mouse over the mousemove-capture-container
    439   // div. We then move the mouse over that div to ensure the mouse was properly
    440   // unlocked and that the div receieves the message.
    441   ExtensionTestMessageListener move_captured_listener("move-captured", false);
    442   move_captured_listener.AlsoListenForFailureMessage("timeout");
    443 
    444   // Mouse should already be over lock button (since we just unlocked), so send
    445   // click to re-lock the mouse.
    446   SendMouseClickWithListener(ui_controls::LEFT, "deleted");
    447 
    448   // A mousemove event is triggered on the mousemove-capture-container element
    449   // when we delete the webview container (since the mouse moves onto the
    450   // element), but just in case, send an explicit mouse movement to be safe.
    451   ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(
    452       gfx::Point(corner().x() + 50, corner().y() + 10)));
    453 
    454   // Wait for page to receive second (successful) mouselock response.
    455   bool success = move_captured_listener.WaitUntilSatisfied();
    456   if (!success) {
    457     fprintf(stderr, "TIMEOUT - retrying\n");
    458     // About 1 in 40 tests fail to detect mouse moves at this point (why?).
    459     // Sending a right click seems to fix this (why?).
    460     ExtensionTestMessageListener move_listener2("move-captured", false);
    461     SendMouseClick(ui_controls::RIGHT);
    462     ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(
    463         gfx::Point(corner().x() + 51, corner().y() + 11)));
    464     ASSERT_TRUE(move_listener2.WaitUntilSatisfied());
    465   }
    466 }
    467 
    468 #endif  // (defined(OS_WIN) || defined(OS_LINUX))
    469 
    470 // Tests that setting focus on the <webview> sets focus on the guest.
    471 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, DISABLED_Focus) {
    472   ASSERT_TRUE(StartEmbeddedTestServer());  // For serving guest pages.
    473   ASSERT_TRUE(RunPlatformAppTest("platform_apps/web_view/focus"))
    474       << message_;
    475 }
    476 
    477 // Tests that guests receive edit commands and respond appropriately.
    478 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, EditCommands) {
    479   SetupTest("web_view/edit_commands",
    480             "/extensions/platform_apps/web_view/edit_commands/guest.html");
    481 
    482   ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(
    483       GetPlatformAppWindow()));
    484 
    485   // Flush any pending events to make sure we start with a clean slate.
    486   content::RunAllPendingInMessageLoop();
    487 
    488   ExtensionTestMessageListener copy_listener("copy", false);
    489   SendCopyKeyPressToPlatformApp();
    490 
    491   // Wait for the guest to receive a 'copy' edit command.
    492   ASSERT_TRUE(copy_listener.WaitUntilSatisfied());
    493 }
    494 
    495 // Tests that guests receive edit commands and respond appropriately.
    496 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, EditCommandsNoMenu) {
    497   SetupTest("web_view/edit_commands_no_menu",
    498       "/extensions/platform_apps/web_view/edit_commands_no_menu/"
    499       "guest.html");
    500 
    501   ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(
    502       GetPlatformAppWindow()));
    503 
    504   // Flush any pending events to make sure we start with a clean slate.
    505   content::RunAllPendingInMessageLoop();
    506 
    507   ExtensionTestMessageListener start_of_line_listener("StartOfLine", false);
    508   SendStartOfLineKeyPressToPlatformApp();
    509   // Wait for the guest to receive a 'copy' edit command.
    510   ASSERT_TRUE(start_of_line_listener.WaitUntilSatisfied());
    511 }
    512 
    513 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest,
    514                        NewWindow_NewWindowNameTakesPrecedence) {
    515   TestHelper("testNewWindowNameTakesPrecedence",
    516              "DoneNewWindowTest.PASSED",
    517              "DoneNewWindowTest.FAILED",
    518              "web_view/newwindow");
    519 }
    520 
    521 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest,
    522                        NewWindow_WebViewNameTakesPrecedence) {
    523   TestHelper("testWebViewNameTakesPrecedence",
    524              "DoneNewWindowTest.PASSED",
    525              "DoneNewWindowTest.FAILED",
    526              "web_view/newwindow");
    527 }
    528 
    529 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, NewWindow_NoName) {
    530   TestHelper("testNoName",
    531              "DoneNewWindowTest.PASSED",
    532              "DoneNewWindowTest.FAILED",
    533              "web_view/newwindow");
    534 }
    535 
    536 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, NewWindow_Redirect) {
    537   TestHelper("testNewWindowRedirect",
    538              "DoneNewWindowTest.PASSED",
    539              "DoneNewWindowTest.FAILED",
    540              "web_view/newwindow");
    541 }
    542 
    543 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, NewWindow_Close) {
    544   TestHelper("testNewWindowClose",
    545              "DoneNewWindowTest.PASSED",
    546              "DoneNewWindowTest.FAILED",
    547              "web_view/newwindow");
    548 }
    549 
    550 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, NewWindow_ExecuteScript) {
    551   TestHelper("testNewWindowExecuteScript",
    552              "DoneNewWindowTest.PASSED",
    553              "DoneNewWindowTest.FAILED",
    554              "web_view/newwindow");
    555 }
    556 
    557 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, NewWindow_WebRequest) {
    558   TestHelper("testNewWindowWebRequest",
    559              "DoneNewWindowTest.PASSED",
    560              "DoneNewWindowTest.FAILED",
    561              "web_view/newwindow");
    562 }
    563 
    564 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, ExecuteCode) {
    565   ASSERT_TRUE(StartEmbeddedTestServer());  // For serving guest pages.
    566   ASSERT_TRUE(RunPlatformAppTestWithArg(
    567       "platform_apps/web_view/common", "execute_code")) << message_;
    568 }
    569 
    570 // This test used the old Autofill UI, which has been removed.
    571 // See crbug.com/259438
    572 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, DISABLED_PopupPositioning) {
    573   SetupTest(
    574       "web_view/popup_positioning",
    575       "/extensions/platform_apps/web_view/popup_positioning/guest.html");
    576   ASSERT_TRUE(guest_web_contents());
    577 
    578   PopupTestHelper(gfx::Point());
    579 
    580   // moveTo a random location and run the steps again.
    581   EXPECT_TRUE(content::ExecuteScript(embedder_web_contents(),
    582                                      "window.moveTo(16, 20);"));
    583   PopupTestHelper(gfx::Point());
    584 }
    585 
    586 // Tests that moving browser plugin (without resize/UpdateRects) correctly
    587 // repositions popup.
    588 // Started flakily failing after a Blink roll: http://crbug.com/245332
    589 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, DISABLED_PopupPositioningMoved) {
    590   SetupTest(
    591       "web_view/popup_positioning_moved",
    592       "/extensions/platform_apps/web_view/popup_positioning_moved"
    593       "/guest.html");
    594   ASSERT_TRUE(guest_web_contents());
    595 
    596   PopupTestHelper(gfx::Point(20, 0));
    597 }
    598 
    599 // Drag and drop inside a webview is currently only enabled for linux and mac,
    600 // but the tests don't work on anything except chromeos for now. This is because
    601 // of simulating mouse drag code's dependency on platforms.
    602 #if defined(OS_CHROMEOS)
    603 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, DragDropWithinWebView) {
    604   SetupTest(
    605       "web_view/dnd_within_webview",
    606       "/extensions/platform_apps/web_view/dnd_within_webview/guest.html");
    607   ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(GetPlatformAppWindow()));
    608 
    609   // Flush any pending events to make sure we start with a clean slate.
    610   content::RunAllPendingInMessageLoop();
    611   base::RunLoop run_loop;
    612   quit_closure_ = run_loop.QuitClosure();
    613   base::MessageLoop::current()->PostTask(
    614       FROM_HERE,
    615       base::Bind(&WebViewInteractiveTest::DragTestStep1,
    616                  base::Unretained(this)));
    617   run_loop.Run();
    618 }
    619 #endif  // (defined(OS_CHROMEOS))
    620 
    621 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, Navigation) {
    622   TestHelper("testNavigation",
    623              "DoneNavigationTest.PASSED",
    624              "DoneNavigationTest.FAILED",
    625              "web_view/navigation");
    626 }
    627 
    628 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest, Navigation_BackForwardKeys) {
    629   ASSERT_TRUE(StartEmbeddedTestServer());  // For serving guest pages.
    630   ExtensionTestMessageListener launched_listener("Launched", false);
    631   LoadAndLaunchPlatformApp("web_view/navigation");
    632   ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
    633 
    634   ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(
    635       GetPlatformAppWindow()));
    636   // Flush any pending events to make sure we start with a clean slate.
    637   content::RunAllPendingInMessageLoop();
    638 
    639   content::WebContents* embedder_web_contents =
    640       GetFirstShellWindowWebContents();
    641   ASSERT_TRUE(embedder_web_contents);
    642 
    643   ExtensionTestMessageListener done_listener(
    644       "DoneNavigationTest.PASSED", false);
    645   done_listener.AlsoListenForFailureMessage("DoneNavigationTest.FAILED");
    646   ExtensionTestMessageListener ready_back_key_listener(
    647       "ReadyForBackKey", false);
    648   ExtensionTestMessageListener ready_forward_key_listener(
    649       "ReadyForForwardKey", false);
    650 
    651   EXPECT_TRUE(content::ExecuteScript(
    652                   embedder_web_contents,
    653                   "runTest('testBackForwardKeys')"));
    654 
    655   ASSERT_TRUE(ready_back_key_listener.WaitUntilSatisfied());
    656   SendBackShortcutToPlatformApp();
    657 
    658   ASSERT_TRUE(ready_forward_key_listener.WaitUntilSatisfied());
    659   SendForwardShortcutToPlatformApp();
    660 
    661   ASSERT_TRUE(done_listener.WaitUntilSatisfied());
    662 }
    663 
    664 IN_PROC_BROWSER_TEST_F(WebViewInteractiveTest,
    665                        PointerLock_PointerLockLostWithFocus) {
    666   TestHelper("testPointerLockLostWithFocus",
    667              "DonePointerLockTest.PASSED",
    668              "DonePointerLockTest.FAILED",
    669              "web_view/pointerlock");
    670 }
    671 
    672