Commit e580c0bb authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Set a root window for the AuraTestHelper DefaultCaptureClient.

This requires fixing a test that tried to drag between different root
windows while the default capture client was installed, which can't
handle that.  Looking through history, it seems like the whole reason
AuraTestHelper _didn't_ set a root window here originally was because
this test existed, and it was worked around instead of fixed.

TBH, I can't quite remember why I needed to do this at this point,
but it seems more correct regardless.

Bug: none
Change-Id: Ibc14703786d48f3283ec393434781ed02eae5ddb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2117068
Commit-Queue: Scott Violet <sky@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#752831}
parent 3674d6f6
...@@ -27,4 +27,7 @@ specific_include_rules = { ...@@ -27,4 +27,7 @@ specific_include_rules = {
"native_window_occlusion_tracker_win_interactive_test\.cc": [ "native_window_occlusion_tracker_win_interactive_test\.cc": [
"+mojo/core/embedder/embedder.h", "+mojo/core/embedder/embedder.h",
], ],
"window_event_dispatcher_unittest\.cc": [
"+ui/wm/core",
],
} }
...@@ -21,15 +21,14 @@ Window* global_capture_window_ = nullptr; ...@@ -21,15 +21,14 @@ Window* global_capture_window_ = nullptr;
DefaultCaptureClient::DefaultCaptureClient(Window* root_window) DefaultCaptureClient::DefaultCaptureClient(Window* root_window)
: root_window_(root_window), capture_window_(nullptr) { : root_window_(root_window), capture_window_(nullptr) {
if (root_window_) DCHECK(root_window_);
SetCaptureClient(root_window_, this); SetCaptureClient(root_window_, this);
} }
DefaultCaptureClient::~DefaultCaptureClient() { DefaultCaptureClient::~DefaultCaptureClient() {
if (global_capture_window_ == capture_window_) if (global_capture_window_ == capture_window_)
global_capture_window_ = nullptr; global_capture_window_ = nullptr;
if (root_window_) SetCaptureClient(root_window_, nullptr);
SetCaptureClient(root_window_, nullptr);
} }
void DefaultCaptureClient::SetCapture(Window* window) { void DefaultCaptureClient::SetCapture(Window* window) {
......
...@@ -15,7 +15,7 @@ namespace client { ...@@ -15,7 +15,7 @@ namespace client {
class AURA_EXPORT DefaultCaptureClient : public client::CaptureClient { class AURA_EXPORT DefaultCaptureClient : public client::CaptureClient {
public: public:
explicit DefaultCaptureClient(Window* root_window = nullptr); explicit DefaultCaptureClient(Window* root_window);
~DefaultCaptureClient() override; ~DefaultCaptureClient() override;
protected: protected:
......
...@@ -83,7 +83,6 @@ void AuraTestHelper::SetUp(ui::ContextFactory* context_factory) { ...@@ -83,7 +83,6 @@ void AuraTestHelper::SetUp(ui::ContextFactory* context_factory) {
wm_state_ = std::make_unique<wm::WMState>(); wm_state_ = std::make_unique<wm::WMState>();
// Needs to be before creating WindowTreeClient. // Needs to be before creating WindowTreeClient.
focus_client_ = std::make_unique<TestFocusClient>(); focus_client_ = std::make_unique<TestFocusClient>();
capture_client_ = std::make_unique<client::DefaultCaptureClient>();
if (!env) { if (!env) {
// Some tests suites create Env globally rather than per test. // Some tests suites create Env globally rather than per test.
...@@ -123,7 +122,8 @@ void AuraTestHelper::SetUp(ui::ContextFactory* context_factory) { ...@@ -123,7 +122,8 @@ void AuraTestHelper::SetUp(ui::ContextFactory* context_factory) {
host_->window()->SetEventTargeter(std::make_unique<WindowTargeter>()); host_->window()->SetEventTargeter(std::make_unique<WindowTargeter>());
client::SetFocusClient(root_window(), focus_client_.get()); client::SetFocusClient(root_window(), focus_client_.get());
client::SetCaptureClient(root_window(), capture_client()); capture_client_ =
std::make_unique<client::DefaultCaptureClient>(root_window());
parenting_client_ = parenting_client_ =
std::make_unique<TestWindowParentingClient>(root_window()); std::make_unique<TestWindowParentingClient>(root_window());
...@@ -139,7 +139,7 @@ void AuraTestHelper::TearDown() { ...@@ -139,7 +139,7 @@ void AuraTestHelper::TearDown() {
teardown_called_ = true; teardown_called_ = true;
parenting_client_.reset(); parenting_client_.reset();
client::SetFocusClient(root_window(), nullptr); client::SetFocusClient(root_window(), nullptr);
client::SetCaptureClient(root_window(), nullptr); capture_client_.reset();
host_.reset(); host_.reset();
if (display::Screen::GetScreen() == test_screen_.get()) if (display::Screen::GetScreen() == test_screen_.get())
...@@ -147,7 +147,6 @@ void AuraTestHelper::TearDown() { ...@@ -147,7 +147,6 @@ void AuraTestHelper::TearDown() {
test_screen_.reset(); test_screen_.reset();
focus_client_.reset(); focus_client_.reset();
capture_client_.reset();
ui::ShutdownInputMethodForTesting(); ui::ShutdownInputMethodForTesting();
......
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
#include "ui/gfx/transform.h" #include "ui/gfx/transform.h"
#include "ui/platform_window/platform_window_init_properties.h" #include "ui/platform_window/platform_window_init_properties.h"
#include "ui/wm/core/capture_controller.h"
namespace aura { namespace aura {
namespace { namespace {
...@@ -2795,40 +2796,49 @@ TEST_F(WindowEventDispatcherTest, ...@@ -2795,40 +2796,49 @@ TEST_F(WindowEventDispatcherTest,
ui::PlatformWindowInitProperties{gfx::Rect(20, 30, 100, 50)}); ui::PlatformWindowInitProperties{gfx::Rect(20, 30, 100, 50)});
second_host->InitHost(); second_host->InitHost();
second_host->window()->Show(); second_host->window()->Show();
client::SetCaptureClient(second_host->window(),
client::GetCaptureClient(root_window()));
test::EventCountDelegate delegate; // AuraTestBase sets up a DefaultCaptureClient for root_window(), but that
std::unique_ptr<Window> window_first(CreateTestWindowWithDelegate( // can't deal with capture between different root windows. Instead we need to
&delegate, 123, gfx::Rect(20, 10, 10, 20), root_window())); // use the wm::CaptureController instance that also exists, which can handle
window_first->Show(); // this situation. Exchange the capture clients and put the old one back at
// the end.
std::unique_ptr<Window> window_second(CreateTestWindowWithDelegate( client::CaptureClient* const old_capture_client =
&delegate, 12, gfx::Rect(10, 10, 20, 30), second_host->window())); client::GetCaptureClient(root_window());
window_second->Show(); {
wm::ScopedCaptureClient scoped_capture_first(root_window());
window_second->SetCapture(); wm::ScopedCaptureClient scoped_capture_second(second_host->window());
EXPECT_EQ(window_second.get(),
client::GetCaptureWindow(root_window())); test::EventCountDelegate delegate;
std::unique_ptr<Window> window_first(CreateTestWindowWithDelegate(
// Send an event to the first host. Make sure it goes to |window_second| in &delegate, 123, gfx::Rect(20, 10, 10, 20), root_window()));
// |second_host| instead (since it has capture). window_first->Show();
EventFilterRecorder recorder_first;
window_first->AddPreTargetHandler(&recorder_first); std::unique_ptr<Window> window_second(CreateTestWindowWithDelegate(
EventFilterRecorder recorder_second; &delegate, 12, gfx::Rect(10, 10, 20, 30), second_host->window()));
window_second->AddPreTargetHandler(&recorder_second); window_second->Show();
const gfx::Point event_location(25, 15);
ui::MouseEvent mouse(ui::ET_MOUSE_PRESSED, event_location, event_location, window_second->SetCapture();
ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
ui::EF_LEFT_MOUSE_BUTTON); // Send an event to the first host. Make sure it goes to |window_second| in
DispatchEventUsingWindowDispatcher(&mouse); // |second_host| instead (since it has capture).
EXPECT_TRUE(recorder_first.events().empty()); EventFilterRecorder recorder_first;
ASSERT_EQ(1u, recorder_second.events().size()); window_first->AddPreTargetHandler(&recorder_first);
EXPECT_EQ(ui::ET_MOUSE_PRESSED, recorder_second.events()[0]); EventFilterRecorder recorder_second;
EXPECT_EQ(event_location.ToString(), window_second->AddPreTargetHandler(&recorder_second);
recorder_second.mouse_locations()[0].ToString()); const gfx::Point event_location(25, 15);
window_first->RemovePreTargetHandler(&recorder_first); ui::MouseEvent mouse(ui::ET_MOUSE_PRESSED, event_location, event_location,
window_second->RemovePreTargetHandler(&recorder_second); ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
ui::EF_LEFT_MOUSE_BUTTON);
DispatchEventUsingWindowDispatcher(&mouse);
EXPECT_TRUE(recorder_first.events().empty());
ASSERT_EQ(1u, recorder_second.events().size());
EXPECT_EQ(ui::ET_MOUSE_PRESSED, recorder_second.events()[0]);
EXPECT_EQ(event_location.ToString(),
recorder_second.mouse_locations()[0].ToString());
window_first->RemovePreTargetHandler(&recorder_first);
window_second->RemovePreTargetHandler(&recorder_second);
}
client::SetCaptureClient(root_window(), old_capture_client);
} }
class AsyncWindowDelegate : public test::TestWindowDelegate { class AsyncWindowDelegate : public test::TestWindowDelegate {
......
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