OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_per_app.h" | 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 | 134 |
135 // Installing |extension3_| should add it to the launcher. | 135 // Installing |extension3_| should add it to the launcher. |
136 extension_service_->AddExtension(extension3_.get()); | 136 extension_service_->AddExtension(extension3_.get()); |
137 EXPECT_EQ(3, model_.item_count()); | 137 EXPECT_EQ(3, model_.item_count()); |
138 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_.items()[kExpectedAppIndex].type); | 138 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_.items()[kExpectedAppIndex].type); |
139 EXPECT_FALSE(launcher_controller.IsAppPinned(extension1_->id())); | 139 EXPECT_FALSE(launcher_controller.IsAppPinned(extension1_->id())); |
140 EXPECT_FALSE(launcher_controller.IsAppPinned(extension2_->id())); | 140 EXPECT_FALSE(launcher_controller.IsAppPinned(extension2_->id())); |
141 EXPECT_TRUE(launcher_controller.IsAppPinned(extension3_->id())); | 141 EXPECT_TRUE(launcher_controller.IsAppPinned(extension3_->id())); |
142 } | 142 } |
143 | 143 |
| 144 // Check that simple locking of an application will 'create' a launcher item. |
| 145 TEST_F(ChromeLauncherControllerPerAppTest, CheckLockApps) { |
| 146 ChromeLauncherControllerPerApp launcher_controller(profile(), &model_); |
| 147 launcher_controller.Init(); |
| 148 |
| 149 // Model should only contain the browser shortcut and app list items. |
| 150 EXPECT_EQ(2, model_.item_count()); |
| 151 EXPECT_FALSE(launcher_controller.IsAppPinned(extension1_->id())); |
| 152 EXPECT_FALSE(launcher_controller.IsWindowedAppInLauncher(extension1_->id())); |
| 153 EXPECT_FALSE(launcher_controller.IsAppPinned(extension2_->id())); |
| 154 EXPECT_FALSE(launcher_controller.IsWindowedAppInLauncher(extension2_->id())); |
| 155 |
| 156 launcher_controller.LockV1AppWithID(extension1_->id()); |
| 157 |
| 158 EXPECT_EQ(3, model_.item_count()); |
| 159 EXPECT_EQ(ash::TYPE_WINDOWED_APP, model_.items()[kExpectedAppIndex].type); |
| 160 EXPECT_FALSE(launcher_controller.IsAppPinned(extension1_->id())); |
| 161 EXPECT_TRUE(launcher_controller.IsWindowedAppInLauncher(extension1_->id())); |
| 162 EXPECT_FALSE(launcher_controller.IsAppPinned(extension2_->id())); |
| 163 EXPECT_FALSE(launcher_controller.IsWindowedAppInLauncher(extension2_->id())); |
| 164 |
| 165 launcher_controller.UnlockV1AppWithID(extension1_->id()); |
| 166 |
| 167 EXPECT_EQ(2, model_.item_count()); |
| 168 EXPECT_FALSE(launcher_controller.IsAppPinned(extension1_->id())); |
| 169 EXPECT_FALSE(launcher_controller.IsWindowedAppInLauncher(extension1_->id())); |
| 170 EXPECT_FALSE(launcher_controller.IsAppPinned(extension2_->id())); |
| 171 EXPECT_FALSE(launcher_controller.IsWindowedAppInLauncher(extension2_->id())); |
| 172 } |
| 173 |
| 174 // Check that multiple locks of an application will be properly handled. |
| 175 TEST_F(ChromeLauncherControllerPerAppTest, CheckMukltiLockApps) { |
| 176 ChromeLauncherControllerPerApp launcher_controller(profile(), &model_); |
| 177 launcher_controller.Init(); |
| 178 |
| 179 // Model should only contain the browser shortcut and app list items. |
| 180 EXPECT_EQ(2, model_.item_count()); |
| 181 EXPECT_FALSE(launcher_controller.IsAppPinned(extension1_->id())); |
| 182 EXPECT_FALSE(launcher_controller.IsWindowedAppInLauncher(extension1_->id())); |
| 183 |
| 184 for (int i = 0; i < 2; i++) { |
| 185 launcher_controller.LockV1AppWithID(extension1_->id()); |
| 186 |
| 187 EXPECT_EQ(3, model_.item_count()); |
| 188 EXPECT_EQ(ash::TYPE_WINDOWED_APP, model_.items()[kExpectedAppIndex].type); |
| 189 EXPECT_FALSE(launcher_controller.IsAppPinned(extension1_->id())); |
| 190 EXPECT_TRUE(launcher_controller.IsWindowedAppInLauncher( |
| 191 extension1_->id())); |
| 192 } |
| 193 |
| 194 launcher_controller.UnlockV1AppWithID(extension1_->id()); |
| 195 |
| 196 EXPECT_EQ(3, model_.item_count()); |
| 197 EXPECT_EQ(ash::TYPE_WINDOWED_APP, model_.items()[kExpectedAppIndex].type); |
| 198 EXPECT_FALSE(launcher_controller.IsAppPinned(extension1_->id())); |
| 199 EXPECT_TRUE(launcher_controller.IsWindowedAppInLauncher(extension1_->id())); |
| 200 |
| 201 launcher_controller.UnlockV1AppWithID(extension1_->id()); |
| 202 |
| 203 EXPECT_EQ(2, model_.item_count()); |
| 204 EXPECT_FALSE(launcher_controller.IsAppPinned(extension1_->id())); |
| 205 EXPECT_FALSE(launcher_controller.IsWindowedAppInLauncher(extension1_->id())); |
| 206 EXPECT_FALSE(launcher_controller.IsAppPinned(extension2_->id())); |
| 207 EXPECT_FALSE(launcher_controller.IsWindowedAppInLauncher(extension1_->id())); |
| 208 } |
| 209 |
| 210 // Check that already pinned items are not effected by locks. |
| 211 TEST_F(ChromeLauncherControllerPerAppTest, CheckAlreadyPinnedLockApps) { |
| 212 ChromeLauncherControllerPerApp launcher_controller(profile(), &model_); |
| 213 launcher_controller.Init(); |
| 214 |
| 215 // Model should only contain the browser shortcut and app list items. |
| 216 EXPECT_EQ(2, model_.item_count()); |
| 217 EXPECT_FALSE(launcher_controller.IsAppPinned(extension1_->id())); |
| 218 EXPECT_FALSE(launcher_controller.IsWindowedAppInLauncher(extension1_->id())); |
| 219 |
| 220 launcher_controller.PinAppWithID(extension1_->id()); |
| 221 |
| 222 EXPECT_EQ(3, model_.item_count()); |
| 223 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_.items()[kExpectedAppIndex].type); |
| 224 EXPECT_TRUE(launcher_controller.IsAppPinned(extension1_->id())); |
| 225 EXPECT_FALSE(launcher_controller.IsWindowedAppInLauncher(extension1_->id())); |
| 226 |
| 227 launcher_controller.LockV1AppWithID(extension1_->id()); |
| 228 |
| 229 EXPECT_EQ(3, model_.item_count()); |
| 230 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_.items()[kExpectedAppIndex].type); |
| 231 EXPECT_TRUE(launcher_controller.IsAppPinned(extension1_->id())); |
| 232 EXPECT_FALSE(launcher_controller.IsWindowedAppInLauncher(extension1_->id())); |
| 233 |
| 234 launcher_controller.UnlockV1AppWithID(extension1_->id()); |
| 235 |
| 236 EXPECT_EQ(3, model_.item_count()); |
| 237 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_.items()[kExpectedAppIndex].type); |
| 238 EXPECT_TRUE(launcher_controller.IsAppPinned(extension1_->id())); |
| 239 EXPECT_FALSE(launcher_controller.IsWindowedAppInLauncher(extension1_->id())); |
| 240 |
| 241 launcher_controller.UnpinAppsWithID(extension1_->id()); |
| 242 |
| 243 EXPECT_EQ(2, model_.item_count()); |
| 244 } |
| 245 |
| 246 // Check that already pinned items which get locked stay after unpinning. |
| 247 TEST_F(ChromeLauncherControllerPerAppTest, CheckPinnedAppsStayAfterUnlock) { |
| 248 ChromeLauncherControllerPerApp launcher_controller(profile(), &model_); |
| 249 launcher_controller.Init(); |
| 250 |
| 251 // Model should only contain the browser shortcut and app list items. |
| 252 EXPECT_EQ(2, model_.item_count()); |
| 253 EXPECT_FALSE(launcher_controller.IsAppPinned(extension1_->id())); |
| 254 EXPECT_FALSE(launcher_controller.IsWindowedAppInLauncher(extension1_->id())); |
| 255 |
| 256 launcher_controller.PinAppWithID(extension1_->id()); |
| 257 |
| 258 EXPECT_EQ(3, model_.item_count()); |
| 259 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_.items()[kExpectedAppIndex].type); |
| 260 EXPECT_TRUE(launcher_controller.IsAppPinned(extension1_->id())); |
| 261 EXPECT_FALSE(launcher_controller.IsWindowedAppInLauncher(extension1_->id())); |
| 262 |
| 263 launcher_controller.LockV1AppWithID(extension1_->id()); |
| 264 |
| 265 EXPECT_EQ(3, model_.item_count()); |
| 266 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_.items()[kExpectedAppIndex].type); |
| 267 EXPECT_TRUE(launcher_controller.IsAppPinned(extension1_->id())); |
| 268 EXPECT_FALSE(launcher_controller.IsWindowedAppInLauncher(extension1_->id())); |
| 269 |
| 270 launcher_controller.UnpinAppsWithID(extension1_->id()); |
| 271 |
| 272 EXPECT_EQ(3, model_.item_count()); |
| 273 EXPECT_EQ(ash::TYPE_WINDOWED_APP, model_.items()[kExpectedAppIndex].type); |
| 274 EXPECT_FALSE(launcher_controller.IsAppPinned(extension1_->id())); |
| 275 EXPECT_TRUE(launcher_controller.IsWindowedAppInLauncher(extension1_->id())); |
| 276 |
| 277 launcher_controller.UnlockV1AppWithID(extension1_->id()); |
| 278 |
| 279 EXPECT_EQ(2, model_.item_count()); |
| 280 } |
| 281 |
| 282 // Check that lock -> pin -> unlock -> unpin does properly transition. |
| 283 TEST_F(ChromeLauncherControllerPerAppTest, CheckLockPinUnlockUnpin) { |
| 284 ChromeLauncherControllerPerApp launcher_controller(profile(), &model_); |
| 285 launcher_controller.Init(); |
| 286 |
| 287 // Model should only contain the browser shortcut and app list items. |
| 288 EXPECT_EQ(2, model_.item_count()); |
| 289 EXPECT_FALSE(launcher_controller.IsAppPinned(extension1_->id())); |
| 290 EXPECT_FALSE(launcher_controller.IsWindowedAppInLauncher(extension1_->id())); |
| 291 |
| 292 launcher_controller.LockV1AppWithID(extension1_->id()); |
| 293 |
| 294 EXPECT_EQ(3, model_.item_count()); |
| 295 EXPECT_EQ(ash::TYPE_WINDOWED_APP, model_.items()[kExpectedAppIndex].type); |
| 296 EXPECT_FALSE(launcher_controller.IsAppPinned(extension1_->id())); |
| 297 EXPECT_TRUE(launcher_controller.IsWindowedAppInLauncher(extension1_->id())); |
| 298 |
| 299 launcher_controller.PinAppWithID(extension1_->id()); |
| 300 |
| 301 EXPECT_EQ(3, model_.item_count()); |
| 302 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_.items()[kExpectedAppIndex].type); |
| 303 EXPECT_TRUE(launcher_controller.IsAppPinned(extension1_->id())); |
| 304 EXPECT_FALSE(launcher_controller.IsWindowedAppInLauncher(extension1_->id())); |
| 305 |
| 306 launcher_controller.UnlockV1AppWithID(extension1_->id()); |
| 307 |
| 308 EXPECT_EQ(3, model_.item_count()); |
| 309 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_.items()[kExpectedAppIndex].type); |
| 310 EXPECT_TRUE(launcher_controller.IsAppPinned(extension1_->id())); |
| 311 EXPECT_FALSE(launcher_controller.IsWindowedAppInLauncher(extension1_->id())); |
| 312 |
| 313 launcher_controller.UnpinAppsWithID(extension1_->id()); |
| 314 |
| 315 EXPECT_EQ(2, model_.item_count()); |
| 316 } |
| 317 |
144 TEST_F(ChromeLauncherControllerPerAppTest, Policy) { | 318 TEST_F(ChromeLauncherControllerPerAppTest, Policy) { |
145 extension_service_->AddExtension(extension1_.get()); | 319 extension_service_->AddExtension(extension1_.get()); |
146 extension_service_->AddExtension(extension3_.get()); | 320 extension_service_->AddExtension(extension3_.get()); |
147 | 321 |
148 base::ListValue policy_value; | 322 base::ListValue policy_value; |
149 InsertPrefValue(&policy_value, 0, extension1_->id()); | 323 InsertPrefValue(&policy_value, 0, extension1_->id()); |
150 InsertPrefValue(&policy_value, 1, extension2_->id()); | 324 InsertPrefValue(&policy_value, 1, extension2_->id()); |
151 profile()->GetTestingPrefService()->SetManagedPref(prefs::kPinnedLauncherApps, | 325 profile()->GetTestingPrefService()->SetManagedPref(prefs::kPinnedLauncherApps, |
152 policy_value.DeepCopy()); | 326 policy_value.DeepCopy()); |
153 | 327 |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 { | 661 { |
488 scoped_ptr<ui::MenuModel> menu( | 662 scoped_ptr<ui::MenuModel> menu( |
489 launcher_controller.CreateApplicationMenu(item_gmail)); | 663 launcher_controller.CreateApplicationMenu(item_gmail)); |
490 int first_item = | 664 int first_item = |
491 (menu->GetTypeAt(0) == ui::MenuModel::TYPE_SEPARATOR) ? 1 : 0; | 665 (menu->GetTypeAt(0) == ui::MenuModel::TYPE_SEPARATOR) ? 1 : 0; |
492 menu->ActivatedAt(first_item + 3); | 666 menu->ActivatedAt(first_item + 3); |
493 } | 667 } |
494 // Now the active tab should be the second item. | 668 // Now the active tab should be the second item. |
495 EXPECT_EQ(0, browser()->tab_strip_model()->active_index()); | 669 EXPECT_EQ(0, browser()->tab_strip_model()->active_index()); |
496 } | 670 } |
OLD | NEW |