| 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/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/transient_window_manager.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 20 matching lines...) Expand all Loading... |
| 40 scoped_ptr<Window> w1(CreateTestWindowWithId(1, parent.get())); | 42 scoped_ptr<Window> w1(CreateTestWindowWithId(1, parent.get())); |
| 41 Window* w11 = CreateTestWindowWithId(11, parent.get()); | 43 Window* w11 = CreateTestWindowWithId(11, parent.get()); |
| 42 scoped_ptr<Window> w2(CreateTestWindowWithId(2, parent.get())); | 44 scoped_ptr<Window> w2(CreateTestWindowWithId(2, parent.get())); |
| 43 Window* w21 = CreateTestWindowWithId(21, parent.get()); | 45 Window* w21 = CreateTestWindowWithId(21, parent.get()); |
| 44 Window* w211 = CreateTestWindowWithId(211, parent.get()); | 46 Window* w211 = CreateTestWindowWithId(211, parent.get()); |
| 45 Window* w212 = CreateTestWindowWithId(212, parent.get()); | 47 Window* w212 = CreateTestWindowWithId(212, parent.get()); |
| 46 Window* w213 = CreateTestWindowWithId(213, parent.get()); | 48 Window* w213 = CreateTestWindowWithId(213, parent.get()); |
| 47 Window* w22 = CreateTestWindowWithId(22, parent.get()); | 49 Window* w22 = CreateTestWindowWithId(22, parent.get()); |
| 48 ASSERT_EQ(8u, parent->children().size()); | 50 ASSERT_EQ(8u, parent->children().size()); |
| 49 | 51 |
| 50 w1->AddTransientChild(w11); // w11 is now owned by w1. | 52 AddTransientChild(w1.get(), w11); // w11 is now owned by w1. |
| 51 w2->AddTransientChild(w21); // w21 is now owned by w2. | 53 AddTransientChild(w2.get(), w21); // w21 is now owned by w2. |
| 52 w2->AddTransientChild(w22); // w22 is now owned by w2. | 54 AddTransientChild(w2.get(), w22); // w22 is now owned by w2. |
| 53 w21->AddTransientChild(w211); // w211 is now owned by w21. | 55 AddTransientChild(w21, w211); // w211 is now owned by w21. |
| 54 w21->AddTransientChild(w212); // w212 is now owned by w21. | 56 AddTransientChild(w21, w212); // w212 is now owned by w21. |
| 55 w21->AddTransientChild(w213); // w213 is now owned by w21. | 57 AddTransientChild(w21, w213); // w213 is now owned by w21. |
| 56 EXPECT_EQ("1 11 2 21 211 212 213 22", ChildWindowIDsAsString(parent.get())); | 58 EXPECT_EQ("1 11 2 21 211 212 213 22", ChildWindowIDsAsString(parent.get())); |
| 57 | 59 |
| 58 // Stack w1 at the top (end), this should force w11 to be last (on top of w1). | 60 // Stack w1 at the top (end), this should force w11 to be last (on top of w1). |
| 59 parent->StackChildAtTop(w1.get()); | 61 parent->StackChildAtTop(w1.get()); |
| 60 EXPECT_EQ(w11, parent->children().back()); | 62 EXPECT_EQ(w11, parent->children().back()); |
| 61 EXPECT_EQ("2 21 211 212 213 22 1 11", ChildWindowIDsAsString(parent.get())); | 63 EXPECT_EQ("2 21 211 212 213 22 1 11", ChildWindowIDsAsString(parent.get())); |
| 62 | 64 |
| 63 // This tests that the order in children_ array rather than in | 65 // This tests that the order in children_ array rather than in |
| 64 // transient_children_ array is used when reinserting transient children. | 66 // transient_children_ array is used when reinserting transient children. |
| 65 // If transient_children_ array was used '22' would be following '21'. | 67 // If transient_children_ array was used '22' would be following '21'. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 scoped_ptr<Window> w1(CreateTestWindowWithId(1, parent.get())); | 112 scoped_ptr<Window> w1(CreateTestWindowWithId(1, parent.get())); |
| 111 Window* w11 = CreateTestWindowWithId(11, parent.get()); | 113 Window* w11 = CreateTestWindowWithId(11, parent.get()); |
| 112 scoped_ptr<Window> w2(CreateTestWindowWithId(2, parent.get())); | 114 scoped_ptr<Window> w2(CreateTestWindowWithId(2, parent.get())); |
| 113 Window* w21 = CreateTestWindowWithId(21, parent.get()); | 115 Window* w21 = CreateTestWindowWithId(21, parent.get()); |
| 114 Window* w211 = CreateTestWindowWithId(211, parent.get()); | 116 Window* w211 = CreateTestWindowWithId(211, parent.get()); |
| 115 Window* w212 = CreateTestWindowWithId(212, parent.get()); | 117 Window* w212 = CreateTestWindowWithId(212, parent.get()); |
| 116 Window* w213 = CreateTestWindowWithId(213, parent.get()); | 118 Window* w213 = CreateTestWindowWithId(213, parent.get()); |
| 117 Window* w22 = CreateTestWindowWithId(22, parent.get()); | 119 Window* w22 = CreateTestWindowWithId(22, parent.get()); |
| 118 ASSERT_EQ(8u, parent->children().size()); | 120 ASSERT_EQ(8u, parent->children().size()); |
| 119 | 121 |
| 120 w1->AddTransientChild(w11); // w11 is now owned by w1. | 122 AddTransientChild(w1.get(), w11); // w11 is now owned by w1. |
| 121 w2->AddTransientChild(w21); // w21 is now owned by w2. | 123 AddTransientChild(w2.get(), w21); // w21 is now owned by w2. |
| 122 w2->AddTransientChild(w22); // w22 is now owned by w2. | 124 AddTransientChild(w2.get(), w22); // w22 is now owned by w2. |
| 123 w21->AddTransientChild(w211); // w211 is now owned by w21. | 125 AddTransientChild(w21, w211); // w211 is now owned by w21. |
| 124 w21->AddTransientChild(w212); // w212 is now owned by w21. | 126 AddTransientChild(w21, w212); // w212 is now owned by w21. |
| 125 w21->AddTransientChild(w213); // w213 is now owned by w21. | 127 AddTransientChild(w21, w213); // w213 is now owned by w21. |
| 126 EXPECT_EQ("1 11 2 21 211 212 213 22", ChildWindowIDsAsString(parent.get())); | 128 EXPECT_EQ("1 11 2 21 211 212 213 22", ChildWindowIDsAsString(parent.get())); |
| 127 | 129 |
| 128 // Stack w2 at the bottom, this should force w11 to be last (on top of w1). | 130 // Stack w2 at the bottom, this should force w11 to be last (on top of w1). |
| 129 // This also tests that the order in children_ array rather than in | 131 // This also tests that the order in children_ array rather than in |
| 130 // transient_children_ array is used when reinserting transient children. | 132 // transient_children_ array is used when reinserting transient children. |
| 131 // If transient_children_ array was used '22' would be following '21'. | 133 // If transient_children_ array was used '22' would be following '21'. |
| 132 parent->StackChildAtBottom(w2.get()); | 134 parent->StackChildAtBottom(w2.get()); |
| 133 EXPECT_EQ(w11, parent->children().back()); | 135 EXPECT_EQ(w11, parent->children().back()); |
| 134 EXPECT_EQ("2 21 211 212 213 22 1 11", ChildWindowIDsAsString(parent.get())); | 136 EXPECT_EQ("2 21 211 212 213 22 1 11", ChildWindowIDsAsString(parent.get())); |
| 135 | 137 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 164 | 166 |
| 165 parent->StackChildBelow(w1.get(), w2.get()); | 167 parent->StackChildBelow(w1.get(), w2.get()); |
| 166 EXPECT_EQ(w212, parent->children().back()); | 168 EXPECT_EQ(w212, parent->children().back()); |
| 167 EXPECT_EQ("1 11 2 22 21 213 211 212", ChildWindowIDsAsString(parent.get())); | 169 EXPECT_EQ("1 11 2 22 21 213 211 212", ChildWindowIDsAsString(parent.get())); |
| 168 | 170 |
| 169 parent->StackChildBelow(w213, w11); | 171 parent->StackChildBelow(w213, w11); |
| 170 EXPECT_EQ(w11, parent->children().back()); | 172 EXPECT_EQ(w11, parent->children().back()); |
| 171 EXPECT_EQ("2 22 21 213 211 212 1 11", ChildWindowIDsAsString(parent.get())); | 173 EXPECT_EQ("2 22 21 213 211 212 1 11", ChildWindowIDsAsString(parent.get())); |
| 172 } | 174 } |
| 173 | 175 |
| 176 TEST_F(TransientWindowStackingClientTest, |
| 177 StackWindowsWhoseLayersHaveNoDelegate) { |
| 178 scoped_ptr<Window> window1(CreateTestWindowWithId(1, root_window())); |
| 179 window1->layer()->set_name("1"); |
| 180 scoped_ptr<Window> window2(CreateTestWindowWithId(2, root_window())); |
| 181 window2->layer()->set_name("2"); |
| 182 scoped_ptr<Window> window3(CreateTestWindowWithId(3, root_window())); |
| 183 window3->layer()->set_name("3"); |
| 184 |
| 185 // This brings |window1| (and its layer) to the front. |
| 186 root_window()->StackChildAbove(window1.get(), window3.get()); |
| 187 EXPECT_EQ("2 3 1", ChildWindowIDsAsString(root_window())); |
| 188 EXPECT_EQ("2 3 1", |
| 189 ui::test::ChildLayerNamesAsString(*root_window()->layer())); |
| 190 |
| 191 // Since |window1| does not have a delegate, |window2| should not move in |
| 192 // front of it, nor should its layer. |
| 193 window1->layer()->set_delegate(NULL); |
| 194 root_window()->StackChildAbove(window2.get(), window1.get()); |
| 195 EXPECT_EQ("3 2 1", ChildWindowIDsAsString(root_window())); |
| 196 EXPECT_EQ("3 2 1", |
| 197 ui::test::ChildLayerNamesAsString(*root_window()->layer())); |
| 198 |
| 199 // It should still be possible to stack |window3| immediately below |window1|. |
| 200 root_window()->StackChildBelow(window3.get(), window1.get()); |
| 201 EXPECT_EQ("2 3 1", ChildWindowIDsAsString(root_window())); |
| 202 EXPECT_EQ("2 3 1", |
| 203 ui::test::ChildLayerNamesAsString(*root_window()->layer())); |
| 204 |
| 205 // Since neither |window3| nor |window1| have a delegate, |window2| should |
| 206 // not move in front of either. |
| 207 window3->layer()->set_delegate(NULL); |
| 208 root_window()->StackChildBelow(window2.get(), window1.get()); |
| 209 EXPECT_EQ("2 3 1", ChildWindowIDsAsString(root_window())); |
| 210 EXPECT_EQ("2 3 1", |
| 211 ui::test::ChildLayerNamesAsString(*root_window()->layer())); |
| 212 } |
| 213 |
| 174 } // namespace corewm | 214 } // namespace corewm |
| 175 } // namespace views | 215 } // namespace views |
| OLD | NEW |