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

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: Handle re-parenting not to default_container Created 7 years 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
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/launcher/launcher_types.h" 7 #include "ash/launcher/launcher_types.h"
8 #include "ash/shelf/shelf_model.h" 8 #include "ash/shelf/shelf_model.h"
9 #include "ash/shelf/shelf_util.h" 9 #include "ash/shelf/shelf_util.h"
10 #include "ash/shell.h" 10 #include "ash/shell.h"
11 #include "ash/shell_window_ids.h"
11 #include "ash/test/ash_test_base.h" 12 #include "ash/test/ash_test_base.h"
12 #include "ash/test/shell_test_api.h" 13 #include "ash/test/shell_test_api.h"
14 #include "ash/wm/window_resizer.h"
13 #include "ash/wm/window_state.h" 15 #include "ash/wm/window_state.h"
14 #include "ash/wm/window_util.h" 16 #include "ash/wm/window_util.h"
15 #include "ui/aura/client/aura_constants.h" 17 #include "ui/aura/client/aura_constants.h"
16 #include "ui/aura/window.h" 18 #include "ui/aura/window.h"
19 #include "ui/base/hit_test.h"
17 20
18 namespace ash { 21 namespace ash {
19 namespace internal { 22 namespace internal {
20 23
21 class ShelfWindowWatcherTest : public test::AshTestBase { 24 class ShelfWindowWatcherTest : public test::AshTestBase {
22 public: 25 public:
23 ShelfWindowWatcherTest() : model_(NULL) {} 26 ShelfWindowWatcherTest() : model_(NULL) {}
24 virtual ~ShelfWindowWatcherTest() {} 27 virtual ~ShelfWindowWatcherTest() {}
25 28
26 virtual void SetUp() OVERRIDE { 29 virtual void SetUp() OVERRIDE {
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 EXPECT_EQ(2, model_->item_count()); 162 EXPECT_EQ(2, model_->item_count());
160 // index and id are not changed after maximizing a window |window|. 163 // index and id are not changed after maximizing a window |window|.
161 EXPECT_EQ(index, model_->ItemIndexByID(id)); 164 EXPECT_EQ(index, model_->ItemIndexByID(id));
162 EXPECT_EQ(id, model_->items()[index].id); 165 EXPECT_EQ(id, model_->items()[index].id);
163 166
164 // Restore window |window|. 167 // Restore window |window|.
165 window_state->Restore(); 168 window_state->Restore();
166 EXPECT_FALSE(window_state->IsMaximized()); 169 EXPECT_FALSE(window_state->IsMaximized());
167 // No new item is created after restoring a window |window|. 170 // No new item is created after restoring a window |window|.
168 EXPECT_EQ(2, model_->item_count()); 171 EXPECT_EQ(2, model_->item_count());
169 // index and id are not changed after maximizing a window |window|. 172 // Index and id are not changed after maximizing a window |window|.
170 EXPECT_EQ(index, model_->ItemIndexByID(id)); 173 EXPECT_EQ(index, model_->ItemIndexByID(id));
171 EXPECT_EQ(id, model_->items()[index].id); 174 EXPECT_EQ(id, model_->items()[index].id);
172 } 175 }
173 176
177 // TODO(simonhong): Add a test for removing a Window during the dragging.
178 TEST_F(ShelfWindowWatcherTest, DragWindow) {
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
184 // Create a LauncherItem for |window|.
185 LauncherID id = CreateLauncherItem(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 // Simulate dragging of |window| and check its item is not changed.
192 scoped_ptr<WindowResizer> resizer(
193 CreateWindowResizer(window.get(),
194 gfx::Point(),
195 HTCAPTION,
196 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
197 ASSERT_TRUE(resizer.get());
198 resizer->Drag(gfx::Point(50, 50), 0);
199 resizer->CompleteDrag(0);
200
201 //Index and id are not changed after dragging a |window|.
202 EXPECT_EQ(index, model_->ItemIndexByID(id));
203 EXPECT_EQ(id, model_->items()[index].id);
204 }
205
206 // Check that an item is remove when its associated Window is re-parented.
207 TEST_F(ShelfWindowWatcherTest, ReparentWindow) {
208 // ShelfModel only has an APP_LIST item.
209 EXPECT_EQ(1, model_->item_count());
210
211 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
212 window->set_owned_by_parent(false);
213
214 // Create a LauncherItem for |window|.
215 LauncherID id = CreateLauncherItem(window.get());
216 EXPECT_EQ(2, model_->item_count());
217
218 int index = model_->ItemIndexByID(id);
219 EXPECT_EQ(STATUS_RUNNING, model_->items()[index].status);
220
221 aura::Window* root_window = window->GetRootWindow();
222 aura::Window* default_container = Shell::GetContainer(
223 root_window,
224 kShellWindowId_DefaultContainer);
225
226 EXPECT_EQ(default_container, window->parent());
227
228 scoped_ptr<aura::Window> new_parent(CreateTestWindowInShellWithId(0));
229 // Check |window|'s item is removed when it is re-parented to |new_parent|
230 // which is not default container.
231 new_parent->AddChild(window.get());
232 EXPECT_EQ(1, model_->item_count());
233
234 // Item is not created for |window| because its parent is not a
235 // |default_container|.
236 id = CreateLauncherItem(window.get());
237 EXPECT_EQ(1, model_->item_count());
238
239 // Add |window| to |default_container| and create a LauncherItem for |window|.
240 default_container->AddChild(window.get());
241 id = CreateLauncherItem(window.get());
242 EXPECT_EQ(2, model_->item_count());
243
244 // Simulate re-parenting |window| to |new_parent| which is not a
245 // |default_container|.
246 {
247 scoped_ptr<WindowResizer> resizer(
248 CreateWindowResizer(window.get(),
249 gfx::Point(),
250 HTCAPTION,
251 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
252 ASSERT_TRUE(resizer.get());
253 resizer->Drag(gfx::Point(50, 50), 0);
254 resizer->CompleteDrag(0);
255 EXPECT_EQ(2, model_->item_count());
256
257 // Item should be removed when |window| is re-parented not to default
258 // container before fininshing the dragging.
259 EXPECT_TRUE(ash::wm::GetWindowState(window.get())->is_dragged());
260 new_parent->AddChild(window.get());
261 EXPECT_EQ(1, model_->item_count());
262 }
263 EXPECT_FALSE(ash::wm::GetWindowState(window.get())->is_dragged());
264 EXPECT_EQ(1, model_->item_count());
265 }
266
174 } // namespace internal 267 } // namespace internal
175 } // namespace ash 268 } // namespace ash
OLDNEW
« ash/shelf/shelf_window_watcher.cc ('K') | « ash/shelf/shelf_window_watcher.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698