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/ash_switches.h" |
7 #include "ash/launcher/launcher_types.h" | 8 #include "ash/launcher/launcher_types.h" |
8 #include "ash/shelf/shelf_model.h" | 9 #include "ash/shelf/shelf_model.h" |
9 #include "ash/shelf/shelf_util.h" | 10 #include "ash/shelf/shelf_util.h" |
10 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 12 #include "ash/shell_window_ids.h" |
11 #include "ash/test/ash_test_base.h" | 13 #include "ash/test/ash_test_base.h" |
12 #include "ash/test/shell_test_api.h" | 14 #include "ash/test/shell_test_api.h" |
| 15 #include "ash/wm/window_resizer.h" |
13 #include "ash/wm/window_state.h" | 16 #include "ash/wm/window_state.h" |
14 #include "ash/wm/window_util.h" | 17 #include "ash/wm/window_util.h" |
| 18 #include "base/command_line.h" |
15 #include "ui/aura/client/aura_constants.h" | 19 #include "ui/aura/client/aura_constants.h" |
16 #include "ui/aura/window.h" | 20 #include "ui/aura/window.h" |
| 21 #include "ui/base/hit_test.h" |
17 | 22 |
18 namespace ash { | 23 namespace ash { |
19 namespace internal { | 24 namespace internal { |
20 | 25 |
21 class ShelfWindowWatcherTest : public test::AshTestBase { | 26 class ShelfWindowWatcherTest : public test::AshTestBase { |
22 public: | 27 public: |
23 ShelfWindowWatcherTest() : model_(NULL) {} | 28 ShelfWindowWatcherTest() : model_(NULL) {} |
24 virtual ~ShelfWindowWatcherTest() {} | 29 virtual ~ShelfWindowWatcherTest() {} |
25 | 30 |
26 virtual void SetUp() OVERRIDE { | 31 virtual void SetUp() OVERRIDE { |
27 test::AshTestBase::SetUp(); | 32 test::AshTestBase::SetUp(); |
28 model_ = test::ShellTestApi(Shell::GetInstance()).shelf_model(); | 33 model_ = test::ShellTestApi(Shell::GetInstance()).shelf_model(); |
29 } | 34 } |
30 | 35 |
31 virtual void TearDown() OVERRIDE { | 36 virtual void TearDown() OVERRIDE { |
32 model_ = NULL; | 37 model_ = NULL; |
33 test::AshTestBase::TearDown(); | 38 test::AshTestBase::TearDown(); |
34 } | 39 } |
35 | 40 |
36 ash::LauncherID CreateShelfItem(aura::Window* window) { | 41 LauncherID CreateShelfItem(aura::Window* window) { |
37 LauncherID id = model_->next_id(); | 42 LauncherID id = model_->next_id(); |
38 ash::LauncherItemDetails item_details; | 43 LauncherItemDetails item_details; |
39 item_details.type = TYPE_PLATFORM_APP; | 44 item_details.type = TYPE_PLATFORM_APP; |
40 SetShelfItemDetailsForWindow(window, item_details); | 45 SetShelfItemDetailsForWindow(window, item_details); |
41 return id; | 46 return id; |
42 } | 47 } |
43 | 48 |
44 void UpdateLauncherItem(aura::Window* window) { | |
45 } | |
46 | |
47 protected: | 49 protected: |
48 ShelfModel* model_; | 50 ShelfModel* model_; |
49 | 51 |
50 private: | 52 private: |
51 DISALLOW_COPY_AND_ASSIGN(ShelfWindowWatcherTest); | 53 DISALLOW_COPY_AND_ASSIGN(ShelfWindowWatcherTest); |
52 }; | 54 }; |
53 | 55 |
54 TEST_F(ShelfWindowWatcherTest, CreateAndRemoveLauncherItem) { | 56 TEST_F(ShelfWindowWatcherTest, CreateAndRemoveLauncherItem) { |
55 // ShelfModel only has an APP_LIST item. | 57 // ShelfModel only has an APP_LIST item. |
56 EXPECT_EQ(1, model_->item_count()); | 58 EXPECT_EQ(1, model_->item_count()); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 EXPECT_EQ(2, model_->item_count()); | 161 EXPECT_EQ(2, model_->item_count()); |
160 // index and id are not changed after maximizing a window |window|. | 162 // index and id are not changed after maximizing a window |window|. |
161 EXPECT_EQ(index, model_->ItemIndexByID(id)); | 163 EXPECT_EQ(index, model_->ItemIndexByID(id)); |
162 EXPECT_EQ(id, model_->items()[index].id); | 164 EXPECT_EQ(id, model_->items()[index].id); |
163 | 165 |
164 // Restore window |window|. | 166 // Restore window |window|. |
165 window_state->Restore(); | 167 window_state->Restore(); |
166 EXPECT_FALSE(window_state->IsMaximized()); | 168 EXPECT_FALSE(window_state->IsMaximized()); |
167 // No new item is created after restoring a window |window|. | 169 // No new item is created after restoring a window |window|. |
168 EXPECT_EQ(2, model_->item_count()); | 170 EXPECT_EQ(2, model_->item_count()); |
169 // index and id are not changed after maximizing a window |window|. | 171 // Index and id are not changed after maximizing a window |window|. |
170 EXPECT_EQ(index, model_->ItemIndexByID(id)); | 172 EXPECT_EQ(index, model_->ItemIndexByID(id)); |
171 EXPECT_EQ(id, model_->items()[index].id); | 173 EXPECT_EQ(id, model_->items()[index].id); |
172 } | 174 } |
173 | 175 |
| 176 |
| 177 // Check that an item is removed when its associated Window is re-parented. |
| 178 TEST_F(ShelfWindowWatcherTest, ReparentWindow) { |
| 179 // ShelfModel only has an APP_LIST item. |
| 180 EXPECT_EQ(1, model_->item_count()); |
| 181 |
| 182 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); |
| 183 window->set_owned_by_parent(false); |
| 184 |
| 185 // Create a LauncherItem for |window|. |
| 186 LauncherID id = CreateShelfItem(window.get()); |
| 187 EXPECT_EQ(2, model_->item_count()); |
| 188 |
| 189 int index = model_->ItemIndexByID(id); |
| 190 EXPECT_EQ(STATUS_RUNNING, model_->items()[index].status); |
| 191 |
| 192 aura::Window* root_window = window->GetRootWindow(); |
| 193 aura::Window* default_container = Shell::GetContainer( |
| 194 root_window, |
| 195 kShellWindowId_DefaultContainer); |
| 196 EXPECT_EQ(default_container, window->parent()); |
| 197 |
| 198 aura::Window* new_parent = Shell::GetContainer( |
| 199 root_window, |
| 200 kShellWindowId_PanelContainer); |
| 201 |
| 202 // Check |window|'s item is removed when it is re-parented to |new_parent| |
| 203 // which is not default container. |
| 204 new_parent->AddChild(window.get()); |
| 205 EXPECT_EQ(1, model_->item_count()); |
| 206 |
| 207 // Check |window|'s item is added when it is re-parented to |
| 208 // |default_container|. |
| 209 default_container->AddChild(window.get()); |
| 210 EXPECT_EQ(2, model_->item_count()); |
| 211 } |
| 212 |
| 213 // To test re-parenting during the dragging, --ash-enable-docked-windows option |
| 214 // is needed. |
| 215 class ShelfWindowWatcherTestWithDockedWindow : public ShelfWindowWatcherTest { |
| 216 public: |
| 217 ShelfWindowWatcherTestWithDockedWindow() {} |
| 218 virtual ~ShelfWindowWatcherTestWithDockedWindow() {} |
| 219 |
| 220 virtual void SetUp() OVERRIDE { |
| 221 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 222 switches::kAshEnableDockedWindows); |
| 223 ShelfWindowWatcherTest::SetUp(); |
| 224 } |
| 225 |
| 226 private: |
| 227 DISALLOW_COPY_AND_ASSIGN(ShelfWindowWatcherTestWithDockedWindow); |
| 228 }; |
| 229 |
| 230 // Check |window|'s item is not changed during the dragging. |
| 231 // TODO(simonhong): Add a test for removing a Window during the dragging. |
| 232 TEST_F(ShelfWindowWatcherTestWithDockedWindow, DragWindow) { |
| 233 // ShelfModel only has an APP_LIST item. |
| 234 EXPECT_EQ(1, model_->item_count()); |
| 235 |
| 236 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); |
| 237 |
| 238 // Create a LauncherItem for |window|. |
| 239 LauncherID id = CreateShelfItem(window.get()); |
| 240 EXPECT_EQ(2, model_->item_count()); |
| 241 |
| 242 int index = model_->ItemIndexByID(id); |
| 243 EXPECT_EQ(STATUS_RUNNING, model_->items()[index].status); |
| 244 |
| 245 // Simulate dragging of |window| and check its item is not changed. |
| 246 scoped_ptr<WindowResizer> resizer( |
| 247 CreateWindowResizer(window.get(), |
| 248 gfx::Point(), |
| 249 HTCAPTION, |
| 250 aura::client::WINDOW_MOVE_SOURCE_MOUSE)); |
| 251 ASSERT_TRUE(resizer.get()); |
| 252 resizer->Drag(gfx::Point(50, 50), 0); |
| 253 resizer->CompleteDrag(); |
| 254 |
| 255 //Index and id are not changed after dragging a |window|. |
| 256 EXPECT_EQ(index, model_->ItemIndexByID(id)); |
| 257 EXPECT_EQ(id, model_->items()[index].id); |
| 258 } |
| 259 |
| 260 // Check |window|'s item is removed when it is re-parented not to default |
| 261 // container during the dragging. |
| 262 TEST_F(ShelfWindowWatcherTestWithDockedWindow, ReparentWindow) { |
| 263 // ShelfModel only has an APP_LIST item. |
| 264 EXPECT_EQ(1, model_->item_count()); |
| 265 |
| 266 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); |
| 267 window->set_owned_by_parent(false); |
| 268 |
| 269 // Create a LauncherItem for |window|. |
| 270 LauncherID id = CreateShelfItem(window.get()); |
| 271 EXPECT_EQ(2, model_->item_count()); |
| 272 int index = model_->ItemIndexByID(id); |
| 273 EXPECT_EQ(STATUS_RUNNING, model_->items()[index].status); |
| 274 |
| 275 aura::Window* root_window = window->GetRootWindow(); |
| 276 aura::Window* default_container = Shell::GetContainer( |
| 277 root_window, |
| 278 kShellWindowId_DefaultContainer); |
| 279 EXPECT_EQ(default_container, window->parent()); |
| 280 |
| 281 aura::Window* new_parent = Shell::GetContainer( |
| 282 root_window, |
| 283 kShellWindowId_PanelContainer); |
| 284 |
| 285 // Simulate re-parenting to |new_parent| during the dragging. |
| 286 { |
| 287 scoped_ptr<WindowResizer> resizer( |
| 288 CreateWindowResizer(window.get(), |
| 289 gfx::Point(), |
| 290 HTCAPTION, |
| 291 aura::client::WINDOW_MOVE_SOURCE_MOUSE)); |
| 292 ASSERT_TRUE(resizer.get()); |
| 293 resizer->Drag(gfx::Point(50, 50), 0); |
| 294 resizer->CompleteDrag(); |
| 295 EXPECT_EQ(2, model_->item_count()); |
| 296 |
| 297 // Item should be removed when |window| is re-parented not to default |
| 298 // container before fininshing the dragging. |
| 299 EXPECT_TRUE(wm::GetWindowState(window.get())->is_dragged()); |
| 300 new_parent->AddChild(window.get()); |
| 301 EXPECT_EQ(1, model_->item_count()); |
| 302 } |
| 303 EXPECT_FALSE(wm::GetWindowState(window.get())->is_dragged()); |
| 304 EXPECT_EQ(1, model_->item_count()); |
| 305 } |
| 306 |
174 } // namespace internal | 307 } // namespace internal |
175 } // namespace ash | 308 } // namespace ash |
OLD | NEW |