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/cpp/tests/window_server_shelltest_base.h" | 13 #include "components/mus/public/cpp/tests/window_server_shelltest_base.h" |
14 #include "components/mus/public/interfaces/window_tree.mojom.h" | 14 #include "components/mus/public/interfaces/window_tree.mojom.h" |
15 #include "components/mus/public/interfaces/window_tree_host.mojom.h" | 15 #include "components/mus/public/interfaces/window_tree_host.mojom.h" |
16 #include "components/mus/ws/ids.h" | 16 #include "components/mus/ws/ids.h" |
17 #include "components/mus/ws/test_change_tracker.h" | 17 #include "components/mus/ws/test_change_tracker.h" |
18 #include "mojo/public/cpp/bindings/associated_binding.h" | 18 #include "mojo/public/cpp/bindings/associated_binding.h" |
19 #include "services/shell/public/cpp/shell_test.h" | 19 #include "services/shell/public/cpp/shell_test.h" |
20 #include "ui/gfx/geometry/mojo/geometry_type_converters.h" | |
21 | 20 |
22 using mojo::Array; | 21 using mojo::Array; |
23 using mojo::Callback; | 22 using mojo::Callback; |
24 using shell::Connection; | 23 using shell::Connection; |
25 using mojo::InterfaceRequest; | 24 using mojo::InterfaceRequest; |
26 using mojo::RectPtr; | |
27 using shell::ShellClient; | 25 using shell::ShellClient; |
28 using mojo::String; | 26 using mojo::String; |
29 using mus::mojom::ErrorCode; | 27 using mus::mojom::ErrorCode; |
30 using mus::mojom::EventPtr; | 28 using mus::mojom::EventPtr; |
31 using mus::mojom::WindowDataPtr; | 29 using mus::mojom::WindowDataPtr; |
32 using mus::mojom::WindowTree; | 30 using mus::mojom::WindowTree; |
33 using mus::mojom::WindowTreeClient; | 31 using mus::mojom::WindowTreeClient; |
34 | 32 |
35 namespace mus { | 33 namespace mus { |
36 namespace ws { | 34 namespace ws { |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 void OnLostCapture(Id window_id) override { | 293 void OnLostCapture(Id window_id) override { |
296 tracker()->OnLostCapture(window_id); | 294 tracker()->OnLostCapture(window_id); |
297 } | 295 } |
298 void OnTopLevelCreated(uint32_t change_id, | 296 void OnTopLevelCreated(uint32_t change_id, |
299 mojom::WindowDataPtr data, | 297 mojom::WindowDataPtr data, |
300 int64_t display_id, | 298 int64_t display_id, |
301 bool drawn) override { | 299 bool drawn) override { |
302 tracker()->OnTopLevelCreated(change_id, std::move(data), drawn); | 300 tracker()->OnTopLevelCreated(change_id, std::move(data), drawn); |
303 } | 301 } |
304 void OnWindowBoundsChanged(Id window_id, | 302 void OnWindowBoundsChanged(Id window_id, |
305 RectPtr old_bounds, | 303 const gfx::Rect& old_bounds, |
306 RectPtr new_bounds) override { | 304 const gfx::Rect& new_bounds) override { |
307 // The bounds of the root may change during startup on Android at random | 305 // The bounds of the root may change during startup on Android at random |
308 // times. As this doesn't matter, and shouldn't impact test exepctations, | 306 // times. As this doesn't matter, and shouldn't impact test exepctations, |
309 // it is ignored. | 307 // it is ignored. |
310 if (window_id == root_window_id_ && !track_root_bounds_changes_) | 308 if (window_id == root_window_id_ && !track_root_bounds_changes_) |
311 return; | 309 return; |
312 tracker()->OnWindowBoundsChanged(window_id, std::move(old_bounds), | 310 tracker()->OnWindowBoundsChanged(window_id, old_bounds, new_bounds); |
313 std::move(new_bounds)); | |
314 } | 311 } |
315 void OnClientAreaChanged( | 312 void OnClientAreaChanged( |
316 uint32_t window_id, | 313 uint32_t window_id, |
317 mojo::InsetsPtr new_client_area, | 314 const gfx::Insets& new_client_area, |
318 mojo::Array<mojo::RectPtr> new_additional_client_areas) override {} | 315 mojo::Array<gfx::Rect> new_additional_client_areas) override {} |
319 void OnTransientWindowAdded(uint32_t window_id, | 316 void OnTransientWindowAdded(uint32_t window_id, |
320 uint32_t transient_window_id) override { | 317 uint32_t transient_window_id) override { |
321 tracker()->OnTransientWindowAdded(window_id, transient_window_id); | 318 tracker()->OnTransientWindowAdded(window_id, transient_window_id); |
322 } | 319 } |
323 void OnTransientWindowRemoved(uint32_t window_id, | 320 void OnTransientWindowRemoved(uint32_t window_id, |
324 uint32_t transient_window_id) override { | 321 uint32_t transient_window_id) override { |
325 tracker()->OnTransientWindowRemoved(window_id, transient_window_id); | 322 tracker()->OnTransientWindowRemoved(window_id, transient_window_id); |
326 } | 323 } |
327 void OnWindowHierarchyChanged(Id window, | 324 void OnWindowHierarchyChanged(Id window, |
328 Id old_parent, | 325 Id old_parent, |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 window_manager_binding_.reset( | 382 window_manager_binding_.reset( |
386 new mojo::AssociatedBinding<mojom::WindowManager>(this, | 383 new mojo::AssociatedBinding<mojom::WindowManager>(this, |
387 std::move(internal))); | 384 std::move(internal))); |
388 tree_->GetWindowManagerClient( | 385 tree_->GetWindowManagerClient( |
389 GetProxy(&window_manager_client_, tree_.associated_group())); | 386 GetProxy(&window_manager_client_, tree_.associated_group())); |
390 } | 387 } |
391 | 388 |
392 // mojom::WindowManager: | 389 // mojom::WindowManager: |
393 void WmSetBounds(uint32_t change_id, | 390 void WmSetBounds(uint32_t change_id, |
394 uint32_t window_id, | 391 uint32_t window_id, |
395 mojo::RectPtr bounds) override { | 392 const gfx::Rect& bounds) override { |
396 window_manager_client_->WmResponse(change_id, false); | 393 window_manager_client_->WmResponse(change_id, false); |
397 } | 394 } |
398 void WmSetProperty(uint32_t change_id, | 395 void WmSetProperty(uint32_t change_id, |
399 uint32_t window_id, | 396 uint32_t window_id, |
400 const mojo::String& name, | 397 const mojo::String& name, |
401 mojo::Array<uint8_t> value) override { | 398 mojo::Array<uint8_t> value) override { |
402 window_manager_client_->WmResponse(change_id, false); | 399 window_manager_client_->WmResponse(change_id, false); |
403 } | 400 } |
404 void WmCreateTopLevelWindow( | 401 void WmCreateTopLevelWindow( |
405 uint32_t change_id, | 402 uint32_t change_id, |
(...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1201 Id window_1_1 = wt_client1()->NewWindow(1); | 1198 Id window_1_1 = wt_client1()->NewWindow(1); |
1202 ASSERT_TRUE(window_1_1); | 1199 ASSERT_TRUE(window_1_1); |
1203 ASSERT_TRUE(wt_client1()->AddWindow(root_window_id(), window_1_1)); | 1200 ASSERT_TRUE(wt_client1()->AddWindow(root_window_id(), window_1_1)); |
1204 | 1201 |
1205 ASSERT_NO_FATAL_FAILURE(EstablishSecondClient(false)); | 1202 ASSERT_NO_FATAL_FAILURE(EstablishSecondClient(false)); |
1206 | 1203 |
1207 changes2()->clear(); | 1204 changes2()->clear(); |
1208 | 1205 |
1209 wt_client2_->set_track_root_bounds_changes(true); | 1206 wt_client2_->set_track_root_bounds_changes(true); |
1210 | 1207 |
1211 wt1()->SetWindowBounds(10, window_1_1, | 1208 wt1()->SetWindowBounds(10, window_1_1, gfx::Rect(0, 0, 100, 100)); |
1212 mojo::Rect::From(gfx::Rect(0, 0, 100, 100))); | |
1213 ASSERT_TRUE(wt_client1()->WaitForChangeCompleted(10)); | 1209 ASSERT_TRUE(wt_client1()->WaitForChangeCompleted(10)); |
1214 | 1210 |
1215 wt_client2_->WaitForChangeCount(1); | 1211 wt_client2_->WaitForChangeCount(1); |
1216 EXPECT_EQ("BoundsChanged window=" + IdToString(window_1_1) + | 1212 EXPECT_EQ("BoundsChanged window=" + IdToString(window_1_1) + |
1217 " old_bounds=0,0 0x0 new_bounds=0,0 100x100", | 1213 " old_bounds=0,0 0x0 new_bounds=0,0 100x100", |
1218 SingleChangeToDescription(*changes2())); | 1214 SingleChangeToDescription(*changes2())); |
1219 | 1215 |
1220 // Should not be possible to change the bounds of a window created by another | 1216 // Should not be possible to change the bounds of a window created by another |
1221 // client. | 1217 // client. |
1222 wt2()->SetWindowBounds(11, window_1_1, | 1218 wt2()->SetWindowBounds(11, window_1_1, gfx::Rect(0, 0, 0, 0)); |
1223 mojo::Rect::From(gfx::Rect(0, 0, 0, 0))); | |
1224 ASSERT_FALSE(wt_client2()->WaitForChangeCompleted(11)); | 1219 ASSERT_FALSE(wt_client2()->WaitForChangeCompleted(11)); |
1225 } | 1220 } |
1226 | 1221 |
1227 // Verify AddWindow fails when trying to manipulate windows in other roots. | 1222 // Verify AddWindow fails when trying to manipulate windows in other roots. |
1228 TEST_F(WindowTreeClientTest, CantMoveWindowsFromOtherRoot) { | 1223 TEST_F(WindowTreeClientTest, CantMoveWindowsFromOtherRoot) { |
1229 // Create 1 and 2 in the first client. | 1224 // Create 1 and 2 in the first client. |
1230 Id window_1_1 = wt_client1()->NewWindow(1); | 1225 Id window_1_1 = wt_client1()->NewWindow(1); |
1231 Id window_1_2 = wt_client1()->NewWindow(2); | 1226 Id window_1_2 = wt_client1()->NewWindow(2); |
1232 ASSERT_TRUE(window_1_1); | 1227 ASSERT_TRUE(window_1_1); |
1233 ASSERT_TRUE(window_1_2); | 1228 ASSERT_TRUE(window_1_2); |
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1950 const Id window_2_101 = wt_client2()->NewWindow(101); | 1945 const Id window_2_101 = wt_client2()->NewWindow(101); |
1951 ASSERT_TRUE(wt_client2()->AddWindow(window_1_100_in_ws2, window_2_101)); | 1946 ASSERT_TRUE(wt_client2()->AddWindow(window_1_100_in_ws2, window_2_101)); |
1952 const Id window_2_101_in_ws1 = BuildWindowId(client_id_2(), 1); | 1947 const Id window_2_101_in_ws1 = BuildWindowId(client_id_2(), 1); |
1953 wt_client1()->WaitForChangeCount(1); | 1948 wt_client1()->WaitForChangeCount(1); |
1954 EXPECT_EQ("HierarchyChanged window=" + IdToString(window_2_101_in_ws1) + | 1949 EXPECT_EQ("HierarchyChanged window=" + IdToString(window_2_101_in_ws1) + |
1955 " old_parent=null new_parent=" + IdToString(window_1_100), | 1950 " old_parent=null new_parent=" + IdToString(window_1_100), |
1956 SingleChangeToDescription(*changes1())); | 1951 SingleChangeToDescription(*changes1())); |
1957 changes1()->clear(); | 1952 changes1()->clear(); |
1958 | 1953 |
1959 // Change the bounds of window_2_101 and make sure server gets it. | 1954 // Change the bounds of window_2_101 and make sure server gets it. |
1960 wt2()->SetWindowBounds(11, window_2_101, | 1955 wt2()->SetWindowBounds(11, window_2_101, gfx::Rect(1, 2, 3, 4)); |
1961 mojo::Rect::From(gfx::Rect(1, 2, 3, 4))); | |
1962 ASSERT_TRUE(wt_client2()->WaitForChangeCompleted(11)); | 1956 ASSERT_TRUE(wt_client2()->WaitForChangeCompleted(11)); |
1963 wt_client1()->WaitForChangeCount(1); | 1957 wt_client1()->WaitForChangeCount(1); |
1964 EXPECT_EQ("BoundsChanged window=" + IdToString(window_2_101_in_ws1) + | 1958 EXPECT_EQ("BoundsChanged window=" + IdToString(window_2_101_in_ws1) + |
1965 " old_bounds=0,0 0x0 new_bounds=1,2 3x4", | 1959 " old_bounds=0,0 0x0 new_bounds=1,2 3x4", |
1966 SingleChangeToDescription(*changes1())); | 1960 SingleChangeToDescription(*changes1())); |
1967 changes2()->clear(); | 1961 changes2()->clear(); |
1968 | 1962 |
1969 // Remove 2_101 from wm, client1 should see the change. | 1963 // Remove 2_101 from wm, client1 should see the change. |
1970 wt1()->RemoveWindowFromParent(12, window_2_101_in_ws1); | 1964 wt1()->RemoveWindowFromParent(12, window_2_101_in_ws1); |
1971 ASSERT_TRUE(wt_client1()->WaitForChangeCompleted(12)); | 1965 ASSERT_TRUE(wt_client1()->WaitForChangeCompleted(12)); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2033 | 2027 |
2034 // TODO(sky): make sure coverage of what was | 2028 // TODO(sky): make sure coverage of what was |
2035 // WindowManagerTest.SecondEmbedRoot_InitService and | 2029 // WindowManagerTest.SecondEmbedRoot_InitService and |
2036 // WindowManagerTest.MultipleEmbedRootsBeforeWTHReady gets added to window | 2030 // WindowManagerTest.MultipleEmbedRootsBeforeWTHReady gets added to window |
2037 // manager | 2031 // manager |
2038 // tests. | 2032 // tests. |
2039 | 2033 |
2040 } // namespace test | 2034 } // namespace test |
2041 } // namespace ws | 2035 } // namespace ws |
2042 } // namespace mus | 2036 } // namespace mus |
OLD | NEW |