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

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

Issue 115453004: Moves management of transients out of Window (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix MRUWindowTracker and MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest Created 7 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 | 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_manager.h"
6
7 #include "ui/aura/client/visibility_client.h"
8 #include "ui/aura/client/window_tree_client.h"
9 #include "ui/aura/layout_manager.h"
10 #include "ui/aura/test/test_windows.h"
11 #include "ui/aura/window.h"
12 #include "ui/views/test/views_test_base.h"
13
14 using aura::Window;
15
16 using aura::test::ChildWindowIDsAsString;
17 using aura::test::CreateTestWindowWithId;
18
19 namespace views {
20 namespace corewm {
21
22 class TransientWindowManagerTest : public views::ViewsTestBase {
23 public:
24 TransientWindowManagerTest() {}
25 virtual ~TransientWindowManagerTest() {}
26
27 protected:
28 // Creates a transient window that is transient to |parent|.
29 Window* CreateTransientChild(int id, Window* parent) {
30 Window* window = new Window(NULL);
31 window->set_id(id);
32 window->SetType(aura::client::WINDOW_TYPE_NORMAL);
33 window->Init(ui::LAYER_TEXTURED);
34 aura::client::ParentWindowWithContext(window, GetContext(), gfx::Rect());
35 AddTransientChild(parent, window);
36 return window;
37 }
38
39 private:
40 DISALLOW_COPY_AND_ASSIGN(TransientWindowManagerTest);
41 };
42
43 // Various assertions for transient children.
44 TEST_F(TransientWindowManagerTest, TransientChildren) {
45 scoped_ptr<Window> parent(CreateTestWindowWithId(0, GetContext()));
46 scoped_ptr<Window> w1(CreateTestWindowWithId(1, parent.get()));
47 scoped_ptr<Window> w3(CreateTestWindowWithId(3, parent.get()));
48 Window* w2 = CreateTestWindowWithId(2, parent.get());
49 // w2 is now owned by w1.
50 AddTransientChild(w1.get(), w2);
51 // Stack w1 at the top (end), this should force w2 to be last (on top of w1).
52 parent->StackChildAtTop(w1.get());
53 ASSERT_EQ(3u, parent->children().size());
54 EXPECT_EQ(w2, parent->children().back());
55
56 // Destroy w1, which should also destroy w3 (since it's a transient child).
57 w1.reset();
58 w2 = NULL;
59 ASSERT_EQ(1u, parent->children().size());
60 EXPECT_EQ(w3.get(), parent->children()[0]);
61
62 w1.reset(CreateTestWindowWithId(4, parent.get()));
63 w2 = CreateTestWindowWithId(5, w3.get());
64 AddTransientChild(w1.get(), w2);
65 parent->StackChildAtTop(w3.get());
66 // Stack w1 at the top (end), this shouldn't affect w2 since it has a
67 // different parent.
68 parent->StackChildAtTop(w1.get());
69 ASSERT_EQ(2u, parent->children().size());
70 EXPECT_EQ(w3.get(), parent->children()[0]);
71 EXPECT_EQ(w1.get(), parent->children()[1]);
72
73 // Hiding parent should hide transient children.
74 EXPECT_TRUE(w2->IsVisible());
75 w1->Hide();
76 EXPECT_FALSE(w2->IsVisible());
77 }
78
79 // Tests that transient children are stacked as a unit when using stack above.
80 TEST_F(TransientWindowManagerTest, TransientChildrenGroupAbove) {
81 scoped_ptr<Window> parent(CreateTestWindowWithId(0, GetContext()));
82 scoped_ptr<Window> w1(CreateTestWindowWithId(1, parent.get()));
83 Window* w11 = CreateTestWindowWithId(11, parent.get());
84 scoped_ptr<Window> w2(CreateTestWindowWithId(2, parent.get()));
85 Window* w21 = CreateTestWindowWithId(21, parent.get());
86 Window* w211 = CreateTestWindowWithId(211, parent.get());
87 Window* w212 = CreateTestWindowWithId(212, parent.get());
88 Window* w213 = CreateTestWindowWithId(213, parent.get());
89 Window* w22 = CreateTestWindowWithId(22, parent.get());
90 ASSERT_EQ(8u, parent->children().size());
91
92 // w11 is now owned by w1.
93 AddTransientChild(w1.get(), w11);
94 // w21 is now owned by w2.
95 AddTransientChild(w2.get(), w21);
96 // w22 is now owned by w2.
97 AddTransientChild(w2.get(), w22);
98 // w211 is now owned by w21.
99 AddTransientChild(w21, w211);
100 // w212 is now owned by w21.
101 AddTransientChild(w21, w212);
102 // w213 is now owned by w21.
103 AddTransientChild(w21, w213);
104 EXPECT_EQ("1 11 2 21 211 212 213 22", ChildWindowIDsAsString(parent.get()));
105
106 // Stack w1 at the top (end), this should force w11 to be last (on top of w1).
107 parent->StackChildAtTop(w1.get());
108 EXPECT_EQ(w11, parent->children().back());
109 EXPECT_EQ("2 21 211 212 213 22 1 11", ChildWindowIDsAsString(parent.get()));
110
111 // This tests that the order in children_ array rather than in
112 // transient_children_ array is used when reinserting transient children.
113 // If transient_children_ array was used '22' would be following '21'.
114 parent->StackChildAtTop(w2.get());
115 EXPECT_EQ(w22, parent->children().back());
116 EXPECT_EQ("1 11 2 21 211 212 213 22", ChildWindowIDsAsString(parent.get()));
117
118 parent->StackChildAbove(w11, w2.get());
119 EXPECT_EQ(w11, parent->children().back());
120 EXPECT_EQ("2 21 211 212 213 22 1 11", ChildWindowIDsAsString(parent.get()));
121
122 parent->StackChildAbove(w21, w1.get());
123 EXPECT_EQ(w22, parent->children().back());
124 EXPECT_EQ("1 11 2 21 211 212 213 22", ChildWindowIDsAsString(parent.get()));
125
126 parent->StackChildAbove(w21, w22);
127 EXPECT_EQ(w213, parent->children().back());
128 EXPECT_EQ("1 11 2 22 21 211 212 213", ChildWindowIDsAsString(parent.get()));
129
130 parent->StackChildAbove(w11, w21);
131 EXPECT_EQ(w11, parent->children().back());
132 EXPECT_EQ("2 22 21 211 212 213 1 11", ChildWindowIDsAsString(parent.get()));
133
134 parent->StackChildAbove(w213, w21);
135 EXPECT_EQ(w11, parent->children().back());
136 EXPECT_EQ("2 22 21 213 211 212 1 11", ChildWindowIDsAsString(parent.get()));
137
138 // No change when stacking a transient parent above its transient child.
139 parent->StackChildAbove(w21, w211);
140 EXPECT_EQ(w11, parent->children().back());
141 EXPECT_EQ("2 22 21 213 211 212 1 11", ChildWindowIDsAsString(parent.get()));
142
143 // This tests that the order in children_ array rather than in
144 // transient_children_ array is used when reinserting transient children.
145 // If transient_children_ array was used '22' would be following '21'.
146 parent->StackChildAbove(w2.get(), w1.get());
147 EXPECT_EQ(w212, parent->children().back());
148 EXPECT_EQ("1 11 2 22 21 213 211 212", ChildWindowIDsAsString(parent.get()));
149
150 parent->StackChildAbove(w11, w213);
151 EXPECT_EQ(w11, parent->children().back());
152 EXPECT_EQ("2 22 21 213 211 212 1 11", ChildWindowIDsAsString(parent.get()));
153 }
154
155 // Tests that transient children are stacked as a unit when using stack below.
156 TEST_F(TransientWindowManagerTest, TransientChildrenGroupBelow) {
157 scoped_ptr<Window> parent(CreateTestWindowWithId(0, GetContext()));
158 scoped_ptr<Window> w1(CreateTestWindowWithId(1, parent.get()));
159 Window* w11 = CreateTestWindowWithId(11, parent.get());
160 scoped_ptr<Window> w2(CreateTestWindowWithId(2, parent.get()));
161 Window* w21 = CreateTestWindowWithId(21, parent.get());
162 Window* w211 = CreateTestWindowWithId(211, parent.get());
163 Window* w212 = CreateTestWindowWithId(212, parent.get());
164 Window* w213 = CreateTestWindowWithId(213, parent.get());
165 Window* w22 = CreateTestWindowWithId(22, parent.get());
166 ASSERT_EQ(8u, parent->children().size());
167
168 // w11 is now owned by w1.
169 AddTransientChild(w1.get(), w11);
170 // w21 is now owned by w2.
171 AddTransientChild(w2.get(), w21);
172 // w22 is now owned by w2.
173 AddTransientChild(w2.get(), w22);
174 // w211 is now owned by w21.
175 AddTransientChild(w21, w211);
176 // w212 is now owned by w21.
177 AddTransientChild(w21, w212);
178 // w213 is now owned by w21.
179 AddTransientChild(w21, w213);
180 EXPECT_EQ("1 11 2 21 211 212 213 22", ChildWindowIDsAsString(parent.get()));
181
182 // Stack w2 at the bottom, this should force w11 to be last (on top of w1).
183 // This also tests that the order in children_ array rather than in
184 // transient_children_ array is used when reinserting transient children.
185 // If transient_children_ array was used '22' would be following '21'.
186 parent->StackChildAtBottom(w2.get());
187 EXPECT_EQ(w11, parent->children().back());
188 EXPECT_EQ("2 21 211 212 213 22 1 11", ChildWindowIDsAsString(parent.get()));
189
190 parent->StackChildAtBottom(w1.get());
191 EXPECT_EQ(w22, parent->children().back());
192 EXPECT_EQ("1 11 2 21 211 212 213 22", ChildWindowIDsAsString(parent.get()));
193
194 parent->StackChildBelow(w21, w1.get());
195 EXPECT_EQ(w11, parent->children().back());
196 EXPECT_EQ("2 21 211 212 213 22 1 11", ChildWindowIDsAsString(parent.get()));
197
198 parent->StackChildBelow(w11, w2.get());
199 EXPECT_EQ(w22, parent->children().back());
200 EXPECT_EQ("1 11 2 21 211 212 213 22", ChildWindowIDsAsString(parent.get()));
201
202 parent->StackChildBelow(w22, w21);
203 EXPECT_EQ(w213, parent->children().back());
204 EXPECT_EQ("1 11 2 22 21 211 212 213", ChildWindowIDsAsString(parent.get()));
205
206 parent->StackChildBelow(w21, w11);
207 EXPECT_EQ(w11, parent->children().back());
208 EXPECT_EQ("2 22 21 211 212 213 1 11", ChildWindowIDsAsString(parent.get()));
209
210 parent->StackChildBelow(w213, w211);
211 EXPECT_EQ(w11, parent->children().back());
212 EXPECT_EQ("2 22 21 213 211 212 1 11", ChildWindowIDsAsString(parent.get()));
213
214 // No change when stacking a transient parent below its transient child.
215 parent->StackChildBelow(w21, w211);
216 EXPECT_EQ(w11, parent->children().back());
217 EXPECT_EQ("2 22 21 213 211 212 1 11", ChildWindowIDsAsString(parent.get()));
218
219 parent->StackChildBelow(w1.get(), w2.get());
220 EXPECT_EQ(w212, parent->children().back());
221 EXPECT_EQ("1 11 2 22 21 213 211 212", ChildWindowIDsAsString(parent.get()));
222
223 parent->StackChildBelow(w213, w11);
224 EXPECT_EQ(w11, parent->children().back());
225 EXPECT_EQ("2 22 21 213 211 212 1 11", ChildWindowIDsAsString(parent.get()));
226 }
227
228 namespace {
229
230 // Used by NotifyDelegateAfterDeletingTransients. Adds a string to a vector when
231 // OnWindowDestroyed() is invoked so that destruction order can be verified.
232 class DestroyedTrackingDelegate : public aura::test::TestWindowDelegate {
233 public:
234 explicit DestroyedTrackingDelegate(const std::string& name,
235 std::vector<std::string>* results)
236 : name_(name),
237 results_(results) {}
238
239 virtual void OnWindowDestroyed() OVERRIDE {
240 results_->push_back(name_);
241 }
242
243 private:
244 const std::string name_;
245 std::vector<std::string>* results_;
246
247 DISALLOW_COPY_AND_ASSIGN(DestroyedTrackingDelegate);
248 };
249
250 } // namespace
251
252 // Verifies the delegate is notified of destruction after transients are
253 // destroyed.
254 TEST_F(TransientWindowManagerTest, NotifyDelegateAfterDeletingTransients) {
255 std::vector<std::string> destruction_order;
256
257 DestroyedTrackingDelegate parent_delegate("parent", &destruction_order);
258 scoped_ptr<Window> parent(new Window(&parent_delegate));
259 parent->Init(ui::LAYER_NOT_DRAWN);
260
261 DestroyedTrackingDelegate transient_delegate("transient", &destruction_order);
262 Window* transient = new Window(&transient_delegate); // Owned by |parent|.
263 transient->Init(ui::LAYER_NOT_DRAWN);
264 AddTransientChild(parent.get(), transient);
265 parent.reset();
266
267 ASSERT_EQ(2u, destruction_order.size());
268 EXPECT_EQ("transient", destruction_order[0]);
269 EXPECT_EQ("parent", destruction_order[1]);
270 }
271
272 TEST_F(TransientWindowManagerTest, StackTransientsWhoseLayersHaveNoDelegate) {
273 // Create a window with several transients, then a couple windows on top.
274 scoped_ptr<Window> window1(CreateTestWindowWithId(1, GetContext()));
275 scoped_ptr<Window> window11(CreateTransientChild(11, window1.get()));
276 scoped_ptr<Window> window12(CreateTransientChild(12, window1.get()));
277 scoped_ptr<Window> window13(CreateTransientChild(13, window1.get()));
278 scoped_ptr<Window> window2(CreateTestWindowWithId(2, GetContext()));
279 scoped_ptr<Window> window3(CreateTestWindowWithId(3, GetContext()));
280
281 EXPECT_EQ("1 11 12 13 2 3", ChildWindowIDsAsString(GetContext()));
282
283 // Remove the delegates of a couple of transients, as if they are closing
284 // and animating out.
285 window11->layer()->set_delegate(NULL);
286 window13->layer()->set_delegate(NULL);
287
288 // Move window1 to the front. All transients should move with it, and their
289 // order should be preserved.
290 GetContext()->StackChildAtTop(window1.get());
291
292 EXPECT_EQ("2 3 1 11 12 13", ChildWindowIDsAsString(GetContext()));
293 }
294
295 TEST_F(TransientWindowManagerTest,
296 StackTransientsLayersRelativeToOtherTransients) {
297 // Create a window with several transients, then a couple windows on top.
298 scoped_ptr<Window> window1(CreateTestWindowWithId(1, GetContext()));
299 scoped_ptr<Window> window11(CreateTransientChild(11, window1.get()));
300 scoped_ptr<Window> window12(CreateTransientChild(12, window1.get()));
301 scoped_ptr<Window> window13(CreateTransientChild(13, window1.get()));
302
303 EXPECT_EQ("1 11 12 13", ChildWindowIDsAsString(GetContext()));
304
305 // Stack 11 above 12.
306 GetContext()->StackChildAbove(window11.get(), window12.get());
307 EXPECT_EQ("1 12 11 13", ChildWindowIDsAsString(GetContext()));
308
309 // Stack 13 below 12.
310 GetContext()->StackChildBelow(window13.get(), window12.get());
311 EXPECT_EQ("1 13 12 11", ChildWindowIDsAsString(GetContext()));
312
313 // Stack 11 above 1.
314 GetContext()->StackChildAbove(window11.get(), window1.get());
315 EXPECT_EQ("1 11 13 12", ChildWindowIDsAsString(GetContext()));
316
317 // Stack 12 below 13.
318 GetContext()->StackChildBelow(window12.get(), window13.get());
319 EXPECT_EQ("1 11 12 13", ChildWindowIDsAsString(GetContext()));
320 }
321
322 TEST_F(TransientWindowManagerTest,
323 StackTransientsLayersRelativeToOtherTransientsNoLayerDelegate) {
324 // Create a window with several transients, then a couple windows on top.
325 scoped_ptr<Window> window1(CreateTestWindowWithId(1, GetContext()));
326 scoped_ptr<Window> window11(CreateTransientChild(11, window1.get()));
327 scoped_ptr<Window> window12(CreateTransientChild(12, window1.get()));
328 scoped_ptr<Window> window13(CreateTransientChild(13, window1.get()));
329 scoped_ptr<Window> window2(CreateTestWindowWithId(2, GetContext()));
330 scoped_ptr<Window> window3(CreateTestWindowWithId(3, GetContext()));
331
332 EXPECT_EQ("1 11 12 13 2 3", ChildWindowIDsAsString(GetContext()));
333
334 window1->layer()->set_delegate(NULL);
335
336 // Stack 1 at top.
337 GetContext()->StackChildAtTop(window1.get());
338 EXPECT_EQ("2 3 1 11 12 13", ChildWindowIDsAsString(GetContext()));
339 }
340
341 class StackingMadrigalLayoutManager : public aura::LayoutManager {
342 public:
343 explicit StackingMadrigalLayoutManager(Window* root_window)
344 : root_window_(root_window) {
345 root_window_->SetLayoutManager(this);
346 }
347 virtual ~StackingMadrigalLayoutManager() {
348 }
349
350 private:
351 // Overridden from LayoutManager:
352 virtual void OnWindowResized() OVERRIDE {}
353 virtual void OnWindowAddedToLayout(Window* child) OVERRIDE {}
354 virtual void OnWillRemoveWindowFromLayout(Window* child) OVERRIDE {}
355 virtual void OnWindowRemovedFromLayout(Window* child) OVERRIDE {}
356 virtual void OnChildWindowVisibilityChanged(Window* child,
357 bool visible) OVERRIDE {
358 Window::Windows::const_iterator it = root_window_->children().begin();
359 Window* last_window = NULL;
360 for (; it != root_window_->children().end(); ++it) {
361 if (*it == child && last_window) {
362 if (!visible)
363 root_window_->StackChildAbove(last_window, *it);
364 else
365 root_window_->StackChildAbove(*it, last_window);
366 break;
367 }
368 last_window = *it;
369 }
370 }
371 virtual void SetChildBounds(Window* child,
372 const gfx::Rect& requested_bounds) OVERRIDE {
373 SetChildBoundsDirect(child, requested_bounds);
374 }
375
376 Window* root_window_;
377
378 DISALLOW_COPY_AND_ASSIGN(StackingMadrigalLayoutManager);
379 };
380
381 class StackingMadrigalVisibilityClient : public aura::client::VisibilityClient {
382 public:
383 explicit StackingMadrigalVisibilityClient(Window* root_window)
384 : ignored_window_(NULL) {
385 aura::client::SetVisibilityClient(root_window, this);
386 }
387 virtual ~StackingMadrigalVisibilityClient() {
388 }
389
390 void set_ignored_window(Window* ignored_window) {
391 ignored_window_ = ignored_window;
392 }
393
394 private:
395 // Overridden from client::VisibilityClient:
396 virtual void UpdateLayerVisibility(Window* window, bool visible) OVERRIDE {
397 if (!visible) {
398 if (window == ignored_window_)
399 window->layer()->set_delegate(NULL);
400 else
401 window->layer()->SetVisible(visible);
402 } else {
403 window->layer()->SetVisible(visible);
404 }
405 }
406
407 Window* ignored_window_;
408
409 DISALLOW_COPY_AND_ASSIGN(StackingMadrigalVisibilityClient);
410 };
411
412 // This test attempts to reconstruct a circumstance that can happen when the
413 // aura client attempts to manipulate the visibility and delegate of a layer
414 // independent of window visibility.
415 // A use case is where the client attempts to keep a window visible onscreen
416 // even after code has called Hide() on the window. The use case for this would
417 // be that window hides are animated (e.g. the window fades out). To prevent
418 // spurious updating the client code may also clear window's layer's delegate,
419 // so that the window cannot attempt to paint or update it further. The window
420 // uses the presence of a NULL layer delegate as a signal in stacking to note
421 // that the window is being manipulated by such a use case and its stacking
422 // should not be adjusted.
423 // One issue that can arise when a window opens two transient children, and the
424 // first is hidden. Subsequent attempts to activate the transient parent can
425 // result in the transient parent being stacked above the second transient
426 // child. A fix is made to Window::StackAbove to prevent this, and this test
427 // verifies this fix.
428 TEST_F(TransientWindowManagerTest, StackingMadrigal) {
429 new StackingMadrigalLayoutManager(GetContext());
430 StackingMadrigalVisibilityClient visibility_client(GetContext());
431
432 scoped_ptr<Window> window1(CreateTestWindowWithId(1, GetContext()));
433 scoped_ptr<Window> window11(CreateTransientChild(11, window1.get()));
434
435 visibility_client.set_ignored_window(window11.get());
436
437 window11->Show();
438 window11->Hide();
439
440 // As a transient, window11 should still be stacked above window1, even when
441 // hidden.
442 EXPECT_TRUE(aura::test::WindowIsAbove(window11.get(), window1.get()));
443 EXPECT_TRUE(aura::test::LayerIsAbove(window11.get(), window1.get()));
444
445 // A new transient should still be above window1. It will appear behind
446 // window11 because we don't stack windows on top of targets with NULL
447 // delegates.
448 scoped_ptr<Window> window12(CreateTransientChild(12, window1.get()));
449 window12->Show();
450
451 EXPECT_TRUE(aura::test::WindowIsAbove(window12.get(), window1.get()));
452 EXPECT_TRUE(aura::test::LayerIsAbove(window12.get(), window1.get()));
453
454 // In earlier versions of the StackChildAbove() method, attempting to stack
455 // window1 above window12 at this point would actually restack the layers
456 // resulting in window12's layer being below window1's layer (though the
457 // windows themselves would still be correctly stacked, so events would pass
458 // through.)
459 GetContext()->StackChildAbove(window1.get(), window12.get());
460
461 // Both window12 and its layer should be stacked above window1.
462 EXPECT_TRUE(aura::test::WindowIsAbove(window12.get(), window1.get()));
463 EXPECT_TRUE(aura::test::LayerIsAbove(window12.get(), window1.get()));
464 }
465
466 // Test for an issue where attempting to stack a primary window on top of a
467 // transient with a NULL layer delegate causes that primary window to be moved,
468 // but the layer order not changed to match. http://crbug.com/112562
469 TEST_F(TransientWindowManagerTest, StackOverClosingTransient) {
470 scoped_ptr<Window> window1(CreateTestWindowWithId(1, GetContext()));
471 scoped_ptr<Window> transient1(CreateTransientChild(11, window1.get()));
472 scoped_ptr<Window> window2(CreateTestWindowWithId(2, GetContext()));
473 scoped_ptr<Window> transient2(CreateTransientChild(21, window2.get()));
474
475 // Both windows and layers are stacked in creation order.
476 Window* root = GetContext();
477 ASSERT_EQ(4u, root->children().size());
478 EXPECT_EQ(root->children()[0], window1.get());
479 EXPECT_EQ(root->children()[1], transient1.get());
480 EXPECT_EQ(root->children()[2], window2.get());
481 EXPECT_EQ(root->children()[3], transient2.get());
482 ASSERT_EQ(4u, root->layer()->children().size());
483 EXPECT_EQ(root->layer()->children()[0], window1->layer());
484 EXPECT_EQ(root->layer()->children()[1], transient1->layer());
485 EXPECT_EQ(root->layer()->children()[2], window2->layer());
486 EXPECT_EQ(root->layer()->children()[3], transient2->layer());
487 EXPECT_EQ("1 11 2 21", ChildWindowIDsAsString(GetContext()));
488
489 // This brings window1 and its transient to the front.
490 root->StackChildAtTop(window1.get());
491 EXPECT_EQ("2 21 1 11", ChildWindowIDsAsString(GetContext()));
492
493 EXPECT_EQ(root->children()[0], window2.get());
494 EXPECT_EQ(root->children()[1], transient2.get());
495 EXPECT_EQ(root->children()[2], window1.get());
496 EXPECT_EQ(root->children()[3], transient1.get());
497 EXPECT_EQ(root->layer()->children()[0], window2->layer());
498 EXPECT_EQ(root->layer()->children()[1], transient2->layer());
499 EXPECT_EQ(root->layer()->children()[2], window1->layer());
500 EXPECT_EQ(root->layer()->children()[3], transient1->layer());
501
502 // Pretend we're closing the top-most transient, then bring window2 to the
503 // front. This mimics activating a browser window while the status bubble
504 // is fading out. The transient should stay topmost.
505 transient1->layer()->set_delegate(NULL);
506 root->StackChildAtTop(window2.get());
507
508 EXPECT_EQ(root->children()[0], window1.get());
509 EXPECT_EQ(root->children()[1], window2.get());
510 EXPECT_EQ(root->children()[2], transient2.get());
511 EXPECT_EQ(root->children()[3], transient1.get());
512 EXPECT_EQ(root->layer()->children()[0], window1->layer());
513 EXPECT_EQ(root->layer()->children()[1], window2->layer());
514 EXPECT_EQ(root->layer()->children()[2], transient2->layer());
515 EXPECT_EQ(root->layer()->children()[3], transient1->layer());
516
517 // Close the transient. Remaining windows are stable.
518 transient1.reset();
519
520 ASSERT_EQ(3u, root->children().size());
521 EXPECT_EQ(root->children()[0], window1.get());
522 EXPECT_EQ(root->children()[1], window2.get());
523 EXPECT_EQ(root->children()[2], transient2.get());
524 ASSERT_EQ(3u, root->layer()->children().size());
525 EXPECT_EQ(root->layer()->children()[0], window1->layer());
526 EXPECT_EQ(root->layer()->children()[1], window2->layer());
527 EXPECT_EQ(root->layer()->children()[2], transient2->layer());
528
529 // Open another window on top.
530 scoped_ptr<Window> window3(CreateTestWindowWithId(3, GetContext()));
531
532 ASSERT_EQ(4u, root->children().size());
533 EXPECT_EQ(root->children()[0], window1.get());
534 EXPECT_EQ(root->children()[1], window2.get());
535 EXPECT_EQ(root->children()[2], transient2.get());
536 EXPECT_EQ(root->children()[3], window3.get());
537 ASSERT_EQ(4u, root->layer()->children().size());
538 EXPECT_EQ(root->layer()->children()[0], window1->layer());
539 EXPECT_EQ(root->layer()->children()[1], window2->layer());
540 EXPECT_EQ(root->layer()->children()[2], transient2->layer());
541 EXPECT_EQ(root->layer()->children()[3], window3->layer());
542
543 // Pretend we're closing the topmost non-transient window, then bring
544 // window2 to the top. It should not move.
545 window3->layer()->set_delegate(NULL);
546 root->StackChildAtTop(window2.get());
547
548 ASSERT_EQ(4u, root->children().size());
549 EXPECT_EQ(root->children()[0], window1.get());
550 EXPECT_EQ(root->children()[1], window2.get());
551 EXPECT_EQ(root->children()[2], transient2.get());
552 EXPECT_EQ(root->children()[3], window3.get());
553 ASSERT_EQ(4u, root->layer()->children().size());
554 EXPECT_EQ(root->layer()->children()[0], window1->layer());
555 EXPECT_EQ(root->layer()->children()[1], window2->layer());
556 EXPECT_EQ(root->layer()->children()[2], transient2->layer());
557 EXPECT_EQ(root->layer()->children()[3], window3->layer());
558
559 // Bring window1 to the top. It should move ahead of window2, but not
560 // ahead of window3 (with NULL delegate).
561 root->StackChildAtTop(window1.get());
562
563 ASSERT_EQ(4u, root->children().size());
564 EXPECT_EQ(root->children()[0], window2.get());
565 EXPECT_EQ(root->children()[1], transient2.get());
566 EXPECT_EQ(root->children()[2], window1.get());
567 EXPECT_EQ(root->children()[3], window3.get());
568 ASSERT_EQ(4u, root->layer()->children().size());
569 EXPECT_EQ(root->layer()->children()[0], window2->layer());
570 EXPECT_EQ(root->layer()->children()[1], transient2->layer());
571 EXPECT_EQ(root->layer()->children()[2], window1->layer());
572 EXPECT_EQ(root->layer()->children()[3], window3->layer());
573 }
574
575 } // namespace corewm
576 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698