| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 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 "base/compiler_specific.h" | |
| 6 #include "chrome/browser/devtools/devtools_window.h" | |
| 7 #include "chrome/browser/ui/browser.h" | |
| 8 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
| 9 #include "chrome/test/base/in_process_browser_test.h" | |
| 10 #include "chrome/test/base/interactive_test_utils.h" | |
| 11 #include "content/public/browser/devtools_manager.h" | |
| 12 #include "content/public/browser/notification_types.h" | |
| 13 #include "content/public/browser/render_view_host.h" | |
| 14 #include "content/public/browser/web_contents.h" | |
| 15 #include "content/public/test/browser_test_utils.h" | |
| 16 | |
| 17 using content::RenderViewHost; | |
| 18 using content::WebContents; | |
| 19 | |
| 20 namespace { | |
| 21 const char kTouchEmulationPage[] = "files/devtools/touch_emulation.html"; | |
| 22 } // namespace | |
| 23 | |
| 24 class DevToolsInteractiveTest : public InProcessBrowserTest { | |
| 25 public: | |
| 26 DevToolsInteractiveTest() | |
| 27 : devtools_window_(NULL) {} | |
| 28 | |
| 29 protected: | |
| 30 void LoadTestPage(const std::string& test_page) { | |
| 31 GURL url = test_server()->GetURL(test_page); | |
| 32 ui_test_utils::NavigateToURL(browser(), url); | |
| 33 } | |
| 34 | |
| 35 void OpenDevToolsWindow(const std::string& test_page, bool is_docked) { | |
| 36 ASSERT_TRUE(test_server()->Start()); | |
| 37 LoadTestPage(test_page); | |
| 38 | |
| 39 devtools_window_ = DevToolsWindow::OpenDevToolsWindowForTest( | |
| 40 GetInspectedTab()->GetRenderViewHost(), is_docked); | |
| 41 ui_test_utils::WaitUntilDevToolsWindowLoaded(devtools_window_); | |
| 42 } | |
| 43 | |
| 44 WebContents* GetInspectedTab() { | |
| 45 return browser()->tab_strip_model()->GetWebContentsAt(0); | |
| 46 } | |
| 47 | |
| 48 void CloseDevToolsWindow() { | |
| 49 content::DevToolsManager* devtools_manager = | |
| 50 content::DevToolsManager::GetInstance(); | |
| 51 content::WindowedNotificationObserver close_observer( | |
| 52 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | |
| 53 content::Source<content::WebContents>( | |
| 54 devtools_window_->web_contents())); | |
| 55 devtools_manager->CloseAllClientHosts(); | |
| 56 close_observer.Wait(); | |
| 57 } | |
| 58 | |
| 59 DevToolsWindow* devtools_window_; | |
| 60 }; | |
| 61 | |
| 62 // SendMouseMoseSync only reliably works on Linux. | |
| 63 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | |
| 64 #define MAYBE_TouchEmulation TouchEmulation | |
| 65 #else | |
| 66 #define MAYBE_TouchEmulation DISABLED_TouchEmulation | |
| 67 #endif | |
| 68 | |
| 69 IN_PROC_BROWSER_TEST_F(DevToolsInteractiveTest, MAYBE_TouchEmulation) { | |
| 70 OpenDevToolsWindow(kTouchEmulationPage, false); | |
| 71 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | |
| 72 std::string result; | |
| 73 | |
| 74 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | |
| 75 devtools_window_->web_contents()->GetRenderViewHost(), | |
| 76 "uiTests.runTest('enableTouchEmulation')", | |
| 77 &result)); | |
| 78 EXPECT_EQ("[OK]", result); | |
| 79 | |
| 80 // Clear dirty events before touch emulation. | |
| 81 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | |
| 82 GetInspectedTab()->GetRenderViewHost(), | |
| 83 "getEventNames(0)", | |
| 84 &result)); | |
| 85 | |
| 86 gfx::Rect bounds = GetInspectedTab()->GetContainerBounds(); | |
| 87 gfx::Point position = bounds.origin(); | |
| 88 | |
| 89 // Simple touch sequence. | |
| 90 position.Offset(10, 10); | |
| 91 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(position)); | |
| 92 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync( | |
| 93 ui_controls::LEFT, ui_controls::DOWN)); | |
| 94 position.Offset(30, 0); | |
| 95 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(position)); | |
| 96 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync( | |
| 97 ui_controls::LEFT, ui_controls::UP)); | |
| 98 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | |
| 99 GetInspectedTab()->GetRenderViewHost(), | |
| 100 "getEventNames(3)", | |
| 101 &result)); | |
| 102 EXPECT_EQ("touchstart touchmove touchend", result); | |
| 103 | |
| 104 // If mouse is not pressed - no touches. | |
| 105 position.Offset(-30, 0); | |
| 106 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(position)); | |
| 107 position.Offset(30, 0); | |
| 108 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(position)); | |
| 109 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | |
| 110 GetInspectedTab()->GetRenderViewHost(), | |
| 111 "getEventNames(0)", | |
| 112 &result)); | |
| 113 EXPECT_EQ("", result); | |
| 114 | |
| 115 // Don't prevent default to get click sequence. | |
| 116 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | |
| 117 GetInspectedTab()->GetRenderViewHost(), | |
| 118 "preventDefault = false; window.domAutomationController.send('OK')", | |
| 119 &result)); | |
| 120 // Click. | |
| 121 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync( | |
| 122 ui_controls::LEFT, ui_controls::DOWN)); | |
| 123 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync( | |
| 124 ui_controls::LEFT, ui_controls::UP)); | |
| 125 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | |
| 126 GetInspectedTab()->GetRenderViewHost(), | |
| 127 "getEventNames(6)", | |
| 128 &result)); | |
| 129 EXPECT_EQ( | |
| 130 "touchstart touchend mousemove mousedown mouseup click", | |
| 131 result); | |
| 132 | |
| 133 CloseDevToolsWindow(); | |
| 134 | |
| 135 // Touch emulation is off - mouse events should come. | |
| 136 position.Offset(-30, 0); | |
| 137 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(position)); | |
| 138 position.Offset(30, 0); | |
| 139 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(position)); | |
| 140 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | |
| 141 GetInspectedTab()->GetRenderViewHost(), | |
| 142 "getEventNames(2)", | |
| 143 &result)); | |
| 144 EXPECT_EQ("mousemove mousemove", result); | |
| 145 | |
| 146 // Ensure no extra events. | |
| 147 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(200)); | |
| 148 content::RunAllPendingInMessageLoop(); | |
| 149 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | |
| 150 GetInspectedTab()->GetRenderViewHost(), | |
| 151 "getEventNames(0)", | |
| 152 &result)); | |
| 153 EXPECT_EQ("", result); | |
| 154 } | |
| OLD | NEW |