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

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

Issue 198063003: Revert of Shelf Cleanup (- binary files) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 598 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 LauncherItemController* test_controller_; 609 LauncherItemController* test_controller_;
610 610
611 ExtensionService* extension_service_; 611 ExtensionService* extension_service_;
612 612
613 ash::ShelfItemDelegateManager* item_delegate_manager_; 613 ash::ShelfItemDelegateManager* item_delegate_manager_;
614 614
615 private: 615 private:
616 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerTest); 616 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerTest);
617 }; 617 };
618 618
619 // The testing framework to test the legacy shelf layout.
620 class LegacyShelfLayoutChromeLauncherControllerTest
621 : public ChromeLauncherControllerTest {
622 protected:
623 LegacyShelfLayoutChromeLauncherControllerTest() {
624 }
625
626 virtual ~LegacyShelfLayoutChromeLauncherControllerTest() {
627 }
628
629 // Overwrite the Setup function to use the legacy shelf layout option.
630 virtual void SetUp() OVERRIDE {
631 CommandLine::ForCurrentProcess()->AppendSwitch(
632 ash::switches::kAshDisableAlternateShelfLayout);
633 ChromeLauncherControllerTest::SetUp();
634 }
635
636 private:
637 DISALLOW_COPY_AND_ASSIGN(LegacyShelfLayoutChromeLauncherControllerTest);
638 };
639
619 #if defined(OS_CHROMEOS) 640 #if defined(OS_CHROMEOS)
620 // A browser window proxy which is able to associate an aura native window with 641 // A browser window proxy which is able to associate an aura native window with
621 // it. 642 // it.
622 class TestBrowserWindowAura : public TestBrowserWindow { 643 class TestBrowserWindowAura : public TestBrowserWindow {
623 public: 644 public:
624 // |native_window| will still be owned by the caller after the constructor 645 // |native_window| will still be owned by the caller after the constructor
625 // was called. 646 // was called.
626 explicit TestBrowserWindowAura(aura::Window* native_window) 647 explicit TestBrowserWindowAura(aura::Window* native_window)
627 : native_window_(native_window) { 648 : native_window_(native_window) {
628 } 649 }
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 ash::test::TestSessionStateDelegate* session_delegate_; 965 ash::test::TestSessionStateDelegate* session_delegate_;
945 ash::test::TestShellDelegate* shell_delegate_; 966 ash::test::TestShellDelegate* shell_delegate_;
946 967
947 ProfileToNameMap created_profiles_; 968 ProfileToNameMap created_profiles_;
948 969
949 DISALLOW_COPY_AND_ASSIGN( 970 DISALLOW_COPY_AND_ASSIGN(
950 MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest); 971 MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest);
951 }; 972 };
952 #endif // defined(OS_CHROMEOS) 973 #endif // defined(OS_CHROMEOS)
953 974
975 TEST_F(LegacyShelfLayoutChromeLauncherControllerTest, DefaultApps) {
976 InitLauncherController();
977 // Model should only contain the browser shortcut and app list items.
978 EXPECT_EQ(2, model_->item_count());
979 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
980 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
981 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
982
983 // Installing |extension3_| should add it to the launcher - behind the
984 // chrome icon.
985 extension_service_->AddExtension(extension3_.get());
986 EXPECT_EQ("Chrome, App3, AppList", GetPinnedAppStatus());
987 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
988 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
989 }
990
991 // Check that the restauration of launcher items is happening in the same order
992 // as the user has pinned them (on another system) when they are synced reverse
993 // order.
994 TEST_F(LegacyShelfLayoutChromeLauncherControllerTest,
995 RestoreDefaultAppsReverseOrder) {
996 InitLauncherController();
997
998 base::ListValue policy_value;
999 InsertPrefValue(&policy_value, 0, extension1_->id());
1000 InsertPrefValue(&policy_value, 1, extension2_->id());
1001 InsertPrefValue(&policy_value, 2, extension3_->id());
1002 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
1003 policy_value.DeepCopy());
1004 EXPECT_EQ(0, profile()->GetPrefs()->GetInteger(prefs::kShelfChromeIconIndex));
1005 // Model should only contain the browser shortcut and app list items.
1006 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1007 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
1008 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
1009 EXPECT_EQ("Chrome, AppList", GetPinnedAppStatus());
1010
1011 // Installing |extension3_| should add it to the shelf - behind the
1012 // chrome icon.
1013 ash::ShelfItem item;
1014 extension_service_->AddExtension(extension3_.get());
1015 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1016 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
1017 EXPECT_EQ("Chrome, App3, AppList", GetPinnedAppStatus());
1018
1019 // Installing |extension2_| should add it to the launcher - behind the
1020 // chrome icon, but in first location.
1021 extension_service_->AddExtension(extension2_.get());
1022 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1023 EXPECT_EQ("Chrome, App2, App3, AppList", GetPinnedAppStatus());
1024
1025 // Installing |extension1_| should add it to the launcher - behind the
1026 // chrome icon, but in first location.
1027 extension_service_->AddExtension(extension1_.get());
1028 EXPECT_EQ("Chrome, App1, App2, App3, AppList", GetPinnedAppStatus());
1029 }
1030
1031 // Check that the restauration of launcher items is happening in the same order
1032 // as the user has pinned them (on another system) when they are synced random
1033 // order.
1034 TEST_F(LegacyShelfLayoutChromeLauncherControllerTest,
1035 RestoreDefaultAppsRandomOrder) {
1036 InitLauncherController();
1037
1038 base::ListValue policy_value;
1039 InsertPrefValue(&policy_value, 0, extension1_->id());
1040 InsertPrefValue(&policy_value, 1, extension2_->id());
1041 InsertPrefValue(&policy_value, 2, extension3_->id());
1042 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
1043 policy_value.DeepCopy());
1044 EXPECT_EQ(0, profile()->GetPrefs()->GetInteger(prefs::kShelfChromeIconIndex));
1045 // Model should only contain the browser shortcut and app list items.
1046 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1047 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
1048 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
1049 EXPECT_EQ("Chrome, AppList", GetPinnedAppStatus());
1050
1051 // Installing |extension2_| should add it to the launcher - behind the
1052 // chrome icon.
1053 extension_service_->AddExtension(extension2_.get());
1054 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1055 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
1056 EXPECT_EQ("Chrome, App2, AppList", GetPinnedAppStatus());
1057
1058 // Installing |extension1_| should add it to the launcher - behind the
1059 // chrome icon, but in first location.
1060 extension_service_->AddExtension(extension1_.get());
1061 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
1062 EXPECT_EQ("Chrome, App1, App2, AppList", GetPinnedAppStatus());
1063
1064 // Installing |extension3_| should add it to the launcher - behind the
1065 // chrome icon, but in first location.
1066 extension_service_->AddExtension(extension3_.get());
1067 EXPECT_EQ("Chrome, App1, App2, App3, AppList", GetPinnedAppStatus());
1068 }
1069
954 // Check that the restauration of launcher items is happening in the same order 1070 // Check that the restauration of launcher items is happening in the same order
955 // as the user has pinned / moved them (on another system) when they are synced 1071 // as the user has pinned / moved them (on another system) when they are synced
956 // random order - including the chrome icon. 1072 // random order - including the chrome icon.
1073 TEST_F(LegacyShelfLayoutChromeLauncherControllerTest,
1074 RestoreDefaultAppsRandomOrderChromeMoved) {
1075 InitLauncherController();
1076
1077 base::ListValue policy_value;
1078 InsertPrefValue(&policy_value, 0, extension1_->id());
1079 InsertPrefValue(&policy_value, 1, extension2_->id());
1080 InsertPrefValue(&policy_value, 2, extension3_->id());
1081 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
1082 policy_value.DeepCopy());
1083 profile()->GetTestingPrefService()->SetInteger(prefs::kShelfChromeIconIndex,
1084 1);
1085 // Model should only contain the browser shortcut and app list items.
1086 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1087 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
1088 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
1089 EXPECT_EQ("Chrome, AppList", GetPinnedAppStatus());
1090
1091 // Installing |extension2_| should add it to the shelf - behind the
1092 // chrome icon.
1093 ash::ShelfItem item;
1094 extension_service_->AddExtension(extension2_.get());
1095 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1096 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
1097 EXPECT_EQ("Chrome, App2, AppList", GetPinnedAppStatus());
1098
1099 // Installing |extension1_| should add it to the launcher - behind the
1100 // chrome icon, but in first location.
1101 extension_service_->AddExtension(extension1_.get());
1102 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
1103 EXPECT_EQ("App1, Chrome, App2, AppList", GetPinnedAppStatus());
1104
1105 // Installing |extension3_| should add it to the launcher - behind the
1106 // chrome icon, but in first location.
1107 extension_service_->AddExtension(extension3_.get());
1108 EXPECT_EQ("App1, Chrome, App2, App3, AppList", GetPinnedAppStatus());
1109 }
1110
1111 // Check that syncing to a different state does the correct thing.
1112 TEST_F(LegacyShelfLayoutChromeLauncherControllerTest,
1113 RestoreDefaultAppsResyncOrder) {
1114 InitLauncherController();
1115 base::ListValue policy_value;
1116 InsertPrefValue(&policy_value, 0, extension1_->id());
1117 InsertPrefValue(&policy_value, 1, extension2_->id());
1118 InsertPrefValue(&policy_value, 2, extension3_->id());
1119 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
1120 policy_value.DeepCopy());
1121 EXPECT_EQ(0, profile()->GetPrefs()->GetInteger(prefs::kShelfChromeIconIndex));
1122 extension_service_->AddExtension(extension2_.get());
1123 extension_service_->AddExtension(extension1_.get());
1124 extension_service_->AddExtension(extension3_.get());
1125 EXPECT_EQ("Chrome, App1, App2, App3, AppList", GetPinnedAppStatus());
1126
1127 // Change the order with increasing chrome position and decreasing position.
1128 base::ListValue policy_value1;
1129 InsertPrefValue(&policy_value1, 0, extension3_->id());
1130 InsertPrefValue(&policy_value1, 1, extension1_->id());
1131 InsertPrefValue(&policy_value1, 2, extension2_->id());
1132 profile()->GetTestingPrefService()->SetInteger(prefs::kShelfChromeIconIndex,
1133 2);
1134 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
1135 policy_value1.DeepCopy());
1136 EXPECT_EQ("App3, App1, Chrome, App2, AppList", GetPinnedAppStatus());
1137 base::ListValue policy_value2;
1138 InsertPrefValue(&policy_value2, 0, extension2_->id());
1139 InsertPrefValue(&policy_value2, 1, extension3_->id());
1140 InsertPrefValue(&policy_value2, 2, extension1_->id());
1141 profile()->GetTestingPrefService()->SetInteger(prefs::kShelfChromeIconIndex,
1142 1);
1143 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
1144 policy_value2.DeepCopy());
1145 EXPECT_EQ("App2, Chrome, App3, App1, AppList", GetPinnedAppStatus());
1146 }
1147
957 TEST_F(ChromeLauncherControllerTest, DefaultApps) { 1148 TEST_F(ChromeLauncherControllerTest, DefaultApps) {
958 InitLauncherController(); 1149 InitLauncherController();
959 // Model should only contain the browser shortcut and app list items. 1150 // Model should only contain the browser shortcut and app list items.
960 EXPECT_EQ(2, model_->item_count()); 1151 EXPECT_EQ(2, model_->item_count());
961 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1152 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
962 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 1153 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
963 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 1154 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
964 1155
965 // Installing |extension3_| should add it to the launcher - behind the 1156 // Installing |extension3_| should add it to the launcher - behind the
966 // chrome icon. 1157 // chrome icon.
967 extension_service_->AddExtension(extension3_.get()); 1158 extension_service_->AddExtension(extension3_.get());
968 EXPECT_EQ("AppList, Chrome, App3", GetPinnedAppStatus()); 1159 EXPECT_EQ("AppList, Chrome, App3", GetPinnedAppStatus());
969 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1160 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
970 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 1161 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
971 } 1162 }
972 1163
1164 // Check that changing from the alternate shelf layout to the old shelflayout
1165 // and back does keep the app launcher at location #0.
1166 TEST_F(ChromeLauncherControllerTest,
1167 SwitchingFromAlternateShelfLayoutToLegacyAndBack) {
1168 InitLauncherController();
1169
1170 // We simulate this problem by intentionally placing the app list item in
1171 // the middle of several apps which caused a crash (see crbug.com/329597).
1172 const char kAppShelfIdPlaceholder[] = "AppShelfIDPlaceholder--------";
1173
1174 base::ListValue policy_value;
1175 InsertPrefValue(&policy_value, 0, extension1_->id());
1176 InsertPrefValue(&policy_value, 1, kAppShelfIdPlaceholder);
1177 InsertPrefValue(&policy_value, 2, extension2_->id());
1178 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
1179 policy_value.DeepCopy());
1180 EXPECT_EQ(0, profile()->GetPrefs()->GetInteger(prefs::kShelfChromeIconIndex));
1181 // Model should only contain the browser shortcut and app list items.
1182 extension_service_->AddExtension(extension1_.get());
1183 extension_service_->AddExtension(extension2_.get());
1184 EXPECT_EQ("AppList, Chrome, App1, App2", GetPinnedAppStatus());
1185 }
1186
973 // Check that the restauration of launcher items is happening in the same order 1187 // Check that the restauration of launcher items is happening in the same order
974 // as the user has pinned them (on another system) when they are synced reverse 1188 // as the user has pinned them (on another system) when they are synced reverse
975 // order. 1189 // order.
976 TEST_F(ChromeLauncherControllerTest, RestoreDefaultAppsReverseOrder) { 1190 TEST_F(ChromeLauncherControllerTest, RestoreDefaultAppsReverseOrder) {
977 InitLauncherController(); 1191 InitLauncherController();
978 1192
979 base::ListValue policy_value; 1193 base::ListValue policy_value;
980 InsertPrefValue(&policy_value, 0, extension1_->id()); 1194 InsertPrefValue(&policy_value, 0, extension1_->id());
981 InsertPrefValue(&policy_value, 1, extension2_->id()); 1195 InsertPrefValue(&policy_value, 1, extension2_->id());
982 InsertPrefValue(&policy_value, 2, extension3_->id()); 1196 InsertPrefValue(&policy_value, 2, extension3_->id());
(...skipping 1590 matching lines...) Expand 10 before | Expand all | Expand 10 after
2573 2787
2574 EXPECT_EQ(1, app_icon_loader->fetch_count()); 2788 EXPECT_EQ(1, app_icon_loader->fetch_count());
2575 ASSERT_EQ(initial_size + 1, model_->items().size()); 2789 ASSERT_EQ(initial_size + 1, model_->items().size());
2576 EXPECT_TRUE(launcher_controller_->IsAppPinned("1")); 2790 EXPECT_TRUE(launcher_controller_->IsAppPinned("1"));
2577 EXPECT_FALSE(launcher_controller_->IsAppPinned("0")); 2791 EXPECT_FALSE(launcher_controller_->IsAppPinned("0"));
2578 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type); 2792 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type);
2579 2793
2580 launcher_controller_->UnpinAppWithID("1"); 2794 launcher_controller_->UnpinAppWithID("1");
2581 ASSERT_EQ(initial_size, model_->items().size()); 2795 ASSERT_EQ(initial_size, model_->items().size());
2582 } 2796 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698