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

Side by Side Diff: ui/views/corewm/transient_window_stacking_client_unittest.cc

Issue 194843004: Move files from ui/views/corewm to ui/wm/core (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 9 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ui/views/corewm/transient_window_stacking_client.h"
6
7 #include "base/memory/scoped_ptr.h"
8 #include "ui/aura/test/aura_test_base.h"
9 #include "ui/aura/test/test_windows.h"
10 #include "ui/compositor/test/test_layers.h"
11 #include "ui/views/corewm/window_util.h"
12
13 using aura::test::ChildWindowIDsAsString;
14 using aura::test::CreateTestWindowWithId;
15 using aura::Window;
16
17 namespace views {
18 namespace corewm {
19
20 class TransientWindowStackingClientTest : public aura::test::AuraTestBase {
21 public:
22 TransientWindowStackingClientTest() {}
23 virtual ~TransientWindowStackingClientTest() {}
24
25 virtual void SetUp() OVERRIDE {
26 AuraTestBase::SetUp();
27 client_.reset(new TransientWindowStackingClient);
28 aura::client::SetWindowStackingClient(client_.get());
29 }
30
31 virtual void TearDown() OVERRIDE {
32 aura::client::SetWindowStackingClient(NULL);
33 AuraTestBase::TearDown();
34 }
35
36 private:
37 scoped_ptr<TransientWindowStackingClient> client_;
38 DISALLOW_COPY_AND_ASSIGN(TransientWindowStackingClientTest);
39 };
40
41 // Tests that transient children are stacked as a unit when using stack above.
42 TEST_F(TransientWindowStackingClientTest, TransientChildrenGroupAbove) {
43 scoped_ptr<Window> parent(CreateTestWindowWithId(0, root_window()));
44 scoped_ptr<Window> w1(CreateTestWindowWithId(1, parent.get()));
45 Window* w11 = CreateTestWindowWithId(11, parent.get());
46 scoped_ptr<Window> w2(CreateTestWindowWithId(2, parent.get()));
47 Window* w21 = CreateTestWindowWithId(21, parent.get());
48 Window* w211 = CreateTestWindowWithId(211, parent.get());
49 Window* w212 = CreateTestWindowWithId(212, parent.get());
50 Window* w213 = CreateTestWindowWithId(213, parent.get());
51 Window* w22 = CreateTestWindowWithId(22, parent.get());
52 ASSERT_EQ(8u, parent->children().size());
53
54 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(), w22); // w22 is now owned by w2.
57 AddTransientChild(w21, w211); // w211 is now owned by w21.
58 AddTransientChild(w21, w212); // w212 is now owned by w21.
59 AddTransientChild(w21, w213); // w213 is now owned by w21.
60 EXPECT_EQ("1 11 2 21 211 212 213 22", ChildWindowIDsAsString(parent.get()));
61
62 // Stack w1 at the top (end), this should force w11 to be last (on top of w1).
63 parent->StackChildAtTop(w1.get());
64 EXPECT_EQ(w11, parent->children().back());
65 EXPECT_EQ("2 21 211 212 213 22 1 11", ChildWindowIDsAsString(parent.get()));
66
67 // This tests that the order in children_ array rather than in
68 // transient_children_ array is used when reinserting transient children.
69 // If transient_children_ array was used '22' would be following '21'.
70 parent->StackChildAtTop(w2.get());
71 EXPECT_EQ(w22, parent->children().back());
72 EXPECT_EQ("1 11 2 21 211 212 213 22", ChildWindowIDsAsString(parent.get()));
73
74 parent->StackChildAbove(w11, w2.get());
75 EXPECT_EQ(w11, parent->children().back());
76 EXPECT_EQ("2 21 211 212 213 22 1 11", ChildWindowIDsAsString(parent.get()));
77
78 parent->StackChildAbove(w21, w1.get());
79 EXPECT_EQ(w22, parent->children().back());
80 EXPECT_EQ("1 11 2 21 211 212 213 22", ChildWindowIDsAsString(parent.get()));
81
82 parent->StackChildAbove(w21, w22);
83 EXPECT_EQ(w213, parent->children().back());
84 EXPECT_EQ("1 11 2 22 21 211 212 213", ChildWindowIDsAsString(parent.get()));
85
86 parent->StackChildAbove(w11, w21);
87 EXPECT_EQ(w11, parent->children().back());
88 EXPECT_EQ("2 22 21 211 212 213 1 11", ChildWindowIDsAsString(parent.get()));
89
90 parent->StackChildAbove(w213, w21);
91 EXPECT_EQ(w11, parent->children().back());
92 EXPECT_EQ("2 22 21 213 211 212 1 11", ChildWindowIDsAsString(parent.get()));
93
94 // No change when stacking a transient parent above its transient child.
95 parent->StackChildAbove(w21, w211);
96 EXPECT_EQ(w11, parent->children().back());
97 EXPECT_EQ("2 22 21 213 211 212 1 11", ChildWindowIDsAsString(parent.get()));
98
99 // This tests that the order in children_ array rather than in
100 // transient_children_ array is used when reinserting transient children.
101 // If transient_children_ array was used '22' would be following '21'.
102 parent->StackChildAbove(w2.get(), w1.get());
103 EXPECT_EQ(w212, parent->children().back());
104 EXPECT_EQ("1 11 2 22 21 213 211 212", ChildWindowIDsAsString(parent.get()));
105
106 parent->StackChildAbove(w11, w213);
107 EXPECT_EQ(w11, parent->children().back());
108 EXPECT_EQ("2 22 21 213 211 212 1 11", ChildWindowIDsAsString(parent.get()));
109 }
110
111 // Tests that transient children are stacked as a unit when using stack below.
112 TEST_F(TransientWindowStackingClientTest, TransientChildrenGroupBelow) {
113 scoped_ptr<Window> parent(CreateTestWindowWithId(0, root_window()));
114 scoped_ptr<Window> w1(CreateTestWindowWithId(1, parent.get()));
115 Window* w11 = CreateTestWindowWithId(11, parent.get());
116 scoped_ptr<Window> w2(CreateTestWindowWithId(2, parent.get()));
117 Window* w21 = CreateTestWindowWithId(21, parent.get());
118 Window* w211 = CreateTestWindowWithId(211, parent.get());
119 Window* w212 = CreateTestWindowWithId(212, parent.get());
120 Window* w213 = CreateTestWindowWithId(213, parent.get());
121 Window* w22 = CreateTestWindowWithId(22, parent.get());
122 ASSERT_EQ(8u, parent->children().size());
123
124 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(), w22); // w22 is now owned by w2.
127 AddTransientChild(w21, w211); // w211 is now owned by w21.
128 AddTransientChild(w21, w212); // w212 is now owned by w21.
129 AddTransientChild(w21, w213); // w213 is now owned by w21.
130 EXPECT_EQ("1 11 2 21 211 212 213 22", ChildWindowIDsAsString(parent.get()));
131
132 // Stack w2 at the bottom, this should force w11 to be last (on top of w1).
133 // This also tests that the order in children_ array rather than in
134 // transient_children_ array is used when reinserting transient children.
135 // If transient_children_ array was used '22' would be following '21'.
136 parent->StackChildAtBottom(w2.get());
137 EXPECT_EQ(w11, parent->children().back());
138 EXPECT_EQ("2 21 211 212 213 22 1 11", ChildWindowIDsAsString(parent.get()));
139
140 parent->StackChildAtBottom(w1.get());
141 EXPECT_EQ(w22, parent->children().back());
142 EXPECT_EQ("1 11 2 21 211 212 213 22", ChildWindowIDsAsString(parent.get()));
143
144 parent->StackChildBelow(w21, w1.get());
145 EXPECT_EQ(w11, parent->children().back());
146 EXPECT_EQ("2 21 211 212 213 22 1 11", ChildWindowIDsAsString(parent.get()));
147
148 parent->StackChildBelow(w11, w2.get());
149 EXPECT_EQ(w22, parent->children().back());
150 EXPECT_EQ("1 11 2 21 211 212 213 22", ChildWindowIDsAsString(parent.get()));
151
152 parent->StackChildBelow(w22, w21);
153 EXPECT_EQ(w213, parent->children().back());
154 EXPECT_EQ("1 11 2 22 21 211 212 213", ChildWindowIDsAsString(parent.get()));
155
156 parent->StackChildBelow(w21, w11);
157 EXPECT_EQ(w11, parent->children().back());
158 EXPECT_EQ("2 22 21 211 212 213 1 11", ChildWindowIDsAsString(parent.get()));
159
160 parent->StackChildBelow(w213, w211);
161 EXPECT_EQ(w11, parent->children().back());
162 EXPECT_EQ("2 22 21 213 211 212 1 11", ChildWindowIDsAsString(parent.get()));
163
164 // No change when stacking a transient parent below its transient child.
165 parent->StackChildBelow(w21, w211);
166 EXPECT_EQ(w11, parent->children().back());
167 EXPECT_EQ("2 22 21 213 211 212 1 11", ChildWindowIDsAsString(parent.get()));
168
169 parent->StackChildBelow(w1.get(), w2.get());
170 EXPECT_EQ(w212, parent->children().back());
171 EXPECT_EQ("1 11 2 22 21 213 211 212", ChildWindowIDsAsString(parent.get()));
172
173 parent->StackChildBelow(w213, w11);
174 EXPECT_EQ(w11, parent->children().back());
175 EXPECT_EQ("2 22 21 213 211 212 1 11", ChildWindowIDsAsString(parent.get()));
176 }
177
178 TEST_F(TransientWindowStackingClientTest,
179 StackWindowsWhoseLayersHaveNoDelegate) {
180 scoped_ptr<Window> window1(CreateTestWindowWithId(1, root_window()));
181 window1->layer()->set_name("1");
182 scoped_ptr<Window> window2(CreateTestWindowWithId(2, root_window()));
183 window2->layer()->set_name("2");
184 scoped_ptr<Window> window3(CreateTestWindowWithId(3, root_window()));
185 window3->layer()->set_name("3");
186
187 // This brings |window1| (and its layer) to the front.
188 root_window()->StackChildAbove(window1.get(), window3.get());
189 EXPECT_EQ("2 3 1", ChildWindowIDsAsString(root_window()));
190 EXPECT_EQ("2 3 1",
191 ui::test::ChildLayerNamesAsString(*root_window()->layer()));
192
193 // Since |window1| does not have a delegate, |window2| should not move in
194 // front of it, nor should its layer.
195 window1->layer()->set_delegate(NULL);
196 root_window()->StackChildAbove(window2.get(), window1.get());
197 EXPECT_EQ("3 2 1", ChildWindowIDsAsString(root_window()));
198 EXPECT_EQ("3 2 1",
199 ui::test::ChildLayerNamesAsString(*root_window()->layer()));
200
201 // It should still be possible to stack |window3| immediately below |window1|.
202 root_window()->StackChildBelow(window3.get(), window1.get());
203 EXPECT_EQ("2 3 1", ChildWindowIDsAsString(root_window()));
204 EXPECT_EQ("2 3 1",
205 ui::test::ChildLayerNamesAsString(*root_window()->layer()));
206
207 // Since neither |window3| nor |window1| have a delegate, |window2| should
208 // not move in front of either.
209 window3->layer()->set_delegate(NULL);
210 root_window()->StackChildBelow(window2.get(), window1.get());
211 EXPECT_EQ("2 3 1", ChildWindowIDsAsString(root_window()));
212 EXPECT_EQ("2 3 1",
213 ui::test::ChildLayerNamesAsString(*root_window()->layer()));
214 }
215
216 } // namespace corewm
217 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/corewm/transient_window_stacking_client.cc ('k') | ui/views/corewm/visibility_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698