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

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

Issue 115453004: Moves management of transients out of Window (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove unneeded parens Created 6 years, 11 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
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/views/corewm/transient_window_stacking_client.h" 5 #include "ui/views/corewm/transient_window_stacking_client.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "ui/aura/test/aura_test_base.h" 8 #include "ui/aura/test/aura_test_base.h"
9 #include "ui/aura/test/test_windows.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"
10 12
11 using aura::test::ChildWindowIDsAsString; 13 using aura::test::ChildWindowIDsAsString;
12 using aura::test::CreateTestWindowWithId; 14 using aura::test::CreateTestWindowWithId;
13 using aura::Window; 15 using aura::Window;
14 16
15 namespace views { 17 namespace views {
16 namespace corewm { 18 namespace corewm {
17 19
18 class TransientWindowStackingClientTest : public aura::test::AuraTestBase { 20 class TransientWindowStackingClientTest : public aura::test::AuraTestBase {
19 public: 21 public:
(...skipping 22 matching lines...) Expand all
42 scoped_ptr<Window> w1(CreateTestWindowWithId(1, parent.get())); 44 scoped_ptr<Window> w1(CreateTestWindowWithId(1, parent.get()));
43 Window* w11 = CreateTestWindowWithId(11, parent.get()); 45 Window* w11 = CreateTestWindowWithId(11, parent.get());
44 scoped_ptr<Window> w2(CreateTestWindowWithId(2, parent.get())); 46 scoped_ptr<Window> w2(CreateTestWindowWithId(2, parent.get()));
45 Window* w21 = CreateTestWindowWithId(21, parent.get()); 47 Window* w21 = CreateTestWindowWithId(21, parent.get());
46 Window* w211 = CreateTestWindowWithId(211, parent.get()); 48 Window* w211 = CreateTestWindowWithId(211, parent.get());
47 Window* w212 = CreateTestWindowWithId(212, parent.get()); 49 Window* w212 = CreateTestWindowWithId(212, parent.get());
48 Window* w213 = CreateTestWindowWithId(213, parent.get()); 50 Window* w213 = CreateTestWindowWithId(213, parent.get());
49 Window* w22 = CreateTestWindowWithId(22, parent.get()); 51 Window* w22 = CreateTestWindowWithId(22, parent.get());
50 ASSERT_EQ(8u, parent->children().size()); 52 ASSERT_EQ(8u, parent->children().size());
51 53
52 w1->AddTransientChild(w11); // w11 is now owned by w1. 54 AddTransientChild(w1.get(), w11); // w11 is now owned by w1.
53 w2->AddTransientChild(w21); // w21 is now owned by w2. 55 AddTransientChild(w2.get(), w21); // w21 is now owned by w2.
54 w2->AddTransientChild(w22); // w22 is now owned by w2. 56 AddTransientChild(w2.get(), w22); // w22 is now owned by w2.
55 w21->AddTransientChild(w211); // w211 is now owned by w21. 57 AddTransientChild(w21, w211); // w211 is now owned by w21.
56 w21->AddTransientChild(w212); // w212 is now owned by w21. 58 AddTransientChild(w21, w212); // w212 is now owned by w21.
57 w21->AddTransientChild(w213); // w213 is now owned by w21. 59 AddTransientChild(w21, w213); // w213 is now owned by w21.
58 EXPECT_EQ("1 11 2 21 211 212 213 22", ChildWindowIDsAsString(parent.get())); 60 EXPECT_EQ("1 11 2 21 211 212 213 22", ChildWindowIDsAsString(parent.get()));
59 61
60 // Stack w1 at the top (end), this should force w11 to be last (on top of w1). 62 // Stack w1 at the top (end), this should force w11 to be last (on top of w1).
61 parent->StackChildAtTop(w1.get()); 63 parent->StackChildAtTop(w1.get());
62 EXPECT_EQ(w11, parent->children().back()); 64 EXPECT_EQ(w11, parent->children().back());
63 EXPECT_EQ("2 21 211 212 213 22 1 11", ChildWindowIDsAsString(parent.get())); 65 EXPECT_EQ("2 21 211 212 213 22 1 11", ChildWindowIDsAsString(parent.get()));
64 66
65 // This tests that the order in children_ array rather than in 67 // This tests that the order in children_ array rather than in
66 // transient_children_ array is used when reinserting transient children. 68 // transient_children_ array is used when reinserting transient children.
67 // If transient_children_ array was used '22' would be following '21'. 69 // If transient_children_ array was used '22' would be following '21'.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 scoped_ptr<Window> w1(CreateTestWindowWithId(1, parent.get())); 114 scoped_ptr<Window> w1(CreateTestWindowWithId(1, parent.get()));
113 Window* w11 = CreateTestWindowWithId(11, parent.get()); 115 Window* w11 = CreateTestWindowWithId(11, parent.get());
114 scoped_ptr<Window> w2(CreateTestWindowWithId(2, parent.get())); 116 scoped_ptr<Window> w2(CreateTestWindowWithId(2, parent.get()));
115 Window* w21 = CreateTestWindowWithId(21, parent.get()); 117 Window* w21 = CreateTestWindowWithId(21, parent.get());
116 Window* w211 = CreateTestWindowWithId(211, parent.get()); 118 Window* w211 = CreateTestWindowWithId(211, parent.get());
117 Window* w212 = CreateTestWindowWithId(212, parent.get()); 119 Window* w212 = CreateTestWindowWithId(212, parent.get());
118 Window* w213 = CreateTestWindowWithId(213, parent.get()); 120 Window* w213 = CreateTestWindowWithId(213, parent.get());
119 Window* w22 = CreateTestWindowWithId(22, parent.get()); 121 Window* w22 = CreateTestWindowWithId(22, parent.get());
120 ASSERT_EQ(8u, parent->children().size()); 122 ASSERT_EQ(8u, parent->children().size());
121 123
122 w1->AddTransientChild(w11); // w11 is now owned by w1. 124 AddTransientChild(w1.get(), w11); // w11 is now owned by w1.
123 w2->AddTransientChild(w21); // w21 is now owned by w2. 125 AddTransientChild(w2.get(), w21); // w21 is now owned by w2.
124 w2->AddTransientChild(w22); // w22 is now owned by w2. 126 AddTransientChild(w2.get(), w22); // w22 is now owned by w2.
125 w21->AddTransientChild(w211); // w211 is now owned by w21. 127 AddTransientChild(w21, w211); // w211 is now owned by w21.
126 w21->AddTransientChild(w212); // w212 is now owned by w21. 128 AddTransientChild(w21, w212); // w212 is now owned by w21.
127 w21->AddTransientChild(w213); // w213 is now owned by w21. 129 AddTransientChild(w21, w213); // w213 is now owned by w21.
128 EXPECT_EQ("1 11 2 21 211 212 213 22", ChildWindowIDsAsString(parent.get())); 130 EXPECT_EQ("1 11 2 21 211 212 213 22", ChildWindowIDsAsString(parent.get()));
129 131
130 // Stack w2 at the bottom, this should force w11 to be last (on top of w1). 132 // Stack w2 at the bottom, this should force w11 to be last (on top of w1).
131 // This also tests that the order in children_ array rather than in 133 // This also tests that the order in children_ array rather than in
132 // transient_children_ array is used when reinserting transient children. 134 // transient_children_ array is used when reinserting transient children.
133 // If transient_children_ array was used '22' would be following '21'. 135 // If transient_children_ array was used '22' would be following '21'.
134 parent->StackChildAtBottom(w2.get()); 136 parent->StackChildAtBottom(w2.get());
135 EXPECT_EQ(w11, parent->children().back()); 137 EXPECT_EQ(w11, parent->children().back());
136 EXPECT_EQ("2 21 211 212 213 22 1 11", ChildWindowIDsAsString(parent.get())); 138 EXPECT_EQ("2 21 211 212 213 22 1 11", ChildWindowIDsAsString(parent.get()));
137 139
(...skipping 28 matching lines...) Expand all
166 168
167 parent->StackChildBelow(w1.get(), w2.get()); 169 parent->StackChildBelow(w1.get(), w2.get());
168 EXPECT_EQ(w212, parent->children().back()); 170 EXPECT_EQ(w212, parent->children().back());
169 EXPECT_EQ("1 11 2 22 21 213 211 212", ChildWindowIDsAsString(parent.get())); 171 EXPECT_EQ("1 11 2 22 21 213 211 212", ChildWindowIDsAsString(parent.get()));
170 172
171 parent->StackChildBelow(w213, w11); 173 parent->StackChildBelow(w213, w11);
172 EXPECT_EQ(w11, parent->children().back()); 174 EXPECT_EQ(w11, parent->children().back());
173 EXPECT_EQ("2 22 21 213 211 212 1 11", ChildWindowIDsAsString(parent.get())); 175 EXPECT_EQ("2 22 21 213 211 212 1 11", ChildWindowIDsAsString(parent.get()));
174 } 176 }
175 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
176 } // namespace corewm 216 } // namespace corewm
177 } // namespace views 217 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/corewm/transient_window_stacking_client.cc ('k') | ui/views/corewm/window_modality_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698