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

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

Issue 140323010: Ash:Shelf - Cleanup of Alternate Shelf (part 1) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ButtonSize and ButtonSpacing moved to shelf_constants Created 6 years, 11 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 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 // |item_delegate_manager_| owns |test_controller_|. 610 // |item_delegate_manager_| owns |test_controller_|.
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 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerTest); 617 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerTest);
618 }; 618 };
619 619
620 // The testing framework to test the legacy shelf layout.
621 class LegacyShelfLayoutChromeLauncherControllerTest
622 : public ChromeLauncherControllerTest {
623 protected:
624 LegacyShelfLayoutChromeLauncherControllerTest() {
625 }
626
627 virtual ~LegacyShelfLayoutChromeLauncherControllerTest() {
628 }
629
630 // Overwrite the Setup function to use the legacy shelf layout option.
631 virtual void SetUp() OVERRIDE {
632 CommandLine::ForCurrentProcess()->AppendSwitch(
633 ash::switches::kAshDisableAlternateShelfLayout);
634 ChromeLauncherControllerTest::SetUp();
635 }
636
637 private:
638
639 DISALLOW_COPY_AND_ASSIGN(LegacyShelfLayoutChromeLauncherControllerTest);
640 };
641
642 #if defined(OS_CHROMEOS) 620 #if defined(OS_CHROMEOS)
643 // A browser window proxy which is able to associate an aura native window with 621 // A browser window proxy which is able to associate an aura native window with
644 // it. 622 // it.
645 class TestBrowserWindowAura : public TestBrowserWindow { 623 class TestBrowserWindowAura : public TestBrowserWindow {
646 public: 624 public:
647 // |native_window| will still be owned by the caller after the constructor 625 // |native_window| will still be owned by the caller after the constructor
648 // was called. 626 // was called.
649 explicit TestBrowserWindowAura(aura::Window* native_window) 627 explicit TestBrowserWindowAura(aura::Window* native_window)
650 : native_window_(native_window) { 628 : native_window_(native_window) {
651 } 629 }
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
976 ash::test::TestSessionStateDelegate* session_delegate_; 954 ash::test::TestSessionStateDelegate* session_delegate_;
977 ash::test::TestShellDelegate* shell_delegate_; 955 ash::test::TestShellDelegate* shell_delegate_;
978 956
979 ProfileToNameMap created_profiles_; 957 ProfileToNameMap created_profiles_;
980 958
981 DISALLOW_COPY_AND_ASSIGN( 959 DISALLOW_COPY_AND_ASSIGN(
982 MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest); 960 MultiProfileMultiBrowserShelfLayoutChromeLauncherControllerTest);
983 }; 961 };
984 #endif // defined(OS_CHROMEOS) 962 #endif // defined(OS_CHROMEOS)
985 963
986 TEST_F(LegacyShelfLayoutChromeLauncherControllerTest, DefaultApps) {
987 InitLauncherController();
988 // Model should only contain the browser shortcut and app list items.
989 EXPECT_EQ(2, model_->item_count());
990 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
991 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
992 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
993
994 // Installing |extension3_| should add it to the launcher - behind the
995 // chrome icon.
996 extension_service_->AddExtension(extension3_.get());
997 EXPECT_EQ("Chrome, App3, AppList", GetPinnedAppStatus());
998 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
999 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
1000 }
1001
1002 // Check that the restauration of launcher items is happening in the same order
1003 // as the user has pinned them (on another system) when they are synced reverse
1004 // order.
1005 TEST_F(LegacyShelfLayoutChromeLauncherControllerTest,
1006 RestoreDefaultAppsReverseOrder) {
1007 InitLauncherController();
1008
1009 base::ListValue policy_value;
1010 InsertPrefValue(&policy_value, 0, extension1_->id());
1011 InsertPrefValue(&policy_value, 1, extension2_->id());
1012 InsertPrefValue(&policy_value, 2, extension3_->id());
1013 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
1014 policy_value.DeepCopy());
1015 EXPECT_EQ(0, profile()->GetPrefs()->GetInteger(prefs::kShelfChromeIconIndex));
1016 // Model should only contain the browser shortcut and app list items.
1017 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1018 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
1019 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
1020 EXPECT_EQ("Chrome, AppList", GetPinnedAppStatus());
1021
1022 // Installing |extension3_| should add it to the launcher - behind the
1023 // chrome icon.
1024 ash::LauncherItem item;
1025 extension_service_->AddExtension(extension3_.get());
1026 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1027 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
1028 EXPECT_EQ("Chrome, App3, AppList", GetPinnedAppStatus());
1029
1030 // Installing |extension2_| should add it to the launcher - behind the
1031 // chrome icon, but in first location.
1032 extension_service_->AddExtension(extension2_.get());
1033 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1034 EXPECT_EQ("Chrome, App2, App3, AppList", GetPinnedAppStatus());
1035
1036 // Installing |extension1_| should add it to the launcher - behind the
1037 // chrome icon, but in first location.
1038 extension_service_->AddExtension(extension1_.get());
1039 EXPECT_EQ("Chrome, App1, App2, App3, AppList", GetPinnedAppStatus());
1040 }
1041
1042 // Check that the restauration of launcher items is happening in the same order
1043 // as the user has pinned them (on another system) when they are synced random
1044 // order.
1045 TEST_F(LegacyShelfLayoutChromeLauncherControllerTest,
1046 RestoreDefaultAppsRandomOrder) {
1047 InitLauncherController();
1048
1049 base::ListValue policy_value;
1050 InsertPrefValue(&policy_value, 0, extension1_->id());
1051 InsertPrefValue(&policy_value, 1, extension2_->id());
1052 InsertPrefValue(&policy_value, 2, extension3_->id());
1053 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
1054 policy_value.DeepCopy());
1055 EXPECT_EQ(0, profile()->GetPrefs()->GetInteger(prefs::kShelfChromeIconIndex));
1056 // Model should only contain the browser shortcut and app list items.
1057 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1058 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
1059 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
1060 EXPECT_EQ("Chrome, AppList", GetPinnedAppStatus());
1061
1062 // Installing |extension2_| should add it to the launcher - behind the
1063 // chrome icon.
1064 extension_service_->AddExtension(extension2_.get());
1065 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1066 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
1067 EXPECT_EQ("Chrome, App2, AppList", GetPinnedAppStatus());
1068
1069 // Installing |extension1_| should add it to the launcher - behind the
1070 // chrome icon, but in first location.
1071 extension_service_->AddExtension(extension1_.get());
1072 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
1073 EXPECT_EQ("Chrome, App1, App2, AppList", GetPinnedAppStatus());
1074
1075 // Installing |extension3_| should add it to the launcher - behind the
1076 // chrome icon, but in first location.
1077 extension_service_->AddExtension(extension3_.get());
1078 EXPECT_EQ("Chrome, App1, App2, App3, AppList", GetPinnedAppStatus());
1079 }
1080
1081 // Check that the restauration of launcher items is happening in the same order 964 // Check that the restauration of launcher items is happening in the same order
1082 // as the user has pinned / moved them (on another system) when they are synced 965 // as the user has pinned / moved them (on another system) when they are synced
1083 // random order - including the chrome icon. 966 // random order - including the chrome icon.
1084 TEST_F(LegacyShelfLayoutChromeLauncherControllerTest,
1085 RestoreDefaultAppsRandomOrderChromeMoved) {
1086 InitLauncherController();
1087
1088 base::ListValue policy_value;
1089 InsertPrefValue(&policy_value, 0, extension1_->id());
1090 InsertPrefValue(&policy_value, 1, extension2_->id());
1091 InsertPrefValue(&policy_value, 2, extension3_->id());
1092 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
1093 policy_value.DeepCopy());
1094 profile()->GetTestingPrefService()->SetInteger(prefs::kShelfChromeIconIndex,
1095 1);
1096 // Model should only contain the browser shortcut and app list items.
1097 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1098 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
1099 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
1100 EXPECT_EQ("Chrome, AppList", GetPinnedAppStatus());
1101
1102 // Installing |extension2_| should add it to the launcher - behind the
1103 // chrome icon.
1104 ash::LauncherItem item;
1105 extension_service_->AddExtension(extension2_.get());
1106 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1107 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
1108 EXPECT_EQ("Chrome, App2, AppList", GetPinnedAppStatus());
1109
1110 // Installing |extension1_| should add it to the launcher - behind the
1111 // chrome icon, but in first location.
1112 extension_service_->AddExtension(extension1_.get());
1113 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
1114 EXPECT_EQ("App1, Chrome, App2, AppList", GetPinnedAppStatus());
1115
1116 // Installing |extension3_| should add it to the launcher - behind the
1117 // chrome icon, but in first location.
1118 extension_service_->AddExtension(extension3_.get());
1119 EXPECT_EQ("App1, Chrome, App2, App3, AppList", GetPinnedAppStatus());
1120 }
1121
1122 // Check that syncing to a different state does the correct thing.
1123 TEST_F(LegacyShelfLayoutChromeLauncherControllerTest,
1124 RestoreDefaultAppsResyncOrder) {
1125 InitLauncherController();
1126 base::ListValue policy_value;
1127 InsertPrefValue(&policy_value, 0, extension1_->id());
1128 InsertPrefValue(&policy_value, 1, extension2_->id());
1129 InsertPrefValue(&policy_value, 2, extension3_->id());
1130 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
1131 policy_value.DeepCopy());
1132 EXPECT_EQ(0, profile()->GetPrefs()->GetInteger(prefs::kShelfChromeIconIndex));
1133 extension_service_->AddExtension(extension2_.get());
1134 extension_service_->AddExtension(extension1_.get());
1135 extension_service_->AddExtension(extension3_.get());
1136 EXPECT_EQ("Chrome, App1, App2, App3, AppList", GetPinnedAppStatus());
1137
1138 // Change the order with increasing chrome position and decreasing position.
1139 base::ListValue policy_value1;
1140 InsertPrefValue(&policy_value1, 0, extension3_->id());
1141 InsertPrefValue(&policy_value1, 1, extension1_->id());
1142 InsertPrefValue(&policy_value1, 2, extension2_->id());
1143 profile()->GetTestingPrefService()->SetInteger(prefs::kShelfChromeIconIndex,
1144 2);
1145 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
1146 policy_value1.DeepCopy());
1147 EXPECT_EQ("App3, App1, Chrome, App2, AppList", GetPinnedAppStatus());
1148 base::ListValue policy_value2;
1149 InsertPrefValue(&policy_value2, 0, extension2_->id());
1150 InsertPrefValue(&policy_value2, 1, extension3_->id());
1151 InsertPrefValue(&policy_value2, 2, extension1_->id());
1152 profile()->GetTestingPrefService()->SetInteger(prefs::kShelfChromeIconIndex,
1153 1);
1154 profile()->GetTestingPrefService()->SetUserPref(prefs::kPinnedLauncherApps,
1155 policy_value2.DeepCopy());
1156 EXPECT_EQ("App2, Chrome, App3, App1, AppList", GetPinnedAppStatus());
1157 }
1158
1159 TEST_F(ChromeLauncherControllerTest, DefaultApps) { 967 TEST_F(ChromeLauncherControllerTest, DefaultApps) {
1160 InitLauncherController(); 968 InitLauncherController();
1161 // Model should only contain the browser shortcut and app list items. 969 // Model should only contain the browser shortcut and app list items.
1162 EXPECT_EQ(2, model_->item_count()); 970 EXPECT_EQ(2, model_->item_count());
1163 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 971 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
1164 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id())); 972 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension2_->id()));
1165 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id())); 973 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension3_->id()));
1166 974
1167 // Installing |extension3_| should add it to the launcher - behind the 975 // Installing |extension3_| should add it to the launcher - behind the
1168 // chrome icon. 976 // chrome icon.
(...skipping 1629 matching lines...) Expand 10 before | Expand all | Expand 10 after
2798 2606
2799 EXPECT_EQ(1, app_icon_loader->fetch_count()); 2607 EXPECT_EQ(1, app_icon_loader->fetch_count());
2800 ASSERT_EQ(initial_size + 1, model_->items().size()); 2608 ASSERT_EQ(initial_size + 1, model_->items().size());
2801 EXPECT_TRUE(launcher_controller_->IsAppPinned("1")); 2609 EXPECT_TRUE(launcher_controller_->IsAppPinned("1"));
2802 EXPECT_FALSE(launcher_controller_->IsAppPinned("0")); 2610 EXPECT_FALSE(launcher_controller_->IsAppPinned("0"));
2803 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type); 2611 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type);
2804 2612
2805 launcher_controller_->UnpinAppWithID("1"); 2613 launcher_controller_->UnpinAppWithID("1");
2806 ASSERT_EQ(initial_size, model_->items().size()); 2614 ASSERT_EQ(initial_size, model_->items().size());
2807 } 2615 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698