| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/mus/public/cpp/lib/window_tree_client_impl.h" | 5 #include "components/mus/public/cpp/window_tree_client.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "components/mus/common/util.h" | 11 #include "components/mus/common/util.h" |
| 12 #include "components/mus/public/cpp/input_event_handler.h" | 12 #include "components/mus/public/cpp/input_event_handler.h" |
| 13 #include "components/mus/public/cpp/lib/window_private.h" | 13 #include "components/mus/public/cpp/lib/window_private.h" |
| 14 #include "components/mus/public/cpp/property_type_converters.h" | 14 #include "components/mus/public/cpp/property_type_converters.h" |
| 15 #include "components/mus/public/cpp/tests/test_window.h" | 15 #include "components/mus/public/cpp/tests/test_window.h" |
| 16 #include "components/mus/public/cpp/tests/test_window_tree.h" | 16 #include "components/mus/public/cpp/tests/test_window_tree.h" |
| 17 #include "components/mus/public/cpp/tests/window_tree_client_impl_private.h" | 17 #include "components/mus/public/cpp/tests/window_tree_client_private.h" |
| 18 #include "components/mus/public/cpp/window.h" | 18 #include "components/mus/public/cpp/window.h" |
| 19 #include "components/mus/public/cpp/window_observer.h" | 19 #include "components/mus/public/cpp/window_observer.h" |
| 20 #include "components/mus/public/cpp/window_property.h" | 20 #include "components/mus/public/cpp/window_property.h" |
| 21 #include "components/mus/public/cpp/window_tracker.h" | 21 #include "components/mus/public/cpp/window_tracker.h" |
| 22 #include "components/mus/public/cpp/window_tree_delegate.h" | 22 #include "components/mus/public/cpp/window_tree_client_delegate.h" |
| 23 #include "mojo/common/common_type_converters.h" | 23 #include "mojo/common/common_type_converters.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 25 #include "ui/events/event.h" | 25 #include "ui/events/event.h" |
| 26 #include "ui/events/event_utils.h" | 26 #include "ui/events/event_utils.h" |
| 27 #include "ui/events/mojo/input_events_type_converters.h" | 27 #include "ui/events/mojo/input_events_type_converters.h" |
| 28 #include "ui/gfx/geometry/rect.h" | 28 #include "ui/gfx/geometry/rect.h" |
| 29 | 29 |
| 30 namespace mus { | 30 namespace mus { |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 void DoNothingWithEventResult(mojom::EventResult result) {} | 34 void DoNothingWithEventResult(mojom::EventResult result) {} |
| 35 | 35 |
| 36 Id server_id(mus::Window* window) { | 36 Id server_id(mus::Window* window) { |
| 37 return WindowPrivate(window).server_id(); | 37 return WindowPrivate(window).server_id(); |
| 38 } | 38 } |
| 39 | 39 |
| 40 } // namespace | 40 } // namespace |
| 41 | 41 |
| 42 mojo::Array<uint8_t> Int32ToPropertyTransportValue(int32_t value) { | 42 mojo::Array<uint8_t> Int32ToPropertyTransportValue(int32_t value) { |
| 43 const std::vector<uint8_t> bytes = | 43 const std::vector<uint8_t> bytes = |
| 44 mojo::ConvertTo<std::vector<uint8_t>>(value); | 44 mojo::ConvertTo<std::vector<uint8_t>>(value); |
| 45 mojo::Array<uint8_t> transport_value; | 45 mojo::Array<uint8_t> transport_value; |
| 46 transport_value.resize(bytes.size()); | 46 transport_value.resize(bytes.size()); |
| 47 memcpy(&transport_value.front(), &(bytes.front()), bytes.size()); | 47 memcpy(&transport_value.front(), &(bytes.front()), bytes.size()); |
| 48 return transport_value; | 48 return transport_value; |
| 49 } | 49 } |
| 50 | 50 |
| 51 class TestWindowTreeDelegate : public WindowTreeDelegate { | 51 class TestWindowTreeClientDelegate : public WindowTreeClientDelegate { |
| 52 public: | 52 public: |
| 53 TestWindowTreeDelegate() {} | 53 TestWindowTreeClientDelegate() {} |
| 54 ~TestWindowTreeDelegate() override {} | 54 ~TestWindowTreeClientDelegate() override {} |
| 55 | 55 |
| 56 ui::Event* last_event_observed() { return last_event_observed_.get(); } | 56 ui::Event* last_event_observed() { return last_event_observed_.get(); } |
| 57 | 57 |
| 58 void Reset() { last_event_observed_.reset(); } | 58 void Reset() { last_event_observed_.reset(); } |
| 59 | 59 |
| 60 // WindowTreeDelegate: | 60 // WindowTreeClientDelegate: |
| 61 void OnEmbed(Window* root) override {} | 61 void OnEmbed(Window* root) override {} |
| 62 void OnConnectionLost(WindowTreeConnection* connection) override {} | 62 void OnWindowTreeClientDestroyed(WindowTreeClient* client) override {} |
| 63 void OnEventObserved(const ui::Event& event, Window* target) override { | 63 void OnEventObserved(const ui::Event& event, Window* target) override { |
| 64 last_event_observed_ = ui::Event::Clone(event); | 64 last_event_observed_ = ui::Event::Clone(event); |
| 65 } | 65 } |
| 66 | 66 |
| 67 private: | 67 private: |
| 68 std::unique_ptr<ui::Event> last_event_observed_; | 68 std::unique_ptr<ui::Event> last_event_observed_; |
| 69 | 69 |
| 70 DISALLOW_COPY_AND_ASSIGN(TestWindowTreeDelegate); | 70 DISALLOW_COPY_AND_ASSIGN(TestWindowTreeClientDelegate); |
| 71 }; | 71 }; |
| 72 | 72 |
| 73 class WindowTreeSetup { | 73 class WindowTreeSetup { |
| 74 public: | 74 public: |
| 75 WindowTreeSetup() : tree_client_(&window_tree_delegate_, nullptr, nullptr) { | 75 WindowTreeSetup() : tree_client_(&window_tree_delegate_, nullptr, nullptr) { |
| 76 WindowTreeClientImplPrivate(&tree_client_).OnEmbed(&window_tree_); | 76 WindowTreeClientPrivate(&tree_client_).OnEmbed(&window_tree_); |
| 77 window_tree_.GetAndClearChangeId(nullptr); | 77 window_tree_.GetAndClearChangeId(nullptr); |
| 78 } | 78 } |
| 79 | 79 |
| 80 WindowTreeConnection* window_tree_connection() { | 80 WindowTreeClient* client() { |
| 81 return static_cast<WindowTreeConnection*>(&tree_client_); | 81 return &tree_client_; |
| 82 } | 82 } |
| 83 | 83 |
| 84 mojom::WindowTreeClient* window_tree_client() { | 84 mojom::WindowTreeClient* window_tree_client() { |
| 85 return static_cast<mojom::WindowTreeClient*>(&tree_client_); | 85 return static_cast<mojom::WindowTreeClient*>(&tree_client_); |
| 86 } | 86 } |
| 87 | 87 |
| 88 TestWindowTree* window_tree() { return &window_tree_; } | 88 TestWindowTree* window_tree() { return &window_tree_; } |
| 89 | 89 |
| 90 TestWindowTreeDelegate* window_tree_delegate() { | 90 TestWindowTreeClientDelegate* window_tree_delegate() { |
| 91 return &window_tree_delegate_; | 91 return &window_tree_delegate_; |
| 92 } | 92 } |
| 93 | 93 |
| 94 Window* GetFirstRoot() { | 94 Window* GetFirstRoot() { |
| 95 return window_tree_connection()->GetRoots().empty() | 95 return client()->GetRoots().empty() ? nullptr |
| 96 ? nullptr | 96 : *client()->GetRoots().begin(); |
| 97 : *window_tree_connection()->GetRoots().begin(); | |
| 98 } | 97 } |
| 99 | 98 |
| 100 uint32_t GetEventObserverId() { | 99 uint32_t GetEventObserverId() { |
| 101 return WindowTreeClientImplPrivate(&tree_client_).event_observer_id(); | 100 return WindowTreeClientPrivate(&tree_client_).event_observer_id(); |
| 102 } | 101 } |
| 103 | 102 |
| 104 private: | 103 private: |
| 105 TestWindowTree window_tree_; | 104 TestWindowTree window_tree_; |
| 106 TestWindowTreeDelegate window_tree_delegate_; | 105 TestWindowTreeClientDelegate window_tree_delegate_; |
| 107 WindowTreeClientImpl tree_client_; | 106 WindowTreeClient tree_client_; |
| 108 | 107 |
| 109 DISALLOW_COPY_AND_ASSIGN(WindowTreeSetup); | 108 DISALLOW_COPY_AND_ASSIGN(WindowTreeSetup); |
| 110 }; | 109 }; |
| 111 | 110 |
| 112 class TestInputEventHandler : public InputEventHandler { | 111 class TestInputEventHandler : public InputEventHandler { |
| 113 public: | 112 public: |
| 114 TestInputEventHandler() | 113 TestInputEventHandler() |
| 115 : received_event_(false), should_manually_ack_(false) {} | 114 : received_event_(false), should_manually_ack_(false) {} |
| 116 ~TestInputEventHandler() override {} | 115 ~TestInputEventHandler() override {} |
| 117 | 116 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 146 } | 145 } |
| 147 } | 146 } |
| 148 | 147 |
| 149 bool received_event_; | 148 bool received_event_; |
| 150 bool should_manually_ack_; | 149 bool should_manually_ack_; |
| 151 base::Callback<void(mojom::EventResult)> ack_callback_; | 150 base::Callback<void(mojom::EventResult)> ack_callback_; |
| 152 | 151 |
| 153 DISALLOW_COPY_AND_ASSIGN(TestInputEventHandler); | 152 DISALLOW_COPY_AND_ASSIGN(TestInputEventHandler); |
| 154 }; | 153 }; |
| 155 | 154 |
| 156 using WindowTreeClientImplTest = testing::Test; | 155 using WindowTreeClientTest = testing::Test; |
| 157 | 156 |
| 158 // Verifies bounds are reverted if the server replied that the change failed. | 157 // Verifies bounds are reverted if the server replied that the change failed. |
| 159 TEST_F(WindowTreeClientImplTest, SetBoundsFailed) { | 158 TEST_F(WindowTreeClientTest, SetBoundsFailed) { |
| 160 WindowTreeSetup setup; | 159 WindowTreeSetup setup; |
| 161 Window* root = setup.GetFirstRoot(); | 160 Window* root = setup.GetFirstRoot(); |
| 162 ASSERT_TRUE(root); | 161 ASSERT_TRUE(root); |
| 163 const gfx::Rect original_bounds(root->bounds()); | 162 const gfx::Rect original_bounds(root->bounds()); |
| 164 const gfx::Rect new_bounds(gfx::Rect(0, 0, 100, 100)); | 163 const gfx::Rect new_bounds(gfx::Rect(0, 0, 100, 100)); |
| 165 ASSERT_NE(new_bounds, root->bounds()); | 164 ASSERT_NE(new_bounds, root->bounds()); |
| 166 root->SetBounds(new_bounds); | 165 root->SetBounds(new_bounds); |
| 167 uint32_t change_id; | 166 uint32_t change_id; |
| 168 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); | 167 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); |
| 169 setup.window_tree_client()->OnChangeCompleted(change_id, false); | 168 setup.window_tree_client()->OnChangeCompleted(change_id, false); |
| 170 EXPECT_EQ(original_bounds, root->bounds()); | 169 EXPECT_EQ(original_bounds, root->bounds()); |
| 171 } | 170 } |
| 172 | 171 |
| 173 // Simulates a bounds change, and while the bounds change is in flight the | 172 // Simulates a bounds change, and while the bounds change is in flight the |
| 174 // server replies with a new bounds and the original bounds change fails. | 173 // server replies with a new bounds and the original bounds change fails. |
| 175 TEST_F(WindowTreeClientImplTest, SetBoundsFailedWithPendingChange) { | 174 TEST_F(WindowTreeClientTest, SetBoundsFailedWithPendingChange) { |
| 176 WindowTreeSetup setup; | 175 WindowTreeSetup setup; |
| 177 Window* root = setup.GetFirstRoot(); | 176 Window* root = setup.GetFirstRoot(); |
| 178 ASSERT_TRUE(root); | 177 ASSERT_TRUE(root); |
| 179 const gfx::Rect original_bounds(root->bounds()); | 178 const gfx::Rect original_bounds(root->bounds()); |
| 180 const gfx::Rect new_bounds(gfx::Rect(0, 0, 100, 100)); | 179 const gfx::Rect new_bounds(gfx::Rect(0, 0, 100, 100)); |
| 181 ASSERT_NE(new_bounds, root->bounds()); | 180 ASSERT_NE(new_bounds, root->bounds()); |
| 182 root->SetBounds(new_bounds); | 181 root->SetBounds(new_bounds); |
| 183 EXPECT_EQ(new_bounds, root->bounds()); | 182 EXPECT_EQ(new_bounds, root->bounds()); |
| 184 uint32_t change_id; | 183 uint32_t change_id; |
| 185 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); | 184 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 196 // most recent bounds from server. | 195 // most recent bounds from server. |
| 197 setup.window_tree_client()->OnChangeCompleted(change_id, false); | 196 setup.window_tree_client()->OnChangeCompleted(change_id, false); |
| 198 EXPECT_EQ(server_changed_bounds, root->bounds()); | 197 EXPECT_EQ(server_changed_bounds, root->bounds()); |
| 199 | 198 |
| 200 // Simulate server changing back to original bounds. Should take immediately. | 199 // Simulate server changing back to original bounds. Should take immediately. |
| 201 setup.window_tree_client()->OnWindowBoundsChanged( | 200 setup.window_tree_client()->OnWindowBoundsChanged( |
| 202 server_id(root), server_changed_bounds, original_bounds); | 201 server_id(root), server_changed_bounds, original_bounds); |
| 203 EXPECT_EQ(original_bounds, root->bounds()); | 202 EXPECT_EQ(original_bounds, root->bounds()); |
| 204 } | 203 } |
| 205 | 204 |
| 206 TEST_F(WindowTreeClientImplTest, TwoInFlightBoundsChangesBothCanceled) { | 205 TEST_F(WindowTreeClientTest, TwoInFlightBoundsChangesBothCanceled) { |
| 207 WindowTreeSetup setup; | 206 WindowTreeSetup setup; |
| 208 Window* root = setup.GetFirstRoot(); | 207 Window* root = setup.GetFirstRoot(); |
| 209 ASSERT_TRUE(root); | 208 ASSERT_TRUE(root); |
| 210 const gfx::Rect original_bounds(root->bounds()); | 209 const gfx::Rect original_bounds(root->bounds()); |
| 211 const gfx::Rect bounds1(gfx::Rect(0, 0, 100, 100)); | 210 const gfx::Rect bounds1(gfx::Rect(0, 0, 100, 100)); |
| 212 const gfx::Rect bounds2(gfx::Rect(0, 0, 100, 102)); | 211 const gfx::Rect bounds2(gfx::Rect(0, 0, 100, 102)); |
| 213 root->SetBounds(bounds1); | 212 root->SetBounds(bounds1); |
| 214 EXPECT_EQ(bounds1, root->bounds()); | 213 EXPECT_EQ(bounds1, root->bounds()); |
| 215 uint32_t change_id1; | 214 uint32_t change_id1; |
| 216 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id1)); | 215 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id1)); |
| 217 | 216 |
| 218 root->SetBounds(bounds2); | 217 root->SetBounds(bounds2); |
| 219 EXPECT_EQ(bounds2, root->bounds()); | 218 EXPECT_EQ(bounds2, root->bounds()); |
| 220 uint32_t change_id2; | 219 uint32_t change_id2; |
| 221 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id2)); | 220 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id2)); |
| 222 | 221 |
| 223 // Tell the client change 1 failed. As there is a still a change in flight | 222 // Tell the client change 1 failed. As there is a still a change in flight |
| 224 // nothing should happen. | 223 // nothing should happen. |
| 225 setup.window_tree_client()->OnChangeCompleted(change_id1, false); | 224 setup.window_tree_client()->OnChangeCompleted(change_id1, false); |
| 226 EXPECT_EQ(bounds2, root->bounds()); | 225 EXPECT_EQ(bounds2, root->bounds()); |
| 227 | 226 |
| 228 // And tell the client change 2 failed too. Should now fallback to original | 227 // And tell the client change 2 failed too. Should now fallback to original |
| 229 // bounds. | 228 // bounds. |
| 230 setup.window_tree_client()->OnChangeCompleted(change_id2, false); | 229 setup.window_tree_client()->OnChangeCompleted(change_id2, false); |
| 231 EXPECT_EQ(original_bounds, root->bounds()); | 230 EXPECT_EQ(original_bounds, root->bounds()); |
| 232 } | 231 } |
| 233 | 232 |
| 234 // Verifies properties are reverted if the server replied that the change | 233 // Verifies properties are reverted if the server replied that the change |
| 235 // failed. | 234 // failed. |
| 236 TEST_F(WindowTreeClientImplTest, SetPropertyFailed) { | 235 TEST_F(WindowTreeClientTest, SetPropertyFailed) { |
| 237 WindowTreeSetup setup; | 236 WindowTreeSetup setup; |
| 238 Window* root = setup.GetFirstRoot(); | 237 Window* root = setup.GetFirstRoot(); |
| 239 ASSERT_TRUE(root); | 238 ASSERT_TRUE(root); |
| 240 ASSERT_FALSE(root->HasSharedProperty("foo")); | 239 ASSERT_FALSE(root->HasSharedProperty("foo")); |
| 241 const int32_t new_value = 11; | 240 const int32_t new_value = 11; |
| 242 root->SetSharedProperty("foo", new_value); | 241 root->SetSharedProperty("foo", new_value); |
| 243 ASSERT_TRUE(root->HasSharedProperty("foo")); | 242 ASSERT_TRUE(root->HasSharedProperty("foo")); |
| 244 EXPECT_EQ(new_value, root->GetSharedProperty<int32_t>("foo")); | 243 EXPECT_EQ(new_value, root->GetSharedProperty<int32_t>("foo")); |
| 245 uint32_t change_id; | 244 uint32_t change_id; |
| 246 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); | 245 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); |
| 247 setup.window_tree_client()->OnChangeCompleted(change_id, false); | 246 setup.window_tree_client()->OnChangeCompleted(change_id, false); |
| 248 EXPECT_FALSE(root->HasSharedProperty("foo")); | 247 EXPECT_FALSE(root->HasSharedProperty("foo")); |
| 249 } | 248 } |
| 250 | 249 |
| 251 // Simulates a property change, and while the property change is in flight the | 250 // Simulates a property change, and while the property change is in flight the |
| 252 // server replies with a new property and the original property change fails. | 251 // server replies with a new property and the original property change fails. |
| 253 TEST_F(WindowTreeClientImplTest, SetPropertyFailedWithPendingChange) { | 252 TEST_F(WindowTreeClientTest, SetPropertyFailedWithPendingChange) { |
| 254 WindowTreeSetup setup; | 253 WindowTreeSetup setup; |
| 255 Window* root = setup.GetFirstRoot(); | 254 Window* root = setup.GetFirstRoot(); |
| 256 ASSERT_TRUE(root); | 255 ASSERT_TRUE(root); |
| 257 const int32_t value1 = 11; | 256 const int32_t value1 = 11; |
| 258 root->SetSharedProperty("foo", value1); | 257 root->SetSharedProperty("foo", value1); |
| 259 ASSERT_TRUE(root->HasSharedProperty("foo")); | 258 ASSERT_TRUE(root->HasSharedProperty("foo")); |
| 260 EXPECT_EQ(value1, root->GetSharedProperty<int32_t>("foo")); | 259 EXPECT_EQ(value1, root->GetSharedProperty<int32_t>("foo")); |
| 261 uint32_t change_id; | 260 uint32_t change_id; |
| 262 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); | 261 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); |
| 263 | 262 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 277 EXPECT_EQ(server_value, root->GetSharedProperty<int32_t>("foo")); | 276 EXPECT_EQ(server_value, root->GetSharedProperty<int32_t>("foo")); |
| 278 | 277 |
| 279 // Simulate server changing back to value1. Should take immediately. | 278 // Simulate server changing back to value1. Should take immediately. |
| 280 setup.window_tree_client()->OnWindowSharedPropertyChanged( | 279 setup.window_tree_client()->OnWindowSharedPropertyChanged( |
| 281 server_id(root), "foo", Int32ToPropertyTransportValue(value1)); | 280 server_id(root), "foo", Int32ToPropertyTransportValue(value1)); |
| 282 ASSERT_TRUE(root->HasSharedProperty("foo")); | 281 ASSERT_TRUE(root->HasSharedProperty("foo")); |
| 283 EXPECT_EQ(value1, root->GetSharedProperty<int32_t>("foo")); | 282 EXPECT_EQ(value1, root->GetSharedProperty<int32_t>("foo")); |
| 284 } | 283 } |
| 285 | 284 |
| 286 // Verifies visible is reverted if the server replied that the change failed. | 285 // Verifies visible is reverted if the server replied that the change failed. |
| 287 TEST_F(WindowTreeClientImplTest, SetVisibleFailed) { | 286 TEST_F(WindowTreeClientTest, SetVisibleFailed) { |
| 288 WindowTreeSetup setup; | 287 WindowTreeSetup setup; |
| 289 Window* root = setup.GetFirstRoot(); | 288 Window* root = setup.GetFirstRoot(); |
| 290 ASSERT_TRUE(root); | 289 ASSERT_TRUE(root); |
| 291 const bool original_visible = root->visible(); | 290 const bool original_visible = root->visible(); |
| 292 const bool new_visible = !original_visible; | 291 const bool new_visible = !original_visible; |
| 293 ASSERT_NE(new_visible, root->visible()); | 292 ASSERT_NE(new_visible, root->visible()); |
| 294 root->SetVisible(new_visible); | 293 root->SetVisible(new_visible); |
| 295 uint32_t change_id; | 294 uint32_t change_id; |
| 296 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); | 295 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); |
| 297 setup.window_tree_client()->OnChangeCompleted(change_id, false); | 296 setup.window_tree_client()->OnChangeCompleted(change_id, false); |
| 298 EXPECT_EQ(original_visible, root->visible()); | 297 EXPECT_EQ(original_visible, root->visible()); |
| 299 } | 298 } |
| 300 | 299 |
| 301 // Simulates a visible change, and while the visible change is in flight the | 300 // Simulates a visible change, and while the visible change is in flight the |
| 302 // server replies with a new visible and the original visible change fails. | 301 // server replies with a new visible and the original visible change fails. |
| 303 TEST_F(WindowTreeClientImplTest, SetVisibleFailedWithPendingChange) { | 302 TEST_F(WindowTreeClientTest, SetVisibleFailedWithPendingChange) { |
| 304 WindowTreeSetup setup; | 303 WindowTreeSetup setup; |
| 305 Window* root = setup.GetFirstRoot(); | 304 Window* root = setup.GetFirstRoot(); |
| 306 ASSERT_TRUE(root); | 305 ASSERT_TRUE(root); |
| 307 const bool original_visible = root->visible(); | 306 const bool original_visible = root->visible(); |
| 308 const bool new_visible = !original_visible; | 307 const bool new_visible = !original_visible; |
| 309 ASSERT_NE(new_visible, root->visible()); | 308 ASSERT_NE(new_visible, root->visible()); |
| 310 root->SetVisible(new_visible); | 309 root->SetVisible(new_visible); |
| 311 EXPECT_EQ(new_visible, root->visible()); | 310 EXPECT_EQ(new_visible, root->visible()); |
| 312 uint32_t change_id; | 311 uint32_t change_id; |
| 313 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); | 312 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 326 EXPECT_EQ(server_changed_visible, root->visible()); | 325 EXPECT_EQ(server_changed_visible, root->visible()); |
| 327 | 326 |
| 328 // Simulate server changing back to original visible. Should take immediately. | 327 // Simulate server changing back to original visible. Should take immediately. |
| 329 setup.window_tree_client()->OnWindowVisibilityChanged(server_id(root), | 328 setup.window_tree_client()->OnWindowVisibilityChanged(server_id(root), |
| 330 original_visible); | 329 original_visible); |
| 331 EXPECT_EQ(original_visible, root->visible()); | 330 EXPECT_EQ(original_visible, root->visible()); |
| 332 } | 331 } |
| 333 | 332 |
| 334 // Verifies that local opacity is not changed if the server replied that the | 333 // Verifies that local opacity is not changed if the server replied that the |
| 335 // change succeeded. | 334 // change succeeded. |
| 336 TEST_F(WindowTreeClientImplTest, SetOpacitySucceeds) { | 335 TEST_F(WindowTreeClientTest, SetOpacitySucceeds) { |
| 337 WindowTreeSetup setup; | 336 WindowTreeSetup setup; |
| 338 Window* root = setup.GetFirstRoot(); | 337 Window* root = setup.GetFirstRoot(); |
| 339 ASSERT_TRUE(root); | 338 ASSERT_TRUE(root); |
| 340 const float original_opacity = root->opacity(); | 339 const float original_opacity = root->opacity(); |
| 341 const float new_opacity = 0.5f; | 340 const float new_opacity = 0.5f; |
| 342 ASSERT_NE(new_opacity, original_opacity); | 341 ASSERT_NE(new_opacity, original_opacity); |
| 343 ASSERT_NE(new_opacity, root->opacity()); | 342 ASSERT_NE(new_opacity, root->opacity()); |
| 344 root->SetOpacity(new_opacity); | 343 root->SetOpacity(new_opacity); |
| 345 uint32_t change_id; | 344 uint32_t change_id; |
| 346 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); | 345 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); |
| 347 setup.window_tree_client()->OnChangeCompleted(change_id, true); | 346 setup.window_tree_client()->OnChangeCompleted(change_id, true); |
| 348 EXPECT_EQ(new_opacity, root->opacity()); | 347 EXPECT_EQ(new_opacity, root->opacity()); |
| 349 } | 348 } |
| 350 | 349 |
| 351 // Verifies that opacity is reverted if the server replied that the change | 350 // Verifies that opacity is reverted if the server replied that the change |
| 352 // failed. | 351 // failed. |
| 353 TEST_F(WindowTreeClientImplTest, SetOpacityFailed) { | 352 TEST_F(WindowTreeClientTest, SetOpacityFailed) { |
| 354 WindowTreeSetup setup; | 353 WindowTreeSetup setup; |
| 355 Window* root = setup.GetFirstRoot(); | 354 Window* root = setup.GetFirstRoot(); |
| 356 ASSERT_TRUE(root); | 355 ASSERT_TRUE(root); |
| 357 const float original_opacity = root->opacity(); | 356 const float original_opacity = root->opacity(); |
| 358 const float new_opacity = 0.5f; | 357 const float new_opacity = 0.5f; |
| 359 ASSERT_NE(new_opacity, root->opacity()); | 358 ASSERT_NE(new_opacity, root->opacity()); |
| 360 root->SetOpacity(new_opacity); | 359 root->SetOpacity(new_opacity); |
| 361 uint32_t change_id; | 360 uint32_t change_id; |
| 362 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); | 361 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); |
| 363 setup.window_tree_client()->OnChangeCompleted(change_id, false); | 362 setup.window_tree_client()->OnChangeCompleted(change_id, false); |
| 364 EXPECT_EQ(original_opacity, root->opacity()); | 363 EXPECT_EQ(original_opacity, root->opacity()); |
| 365 } | 364 } |
| 366 | 365 |
| 367 // Simulates the server changing the opacitry while there is an opacity change | 366 // Simulates the server changing the opacitry while there is an opacity change |
| 368 // in flight, causing the requested change to fail. | 367 // in flight, causing the requested change to fail. |
| 369 TEST_F(WindowTreeClientImplTest, SetOpacityFailedWithPendingChange) { | 368 TEST_F(WindowTreeClientTest, SetOpacityFailedWithPendingChange) { |
| 370 WindowTreeSetup setup; | 369 WindowTreeSetup setup; |
| 371 Window* root = setup.GetFirstRoot(); | 370 Window* root = setup.GetFirstRoot(); |
| 372 ASSERT_TRUE(root); | 371 ASSERT_TRUE(root); |
| 373 const float original_opacity = root->opacity(); | 372 const float original_opacity = root->opacity(); |
| 374 const float new_opacity = 0.5f; | 373 const float new_opacity = 0.5f; |
| 375 ASSERT_NE(new_opacity, root->opacity()); | 374 ASSERT_NE(new_opacity, root->opacity()); |
| 376 root->SetOpacity(new_opacity); | 375 root->SetOpacity(new_opacity); |
| 377 EXPECT_EQ(new_opacity, root->opacity()); | 376 EXPECT_EQ(new_opacity, root->opacity()); |
| 378 uint32_t change_id; | 377 uint32_t change_id; |
| 379 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); | 378 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 392 EXPECT_EQ(server_changed_opacity, root->opacity()); | 391 EXPECT_EQ(server_changed_opacity, root->opacity()); |
| 393 | 392 |
| 394 // Simulate server changing back to original opacity. Should take immediately. | 393 // Simulate server changing back to original opacity. Should take immediately. |
| 395 setup.window_tree_client()->OnWindowOpacityChanged( | 394 setup.window_tree_client()->OnWindowOpacityChanged( |
| 396 server_id(root), server_changed_opacity, original_opacity); | 395 server_id(root), server_changed_opacity, original_opacity); |
| 397 EXPECT_EQ(original_opacity, root->opacity()); | 396 EXPECT_EQ(original_opacity, root->opacity()); |
| 398 } | 397 } |
| 399 | 398 |
| 400 // Tests that when there are multiple changes in flight, that failing changes | 399 // Tests that when there are multiple changes in flight, that failing changes |
| 401 // update the revert state of subsequent changes. | 400 // update the revert state of subsequent changes. |
| 402 TEST_F(WindowTreeClientImplTest, SetOpacityFailedWithMultiplePendingChange) { | 401 TEST_F(WindowTreeClientTest, SetOpacityFailedWithMultiplePendingChange) { |
| 403 WindowTreeSetup setup; | 402 WindowTreeSetup setup; |
| 404 Window* root = setup.GetFirstRoot(); | 403 Window* root = setup.GetFirstRoot(); |
| 405 ASSERT_TRUE(root); | 404 ASSERT_TRUE(root); |
| 406 const float original_opacity = root->opacity(); | 405 const float original_opacity = root->opacity(); |
| 407 const float new_opacity = 0.5f; | 406 const float new_opacity = 0.5f; |
| 408 ASSERT_NE(new_opacity, root->opacity()); | 407 ASSERT_NE(new_opacity, root->opacity()); |
| 409 root->SetOpacity(new_opacity); | 408 root->SetOpacity(new_opacity); |
| 410 uint32_t change_id1; | 409 uint32_t change_id1; |
| 411 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id1)); | 410 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id1)); |
| 412 | 411 |
| 413 const float second_new_opacity = 0.75f; | 412 const float second_new_opacity = 0.75f; |
| 414 ASSERT_NE(second_new_opacity, root->opacity()); | 413 ASSERT_NE(second_new_opacity, root->opacity()); |
| 415 root->SetOpacity(second_new_opacity); | 414 root->SetOpacity(second_new_opacity); |
| 416 uint32_t change_id2; | 415 uint32_t change_id2; |
| 417 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id2)); | 416 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id2)); |
| 418 | 417 |
| 419 // Canceling the first one, while there is another in flight, should not | 418 // Canceling the first one, while there is another in flight, should not |
| 420 // change the local opacity. | 419 // change the local opacity. |
| 421 setup.window_tree_client()->OnChangeCompleted(change_id1, false); | 420 setup.window_tree_client()->OnChangeCompleted(change_id1, false); |
| 422 EXPECT_EQ(second_new_opacity, root->opacity()); | 421 EXPECT_EQ(second_new_opacity, root->opacity()); |
| 423 | 422 |
| 424 // The previous cancelation should have updated the revert value of the in | 423 // The previous cancelation should have updated the revert value of the in |
| 425 // flight change. | 424 // flight change. |
| 426 setup.window_tree_client()->OnChangeCompleted(change_id2, false); | 425 setup.window_tree_client()->OnChangeCompleted(change_id2, false); |
| 427 EXPECT_EQ(original_opacity, root->opacity()); | 426 EXPECT_EQ(original_opacity, root->opacity()); |
| 428 } | 427 } |
| 429 | 428 |
| 430 // Verifies |is_modal| is reverted if the server replied that the change failed. | 429 // Verifies |is_modal| is reverted if the server replied that the change failed. |
| 431 TEST_F(WindowTreeClientImplTest, SetModalFailed) { | 430 TEST_F(WindowTreeClientTest, SetModalFailed) { |
| 432 WindowTreeSetup setup; | 431 WindowTreeSetup setup; |
| 433 Window* root = setup.GetFirstRoot(); | 432 Window* root = setup.GetFirstRoot(); |
| 434 ASSERT_TRUE(root); | 433 ASSERT_TRUE(root); |
| 435 EXPECT_FALSE(root->is_modal()); | 434 EXPECT_FALSE(root->is_modal()); |
| 436 root->SetModal(); | 435 root->SetModal(); |
| 437 uint32_t change_id; | 436 uint32_t change_id; |
| 438 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); | 437 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); |
| 439 EXPECT_TRUE(root->is_modal()); | 438 EXPECT_TRUE(root->is_modal()); |
| 440 setup.window_tree_client()->OnChangeCompleted(change_id, false); | 439 setup.window_tree_client()->OnChangeCompleted(change_id, false); |
| 441 EXPECT_FALSE(root->is_modal()); | 440 EXPECT_FALSE(root->is_modal()); |
| 442 } | 441 } |
| 443 | 442 |
| 444 TEST_F(WindowTreeClientImplTest, InputEventBasic) { | 443 TEST_F(WindowTreeClientTest, InputEventBasic) { |
| 445 WindowTreeSetup setup; | 444 WindowTreeSetup setup; |
| 446 Window* root = setup.GetFirstRoot(); | 445 Window* root = setup.GetFirstRoot(); |
| 447 ASSERT_TRUE(root); | 446 ASSERT_TRUE(root); |
| 448 | 447 |
| 449 TestInputEventHandler event_handler; | 448 TestInputEventHandler event_handler; |
| 450 root->set_input_event_handler(&event_handler); | 449 root->set_input_event_handler(&event_handler); |
| 451 | 450 |
| 452 std::unique_ptr<ui::Event> ui_event( | 451 std::unique_ptr<ui::Event> ui_event( |
| 453 new ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(), | 452 new ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(), |
| 454 ui::EventTimeForNow(), ui::EF_NONE, 0)); | 453 ui::EventTimeForNow(), ui::EF_NONE, 0)); |
| 455 setup.window_tree_client()->OnWindowInputEvent( | 454 setup.window_tree_client()->OnWindowInputEvent( |
| 456 1, server_id(root), mojom::Event::From(*ui_event.get()), 0); | 455 1, server_id(root), mojom::Event::From(*ui_event.get()), 0); |
| 457 EXPECT_TRUE(event_handler.received_event()); | 456 EXPECT_TRUE(event_handler.received_event()); |
| 458 EXPECT_TRUE(setup.window_tree()->WasEventAcked(1)); | 457 EXPECT_TRUE(setup.window_tree()->WasEventAcked(1)); |
| 459 event_handler.Reset(); | 458 event_handler.Reset(); |
| 460 | 459 |
| 461 event_handler.set_should_manually_ack(); | 460 event_handler.set_should_manually_ack(); |
| 462 setup.window_tree_client()->OnWindowInputEvent( | 461 setup.window_tree_client()->OnWindowInputEvent( |
| 463 33, server_id(root), mojom::Event::From(*ui_event.get()), 0); | 462 33, server_id(root), mojom::Event::From(*ui_event.get()), 0); |
| 464 EXPECT_TRUE(event_handler.received_event()); | 463 EXPECT_TRUE(event_handler.received_event()); |
| 465 EXPECT_FALSE(setup.window_tree()->WasEventAcked(33)); | 464 EXPECT_FALSE(setup.window_tree()->WasEventAcked(33)); |
| 466 | 465 |
| 467 event_handler.AckEvent(); | 466 event_handler.AckEvent(); |
| 468 EXPECT_TRUE(setup.window_tree()->WasEventAcked(33)); | 467 EXPECT_TRUE(setup.window_tree()->WasEventAcked(33)); |
| 469 } | 468 } |
| 470 | 469 |
| 471 // Tests event observers triggered by events that did not hit a target in this | 470 // Tests event observers triggered by events that did not hit a target in this |
| 472 // window tree. | 471 // window tree. |
| 473 TEST_F(WindowTreeClientImplTest, OnEventObserved) { | 472 TEST_F(WindowTreeClientTest, OnEventObserved) { |
| 474 WindowTreeSetup setup; | 473 WindowTreeSetup setup; |
| 475 Window* root = setup.GetFirstRoot(); | 474 Window* root = setup.GetFirstRoot(); |
| 476 ASSERT_TRUE(root); | 475 ASSERT_TRUE(root); |
| 477 | 476 |
| 478 // Set up an event observer. | 477 // Set up an event observer. |
| 479 mojom::EventMatcherPtr matcher = mojom::EventMatcher::New(); | 478 mojom::EventMatcherPtr matcher = mojom::EventMatcher::New(); |
| 480 matcher->type_matcher = mojom::EventTypeMatcher::New(); | 479 matcher->type_matcher = mojom::EventTypeMatcher::New(); |
| 481 matcher->type_matcher->type = mojom::EventType::POINTER_DOWN; | 480 matcher->type_matcher->type = mojom::EventType::POINTER_DOWN; |
| 482 setup.window_tree_connection()->SetEventObserver(std::move(matcher)); | 481 setup.client()->SetEventObserver(std::move(matcher)); |
| 483 | 482 |
| 484 // Simulate the server sending an observed event. | 483 // Simulate the server sending an observed event. |
| 485 uint32_t event_observer_id = setup.GetEventObserverId(); | 484 uint32_t event_observer_id = setup.GetEventObserverId(); |
| 486 std::unique_ptr<ui::Event> ui_event( | 485 std::unique_ptr<ui::Event> ui_event( |
| 487 new ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), | 486 new ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), |
| 488 ui::EventTimeForNow(), ui::EF_CONTROL_DOWN, 0)); | 487 ui::EventTimeForNow(), ui::EF_CONTROL_DOWN, 0)); |
| 489 setup.window_tree_client()->OnEventObserved( | 488 setup.window_tree_client()->OnEventObserved( |
| 490 mojom::Event::From(*ui_event.get()), event_observer_id); | 489 mojom::Event::From(*ui_event.get()), event_observer_id); |
| 491 | 490 |
| 492 // Delegate sensed the event. | 491 // Delegate sensed the event. |
| 493 ui::Event* last_event = setup.window_tree_delegate()->last_event_observed(); | 492 ui::Event* last_event = setup.window_tree_delegate()->last_event_observed(); |
| 494 EXPECT_EQ(ui::ET_MOUSE_PRESSED, last_event->type()); | 493 EXPECT_EQ(ui::ET_MOUSE_PRESSED, last_event->type()); |
| 495 EXPECT_EQ(ui::EF_CONTROL_DOWN, last_event->flags()); | 494 EXPECT_EQ(ui::EF_CONTROL_DOWN, last_event->flags()); |
| 496 setup.window_tree_delegate()->Reset(); | 495 setup.window_tree_delegate()->Reset(); |
| 497 | 496 |
| 498 // Clear the event observer. | 497 // Clear the event observer. |
| 499 setup.window_tree_connection()->SetEventObserver(nullptr); | 498 setup.client()->SetEventObserver(nullptr); |
| 500 | 499 |
| 501 // Simulate another event from the server. | 500 // Simulate another event from the server. |
| 502 setup.window_tree_client()->OnEventObserved( | 501 setup.window_tree_client()->OnEventObserved( |
| 503 mojom::Event::From(*ui_event.get()), event_observer_id); | 502 mojom::Event::From(*ui_event.get()), event_observer_id); |
| 504 | 503 |
| 505 // No event was sensed. | 504 // No event was sensed. |
| 506 EXPECT_FALSE(setup.window_tree_delegate()->last_event_observed()); | 505 EXPECT_FALSE(setup.window_tree_delegate()->last_event_observed()); |
| 507 } | 506 } |
| 508 | 507 |
| 509 // Tests event observers triggered by events that hit this window tree. | 508 // Tests event observers triggered by events that hit this window tree. |
| 510 TEST_F(WindowTreeClientImplTest, OnWindowInputEventWithEventObserver) { | 509 TEST_F(WindowTreeClientTest, OnWindowInputEventWithEventObserver) { |
| 511 WindowTreeSetup setup; | 510 WindowTreeSetup setup; |
| 512 Window* root = setup.GetFirstRoot(); | 511 Window* root = setup.GetFirstRoot(); |
| 513 ASSERT_TRUE(root); | 512 ASSERT_TRUE(root); |
| 514 | 513 |
| 515 // Set up an event observer. | 514 // Set up an event observer. |
| 516 mojom::EventMatcherPtr matcher = mojom::EventMatcher::New(); | 515 mojom::EventMatcherPtr matcher = mojom::EventMatcher::New(); |
| 517 matcher->type_matcher = mojom::EventTypeMatcher::New(); | 516 matcher->type_matcher = mojom::EventTypeMatcher::New(); |
| 518 matcher->type_matcher->type = mojom::EventType::POINTER_DOWN; | 517 matcher->type_matcher->type = mojom::EventType::POINTER_DOWN; |
| 519 setup.window_tree_connection()->SetEventObserver(std::move(matcher)); | 518 setup.client()->SetEventObserver(std::move(matcher)); |
| 520 | 519 |
| 521 // Simulate the server dispatching an event that also matched the observer. | 520 // Simulate the server dispatching an event that also matched the observer. |
| 522 uint32_t event_observer_id = setup.GetEventObserverId(); | 521 uint32_t event_observer_id = setup.GetEventObserverId(); |
| 523 std::unique_ptr<ui::Event> ui_event( | 522 std::unique_ptr<ui::Event> ui_event( |
| 524 new ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), | 523 new ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), |
| 525 ui::EventTimeForNow(), ui::EF_CONTROL_DOWN, 0)); | 524 ui::EventTimeForNow(), ui::EF_CONTROL_DOWN, 0)); |
| 526 setup.window_tree_client()->OnWindowInputEvent( | 525 setup.window_tree_client()->OnWindowInputEvent( |
| 527 1, server_id(root), mojom::Event::From(*ui_event.get()), | 526 1, server_id(root), mojom::Event::From(*ui_event.get()), |
| 528 event_observer_id); | 527 event_observer_id); |
| 529 | 528 |
| 530 // Delegate sensed the event. | 529 // Delegate sensed the event. |
| 531 ui::Event* last_event = setup.window_tree_delegate()->last_event_observed(); | 530 ui::Event* last_event = setup.window_tree_delegate()->last_event_observed(); |
| 532 EXPECT_EQ(ui::ET_MOUSE_PRESSED, last_event->type()); | 531 EXPECT_EQ(ui::ET_MOUSE_PRESSED, last_event->type()); |
| 533 EXPECT_EQ(ui::EF_CONTROL_DOWN, last_event->flags()); | 532 EXPECT_EQ(ui::EF_CONTROL_DOWN, last_event->flags()); |
| 534 } | 533 } |
| 535 | 534 |
| 536 // Tests that replacing an event observer with a new one results in only new | 535 // Tests that replacing an event observer with a new one results in only new |
| 537 // events being observed. | 536 // events being observed. |
| 538 TEST_F(WindowTreeClientImplTest, EventObserverReplaced) { | 537 TEST_F(WindowTreeClientTest, EventObserverReplaced) { |
| 539 WindowTreeSetup setup; | 538 WindowTreeSetup setup; |
| 540 Window* root = setup.GetFirstRoot(); | 539 Window* root = setup.GetFirstRoot(); |
| 541 ASSERT_TRUE(root); | 540 ASSERT_TRUE(root); |
| 542 | 541 |
| 543 // Set up an event observer. | 542 // Set up an event observer. |
| 544 mojom::EventMatcherPtr matcher1 = mojom::EventMatcher::New(); | 543 mojom::EventMatcherPtr matcher1 = mojom::EventMatcher::New(); |
| 545 matcher1->type_matcher = mojom::EventTypeMatcher::New(); | 544 matcher1->type_matcher = mojom::EventTypeMatcher::New(); |
| 546 matcher1->type_matcher->type = mojom::EventType::POINTER_DOWN; | 545 matcher1->type_matcher->type = mojom::EventType::POINTER_DOWN; |
| 547 setup.window_tree_connection()->SetEventObserver(std::move(matcher1)); | 546 setup.client()->SetEventObserver(std::move(matcher1)); |
| 548 uint32_t event_observer_id1 = setup.GetEventObserverId(); | 547 uint32_t event_observer_id1 = setup.GetEventObserverId(); |
| 549 | 548 |
| 550 // Replace it with a second observer. | 549 // Replace it with a second observer. |
| 551 mojom::EventMatcherPtr matcher2 = mojom::EventMatcher::New(); | 550 mojom::EventMatcherPtr matcher2 = mojom::EventMatcher::New(); |
| 552 matcher2->type_matcher = mojom::EventTypeMatcher::New(); | 551 matcher2->type_matcher = mojom::EventTypeMatcher::New(); |
| 553 matcher2->type_matcher->type = mojom::EventType::POINTER_UP; | 552 matcher2->type_matcher->type = mojom::EventType::POINTER_UP; |
| 554 setup.window_tree_connection()->SetEventObserver(std::move(matcher2)); | 553 setup.client()->SetEventObserver(std::move(matcher2)); |
| 555 uint32_t event_observer_id2 = setup.GetEventObserverId(); | 554 uint32_t event_observer_id2 = setup.GetEventObserverId(); |
| 556 | 555 |
| 557 // Simulate the server sending an observed event that matched the old observer | 556 // Simulate the server sending an observed event that matched the old observer |
| 558 // (e.g. that was in-flight when the observer was replaced). | 557 // (e.g. that was in-flight when the observer was replaced). |
| 559 std::unique_ptr<ui::Event> pressed_event( | 558 std::unique_ptr<ui::Event> pressed_event( |
| 560 new ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), | 559 new ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), |
| 561 ui::EventTimeForNow(), ui::EF_NONE, 0)); | 560 ui::EventTimeForNow(), ui::EF_NONE, 0)); |
| 562 setup.window_tree_client()->OnEventObserved( | 561 setup.window_tree_client()->OnEventObserved( |
| 563 mojom::Event::From(*pressed_event.get()), event_observer_id1); | 562 mojom::Event::From(*pressed_event.get()), event_observer_id1); |
| 564 | 563 |
| 565 // The event was not sensed, because it does not match the current observer. | 564 // The event was not sensed, because it does not match the current observer. |
| 566 EXPECT_FALSE(setup.window_tree_delegate()->last_event_observed()); | 565 EXPECT_FALSE(setup.window_tree_delegate()->last_event_observed()); |
| 567 | 566 |
| 568 // Simulate another event that matches the new observer. | 567 // Simulate another event that matches the new observer. |
| 569 std::unique_ptr<ui::Event> released_event( | 568 std::unique_ptr<ui::Event> released_event( |
| 570 new ui::MouseEvent(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), | 569 new ui::MouseEvent(ui::ET_MOUSE_RELEASED, gfx::Point(), gfx::Point(), |
| 571 ui::EventTimeForNow(), ui::EF_CONTROL_DOWN, 0)); | 570 ui::EventTimeForNow(), ui::EF_CONTROL_DOWN, 0)); |
| 572 setup.window_tree_client()->OnEventObserved( | 571 setup.window_tree_client()->OnEventObserved( |
| 573 mojom::Event::From(*released_event.get()), event_observer_id2); | 572 mojom::Event::From(*released_event.get()), event_observer_id2); |
| 574 | 573 |
| 575 // The delegate sensed the event. | 574 // The delegate sensed the event. |
| 576 ui::Event* last_event = setup.window_tree_delegate()->last_event_observed(); | 575 ui::Event* last_event = setup.window_tree_delegate()->last_event_observed(); |
| 577 EXPECT_EQ(ui::ET_MOUSE_RELEASED, last_event->type()); | 576 EXPECT_EQ(ui::ET_MOUSE_RELEASED, last_event->type()); |
| 578 EXPECT_EQ(ui::EF_CONTROL_DOWN, last_event->flags()); | 577 EXPECT_EQ(ui::EF_CONTROL_DOWN, last_event->flags()); |
| 579 } | 578 } |
| 580 | 579 |
| 581 // Verifies focus is reverted if the server replied that the change failed. | 580 // Verifies focus is reverted if the server replied that the change failed. |
| 582 TEST_F(WindowTreeClientImplTest, SetFocusFailed) { | 581 TEST_F(WindowTreeClientTest, SetFocusFailed) { |
| 583 WindowTreeSetup setup; | 582 WindowTreeSetup setup; |
| 584 Window* root = setup.GetFirstRoot(); | 583 Window* root = setup.GetFirstRoot(); |
| 585 ASSERT_TRUE(root); | 584 ASSERT_TRUE(root); |
| 586 root->SetVisible(true); | 585 root->SetVisible(true); |
| 587 Window* child = setup.window_tree_connection()->NewWindow(); | 586 Window* child = setup.client()->NewWindow(); |
| 588 child->SetVisible(true); | 587 child->SetVisible(true); |
| 589 root->AddChild(child); | 588 root->AddChild(child); |
| 590 Window* original_focus = setup.window_tree_connection()->GetFocusedWindow(); | 589 Window* original_focus = setup.client()->GetFocusedWindow(); |
| 591 Window* new_focus = child; | 590 Window* new_focus = child; |
| 592 ASSERT_NE(new_focus, original_focus); | 591 ASSERT_NE(new_focus, original_focus); |
| 593 new_focus->SetFocus(); | 592 new_focus->SetFocus(); |
| 594 ASSERT_TRUE(new_focus->HasFocus()); | 593 ASSERT_TRUE(new_focus->HasFocus()); |
| 595 uint32_t change_id; | 594 uint32_t change_id; |
| 596 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); | 595 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); |
| 597 setup.window_tree_client()->OnChangeCompleted(change_id, false); | 596 setup.window_tree_client()->OnChangeCompleted(change_id, false); |
| 598 EXPECT_EQ(original_focus, setup.window_tree_connection()->GetFocusedWindow()); | 597 EXPECT_EQ(original_focus, setup.client()->GetFocusedWindow()); |
| 599 } | 598 } |
| 600 | 599 |
| 601 // Simulates a focus change, and while the focus change is in flight the server | 600 // Simulates a focus change, and while the focus change is in flight the server |
| 602 // replies with a new focus and the original focus change fails. | 601 // replies with a new focus and the original focus change fails. |
| 603 TEST_F(WindowTreeClientImplTest, SetFocusFailedWithPendingChange) { | 602 TEST_F(WindowTreeClientTest, SetFocusFailedWithPendingChange) { |
| 604 WindowTreeSetup setup; | 603 WindowTreeSetup setup; |
| 605 Window* root = setup.GetFirstRoot(); | 604 Window* root = setup.GetFirstRoot(); |
| 606 ASSERT_TRUE(root); | 605 ASSERT_TRUE(root); |
| 607 root->SetVisible(true); | 606 root->SetVisible(true); |
| 608 Window* child1 = setup.window_tree_connection()->NewWindow(); | 607 Window* child1 = setup.client()->NewWindow(); |
| 609 child1->SetVisible(true); | 608 child1->SetVisible(true); |
| 610 root->AddChild(child1); | 609 root->AddChild(child1); |
| 611 Window* child2 = setup.window_tree_connection()->NewWindow(); | 610 Window* child2 = setup.client()->NewWindow(); |
| 612 child2->SetVisible(true); | 611 child2->SetVisible(true); |
| 613 root->AddChild(child2); | 612 root->AddChild(child2); |
| 614 Window* original_focus = setup.window_tree_connection()->GetFocusedWindow(); | 613 Window* original_focus = setup.client()->GetFocusedWindow(); |
| 615 Window* new_focus = child1; | 614 Window* new_focus = child1; |
| 616 ASSERT_NE(new_focus, original_focus); | 615 ASSERT_NE(new_focus, original_focus); |
| 617 new_focus->SetFocus(); | 616 new_focus->SetFocus(); |
| 618 ASSERT_TRUE(new_focus->HasFocus()); | 617 ASSERT_TRUE(new_focus->HasFocus()); |
| 619 uint32_t change_id; | 618 uint32_t change_id; |
| 620 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); | 619 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); |
| 621 | 620 |
| 622 // Simulate the server responding with a focus change. | 621 // Simulate the server responding with a focus change. |
| 623 setup.window_tree_client()->OnWindowFocused(server_id(child2)); | 622 setup.window_tree_client()->OnWindowFocused(server_id(child2)); |
| 624 | 623 |
| 625 // This shouldn't trigger focus changing yet. | 624 // This shouldn't trigger focus changing yet. |
| 626 EXPECT_TRUE(child1->HasFocus()); | 625 EXPECT_TRUE(child1->HasFocus()); |
| 627 | 626 |
| 628 // Tell the client the change failed, which should trigger failing to the | 627 // Tell the client the change failed, which should trigger failing to the |
| 629 // most recent focus from server. | 628 // most recent focus from server. |
| 630 setup.window_tree_client()->OnChangeCompleted(change_id, false); | 629 setup.window_tree_client()->OnChangeCompleted(change_id, false); |
| 631 EXPECT_FALSE(child1->HasFocus()); | 630 EXPECT_FALSE(child1->HasFocus()); |
| 632 EXPECT_TRUE(child2->HasFocus()); | 631 EXPECT_TRUE(child2->HasFocus()); |
| 633 EXPECT_EQ(child2, setup.window_tree_connection()->GetFocusedWindow()); | 632 EXPECT_EQ(child2, setup.client()->GetFocusedWindow()); |
| 634 | 633 |
| 635 // Simulate server changing focus to child1. Should take immediately. | 634 // Simulate server changing focus to child1. Should take immediately. |
| 636 setup.window_tree_client()->OnWindowFocused(server_id(child1)); | 635 setup.window_tree_client()->OnWindowFocused(server_id(child1)); |
| 637 EXPECT_TRUE(child1->HasFocus()); | 636 EXPECT_TRUE(child1->HasFocus()); |
| 638 } | 637 } |
| 639 | 638 |
| 640 TEST_F(WindowTreeClientImplTest, FocusOnRemovedWindowWithInFlightFocusChange) { | 639 TEST_F(WindowTreeClientTest, FocusOnRemovedWindowWithInFlightFocusChange) { |
| 641 WindowTreeSetup setup; | 640 WindowTreeSetup setup; |
| 642 Window* root = setup.GetFirstRoot(); | 641 Window* root = setup.GetFirstRoot(); |
| 643 ASSERT_TRUE(root); | 642 ASSERT_TRUE(root); |
| 644 root->SetVisible(true); | 643 root->SetVisible(true); |
| 645 Window* child1 = setup.window_tree_connection()->NewWindow(); | 644 Window* child1 = setup.client()->NewWindow(); |
| 646 child1->SetVisible(true); | 645 child1->SetVisible(true); |
| 647 root->AddChild(child1); | 646 root->AddChild(child1); |
| 648 Window* child2 = setup.window_tree_connection()->NewWindow(); | 647 Window* child2 = setup.client()->NewWindow(); |
| 649 child2->SetVisible(true); | 648 child2->SetVisible(true); |
| 650 root->AddChild(child2); | 649 root->AddChild(child2); |
| 651 | 650 |
| 652 child1->SetFocus(); | 651 child1->SetFocus(); |
| 653 uint32_t change_id; | 652 uint32_t change_id; |
| 654 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); | 653 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); |
| 655 | 654 |
| 656 // Destroy child1, which should set focus to null. | 655 // Destroy child1, which should set focus to null. |
| 657 child1->Destroy(); | 656 child1->Destroy(); |
| 658 EXPECT_EQ(nullptr, setup.window_tree_connection()->GetFocusedWindow()); | 657 EXPECT_EQ(nullptr, setup.client()->GetFocusedWindow()); |
| 659 | 658 |
| 660 // Server changes focus to 2. | 659 // Server changes focus to 2. |
| 661 setup.window_tree_client()->OnWindowFocused(server_id(child2)); | 660 setup.window_tree_client()->OnWindowFocused(server_id(child2)); |
| 662 // Shouldn't take immediately. | 661 // Shouldn't take immediately. |
| 663 EXPECT_FALSE(child2->HasFocus()); | 662 EXPECT_FALSE(child2->HasFocus()); |
| 664 | 663 |
| 665 // Ack the change, focus should still be null. | 664 // Ack the change, focus should still be null. |
| 666 setup.window_tree_client()->OnChangeCompleted(change_id, true); | 665 setup.window_tree_client()->OnChangeCompleted(change_id, true); |
| 667 EXPECT_EQ(nullptr, setup.window_tree_connection()->GetFocusedWindow()); | 666 EXPECT_EQ(nullptr, setup.client()->GetFocusedWindow()); |
| 668 | 667 |
| 669 // Change to 2 again, this time it should take. | 668 // Change to 2 again, this time it should take. |
| 670 setup.window_tree_client()->OnWindowFocused(server_id(child2)); | 669 setup.window_tree_client()->OnWindowFocused(server_id(child2)); |
| 671 EXPECT_TRUE(child2->HasFocus()); | 670 EXPECT_TRUE(child2->HasFocus()); |
| 672 } | 671 } |
| 673 | 672 |
| 674 class ToggleVisibilityFromDestroyedObserver : public WindowObserver { | 673 class ToggleVisibilityFromDestroyedObserver : public WindowObserver { |
| 675 public: | 674 public: |
| 676 explicit ToggleVisibilityFromDestroyedObserver(Window* window) | 675 explicit ToggleVisibilityFromDestroyedObserver(Window* window) |
| 677 : window_(window) { | 676 : window_(window) { |
| 678 window_->AddObserver(this); | 677 window_->AddObserver(this); |
| 679 } | 678 } |
| 680 | 679 |
| 681 ToggleVisibilityFromDestroyedObserver() { EXPECT_FALSE(window_); } | 680 ToggleVisibilityFromDestroyedObserver() { EXPECT_FALSE(window_); } |
| 682 | 681 |
| 683 // WindowObserver: | 682 // WindowObserver: |
| 684 void OnWindowDestroyed(Window* window) override { | 683 void OnWindowDestroyed(Window* window) override { |
| 685 window_->SetVisible(!window->visible()); | 684 window_->SetVisible(!window->visible()); |
| 686 window_->RemoveObserver(this); | 685 window_->RemoveObserver(this); |
| 687 window_ = nullptr; | 686 window_ = nullptr; |
| 688 } | 687 } |
| 689 | 688 |
| 690 private: | 689 private: |
| 691 Window* window_; | 690 Window* window_; |
| 692 | 691 |
| 693 DISALLOW_COPY_AND_ASSIGN(ToggleVisibilityFromDestroyedObserver); | 692 DISALLOW_COPY_AND_ASSIGN(ToggleVisibilityFromDestroyedObserver); |
| 694 }; | 693 }; |
| 695 | 694 |
| 696 TEST_F(WindowTreeClientImplTest, ToggleVisibilityFromWindowDestroyed) { | 695 TEST_F(WindowTreeClientTest, ToggleVisibilityFromWindowDestroyed) { |
| 697 WindowTreeSetup setup; | 696 WindowTreeSetup setup; |
| 698 Window* root = setup.GetFirstRoot(); | 697 Window* root = setup.GetFirstRoot(); |
| 699 ASSERT_TRUE(root); | 698 ASSERT_TRUE(root); |
| 700 Window* child1 = setup.window_tree_connection()->NewWindow(); | 699 Window* child1 = setup.client()->NewWindow(); |
| 701 root->AddChild(child1); | 700 root->AddChild(child1); |
| 702 ToggleVisibilityFromDestroyedObserver toggler(child1); | 701 ToggleVisibilityFromDestroyedObserver toggler(child1); |
| 703 // Destroying the window triggers | 702 // Destroying the window triggers |
| 704 // ToggleVisibilityFromDestroyedObserver::OnWindowDestroyed(), which toggles | 703 // ToggleVisibilityFromDestroyedObserver::OnWindowDestroyed(), which toggles |
| 705 // the visibility of the window. Ack the change, which should not crash or | 704 // the visibility of the window. Ack the change, which should not crash or |
| 706 // trigger DCHECKs. | 705 // trigger DCHECKs. |
| 707 child1->Destroy(); | 706 child1->Destroy(); |
| 708 uint32_t change_id; | 707 uint32_t change_id; |
| 709 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); | 708 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); |
| 710 setup.window_tree_client()->OnChangeCompleted(change_id, true); | 709 setup.window_tree_client()->OnChangeCompleted(change_id, true); |
| 711 } | 710 } |
| 712 | 711 |
| 713 TEST_F(WindowTreeClientImplTest, NewTopLevelWindow) { | 712 TEST_F(WindowTreeClientTest, NewTopLevelWindow) { |
| 714 WindowTreeSetup setup; | 713 WindowTreeSetup setup; |
| 715 Window* root1 = setup.GetFirstRoot(); | 714 Window* root1 = setup.GetFirstRoot(); |
| 716 ASSERT_TRUE(root1); | 715 ASSERT_TRUE(root1); |
| 717 Window* root2 = setup.window_tree_connection()->NewTopLevelWindow(nullptr); | 716 Window* root2 = setup.client()->NewTopLevelWindow(nullptr); |
| 718 ASSERT_TRUE(root2); | 717 ASSERT_TRUE(root2); |
| 719 EXPECT_TRUE(WindowPrivate(root2).parent_drawn()); | 718 EXPECT_TRUE(WindowPrivate(root2).parent_drawn()); |
| 720 ASSERT_NE(root2, root1); | 719 ASSERT_NE(root2, root1); |
| 721 EXPECT_NE(server_id(root2), server_id(root1)); | 720 EXPECT_NE(server_id(root2), server_id(root1)); |
| 722 EXPECT_EQ(2u, setup.window_tree_connection()->GetRoots().size()); | 721 EXPECT_EQ(2u, setup.client()->GetRoots().size()); |
| 723 EXPECT_TRUE(setup.window_tree_connection()->GetRoots().count(root1) > 0u); | 722 EXPECT_TRUE(setup.client()->GetRoots().count(root1) > 0u); |
| 724 EXPECT_TRUE(setup.window_tree_connection()->GetRoots().count(root2) > 0u); | 723 EXPECT_TRUE(setup.client()->GetRoots().count(root2) > 0u); |
| 725 | 724 |
| 726 // Ack the request to the windowtree to create the new window. | 725 // Ack the request to the windowtree to create the new window. |
| 727 uint32_t change_id; | 726 uint32_t change_id; |
| 728 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); | 727 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); |
| 729 EXPECT_EQ(setup.window_tree()->window_id(), server_id(root2)); | 728 EXPECT_EQ(setup.window_tree()->window_id(), server_id(root2)); |
| 730 | 729 |
| 731 mojom::WindowDataPtr data = mojom::WindowData::New(); | 730 mojom::WindowDataPtr data = mojom::WindowData::New(); |
| 732 data->window_id = server_id(root2); | 731 data->window_id = server_id(root2); |
| 733 const int64_t display_id = 1; | 732 const int64_t display_id = 1; |
| 734 setup.window_tree_client()->OnTopLevelCreated(change_id, std::move(data), | 733 setup.window_tree_client()->OnTopLevelCreated(change_id, std::move(data), |
| 735 display_id, false); | 734 display_id, false); |
| 736 | 735 |
| 737 EXPECT_FALSE(WindowPrivate(root2).parent_drawn()); | 736 EXPECT_FALSE(WindowPrivate(root2).parent_drawn()); |
| 738 | 737 |
| 739 // Should not be able to add a top level as a child of another window. | 738 // Should not be able to add a top level as a child of another window. |
| 740 root1->AddChild(root2); | 739 root1->AddChild(root2); |
| 741 ASSERT_EQ(nullptr, root2->parent()); | 740 ASSERT_EQ(nullptr, root2->parent()); |
| 742 | 741 |
| 743 // Destroy the first root, shouldn't initiate tear down. | 742 // Destroy the first root, shouldn't initiate tear down. |
| 744 root1->Destroy(); | 743 root1->Destroy(); |
| 745 root1 = nullptr; | 744 root1 = nullptr; |
| 746 EXPECT_EQ(1u, setup.window_tree_connection()->GetRoots().size()); | 745 EXPECT_EQ(1u, setup.client()->GetRoots().size()); |
| 747 EXPECT_TRUE(setup.window_tree_connection()->GetRoots().count(root2) > 0u); | 746 EXPECT_TRUE(setup.client()->GetRoots().count(root2) > 0u); |
| 748 } | 747 } |
| 749 | 748 |
| 750 TEST_F(WindowTreeClientImplTest, NewTopLevelWindowGetsPropertiesFromData) { | 749 TEST_F(WindowTreeClientTest, NewTopLevelWindowGetsPropertiesFromData) { |
| 751 WindowTreeSetup setup; | 750 WindowTreeSetup setup; |
| 752 Window* root1 = setup.GetFirstRoot(); | 751 Window* root1 = setup.GetFirstRoot(); |
| 753 ASSERT_TRUE(root1); | 752 ASSERT_TRUE(root1); |
| 754 Window* root2 = setup.window_tree_connection()->NewTopLevelWindow(nullptr); | 753 Window* root2 = setup.client()->NewTopLevelWindow(nullptr); |
| 755 ASSERT_TRUE(root2); | 754 ASSERT_TRUE(root2); |
| 756 | 755 |
| 757 EXPECT_FALSE(root2->IsDrawn()); | 756 EXPECT_FALSE(root2->IsDrawn()); |
| 758 EXPECT_FALSE(root2->visible()); | 757 EXPECT_FALSE(root2->visible()); |
| 759 | 758 |
| 760 // Ack the request to the windowtree to create the new window. | 759 // Ack the request to the windowtree to create the new window. |
| 761 uint32_t change_id; | 760 uint32_t change_id; |
| 762 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); | 761 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); |
| 763 EXPECT_EQ(setup.window_tree()->window_id(), server_id(root2)); | 762 EXPECT_EQ(setup.window_tree()->window_id(), server_id(root2)); |
| 764 | 763 |
| 765 mojom::WindowDataPtr data = mojom::WindowData::New(); | 764 mojom::WindowDataPtr data = mojom::WindowData::New(); |
| 766 data->window_id = server_id(root2); | 765 data->window_id = server_id(root2); |
| 767 data->bounds.SetRect(1, 2, 3, 4); | 766 data->bounds.SetRect(1, 2, 3, 4); |
| 768 data->visible = true; | 767 data->visible = true; |
| 769 const int64_t display_id = 1; | 768 const int64_t display_id = 1; |
| 770 setup.window_tree_client()->OnTopLevelCreated(change_id, std::move(data), | 769 setup.window_tree_client()->OnTopLevelCreated(change_id, std::move(data), |
| 771 display_id, true); | 770 display_id, true); |
| 772 | 771 |
| 773 // Make sure all the properties took. | 772 // Make sure all the properties took. |
| 774 EXPECT_TRUE(root2->IsDrawn()); | 773 EXPECT_TRUE(root2->IsDrawn()); |
| 775 EXPECT_TRUE(root2->visible()); | 774 EXPECT_TRUE(root2->visible()); |
| 776 EXPECT_EQ(1, root2->display_id()); | 775 EXPECT_EQ(1, root2->display_id()); |
| 777 EXPECT_EQ(gfx::Rect(1, 2, 3, 4), root2->bounds()); | 776 EXPECT_EQ(gfx::Rect(1, 2, 3, 4), root2->bounds()); |
| 778 } | 777 } |
| 779 | 778 |
| 780 TEST_F(WindowTreeClientImplTest, NewTopLevelWindowGetsAllChangesInFlight) { | 779 TEST_F(WindowTreeClientTest, NewTopLevelWindowGetsAllChangesInFlight) { |
| 781 WindowTreeSetup setup; | 780 WindowTreeSetup setup; |
| 782 Window* root1 = setup.GetFirstRoot(); | 781 Window* root1 = setup.GetFirstRoot(); |
| 783 ASSERT_TRUE(root1); | 782 ASSERT_TRUE(root1); |
| 784 Window* root2 = setup.window_tree_connection()->NewTopLevelWindow(nullptr); | 783 Window* root2 = setup.client()->NewTopLevelWindow(nullptr); |
| 785 ASSERT_TRUE(root2); | 784 ASSERT_TRUE(root2); |
| 786 | 785 |
| 787 EXPECT_FALSE(root2->IsDrawn()); | 786 EXPECT_FALSE(root2->IsDrawn()); |
| 788 EXPECT_FALSE(root2->visible()); | 787 EXPECT_FALSE(root2->visible()); |
| 789 | 788 |
| 790 // Get the id of the in flight change for creating the new window. | 789 // Get the id of the in flight change for creating the new window. |
| 791 uint32_t new_window_in_flight_change_id; | 790 uint32_t new_window_in_flight_change_id; |
| 792 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId( | 791 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId( |
| 793 &new_window_in_flight_change_id)); | 792 &new_window_in_flight_change_id)); |
| 794 EXPECT_EQ(setup.window_tree()->window_id(), server_id(root2)); | 793 EXPECT_EQ(setup.window_tree()->window_id(), server_id(root2)); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 856 false); | 855 false); |
| 857 EXPECT_EQ(2u, root2->shared_properties().size()); | 856 EXPECT_EQ(2u, root2->shared_properties().size()); |
| 858 ASSERT_TRUE(root2->HasSharedProperty("yy")); | 857 ASSERT_TRUE(root2->HasSharedProperty("yy")); |
| 859 EXPECT_EQ("server_yy", root2->GetSharedProperty<std::string>("yy")); | 858 EXPECT_EQ("server_yy", root2->GetSharedProperty<std::string>("yy")); |
| 860 ASSERT_TRUE(root2->HasSharedProperty("xx")); | 859 ASSERT_TRUE(root2->HasSharedProperty("xx")); |
| 861 EXPECT_EQ("server_xx", root2->GetSharedProperty<std::string>("xx")); | 860 EXPECT_EQ("server_xx", root2->GetSharedProperty<std::string>("xx")); |
| 862 } | 861 } |
| 863 | 862 |
| 864 // Tests that if the client has multiple unowned windows, and one of them is a | 863 // Tests that if the client has multiple unowned windows, and one of them is a |
| 865 // transient child to another, the teardown can happen cleanly. | 864 // transient child to another, the teardown can happen cleanly. |
| 866 TEST_F(WindowTreeClientImplTest, MultipleUnOwnedWindowsDuringDestruction) { | 865 TEST_F(WindowTreeClientTest, MultipleUnOwnedWindowsDuringDestruction) { |
| 867 std::unique_ptr<WindowTreeSetup> setup(new WindowTreeSetup()); | 866 std::unique_ptr<WindowTreeSetup> setup(new WindowTreeSetup()); |
| 868 Window* root1 = setup->GetFirstRoot(); | 867 Window* root1 = setup->GetFirstRoot(); |
| 869 ASSERT_TRUE(root1); | 868 ASSERT_TRUE(root1); |
| 870 Window* root2 = setup->window_tree_connection()->NewTopLevelWindow(nullptr); | 869 Window* root2 = setup->client()->NewTopLevelWindow(nullptr); |
| 871 ASSERT_TRUE(root2); | 870 ASSERT_TRUE(root2); |
| 872 root1->AddTransientWindow(root2); | 871 root1->AddTransientWindow(root2); |
| 873 | 872 |
| 874 WindowTracker tracker; | 873 WindowTracker tracker; |
| 875 tracker.Add(root1); | 874 tracker.Add(root1); |
| 876 tracker.Add(root2); | 875 tracker.Add(root2); |
| 877 setup.reset(); | 876 setup.reset(); |
| 878 EXPECT_TRUE(tracker.windows().empty()); | 877 EXPECT_TRUE(tracker.windows().empty()); |
| 879 } | 878 } |
| 880 | 879 |
| 881 TEST_F(WindowTreeClientImplTest, TopLevelWindowDestroyedBeforeCreateComplete) { | 880 TEST_F(WindowTreeClientTest, TopLevelWindowDestroyedBeforeCreateComplete) { |
| 882 WindowTreeSetup setup; | 881 WindowTreeSetup setup; |
| 883 Window* root1 = setup.GetFirstRoot(); | 882 Window* root1 = setup.GetFirstRoot(); |
| 884 ASSERT_TRUE(root1); | 883 ASSERT_TRUE(root1); |
| 885 Window* root2 = setup.window_tree_connection()->NewTopLevelWindow(nullptr); | 884 Window* root2 = setup.client()->NewTopLevelWindow(nullptr); |
| 886 ASSERT_TRUE(root2); | 885 ASSERT_TRUE(root2); |
| 887 ASSERT_EQ(2u, setup.window_tree_connection()->GetRoots().size()); | 886 ASSERT_EQ(2u, setup.client()->GetRoots().size()); |
| 888 | 887 |
| 889 // Get the id of the in flight change for creating the new window. | 888 // Get the id of the in flight change for creating the new window. |
| 890 uint32_t change_id; | 889 uint32_t change_id; |
| 891 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); | 890 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); |
| 892 EXPECT_EQ(setup.window_tree()->window_id(), server_id(root2)); | 891 EXPECT_EQ(setup.window_tree()->window_id(), server_id(root2)); |
| 893 | 892 |
| 894 mojom::WindowDataPtr data = mojom::WindowData::New(); | 893 mojom::WindowDataPtr data = mojom::WindowData::New(); |
| 895 data->window_id = server_id(root2); | 894 data->window_id = server_id(root2); |
| 896 | 895 |
| 897 // Destroy the window before the server has a chance to ack the window | 896 // Destroy the window before the server has a chance to ack the window |
| 898 // creation. | 897 // creation. |
| 899 root2->Destroy(); | 898 root2->Destroy(); |
| 900 EXPECT_EQ(1u, setup.window_tree_connection()->GetRoots().size()); | 899 EXPECT_EQ(1u, setup.client()->GetRoots().size()); |
| 901 | 900 |
| 902 const int64_t display_id = 1; | 901 const int64_t display_id = 1; |
| 903 setup.window_tree_client()->OnTopLevelCreated(change_id, std::move(data), | 902 setup.window_tree_client()->OnTopLevelCreated(change_id, std::move(data), |
| 904 display_id, true); | 903 display_id, true); |
| 905 EXPECT_EQ(1u, setup.window_tree_connection()->GetRoots().size()); | 904 EXPECT_EQ(1u, setup.client()->GetRoots().size()); |
| 906 } | 905 } |
| 907 | 906 |
| 908 // Tests both SetCapture and ReleaseCapture, to ensure that Window is properly | 907 // Tests both SetCapture and ReleaseCapture, to ensure that Window is properly |
| 909 // updated on failures. | 908 // updated on failures. |
| 910 TEST_F(WindowTreeClientImplTest, ExplicitCapture) { | 909 TEST_F(WindowTreeClientTest, ExplicitCapture) { |
| 911 WindowTreeSetup setup; | 910 WindowTreeSetup setup; |
| 912 Window* root = setup.GetFirstRoot(); | 911 Window* root = setup.GetFirstRoot(); |
| 913 ASSERT_TRUE(root); | 912 ASSERT_TRUE(root); |
| 914 | 913 |
| 915 root->SetCapture(); | 914 root->SetCapture(); |
| 916 EXPECT_TRUE(root->HasCapture()); | 915 EXPECT_TRUE(root->HasCapture()); |
| 917 uint32_t change_id1; | 916 uint32_t change_id1; |
| 918 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id1)); | 917 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id1)); |
| 919 setup.window_tree_client()->OnChangeCompleted(change_id1, false); | 918 setup.window_tree_client()->OnChangeCompleted(change_id1, false); |
| 920 EXPECT_FALSE(root->HasCapture()); | 919 EXPECT_FALSE(root->HasCapture()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 934 EXPECT_TRUE(root->HasCapture()); | 933 EXPECT_TRUE(root->HasCapture()); |
| 935 | 934 |
| 936 root->ReleaseCapture(); | 935 root->ReleaseCapture(); |
| 937 uint32_t change_id4; | 936 uint32_t change_id4; |
| 938 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id4)); | 937 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id4)); |
| 939 setup.window_tree_client()->OnChangeCompleted(change_id4, true); | 938 setup.window_tree_client()->OnChangeCompleted(change_id4, true); |
| 940 EXPECT_FALSE(root->HasCapture()); | 939 EXPECT_FALSE(root->HasCapture()); |
| 941 } | 940 } |
| 942 | 941 |
| 943 // Tests that when capture is lost, that the window tree updates properly. | 942 // Tests that when capture is lost, that the window tree updates properly. |
| 944 TEST_F(WindowTreeClientImplTest, LostCapture) { | 943 TEST_F(WindowTreeClientTest, LostCapture) { |
| 945 WindowTreeSetup setup; | 944 WindowTreeSetup setup; |
| 946 Window* root = setup.GetFirstRoot(); | 945 Window* root = setup.GetFirstRoot(); |
| 947 ASSERT_TRUE(root); | 946 ASSERT_TRUE(root); |
| 948 | 947 |
| 949 root->SetCapture(); | 948 root->SetCapture(); |
| 950 EXPECT_TRUE(root->HasCapture()); | 949 EXPECT_TRUE(root->HasCapture()); |
| 951 uint32_t change_id1; | 950 uint32_t change_id1; |
| 952 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id1)); | 951 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id1)); |
| 953 setup.window_tree_client()->OnChangeCompleted(change_id1, true); | 952 setup.window_tree_client()->OnChangeCompleted(change_id1, true); |
| 954 EXPECT_TRUE(root->HasCapture()); | 953 EXPECT_TRUE(root->HasCapture()); |
| 955 | 954 |
| 956 // The second SetCapture should be ignored. | 955 // The second SetCapture should be ignored. |
| 957 root->SetCapture(); | 956 root->SetCapture(); |
| 958 uint32_t change_id2; | 957 uint32_t change_id2; |
| 959 ASSERT_FALSE(setup.window_tree()->GetAndClearChangeId(&change_id2)); | 958 ASSERT_FALSE(setup.window_tree()->GetAndClearChangeId(&change_id2)); |
| 960 | 959 |
| 961 setup.window_tree_client()->OnLostCapture(server_id(root)); | 960 setup.window_tree_client()->OnLostCapture(server_id(root)); |
| 962 EXPECT_FALSE(root->HasCapture()); | 961 EXPECT_FALSE(root->HasCapture()); |
| 963 } | 962 } |
| 964 | 963 |
| 965 // Tests that when capture is lost, while there is a release capture request | 964 // Tests that when capture is lost, while there is a release capture request |
| 966 // inflight, that the revert value of that request is updated correctly. | 965 // inflight, that the revert value of that request is updated correctly. |
| 967 TEST_F(WindowTreeClientImplTest, LostCaptureDifferentInFlightChange) { | 966 TEST_F(WindowTreeClientTest, LostCaptureDifferentInFlightChange) { |
| 968 WindowTreeSetup setup; | 967 WindowTreeSetup setup; |
| 969 Window* root = setup.GetFirstRoot(); | 968 Window* root = setup.GetFirstRoot(); |
| 970 ASSERT_TRUE(root); | 969 ASSERT_TRUE(root); |
| 971 | 970 |
| 972 root->SetCapture(); | 971 root->SetCapture(); |
| 973 EXPECT_TRUE(root->HasCapture()); | 972 EXPECT_TRUE(root->HasCapture()); |
| 974 uint32_t change_id1; | 973 uint32_t change_id1; |
| 975 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id1)); | 974 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id1)); |
| 976 setup.window_tree_client()->OnChangeCompleted(change_id1, true); | 975 setup.window_tree_client()->OnChangeCompleted(change_id1, true); |
| 977 EXPECT_TRUE(root->HasCapture()); | 976 EXPECT_TRUE(root->HasCapture()); |
| 978 | 977 |
| 979 // The ReleaseCapture should be updated to the revert of the SetCapture. | 978 // The ReleaseCapture should be updated to the revert of the SetCapture. |
| 980 root->ReleaseCapture(); | 979 root->ReleaseCapture(); |
| 981 uint32_t change_id2; | 980 uint32_t change_id2; |
| 982 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id2)); | 981 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id2)); |
| 983 | 982 |
| 984 setup.window_tree_client()->OnLostCapture(server_id(root)); | 983 setup.window_tree_client()->OnLostCapture(server_id(root)); |
| 985 EXPECT_FALSE(root->HasCapture()); | 984 EXPECT_FALSE(root->HasCapture()); |
| 986 | 985 |
| 987 setup.window_tree_client()->OnChangeCompleted(change_id2, false); | 986 setup.window_tree_client()->OnChangeCompleted(change_id2, false); |
| 988 EXPECT_FALSE(root->HasCapture()); | 987 EXPECT_FALSE(root->HasCapture()); |
| 989 } | 988 } |
| 990 | 989 |
| 991 // Tests that while two windows can inflight capture requests, that the | 990 // Tests that while two windows can inflight capture requests, that the |
| 992 // WindowTreeClient only identifies one as having the current capture. | 991 // WindowTreeClient only identifies one as having the current capture. |
| 993 TEST_F(WindowTreeClientImplTest, TwoWindowsRequestCapture) { | 992 TEST_F(WindowTreeClientTest, TwoWindowsRequestCapture) { |
| 994 WindowTreeSetup setup; | 993 WindowTreeSetup setup; |
| 995 Window* root = setup.GetFirstRoot(); | 994 Window* root = setup.GetFirstRoot(); |
| 996 Window* child = setup.window_tree_connection()->NewWindow(); | 995 Window* child = setup.client()->NewWindow(); |
| 997 child->SetVisible(true); | 996 child->SetVisible(true); |
| 998 root->AddChild(child); | 997 root->AddChild(child); |
| 999 | 998 |
| 1000 root->SetCapture(); | 999 root->SetCapture(); |
| 1001 EXPECT_TRUE(root->HasCapture()); | 1000 EXPECT_TRUE(root->HasCapture()); |
| 1002 uint32_t change_id1; | 1001 uint32_t change_id1; |
| 1003 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id1)); | 1002 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id1)); |
| 1004 | 1003 |
| 1005 child->SetCapture(); | 1004 child->SetCapture(); |
| 1006 EXPECT_TRUE(child->HasCapture()); | 1005 EXPECT_TRUE(child->HasCapture()); |
| 1007 EXPECT_FALSE(root->HasCapture()); | 1006 EXPECT_FALSE(root->HasCapture()); |
| 1008 | 1007 |
| 1009 uint32_t change_id2; | 1008 uint32_t change_id2; |
| 1010 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id2)); | 1009 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id2)); |
| 1011 | 1010 |
| 1012 setup.window_tree_client()->OnChangeCompleted(change_id1, true); | 1011 setup.window_tree_client()->OnChangeCompleted(change_id1, true); |
| 1013 EXPECT_FALSE(root->HasCapture()); | 1012 EXPECT_FALSE(root->HasCapture()); |
| 1014 EXPECT_TRUE(child->HasCapture()); | 1013 EXPECT_TRUE(child->HasCapture()); |
| 1015 | 1014 |
| 1016 setup.window_tree_client()->OnChangeCompleted(change_id2, false); | 1015 setup.window_tree_client()->OnChangeCompleted(change_id2, false); |
| 1017 EXPECT_FALSE(child->HasCapture()); | 1016 EXPECT_FALSE(child->HasCapture()); |
| 1018 EXPECT_TRUE(root->HasCapture()); | 1017 EXPECT_TRUE(root->HasCapture()); |
| 1019 | 1018 |
| 1020 setup.window_tree_client()->OnLostCapture(server_id(root)); | 1019 setup.window_tree_client()->OnLostCapture(server_id(root)); |
| 1021 EXPECT_FALSE(root->HasCapture()); | 1020 EXPECT_FALSE(root->HasCapture()); |
| 1022 } | 1021 } |
| 1023 | 1022 |
| 1024 TEST_F(WindowTreeClientImplTest, WindowDestroyedWhileTransientChildHasCapture) { | 1023 TEST_F(WindowTreeClientTest, WindowDestroyedWhileTransientChildHasCapture) { |
| 1025 WindowTreeSetup setup; | 1024 WindowTreeSetup setup; |
| 1026 Window* root = setup.GetFirstRoot(); | 1025 Window* root = setup.GetFirstRoot(); |
| 1027 Window* transient_parent = setup.window_tree_connection()->NewWindow(); | 1026 Window* transient_parent = setup.client()->NewWindow(); |
| 1028 Window* transient_child = setup.window_tree_connection()->NewWindow(); | 1027 Window* transient_child = setup.client()->NewWindow(); |
| 1029 transient_parent->SetVisible(true); | 1028 transient_parent->SetVisible(true); |
| 1030 transient_child->SetVisible(true); | 1029 transient_child->SetVisible(true); |
| 1031 root->AddChild(transient_parent); | 1030 root->AddChild(transient_parent); |
| 1032 root->AddChild(transient_child); | 1031 root->AddChild(transient_child); |
| 1033 | 1032 |
| 1034 transient_parent->AddTransientWindow(transient_child); | 1033 transient_parent->AddTransientWindow(transient_child); |
| 1035 | 1034 |
| 1036 WindowTracker tracker; | 1035 WindowTracker tracker; |
| 1037 tracker.Add(transient_parent); | 1036 tracker.Add(transient_parent); |
| 1038 tracker.Add(transient_child); | 1037 tracker.Add(transient_child); |
| 1039 // Request a capture on the transient child, then destroy the transient | 1038 // Request a capture on the transient child, then destroy the transient |
| 1040 // parent. That will destroy both windows, and should reset the capture window | 1039 // parent. That will destroy both windows, and should reset the capture window |
| 1041 // correctly. | 1040 // correctly. |
| 1042 transient_child->SetCapture(); | 1041 transient_child->SetCapture(); |
| 1043 transient_parent->Destroy(); | 1042 transient_parent->Destroy(); |
| 1044 EXPECT_TRUE(tracker.windows().empty()); | 1043 EXPECT_TRUE(tracker.windows().empty()); |
| 1045 | 1044 |
| 1046 // Create a new Window, and attempt to place capture on that. | 1045 // Create a new Window, and attempt to place capture on that. |
| 1047 Window* child = setup.window_tree_connection()->NewWindow(); | 1046 Window* child = setup.client()->NewWindow(); |
| 1048 child->SetVisible(true); | 1047 child->SetVisible(true); |
| 1049 root->AddChild(child); | 1048 root->AddChild(child); |
| 1050 child->SetCapture(); | 1049 child->SetCapture(); |
| 1051 EXPECT_TRUE(child->HasCapture()); | 1050 EXPECT_TRUE(child->HasCapture()); |
| 1052 } | 1051 } |
| 1053 | 1052 |
| 1054 } // namespace mus | 1053 } // namespace mus |
| OLD | NEW |