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 1217aae2e5ecb048efa0850646722c290b2d25a9..dac0043ae9d360fc5bea600d23b6c923c3d33d41 100644 |
--- a/ash/shelf/shelf_window_watcher_unittest.cc |
+++ b/ash/shelf/shelf_window_watcher_unittest.cc |
@@ -8,12 +8,15 @@ |
#include "ash/shelf/shelf_model.h" |
#include "ash/shelf/shelf_util.h" |
#include "ash/shell.h" |
+#include "ash/shell_window_ids.h" |
#include "ash/test/ash_test_base.h" |
#include "ash/test/shell_test_api.h" |
+#include "ash/wm/window_resizer.h" |
#include "ash/wm/window_state.h" |
#include "ash/wm/window_util.h" |
#include "ui/aura/client/aura_constants.h" |
#include "ui/aura/window.h" |
+#include "ui/base/hit_test.h" |
namespace ash { |
namespace internal { |
@@ -166,10 +169,100 @@ TEST_F(ShelfWindowWatcherTest, MaximizeAndRestoreWindow) { |
EXPECT_FALSE(window_state->IsMaximized()); |
// No new item is created after restoring a window |window|. |
EXPECT_EQ(2, model_->item_count()); |
- // index and id are not changed after maximizing a window |window|. |
+ // Index and id are not changed after maximizing a window |window|. |
EXPECT_EQ(index, model_->ItemIndexByID(id)); |
EXPECT_EQ(id, model_->items()[index].id); |
} |
+// TODO(simonhong): Add a test for removing a Window during the dragging. |
+TEST_F(ShelfWindowWatcherTest, DragWindow) { |
+ // ShelfModel only has an APP_LIST item. |
+ EXPECT_EQ(1, model_->item_count()); |
+ |
+ scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); |
+ |
+ // Create a LauncherItem for |window|. |
+ LauncherID id = CreateLauncherItem(window.get()); |
+ EXPECT_EQ(2, model_->item_count()); |
+ |
+ int index = model_->ItemIndexByID(id); |
+ EXPECT_EQ(STATUS_RUNNING, model_->items()[index].status); |
+ |
+ // Simulate dragging of |window| and check its item is not changed. |
+ scoped_ptr<WindowResizer> resizer( |
+ CreateWindowResizer(window.get(), |
+ gfx::Point(), |
+ HTCAPTION, |
+ aura::client::WINDOW_MOVE_SOURCE_MOUSE)); |
+ ASSERT_TRUE(resizer.get()); |
+ resizer->Drag(gfx::Point(50, 50), 0); |
+ resizer->CompleteDrag(0); |
+ |
+ //Index and id are not changed after dragging a |window|. |
+ EXPECT_EQ(index, model_->ItemIndexByID(id)); |
+ EXPECT_EQ(id, model_->items()[index].id); |
+} |
+ |
+// Check that an item is remove when its associated Window is re-parented. |
+TEST_F(ShelfWindowWatcherTest, ReparentWindow) { |
+ // ShelfModel only has an APP_LIST item. |
+ EXPECT_EQ(1, model_->item_count()); |
+ |
+ scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); |
+ window->set_owned_by_parent(false); |
+ |
+ // Create a LauncherItem for |window|. |
+ LauncherID id = CreateLauncherItem(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()); |
+ |
+ scoped_ptr<aura::Window> new_parent(CreateTestWindowInShellWithId(0)); |
+ // 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()); |
+ |
+ // Item is not created for |window| because its parent is not a |
+ // |default_container|. |
+ id = CreateLauncherItem(window.get()); |
+ EXPECT_EQ(1, model_->item_count()); |
+ |
+ // Add |window| to |default_container| and create a LauncherItem for |window|. |
+ default_container->AddChild(window.get()); |
+ id = CreateLauncherItem(window.get()); |
+ EXPECT_EQ(2, model_->item_count()); |
+ |
+ // Simulate re-parenting |window| to |new_parent| which is not a |
+ // |default_container|. |
+ { |
+ scoped_ptr<WindowResizer> resizer( |
+ CreateWindowResizer(window.get(), |
+ gfx::Point(), |
+ HTCAPTION, |
+ aura::client::WINDOW_MOVE_SOURCE_MOUSE)); |
+ ASSERT_TRUE(resizer.get()); |
+ resizer->Drag(gfx::Point(50, 50), 0); |
+ resizer->CompleteDrag(0); |
+ 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(ash::wm::GetWindowState(window.get())->is_dragged()); |
+ new_parent->AddChild(window.get()); |
+ EXPECT_EQ(1, model_->item_count()); |
+ } |
+ EXPECT_FALSE(ash::wm::GetWindowState(window.get())->is_dragged()); |
+ EXPECT_EQ(1, model_->item_count()); |
+} |
+ |
} // namespace internal |
} // namespace ash |