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

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

Issue 2860503002: mash: Replace int ShelfIDs with AppLaunchID strings. (Closed)
Patch Set: Fix struct traits typo. Created 3 years, 7 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_model.cc ('k') | ash/shelf/shelf_tooltip_manager_unittest.cc » ('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_model.h" 5 #include "ash/shelf/shelf_model.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 9
10 #include "ash/shelf/shelf_model_observer.h" 10 #include "ash/shelf/shelf_model_observer.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 ShelfModelTest() {} 62 ShelfModelTest() {}
63 ~ShelfModelTest() override {} 63 ~ShelfModelTest() override {}
64 64
65 void SetUp() override { 65 void SetUp() override {
66 model_.reset(new ShelfModel); 66 model_.reset(new ShelfModel);
67 observer_.reset(new TestShelfModelObserver); 67 observer_.reset(new TestShelfModelObserver);
68 EXPECT_EQ(0, model_->item_count()); 68 EXPECT_EQ(0, model_->item_count());
69 69
70 ShelfItem item; 70 ShelfItem item;
71 item.type = TYPE_APP_LIST; 71 item.type = TYPE_APP_LIST;
72 item.id = ShelfID("AppListId");
72 model_->Add(item); 73 model_->Add(item);
73 EXPECT_EQ(1, model_->item_count()); 74 EXPECT_EQ(1, model_->item_count());
74 75
75 model_->AddObserver(observer_.get()); 76 model_->AddObserver(observer_.get());
76 } 77 }
77 78
78 void TearDown() override { 79 void TearDown() override {
79 observer_.reset(); 80 observer_.reset();
80 model_.reset(); 81 model_.reset();
81 } 82 }
82 83
83 std::unique_ptr<ShelfModel> model_; 84 std::unique_ptr<ShelfModel> model_;
84 std::unique_ptr<TestShelfModelObserver> observer_; 85 std::unique_ptr<TestShelfModelObserver> observer_;
85 86
86 private: 87 private:
87 DISALLOW_COPY_AND_ASSIGN(ShelfModelTest); 88 DISALLOW_COPY_AND_ASSIGN(ShelfModelTest);
88 }; 89 };
89 90
90 TEST_F(ShelfModelTest, BasicAssertions) { 91 TEST_F(ShelfModelTest, BasicAssertions) {
91 // Add an item. 92 // Add an item.
92 ShelfItem item; 93 ShelfItem item1;
93 item.type = TYPE_PINNED_APP; 94 item1.id = ShelfID("item1");
94 int index = model_->Add(item); 95 item1.type = TYPE_PINNED_APP;
96 int index = model_->Add(item1);
95 EXPECT_EQ(2, model_->item_count()); 97 EXPECT_EQ(2, model_->item_count());
96 EXPECT_EQ("added=1", observer_->StateStringAndClear()); 98 EXPECT_EQ("added=1", observer_->StateStringAndClear());
97 99
98 // Change to a platform app item. 100 // Change to a platform app item.
99 ShelfID original_id = model_->items()[index].id; 101 ShelfID original_id = model_->items()[index].id;
100 item.type = TYPE_APP; 102 item1.type = TYPE_APP;
101 model_->Set(index, item); 103 model_->Set(index, item1);
102 EXPECT_EQ(original_id, model_->items()[index].id); 104 EXPECT_EQ(original_id, model_->items()[index].id);
103 EXPECT_EQ("changed=1", observer_->StateStringAndClear()); 105 EXPECT_EQ("changed=1", observer_->StateStringAndClear());
104 EXPECT_EQ(TYPE_APP, model_->items()[index].type); 106 EXPECT_EQ(TYPE_APP, model_->items()[index].type);
105 107
106 // Remove the item. 108 // Remove the item.
107 model_->RemoveItemAt(index); 109 model_->RemoveItemAt(index);
108 EXPECT_EQ(1, model_->item_count()); 110 EXPECT_EQ(1, model_->item_count());
109 EXPECT_EQ("removed=1", observer_->StateStringAndClear()); 111 EXPECT_EQ("removed=1", observer_->StateStringAndClear());
110 112
111 // Add an app item. 113 // Add an app item.
112 item.type = TYPE_PINNED_APP; 114 ShelfItem item2;
113 index = model_->Add(item); 115 item2.id = ShelfID("item2");
116 item2.type = TYPE_PINNED_APP;
117 index = model_->Add(item2);
114 observer_->StateStringAndClear(); 118 observer_->StateStringAndClear();
115 119
116 // Change everything. 120 // Change the item type.
117 model_->Set(index, item); 121 item2.type = TYPE_APP;
122 model_->Set(index, item2);
118 EXPECT_EQ("changed=1", observer_->StateStringAndClear()); 123 EXPECT_EQ("changed=1", observer_->StateStringAndClear());
119 EXPECT_EQ(TYPE_PINNED_APP, model_->items()[index].type); 124 EXPECT_EQ(TYPE_APP, model_->items()[index].type);
120 125
121 // Add another item. 126 // Add another item.
122 item.type = TYPE_PINNED_APP; 127 ShelfItem item3;
123 model_->Add(item); 128 item3.id = ShelfID("item3");
129 item3.type = TYPE_PINNED_APP;
130 model_->Add(item3);
124 observer_->StateStringAndClear(); 131 observer_->StateStringAndClear();
125 132
126 // Move the second to the first. 133 // Move the second to the first.
127 model_->Move(1, 0); 134 model_->Move(1, 0);
128 EXPECT_EQ("moved=1", observer_->StateStringAndClear()); 135 EXPECT_EQ("moved=1", observer_->StateStringAndClear());
129 136
130 // And back. 137 // And back.
131 model_->Move(0, 1); 138 model_->Move(0, 1);
132 EXPECT_EQ("moved=1", observer_->StateStringAndClear()); 139 EXPECT_EQ("moved=1", observer_->StateStringAndClear());
133 140
134 // Verifies all the items get unique ids. 141 // Verifies all the items get unique ids.
135 std::set<ShelfID> ids; 142 std::set<ShelfID> ids;
136 for (int i = 0; i < model_->item_count(); ++i) 143 for (int i = 0; i < model_->item_count(); ++i)
137 ids.insert(model_->items()[i].id); 144 ids.insert(model_->items()[i].id);
138 EXPECT_EQ(model_->item_count(), static_cast<int>(ids.size())); 145 EXPECT_EQ(model_->item_count(), static_cast<int>(ids.size()));
139 } 146 }
140 147
141 // Assertions around where items are added. 148 // Assertions around where items are added.
142 TEST_F(ShelfModelTest, AddIndices) { 149 TEST_F(ShelfModelTest, AddIndices) {
143 // Insert browser short cut at index 1. 150 // Insert browser short cut at index 1.
144 ShelfItem browser_shortcut; 151 ShelfItem browser_shortcut;
152 browser_shortcut.id = ShelfID("browser");
145 browser_shortcut.type = TYPE_BROWSER_SHORTCUT; 153 browser_shortcut.type = TYPE_BROWSER_SHORTCUT;
146 int browser_shortcut_index = model_->Add(browser_shortcut); 154 int browser_shortcut_index = model_->Add(browser_shortcut);
147 EXPECT_EQ(1, browser_shortcut_index); 155 EXPECT_EQ(1, browser_shortcut_index);
148 156
149 // App items should be after the browser shortcut. 157 // App items should be after the browser shortcut.
150 ShelfItem item; 158 ShelfItem item;
151 item.type = TYPE_APP; 159 item.type = TYPE_APP;
160 item.id = ShelfID("id1");
152 int platform_app_index1 = model_->Add(item); 161 int platform_app_index1 = model_->Add(item);
153 EXPECT_EQ(2, platform_app_index1); 162 EXPECT_EQ(2, platform_app_index1);
154 163
155 // Add another platform app item, it should follow first. 164 // Add another platform app item, it should follow first.
165 item.id = ShelfID("id2");
156 int platform_app_index2 = model_->Add(item); 166 int platform_app_index2 = model_->Add(item);
157 EXPECT_EQ(3, platform_app_index2); 167 EXPECT_EQ(3, platform_app_index2);
158 168
159 // TYPE_PINNED_APP priority is higher than TYPE_APP but same as 169 // TYPE_PINNED_APP priority is higher than TYPE_APP but same as
160 // TYPE_BROWSER_SHORTCUT. So TYPE_PINNED_APP is located after 170 // TYPE_BROWSER_SHORTCUT. So TYPE_PINNED_APP is located after
161 // TYPE_BROWSER_SHORTCUT. 171 // TYPE_BROWSER_SHORTCUT.
162 item.type = TYPE_PINNED_APP; 172 item.type = TYPE_PINNED_APP;
173 item.id = ShelfID("id3");
163 int app_shortcut_index1 = model_->Add(item); 174 int app_shortcut_index1 = model_->Add(item);
164 EXPECT_EQ(2, app_shortcut_index1); 175 EXPECT_EQ(2, app_shortcut_index1);
165 176
166 item.type = TYPE_PINNED_APP; 177 item.type = TYPE_PINNED_APP;
178 item.id = ShelfID("id4");
167 int app_shortcut_index2 = model_->Add(item); 179 int app_shortcut_index2 = model_->Add(item);
168 EXPECT_EQ(3, app_shortcut_index2); 180 EXPECT_EQ(3, app_shortcut_index2);
169 181
170 // Check that AddAt() figures out the correct indexes for app shortcuts. 182 // Check that AddAt() figures out the correct indexes for app shortcuts.
171 // TYPE_PINNED_APP and TYPE_BROWSER_SHORTCUT has the same weight. 183 // TYPE_PINNED_APP and TYPE_BROWSER_SHORTCUT has the same weight.
172 // So TYPE_PINNED_APP is located at index 0. And, TYPE_BROWSER_SHORTCUT is 184 // So TYPE_PINNED_APP is located at index 0. And, TYPE_BROWSER_SHORTCUT is
173 // located at index 1. 185 // located at index 1.
174 item.type = TYPE_PINNED_APP; 186 item.type = TYPE_PINNED_APP;
187 item.id = ShelfID("id5");
175 int app_shortcut_index3 = model_->AddAt(1, item); 188 int app_shortcut_index3 = model_->AddAt(1, item);
176 EXPECT_EQ(1, app_shortcut_index3); 189 EXPECT_EQ(1, app_shortcut_index3);
177 190
178 item.type = TYPE_PINNED_APP; 191 item.type = TYPE_PINNED_APP;
192 item.id = ShelfID("id6");
179 int app_shortcut_index4 = model_->AddAt(6, item); 193 int app_shortcut_index4 = model_->AddAt(6, item);
180 EXPECT_EQ(5, app_shortcut_index4); 194 EXPECT_EQ(5, app_shortcut_index4);
181 195
182 item.type = TYPE_PINNED_APP; 196 item.type = TYPE_PINNED_APP;
197 item.id = ShelfID("id7");
183 int app_shortcut_index5 = model_->AddAt(3, item); 198 int app_shortcut_index5 = model_->AddAt(3, item);
184 EXPECT_EQ(3, app_shortcut_index5); 199 EXPECT_EQ(3, app_shortcut_index5);
185 200
186 // Before there are any panels, no icons should be right aligned. 201 // Before there are any panels, no icons should be right aligned.
187 EXPECT_EQ(model_->item_count(), model_->FirstPanelIndex()); 202 EXPECT_EQ(model_->item_count(), model_->FirstPanelIndex());
188 203
189 // Check that AddAt() figures out the correct indexes for apps and panels. 204 // Check that AddAt() figures out the correct indexes for apps and panels.
190 item.type = TYPE_APP; 205 item.type = TYPE_APP;
206 item.id = ShelfID("id8");
191 int platform_app_index3 = model_->AddAt(3, item); 207 int platform_app_index3 = model_->AddAt(3, item);
192 EXPECT_EQ(7, platform_app_index3); 208 EXPECT_EQ(7, platform_app_index3);
193 209
194 item.type = TYPE_APP_PANEL; 210 item.type = TYPE_APP_PANEL;
211 item.id = ShelfID("id9");
195 int app_panel_index1 = model_->AddAt(2, item); 212 int app_panel_index1 = model_->AddAt(2, item);
196 EXPECT_EQ(10, app_panel_index1); 213 EXPECT_EQ(10, app_panel_index1);
197 214
198 item.type = TYPE_APP; 215 item.type = TYPE_APP;
216 item.id = ShelfID("id10");
199 int platform_app_index4 = model_->AddAt(11, item); 217 int platform_app_index4 = model_->AddAt(11, item);
200 EXPECT_EQ(10, platform_app_index4); 218 EXPECT_EQ(10, platform_app_index4);
201 219
202 item.type = TYPE_APP_PANEL; 220 item.type = TYPE_APP_PANEL;
221 item.id = ShelfID("id11");
203 int app_panel_index2 = model_->AddAt(12, item); 222 int app_panel_index2 = model_->AddAt(12, item);
204 EXPECT_EQ(12, app_panel_index2); 223 EXPECT_EQ(12, app_panel_index2);
205 224
206 item.type = TYPE_APP; 225 item.type = TYPE_APP;
226 item.id = ShelfID("id12");
207 int platform_app_index5 = model_->AddAt(7, item); 227 int platform_app_index5 = model_->AddAt(7, item);
208 EXPECT_EQ(7, platform_app_index5); 228 EXPECT_EQ(7, platform_app_index5);
209 229
210 item.type = TYPE_APP_PANEL; 230 item.type = TYPE_APP_PANEL;
231 item.id = ShelfID("id13");
211 int app_panel_index3 = model_->AddAt(13, item); 232 int app_panel_index3 = model_->AddAt(13, item);
212 EXPECT_EQ(13, app_panel_index3); 233 EXPECT_EQ(13, app_panel_index3);
213 234
214 // Right aligned index should be the first app panel index. 235 // Right aligned index should be the first app panel index.
215 EXPECT_EQ(12, model_->FirstPanelIndex()); 236 EXPECT_EQ(12, model_->FirstPanelIndex());
216 237
217 EXPECT_EQ(TYPE_BROWSER_SHORTCUT, model_->items()[2].type); 238 EXPECT_EQ(TYPE_BROWSER_SHORTCUT, model_->items()[2].type);
218 EXPECT_EQ(TYPE_APP_LIST, model_->items()[0].type); 239 EXPECT_EQ(TYPE_APP_LIST, model_->items()[0].type);
219 } 240 }
220 241
221 // Test that the indexes for the running applications are properly determined. 242 // Test that the indexes for the running applications are properly determined.
222 TEST_F(ShelfModelTest, FirstRunningAppIndex) { 243 TEST_F(ShelfModelTest, FirstRunningAppIndex) {
223 // Insert the browser shortcut at index 1 and check that the running 244 // Insert the browser shortcut at index 1 and check that the running
224 // application index would be behind it. 245 // application index would be behind it.
225 ShelfItem item; 246 ShelfItem item;
247 item.id = ShelfID("browser");
226 item.type = TYPE_BROWSER_SHORTCUT; 248 item.type = TYPE_BROWSER_SHORTCUT;
227 EXPECT_EQ(1, model_->Add(item)); 249 EXPECT_EQ(1, model_->Add(item));
228 EXPECT_EQ(2, model_->FirstRunningAppIndex()); 250 EXPECT_EQ(2, model_->FirstRunningAppIndex());
229 251
230 // Insert a panel application at the end and check that the running 252 // Insert a panel application at the end and check that the running
231 // application index would be at / before the application panel. 253 // application index would be at / before the application panel.
232 item.type = TYPE_APP_PANEL; 254 item.type = TYPE_APP_PANEL;
255 item.id = ShelfID("app panel");
233 EXPECT_EQ(2, model_->Add(item)); 256 EXPECT_EQ(2, model_->Add(item));
234 EXPECT_EQ(2, model_->FirstRunningAppIndex()); 257 EXPECT_EQ(2, model_->FirstRunningAppIndex());
235 258
236 // Insert an application shortcut and make sure that the running application 259 // Insert an application shortcut and make sure that the running application
237 // index would be behind it. 260 // index would be behind it.
238 item.type = TYPE_PINNED_APP; 261 item.type = TYPE_PINNED_APP;
262 item.id = ShelfID("pinned app");
239 EXPECT_EQ(2, model_->Add(item)); 263 EXPECT_EQ(2, model_->Add(item));
240 EXPECT_EQ(3, model_->FirstRunningAppIndex()); 264 EXPECT_EQ(3, model_->FirstRunningAppIndex());
241 265
242 // Insert a two app items and check the first running app index. 266 // Insert a two app items and check the first running app index.
243 item.type = TYPE_APP; 267 item.type = TYPE_APP;
268 item.id = ShelfID("app1");
244 EXPECT_EQ(3, model_->Add(item)); 269 EXPECT_EQ(3, model_->Add(item));
245 EXPECT_EQ(3, model_->FirstRunningAppIndex()); 270 EXPECT_EQ(3, model_->FirstRunningAppIndex());
271 item.id = ShelfID("app2");
246 EXPECT_EQ(4, model_->Add(item)); 272 EXPECT_EQ(4, model_->Add(item));
247 EXPECT_EQ(3, model_->FirstRunningAppIndex()); 273 EXPECT_EQ(3, model_->FirstRunningAppIndex());
248 } 274 }
249 275
250 // Assertions around id generation and usage. 276 // Test item reordering on type/weight (eg. pinning) changes. crbug.com/248769.
251 TEST_F(ShelfModelTest, ShelfIDTests) { 277 TEST_F(ShelfModelTest, ReorderOnTypeChanges) {
252 // Get the next to use ID counter. 278 EXPECT_EQ(TYPE_APP_LIST, model_->items()[0].type);
253 ShelfID id = model_->next_id();
254 279
255 // Calling this function multiple times does not change the returned ID. 280 // Add three pinned items.
256 EXPECT_EQ(model_->next_id(), id); 281 ShelfItem item1;
282 item1.type = TYPE_PINNED_APP;
283 item1.id = ShelfID("id1");
284 int app1_index = model_->Add(item1);
285 EXPECT_EQ(1, app1_index);
257 286
258 // Adding another item to the list should produce a new ID. 287 ShelfItem item2;
259 ShelfItem item; 288 item2.type = TYPE_PINNED_APP;
260 item.type = TYPE_APP; 289 item2.id = ShelfID("id2");
261 model_->Add(item); 290 int app2_index = model_->Add(item2);
262 EXPECT_NE(model_->next_id(), id); 291 EXPECT_EQ(2, app2_index);
263 }
264 292
265 // This verifies that converting an existing item into a lower weight category 293 ShelfItem item3;
266 // (e.g. shortcut to running but not pinned app) will move it to the proper 294 item3.type = TYPE_PINNED_APP;
267 // location. See crbug.com/248769. 295 item3.id = ShelfID("id3");
268 TEST_F(ShelfModelTest, CorrectMoveItemsWhenStateChange) { 296 int app3_index = model_->Add(item3);
269 // The first item is the app list and last item is the browser. 297 EXPECT_EQ(3, app3_index);
270 ShelfItem browser_shortcut;
271 browser_shortcut.type = TYPE_BROWSER_SHORTCUT;
272 int browser_shortcut_index = model_->Add(browser_shortcut);
273 EXPECT_EQ(TYPE_APP_LIST, model_->items()[0].type);
274 EXPECT_EQ(1, browser_shortcut_index);
275 298
276 // Add three shortcuts. They should all be moved between the two. 299 // Unpinning an item moves it behind the shortcuts.
277 ShelfItem item; 300 EXPECT_EQ(item3.id, model_->items()[3].id);
278 item.type = TYPE_PINNED_APP; 301 item2.type = TYPE_APP;
279 int app1_index = model_->Add(item); 302 model_->Set(app2_index, item2);
280 EXPECT_EQ(2, app1_index); 303 EXPECT_EQ(item2.id, model_->items()[3].id);
281 int app2_index = model_->Add(item);
282 EXPECT_EQ(3, app2_index);
283 int app3_index = model_->Add(item);
284 EXPECT_EQ(4, app3_index);
285
286 // Now change the type of the second item and make sure that it is moving
287 // behind the shortcuts.
288 item.type = TYPE_APP;
289 model_->Set(app2_index, item);
290
291 // The item should have moved in front of the app launcher.
292 EXPECT_EQ(TYPE_APP, model_->items()[4].type);
293 } 304 }
294 305
295 // Test conversion between ShelfID and application [launch] ids. 306 // Test conversion between ShelfID and application [launch] ids.
296 TEST_F(ShelfModelTest, IdentifierConversion) { 307 TEST_F(ShelfModelTest, IdentifierConversion) {
297 const std::string app_id1("app_id1"); 308 const std::string app_id1("app_id1");
298 const std::string launch_id("launch_id"); 309 const std::string launch_id("launch_id");
299 const ShelfID unknown_shelf_id = 123;
300 310
301 // Expect kInvalidShelfID and empty app ids for input not found in the model. 311 // Expect empty ShelfIDs and app ids for input not found in the model.
302 EXPECT_EQ(kInvalidShelfID, model_->GetShelfIDForAppID(std::string())); 312 EXPECT_TRUE(model_->GetShelfIDForAppID(std::string()).IsNull());
303 EXPECT_EQ(kInvalidShelfID, model_->GetShelfIDForAppID(app_id1)); 313 EXPECT_TRUE(model_->GetShelfIDForAppID(app_id1).IsNull());
304 EXPECT_EQ(kInvalidShelfID, 314 EXPECT_TRUE(
305 model_->GetShelfIDForAppIDAndLaunchID(app_id1, std::string())); 315 model_->GetShelfIDForAppIDAndLaunchID(app_id1, std::string()).IsNull());
306 EXPECT_EQ(kInvalidShelfID, 316 EXPECT_TRUE(
307 model_->GetShelfIDForAppIDAndLaunchID(app_id1, launch_id)); 317 model_->GetShelfIDForAppIDAndLaunchID(app_id1, launch_id).IsNull());
308 EXPECT_TRUE(model_->GetAppIDForShelfID(kInvalidShelfID).empty()); 318 EXPECT_TRUE(model_->GetAppIDForShelfID(ShelfID()).empty());
309 EXPECT_TRUE(model_->GetAppIDForShelfID(unknown_shelf_id).empty()); 319 EXPECT_TRUE(model_->GetAppIDForShelfID(ShelfID("foo")).empty());
310 320
311 // Add an example app with an app id and a launch id. 321 // Add an example app with an app id and a launch id.
312 ShelfItem item; 322 ShelfItem item;
313 item.type = TYPE_PINNED_APP; 323 item.type = TYPE_PINNED_APP;
314 item.app_launch_id = AppLaunchId(app_id1, launch_id); 324 item.id = ShelfID(app_id1, launch_id);
315 const ShelfID assigned_shelf_id1 = model_->next_id();
316 const int index = model_->Add(item); 325 const int index = model_->Add(item);
317 326
318 // Ensure the item ids can be found and converted as expected. 327 // Ensure the item ids can be found and converted as expected.
319 EXPECT_NE(kInvalidShelfID, assigned_shelf_id1); 328 EXPECT_EQ(item.id, model_->GetShelfIDForAppID(app_id1));
320 EXPECT_EQ(assigned_shelf_id1, model_->GetShelfIDForAppID(app_id1)); 329 EXPECT_EQ(item.id, model_->GetShelfIDForAppIDAndLaunchID(app_id1, launch_id));
321 EXPECT_EQ(assigned_shelf_id1, 330 EXPECT_NE(item.id,
322 model_->GetShelfIDForAppIDAndLaunchID(app_id1, launch_id)); 331 model_->GetShelfIDForAppIDAndLaunchID(app_id1, std::string()));
323 EXPECT_EQ(app_id1, model_->GetAppIDForShelfID(assigned_shelf_id1)); 332 EXPECT_EQ(app_id1, model_->GetAppIDForShelfID(item.id));
324 333
325 // Removing the example app should again yield invalid ids. 334 // Removing the example app should again yield invalid ids.
326 model_->RemoveItemAt(index); 335 model_->RemoveItemAt(index);
327 EXPECT_EQ(kInvalidShelfID, model_->GetShelfIDForAppID(app_id1)); 336 EXPECT_TRUE(model_->GetShelfIDForAppID(app_id1).IsNull());
328 EXPECT_EQ(kInvalidShelfID, 337 EXPECT_TRUE(
329 model_->GetShelfIDForAppIDAndLaunchID(app_id1, launch_id)); 338 model_->GetShelfIDForAppIDAndLaunchID(app_id1, launch_id).IsNull());
330 EXPECT_TRUE(model_->GetAppIDForShelfID(assigned_shelf_id1).empty()); 339 EXPECT_TRUE(model_->GetAppIDForShelfID(item.id).empty());
331 340
332 // Add an example app with a different app id and no launch id. 341 // Add an example app with a different app id and no launch id.
333 const std::string app_id2("app_id2"); 342 const std::string app_id2("app_id2");
334 item.app_launch_id = AppLaunchId(app_id2); 343 item.id = ShelfID(app_id2);
335 const ShelfID assigned_shelf_id2 = model_->next_id();
336 model_->Add(item); 344 model_->Add(item);
337 345
338 // Ensure the item ids can be found and converted as expected. 346 // Ensure the item ids can be found and converted as expected.
339 EXPECT_NE(kInvalidShelfID, assigned_shelf_id2); 347 EXPECT_EQ(item.id, model_->GetShelfIDForAppID(app_id2));
340 EXPECT_NE(assigned_shelf_id1, assigned_shelf_id2); 348 EXPECT_EQ(item.id,
341 EXPECT_EQ(assigned_shelf_id2, model_->GetShelfIDForAppID(app_id2));
342 EXPECT_EQ(assigned_shelf_id2,
343 model_->GetShelfIDForAppIDAndLaunchID(app_id2, std::string())); 349 model_->GetShelfIDForAppIDAndLaunchID(app_id2, std::string()));
344 EXPECT_EQ(kInvalidShelfID, 350 EXPECT_NE(item.id, model_->GetShelfIDForAppIDAndLaunchID(app_id2, launch_id));
345 model_->GetShelfIDForAppIDAndLaunchID(app_id2, launch_id)); 351 EXPECT_EQ(app_id2, model_->GetAppIDForShelfID(item.id));
346 EXPECT_EQ(app_id2, model_->GetAppIDForShelfID(assigned_shelf_id2));
347 } 352 }
348 353
349 // Test pinning and unpinning a closed app, and checking if it is pinned. 354 // Test pinning and unpinning a closed app, and checking if it is pinned.
350 TEST_F(ShelfModelTest, ClosedAppPinning) { 355 TEST_F(ShelfModelTest, ClosedAppPinning) {
351 const std::string app_id("app_id"); 356 const std::string app_id("app_id");
352 357
353 // Check the initial state. 358 // Check the initial state.
354 EXPECT_FALSE(model_->IsAppPinned(app_id)); 359 EXPECT_FALSE(model_->IsAppPinned(app_id));
355 EXPECT_EQ(1, model_->item_count()); 360 EXPECT_EQ(1, model_->item_count());
356 361
357 // Pinning a previously unknown app should add an item. 362 // Pinning a previously unknown app should add an item.
358 model_->PinAppWithID(app_id); 363 model_->PinAppWithID(app_id);
359 EXPECT_TRUE(model_->IsAppPinned(app_id)); 364 EXPECT_TRUE(model_->IsAppPinned(app_id));
360 EXPECT_EQ(2, model_->item_count()); 365 EXPECT_EQ(2, model_->item_count());
361 EXPECT_EQ(TYPE_PINNED_APP, model_->items()[1].type); 366 EXPECT_EQ(TYPE_PINNED_APP, model_->items()[1].type);
362 EXPECT_EQ(app_id, model_->items()[1].app_launch_id.app_id()); 367 EXPECT_EQ(app_id, model_->items()[1].id.app_id);
363 368
364 // Pinning the same app id again should have no change. 369 // Pinning the same app id again should have no change.
365 model_->PinAppWithID(app_id); 370 model_->PinAppWithID(app_id);
366 EXPECT_TRUE(model_->IsAppPinned(app_id)); 371 EXPECT_TRUE(model_->IsAppPinned(app_id));
367 EXPECT_EQ(2, model_->item_count()); 372 EXPECT_EQ(2, model_->item_count());
368 EXPECT_EQ(TYPE_PINNED_APP, model_->items()[1].type); 373 EXPECT_EQ(TYPE_PINNED_APP, model_->items()[1].type);
369 EXPECT_EQ(app_id, model_->items()[1].app_launch_id.app_id()); 374 EXPECT_EQ(app_id, model_->items()[1].id.app_id);
370 375
371 // Unpinning the app should remove the item. 376 // Unpinning the app should remove the item.
372 model_->UnpinAppWithID(app_id); 377 model_->UnpinAppWithID(app_id);
373 EXPECT_FALSE(model_->IsAppPinned(app_id)); 378 EXPECT_FALSE(model_->IsAppPinned(app_id));
374 EXPECT_EQ(1, model_->item_count()); 379 EXPECT_EQ(1, model_->item_count());
375 380
376 // Unpinning the same app id again should have no change. 381 // Unpinning the same app id again should have no change.
377 model_->UnpinAppWithID(app_id); 382 model_->UnpinAppWithID(app_id);
378 EXPECT_FALSE(model_->IsAppPinned(app_id)); 383 EXPECT_FALSE(model_->IsAppPinned(app_id));
379 EXPECT_EQ(1, model_->item_count()); 384 EXPECT_EQ(1, model_->item_count());
380 } 385 }
381 386
382 // Test pinning and unpinning a running app, and checking if it is pinned. 387 // Test pinning and unpinning a running app, and checking if it is pinned.
383 TEST_F(ShelfModelTest, RunningAppPinning) { 388 TEST_F(ShelfModelTest, RunningAppPinning) {
384 const std::string app_id("app_id"); 389 const std::string app_id("app_id");
385 390
386 // Check the initial state. 391 // Check the initial state.
387 EXPECT_FALSE(model_->IsAppPinned(app_id)); 392 EXPECT_FALSE(model_->IsAppPinned(app_id));
388 EXPECT_EQ(1, model_->item_count()); 393 EXPECT_EQ(1, model_->item_count());
389 394
390 // Add an example running app. 395 // Add an example running app.
391 ShelfItem item; 396 ShelfItem item;
392 item.type = TYPE_APP; 397 item.type = TYPE_APP;
393 item.status = STATUS_RUNNING; 398 item.status = STATUS_RUNNING;
394 item.app_launch_id = AppLaunchId(app_id); 399 item.id = ShelfID(app_id);
395 const ShelfID assigned_shelf_id = model_->next_id();
396 const int index = model_->Add(item); 400 const int index = model_->Add(item);
397 401
398 // The item should be added but not pinned. 402 // The item should be added but not pinned.
399 EXPECT_FALSE(model_->IsAppPinned(app_id)); 403 EXPECT_FALSE(model_->IsAppPinned(app_id));
400 EXPECT_EQ(2, model_->item_count()); 404 EXPECT_EQ(2, model_->item_count());
401 EXPECT_EQ(TYPE_APP, model_->items()[index].type); 405 EXPECT_EQ(TYPE_APP, model_->items()[index].type);
402 EXPECT_EQ(app_id, model_->items()[index].app_launch_id.app_id()); 406 EXPECT_EQ(item.id, model_->items()[index].id);
403 EXPECT_EQ(assigned_shelf_id, model_->items()[index].id);
404 407
405 // Pinning the item should just change its type. 408 // Pinning the item should just change its type.
406 model_->PinAppWithID(app_id); 409 model_->PinAppWithID(app_id);
407 EXPECT_TRUE(model_->IsAppPinned(app_id)); 410 EXPECT_TRUE(model_->IsAppPinned(app_id));
408 EXPECT_EQ(2, model_->item_count()); 411 EXPECT_EQ(2, model_->item_count());
409 EXPECT_EQ(TYPE_PINNED_APP, model_->items()[index].type); 412 EXPECT_EQ(TYPE_PINNED_APP, model_->items()[index].type);
410 EXPECT_EQ(app_id, model_->items()[index].app_launch_id.app_id()); 413 EXPECT_EQ(item.id, model_->items()[index].id);
411 EXPECT_EQ(assigned_shelf_id, model_->items()[index].id);
412 414
413 // Pinning the same app id again should have no change. 415 // Pinning the same app id again should have no change.
414 model_->PinAppWithID(app_id); 416 model_->PinAppWithID(app_id);
415 EXPECT_TRUE(model_->IsAppPinned(app_id)); 417 EXPECT_TRUE(model_->IsAppPinned(app_id));
416 EXPECT_EQ(2, model_->item_count()); 418 EXPECT_EQ(2, model_->item_count());
417 EXPECT_EQ(TYPE_PINNED_APP, model_->items()[index].type); 419 EXPECT_EQ(TYPE_PINNED_APP, model_->items()[index].type);
418 EXPECT_EQ(app_id, model_->items()[index].app_launch_id.app_id()); 420 EXPECT_EQ(item.id, model_->items()[index].id);
419 EXPECT_EQ(assigned_shelf_id, model_->items()[index].id);
420 421
421 // Unpinning the app should leave the item unpinnned but running. 422 // Unpinning the app should leave the item unpinnned but running.
422 model_->UnpinAppWithID(app_id); 423 model_->UnpinAppWithID(app_id);
423 EXPECT_FALSE(model_->IsAppPinned(app_id)); 424 EXPECT_FALSE(model_->IsAppPinned(app_id));
424 EXPECT_EQ(2, model_->item_count()); 425 EXPECT_EQ(2, model_->item_count());
425 EXPECT_EQ(TYPE_APP, model_->items()[index].type); 426 EXPECT_EQ(TYPE_APP, model_->items()[index].type);
426 EXPECT_EQ(app_id, model_->items()[index].app_launch_id.app_id()); 427 EXPECT_EQ(item.id, model_->items()[index].id);
427 EXPECT_EQ(assigned_shelf_id, model_->items()[index].id);
428 428
429 // Unpinning the same app id again should have no change. 429 // Unpinning the same app id again should have no change.
430 model_->UnpinAppWithID(app_id); 430 model_->UnpinAppWithID(app_id);
431 EXPECT_FALSE(model_->IsAppPinned(app_id)); 431 EXPECT_FALSE(model_->IsAppPinned(app_id));
432 EXPECT_EQ(2, model_->item_count()); 432 EXPECT_EQ(2, model_->item_count());
433 EXPECT_EQ(TYPE_APP, model_->items()[index].type); 433 EXPECT_EQ(TYPE_APP, model_->items()[index].type);
434 EXPECT_EQ(app_id, model_->items()[index].app_launch_id.app_id()); 434 EXPECT_EQ(item.id, model_->items()[index].id);
435 EXPECT_EQ(assigned_shelf_id, model_->items()[index].id);
436 } 435 }
437 436
438 } // namespace ash 437 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_model.cc ('k') | ash/shelf/shelf_tooltip_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698