OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "athena/wm/window_list_provider_impl.h" | 5 #include "athena/wm/window_list_provider_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "athena/test/athena_test_base.h" | 9 #include "athena/test/athena_test_base.h" |
10 #include "ui/aura/test/test_window_delegate.h" | 10 #include "ui/aura/test/test_window_delegate.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 } | 21 } |
22 | 22 |
23 scoped_ptr<aura::Window> CreateWindow(aura::WindowDelegate* delegate, | 23 scoped_ptr<aura::Window> CreateWindow(aura::WindowDelegate* delegate, |
24 ui::wm::WindowType window_type) { | 24 ui::wm::WindowType window_type) { |
25 scoped_ptr<aura::Window> window(new aura::Window(delegate)); | 25 scoped_ptr<aura::Window> window(new aura::Window(delegate)); |
26 window->SetType(window_type); | 26 window->SetType(window_type); |
27 window->Init(aura::WINDOW_LAYER_SOLID_COLOR); | 27 window->Init(aura::WINDOW_LAYER_SOLID_COLOR); |
28 return window.Pass(); | 28 return window.Pass(); |
29 } | 29 } |
30 | 30 |
| 31 // Return a string which defines the order of windows in |now| using the indices |
| 32 // of |original|. The string will then have the lowest/oldest window on the left |
| 33 // and the highest / newest on the right. |
| 34 std::string GetWindowOrder(const aura::Window::Windows& original, |
| 35 const aura::Window::Windows& now) { |
| 36 if (original.size() != now.size()) |
| 37 return "size has changed."; |
| 38 std::string output; |
| 39 for (aura::Window::Windows::const_iterator it = now.begin(); |
| 40 it != now.end(); ++it) { |
| 41 for (size_t i = 0; i < original.size(); i++) { |
| 42 if ((*it) == original[i]) { |
| 43 output += (output.size() ? " " : "") + std::to_string(i + 1); |
| 44 break; |
| 45 } |
| 46 } |
| 47 } |
| 48 return output; |
| 49 } |
| 50 |
31 } // namespace | 51 } // namespace |
32 | 52 |
33 typedef test::AthenaTestBase WindowListProviderImplTest; | 53 typedef test::AthenaTestBase WindowListProviderImplTest; |
34 | 54 |
35 // Tests that the order of windows match the stacking order of the windows in | 55 // Tests that the order of windows match the stacking order of the windows in |
36 // the container, even after the order is changed through the aura Window API. | 56 // the container, even after the order is changed through the aura Window API. |
37 TEST_F(WindowListProviderImplTest, StackingOrder) { | 57 TEST_F(WindowListProviderImplTest, StackingOrder) { |
38 aura::test::TestWindowDelegate delegate; | 58 aura::test::TestWindowDelegate delegate; |
39 scoped_ptr<aura::Window> container(new aura::Window(&delegate)); | 59 scoped_ptr<aura::Window> container(new aura::Window(&delegate)); |
40 scoped_ptr<aura::Window> first = | 60 scoped_ptr<aura::Window> first = |
41 CreateWindow(&delegate, ui::wm::WINDOW_TYPE_NORMAL); | 61 CreateWindow(&delegate, ui::wm::WINDOW_TYPE_NORMAL); |
42 scoped_ptr<aura::Window> second = | 62 scoped_ptr<aura::Window> second = |
43 CreateWindow(&delegate, ui::wm::WINDOW_TYPE_NORMAL); | 63 CreateWindow(&delegate, ui::wm::WINDOW_TYPE_NORMAL); |
44 scoped_ptr<aura::Window> third = | 64 scoped_ptr<aura::Window> third = |
45 CreateWindow(&delegate, ui::wm::WINDOW_TYPE_NORMAL); | 65 CreateWindow(&delegate, ui::wm::WINDOW_TYPE_NORMAL); |
46 container->AddChild(first.get()); | 66 container->AddChild(first.get()); |
47 container->AddChild(second.get()); | 67 container->AddChild(second.get()); |
48 container->AddChild(third.get()); | 68 container->AddChild(third.get()); |
49 | 69 |
50 scoped_ptr<WindowListProvider> list_provider( | 70 scoped_ptr<WindowListProvider> list_provider( |
51 new WindowListProviderImpl(container.get())); | 71 new WindowListProviderImpl(container.get())); |
52 EXPECT_TRUE(AreWindowListsEqual(container->children(), | 72 EXPECT_TRUE(AreWindowListsEqual(container->children(), |
53 list_provider->GetWindowList())); | 73 list_provider->GetCurrentWindowList())); |
54 | 74 |
55 container->StackChildAtTop(first.get()); | 75 container->StackChildAtTop(first.get()); |
56 EXPECT_TRUE(AreWindowListsEqual(container->children(), | 76 EXPECT_TRUE(AreWindowListsEqual(container->children(), |
57 list_provider->GetWindowList())); | 77 list_provider->GetCurrentWindowList())); |
58 EXPECT_EQ(first.get(), container->children().back()); | 78 EXPECT_EQ(first.get(), container->children().back()); |
59 } | 79 } |
60 | 80 |
| 81 // Tests that only normal windows of the associated container will be listed. |
61 TEST_F(WindowListProviderImplTest, ListContainsOnlyNormalWindows) { | 82 TEST_F(WindowListProviderImplTest, ListContainsOnlyNormalWindows) { |
62 aura::test::TestWindowDelegate delegate; | 83 aura::test::TestWindowDelegate delegate; |
63 scoped_ptr<aura::Window> container(new aura::Window(&delegate)); | 84 scoped_ptr<aura::Window> container(new aura::Window(&delegate)); |
64 scoped_ptr<aura::Window> first = | 85 scoped_ptr<aura::Window> first = |
65 CreateWindow(&delegate, ui::wm::WINDOW_TYPE_NORMAL); | 86 CreateWindow(&delegate, ui::wm::WINDOW_TYPE_NORMAL); |
66 scoped_ptr<aura::Window> second = | 87 scoped_ptr<aura::Window> second = |
67 CreateWindow(&delegate, ui::wm::WINDOW_TYPE_POPUP); | 88 CreateWindow(&delegate, ui::wm::WINDOW_TYPE_POPUP); |
68 scoped_ptr<aura::Window> third = | 89 scoped_ptr<aura::Window> third = |
69 CreateWindow(&delegate, ui::wm::WINDOW_TYPE_NORMAL); | 90 CreateWindow(&delegate, ui::wm::WINDOW_TYPE_NORMAL); |
70 scoped_ptr<aura::Window> fourth = | 91 scoped_ptr<aura::Window> fourth = |
71 CreateWindow(&delegate, ui::wm::WINDOW_TYPE_MENU); | 92 CreateWindow(&delegate, ui::wm::WINDOW_TYPE_MENU); |
72 container->AddChild(first.get()); | 93 container->AddChild(first.get()); |
73 container->AddChild(second.get()); | 94 container->AddChild(second.get()); |
74 container->AddChild(third.get()); | 95 container->AddChild(third.get()); |
75 container->AddChild(fourth.get()); | 96 container->AddChild(fourth.get()); |
76 | 97 |
77 scoped_ptr<WindowListProvider> list_provider( | 98 scoped_ptr<WindowListProvider> list_provider( |
78 new WindowListProviderImpl(container.get())); | 99 new WindowListProviderImpl(container.get())); |
79 const aura::Window::Windows list = list_provider->GetWindowList(); | 100 |
| 101 const aura::Window::Windows list = list_provider->GetCurrentWindowList(); |
80 EXPECT_EQ(list.end(), std::find(list.begin(), list.end(), second.get())); | 102 EXPECT_EQ(list.end(), std::find(list.begin(), list.end(), second.get())); |
81 EXPECT_EQ(list.end(), std::find(list.begin(), list.end(), fourth.get())); | 103 EXPECT_EQ(list.end(), std::find(list.begin(), list.end(), fourth.get())); |
82 EXPECT_NE(list.end(), std::find(list.begin(), list.end(), first.get())); | 104 EXPECT_NE(list.end(), std::find(list.begin(), list.end(), first.get())); |
83 EXPECT_NE(list.end(), std::find(list.begin(), list.end(), third.get())); | 105 EXPECT_NE(list.end(), std::find(list.begin(), list.end(), third.get())); |
84 } | 106 } |
85 | 107 |
| 108 // Testing that IsValidWidow, IsWindowInList and AddWindow work as expected. |
| 109 TEST_F(WindowListProviderImplTest, SimpleChecks) { |
| 110 aura::test::TestWindowDelegate delegate; |
| 111 scoped_ptr<aura::Window> container(new aura::Window(&delegate)); |
| 112 |
| 113 scoped_ptr<aura::Window> normal_window = |
| 114 CreateWindow(&delegate, ui::wm::WINDOW_TYPE_NORMAL); |
| 115 scoped_ptr<aura::Window> popup_window = |
| 116 CreateWindow(&delegate, ui::wm::WINDOW_TYPE_POPUP); |
| 117 scoped_ptr<aura::Window> menu_window = |
| 118 CreateWindow(&delegate, ui::wm::WINDOW_TYPE_MENU); |
| 119 |
| 120 scoped_ptr<WindowListProvider> list_provider( |
| 121 new WindowListProviderImpl(container.get())); |
| 122 |
| 123 // Check which windows are valid and which are not. |
| 124 EXPECT_TRUE(list_provider->IsValidWindow(normal_window.get())); |
| 125 EXPECT_FALSE(list_provider->IsValidWindow(popup_window.get())); |
| 126 EXPECT_FALSE(list_provider->IsValidWindow(menu_window.get())); |
| 127 |
| 128 // Check that no window is currently in the list. |
| 129 EXPECT_FALSE(list_provider->IsWindowInList(normal_window.get())); |
| 130 EXPECT_FALSE(list_provider->IsWindowInList(popup_window.get())); |
| 131 EXPECT_FALSE(list_provider->IsWindowInList(menu_window.get())); |
| 132 |
| 133 // Check that adding the window will add it to the list. |
| 134 list_provider->AddWindow(normal_window.get()); |
| 135 EXPECT_TRUE(list_provider->IsWindowInList(normal_window.get())); |
| 136 } |
| 137 |
| 138 // Testing that window ordering functions work as expected. |
| 139 TEST_F(WindowListProviderImplTest, TestWindowOrderingFunctions) { |
| 140 aura::test::TestWindowDelegate delegate; |
| 141 scoped_ptr<aura::Window> container(new aura::Window(&delegate)); |
| 142 |
| 143 scoped_ptr<aura::Window> window1 = |
| 144 CreateWindow(&delegate, ui::wm::WINDOW_TYPE_NORMAL); |
| 145 scoped_ptr<aura::Window> window2 = |
| 146 CreateWindow(&delegate, ui::wm::WINDOW_TYPE_NORMAL); |
| 147 scoped_ptr<aura::Window> window3 = |
| 148 CreateWindow(&delegate, ui::wm::WINDOW_TYPE_NORMAL); |
| 149 |
| 150 scoped_ptr<WindowListProvider> list_provider( |
| 151 new WindowListProviderImpl(container.get())); |
| 152 |
| 153 EXPECT_FALSE(list_provider->IsWindowInList(window1.get())); |
| 154 EXPECT_FALSE(list_provider->IsWindowInList(window2.get())); |
| 155 EXPECT_FALSE(list_provider->IsWindowInList(window3.get())); |
| 156 |
| 157 // Add the windows. |
| 158 list_provider->AddWindow(window1.get()); |
| 159 list_provider->AddWindow(window2.get()); |
| 160 list_provider->AddWindow(window3.get()); |
| 161 aura::Window::Windows original_order = list_provider->GetCurrentWindowList(); |
| 162 ASSERT_EQ(3U, original_order.size()); |
| 163 EXPECT_EQ(original_order[0], window1.get()); |
| 164 EXPECT_EQ(original_order[1], window2.get()); |
| 165 EXPECT_EQ(original_order[2], window3.get()); |
| 166 |
| 167 // Move 2 to the front. |
| 168 list_provider->MoveToFront(window2.get()); |
| 169 EXPECT_EQ("1 3 2", GetWindowOrder(original_order, |
| 170 list_provider->GetCurrentWindowList())); |
| 171 |
| 172 // Move 2 to the front again. Should not change anything. |
| 173 list_provider->MoveToFront(window2.get()); |
| 174 EXPECT_EQ("1 3 2", GetWindowOrder(original_order, |
| 175 list_provider->GetCurrentWindowList())); |
| 176 |
| 177 // Move 1 (from the back) in front of 2. |
| 178 list_provider->MoveWindowInFrontOfReferenceWindow(window1.get(), |
| 179 window3.get()); |
| 180 EXPECT_EQ("3 1 2", GetWindowOrder(original_order, |
| 181 list_provider->GetCurrentWindowList())); |
| 182 |
| 183 // Move 2 (from the front) in front of 3. |
| 184 list_provider->MoveWindowInFrontOfReferenceWindow(window2.get(), |
| 185 window3.get()); |
| 186 EXPECT_EQ("3 2 1", GetWindowOrder(original_order, |
| 187 list_provider->GetCurrentWindowList())); |
| 188 } |
| 189 |
86 } // namespace athena | 190 } // namespace athena |
OLD | NEW |