| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "components/mus/public/interfaces/window_tree.mojom.h" | 13 #include "components/mus/public/interfaces/window_tree.mojom.h" |
| 14 #include "components/mus/public/interfaces/window_tree_host.mojom.h" | 14 #include "components/mus/public/interfaces/window_tree_host.mojom.h" |
| 15 #include "components/mus/ws/ids.h" | 15 #include "components/mus/ws/ids.h" |
| 16 #include "components/mus/ws/test_change_tracker.h" | 16 #include "components/mus/ws/test_change_tracker.h" |
| 17 #include "mojo/converters/geometry/geometry_type_converters.h" | 17 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 18 #include "mojo/shell/public/cpp/application_delegate.h" | 18 #include "mojo/shell/public/cpp/application_delegate.h" |
| 19 #include "mojo/shell/public/cpp/application_impl.h" | 19 #include "mojo/shell/public/cpp/application_impl.h" |
| 20 #include "mojo/shell/public/cpp/application_test_base.h" | 20 #include "mojo/shell/public/cpp/application_test_base.h" |
| 21 | 21 |
| 22 using mojo::ApplicationConnection; | 22 using mojo::ApplicationConnection; |
| 23 using mojo::ApplicationDelegate; | 23 using mojo::ApplicationDelegate; |
| 24 using mojo::Array; | 24 using mojo::Array; |
| 25 using mojo::Callback; | 25 using mojo::Callback; |
| 26 using mojo::InterfaceRequest; | 26 using mojo::InterfaceRequest; |
| 27 using mojo::RectPtr; | 27 using mojo::RectPtr; |
| 28 using mojo::String; | 28 using mojo::String; |
| 29 using mus::mojom::ERROR_CODE_NONE; | |
| 30 using mus::mojom::ErrorCode; | 29 using mus::mojom::ErrorCode; |
| 31 using mus::mojom::EventPtr; | 30 using mus::mojom::EventPtr; |
| 32 using mus::mojom::ViewportMetricsPtr; | 31 using mus::mojom::ViewportMetricsPtr; |
| 33 using mus::mojom::WindowDataPtr; | 32 using mus::mojom::WindowDataPtr; |
| 34 using mus::mojom::WindowTree; | 33 using mus::mojom::WindowTree; |
| 35 using mus::mojom::WindowTreeClient; | 34 using mus::mojom::WindowTreeClient; |
| 36 | 35 |
| 37 namespace mus { | 36 namespace mus { |
| 38 namespace ws { | 37 namespace ws { |
| 39 | 38 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 68 bool EmbedUrl(mojo::ApplicationImpl* app, | 67 bool EmbedUrl(mojo::ApplicationImpl* app, |
| 69 WindowTree* ws, | 68 WindowTree* ws, |
| 70 const String& url, | 69 const String& url, |
| 71 Id root_id) { | 70 Id root_id) { |
| 72 bool result = false; | 71 bool result = false; |
| 73 base::RunLoop run_loop; | 72 base::RunLoop run_loop; |
| 74 { | 73 { |
| 75 mojom::WindowTreeClientPtr client; | 74 mojom::WindowTreeClientPtr client; |
| 76 app->ConnectToService(url.get(), &client); | 75 app->ConnectToService(url.get(), &client); |
| 77 ws->Embed(root_id, std::move(client), | 76 ws->Embed(root_id, std::move(client), |
| 78 mojom::WindowTree::ACCESS_POLICY_DEFAULT, | 77 mojom::WindowTree::kAccessPolicyDefault, |
| 79 base::Bind(&EmbedCallbackImpl, &run_loop, &result)); | 78 base::Bind(&EmbedCallbackImpl, &run_loop, &result)); |
| 80 } | 79 } |
| 81 run_loop.Run(); | 80 run_loop.Run(); |
| 82 return result; | 81 return result; |
| 83 } | 82 } |
| 84 | 83 |
| 85 bool Embed(WindowTree* ws, Id root_id, mojom::WindowTreeClientPtr client) { | 84 bool Embed(WindowTree* ws, Id root_id, mojom::WindowTreeClientPtr client) { |
| 86 bool result = false; | 85 bool result = false; |
| 87 base::RunLoop run_loop; | 86 base::RunLoop run_loop; |
| 88 { | 87 { |
| 89 ws->Embed(root_id, std::move(client), | 88 ws->Embed(root_id, std::move(client), |
| 90 mojom::WindowTree::ACCESS_POLICY_DEFAULT, | 89 mojom::WindowTree::kAccessPolicyDefault, |
| 91 base::Bind(&EmbedCallbackImpl, &run_loop, &result)); | 90 base::Bind(&EmbedCallbackImpl, &run_loop, &result)); |
| 92 } | 91 } |
| 93 run_loop.Run(); | 92 run_loop.Run(); |
| 94 return result; | 93 return result; |
| 95 } | 94 } |
| 96 | 95 |
| 97 void GetWindowTree(WindowTree* ws, | 96 void GetWindowTree(WindowTree* ws, |
| 98 Id window_id, | 97 Id window_id, |
| 99 std::vector<TestWindow>* windows) { | 98 std::vector<TestWindow>* windows) { |
| 100 base::RunLoop run_loop; | 99 base::RunLoop run_loop; |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 return client_factory_->WaitForInstance(); | 487 return client_factory_->WaitForInstance(); |
| 489 } | 488 } |
| 490 | 489 |
| 491 // Establishes a new connection by way of Embed() on the specified | 490 // Establishes a new connection by way of Embed() on the specified |
| 492 // WindowTree. | 491 // WindowTree. |
| 493 scoped_ptr<TestWindowTreeClientImpl> EstablishConnectionViaEmbed( | 492 scoped_ptr<TestWindowTreeClientImpl> EstablishConnectionViaEmbed( |
| 494 WindowTree* owner, | 493 WindowTree* owner, |
| 495 Id root_id, | 494 Id root_id, |
| 496 int* connection_id) { | 495 int* connection_id) { |
| 497 return EstablishConnectionViaEmbedWithPolicyBitmask( | 496 return EstablishConnectionViaEmbedWithPolicyBitmask( |
| 498 owner, root_id, mojom::WindowTree::ACCESS_POLICY_DEFAULT, | 497 owner, root_id, mojom::WindowTree::kAccessPolicyDefault, connection_id); |
| 499 connection_id); | |
| 500 } | 498 } |
| 501 | 499 |
| 502 scoped_ptr<TestWindowTreeClientImpl> | 500 scoped_ptr<TestWindowTreeClientImpl> |
| 503 EstablishConnectionViaEmbedWithPolicyBitmask(WindowTree* owner, | 501 EstablishConnectionViaEmbedWithPolicyBitmask(WindowTree* owner, |
| 504 Id root_id, | 502 Id root_id, |
| 505 uint32_t policy_bitmask, | 503 uint32_t policy_bitmask, |
| 506 int* connection_id) { | 504 int* connection_id) { |
| 507 if (!EmbedUrl(application_impl(), owner, application_impl()->url(), | 505 if (!EmbedUrl(application_impl(), owner, application_impl()->url(), |
| 508 root_id)) { | 506 root_id)) { |
| 509 ADD_FAILURE() << "Embed() failed"; | 507 ADD_FAILURE() << "Embed() failed"; |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 936 ASSERT_TRUE(ws_client2()->AddWindow(window_2_1, window_2_2)); | 934 ASSERT_TRUE(ws_client2()->AddWindow(window_2_1, window_2_2)); |
| 937 ASSERT_TRUE(ws_client2()->AddWindow(window_2_2, window_2_6)); | 935 ASSERT_TRUE(ws_client2()->AddWindow(window_2_2, window_2_6)); |
| 938 ASSERT_TRUE(ws_client2()->AddWindow(window_2_1, window_2_3)); | 936 ASSERT_TRUE(ws_client2()->AddWindow(window_2_1, window_2_3)); |
| 939 ASSERT_TRUE(ws_client1()->AddWindow(root_window_id(), window_1_4)); | 937 ASSERT_TRUE(ws_client1()->AddWindow(root_window_id(), window_1_4)); |
| 940 ASSERT_TRUE(ws_client1()->AddWindow(root_window_id(), window_1_5)); | 938 ASSERT_TRUE(ws_client1()->AddWindow(root_window_id(), window_1_5)); |
| 941 ASSERT_TRUE(ws_client1()->AddWindow(root_window_id(), window_2_1)); | 939 ASSERT_TRUE(ws_client1()->AddWindow(root_window_id(), window_2_1)); |
| 942 | 940 |
| 943 { | 941 { |
| 944 changes1()->clear(); | 942 changes1()->clear(); |
| 945 ASSERT_TRUE(ws_client2()->ReorderWindow(window_2_2, window_2_3, | 943 ASSERT_TRUE(ws_client2()->ReorderWindow(window_2_2, window_2_3, |
| 946 mojom::ORDER_DIRECTION_ABOVE)); | 944 mojom::OrderDirection::ABOVE)); |
| 947 | 945 |
| 948 ws_client1_->WaitForChangeCount(1); | 946 ws_client1_->WaitForChangeCount(1); |
| 949 EXPECT_EQ("Reordered window=" + IdToString(window_2_2) + " relative=" + | 947 EXPECT_EQ("Reordered window=" + IdToString(window_2_2) + " relative=" + |
| 950 IdToString(window_2_3) + " direction=above", | 948 IdToString(window_2_3) + " direction=above", |
| 951 SingleChangeToDescription(*changes1())); | 949 SingleChangeToDescription(*changes1())); |
| 952 } | 950 } |
| 953 | 951 |
| 954 { | 952 { |
| 955 changes1()->clear(); | 953 changes1()->clear(); |
| 956 ASSERT_TRUE(ws_client2()->ReorderWindow(window_2_2, window_2_3, | 954 ASSERT_TRUE(ws_client2()->ReorderWindow(window_2_2, window_2_3, |
| 957 mojom::ORDER_DIRECTION_BELOW)); | 955 mojom::OrderDirection::BELOW)); |
| 958 | 956 |
| 959 ws_client1_->WaitForChangeCount(1); | 957 ws_client1_->WaitForChangeCount(1); |
| 960 EXPECT_EQ("Reordered window=" + IdToString(window_2_2) + " relative=" + | 958 EXPECT_EQ("Reordered window=" + IdToString(window_2_2) + " relative=" + |
| 961 IdToString(window_2_3) + " direction=below", | 959 IdToString(window_2_3) + " direction=below", |
| 962 SingleChangeToDescription(*changes1())); | 960 SingleChangeToDescription(*changes1())); |
| 963 } | 961 } |
| 964 | 962 |
| 965 // view2 is already below view3. | 963 // view2 is already below view3. |
| 966 EXPECT_FALSE(ws_client2()->ReorderWindow(window_2_2, window_2_3, | 964 EXPECT_FALSE(ws_client2()->ReorderWindow(window_2_2, window_2_3, |
| 967 mojom::ORDER_DIRECTION_BELOW)); | 965 mojom::OrderDirection::BELOW)); |
| 968 | 966 |
| 969 // view4 & 5 are unknown to connection2_. | 967 // view4 & 5 are unknown to connection2_. |
| 970 EXPECT_FALSE(ws_client2()->ReorderWindow(window_1_4, window_1_5, | 968 EXPECT_FALSE(ws_client2()->ReorderWindow(window_1_4, window_1_5, |
| 971 mojom::ORDER_DIRECTION_ABOVE)); | 969 mojom::OrderDirection::ABOVE)); |
| 972 | 970 |
| 973 // view6 & view3 have different parents. | 971 // view6 & view3 have different parents. |
| 974 EXPECT_FALSE(ws_client1()->ReorderWindow(window_2_3, window_2_6, | 972 EXPECT_FALSE(ws_client1()->ReorderWindow(window_2_3, window_2_6, |
| 975 mojom::ORDER_DIRECTION_ABOVE)); | 973 mojom::OrderDirection::ABOVE)); |
| 976 | 974 |
| 977 // Non-existent window-ids | 975 // Non-existent window-ids |
| 978 EXPECT_FALSE(ws_client1()->ReorderWindow(BuildWindowId(connection_id_1(), 27), | 976 EXPECT_FALSE(ws_client1()->ReorderWindow(BuildWindowId(connection_id_1(), 27), |
| 979 BuildWindowId(connection_id_1(), 28), | 977 BuildWindowId(connection_id_1(), 28), |
| 980 mojom::ORDER_DIRECTION_ABOVE)); | 978 mojom::OrderDirection::ABOVE)); |
| 981 | 979 |
| 982 // view7 & view8 are un-parented. | 980 // view7 & view8 are un-parented. |
| 983 EXPECT_FALSE(ws_client1()->ReorderWindow(window_2_7, window_2_8, | 981 EXPECT_FALSE(ws_client1()->ReorderWindow(window_2_7, window_2_8, |
| 984 mojom::ORDER_DIRECTION_ABOVE)); | 982 mojom::OrderDirection::ABOVE)); |
| 985 } | 983 } |
| 986 | 984 |
| 987 // Verifies DeleteWindow works. | 985 // Verifies DeleteWindow works. |
| 988 TEST_F(WindowTreeAppTest, DeleteWindow) { | 986 TEST_F(WindowTreeAppTest, DeleteWindow) { |
| 989 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 987 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 990 Id window_1_1 = BuildWindowId(connection_id_1(), 1); | 988 Id window_1_1 = BuildWindowId(connection_id_1(), 1); |
| 991 Id window_2_2 = ws_client2()->NewWindow(2); | 989 Id window_2_2 = ws_client2()->NewWindow(2); |
| 992 ASSERT_TRUE(window_2_2); | 990 ASSERT_TRUE(window_2_2); |
| 993 | 991 |
| 994 // Make 2 a child of 1. | 992 // Make 2 a child of 1. |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1413 } | 1411 } |
| 1414 } | 1412 } |
| 1415 | 1413 |
| 1416 // Test that we hear the cursor change in other connections. | 1414 // Test that we hear the cursor change in other connections. |
| 1417 TEST_F(WindowTreeAppTest, SetCursor) { | 1415 TEST_F(WindowTreeAppTest, SetCursor) { |
| 1418 // Get a second connection to listen in. | 1416 // Get a second connection to listen in. |
| 1419 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 1417 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 1420 Id window_1_1 = BuildWindowId(connection_id_1(), 1); | 1418 Id window_1_1 = BuildWindowId(connection_id_1(), 1); |
| 1421 changes2()->clear(); | 1419 changes2()->clear(); |
| 1422 | 1420 |
| 1423 ASSERT_TRUE(ws_client1()->SetPredefinedCursor(window_1_1, | 1421 ASSERT_TRUE( |
| 1424 mojom::Cursor::CURSOR_IBEAM)); | 1422 ws_client1()->SetPredefinedCursor(window_1_1, mojom::Cursor::IBEAM)); |
| 1425 ws_client2_->WaitForChangeCount(1u); | 1423 ws_client2_->WaitForChangeCount(1u); |
| 1426 | 1424 |
| 1427 EXPECT_EQ("CursorChanged id=" + IdToString(window_1_1) + " cursor_id=4", | 1425 EXPECT_EQ("CursorChanged id=" + IdToString(window_1_1) + " cursor_id=4", |
| 1428 SingleChangeToDescription(*changes2())); | 1426 SingleChangeToDescription(*changes2())); |
| 1429 } | 1427 } |
| 1430 | 1428 |
| 1431 // Assertions for SetWindowVisibility sending notifications. | 1429 // Assertions for SetWindowVisibility sending notifications. |
| 1432 TEST_F(WindowTreeAppTest, SetWindowVisibilityNotifications) { | 1430 TEST_F(WindowTreeAppTest, SetWindowVisibilityNotifications) { |
| 1433 // Create 1,1 and 1,2. 1,2 is made a child of 1,1 and 1,1 a child of the root. | 1431 // Create 1,1 and 1,2. 1,2 is made a child of 1,1 and 1,1 a child of the root. |
| 1434 Id window_1_1 = ws_client1()->NewWindow(1); | 1432 Id window_1_1 = ws_client1()->NewWindow(1); |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1704 | 1702 |
| 1705 // Need to wait for a WindowTreeClient for same reason as above. | 1703 // Need to wait for a WindowTreeClient for same reason as above. |
| 1706 WaitForWindowTreeClient(); | 1704 WaitForWindowTreeClient(); |
| 1707 | 1705 |
| 1708 Id window_1_2 = ws_client1()->NewWindow(2); | 1706 Id window_1_2 = ws_client1()->NewWindow(2); |
| 1709 ASSERT_TRUE(window_1_2); | 1707 ASSERT_TRUE(window_1_2); |
| 1710 ASSERT_TRUE( | 1708 ASSERT_TRUE( |
| 1711 ws_client1()->AddWindow(BuildWindowId(connection_id_1(), 1), window_1_2)); | 1709 ws_client1()->AddWindow(BuildWindowId(connection_id_1(), 1), window_1_2)); |
| 1712 ASSERT_TRUE(ws_client3_.get() == nullptr); | 1710 ASSERT_TRUE(ws_client3_.get() == nullptr); |
| 1713 ws_client3_ = EstablishConnectionViaEmbedWithPolicyBitmask( | 1711 ws_client3_ = EstablishConnectionViaEmbedWithPolicyBitmask( |
| 1714 ws1(), window_1_2, mojom::WindowTree::ACCESS_POLICY_EMBED_ROOT, nullptr); | 1712 ws1(), window_1_2, mojom::WindowTree::kAccessPolicyEmbedRoot, nullptr); |
| 1715 ASSERT_TRUE(ws_client3_.get() != nullptr); | 1713 ASSERT_TRUE(ws_client3_.get() != nullptr); |
| 1716 ws_client3_->set_root_window(root_window_id()); | 1714 ws_client3_->set_root_window(root_window_id()); |
| 1717 | 1715 |
| 1718 // window_1_2 is ws3's root, so even though v3 is an embed root it should not | 1716 // window_1_2 is ws3's root, so even though v3 is an embed root it should not |
| 1719 // be able to Embed into itself. | 1717 // be able to Embed into itself. |
| 1720 ASSERT_FALSE(EmbedUrl(application_impl(), ws3(), application_impl()->url(), | 1718 ASSERT_FALSE(EmbedUrl(application_impl(), ws3(), application_impl()->url(), |
| 1721 window_1_2)); | 1719 window_1_2)); |
| 1722 } | 1720 } |
| 1723 | 1721 |
| 1724 // Verifies that a transient window tracks its parent's lifetime. | 1722 // Verifies that a transient window tracks its parent's lifetime. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1772 // originating connection. | 1770 // originating connection. |
| 1773 | 1771 |
| 1774 // TODO(sky): make sure coverage of what was | 1772 // TODO(sky): make sure coverage of what was |
| 1775 // WindowManagerTest.SecondEmbedRoot_InitService and | 1773 // WindowManagerTest.SecondEmbedRoot_InitService and |
| 1776 // WindowManagerTest.MultipleEmbedRootsBeforeWTHReady gets added to window | 1774 // WindowManagerTest.MultipleEmbedRootsBeforeWTHReady gets added to window |
| 1777 // manager | 1775 // manager |
| 1778 // tests. | 1776 // tests. |
| 1779 | 1777 |
| 1780 } // namespace ws | 1778 } // namespace ws |
| 1781 } // namespace mus | 1779 } // namespace mus |
| OLD | NEW |