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 |
180 } // namespace | 217 } // namespace |
181 | 218 |
182 class ChromeLauncherControllerTest : public BrowserWithTestWindowTest { | 219 class ChromeLauncherControllerTest : public BrowserWithTestWindowTest { |
183 protected: | 220 protected: |
184 ChromeLauncherControllerTest() : extension_service_(NULL) { | 221 ChromeLauncherControllerTest() : extension_service_(NULL) { |
185 SetHostDesktopType(chrome::HOST_DESKTOP_TYPE_ASH); | 222 SetHostDesktopType(chrome::HOST_DESKTOP_TYPE_ASH); |
186 } | 223 } |
187 | 224 |
188 virtual ~ChromeLauncherControllerTest() { | 225 virtual ~ChromeLauncherControllerTest() { |
189 } | 226 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 Extension::NO_FLAGS, | 274 Extension::NO_FLAGS, |
238 extension_misc::kGmailAppId, | 275 extension_misc::kGmailAppId, |
239 &error); | 276 &error); |
240 | 277 |
241 // Fake search extension. | 278 // Fake search extension. |
242 extension4_ = Extension::Create(base::FilePath(), Manifest::UNPACKED, | 279 extension4_ = Extension::Create(base::FilePath(), Manifest::UNPACKED, |
243 manifest, | 280 manifest, |
244 Extension::NO_FLAGS, | 281 Extension::NO_FLAGS, |
245 extension_misc::kGoogleSearchAppId, | 282 extension_misc::kGoogleSearchAppId, |
246 &error); | 283 &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()); |
247 } | 356 } |
248 | 357 |
249 virtual void TearDown() OVERRIDE { | 358 virtual void TearDown() OVERRIDE { |
250 model_->RemoveObserver(model_observer_.get()); | 359 model_->RemoveObserver(model_observer_.get()); |
251 model_observer_.reset(); | 360 model_observer_.reset(); |
252 launcher_controller_.reset(); | 361 launcher_controller_.reset(); |
253 model_.reset(); | 362 model_.reset(); |
254 | 363 |
255 BrowserWithTestWindowTest::TearDown(); | 364 BrowserWithTestWindowTest::TearDown(); |
256 } | 365 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 iter != model_->items().end(); ++iter) { | 407 iter != model_->items().end(); ++iter) { |
299 ChromeLauncherController::IDToItemControllerMap::const_iterator | 408 ChromeLauncherController::IDToItemControllerMap::const_iterator |
300 entry(controller->id_to_item_controller_map_.find(iter->id)); | 409 entry(controller->id_to_item_controller_map_.find(iter->id)); |
301 if (iter->type == ash::TYPE_APP_SHORTCUT && | 410 if (iter->type == ash::TYPE_APP_SHORTCUT && |
302 entry != controller->id_to_item_controller_map_.end()) { | 411 entry != controller->id_to_item_controller_map_.end()) { |
303 launchers->push_back(entry->second->app_id()); | 412 launchers->push_back(entry->second->app_id()); |
304 } | 413 } |
305 } | 414 } |
306 } | 415 } |
307 | 416 |
| 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. |
308 std::string GetPinnedAppStatus() { | 421 std::string GetPinnedAppStatus() { |
309 std::string result; | 422 std::string result; |
310 for (int i = 0; i < model_->item_count(); i++) { | 423 for (int i = 0; i < model_->item_count(); i++) { |
311 switch (model_->items()[i].type) { | 424 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 } |
312 case ash::TYPE_APP_SHORTCUT: { | 469 case ash::TYPE_APP_SHORTCUT: { |
313 const std::string& app = | 470 const std::string& app = |
314 launcher_controller_->GetAppIDForLauncherID( | 471 launcher_controller_->GetAppIDForLauncherID( |
315 model_->items()[i].id); | 472 model_->items()[i].id); |
316 if (app == extension1_->id()) { | 473 if (app == extension1_->id()) { |
317 result += "App1, "; | 474 result += "App1, "; |
318 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); | 475 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); |
319 } else if (app == extension2_->id()) { | 476 } else if (app == extension2_->id()) { |
320 result += "App2, "; | 477 result += "App2, "; |
321 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id())); | 478 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id())); |
322 } else if (app == extension3_->id()) { | 479 } else if (app == extension3_->id()) { |
323 result += "App3, "; | 480 result += "App3, "; |
324 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id())); | 481 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id())); |
325 } else if (app == extension4_->id()) { | 482 } else if (app == extension4_->id()) { |
326 result += "App4, "; | 483 result += "App4, "; |
327 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension4_->id())); | 484 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())); |
328 } else { | 497 } else { |
329 result += "unknown, "; | 498 result += "unknown, "; |
330 } | 499 } |
331 break; | 500 break; |
332 } | 501 } |
333 case ash::TYPE_BROWSER_SHORTCUT: | 502 case ash::TYPE_BROWSER_SHORTCUT: |
334 result += "Chrome, "; | 503 result += "Chrome, "; |
335 break; | 504 break; |
336 case ash::TYPE_APP_LIST: | 505 case ash::TYPE_APP_LIST: |
337 result += "AppList, "; | 506 result += "AppList, "; |
338 break; | 507 break; |
339 default: | 508 default: |
340 result += "Unknown"; | 509 result += "Unknown"; |
341 break; | 510 break; |
342 } | 511 } |
343 } | 512 } |
344 return result; | 513 return result; |
345 } | 514 } |
346 | 515 |
347 // Set the index at which the chrome icon should be. | 516 // Set the index at which the chrome icon should be. |
348 void SetShelfChromeIconIndex(int index) { | 517 void SetShelfChromeIconIndex(int index) { |
349 profile()->GetTestingPrefService()->SetInteger(prefs::kShelfChromeIconIndex, | 518 profile()->GetTestingPrefService()->SetInteger(prefs::kShelfChromeIconIndex, |
350 index + 1); | 519 index); |
351 } | 520 } |
352 | 521 |
353 // Needed for extension service & friends to work. | 522 // Needed for extension service & friends to work. |
354 scoped_refptr<Extension> extension1_; | 523 scoped_refptr<Extension> extension1_; |
355 scoped_refptr<Extension> extension2_; | 524 scoped_refptr<Extension> extension2_; |
356 scoped_refptr<Extension> extension3_; | 525 scoped_refptr<Extension> extension3_; |
357 scoped_refptr<Extension> extension4_; | 526 scoped_refptr<Extension> extension4_; |
| 527 scoped_refptr<Extension> extension5_; |
| 528 scoped_refptr<Extension> extension6_; |
| 529 scoped_refptr<Extension> extension7_; |
| 530 scoped_refptr<Extension> extension8_; |
358 scoped_ptr<ChromeLauncherController> launcher_controller_; | 531 scoped_ptr<ChromeLauncherController> launcher_controller_; |
359 scoped_ptr<TestLauncherModelObserver> model_observer_; | 532 scoped_ptr<TestLauncherModelObserver> model_observer_; |
360 scoped_ptr<ash::LauncherModel> model_; | 533 scoped_ptr<ash::LauncherModel> model_; |
361 | 534 |
362 ExtensionService* extension_service_; | 535 ExtensionService* extension_service_; |
363 | 536 |
364 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerTest); | 537 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerTest); |
365 }; | 538 }; |
366 | 539 |
367 // The testing framework to test the legacy shelf layout. | 540 // The testing framework to test the legacy shelf layout. |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
780 EXPECT_EQ(2, model_->item_count()); | 953 EXPECT_EQ(2, model_->item_count()); |
781 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); | 954 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); |
782 EXPECT_FALSE( | 955 EXPECT_FALSE( |
783 launcher_controller_->IsWindowedAppInLauncher(extension1_->id())); | 956 launcher_controller_->IsWindowedAppInLauncher(extension1_->id())); |
784 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); | 957 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); |
785 EXPECT_FALSE( | 958 EXPECT_FALSE( |
786 launcher_controller_->IsWindowedAppInLauncher(extension2_->id())); | 959 launcher_controller_->IsWindowedAppInLauncher(extension2_->id())); |
787 } | 960 } |
788 | 961 |
789 // Check that multiple locks of an application will be properly handled. | 962 // Check that multiple locks of an application will be properly handled. |
790 TEST_F(ChromeLauncherControllerTest, CheckMukltiLockApps) { | 963 TEST_F(ChromeLauncherControllerTest, CheckMultiLockApps) { |
791 InitLauncherController(); | 964 InitLauncherController(); |
792 // Model should only contain the browser shortcut and app list items. | 965 // Model should only contain the browser shortcut and app list items. |
793 EXPECT_EQ(2, model_->item_count()); | 966 EXPECT_EQ(2, model_->item_count()); |
794 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); | 967 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); |
795 EXPECT_FALSE( | 968 EXPECT_FALSE( |
796 launcher_controller_->IsWindowedAppInLauncher(extension1_->id())); | 969 launcher_controller_->IsWindowedAppInLauncher(extension1_->id())); |
797 | 970 |
798 for (int i = 0; i < 2; i++) { | 971 for (int i = 0; i < 2; i++) { |
799 launcher_controller_->LockV1AppWithID(extension1_->id()); | 972 launcher_controller_->LockV1AppWithID(extension1_->id()); |
800 | 973 |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
930 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); | 1103 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); |
931 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); | 1104 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); |
932 EXPECT_FALSE( | 1105 EXPECT_FALSE( |
933 launcher_controller_->IsWindowedAppInLauncher(extension1_->id())); | 1106 launcher_controller_->IsWindowedAppInLauncher(extension1_->id())); |
934 | 1107 |
935 launcher_controller_->UnpinAppWithID(extension1_->id()); | 1108 launcher_controller_->UnpinAppWithID(extension1_->id()); |
936 | 1109 |
937 EXPECT_EQ(2, model_->item_count()); | 1110 EXPECT_EQ(2, model_->item_count()); |
938 } | 1111 } |
939 | 1112 |
| 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 // Each user has a different set of applications pinned, and one user has an |
| 1295 // application running. The chrome icon is not the last item in the list. |
| 1296 // Check that when switching between the two users, the state gets properly set. |
| 1297 // There was once a bug associated with this. |
| 1298 TEST_F(ChromeLauncherControllerTest, |
| 1299 UserSwitchIconRestoreWithRunningV2AppChromeInMiddle) { |
| 1300 base::ListValue user_a; |
| 1301 base::ListValue user_b; |
| 1302 SetUpMultiUserScenario(&user_a, &user_b); |
| 1303 |
| 1304 // Run App1 and assume that it is a V2 app. |
| 1305 CreateRunningV2App(extension1_->id()); |
| 1306 |
| 1307 // Show user 1. |
| 1308 SetShelfChromeIconIndex(5); |
| 1309 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, |
| 1310 user_a.DeepCopy()); |
| 1311 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, Chrome, App6, ", |
| 1312 GetPinnedAppStatus()); |
| 1313 |
| 1314 // Show user 2. |
| 1315 SetShelfChromeIconIndex(4); |
| 1316 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, |
| 1317 user_b.DeepCopy()); |
| 1318 |
| 1319 EXPECT_EQ("AppList, App7, App8, Chrome, *app1, ", GetPinnedAppStatus()); |
| 1320 |
| 1321 // Switch back to 1. |
| 1322 SetShelfChromeIconIndex(5); |
| 1323 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, |
| 1324 user_a.DeepCopy()); |
| 1325 EXPECT_EQ("AppList, App1, App2, App3, App4, App5, Chrome, App6, ", |
| 1326 GetPinnedAppStatus()); |
| 1327 } |
| 1328 |
940 TEST_F(ChromeLauncherControllerTest, Policy) { | 1329 TEST_F(ChromeLauncherControllerTest, Policy) { |
941 extension_service_->AddExtension(extension1_.get()); | 1330 extension_service_->AddExtension(extension1_.get()); |
942 extension_service_->AddExtension(extension3_.get()); | 1331 extension_service_->AddExtension(extension3_.get()); |
943 | 1332 |
944 base::ListValue policy_value; | 1333 base::ListValue policy_value; |
945 InsertPrefValue(&policy_value, 0, extension1_->id()); | 1334 InsertPrefValue(&policy_value, 0, extension1_->id()); |
946 InsertPrefValue(&policy_value, 1, extension2_->id()); | 1335 InsertPrefValue(&policy_value, 1, extension2_->id()); |
947 profile()->GetTestingPrefService()->SetManagedPref(prefs::kPinnedLauncherApps, | 1336 profile()->GetTestingPrefService()->SetManagedPref(prefs::kPinnedLauncherApps, |
948 policy_value.DeepCopy()); | 1337 policy_value.DeepCopy()); |
949 | 1338 |
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1510 ash::LauncherID id = launcher_controller_->GetLauncherIDForAppID("1"); | 1899 ash::LauncherID id = launcher_controller_->GetLauncherIDForAppID("1"); |
1511 int app_index = model_->ItemIndexByID(id); | 1900 int app_index = model_->ItemIndexByID(id); |
1512 EXPECT_EQ(1, app_icon_loader->fetch_count()); | 1901 EXPECT_EQ(1, app_icon_loader->fetch_count()); |
1513 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type); | 1902 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type); |
1514 EXPECT_TRUE(launcher_controller_->IsAppPinned("1")); | 1903 EXPECT_TRUE(launcher_controller_->IsAppPinned("1")); |
1515 EXPECT_FALSE(launcher_controller_->IsAppPinned("0")); | 1904 EXPECT_FALSE(launcher_controller_->IsAppPinned("0")); |
1516 EXPECT_EQ(initial_size + 1, model_->items().size()); | 1905 EXPECT_EQ(initial_size + 1, model_->items().size()); |
1517 | 1906 |
1518 launcher_controller_.reset(); | 1907 launcher_controller_.reset(); |
1519 model_.reset(new ash::LauncherModel); | 1908 model_.reset(new ash::LauncherModel); |
| 1909 AddAppListLauncherItem(); |
1520 launcher_controller_.reset( | 1910 launcher_controller_.reset( |
1521 ChromeLauncherController::CreateInstance(profile(), model_.get())); | 1911 ChromeLauncherController::CreateInstance(profile(), model_.get())); |
1522 app_tab_helper = new TestAppTabHelperImpl; | 1912 app_tab_helper = new TestAppTabHelperImpl; |
1523 app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); | 1913 app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); |
1524 SetAppTabHelper(app_tab_helper); | 1914 SetAppTabHelper(app_tab_helper); |
1525 app_icon_loader = new TestAppIconLoaderImpl; | 1915 app_icon_loader = new TestAppIconLoaderImpl; |
1526 SetAppIconLoader(app_icon_loader); | 1916 SetAppIconLoader(app_icon_loader); |
1527 AddAppListLauncherItem(); | |
1528 launcher_controller_->Init(); | 1917 launcher_controller_->Init(); |
1529 | 1918 |
1530 EXPECT_EQ(1, app_icon_loader->fetch_count()); | 1919 EXPECT_EQ(1, app_icon_loader->fetch_count()); |
1531 ASSERT_EQ(initial_size + 1, model_->items().size()); | 1920 ASSERT_EQ(initial_size + 1, model_->items().size()); |
1532 EXPECT_TRUE(launcher_controller_->IsAppPinned("1")); | 1921 EXPECT_TRUE(launcher_controller_->IsAppPinned("1")); |
1533 EXPECT_FALSE(launcher_controller_->IsAppPinned("0")); | 1922 EXPECT_FALSE(launcher_controller_->IsAppPinned("0")); |
1534 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type); | 1923 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type); |
1535 | 1924 |
1536 launcher_controller_->UnpinAppWithID("1"); | 1925 launcher_controller_->UnpinAppWithID("1"); |
1537 ASSERT_EQ(initial_size, model_->items().size()); | 1926 ASSERT_EQ(initial_size, model_->items().size()); |
1538 } | 1927 } |
OLD | NEW |