| Index: ui/aura/mus/window_tree_client_unittest.cc
|
| diff --git a/ui/aura/mus/window_tree_client_unittest.cc b/ui/aura/mus/window_tree_client_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..f186bd6f14708534cf2db8111b7bfc0f8f880cd5
|
| --- /dev/null
|
| +++ b/ui/aura/mus/window_tree_client_unittest.cc
|
| @@ -0,0 +1,1051 @@
|
| +// Copyright 2015 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/aura/mus/window_tree_client.h"
|
| +
|
| +#include <stdint.h>
|
| +
|
| +#include "base/logging.h"
|
| +#include "base/macros.h"
|
| +#include "mojo/common/common_type_converters.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +#include "ui/aura/client/aura_constants.h"
|
| +#include "ui/aura/client/capture_client.h"
|
| +#include "ui/aura/client/focus_client.h"
|
| +#include "ui/aura/mus/property_converter.h"
|
| +#include "ui/aura/mus/window_mus.h"
|
| +#include "ui/aura/mus/window_tree_client_delegate.h"
|
| +#include "ui/aura/mus/window_tree_client_observer.h"
|
| +#include "ui/aura/test/aura_mus_test_base.h"
|
| +#include "ui/aura/test/mus/test_window_tree.h"
|
| +#include "ui/aura/test/mus/window_tree_client_private.h"
|
| +#include "ui/aura/test/test_window_delegate.h"
|
| +#include "ui/aura/window.h"
|
| +#include "ui/aura/window_property.h"
|
| +#include "ui/aura/window_tracker.h"
|
| +#include "ui/events/event.h"
|
| +#include "ui/events/event_utils.h"
|
| +#include "ui/gfx/geometry/rect.h"
|
| +
|
| +DECLARE_WINDOW_PROPERTY_TYPE(uint8_t)
|
| +
|
| +namespace aura {
|
| +
|
| +namespace {
|
| +
|
| +DEFINE_WINDOW_PROPERTY_KEY(uint8_t, kTestPropertyKey1, 0);
|
| +DEFINE_WINDOW_PROPERTY_KEY(uint8_t, kTestPropertyKey2, 0);
|
| +
|
| +Id server_id(Window* window) {
|
| + return WindowMus::Get(window)->server_id();
|
| +}
|
| +
|
| +void SetWindowVisibility(Window* window, bool visible) {
|
| + if (visible)
|
| + window->Show();
|
| + else
|
| + window->Hide();
|
| +}
|
| +
|
| +Window* GetFirstRoot(WindowTreeClient* client) {
|
| + return client->GetRoots().empty() ? nullptr : *client->GetRoots().begin();
|
| +}
|
| +
|
| +const char kAlwaysOnTopServerKey[] = "always-on-top-server";
|
| +const char kTestPropertyServerKey1[] = "test-property-server1";
|
| +const char kTestPropertyServerKey2[] = "test-property-server2";
|
| +
|
| +class TestPropertyConverter : public PropertyConverter {
|
| + public:
|
| + TestPropertyConverter() {}
|
| + ~TestPropertyConverter() override {}
|
| +
|
| + // PropertyConverter:
|
| + bool ConvertPropertyForTransport(
|
| + Window* window,
|
| + const void* key,
|
| + std::string* server_property_name,
|
| + std::unique_ptr<std::vector<uint8_t>>* server_property_value) override {
|
| + if (key == client::kAlwaysOnTopKey) {
|
| + *server_property_name = kAlwaysOnTopServerKey;
|
| + *server_property_value = base::MakeUnique<std::vector<uint8_t>>(1);
|
| + (*server_property_value->get())[0] =
|
| + window->GetProperty(client::kAlwaysOnTopKey);
|
| + return true;
|
| + }
|
| + if (key == kTestPropertyKey1) {
|
| + *server_property_name = kTestPropertyServerKey1;
|
| + *server_property_value = base::MakeUnique<std::vector<uint8_t>>(1);
|
| + (*server_property_value->get())[0] =
|
| + window->GetProperty(kTestPropertyKey1);
|
| + return true;
|
| + }
|
| + if (key == kTestPropertyKey2) {
|
| + *server_property_name = kTestPropertyServerKey2;
|
| + *server_property_value = base::MakeUnique<std::vector<uint8_t>>(1);
|
| + (*server_property_value->get())[0] =
|
| + window->GetProperty(kTestPropertyKey2);
|
| + return true;
|
| + }
|
| + return false;
|
| + }
|
| +
|
| + std::string GetTransportNameForPropertyKey(const void* key) override {
|
| + if (key == client::kAlwaysOnTopKey)
|
| + return kAlwaysOnTopServerKey;
|
| + if (key == kTestPropertyKey1)
|
| + return kTestPropertyServerKey1;
|
| + if (key == kTestPropertyKey2)
|
| + return kTestPropertyServerKey2;
|
| + return std::string();
|
| + }
|
| +
|
| + void SetPropertyFromTransportValue(
|
| + Window* window,
|
| + const std::string& server_property_name,
|
| + const std::vector<uint8_t>* data) override {
|
| + if (server_property_name == kAlwaysOnTopServerKey) {
|
| + window->SetProperty(client::kAlwaysOnTopKey,
|
| + static_cast<bool>((*data)[0]));
|
| + } else if (server_property_name == kTestPropertyServerKey1) {
|
| + window->SetProperty(kTestPropertyKey1, (*data)[0]);
|
| + } else if (server_property_name == kTestPropertyServerKey2) {
|
| + window->SetProperty(kTestPropertyKey2, (*data)[0]);
|
| + }
|
| + }
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(TestPropertyConverter);
|
| +};
|
| +
|
| +} // namespace
|
| +
|
| +mojo::Array<uint8_t> Uint8ToPropertyTransportValue(uint8_t value) {
|
| + mojo::Array<uint8_t> transport_value(1);
|
| + transport_value[0] = value;
|
| + return transport_value;
|
| +}
|
| +
|
| +using WindowTreeClientWmTest = test::AuraMusWmTestBase;
|
| +using WindowTreeClientClientTest = test::AuraMusClientTestBase;
|
| +
|
| +// Verifies bounds are reverted if the server replied that the change failed.
|
| +TEST_F(WindowTreeClientWmTest, SetBoundsFailed) {
|
| + Window window(nullptr);
|
| + window.Init(ui::LAYER_NOT_DRAWN);
|
| + const gfx::Rect original_bounds(window.bounds());
|
| + const gfx::Rect new_bounds(gfx::Rect(0, 0, 100, 100));
|
| + ASSERT_NE(new_bounds, window.bounds());
|
| + window.SetBounds(new_bounds);
|
| + EXPECT_EQ(new_bounds, window.bounds());
|
| + ASSERT_TRUE(window_tree()->AckSingleChangeOfType(WindowTreeChangeType::BOUNDS,
|
| + false));
|
| + EXPECT_EQ(original_bounds, window.bounds());
|
| +}
|
| +
|
| +// Verifies a new window from the server doesn't result in attempting to add
|
| +// the window back to the server.
|
| +TEST_F(WindowTreeClientWmTest, AddFromServerDoesntAddAgain) {
|
| + const Id child_window_id = server_id(root_window()) + 11;
|
| + ui::mojom::WindowDataPtr data = ui::mojom::WindowData::New();
|
| + data->parent_id = server_id(root_window());
|
| + data->window_id = child_window_id;
|
| + data->bounds = gfx::Rect(1, 2, 3, 4);
|
| + data->visible = false;
|
| + mojo::Array<ui::mojom::WindowDataPtr> data_array(1);
|
| + data_array[0] = std::move(data);
|
| + ASSERT_TRUE(root_window()->children().empty());
|
| + window_tree_client()->OnWindowHierarchyChanged(
|
| + child_window_id, 0, server_id(root_window()), std::move(data_array));
|
| + ASSERT_FALSE(window_tree()->has_change());
|
| + ASSERT_EQ(1u, root_window()->children().size());
|
| + Window* child = root_window()->children()[0];
|
| + EXPECT_FALSE(child->TargetVisibility());
|
| +}
|
| +
|
| +// Verifies a reparent from the server doesn't attempt signal the server.
|
| +TEST_F(WindowTreeClientWmTest, ReparentFromServerDoesntAddAgain) {
|
| + Window window1(nullptr);
|
| + window1.Init(ui::LAYER_NOT_DRAWN);
|
| + Window window2(nullptr);
|
| + window2.Init(ui::LAYER_NOT_DRAWN);
|
| + root_window()->AddChild(&window1);
|
| + root_window()->AddChild(&window2);
|
| +
|
| + window_tree()->AckAllChanges();
|
| + // Simulate moving |window1| to be a child of |window2| from the server.
|
| + window_tree_client()->OnWindowHierarchyChanged(server_id(&window1),
|
| + server_id(root_window()),
|
| + server_id(&window2), nullptr);
|
| + ASSERT_FALSE(window_tree()->has_change());
|
| + EXPECT_EQ(&window2, window1.parent());
|
| + EXPECT_EQ(root_window(), window2.parent());
|
| + window1.parent()->RemoveChild(&window1);
|
| +}
|
| +
|
| +// Verifies properties passed in OnWindowHierarchyChanged() make there way to
|
| +// the new window.
|
| +TEST_F(WindowTreeClientWmTest, OnWindowHierarchyChangedWithProperties) {
|
| + SetPropertyConverter(base::MakeUnique<TestPropertyConverter>());
|
| + window_tree()->AckAllChanges();
|
| + const Id child_window_id = server_id(root_window()) + 11;
|
| + ui::mojom::WindowDataPtr data = ui::mojom::WindowData::New();
|
| + const uint8_t server_test_property1_value = 91;
|
| + data->properties[kTestPropertyServerKey1] =
|
| + Uint8ToPropertyTransportValue(server_test_property1_value);
|
| + data->parent_id = server_id(root_window());
|
| + data->window_id = child_window_id;
|
| + data->bounds = gfx::Rect(1, 2, 3, 4);
|
| + data->visible = false;
|
| + mojo::Array<ui::mojom::WindowDataPtr> data_array(1);
|
| + data_array[0] = std::move(data);
|
| + ASSERT_TRUE(root_window()->children().empty());
|
| + window_tree_client()->OnWindowHierarchyChanged(
|
| + child_window_id, 0, server_id(root_window()), std::move(data_array));
|
| + ASSERT_FALSE(window_tree()->has_change());
|
| + ASSERT_EQ(1u, root_window()->children().size());
|
| + Window* child = root_window()->children()[0];
|
| + EXPECT_FALSE(child->TargetVisibility());
|
| + EXPECT_EQ(server_test_property1_value, child->GetProperty(kTestPropertyKey1));
|
| +}
|
| +
|
| +// Verifies a move from the server doesn't attempt signal the server.
|
| +TEST_F(WindowTreeClientWmTest, MoveFromServerDoesntAddAgain) {
|
| + Window window1(nullptr);
|
| + window1.Init(ui::LAYER_NOT_DRAWN);
|
| + Window window2(nullptr);
|
| + window2.Init(ui::LAYER_NOT_DRAWN);
|
| + root_window()->AddChild(&window1);
|
| + root_window()->AddChild(&window2);
|
| +
|
| + window_tree()->AckAllChanges();
|
| + // Simulate moving |window1| to be a child of |window2| from the server.
|
| + window_tree_client()->OnWindowReordered(server_id(&window2),
|
| + server_id(&window1),
|
| + ui::mojom::OrderDirection::BELOW);
|
| + ASSERT_FALSE(window_tree()->has_change());
|
| + ASSERT_EQ(2u, root_window()->children().size());
|
| + EXPECT_EQ(&window2, root_window()->children()[0]);
|
| + EXPECT_EQ(&window1, root_window()->children()[1]);
|
| +}
|
| +
|
| +TEST_F(WindowTreeClientWmTest, FocusFromServer) {
|
| + Window window1(nullptr);
|
| + window1.Init(ui::LAYER_NOT_DRAWN);
|
| + Window window2(nullptr);
|
| + window2.Init(ui::LAYER_NOT_DRAWN);
|
| + root_window()->AddChild(&window1);
|
| + root_window()->AddChild(&window2);
|
| +
|
| + ASSERT_TRUE(window1.CanFocus());
|
| + window_tree()->AckAllChanges();
|
| + EXPECT_FALSE(window1.HasFocus());
|
| + // Simulate moving |window1| to be a child of |window2| from the server.
|
| + window_tree_client()->OnWindowFocused(server_id(&window1));
|
| + ASSERT_FALSE(window_tree()->has_change());
|
| + EXPECT_TRUE(window1.HasFocus());
|
| +}
|
| +
|
| +// Simulates a bounds change, and while the bounds change is in flight the
|
| +// server replies with a new bounds and the original bounds change fails.
|
| +TEST_F(WindowTreeClientWmTest, SetBoundsFailedWithPendingChange) {
|
| + const gfx::Rect original_bounds(root_window()->bounds());
|
| + const gfx::Rect new_bounds(gfx::Rect(0, 0, 100, 100));
|
| + ASSERT_NE(new_bounds, root_window()->bounds());
|
| + root_window()->SetBounds(new_bounds);
|
| + EXPECT_EQ(new_bounds, root_window()->bounds());
|
| +
|
| + // Simulate the server responding with a bounds change.
|
| + const gfx::Rect server_changed_bounds(gfx::Rect(0, 0, 101, 102));
|
| + window_tree_client()->OnWindowBoundsChanged(
|
| + server_id(root_window()), original_bounds, server_changed_bounds);
|
| +
|
| + // This shouldn't trigger the bounds changing yet.
|
| + EXPECT_EQ(new_bounds, root_window()->bounds());
|
| +
|
| + // Tell the client the change failed, which should trigger failing to the
|
| + // most recent bounds from server.
|
| + ASSERT_TRUE(window_tree()->AckSingleChangeOfType(WindowTreeChangeType::BOUNDS,
|
| + false));
|
| + EXPECT_EQ(server_changed_bounds, root_window()->bounds());
|
| +
|
| + // Simulate server changing back to original bounds. Should take immediately.
|
| + window_tree_client()->OnWindowBoundsChanged(
|
| + server_id(root_window()), server_changed_bounds, original_bounds);
|
| + EXPECT_EQ(original_bounds, root_window()->bounds());
|
| +}
|
| +
|
| +TEST_F(WindowTreeClientWmTest, TwoInFlightBoundsChangesBothCanceled) {
|
| + const gfx::Rect original_bounds(root_window()->bounds());
|
| + const gfx::Rect bounds1(gfx::Rect(0, 0, 100, 100));
|
| + const gfx::Rect bounds2(gfx::Rect(0, 0, 100, 102));
|
| + root_window()->SetBounds(bounds1);
|
| + EXPECT_EQ(bounds1, root_window()->bounds());
|
| +
|
| + root_window()->SetBounds(bounds2);
|
| + EXPECT_EQ(bounds2, root_window()->bounds());
|
| +
|
| + // Tell the client the first bounds failed. As there is a still a change in
|
| + // flight nothing should happen.
|
| + ASSERT_TRUE(
|
| + window_tree()->AckFirstChangeOfType(WindowTreeChangeType::BOUNDS, false));
|
| + EXPECT_EQ(bounds2, root_window()->bounds());
|
| +
|
| + // Tell the client the seconds bounds failed. Should now fallback to original
|
| + // value.
|
| + ASSERT_TRUE(window_tree()->AckSingleChangeOfType(WindowTreeChangeType::BOUNDS,
|
| + false));
|
| + EXPECT_EQ(original_bounds, root_window()->bounds());
|
| +}
|
| +
|
| +// Verifies properties are reverted if the server replied that the change
|
| +// failed.
|
| +TEST_F(WindowTreeClientWmTest, SetPropertyFailed) {
|
| + SetPropertyConverter(base::MakeUnique<TestPropertyConverter>());
|
| + ASSERT_FALSE(root_window()->GetProperty(client::kAlwaysOnTopKey));
|
| + root_window()->SetProperty(client::kAlwaysOnTopKey, true);
|
| + EXPECT_TRUE(root_window()->GetProperty(client::kAlwaysOnTopKey));
|
| + mojo::Array<uint8_t> transport_value = window_tree()->GetLastPropertyValue();
|
| + ASSERT_FALSE(transport_value.is_null());
|
| + ASSERT_EQ(1u, transport_value.size());
|
| + EXPECT_EQ(1, transport_value[0]);
|
| + ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
|
| + WindowTreeChangeType::PROPERTY, false));
|
| + EXPECT_FALSE(root_window()->GetProperty(client::kAlwaysOnTopKey));
|
| +}
|
| +
|
| +// Simulates a property change, and while the property change is in flight the
|
| +// server replies with a new property and the original property change fails.
|
| +TEST_F(WindowTreeClientWmTest, SetPropertyFailedWithPendingChange) {
|
| + SetPropertyConverter(base::MakeUnique<TestPropertyConverter>());
|
| + const uint8_t value1 = 11;
|
| + root_window()->SetProperty(kTestPropertyKey1, value1);
|
| + EXPECT_EQ(value1, root_window()->GetProperty(kTestPropertyKey1));
|
| +
|
| + // Simulate the server responding with a different value.
|
| + const uint8_t server_value = 12;
|
| + window_tree_client()->OnWindowSharedPropertyChanged(
|
| + server_id(root_window()), kTestPropertyServerKey1,
|
| + Uint8ToPropertyTransportValue(server_value));
|
| +
|
| + // This shouldn't trigger the property changing yet.
|
| + EXPECT_EQ(value1, root_window()->GetProperty(kTestPropertyKey1));
|
| +
|
| + // Tell the client the change failed, which should trigger failing to the
|
| + // most recent value from server.
|
| + ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
|
| + WindowTreeChangeType::PROPERTY, false));
|
| + EXPECT_EQ(server_value, root_window()->GetProperty(kTestPropertyKey1));
|
| +
|
| + // Simulate server changing back to value1. Should take immediately.
|
| + window_tree_client()->OnWindowSharedPropertyChanged(
|
| + server_id(root_window()), kTestPropertyServerKey1,
|
| + Uint8ToPropertyTransportValue(value1));
|
| + EXPECT_EQ(value1, root_window()->GetProperty(kTestPropertyKey1));
|
| +}
|
| +
|
| +// Verifies visible is reverted if the server replied that the change failed.
|
| +TEST_F(WindowTreeClientWmTest, SetVisibleFailed) {
|
| + const bool original_visible = root_window()->TargetVisibility();
|
| + const bool new_visible = !original_visible;
|
| + SetWindowVisibility(root_window(), new_visible);
|
| + ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
|
| + WindowTreeChangeType::VISIBLE, false));
|
| + EXPECT_EQ(original_visible, root_window()->TargetVisibility());
|
| +}
|
| +
|
| +// Simulates a visible change, and while the visible change is in flight the
|
| +// server replies with a new visible and the original visible change fails.
|
| +TEST_F(WindowTreeClientWmTest, SetVisibleFailedWithPendingChange) {
|
| + const bool original_visible = root_window()->TargetVisibility();
|
| + const bool new_visible = !original_visible;
|
| + SetWindowVisibility(root_window(), new_visible);
|
| + EXPECT_EQ(new_visible, root_window()->TargetVisibility());
|
| +
|
| + // Simulate the server responding with a visible change.
|
| + const bool server_changed_visible = !new_visible;
|
| + window_tree_client()->OnWindowVisibilityChanged(server_id(root_window()),
|
| + server_changed_visible);
|
| +
|
| + // This shouldn't trigger visible changing yet.
|
| + EXPECT_EQ(new_visible, root_window()->TargetVisibility());
|
| +
|
| + // Tell the client the change failed, which should trigger failing to the
|
| + // most recent visible from server.
|
| + ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
|
| + WindowTreeChangeType::VISIBLE, false));
|
| + EXPECT_EQ(server_changed_visible, root_window()->TargetVisibility());
|
| +
|
| + // Simulate server changing back to original visible. Should take immediately.
|
| + window_tree_client()->OnWindowVisibilityChanged(server_id(root_window()),
|
| + original_visible);
|
| + EXPECT_EQ(original_visible, root_window()->TargetVisibility());
|
| +}
|
| +
|
| +/*
|
| +// Verifies |is_modal| is reverted if the server replied that the change failed.
|
| +TEST_F(WindowTreeClientWmTest, SetModalFailed) {
|
| + WindowTreeSetup setup;
|
| + Window* root = GetFirstRoot();
|
| + ASSERT_TRUE(root);
|
| + EXPECT_FALSE(root->is_modal());
|
| + root->SetModal();
|
| + uint32_t change_id;
|
| + ASSERT_TRUE(window_tree()->GetAndClearChangeId(&change_id));
|
| + EXPECT_TRUE(root->is_modal());
|
| + window_tree_client()->OnChangeCompleted(change_id, false);
|
| + EXPECT_FALSE(root->is_modal());
|
| +}
|
| +*/
|
| +
|
| +namespace {
|
| +
|
| +class InputEventBasicTestWindowDelegate : public test::TestWindowDelegate {
|
| + public:
|
| + static uint32_t constexpr kEventId = 1;
|
| +
|
| + explicit InputEventBasicTestWindowDelegate(TestWindowTree* test_window_tree)
|
| + : test_window_tree_(test_window_tree) {}
|
| + ~InputEventBasicTestWindowDelegate() override {}
|
| +
|
| + bool got_move() const { return got_move_; }
|
| + bool was_acked() const { return was_acked_; }
|
| +
|
| + // TestWindowDelegate::
|
| + void OnMouseEvent(ui::MouseEvent* event) override {
|
| + was_acked_ = test_window_tree_->WasEventAcked(kEventId);
|
| + if (event->type() == ui::ET_MOUSE_MOVED)
|
| + got_move_ = true;
|
| + }
|
| +
|
| + private:
|
| + TestWindowTree* test_window_tree_;
|
| + bool was_acked_ = false;
|
| + bool got_move_ = false;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(InputEventBasicTestWindowDelegate);
|
| +};
|
| +
|
| +} // namespace
|
| +
|
| +TEST_F(WindowTreeClientClientTest, InputEventBasic) {
|
| + InputEventBasicTestWindowDelegate window_delegate(window_tree());
|
| + std::unique_ptr<Window> top_level(base::MakeUnique<Window>(&window_delegate));
|
| + top_level->SetType(ui::wm::WINDOW_TYPE_NORMAL);
|
| + top_level->Init(ui::LAYER_NOT_DRAWN);
|
| + top_level->SetBounds(gfx::Rect(0, 0, 100, 100));
|
| + top_level->Show();
|
| + EXPECT_FALSE(window_delegate.got_move());
|
| + EXPECT_FALSE(window_delegate.was_acked());
|
| + std::unique_ptr<ui::Event> ui_event(
|
| + new ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(),
|
| + ui::EventTimeForNow(), ui::EF_NONE, 0));
|
| + window_tree_client()->OnWindowInputEvent(
|
| + InputEventBasicTestWindowDelegate::kEventId, server_id(top_level.get()),
|
| + ui::Event::Clone(*ui_event.get()), 0);
|
| + EXPECT_TRUE(window_tree()->WasEventAcked(1));
|
| + EXPECT_TRUE(window_delegate.got_move());
|
| + EXPECT_FALSE(window_delegate.was_acked());
|
| +}
|
| +
|
| +class WindowTreeClientPointerObserverTest : public WindowTreeClientClientTest {
|
| + public:
|
| + WindowTreeClientPointerObserverTest() {}
|
| + ~WindowTreeClientPointerObserverTest() override {}
|
| +
|
| + void DeleteLastEventObserved() { last_event_observed_.reset(); }
|
| + const ui::PointerEvent* last_event_observed() const {
|
| + return last_event_observed_.get();
|
| + }
|
| +
|
| + // WindowTreeClientClientTest:
|
| + void OnPointerEventObserved(const ui::PointerEvent& event,
|
| + Window* target) override {
|
| + last_event_observed_.reset(new ui::PointerEvent(event));
|
| + }
|
| +
|
| + private:
|
| + std::unique_ptr<ui::PointerEvent> last_event_observed_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(WindowTreeClientPointerObserverTest);
|
| +};
|
| +
|
| +// Tests pointer watchers triggered by events that did not hit a target in this
|
| +// window tree.
|
| +TEST_F(WindowTreeClientPointerObserverTest, OnPointerEventObserved) {
|
| + std::unique_ptr<Window> top_level(base::MakeUnique<Window>(nullptr));
|
| + top_level->SetType(ui::wm::WINDOW_TYPE_NORMAL);
|
| + top_level->Init(ui::LAYER_NOT_DRAWN);
|
| + top_level->SetBounds(gfx::Rect(0, 0, 100, 100));
|
| + top_level->Show();
|
| +
|
| + // Start a pointer watcher for all events excluding move events.
|
| + window_tree_client_impl()->StartPointerWatcher(false /* want_moves */);
|
| +
|
| + // Simulate the server sending an observed event.
|
| + std::unique_ptr<ui::PointerEvent> pointer_event_down(new ui::PointerEvent(
|
| + ui::ET_POINTER_DOWN, gfx::Point(), gfx::Point(), ui::EF_CONTROL_DOWN, 1,
|
| + 0, ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH),
|
| + base::TimeTicks()));
|
| + window_tree_client()->OnPointerEventObserved(std::move(pointer_event_down),
|
| + 0u);
|
| +
|
| + // Delegate sensed the event.
|
| + const ui::PointerEvent* last_event = last_event_observed();
|
| + ASSERT_TRUE(last_event);
|
| + EXPECT_EQ(ui::ET_POINTER_DOWN, last_event->type());
|
| + EXPECT_EQ(ui::EF_CONTROL_DOWN, last_event->flags());
|
| + DeleteLastEventObserved();
|
| +
|
| + // Stop the pointer watcher.
|
| + window_tree_client_impl()->StopPointerWatcher();
|
| +
|
| + // Simulate another event from the server.
|
| + std::unique_ptr<ui::PointerEvent> pointer_event_up(new ui::PointerEvent(
|
| + ui::ET_POINTER_UP, gfx::Point(), gfx::Point(), ui::EF_CONTROL_DOWN, 1, 0,
|
| + ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH),
|
| + base::TimeTicks()));
|
| + window_tree_client()->OnPointerEventObserved(std::move(pointer_event_up), 0u);
|
| +
|
| + // No event was sensed.
|
| + EXPECT_FALSE(last_event_observed());
|
| +}
|
| +
|
| +// Tests pointer watchers triggered by events that hit this window tree.
|
| +TEST_F(WindowTreeClientPointerObserverTest,
|
| + OnWindowInputEventWithPointerWatcher) {
|
| + std::unique_ptr<Window> top_level(base::MakeUnique<Window>(nullptr));
|
| + top_level->SetType(ui::wm::WINDOW_TYPE_NORMAL);
|
| + top_level->Init(ui::LAYER_NOT_DRAWN);
|
| + top_level->SetBounds(gfx::Rect(0, 0, 100, 100));
|
| + top_level->Show();
|
| +
|
| + // Start a pointer watcher for all events excluding move events.
|
| + window_tree_client_impl()->StartPointerWatcher(false /* want_moves */);
|
| +
|
| + // Simulate the server dispatching an event that also matched the observer.
|
| + std::unique_ptr<ui::PointerEvent> pointer_event_down(new ui::PointerEvent(
|
| + ui::ET_POINTER_DOWN, gfx::Point(), gfx::Point(), ui::EF_CONTROL_DOWN, 1,
|
| + 0, ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH),
|
| + base::TimeTicks::Now()));
|
| + window_tree_client()->OnWindowInputEvent(1, server_id(top_level.get()),
|
| + std::move(pointer_event_down), true);
|
| +
|
| + // Delegate sensed the event.
|
| + const ui::Event* last_event = last_event_observed();
|
| + ASSERT_TRUE(last_event);
|
| + EXPECT_EQ(ui::ET_POINTER_DOWN, last_event->type());
|
| + EXPECT_EQ(ui::EF_CONTROL_DOWN, last_event->flags());
|
| +}
|
| +
|
| +// Verifies focus is reverted if the server replied that the change failed.
|
| +TEST_F(WindowTreeClientWmTest, SetFocusFailed) {
|
| + Window child(nullptr);
|
| + child.Init(ui::LAYER_NOT_DRAWN);
|
| + root_window()->AddChild(&child);
|
| + child.Focus();
|
| + ASSERT_TRUE(child.HasFocus());
|
| + ASSERT_TRUE(
|
| + window_tree()->AckSingleChangeOfType(WindowTreeChangeType::FOCUS, false));
|
| + EXPECT_EQ(nullptr, client::GetFocusClient(&child)->GetFocusedWindow());
|
| +}
|
| +
|
| +// Simulates a focus change, and while the focus change is in flight the server
|
| +// replies with a new focus and the original focus change fails.
|
| +TEST_F(WindowTreeClientWmTest, SetFocusFailedWithPendingChange) {
|
| + Window child1(nullptr);
|
| + child1.Init(ui::LAYER_NOT_DRAWN);
|
| + root_window()->AddChild(&child1);
|
| + Window child2(nullptr);
|
| + child2.Init(ui::LAYER_NOT_DRAWN);
|
| + root_window()->AddChild(&child2);
|
| + Window* original_focus = client::GetFocusClient(&child1)->GetFocusedWindow();
|
| + Window* new_focus = &child1;
|
| + ASSERT_NE(new_focus, original_focus);
|
| + new_focus->Focus();
|
| + ASSERT_TRUE(new_focus->HasFocus());
|
| +
|
| + // Simulate the server responding with a focus change.
|
| + window_tree_client()->OnWindowFocused(server_id(&child2));
|
| +
|
| + // This shouldn't trigger focus changing yet.
|
| + EXPECT_TRUE(child1.HasFocus());
|
| +
|
| + // Tell the client the change failed, which should trigger failing to the
|
| + // most recent focus from server.
|
| + ASSERT_TRUE(
|
| + window_tree()->AckSingleChangeOfType(WindowTreeChangeType::FOCUS, false));
|
| + EXPECT_FALSE(child1.HasFocus());
|
| + EXPECT_TRUE(child2.HasFocus());
|
| + EXPECT_EQ(&child2, client::GetFocusClient(&child1)->GetFocusedWindow());
|
| +
|
| + // Simulate server changing focus to child1. Should take immediately.
|
| + window_tree_client()->OnWindowFocused(server_id(&child1));
|
| + EXPECT_TRUE(child1.HasFocus());
|
| +}
|
| +
|
| +TEST_F(WindowTreeClientWmTest, FocusOnRemovedWindowWithInFlightFocusChange) {
|
| + std::unique_ptr<Window> child1(base::MakeUnique<Window>(nullptr));
|
| + child1->Init(ui::LAYER_NOT_DRAWN);
|
| + root_window()->AddChild(child1.get());
|
| + Window child2(nullptr);
|
| + child2.Init(ui::LAYER_NOT_DRAWN);
|
| + root_window()->AddChild(&child2);
|
| +
|
| + child1->Focus();
|
| +
|
| + // Destroy child1, which should set focus to null.
|
| + child1.reset(nullptr);
|
| + EXPECT_EQ(nullptr, client::GetFocusClient(root_window())->GetFocusedWindow());
|
| +
|
| + // Server changes focus to 2.
|
| + window_tree_client()->OnWindowFocused(server_id(&child2));
|
| + // Shouldn't take immediately.
|
| + EXPECT_FALSE(child2.HasFocus());
|
| +
|
| + // Ack both changes, focus should still be null.
|
| + ASSERT_TRUE(
|
| + window_tree()->AckFirstChangeOfType(WindowTreeChangeType::FOCUS, true));
|
| + EXPECT_EQ(nullptr, client::GetFocusClient(root_window())->GetFocusedWindow());
|
| + ASSERT_TRUE(
|
| + window_tree()->AckSingleChangeOfType(WindowTreeChangeType::FOCUS, true));
|
| + EXPECT_EQ(nullptr, client::GetFocusClient(root_window())->GetFocusedWindow());
|
| +
|
| + // Change to 2 again, this time it should take.
|
| + window_tree_client()->OnWindowFocused(server_id(&child2));
|
| + EXPECT_TRUE(child2.HasFocus());
|
| +}
|
| +
|
| +class ToggleVisibilityFromDestroyedObserver : public WindowObserver {
|
| + public:
|
| + explicit ToggleVisibilityFromDestroyedObserver(Window* window)
|
| + : window_(window) {
|
| + window_->AddObserver(this);
|
| + }
|
| +
|
| + ToggleVisibilityFromDestroyedObserver() { EXPECT_FALSE(window_); }
|
| +
|
| + // WindowObserver:
|
| + void OnWindowDestroyed(Window* window) override {
|
| + SetWindowVisibility(window, !window->TargetVisibility());
|
| + window_->RemoveObserver(this);
|
| + window_ = nullptr;
|
| + }
|
| +
|
| + private:
|
| + Window* window_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(ToggleVisibilityFromDestroyedObserver);
|
| +};
|
| +
|
| +TEST_F(WindowTreeClientWmTest, ToggleVisibilityFromWindowDestroyed) {
|
| + std::unique_ptr<Window> child(base::MakeUnique<Window>(nullptr));
|
| + child->Init(ui::LAYER_NOT_DRAWN);
|
| + root_window()->AddChild(child.get());
|
| + ToggleVisibilityFromDestroyedObserver toggler(child.get());
|
| + // Destroying the window triggers
|
| + // ToggleVisibilityFromDestroyedObserver::OnWindowDestroyed(), which toggles
|
| + // the visibility of the window. Ack the change, which should not crash or
|
| + // trigger DCHECKs.
|
| + child.reset();
|
| + ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
|
| + WindowTreeChangeType::VISIBLE, true));
|
| +}
|
| +
|
| +TEST_F(WindowTreeClientClientTest, NewTopLevelWindow) {
|
| + const size_t initial_root_count =
|
| + window_tree_client_impl()->GetRoots().size();
|
| + std::unique_ptr<Window> top_level(base::MakeUnique<Window>(nullptr));
|
| + top_level->SetType(ui::wm::WINDOW_TYPE_NORMAL);
|
| + top_level->Init(ui::LAYER_NOT_DRAWN);
|
| + // TODO: need to check WindowTreeHost visibility.
|
| + // EXPECT_TRUE(WindowPrivate(root2).parent_drawn());
|
| + EXPECT_NE(server_id(top_level.get()), server_id(root_window()));
|
| + EXPECT_EQ(initial_root_count + 1,
|
| + window_tree_client_impl()->GetRoots().size());
|
| + EXPECT_TRUE(window_tree_client_impl()->GetRoots().count(top_level.get()) >
|
| + 0u);
|
| +
|
| + // Ack the request to the windowtree to create the new window.
|
| + uint32_t change_id;
|
| + ASSERT_TRUE(window_tree()->GetAndRemoveFirstChangeOfType(
|
| + WindowTreeChangeType::NEW_TOP_LEVEL, &change_id));
|
| + EXPECT_EQ(window_tree()->window_id(), server_id(top_level.get()));
|
| +
|
| + ui::mojom::WindowDataPtr data = ui::mojom::WindowData::New();
|
| + data->window_id = server_id(top_level.get());
|
| + const int64_t display_id = 1;
|
| + window_tree_client()->OnTopLevelCreated(change_id, std::move(data),
|
| + display_id, false);
|
| +
|
| + // TODO: need to check WindowTreeHost visibility.
|
| + // EXPECT_FALSE(WindowPrivate(root2).parent_drawn());
|
| +
|
| + // Should not be able to add a top level as a child of another window.
|
| + // TODO(sky): decide how to handle this.
|
| + // root_window()->AddChild(top_level.get());
|
| + // ASSERT_EQ(nullptr, top_level->parent());
|
| +
|
| + // Destroy the first root, shouldn't initiate tear down.
|
| + top_level.reset();
|
| + EXPECT_EQ(initial_root_count, window_tree_client_impl()->GetRoots().size());
|
| +}
|
| +
|
| +TEST_F(WindowTreeClientClientTest, NewTopLevelWindowGetsPropertiesFromData) {
|
| + const size_t initial_root_count =
|
| + window_tree_client_impl()->GetRoots().size();
|
| + std::unique_ptr<Window> top_level(base::MakeUnique<Window>(nullptr));
|
| + top_level->SetType(ui::wm::WINDOW_TYPE_NORMAL);
|
| + top_level->Init(ui::LAYER_NOT_DRAWN);
|
| + EXPECT_EQ(initial_root_count + 1,
|
| + window_tree_client_impl()->GetRoots().size());
|
| +
|
| + // TODO: check drawn.
|
| + // EXPECT_FALSE(root2->IsDrawn());
|
| + EXPECT_FALSE(top_level->TargetVisibility());
|
| +
|
| + // Ack the request to the windowtree to create the new window.
|
| + EXPECT_EQ(window_tree()->window_id(), server_id(top_level.get()));
|
| +
|
| + ui::mojom::WindowDataPtr data = ui::mojom::WindowData::New();
|
| + data->window_id = server_id(top_level.get());
|
| + data->bounds.SetRect(1, 2, 3, 4);
|
| + data->visible = true;
|
| + const int64_t display_id = 1;
|
| + uint32_t change_id;
|
| + ASSERT_TRUE(window_tree()->GetAndRemoveFirstChangeOfType(
|
| + WindowTreeChangeType::NEW_TOP_LEVEL, &change_id));
|
| + window_tree_client()->OnTopLevelCreated(change_id, std::move(data),
|
| + display_id, true);
|
| +
|
| + // Make sure all the properties took.
|
| + // EXPECT_TRUE(root2->IsDrawn());
|
| + EXPECT_TRUE(top_level->TargetVisibility());
|
| + // TODO: check display_id.
|
| + // EXPECT_EQ(1, root2->display_id());
|
| + EXPECT_EQ(gfx::Rect(1, 2, 3, 4), top_level->bounds());
|
| +}
|
| +
|
| +TEST_F(WindowTreeClientClientTest, NewWindowGetsAllChangesInFlight) {
|
| + SetPropertyConverter(base::MakeUnique<TestPropertyConverter>());
|
| +
|
| + Window window(nullptr);
|
| + window.Init(ui::LAYER_NOT_DRAWN);
|
| +
|
| + EXPECT_FALSE(window.TargetVisibility());
|
| +
|
| + // Make visibility go from false->true->false. Don't ack immediately.
|
| + window.Show();
|
| + window.Hide();
|
| +
|
| + // Change bounds to 5, 6, 7, 8.
|
| + window.SetBounds(gfx::Rect(5, 6, 7, 8));
|
| +
|
| + const uint8_t explicitly_set_test_property1_value = 2;
|
| + window.SetProperty(kTestPropertyKey1, explicitly_set_test_property1_value);
|
| +
|
| + // Ack the new window top level window. Vis and bounds shouldn't change.
|
| + ui::mojom::WindowDataPtr data = ui::mojom::WindowData::New();
|
| + data->window_id = server_id(&window);
|
| + data->bounds.SetRect(1, 2, 3, 4);
|
| + data->visible = true;
|
| + const uint8_t server_test_property1_value = 3;
|
| + data->properties[kTestPropertyServerKey1] =
|
| + Uint8ToPropertyTransportValue(server_test_property1_value);
|
| + const uint8_t server_test_property2_value = 4;
|
| + data->properties[kTestPropertyServerKey2] =
|
| + Uint8ToPropertyTransportValue(server_test_property2_value);
|
| + const int64_t display_id = 1;
|
| + // Get the id of the in flight change for creating the new window.
|
| + uint32_t new_window_in_flight_change_id;
|
| + ASSERT_TRUE(window_tree()->GetAndRemoveFirstChangeOfType(
|
| + WindowTreeChangeType::NEW_WINDOW, &new_window_in_flight_change_id));
|
| + window_tree_client()->OnTopLevelCreated(new_window_in_flight_change_id,
|
| + std::move(data), display_id, true);
|
| +
|
| + // The only value that should take effect is the property for 'yy' as it was
|
| + // not in flight.
|
| + EXPECT_FALSE(window.TargetVisibility());
|
| + EXPECT_EQ(gfx::Rect(5, 6, 7, 8), window.bounds());
|
| + EXPECT_EQ(explicitly_set_test_property1_value,
|
| + window.GetProperty(kTestPropertyKey1));
|
| + EXPECT_EQ(server_test_property2_value, window.GetProperty(kTestPropertyKey2));
|
| +
|
| + // Tell the client the changes failed. This should cause the values to change
|
| + // to that of the server.
|
| + ASSERT_TRUE(window_tree()->AckFirstChangeOfType(WindowTreeChangeType::VISIBLE,
|
| + false));
|
| + EXPECT_FALSE(window.TargetVisibility());
|
| + ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
|
| + WindowTreeChangeType::VISIBLE, false));
|
| + EXPECT_TRUE(window.TargetVisibility());
|
| + window_tree()->AckAllChangesOfType(WindowTreeChangeType::BOUNDS, false);
|
| + EXPECT_EQ(gfx::Rect(1, 2, 3, 4), window.bounds());
|
| + ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
|
| + WindowTreeChangeType::PROPERTY, false));
|
| + EXPECT_EQ(server_test_property1_value, window.GetProperty(kTestPropertyKey1));
|
| + EXPECT_EQ(server_test_property2_value, window.GetProperty(kTestPropertyKey2));
|
| +}
|
| +
|
| +TEST_F(WindowTreeClientClientTest, NewWindowGetsProperties) {
|
| + SetPropertyConverter(base::MakeUnique<TestPropertyConverter>());
|
| + Window window(nullptr);
|
| + const uint8_t explicitly_set_test_property1_value = 29;
|
| + window.SetProperty(kTestPropertyKey1, explicitly_set_test_property1_value);
|
| + window.Init(ui::LAYER_NOT_DRAWN);
|
| + mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties =
|
| + window_tree()->GetLastNewWindowProperties();
|
| + ASSERT_FALSE(transport_properties.is_null());
|
| + std::map<std::string, std::vector<uint8_t>> properties =
|
| + transport_properties.To<std::map<std::string, std::vector<uint8_t>>>();
|
| + ASSERT_EQ(1u, properties.count(kTestPropertyServerKey1));
|
| + ASSERT_EQ(1u, properties[kTestPropertyServerKey1].size());
|
| + EXPECT_EQ(explicitly_set_test_property1_value,
|
| + properties[kTestPropertyServerKey1][0]);
|
| + ASSERT_EQ(0u, properties.count(kTestPropertyServerKey2));
|
| +}
|
| +
|
| +/*
|
| +// Tests that if the client has multiple unowned windows, and one of them is a
|
| +// transient child to another, the teardown can happen cleanly.
|
| +TEST_F(WindowTreeClientWmTest, MultipleUnOwnedWindowsDuringDestruction) {
|
| + std::unique_ptr<WindowTreeSetup> setup(new WindowTreeSetup());
|
| + Window* root1 = setup->GetFirstRoot();
|
| + ASSERT_TRUE(root1);
|
| + Window* root2 = setup->client()->NewTopLevelWindow(nullptr);
|
| + ASSERT_TRUE(root2);
|
| + root1->AddTransientWindow(root2);
|
| +
|
| + WindowTracker tracker;
|
| + tracker.Add(root1);
|
| + tracker.Add(root2);
|
| + reset();
|
| + EXPECT_TRUE(tracker.windows().empty());
|
| +}
|
| +*/
|
| +
|
| +TEST_F(WindowTreeClientClientTest,
|
| + TopLevelWindowDestroyedBeforeCreateComplete) {
|
| + const size_t initial_root_count =
|
| + window_tree_client_impl()->GetRoots().size();
|
| + std::unique_ptr<Window> top_level(base::MakeUnique<Window>(nullptr));
|
| + top_level->SetType(ui::wm::WINDOW_TYPE_NORMAL);
|
| + top_level->Init(ui::LAYER_NOT_DRAWN);
|
| + EXPECT_EQ(initial_root_count + 1,
|
| + window_tree_client_impl()->GetRoots().size());
|
| +
|
| + ui::mojom::WindowDataPtr data = ui::mojom::WindowData::New();
|
| + data->window_id = server_id(top_level.get());
|
| +
|
| + // Destroy the window before the server has a chance to ack the window
|
| + // creation.
|
| + top_level.reset();
|
| + EXPECT_EQ(initial_root_count, window_tree_client_impl()->GetRoots().size());
|
| +
|
| + // Get the id of the in flight change for creating the new window.
|
| + uint32_t change_id;
|
| + ASSERT_TRUE(window_tree()->GetAndRemoveFirstChangeOfType(
|
| + WindowTreeChangeType::NEW_TOP_LEVEL, &change_id));
|
| +
|
| + const int64_t display_id = 1;
|
| + window_tree_client()->OnTopLevelCreated(change_id, std::move(data),
|
| + display_id, true);
|
| + EXPECT_EQ(initial_root_count, window_tree_client_impl()->GetRoots().size());
|
| +}
|
| +
|
| +// Tests both SetCapture and ReleaseCapture, to ensure that Window is properly
|
| +// updated on failures.
|
| +TEST_F(WindowTreeClientWmTest, ExplicitCapture) {
|
| + root_window()->SetCapture();
|
| + EXPECT_TRUE(root_window()->HasCapture());
|
| + ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
|
| + WindowTreeChangeType::CAPTURE, false));
|
| + EXPECT_FALSE(root_window()->HasCapture());
|
| +
|
| + root_window()->SetCapture();
|
| + EXPECT_TRUE(root_window()->HasCapture());
|
| + ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
|
| + WindowTreeChangeType::CAPTURE, true));
|
| + EXPECT_TRUE(root_window()->HasCapture());
|
| +
|
| + root_window()->ReleaseCapture();
|
| + EXPECT_FALSE(root_window()->HasCapture());
|
| + ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
|
| + WindowTreeChangeType::CAPTURE, false));
|
| + EXPECT_TRUE(root_window()->HasCapture());
|
| +
|
| + root_window()->ReleaseCapture();
|
| + ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
|
| + WindowTreeChangeType::CAPTURE, true));
|
| + EXPECT_FALSE(root_window()->HasCapture());
|
| +}
|
| +
|
| +// Tests that when capture is lost, while there is a release capture request
|
| +// inflight, that the revert value of that request is updated correctly.
|
| +TEST_F(WindowTreeClientWmTest, LostCaptureDifferentInFlightChange) {
|
| + root_window()->SetCapture();
|
| + EXPECT_TRUE(root_window()->HasCapture());
|
| + ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
|
| + WindowTreeChangeType::CAPTURE, true));
|
| + EXPECT_TRUE(root_window()->HasCapture());
|
| +
|
| + // The ReleaseCapture should be updated to the revert of the SetCapture.
|
| + root_window()->ReleaseCapture();
|
| +
|
| + window_tree_client()->OnCaptureChanged(0, server_id(root_window()));
|
| + EXPECT_FALSE(root_window()->HasCapture());
|
| +
|
| + ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
|
| + WindowTreeChangeType::CAPTURE, false));
|
| + EXPECT_FALSE(root_window()->HasCapture());
|
| +}
|
| +
|
| +// Tests that while two windows can inflight capture requests, that the
|
| +// WindowTreeClient only identifies one as having the current capture.
|
| +TEST_F(WindowTreeClientWmTest, TwoWindowsRequestCapture) {
|
| + Window child(nullptr);
|
| + child.Init(ui::LAYER_NOT_DRAWN);
|
| + root_window()->AddChild(&child);
|
| + child.Show();
|
| +
|
| + root_window()->SetCapture();
|
| + EXPECT_TRUE(root_window()->HasCapture());
|
| +
|
| + child.SetCapture();
|
| + EXPECT_TRUE(child.HasCapture());
|
| + EXPECT_FALSE(root_window()->HasCapture());
|
| +
|
| + ASSERT_TRUE(
|
| + window_tree()->AckFirstChangeOfType(WindowTreeChangeType::CAPTURE, true));
|
| + EXPECT_FALSE(root_window()->HasCapture());
|
| + EXPECT_TRUE(child.HasCapture());
|
| +
|
| + ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
|
| + WindowTreeChangeType::CAPTURE, false));
|
| + EXPECT_FALSE(child.HasCapture());
|
| + EXPECT_TRUE(root_window()->HasCapture());
|
| +
|
| + window_tree_client()->OnCaptureChanged(0, server_id(root_window()));
|
| + EXPECT_FALSE(root_window()->HasCapture());
|
| +}
|
| +
|
| +/*
|
| +TEST_F(WindowTreeClientWmTest, WindowDestroyedWhileTransientChildHasCapture) {
|
| + WindowTreeSetup setup;
|
| + Window* root = GetFirstRoot();
|
| + Window* transient_parent = client()->NewWindow();
|
| + Window* transient_child = client()->NewWindow();
|
| + transient_parent->SetVisible(true);
|
| + transient_child->SetVisible(true);
|
| + root->AddChild(transient_parent);
|
| + root->AddChild(transient_child);
|
| +
|
| + transient_parent->AddTransientWindow(transient_child);
|
| +
|
| + WindowTracker tracker;
|
| + tracker.Add(transient_parent);
|
| + tracker.Add(transient_child);
|
| + // Request a capture on the transient child, then destroy the transient
|
| + // parent. That will destroy both windows, and should reset the capture window
|
| + // correctly.
|
| + transient_child->SetCapture();
|
| + transient_parent->Destroy();
|
| + EXPECT_TRUE(tracker.windows().empty());
|
| +
|
| + // Create a new Window, and attempt to place capture on that.
|
| + Window* child = client()->NewWindow();
|
| + child->SetVisible(true);
|
| + root->AddChild(child);
|
| + child->SetCapture();
|
| + EXPECT_TRUE(child->HasCapture());
|
| +}
|
| +*/
|
| +
|
| +namespace {
|
| +
|
| +class CaptureRecorder : public client::CaptureClientObserver {
|
| + public:
|
| + explicit CaptureRecorder(Window* root_window) : root_window_(root_window) {
|
| + client::GetCaptureClient(root_window)->AddObserver(this);
|
| + }
|
| +
|
| + ~CaptureRecorder() override {
|
| + client::GetCaptureClient(root_window_)->RemoveObserver(this);
|
| + }
|
| +
|
| + void reset_capture_captured_count() { capture_changed_count_ = 0; }
|
| + int capture_changed_count() const { return capture_changed_count_; }
|
| + int last_gained_capture_window_id() const {
|
| + return last_gained_capture_window_id_;
|
| + }
|
| + int last_lost_capture_window_id() const {
|
| + return last_lost_capture_window_id_;
|
| + }
|
| +
|
| + // client::CaptureClientObserver:
|
| + void OnCaptureChanged(Window* lost_capture, Window* gained_capture) override {
|
| + capture_changed_count_++;
|
| + last_gained_capture_window_id_ = gained_capture ? gained_capture->id() : 0;
|
| + last_lost_capture_window_id_ = lost_capture ? lost_capture->id() : 0;
|
| + }
|
| +
|
| + private:
|
| + Window* root_window_;
|
| + int capture_changed_count_ = 0;
|
| + int last_gained_capture_window_id_ = 0;
|
| + int last_lost_capture_window_id_ = 0;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(CaptureRecorder);
|
| +};
|
| +
|
| +} // namespace
|
| +
|
| +TEST_F(WindowTreeClientWmTest, OnWindowTreeCaptureChanged) {
|
| + CaptureRecorder capture_recorder(root_window());
|
| +
|
| + std::unique_ptr<Window> child1(base::MakeUnique<Window>(nullptr));
|
| + const int child1_id = 1;
|
| + child1->Init(ui::LAYER_NOT_DRAWN);
|
| + child1->set_id(child1_id);
|
| + child1->Show();
|
| + root_window()->AddChild(child1.get());
|
| +
|
| + Window child2(nullptr);
|
| + const int child2_id = 2;
|
| + child2.Init(ui::LAYER_NOT_DRAWN);
|
| + child2.set_id(child2_id);
|
| + child2.Show();
|
| + root_window()->AddChild(&child2);
|
| +
|
| + EXPECT_EQ(0, capture_recorder.capture_changed_count());
|
| + // Give capture to child1 and ensure everyone is notified correctly.
|
| + child1->SetCapture();
|
| + ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
|
| + WindowTreeChangeType::CAPTURE, true));
|
| + EXPECT_EQ(1, capture_recorder.capture_changed_count());
|
| + EXPECT_EQ(child1_id, capture_recorder.last_gained_capture_window_id());
|
| + EXPECT_EQ(0, capture_recorder.last_lost_capture_window_id());
|
| + capture_recorder.reset_capture_captured_count();
|
| +
|
| + // Deleting a window with capture should notify observers as well.
|
| + child1.reset();
|
| +
|
| + // Deletion implicitly releases focus.
|
| + ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
|
| + WindowTreeChangeType::CAPTURE, true));
|
| +
|
| + EXPECT_EQ(1, capture_recorder.capture_changed_count());
|
| + EXPECT_EQ(0, capture_recorder.last_gained_capture_window_id());
|
| + EXPECT_EQ(child1_id, capture_recorder.last_lost_capture_window_id());
|
| + capture_recorder.reset_capture_captured_count();
|
| +
|
| + // Changes originating from server should notify observers too.
|
| + window_tree_client()->OnCaptureChanged(server_id(&child2), 0);
|
| + EXPECT_EQ(1, capture_recorder.capture_changed_count());
|
| + EXPECT_EQ(child2_id, capture_recorder.last_gained_capture_window_id());
|
| + EXPECT_EQ(0, capture_recorder.last_lost_capture_window_id());
|
| + capture_recorder.reset_capture_captured_count();
|
| +}
|
| +
|
| +} // namespace aura
|
|
|