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..a735c248d7d9163e3eb430654855c6164b27adcd 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 { |
@@ -41,9 +46,6 @@ class ShelfWindowWatcherTest : public test::AshTestBase { |
return id; |
} |
- void UpdateLauncherItem(aura::Window* window) { |
- } |
- |
protected: |
ShelfModel* model_; |
@@ -166,10 +168,141 @@ 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 = 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()); |
+ |
+ 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()); |
+} |
+ |
+// To test re-parenting during the dragging, --ash-enable-docked-windows option |
+// is needed. |
+class ShelfWindowWatcherTestWithDockedWindow : public ShelfWindowWatcherTest { |
+ public: |
+ ShelfWindowWatcherTestWithDockedWindow() {} |
+ virtual ~ShelfWindowWatcherTestWithDockedWindow() {} |
+ |
+ virtual void SetUp() OVERRIDE { |
+ CommandLine::ForCurrentProcess()->AppendSwitch( |
+ ash::switches::kAshEnableDockedWindows); |
+ ShelfWindowWatcherTest::SetUp(); |
+ } |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(ShelfWindowWatcherTestWithDockedWindow); |
+}; |
+ |
+// Check |window|'s item is not changed during the dragging. |
+// TODO(simonhong): Add a test for removing a Window during the dragging. |
+TEST_F(ShelfWindowWatcherTestWithDockedWindow, 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 |window|'s item is removed when it is re-parented not to default |
+// container during the dragging. |
+TEST_F(ShelfWindowWatcherTestWithDockedWindow, 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()); |
+ |
+ 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(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 |