Index: ash/shelf/shelf_window_watcher_unittest.cc |
diff --git a/ash/shelf/shelf_window_watcher_unittest.cc b/ash/shelf/shelf_window_watcher_unittest.cc |
index 606e7be629fb3eecc6f97c8ef20285e59da66bb2..af41ee8776064e9c159b8d0d818745d22ab3843d 100644 |
--- a/ash/shelf/shelf_window_watcher_unittest.cc |
+++ b/ash/shelf/shelf_window_watcher_unittest.cc |
@@ -54,7 +54,30 @@ class ShelfWindowWatcherTest : public test::AshTestBase { |
DISALLOW_COPY_AND_ASSIGN(ShelfWindowWatcherTest); |
}; |
-TEST_F(ShelfWindowWatcherTest, CreateAndRemoveShelfItem) { |
+// Tests that shelf items are removed as windows are closed. |
+TEST_F(ShelfWindowWatcherTest, OpenAndClose) { |
+ // ShelfModel only has an APP_LIST item. |
+ EXPECT_EQ(1, model_->item_count()); |
+ |
+ std::unique_ptr<aura::Window> w1(CreateTestWindowInShellWithId(0)); |
+ std::unique_ptr<aura::Window> w2(CreateTestWindowInShellWithId(0)); |
+ |
+ // Create a ShelfItem for w1. |
msw
2016/07/27 18:36:11
Is it possible to test that items are created when
James Cook
2016/07/27 20:14:06
Done (and thanks for the suggestion, it's better).
|
+ CreateShelfItem(w1.get()); |
+ EXPECT_EQ(2, model_->item_count()); |
+ |
+ // Create a ShelfItem for w2. |
+ CreateShelfItem(w2.get()); |
+ EXPECT_EQ(3, model_->item_count()); |
+ |
+ // Each ShelfItem is removed when the associated window is destroyed. |
+ w1.reset(); |
+ EXPECT_EQ(2, model_->item_count()); |
+ w2.reset(); |
+ EXPECT_EQ(1, model_->item_count()); |
+} |
+ |
+TEST_F(ShelfWindowWatcherTest, CreateAndRemoveShelfItemDetails) { |
// ShelfModel only has an APP_LIST item. |
EXPECT_EQ(1, model_->item_count()); |
@@ -75,12 +98,12 @@ TEST_F(ShelfWindowWatcherTest, CreateAndRemoveShelfItem) { |
int index_w2 = model_->ItemIndexByID(id_w2); |
EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w2].status); |
- // ShelfItem is removed when assoicated window is destroyed. |
+ // ShelfItem is removed when its window property is cleared. |
ClearShelfItemDetailsForWindow(w1.get()); |
EXPECT_EQ(2, model_->item_count()); |
ClearShelfItemDetailsForWindow(w2.get()); |
EXPECT_EQ(1, model_->item_count()); |
- // Clears twice doesn't do anything. |
+ // Clearing twice doesn't do anything. |
ClearShelfItemDetailsForWindow(w2.get()); |
EXPECT_EQ(1, model_->item_count()); |
} |
@@ -173,8 +196,8 @@ TEST_F(ShelfWindowWatcherTest, MaximizeAndRestoreWindow) { |
EXPECT_EQ(id, model_->items()[index].id); |
} |
-// Check that an item is removed when its associated Window is re-parented. |
-TEST_F(ShelfWindowWatcherTest, ReparentWindow) { |
+// Check that an item is maintained when its associated Window is docked. |
+TEST_F(ShelfWindowWatcherTest, DockWindow) { |
// ShelfModel only has an APP_LIST item. |
EXPECT_EQ(1, model_->item_count()); |
@@ -193,18 +216,17 @@ TEST_F(ShelfWindowWatcherTest, ReparentWindow) { |
Shell::GetContainer(root_window, kShellWindowId_DefaultContainer); |
EXPECT_EQ(default_container, window->parent()); |
- aura::Window* new_parent = |
- Shell::GetContainer(root_window, kShellWindowId_PanelContainer); |
+ aura::Window* docked_container = |
+ Shell::GetContainer(root_window, kShellWindowId_DockedContainer); |
- // Check |window|'s item is removed when it is re-parented to |new_parent| |
- // which is not default container. |
- new_parent->AddChild(window.get()); |
- EXPECT_EQ(1, model_->item_count()); |
- |
- // Check |window|'s item is added when it is re-parented to |
- // |default_container|. |
- default_container->AddChild(window.get()); |
+ // Check |window|'s item is not removed when it is re-parented to the dock. |
+ docked_container->AddChild(window.get()); |
EXPECT_EQ(2, model_->item_count()); |
+ |
+ // The shelf item is removed when the window is closed, even if it is in the |
+ // docked container at the time. |
+ window.reset(); |
+ EXPECT_EQ(1, model_->item_count()); |
} |
// Check |window|'s item is not changed during the dragging. |
@@ -235,47 +257,4 @@ TEST_F(ShelfWindowWatcherTest, DragWindow) { |
EXPECT_EQ(id, model_->items()[index].id); |
} |
-// Check |window|'s item is removed when it is re-parented not to default |
-// container during the dragging. |
-TEST_F(ShelfWindowWatcherTest, ReparentWindowDuringTheDragging) { |
- // ShelfModel only has an APP_LIST item. |
- EXPECT_EQ(1, model_->item_count()); |
- |
- std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); |
- window->set_owned_by_parent(false); |
- |
- // Create a ShelfItem for |window|. |
- ShelfID id = CreateShelfItem(window.get()); |
- EXPECT_EQ(2, model_->item_count()); |
- int index = model_->ItemIndexByID(id); |
- EXPECT_EQ(STATUS_RUNNING, model_->items()[index].status); |
- |
- aura::Window* root_window = window->GetRootWindow(); |
- aura::Window* default_container = |
- Shell::GetContainer(root_window, kShellWindowId_DefaultContainer); |
- EXPECT_EQ(default_container, window->parent()); |
- |
- aura::Window* new_parent = |
- Shell::GetContainer(root_window, kShellWindowId_PanelContainer); |
- |
- // Simulate re-parenting to |new_parent| during the dragging. |
- { |
- std::unique_ptr<WindowResizer> resizer( |
- CreateWindowResizer(WmWindowAura::Get(window.get()), gfx::Point(), |
- HTCAPTION, aura::client::WINDOW_MOVE_SOURCE_MOUSE)); |
- ASSERT_TRUE(resizer.get()); |
- resizer->Drag(gfx::Point(50, 50), 0); |
- resizer->CompleteDrag(); |
- EXPECT_EQ(2, model_->item_count()); |
- |
- // Item should be removed when |window| is re-parented not to default |
- // container before fininshing the dragging. |
- EXPECT_TRUE(wm::GetWindowState(window.get())->is_dragged()); |
- new_parent->AddChild(window.get()); |
- EXPECT_EQ(1, model_->item_count()); |
- } |
- EXPECT_FALSE(wm::GetWindowState(window.get())->is_dragged()); |
- EXPECT_EQ(1, model_->item_count()); |
-} |
- |
} // namespace ash |