| 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/shelf/shelf_window_watcher.h" | 5 #include "ash/shelf/shelf_window_watcher.h" |
| 6 | 6 |
| 7 #include "ash/aura/wm_window_aura.h" | 7 #include "ash/aura/wm_window_aura.h" |
| 8 #include "ash/common/ash_switches.h" | 8 #include "ash/common/ash_switches.h" |
| 9 #include "ash/common/shelf/shelf_item_types.h" | 9 #include "ash/common/shelf/shelf_item_types.h" |
| 10 #include "ash/common/shelf/shelf_model.h" | 10 #include "ash/common/shelf/shelf_model.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w2].status); | 76 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w2].status); |
| 77 | 77 |
| 78 // ShelfItem is removed when assoicated window is destroyed. | 78 // ShelfItem is removed when assoicated window is destroyed. |
| 79 ClearShelfItemDetailsForWindow(w1.get()); | 79 ClearShelfItemDetailsForWindow(w1.get()); |
| 80 EXPECT_EQ(2, model_->item_count()); | 80 EXPECT_EQ(2, model_->item_count()); |
| 81 ClearShelfItemDetailsForWindow(w2.get()); | 81 ClearShelfItemDetailsForWindow(w2.get()); |
| 82 EXPECT_EQ(1, model_->item_count()); | 82 EXPECT_EQ(1, model_->item_count()); |
| 83 // Clears twice doesn't do anything. | 83 // Clears twice doesn't do anything. |
| 84 ClearShelfItemDetailsForWindow(w2.get()); | 84 ClearShelfItemDetailsForWindow(w2.get()); |
| 85 EXPECT_EQ(1, model_->item_count()); | 85 EXPECT_EQ(1, model_->item_count()); |
| 86 | |
| 87 } | 86 } |
| 88 | 87 |
| 89 TEST_F(ShelfWindowWatcherTest, ActivateWindow) { | 88 TEST_F(ShelfWindowWatcherTest, ActivateWindow) { |
| 90 // ShelfModel only have APP_LIST item. | 89 // ShelfModel only have APP_LIST item. |
| 91 EXPECT_EQ(1, model_->item_count()); | 90 EXPECT_EQ(1, model_->item_count()); |
| 92 std::unique_ptr<aura::Window> w1(CreateTestWindowInShellWithId(0)); | 91 std::unique_ptr<aura::Window> w1(CreateTestWindowInShellWithId(0)); |
| 93 std::unique_ptr<aura::Window> w2(CreateTestWindowInShellWithId(0)); | 92 std::unique_ptr<aura::Window> w2(CreateTestWindowInShellWithId(0)); |
| 94 | 93 |
| 95 // Create a ShelfItem for w1. | 94 // Create a ShelfItem for w1. |
| 96 ShelfID id_w1 = CreateShelfItem(w1.get()); | 95 ShelfID id_w1 = CreateShelfItem(w1.get()); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 window->set_owned_by_parent(false); | 182 window->set_owned_by_parent(false); |
| 184 | 183 |
| 185 // Create a ShelfItem for |window|. | 184 // Create a ShelfItem for |window|. |
| 186 ShelfID id = CreateShelfItem(window.get()); | 185 ShelfID id = CreateShelfItem(window.get()); |
| 187 EXPECT_EQ(2, model_->item_count()); | 186 EXPECT_EQ(2, model_->item_count()); |
| 188 | 187 |
| 189 int index = model_->ItemIndexByID(id); | 188 int index = model_->ItemIndexByID(id); |
| 190 EXPECT_EQ(STATUS_RUNNING, model_->items()[index].status); | 189 EXPECT_EQ(STATUS_RUNNING, model_->items()[index].status); |
| 191 | 190 |
| 192 aura::Window* root_window = window->GetRootWindow(); | 191 aura::Window* root_window = window->GetRootWindow(); |
| 193 aura::Window* default_container = Shell::GetContainer( | 192 aura::Window* default_container = |
| 194 root_window, | 193 Shell::GetContainer(root_window, kShellWindowId_DefaultContainer); |
| 195 kShellWindowId_DefaultContainer); | |
| 196 EXPECT_EQ(default_container, window->parent()); | 194 EXPECT_EQ(default_container, window->parent()); |
| 197 | 195 |
| 198 aura::Window* new_parent = Shell::GetContainer( | 196 aura::Window* new_parent = |
| 199 root_window, | 197 Shell::GetContainer(root_window, kShellWindowId_PanelContainer); |
| 200 kShellWindowId_PanelContainer); | |
| 201 | 198 |
| 202 // Check |window|'s item is removed when it is re-parented to |new_parent| | 199 // Check |window|'s item is removed when it is re-parented to |new_parent| |
| 203 // which is not default container. | 200 // which is not default container. |
| 204 new_parent->AddChild(window.get()); | 201 new_parent->AddChild(window.get()); |
| 205 EXPECT_EQ(1, model_->item_count()); | 202 EXPECT_EQ(1, model_->item_count()); |
| 206 | 203 |
| 207 // Check |window|'s item is added when it is re-parented to | 204 // Check |window|'s item is added when it is re-parented to |
| 208 // |default_container|. | 205 // |default_container|. |
| 209 default_container->AddChild(window.get()); | 206 default_container->AddChild(window.get()); |
| 210 EXPECT_EQ(2, model_->item_count()); | 207 EXPECT_EQ(2, model_->item_count()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 226 EXPECT_EQ(STATUS_RUNNING, model_->items()[index].status); | 223 EXPECT_EQ(STATUS_RUNNING, model_->items()[index].status); |
| 227 | 224 |
| 228 // Simulate dragging of |window| and check its item is not changed. | 225 // Simulate dragging of |window| and check its item is not changed. |
| 229 std::unique_ptr<WindowResizer> resizer( | 226 std::unique_ptr<WindowResizer> resizer( |
| 230 CreateWindowResizer(WmWindowAura::Get(window.get()), gfx::Point(), | 227 CreateWindowResizer(WmWindowAura::Get(window.get()), gfx::Point(), |
| 231 HTCAPTION, aura::client::WINDOW_MOVE_SOURCE_MOUSE)); | 228 HTCAPTION, aura::client::WINDOW_MOVE_SOURCE_MOUSE)); |
| 232 ASSERT_TRUE(resizer.get()); | 229 ASSERT_TRUE(resizer.get()); |
| 233 resizer->Drag(gfx::Point(50, 50), 0); | 230 resizer->Drag(gfx::Point(50, 50), 0); |
| 234 resizer->CompleteDrag(); | 231 resizer->CompleteDrag(); |
| 235 | 232 |
| 236 //Index and id are not changed after dragging a |window|. | 233 // Index and id are not changed after dragging a |window|. |
| 237 EXPECT_EQ(index, model_->ItemIndexByID(id)); | 234 EXPECT_EQ(index, model_->ItemIndexByID(id)); |
| 238 EXPECT_EQ(id, model_->items()[index].id); | 235 EXPECT_EQ(id, model_->items()[index].id); |
| 239 } | 236 } |
| 240 | 237 |
| 241 // Check |window|'s item is removed when it is re-parented not to default | 238 // Check |window|'s item is removed when it is re-parented not to default |
| 242 // container during the dragging. | 239 // container during the dragging. |
| 243 TEST_F(ShelfWindowWatcherTest, ReparentWindowDuringTheDragging) { | 240 TEST_F(ShelfWindowWatcherTest, ReparentWindowDuringTheDragging) { |
| 244 // ShelfModel only has an APP_LIST item. | 241 // ShelfModel only has an APP_LIST item. |
| 245 EXPECT_EQ(1, model_->item_count()); | 242 EXPECT_EQ(1, model_->item_count()); |
| 246 | 243 |
| 247 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); | 244 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); |
| 248 window->set_owned_by_parent(false); | 245 window->set_owned_by_parent(false); |
| 249 | 246 |
| 250 // Create a ShelfItem for |window|. | 247 // Create a ShelfItem for |window|. |
| 251 ShelfID id = CreateShelfItem(window.get()); | 248 ShelfID id = CreateShelfItem(window.get()); |
| 252 EXPECT_EQ(2, model_->item_count()); | 249 EXPECT_EQ(2, model_->item_count()); |
| 253 int index = model_->ItemIndexByID(id); | 250 int index = model_->ItemIndexByID(id); |
| 254 EXPECT_EQ(STATUS_RUNNING, model_->items()[index].status); | 251 EXPECT_EQ(STATUS_RUNNING, model_->items()[index].status); |
| 255 | 252 |
| 256 aura::Window* root_window = window->GetRootWindow(); | 253 aura::Window* root_window = window->GetRootWindow(); |
| 257 aura::Window* default_container = Shell::GetContainer( | 254 aura::Window* default_container = |
| 258 root_window, | 255 Shell::GetContainer(root_window, kShellWindowId_DefaultContainer); |
| 259 kShellWindowId_DefaultContainer); | |
| 260 EXPECT_EQ(default_container, window->parent()); | 256 EXPECT_EQ(default_container, window->parent()); |
| 261 | 257 |
| 262 aura::Window* new_parent = Shell::GetContainer( | 258 aura::Window* new_parent = |
| 263 root_window, | 259 Shell::GetContainer(root_window, kShellWindowId_PanelContainer); |
| 264 kShellWindowId_PanelContainer); | |
| 265 | 260 |
| 266 // Simulate re-parenting to |new_parent| during the dragging. | 261 // Simulate re-parenting to |new_parent| during the dragging. |
| 267 { | 262 { |
| 268 std::unique_ptr<WindowResizer> resizer( | 263 std::unique_ptr<WindowResizer> resizer( |
| 269 CreateWindowResizer(WmWindowAura::Get(window.get()), gfx::Point(), | 264 CreateWindowResizer(WmWindowAura::Get(window.get()), gfx::Point(), |
| 270 HTCAPTION, aura::client::WINDOW_MOVE_SOURCE_MOUSE)); | 265 HTCAPTION, aura::client::WINDOW_MOVE_SOURCE_MOUSE)); |
| 271 ASSERT_TRUE(resizer.get()); | 266 ASSERT_TRUE(resizer.get()); |
| 272 resizer->Drag(gfx::Point(50, 50), 0); | 267 resizer->Drag(gfx::Point(50, 50), 0); |
| 273 resizer->CompleteDrag(); | 268 resizer->CompleteDrag(); |
| 274 EXPECT_EQ(2, model_->item_count()); | 269 EXPECT_EQ(2, model_->item_count()); |
| 275 | 270 |
| 276 // Item should be removed when |window| is re-parented not to default | 271 // Item should be removed when |window| is re-parented not to default |
| 277 // container before fininshing the dragging. | 272 // container before fininshing the dragging. |
| 278 EXPECT_TRUE(wm::GetWindowState(window.get())->is_dragged()); | 273 EXPECT_TRUE(wm::GetWindowState(window.get())->is_dragged()); |
| 279 new_parent->AddChild(window.get()); | 274 new_parent->AddChild(window.get()); |
| 280 EXPECT_EQ(1, model_->item_count()); | 275 EXPECT_EQ(1, model_->item_count()); |
| 281 } | 276 } |
| 282 EXPECT_FALSE(wm::GetWindowState(window.get())->is_dragged()); | 277 EXPECT_FALSE(wm::GetWindowState(window.get())->is_dragged()); |
| 283 EXPECT_EQ(1, model_->item_count()); | 278 EXPECT_EQ(1, model_->item_count()); |
| 284 } | 279 } |
| 285 | 280 |
| 286 } // namespace ash | 281 } // namespace ash |
| OLD | NEW |