Commit 4dcd8ad1 authored by thomasanderson's avatar thomasanderson Committed by Commit bot

X11: Add TestDesktopScreenX11 to simulate mouse movement in ui tests

BUG=640741

Review-Url: https://codereview.chromium.org/2327623002
Cr-Commit-Position: refs/heads/master@{#417978}
parent 346b5074
......@@ -45,6 +45,8 @@ void ChromeBrowserMainExtraPartsViews::ToolkitInitialized() {
void ChromeBrowserMainExtraPartsViews::PreCreateThreads() {
#if defined(USE_AURA) && !defined(OS_CHROMEOS)
// The screen may have already been set in test initialization.
if (!display::Screen::GetScreen())
display::Screen::SetScreenInstance(views::CreateDesktopScreen());
#endif
}
......
......@@ -673,15 +673,9 @@ void DragToSeparateWindowStep2(DetachToBrowserTabDragControllerTest* test,
} // namespace
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
// TODO: Disabled as mouse isn't updated propertly, http://crbug.com/640741.
#define MAYBE_DragToSeparateWindow DISABLED_DragToSeparateWindow
#else
#define MAYBE_DragToSeparateWindow DragToSeparateWindow
#endif
// Creates two browsers, drags from first into second.
IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest,
MAYBE_DragToSeparateWindow) {
DragToSeparateWindow) {
TabStrip* tab_strip = GetTabStripForBrowser(browser());
// Add another tab to browser().
......
......@@ -86,6 +86,10 @@
#include "chrome/test/base/default_ash_event_generator_delegate.h"
#endif
#if !defined(OS_CHROMEOS) && defined(OS_LINUX)
#include "ui/views/test/test_desktop_screen_x11.h"
#endif
namespace {
// Passed as value of kTestType.
......@@ -222,7 +226,11 @@ void InProcessBrowserTest::SetUp() {
command_line->AppendSwitchASCII(switches::kHostWindowBounds,
"0+0-1280x800");
}
#endif // defined(OS_CHROMEOS)
#elif defined(OS_LINUX)
DCHECK(!display::Screen::GetScreen());
display::Screen::SetScreenInstance(
views::test::TestDesktopScreenX11::GetInstance());
#endif
// Always use a mocked password storage if OS encryption is used (which is
// when anything sensitive gets stored, including Cookies). Without this on
......
......@@ -10,6 +10,10 @@
#include "ui/display/screen.h"
#include "ui/views/widget/desktop_aura/desktop_screen.h"
#if !defined(OS_CHROMEOS) && defined(OS_LINUX)
#include "ui/views/test/test_desktop_screen_x11.h"
#endif
namespace {
// ViewEventTestPlatformPart implementation for Views, but non-CrOS.
......@@ -18,8 +22,14 @@ class ViewEventTestPlatformPartDefault : public ViewEventTestPlatformPart {
explicit ViewEventTestPlatformPartDefault(
ui::ContextFactory* context_factory) {
#if defined(USE_AURA)
DCHECK(!display::Screen::GetScreen());
#if !defined(OS_CHROMEOS) && defined(OS_LINUX)
display::Screen::SetScreenInstance(
views::test::TestDesktopScreenX11::GetInstance());
#else
screen_.reset(views::CreateDesktopScreen());
display::Screen::SetScreenInstance(screen_.get());
#endif
env_ = aura::Env::CreateInstance();
env_->set_context_factory(context_factory);
#endif
......
......@@ -756,6 +756,8 @@ static_library("test_support_internal") {
sources += [
"test/desktop_screen_x11_test_api.cc",
"test/desktop_screen_x11_test_api.h",
"test/test_desktop_screen_x11.cc",
"test/test_desktop_screen_x11.h",
"test/ui_controls_factory_desktop_aurax11.cc",
"test/ui_controls_factory_desktop_aurax11.h",
]
......
// Copyright 2016 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 "ui/views/test/test_desktop_screen_x11.h"
#include "base/memory/singleton.h"
namespace views {
namespace test {
TestDesktopScreenX11* TestDesktopScreenX11::GetInstance() {
return base::Singleton<TestDesktopScreenX11>::get();
}
TestDesktopScreenX11::TestDesktopScreenX11() {}
TestDesktopScreenX11::~TestDesktopScreenX11() {}
gfx::Point TestDesktopScreenX11::GetCursorScreenPoint() {
return cursor_screen_point_;
}
TestDesktopScreenX11* GetTestDesktopScreenX11() {
static std::unique_ptr<TestDesktopScreenX11> test_screen_instance;
if (!test_screen_instance.get())
test_screen_instance.reset(new TestDesktopScreenX11());
return test_screen_instance.get();
}
} // namespace test
} // namespace views
// Copyright 2016 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.
#ifndef UI_VIEWS_TEST_TEST_DESKTOP_SCREEN_X11_H_
#define UI_VIEWS_TEST_TEST_DESKTOP_SCREEN_X11_H_
#include "ui/gfx/geometry/point.h"
#include "ui/views/widget/desktop_aura/desktop_screen_x11.h"
namespace base {
template<typename T> struct DefaultSingletonTraits;
}
namespace views {
namespace test {
// Replaces the screen instance in Linux (non-ChromeOS) tests. Allows
// aura tests to manually set the cursor screen point to be reported
// by GetCursorScreenPoint(). Needed because of a limitation in the
// X11 protocol that restricts us from warping the pointer with the
// mouse button held down.
class TestDesktopScreenX11 : public DesktopScreenX11 {
public:
static TestDesktopScreenX11* GetInstance();
TestDesktopScreenX11();
~TestDesktopScreenX11() override;
// DesktopScreenX11:
gfx::Point GetCursorScreenPoint() override;
void set_cursor_screen_point(const gfx::Point& point) {
cursor_screen_point_ = point;
}
private:
friend struct base::DefaultSingletonTraits<TestDesktopScreenX11>;
gfx::Point cursor_screen_point_;
DISALLOW_COPY_AND_ASSIGN(TestDesktopScreenX11);
};
} // namespace test
} // namespace views
#endif // UI_VIEWS_TEST_TEST_DESKTOP_SCREEN_X11_H_
......@@ -25,6 +25,7 @@
#include "ui/events/keycodes/keyboard_code_conversion_x.h"
#include "ui/events/test/platform_event_waiter.h"
#include "ui/gfx/x/x11_connection.h"
#include "ui/views/test/test_desktop_screen_x11.h"
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h"
namespace views {
......@@ -145,6 +146,10 @@ class UIControlsDesktopX11 : public UIControlsAura {
aura::test::QueryLatestMousePositionRequestInHost(host);
host->ConvertPointFromHost(&root_current_location);
auto screen = views::test::TestDesktopScreenX11::GetInstance();
DCHECK_EQ(screen, display::Screen::GetScreen());
screen->set_cursor_screen_point(gfx::Point(screen_x, screen_y));
if (root_location != root_current_location && button_down_mask == 0) {
// Move the cursor because EnterNotify/LeaveNotify are generated with the
// current mouse position as a result of XGrabPointer()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment