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/tests/window_tree_client_impl_private.h" | 17 #include "components/mus/public/cpp/tests/window_tree_client_impl_private.h" |
18 #include "components/mus/public/cpp/window.h" | 18 #include "components/mus/public/cpp/window.h" |
19 #include "components/mus/public/cpp/window_observer.h" | 19 #include "components/mus/public/cpp/window_observer.h" |
20 #include "components/mus/public/cpp/window_property.h" | 20 #include "components/mus/public/cpp/window_property.h" |
21 #include "components/mus/public/cpp/window_tracker.h" | 21 #include "components/mus/public/cpp/window_tracker.h" |
22 #include "components/mus/public/cpp/window_tree_delegate.h" | 22 #include "components/mus/public/cpp/window_tree_delegate.h" |
23 #include "mojo/common/common_type_converters.h" | 23 #include "mojo/common/common_type_converters.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
25 #include "ui/events/event.h" | 25 #include "ui/events/event.h" |
26 #include "ui/events/event_utils.h" | 26 #include "ui/events/event_utils.h" |
27 #include "ui/events/mojo/input_events_type_converters.h" | 27 #include "ui/events/mojo/input_events_type_converters.h" |
28 #include "ui/gfx/geometry/mojo/geometry_type_converters.h" | |
29 #include "ui/gfx/geometry/rect.h" | 28 #include "ui/gfx/geometry/rect.h" |
30 | 29 |
31 namespace mus { | 30 namespace mus { |
32 | 31 |
33 namespace { | 32 namespace { |
34 | 33 |
35 void DoNothingWithEventResult(mojom::EventResult result) {} | 34 void DoNothingWithEventResult(mojom::EventResult result) {} |
36 | 35 |
37 Id server_id(mus::Window* window) { | 36 Id server_id(mus::Window* window) { |
38 return WindowPrivate(window).server_id(); | 37 return WindowPrivate(window).server_id(); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 const gfx::Rect new_bounds(gfx::Rect(0, 0, 100, 100)); | 180 const gfx::Rect new_bounds(gfx::Rect(0, 0, 100, 100)); |
182 ASSERT_NE(new_bounds, root->bounds()); | 181 ASSERT_NE(new_bounds, root->bounds()); |
183 root->SetBounds(new_bounds); | 182 root->SetBounds(new_bounds); |
184 EXPECT_EQ(new_bounds, root->bounds()); | 183 EXPECT_EQ(new_bounds, root->bounds()); |
185 uint32_t change_id; | 184 uint32_t change_id; |
186 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); | 185 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); |
187 | 186 |
188 // Simulate the server responding with a bounds change. | 187 // Simulate the server responding with a bounds change. |
189 const gfx::Rect server_changed_bounds(gfx::Rect(0, 0, 101, 102)); | 188 const gfx::Rect server_changed_bounds(gfx::Rect(0, 0, 101, 102)); |
190 setup.window_tree_client()->OnWindowBoundsChanged( | 189 setup.window_tree_client()->OnWindowBoundsChanged( |
191 server_id(root), mojo::Rect::From(original_bounds), | 190 server_id(root), original_bounds, server_changed_bounds); |
192 mojo::Rect::From(server_changed_bounds)); | |
193 | 191 |
194 // This shouldn't trigger the bounds changing yet. | 192 // This shouldn't trigger the bounds changing yet. |
195 EXPECT_EQ(new_bounds, root->bounds()); | 193 EXPECT_EQ(new_bounds, root->bounds()); |
196 | 194 |
197 // Tell the client the change failed, which should trigger failing to the | 195 // Tell the client the change failed, which should trigger failing to the |
198 // most recent bounds from server. | 196 // most recent bounds from server. |
199 setup.window_tree_client()->OnChangeCompleted(change_id, false); | 197 setup.window_tree_client()->OnChangeCompleted(change_id, false); |
200 EXPECT_EQ(server_changed_bounds, root->bounds()); | 198 EXPECT_EQ(server_changed_bounds, root->bounds()); |
201 | 199 |
202 // Simulate server changing back to original bounds. Should take immediately. | 200 // Simulate server changing back to original bounds. Should take immediately. |
203 setup.window_tree_client()->OnWindowBoundsChanged( | 201 setup.window_tree_client()->OnWindowBoundsChanged( |
204 server_id(root), mojo::Rect::From(server_changed_bounds), | 202 server_id(root), server_changed_bounds, original_bounds); |
205 mojo::Rect::From(original_bounds)); | |
206 EXPECT_EQ(original_bounds, root->bounds()); | 203 EXPECT_EQ(original_bounds, root->bounds()); |
207 } | 204 } |
208 | 205 |
209 TEST_F(WindowTreeClientImplTest, TwoInFlightBoundsChangesBothCanceled) { | 206 TEST_F(WindowTreeClientImplTest, TwoInFlightBoundsChangesBothCanceled) { |
210 WindowTreeSetup setup; | 207 WindowTreeSetup setup; |
211 Window* root = setup.GetFirstRoot(); | 208 Window* root = setup.GetFirstRoot(); |
212 ASSERT_TRUE(root); | 209 ASSERT_TRUE(root); |
213 const gfx::Rect original_bounds(root->bounds()); | 210 const gfx::Rect original_bounds(root->bounds()); |
214 const gfx::Rect bounds1(gfx::Rect(0, 0, 100, 100)); | 211 const gfx::Rect bounds1(gfx::Rect(0, 0, 100, 100)); |
215 const gfx::Rect bounds2(gfx::Rect(0, 0, 100, 102)); | 212 const gfx::Rect bounds2(gfx::Rect(0, 0, 100, 102)); |
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
760 EXPECT_FALSE(root2->IsDrawn()); | 757 EXPECT_FALSE(root2->IsDrawn()); |
761 EXPECT_FALSE(root2->visible()); | 758 EXPECT_FALSE(root2->visible()); |
762 | 759 |
763 // Ack the request to the windowtree to create the new window. | 760 // Ack the request to the windowtree to create the new window. |
764 uint32_t change_id; | 761 uint32_t change_id; |
765 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); | 762 ASSERT_TRUE(setup.window_tree()->GetAndClearChangeId(&change_id)); |
766 EXPECT_EQ(setup.window_tree()->window_id(), server_id(root2)); | 763 EXPECT_EQ(setup.window_tree()->window_id(), server_id(root2)); |
767 | 764 |
768 mojom::WindowDataPtr data = mojom::WindowData::New(); | 765 mojom::WindowDataPtr data = mojom::WindowData::New(); |
769 data->window_id = server_id(root2); | 766 data->window_id = server_id(root2); |
770 data->bounds = mojo::Rect::From(gfx::Rect(1, 2, 3, 4)); | 767 data->bounds.SetRect(1, 2, 3, 4); |
771 data->visible = true; | 768 data->visible = true; |
772 const int64_t display_id = 1; | 769 const int64_t display_id = 1; |
773 setup.window_tree_client()->OnTopLevelCreated(change_id, std::move(data), | 770 setup.window_tree_client()->OnTopLevelCreated(change_id, std::move(data), |
774 display_id, true); | 771 display_id, true); |
775 | 772 |
776 // Make sure all the properties took. | 773 // Make sure all the properties took. |
777 EXPECT_TRUE(root2->IsDrawn()); | 774 EXPECT_TRUE(root2->IsDrawn()); |
778 EXPECT_TRUE(root2->visible()); | 775 EXPECT_TRUE(root2->visible()); |
779 EXPECT_EQ(1, root2->display_id()); | 776 EXPECT_EQ(1, root2->display_id()); |
780 EXPECT_EQ(gfx::Rect(1, 2, 3, 4), root2->bounds()); | 777 EXPECT_EQ(gfx::Rect(1, 2, 3, 4), root2->bounds()); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
817 | 814 |
818 root2->SetSharedProperty<std::string>("xx", "client_xx"); | 815 root2->SetSharedProperty<std::string>("xx", "client_xx"); |
819 uint32_t property_in_flight_change_id; | 816 uint32_t property_in_flight_change_id; |
820 ASSERT_TRUE( | 817 ASSERT_TRUE( |
821 setup.window_tree()->GetAndClearChangeId(&property_in_flight_change_id)); | 818 setup.window_tree()->GetAndClearChangeId(&property_in_flight_change_id)); |
822 EXPECT_NE(bounds_in_flight_change_id, property_in_flight_change_id); | 819 EXPECT_NE(bounds_in_flight_change_id, property_in_flight_change_id); |
823 | 820 |
824 // Ack the new window top level window. Vis and bounds shouldn't change. | 821 // Ack the new window top level window. Vis and bounds shouldn't change. |
825 mojom::WindowDataPtr data = mojom::WindowData::New(); | 822 mojom::WindowDataPtr data = mojom::WindowData::New(); |
826 data->window_id = server_id(root2); | 823 data->window_id = server_id(root2); |
827 data->bounds = mojo::Rect::From(gfx::Rect(1, 2, 3, 4)); | 824 data->bounds.SetRect(1, 2, 3, 4); |
828 data->visible = true; | 825 data->visible = true; |
829 data->properties["xx"] = mojo::Array<uint8_t>::From(std::string("server_xx")); | 826 data->properties["xx"] = mojo::Array<uint8_t>::From(std::string("server_xx")); |
830 data->properties["yy"] = mojo::Array<uint8_t>::From(std::string("server_yy")); | 827 data->properties["yy"] = mojo::Array<uint8_t>::From(std::string("server_yy")); |
831 const int64_t display_id = 1; | 828 const int64_t display_id = 1; |
832 setup.window_tree_client()->OnTopLevelCreated( | 829 setup.window_tree_client()->OnTopLevelCreated( |
833 new_window_in_flight_change_id, std::move(data), display_id, true); | 830 new_window_in_flight_change_id, std::move(data), display_id, true); |
834 | 831 |
835 // The only value that should take effect is the property for 'yy' as it was | 832 // The only value that should take effect is the property for 'yy' as it was |
836 // not in flight. | 833 // not in flight. |
837 EXPECT_TRUE(WindowPrivate(root2).parent_drawn()); | 834 EXPECT_TRUE(WindowPrivate(root2).parent_drawn()); |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1048 | 1045 |
1049 // Create a new Window, and attempt to place capture on that. | 1046 // Create a new Window, and attempt to place capture on that. |
1050 Window* child = setup.window_tree_connection()->NewWindow(); | 1047 Window* child = setup.window_tree_connection()->NewWindow(); |
1051 child->SetVisible(true); | 1048 child->SetVisible(true); |
1052 root->AddChild(child); | 1049 root->AddChild(child); |
1053 child->SetCapture(); | 1050 child->SetCapture(); |
1054 EXPECT_TRUE(child->HasCapture()); | 1051 EXPECT_TRUE(child->HasCapture()); |
1055 } | 1052 } |
1056 | 1053 |
1057 } // namespace mus | 1054 } // namespace mus |
OLD | NEW |