OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/wm/core/transient_window_stacking_client.h" | 5 #include "ui/wm/core/transient_window_stacking_client.h" |
6 | 6 |
| 7 #include <memory> |
| 8 |
7 #include "base/macros.h" | 9 #include "base/macros.h" |
8 #include "base/memory/scoped_ptr.h" | |
9 #include "ui/aura/test/aura_test_base.h" | 10 #include "ui/aura/test/aura_test_base.h" |
10 #include "ui/aura/test/test_windows.h" | 11 #include "ui/aura/test/test_windows.h" |
11 #include "ui/compositor/test/test_layers.h" | 12 #include "ui/compositor/test/test_layers.h" |
12 #include "ui/wm/core/window_util.h" | 13 #include "ui/wm/core/window_util.h" |
13 | 14 |
14 using aura::test::ChildWindowIDsAsString; | 15 using aura::test::ChildWindowIDsAsString; |
15 using aura::test::CreateTestWindowWithId; | 16 using aura::test::CreateTestWindowWithId; |
16 using aura::Window; | 17 using aura::Window; |
17 | 18 |
18 namespace wm { | 19 namespace wm { |
19 | 20 |
20 class TransientWindowStackingClientTest : public aura::test::AuraTestBase { | 21 class TransientWindowStackingClientTest : public aura::test::AuraTestBase { |
21 public: | 22 public: |
22 TransientWindowStackingClientTest() {} | 23 TransientWindowStackingClientTest() {} |
23 ~TransientWindowStackingClientTest() override {} | 24 ~TransientWindowStackingClientTest() override {} |
24 | 25 |
25 void SetUp() override { | 26 void SetUp() override { |
26 AuraTestBase::SetUp(); | 27 AuraTestBase::SetUp(); |
27 client_.reset(new TransientWindowStackingClient); | 28 client_.reset(new TransientWindowStackingClient); |
28 aura::client::SetWindowStackingClient(client_.get()); | 29 aura::client::SetWindowStackingClient(client_.get()); |
29 } | 30 } |
30 | 31 |
31 void TearDown() override { | 32 void TearDown() override { |
32 aura::client::SetWindowStackingClient(NULL); | 33 aura::client::SetWindowStackingClient(NULL); |
33 AuraTestBase::TearDown(); | 34 AuraTestBase::TearDown(); |
34 } | 35 } |
35 | 36 |
36 private: | 37 private: |
37 scoped_ptr<TransientWindowStackingClient> client_; | 38 std::unique_ptr<TransientWindowStackingClient> client_; |
38 DISALLOW_COPY_AND_ASSIGN(TransientWindowStackingClientTest); | 39 DISALLOW_COPY_AND_ASSIGN(TransientWindowStackingClientTest); |
39 }; | 40 }; |
40 | 41 |
41 // Tests that transient children are stacked as a unit when using stack above. | 42 // Tests that transient children are stacked as a unit when using stack above. |
42 TEST_F(TransientWindowStackingClientTest, TransientChildrenGroupAbove) { | 43 TEST_F(TransientWindowStackingClientTest, TransientChildrenGroupAbove) { |
43 scoped_ptr<Window> parent(CreateTestWindowWithId(0, root_window())); | 44 std::unique_ptr<Window> parent(CreateTestWindowWithId(0, root_window())); |
44 scoped_ptr<Window> w1(CreateTestWindowWithId(1, parent.get())); | 45 std::unique_ptr<Window> w1(CreateTestWindowWithId(1, parent.get())); |
45 Window* w11 = CreateTestWindowWithId(11, parent.get()); | 46 Window* w11 = CreateTestWindowWithId(11, parent.get()); |
46 scoped_ptr<Window> w2(CreateTestWindowWithId(2, parent.get())); | 47 std::unique_ptr<Window> w2(CreateTestWindowWithId(2, parent.get())); |
47 Window* w21 = CreateTestWindowWithId(21, parent.get()); | 48 Window* w21 = CreateTestWindowWithId(21, parent.get()); |
48 Window* w211 = CreateTestWindowWithId(211, parent.get()); | 49 Window* w211 = CreateTestWindowWithId(211, parent.get()); |
49 Window* w212 = CreateTestWindowWithId(212, parent.get()); | 50 Window* w212 = CreateTestWindowWithId(212, parent.get()); |
50 Window* w213 = CreateTestWindowWithId(213, parent.get()); | 51 Window* w213 = CreateTestWindowWithId(213, parent.get()); |
51 Window* w22 = CreateTestWindowWithId(22, parent.get()); | 52 Window* w22 = CreateTestWindowWithId(22, parent.get()); |
52 ASSERT_EQ(8u, parent->children().size()); | 53 ASSERT_EQ(8u, parent->children().size()); |
53 | 54 |
54 AddTransientChild(w1.get(), w11); // w11 is now owned by w1. | 55 AddTransientChild(w1.get(), w11); // w11 is now owned by w1. |
55 AddTransientChild(w2.get(), w21); // w21 is now owned by w2. | 56 AddTransientChild(w2.get(), w21); // w21 is now owned by w2. |
56 AddTransientChild(w2.get(), w22); // w22 is now owned by w2. | 57 AddTransientChild(w2.get(), w22); // w22 is now owned by w2. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 EXPECT_EQ(w212, parent->children().back()); | 104 EXPECT_EQ(w212, parent->children().back()); |
104 EXPECT_EQ("1 11 2 22 21 213 211 212", ChildWindowIDsAsString(parent.get())); | 105 EXPECT_EQ("1 11 2 22 21 213 211 212", ChildWindowIDsAsString(parent.get())); |
105 | 106 |
106 parent->StackChildAbove(w11, w213); | 107 parent->StackChildAbove(w11, w213); |
107 EXPECT_EQ(w11, parent->children().back()); | 108 EXPECT_EQ(w11, parent->children().back()); |
108 EXPECT_EQ("2 22 21 213 211 212 1 11", ChildWindowIDsAsString(parent.get())); | 109 EXPECT_EQ("2 22 21 213 211 212 1 11", ChildWindowIDsAsString(parent.get())); |
109 } | 110 } |
110 | 111 |
111 // Tests that transient children are stacked as a unit when using stack below. | 112 // Tests that transient children are stacked as a unit when using stack below. |
112 TEST_F(TransientWindowStackingClientTest, TransientChildrenGroupBelow) { | 113 TEST_F(TransientWindowStackingClientTest, TransientChildrenGroupBelow) { |
113 scoped_ptr<Window> parent(CreateTestWindowWithId(0, root_window())); | 114 std::unique_ptr<Window> parent(CreateTestWindowWithId(0, root_window())); |
114 scoped_ptr<Window> w1(CreateTestWindowWithId(1, parent.get())); | 115 std::unique_ptr<Window> w1(CreateTestWindowWithId(1, parent.get())); |
115 Window* w11 = CreateTestWindowWithId(11, parent.get()); | 116 Window* w11 = CreateTestWindowWithId(11, parent.get()); |
116 scoped_ptr<Window> w2(CreateTestWindowWithId(2, parent.get())); | 117 std::unique_ptr<Window> w2(CreateTestWindowWithId(2, parent.get())); |
117 Window* w21 = CreateTestWindowWithId(21, parent.get()); | 118 Window* w21 = CreateTestWindowWithId(21, parent.get()); |
118 Window* w211 = CreateTestWindowWithId(211, parent.get()); | 119 Window* w211 = CreateTestWindowWithId(211, parent.get()); |
119 Window* w212 = CreateTestWindowWithId(212, parent.get()); | 120 Window* w212 = CreateTestWindowWithId(212, parent.get()); |
120 Window* w213 = CreateTestWindowWithId(213, parent.get()); | 121 Window* w213 = CreateTestWindowWithId(213, parent.get()); |
121 Window* w22 = CreateTestWindowWithId(22, parent.get()); | 122 Window* w22 = CreateTestWindowWithId(22, parent.get()); |
122 ASSERT_EQ(8u, parent->children().size()); | 123 ASSERT_EQ(8u, parent->children().size()); |
123 | 124 |
124 AddTransientChild(w1.get(), w11); // w11 is now owned by w1. | 125 AddTransientChild(w1.get(), w11); // w11 is now owned by w1. |
125 AddTransientChild(w2.get(), w21); // w21 is now owned by w2. | 126 AddTransientChild(w2.get(), w21); // w21 is now owned by w2. |
126 AddTransientChild(w2.get(), w22); // w22 is now owned by w2. | 127 AddTransientChild(w2.get(), w22); // w22 is now owned by w2. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 parent->StackChildBelow(w213, w11); | 174 parent->StackChildBelow(w213, w11); |
174 EXPECT_EQ(w11, parent->children().back()); | 175 EXPECT_EQ(w11, parent->children().back()); |
175 EXPECT_EQ("2 22 21 213 211 212 1 11", ChildWindowIDsAsString(parent.get())); | 176 EXPECT_EQ("2 22 21 213 211 212 1 11", ChildWindowIDsAsString(parent.get())); |
176 } | 177 } |
177 | 178 |
178 // Tests that windows can be stacked above windows with a NULL layer delegate. | 179 // Tests that windows can be stacked above windows with a NULL layer delegate. |
179 // Windows have a NULL layer delegate when they are in the process of closing. | 180 // Windows have a NULL layer delegate when they are in the process of closing. |
180 // See crbug.com/443433 | 181 // See crbug.com/443433 |
181 TEST_F(TransientWindowStackingClientTest, | 182 TEST_F(TransientWindowStackingClientTest, |
182 StackAboveWindowWithNULLLayerDelegate) { | 183 StackAboveWindowWithNULLLayerDelegate) { |
183 scoped_ptr<Window> parent(CreateTestWindowWithId(0, root_window())); | 184 std::unique_ptr<Window> parent(CreateTestWindowWithId(0, root_window())); |
184 scoped_ptr<Window> w1(CreateTestWindowWithId(1, parent.get())); | 185 std::unique_ptr<Window> w1(CreateTestWindowWithId(1, parent.get())); |
185 scoped_ptr<Window> w2(CreateTestWindowWithId(2, parent.get())); | 186 std::unique_ptr<Window> w2(CreateTestWindowWithId(2, parent.get())); |
186 w2->layer()->set_delegate(NULL); | 187 w2->layer()->set_delegate(NULL); |
187 EXPECT_EQ(w2.get(), parent->children().back()); | 188 EXPECT_EQ(w2.get(), parent->children().back()); |
188 | 189 |
189 parent->StackChildAbove(w1.get(), w2.get()); | 190 parent->StackChildAbove(w1.get(), w2.get()); |
190 EXPECT_EQ(w1.get(), parent->children().back()); | 191 EXPECT_EQ(w1.get(), parent->children().back()); |
191 } | 192 } |
192 | 193 |
193 } // namespace wm | 194 } // namespace wm |
OLD | NEW |