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

Side by Side Diff: ui/aura/mus/window_tree_client_unittest.cc

Issue 2517853002: Fixes bug in handling restacking because of transients (Closed)
Patch Set: feedback Created 4 years 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 "ui/aura/mus/window_tree_client.h" 5 #include "ui/aura/mus/window_tree_client.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"
(...skipping 888 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 server_id(&transient)); 899 server_id(&transient));
900 EXPECT_EQ(&parent, transient_client->GetTransientParent(&transient)); 900 EXPECT_EQ(&parent, transient_client->GetTransientParent(&transient));
901 901
902 // Remove locally. 902 // Remove locally.
903 transient_client->RemoveTransientChild(&parent, &transient); 903 transient_client->RemoveTransientChild(&parent, &transient);
904 ASSERT_EQ(1u, window_tree()->GetChangeCountForType( 904 ASSERT_EQ(1u, window_tree()->GetChangeCountForType(
905 WindowTreeChangeType::REMOVE_TRANSIENT)); 905 WindowTreeChangeType::REMOVE_TRANSIENT));
906 EXPECT_EQ(server_id(&transient), window_tree()->transient_data().child_id); 906 EXPECT_EQ(server_id(&transient), window_tree()->transient_data().child_id);
907 } 907 }
908 908
909 // Verifies adding/removing a transient child doesn't notify the server of the
910 // restack when the change originates from the server.
911 TEST_F(WindowTreeClientClientTest,
912 TransientChildServerMutateDoesntNotifyOfRestack) {
913 Window* w1 = new Window(nullptr);
914 w1->Init(ui::LAYER_NOT_DRAWN);
915 root_window()->AddChild(w1);
916 Window* w2 = new Window(nullptr);
917 w2->Init(ui::LAYER_NOT_DRAWN);
918 root_window()->AddChild(w2);
919 Window* w3 = new Window(nullptr);
920 w3->Init(ui::LAYER_NOT_DRAWN);
921 root_window()->AddChild(w3);
922 // Three children of root: |w1|, |w2| and |w3| (in that order). Make |w1| a
923 // transient child of |w2|. Should trigger moving |w1| on top of |w2|, but not
924 // notify the server of the reorder.
925 window_tree()->AckAllChanges();
926 window_tree_client()->OnTransientWindowAdded(server_id(w2), server_id(w1));
927 EXPECT_EQ(w2, root_window()->children()[0]);
928 EXPECT_EQ(w1, root_window()->children()[1]);
929 EXPECT_EQ(w3, root_window()->children()[2]);
930 // No changes should be scheduled.
931 EXPECT_EQ(0u, window_tree()->number_of_changes());
932
933 // Make |w3| also a transient child of |w2|. Order shouldn't change.
934 window_tree_client()->OnTransientWindowAdded(server_id(w2), server_id(w3));
935 EXPECT_EQ(w2, root_window()->children()[0]);
936 EXPECT_EQ(w1, root_window()->children()[1]);
937 EXPECT_EQ(w3, root_window()->children()[2]);
938 EXPECT_EQ(0u, window_tree()->number_of_changes());
939
940 // Remove |w1| as a transient child, this should move |w3| on top of |w2|.
941 window_tree_client()->OnTransientWindowRemoved(server_id(w2), server_id(w1));
942 EXPECT_EQ(w2, root_window()->children()[0]);
943 EXPECT_EQ(w3, root_window()->children()[1]);
944 EXPECT_EQ(w1, root_window()->children()[2]);
945 EXPECT_EQ(0u, window_tree()->number_of_changes());
946 }
947
948 // Verifies adding/removing a transient child doesn't notify the server of the
949 // restack when the change originates from the client.
950 TEST_F(WindowTreeClientClientTest,
951 TransientChildClientMutateDoesntNotifyOfRestack) {
952 client::TransientWindowClient* transient_client =
953 client::GetTransientWindowClient();
954 Window* w1 = new Window(nullptr);
955 w1->Init(ui::LAYER_NOT_DRAWN);
956 root_window()->AddChild(w1);
957 Window* w2 = new Window(nullptr);
958 w2->Init(ui::LAYER_NOT_DRAWN);
959 root_window()->AddChild(w2);
960 Window* w3 = new Window(nullptr);
961 w3->Init(ui::LAYER_NOT_DRAWN);
962 root_window()->AddChild(w3);
963 // Three children of root: |w1|, |w2| and |w3| (in that order). Make |w1| a
964 // transient child of |w2|. Should trigger moving |w1| on top of |w2|, but not
965 // notify the server of the reorder.
966 window_tree()->AckAllChanges();
967 transient_client->AddTransientChild(w2, w1);
968 EXPECT_EQ(w2, root_window()->children()[0]);
969 EXPECT_EQ(w1, root_window()->children()[1]);
970 EXPECT_EQ(w3, root_window()->children()[2]);
971 // Only a single add transient change should be added.
972 EXPECT_TRUE(window_tree()->AckSingleChangeOfType(
973 WindowTreeChangeType::ADD_TRANSIENT, true));
974 EXPECT_EQ(0u, window_tree()->number_of_changes());
975
976 // Make |w3| also a transient child of |w2|. Order shouldn't change.
977 transient_client->AddTransientChild(w2, w3);
978 EXPECT_EQ(w2, root_window()->children()[0]);
979 EXPECT_EQ(w1, root_window()->children()[1]);
980 EXPECT_EQ(w3, root_window()->children()[2]);
981 EXPECT_TRUE(window_tree()->AckSingleChangeOfType(
982 WindowTreeChangeType::ADD_TRANSIENT, true));
983 EXPECT_EQ(0u, window_tree()->number_of_changes());
984
985 // Remove |w1| as a transient child, this should move |w3| on top of |w2|.
986 transient_client->RemoveTransientChild(w2, w1);
987 EXPECT_EQ(w2, root_window()->children()[0]);
988 EXPECT_EQ(w3, root_window()->children()[1]);
989 EXPECT_EQ(w1, root_window()->children()[2]);
990 EXPECT_TRUE(window_tree()->AckSingleChangeOfType(
991 WindowTreeChangeType::REMOVE_TRANSIENT, true));
992 EXPECT_EQ(0u, window_tree()->number_of_changes());
993
994 // Make |w1| the first child and ensure a REORDER was scheduled.
995 root_window()->StackChildAtBottom(w1);
996 EXPECT_EQ(w1, root_window()->children()[0]);
997 EXPECT_EQ(w2, root_window()->children()[1]);
998 EXPECT_EQ(w3, root_window()->children()[2]);
999 EXPECT_TRUE(window_tree()->AckSingleChangeOfType(
1000 WindowTreeChangeType::REORDER, true));
1001 EXPECT_EQ(0u, window_tree()->number_of_changes());
1002
1003 // Try stacking |w2| above |w3|. This should be disallowed as that would
1004 // result in placing |w2| above its transient parent.
msw 2016/11/21 22:34:49 Did you mean "above its transient child."?
msw 2016/11/21 22:43:50 ping fyi
sky 2016/11/21 22:50:33 Indeed. Will update.
1005 root_window()->StackChildAbove(w2, w3);
1006 EXPECT_EQ(w1, root_window()->children()[0]);
1007 EXPECT_EQ(w2, root_window()->children()[1]);
1008 EXPECT_EQ(w3, root_window()->children()[2]);
1009 // NOTE: even though the order didn't change, internally the order was
1010 // changed and then changed back. That is the StackChildAbove() call really
1011 // succeeded, but then TransientWindowManager reordered the windows back to
1012 // a valid configuration. We expect only one REORDER here as the second
1013 // results from TransientWindowManager and we assume the server applied it as
1014 // well.
1015 EXPECT_EQ(1u, window_tree()->number_of_changes());
1016 window_tree()->AckAllChangesOfType(WindowTreeChangeType::REORDER, true);
1017 EXPECT_EQ(0u, window_tree()->number_of_changes());
1018 }
1019
909 TEST_F(WindowTreeClientClientTest, 1020 TEST_F(WindowTreeClientClientTest,
910 TopLevelWindowDestroyedBeforeCreateComplete) { 1021 TopLevelWindowDestroyedBeforeCreateComplete) {
911 const size_t initial_root_count = 1022 const size_t initial_root_count =
912 window_tree_client_impl()->GetRoots().size(); 1023 window_tree_client_impl()->GetRoots().size();
913 std::unique_ptr<WindowTreeHostMus> window_tree_host = 1024 std::unique_ptr<WindowTreeHostMus> window_tree_host =
914 base::MakeUnique<WindowTreeHostMus>(window_tree_client_impl()); 1025 base::MakeUnique<WindowTreeHostMus>(window_tree_client_impl());
915 EXPECT_EQ(initial_root_count + 1, 1026 EXPECT_EQ(initial_root_count + 1,
916 window_tree_client_impl()->GetRoots().size()); 1027 window_tree_client_impl()->GetRoots().size());
917 1028
918 ui::mojom::WindowDataPtr data = ui::mojom::WindowData::New(); 1029 ui::mojom::WindowDataPtr data = ui::mojom::WindowData::New();
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
1233 window1.Init(ui::LAYER_NOT_DRAWN); 1344 window1.Init(ui::LAYER_NOT_DRAWN);
1234 Window* window2 = new Window(nullptr); 1345 Window* window2 = new Window(nullptr);
1235 window2->Init(ui::LAYER_NOT_DRAWN); 1346 window2->Init(ui::LAYER_NOT_DRAWN);
1236 window1.AddChild(window2); 1347 window1.AddChild(window2);
1237 window_tree()->AckAllChanges(); 1348 window_tree()->AckAllChanges();
1238 window_tree_client()->OnWindowDeleted(server_id(window2)); 1349 window_tree_client()->OnWindowDeleted(server_id(window2));
1239 EXPECT_FALSE(window_tree()->has_change()); 1350 EXPECT_FALSE(window_tree()->has_change());
1240 } 1351 }
1241 1352
1242 } // namespace aura 1353 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698