Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(317)

Side by Side Diff: ash/shelf/shelf_window_watcher_unittest.cc

Issue 108313006: [ash] Don't remove an item when associated window is dragged (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ash/shelf/shelf_window_watcher.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 // Check that an item is removed when its associated Window is re-parented.
177 TEST_F(ShelfWindowWatcherTest, ReparentWindow) {
178 // ShelfModel only has an APP_LIST item.
179 EXPECT_EQ(1, model_->item_count());
180
181 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
182 window->set_owned_by_parent(false);
183
184 // Create a LauncherItem for |window|.
185 LauncherID id = CreateShelfItem(window.get());
186 EXPECT_EQ(2, model_->item_count());
187
188 int index = model_->ItemIndexByID(id);
189 EXPECT_EQ(STATUS_RUNNING, model_->items()[index].status);
190
191 aura::Window* root_window = window->GetRootWindow();
192 aura::Window* default_container = Shell::GetContainer(
193 root_window,
194 kShellWindowId_DefaultContainer);
195 EXPECT_EQ(default_container, window->parent());
196
197 aura::Window* new_parent = Shell::GetContainer(
198 root_window,
199 kShellWindowId_PanelContainer);
200
201 // Check |window|'s item is removed when it is re-parented to |new_parent|
202 // which is not default container.
203 new_parent->AddChild(window.get());
204 EXPECT_EQ(1, model_->item_count());
205
206 // Check |window|'s item is added when it is re-parented to
207 // |default_container|.
208 default_container->AddChild(window.get());
209 EXPECT_EQ(2, model_->item_count());
210 }
211
212 // Check |window|'s item is not changed during the dragging.
213 // TODO(simonhong): Add a test for removing a Window during the dragging.
214 TEST_F(ShelfWindowWatcherTest, DragWindow) {
215 // ShelfModel only has an APP_LIST item.
216 EXPECT_EQ(1, model_->item_count());
217
218 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
219
220 // Create a LauncherItem for |window|.
221 LauncherID id = CreateShelfItem(window.get());
222 EXPECT_EQ(2, model_->item_count());
223
224 int index = model_->ItemIndexByID(id);
225 EXPECT_EQ(STATUS_RUNNING, model_->items()[index].status);
226
227 // Simulate dragging of |window| and check its item is not changed.
228 scoped_ptr<WindowResizer> resizer(
229 CreateWindowResizer(window.get(),
230 gfx::Point(),
231 HTCAPTION,
232 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
233 ASSERT_TRUE(resizer.get());
234 resizer->Drag(gfx::Point(50, 50), 0);
235 resizer->CompleteDrag();
236
237 //Index and id are not changed after dragging a |window|.
238 EXPECT_EQ(index, model_->ItemIndexByID(id));
239 EXPECT_EQ(id, model_->items()[index].id);
240 }
241
242 // Check |window|'s item is removed when it is re-parented not to default
243 // container during the dragging.
244 TEST_F(ShelfWindowWatcherTest, ReparentWindowDuringTheDragging) {
245 // ShelfModel only has an APP_LIST item.
246 EXPECT_EQ(1, model_->item_count());
247
248 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
249 window->set_owned_by_parent(false);
250
251 // Create a LauncherItem for |window|.
252 LauncherID id = CreateShelfItem(window.get());
253 EXPECT_EQ(2, model_->item_count());
254 int index = model_->ItemIndexByID(id);
255 EXPECT_EQ(STATUS_RUNNING, model_->items()[index].status);
256
257 aura::Window* root_window = window->GetRootWindow();
258 aura::Window* default_container = Shell::GetContainer(
259 root_window,
260 kShellWindowId_DefaultContainer);
261 EXPECT_EQ(default_container, window->parent());
262
263 aura::Window* new_parent = Shell::GetContainer(
264 root_window,
265 kShellWindowId_PanelContainer);
266
267 // Simulate re-parenting to |new_parent| during the dragging.
268 {
269 scoped_ptr<WindowResizer> resizer(
270 CreateWindowResizer(window.get(),
271 gfx::Point(),
272 HTCAPTION,
273 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
274 ASSERT_TRUE(resizer.get());
275 resizer->Drag(gfx::Point(50, 50), 0);
276 resizer->CompleteDrag();
277 EXPECT_EQ(2, model_->item_count());
278
279 // Item should be removed when |window| is re-parented not to default
280 // container before fininshing the dragging.
281 EXPECT_TRUE(wm::GetWindowState(window.get())->is_dragged());
282 new_parent->AddChild(window.get());
283 EXPECT_EQ(1, model_->item_count());
284 }
285 EXPECT_FALSE(wm::GetWindowState(window.get())->is_dragged());
286 EXPECT_EQ(1, model_->item_count());
287 }
288
174 } // namespace internal 289 } // namespace internal
175 } // namespace ash 290 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_window_watcher.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698