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

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

Issue 2456843004: Wires up transient windows for aura-mus (Closed)
Patch Set: comment Created 4 years, 1 month 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"
11 #include "mojo/common/common_type_converters.h" 11 #include "mojo/common/common_type_converters.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "ui/aura/client/aura_constants.h" 13 #include "ui/aura/client/aura_constants.h"
14 #include "ui/aura/client/capture_client.h" 14 #include "ui/aura/client/capture_client.h"
15 #include "ui/aura/client/focus_client.h" 15 #include "ui/aura/client/focus_client.h"
16 #include "ui/aura/client/transient_window_client.h"
16 #include "ui/aura/mus/property_converter.h" 17 #include "ui/aura/mus/property_converter.h"
17 #include "ui/aura/mus/window_mus.h" 18 #include "ui/aura/mus/window_mus.h"
18 #include "ui/aura/mus/window_tree_client_delegate.h" 19 #include "ui/aura/mus/window_tree_client_delegate.h"
19 #include "ui/aura/mus/window_tree_client_observer.h" 20 #include "ui/aura/mus/window_tree_client_observer.h"
20 #include "ui/aura/test/aura_mus_test_base.h" 21 #include "ui/aura/test/aura_mus_test_base.h"
21 #include "ui/aura/test/mus/test_window_tree.h" 22 #include "ui/aura/test/mus/test_window_tree.h"
22 #include "ui/aura/test/mus/window_tree_client_private.h" 23 #include "ui/aura/test/mus/window_tree_client_private.h"
23 #include "ui/aura/test/test_window_delegate.h" 24 #include "ui/aura/test/test_window_delegate.h"
24 #include "ui/aura/window.h" 25 #include "ui/aura/window.h"
25 #include "ui/aura/window_property.h" 26 #include "ui/aura/window_property.h"
(...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 ASSERT_FALSE(transport_properties.is_null()); 821 ASSERT_FALSE(transport_properties.is_null());
821 std::map<std::string, std::vector<uint8_t>> properties = 822 std::map<std::string, std::vector<uint8_t>> properties =
822 transport_properties.To<std::map<std::string, std::vector<uint8_t>>>(); 823 transport_properties.To<std::map<std::string, std::vector<uint8_t>>>();
823 ASSERT_EQ(1u, properties.count(kTestPropertyServerKey1)); 824 ASSERT_EQ(1u, properties.count(kTestPropertyServerKey1));
824 ASSERT_EQ(1u, properties[kTestPropertyServerKey1].size()); 825 ASSERT_EQ(1u, properties[kTestPropertyServerKey1].size());
825 EXPECT_EQ(explicitly_set_test_property1_value, 826 EXPECT_EQ(explicitly_set_test_property1_value,
826 properties[kTestPropertyServerKey1][0]); 827 properties[kTestPropertyServerKey1][0]);
827 ASSERT_EQ(0u, properties.count(kTestPropertyServerKey2)); 828 ASSERT_EQ(0u, properties.count(kTestPropertyServerKey2));
828 } 829 }
829 830
830 /* 831 // Assertions around transient windows.
831 // Tests that if the client has multiple unowned windows, and one of them is a 832 TEST_F(WindowTreeClientClientTest, Transients) {
832 // transient child to another, the teardown can happen cleanly. 833 client::TransientWindowClient* transient_client =
833 TEST_F(WindowTreeClientWmTest, MultipleUnOwnedWindowsDuringDestruction) { 834 client::GetTransientWindowClient();
834 std::unique_ptr<WindowTreeSetup> setup(new WindowTreeSetup()); 835 Window parent(nullptr);
835 Window* root1 = setup->GetFirstRoot(); 836 parent.Init(ui::LAYER_NOT_DRAWN);
836 ASSERT_TRUE(root1); 837 root_window()->AddChild(&parent);
837 Window* root2 = setup->client()->NewTopLevelWindow(nullptr); 838 Window transient(nullptr);
msw 2016/10/27 23:46:10 Is this |transient| owned by |parent|, like |trans
sky 2016/10/28 03:16:32 This test changes the transient status a bunch. So
838 ASSERT_TRUE(root2); 839 transient.Init(ui::LAYER_NOT_DRAWN);
839 root1->AddTransientWindow(root2); 840 root_window()->AddChild(&transient);
841 window_tree()->AckAllChanges();
842 transient_client->AddTransientChild(&parent, &transient);
843 ASSERT_EQ(1u, window_tree()->GetChangeCountForType(
844 WindowTreeChangeType::ADD_TRANSIENT));
845 EXPECT_EQ(server_id(&parent), window_tree()->transient_data().parent_id);
846 EXPECT_EQ(server_id(&transient), window_tree()->transient_data().child_id);
840 847
841 WindowTracker tracker; 848 // Remove from the server side.
842 tracker.Add(root1); 849 window_tree_client()->OnTransientWindowRemoved(server_id(&parent),
843 tracker.Add(root2); 850 server_id(&transient));
844 reset(); 851 EXPECT_EQ(nullptr, transient_client->GetTransientParent(&transient));
845 EXPECT_TRUE(tracker.windows().empty()); 852 window_tree()->AckAllChanges();
853
854 // Add from the server.
855 window_tree_client()->OnTransientWindowAdded(server_id(&parent),
856 server_id(&transient));
857 EXPECT_EQ(&parent, transient_client->GetTransientParent(&transient));
858
859 // Remove locally.
860 transient_client->RemoveTransientChild(&parent, &transient);
861 ASSERT_EQ(1u, window_tree()->GetChangeCountForType(
862 WindowTreeChangeType::REMOVE_TRANSIENT));
863 EXPECT_EQ(server_id(&transient), window_tree()->transient_data().child_id);
846 } 864 }
847 */
848 865
849 TEST_F(WindowTreeClientClientTest, 866 TEST_F(WindowTreeClientClientTest,
850 TopLevelWindowDestroyedBeforeCreateComplete) { 867 TopLevelWindowDestroyedBeforeCreateComplete) {
851 const size_t initial_root_count = 868 const size_t initial_root_count =
852 window_tree_client_impl()->GetRoots().size(); 869 window_tree_client_impl()->GetRoots().size();
853 std::unique_ptr<Window> top_level(base::MakeUnique<Window>(nullptr)); 870 std::unique_ptr<Window> top_level(base::MakeUnique<Window>(nullptr));
854 top_level->SetType(ui::wm::WINDOW_TYPE_NORMAL); 871 top_level->SetType(ui::wm::WINDOW_TYPE_NORMAL);
855 top_level->Init(ui::LAYER_NOT_DRAWN); 872 top_level->Init(ui::LAYER_NOT_DRAWN);
856 EXPECT_EQ(initial_root_count + 1, 873 EXPECT_EQ(initial_root_count + 1,
857 window_tree_client_impl()->GetRoots().size()); 874 window_tree_client_impl()->GetRoots().size());
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 961
945 ASSERT_TRUE(window_tree()->AckSingleChangeOfType( 962 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
946 WindowTreeChangeType::CAPTURE, false)); 963 WindowTreeChangeType::CAPTURE, false));
947 EXPECT_FALSE(child.HasCapture()); 964 EXPECT_FALSE(child.HasCapture());
948 EXPECT_TRUE(root_window()->HasCapture()); 965 EXPECT_TRUE(root_window()->HasCapture());
949 966
950 window_tree_client()->OnCaptureChanged(0, server_id(root_window())); 967 window_tree_client()->OnCaptureChanged(0, server_id(root_window()));
951 EXPECT_FALSE(root_window()->HasCapture()); 968 EXPECT_FALSE(root_window()->HasCapture());
952 } 969 }
953 970
954 /*
955 TEST_F(WindowTreeClientWmTest, WindowDestroyedWhileTransientChildHasCapture) { 971 TEST_F(WindowTreeClientWmTest, WindowDestroyedWhileTransientChildHasCapture) {
956 WindowTreeSetup setup; 972 std::unique_ptr<Window> transient_parent(base::MakeUnique<Window>(nullptr));
957 Window* root = GetFirstRoot(); 973 transient_parent->Init(ui::LAYER_NOT_DRAWN);
958 Window* transient_parent = client()->NewWindow(); 974 // Owned by |transient_parent|.
959 Window* transient_child = client()->NewWindow(); 975 Window* transient_child = new Window(nullptr);
960 transient_parent->SetVisible(true); 976 transient_child->Init(ui::LAYER_NOT_DRAWN);
961 transient_child->SetVisible(true); 977 transient_parent->Show();
962 root->AddChild(transient_parent); 978 transient_child->Show();
963 root->AddChild(transient_child); 979 root_window()->AddChild(transient_parent.get());
980 root_window()->AddChild(transient_child);
964 981
965 transient_parent->AddTransientWindow(transient_child); 982 client::GetTransientWindowClient()->AddTransientChild(transient_parent.get(),
983 transient_child);
966 984
967 WindowTracker tracker; 985 WindowTracker tracker;
968 tracker.Add(transient_parent); 986 tracker.Add(transient_parent.get());
969 tracker.Add(transient_child); 987 tracker.Add(transient_child);
970 // Request a capture on the transient child, then destroy the transient 988 // Request a capture on the transient child, then destroy the transient
971 // parent. That will destroy both windows, and should reset the capture window 989 // parent. That will destroy both windows, and should reset the capture window
972 // correctly. 990 // correctly.
973 transient_child->SetCapture(); 991 transient_child->SetCapture();
974 transient_parent->Destroy(); 992 transient_parent.reset();
975 EXPECT_TRUE(tracker.windows().empty()); 993 EXPECT_TRUE(tracker.windows().empty());
976 994
977 // Create a new Window, and attempt to place capture on that. 995 // Create a new Window, and attempt to place capture on that.
978 Window* child = client()->NewWindow(); 996 Window child(nullptr);
979 child->SetVisible(true); 997 child.Init(ui::LAYER_NOT_DRAWN);
980 root->AddChild(child); 998 child.Show();
981 child->SetCapture(); 999 root_window()->AddChild(&child);
982 EXPECT_TRUE(child->HasCapture()); 1000 child.SetCapture();
1001 EXPECT_TRUE(child.HasCapture());
983 } 1002 }
984 */
985 1003
986 namespace { 1004 namespace {
987 1005
988 class CaptureRecorder : public client::CaptureClientObserver { 1006 class CaptureRecorder : public client::CaptureClientObserver {
989 public: 1007 public:
990 explicit CaptureRecorder(Window* root_window) : root_window_(root_window) { 1008 explicit CaptureRecorder(Window* root_window) : root_window_(root_window) {
991 client::GetCaptureClient(root_window)->AddObserver(this); 1009 client::GetCaptureClient(root_window)->AddObserver(this);
992 } 1010 }
993 1011
994 ~CaptureRecorder() override { 1012 ~CaptureRecorder() override {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 1081
1064 // Changes originating from server should notify observers too. 1082 // Changes originating from server should notify observers too.
1065 window_tree_client()->OnCaptureChanged(server_id(&child2), 0); 1083 window_tree_client()->OnCaptureChanged(server_id(&child2), 0);
1066 EXPECT_EQ(1, capture_recorder.capture_changed_count()); 1084 EXPECT_EQ(1, capture_recorder.capture_changed_count());
1067 EXPECT_EQ(child2_id, capture_recorder.last_gained_capture_window_id()); 1085 EXPECT_EQ(child2_id, capture_recorder.last_gained_capture_window_id());
1068 EXPECT_EQ(0, capture_recorder.last_lost_capture_window_id()); 1086 EXPECT_EQ(0, capture_recorder.last_lost_capture_window_id());
1069 capture_recorder.reset_capture_captured_count(); 1087 capture_recorder.reset_capture_captured_count();
1070 } 1088 }
1071 1089
1072 } // namespace aura 1090 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698