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

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

Issue 2192553002: mash: Convert ShelfWindowWatcher to wm common types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cleanup Created 4 years, 4 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
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/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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 return id; 47 return id;
48 } 48 }
49 49
50 protected: 50 protected:
51 ShelfModel* model_; 51 ShelfModel* model_;
52 52
53 private: 53 private:
54 DISALLOW_COPY_AND_ASSIGN(ShelfWindowWatcherTest); 54 DISALLOW_COPY_AND_ASSIGN(ShelfWindowWatcherTest);
55 }; 55 };
56 56
57 TEST_F(ShelfWindowWatcherTest, CreateAndRemoveShelfItem) { 57 // Tests that shelf items are removed as windows are closed.
58 TEST_F(ShelfWindowWatcherTest, OpenAndClose) {
58 // ShelfModel only has an APP_LIST item. 59 // ShelfModel only has an APP_LIST item.
59 EXPECT_EQ(1, model_->item_count()); 60 EXPECT_EQ(1, model_->item_count());
60 61
62 std::unique_ptr<aura::Window> w1(CreateTestWindowInShellWithId(0));
63 std::unique_ptr<aura::Window> w2(CreateTestWindowInShellWithId(0));
64
65 // Create a ShelfItem for w1.
msw 2016/07/27 18:36:11 Is it possible to test that items are created when
James Cook 2016/07/27 20:14:06 Done (and thanks for the suggestion, it's better).
66 CreateShelfItem(w1.get());
67 EXPECT_EQ(2, model_->item_count());
68
69 // Create a ShelfItem for w2.
70 CreateShelfItem(w2.get());
71 EXPECT_EQ(3, model_->item_count());
72
73 // Each ShelfItem is removed when the associated window is destroyed.
74 w1.reset();
75 EXPECT_EQ(2, model_->item_count());
76 w2.reset();
77 EXPECT_EQ(1, model_->item_count());
78 }
79
80 TEST_F(ShelfWindowWatcherTest, CreateAndRemoveShelfItemDetails) {
81 // ShelfModel only has an APP_LIST item.
82 EXPECT_EQ(1, model_->item_count());
83
61 std::unique_ptr<aura::Window> w1(CreateTestWindowInShellWithId(0)); 84 std::unique_ptr<aura::Window> w1(CreateTestWindowInShellWithId(0));
62 std::unique_ptr<aura::Window> w2(CreateTestWindowInShellWithId(0)); 85 std::unique_ptr<aura::Window> w2(CreateTestWindowInShellWithId(0));
63 86
64 // Create a ShelfItem for w1. 87 // Create a ShelfItem for w1.
65 ShelfID id_w1 = CreateShelfItem(w1.get()); 88 ShelfID id_w1 = CreateShelfItem(w1.get());
66 EXPECT_EQ(2, model_->item_count()); 89 EXPECT_EQ(2, model_->item_count());
67 90
68 int index_w1 = model_->ItemIndexByID(id_w1); 91 int index_w1 = model_->ItemIndexByID(id_w1);
69 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status); 92 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status);
70 93
71 // Create a ShelfItem for w2. 94 // Create a ShelfItem for w2.
72 ShelfID id_w2 = CreateShelfItem(w2.get()); 95 ShelfID id_w2 = CreateShelfItem(w2.get());
73 EXPECT_EQ(3, model_->item_count()); 96 EXPECT_EQ(3, model_->item_count());
74 97
75 int index_w2 = model_->ItemIndexByID(id_w2); 98 int index_w2 = model_->ItemIndexByID(id_w2);
76 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w2].status); 99 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w2].status);
77 100
78 // ShelfItem is removed when assoicated window is destroyed. 101 // ShelfItem is removed when its window property is cleared.
79 ClearShelfItemDetailsForWindow(w1.get()); 102 ClearShelfItemDetailsForWindow(w1.get());
80 EXPECT_EQ(2, model_->item_count()); 103 EXPECT_EQ(2, model_->item_count());
81 ClearShelfItemDetailsForWindow(w2.get()); 104 ClearShelfItemDetailsForWindow(w2.get());
82 EXPECT_EQ(1, model_->item_count()); 105 EXPECT_EQ(1, model_->item_count());
83 // Clears twice doesn't do anything. 106 // Clearing twice doesn't do anything.
84 ClearShelfItemDetailsForWindow(w2.get()); 107 ClearShelfItemDetailsForWindow(w2.get());
85 EXPECT_EQ(1, model_->item_count()); 108 EXPECT_EQ(1, model_->item_count());
86 } 109 }
87 110
88 TEST_F(ShelfWindowWatcherTest, ActivateWindow) { 111 TEST_F(ShelfWindowWatcherTest, ActivateWindow) {
89 // ShelfModel only have APP_LIST item. 112 // ShelfModel only have APP_LIST item.
90 EXPECT_EQ(1, model_->item_count()); 113 EXPECT_EQ(1, model_->item_count());
91 std::unique_ptr<aura::Window> w1(CreateTestWindowInShellWithId(0)); 114 std::unique_ptr<aura::Window> w1(CreateTestWindowInShellWithId(0));
92 std::unique_ptr<aura::Window> w2(CreateTestWindowInShellWithId(0)); 115 std::unique_ptr<aura::Window> w2(CreateTestWindowInShellWithId(0));
93 116
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 // Restore window |window|. 189 // Restore window |window|.
167 window_state->Restore(); 190 window_state->Restore();
168 EXPECT_FALSE(window_state->IsMaximized()); 191 EXPECT_FALSE(window_state->IsMaximized());
169 // No new item is created after restoring a window |window|. 192 // No new item is created after restoring a window |window|.
170 EXPECT_EQ(2, model_->item_count()); 193 EXPECT_EQ(2, model_->item_count());
171 // Index and id are not changed after maximizing a window |window|. 194 // Index and id are not changed after maximizing a window |window|.
172 EXPECT_EQ(index, model_->ItemIndexByID(id)); 195 EXPECT_EQ(index, model_->ItemIndexByID(id));
173 EXPECT_EQ(id, model_->items()[index].id); 196 EXPECT_EQ(id, model_->items()[index].id);
174 } 197 }
175 198
176 // Check that an item is removed when its associated Window is re-parented. 199 // Check that an item is maintained when its associated Window is docked.
177 TEST_F(ShelfWindowWatcherTest, ReparentWindow) { 200 TEST_F(ShelfWindowWatcherTest, DockWindow) {
178 // ShelfModel only has an APP_LIST item. 201 // ShelfModel only has an APP_LIST item.
179 EXPECT_EQ(1, model_->item_count()); 202 EXPECT_EQ(1, model_->item_count());
180 203
181 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); 204 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
182 window->set_owned_by_parent(false); 205 window->set_owned_by_parent(false);
183 206
184 // Create a ShelfItem for |window|. 207 // Create a ShelfItem for |window|.
185 ShelfID id = CreateShelfItem(window.get()); 208 ShelfID id = CreateShelfItem(window.get());
186 EXPECT_EQ(2, model_->item_count()); 209 EXPECT_EQ(2, model_->item_count());
187 210
188 int index = model_->ItemIndexByID(id); 211 int index = model_->ItemIndexByID(id);
189 EXPECT_EQ(STATUS_RUNNING, model_->items()[index].status); 212 EXPECT_EQ(STATUS_RUNNING, model_->items()[index].status);
190 213
191 aura::Window* root_window = window->GetRootWindow(); 214 aura::Window* root_window = window->GetRootWindow();
192 aura::Window* default_container = 215 aura::Window* default_container =
193 Shell::GetContainer(root_window, kShellWindowId_DefaultContainer); 216 Shell::GetContainer(root_window, kShellWindowId_DefaultContainer);
194 EXPECT_EQ(default_container, window->parent()); 217 EXPECT_EQ(default_container, window->parent());
195 218
196 aura::Window* new_parent = 219 aura::Window* docked_container =
197 Shell::GetContainer(root_window, kShellWindowId_PanelContainer); 220 Shell::GetContainer(root_window, kShellWindowId_DockedContainer);
198 221
199 // Check |window|'s item is removed when it is re-parented to |new_parent| 222 // Check |window|'s item is not removed when it is re-parented to the dock.
200 // which is not default container. 223 docked_container->AddChild(window.get());
201 new_parent->AddChild(window.get()); 224 EXPECT_EQ(2, model_->item_count());
225
226 // The shelf item is removed when the window is closed, even if it is in the
227 // docked container at the time.
228 window.reset();
202 EXPECT_EQ(1, model_->item_count()); 229 EXPECT_EQ(1, model_->item_count());
203
204 // Check |window|'s item is added when it is re-parented to
205 // |default_container|.
206 default_container->AddChild(window.get());
207 EXPECT_EQ(2, model_->item_count());
208 } 230 }
209 231
210 // Check |window|'s item is not changed during the dragging. 232 // Check |window|'s item is not changed during the dragging.
211 // TODO(simonhong): Add a test for removing a Window during the dragging. 233 // TODO(simonhong): Add a test for removing a Window during the dragging.
212 TEST_F(ShelfWindowWatcherTest, DragWindow) { 234 TEST_F(ShelfWindowWatcherTest, DragWindow) {
213 // ShelfModel only has an APP_LIST item. 235 // ShelfModel only has an APP_LIST item.
214 EXPECT_EQ(1, model_->item_count()); 236 EXPECT_EQ(1, model_->item_count());
215 237
216 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); 238 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
217 239
(...skipping 10 matching lines...) Expand all
228 HTCAPTION, aura::client::WINDOW_MOVE_SOURCE_MOUSE)); 250 HTCAPTION, aura::client::WINDOW_MOVE_SOURCE_MOUSE));
229 ASSERT_TRUE(resizer.get()); 251 ASSERT_TRUE(resizer.get());
230 resizer->Drag(gfx::Point(50, 50), 0); 252 resizer->Drag(gfx::Point(50, 50), 0);
231 resizer->CompleteDrag(); 253 resizer->CompleteDrag();
232 254
233 // Index and id are not changed after dragging a |window|. 255 // Index and id are not changed after dragging a |window|.
234 EXPECT_EQ(index, model_->ItemIndexByID(id)); 256 EXPECT_EQ(index, model_->ItemIndexByID(id));
235 EXPECT_EQ(id, model_->items()[index].id); 257 EXPECT_EQ(id, model_->items()[index].id);
236 } 258 }
237 259
238 // Check |window|'s item is removed when it is re-parented not to default
239 // container during the dragging.
240 TEST_F(ShelfWindowWatcherTest, ReparentWindowDuringTheDragging) {
241 // ShelfModel only has an APP_LIST item.
242 EXPECT_EQ(1, model_->item_count());
243
244 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
245 window->set_owned_by_parent(false);
246
247 // Create a ShelfItem for |window|.
248 ShelfID id = CreateShelfItem(window.get());
249 EXPECT_EQ(2, model_->item_count());
250 int index = model_->ItemIndexByID(id);
251 EXPECT_EQ(STATUS_RUNNING, model_->items()[index].status);
252
253 aura::Window* root_window = window->GetRootWindow();
254 aura::Window* default_container =
255 Shell::GetContainer(root_window, kShellWindowId_DefaultContainer);
256 EXPECT_EQ(default_container, window->parent());
257
258 aura::Window* new_parent =
259 Shell::GetContainer(root_window, kShellWindowId_PanelContainer);
260
261 // Simulate re-parenting to |new_parent| during the dragging.
262 {
263 std::unique_ptr<WindowResizer> resizer(
264 CreateWindowResizer(WmWindowAura::Get(window.get()), gfx::Point(),
265 HTCAPTION, aura::client::WINDOW_MOVE_SOURCE_MOUSE));
266 ASSERT_TRUE(resizer.get());
267 resizer->Drag(gfx::Point(50, 50), 0);
268 resizer->CompleteDrag();
269 EXPECT_EQ(2, model_->item_count());
270
271 // Item should be removed when |window| is re-parented not to default
272 // container before fininshing the dragging.
273 EXPECT_TRUE(wm::GetWindowState(window.get())->is_dragged());
274 new_parent->AddChild(window.get());
275 EXPECT_EQ(1, model_->item_count());
276 }
277 EXPECT_FALSE(wm::GetWindowState(window.get())->is_dragged());
278 EXPECT_EQ(1, model_->item_count());
279 }
280
281 } // namespace ash 260 } // namespace ash
OLDNEW
« ash/shelf/shelf_window_watcher.cc ('K') | « ash/shelf/shelf_window_watcher_item_delegate.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698