| 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/application/public/cpp/application_delegate.h" | 17 #include "mojo/application/public/cpp/application_delegate.h" |
| 18 #include "mojo/application/public/cpp/application_impl.h" | 18 #include "mojo/application/public/cpp/application_impl.h" |
| 19 #include "mojo/application/public/cpp/application_test_base.h" | 19 #include "mojo/application/public/cpp/application_test_base.h" |
| 20 #include "mojo/converters/geometry/geometry_type_converters.h" | 20 #include "mojo/converters/geometry/geometry_type_converters.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 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 return client_factory_->WaitForInstance(); | 485 return client_factory_->WaitForInstance(); |
| 487 } | 486 } |
| 488 | 487 |
| 489 // Establishes a new connection by way of Embed() on the specified | 488 // Establishes a new connection by way of Embed() on the specified |
| 490 // WindowTree. | 489 // WindowTree. |
| 491 scoped_ptr<TestWindowTreeClientImpl> EstablishConnectionViaEmbed( | 490 scoped_ptr<TestWindowTreeClientImpl> EstablishConnectionViaEmbed( |
| 492 WindowTree* owner, | 491 WindowTree* owner, |
| 493 Id root_id, | 492 Id root_id, |
| 494 int* connection_id) { | 493 int* connection_id) { |
| 495 return EstablishConnectionViaEmbedWithPolicyBitmask( | 494 return EstablishConnectionViaEmbedWithPolicyBitmask( |
| 496 owner, root_id, mojom::WindowTree::ACCESS_POLICY_DEFAULT, | 495 owner, root_id, mojom::WindowTree::kAccessPolicyDefault, connection_id); |
| 497 connection_id); | |
| 498 } | 496 } |
| 499 | 497 |
| 500 scoped_ptr<TestWindowTreeClientImpl> | 498 scoped_ptr<TestWindowTreeClientImpl> |
| 501 EstablishConnectionViaEmbedWithPolicyBitmask(WindowTree* owner, | 499 EstablishConnectionViaEmbedWithPolicyBitmask(WindowTree* owner, |
| 502 Id root_id, | 500 Id root_id, |
| 503 uint32_t policy_bitmask, | 501 uint32_t policy_bitmask, |
| 504 int* connection_id) { | 502 int* connection_id) { |
| 505 if (!EmbedUrl(application_impl(), owner, application_impl()->url(), | 503 if (!EmbedUrl(application_impl(), owner, application_impl()->url(), |
| 506 root_id)) { | 504 root_id)) { |
| 507 ADD_FAILURE() << "Embed() failed"; | 505 ADD_FAILURE() << "Embed() failed"; |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 934 ASSERT_TRUE(ws_client2()->AddWindow(window_2_1, window_2_2)); | 932 ASSERT_TRUE(ws_client2()->AddWindow(window_2_1, window_2_2)); |
| 935 ASSERT_TRUE(ws_client2()->AddWindow(window_2_2, window_2_6)); | 933 ASSERT_TRUE(ws_client2()->AddWindow(window_2_2, window_2_6)); |
| 936 ASSERT_TRUE(ws_client2()->AddWindow(window_2_1, window_2_3)); | 934 ASSERT_TRUE(ws_client2()->AddWindow(window_2_1, window_2_3)); |
| 937 ASSERT_TRUE(ws_client1()->AddWindow(root_window_id(), window_1_4)); | 935 ASSERT_TRUE(ws_client1()->AddWindow(root_window_id(), window_1_4)); |
| 938 ASSERT_TRUE(ws_client1()->AddWindow(root_window_id(), window_1_5)); | 936 ASSERT_TRUE(ws_client1()->AddWindow(root_window_id(), window_1_5)); |
| 939 ASSERT_TRUE(ws_client1()->AddWindow(root_window_id(), window_2_1)); | 937 ASSERT_TRUE(ws_client1()->AddWindow(root_window_id(), window_2_1)); |
| 940 | 938 |
| 941 { | 939 { |
| 942 changes1()->clear(); | 940 changes1()->clear(); |
| 943 ASSERT_TRUE(ws_client2()->ReorderWindow(window_2_2, window_2_3, | 941 ASSERT_TRUE(ws_client2()->ReorderWindow(window_2_2, window_2_3, |
| 944 mojom::ORDER_DIRECTION_ABOVE)); | 942 mojom::OrderDirection::ABOVE)); |
| 945 | 943 |
| 946 ws_client1_->WaitForChangeCount(1); | 944 ws_client1_->WaitForChangeCount(1); |
| 947 EXPECT_EQ("Reordered window=" + IdToString(window_2_2) + " relative=" + | 945 EXPECT_EQ("Reordered window=" + IdToString(window_2_2) + " relative=" + |
| 948 IdToString(window_2_3) + " direction=above", | 946 IdToString(window_2_3) + " direction=above", |
| 949 SingleChangeToDescription(*changes1())); | 947 SingleChangeToDescription(*changes1())); |
| 950 } | 948 } |
| 951 | 949 |
| 952 { | 950 { |
| 953 changes1()->clear(); | 951 changes1()->clear(); |
| 954 ASSERT_TRUE(ws_client2()->ReorderWindow(window_2_2, window_2_3, | 952 ASSERT_TRUE(ws_client2()->ReorderWindow(window_2_2, window_2_3, |
| 955 mojom::ORDER_DIRECTION_BELOW)); | 953 mojom::OrderDirection::BELOW)); |
| 956 | 954 |
| 957 ws_client1_->WaitForChangeCount(1); | 955 ws_client1_->WaitForChangeCount(1); |
| 958 EXPECT_EQ("Reordered window=" + IdToString(window_2_2) + " relative=" + | 956 EXPECT_EQ("Reordered window=" + IdToString(window_2_2) + " relative=" + |
| 959 IdToString(window_2_3) + " direction=below", | 957 IdToString(window_2_3) + " direction=below", |
| 960 SingleChangeToDescription(*changes1())); | 958 SingleChangeToDescription(*changes1())); |
| 961 } | 959 } |
| 962 | 960 |
| 963 // view2 is already below view3. | 961 // view2 is already below view3. |
| 964 EXPECT_FALSE(ws_client2()->ReorderWindow(window_2_2, window_2_3, | 962 EXPECT_FALSE(ws_client2()->ReorderWindow(window_2_2, window_2_3, |
| 965 mojom::ORDER_DIRECTION_BELOW)); | 963 mojom::OrderDirection::BELOW)); |
| 966 | 964 |
| 967 // view4 & 5 are unknown to connection2_. | 965 // view4 & 5 are unknown to connection2_. |
| 968 EXPECT_FALSE(ws_client2()->ReorderWindow(window_1_4, window_1_5, | 966 EXPECT_FALSE(ws_client2()->ReorderWindow(window_1_4, window_1_5, |
| 969 mojom::ORDER_DIRECTION_ABOVE)); | 967 mojom::OrderDirection::ABOVE)); |
| 970 | 968 |
| 971 // view6 & view3 have different parents. | 969 // view6 & view3 have different parents. |
| 972 EXPECT_FALSE(ws_client1()->ReorderWindow(window_2_3, window_2_6, | 970 EXPECT_FALSE(ws_client1()->ReorderWindow(window_2_3, window_2_6, |
| 973 mojom::ORDER_DIRECTION_ABOVE)); | 971 mojom::OrderDirection::ABOVE)); |
| 974 | 972 |
| 975 // Non-existent window-ids | 973 // Non-existent window-ids |
| 976 EXPECT_FALSE(ws_client1()->ReorderWindow(BuildWindowId(connection_id_1(), 27), | 974 EXPECT_FALSE(ws_client1()->ReorderWindow(BuildWindowId(connection_id_1(), 27), |
| 977 BuildWindowId(connection_id_1(), 28), | 975 BuildWindowId(connection_id_1(), 28), |
| 978 mojom::ORDER_DIRECTION_ABOVE)); | 976 mojom::OrderDirection::ABOVE)); |
| 979 | 977 |
| 980 // view7 & view8 are un-parented. | 978 // view7 & view8 are un-parented. |
| 981 EXPECT_FALSE(ws_client1()->ReorderWindow(window_2_7, window_2_8, | 979 EXPECT_FALSE(ws_client1()->ReorderWindow(window_2_7, window_2_8, |
| 982 mojom::ORDER_DIRECTION_ABOVE)); | 980 mojom::OrderDirection::ABOVE)); |
| 983 } | 981 } |
| 984 | 982 |
| 985 // Verifies DeleteWindow works. | 983 // Verifies DeleteWindow works. |
| 986 TEST_F(WindowTreeAppTest, DeleteWindow) { | 984 TEST_F(WindowTreeAppTest, DeleteWindow) { |
| 987 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 985 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 988 Id window_1_1 = BuildWindowId(connection_id_1(), 1); | 986 Id window_1_1 = BuildWindowId(connection_id_1(), 1); |
| 989 Id window_2_2 = ws_client2()->NewWindow(2); | 987 Id window_2_2 = ws_client2()->NewWindow(2); |
| 990 ASSERT_TRUE(window_2_2); | 988 ASSERT_TRUE(window_2_2); |
| 991 | 989 |
| 992 // Make 2 a child of 1. | 990 // Make 2 a child of 1. |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1409 } | 1407 } |
| 1410 } | 1408 } |
| 1411 | 1409 |
| 1412 // Test that we hear the cursor change in other connections. | 1410 // Test that we hear the cursor change in other connections. |
| 1413 TEST_F(WindowTreeAppTest, SetCursor) { | 1411 TEST_F(WindowTreeAppTest, SetCursor) { |
| 1414 // Get a second connection to listen in. | 1412 // Get a second connection to listen in. |
| 1415 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); | 1413 ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true)); |
| 1416 Id window_1_1 = BuildWindowId(connection_id_1(), 1); | 1414 Id window_1_1 = BuildWindowId(connection_id_1(), 1); |
| 1417 changes2()->clear(); | 1415 changes2()->clear(); |
| 1418 | 1416 |
| 1419 ASSERT_TRUE(ws_client1()->SetPredefinedCursor(window_1_1, | 1417 ASSERT_TRUE( |
| 1420 mojom::Cursor::CURSOR_IBEAM)); | 1418 ws_client1()->SetPredefinedCursor(window_1_1, mojom::Cursor::IBEAM)); |
| 1421 ws_client2_->WaitForChangeCount(1u); | 1419 ws_client2_->WaitForChangeCount(1u); |
| 1422 | 1420 |
| 1423 EXPECT_EQ("CursorChanged id=" + IdToString(window_1_1) + " cursor_id=4", | 1421 EXPECT_EQ("CursorChanged id=" + IdToString(window_1_1) + " cursor_id=4", |
| 1424 SingleChangeToDescription(*changes2())); | 1422 SingleChangeToDescription(*changes2())); |
| 1425 } | 1423 } |
| 1426 | 1424 |
| 1427 // Assertions for SetWindowVisibility sending notifications. | 1425 // Assertions for SetWindowVisibility sending notifications. |
| 1428 TEST_F(WindowTreeAppTest, SetWindowVisibilityNotifications) { | 1426 TEST_F(WindowTreeAppTest, SetWindowVisibilityNotifications) { |
| 1429 // Create 1,1 and 1,2. 1,2 is made a child of 1,1 and 1,1 a child of the root. | 1427 // Create 1,1 and 1,2. 1,2 is made a child of 1,1 and 1,1 a child of the root. |
| 1430 Id window_1_1 = ws_client1()->NewWindow(1); | 1428 Id window_1_1 = ws_client1()->NewWindow(1); |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1700 | 1698 |
| 1701 // Need to wait for a WindowTreeClient for same reason as above. | 1699 // Need to wait for a WindowTreeClient for same reason as above. |
| 1702 WaitForWindowTreeClient(); | 1700 WaitForWindowTreeClient(); |
| 1703 | 1701 |
| 1704 Id window_1_2 = ws_client1()->NewWindow(2); | 1702 Id window_1_2 = ws_client1()->NewWindow(2); |
| 1705 ASSERT_TRUE(window_1_2); | 1703 ASSERT_TRUE(window_1_2); |
| 1706 ASSERT_TRUE( | 1704 ASSERT_TRUE( |
| 1707 ws_client1()->AddWindow(BuildWindowId(connection_id_1(), 1), window_1_2)); | 1705 ws_client1()->AddWindow(BuildWindowId(connection_id_1(), 1), window_1_2)); |
| 1708 ASSERT_TRUE(ws_client3_.get() == nullptr); | 1706 ASSERT_TRUE(ws_client3_.get() == nullptr); |
| 1709 ws_client3_ = EstablishConnectionViaEmbedWithPolicyBitmask( | 1707 ws_client3_ = EstablishConnectionViaEmbedWithPolicyBitmask( |
| 1710 ws1(), window_1_2, mojom::WindowTree::ACCESS_POLICY_EMBED_ROOT, nullptr); | 1708 ws1(), window_1_2, mojom::WindowTree::kAccessPolicyEmbedRoot, nullptr); |
| 1711 ASSERT_TRUE(ws_client3_.get() != nullptr); | 1709 ASSERT_TRUE(ws_client3_.get() != nullptr); |
| 1712 ws_client3_->set_root_window(root_window_id()); | 1710 ws_client3_->set_root_window(root_window_id()); |
| 1713 | 1711 |
| 1714 // window_1_2 is ws3's root, so even though v3 is an embed root it should not | 1712 // window_1_2 is ws3's root, so even though v3 is an embed root it should not |
| 1715 // be able to Embed into itself. | 1713 // be able to Embed into itself. |
| 1716 ASSERT_FALSE(EmbedUrl(application_impl(), ws3(), application_impl()->url(), | 1714 ASSERT_FALSE(EmbedUrl(application_impl(), ws3(), application_impl()->url(), |
| 1717 window_1_2)); | 1715 window_1_2)); |
| 1718 } | 1716 } |
| 1719 | 1717 |
| 1720 // Verifies that a transient window tracks its parent's lifetime. | 1718 // Verifies that a transient window tracks its parent's lifetime. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1768 // originating connection. | 1766 // originating connection. |
| 1769 | 1767 |
| 1770 // TODO(sky): make sure coverage of what was | 1768 // TODO(sky): make sure coverage of what was |
| 1771 // WindowManagerTest.SecondEmbedRoot_InitService and | 1769 // WindowManagerTest.SecondEmbedRoot_InitService and |
| 1772 // WindowManagerTest.MultipleEmbedRootsBeforeWTHReady gets added to window | 1770 // WindowManagerTest.MultipleEmbedRootsBeforeWTHReady gets added to window |
| 1773 // manager | 1771 // manager |
| 1774 // tests. | 1772 // tests. |
| 1775 | 1773 |
| 1776 } // namespace ws | 1774 } // namespace ws |
| 1777 } // namespace mus | 1775 } // namespace mus |
| OLD | NEW |