OLD | NEW |
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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 TestLauncherModelObserver observer; | 138 TestLauncherModelObserver observer; |
137 LauncherModel model; | 139 LauncherModel model; |
138 | 140 |
139 // Model is initially populated with one item. | 141 // Model is initially populated with one item. |
140 EXPECT_EQ(1, model.item_count()); | 142 EXPECT_EQ(1, model.item_count()); |
141 | 143 |
142 // Insert browser short cut at index 0. | 144 // Insert browser short cut at index 0. |
143 LauncherItem browser_shortcut; | 145 LauncherItem browser_shortcut; |
144 browser_shortcut.type = TYPE_BROWSER_SHORTCUT; | 146 browser_shortcut.type = TYPE_BROWSER_SHORTCUT; |
145 int browser_shortcut_index = model.Add(browser_shortcut); | 147 int browser_shortcut_index = model.Add(browser_shortcut); |
| 148 EXPECT_EQ(1, browser_shortcut_index); |
| 149 |
| 150 // platform app items should be after browser shortcut. |
| 151 LauncherItem item; |
| 152 item.type = TYPE_PLATFORM_APP; |
| 153 int platform_app_index1 = model.Add(item); |
| 154 EXPECT_EQ(2, platform_app_index1); |
| 155 |
| 156 // Add another platform app item, it should follow first. |
| 157 int platform_app_index2 = model.Add(item); |
| 158 EXPECT_EQ(3, platform_app_index2); |
| 159 |
| 160 // APP_SHORTCUT priority is higher than PLATFORM_APP but same as |
| 161 // BROWSER_SHORTCUT. So APP_SHORTCUT is located after BROWSER_SHORCUT. |
| 162 item.type = TYPE_APP_SHORTCUT; |
| 163 int app_shortcut_index1 = model.Add(item); |
| 164 EXPECT_EQ(2, app_shortcut_index1); |
| 165 |
| 166 item.type = TYPE_APP_SHORTCUT; |
| 167 int app_shortcut_index2 = model.Add(item); |
| 168 EXPECT_EQ(3, app_shortcut_index2); |
| 169 |
| 170 // Check that AddAt() figures out the correct indexes for app shortcuts. |
| 171 // APP_SHORTCUT and BROWSER_SHORTCUT has the same weight. |
| 172 // So APP_SHORTCUT is located at index 0. And, BROWSER_SHORTCUT is located at |
| 173 // index 1. |
| 174 item.type = TYPE_APP_SHORTCUT; |
| 175 int app_shortcut_index3 = model.AddAt(1, item); |
| 176 EXPECT_EQ(1, app_shortcut_index3); |
| 177 |
| 178 item.type = TYPE_APP_SHORTCUT; |
| 179 int app_shortcut_index4 = model.AddAt(6, item); |
| 180 EXPECT_EQ(5, app_shortcut_index4); |
| 181 |
| 182 item.type = TYPE_APP_SHORTCUT; |
| 183 int app_shortcut_index5 = model.AddAt(3, item); |
| 184 EXPECT_EQ(3, app_shortcut_index5); |
| 185 |
| 186 // Before there are any panels, no icons should be right aligned. |
| 187 EXPECT_EQ(model.item_count(), model.FirstPanelIndex()); |
| 188 |
| 189 // Check that AddAt() figures out the correct indexes for platform apps and |
| 190 // panels. |
| 191 item.type = TYPE_PLATFORM_APP; |
| 192 int platform_app_index3 = model.AddAt(3, item); |
| 193 EXPECT_EQ(7, platform_app_index3); |
| 194 |
| 195 item.type = TYPE_APP_PANEL; |
| 196 int app_panel_index1 = model.AddAt(2, item); |
| 197 EXPECT_EQ(10, app_panel_index1); |
| 198 |
| 199 item.type = TYPE_PLATFORM_APP; |
| 200 int platform_app_index4 = model.AddAt(11, item); |
| 201 EXPECT_EQ(10, platform_app_index4); |
| 202 |
| 203 item.type = TYPE_APP_PANEL; |
| 204 int app_panel_index2 = model.AddAt(12, item); |
| 205 EXPECT_EQ(12, app_panel_index2); |
| 206 |
| 207 item.type = TYPE_PLATFORM_APP; |
| 208 int platform_app_index5 = model.AddAt(7, item); |
| 209 EXPECT_EQ(7, platform_app_index5); |
| 210 |
| 211 item.type = TYPE_APP_PANEL; |
| 212 int app_panel_index3 = model.AddAt(13, item); |
| 213 EXPECT_EQ(13, app_panel_index3); |
| 214 |
| 215 // Right aligned index should be the first app panel index. |
| 216 EXPECT_EQ(12, model.FirstPanelIndex()); |
| 217 |
| 218 EXPECT_EQ(TYPE_BROWSER_SHORTCUT, model.items()[2].type); |
| 219 EXPECT_EQ(TYPE_APP_LIST, model.items()[0].type); |
| 220 } |
| 221 |
| 222 // Assertions around where items are added. |
| 223 TEST(LauncherModel, AddIndicesForLegacyShelfLayout) { |
| 224 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 225 ash::switches::kAshDisableAlternateShelfLayout); |
| 226 TestLauncherModelObserver observer; |
| 227 LauncherModel model; |
| 228 |
| 229 // Model is initially populated with one item. |
| 230 EXPECT_EQ(1, model.item_count()); |
| 231 |
| 232 // Insert browser short cut at index 0. |
| 233 LauncherItem browser_shortcut; |
| 234 browser_shortcut.type = TYPE_BROWSER_SHORTCUT; |
| 235 int browser_shortcut_index = model.Add(browser_shortcut); |
146 EXPECT_EQ(0, browser_shortcut_index); | 236 EXPECT_EQ(0, browser_shortcut_index); |
147 | 237 |
148 // platform app items should be after browser shortcut. | 238 // platform app items should be after browser shortcut. |
149 LauncherItem item; | 239 LauncherItem item; |
150 item.type = TYPE_PLATFORM_APP; | 240 item.type = TYPE_PLATFORM_APP; |
151 int platform_app_index1 = model.Add(item); | 241 int platform_app_index1 = model.Add(item); |
152 EXPECT_EQ(1, platform_app_index1); | 242 EXPECT_EQ(1, platform_app_index1); |
153 | 243 |
154 // Add another platform app item, it should follow first. | 244 // Add another platform app item, it should follow first. |
155 int platform_app_index2 = model.Add(item); | 245 int platform_app_index2 = model.Add(item); |
156 EXPECT_EQ(2, platform_app_index2); | 246 EXPECT_EQ(2, platform_app_index2); |
157 | 247 |
158 // APP_SHORTCUT's priority is higher than PLATFORM_APP but same as | 248 // APP_SHORTCUT priority is higher than PLATFORM_APP but same as |
159 // BROWSER_SHORTCUT. So APP_SHORTCUT is located after BROWSER_SHORCUT. | 249 // BROWSER_SHORTCUT. So APP_SHORTCUT is located after BROWSER_SHORCUT. |
160 item.type = TYPE_APP_SHORTCUT; | 250 item.type = TYPE_APP_SHORTCUT; |
161 int app_shortcut_index1 = model.Add(item); | 251 int app_shortcut_index1 = model.Add(item); |
162 EXPECT_EQ(1, app_shortcut_index1); | 252 EXPECT_EQ(1, app_shortcut_index1); |
163 | 253 |
164 item.type = TYPE_APP_SHORTCUT; | 254 item.type = TYPE_APP_SHORTCUT; |
165 int app_shortcut_index2 = model.Add(item); | 255 int app_shortcut_index2 = model.Add(item); |
166 EXPECT_EQ(2, app_shortcut_index2); | 256 EXPECT_EQ(2, app_shortcut_index2); |
167 | 257 |
168 // Check that AddAt() figures out the correct indexes for app shortcuts. | 258 // Check that AddAt() figures out the correct indexes for app shortcuts. |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 TEST(LauncherModel, CorrectMoveItemsWhenStateChange) { | 341 TEST(LauncherModel, CorrectMoveItemsWhenStateChange) { |
252 LauncherModel model; | 342 LauncherModel model; |
253 | 343 |
254 // The app list should be the last item in the list. | 344 // The app list should be the last item in the list. |
255 EXPECT_EQ(1, model.item_count()); | 345 EXPECT_EQ(1, model.item_count()); |
256 | 346 |
257 // The first item is the browser. | 347 // The first item is the browser. |
258 LauncherItem browser_shortcut; | 348 LauncherItem browser_shortcut; |
259 browser_shortcut.type = TYPE_BROWSER_SHORTCUT; | 349 browser_shortcut.type = TYPE_BROWSER_SHORTCUT; |
260 int browser_shortcut_index = model.Add(browser_shortcut); | 350 int browser_shortcut_index = model.Add(browser_shortcut); |
| 351 EXPECT_EQ(1, browser_shortcut_index); |
| 352 |
| 353 // Add three shortcuts. They should all be moved between the two. |
| 354 LauncherItem item; |
| 355 item.type = TYPE_APP_SHORTCUT; |
| 356 int app1_index = model.Add(item); |
| 357 EXPECT_EQ(2, app1_index); |
| 358 int app2_index = model.Add(item); |
| 359 EXPECT_EQ(3, app2_index); |
| 360 int app3_index = model.Add(item); |
| 361 EXPECT_EQ(4, app3_index); |
| 362 |
| 363 // Now change the type of the second item and make sure that it is moving |
| 364 // behind the shortcuts. |
| 365 item.type = TYPE_PLATFORM_APP; |
| 366 model.Set(app2_index, item); |
| 367 |
| 368 // The item should have moved in front of the app launcher. |
| 369 EXPECT_EQ(TYPE_PLATFORM_APP, model.items()[4].type); |
| 370 } |
| 371 |
| 372 TEST(LauncherModel, CorrectMoveItemsWhenStateChangeForLegacyShelfLayout) { |
| 373 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 374 ash::switches::kAshDisableAlternateShelfLayout); |
| 375 LauncherModel model; |
| 376 |
| 377 // The app list should be the last item in the list. |
| 378 EXPECT_EQ(1, model.item_count()); |
| 379 |
| 380 // The first item is the browser. |
| 381 LauncherItem browser_shortcut; |
| 382 browser_shortcut.type = TYPE_BROWSER_SHORTCUT; |
| 383 int browser_shortcut_index = model.Add(browser_shortcut); |
261 EXPECT_EQ(0, browser_shortcut_index); | 384 EXPECT_EQ(0, browser_shortcut_index); |
262 | 385 |
263 // Add three shortcuts. They should all be moved between the two. | 386 // Add three shortcuts. They should all be moved between the two. |
264 LauncherItem item; | 387 LauncherItem item; |
265 item.type = TYPE_APP_SHORTCUT; | 388 item.type = TYPE_APP_SHORTCUT; |
266 int app1_index = model.Add(item); | 389 int app1_index = model.Add(item); |
267 EXPECT_EQ(1, app1_index); | 390 EXPECT_EQ(1, app1_index); |
268 int app2_index = model.Add(item); | 391 int app2_index = model.Add(item); |
269 EXPECT_EQ(2, app2_index); | 392 EXPECT_EQ(2, app2_index); |
270 int app3_index = model.Add(item); | 393 int app3_index = model.Add(item); |
271 EXPECT_EQ(3, app3_index); | 394 EXPECT_EQ(3, app3_index); |
272 | 395 |
273 // Now change the type of the second item and make sure that it is moving | 396 // Now change the type of the second item and make sure that it is moving |
274 // behind the shortcuts. | 397 // behind the shortcuts. |
275 item.type = TYPE_PLATFORM_APP; | 398 item.type = TYPE_PLATFORM_APP; |
276 model.Set(app2_index, item); | 399 model.Set(app2_index, item); |
277 | 400 |
278 // The item should have moved in front of the app launcher. | 401 // The item should have moved in front of the app launcher. |
279 EXPECT_EQ(TYPE_PLATFORM_APP, model.items()[3].type); | 402 EXPECT_EQ(TYPE_PLATFORM_APP, model.items()[3].type); |
280 } | 403 } |
281 | 404 |
282 } // namespace ash | 405 } // namespace ash |
OLD | NEW |