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

Side by Side Diff: ash/launcher/launcher_model_unittest.cc

Issue 22793011: ash:Shelf - Enable Alternate Shelf and Side Shelf by default. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: missed rm #include Created 7 years, 3 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/launcher/launcher_model.h" 5 #include "ash/launcher/launcher_model.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 9
10 #include "ash/ash_switches.h"
10 #include "ash/launcher/launcher_model_observer.h" 11 #include "ash/launcher/launcher_model_observer.h"
12 #include "base/command_line.h"
11 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
12 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
13 15
14 namespace ash { 16 namespace ash {
15 17
16 namespace { 18 namespace {
17 19
18 // LauncherModelObserver implementation that tracks what message are invoked. 20 // LauncherModelObserver implementation that tracks what message are invoked.
19 class TestLauncherModelObserver : public LauncherModelObserver { 21 class TestLauncherModelObserver : public LauncherModelObserver {
20 public: 22 public:
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 } 132 }
131 133
132 // Assertions around where items are added. 134 // Assertions around where items are added.
133 TEST(LauncherModel, AddIndices) { 135 TEST(LauncherModel, AddIndices) {
134 TestLauncherModelObserver observer; 136 TestLauncherModelObserver observer;
135 LauncherModel model; 137 LauncherModel model;
136 138
137 // Model is initially populated with one item. 139 // Model is initially populated with one item.
138 EXPECT_EQ(1, model.item_count()); 140 EXPECT_EQ(1, model.item_count());
139 141
142 // Insert browser short cut at index 1.
143 LauncherItem browser_shortcut;
144 browser_shortcut.type = TYPE_BROWSER_SHORTCUT;
145 int browser_shortcut_index = model.Add(browser_shortcut);
146 EXPECT_EQ(1, browser_shortcut_index);
147
148 // Tabbed items should be after browser shortcut.
149 LauncherItem item;
150 int tabbed_index1 = model.Add(item);
151 EXPECT_EQ(2, tabbed_index1);
152
153 // Add another tabbed item, it should follow first.
154 int tabbed_index2 = model.Add(item);
155 EXPECT_EQ(3, tabbed_index2);
156
157 // APP_SHORTCUT's priority is higher than TABBED but same as
Mr4D (OOO till 08-26) 2013/08/27 02:35:14 Usually we use |APP_SHORTCUT| and so in comments.
Harry McCleave 2013/08/27 03:25:45 Done.
Mr4D (OOO till 08-26) 2013/08/27 14:13:36 Hmmm. Where? I still see the // APP_SHORTCUT prior
158 // BROWSER_SHORTCUT. So APP_SHORTCUT is located after BROWSER_SHORCUT.
159 item.type = TYPE_APP_SHORTCUT;
160 int app_shortcut_index1 = model.Add(item);
161 EXPECT_EQ(2, app_shortcut_index1);
162
163 item.type = TYPE_APP_SHORTCUT;
164 int app_shortcut_index2 = model.Add(item);
165 EXPECT_EQ(3, app_shortcut_index2);
166
167 // Check that AddAt() figures out the correct indexes for app shortcuts.
168 // APP_SHORTCUT and BROWSER_SHORTCUT has the same weight.
169 // So APP_SHORTCUT is located at index 0. And, BROWSER_SHORTCUT is located at
170 // index 1.
171 item.type = TYPE_APP_SHORTCUT;
172 int app_shortcut_index3 = model.AddAt(1, item);
173 EXPECT_EQ(1, app_shortcut_index3);
174
175 item.type = TYPE_APP_SHORTCUT;
176 int app_shortcut_index4 = model.AddAt(6, item);
177 EXPECT_EQ(5, app_shortcut_index4);
178
179 item.type = TYPE_APP_SHORTCUT;
180 int app_shortcut_index5 = model.AddAt(3, item);
181 EXPECT_EQ(3, app_shortcut_index5);
182
183 // Before there are any panels, no icons should be right aligned.
184 EXPECT_EQ(model.item_count(), model.FirstPanelIndex());
185
186 // Check that AddAt() figures out the correct indexes for tabs and panels.
187 item.type = TYPE_TABBED;
188 int tabbed_index3 = model.AddAt(3, item);
189 EXPECT_EQ(7, tabbed_index3);
190
191 item.type = TYPE_APP_PANEL;
192 int app_panel_index1 = model.AddAt(2, item);
193 EXPECT_EQ(10, app_panel_index1);
194
195 item.type = TYPE_TABBED;
196 int tabbed_index4 = model.AddAt(11, item);
197 EXPECT_EQ(10, tabbed_index4);
198
199 item.type = TYPE_APP_PANEL;
200 int app_panel_index2 = model.AddAt(12, item);
201 EXPECT_EQ(12, app_panel_index2);
202
203 item.type = TYPE_TABBED;
204 int tabbed_index5 = model.AddAt(7, item);
205 EXPECT_EQ(7, tabbed_index5);
206
207 item.type = TYPE_APP_PANEL;
208 int app_panel_index3 = model.AddAt(13, item);
209 EXPECT_EQ(13, app_panel_index3);
210
211 // Right aligned index should be the first app panel index.
212 EXPECT_EQ(12, model.FirstPanelIndex());
213
214 EXPECT_EQ(TYPE_BROWSER_SHORTCUT, model.items()[2].type);
215 EXPECT_EQ(TYPE_APP_LIST, model.items()[0].type);
216 }
217
218 TEST(LauncherModel, TestLegacyLayoutAddIndices) {
219 CommandLine::ForCurrentProcess()->AppendSwitch(
220 ash::switches::kAshDisableAlternateShelfLayout);
221 TestLauncherModelObserver observer;
222 LauncherModel model;
223
224 // Model is initially populated with one item.
225 EXPECT_EQ(1, model.item_count());
226
140 // Insert browser short cut at index 0. 227 // Insert browser short cut at index 0.
141 LauncherItem browser_shortcut; 228 LauncherItem browser_shortcut;
142 browser_shortcut.type = TYPE_BROWSER_SHORTCUT; 229 browser_shortcut.type = TYPE_BROWSER_SHORTCUT;
143 int browser_shortcut_index = model.Add(browser_shortcut); 230 int browser_shortcut_index = model.Add(browser_shortcut);
144 EXPECT_EQ(0, browser_shortcut_index); 231 EXPECT_EQ(0, browser_shortcut_index);
145 232
146 // Tabbed items should be after browser shortcut. 233 // Tabbed items should be after browser shortcut.
147 LauncherItem item; 234 LauncherItem item;
148 int tabbed_index1 = model.Add(item); 235 int tabbed_index1 = model.Add(item);
149 EXPECT_EQ(1, tabbed_index1); 236 EXPECT_EQ(1, tabbed_index1);
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 TEST(LauncherModel, CorrectMoveItemsWhenStateChange) { 334 TEST(LauncherModel, CorrectMoveItemsWhenStateChange) {
248 LauncherModel model; 335 LauncherModel model;
249 336
250 // The app list should be the last item in the list. 337 // The app list should be the last item in the list.
251 EXPECT_EQ(1, model.item_count()); 338 EXPECT_EQ(1, model.item_count());
252 339
253 // The first item is the browser. 340 // The first item is the browser.
254 LauncherItem browser_shortcut; 341 LauncherItem browser_shortcut;
255 browser_shortcut.type = TYPE_BROWSER_SHORTCUT; 342 browser_shortcut.type = TYPE_BROWSER_SHORTCUT;
256 int browser_shortcut_index = model.Add(browser_shortcut); 343 int browser_shortcut_index = model.Add(browser_shortcut);
344 EXPECT_EQ(1, browser_shortcut_index);
345
346 // Add three shortcuts. They should all be moved between the two.
347 LauncherItem item;
348 item.type = TYPE_APP_SHORTCUT;
349 int app1_index = model.Add(item);
350 EXPECT_EQ(2, app1_index);
351 int app2_index = model.Add(item);
352 EXPECT_EQ(3, app2_index);
353 int app3_index = model.Add(item);
354 EXPECT_EQ(4, app3_index);
355
356 // Now change the type of the second item and make sure that it is moving
357 // behind the shortcuts.
358 item.type = TYPE_PLATFORM_APP;
359 model.Set(app2_index, item);
360
361 // The item should have moved to the end of the list.
362 EXPECT_EQ(TYPE_PLATFORM_APP, model.items()[4].type);
363 }
364
365 TEST(LauncherModel, LegacyLayoutCorrectMoveItemsWhenStateChange) {
366 CommandLine::ForCurrentProcess()->AppendSwitch(
367 ash::switches::kAshDisableAlternateShelfLayout);
368 LauncherModel model;
369
370 // The app list should be the last item in the list.
371 EXPECT_EQ(1, model.item_count());
372
373 // The first item is the browser.
374 LauncherItem browser_shortcut;
375 browser_shortcut.type = TYPE_BROWSER_SHORTCUT;
376 int browser_shortcut_index = model.Add(browser_shortcut);
257 EXPECT_EQ(0, browser_shortcut_index); 377 EXPECT_EQ(0, browser_shortcut_index);
258 378
259 // Add three shortcuts. They should all be moved between the two. 379 // Add three shortcuts. They should all be moved between the two.
260 LauncherItem item; 380 LauncherItem item;
261 item.type = TYPE_APP_SHORTCUT; 381 item.type = TYPE_APP_SHORTCUT;
262 int app1_index = model.Add(item); 382 int app1_index = model.Add(item);
263 EXPECT_EQ(1, app1_index); 383 EXPECT_EQ(1, app1_index);
264 int app2_index = model.Add(item); 384 int app2_index = model.Add(item);
265 EXPECT_EQ(2, app2_index); 385 EXPECT_EQ(2, app2_index);
266 int app3_index = model.Add(item); 386 int app3_index = model.Add(item);
267 EXPECT_EQ(3, app3_index); 387 EXPECT_EQ(3, app3_index);
268 388
269 // Now change the type of the second item and make sure that it is moving 389 // Now change the type of the second item and make sure that it is moving
270 // behind the shortcuts. 390 // behind the shortcuts.
271 item.type = TYPE_PLATFORM_APP; 391 item.type = TYPE_PLATFORM_APP;
272 model.Set(app2_index, item); 392 model.Set(app2_index, item);
273 393
274 // The item should have moved in front of the app launcher. 394 // The item should have moved in front of the app launcher.
275 EXPECT_EQ(TYPE_PLATFORM_APP, model.items()[3].type); 395 EXPECT_EQ(TYPE_PLATFORM_APP, model.items()[3].type);
276 } 396 }
277 397
278 } // namespace ash 398 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698