OLD | NEW |
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 "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 } | 170 } |
171 | 171 |
172 private: | 172 private: |
173 typedef std::map<content::WebContents*, std::string> TabToStringMap; | 173 typedef std::map<content::WebContents*, std::string> TabToStringMap; |
174 | 174 |
175 TabToStringMap tab_id_map_; | 175 TabToStringMap tab_id_map_; |
176 | 176 |
177 DISALLOW_COPY_AND_ASSIGN(TestAppTabHelperImpl); | 177 DISALLOW_COPY_AND_ASSIGN(TestAppTabHelperImpl); |
178 }; | 178 }; |
179 | 179 |
180 // Test implementation of a V2 app launcher item controller. | |
181 class TestV2AppLauncherItemController : public LauncherItemController { | |
182 public: | |
183 TestV2AppLauncherItemController(const std::string& app_id, | |
184 ChromeLauncherController* controller) | |
185 : LauncherItemController(LauncherItemController::TYPE_APP, | |
186 app_id, | |
187 controller) { | |
188 } | |
189 | |
190 virtual ~TestV2AppLauncherItemController() {} | |
191 | |
192 // Override for LauncherItemController: | |
193 virtual string16 GetTitle() OVERRIDE { return string16(); } | |
194 virtual bool IsCurrentlyShownInWindow(aura::Window* window) const OVERRIDE { | |
195 return true; | |
196 } | |
197 virtual bool IsOpen() const OVERRIDE { return true; } | |
198 virtual bool IsVisible() const OVERRIDE { return true; } | |
199 virtual void Launch(int event_flags) OVERRIDE {} | |
200 virtual void Activate() OVERRIDE {} | |
201 virtual void Close() OVERRIDE {} | |
202 virtual void Clicked(const ui::Event& event) OVERRIDE {} | |
203 virtual void OnRemoved() OVERRIDE {} | |
204 virtual ChromeLauncherAppMenuItems GetApplicationList( | |
205 int event_flags) OVERRIDE { | |
206 ChromeLauncherAppMenuItems items; | |
207 items.push_back(new ChromeLauncherAppMenuItem(string16(), NULL, false)); | |
208 items.push_back(new ChromeLauncherAppMenuItem(string16(), NULL, false)); | |
209 return items.Pass(); | |
210 } | |
211 | |
212 private: | |
213 | |
214 DISALLOW_COPY_AND_ASSIGN(TestV2AppLauncherItemController); | |
215 }; | |
216 | |
217 } // namespace | 180 } // namespace |
218 | 181 |
219 class ChromeLauncherControllerTest : public BrowserWithTestWindowTest { | 182 class ChromeLauncherControllerTest : public BrowserWithTestWindowTest { |
220 protected: | 183 protected: |
221 ChromeLauncherControllerTest() : extension_service_(NULL) { | 184 ChromeLauncherControllerTest() : extension_service_(NULL) { |
222 SetHostDesktopType(chrome::HOST_DESKTOP_TYPE_ASH); | 185 SetHostDesktopType(chrome::HOST_DESKTOP_TYPE_ASH); |
223 } | 186 } |
224 | 187 |
225 virtual ~ChromeLauncherControllerTest() { | 188 virtual ~ChromeLauncherControllerTest() { |
226 } | 189 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 Extension::NO_FLAGS, | 237 Extension::NO_FLAGS, |
275 extension_misc::kGmailAppId, | 238 extension_misc::kGmailAppId, |
276 &error); | 239 &error); |
277 | 240 |
278 // Fake search extension. | 241 // Fake search extension. |
279 extension4_ = Extension::Create(base::FilePath(), Manifest::UNPACKED, | 242 extension4_ = Extension::Create(base::FilePath(), Manifest::UNPACKED, |
280 manifest, | 243 manifest, |
281 Extension::NO_FLAGS, | 244 Extension::NO_FLAGS, |
282 extension_misc::kGoogleSearchAppId, | 245 extension_misc::kGoogleSearchAppId, |
283 &error); | 246 &error); |
284 extension5_ = Extension::Create(base::FilePath(), Manifest::UNPACKED, | |
285 manifest, | |
286 Extension::NO_FLAGS, | |
287 "cccccccccccccccccccccccccccccccc", | |
288 &error); | |
289 extension6_ = Extension::Create(base::FilePath(), Manifest::UNPACKED, | |
290 manifest, | |
291 Extension::NO_FLAGS, | |
292 "dddddddddddddddddddddddddddddddd", | |
293 &error); | |
294 extension7_ = Extension::Create(base::FilePath(), Manifest::UNPACKED, | |
295 manifest, | |
296 Extension::NO_FLAGS, | |
297 "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", | |
298 &error); | |
299 extension8_ = Extension::Create(base::FilePath(), Manifest::UNPACKED, | |
300 manifest, | |
301 Extension::NO_FLAGS, | |
302 "ffffffffffffffffffffffffffffffff", | |
303 &error); | |
304 } | |
305 | |
306 // Creates a running V2 app (not pinned) of type |app_id|. | |
307 virtual void CreateRunningV2App(const std::string& app_id) { | |
308 ash::LauncherID id = | |
309 launcher_controller_->CreateAppShortcutLauncherItemWithType( | |
310 app_id, | |
311 model_->item_count(), | |
312 ash::TYPE_PLATFORM_APP); | |
313 DCHECK(id); | |
314 // Change the created launcher controller into a V2 app controller. | |
315 launcher_controller_->SetItemController(id, | |
316 new TestV2AppLauncherItemController(app_id, | |
317 launcher_controller_.get())); | |
318 } | |
319 | |
320 // Sets the stage for a multi user test. | |
321 virtual void SetUpMultiUserScenario(base::ListValue* user_a, | |
322 base::ListValue* user_b) { | |
323 InitLauncherController(); | |
324 EXPECT_EQ("AppList, Chrome, ", GetPinnedAppStatus()); | |
325 | |
326 // Set an empty pinned pref to begin with. | |
327 base::ListValue no_user; | |
328 SetShelfChromeIconIndex(0); | |
329 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | |
330 no_user.DeepCopy()); | |
331 EXPECT_EQ("AppList, Chrome, ", GetPinnedAppStatus()); | |
332 | |
333 // Assume all applications have been added already. | |
334 extension_service_->AddExtension(extension1_.get()); | |
335 extension_service_->AddExtension(extension2_.get()); | |
336 extension_service_->AddExtension(extension3_.get()); | |
337 extension_service_->AddExtension(extension4_.get()); | |
338 extension_service_->AddExtension(extension5_.get()); | |
339 extension_service_->AddExtension(extension6_.get()); | |
340 extension_service_->AddExtension(extension7_.get()); | |
341 extension_service_->AddExtension(extension8_.get()); | |
342 // There should be nothing in the list by now. | |
343 EXPECT_EQ("AppList, Chrome, ", GetPinnedAppStatus()); | |
344 | |
345 // Set user a preferences. | |
346 InsertPrefValue(user_a, 0, extension1_->id()); | |
347 InsertPrefValue(user_a, 1, extension2_->id()); | |
348 InsertPrefValue(user_a, 2, extension3_->id()); | |
349 InsertPrefValue(user_a, 3, extension4_->id()); | |
350 InsertPrefValue(user_a, 4, extension5_->id()); | |
351 InsertPrefValue(user_a, 5, extension6_->id()); | |
352 | |
353 // Set user b preferences. | |
354 InsertPrefValue(user_b, 0, extension7_->id()); | |
355 InsertPrefValue(user_b, 1, extension8_->id()); | |
356 } | 247 } |
357 | 248 |
358 virtual void TearDown() OVERRIDE { | 249 virtual void TearDown() OVERRIDE { |
359 model_->RemoveObserver(model_observer_.get()); | 250 model_->RemoveObserver(model_observer_.get()); |
360 model_observer_.reset(); | 251 model_observer_.reset(); |
361 launcher_controller_.reset(); | 252 launcher_controller_.reset(); |
362 model_.reset(); | 253 model_.reset(); |
363 | 254 |
364 BrowserWithTestWindowTest::TearDown(); | 255 BrowserWithTestWindowTest::TearDown(); |
365 } | 256 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 iter != model_->items().end(); ++iter) { | 298 iter != model_->items().end(); ++iter) { |
408 ChromeLauncherController::IDToItemControllerMap::const_iterator | 299 ChromeLauncherController::IDToItemControllerMap::const_iterator |
409 entry(controller->id_to_item_controller_map_.find(iter->id)); | 300 entry(controller->id_to_item_controller_map_.find(iter->id)); |
410 if (iter->type == ash::TYPE_APP_SHORTCUT && | 301 if (iter->type == ash::TYPE_APP_SHORTCUT && |
411 entry != controller->id_to_item_controller_map_.end()) { | 302 entry != controller->id_to_item_controller_map_.end()) { |
412 launchers->push_back(entry->second->app_id()); | 303 launchers->push_back(entry->second->app_id()); |
413 } | 304 } |
414 } | 305 } |
415 } | 306 } |
416 | 307 |
417 // Get the setup of the currently shown launcher items in one string. | |
418 // Each pinned element will start with a big letter, each running but not | |
419 // pinned V1 app will start with a small letter and each running but not | |
420 // pinned V2 app will start with a '*' + small letter. | |
421 std::string GetPinnedAppStatus() { | 308 std::string GetPinnedAppStatus() { |
422 std::string result; | 309 std::string result; |
423 for (int i = 0; i < model_->item_count(); i++) { | 310 for (int i = 0; i < model_->item_count(); i++) { |
424 switch (model_->items()[i].type) { | 311 switch (model_->items()[i].type) { |
425 case ash::TYPE_PLATFORM_APP: | |
426 result+= "*"; | |
427 // FALLTHROUGH | |
428 case ash::TYPE_WINDOWED_APP: { | |
429 const std::string& app = | |
430 launcher_controller_->GetAppIDForLauncherID( | |
431 model_->items()[i].id); | |
432 if (app == extension1_->id()) { | |
433 result += "app1, "; | |
434 EXPECT_FALSE( | |
435 launcher_controller_->IsAppPinned(extension1_->id())); | |
436 } else if (app == extension2_->id()) { | |
437 result += "app2, "; | |
438 EXPECT_FALSE( | |
439 launcher_controller_->IsAppPinned(extension2_->id())); | |
440 } else if (app == extension3_->id()) { | |
441 result += "app3, "; | |
442 EXPECT_FALSE( | |
443 launcher_controller_->IsAppPinned(extension3_->id())); | |
444 } else if (app == extension4_->id()) { | |
445 result += "app4, "; | |
446 EXPECT_FALSE( | |
447 launcher_controller_->IsAppPinned(extension4_->id())); | |
448 } else if (app == extension5_->id()) { | |
449 result += "app5, "; | |
450 EXPECT_FALSE( | |
451 launcher_controller_->IsAppPinned(extension5_->id())); | |
452 } else if (app == extension6_->id()) { | |
453 result += "app6, "; | |
454 EXPECT_FALSE( | |
455 launcher_controller_->IsAppPinned(extension6_->id())); | |
456 } else if (app == extension7_->id()) { | |
457 result += "app7, "; | |
458 EXPECT_FALSE( | |
459 launcher_controller_->IsAppPinned(extension7_->id())); | |
460 } else if (app == extension8_->id()) { | |
461 result += "app8, "; | |
462 EXPECT_FALSE( | |
463 launcher_controller_->IsAppPinned(extension8_->id())); | |
464 } else { | |
465 result += "unknown, "; | |
466 } | |
467 break; | |
468 } | |
469 case ash::TYPE_APP_SHORTCUT: { | 312 case ash::TYPE_APP_SHORTCUT: { |
470 const std::string& app = | 313 const std::string& app = |
471 launcher_controller_->GetAppIDForLauncherID( | 314 launcher_controller_->GetAppIDForLauncherID( |
472 model_->items()[i].id); | 315 model_->items()[i].id); |
473 if (app == extension1_->id()) { | 316 if (app == extension1_->id()) { |
474 result += "App1, "; | 317 result += "App1, "; |
475 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); | 318 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); |
476 } else if (app == extension2_->id()) { | 319 } else if (app == extension2_->id()) { |
477 result += "App2, "; | 320 result += "App2, "; |
478 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id())); | 321 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id())); |
479 } else if (app == extension3_->id()) { | 322 } else if (app == extension3_->id()) { |
480 result += "App3, "; | 323 result += "App3, "; |
481 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id())); | 324 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id())); |
482 } else if (app == extension4_->id()) { | 325 } else if (app == extension4_->id()) { |
483 result += "App4, "; | 326 result += "App4, "; |
484 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension4_->id())); | 327 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension4_->id())); |
485 } else if (app == extension5_->id()) { | |
486 result += "App5, "; | |
487 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension5_->id())); | |
488 } else if (app == extension6_->id()) { | |
489 result += "App6, "; | |
490 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension6_->id())); | |
491 } else if (app == extension7_->id()) { | |
492 result += "App7, "; | |
493 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension7_->id())); | |
494 } else if (app == extension8_->id()) { | |
495 result += "App8, "; | |
496 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension8_->id())); | |
497 } else { | 328 } else { |
498 result += "unknown, "; | 329 result += "unknown, "; |
499 } | 330 } |
500 break; | 331 break; |
501 } | 332 } |
502 case ash::TYPE_BROWSER_SHORTCUT: | 333 case ash::TYPE_BROWSER_SHORTCUT: |
503 result += "Chrome, "; | 334 result += "Chrome, "; |
504 break; | 335 break; |
505 case ash::TYPE_APP_LIST: | 336 case ash::TYPE_APP_LIST: |
506 result += "AppList, "; | 337 result += "AppList, "; |
507 break; | 338 break; |
508 default: | 339 default: |
509 result += "Unknown"; | 340 result += "Unknown"; |
510 break; | 341 break; |
511 } | 342 } |
512 } | 343 } |
513 return result; | 344 return result; |
514 } | 345 } |
515 | 346 |
516 // Set the index at which the chrome icon should be. | 347 // Set the index at which the chrome icon should be. |
517 void SetShelfChromeIconIndex(int index) { | 348 void SetShelfChromeIconIndex(int index) { |
518 profile()->GetTestingPrefService()->SetInteger(prefs::kShelfChromeIconIndex, | 349 profile()->GetTestingPrefService()->SetInteger(prefs::kShelfChromeIconIndex, |
519 index); | 350 index + 1); |
520 } | 351 } |
521 | 352 |
522 // Needed for extension service & friends to work. | 353 // Needed for extension service & friends to work. |
523 scoped_refptr<Extension> extension1_; | 354 scoped_refptr<Extension> extension1_; |
524 scoped_refptr<Extension> extension2_; | 355 scoped_refptr<Extension> extension2_; |
525 scoped_refptr<Extension> extension3_; | 356 scoped_refptr<Extension> extension3_; |
526 scoped_refptr<Extension> extension4_; | 357 scoped_refptr<Extension> extension4_; |
527 scoped_refptr<Extension> extension5_; | |
528 scoped_refptr<Extension> extension6_; | |
529 scoped_refptr<Extension> extension7_; | |
530 scoped_refptr<Extension> extension8_; | |
531 scoped_ptr<ChromeLauncherController> launcher_controller_; | 358 scoped_ptr<ChromeLauncherController> launcher_controller_; |
532 scoped_ptr<TestLauncherModelObserver> model_observer_; | 359 scoped_ptr<TestLauncherModelObserver> model_observer_; |
533 scoped_ptr<ash::LauncherModel> model_; | 360 scoped_ptr<ash::LauncherModel> model_; |
534 | 361 |
535 ExtensionService* extension_service_; | 362 ExtensionService* extension_service_; |
536 | 363 |
537 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerTest); | 364 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerTest); |
538 }; | 365 }; |
539 | 366 |
540 // The testing framework to test the legacy shelf layout. | 367 // The testing framework to test the legacy shelf layout. |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
953 EXPECT_EQ(2, model_->item_count()); | 780 EXPECT_EQ(2, model_->item_count()); |
954 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); | 781 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); |
955 EXPECT_FALSE( | 782 EXPECT_FALSE( |
956 launcher_controller_->IsWindowedAppInLauncher(extension1_->id())); | 783 launcher_controller_->IsWindowedAppInLauncher(extension1_->id())); |
957 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); | 784 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); |
958 EXPECT_FALSE( | 785 EXPECT_FALSE( |
959 launcher_controller_->IsWindowedAppInLauncher(extension2_->id())); | 786 launcher_controller_->IsWindowedAppInLauncher(extension2_->id())); |
960 } | 787 } |
961 | 788 |
962 // Check that multiple locks of an application will be properly handled. | 789 // Check that multiple locks of an application will be properly handled. |
963 TEST_F(ChromeLauncherControllerTest, CheckMultiLockApps) { | 790 TEST_F(ChromeLauncherControllerTest, CheckMukltiLockApps) { |
964 InitLauncherController(); | 791 InitLauncherController(); |
965 // Model should only contain the browser shortcut and app list items. | 792 // Model should only contain the browser shortcut and app list items. |
966 EXPECT_EQ(2, model_->item_count()); | 793 EXPECT_EQ(2, model_->item_count()); |
967 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); | 794 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); |
968 EXPECT_FALSE( | 795 EXPECT_FALSE( |
969 launcher_controller_->IsWindowedAppInLauncher(extension1_->id())); | 796 launcher_controller_->IsWindowedAppInLauncher(extension1_->id())); |
970 | 797 |
971 for (int i = 0; i < 2; i++) { | 798 for (int i = 0; i < 2; i++) { |
972 launcher_controller_->LockV1AppWithID(extension1_->id()); | 799 launcher_controller_->LockV1AppWithID(extension1_->id()); |
973 | 800 |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1103 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); | 930 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); |
1104 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); | 931 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); |
1105 EXPECT_FALSE( | 932 EXPECT_FALSE( |
1106 launcher_controller_->IsWindowedAppInLauncher(extension1_->id())); | 933 launcher_controller_->IsWindowedAppInLauncher(extension1_->id())); |
1107 | 934 |
1108 launcher_controller_->UnpinAppWithID(extension1_->id()); | 935 launcher_controller_->UnpinAppWithID(extension1_->id()); |
1109 | 936 |
1110 EXPECT_EQ(2, model_->item_count()); | 937 EXPECT_EQ(2, model_->item_count()); |
1111 } | 938 } |
1112 | 939 |
1113 // Check that a locked (windowed V1 application) will be properly converted | |
1114 // between locked and pinned when the order gets changed through a profile / | |
1115 // policy change. | |
1116 TEST_F(ChromeLauncherControllerTest, RestoreDefaultAndLockedAppsResyncOrder) { | |
1117 InitLauncherController(); | |
1118 base::ListValue policy_value0; | |
1119 InsertPrefValue(&policy_value0, 0, extension1_->id()); | |
1120 InsertPrefValue(&policy_value0, 1, extension3_->id()); | |
1121 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | |
1122 policy_value0.DeepCopy()); | |
1123 // The shelf layout has always one static item at the beginning (App List). | |
1124 SetShelfChromeIconIndex(0); | |
1125 extension_service_->AddExtension(extension1_.get()); | |
1126 EXPECT_EQ("AppList, Chrome, App1, ", GetPinnedAppStatus()); | |
1127 extension_service_->AddExtension(extension2_.get()); | |
1128 // No new app icon will be generated. | |
1129 EXPECT_EQ("AppList, Chrome, App1, ", GetPinnedAppStatus()); | |
1130 // Add the app as locked app which will add it (un-pinned). | |
1131 launcher_controller_->LockV1AppWithID(extension2_->id()); | |
1132 EXPECT_EQ("AppList, Chrome, App1, app2, ", GetPinnedAppStatus()); | |
1133 extension_service_->AddExtension(extension3_.get()); | |
1134 EXPECT_EQ("AppList, Chrome, App1, App3, app2, ", GetPinnedAppStatus()); | |
1135 | |
1136 // Now request to pin all items which should convert the locked item into a | |
1137 // pinned item. | |
1138 base::ListValue policy_value1; | |
1139 InsertPrefValue(&policy_value1, 0, extension3_->id()); | |
1140 InsertPrefValue(&policy_value1, 1, extension2_->id()); | |
1141 InsertPrefValue(&policy_value1, 2, extension1_->id()); | |
1142 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | |
1143 policy_value1.DeepCopy()); | |
1144 EXPECT_EQ("AppList, Chrome, App3, App2, App1, ", GetPinnedAppStatus()); | |
1145 | |
1146 // Going back to a status where there is no requirement for app 2 to be pinned | |
1147 // should convert it back to locked but not pinned and state. The position | |
1148 // is determined by the |LauncherModel|'s weight system. Since at the moment | |
1149 // the weight of a running app has the same as a shortcut, it will remain | |
1150 // where it is. Surely note ideal, but since the sync process can shift around | |
1151 // locations - as well as many other edge cases - this gets nearly impossible | |
1152 // to get right. | |
1153 // TODO(skuhne): Filed crbug.com/293761 to track of this. | |
1154 base::ListValue policy_value2; | |
1155 InsertPrefValue(&policy_value2, 0, extension3_->id()); | |
1156 InsertPrefValue(&policy_value2, 1, extension1_->id()); | |
1157 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | |
1158 policy_value2.DeepCopy()); | |
1159 EXPECT_EQ("AppList, Chrome, App3, app2, App1, ", GetPinnedAppStatus()); | |
1160 | |
1161 // Removing an item should simply close it and everything should shift. | |
1162 base::ListValue policy_value3; | |
1163 InsertPrefValue(&policy_value3, 0, extension3_->id()); | |
1164 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | |
1165 policy_value3.DeepCopy()); | |
1166 EXPECT_EQ("AppList, Chrome, App3, app2, ", GetPinnedAppStatus()); | |
1167 } | |
1168 | |
1169 // Check that a running and not pinned V2 application will be properly converted | |
1170 // between locked and pinned when the order gets changed through a profile / | |
1171 // policy change. | |
1172 TEST_F(ChromeLauncherControllerTest, | |
1173 RestoreDefaultAndRunningV2AppsResyncOrder) { | |
1174 InitLauncherController(); | |
1175 base::ListValue policy_value0; | |
1176 InsertPrefValue(&policy_value0, 0, extension1_->id()); | |
1177 InsertPrefValue(&policy_value0, 1, extension3_->id()); | |
1178 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | |
1179 policy_value0.DeepCopy()); | |
1180 // The shelf layout has always one static item at the beginning (app List). | |
1181 SetShelfChromeIconIndex(0); | |
1182 extension_service_->AddExtension(extension1_.get()); | |
1183 EXPECT_EQ("AppList, Chrome, App1, ", GetPinnedAppStatus()); | |
1184 extension_service_->AddExtension(extension2_.get()); | |
1185 // No new app icon will be generated. | |
1186 EXPECT_EQ("AppList, Chrome, App1, ", GetPinnedAppStatus()); | |
1187 // Add the app as an unpinned but running V2 app. | |
1188 CreateRunningV2App(extension2_->id()); | |
1189 EXPECT_EQ("AppList, Chrome, App1, *app2, ", GetPinnedAppStatus()); | |
1190 extension_service_->AddExtension(extension3_.get()); | |
1191 EXPECT_EQ("AppList, Chrome, App1, App3, *app2, ", GetPinnedAppStatus()); | |
1192 | |
1193 // Now request to pin all items which should convert the locked item into a | |
1194 // pinned item. | |
1195 base::ListValue policy_value1; | |
1196 InsertPrefValue(&policy_value1, 0, extension3_->id()); | |
1197 InsertPrefValue(&policy_value1, 1, extension2_->id()); | |
1198 InsertPrefValue(&policy_value1, 2, extension1_->id()); | |
1199 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | |
1200 policy_value1.DeepCopy()); | |
1201 EXPECT_EQ("AppList, Chrome, App3, App2, App1, ", GetPinnedAppStatus()); | |
1202 | |
1203 // Going back to a status where there is no requirement for app 2 to be pinned | |
1204 // should convert it back to running V2 app. Since the position is determined | |
1205 // by the |LauncherModel|'s weight system, it will be after last pinned item. | |
1206 base::ListValue policy_value2; | |
1207 InsertPrefValue(&policy_value2, 0, extension3_->id()); | |
1208 InsertPrefValue(&policy_value2, 1, extension1_->id()); | |
1209 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | |
1210 policy_value2.DeepCopy()); | |
1211 EXPECT_EQ("AppList, Chrome, App3, App1, *app2, ", GetPinnedAppStatus()); | |
1212 | |
1213 // Removing an item should simply close it and everything should shift. | |
1214 base::ListValue policy_value3; | |
1215 InsertPrefValue(&policy_value3, 0, extension3_->id()); | |
1216 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | |
1217 policy_value3.DeepCopy()); | |
1218 EXPECT_EQ("AppList, Chrome, App3, *app2, ", GetPinnedAppStatus()); | |
1219 } | |
1220 | |
1221 // Each user has a different set of applications pinned. Check that when | |
1222 // switching between the two users, the state gets properly set. | |
1223 TEST_F(ChromeLauncherControllerTest, UserSwitchIconRestore) { | |
1224 base::ListValue user_a; | |
1225 base::ListValue user_b; | |
1226 SetUpMultiUserScenario(&user_a, &user_b); | |
1227 // Show user 1. | |
1228 SetShelfChromeIconIndex(6); | |
1229 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | |
1230 user_a.DeepCopy()); | |
1231 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, App6, Chrome, ", | |
1232 GetPinnedAppStatus()); | |
1233 | |
1234 // Show user 2. | |
1235 SetShelfChromeIconIndex(4); | |
1236 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | |
1237 user_b.DeepCopy()); | |
1238 | |
1239 EXPECT_EQ("AppList, App7, App8, Chrome, ", GetPinnedAppStatus()); | |
1240 | |
1241 // Switch back to 1. | |
1242 SetShelfChromeIconIndex(8); | |
1243 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | |
1244 user_a.DeepCopy()); | |
1245 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, App6, Chrome, ", | |
1246 GetPinnedAppStatus()); | |
1247 | |
1248 // Switch back to 2. | |
1249 SetShelfChromeIconIndex(4); | |
1250 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | |
1251 user_b.DeepCopy()); | |
1252 EXPECT_EQ("AppList, App7, App8, Chrome, ", GetPinnedAppStatus()); | |
1253 } | |
1254 | |
1255 // Each user has a different set of applications pinned, and one user has an | |
1256 // application running. Check that when switching between the two users, the | |
1257 // state gets properly set. | |
1258 TEST_F(ChromeLauncherControllerTest, UserSwitchIconRestoreWithRunningV2App) { | |
1259 base::ListValue user_a; | |
1260 base::ListValue user_b; | |
1261 SetUpMultiUserScenario(&user_a, &user_b); | |
1262 | |
1263 // Run App1 and assume that it is a V2 app. | |
1264 CreateRunningV2App(extension1_->id()); | |
1265 | |
1266 // Show user 1. | |
1267 SetShelfChromeIconIndex(6); | |
1268 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | |
1269 user_a.DeepCopy()); | |
1270 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, App6, Chrome, ", | |
1271 GetPinnedAppStatus()); | |
1272 | |
1273 // Show user 2. | |
1274 SetShelfChromeIconIndex(4); | |
1275 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | |
1276 user_b.DeepCopy()); | |
1277 | |
1278 EXPECT_EQ("AppList, App7, App8, Chrome, *app1, ", GetPinnedAppStatus()); | |
1279 | |
1280 // Switch back to 1. | |
1281 SetShelfChromeIconIndex(8); | |
1282 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | |
1283 user_a.DeepCopy()); | |
1284 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, App6, Chrome, ", | |
1285 GetPinnedAppStatus()); | |
1286 | |
1287 // Switch back to 2. | |
1288 SetShelfChromeIconIndex(4); | |
1289 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, | |
1290 user_b.DeepCopy()); | |
1291 EXPECT_EQ("AppList, App7, App8, Chrome, *app1, ", GetPinnedAppStatus()); | |
1292 } | |
1293 | |
1294 TEST_F(ChromeLauncherControllerTest, Policy) { | 940 TEST_F(ChromeLauncherControllerTest, Policy) { |
1295 extension_service_->AddExtension(extension1_.get()); | 941 extension_service_->AddExtension(extension1_.get()); |
1296 extension_service_->AddExtension(extension3_.get()); | 942 extension_service_->AddExtension(extension3_.get()); |
1297 | 943 |
1298 base::ListValue policy_value; | 944 base::ListValue policy_value; |
1299 InsertPrefValue(&policy_value, 0, extension1_->id()); | 945 InsertPrefValue(&policy_value, 0, extension1_->id()); |
1300 InsertPrefValue(&policy_value, 1, extension2_->id()); | 946 InsertPrefValue(&policy_value, 1, extension2_->id()); |
1301 profile()->GetTestingPrefService()->SetManagedPref(prefs::kPinnedLauncherApps, | 947 profile()->GetTestingPrefService()->SetManagedPref(prefs::kPinnedLauncherApps, |
1302 policy_value.DeepCopy()); | 948 policy_value.DeepCopy()); |
1303 | 949 |
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1864 ash::LauncherID id = launcher_controller_->GetLauncherIDForAppID("1"); | 1510 ash::LauncherID id = launcher_controller_->GetLauncherIDForAppID("1"); |
1865 int app_index = model_->ItemIndexByID(id); | 1511 int app_index = model_->ItemIndexByID(id); |
1866 EXPECT_EQ(1, app_icon_loader->fetch_count()); | 1512 EXPECT_EQ(1, app_icon_loader->fetch_count()); |
1867 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type); | 1513 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type); |
1868 EXPECT_TRUE(launcher_controller_->IsAppPinned("1")); | 1514 EXPECT_TRUE(launcher_controller_->IsAppPinned("1")); |
1869 EXPECT_FALSE(launcher_controller_->IsAppPinned("0")); | 1515 EXPECT_FALSE(launcher_controller_->IsAppPinned("0")); |
1870 EXPECT_EQ(initial_size + 1, model_->items().size()); | 1516 EXPECT_EQ(initial_size + 1, model_->items().size()); |
1871 | 1517 |
1872 launcher_controller_.reset(); | 1518 launcher_controller_.reset(); |
1873 model_.reset(new ash::LauncherModel); | 1519 model_.reset(new ash::LauncherModel); |
1874 AddAppListLauncherItem(); | |
1875 launcher_controller_.reset( | 1520 launcher_controller_.reset( |
1876 ChromeLauncherController::CreateInstance(profile(), model_.get())); | 1521 ChromeLauncherController::CreateInstance(profile(), model_.get())); |
1877 app_tab_helper = new TestAppTabHelperImpl; | 1522 app_tab_helper = new TestAppTabHelperImpl; |
1878 app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); | 1523 app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); |
1879 SetAppTabHelper(app_tab_helper); | 1524 SetAppTabHelper(app_tab_helper); |
1880 app_icon_loader = new TestAppIconLoaderImpl; | 1525 app_icon_loader = new TestAppIconLoaderImpl; |
1881 SetAppIconLoader(app_icon_loader); | 1526 SetAppIconLoader(app_icon_loader); |
| 1527 AddAppListLauncherItem(); |
1882 launcher_controller_->Init(); | 1528 launcher_controller_->Init(); |
1883 | 1529 |
1884 EXPECT_EQ(1, app_icon_loader->fetch_count()); | 1530 EXPECT_EQ(1, app_icon_loader->fetch_count()); |
1885 ASSERT_EQ(initial_size + 1, model_->items().size()); | 1531 ASSERT_EQ(initial_size + 1, model_->items().size()); |
1886 EXPECT_TRUE(launcher_controller_->IsAppPinned("1")); | 1532 EXPECT_TRUE(launcher_controller_->IsAppPinned("1")); |
1887 EXPECT_FALSE(launcher_controller_->IsAppPinned("0")); | 1533 EXPECT_FALSE(launcher_controller_->IsAppPinned("0")); |
1888 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type); | 1534 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type); |
1889 | 1535 |
1890 launcher_controller_->UnpinAppWithID("1"); | 1536 launcher_controller_->UnpinAppWithID("1"); |
1891 ASSERT_EQ(initial_size, model_->items().size()); | 1537 ASSERT_EQ(initial_size, model_->items().size()); |
1892 } | 1538 } |
OLD | NEW |