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

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

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

Powered by Google App Engine
This is Rietveld 408576698