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,14 +21,13 @@ Window* global_capture_window_ = nullptr; ...@@ -21,14 +21,13 @@ 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);
} }
......
...@@ -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,8 +2796,17 @@ TEST_F(WindowEventDispatcherTest, ...@@ -2795,8 +2796,17 @@ 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())); // AuraTestBase sets up a DefaultCaptureClient for root_window(), but that
// can't deal with capture between different root windows. Instead we need to
// use the wm::CaptureController instance that also exists, which can handle
// this situation. Exchange the capture clients and put the old one back at
// the end.
client::CaptureClient* const old_capture_client =
client::GetCaptureClient(root_window());
{
wm::ScopedCaptureClient scoped_capture_first(root_window());
wm::ScopedCaptureClient scoped_capture_second(second_host->window());
test::EventCountDelegate delegate; test::EventCountDelegate delegate;
std::unique_ptr<Window> window_first(CreateTestWindowWithDelegate( std::unique_ptr<Window> window_first(CreateTestWindowWithDelegate(
...@@ -2808,8 +2818,6 @@ TEST_F(WindowEventDispatcherTest, ...@@ -2808,8 +2818,6 @@ TEST_F(WindowEventDispatcherTest,
window_second->Show(); window_second->Show();
window_second->SetCapture(); window_second->SetCapture();
EXPECT_EQ(window_second.get(),
client::GetCaptureWindow(root_window()));
// Send an event to the first host. Make sure it goes to |window_second| in // Send an event to the first host. Make sure it goes to |window_second| in
// |second_host| instead (since it has capture). // |second_host| instead (since it has capture).
...@@ -2829,6 +2837,8 @@ TEST_F(WindowEventDispatcherTest, ...@@ -2829,6 +2837,8 @@ TEST_F(WindowEventDispatcherTest,
recorder_second.mouse_locations()[0].ToString()); recorder_second.mouse_locations()[0].ToString());
window_first->RemovePreTargetHandler(&recorder_first); window_first->RemovePreTargetHandler(&recorder_first);
window_second->RemovePreTargetHandler(&recorder_second); 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