| Index: chrome/browser/devtools/devtools_interactive_uitest.cc
|
| diff --git a/chrome/browser/devtools/devtools_interactive_uitest.cc b/chrome/browser/devtools/devtools_interactive_uitest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..0c0c5dcf77d441e8501eeb1f6ad23ae02dc8bf3a
|
| --- /dev/null
|
| +++ b/chrome/browser/devtools/devtools_interactive_uitest.cc
|
| @@ -0,0 +1,155 @@
|
| +// Copyright (c) 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "base/compiler_specific.h"
|
| +#include "chrome/browser/devtools/devtools_window.h"
|
| +#include "chrome/browser/ui/browser.h"
|
| +#include "chrome/browser/ui/tabs/tab_strip_model.h"
|
| +#include "chrome/test/base/in_process_browser_test.h"
|
| +#include "chrome/test/base/interactive_test_utils.h"
|
| +#include "content/public/browser/devtools_manager.h"
|
| +#include "content/public/browser/render_view_host.h"
|
| +#include "content/public/browser/web_contents.h"
|
| +#include "content/public/browser/web_contents_view.h"
|
| +#include "content/public/test/browser_test_utils.h"
|
| +
|
| +using content::RenderViewHost;
|
| +using content::WebContents;
|
| +
|
| +namespace {
|
| +const char kTouchEmulationPage[] = "files/devtools/touch_emulation.html";
|
| +} // namespace
|
| +
|
| +class DevToolsInteractiveTest : public InProcessBrowserTest {
|
| + public:
|
| + DevToolsInteractiveTest()
|
| + : devtools_window_(NULL) {}
|
| +
|
| + protected:
|
| + void LoadTestPage(const std::string& test_page) {
|
| + GURL url = test_server()->GetURL(test_page);
|
| + ui_test_utils::NavigateToURL(browser(), url);
|
| + }
|
| +
|
| + void OpenDevToolsWindow(const std::string& test_page, bool is_docked) {
|
| + ASSERT_TRUE(test_server()->Start());
|
| + LoadTestPage(test_page);
|
| +
|
| + devtools_window_ = DevToolsWindow::OpenDevToolsWindowForTest(
|
| + GetInspectedTab()->GetRenderViewHost(), is_docked);
|
| + ui_test_utils::WaitUntilDevToolsWindowLoaded(devtools_window_);
|
| + }
|
| +
|
| + WebContents* GetInspectedTab() {
|
| + return browser()->tab_strip_model()->GetWebContentsAt(0);
|
| + }
|
| +
|
| + void CloseDevToolsWindow() {
|
| + content::DevToolsManager* devtools_manager =
|
| + content::DevToolsManager::GetInstance();
|
| + content::WindowedNotificationObserver close_observer(
|
| + content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
|
| + content::Source<content::WebContents>(
|
| + devtools_window_->web_contents()));
|
| + devtools_manager->CloseAllClientHosts();
|
| + close_observer.Wait();
|
| + }
|
| +
|
| + DevToolsWindow* devtools_window_;
|
| +};
|
| +
|
| +IN_PROC_BROWSER_TEST_F(DevToolsInteractiveTest, TouchEmulation) {
|
| + OpenDevToolsWindow(kTouchEmulationPage, false);
|
| + std::string result;
|
| +
|
| + ASSERT_TRUE(content::ExecuteScriptAndExtractString(
|
| + devtools_window_->GetRenderViewHost(),
|
| + "uiTests.runTest('enableTouchEmulation')",
|
| + &result));
|
| + EXPECT_EQ("[OK]", result);
|
| +
|
| + // Clear dirty events before touch emulation.
|
| + ASSERT_TRUE(content::ExecuteScriptAndExtractString(
|
| + GetInspectedTab()->GetRenderViewHost(),
|
| + "getEventNames(0)",
|
| + &result));
|
| +
|
| + gfx::Rect bounds;
|
| + GetInspectedTab()->GetView()->GetContainerBounds(&bounds);
|
| + gfx::Point position = bounds.origin();
|
| +
|
| + // Simple touch sequence.
|
| + position.Offset(10, 10);
|
| + ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(position));
|
| + ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(
|
| + ui_controls::LEFT, ui_controls::DOWN));
|
| + // Prevent coalescing.
|
| + base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(20));
|
| + position.Offset(30, 0);
|
| + ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(position));
|
| + ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(
|
| + ui_controls::LEFT, ui_controls::UP));
|
| + ASSERT_TRUE(content::ExecuteScriptAndExtractString(
|
| + GetInspectedTab()->GetRenderViewHost(),
|
| + "getEventNames(3)",
|
| + &result));
|
| + EXPECT_EQ("touchstart touchmove touchend", result);
|
| +
|
| + // If mouse is not pressed - no touches.
|
| + position.Offset(-30, 0);
|
| + ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(position));
|
| + // Prevent coalescing.
|
| + base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(20));
|
| + position.Offset(30, 0);
|
| + ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(position));
|
| + ASSERT_TRUE(content::ExecuteScriptAndExtractString(
|
| + GetInspectedTab()->GetRenderViewHost(),
|
| + "getEventNames(0)",
|
| + &result));
|
| + EXPECT_EQ("", result);
|
| +
|
| + // Don't prevent default to get click sequence.
|
| + ASSERT_TRUE(content::ExecuteScriptAndExtractString(
|
| + GetInspectedTab()->GetRenderViewHost(),
|
| + "preventDefault = false; window.domAutomationController.send('OK')",
|
| + &result));
|
| + // Click.
|
| + ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(
|
| + ui_controls::LEFT, ui_controls::DOWN));
|
| + // Prevent coalescing.
|
| + base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(20));
|
| + ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(
|
| + ui_controls::LEFT, ui_controls::UP));
|
| + ASSERT_TRUE(content::ExecuteScriptAndExtractString(
|
| + GetInspectedTab()->GetRenderViewHost(),
|
| + "getEventNames(7)",
|
| + &result));
|
| + EXPECT_EQ(
|
| + "touchstart touchend mouseover mousemove mousedown mouseup click",
|
| + result);
|
| +
|
| + CloseDevToolsWindow();
|
| +
|
| + // Touch emulation is off - mouse events should come.
|
| + position.Offset(-30, 0);
|
| + ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(position));
|
| + // Prevent coalescing.
|
| + base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(20));
|
| + position.Offset(30, 0);
|
| + ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(position));
|
| + ASSERT_TRUE(content::ExecuteScriptAndExtractString(
|
| + GetInspectedTab()->GetRenderViewHost(),
|
| + "getEventNames(2)",
|
| + &result));
|
| + EXPECT_EQ("mousemove mousemove", result);
|
| +
|
| + // Ensure no extra events.
|
| + base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(200));
|
| + content::RunAllPendingInMessageLoop();
|
| + ASSERT_TRUE(content::ExecuteScriptAndExtractString(
|
| + GetInspectedTab()->GetRenderViewHost(),
|
| + "getEventNames(0)",
|
| + &result));
|
| + EXPECT_EQ("", result);
|
| +}
|
|
|