OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "ash/common/shelf/shelf_window_watcher.h" | 5 #include "ash/common/shelf/shelf_window_watcher.h" |
6 | 6 |
7 #include "ash/common/session/session_controller.h" | 7 #include "ash/common/session/session_controller.h" |
8 #include "ash/common/shelf/shelf_model.h" | 8 #include "ash/common/shelf/shelf_model.h" |
9 #include "ash/common/wm/window_resizer.h" | 9 #include "ash/common/wm/window_resizer.h" |
10 #include "ash/common/wm/window_state.h" | 10 #include "ash/common/wm/window_state.h" |
11 #include "ash/common/wm_shell.h" | 11 #include "ash/common/wm_shell.h" |
12 #include "ash/common/wm_window.h" | 12 #include "ash/common/wm_window.h" |
13 #include "ash/public/cpp/shelf_item.h" | 13 #include "ash/public/cpp/shelf_item.h" |
14 #include "ash/public/cpp/shell_window_ids.h" | 14 #include "ash/public/cpp/shell_window_ids.h" |
15 #include "ash/public/cpp/window_properties.h" | 15 #include "ash/public/cpp/window_properties.h" |
16 #include "ash/root_window_controller.h" | 16 #include "ash/root_window_controller.h" |
17 #include "ash/shell.h" | 17 #include "ash/shell.h" |
18 #include "ash/test/ash_test_base.h" | 18 #include "ash/test/ash_test_base.h" |
19 #include "ui/aura/window.h" | 19 #include "ui/aura/window.h" |
20 #include "ui/base/hit_test.h" | 20 #include "ui/base/hit_test.h" |
21 #include "ui/compositor/layer_type.h" | |
22 #include "ui/views/widget/widget.h" | 21 #include "ui/views/widget/widget.h" |
23 | 22 |
24 namespace ash { | 23 namespace ash { |
25 | 24 |
26 class ShelfWindowWatcherTest : public test::AshTestBase { | 25 class ShelfWindowWatcherTest : public test::AshTestBase { |
27 public: | 26 public: |
28 ShelfWindowWatcherTest() : model_(nullptr) {} | 27 ShelfWindowWatcherTest() : model_(nullptr) {} |
29 ~ShelfWindowWatcherTest() override {} | 28 ~ShelfWindowWatcherTest() override {} |
30 | 29 |
31 void SetUp() override { | 30 void SetUp() override { |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 // Restore window |window|. | 217 // Restore window |window|. |
219 window_state->Restore(); | 218 window_state->Restore(); |
220 EXPECT_FALSE(window_state->IsMaximized()); | 219 EXPECT_FALSE(window_state->IsMaximized()); |
221 // No new item is created after restoring a window |window|. | 220 // No new item is created after restoring a window |window|. |
222 EXPECT_EQ(2, model_->item_count()); | 221 EXPECT_EQ(2, model_->item_count()); |
223 // Index and id are not changed after maximizing a window |window|. | 222 // Index and id are not changed after maximizing a window |window|. |
224 EXPECT_EQ(index, model_->ItemIndexByID(id)); | 223 EXPECT_EQ(index, model_->ItemIndexByID(id)); |
225 EXPECT_EQ(id, model_->items()[index].id); | 224 EXPECT_EQ(id, model_->items()[index].id); |
226 } | 225 } |
227 | 226 |
228 // Check that an item is maintained when its associated Window is docked. | |
229 TEST_F(ShelfWindowWatcherTest, DockWindow) { | |
230 // TODO: investigate failure in mash. http://crbug.com/695562. | |
231 if (WmShell::Get()->IsRunningInMash()) | |
232 return; | |
233 | |
234 // ShelfModel only has an APP_LIST item. | |
235 EXPECT_EQ(1, model_->item_count()); | |
236 | |
237 std::unique_ptr<views::Widget> widget = | |
238 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); | |
239 WmWindow* window = WmWindow::Get(widget->GetNativeWindow()); | |
240 | |
241 // Create a ShelfItem for |window|. | |
242 ShelfID id = CreateShelfItem(window); | |
243 EXPECT_EQ(2, model_->item_count()); | |
244 | |
245 int index = model_->ItemIndexByID(id); | |
246 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index].status); | |
247 | |
248 WmWindow* root_window = window->GetRootWindow(); | |
249 WmWindow* default_container = | |
250 root_window->GetChildByShellWindowId(kShellWindowId_DefaultContainer); | |
251 EXPECT_EQ(default_container, window->GetParent()); | |
252 | |
253 WmWindow* docked_container = | |
254 root_window->GetChildByShellWindowId(kShellWindowId_DockedContainer); | |
255 | |
256 // Check |window|'s item is not removed when it is re-parented to the dock. | |
257 docked_container->AddChild(window); | |
258 EXPECT_EQ(docked_container, window->GetParent()); | |
259 EXPECT_EQ(2, model_->item_count()); | |
260 | |
261 // The shelf item is removed when the window is closed, even if it is in the | |
262 // docked container at the time. | |
263 widget.reset(); | |
264 EXPECT_EQ(1, model_->item_count()); | |
265 } | |
266 | |
267 // Check |window|'s item is not changed during the dragging. | 227 // Check |window|'s item is not changed during the dragging. |
268 // TODO(simonhong): Add a test for removing a Window during the dragging. | 228 // TODO(simonhong): Add a test for removing a Window during the dragging. |
269 TEST_F(ShelfWindowWatcherTest, DragWindow) { | 229 TEST_F(ShelfWindowWatcherTest, DragWindow) { |
270 // TODO: investigate failure in mash. http://crbug.com/695562. | 230 // TODO: investigate failure in mash. http://crbug.com/695562. |
271 if (WmShell::Get()->IsRunningInMash()) | 231 if (WmShell::Get()->IsRunningInMash()) |
272 return; | 232 return; |
273 | 233 |
274 // ShelfModel only has an APP_LIST item. | 234 // ShelfModel only has an APP_LIST item. |
275 EXPECT_EQ(1, model_->item_count()); | 235 EXPECT_EQ(1, model_->item_count()); |
276 | 236 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 WmWindow* window = WmWindow::Get(widget->GetNativeWindow()); | 348 WmWindow* window = WmWindow::Get(widget->GetNativeWindow()); |
389 ShelfWindowWatcherTest::CreateShelfItem(window); | 349 ShelfWindowWatcherTest::CreateShelfItem(window); |
390 EXPECT_EQ(1, model->item_count()); | 350 EXPECT_EQ(1, model->item_count()); |
391 | 351 |
392 // Start the test user session; ShelfWindowWatcher will find the open window. | 352 // Start the test user session; ShelfWindowWatcher will find the open window. |
393 SetSessionStarted(true); | 353 SetSessionStarted(true); |
394 EXPECT_EQ(2, model->item_count()); | 354 EXPECT_EQ(2, model->item_count()); |
395 } | 355 } |
396 | 356 |
397 } // namespace ash | 357 } // namespace ash |
OLD | NEW |