Revert "Unify TestScreen usages across aura and Mac"
This reverts commit 793e3a1c27
.
Reason for revert: This has resulted in a lot of random flake. See https://bugs.chromium.org/p/chromium/issues/detail?id=1219461 . I believe the core issue is that test code is now destroying Screens before other code may be trying to access it. This leads to the possibility of a uaf. For the PageInfoBubbleView tests, this is now the case. Unfortunately the destructor of TestWebContentsFactory calls RunUntilIdle, which is why the failure is not always consistent.
Original change's description:
> Unify TestScreen usages across aura and Mac
>
> This CL mainly did the following changes:
> -- Add a TestScreenMac in ViewsTestHelperMac;
> -- Change aura::TestScreen to also inherit from display::TestScreen;
> -- Remove some unnecessay test screen overrides to make tests work;
> -- Re-enable one LinkTest
>
> More details about these changes are in https://bit.ly/3yjxheL
>
> Fixed: 1071633
> Change-Id: Ia8ad7706ff3c6fce7f1b6ffc9e72e538bd89b6aa
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2898843
> Reviewed-by: Sadrul Chowdhury <sadrul@chromium.org>
> Reviewed-by: Mike Wasserman <msw@chromium.org>
> Commit-Queue: Wei Li <weili@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#891841}
Change-Id: I60d5e23fa76a57f15607edea4bada981d21c51cd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2959780
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Scott Violet <sky@chromium.org>
Owners-Override: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#892227}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
a5cc8cdf47
commit
b9aea738ca
chrome/browser/ui/views
global_media_controls
omnibox
overlay
ui
@ -21,6 +21,7 @@
|
||||
#include "media/base/media_switches.h"
|
||||
#include "services/media_session/public/mojom/media_session.mojom.h"
|
||||
#include "testing/gmock/include/gmock/gmock.h"
|
||||
#include "ui/display/test/scoped_screen_override.h"
|
||||
#include "ui/display/test/test_screen.h"
|
||||
#include "ui/events/base_event_utils.h"
|
||||
#include "ui/events/test/event_generator.h"
|
||||
@ -101,7 +102,7 @@ class MockMediaNotificationController
|
||||
|
||||
class MediaNotificationContainerImplViewTest : public ChromeViewsTestBase {
|
||||
public:
|
||||
MediaNotificationContainerImplViewTest() = default;
|
||||
MediaNotificationContainerImplViewTest() : screen_override_(&fake_screen_) {}
|
||||
~MediaNotificationContainerImplViewTest() override = default;
|
||||
|
||||
// ViewsTestBase:
|
||||
@ -143,7 +144,7 @@ class MediaNotificationContainerImplViewTest : public ChromeViewsTestBase {
|
||||
bool IsDismissButtonVisible() { return GetDismissButton()->IsDrawn(); }
|
||||
|
||||
void SimulateHoverOverContainer() {
|
||||
GetTestScreen()->SetCursorScreenPointForTesting(
|
||||
fake_screen_.set_cursor_screen_point(
|
||||
notification_container_->GetBoundsInScreen().CenterPoint());
|
||||
|
||||
ui::MouseEvent event(ui::ET_MOUSE_ENTERED, gfx::Point(), gfx::Point(),
|
||||
@ -155,7 +156,7 @@ class MediaNotificationContainerImplViewTest : public ChromeViewsTestBase {
|
||||
gfx::Rect container_bounds = notification_container_->GetBoundsInScreen();
|
||||
gfx::Point point_outside_container =
|
||||
container_bounds.bottom_right() + gfx::Vector2d(1, 1);
|
||||
GetTestScreen()->SetCursorScreenPointForTesting(point_outside_container);
|
||||
fake_screen_.set_cursor_screen_point(point_outside_container);
|
||||
|
||||
ui::MouseEvent event(ui::ET_MOUSE_EXITED, gfx::Point(), gfx::Point(),
|
||||
ui::EventTimeForNow(), 0, 0);
|
||||
@ -294,6 +295,9 @@ class MediaNotificationContainerImplViewTest : public ChromeViewsTestBase {
|
||||
// Set of actions currently enabled.
|
||||
base::flat_set<MediaSessionAction> actions_;
|
||||
|
||||
display::test::TestScreen fake_screen_;
|
||||
display::test::ScopedScreenOverride screen_override_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(MediaNotificationContainerImplViewTest);
|
||||
};
|
||||
|
||||
|
@ -100,7 +100,7 @@ class OmniboxResultViewTest : public ChromeViewsTestBase {
|
||||
int flags,
|
||||
float x,
|
||||
float y) {
|
||||
test_screen_->SetCursorScreenPointForTesting(gfx::Point(x, y));
|
||||
test_screen_->set_cursor_screen_point(gfx::Point(x, y));
|
||||
return ui::MouseEvent(type, gfx::Point(x, y), gfx::Point(),
|
||||
ui::EventTimeForNow(), flags, 0);
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "content/public/test/web_contents_tester.h"
|
||||
#include "media/base/media_switches.h"
|
||||
#include "ui/compositor/layer.h"
|
||||
#include "ui/display/test/scoped_screen_override.h"
|
||||
#include "ui/display/test/test_screen.h"
|
||||
|
||||
class TestPictureInPictureWindowController
|
||||
@ -75,10 +76,9 @@ class OverlayWindowViewsTest : public ChromeViewsTestBase {
|
||||
}
|
||||
|
||||
void SetDisplayWorkArea(const gfx::Rect& work_area) {
|
||||
display::test::TestScreen* screen = GetTestScreen();
|
||||
display::Display display = screen->GetPrimaryDisplay();
|
||||
display::Display display = test_screen_.GetPrimaryDisplay();
|
||||
display.set_work_area(work_area);
|
||||
screen->display_list().UpdateDisplay(display);
|
||||
test_screen_.display_list().UpdateDisplay(display);
|
||||
}
|
||||
|
||||
OverlayWindowViews& overlay_window() { return *overlay_window_; }
|
||||
@ -92,6 +92,9 @@ class OverlayWindowViewsTest : public ChromeViewsTestBase {
|
||||
web_contents_factory_.CreateWebContents(&profile_);
|
||||
TestPictureInPictureWindowController pip_window_controller_{web_contents_};
|
||||
|
||||
display::test::TestScreen test_screen_;
|
||||
display::test::ScopedScreenOverride scoped_screen_override_{&test_screen_};
|
||||
|
||||
std::unique_ptr<OverlayWindowViews> overlay_window_;
|
||||
};
|
||||
|
||||
|
@ -245,7 +245,6 @@ static_library("test_support") {
|
||||
"//ui/base/ime/init",
|
||||
"//ui/compositor:test_support",
|
||||
"//ui/display",
|
||||
"//ui/display:test_support",
|
||||
"//ui/display/manager",
|
||||
"//ui/events",
|
||||
"//ui/events:events_base",
|
||||
|
@ -7,15 +7,14 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include "base/check_op.h"
|
||||
#include "build/build_config.h"
|
||||
#include "ui/aura/env.h"
|
||||
#include "ui/aura/window.h"
|
||||
#include "ui/aura/window_event_dispatcher.h"
|
||||
#include "ui/aura/window_tree_host.h"
|
||||
#include "ui/base/ime/input_method.h"
|
||||
#include "ui/compositor/compositor.h"
|
||||
#include "ui/display/display.h"
|
||||
#include "ui/display/display_transform.h"
|
||||
#include "ui/display/test/test_screen.h"
|
||||
#include "ui/gfx/geometry/rect_conversions.h"
|
||||
#include "ui/gfx/geometry/size_conversions.h"
|
||||
#include "ui/gfx/native_widget_types.h"
|
||||
@ -32,13 +31,12 @@ bool IsRotationPortrait(display::Display::Rotation rotation) {
|
||||
|
||||
} // namespace
|
||||
|
||||
// TODO(weili): Remove this and use the constructor directly.
|
||||
// static
|
||||
TestScreen* TestScreen::Create(const gfx::Size& size) {
|
||||
const gfx::Size kDefaultSize(800, 600);
|
||||
// Use (0,0) because the desktop aura tests are executed in
|
||||
// native environment where the display's origin is (0,0).
|
||||
return new TestScreen(size.IsEmpty() ? kDefaultScreenBounds
|
||||
: gfx::Rect(size));
|
||||
return new TestScreen(gfx::Rect(size.IsEmpty() ? kDefaultSize : size));
|
||||
}
|
||||
|
||||
TestScreen::~TestScreen() {
|
||||
@ -171,14 +169,7 @@ std::string TestScreen::GetCurrentWorkspace() {
|
||||
return {};
|
||||
}
|
||||
|
||||
void TestScreen::SetCursorScreenPointForTesting(const gfx::Point& point) {
|
||||
display::test::TestScreen::SetCursorScreenPointForTesting(point);
|
||||
|
||||
Env::GetInstance()->SetLastMouseLocation(point);
|
||||
}
|
||||
|
||||
TestScreen::TestScreen(const gfx::Rect& screen_bounds)
|
||||
: display::test::TestScreen(/* create_display = */ false) {
|
||||
TestScreen::TestScreen(const gfx::Rect& screen_bounds) {
|
||||
static int64_t synthesized_display_id = 2000;
|
||||
display::Display display(synthesized_display_id++);
|
||||
display.SetScaleAndBounds(1.0f, screen_bounds);
|
||||
|
@ -5,9 +5,11 @@
|
||||
#ifndef UI_AURA_TEST_TEST_SCREEN_H_
|
||||
#define UI_AURA_TEST_TEST_SCREEN_H_
|
||||
|
||||
#include "base/compiler_specific.h"
|
||||
#include "base/macros.h"
|
||||
#include "ui/aura/window_observer.h"
|
||||
#include "ui/display/display.h"
|
||||
#include "ui/display/test/test_screen.h"
|
||||
#include "ui/display/screen_base.h"
|
||||
|
||||
namespace gfx {
|
||||
class ColorSpace;
|
||||
@ -20,14 +22,13 @@ namespace aura {
|
||||
class Window;
|
||||
class WindowTreeHost;
|
||||
|
||||
// A minimal Aura implementation of display::test::TestScreen.
|
||||
class TestScreen : public display::test::TestScreen, public WindowObserver {
|
||||
// A minimal, testing Aura implementation of display::Screen.
|
||||
// TODO(bruthig): Consider extending gfx::test::TestScreen.
|
||||
class TestScreen : public display::ScreenBase, public WindowObserver {
|
||||
public:
|
||||
// Creates a display::Screen of the specified size. If no size is specified,
|
||||
// then creates a 800x600 screen. |size| is in physical pixels.
|
||||
static TestScreen* Create(const gfx::Size& size);
|
||||
TestScreen(const TestScreen&) = delete;
|
||||
TestScreen& operator=(const TestScreen&) = delete;
|
||||
~TestScreen() override;
|
||||
|
||||
WindowTreeHost* CreateHostForPrimaryDisplay();
|
||||
@ -61,7 +62,6 @@ class TestScreen : public display::test::TestScreen, public WindowObserver {
|
||||
display::Display GetDisplayNearestWindow(
|
||||
gfx::NativeWindow window) const override;
|
||||
std::string GetCurrentWorkspace() override;
|
||||
void SetCursorScreenPointForTesting(const gfx::Point& point) override;
|
||||
|
||||
private:
|
||||
explicit TestScreen(const gfx::Rect& screen_bounds);
|
||||
@ -69,6 +69,8 @@ class TestScreen : public display::test::TestScreen, public WindowObserver {
|
||||
aura::WindowTreeHost* host_ = nullptr;
|
||||
|
||||
float ui_scale_ = 1.0f;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(TestScreen);
|
||||
};
|
||||
|
||||
} // namespace aura
|
||||
|
@ -157,13 +157,6 @@ static_library("test_support") {
|
||||
]
|
||||
}
|
||||
|
||||
if (is_mac) {
|
||||
sources += [
|
||||
"mac/test/test_screen_mac.h",
|
||||
"mac/test/test_screen_mac.mm",
|
||||
]
|
||||
}
|
||||
|
||||
if (build_display_configuration) {
|
||||
sources += [
|
||||
"manager/test/action_logger.cc",
|
||||
|
@ -1,32 +0,0 @@
|
||||
// Copyright 2021 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_DISPLAY_MAC_TEST_TEST_SCREEN_MAC_H_
|
||||
#define UI_DISPLAY_MAC_TEST_TEST_SCREEN_MAC_H_
|
||||
|
||||
#include "ui/display/test/test_screen.h"
|
||||
|
||||
namespace gfx {
|
||||
class Size;
|
||||
}
|
||||
|
||||
namespace display {
|
||||
|
||||
namespace test {
|
||||
|
||||
// A test screen implementation for Mac.
|
||||
// It implements the minimal functionalities such as using a valid display id to
|
||||
// create a display for the screen.
|
||||
class TestScreenMac : public TestScreen {
|
||||
public:
|
||||
TestScreenMac(const gfx::Size& size);
|
||||
TestScreenMac(const TestScreenMac&) = delete;
|
||||
TestScreenMac& operator=(const TestScreenMac&) = delete;
|
||||
~TestScreenMac() override;
|
||||
};
|
||||
|
||||
} // namespace test
|
||||
} // namespace display
|
||||
|
||||
#endif // UI_DISPLAY_MAC_TEST_TEST_SCREEN_MAC_H_
|
@ -1,33 +0,0 @@
|
||||
// Copyright 2021 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/display/mac/test/test_screen_mac.h"
|
||||
|
||||
#import <AppKit/AppKit.h>
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#include "ui/display/display.h"
|
||||
#include "ui/display/test/test_screen.h"
|
||||
#include "ui/gfx/geometry/rect.h"
|
||||
#include "ui/gfx/geometry/size.h"
|
||||
|
||||
namespace display {
|
||||
namespace test {
|
||||
|
||||
TestScreenMac::TestScreenMac(const gfx::Size& size)
|
||||
: TestScreen(/* create_display = */ false) {
|
||||
NSScreen* screen = [[NSScreen screens] firstObject];
|
||||
CGDirectDisplayID display_id =
|
||||
[[screen deviceDescription][@"NSScreenNumber"] unsignedIntValue];
|
||||
|
||||
Display display(display_id);
|
||||
display.SetScaleAndBounds(
|
||||
1.0f, size.IsEmpty() ? kDefaultScreenBounds : gfx::Rect(size));
|
||||
ProcessDisplayChanged(display, /* is_primary = */ true);
|
||||
}
|
||||
|
||||
TestScreenMac::~TestScreenMac() = default;
|
||||
|
||||
} // namespace test
|
||||
} // namespace display
|
@ -29,6 +29,7 @@ Screen::~Screen() = default;
|
||||
// static
|
||||
Screen* Screen::GetScreen() {
|
||||
#if defined(OS_APPLE)
|
||||
// TODO(scottmg): https://crbug.com/558054
|
||||
if (!g_screen)
|
||||
g_screen = CreateNativeScreen();
|
||||
#endif
|
||||
@ -40,10 +41,6 @@ Screen* Screen::SetScreenInstance(Screen* instance) {
|
||||
return std::exchange(g_screen, instance);
|
||||
}
|
||||
|
||||
void Screen::SetCursorScreenPointForTesting(const gfx::Point& point) {
|
||||
NOTIMPLEMENTED_LOG_ONCE();
|
||||
}
|
||||
|
||||
Display Screen::GetDisplayNearestView(gfx::NativeView view) const {
|
||||
return GetDisplayNearestWindow(GetWindowForView(view));
|
||||
}
|
||||
|
@ -53,9 +53,6 @@ class DISPLAY_EXPORT Screen {
|
||||
// Returns the current absolute position of the mouse pointer.
|
||||
virtual gfx::Point GetCursorScreenPoint() = 0;
|
||||
|
||||
// Allows tests to override the cursor point location on the screen.
|
||||
virtual void SetCursorScreenPointForTesting(const gfx::Point& point);
|
||||
|
||||
// Returns true if the cursor is directly over |window|.
|
||||
virtual bool IsWindowUnderCursor(gfx::NativeWindow window) = 0;
|
||||
|
||||
@ -180,7 +177,7 @@ class DISPLAY_EXPORT Screen {
|
||||
DISALLOW_COPY_AND_ASSIGN(Screen);
|
||||
};
|
||||
|
||||
DISPLAY_EXPORT Screen* CreateNativeScreen();
|
||||
Screen* CreateNativeScreen();
|
||||
|
||||
} // namespace display
|
||||
|
||||
|
@ -2,27 +2,24 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "ui/display/test/test_screen.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "ui/display/display.h"
|
||||
#include "ui/display/test/test_screen.h"
|
||||
|
||||
namespace display {
|
||||
namespace test {
|
||||
|
||||
// static
|
||||
constexpr gfx::Rect TestScreen::kDefaultScreenBounds;
|
||||
|
||||
TestScreen::TestScreen(bool create_display) {
|
||||
if (!create_display)
|
||||
return;
|
||||
Display display(1, kDefaultScreenBounds);
|
||||
ProcessDisplayChanged(display, /* is_primary = */ true);
|
||||
TestScreen::TestScreen() {
|
||||
Display display(1, gfx::Rect(0, 0, 100, 100));
|
||||
ProcessDisplayChanged(display, true /* is_primary */);
|
||||
}
|
||||
|
||||
TestScreen::~TestScreen() {}
|
||||
|
||||
void TestScreen::set_cursor_screen_point(const gfx::Point& point) {
|
||||
cursor_screen_point_ = point;
|
||||
}
|
||||
|
||||
gfx::Point TestScreen::GetCursorScreenPoint() {
|
||||
return cursor_screen_point_;
|
||||
}
|
||||
@ -39,13 +36,5 @@ Display TestScreen::GetDisplayNearestWindow(gfx::NativeWindow window) const {
|
||||
return GetPrimaryDisplay();
|
||||
}
|
||||
|
||||
Display TestScreen::GetDisplayMatching(const gfx::Rect& match_rect) const {
|
||||
return GetPrimaryDisplay();
|
||||
}
|
||||
|
||||
void TestScreen::SetCursorScreenPointForTesting(const gfx::Point& point) {
|
||||
cursor_screen_point_ = point;
|
||||
}
|
||||
|
||||
} // namespace test
|
||||
} // namespace display
|
||||
|
@ -5,36 +5,38 @@
|
||||
#ifndef UI_DISPLAY_TEST_TEST_SCREEN_H_
|
||||
#define UI_DISPLAY_TEST_TEST_SCREEN_H_
|
||||
|
||||
|
||||
#include "base/macros.h"
|
||||
#include "ui/display/display.h"
|
||||
#include "ui/display/screen_base.h"
|
||||
#include "ui/gfx/geometry/rect.h"
|
||||
|
||||
namespace display {
|
||||
|
||||
namespace test {
|
||||
|
||||
// A fake and simplified Screen implementation that contains a single
|
||||
// Display only with the default size.
|
||||
// A dummy implementation of Screen that contains a single
|
||||
// Display only. The contained Display can be accessed and modified via
|
||||
// TestScreen::display().
|
||||
//
|
||||
// NOTE: Adding and removing DisplayOberver's are no-ops and observers
|
||||
// will NOT be notified ever.
|
||||
class TestScreen : public ScreenBase {
|
||||
public:
|
||||
static constexpr gfx::Rect kDefaultScreenBounds = gfx::Rect(0, 0, 800, 600);
|
||||
|
||||
// TODO(weili): Split this into a protected no-argument constructor for
|
||||
// subclass uses and the public one with gfx::Size argument.
|
||||
explicit TestScreen(bool create_display = true);
|
||||
TestScreen(const TestScreen&) = delete;
|
||||
TestScreen& operator=(const TestScreen&) = delete;
|
||||
TestScreen();
|
||||
~TestScreen() override;
|
||||
|
||||
// ScreenBase:
|
||||
// Sets the fake cursor location for the TestScreen.
|
||||
void set_cursor_screen_point(const gfx::Point& point);
|
||||
|
||||
// Screen:
|
||||
gfx::Point GetCursorScreenPoint() override;
|
||||
bool IsWindowUnderCursor(gfx::NativeWindow window) override;
|
||||
gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) override;
|
||||
Display GetDisplayNearestWindow(gfx::NativeWindow window) const override;
|
||||
Display GetDisplayMatching(const gfx::Rect& match_rect) const override;
|
||||
void SetCursorScreenPointForTesting(const gfx::Point& point) override;
|
||||
|
||||
private:
|
||||
gfx::Point cursor_screen_point_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(TestScreen);
|
||||
};
|
||||
|
||||
} // namespace test
|
||||
|
@ -978,6 +978,20 @@ source_set("test_support") {
|
||||
"views_test_suite.h",
|
||||
]
|
||||
|
||||
if (is_mac) {
|
||||
sources += [
|
||||
"test/desktop_test_views_delegate_mac.mm",
|
||||
"test/event_generator_delegate_mac.h",
|
||||
"test/event_generator_delegate_mac.mm",
|
||||
"test/scoped_views_test_helper_cocoa.mm",
|
||||
"test/test_views_delegate_mac.mm",
|
||||
"test/views_test_base_mac.mm",
|
||||
"test/views_test_helper_mac.h",
|
||||
"test/views_test_helper_mac.mm",
|
||||
"test/widget_test_mac.mm",
|
||||
]
|
||||
}
|
||||
|
||||
configs += [ "//build/config:precompiled_headers" ]
|
||||
|
||||
deps = [
|
||||
@ -997,7 +1011,6 @@ source_set("test_support") {
|
||||
"//ui/base/ime/init",
|
||||
"//ui/compositor",
|
||||
"//ui/compositor:test_support",
|
||||
"//ui/display:test_support",
|
||||
"//ui/events",
|
||||
"//ui/events:events_base",
|
||||
"//ui/events:test_support",
|
||||
@ -1014,24 +1027,8 @@ source_set("test_support") {
|
||||
"test/desktop_window_tree_host_win_test_api.h",
|
||||
]
|
||||
}
|
||||
|
||||
if (is_mac) {
|
||||
sources += [
|
||||
"test/desktop_test_views_delegate_mac.mm",
|
||||
"test/event_generator_delegate_mac.h",
|
||||
"test/event_generator_delegate_mac.mm",
|
||||
"test/scoped_views_test_helper_cocoa.mm",
|
||||
"test/test_views_delegate_mac.mm",
|
||||
"test/views_test_base_mac.mm",
|
||||
"test/views_test_helper_mac.h",
|
||||
"test/views_test_helper_mac.mm",
|
||||
"test/widget_test_mac.mm",
|
||||
]
|
||||
|
||||
deps += [
|
||||
"//components/remote_cocoa/app_shim",
|
||||
"//ui/display:test_support",
|
||||
]
|
||||
deps += [ "//components/remote_cocoa/app_shim" ]
|
||||
}
|
||||
|
||||
if (use_aura) {
|
||||
@ -1303,10 +1300,6 @@ test("views_unittests") {
|
||||
# views_unittests not yet compiling on Mac. http://crbug.com/378134
|
||||
sources -= [ "controls/native/native_view_host_unittest.cc" ]
|
||||
|
||||
deps += [
|
||||
"//ui/display", # native_widget_mac_unittest.mm uses display::Screen.
|
||||
]
|
||||
|
||||
public_deps = [
|
||||
"//components/remote_cocoa/app_shim",
|
||||
"//ui/accelerated_widget_mac",
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "build/build_config.h"
|
||||
#include "ui/base/hit_test.h"
|
||||
#include "ui/display/test/scoped_screen_override.h"
|
||||
#include "ui/display/test/test_screen.h"
|
||||
#include "ui/events/event_utils.h"
|
||||
#include "ui/views/animation/ink_drop.h"
|
||||
@ -656,7 +657,8 @@ TEST_F(BubbleDialogDelegateViewTest, GetThemeProvider_FromAnchorWidget) {
|
||||
anchor_widget->GetThemeProvider());
|
||||
}
|
||||
|
||||
static constexpr gfx::Rect kScreenBounds = gfx::Rect(0, 0, 1024, 768);
|
||||
const int kScreenWidth = 1024;
|
||||
const int kScreenHeight = 768;
|
||||
|
||||
struct ArrowTestParameters {
|
||||
views::BubbleBorder::Arrow arrow;
|
||||
@ -668,9 +670,10 @@ struct ArrowTestParameters {
|
||||
gfx::Rect adjusted_anchor_rect = anchor_rect;
|
||||
adjusted_anchor_rect.Offset(
|
||||
0, ViewsTestBase::GetSystemReservedHeightAtTopOfScreen());
|
||||
gfx::Rect screen_rect = gfx::Rect(0, 0, kScreenWidth, kScreenHeight);
|
||||
|
||||
return BubbleDialogDelegate::GetAvailableSpaceToPlaceBubble(
|
||||
expected_arrow, adjusted_anchor_rect, kScreenBounds);
|
||||
expected_arrow, adjusted_anchor_rect, screen_rect);
|
||||
}
|
||||
};
|
||||
|
||||
@ -678,26 +681,26 @@ class BubbleDialogDelegateViewArrowTest
|
||||
: public BubbleDialogDelegateViewTest,
|
||||
public testing::WithParamInterface<ArrowTestParameters> {
|
||||
public:
|
||||
BubbleDialogDelegateViewArrowTest() = default;
|
||||
BubbleDialogDelegateViewArrowTest(const BubbleDialogDelegateViewArrowTest&) =
|
||||
delete;
|
||||
BubbleDialogDelegateViewArrowTest& operator=(
|
||||
const BubbleDialogDelegateViewArrowTest&) = delete;
|
||||
BubbleDialogDelegateViewArrowTest() : screen_override_(SetUpTestScreen()) {}
|
||||
~BubbleDialogDelegateViewArrowTest() override = default;
|
||||
|
||||
void SetUp() override {
|
||||
BubbleDialogDelegateViewTest::SetUp();
|
||||
SetUpTestScreen();
|
||||
private:
|
||||
display::Screen* SetUpTestScreen() {
|
||||
const display::Display test_display = test_screen_.GetPrimaryDisplay();
|
||||
display::Display display(test_display);
|
||||
display.set_id(0x2);
|
||||
display.set_bounds(gfx::Rect(0, 0, kScreenWidth, kScreenHeight));
|
||||
display.set_work_area(gfx::Rect(0, 0, kScreenWidth, kScreenHeight));
|
||||
test_screen_.display_list().RemoveDisplay(test_display.id());
|
||||
test_screen_.display_list().AddDisplay(display,
|
||||
display::DisplayList::Type::PRIMARY);
|
||||
return &test_screen_;
|
||||
}
|
||||
|
||||
private:
|
||||
void SetUpTestScreen() {
|
||||
display::test::TestScreen* screen = GetTestScreen();
|
||||
display::Display test_display = screen->GetPrimaryDisplay();
|
||||
test_display.set_bounds(kScreenBounds);
|
||||
test_display.set_work_area(kScreenBounds);
|
||||
screen->display_list().UpdateDisplay(test_display);
|
||||
}
|
||||
display::test::TestScreen test_screen_;
|
||||
display::test::ScopedScreenOverride screen_override_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(BubbleDialogDelegateViewArrowTest);
|
||||
};
|
||||
|
||||
TEST_P(BubbleDialogDelegateViewArrowTest, AvailableScreenSpaceTest) {
|
||||
|
@ -87,6 +87,8 @@ TEST_F(LinkTest, TestLinkTap) {
|
||||
EXPECT_TRUE(link_clicked);
|
||||
}
|
||||
|
||||
// This test doesn't work on Mac due to crbug.com/1071633.
|
||||
#if !defined(OS_MAC)
|
||||
// Tests that hovering and unhovering a link adds and removes an underline.
|
||||
TEST_F(LinkTest, TestUnderlineOnHover) {
|
||||
// A non-hovered link should not be underlined.
|
||||
@ -109,5 +111,6 @@ TEST_F(LinkTest, TestUnderlineOnHover) {
|
||||
EXPECT_FALSE(link()->IsMouseHovered());
|
||||
EXPECT_FALSE(link_underlined());
|
||||
}
|
||||
#endif // !defined(OS_MAC)
|
||||
|
||||
} // namespace views
|
||||
|
@ -10,16 +10,12 @@
|
||||
#include "base/memory/singleton.h"
|
||||
#include "base/stl_util.h"
|
||||
#include "ui/base/cocoa/cocoa_base_utils.h"
|
||||
#include "ui/display/screen.h"
|
||||
#include "ui/events/event.h"
|
||||
#include "ui/events/event_dispatcher.h"
|
||||
#include "ui/events/event_processor.h"
|
||||
#include "ui/events/event_target.h"
|
||||
#include "ui/events/event_target_iterator.h"
|
||||
#include "ui/events/event_targeter.h"
|
||||
#import "ui/events/test/cocoa_test_event_utils.h"
|
||||
#include "ui/events/test/event_generator.h"
|
||||
#include "ui/events/types/event_type.h"
|
||||
#include "ui/gfx/mac/coordinate_conversion.h"
|
||||
|
||||
namespace {
|
||||
@ -246,9 +242,6 @@ class EventGeneratorDelegateMac : public ui::EventTarget,
|
||||
EventGeneratorDelegateMac(ui::test::EventGenerator* owner,
|
||||
gfx::NativeWindow root_window,
|
||||
gfx::NativeWindow target_window);
|
||||
EventGeneratorDelegateMac(const EventGeneratorDelegateMac&) = delete;
|
||||
EventGeneratorDelegateMac& operator=(const EventGeneratorDelegateMac&) =
|
||||
delete;
|
||||
~EventGeneratorDelegateMac() override;
|
||||
|
||||
static EventGeneratorDelegateMac* instance() { return instance_; }
|
||||
@ -319,12 +312,6 @@ class EventGeneratorDelegateMac : public ui::EventTarget,
|
||||
void ConvertPointFromHost(const ui::EventTarget* hosted_target,
|
||||
gfx::Point* point) const override {}
|
||||
|
||||
protected:
|
||||
// Overridden from ui::EventDispatcherDelegate (via ui::EventProcessor)
|
||||
ui::EventDispatchDetails PreDispatchEvent(ui::EventTarget* target,
|
||||
ui::Event* event) override
|
||||
WARN_UNUSED_RESULT;
|
||||
|
||||
private:
|
||||
static EventGeneratorDelegateMac* instance_;
|
||||
|
||||
@ -342,6 +329,8 @@ class EventGeneratorDelegateMac : public ui::EventTarget,
|
||||
|
||||
// Timestamp on the last scroll update, used to simulate scroll momentum.
|
||||
base::TimeTicks last_scroll_timestamp_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(EventGeneratorDelegateMac);
|
||||
};
|
||||
|
||||
// static
|
||||
@ -577,28 +566,6 @@ gfx::Point EventGeneratorDelegateMac::CenterOfWindow(
|
||||
return gfx::Point(NSWidth([window frame]) / 2, NSHeight([window frame]) / 2);
|
||||
}
|
||||
|
||||
ui::EventDispatchDetails EventGeneratorDelegateMac::PreDispatchEvent(
|
||||
ui::EventTarget* target,
|
||||
ui::Event* event) {
|
||||
// Set the TestScreen's cursor point before mouse event dispatch. The
|
||||
// Screen's value is checked by views controls and other UI components; this
|
||||
// pattern matches aura::WindowEventDispatcher::PreDispatchMouseEvent().
|
||||
if (event->IsMouseEvent()) {
|
||||
ui::MouseEvent* mouse_event = event->AsMouseEvent();
|
||||
// Similar to the logic in Aura's
|
||||
// EnvInputStateController::UpdateStateForMouseEvent(), capture change and
|
||||
// synthesized events don't need to update the cursor location.
|
||||
if (mouse_event->type() != ui::ET_MOUSE_CAPTURE_CHANGED &&
|
||||
!(mouse_event->flags() & ui::EF_IS_SYNTHESIZED)) {
|
||||
// Update the cursor location on screen.
|
||||
owner_->set_current_screen_location(mouse_event->root_location());
|
||||
display::Screen::GetScreen()->SetCursorScreenPointForTesting(
|
||||
mouse_event->root_location());
|
||||
}
|
||||
}
|
||||
return ui::EventDispatchDetails();
|
||||
}
|
||||
|
||||
ui::test::EventGenerator* GetActiveGenerator() {
|
||||
return EventGeneratorDelegateMac::instance()
|
||||
? EventGeneratorDelegateMac::instance()->owner()
|
||||
|
@ -8,7 +8,6 @@
|
||||
|
||||
#include "ui/base/clipboard/clipboard.h"
|
||||
#include "ui/base/clipboard/test/test_clipboard.h"
|
||||
#include "ui/display/test/test_screen.h"
|
||||
#include "ui/views/test/test_views_delegate.h"
|
||||
|
||||
#if defined(USE_AURA)
|
||||
@ -40,10 +39,6 @@ gfx::NativeWindow ScopedViewsTestHelper::GetContext() {
|
||||
return test_helper_->GetContext();
|
||||
}
|
||||
|
||||
display::test::TestScreen* ScopedViewsTestHelper::GetTestScreen() const {
|
||||
return test_helper_->GetTestScreen();
|
||||
}
|
||||
|
||||
#if defined(USE_AURA)
|
||||
void ScopedViewsTestHelper::SimulateNativeDestroy(Widget* widget) {
|
||||
delete widget->GetNativeView();
|
||||
|
@ -13,12 +13,6 @@
|
||||
#include "ui/views/test/views_test_helper.h"
|
||||
#include "ui/views/views_delegate.h"
|
||||
|
||||
namespace display {
|
||||
namespace test {
|
||||
class TestScreen;
|
||||
} // namespace test
|
||||
} // namespace display
|
||||
|
||||
namespace views {
|
||||
|
||||
class TestViewsDelegate;
|
||||
@ -43,9 +37,6 @@ class ScopedViewsTestHelper {
|
||||
// the RootWindow. Everywhere else, null.
|
||||
gfx::NativeWindow GetContext();
|
||||
|
||||
// Returns the test screen created by |test_helper_|.
|
||||
display::test::TestScreen* GetTestScreen() const;
|
||||
|
||||
// Simulate an OS-level destruction of the native window held by |widget|.
|
||||
void SimulateNativeDestroy(Widget* widget);
|
||||
|
||||
|
@ -15,8 +15,6 @@
|
||||
#include "ui/base/clipboard/clipboard.h"
|
||||
#include "ui/base/resource/resource_bundle.h"
|
||||
#include "ui/base/ui_base_paths.h"
|
||||
#include "ui/display/screen.h"
|
||||
#include "ui/display/test/test_screen.h"
|
||||
#include "ui/gl/test/gl_surface_test_support.h"
|
||||
#include "ui/views/buildflags.h"
|
||||
#include "ui/views/test/test_platform_native_widget.h"
|
||||
@ -152,13 +150,6 @@ int ViewsTestBase::GetSystemReservedHeightAtTopOfScreen() {
|
||||
}
|
||||
#endif
|
||||
|
||||
display::test::TestScreen* ViewsTestBase::GetTestScreen() const {
|
||||
display::test::TestScreen* test_screen = test_helper_->GetTestScreen();
|
||||
// This TestScreen should be installed as the display::Screen singleton.
|
||||
DCHECK_EQ(display::Screen::GetScreen(), test_screen);
|
||||
return test_screen;
|
||||
}
|
||||
|
||||
gfx::NativeWindow ViewsTestBase::GetContext() {
|
||||
return test_helper_->GetContext();
|
||||
}
|
||||
|
@ -28,12 +28,6 @@
|
||||
#include "ui/aura/window_tree_host.h"
|
||||
#endif
|
||||
|
||||
namespace display {
|
||||
namespace test {
|
||||
class TestScreen;
|
||||
} // namespace test
|
||||
} // namespace display
|
||||
|
||||
namespace views {
|
||||
|
||||
// A base class for views unit test. It creates a message loop necessary
|
||||
@ -100,10 +94,6 @@ class ViewsTestBase : public PlatformTest {
|
||||
// includes the menu bar and title bar.
|
||||
static int GetSystemReservedHeightAtTopOfScreen();
|
||||
|
||||
// Returns the test screen installed by |test_helper_|. We also dcheck that it
|
||||
// should be the global screen instance.
|
||||
display::test::TestScreen* GetTestScreen() const;
|
||||
|
||||
protected:
|
||||
base::test::TaskEnvironment* task_environment() {
|
||||
return task_environment_.get();
|
||||
|
@ -12,12 +12,6 @@
|
||||
#include "ui/gfx/native_widget_types.h"
|
||||
#include "ui/views/views_delegate.h"
|
||||
|
||||
namespace display {
|
||||
namespace test {
|
||||
class TestScreen;
|
||||
} // namespace test
|
||||
} // namespace display
|
||||
|
||||
namespace views {
|
||||
|
||||
class TestViewsDelegate;
|
||||
@ -47,9 +41,6 @@ class ViewsTestHelper {
|
||||
// Returns a context window, e.g. the Aura root window.
|
||||
virtual gfx::NativeWindow GetContext();
|
||||
|
||||
// Return the test screen created by this class.
|
||||
virtual display::test::TestScreen* GetTestScreen() const = 0;
|
||||
|
||||
protected:
|
||||
ViewsTestHelper() = default;
|
||||
};
|
||||
|
@ -7,9 +7,7 @@
|
||||
#include "base/check_op.h"
|
||||
#include "build/build_config.h"
|
||||
#include "build/chromeos_buildflags.h"
|
||||
#include "ui/aura/test/test_screen.h"
|
||||
#include "ui/aura/window.h"
|
||||
#include "ui/display/test/test_screen.h"
|
||||
#include "ui/views/test/test_views_delegate.h"
|
||||
|
||||
namespace views {
|
||||
@ -79,10 +77,6 @@ gfx::NativeWindow ViewsTestHelperAura::GetContext() {
|
||||
return aura_test_helper_->GetContext();
|
||||
}
|
||||
|
||||
display::test::TestScreen* ViewsTestHelperAura::GetTestScreen() const {
|
||||
return aura_test_helper_->GetTestScreen();
|
||||
}
|
||||
|
||||
// static
|
||||
void ViewsTestHelperAura::SetAuraTestHelperFactory(
|
||||
AuraTestHelperFactory factory) {
|
||||
|
@ -10,12 +10,6 @@
|
||||
#include "ui/aura/test/aura_test_helper.h"
|
||||
#include "ui/views/test/views_test_helper.h"
|
||||
|
||||
namespace display {
|
||||
namespace test {
|
||||
class TestScreen;
|
||||
} // namespace test
|
||||
} // namespace display
|
||||
|
||||
namespace views {
|
||||
|
||||
class ViewsTestHelperAura : public ViewsTestHelper {
|
||||
@ -33,7 +27,6 @@ class ViewsTestHelperAura : public ViewsTestHelper {
|
||||
std::unique_ptr<TestViewsDelegate> GetFallbackTestViewsDelegate() override;
|
||||
void SetUp() override;
|
||||
gfx::NativeWindow GetContext() override;
|
||||
display::test::TestScreen* GetTestScreen() const override;
|
||||
|
||||
// Provides a way for test bases to customize what test helper will be used
|
||||
// for |aura_test_helper_|.
|
||||
|
@ -12,13 +12,6 @@
|
||||
#include "ui/compositor/test/test_context_factories.h"
|
||||
#include "ui/views/test/views_test_helper.h"
|
||||
|
||||
namespace display {
|
||||
namespace test {
|
||||
class TestScreen;
|
||||
class TestScreenMac;
|
||||
} // namespace test
|
||||
} // namespace display
|
||||
|
||||
namespace ui {
|
||||
namespace test {
|
||||
class ScopedFakeNSWindowFocus;
|
||||
@ -39,7 +32,6 @@ class ViewsTestHelperMac : public ViewsTestHelper {
|
||||
void SetUpTestViewsDelegate(
|
||||
TestViewsDelegate* delegate,
|
||||
absl::optional<ViewsDelegate::NativeWidgetFactory> factory) override;
|
||||
display::test::TestScreen* GetTestScreen() const override;
|
||||
|
||||
private:
|
||||
ui::TestContextFactories context_factories_{false};
|
||||
@ -66,8 +58,6 @@ class ViewsTestHelperMac : public ViewsTestHelper {
|
||||
// more consistent with other platforms, where most views are focusable by
|
||||
// default.
|
||||
ui::test::ScopedFakeFullKeyboardAccess faked_full_keyboard_access_;
|
||||
|
||||
std::unique_ptr<display::test::TestScreenMac> test_screen_;
|
||||
};
|
||||
|
||||
} // namespace views
|
||||
|
@ -10,8 +10,6 @@
|
||||
#include "ui/base/test/scoped_fake_nswindow_focus.h"
|
||||
#include "ui/base/test/scoped_fake_nswindow_fullscreen.h"
|
||||
#include "ui/base/test/ui_controls.h"
|
||||
#include "ui/display/mac/test/test_screen_mac.h"
|
||||
#include "ui/display/test/test_screen.h"
|
||||
#include "ui/events/test/event_generator.h"
|
||||
#include "ui/views/test/event_generator_delegate_mac.h"
|
||||
#include "ui/views/test/test_views_delegate.h"
|
||||
@ -42,11 +40,6 @@ ViewsTestHelperMac::ViewsTestHelperMac() {
|
||||
faked_fullscreen_ =
|
||||
std::make_unique<ui::test::ScopedFakeNSWindowFullscreen>();
|
||||
}
|
||||
|
||||
test_screen_ = std::make_unique<display::test::TestScreenMac>(gfx::Size());
|
||||
// Purposely not use ScopedScreenOverride, in which GetScreen() will
|
||||
// create a native screen.
|
||||
display::Screen::SetScreenInstance(test_screen_.get());
|
||||
}
|
||||
|
||||
ViewsTestHelperMac::~ViewsTestHelperMac() {
|
||||
@ -64,7 +57,6 @@ ViewsTestHelperMac::~ViewsTestHelperMac() {
|
||||
ui::test::EventGeneratorDelegate::SetFactoryFunction(
|
||||
ui::test::EventGeneratorDelegate::FactoryFunction());
|
||||
}
|
||||
display::Screen::SetScreenInstance(nullptr);
|
||||
}
|
||||
|
||||
void ViewsTestHelperMac::SetUpTestViewsDelegate(
|
||||
@ -74,8 +66,4 @@ void ViewsTestHelperMac::SetUpTestViewsDelegate(
|
||||
delegate->set_context_factory(context_factories_.GetContextFactory());
|
||||
}
|
||||
|
||||
display::test::TestScreen* ViewsTestHelperMac::GetTestScreen() const {
|
||||
return test_screen_.get();
|
||||
}
|
||||
|
||||
} // namespace views
|
||||
|
@ -30,8 +30,6 @@
|
||||
#import "ui/base/test/scoped_fake_full_keyboard_access.h"
|
||||
#include "ui/compositor/layer.h"
|
||||
#include "ui/compositor/recyclable_compositor_mac.h"
|
||||
#include "ui/display/screen.h"
|
||||
#include "ui/display/test/scoped_screen_override.h"
|
||||
#import "ui/events/test/cocoa_test_event_utils.h"
|
||||
#include "ui/events/test/event_generator.h"
|
||||
#import "ui/gfx/mac/coordinate_conversion.h"
|
||||
@ -204,31 +202,6 @@ class NativeWidgetMacTest : public WidgetTest {
|
||||
DISALLOW_COPY_AND_ASSIGN(NativeWidgetMacTest);
|
||||
};
|
||||
|
||||
// Uses the native screen instance to match test expectations when
|
||||
// display::Screen is compared with values from direct OS API calls.
|
||||
class NativeWidgetMacWithNativeScreenTest : public WidgetTest {
|
||||
public:
|
||||
NativeWidgetMacWithNativeScreenTest() = default;
|
||||
NativeWidgetMacWithNativeScreenTest(
|
||||
const NativeWidgetMacWithNativeScreenTest&) = delete;
|
||||
NativeWidgetMacWithNativeScreenTest& operator=(
|
||||
const NativeWidgetMacWithNativeScreenTest&) = delete;
|
||||
~NativeWidgetMacWithNativeScreenTest() override = default;
|
||||
|
||||
void SetUp() override {
|
||||
WidgetTest::SetUp();
|
||||
|
||||
native_screen_ = base::WrapUnique(display::CreateNativeScreen());
|
||||
scoped_screen_override_ =
|
||||
std::make_unique<display::test::ScopedScreenOverride>(
|
||||
native_screen_.get());
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<display::Screen> native_screen_;
|
||||
std::unique_ptr<display::test::ScopedScreenOverride> scoped_screen_override_;
|
||||
};
|
||||
|
||||
class WidgetChangeObserver : public TestWidgetObserver {
|
||||
public:
|
||||
explicit WidgetChangeObserver(Widget* widget) : TestWidgetObserver(widget) {}
|
||||
@ -1913,7 +1886,7 @@ TEST_F(NativeWidgetMacTest, ContentOpacity) {
|
||||
}
|
||||
|
||||
// Test the expected result of GetWorkAreaBoundsInScreen().
|
||||
TEST_F(NativeWidgetMacWithNativeScreenTest, GetWorkAreaBoundsInScreen) {
|
||||
TEST_F(NativeWidgetMacTest, GetWorkAreaBoundsInScreen) {
|
||||
Widget widget;
|
||||
Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
|
||||
params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
|
||||
|
Reference in New Issue
Block a user