OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 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/render_view_host.h" |
| 13 #include "content/public/browser/web_contents.h" |
| 14 #include "content/public/browser/web_contents_view.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 IN_PROC_BROWSER_TEST_F(DevToolsInteractiveTest, TouchEmulation) { |
| 63 OpenDevToolsWindow(kTouchEmulationPage, false); |
| 64 std::string result; |
| 65 |
| 66 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 67 devtools_window_->GetRenderViewHost(), |
| 68 "uiTests.runTest('enableTouchEmulation')", |
| 69 &result)); |
| 70 EXPECT_EQ("[OK]", result); |
| 71 |
| 72 // Clear dirty events before touch emulation. |
| 73 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 74 GetInspectedTab()->GetRenderViewHost(), |
| 75 "getEventNames(0)", |
| 76 &result)); |
| 77 |
| 78 gfx::Rect bounds; |
| 79 GetInspectedTab()->GetView()->GetContainerBounds(&bounds); |
| 80 gfx::Point position = bounds.origin(); |
| 81 |
| 82 // Simple touch sequence. |
| 83 position.Offset(10, 10); |
| 84 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(position)); |
| 85 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync( |
| 86 ui_controls::LEFT, ui_controls::DOWN)); |
| 87 // Prevent coalescing. |
| 88 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(20)); |
| 89 position.Offset(30, 0); |
| 90 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(position)); |
| 91 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync( |
| 92 ui_controls::LEFT, ui_controls::UP)); |
| 93 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 94 GetInspectedTab()->GetRenderViewHost(), |
| 95 "getEventNames(3)", |
| 96 &result)); |
| 97 EXPECT_EQ("touchstart touchmove touchend", result); |
| 98 |
| 99 // If mouse is not pressed - no touches. |
| 100 position.Offset(-30, 0); |
| 101 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(position)); |
| 102 // Prevent coalescing. |
| 103 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(20)); |
| 104 position.Offset(30, 0); |
| 105 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(position)); |
| 106 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 107 GetInspectedTab()->GetRenderViewHost(), |
| 108 "getEventNames(0)", |
| 109 &result)); |
| 110 EXPECT_EQ("", result); |
| 111 |
| 112 // Don't prevent default to get click sequence. |
| 113 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 114 GetInspectedTab()->GetRenderViewHost(), |
| 115 "preventDefault = false; window.domAutomationController.send('OK')", |
| 116 &result)); |
| 117 // Click. |
| 118 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync( |
| 119 ui_controls::LEFT, ui_controls::DOWN)); |
| 120 // Prevent coalescing. |
| 121 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(20)); |
| 122 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync( |
| 123 ui_controls::LEFT, ui_controls::UP)); |
| 124 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 125 GetInspectedTab()->GetRenderViewHost(), |
| 126 "getEventNames(7)", |
| 127 &result)); |
| 128 EXPECT_EQ( |
| 129 "touchstart touchend mouseover mousemove mousedown mouseup click", |
| 130 result); |
| 131 |
| 132 CloseDevToolsWindow(); |
| 133 |
| 134 // Touch emulation is off - mouse events should come. |
| 135 position.Offset(-30, 0); |
| 136 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(position)); |
| 137 // Prevent coalescing. |
| 138 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(20)); |
| 139 position.Offset(30, 0); |
| 140 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(position)); |
| 141 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 142 GetInspectedTab()->GetRenderViewHost(), |
| 143 "getEventNames(2)", |
| 144 &result)); |
| 145 EXPECT_EQ("mousemove mousemove", result); |
| 146 |
| 147 // Ensure no extra events. |
| 148 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(200)); |
| 149 content::RunAllPendingInMessageLoop(); |
| 150 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 151 GetInspectedTab()->GetRenderViewHost(), |
| 152 "getEventNames(0)", |
| 153 &result)); |
| 154 EXPECT_EQ("", result); |
| 155 } |
OLD | NEW |