Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(250)

Side by Side Diff: components/mus/ws/window_tree_unittest.cc

Issue 1750143002: Changes ownership of WindowTreeHostConnection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/mus/ws/window_tree_host_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 TestClientConnection* last_connection_; 278 TestClientConnection* last_connection_;
279 WindowTreeHostImpl* window_tree_host_; 279 WindowTreeHostImpl* window_tree_host_;
280 280
281 DISALLOW_COPY_AND_ASSIGN(TestConnectionManagerDelegate); 281 DISALLOW_COPY_AND_ASSIGN(TestConnectionManagerDelegate);
282 }; 282 };
283 283
284 // ----------------------------------------------------------------------------- 284 // -----------------------------------------------------------------------------
285 285
286 class TestWindowTreeHostConnection : public WindowTreeHostConnection { 286 class TestWindowTreeHostConnection : public WindowTreeHostConnection {
287 public: 287 public:
288 TestWindowTreeHostConnection(scoped_ptr<WindowTreeHostImpl> host_impl, 288 TestWindowTreeHostConnection(WindowTreeHostImpl* host_impl,
289 ConnectionManager* manager) 289 ConnectionManager* manager)
290 : WindowTreeHostConnection(std::move(host_impl), manager) {} 290 : host_(host_impl), connection_manager_(manager) {}
291 ~TestWindowTreeHostConnection() override {} 291 ~TestWindowTreeHostConnection() override {}
292 292
293 private: 293 private:
294 // WindowTreeHostDelegate: 294 // WindowTreeHostConnection:
295 void OnDisplayInitialized() override { 295 WindowTreeImpl* CreateWindowTree(ServerWindow* root) override {
296 connection_manager()->AddHost(this); 296 return connection_manager_->EmbedAtWindow(
297 set_window_tree(connection_manager()->EmbedAtWindow( 297 root, mus::mojom::WindowTree::kAccessPolicyEmbedRoot,
298 window_tree_host()->root_window(), 298 mus::mojom::WindowTreeClientPtr());
299 mus::mojom::WindowTree::kAccessPolicyEmbedRoot,
300 mus::mojom::WindowTreeClientPtr()));
301 } 299 }
300
301 WindowTreeHostImpl* host_;
302 ConnectionManager* connection_manager_;
303
302 DISALLOW_COPY_AND_ASSIGN(TestWindowTreeHostConnection); 304 DISALLOW_COPY_AND_ASSIGN(TestWindowTreeHostConnection);
303 }; 305 };
304 306
305 // ----------------------------------------------------------------------------- 307 // -----------------------------------------------------------------------------
306 // Empty implementation of DisplayManager. 308 // Empty implementation of DisplayManager.
307 class TestDisplayManager : public DisplayManager { 309 class TestDisplayManager : public DisplayManager {
308 public: 310 public:
309 explicit TestDisplayManager(int32_t* cursor_id_storage) 311 explicit TestDisplayManager(int32_t* cursor_id_storage)
310 : cursor_id_storage_(cursor_id_storage) {} 312 : cursor_id_storage_(cursor_id_storage) {}
311 ~TestDisplayManager() override {} 313 ~TestDisplayManager() override {}
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 } 437 }
436 438
437 TestWindowTreeClient* wm_client() { return wm_client_; } 439 TestWindowTreeClient* wm_client() { return wm_client_; }
438 mus::mojom::Cursor cursor_id() { 440 mus::mojom::Cursor cursor_id() {
439 return static_cast<mus::mojom::Cursor>(cursor_id_); 441 return static_cast<mus::mojom::Cursor>(cursor_id_);
440 } 442 }
441 443
442 TestWindowTreeHostConnection* host_connection() { return host_connection_; } 444 TestWindowTreeHostConnection* host_connection() { return host_connection_; }
443 445
444 void DispatchEventWithoutAck(const ui::Event& event) { 446 void DispatchEventWithoutAck(const ui::Event& event) {
445 host_connection()->window_tree_host()->OnEvent(event); 447 window_tree_host_->OnEvent(event);
446 } 448 }
447 449
448 void set_window_manager_internal(WindowTreeImpl* connection, 450 void set_window_manager_internal(WindowTreeImpl* connection,
449 mojom::WindowManager* wm_internal) { 451 mojom::WindowManager* wm_internal) {
450 connection->window_manager_internal_ = wm_internal; 452 connection->window_manager_internal_ = wm_internal;
451 } 453 }
452 454
453 void AckPreviousEvent() { 455 void AckPreviousEvent() {
454 while (host_connection()->window_tree_host()->tree_awaiting_input_ack_) { 456 while (window_tree_host_->tree_awaiting_input_ack_)
455 host_connection() 457 window_tree_host_->tree_awaiting_input_ack_->OnWindowInputEventAck(0);
456 ->window_tree_host()
457 ->tree_awaiting_input_ack_->OnWindowInputEventAck(0);
458 }
459 } 458 }
460 459
461 void DispatchEventAndAckImmediately(const ui::Event& event) { 460 void DispatchEventAndAckImmediately(const ui::Event& event) {
462 DispatchEventWithoutAck(event); 461 DispatchEventWithoutAck(event);
463 AckPreviousEvent(); 462 AckPreviousEvent();
464 } 463 }
465 464
466 // Creates a new window from wm_connection() and embeds a new connection in 465 // Creates a new window from wm_connection() and embeds a new connection in
467 // it. 466 // it.
468 void SetupEventTargeting(TestWindowTreeClient** out_client, 467 void SetupEventTargeting(TestWindowTreeClient** out_client,
469 WindowTreeImpl** window_tree_connection, 468 WindowTreeImpl** window_tree_connection,
470 ServerWindow** window); 469 ServerWindow** window);
471 470
472 protected: 471 protected:
473 // testing::Test: 472 // testing::Test:
474 void SetUp() override { 473 void SetUp() override {
475 DisplayManager::set_factory_for_testing(&display_manager_factory_); 474 DisplayManager::set_factory_for_testing(&display_manager_factory_);
476 // TODO(fsamuel): This is probably broken. We need a root. 475 // TODO(fsamuel): This is probably broken. We need a root.
477 connection_manager_.reset( 476 connection_manager_.reset(
478 new ConnectionManager(&delegate_, scoped_refptr<SurfacesState>())); 477 new ConnectionManager(&delegate_, scoped_refptr<SurfacesState>()));
479 WindowTreeHostImpl* host = new WindowTreeHostImpl( 478 window_tree_host_ = new WindowTreeHostImpl(
480 connection_manager_.get(), nullptr, scoped_refptr<GpuState>(), 479 connection_manager_.get(), nullptr, scoped_refptr<GpuState>(),
481 scoped_refptr<mus::SurfacesState>()); 480 scoped_refptr<mus::SurfacesState>());
482 // TODO(fsamuel): This is way too magical. We need to find a better way to 481 // TODO(fsamuel): This is way too magical. We need to find a better way to
483 // manage lifetime. 482 // manage lifetime.
484 host_connection_ = new TestWindowTreeHostConnection( 483 host_connection_ = new TestWindowTreeHostConnection(
485 make_scoped_ptr(host), connection_manager_.get()); 484 window_tree_host_, connection_manager_.get());
486 host->Init(host_connection_); 485 window_tree_host_->Init(make_scoped_ptr(host_connection_));
487 wm_client_ = delegate_.last_client(); 486 wm_client_ = delegate_.last_client();
488 } 487 }
489 488
490 private: 489 protected:
491 // TestWindowTreeClient that is used for the WM connection. 490 // TestWindowTreeClient that is used for the WM connection.
492 TestWindowTreeClient* wm_client_; 491 TestWindowTreeClient* wm_client_;
493 int32_t cursor_id_; 492 int32_t cursor_id_;
494 TestDisplayManagerFactory display_manager_factory_; 493 TestDisplayManagerFactory display_manager_factory_;
495 TestConnectionManagerDelegate delegate_; 494 TestConnectionManagerDelegate delegate_;
496 TestWindowTreeHostConnection* host_connection_; 495 TestWindowTreeHostConnection* host_connection_;
496 WindowTreeHostImpl* window_tree_host_ = nullptr;
497 scoped_ptr<ConnectionManager> connection_manager_; 497 scoped_ptr<ConnectionManager> connection_manager_;
498 base::MessageLoop message_loop_; 498 base::MessageLoop message_loop_;
499 499
500 DISALLOW_COPY_AND_ASSIGN(WindowTreeTest); 500 DISALLOW_COPY_AND_ASSIGN(WindowTreeTest);
501 }; 501 };
502 502
503 // Creates a new window in wm_connection(), adds it to the root, embeds a 503 // Creates a new window in wm_connection(), adds it to the root, embeds a
504 // new client in the window and creates a child of said window. |window| is 504 // new client in the window and creates a child of said window. |window| is
505 // set to the child of |window_tree_connection| that is created. 505 // set to the child of |window_tree_connection| that is created.
506 void WindowTreeTest::SetupEventTargeting( 506 void WindowTreeTest::SetupEventTargeting(
507 TestWindowTreeClient** out_client, 507 TestWindowTreeClient** out_client,
508 WindowTreeImpl** window_tree_connection, 508 WindowTreeImpl** window_tree_connection,
509 ServerWindow** window) { 509 ServerWindow** window) {
510 const ClientWindowId embed_window_id = 510 const ClientWindowId embed_window_id =
511 BuildClientWindowId(wm_connection(), 1); 511 BuildClientWindowId(wm_connection(), 1);
512 EXPECT_TRUE( 512 EXPECT_TRUE(
513 wm_connection()->NewWindow(embed_window_id, ServerWindow::Properties())); 513 wm_connection()->NewWindow(embed_window_id, ServerWindow::Properties()));
514 EXPECT_TRUE(wm_connection()->SetWindowVisibility(embed_window_id, true)); 514 EXPECT_TRUE(wm_connection()->SetWindowVisibility(embed_window_id, true));
515 EXPECT_TRUE(wm_connection()->AddWindow(FirstRootId(wm_connection()), 515 EXPECT_TRUE(wm_connection()->AddWindow(FirstRootId(wm_connection()),
516 embed_window_id)); 516 embed_window_id));
517 host_connection()->window_tree_host()->root_window()->SetBounds( 517 window_tree_host_->root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
518 gfx::Rect(0, 0, 100, 100));
519 mojom::WindowTreeClientPtr client; 518 mojom::WindowTreeClientPtr client;
520 mojo::InterfaceRequest<mojom::WindowTreeClient> client_request = 519 mojo::InterfaceRequest<mojom::WindowTreeClient> client_request =
521 GetProxy(&client); 520 GetProxy(&client);
522 wm_client()->Bind(std::move(client_request)); 521 wm_client()->Bind(std::move(client_request));
523 ConnectionSpecificId connection_id = 0; 522 ConnectionSpecificId connection_id = 0;
524 wm_connection()->Embed(embed_window_id, std::move(client), 523 wm_connection()->Embed(embed_window_id, std::move(client),
525 mojom::WindowTree::kAccessPolicyDefault, 524 mojom::WindowTree::kAccessPolicyDefault,
526 &connection_id); 525 &connection_id);
527 ServerWindow* embed_window = 526 ServerWindow* embed_window =
528 wm_connection()->GetWindowByClientId(embed_window_id); 527 wm_connection()->GetWindowByClientId(embed_window_id);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 BuildClientWindowId(wm_connection(), 1); 559 BuildClientWindowId(wm_connection(), 1);
561 EXPECT_TRUE( 560 EXPECT_TRUE(
562 wm_connection()->NewWindow(embed_window_id, ServerWindow::Properties())); 561 wm_connection()->NewWindow(embed_window_id, ServerWindow::Properties()));
563 ServerWindow* embed_window = 562 ServerWindow* embed_window =
564 wm_connection()->GetWindowByClientId(embed_window_id); 563 wm_connection()->GetWindowByClientId(embed_window_id);
565 ASSERT_TRUE(embed_window); 564 ASSERT_TRUE(embed_window);
566 EXPECT_TRUE(wm_connection()->SetWindowVisibility(embed_window_id, true)); 565 EXPECT_TRUE(wm_connection()->SetWindowVisibility(embed_window_id, true));
567 ASSERT_TRUE(FirstRoot(wm_connection())); 566 ASSERT_TRUE(FirstRoot(wm_connection()));
568 const ClientWindowId wm_root_id = FirstRootId(wm_connection()); 567 const ClientWindowId wm_root_id = FirstRootId(wm_connection());
569 EXPECT_TRUE(wm_connection()->AddWindow(wm_root_id, embed_window_id)); 568 EXPECT_TRUE(wm_connection()->AddWindow(wm_root_id, embed_window_id));
570 host_connection()->window_tree_host()->root_window()->SetBounds( 569 window_tree_host_->root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
571 gfx::Rect(0, 0, 100, 100));
572 mojom::WindowTreeClientPtr client; 570 mojom::WindowTreeClientPtr client;
573 mojo::InterfaceRequest<mojom::WindowTreeClient> client_request = 571 mojo::InterfaceRequest<mojom::WindowTreeClient> client_request =
574 GetProxy(&client); 572 GetProxy(&client);
575 wm_client()->Bind(std::move(client_request)); 573 wm_client()->Bind(std::move(client_request));
576 ConnectionSpecificId connection_id = 0; 574 ConnectionSpecificId connection_id = 0;
577 wm_connection()->Embed(embed_window_id, std::move(client), 575 wm_connection()->Embed(embed_window_id, std::move(client),
578 mojom::WindowTree::kAccessPolicyDefault, 576 mojom::WindowTree::kAccessPolicyDefault,
579 &connection_id); 577 &connection_id);
580 WindowTreeImpl* connection1 = 578 WindowTreeImpl* connection1 =
581 connection_manager()->GetConnectionWithRoot(embed_window); 579 connection_manager()->GetConnectionWithRoot(embed_window);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 "Focused id=2,1", 619 "Focused id=2,1",
622 ChangesToDescription1(*connection1_client->tracker()->changes())[0]); 620 ChangesToDescription1(*connection1_client->tracker()->changes())[0]);
623 621
624 DispatchEventAndAckImmediately(CreatePointerUpEvent(21, 22)); 622 DispatchEventAndAckImmediately(CreatePointerUpEvent(21, 22));
625 wm_client()->tracker()->changes()->clear(); 623 wm_client()->tracker()->changes()->clear();
626 connection1_client->tracker()->changes()->clear(); 624 connection1_client->tracker()->changes()->clear();
627 625
628 // Press outside of the embedded window. Note that root cannot be focused 626 // Press outside of the embedded window. Note that root cannot be focused
629 // (because it cannot be activated). So the focus would not move in this case. 627 // (because it cannot be activated). So the focus would not move in this case.
630 DispatchEventAndAckImmediately(CreatePointerDownEvent(61, 22)); 628 DispatchEventAndAckImmediately(CreatePointerDownEvent(61, 22));
631 EXPECT_EQ(child1, host_connection()->window_tree_host()->GetFocusedWindow()); 629 EXPECT_EQ(child1, window_tree_host_->GetFocusedWindow());
632 630
633 DispatchEventAndAckImmediately(CreatePointerUpEvent(21, 22)); 631 DispatchEventAndAckImmediately(CreatePointerUpEvent(21, 22));
634 wm_client()->tracker()->changes()->clear(); 632 wm_client()->tracker()->changes()->clear();
635 connection1_client->tracker()->changes()->clear(); 633 connection1_client->tracker()->changes()->clear();
636 634
637 // Press in the same location. Should not get a focus change event (only input 635 // Press in the same location. Should not get a focus change event (only input
638 // event). 636 // event).
639 DispatchEventAndAckImmediately(CreatePointerDownEvent(61, 22)); 637 DispatchEventAndAckImmediately(CreatePointerDownEvent(61, 22));
640 EXPECT_EQ(child1, host_connection()->window_tree_host()->GetFocusedWindow()); 638 EXPECT_EQ(child1, window_tree_host_->GetFocusedWindow());
641 ASSERT_EQ(wm_client()->tracker()->changes()->size(), 1u) 639 ASSERT_EQ(wm_client()->tracker()->changes()->size(), 1u)
642 << SingleChangeToDescription(*wm_client()->tracker()->changes()); 640 << SingleChangeToDescription(*wm_client()->tracker()->changes());
643 EXPECT_EQ("InputEvent window=0,2 event_action=4", 641 EXPECT_EQ("InputEvent window=0,2 event_action=4",
644 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); 642 ChangesToDescription1(*wm_client()->tracker()->changes())[0]);
645 EXPECT_TRUE(connection1_client->tracker()->changes()->empty()); 643 EXPECT_TRUE(connection1_client->tracker()->changes()->empty());
646 } 644 }
647 645
648 TEST_F(WindowTreeTest, BasicInputEventTarget) { 646 TEST_F(WindowTreeTest, BasicInputEventTarget) {
649 TestWindowTreeClient* embed_connection = nullptr; 647 TestWindowTreeClient* embed_connection = nullptr;
650 WindowTreeImpl* window_tree_connection = nullptr; 648 WindowTreeImpl* window_tree_connection = nullptr;
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 804
807 TEST_F(WindowTreeTest, EventAck) { 805 TEST_F(WindowTreeTest, EventAck) {
808 const ClientWindowId embed_window_id = 806 const ClientWindowId embed_window_id =
809 BuildClientWindowId(wm_connection(), 1); 807 BuildClientWindowId(wm_connection(), 1);
810 EXPECT_TRUE( 808 EXPECT_TRUE(
811 wm_connection()->NewWindow(embed_window_id, ServerWindow::Properties())); 809 wm_connection()->NewWindow(embed_window_id, ServerWindow::Properties()));
812 EXPECT_TRUE(wm_connection()->SetWindowVisibility(embed_window_id, true)); 810 EXPECT_TRUE(wm_connection()->SetWindowVisibility(embed_window_id, true));
813 ASSERT_TRUE(FirstRoot(wm_connection())); 811 ASSERT_TRUE(FirstRoot(wm_connection()));
814 EXPECT_TRUE(wm_connection()->AddWindow(FirstRootId(wm_connection()), 812 EXPECT_TRUE(wm_connection()->AddWindow(FirstRootId(wm_connection()),
815 embed_window_id)); 813 embed_window_id));
816 host_connection()->window_tree_host()->root_window()->SetBounds( 814 window_tree_host_->root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
817 gfx::Rect(0, 0, 100, 100));
818 815
819 wm_client()->tracker()->changes()->clear(); 816 wm_client()->tracker()->changes()->clear();
820 DispatchEventWithoutAck(CreateMouseMoveEvent(21, 22)); 817 DispatchEventWithoutAck(CreateMouseMoveEvent(21, 22));
821 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size()); 818 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size());
822 EXPECT_EQ("InputEvent window=0,2 event_action=5", 819 EXPECT_EQ("InputEvent window=0,2 event_action=5",
823 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); 820 ChangesToDescription1(*wm_client()->tracker()->changes())[0]);
824 wm_client()->tracker()->changes()->clear(); 821 wm_client()->tracker()->changes()->clear();
825 822
826 // Send another event. This event shouldn't reach the client. 823 // Send another event. This event shouldn't reach the client.
827 DispatchEventWithoutAck(CreateMouseMoveEvent(21, 22)); 824 DispatchEventWithoutAck(CreateMouseMoveEvent(21, 22));
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 mojom_window_tree->ReleaseCapture(++change_id, 937 mojom_window_tree->ReleaseCapture(++change_id,
941 WindowIdToTransportId(root_window->id())); 938 WindowIdToTransportId(root_window->id()));
942 EXPECT_EQ(window, host->GetCaptureWindow()); 939 EXPECT_EQ(window, host->GetCaptureWindow());
943 mojom_window_tree->ReleaseCapture(++change_id, 940 mojom_window_tree->ReleaseCapture(++change_id,
944 WindowIdToTransportId(window->id())); 941 WindowIdToTransportId(window->id()));
945 EXPECT_EQ(nullptr, host->GetCaptureWindow()); 942 EXPECT_EQ(nullptr, host->GetCaptureWindow());
946 } 943 }
947 944
948 } // namespace ws 945 } // namespace ws
949 } // namespace mus 946 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/ws/window_tree_host_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698