Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(425)

Side by Side Diff: components/mus/public/cpp/tests/window_tree_client_impl_unittest.cc

Issue 2008193002: Change mojo geometry structs from using type converters to StructTraits. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "mojo/converters/geometry/geometry_type_converters.h"
25 #include "mojo/converters/input_events/input_events_type_converters.h" 24 #include "mojo/converters/input_events/input_events_type_converters.h"
26 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
27 #include "ui/events/event.h" 26 #include "ui/events/event.h"
28 #include "ui/events/event_utils.h" 27 #include "ui/events/event_utils.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
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
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->viewport_metrics = mojom::ViewportMetrics::New(); 767 data->viewport_metrics = mojom::ViewportMetrics::New();
771 data->viewport_metrics->size_in_pixels = mojo::Size::From(gfx::Size(1, 2)); 768 data->viewport_metrics->size_in_pixels = gfx::Size(1, 2);
772 data->bounds = mojo::Rect::From(gfx::Rect(1, 2, 3, 4)); 769 data->bounds = gfx::Rect(1, 2, 3, 4);
773 data->visible = true; 770 data->visible = true;
774 setup.window_tree_client()->OnTopLevelCreated(change_id, std::move(data), 771 setup.window_tree_client()->OnTopLevelCreated(change_id, std::move(data),
775 true); 772 true);
776 773
777 // Make sure all the properties took. 774 // Make sure all the properties took.
778 EXPECT_TRUE(root2->IsDrawn()); 775 EXPECT_TRUE(root2->IsDrawn());
779 EXPECT_TRUE(root2->visible()); 776 EXPECT_TRUE(root2->visible());
780 EXPECT_EQ(gfx::Size(1, 2), 777 EXPECT_EQ(gfx::Size(1, 2), root2->viewport_metrics().size_in_pixels);
781 root2->viewport_metrics().size_in_pixels.To<gfx::Size>());
782 EXPECT_EQ(gfx::Rect(1, 2, 3, 4), root2->bounds()); 778 EXPECT_EQ(gfx::Rect(1, 2, 3, 4), root2->bounds());
783 } 779 }
784 780
785 TEST_F(WindowTreeClientImplTest, NewTopLevelWindowGetsAllChangesInFlight) { 781 TEST_F(WindowTreeClientImplTest, NewTopLevelWindowGetsAllChangesInFlight) {
786 WindowTreeSetup setup; 782 WindowTreeSetup setup;
787 Window* root1 = setup.GetFirstRoot(); 783 Window* root1 = setup.GetFirstRoot();
788 ASSERT_TRUE(root1); 784 ASSERT_TRUE(root1);
789 Window* root2 = setup.window_tree_connection()->NewTopLevelWindow(nullptr); 785 Window* root2 = setup.window_tree_connection()->NewTopLevelWindow(nullptr);
790 ASSERT_TRUE(root2); 786 ASSERT_TRUE(root2);
791 787
(...skipping 28 matching lines...) Expand all
820 root2->SetSharedProperty<std::string>("xx", "client_xx"); 816 root2->SetSharedProperty<std::string>("xx", "client_xx");
821 uint32_t property_in_flight_change_id; 817 uint32_t property_in_flight_change_id;
822 ASSERT_TRUE( 818 ASSERT_TRUE(
823 setup.window_tree()->GetAndClearChangeId(&property_in_flight_change_id)); 819 setup.window_tree()->GetAndClearChangeId(&property_in_flight_change_id));
824 EXPECT_NE(bounds_in_flight_change_id, property_in_flight_change_id); 820 EXPECT_NE(bounds_in_flight_change_id, property_in_flight_change_id);
825 821
826 // Ack the new window top level window. Vis and bounds shouldn't change. 822 // Ack the new window top level window. Vis and bounds shouldn't change.
827 mojom::WindowDataPtr data = mojom::WindowData::New(); 823 mojom::WindowDataPtr data = mojom::WindowData::New();
828 data->window_id = server_id(root2); 824 data->window_id = server_id(root2);
829 data->viewport_metrics = mojom::ViewportMetrics::New(); 825 data->viewport_metrics = mojom::ViewportMetrics::New();
830 data->viewport_metrics->size_in_pixels = mojo::Size::From(gfx::Size(1, 2)); 826 data->viewport_metrics->size_in_pixels = gfx::Size(1, 2);
831 data->bounds = mojo::Rect::From(gfx::Rect(1, 2, 3, 4)); 827 data->bounds = gfx::Rect(1, 2, 3, 4);
832 data->visible = true; 828 data->visible = true;
833 data->properties["xx"] = mojo::Array<uint8_t>::From(std::string("server_xx")); 829 data->properties["xx"] = mojo::Array<uint8_t>::From(std::string("server_xx"));
834 data->properties["yy"] = mojo::Array<uint8_t>::From(std::string("server_yy")); 830 data->properties["yy"] = mojo::Array<uint8_t>::From(std::string("server_yy"));
835 setup.window_tree_client()->OnTopLevelCreated(new_window_in_flight_change_id, 831 setup.window_tree_client()->OnTopLevelCreated(new_window_in_flight_change_id,
836 std::move(data), true); 832 std::move(data), true);
837 833
838 // The only value that should take effect is the property for 'yy' as it was 834 // The only value that should take effect is the property for 'yy' as it was
839 // not in flight. 835 // not in flight.
840 EXPECT_TRUE(WindowPrivate(root2).parent_drawn()); 836 EXPECT_TRUE(WindowPrivate(root2).parent_drawn());
841 EXPECT_FALSE(root2->visible()); 837 EXPECT_FALSE(root2->visible());
842 EXPECT_EQ(gfx::Size(1, 2), 838 EXPECT_EQ(gfx::Size(1, 2), root2->viewport_metrics().size_in_pixels);
843 root2->viewport_metrics().size_in_pixels.To<gfx::Size>());
844 EXPECT_EQ(gfx::Rect(5, 6, 7, 8), root2->bounds()); 839 EXPECT_EQ(gfx::Rect(5, 6, 7, 8), root2->bounds());
845 EXPECT_EQ(2u, root2->shared_properties().size()); 840 EXPECT_EQ(2u, root2->shared_properties().size());
846 ASSERT_TRUE(root2->HasSharedProperty("yy")); 841 ASSERT_TRUE(root2->HasSharedProperty("yy"));
847 EXPECT_EQ("server_yy", root2->GetSharedProperty<std::string>("yy")); 842 EXPECT_EQ("server_yy", root2->GetSharedProperty<std::string>("yy"));
848 ASSERT_TRUE(root2->HasSharedProperty("xx")); 843 ASSERT_TRUE(root2->HasSharedProperty("xx"));
849 EXPECT_EQ("client_xx", root2->GetSharedProperty<std::string>("xx")); 844 EXPECT_EQ("client_xx", root2->GetSharedProperty<std::string>("xx"));
850 845
851 // Tell the client the changes failed. This should cause the values to change 846 // Tell the client the changes failed. This should cause the values to change
852 // to that of the server. 847 // to that of the server.
853 setup.window_tree_client()->OnChangeCompleted(vis_in_flight_change_id1, 848 setup.window_tree_client()->OnChangeCompleted(vis_in_flight_change_id1,
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 1017
1023 setup.window_tree_client()->OnChangeCompleted(change_id2, false); 1018 setup.window_tree_client()->OnChangeCompleted(change_id2, false);
1024 EXPECT_FALSE(child->HasCapture()); 1019 EXPECT_FALSE(child->HasCapture());
1025 EXPECT_TRUE(root->HasCapture()); 1020 EXPECT_TRUE(root->HasCapture());
1026 1021
1027 setup.window_tree_client()->OnLostCapture(server_id(root)); 1022 setup.window_tree_client()->OnLostCapture(server_id(root));
1028 EXPECT_FALSE(root->HasCapture()); 1023 EXPECT_FALSE(root->HasCapture());
1029 } 1024 }
1030 1025
1031 } // namespace mus 1026 } // namespace mus
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698