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

Side by Side Diff: chrome/browser/ui/ash/launcher/chrome_launcher_controller_unittest.cc

Issue 152223002: Renames LauncherID, LauncherItem and LauncherItems... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: OWNERS Created 6 years, 10 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 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 95
96 virtual ~TestShelfModelObserver() { 96 virtual ~TestShelfModelObserver() {
97 } 97 }
98 98
99 // Overridden from ash::ShelfModelObserver: 99 // Overridden from ash::ShelfModelObserver:
100 virtual void ShelfItemAdded(int index) OVERRIDE { 100 virtual void ShelfItemAdded(int index) OVERRIDE {
101 ++added_; 101 ++added_;
102 last_index_ = index; 102 last_index_ = index;
103 } 103 }
104 104
105 virtual void ShelfItemRemoved(int index, ash::LauncherID id) OVERRIDE { 105 virtual void ShelfItemRemoved(int index, ash::ShelfID id) OVERRIDE {
106 ++removed_; 106 ++removed_;
107 last_index_ = index; 107 last_index_ = index;
108 } 108 }
109 109
110 virtual void ShelfItemChanged(int index, 110 virtual void ShelfItemChanged(int index,
111 const ash::LauncherItem& old_item) OVERRIDE { 111 const ash::ShelfItem& old_item) OVERRIDE {
112 ++changed_; 112 ++changed_;
113 last_index_ = index; 113 last_index_ = index;
114 } 114 }
115 115
116 virtual void ShelfItemMoved(int start_index, int target_index) OVERRIDE { 116 virtual void ShelfItemMoved(int start_index, int target_index) OVERRIDE {
117 last_index_ = target_index; 117 last_index_ = target_index;
118 } 118 }
119 119
120 virtual void ShelfStatusChanged() OVERRIDE { 120 virtual void ShelfStatusChanged() OVERRIDE {
121 } 121 }
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 extension8_ = Extension::Create(base::FilePath(), Manifest::UNPACKED, 354 extension8_ = Extension::Create(base::FilePath(), Manifest::UNPACKED,
355 manifest, 355 manifest,
356 Extension::NO_FLAGS, 356 Extension::NO_FLAGS,
357 "ffffffffffffffffffffffffffffffff", 357 "ffffffffffffffffffffffffffffffff",
358 &error); 358 &error);
359 } 359 }
360 360
361 // Creates a running V2 app (not pinned) of type |app_id|. 361 // Creates a running V2 app (not pinned) of type |app_id|.
362 virtual void CreateRunningV2App(const std::string& app_id) { 362 virtual void CreateRunningV2App(const std::string& app_id) {
363 DCHECK(!test_controller_); 363 DCHECK(!test_controller_);
364 ash::LauncherID id = 364 ash::ShelfID id =
365 launcher_controller_->CreateAppShortcutLauncherItemWithType( 365 launcher_controller_->CreateAppShortcutLauncherItemWithType(
366 app_id, 366 app_id,
367 model_->item_count(), 367 model_->item_count(),
368 ash::TYPE_PLATFORM_APP); 368 ash::TYPE_PLATFORM_APP);
369 DCHECK(id); 369 DCHECK(id);
370 // Change the created launcher controller into a V2 app controller. 370 // Change the created launcher controller into a V2 app controller.
371 test_controller_ = new TestV2AppLauncherItemController(app_id, 371 test_controller_ = new TestV2AppLauncherItemController(app_id,
372 launcher_controller_.get()); 372 launcher_controller_.get());
373 launcher_controller_->SetItemController(id, test_controller_); 373 launcher_controller_->SetItemController(id, test_controller_);
374 } 374 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 delete item_delegate_manager_; 416 delete item_delegate_manager_;
417 model_->RemoveObserver(model_observer_.get()); 417 model_->RemoveObserver(model_observer_.get());
418 model_observer_.reset(); 418 model_observer_.reset();
419 launcher_controller_.reset(); 419 launcher_controller_.reset();
420 model_.reset(); 420 model_.reset();
421 421
422 BrowserWithTestWindowTest::TearDown(); 422 BrowserWithTestWindowTest::TearDown();
423 } 423 }
424 424
425 void AddAppListLauncherItem() { 425 void AddAppListLauncherItem() {
426 ash::LauncherItem app_list; 426 ash::ShelfItem app_list;
427 app_list.type = ash::TYPE_APP_LIST; 427 app_list.type = ash::TYPE_APP_LIST;
428 model_->Add(app_list); 428 model_->Add(app_list);
429 } 429 }
430 430
431 void InitLauncherController() { 431 void InitLauncherController() {
432 AddAppListLauncherItem(); 432 AddAppListLauncherItem();
433 launcher_controller_.reset( 433 launcher_controller_.reset(
434 new ChromeLauncherController(profile(), model_.get())); 434 new ChromeLauncherController(profile(), model_.get()));
435 if (!ash::Shell::HasInstance()) 435 if (!ash::Shell::HasInstance())
436 SetShelfItemDelegateManager(item_delegate_manager_); 436 SetShelfItemDelegateManager(item_delegate_manager_);
(...skipping 23 matching lines...) Expand all
460 const std::string& extension_id) { 460 const std::string& extension_id) {
461 base::DictionaryValue* entry = new base::DictionaryValue(); 461 base::DictionaryValue* entry = new base::DictionaryValue();
462 entry->SetString(ash::kPinnedAppsPrefAppIDPath, extension_id); 462 entry->SetString(ash::kPinnedAppsPrefAppIDPath, extension_id);
463 pref_value->Insert(index, entry); 463 pref_value->Insert(index, entry);
464 } 464 }
465 465
466 // Gets the currently configured app launchers from the controller. 466 // Gets the currently configured app launchers from the controller.
467 void GetAppLaunchers(ChromeLauncherController* controller, 467 void GetAppLaunchers(ChromeLauncherController* controller,
468 std::vector<std::string>* launchers) { 468 std::vector<std::string>* launchers) {
469 launchers->clear(); 469 launchers->clear();
470 for (ash::LauncherItems::const_iterator iter(model_->items().begin()); 470 for (ash::ShelfItems::const_iterator iter(model_->items().begin());
471 iter != model_->items().end(); ++iter) { 471 iter != model_->items().end(); ++iter) {
472 ChromeLauncherController::IDToItemControllerMap::const_iterator 472 ChromeLauncherController::IDToItemControllerMap::const_iterator
473 entry(controller->id_to_item_controller_map_.find(iter->id)); 473 entry(controller->id_to_item_controller_map_.find(iter->id));
474 if (iter->type == ash::TYPE_APP_SHORTCUT && 474 if (iter->type == ash::TYPE_APP_SHORTCUT &&
475 entry != controller->id_to_item_controller_map_.end()) { 475 entry != controller->id_to_item_controller_map_.end()) {
476 launchers->push_back(entry->second->app_id()); 476 launchers->push_back(entry->second->app_id());
477 } 477 }
478 } 478 }
479 } 479 }
480 480
481 // Get the setup of the currently shown launcher items in one string. 481 // Get the setup of the currently shown launcher items in one string.
482 // Each pinned element will start with a big letter, each running but not 482 // Each pinned element will start with a big letter, each running but not
483 // pinned V1 app will start with a small letter and each running but not 483 // pinned V1 app will start with a small letter and each running but not
484 // pinned V2 app will start with a '*' + small letter. 484 // pinned V2 app will start with a '*' + small letter.
485 std::string GetPinnedAppStatus() { 485 std::string GetPinnedAppStatus() {
486 std::string result; 486 std::string result;
487 for (int i = 0; i < model_->item_count(); i++) { 487 for (int i = 0; i < model_->item_count(); i++) {
488 if (!result.empty()) 488 if (!result.empty())
489 result.append(", "); 489 result.append(", ");
490 switch (model_->items()[i].type) { 490 switch (model_->items()[i].type) {
491 case ash::TYPE_PLATFORM_APP: 491 case ash::TYPE_PLATFORM_APP:
492 result+= "*"; 492 result+= "*";
493 // FALLTHROUGH 493 // FALLTHROUGH
494 case ash::TYPE_WINDOWED_APP: { 494 case ash::TYPE_WINDOWED_APP: {
495 const std::string& app = 495 const std::string& app =
496 launcher_controller_->GetAppIDForLauncherID( 496 launcher_controller_->GetAppIDForShelfID(model_->items()[i].id);
497 model_->items()[i].id);
498 if (app == extension1_->id()) { 497 if (app == extension1_->id()) {
499 result += "app1"; 498 result += "app1";
500 EXPECT_FALSE( 499 EXPECT_FALSE(
501 launcher_controller_->IsAppPinned(extension1_->id())); 500 launcher_controller_->IsAppPinned(extension1_->id()));
502 } else if (app == extension2_->id()) { 501 } else if (app == extension2_->id()) {
503 result += "app2"; 502 result += "app2";
504 EXPECT_FALSE( 503 EXPECT_FALSE(
505 launcher_controller_->IsAppPinned(extension2_->id())); 504 launcher_controller_->IsAppPinned(extension2_->id()));
506 } else if (app == extension3_->id()) { 505 } else if (app == extension3_->id()) {
507 result += "app3"; 506 result += "app3";
(...skipping 18 matching lines...) Expand all
526 } else if (app == extension8_->id()) { 525 } else if (app == extension8_->id()) {
527 result += "app8"; 526 result += "app8";
528 EXPECT_FALSE( 527 EXPECT_FALSE(
529 launcher_controller_->IsAppPinned(extension8_->id())); 528 launcher_controller_->IsAppPinned(extension8_->id()));
530 } else { 529 } else {
531 result += "unknown"; 530 result += "unknown";
532 } 531 }
533 break; 532 break;
534 } 533 }
535 case ash::TYPE_APP_SHORTCUT: { 534 case ash::TYPE_APP_SHORTCUT: {
536 const std::string& app = 535 const std::string& app =
537 launcher_controller_->GetAppIDForLauncherID( 536 launcher_controller_->GetAppIDForShelfID(model_->items()[i].id);
538 model_->items()[i].id);
539 if (app == extension1_->id()) { 537 if (app == extension1_->id()) {
540 result += "App1"; 538 result += "App1";
541 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id())); 539 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension1_->id()));
542 } else if (app == extension2_->id()) { 540 } else if (app == extension2_->id()) {
543 result += "App2"; 541 result += "App2";
544 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id())); 542 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension2_->id()));
545 } else if (app == extension3_->id()) { 543 } else if (app == extension3_->id()) {
546 result += "App3"; 544 result += "App3";
547 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id())); 545 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id()));
548 } else if (app == extension4_->id()) { 546 } else if (app == extension4_->id()) {
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 InsertPrefValue(&policy_value, 2, extension3_->id()); 1005 InsertPrefValue(&policy_value, 2, extension3_->id());
1008 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 1006 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
1009 policy_value.DeepCopy()); 1007 policy_value.DeepCopy());
1010 EXPECT_EQ(0, profile()->GetPrefs()->GetInteger(prefs::kShelfChromeIconIndex)); 1008 EXPECT_EQ(0, profile()->GetPrefs()->GetInteger(prefs::kShelfChromeIconIndex));
1011 // Model should only contain the browser shortcut and app list items. 1009 // Model should only contain the browser shortcut and app list items.
1012 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1010 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1013 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 1011 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
1014 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 1012 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
1015 EXPECT_EQ("Chrome, AppList", GetPinnedAppStatus()); 1013 EXPECT_EQ("Chrome, AppList", GetPinnedAppStatus());
1016 1014
1017 // Installing |extension3_| should add it to the launcher - behind the 1015 // Installing |extension3_| should add it to the shelf - behind the
1018 // chrome icon. 1016 // chrome icon.
1019 ash::LauncherItem item; 1017 ash::ShelfItem item;
1020 extension_service_->AddExtension(extension3_.get()); 1018 extension_service_->AddExtension(extension3_.get());
1021 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1019 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1022 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 1020 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
1023 EXPECT_EQ("Chrome, App3, AppList", GetPinnedAppStatus()); 1021 EXPECT_EQ("Chrome, App3, AppList", GetPinnedAppStatus());
1024 1022
1025 // Installing |extension2_| should add it to the launcher - behind the 1023 // Installing |extension2_| should add it to the launcher - behind the
1026 // chrome icon, but in first location. 1024 // chrome icon, but in first location.
1027 extension_service_->AddExtension(extension2_.get()); 1025 extension_service_->AddExtension(extension2_.get());
1028 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1026 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1029 EXPECT_EQ("Chrome, App2, App3, AppList", GetPinnedAppStatus()); 1027 EXPECT_EQ("Chrome, App2, App3, AppList", GetPinnedAppStatus());
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1087 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 1085 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
1088 policy_value.DeepCopy()); 1086 policy_value.DeepCopy());
1089 profile()->GetTestingPrefService()->SetInteger(prefs::kShelfChromeIconIndex, 1087 profile()->GetTestingPrefService()->SetInteger(prefs::kShelfChromeIconIndex,
1090 1); 1088 1);
1091 // Model should only contain the browser shortcut and app list items. 1089 // Model should only contain the browser shortcut and app list items.
1092 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1090 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1093 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 1091 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
1094 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 1092 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
1095 EXPECT_EQ("Chrome, AppList", GetPinnedAppStatus()); 1093 EXPECT_EQ("Chrome, AppList", GetPinnedAppStatus());
1096 1094
1097 // Installing |extension2_| should add it to the launcher - behind the 1095 // Installing |extension2_| should add it to the shelf - behind the
1098 // chrome icon. 1096 // chrome icon.
1099 ash::LauncherItem item; 1097 ash::ShelfItem item;
1100 extension_service_->AddExtension(extension2_.get()); 1098 extension_service_->AddExtension(extension2_.get());
1101 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1099 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1102 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 1100 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
1103 EXPECT_EQ("Chrome, App2, AppList", GetPinnedAppStatus()); 1101 EXPECT_EQ("Chrome, App2, AppList", GetPinnedAppStatus());
1104 1102
1105 // Installing |extension1_| should add it to the launcher - behind the 1103 // Installing |extension1_| should add it to the launcher - behind the
1106 // chrome icon, but in first location. 1104 // chrome icon, but in first location.
1107 extension_service_->AddExtension(extension1_.get()); 1105 extension_service_->AddExtension(extension1_.get());
1108 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 1106 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
1109 EXPECT_EQ("App1, Chrome, App2, AppList", GetPinnedAppStatus()); 1107 EXPECT_EQ("App1, Chrome, App2, AppList", GetPinnedAppStatus());
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1168 } 1166 }
1169 1167
1170 // Check that changing from the alternate shelf layout to the old shelflayout 1168 // Check that changing from the alternate shelf layout to the old shelflayout
1171 // and back does keep the app launcher at location #0. 1169 // and back does keep the app launcher at location #0.
1172 TEST_F(ChromeLauncherControllerTest, 1170 TEST_F(ChromeLauncherControllerTest,
1173 SwitchingFromAlternateShelfLayoutToLegacyAndBack) { 1171 SwitchingFromAlternateShelfLayoutToLegacyAndBack) {
1174 InitLauncherController(); 1172 InitLauncherController();
1175 1173
1176 // We simulate this problem by intentionally placing the app list item in 1174 // We simulate this problem by intentionally placing the app list item in
1177 // the middle of several apps which caused a crash (see crbug.com/329597). 1175 // the middle of several apps which caused a crash (see crbug.com/329597).
1178 const char kAppLauncherIdPlaceholder[] = "AppLauncherIDPlaceholder--------"; 1176 const char kAppShelfIdPlaceholder[] = "AppShelfIDPlaceholder--------";
1179 1177
1180 base::ListValue policy_value; 1178 base::ListValue policy_value;
1181 InsertPrefValue(&policy_value, 0, extension1_->id()); 1179 InsertPrefValue(&policy_value, 0, extension1_->id());
1182 InsertPrefValue(&policy_value, 1, kAppLauncherIdPlaceholder); 1180 InsertPrefValue(&policy_value, 1, kAppShelfIdPlaceholder);
1183 InsertPrefValue(&policy_value, 2, extension2_->id()); 1181 InsertPrefValue(&policy_value, 2, extension2_->id());
1184 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 1182 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
1185 policy_value.DeepCopy()); 1183 policy_value.DeepCopy());
1186 EXPECT_EQ(0, profile()->GetPrefs()->GetInteger(prefs::kShelfChromeIconIndex)); 1184 EXPECT_EQ(0, profile()->GetPrefs()->GetInteger(prefs::kShelfChromeIconIndex));
1187 // Model should only contain the browser shortcut and app list items. 1185 // Model should only contain the browser shortcut and app list items.
1188 extension_service_->AddExtension(extension1_.get()); 1186 extension_service_->AddExtension(extension1_.get());
1189 extension_service_->AddExtension(extension2_.get()); 1187 extension_service_->AddExtension(extension2_.get());
1190 EXPECT_EQ("AppList, Chrome, App1, App2", GetPinnedAppStatus()); 1188 EXPECT_EQ("AppList, Chrome, App1, App2", GetPinnedAppStatus());
1191 } 1189 }
1192 1190
1193 // Check that the restauration of launcher items is happening in the same order 1191 // Check that the restauration of launcher items is happening in the same order
1194 // as the user has pinned them (on another system) when they are synced reverse 1192 // as the user has pinned them (on another system) when they are synced reverse
1195 // order. 1193 // order.
1196 TEST_F(ChromeLauncherControllerTest, RestoreDefaultAppsReverseOrder) { 1194 TEST_F(ChromeLauncherControllerTest, RestoreDefaultAppsReverseOrder) {
1197 InitLauncherController(); 1195 InitLauncherController();
1198 1196
1199 base::ListValue policy_value; 1197 base::ListValue policy_value;
1200 InsertPrefValue(&policy_value, 0, extension1_->id()); 1198 InsertPrefValue(&policy_value, 0, extension1_->id());
1201 InsertPrefValue(&policy_value, 1, extension2_->id()); 1199 InsertPrefValue(&policy_value, 1, extension2_->id());
1202 InsertPrefValue(&policy_value, 2, extension3_->id()); 1200 InsertPrefValue(&policy_value, 2, extension3_->id());
1203 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 1201 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
1204 policy_value.DeepCopy()); 1202 policy_value.DeepCopy());
1205 SetShelfChromeIconIndex(0); 1203 SetShelfChromeIconIndex(0);
1206 // Model should only contain the browser shortcut and app list items. 1204 // Model should only contain the browser shortcut and app list items.
1207 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1205 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1208 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 1206 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
1209 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 1207 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
1210 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus()); 1208 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus());
1211 1209
1212 // Installing |extension3_| should add it to the launcher - behind the 1210 // Installing |extension3_| should add it to the shelf - behind the
1213 // chrome icon. 1211 // chrome icon.
1214 ash::LauncherItem item; 1212 ash::ShelfItem item;
1215 extension_service_->AddExtension(extension3_.get()); 1213 extension_service_->AddExtension(extension3_.get());
1216 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1214 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1217 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 1215 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
1218 EXPECT_EQ("AppList, Chrome, App3", GetPinnedAppStatus()); 1216 EXPECT_EQ("AppList, Chrome, App3", GetPinnedAppStatus());
1219 1217
1220 // Installing |extension2_| should add it to the launcher - behind the 1218 // Installing |extension2_| should add it to the launcher - behind the
1221 // chrome icon, but in first location. 1219 // chrome icon, but in first location.
1222 extension_service_->AddExtension(extension2_.get()); 1220 extension_service_->AddExtension(extension2_.get());
1223 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1221 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1224 EXPECT_EQ("AppList, Chrome, App2, App3", GetPinnedAppStatus()); 1222 EXPECT_EQ("AppList, Chrome, App2, App3", GetPinnedAppStatus());
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1279 InsertPrefValue(&policy_value, 2, extension3_->id()); 1277 InsertPrefValue(&policy_value, 2, extension3_->id());
1280 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps, 1278 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
1281 policy_value.DeepCopy()); 1279 policy_value.DeepCopy());
1282 SetShelfChromeIconIndex(1); 1280 SetShelfChromeIconIndex(1);
1283 // Model should only contain the browser shortcut and app list items. 1281 // Model should only contain the browser shortcut and app list items.
1284 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1282 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1285 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 1283 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
1286 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 1284 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
1287 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus()); 1285 EXPECT_EQ("AppList, Chrome", GetPinnedAppStatus());
1288 1286
1289 // Installing |extension2_| should add it to the launcher - behind the 1287 // Installing |extension2_| should add it to the shelf - behind the
1290 // chrome icon. 1288 // chrome icon.
1291 ash::LauncherItem item; 1289 ash::ShelfItem item;
1292 extension_service_->AddExtension(extension2_.get()); 1290 extension_service_->AddExtension(extension2_.get());
1293 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1291 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1294 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 1292 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
1295 EXPECT_EQ("AppList, Chrome, App2", GetPinnedAppStatus()); 1293 EXPECT_EQ("AppList, Chrome, App2", GetPinnedAppStatus());
1296 1294
1297 // Installing |extension1_| should add it to the launcher - behind the 1295 // Installing |extension1_| should add it to the launcher - behind the
1298 // chrome icon, but in first location. 1296 // chrome icon, but in first location.
1299 extension_service_->AddExtension(extension1_.get()); 1297 extension_service_->AddExtension(extension1_.get());
1300 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 1298 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
1301 EXPECT_EQ("AppList, App1, Chrome, App2", GetPinnedAppStatus()); 1299 EXPECT_EQ("AppList, App1, Chrome, App2", GetPinnedAppStatus());
(...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after
2130 GetAppLaunchers(launcher_controller_.get(), &actual_launchers); 2128 GetAppLaunchers(launcher_controller_.get(), &actual_launchers);
2131 EXPECT_EQ(expected_launchers, actual_launchers); 2129 EXPECT_EQ(expected_launchers, actual_launchers);
2132 } 2130 }
2133 2131
2134 // Checks the created menus and menu lists for correctness. It uses the given 2132 // Checks the created menus and menu lists for correctness. It uses the given
2135 // |controller| to create the objects for the given |item| and checks the 2133 // |controller| to create the objects for the given |item| and checks the
2136 // found item count against the |expected_items|. The |title| list contains the 2134 // found item count against the |expected_items|. The |title| list contains the
2137 // menu titles in the order of their appearance in the menu (not including the 2135 // menu titles in the order of their appearance in the menu (not including the
2138 // application name). 2136 // application name).
2139 bool CheckMenuCreation(ChromeLauncherController* controller, 2137 bool CheckMenuCreation(ChromeLauncherController* controller,
2140 const ash::LauncherItem& item, 2138 const ash::ShelfItem& item,
2141 size_t expected_items, 2139 size_t expected_items,
2142 base::string16 title[], 2140 base::string16 title[],
2143 bool is_browser) { 2141 bool is_browser) {
2144 ChromeLauncherAppMenuItems items = controller->GetApplicationList(item, 0); 2142 ChromeLauncherAppMenuItems items = controller->GetApplicationList(item, 0);
2145 // A new behavior has been added: Only show menus if there is at least one 2143 // A new behavior has been added: Only show menus if there is at least one
2146 // item available. 2144 // item available.
2147 if (expected_items < 1 && is_browser) { 2145 if (expected_items < 1 && is_browser) {
2148 EXPECT_EQ(0u, items.size()); 2146 EXPECT_EQ(0u, items.size());
2149 return items.size() == 0; 2147 return items.size() == 0;
2150 } 2148 }
(...skipping 27 matching lines...) Expand all
2178 } 2176 }
2179 2177
2180 // Check that browsers get reflected correctly in the launcher menu. 2178 // Check that browsers get reflected correctly in the launcher menu.
2181 TEST_F(ChromeLauncherControllerTest, BrowserMenuGeneration) { 2179 TEST_F(ChromeLauncherControllerTest, BrowserMenuGeneration) {
2182 EXPECT_EQ(1U, chrome::GetTotalBrowserCount()); 2180 EXPECT_EQ(1U, chrome::GetTotalBrowserCount());
2183 chrome::NewTab(browser()); 2181 chrome::NewTab(browser());
2184 2182
2185 InitLauncherController(); 2183 InitLauncherController();
2186 2184
2187 // Check that the browser list is empty at this time. 2185 // Check that the browser list is empty at this time.
2188 ash::LauncherItem item_browser; 2186 ash::ShelfItem item_browser;
2189 item_browser.type = ash::TYPE_BROWSER_SHORTCUT; 2187 item_browser.type = ash::TYPE_BROWSER_SHORTCUT;
2190 item_browser.id = 2188 item_browser.id =
2191 launcher_controller_->GetLauncherIDForAppID(extension_misc::kChromeAppId); 2189 launcher_controller_->GetShelfIDForAppID(extension_misc::kChromeAppId);
2192 EXPECT_TRUE(CheckMenuCreation( 2190 EXPECT_TRUE(CheckMenuCreation(
2193 launcher_controller_.get(), item_browser, 0, NULL, true)); 2191 launcher_controller_.get(), item_browser, 0, NULL, true));
2194 2192
2195 // Now make the created browser() visible by adding it to the active browser 2193 // Now make the created browser() visible by adding it to the active browser
2196 // list. 2194 // list.
2197 BrowserList::SetLastActive(browser()); 2195 BrowserList::SetLastActive(browser());
2198 base::string16 title1 = ASCIIToUTF16("Test1"); 2196 base::string16 title1 = ASCIIToUTF16("Test1");
2199 NavigateAndCommitActiveTabWithTitle(browser(), GURL("http://test1"), title1); 2197 NavigateAndCommitActiveTabWithTitle(browser(), GURL("http://test1"), title1);
2200 base::string16 one_menu_item[] = { title1 }; 2198 base::string16 one_menu_item[] = { title1 };
2201 2199
(...skipping 21 matching lines...) Expand all
2223 } 2221 }
2224 2222
2225 #if defined(OS_CHROMEOS) 2223 #if defined(OS_CHROMEOS)
2226 // Check the multi profile case where only user related browsers should show 2224 // Check the multi profile case where only user related browsers should show
2227 // up. 2225 // up.
2228 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest, 2226 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
2229 BrowserMenuGenerationTwoUsers) { 2227 BrowserMenuGenerationTwoUsers) {
2230 // Create a browser item in the LauncherController. 2228 // Create a browser item in the LauncherController.
2231 InitLauncherController(); 2229 InitLauncherController();
2232 2230
2233 ash::LauncherItem item_browser; 2231 ash::ShelfItem item_browser;
2234 item_browser.type = ash::TYPE_BROWSER_SHORTCUT; 2232 item_browser.type = ash::TYPE_BROWSER_SHORTCUT;
2235 item_browser.id = 2233 item_browser.id =
2236 launcher_controller_->GetLauncherIDForAppID(extension_misc::kChromeAppId); 2234 launcher_controller_->GetShelfIDForAppID(extension_misc::kChromeAppId);
2237 2235
2238 // Check that the menu is empty. 2236 // Check that the menu is empty.
2239 chrome::NewTab(browser()); 2237 chrome::NewTab(browser());
2240 EXPECT_TRUE(CheckMenuCreation( 2238 EXPECT_TRUE(CheckMenuCreation(
2241 launcher_controller_.get(), item_browser, 0, NULL, true)); 2239 launcher_controller_.get(), item_browser, 0, NULL, true));
2242 2240
2243 // Show the created |browser()| by adding it to the active browser list. 2241 // Show the created |browser()| by adding it to the active browser list.
2244 BrowserList::SetLastActive(browser()); 2242 BrowserList::SetLastActive(browser());
2245 base::string16 title1 = ASCIIToUTF16("Test1"); 2243 base::string16 title1 = ASCIIToUTF16("Test1");
2246 NavigateAndCommitActiveTabWithTitle(browser(), GURL("http://test1"), title1); 2244 NavigateAndCommitActiveTabWithTitle(browser(), GURL("http://test1"), title1);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
2283 EXPECT_EQ(1U, chrome::GetTotalBrowserCount()); 2281 EXPECT_EQ(1U, chrome::GetTotalBrowserCount());
2284 EXPECT_EQ(0, browser()->tab_strip_model()->count()); 2282 EXPECT_EQ(0, browser()->tab_strip_model()->count());
2285 2283
2286 InitLauncherControllerWithBrowser(); 2284 InitLauncherControllerWithBrowser();
2287 2285
2288 // Model should only contain the browser shortcut and app list items. 2286 // Model should only contain the browser shortcut and app list items.
2289 EXPECT_EQ(2, model_->item_count()); 2287 EXPECT_EQ(2, model_->item_count());
2290 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 2288 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
2291 2289
2292 // Installing |extension3_| adds it to the launcher. 2290 // Installing |extension3_| adds it to the launcher.
2293 ash::LauncherID gmail_id = model_->next_id(); 2291 ash::ShelfID gmail_id = model_->next_id();
2294 extension_service_->AddExtension(extension3_.get()); 2292 extension_service_->AddExtension(extension3_.get());
2295 EXPECT_EQ(3, model_->item_count()); 2293 EXPECT_EQ(3, model_->item_count());
2296 int gmail_index = model_->ItemIndexByID(gmail_id); 2294 int gmail_index = model_->ItemIndexByID(gmail_id);
2297 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[gmail_index].type); 2295 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[gmail_index].type);
2298 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id())); 2296 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id()));
2299 launcher_controller_->SetRefocusURLPatternForTest(gmail_id, GURL(gmail_url)); 2297 launcher_controller_->SetRefocusURLPatternForTest(gmail_id, GURL(gmail_url));
2300 2298
2301 // Check the menu content. 2299 // Check the menu content.
2302 ash::LauncherItem item_browser; 2300 ash::ShelfItem item_browser;
2303 item_browser.type = ash::TYPE_BROWSER_SHORTCUT; 2301 item_browser.type = ash::TYPE_BROWSER_SHORTCUT;
2304 item_browser.id = 2302 item_browser.id =
2305 launcher_controller_->GetLauncherIDForAppID(extension_misc::kChromeAppId); 2303 launcher_controller_->GetShelfIDForAppID(extension_misc::kChromeAppId);
2306 2304
2307 ash::LauncherItem item_gmail; 2305 ash::ShelfItem item_gmail;
2308 item_gmail.type = ash::TYPE_APP_SHORTCUT; 2306 item_gmail.type = ash::TYPE_APP_SHORTCUT;
2309 item_gmail.id = gmail_id; 2307 item_gmail.id = gmail_id;
2310 EXPECT_TRUE(CheckMenuCreation( 2308 EXPECT_TRUE(CheckMenuCreation(
2311 launcher_controller_.get(), item_gmail, 0, NULL, false)); 2309 launcher_controller_.get(), item_gmail, 0, NULL, false));
2312 2310
2313 // Set the gmail URL to a new tab. 2311 // Set the gmail URL to a new tab.
2314 base::string16 title1 = ASCIIToUTF16("Test1"); 2312 base::string16 title1 = ASCIIToUTF16("Test1");
2315 NavigateAndCommitActiveTabWithTitle(browser(), GURL(gmail_url), title1); 2313 NavigateAndCommitActiveTabWithTitle(browser(), GURL(gmail_url), title1);
2316 2314
2317 base::string16 one_menu_item[] = { title1 }; 2315 base::string16 one_menu_item[] = { title1 };
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2353 2351
2354 #if defined(OS_CHROMEOS) 2352 #if defined(OS_CHROMEOS)
2355 // Check the multi profile case where only user related apps should show up. 2353 // Check the multi profile case where only user related apps should show up.
2356 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest, 2354 TEST_F(MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest,
2357 V1AppMenuGenerationTwoUsers) { 2355 V1AppMenuGenerationTwoUsers) {
2358 // Create a browser item in the LauncherController. 2356 // Create a browser item in the LauncherController.
2359 InitLauncherController(); 2357 InitLauncherController();
2360 chrome::NewTab(browser()); 2358 chrome::NewTab(browser());
2361 2359
2362 // Installing |extension3_| adds it to the launcher. 2360 // Installing |extension3_| adds it to the launcher.
2363 ash::LauncherID gmail_id = model_->next_id(); 2361 ash::ShelfID gmail_id = model_->next_id();
2364 extension_service_->AddExtension(extension3_.get()); 2362 extension_service_->AddExtension(extension3_.get());
2365 EXPECT_EQ(3, model_->item_count()); 2363 EXPECT_EQ(3, model_->item_count());
2366 int gmail_index = model_->ItemIndexByID(gmail_id); 2364 int gmail_index = model_->ItemIndexByID(gmail_id);
2367 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[gmail_index].type); 2365 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[gmail_index].type);
2368 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id())); 2366 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id()));
2369 launcher_controller_->SetRefocusURLPatternForTest(gmail_id, GURL(gmail_url)); 2367 launcher_controller_->SetRefocusURLPatternForTest(gmail_id, GURL(gmail_url));
2370 2368
2371 // Check the menu content. 2369 // Check the menu content.
2372 ash::LauncherItem item_browser; 2370 ash::ShelfItem item_browser;
2373 item_browser.type = ash::TYPE_BROWSER_SHORTCUT; 2371 item_browser.type = ash::TYPE_BROWSER_SHORTCUT;
2374 item_browser.id = 2372 item_browser.id =
2375 launcher_controller_->GetLauncherIDForAppID(extension_misc::kChromeAppId); 2373 launcher_controller_->GetShelfIDForAppID(extension_misc::kChromeAppId);
2376 2374
2377 ash::LauncherItem item_gmail; 2375 ash::ShelfItem item_gmail;
2378 item_gmail.type = ash::TYPE_APP_SHORTCUT; 2376 item_gmail.type = ash::TYPE_APP_SHORTCUT;
2379 item_gmail.id = gmail_id; 2377 item_gmail.id = gmail_id;
2380 EXPECT_TRUE(CheckMenuCreation( 2378 EXPECT_TRUE(CheckMenuCreation(
2381 launcher_controller_.get(), item_gmail, 0, NULL, false)); 2379 launcher_controller_.get(), item_gmail, 0, NULL, false));
2382 2380
2383 // Set the gmail URL to a new tab. 2381 // Set the gmail URL to a new tab.
2384 base::string16 title1 = ASCIIToUTF16("Test1"); 2382 base::string16 title1 = ASCIIToUTF16("Test1");
2385 NavigateAndCommitActiveTabWithTitle(browser(), GURL(gmail_url), title1); 2383 NavigateAndCommitActiveTabWithTitle(browser(), GURL(gmail_url), title1);
2386 2384
2387 base::string16 one_menu_item[] = { title1 }; 2385 base::string16 one_menu_item[] = { title1 };
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
2473 EXPECT_EQ(2, model_->item_count()); 2471 EXPECT_EQ(2, model_->item_count());
2474 } 2472 }
2475 #endif // defined(OS_CHROMEOS) 2473 #endif // defined(OS_CHROMEOS)
2476 2474
2477 // Checks that the generated menu list properly activates items. 2475 // Checks that the generated menu list properly activates items.
2478 TEST_F(ChromeLauncherControllerTest, V1AppMenuExecution) { 2476 TEST_F(ChromeLauncherControllerTest, V1AppMenuExecution) {
2479 InitLauncherControllerWithBrowser(); 2477 InitLauncherControllerWithBrowser();
2480 2478
2481 // Add |extension3_| to the launcher and add two items. 2479 // Add |extension3_| to the launcher and add two items.
2482 GURL gmail = GURL("https://mail.google.com/mail/u"); 2480 GURL gmail = GURL("https://mail.google.com/mail/u");
2483 ash::LauncherID gmail_id = model_->next_id(); 2481 ash::ShelfID gmail_id = model_->next_id();
2484 extension_service_->AddExtension(extension3_.get()); 2482 extension_service_->AddExtension(extension3_.get());
2485 launcher_controller_->SetRefocusURLPatternForTest(gmail_id, GURL(gmail_url)); 2483 launcher_controller_->SetRefocusURLPatternForTest(gmail_id, GURL(gmail_url));
2486 base::string16 title1 = ASCIIToUTF16("Test1"); 2484 base::string16 title1 = ASCIIToUTF16("Test1");
2487 NavigateAndCommitActiveTabWithTitle(browser(), GURL(gmail_url), title1); 2485 NavigateAndCommitActiveTabWithTitle(browser(), GURL(gmail_url), title1);
2488 chrome::NewTab(browser()); 2486 chrome::NewTab(browser());
2489 base::string16 title2 = ASCIIToUTF16("Test2"); 2487 base::string16 title2 = ASCIIToUTF16("Test2");
2490 NavigateAndCommitActiveTabWithTitle(browser(), GURL(gmail_url), title2); 2488 NavigateAndCommitActiveTabWithTitle(browser(), GURL(gmail_url), title2);
2491 2489
2492 // Check that the menu is properly set. 2490 // Check that the menu is properly set.
2493 ash::LauncherItem item_gmail; 2491 ash::ShelfItem item_gmail;
2494 item_gmail.type = ash::TYPE_APP_SHORTCUT; 2492 item_gmail.type = ash::TYPE_APP_SHORTCUT;
2495 item_gmail.id = gmail_id; 2493 item_gmail.id = gmail_id;
2496 base::string16 two_menu_items[] = {title1, title2}; 2494 base::string16 two_menu_items[] = {title1, title2};
2497 EXPECT_TRUE(CheckMenuCreation( 2495 EXPECT_TRUE(CheckMenuCreation(
2498 launcher_controller_.get(), item_gmail, 2, two_menu_items, false)); 2496 launcher_controller_.get(), item_gmail, 2, two_menu_items, false));
2499 EXPECT_EQ(1, browser()->tab_strip_model()->active_index()); 2497 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
2500 // Execute the second item in the list (which shouldn't do anything since that 2498 // Execute the second item in the list (which shouldn't do anything since that
2501 // item is per definition already the active tab). 2499 // item is per definition already the active tab).
2502 { 2500 {
2503 scoped_ptr<ash::ShelfMenuModel> menu(new LauncherApplicationMenuItemModel( 2501 scoped_ptr<ash::ShelfMenuModel> menu(new LauncherApplicationMenuItemModel(
(...skipping 18 matching lines...) Expand all
2522 // Now the active tab should be the second item. 2520 // Now the active tab should be the second item.
2523 EXPECT_EQ(0, browser()->tab_strip_model()->active_index()); 2521 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
2524 } 2522 }
2525 2523
2526 // Checks that the generated menu list properly deletes items. 2524 // Checks that the generated menu list properly deletes items.
2527 TEST_F(ChromeLauncherControllerTest, V1AppMenuDeletionExecution) { 2525 TEST_F(ChromeLauncherControllerTest, V1AppMenuDeletionExecution) {
2528 InitLauncherControllerWithBrowser(); 2526 InitLauncherControllerWithBrowser();
2529 2527
2530 // Add |extension3_| to the launcher and add two items. 2528 // Add |extension3_| to the launcher and add two items.
2531 GURL gmail = GURL("https://mail.google.com/mail/u"); 2529 GURL gmail = GURL("https://mail.google.com/mail/u");
2532 ash::LauncherID gmail_id = model_->next_id(); 2530 ash::ShelfID gmail_id = model_->next_id();
2533 extension_service_->AddExtension(extension3_.get()); 2531 extension_service_->AddExtension(extension3_.get());
2534 launcher_controller_->SetRefocusURLPatternForTest(gmail_id, GURL(gmail_url)); 2532 launcher_controller_->SetRefocusURLPatternForTest(gmail_id, GURL(gmail_url));
2535 base::string16 title1 = ASCIIToUTF16("Test1"); 2533 base::string16 title1 = ASCIIToUTF16("Test1");
2536 NavigateAndCommitActiveTabWithTitle(browser(), GURL(gmail_url), title1); 2534 NavigateAndCommitActiveTabWithTitle(browser(), GURL(gmail_url), title1);
2537 chrome::NewTab(browser()); 2535 chrome::NewTab(browser());
2538 base::string16 title2 = ASCIIToUTF16("Test2"); 2536 base::string16 title2 = ASCIIToUTF16("Test2");
2539 NavigateAndCommitActiveTabWithTitle(browser(), GURL(gmail_url), title2); 2537 NavigateAndCommitActiveTabWithTitle(browser(), GURL(gmail_url), title2);
2540 2538
2541 // Check that the menu is properly set. 2539 // Check that the menu is properly set.
2542 ash::LauncherItem item_gmail; 2540 ash::ShelfItem item_gmail;
2543 item_gmail.type = ash::TYPE_APP_SHORTCUT; 2541 item_gmail.type = ash::TYPE_APP_SHORTCUT;
2544 item_gmail.id = gmail_id; 2542 item_gmail.id = gmail_id;
2545 base::string16 two_menu_items[] = {title1, title2}; 2543 base::string16 two_menu_items[] = {title1, title2};
2546 EXPECT_TRUE(CheckMenuCreation( 2544 EXPECT_TRUE(CheckMenuCreation(
2547 launcher_controller_.get(), item_gmail, 2, two_menu_items, false)); 2545 launcher_controller_.get(), item_gmail, 2, two_menu_items, false));
2548 2546
2549 int tabs = browser()->tab_strip_model()->count(); 2547 int tabs = browser()->tab_strip_model()->count();
2550 // Activate the proper tab through the menu item. 2548 // Activate the proper tab through the menu item.
2551 { 2549 {
2552 ChromeLauncherAppMenuItems items = 2550 ChromeLauncherAppMenuItems items =
2553 launcher_controller_->GetApplicationList(item_gmail, 0); 2551 launcher_controller_->GetApplicationList(item_gmail, 0);
2554 items[1]->Execute(0); 2552 items[1]->Execute(0);
2555 EXPECT_EQ(tabs, browser()->tab_strip_model()->count()); 2553 EXPECT_EQ(tabs, browser()->tab_strip_model()->count());
2556 } 2554 }
2557 2555
2558 // Delete one tab through the menu item. 2556 // Delete one tab through the menu item.
2559 { 2557 {
2560 ChromeLauncherAppMenuItems items = 2558 ChromeLauncherAppMenuItems items =
2561 launcher_controller_->GetApplicationList(item_gmail, 0); 2559 launcher_controller_->GetApplicationList(item_gmail, 0);
2562 items[1]->Execute(ui::EF_SHIFT_DOWN); 2560 items[1]->Execute(ui::EF_SHIFT_DOWN);
2563 EXPECT_EQ(--tabs, browser()->tab_strip_model()->count()); 2561 EXPECT_EQ(--tabs, browser()->tab_strip_model()->count());
2564 } 2562 }
2565 } 2563 }
2566 2564
2567 // Tests that panels create launcher items correctly 2565 // Tests that panels create launcher items correctly
2568 TEST_F(ChromeLauncherControllerTest, AppPanels) { 2566 TEST_F(ChromeLauncherControllerTest, AppPanels) {
2569 InitLauncherControllerWithBrowser(); 2567 InitLauncherControllerWithBrowser();
2570 // App list and Browser shortcut LauncherItems are added. 2568 // App list and Browser shortcut ShelfItems are added.
2571 EXPECT_EQ(2, model_observer_->added()); 2569 EXPECT_EQ(2, model_observer_->added());
2572 2570
2573 TestAppIconLoaderImpl* app_icon_loader = new TestAppIconLoaderImpl(); 2571 TestAppIconLoaderImpl* app_icon_loader = new TestAppIconLoaderImpl();
2574 SetAppIconLoader(app_icon_loader); 2572 SetAppIconLoader(app_icon_loader);
2575 2573
2576 // Test adding an app panel 2574 // Test adding an app panel
2577 std::string app_id = extension1_->id(); 2575 std::string app_id = extension1_->id();
2578 ShellWindowLauncherItemController* app_panel_controller = 2576 ShellWindowLauncherItemController* app_panel_controller =
2579 new ShellWindowLauncherItemController( 2577 new ShellWindowLauncherItemController(
2580 LauncherItemController::TYPE_APP_PANEL, 2578 LauncherItemController::TYPE_APP_PANEL,
2581 "id", 2579 "id",
2582 app_id, 2580 app_id,
2583 launcher_controller_.get()); 2581 launcher_controller_.get());
2584 ash::LauncherID launcher_id1 = launcher_controller_->CreateAppLauncherItem( 2582 ash::ShelfID shelf_id1 = launcher_controller_->CreateAppLauncherItem(
2585 app_panel_controller, app_id, ash::STATUS_RUNNING); 2583 app_panel_controller, app_id, ash::STATUS_RUNNING);
2586 int panel_index = model_observer_->last_index(); 2584 int panel_index = model_observer_->last_index();
2587 EXPECT_EQ(3, model_observer_->added()); 2585 EXPECT_EQ(3, model_observer_->added());
2588 EXPECT_EQ(0, model_observer_->changed()); 2586 EXPECT_EQ(0, model_observer_->changed());
2589 EXPECT_EQ(1, app_icon_loader->fetch_count()); 2587 EXPECT_EQ(1, app_icon_loader->fetch_count());
2590 model_observer_->clear_counts(); 2588 model_observer_->clear_counts();
2591 2589
2592 // App panels should have a separate identifier than the app id 2590 // App panels should have a separate identifier than the app id
2593 EXPECT_EQ(0, launcher_controller_->GetLauncherIDForAppID(app_id)); 2591 EXPECT_EQ(0, launcher_controller_->GetShelfIDForAppID(app_id));
2594 2592
2595 // Setting the app image image should not change the panel if it set its icon 2593 // Setting the app image image should not change the panel if it set its icon
2596 app_panel_controller->set_image_set_by_controller(true); 2594 app_panel_controller->set_image_set_by_controller(true);
2597 gfx::ImageSkia image; 2595 gfx::ImageSkia image;
2598 launcher_controller_->SetAppImage(app_id, image); 2596 launcher_controller_->SetAppImage(app_id, image);
2599 EXPECT_EQ(0, model_observer_->changed()); 2597 EXPECT_EQ(0, model_observer_->changed());
2600 model_observer_->clear_counts(); 2598 model_observer_->clear_counts();
2601 2599
2602 // Add a second app panel and verify that it get the same index as the first 2600 // Add a second app panel and verify that it get the same index as the first
2603 // one had, being added to the left of the existing panel. 2601 // one had, being added to the left of the existing panel.
2604 ShellWindowLauncherItemController* app_panel_controller2 = 2602 ShellWindowLauncherItemController* app_panel_controller2 =
2605 new ShellWindowLauncherItemController( 2603 new ShellWindowLauncherItemController(
2606 LauncherItemController::TYPE_APP_PANEL, 2604 LauncherItemController::TYPE_APP_PANEL,
2607 "id", 2605 "id",
2608 app_id, 2606 app_id,
2609 launcher_controller_.get()); 2607 launcher_controller_.get());
2610 2608
2611 ash::LauncherID launcher_id2 = launcher_controller_->CreateAppLauncherItem( 2609 ash::ShelfID shelf_id2 = launcher_controller_->CreateAppLauncherItem(
2612 app_panel_controller2, app_id, ash::STATUS_RUNNING); 2610 app_panel_controller2, app_id, ash::STATUS_RUNNING);
2613 EXPECT_EQ(panel_index, model_observer_->last_index()); 2611 EXPECT_EQ(panel_index, model_observer_->last_index());
2614 EXPECT_EQ(1, model_observer_->added()); 2612 EXPECT_EQ(1, model_observer_->added());
2615 model_observer_->clear_counts(); 2613 model_observer_->clear_counts();
2616 2614
2617 launcher_controller_->CloseLauncherItem(launcher_id2); 2615 launcher_controller_->CloseLauncherItem(shelf_id2);
2618 launcher_controller_->CloseLauncherItem(launcher_id1); 2616 launcher_controller_->CloseLauncherItem(shelf_id1);
2619 EXPECT_EQ(2, model_observer_->removed()); 2617 EXPECT_EQ(2, model_observer_->removed());
2620 } 2618 }
2621 2619
2622 // Tests that the Gmail extension matches more then the app itself claims with 2620 // Tests that the Gmail extension matches more then the app itself claims with
2623 // the manifest file. 2621 // the manifest file.
2624 TEST_F(ChromeLauncherControllerTest, GmailMatching) { 2622 TEST_F(ChromeLauncherControllerTest, GmailMatching) {
2625 InitLauncherControllerWithBrowser(); 2623 InitLauncherControllerWithBrowser();
2626 2624
2627 // Create a Gmail browser tab. 2625 // Create a Gmail browser tab.
2628 chrome::NewTab(browser()); 2626 chrome::NewTab(browser());
2629 base::string16 title = ASCIIToUTF16("Test"); 2627 base::string16 title = ASCIIToUTF16("Test");
2630 NavigateAndCommitActiveTabWithTitle(browser(), GURL(gmail_url), title); 2628 NavigateAndCommitActiveTabWithTitle(browser(), GURL(gmail_url), title);
2631 content::WebContents* content = 2629 content::WebContents* content =
2632 browser()->tab_strip_model()->GetActiveWebContents(); 2630 browser()->tab_strip_model()->GetActiveWebContents();
2633 2631
2634 // Check that the launcher controller does not recognize the running app. 2632 // Check that the launcher controller does not recognize the running app.
2635 EXPECT_FALSE(launcher_controller_->ContentCanBeHandledByGmailApp(content)); 2633 EXPECT_FALSE(launcher_controller_->ContentCanBeHandledByGmailApp(content));
2636 2634
2637 // Installing |extension3_| adds it to the launcher. 2635 // Installing |extension3_| adds it to the launcher.
2638 ash::LauncherID gmail_id = model_->next_id(); 2636 ash::ShelfID gmail_id = model_->next_id();
2639 extension_service_->AddExtension(extension3_.get()); 2637 extension_service_->AddExtension(extension3_.get());
2640 EXPECT_EQ(3, model_->item_count()); 2638 EXPECT_EQ(3, model_->item_count());
2641 int gmail_index = model_->ItemIndexByID(gmail_id); 2639 int gmail_index = model_->ItemIndexByID(gmail_id);
2642 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[gmail_index].type); 2640 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[gmail_index].type);
2643 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id())); 2641 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id()));
2644 2642
2645 // Check that it is now handled. 2643 // Check that it is now handled.
2646 EXPECT_TRUE(launcher_controller_->ContentCanBeHandledByGmailApp(content)); 2644 EXPECT_TRUE(launcher_controller_->ContentCanBeHandledByGmailApp(content));
2647 2645
2648 // Check also that the app has detected that properly. 2646 // Check also that the app has detected that properly.
2649 ash::LauncherItem item_gmail; 2647 ash::ShelfItem item_gmail;
2650 item_gmail.type = ash::TYPE_APP_SHORTCUT; 2648 item_gmail.type = ash::TYPE_APP_SHORTCUT;
2651 item_gmail.id = gmail_id; 2649 item_gmail.id = gmail_id;
2652 EXPECT_EQ(2U, launcher_controller_->GetApplicationList(item_gmail, 0).size()); 2650 EXPECT_EQ(2U, launcher_controller_->GetApplicationList(item_gmail, 0).size());
2653 } 2651 }
2654 2652
2655 // Tests that the Gmail extension does not match the offline verison. 2653 // Tests that the Gmail extension does not match the offline verison.
2656 TEST_F(ChromeLauncherControllerTest, GmailOfflineMatching) { 2654 TEST_F(ChromeLauncherControllerTest, GmailOfflineMatching) {
2657 InitLauncherControllerWithBrowser(); 2655 InitLauncherControllerWithBrowser();
2658 2656
2659 // Create a Gmail browser tab. 2657 // Create a Gmail browser tab.
2660 chrome::NewTab(browser()); 2658 chrome::NewTab(browser());
2661 base::string16 title = ASCIIToUTF16("Test"); 2659 base::string16 title = ASCIIToUTF16("Test");
2662 NavigateAndCommitActiveTabWithTitle(browser(), 2660 NavigateAndCommitActiveTabWithTitle(browser(),
2663 GURL(offline_gmail_url), 2661 GURL(offline_gmail_url),
2664 title); 2662 title);
2665 content::WebContents* content = 2663 content::WebContents* content =
2666 browser()->tab_strip_model()->GetActiveWebContents(); 2664 browser()->tab_strip_model()->GetActiveWebContents();
2667 2665
2668 // Installing |extension3_| adds it to the launcher. 2666 // Installing |extension3_| adds it to the launcher.
2669 ash::LauncherID gmail_id = model_->next_id(); 2667 ash::ShelfID gmail_id = model_->next_id();
2670 extension_service_->AddExtension(extension3_.get()); 2668 extension_service_->AddExtension(extension3_.get());
2671 EXPECT_EQ(3, model_->item_count()); 2669 EXPECT_EQ(3, model_->item_count());
2672 int gmail_index = model_->ItemIndexByID(gmail_id); 2670 int gmail_index = model_->ItemIndexByID(gmail_id);
2673 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[gmail_index].type); 2671 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[gmail_index].type);
2674 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id())); 2672 EXPECT_TRUE(launcher_controller_->IsAppPinned(extension3_->id()));
2675 2673
2676 // The content should not be able to be handled by the app. 2674 // The content should not be able to be handled by the app.
2677 EXPECT_FALSE(launcher_controller_->ContentCanBeHandledByGmailApp(content)); 2675 EXPECT_FALSE(launcher_controller_->ContentCanBeHandledByGmailApp(content));
2678 } 2676 }
2679 2677
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
2728 app_tab_helper = new TestAppTabHelperImpl; 2726 app_tab_helper = new TestAppTabHelperImpl;
2729 app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); 2727 app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1");
2730 app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(1), "2"); 2728 app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(1), "2");
2731 SetAppTabHelper(app_tab_helper); 2729 SetAppTabHelper(app_tab_helper);
2732 if (!ash::Shell::HasInstance()) { 2730 if (!ash::Shell::HasInstance()) {
2733 item_delegate_manager_ = new ash::ShelfItemDelegateManager(model_.get()); 2731 item_delegate_manager_ = new ash::ShelfItemDelegateManager(model_.get());
2734 SetShelfItemDelegateManager(item_delegate_manager_); 2732 SetShelfItemDelegateManager(item_delegate_manager_);
2735 } 2733 }
2736 launcher_controller_->Init(); 2734 launcher_controller_->Init();
2737 2735
2738 // Check LauncherItems are restored after resetting ChromeLauncherController. 2736 // Check ShelfItems are restored after resetting ChromeLauncherController.
2739 EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[0].type); 2737 EXPECT_EQ(ash::TYPE_APP_LIST, model_->items()[0].type);
2740 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[1].type); 2738 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[1].type);
2741 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type); 2739 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[2].type);
2742 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_->items()[3].type); 2740 EXPECT_EQ(ash::TYPE_BROWSER_SHORTCUT, model_->items()[3].type);
2743 } 2741 }
2744 2742
2745 // Verifies pinned apps are persisted and restored. 2743 // Verifies pinned apps are persisted and restored.
2746 TEST_F(ChromeLauncherControllerTest, PersistPinned) { 2744 TEST_F(ChromeLauncherControllerTest, PersistPinned) {
2747 InitLauncherControllerWithBrowser(); 2745 InitLauncherControllerWithBrowser();
2748 size_t initial_size = model_->items().size(); 2746 size_t initial_size = model_->items().size();
2749 2747
2750 TabStripModel* tab_strip_model = browser()->tab_strip_model(); 2748 TabStripModel* tab_strip_model = browser()->tab_strip_model();
2751 EXPECT_EQ(1, tab_strip_model->count()); 2749 EXPECT_EQ(1, tab_strip_model->count());
2752 2750
2753 TestAppTabHelperImpl* app_tab_helper = new TestAppTabHelperImpl; 2751 TestAppTabHelperImpl* app_tab_helper = new TestAppTabHelperImpl;
2754 app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1"); 2752 app_tab_helper->SetAppID(tab_strip_model->GetWebContentsAt(0), "1");
2755 SetAppTabHelper(app_tab_helper); 2753 SetAppTabHelper(app_tab_helper);
2756 2754
2757 TestAppIconLoaderImpl* app_icon_loader = new TestAppIconLoaderImpl; 2755 TestAppIconLoaderImpl* app_icon_loader = new TestAppIconLoaderImpl;
2758 SetAppIconLoader(app_icon_loader); 2756 SetAppIconLoader(app_icon_loader);
2759 EXPECT_EQ(0, app_icon_loader->fetch_count()); 2757 EXPECT_EQ(0, app_icon_loader->fetch_count());
2760 2758
2761 launcher_controller_->PinAppWithID("1"); 2759 launcher_controller_->PinAppWithID("1");
2762 ash::LauncherID id = launcher_controller_->GetLauncherIDForAppID("1"); 2760 ash::ShelfID id = launcher_controller_->GetShelfIDForAppID("1");
2763 int app_index = model_->ItemIndexByID(id); 2761 int app_index = model_->ItemIndexByID(id);
2764 EXPECT_EQ(1, app_icon_loader->fetch_count()); 2762 EXPECT_EQ(1, app_icon_loader->fetch_count());
2765 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type); 2763 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type);
2766 EXPECT_TRUE(launcher_controller_->IsAppPinned("1")); 2764 EXPECT_TRUE(launcher_controller_->IsAppPinned("1"));
2767 EXPECT_FALSE(launcher_controller_->IsAppPinned("0")); 2765 EXPECT_FALSE(launcher_controller_->IsAppPinned("0"));
2768 EXPECT_EQ(initial_size + 1, model_->items().size()); 2766 EXPECT_EQ(initial_size + 1, model_->items().size());
2769 2767
2770 launcher_controller_.reset(); 2768 launcher_controller_.reset();
2771 if (!ash::Shell::HasInstance()) { 2769 if (!ash::Shell::HasInstance()) {
2772 delete item_delegate_manager_; 2770 delete item_delegate_manager_;
(...skipping 20 matching lines...) Expand all
2793 2791
2794 EXPECT_EQ(1, app_icon_loader->fetch_count()); 2792 EXPECT_EQ(1, app_icon_loader->fetch_count());
2795 ASSERT_EQ(initial_size + 1, model_->items().size()); 2793 ASSERT_EQ(initial_size + 1, model_->items().size());
2796 EXPECT_TRUE(launcher_controller_->IsAppPinned("1")); 2794 EXPECT_TRUE(launcher_controller_->IsAppPinned("1"));
2797 EXPECT_FALSE(launcher_controller_->IsAppPinned("0")); 2795 EXPECT_FALSE(launcher_controller_->IsAppPinned("0"));
2798 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type); 2796 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type);
2799 2797
2800 launcher_controller_->UnpinAppWithID("1"); 2798 launcher_controller_->UnpinAppWithID("1");
2801 ASSERT_EQ(initial_size, model_->items().size()); 2799 ASSERT_EQ(initial_size, model_->items().size());
2802 } 2800 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698