diff options
Diffstat (limited to 'ash/shelf/shelf_window_watcher_unittest.cc')
-rw-r--r-- | ash/shelf/shelf_window_watcher_unittest.cc | 127 |
1 files changed, 121 insertions, 6 deletions
diff --git a/ash/shelf/shelf_window_watcher_unittest.cc b/ash/shelf/shelf_window_watcher_unittest.cc index 3982c76..2d3bf8e 100644 --- a/ash/shelf/shelf_window_watcher_unittest.cc +++ b/ash/shelf/shelf_window_watcher_unittest.cc @@ -4,16 +4,21 @@ #include "ash/shelf/shelf_window_watcher.h" +#include "ash/ash_switches.h" #include "ash/launcher/launcher_types.h" #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 "base/command_line.h" #include "ui/aura/client/aura_constants.h" #include "ui/aura/window.h" +#include "ui/base/hit_test.h" namespace ash { namespace internal { @@ -33,17 +38,14 @@ class ShelfWindowWatcherTest : public test::AshTestBase { test::AshTestBase::TearDown(); } - ash::LauncherID CreateShelfItem(aura::Window* window) { + LauncherID CreateShelfItem(aura::Window* window) { LauncherID id = model_->next_id(); - ash::LauncherItemDetails item_details; + LauncherItemDetails item_details; item_details.type = TYPE_PLATFORM_APP; SetShelfItemDetailsForWindow(window, item_details); return id; } - void UpdateLauncherItem(aura::Window* window) { - } - protected: ShelfModel* model_; @@ -166,10 +168,123 @@ 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); } +// Check that an item is removed 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 = 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); + + // 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()); + EXPECT_EQ(2, model_->item_count()); +} + +// Check |window|'s item is not changed during the dragging. +// 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 = CreateShelfItem(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(); + + //Index and id are not changed after dragging a |window|. + EXPECT_EQ(index, model_->ItemIndexByID(id)); + 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()); + + scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); + window->set_owned_by_parent(false); + + // Create a LauncherItem for |window|. + LauncherID 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. + { + 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(); + 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 internal } // namespace ash |