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" |
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/window.h" | 17 #include "components/mus/public/cpp/window.h" |
18 #include "components/mus/public/cpp/window_observer.h" | 18 #include "components/mus/public/cpp/window_observer.h" |
19 #include "components/mus/public/cpp/window_property.h" | 19 #include "components/mus/public/cpp/window_property.h" |
20 #include "components/mus/public/cpp/window_tree_delegate.h" | 20 #include "components/mus/public/cpp/window_tree_delegate.h" |
| 21 #include "mojo/common/common_type_converters.h" |
21 #include "mojo/converters/geometry/geometry_type_converters.h" | 22 #include "mojo/converters/geometry/geometry_type_converters.h" |
22 #include "mojo/converters/input_events/input_events_type_converters.h" | 23 #include "mojo/converters/input_events/input_events_type_converters.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
24 #include "ui/events/event.h" | 25 #include "ui/events/event.h" |
25 #include "ui/events/event_utils.h" | 26 #include "ui/events/event_utils.h" |
26 #include "ui/gfx/geometry/rect.h" | 27 #include "ui/gfx/geometry/rect.h" |
27 | 28 |
28 namespace mus { | 29 namespace mus { |
29 | 30 |
30 mojo::Array<uint8_t> Int32ToPropertyTransportValue(int32_t value) { | 31 mojo::Array<uint8_t> Int32ToPropertyTransportValue(int32_t value) { |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 ASSERT_NE(root2, root1); | 502 ASSERT_NE(root2, root1); |
502 EXPECT_NE(root2->id(), root1->id()); | 503 EXPECT_NE(root2->id(), root1->id()); |
503 EXPECT_EQ(2u, setup.window_tree_connection()->GetRoots().size()); | 504 EXPECT_EQ(2u, setup.window_tree_connection()->GetRoots().size()); |
504 EXPECT_TRUE(setup.window_tree_connection()->GetRoots().count(root1) > 0u); | 505 EXPECT_TRUE(setup.window_tree_connection()->GetRoots().count(root1) > 0u); |
505 EXPECT_TRUE(setup.window_tree_connection()->GetRoots().count(root2) > 0u); | 506 EXPECT_TRUE(setup.window_tree_connection()->GetRoots().count(root2) > 0u); |
506 | 507 |
507 // Ack the request to the windowtree to create the new window. | 508 // Ack the request to the windowtree to create the new window. |
508 uint32_t change_id; | 509 uint32_t change_id; |
509 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); | 510 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); |
510 EXPECT_EQ(setup.window_tree()->window_id(), root2->id()); | 511 EXPECT_EQ(setup.window_tree()->window_id(), root2->id()); |
511 setup.window_tree_client()->OnChangeCompleted(change_id, true); | 512 |
| 513 mojom::WindowDataPtr data = mojom::WindowData::New(); |
| 514 data->window_id = root2->id(); |
| 515 data->viewport_metrics = mojom::ViewportMetrics::New(); |
| 516 setup.window_tree_client()->OnTopLevelCreated(change_id, std::move(data)); |
512 | 517 |
513 // Should not be able to add a top level as a child of another window. | 518 // Should not be able to add a top level as a child of another window. |
514 root1->AddChild(root2); | 519 root1->AddChild(root2); |
515 ASSERT_EQ(nullptr, root2->parent()); | 520 ASSERT_EQ(nullptr, root2->parent()); |
516 | 521 |
517 // Destroy the first root, shouldn't initiate tear down. | 522 // Destroy the first root, shouldn't initiate tear down. |
518 root1->Destroy(); | 523 root1->Destroy(); |
519 root1 = nullptr; | 524 root1 = nullptr; |
520 EXPECT_EQ(1u, setup.window_tree_connection()->GetRoots().size()); | 525 EXPECT_EQ(1u, setup.window_tree_connection()->GetRoots().size()); |
521 EXPECT_TRUE(setup.window_tree_connection()->GetRoots().count(root2) > 0u); | 526 EXPECT_TRUE(setup.window_tree_connection()->GetRoots().count(root2) > 0u); |
522 } | 527 } |
523 | 528 |
| 529 TEST_F(WindowTreeClientImplTest, NewTopLevelWindowGetsPropertiesFromData) { |
| 530 WindowTreeSetup setup; |
| 531 Window* root1 = setup.GetFirstRoot(); |
| 532 ASSERT_TRUE(root1); |
| 533 Window* root2 = setup.window_tree_connection()->NewTopLevelWindow(nullptr); |
| 534 ASSERT_TRUE(root2); |
| 535 |
| 536 EXPECT_FALSE(root2->IsDrawn()); |
| 537 EXPECT_FALSE(root2->visible()); |
| 538 |
| 539 // Ack the request to the windowtree to create the new window. |
| 540 uint32_t change_id; |
| 541 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); |
| 542 EXPECT_EQ(setup.window_tree()->window_id(), root2->id()); |
| 543 |
| 544 mojom::WindowDataPtr data = mojom::WindowData::New(); |
| 545 data->window_id = root2->id(); |
| 546 data->viewport_metrics = mojom::ViewportMetrics::New(); |
| 547 data->viewport_metrics->size_in_pixels = mojo::Size::From(gfx::Size(1, 2)); |
| 548 data->bounds = mojo::Rect::From(gfx::Rect(1, 2, 3, 4)); |
| 549 data->visible = true; |
| 550 data->drawn = true; |
| 551 setup.window_tree_client()->OnTopLevelCreated(change_id, std::move(data)); |
| 552 |
| 553 // Make sure all the properties took. |
| 554 EXPECT_TRUE(root2->IsDrawn()); |
| 555 EXPECT_TRUE(root2->visible()); |
| 556 EXPECT_EQ(gfx::Size(1, 2), |
| 557 root2->viewport_metrics().size_in_pixels.To<gfx::Size>()); |
| 558 EXPECT_EQ(gfx::Rect(1, 2, 3, 4), root2->bounds()); |
| 559 } |
| 560 |
| 561 TEST_F(WindowTreeClientImplTest, NewTopLevelWindowGetsAllChangesInFlight) { |
| 562 WindowTreeSetup setup; |
| 563 Window* root1 = setup.GetFirstRoot(); |
| 564 ASSERT_TRUE(root1); |
| 565 Window* root2 = setup.window_tree_connection()->NewTopLevelWindow(nullptr); |
| 566 ASSERT_TRUE(root2); |
| 567 |
| 568 EXPECT_FALSE(root2->IsDrawn()); |
| 569 EXPECT_FALSE(root2->visible()); |
| 570 |
| 571 // Get the id of the in flight change for creating the new window. |
| 572 uint32_t new_window_in_flight_change_id; |
| 573 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId( |
| 574 &new_window_in_flight_change_id)); |
| 575 EXPECT_EQ(setup.window_tree()->window_id(), root2->id()); |
| 576 |
| 577 // Make visibility go from false->true->false. Don't ack immediately. |
| 578 root2->SetVisible(true); |
| 579 uint32_t vis_in_flight_change_id1; |
| 580 ASSERT_TRUE( |
| 581 setup.window_tree()->GetAndClearChangeId(&vis_in_flight_change_id1)); |
| 582 EXPECT_NE(new_window_in_flight_change_id, vis_in_flight_change_id1); |
| 583 root2->SetVisible(false); |
| 584 uint32_t vis_in_flight_change_id2; |
| 585 ASSERT_TRUE( |
| 586 setup.window_tree()->GetAndClearChangeId(&vis_in_flight_change_id2)); |
| 587 EXPECT_NE(vis_in_flight_change_id1, vis_in_flight_change_id2); |
| 588 |
| 589 // Change bounds to 5, 6, 7, 8. |
| 590 root2->SetBounds(gfx::Rect(5, 6, 7, 8)); |
| 591 uint32_t bounds_in_flight_change_id; |
| 592 ASSERT_TRUE( |
| 593 setup.window_tree()->GetAndClearChangeId(&bounds_in_flight_change_id)); |
| 594 EXPECT_NE(vis_in_flight_change_id2, bounds_in_flight_change_id); |
| 595 |
| 596 root2->SetSharedProperty<std::string>("xx", "client_xx"); |
| 597 uint32_t property_in_flight_change_id; |
| 598 ASSERT_TRUE( |
| 599 setup.window_tree()->GetAndClearChangeId(&property_in_flight_change_id)); |
| 600 EXPECT_NE(bounds_in_flight_change_id, property_in_flight_change_id); |
| 601 |
| 602 // Ack the new window top level window. Vis and bounds shouldn't change. |
| 603 mojom::WindowDataPtr data = mojom::WindowData::New(); |
| 604 data->window_id = root2->id(); |
| 605 data->viewport_metrics = mojom::ViewportMetrics::New(); |
| 606 data->viewport_metrics->size_in_pixels = mojo::Size::From(gfx::Size(1, 2)); |
| 607 data->bounds = mojo::Rect::From(gfx::Rect(1, 2, 3, 4)); |
| 608 data->visible = true; |
| 609 data->drawn = true; |
| 610 data->properties["xx"] = mojo::Array<uint8_t>::From(std::string("server_xx")); |
| 611 data->properties["yy"] = mojo::Array<uint8_t>::From(std::string("server_yy")); |
| 612 setup.window_tree_client()->OnTopLevelCreated(new_window_in_flight_change_id, |
| 613 std::move(data)); |
| 614 |
| 615 // The only value that should take effect is the property for 'yy' as it was |
| 616 // not in flight. |
| 617 EXPECT_TRUE(WindowPrivate(root2).drawn()); |
| 618 EXPECT_FALSE(root2->visible()); |
| 619 EXPECT_EQ(gfx::Size(1, 2), |
| 620 root2->viewport_metrics().size_in_pixels.To<gfx::Size>()); |
| 621 EXPECT_EQ(gfx::Rect(5, 6, 7, 8), root2->bounds()); |
| 622 EXPECT_EQ(2u, root2->shared_properties().size()); |
| 623 ASSERT_TRUE(root2->HasSharedProperty("yy")); |
| 624 EXPECT_EQ("server_yy", root2->GetSharedProperty<std::string>("yy")); |
| 625 ASSERT_TRUE(root2->HasSharedProperty("xx")); |
| 626 EXPECT_EQ("client_xx", root2->GetSharedProperty<std::string>("xx")); |
| 627 |
| 628 // Tell the client the changes failed. This should cause the values to change |
| 629 // to that of the server. |
| 630 setup.window_tree_client()->OnChangeCompleted(vis_in_flight_change_id1, |
| 631 false); |
| 632 EXPECT_FALSE(root2->visible()); |
| 633 setup.window_tree_client()->OnChangeCompleted(vis_in_flight_change_id2, |
| 634 false); |
| 635 EXPECT_TRUE(root2->visible()); |
| 636 setup.window_tree_client()->OnChangeCompleted(bounds_in_flight_change_id, |
| 637 false); |
| 638 EXPECT_EQ(gfx::Rect(1, 2, 3, 4), root2->bounds()); |
| 639 setup.window_tree_client()->OnChangeCompleted(property_in_flight_change_id, |
| 640 false); |
| 641 EXPECT_EQ(2u, root2->shared_properties().size()); |
| 642 ASSERT_TRUE(root2->HasSharedProperty("yy")); |
| 643 EXPECT_EQ("server_yy", root2->GetSharedProperty<std::string>("yy")); |
| 644 ASSERT_TRUE(root2->HasSharedProperty("xx")); |
| 645 EXPECT_EQ("server_xx", root2->GetSharedProperty<std::string>("xx")); |
| 646 } |
| 647 |
524 } // namespace mus | 648 } // namespace mus |
OLD | NEW |