| 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/lib/window_tree_client_impl.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" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 : tree_client_impl_(tree_client_impl) {} | 63 : tree_client_impl_(tree_client_impl) {} |
| 64 ~WindowTreeClientImplPrivate() {} | 64 ~WindowTreeClientImplPrivate() {} |
| 65 | 65 |
| 66 void Init(mojom::WindowTree* window_tree) { | 66 void Init(mojom::WindowTree* window_tree) { |
| 67 mojom::WindowDataPtr root_data(mojom::WindowData::New()); | 67 mojom::WindowDataPtr root_data(mojom::WindowData::New()); |
| 68 root_data->parent_id = 0; | 68 root_data->parent_id = 0; |
| 69 root_data->window_id = 1; | 69 root_data->window_id = 1; |
| 70 root_data->bounds = mojo::Rect::From(gfx::Rect()); | 70 root_data->bounds = mojo::Rect::From(gfx::Rect()); |
| 71 root_data->properties.SetToEmpty(); | 71 root_data->properties.SetToEmpty(); |
| 72 root_data->visible = true; | 72 root_data->visible = true; |
| 73 root_data->drawn = true; | |
| 74 root_data->viewport_metrics = mojom::ViewportMetrics::New(); | 73 root_data->viewport_metrics = mojom::ViewportMetrics::New(); |
| 75 root_data->viewport_metrics->size_in_pixels = | 74 root_data->viewport_metrics->size_in_pixels = |
| 76 mojo::Size::From(gfx::Size(1000, 1000)); | 75 mojo::Size::From(gfx::Size(1000, 1000)); |
| 77 root_data->viewport_metrics->device_pixel_ratio = 1; | 76 root_data->viewport_metrics->device_pixel_ratio = 1; |
| 78 tree_client_impl_->OnEmbedImpl(window_tree, 1, std::move(root_data), 0); | 77 tree_client_impl_->OnEmbedImpl(window_tree, 1, std::move(root_data), 0, |
| 78 true); |
| 79 } | 79 } |
| 80 | 80 |
| 81 private: | 81 private: |
| 82 WindowTreeClientImpl* tree_client_impl_; | 82 WindowTreeClientImpl* tree_client_impl_; |
| 83 | 83 |
| 84 DISALLOW_COPY_AND_ASSIGN(WindowTreeClientImplPrivate); | 84 DISALLOW_COPY_AND_ASSIGN(WindowTreeClientImplPrivate); |
| 85 }; | 85 }; |
| 86 | 86 |
| 87 class WindowTreeSetup { | 87 class WindowTreeSetup { |
| 88 public: | 88 public: |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); | 510 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); |
| 511 setup.window_tree_client()->OnChangeCompleted(change_id, true); | 511 setup.window_tree_client()->OnChangeCompleted(change_id, true); |
| 512 } | 512 } |
| 513 | 513 |
| 514 TEST_F(WindowTreeClientImplTest, NewTopLevelWindow) { | 514 TEST_F(WindowTreeClientImplTest, NewTopLevelWindow) { |
| 515 WindowTreeSetup setup; | 515 WindowTreeSetup setup; |
| 516 Window* root1 = setup.GetFirstRoot(); | 516 Window* root1 = setup.GetFirstRoot(); |
| 517 ASSERT_TRUE(root1); | 517 ASSERT_TRUE(root1); |
| 518 Window* root2 = setup.window_tree_connection()->NewTopLevelWindow(nullptr); | 518 Window* root2 = setup.window_tree_connection()->NewTopLevelWindow(nullptr); |
| 519 ASSERT_TRUE(root2); | 519 ASSERT_TRUE(root2); |
| 520 EXPECT_TRUE(WindowPrivate(root2).parent_drawn()); |
| 520 ASSERT_NE(root2, root1); | 521 ASSERT_NE(root2, root1); |
| 521 EXPECT_NE(root2->id(), root1->id()); | 522 EXPECT_NE(root2->id(), root1->id()); |
| 522 EXPECT_EQ(2u, setup.window_tree_connection()->GetRoots().size()); | 523 EXPECT_EQ(2u, setup.window_tree_connection()->GetRoots().size()); |
| 523 EXPECT_TRUE(setup.window_tree_connection()->GetRoots().count(root1) > 0u); | 524 EXPECT_TRUE(setup.window_tree_connection()->GetRoots().count(root1) > 0u); |
| 524 EXPECT_TRUE(setup.window_tree_connection()->GetRoots().count(root2) > 0u); | 525 EXPECT_TRUE(setup.window_tree_connection()->GetRoots().count(root2) > 0u); |
| 525 | 526 |
| 526 // Ack the request to the windowtree to create the new window. | 527 // Ack the request to the windowtree to create the new window. |
| 527 uint32_t change_id; | 528 uint32_t change_id; |
| 528 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); | 529 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); |
| 529 EXPECT_EQ(setup.window_tree()->window_id(), root2->id()); | 530 EXPECT_EQ(setup.window_tree()->window_id(), root2->id()); |
| 530 | 531 |
| 531 mojom::WindowDataPtr data = mojom::WindowData::New(); | 532 mojom::WindowDataPtr data = mojom::WindowData::New(); |
| 532 data->window_id = root2->id(); | 533 data->window_id = root2->id(); |
| 533 data->viewport_metrics = mojom::ViewportMetrics::New(); | 534 data->viewport_metrics = mojom::ViewportMetrics::New(); |
| 534 setup.window_tree_client()->OnTopLevelCreated(change_id, std::move(data)); | 535 setup.window_tree_client()->OnTopLevelCreated(change_id, std::move(data), |
| 536 false); |
| 537 |
| 538 EXPECT_FALSE(WindowPrivate(root2).parent_drawn()); |
| 535 | 539 |
| 536 // Should not be able to add a top level as a child of another window. | 540 // Should not be able to add a top level as a child of another window. |
| 537 root1->AddChild(root2); | 541 root1->AddChild(root2); |
| 538 ASSERT_EQ(nullptr, root2->parent()); | 542 ASSERT_EQ(nullptr, root2->parent()); |
| 539 | 543 |
| 540 // Destroy the first root, shouldn't initiate tear down. | 544 // Destroy the first root, shouldn't initiate tear down. |
| 541 root1->Destroy(); | 545 root1->Destroy(); |
| 542 root1 = nullptr; | 546 root1 = nullptr; |
| 543 EXPECT_EQ(1u, setup.window_tree_connection()->GetRoots().size()); | 547 EXPECT_EQ(1u, setup.window_tree_connection()->GetRoots().size()); |
| 544 EXPECT_TRUE(setup.window_tree_connection()->GetRoots().count(root2) > 0u); | 548 EXPECT_TRUE(setup.window_tree_connection()->GetRoots().count(root2) > 0u); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 558 uint32_t change_id; | 562 uint32_t change_id; |
| 559 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); | 563 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); |
| 560 EXPECT_EQ(setup.window_tree()->window_id(), root2->id()); | 564 EXPECT_EQ(setup.window_tree()->window_id(), root2->id()); |
| 561 | 565 |
| 562 mojom::WindowDataPtr data = mojom::WindowData::New(); | 566 mojom::WindowDataPtr data = mojom::WindowData::New(); |
| 563 data->window_id = root2->id(); | 567 data->window_id = root2->id(); |
| 564 data->viewport_metrics = mojom::ViewportMetrics::New(); | 568 data->viewport_metrics = mojom::ViewportMetrics::New(); |
| 565 data->viewport_metrics->size_in_pixels = mojo::Size::From(gfx::Size(1, 2)); | 569 data->viewport_metrics->size_in_pixels = mojo::Size::From(gfx::Size(1, 2)); |
| 566 data->bounds = mojo::Rect::From(gfx::Rect(1, 2, 3, 4)); | 570 data->bounds = mojo::Rect::From(gfx::Rect(1, 2, 3, 4)); |
| 567 data->visible = true; | 571 data->visible = true; |
| 568 data->drawn = true; | 572 setup.window_tree_client()->OnTopLevelCreated(change_id, std::move(data), |
| 569 setup.window_tree_client()->OnTopLevelCreated(change_id, std::move(data)); | 573 true); |
| 570 | 574 |
| 571 // Make sure all the properties took. | 575 // Make sure all the properties took. |
| 572 EXPECT_TRUE(root2->IsDrawn()); | 576 EXPECT_TRUE(root2->IsDrawn()); |
| 573 EXPECT_TRUE(root2->visible()); | 577 EXPECT_TRUE(root2->visible()); |
| 574 EXPECT_EQ(gfx::Size(1, 2), | 578 EXPECT_EQ(gfx::Size(1, 2), |
| 575 root2->viewport_metrics().size_in_pixels.To<gfx::Size>()); | 579 root2->viewport_metrics().size_in_pixels.To<gfx::Size>()); |
| 576 EXPECT_EQ(gfx::Rect(1, 2, 3, 4), root2->bounds()); | 580 EXPECT_EQ(gfx::Rect(1, 2, 3, 4), root2->bounds()); |
| 577 } | 581 } |
| 578 | 582 |
| 579 TEST_F(WindowTreeClientImplTest, NewTopLevelWindowGetsAllChangesInFlight) { | 583 TEST_F(WindowTreeClientImplTest, NewTopLevelWindowGetsAllChangesInFlight) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 setup.window_tree()->GetAndClearChangeId(&property_in_flight_change_id)); | 621 setup.window_tree()->GetAndClearChangeId(&property_in_flight_change_id)); |
| 618 EXPECT_NE(bounds_in_flight_change_id, property_in_flight_change_id); | 622 EXPECT_NE(bounds_in_flight_change_id, property_in_flight_change_id); |
| 619 | 623 |
| 620 // Ack the new window top level window. Vis and bounds shouldn't change. | 624 // Ack the new window top level window. Vis and bounds shouldn't change. |
| 621 mojom::WindowDataPtr data = mojom::WindowData::New(); | 625 mojom::WindowDataPtr data = mojom::WindowData::New(); |
| 622 data->window_id = root2->id(); | 626 data->window_id = root2->id(); |
| 623 data->viewport_metrics = mojom::ViewportMetrics::New(); | 627 data->viewport_metrics = mojom::ViewportMetrics::New(); |
| 624 data->viewport_metrics->size_in_pixels = mojo::Size::From(gfx::Size(1, 2)); | 628 data->viewport_metrics->size_in_pixels = mojo::Size::From(gfx::Size(1, 2)); |
| 625 data->bounds = mojo::Rect::From(gfx::Rect(1, 2, 3, 4)); | 629 data->bounds = mojo::Rect::From(gfx::Rect(1, 2, 3, 4)); |
| 626 data->visible = true; | 630 data->visible = true; |
| 627 data->drawn = true; | |
| 628 data->properties["xx"] = mojo::Array<uint8_t>::From(std::string("server_xx")); | 631 data->properties["xx"] = mojo::Array<uint8_t>::From(std::string("server_xx")); |
| 629 data->properties["yy"] = mojo::Array<uint8_t>::From(std::string("server_yy")); | 632 data->properties["yy"] = mojo::Array<uint8_t>::From(std::string("server_yy")); |
| 630 setup.window_tree_client()->OnTopLevelCreated(new_window_in_flight_change_id, | 633 setup.window_tree_client()->OnTopLevelCreated(new_window_in_flight_change_id, |
| 631 std::move(data)); | 634 std::move(data), true); |
| 632 | 635 |
| 633 // The only value that should take effect is the property for 'yy' as it was | 636 // The only value that should take effect is the property for 'yy' as it was |
| 634 // not in flight. | 637 // not in flight. |
| 635 EXPECT_TRUE(WindowPrivate(root2).drawn()); | 638 EXPECT_TRUE(WindowPrivate(root2).parent_drawn()); |
| 636 EXPECT_FALSE(root2->visible()); | 639 EXPECT_FALSE(root2->visible()); |
| 637 EXPECT_EQ(gfx::Size(1, 2), | 640 EXPECT_EQ(gfx::Size(1, 2), |
| 638 root2->viewport_metrics().size_in_pixels.To<gfx::Size>()); | 641 root2->viewport_metrics().size_in_pixels.To<gfx::Size>()); |
| 639 EXPECT_EQ(gfx::Rect(5, 6, 7, 8), root2->bounds()); | 642 EXPECT_EQ(gfx::Rect(5, 6, 7, 8), root2->bounds()); |
| 640 EXPECT_EQ(2u, root2->shared_properties().size()); | 643 EXPECT_EQ(2u, root2->shared_properties().size()); |
| 641 ASSERT_TRUE(root2->HasSharedProperty("yy")); | 644 ASSERT_TRUE(root2->HasSharedProperty("yy")); |
| 642 EXPECT_EQ("server_yy", root2->GetSharedProperty<std::string>("yy")); | 645 EXPECT_EQ("server_yy", root2->GetSharedProperty<std::string>("yy")); |
| 643 ASSERT_TRUE(root2->HasSharedProperty("xx")); | 646 ASSERT_TRUE(root2->HasSharedProperty("xx")); |
| 644 EXPECT_EQ("client_xx", root2->GetSharedProperty<std::string>("xx")); | 647 EXPECT_EQ("client_xx", root2->GetSharedProperty<std::string>("xx")); |
| 645 | 648 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 | 698 |
| 696 mojom::WindowDataPtr data = mojom::WindowData::New(); | 699 mojom::WindowDataPtr data = mojom::WindowData::New(); |
| 697 data->window_id = root2->id(); | 700 data->window_id = root2->id(); |
| 698 data->viewport_metrics = mojom::ViewportMetrics::New(); | 701 data->viewport_metrics = mojom::ViewportMetrics::New(); |
| 699 | 702 |
| 700 // Destroy the window before the server has a chance to ack the window | 703 // Destroy the window before the server has a chance to ack the window |
| 701 // creation. | 704 // creation. |
| 702 root2->Destroy(); | 705 root2->Destroy(); |
| 703 EXPECT_EQ(1u, setup.window_tree_connection()->GetRoots().size()); | 706 EXPECT_EQ(1u, setup.window_tree_connection()->GetRoots().size()); |
| 704 | 707 |
| 705 setup.window_tree_client()->OnTopLevelCreated(change_id, std::move(data)); | 708 setup.window_tree_client()->OnTopLevelCreated(change_id, std::move(data), |
| 709 true); |
| 706 EXPECT_EQ(1u, setup.window_tree_connection()->GetRoots().size()); | 710 EXPECT_EQ(1u, setup.window_tree_connection()->GetRoots().size()); |
| 707 } | 711 } |
| 708 | 712 |
| 709 // Tests both SetCapture and ReleaseCapture, to ensure that Window is properly | 713 // Tests both SetCapture and ReleaseCapture, to ensure that Window is properly |
| 710 // updated on failures. | 714 // updated on failures. |
| 711 TEST_F(WindowTreeClientImplTest, ExplicitCapture) { | 715 TEST_F(WindowTreeClientImplTest, ExplicitCapture) { |
| 712 WindowTreeSetup setup; | 716 WindowTreeSetup setup; |
| 713 Window* root = setup.GetFirstRoot(); | 717 Window* root = setup.GetFirstRoot(); |
| 714 ASSERT_TRUE(root); | 718 ASSERT_TRUE(root); |
| 715 | 719 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 816 | 820 |
| 817 setup.window_tree_client()->OnChangeCompleted(change_id2, false); | 821 setup.window_tree_client()->OnChangeCompleted(change_id2, false); |
| 818 EXPECT_FALSE(child->HasCapture()); | 822 EXPECT_FALSE(child->HasCapture()); |
| 819 EXPECT_TRUE(root->HasCapture()); | 823 EXPECT_TRUE(root->HasCapture()); |
| 820 | 824 |
| 821 setup.window_tree_client()->OnLostCapture(root->id()); | 825 setup.window_tree_client()->OnLostCapture(root->id()); |
| 822 EXPECT_FALSE(root->HasCapture()); | 826 EXPECT_FALSE(root->HasCapture()); |
| 823 } | 827 } |
| 824 | 828 |
| 825 } // namespace mus | 829 } // namespace mus |
| OLD | NEW |