| OLD | NEW |
| 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_impl.h" | 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 }; | 251 }; |
| 252 | 252 |
| 253 // Test implementation of a V2 app launcher item controller. | 253 // Test implementation of a V2 app launcher item controller. |
| 254 class TestV2AppLauncherItemController : public LauncherItemController { | 254 class TestV2AppLauncherItemController : public LauncherItemController { |
| 255 public: | 255 public: |
| 256 TestV2AppLauncherItemController(const std::string& app_id, | 256 TestV2AppLauncherItemController(const std::string& app_id, |
| 257 ChromeLauncherController* controller) | 257 ChromeLauncherController* controller) |
| 258 : LauncherItemController(LauncherItemController::TYPE_APP, | 258 : LauncherItemController(LauncherItemController::TYPE_APP, |
| 259 app_id, | 259 app_id, |
| 260 "", | 260 "", |
| 261 "", |
| 261 controller) {} | 262 controller) {} |
| 262 | 263 |
| 263 ~TestV2AppLauncherItemController() override {} | 264 ~TestV2AppLauncherItemController() override {} |
| 264 | 265 |
| 265 // Override for LauncherItemController: | 266 // Override for LauncherItemController: |
| 266 bool IsOpen() const override { return true; } | 267 bool IsOpen() const override { return true; } |
| 267 bool IsVisible() const override { return true; } | 268 bool IsVisible() const override { return true; } |
| 268 void Launch(ash::LaunchSource source, int event_flags) override {} | 269 void Launch(ash::LaunchSource source, int event_flags) override {} |
| 269 ash::ShelfItemDelegate::PerformedAction Activate( | 270 ash::ShelfItemDelegate::PerformedAction Activate( |
| 270 ash::LaunchSource source) override { | 271 ash::LaunchSource source) override { |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 arc_support_host_ = Extension::Create(base::FilePath(), Manifest::UNPACKED, | 414 arc_support_host_ = Extension::Create(base::FilePath(), Manifest::UNPACKED, |
| 414 manifest, Extension::NO_FLAGS, | 415 manifest, Extension::NO_FLAGS, |
| 415 ArcSupportHost::kHostAppId, &error); | 416 ArcSupportHost::kHostAppId, &error); |
| 416 } | 417 } |
| 417 | 418 |
| 418 // Creates a running V2 app (not pinned) of type |app_id|. | 419 // Creates a running V2 app (not pinned) of type |app_id|. |
| 419 virtual void CreateRunningV2App(const std::string& app_id) { | 420 virtual void CreateRunningV2App(const std::string& app_id) { |
| 420 DCHECK(!test_controller_); | 421 DCHECK(!test_controller_); |
| 421 ash::ShelfID id = | 422 ash::ShelfID id = |
| 422 launcher_controller_->CreateAppShortcutLauncherItemWithType( | 423 launcher_controller_->CreateAppShortcutLauncherItemWithType( |
| 423 ash::launcher::AppLauncherId(app_id), model_->item_count(), | 424 ash::launcher::AppLauncherId(app_id), "", model_->item_count(), |
| 424 ash::TYPE_PLATFORM_APP); | 425 ash::TYPE_PLATFORM_APP); |
| 425 DCHECK(id); | 426 DCHECK(id); |
| 426 // Change the created launcher controller into a V2 app controller. | 427 // Change the created launcher controller into a V2 app controller. |
| 427 test_controller_ = new TestV2AppLauncherItemController(app_id, | 428 test_controller_ = new TestV2AppLauncherItemController(app_id, |
| 428 launcher_controller_.get()); | 429 launcher_controller_.get()); |
| 429 launcher_controller_->SetItemController(id, test_controller_); | 430 launcher_controller_->SetItemController(id, test_controller_); |
| 430 } | 431 } |
| 431 | 432 |
| 432 // Sets the stage for a multi user test. | 433 // Sets the stage for a multi user test. |
| 433 virtual void SetUpMultiUserScenario(syncer::SyncChangeList* user_a, | 434 virtual void SetUpMultiUserScenario(syncer::SyncChangeList* user_a, |
| (...skipping 2847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3281 | 3282 |
| 3282 const std::string app_id = extension1_->id(); | 3283 const std::string app_id = extension1_->id(); |
| 3283 // app_icon_loader is owned by ChromeLauncherControllerImpl. | 3284 // app_icon_loader is owned by ChromeLauncherControllerImpl. |
| 3284 TestAppIconLoaderImpl* app_icon_loader = new TestAppIconLoaderImpl(); | 3285 TestAppIconLoaderImpl* app_icon_loader = new TestAppIconLoaderImpl(); |
| 3285 app_icon_loader->AddSupportedApp(app_id); | 3286 app_icon_loader->AddSupportedApp(app_id); |
| 3286 SetAppIconLoader(std::unique_ptr<AppIconLoader>(app_icon_loader)); | 3287 SetAppIconLoader(std::unique_ptr<AppIconLoader>(app_icon_loader)); |
| 3287 | 3288 |
| 3288 // Test adding an app panel | 3289 // Test adding an app panel |
| 3289 AppWindowLauncherItemController* app_panel_controller = | 3290 AppWindowLauncherItemController* app_panel_controller = |
| 3290 new ExtensionAppWindowLauncherItemController( | 3291 new ExtensionAppWindowLauncherItemController( |
| 3291 LauncherItemController::TYPE_APP_PANEL, app_id, "id", | 3292 LauncherItemController::TYPE_APP_PANEL, app_id, "id", "", |
| 3292 launcher_controller_.get()); | 3293 launcher_controller_.get()); |
| 3293 ash::ShelfID shelf_id1 = launcher_controller_->CreateAppLauncherItem( | 3294 ash::ShelfID shelf_id1 = launcher_controller_->CreateAppLauncherItem( |
| 3294 app_panel_controller, app_id, ash::STATUS_RUNNING); | 3295 app_panel_controller, app_id, ash::STATUS_RUNNING); |
| 3295 int panel_index = model_observer_->last_index(); | 3296 int panel_index = model_observer_->last_index(); |
| 3296 EXPECT_EQ(3, model_observer_->added()); | 3297 EXPECT_EQ(3, model_observer_->added()); |
| 3297 EXPECT_EQ(1, model_observer_->changed()); | 3298 EXPECT_EQ(1, model_observer_->changed()); |
| 3298 EXPECT_EQ(1, app_icon_loader->fetch_count()); | 3299 EXPECT_EQ(1, app_icon_loader->fetch_count()); |
| 3299 model_observer_->clear_counts(); | 3300 model_observer_->clear_counts(); |
| 3300 | 3301 |
| 3301 // App panels should have a separate identifier than the app id | 3302 // App panels should have a separate identifier than the app id |
| 3302 EXPECT_EQ(0, launcher_controller_->GetShelfIDForAppID(app_id)); | 3303 EXPECT_EQ(0, launcher_controller_->GetShelfIDForAppID(app_id)); |
| 3303 | 3304 |
| 3304 // Setting the app image image should not change the panel if it set its icon | 3305 // Setting the app image image should not change the panel if it set its icon |
| 3305 app_panel_controller->set_image_set_by_controller(true); | 3306 app_panel_controller->set_image_set_by_controller(true); |
| 3306 gfx::ImageSkia image; | 3307 gfx::ImageSkia image; |
| 3307 launcher_controller_->OnAppImageUpdated(app_id, image); | 3308 launcher_controller_->OnAppImageUpdated(app_id, image); |
| 3308 EXPECT_EQ(0, model_observer_->changed()); | 3309 EXPECT_EQ(0, model_observer_->changed()); |
| 3309 model_observer_->clear_counts(); | 3310 model_observer_->clear_counts(); |
| 3310 | 3311 |
| 3311 // Add a second app panel and verify that it get the same index as the first | 3312 // Add a second app panel and verify that it get the same index as the first |
| 3312 // one had, being added to the left of the existing panel. | 3313 // one had, being added to the left of the existing panel. |
| 3313 AppWindowLauncherItemController* app_panel_controller2 = | 3314 AppWindowLauncherItemController* app_panel_controller2 = |
| 3314 new ExtensionAppWindowLauncherItemController( | 3315 new ExtensionAppWindowLauncherItemController( |
| 3315 LauncherItemController::TYPE_APP_PANEL, app_id, "id", | 3316 LauncherItemController::TYPE_APP_PANEL, app_id, "id", "", |
| 3316 launcher_controller_.get()); | 3317 launcher_controller_.get()); |
| 3317 | 3318 |
| 3318 ash::ShelfID shelf_id2 = launcher_controller_->CreateAppLauncherItem( | 3319 ash::ShelfID shelf_id2 = launcher_controller_->CreateAppLauncherItem( |
| 3319 app_panel_controller2, app_id, ash::STATUS_RUNNING); | 3320 app_panel_controller2, app_id, ash::STATUS_RUNNING); |
| 3320 EXPECT_EQ(panel_index, model_observer_->last_index()); | 3321 EXPECT_EQ(panel_index, model_observer_->last_index()); |
| 3321 EXPECT_EQ(1, model_observer_->added()); | 3322 EXPECT_EQ(1, model_observer_->added()); |
| 3322 model_observer_->clear_counts(); | 3323 model_observer_->clear_counts(); |
| 3323 | 3324 |
| 3324 launcher_controller_->CloseLauncherItem(shelf_id2); | 3325 launcher_controller_->CloseLauncherItem(shelf_id2); |
| 3325 launcher_controller_->CloseLauncherItem(shelf_id1); | 3326 launcher_controller_->CloseLauncherItem(shelf_id1); |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3500 // ChromeLauncherControllerImpl. | 3501 // ChromeLauncherControllerImpl. |
| 3501 TestAppIconLoaderImpl* app_icon_loader1 = new TestAppIconLoaderImpl(); | 3502 TestAppIconLoaderImpl* app_icon_loader1 = new TestAppIconLoaderImpl(); |
| 3502 TestAppIconLoaderImpl* app_icon_loader2 = new TestAppIconLoaderImpl(); | 3503 TestAppIconLoaderImpl* app_icon_loader2 = new TestAppIconLoaderImpl(); |
| 3503 app_icon_loader1->AddSupportedApp(app_id1); | 3504 app_icon_loader1->AddSupportedApp(app_id1); |
| 3504 app_icon_loader2->AddSupportedApp(app_id2); | 3505 app_icon_loader2->AddSupportedApp(app_id2); |
| 3505 SetAppIconLoaders(std::unique_ptr<AppIconLoader>(app_icon_loader1), | 3506 SetAppIconLoaders(std::unique_ptr<AppIconLoader>(app_icon_loader1), |
| 3506 std::unique_ptr<AppIconLoader>(app_icon_loader2)); | 3507 std::unique_ptr<AppIconLoader>(app_icon_loader2)); |
| 3507 | 3508 |
| 3508 AppWindowLauncherItemController* app_panel_controller3 = | 3509 AppWindowLauncherItemController* app_panel_controller3 = |
| 3509 new ExtensionAppWindowLauncherItemController( | 3510 new ExtensionAppWindowLauncherItemController( |
| 3510 LauncherItemController::TYPE_APP_PANEL, app_id3, "id", | 3511 LauncherItemController::TYPE_APP_PANEL, app_id3, "id", "", |
| 3511 launcher_controller_.get()); | 3512 launcher_controller_.get()); |
| 3512 const ash::ShelfID shelfId3 = launcher_controller_->CreateAppLauncherItem( | 3513 const ash::ShelfID shelfId3 = launcher_controller_->CreateAppLauncherItem( |
| 3513 app_panel_controller3, app_id3, ash::STATUS_RUNNING); | 3514 app_panel_controller3, app_id3, ash::STATUS_RUNNING); |
| 3514 EXPECT_EQ(0, app_icon_loader1->fetch_count()); | 3515 EXPECT_EQ(0, app_icon_loader1->fetch_count()); |
| 3515 EXPECT_EQ(0, app_icon_loader1->clear_count()); | 3516 EXPECT_EQ(0, app_icon_loader1->clear_count()); |
| 3516 EXPECT_EQ(0, app_icon_loader2->fetch_count()); | 3517 EXPECT_EQ(0, app_icon_loader2->fetch_count()); |
| 3517 EXPECT_EQ(0, app_icon_loader2->clear_count()); | 3518 EXPECT_EQ(0, app_icon_loader2->clear_count()); |
| 3518 | 3519 |
| 3519 AppWindowLauncherItemController* app_panel_controller2 = | 3520 AppWindowLauncherItemController* app_panel_controller2 = |
| 3520 new ExtensionAppWindowLauncherItemController( | 3521 new ExtensionAppWindowLauncherItemController( |
| 3521 LauncherItemController::TYPE_APP_PANEL, app_id2, "id", | 3522 LauncherItemController::TYPE_APP_PANEL, app_id2, "id", "", |
| 3522 launcher_controller_.get()); | 3523 launcher_controller_.get()); |
| 3523 const ash::ShelfID shelfId2 = launcher_controller_->CreateAppLauncherItem( | 3524 const ash::ShelfID shelfId2 = launcher_controller_->CreateAppLauncherItem( |
| 3524 app_panel_controller2, app_id2, ash::STATUS_RUNNING); | 3525 app_panel_controller2, app_id2, ash::STATUS_RUNNING); |
| 3525 EXPECT_EQ(0, app_icon_loader1->fetch_count()); | 3526 EXPECT_EQ(0, app_icon_loader1->fetch_count()); |
| 3526 EXPECT_EQ(0, app_icon_loader1->clear_count()); | 3527 EXPECT_EQ(0, app_icon_loader1->clear_count()); |
| 3527 EXPECT_EQ(1, app_icon_loader2->fetch_count()); | 3528 EXPECT_EQ(1, app_icon_loader2->fetch_count()); |
| 3528 EXPECT_EQ(0, app_icon_loader2->clear_count()); | 3529 EXPECT_EQ(0, app_icon_loader2->clear_count()); |
| 3529 | 3530 |
| 3530 // Test adding an app panel | 3531 // Test adding an app panel |
| 3531 AppWindowLauncherItemController* app_panel_controller1 = | 3532 AppWindowLauncherItemController* app_panel_controller1 = |
| 3532 new ExtensionAppWindowLauncherItemController( | 3533 new ExtensionAppWindowLauncherItemController( |
| 3533 LauncherItemController::TYPE_APP_PANEL, app_id1, "id", | 3534 LauncherItemController::TYPE_APP_PANEL, app_id1, "id", "", |
| 3534 launcher_controller_.get()); | 3535 launcher_controller_.get()); |
| 3535 | 3536 |
| 3536 const ash::ShelfID shelfId1 = launcher_controller_->CreateAppLauncherItem( | 3537 const ash::ShelfID shelfId1 = launcher_controller_->CreateAppLauncherItem( |
| 3537 app_panel_controller1, app_id1, ash::STATUS_RUNNING); | 3538 app_panel_controller1, app_id1, ash::STATUS_RUNNING); |
| 3538 EXPECT_EQ(1, app_icon_loader1->fetch_count()); | 3539 EXPECT_EQ(1, app_icon_loader1->fetch_count()); |
| 3539 EXPECT_EQ(0, app_icon_loader1->clear_count()); | 3540 EXPECT_EQ(0, app_icon_loader1->clear_count()); |
| 3540 EXPECT_EQ(1, app_icon_loader2->fetch_count()); | 3541 EXPECT_EQ(1, app_icon_loader2->fetch_count()); |
| 3541 EXPECT_EQ(0, app_icon_loader2->clear_count()); | 3542 EXPECT_EQ(0, app_icon_loader2->clear_count()); |
| 3542 | 3543 |
| 3543 launcher_controller_->CloseLauncherItem(shelfId1); | 3544 launcher_controller_->CloseLauncherItem(shelfId1); |
| (...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4044 | 4045 |
| 4045 // Pinned state should not change. | 4046 // Pinned state should not change. |
| 4046 EXPECT_EQ("AppList, Chrome, App1, App2", GetPinnedAppStatus()); | 4047 EXPECT_EQ("AppList, Chrome, App1, App2", GetPinnedAppStatus()); |
| 4047 launcher_controller_->UnpinAppWithID(extension2_->id()); | 4048 launcher_controller_->UnpinAppWithID(extension2_->id()); |
| 4048 EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus()); | 4049 EXPECT_EQ("AppList, Chrome, App1", GetPinnedAppStatus()); |
| 4049 | 4050 |
| 4050 // Resume syncing and sync information overrides local copy. | 4051 // Resume syncing and sync information overrides local copy. |
| 4051 StartAppSyncService(copy_sync_list); | 4052 StartAppSyncService(copy_sync_list); |
| 4052 EXPECT_EQ("AppList, Chrome, App1, App2", GetPinnedAppStatus()); | 4053 EXPECT_EQ("AppList, Chrome, App1, App2", GetPinnedAppStatus()); |
| 4053 } | 4054 } |
| OLD | NEW |