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

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

Issue 1867223004: Convert //ash from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 4 years, 8 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
« no previous file with comments | « ash/shelf/shelf_window_watcher.cc ('k') | ash/shell.h » ('j') | 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/ash_switches.h"
8 #include "ash/shelf/shelf_item_types.h" 8 #include "ash/shelf/shelf_item_types.h"
9 #include "ash/shelf/shelf_model.h" 9 #include "ash/shelf/shelf_model.h"
10 #include "ash/shelf/shelf_util.h" 10 #include "ash/shelf/shelf_util.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 ShelfModel* model_; 49 ShelfModel* model_;
50 50
51 private: 51 private:
52 DISALLOW_COPY_AND_ASSIGN(ShelfWindowWatcherTest); 52 DISALLOW_COPY_AND_ASSIGN(ShelfWindowWatcherTest);
53 }; 53 };
54 54
55 TEST_F(ShelfWindowWatcherTest, CreateAndRemoveShelfItem) { 55 TEST_F(ShelfWindowWatcherTest, CreateAndRemoveShelfItem) {
56 // ShelfModel only has an APP_LIST item. 56 // ShelfModel only has an APP_LIST item.
57 EXPECT_EQ(1, model_->item_count()); 57 EXPECT_EQ(1, model_->item_count());
58 58
59 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithId(0)); 59 std::unique_ptr<aura::Window> w1(CreateTestWindowInShellWithId(0));
60 scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithId(0)); 60 std::unique_ptr<aura::Window> w2(CreateTestWindowInShellWithId(0));
61 61
62 // Create a ShelfItem for w1. 62 // Create a ShelfItem for w1.
63 ShelfID id_w1 = CreateShelfItem(w1.get()); 63 ShelfID id_w1 = CreateShelfItem(w1.get());
64 EXPECT_EQ(2, model_->item_count()); 64 EXPECT_EQ(2, model_->item_count());
65 65
66 int index_w1 = model_->ItemIndexByID(id_w1); 66 int index_w1 = model_->ItemIndexByID(id_w1);
67 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status); 67 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status);
68 68
69 // Create a ShelfItem for w2. 69 // Create a ShelfItem for w2.
70 ShelfID id_w2 = CreateShelfItem(w2.get()); 70 ShelfID id_w2 = CreateShelfItem(w2.get());
71 EXPECT_EQ(3, model_->item_count()); 71 EXPECT_EQ(3, model_->item_count());
72 72
73 int index_w2 = model_->ItemIndexByID(id_w2); 73 int index_w2 = model_->ItemIndexByID(id_w2);
74 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w2].status); 74 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w2].status);
75 75
76 // ShelfItem is removed when assoicated window is destroyed. 76 // ShelfItem is removed when assoicated window is destroyed.
77 ClearShelfItemDetailsForWindow(w1.get()); 77 ClearShelfItemDetailsForWindow(w1.get());
78 EXPECT_EQ(2, model_->item_count()); 78 EXPECT_EQ(2, model_->item_count());
79 ClearShelfItemDetailsForWindow(w2.get()); 79 ClearShelfItemDetailsForWindow(w2.get());
80 EXPECT_EQ(1, model_->item_count()); 80 EXPECT_EQ(1, model_->item_count());
81 // Clears twice doesn't do anything. 81 // Clears twice doesn't do anything.
82 ClearShelfItemDetailsForWindow(w2.get()); 82 ClearShelfItemDetailsForWindow(w2.get());
83 EXPECT_EQ(1, model_->item_count()); 83 EXPECT_EQ(1, model_->item_count());
84 84
85 } 85 }
86 86
87 TEST_F(ShelfWindowWatcherTest, ActivateWindow) { 87 TEST_F(ShelfWindowWatcherTest, ActivateWindow) {
88 // ShelfModel only have APP_LIST item. 88 // ShelfModel only have APP_LIST item.
89 EXPECT_EQ(1, model_->item_count()); 89 EXPECT_EQ(1, model_->item_count());
90 scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithId(0)); 90 std::unique_ptr<aura::Window> w1(CreateTestWindowInShellWithId(0));
91 scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithId(0)); 91 std::unique_ptr<aura::Window> w2(CreateTestWindowInShellWithId(0));
92 92
93 // Create a ShelfItem for w1. 93 // Create a ShelfItem for w1.
94 ShelfID id_w1 = CreateShelfItem(w1.get()); 94 ShelfID id_w1 = CreateShelfItem(w1.get());
95 EXPECT_EQ(2, model_->item_count()); 95 EXPECT_EQ(2, model_->item_count());
96 int index_w1 = model_->ItemIndexByID(id_w1); 96 int index_w1 = model_->ItemIndexByID(id_w1);
97 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status); 97 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status);
98 98
99 // Create a ShelfItem for w2. 99 // Create a ShelfItem for w2.
100 ShelfID id_w2 = CreateShelfItem(w2.get()); 100 ShelfID id_w2 = CreateShelfItem(w2.get());
101 EXPECT_EQ(3, model_->item_count()); 101 EXPECT_EQ(3, model_->item_count());
102 int index_w2 = model_->ItemIndexByID(id_w2); 102 int index_w2 = model_->ItemIndexByID(id_w2);
103 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status); 103 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status);
104 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w2].status); 104 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w2].status);
105 105
106 // ShelfItem for w1 is active when w1 is activated. 106 // ShelfItem for w1 is active when w1 is activated.
107 wm::ActivateWindow(w1.get()); 107 wm::ActivateWindow(w1.get());
108 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index_w1].status); 108 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index_w1].status);
109 109
110 // ShelfItem for w2 is active state when w2 is activated. 110 // ShelfItem for w2 is active state when w2 is activated.
111 wm::ActivateWindow(w2.get()); 111 wm::ActivateWindow(w2.get());
112 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status); 112 EXPECT_EQ(STATUS_RUNNING, model_->items()[index_w1].status);
113 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index_w2].status); 113 EXPECT_EQ(STATUS_ACTIVE, model_->items()[index_w2].status);
114 } 114 }
115 115
116 TEST_F(ShelfWindowWatcherTest, UpdateWindowProperty) { 116 TEST_F(ShelfWindowWatcherTest, UpdateWindowProperty) {
117 // ShelfModel only has an APP_LIST item. 117 // ShelfModel only has an APP_LIST item.
118 EXPECT_EQ(1, model_->item_count()); 118 EXPECT_EQ(1, model_->item_count());
119 119
120 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); 120 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
121 121
122 // Create a ShelfItem for |window|. 122 // Create a ShelfItem for |window|.
123 ShelfID id = CreateShelfItem(window.get()); 123 ShelfID id = CreateShelfItem(window.get());
124 EXPECT_EQ(2, model_->item_count()); 124 EXPECT_EQ(2, model_->item_count());
125 125
126 int index = model_->ItemIndexByID(id); 126 int index = model_->ItemIndexByID(id);
127 EXPECT_EQ(STATUS_RUNNING, model_->items()[index].status); 127 EXPECT_EQ(STATUS_RUNNING, model_->items()[index].status);
128 128
129 // Update ShelfItem for |window|. 129 // Update ShelfItem for |window|.
130 ShelfItemDetails details; 130 ShelfItemDetails details;
131 details.type = TYPE_PLATFORM_APP; 131 details.type = TYPE_PLATFORM_APP;
132 132
133 SetShelfItemDetailsForWindow(window.get(), details); 133 SetShelfItemDetailsForWindow(window.get(), details);
134 // No new item is created after updating a launcher item. 134 // No new item is created after updating a launcher item.
135 EXPECT_EQ(2, model_->item_count()); 135 EXPECT_EQ(2, model_->item_count());
136 // index and id are not changed after updating a launcher item. 136 // index and id are not changed after updating a launcher item.
137 EXPECT_EQ(index, model_->ItemIndexByID(id)); 137 EXPECT_EQ(index, model_->ItemIndexByID(id));
138 EXPECT_EQ(id, model_->items()[index].id); 138 EXPECT_EQ(id, model_->items()[index].id);
139 } 139 }
140 140
141 TEST_F(ShelfWindowWatcherTest, MaximizeAndRestoreWindow) { 141 TEST_F(ShelfWindowWatcherTest, MaximizeAndRestoreWindow) {
142 // ShelfModel only has an APP_LIST item. 142 // ShelfModel only has an APP_LIST item.
143 EXPECT_EQ(1, model_->item_count()); 143 EXPECT_EQ(1, model_->item_count());
144 144
145 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); 145 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
146 wm::WindowState* window_state = wm::GetWindowState(window.get()); 146 wm::WindowState* window_state = wm::GetWindowState(window.get());
147 147
148 // Create a ShelfItem for |window|. 148 // Create a ShelfItem for |window|.
149 ShelfID id = CreateShelfItem(window.get()); 149 ShelfID id = CreateShelfItem(window.get());
150 EXPECT_EQ(2, model_->item_count()); 150 EXPECT_EQ(2, model_->item_count());
151 151
152 int index = model_->ItemIndexByID(id); 152 int index = model_->ItemIndexByID(id);
153 EXPECT_EQ(STATUS_RUNNING, model_->items()[index].status); 153 EXPECT_EQ(STATUS_RUNNING, model_->items()[index].status);
154 154
155 // Maximize window |window|. 155 // Maximize window |window|.
(...skipping 14 matching lines...) Expand all
170 // Index and id are not changed after maximizing a window |window|. 170 // Index and id are not changed after maximizing a window |window|.
171 EXPECT_EQ(index, model_->ItemIndexByID(id)); 171 EXPECT_EQ(index, model_->ItemIndexByID(id));
172 EXPECT_EQ(id, model_->items()[index].id); 172 EXPECT_EQ(id, model_->items()[index].id);
173 } 173 }
174 174
175 // Check that an item is removed when its associated Window is re-parented. 175 // Check that an item is removed when its associated Window is re-parented.
176 TEST_F(ShelfWindowWatcherTest, ReparentWindow) { 176 TEST_F(ShelfWindowWatcherTest, ReparentWindow) {
177 // ShelfModel only has an APP_LIST item. 177 // ShelfModel only has an APP_LIST item.
178 EXPECT_EQ(1, model_->item_count()); 178 EXPECT_EQ(1, model_->item_count());
179 179
180 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); 180 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
181 window->set_owned_by_parent(false); 181 window->set_owned_by_parent(false);
182 182
183 // Create a ShelfItem for |window|. 183 // Create a ShelfItem for |window|.
184 ShelfID id = CreateShelfItem(window.get()); 184 ShelfID id = CreateShelfItem(window.get());
185 EXPECT_EQ(2, model_->item_count()); 185 EXPECT_EQ(2, model_->item_count());
186 186
187 int index = model_->ItemIndexByID(id); 187 int index = model_->ItemIndexByID(id);
188 EXPECT_EQ(STATUS_RUNNING, model_->items()[index].status); 188 EXPECT_EQ(STATUS_RUNNING, model_->items()[index].status);
189 189
190 aura::Window* root_window = window->GetRootWindow(); 190 aura::Window* root_window = window->GetRootWindow();
(...skipping 16 matching lines...) Expand all
207 default_container->AddChild(window.get()); 207 default_container->AddChild(window.get());
208 EXPECT_EQ(2, model_->item_count()); 208 EXPECT_EQ(2, model_->item_count());
209 } 209 }
210 210
211 // Check |window|'s item is not changed during the dragging. 211 // Check |window|'s item is not changed during the dragging.
212 // TODO(simonhong): Add a test for removing a Window during the dragging. 212 // TODO(simonhong): Add a test for removing a Window during the dragging.
213 TEST_F(ShelfWindowWatcherTest, DragWindow) { 213 TEST_F(ShelfWindowWatcherTest, DragWindow) {
214 // ShelfModel only has an APP_LIST item. 214 // ShelfModel only has an APP_LIST item.
215 EXPECT_EQ(1, model_->item_count()); 215 EXPECT_EQ(1, model_->item_count());
216 216
217 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); 217 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
218 218
219 // Create a ShelfItem for |window|. 219 // Create a ShelfItem for |window|.
220 ShelfID id = CreateShelfItem(window.get()); 220 ShelfID id = CreateShelfItem(window.get());
221 EXPECT_EQ(2, model_->item_count()); 221 EXPECT_EQ(2, model_->item_count());
222 222
223 int index = model_->ItemIndexByID(id); 223 int index = model_->ItemIndexByID(id);
224 EXPECT_EQ(STATUS_RUNNING, model_->items()[index].status); 224 EXPECT_EQ(STATUS_RUNNING, model_->items()[index].status);
225 225
226 // Simulate dragging of |window| and check its item is not changed. 226 // Simulate dragging of |window| and check its item is not changed.
227 scoped_ptr<WindowResizer> resizer( 227 std::unique_ptr<WindowResizer> resizer(
228 CreateWindowResizer(window.get(), 228 CreateWindowResizer(window.get(), gfx::Point(), HTCAPTION,
229 gfx::Point(),
230 HTCAPTION,
231 aura::client::WINDOW_MOVE_SOURCE_MOUSE)); 229 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
232 ASSERT_TRUE(resizer.get()); 230 ASSERT_TRUE(resizer.get());
233 resizer->Drag(gfx::Point(50, 50), 0); 231 resizer->Drag(gfx::Point(50, 50), 0);
234 resizer->CompleteDrag(); 232 resizer->CompleteDrag();
235 233
236 //Index and id are not changed after dragging a |window|. 234 //Index and id are not changed after dragging a |window|.
237 EXPECT_EQ(index, model_->ItemIndexByID(id)); 235 EXPECT_EQ(index, model_->ItemIndexByID(id));
238 EXPECT_EQ(id, model_->items()[index].id); 236 EXPECT_EQ(id, model_->items()[index].id);
239 } 237 }
240 238
241 // Check |window|'s item is removed when it is re-parented not to default 239 // Check |window|'s item is removed when it is re-parented not to default
242 // container during the dragging. 240 // container during the dragging.
243 TEST_F(ShelfWindowWatcherTest, ReparentWindowDuringTheDragging) { 241 TEST_F(ShelfWindowWatcherTest, ReparentWindowDuringTheDragging) {
244 // ShelfModel only has an APP_LIST item. 242 // ShelfModel only has an APP_LIST item.
245 EXPECT_EQ(1, model_->item_count()); 243 EXPECT_EQ(1, model_->item_count());
246 244
247 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); 245 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
248 window->set_owned_by_parent(false); 246 window->set_owned_by_parent(false);
249 247
250 // Create a ShelfItem for |window|. 248 // Create a ShelfItem for |window|.
251 ShelfID id = CreateShelfItem(window.get()); 249 ShelfID id = CreateShelfItem(window.get());
252 EXPECT_EQ(2, model_->item_count()); 250 EXPECT_EQ(2, model_->item_count());
253 int index = model_->ItemIndexByID(id); 251 int index = model_->ItemIndexByID(id);
254 EXPECT_EQ(STATUS_RUNNING, model_->items()[index].status); 252 EXPECT_EQ(STATUS_RUNNING, model_->items()[index].status);
255 253
256 aura::Window* root_window = window->GetRootWindow(); 254 aura::Window* root_window = window->GetRootWindow();
257 aura::Window* default_container = Shell::GetContainer( 255 aura::Window* default_container = Shell::GetContainer(
258 root_window, 256 root_window,
259 kShellWindowId_DefaultContainer); 257 kShellWindowId_DefaultContainer);
260 EXPECT_EQ(default_container, window->parent()); 258 EXPECT_EQ(default_container, window->parent());
261 259
262 aura::Window* new_parent = Shell::GetContainer( 260 aura::Window* new_parent = Shell::GetContainer(
263 root_window, 261 root_window,
264 kShellWindowId_PanelContainer); 262 kShellWindowId_PanelContainer);
265 263
266 // Simulate re-parenting to |new_parent| during the dragging. 264 // Simulate re-parenting to |new_parent| during the dragging.
267 { 265 {
268 scoped_ptr<WindowResizer> resizer( 266 std::unique_ptr<WindowResizer> resizer(
269 CreateWindowResizer(window.get(), 267 CreateWindowResizer(window.get(), gfx::Point(), HTCAPTION,
270 gfx::Point(),
271 HTCAPTION,
272 aura::client::WINDOW_MOVE_SOURCE_MOUSE)); 268 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
273 ASSERT_TRUE(resizer.get()); 269 ASSERT_TRUE(resizer.get());
274 resizer->Drag(gfx::Point(50, 50), 0); 270 resizer->Drag(gfx::Point(50, 50), 0);
275 resizer->CompleteDrag(); 271 resizer->CompleteDrag();
276 EXPECT_EQ(2, model_->item_count()); 272 EXPECT_EQ(2, model_->item_count());
277 273
278 // Item should be removed when |window| is re-parented not to default 274 // Item should be removed when |window| is re-parented not to default
279 // container before fininshing the dragging. 275 // container before fininshing the dragging.
280 EXPECT_TRUE(wm::GetWindowState(window.get())->is_dragged()); 276 EXPECT_TRUE(wm::GetWindowState(window.get())->is_dragged());
281 new_parent->AddChild(window.get()); 277 new_parent->AddChild(window.get());
282 EXPECT_EQ(1, model_->item_count()); 278 EXPECT_EQ(1, model_->item_count());
283 } 279 }
284 EXPECT_FALSE(wm::GetWindowState(window.get())->is_dragged()); 280 EXPECT_FALSE(wm::GetWindowState(window.get())->is_dragged());
285 EXPECT_EQ(1, model_->item_count()); 281 EXPECT_EQ(1, model_->item_count());
286 } 282 }
287 283
288 } // namespace ash 284 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_window_watcher.cc ('k') | ash/shell.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698