| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "components/mus/common/types.h" | 9 #include "components/mus/common/types.h" |
| 10 #include "components/mus/common/util.h" | 10 #include "components/mus/common/util.h" |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 tracker_.OnWindowSharedPropertyChanged(window, name, new_data.Pass()); | 116 tracker_.OnWindowSharedPropertyChanged(window, name, new_data.Pass()); |
| 117 } | 117 } |
| 118 void OnWindowInputEvent(uint32_t event_id, | 118 void OnWindowInputEvent(uint32_t event_id, |
| 119 uint32_t window, | 119 uint32_t window, |
| 120 EventPtr event) override { | 120 EventPtr event) override { |
| 121 tracker_.OnWindowInputEvent(window, event.Pass()); | 121 tracker_.OnWindowInputEvent(window, event.Pass()); |
| 122 } | 122 } |
| 123 void OnWindowFocused(uint32_t focused_window_id) override { | 123 void OnWindowFocused(uint32_t focused_window_id) override { |
| 124 tracker_.OnWindowFocused(focused_window_id); | 124 tracker_.OnWindowFocused(focused_window_id); |
| 125 } | 125 } |
| 126 void OnWindowCursorChanged(uint32 window_id, |
| 127 mojom::Cursor cursor_id) override { |
| 128 tracker_.OnWindowCursorChanged(window_id, cursor_id); |
| 129 } |
| 126 void OnChangeCompleted(uint32_t change_id, bool success) override {} | 130 void OnChangeCompleted(uint32_t change_id, bool success) override {} |
| 127 void WmSetBounds(uint32_t change_id, | 131 void WmSetBounds(uint32_t change_id, |
| 128 Id window_id, | 132 Id window_id, |
| 129 mojo::RectPtr bounds) override {} | 133 mojo::RectPtr bounds) override {} |
| 130 void WmSetProperty(uint32_t change_id, | 134 void WmSetProperty(uint32_t change_id, |
| 131 Id window_id, | 135 Id window_id, |
| 132 const mojo::String& name, | 136 const mojo::String& name, |
| 133 mojo::Array<uint8_t> transit_data) override {} | 137 mojo::Array<uint8_t> transit_data) override {} |
| 134 | 138 |
| 135 TestChangeTracker tracker_; | 139 TestChangeTracker tracker_; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 mus::mojom::WindowTree::ACCESS_POLICY_EMBED_ROOT, | 216 mus::mojom::WindowTree::ACCESS_POLICY_EMBED_ROOT, |
| 213 mus::mojom::WindowTreeClientPtr())); | 217 mus::mojom::WindowTreeClientPtr())); |
| 214 } | 218 } |
| 215 DISALLOW_COPY_AND_ASSIGN(TestWindowTreeHostConnection); | 219 DISALLOW_COPY_AND_ASSIGN(TestWindowTreeHostConnection); |
| 216 }; | 220 }; |
| 217 | 221 |
| 218 // ----------------------------------------------------------------------------- | 222 // ----------------------------------------------------------------------------- |
| 219 // Empty implementation of DisplayManager. | 223 // Empty implementation of DisplayManager. |
| 220 class TestDisplayManager : public DisplayManager { | 224 class TestDisplayManager : public DisplayManager { |
| 221 public: | 225 public: |
| 222 TestDisplayManager() {} | 226 TestDisplayManager(int32_t* cursor_id_storage) |
| 227 : cursor_id_storage_(cursor_id_storage) {} |
| 223 ~TestDisplayManager() override {} | 228 ~TestDisplayManager() override {} |
| 224 | 229 |
| 225 // DisplayManager: | 230 // DisplayManager: |
| 226 void Init(DisplayManagerDelegate* delegate) override { | 231 void Init(DisplayManagerDelegate* delegate) override { |
| 227 // It is necessary to tell the delegate about the ViewportMetrics to make | 232 // It is necessary to tell the delegate about the ViewportMetrics to make |
| 228 // sure that the WindowTreeHostConnection is correctly initialized (and a | 233 // sure that the WindowTreeHostConnection is correctly initialized (and a |
| 229 // root-window is created). | 234 // root-window is created). |
| 230 mojom::ViewportMetrics metrics; | 235 mojom::ViewportMetrics metrics; |
| 231 metrics.size_in_pixels = mojo::Size::From(gfx::Size(400, 300)); | 236 metrics.size_in_pixels = mojo::Size::From(gfx::Size(400, 300)); |
| 232 metrics.device_pixel_ratio = 1.f; | 237 metrics.device_pixel_ratio = 1.f; |
| 233 delegate->OnViewportMetricsChanged(mojom::ViewportMetrics(), metrics); | 238 delegate->OnViewportMetricsChanged(mojom::ViewportMetrics(), metrics); |
| 234 } | 239 } |
| 235 void SchedulePaint(const ServerWindow* window, | 240 void SchedulePaint(const ServerWindow* window, |
| 236 const gfx::Rect& bounds) override {} | 241 const gfx::Rect& bounds) override {} |
| 237 void SetViewportSize(const gfx::Size& size) override {} | 242 void SetViewportSize(const gfx::Size& size) override {} |
| 238 void SetTitle(const base::string16& title) override {} | 243 void SetTitle(const base::string16& title) override {} |
| 244 void SetCursorById(int32_t cursor) override { |
| 245 *cursor_id_storage_ = cursor; |
| 246 } |
| 239 const mojom::ViewportMetrics& GetViewportMetrics() override { | 247 const mojom::ViewportMetrics& GetViewportMetrics() override { |
| 240 return display_metrices_; | 248 return display_metrices_; |
| 241 } | 249 } |
| 242 void UpdateTextInputState(const ui::TextInputState& state) override {} | 250 void UpdateTextInputState(const ui::TextInputState& state) override {} |
| 243 void SetImeVisibility(bool visible) override {} | 251 void SetImeVisibility(bool visible) override {} |
| 244 bool IsFramePending() const override { return false; } | 252 bool IsFramePending() const override { return false; } |
| 245 | 253 |
| 246 private: | 254 private: |
| 247 mojom::ViewportMetrics display_metrices_; | 255 mojom::ViewportMetrics display_metrices_; |
| 248 | 256 |
| 257 int32_t* cursor_id_storage_; |
| 258 |
| 249 DISALLOW_COPY_AND_ASSIGN(TestDisplayManager); | 259 DISALLOW_COPY_AND_ASSIGN(TestDisplayManager); |
| 250 }; | 260 }; |
| 251 | 261 |
| 252 // Factory that dispenses TestDisplayManagers. | 262 // Factory that dispenses TestDisplayManagers. |
| 253 class TestDisplayManagerFactory : public DisplayManagerFactory { | 263 class TestDisplayManagerFactory : public DisplayManagerFactory { |
| 254 public: | 264 public: |
| 255 TestDisplayManagerFactory() {} | 265 TestDisplayManagerFactory(int32_t* cursor_id_storage) |
| 266 : cursor_id_storage_(cursor_id_storage) {} |
| 256 ~TestDisplayManagerFactory() {} | 267 ~TestDisplayManagerFactory() {} |
| 257 DisplayManager* CreateDisplayManager( | 268 DisplayManager* CreateDisplayManager( |
| 258 mojo::ApplicationImpl* app_impl, | 269 mojo::ApplicationImpl* app_impl, |
| 259 const scoped_refptr<GpuState>& gpu_state, | 270 const scoped_refptr<GpuState>& gpu_state, |
| 260 const scoped_refptr<mus::SurfacesState>& surfaces_state) override { | 271 const scoped_refptr<mus::SurfacesState>& surfaces_state) override { |
| 261 return new TestDisplayManager(); | 272 return new TestDisplayManager(cursor_id_storage_); |
| 262 } | 273 } |
| 263 | 274 |
| 264 private: | 275 private: |
| 276 int32_t* cursor_id_storage_; |
| 277 |
| 265 DISALLOW_COPY_AND_ASSIGN(TestDisplayManagerFactory); | 278 DISALLOW_COPY_AND_ASSIGN(TestDisplayManagerFactory); |
| 266 }; | 279 }; |
| 267 | 280 |
| 268 EventPtr CreatePointerDownEvent(int x, int y) { | 281 EventPtr CreatePointerDownEvent(int x, int y) { |
| 269 EventPtr event(Event::New()); | 282 EventPtr event(Event::New()); |
| 270 event->action = mus::mojom::EVENT_TYPE_POINTER_DOWN; | 283 event->action = mus::mojom::EVENT_TYPE_POINTER_DOWN; |
| 271 event->pointer_data = PointerData::New(); | 284 event->pointer_data = PointerData::New(); |
| 272 event->pointer_data->pointer_id = 1u; | 285 event->pointer_data->pointer_id = 1u; |
| 273 event->pointer_data->location = LocationData::New(); | 286 event->pointer_data->location = LocationData::New(); |
| 274 event->pointer_data->location->x = x; | 287 event->pointer_data->location->x = x; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 300 event->pointer_data->kind = mojom::POINTER_KIND_MOUSE; | 313 event->pointer_data->kind = mojom::POINTER_KIND_MOUSE; |
| 301 return event.Pass(); | 314 return event.Pass(); |
| 302 } | 315 } |
| 303 | 316 |
| 304 } // namespace | 317 } // namespace |
| 305 | 318 |
| 306 // ----------------------------------------------------------------------------- | 319 // ----------------------------------------------------------------------------- |
| 307 | 320 |
| 308 class WindowTreeTest : public testing::Test { | 321 class WindowTreeTest : public testing::Test { |
| 309 public: | 322 public: |
| 310 WindowTreeTest() : wm_client_(nullptr) {} | 323 WindowTreeTest() |
| 324 : wm_client_(nullptr), |
| 325 cursor_id_(0), |
| 326 display_manager_factory_(&cursor_id_) {} |
| 311 ~WindowTreeTest() override {} | 327 ~WindowTreeTest() override {} |
| 312 | 328 |
| 313 // WindowTreeImpl for the window manager. | 329 // WindowTreeImpl for the window manager. |
| 314 WindowTreeImpl* wm_connection() { | 330 WindowTreeImpl* wm_connection() { |
| 315 return connection_manager_->GetConnection(1); | 331 return connection_manager_->GetConnection(1); |
| 316 } | 332 } |
| 317 | 333 |
| 318 TestWindowTreeClient* last_window_tree_client() { | 334 TestWindowTreeClient* last_window_tree_client() { |
| 319 return delegate_.last_client(); | 335 return delegate_.last_client(); |
| 320 } | 336 } |
| 321 | 337 |
| 322 TestClientConnection* last_client_connection() { | 338 TestClientConnection* last_client_connection() { |
| 323 return delegate_.last_connection(); | 339 return delegate_.last_connection(); |
| 324 } | 340 } |
| 325 | 341 |
| 326 ConnectionManager* connection_manager() { return connection_manager_.get(); } | 342 ConnectionManager* connection_manager() { return connection_manager_.get(); } |
| 327 | 343 |
| 328 TestWindowTreeClient* wm_client() { return wm_client_; } | 344 TestWindowTreeClient* wm_client() { return wm_client_; } |
| 345 int32_t cursor_id() { return cursor_id_; } |
| 329 | 346 |
| 330 TestWindowTreeHostConnection* host_connection() { return host_connection_; } | 347 TestWindowTreeHostConnection* host_connection() { return host_connection_; } |
| 331 | 348 |
| 332 void DispatchEventWithoutAck(mojom::EventPtr event) { | 349 void DispatchEventWithoutAck(mojom::EventPtr event) { |
| 333 host_connection()->window_tree_host()->OnEvent(event.Pass()); | 350 host_connection()->window_tree_host()->OnEvent(event.Pass()); |
| 334 } | 351 } |
| 335 | 352 |
| 336 void AckPreviousEvent() { | 353 void AckPreviousEvent() { |
| 337 host_connection() | 354 host_connection() |
| 338 ->window_tree_host() | 355 ->window_tree_host() |
| 339 ->tree_awaiting_input_ack_->OnWindowInputEventAck(0); | 356 ->tree_awaiting_input_ack_->OnWindowInputEventAck(0); |
| 340 } | 357 } |
| 341 | 358 |
| 342 void DispatchEventAndAckImmediately(mojom::EventPtr event) { | 359 void DispatchEventAndAckImmediately(mojom::EventPtr event) { |
| 343 DispatchEventWithoutAck(event.Pass()); | 360 DispatchEventWithoutAck(event.Pass()); |
| 344 AckPreviousEvent(); | 361 AckPreviousEvent(); |
| 345 } | 362 } |
| 346 | 363 |
| 364 void SetupEventTargeting(TestWindowTreeClient** out_client, |
| 365 ServerWindow** out_window); |
| 366 |
| 347 protected: | 367 protected: |
| 348 // testing::Test: | 368 // testing::Test: |
| 349 void SetUp() override { | 369 void SetUp() override { |
| 350 DisplayManager::set_factory_for_testing(&display_manager_factory_); | 370 DisplayManager::set_factory_for_testing(&display_manager_factory_); |
| 351 // TODO(fsamuel): This is probably broken. We need a root. | 371 // TODO(fsamuel): This is probably broken. We need a root. |
| 352 connection_manager_.reset( | 372 connection_manager_.reset( |
| 353 new ConnectionManager(&delegate_, scoped_refptr<SurfacesState>())); | 373 new ConnectionManager(&delegate_, scoped_refptr<SurfacesState>())); |
| 354 WindowTreeHostImpl* host = new WindowTreeHostImpl( | 374 WindowTreeHostImpl* host = new WindowTreeHostImpl( |
| 355 mus::mojom::WindowTreeHostClientPtr(), connection_manager_.get(), | 375 mus::mojom::WindowTreeHostClientPtr(), connection_manager_.get(), |
| 356 nullptr, scoped_refptr<GpuState>(), scoped_refptr<mus::SurfacesState>(), | 376 nullptr, scoped_refptr<GpuState>(), scoped_refptr<mus::SurfacesState>(), |
| 357 nullptr); | 377 nullptr); |
| 358 // TODO(fsamuel): This is way too magical. We need to find a better way to | 378 // TODO(fsamuel): This is way too magical. We need to find a better way to |
| 359 // manage lifetime. | 379 // manage lifetime. |
| 360 host_connection_ = new TestWindowTreeHostConnection( | 380 host_connection_ = new TestWindowTreeHostConnection( |
| 361 make_scoped_ptr(host), connection_manager_.get()); | 381 make_scoped_ptr(host), connection_manager_.get()); |
| 362 host->Init(host_connection_); | 382 host->Init(host_connection_); |
| 363 wm_client_ = delegate_.last_client(); | 383 wm_client_ = delegate_.last_client(); |
| 364 } | 384 } |
| 365 | 385 |
| 366 private: | 386 private: |
| 367 // TestWindowTreeClient that is used for the WM connection. | 387 // TestWindowTreeClient that is used for the WM connection. |
| 368 TestWindowTreeClient* wm_client_; | 388 TestWindowTreeClient* wm_client_; |
| 389 int32_t cursor_id_; |
| 369 TestDisplayManagerFactory display_manager_factory_; | 390 TestDisplayManagerFactory display_manager_factory_; |
| 370 TestConnectionManagerDelegate delegate_; | 391 TestConnectionManagerDelegate delegate_; |
| 371 TestWindowTreeHostConnection* host_connection_; | 392 TestWindowTreeHostConnection* host_connection_; |
| 372 scoped_ptr<ConnectionManager> connection_manager_; | 393 scoped_ptr<ConnectionManager> connection_manager_; |
| 373 base::MessageLoop message_loop_; | 394 base::MessageLoop message_loop_; |
| 374 | 395 |
| 375 DISALLOW_COPY_AND_ASSIGN(WindowTreeTest); | 396 DISALLOW_COPY_AND_ASSIGN(WindowTreeTest); |
| 376 }; | 397 }; |
| 377 | 398 |
| 399 void WindowTreeTest::SetupEventTargeting(TestWindowTreeClient** out_client, |
| 400 ServerWindow** out_window) { |
| 401 const WindowId embed_window_id(wm_connection()->id(), 1); |
| 402 EXPECT_TRUE( |
| 403 wm_connection()->NewWindow(embed_window_id, ServerWindow::Properties())); |
| 404 EXPECT_TRUE(wm_connection()->SetWindowVisibility(embed_window_id, true)); |
| 405 EXPECT_TRUE( |
| 406 wm_connection()->AddWindow(*(wm_connection()->root()), embed_window_id)); |
| 407 host_connection()->window_tree_host()->root_window()->SetBounds( |
| 408 gfx::Rect(0, 0, 100, 100)); |
| 409 mojom::WindowTreeClientPtr client; |
| 410 mojo::InterfaceRequest<mojom::WindowTreeClient> client_request = |
| 411 GetProxy(&client); |
| 412 wm_client()->Bind(client_request.Pass()); |
| 413 ConnectionSpecificId connection_id = 0; |
| 414 wm_connection()->Embed(embed_window_id, |
| 415 client.Pass(), |
| 416 mojom::WindowTree::ACCESS_POLICY_DEFAULT, |
| 417 &connection_id); |
| 418 WindowTreeImpl* connection1 = |
| 419 connection_manager()->GetConnectionWithRoot(embed_window_id); |
| 420 ASSERT_TRUE(connection1 != nullptr); |
| 421 ASSERT_NE(connection1, wm_connection()); |
| 422 |
| 423 connection_manager() |
| 424 ->GetWindow(embed_window_id) |
| 425 ->SetBounds(gfx::Rect(0, 0, 50, 50)); |
| 426 |
| 427 const WindowId child1(connection1->id(), 1); |
| 428 EXPECT_TRUE(connection1->NewWindow(child1, ServerWindow::Properties())); |
| 429 EXPECT_TRUE(connection1->AddWindow(embed_window_id, child1)); |
| 430 connection1->GetHost()->AddActivationParent( |
| 431 WindowIdToTransportId(embed_window_id)); |
| 432 |
| 433 ServerWindow* v1 = connection1->GetWindow(child1); |
| 434 v1->SetVisible(true); |
| 435 v1->SetBounds(gfx::Rect(20, 20, 20, 20)); |
| 436 |
| 437 TestWindowTreeClient* embed_connection = last_window_tree_client(); |
| 438 embed_connection->tracker()->changes()->clear(); |
| 439 wm_client()->tracker()->changes()->clear(); |
| 440 |
| 441 *out_client = embed_connection; |
| 442 *out_window = v1; |
| 443 } |
| 444 |
| 378 // Verifies focus correctly changes on pointer events. | 445 // Verifies focus correctly changes on pointer events. |
| 379 TEST_F(WindowTreeTest, FocusOnPointer) { | 446 TEST_F(WindowTreeTest, FocusOnPointer) { |
| 380 const WindowId embed_window_id(wm_connection()->id(), 1); | 447 const WindowId embed_window_id(wm_connection()->id(), 1); |
| 381 EXPECT_TRUE( | 448 EXPECT_TRUE( |
| 382 wm_connection()->NewWindow(embed_window_id, ServerWindow::Properties())); | 449 wm_connection()->NewWindow(embed_window_id, ServerWindow::Properties())); |
| 383 EXPECT_TRUE(wm_connection()->SetWindowVisibility(embed_window_id, true)); | 450 EXPECT_TRUE(wm_connection()->SetWindowVisibility(embed_window_id, true)); |
| 384 EXPECT_TRUE( | 451 EXPECT_TRUE( |
| 385 wm_connection()->AddWindow(*(wm_connection()->root()), embed_window_id)); | 452 wm_connection()->AddWindow(*(wm_connection()->root()), embed_window_id)); |
| 386 host_connection()->window_tree_host()->root_window()->SetBounds( | 453 host_connection()->window_tree_host()->root_window()->SetBounds( |
| 387 gfx::Rect(0, 0, 100, 100)); | 454 gfx::Rect(0, 0, 100, 100)); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 DispatchEventAndAckImmediately(CreatePointerDownEvent(61, 22)); | 522 DispatchEventAndAckImmediately(CreatePointerDownEvent(61, 22)); |
| 456 EXPECT_EQ(v1, host_connection()->window_tree_host()->GetFocusedWindow()); | 523 EXPECT_EQ(v1, host_connection()->window_tree_host()->GetFocusedWindow()); |
| 457 ASSERT_EQ(wm_client()->tracker()->changes()->size(), 1u) | 524 ASSERT_EQ(wm_client()->tracker()->changes()->size(), 1u) |
| 458 << SingleChangeToDescription(*wm_client()->tracker()->changes()); | 525 << SingleChangeToDescription(*wm_client()->tracker()->changes()); |
| 459 EXPECT_EQ("InputEvent window=0,2 event_action=4", | 526 EXPECT_EQ("InputEvent window=0,2 event_action=4", |
| 460 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); | 527 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); |
| 461 EXPECT_TRUE(connection1_client->tracker()->changes()->empty()); | 528 EXPECT_TRUE(connection1_client->tracker()->changes()->empty()); |
| 462 } | 529 } |
| 463 | 530 |
| 464 TEST_F(WindowTreeTest, BasicInputEventTarget) { | 531 TEST_F(WindowTreeTest, BasicInputEventTarget) { |
| 465 const WindowId embed_window_id(wm_connection()->id(), 1); | 532 TestWindowTreeClient* embed_connection; |
| 466 EXPECT_TRUE( | 533 ServerWindow* out_window = nullptr; |
| 467 wm_connection()->NewWindow(embed_window_id, ServerWindow::Properties())); | 534 SetupEventTargeting(&embed_connection, &out_window); |
| 468 EXPECT_TRUE(wm_connection()->SetWindowVisibility(embed_window_id, true)); | |
| 469 EXPECT_TRUE( | |
| 470 wm_connection()->AddWindow(*(wm_connection()->root()), embed_window_id)); | |
| 471 host_connection()->window_tree_host()->root_window()->SetBounds( | |
| 472 gfx::Rect(0, 0, 100, 100)); | |
| 473 mojom::WindowTreeClientPtr client; | |
| 474 mojo::InterfaceRequest<mojom::WindowTreeClient> client_request = | |
| 475 GetProxy(&client); | |
| 476 wm_client()->Bind(client_request.Pass()); | |
| 477 ConnectionSpecificId connection_id = 0; | |
| 478 wm_connection()->Embed(embed_window_id, | |
| 479 client.Pass(), | |
| 480 mojom::WindowTree::ACCESS_POLICY_DEFAULT, | |
| 481 &connection_id); | |
| 482 WindowTreeImpl* connection1 = | |
| 483 connection_manager()->GetConnectionWithRoot(embed_window_id); | |
| 484 ASSERT_TRUE(connection1 != nullptr); | |
| 485 ASSERT_NE(connection1, wm_connection()); | |
| 486 | |
| 487 connection_manager() | |
| 488 ->GetWindow(embed_window_id) | |
| 489 ->SetBounds(gfx::Rect(0, 0, 50, 50)); | |
| 490 | |
| 491 const WindowId child1(connection1->id(), 1); | |
| 492 EXPECT_TRUE(connection1->NewWindow(child1, ServerWindow::Properties())); | |
| 493 EXPECT_TRUE(connection1->AddWindow(embed_window_id, child1)); | |
| 494 connection1->GetHost()->AddActivationParent( | |
| 495 WindowIdToTransportId(embed_window_id)); | |
| 496 | |
| 497 ServerWindow* v1 = connection1->GetWindow(child1); | |
| 498 v1->SetVisible(true); | |
| 499 v1->SetBounds(gfx::Rect(20, 20, 20, 20)); | |
| 500 | |
| 501 TestWindowTreeClient* embed_connection = last_window_tree_client(); | |
| 502 embed_connection->tracker()->changes()->clear(); | |
| 503 wm_client()->tracker()->changes()->clear(); | |
| 504 | 535 |
| 505 // Send an event to |v1|. |embed_connection| should get the event, not | 536 // Send an event to |v1|. |embed_connection| should get the event, not |
| 506 // |wm_client|, since |v1| lives inside an embedded window. | 537 // |wm_client|, since |v1| lives inside an embedded window. |
| 507 DispatchEventAndAckImmediately(CreatePointerDownEvent(21, 22)); | 538 DispatchEventAndAckImmediately(CreatePointerDownEvent(21, 22)); |
| 508 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size()); | 539 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size()); |
| 509 EXPECT_EQ("Focused id=2,1", | 540 EXPECT_EQ("Focused id=2,1", |
| 510 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); | 541 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); |
| 511 ASSERT_EQ(2u, embed_connection->tracker()->changes()->size()); | 542 ASSERT_EQ(2u, embed_connection->tracker()->changes()->size()); |
| 512 EXPECT_EQ("Focused id=2,1", | 543 EXPECT_EQ("Focused id=2,1", |
| 513 ChangesToDescription1(*embed_connection->tracker()->changes())[0]); | 544 ChangesToDescription1(*embed_connection->tracker()->changes())[0]); |
| 514 EXPECT_EQ("InputEvent window=2,1 event_action=4", | 545 EXPECT_EQ("InputEvent window=2,1 event_action=4", |
| 515 ChangesToDescription1(*embed_connection->tracker()->changes())[1]); | 546 ChangesToDescription1(*embed_connection->tracker()->changes())[1]); |
| 516 } | 547 } |
| 517 | 548 |
| 549 TEST_F(WindowTreeTest, CursorChangesWhenMouseOverWindowAndWindowSetsCursor) { |
| 550 TestWindowTreeClient* embed_connection = nullptr; |
| 551 ServerWindow* out_window = nullptr; |
| 552 SetupEventTargeting(&embed_connection, &out_window); |
| 553 |
| 554 // Like in BasicInputEventTarget, we send a pointer down event to be |
| 555 // dispatched. This is only to place the mouse cursor over that window though. |
| 556 DispatchEventAndAckImmediately(CreatePointerDownEvent(21, 22)); |
| 557 |
| 558 out_window->SetCursor(mojom::Cursor::CURSOR_IBEAM); |
| 559 |
| 560 // Because the cursor is over the window when SetCursor was called, we should |
| 561 // have immediately changed the cursor. |
| 562 EXPECT_EQ(mojom::Cursor::CURSOR_IBEAM, cursor_id()); |
| 563 } |
| 564 |
| 565 TEST_F(WindowTreeTest, CursorChangesWhenEnteringWindowWithDifferentCursor) { |
| 566 TestWindowTreeClient* embed_connection = nullptr; |
| 567 ServerWindow* out_window = nullptr; |
| 568 SetupEventTargeting(&embed_connection, &out_window); |
| 569 |
| 570 // Let's create a pointer event outside the window and then move the pointer |
| 571 // inside. |
| 572 DispatchEventAndAckImmediately(CreatePointerDownEvent(5, 5)); |
| 573 out_window->SetCursor(mojom::Cursor::CURSOR_IBEAM); |
| 574 EXPECT_EQ(mojom::Cursor::CURSOR_NULL, cursor_id()); |
| 575 DispatchEventAndAckImmediately(CreatePointerUpEvent(5, 5)); |
| 576 |
| 577 DispatchEventAndAckImmediately(CreatePointerDownEvent(21, 22)); |
| 578 EXPECT_EQ(mojom::Cursor::CURSOR_IBEAM, cursor_id()); |
| 579 } |
| 580 |
| 518 TEST_F(WindowTreeTest, EventAck) { | 581 TEST_F(WindowTreeTest, EventAck) { |
| 519 const WindowId embed_window_id(wm_connection()->id(), 1); | 582 const WindowId embed_window_id(wm_connection()->id(), 1); |
| 520 EXPECT_TRUE( | 583 EXPECT_TRUE( |
| 521 wm_connection()->NewWindow(embed_window_id, ServerWindow::Properties())); | 584 wm_connection()->NewWindow(embed_window_id, ServerWindow::Properties())); |
| 522 EXPECT_TRUE(wm_connection()->SetWindowVisibility(embed_window_id, true)); | 585 EXPECT_TRUE(wm_connection()->SetWindowVisibility(embed_window_id, true)); |
| 523 EXPECT_TRUE( | 586 EXPECT_TRUE( |
| 524 wm_connection()->AddWindow(*(wm_connection()->root()), embed_window_id)); | 587 wm_connection()->AddWindow(*(wm_connection()->root()), embed_window_id)); |
| 525 host_connection()->window_tree_host()->root_window()->SetBounds( | 588 host_connection()->window_tree_host()->root_window()->SetBounds( |
| 526 gfx::Rect(0, 0, 100, 100)); | 589 gfx::Rect(0, 0, 100, 100)); |
| 527 | 590 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 539 // Ack the first event. That should trigger the dispatch of the second event. | 602 // Ack the first event. That should trigger the dispatch of the second event. |
| 540 AckPreviousEvent(); | 603 AckPreviousEvent(); |
| 541 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size()); | 604 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size()); |
| 542 EXPECT_EQ("InputEvent window=0,2 event_action=5", | 605 EXPECT_EQ("InputEvent window=0,2 event_action=5", |
| 543 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); | 606 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); |
| 544 } | 607 } |
| 545 | 608 |
| 546 } // namespace ws | 609 } // namespace ws |
| 547 | 610 |
| 548 } // namespace mus | 611 } // namespace mus |
| OLD | NEW |