| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ash/public/cpp/shelf_item_delegate.h" | 5 #include "ash/public/cpp/shelf_item_delegate.h" |
| 6 #include "ash/shelf/shelf_model.h" | 6 #include "ash/shelf/shelf_model.h" |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/wm/window_util.h" | 8 #include "ash/wm/window_util.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 app->name = kTestAppName2; | 97 app->name = kTestAppName2; |
| 98 app->package_name = package_name; | 98 app->package_name = package_name; |
| 99 app->activity = kTestAppActivity2; | 99 app->activity = kTestAppActivity2; |
| 100 app->sticky = false; | 100 app->sticky = false; |
| 101 apps.push_back(std::move(app)); | 101 apps.push_back(std::move(app)); |
| 102 } | 102 } |
| 103 | 103 |
| 104 return apps; | 104 return apps; |
| 105 } | 105 } |
| 106 | 106 |
| 107 ChromeLauncherController* chrome_controller() { | |
| 108 return ChromeLauncherController::instance(); | |
| 109 } | |
| 110 | |
| 111 class AppAnimatedWaiter { | 107 class AppAnimatedWaiter { |
| 112 public: | 108 public: |
| 113 explicit AppAnimatedWaiter(const std::string& app_id) : app_id_(app_id) {} | 109 explicit AppAnimatedWaiter(const std::string& app_id) : app_id_(app_id) {} |
| 114 | 110 |
| 115 void Wait() { | 111 void Wait() { |
| 116 const base::TimeDelta threshold = | 112 const base::TimeDelta threshold = |
| 117 base::TimeDelta::FromMilliseconds(kAppAnimatedThresholdMs); | 113 base::TimeDelta::FromMilliseconds(kAppAnimatedThresholdMs); |
| 118 ArcAppDeferredLauncherController* controller = | 114 ArcAppDeferredLauncherController* controller = |
| 119 chrome_controller()->GetArcDeferredLauncher(); | 115 ChromeLauncherController::instance()->GetArcDeferredLauncher(); |
| 120 while (controller->GetActiveTime(app_id_) < threshold) { | 116 while (controller->GetActiveTime(app_id_) < threshold) { |
| 121 base::RunLoop().RunUntilIdle(); | 117 base::RunLoop().RunUntilIdle(); |
| 122 } | 118 } |
| 123 } | 119 } |
| 124 | 120 |
| 125 private: | 121 private: |
| 126 const std::string app_id_; | 122 const std::string app_id_; |
| 127 }; | 123 }; |
| 128 | 124 |
| 129 enum TestAction { | 125 enum TestAction { |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 app_instance_observer()->OnInstanceReady(); | 245 app_instance_observer()->OnInstanceReady(); |
| 250 } | 246 } |
| 251 | 247 |
| 252 void StopInstance() { | 248 void StopInstance() { |
| 253 arc_session_manager()->Shutdown(); | 249 arc_session_manager()->Shutdown(); |
| 254 app_instance_observer()->OnInstanceClosed(); | 250 app_instance_observer()->OnInstanceClosed(); |
| 255 } | 251 } |
| 256 | 252 |
| 257 ash::ShelfItemDelegate* GetShelfItemDelegate(const std::string& id) { | 253 ash::ShelfItemDelegate* GetShelfItemDelegate(const std::string& id) { |
| 258 ash::ShelfModel* model = ash::Shell::Get()->shelf_model(); | 254 ash::ShelfModel* model = ash::Shell::Get()->shelf_model(); |
| 259 return model->GetShelfItemDelegate(model->GetShelfIDForAppID(id)); | 255 return model->GetShelfItemDelegate(ash::ShelfID(id)); |
| 260 } | 256 } |
| 261 | 257 |
| 262 ArcAppListPrefs* app_prefs() { return ArcAppListPrefs::Get(profile()); } | 258 ArcAppListPrefs* app_prefs() { return ArcAppListPrefs::Get(profile()); } |
| 263 | 259 |
| 264 // Returns as AppHost interface in order to access to private implementation | 260 // Returns as AppHost interface in order to access to private implementation |
| 265 // of the interface. | 261 // of the interface. |
| 266 arc::mojom::AppHost* app_host() { return app_prefs(); } | 262 arc::mojom::AppHost* app_host() { return app_prefs(); } |
| 267 | 263 |
| 268 // Returns as AppInstance observer interface in order to access to private | 264 // Returns as AppInstance observer interface in order to access to private |
| 269 // implementation of the interface. | 265 // implementation of the interface. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 296 DISALLOW_COPY_AND_ASSIGN(ArcAppDeferredLauncherBrowserTest); | 292 DISALLOW_COPY_AND_ASSIGN(ArcAppDeferredLauncherBrowserTest); |
| 297 }; | 293 }; |
| 298 | 294 |
| 299 // This tests simulates normal workflow for starting ARC app in deferred mode. | 295 // This tests simulates normal workflow for starting ARC app in deferred mode. |
| 300 IN_PROC_BROWSER_TEST_P(ArcAppDeferredLauncherBrowserTest, StartAppDeferred) { | 296 IN_PROC_BROWSER_TEST_P(ArcAppDeferredLauncherBrowserTest, StartAppDeferred) { |
| 301 // Install app to remember existing apps. | 297 // Install app to remember existing apps. |
| 302 StartInstance(); | 298 StartInstance(); |
| 303 InstallTestApps(kTestAppPackage, false); | 299 InstallTestApps(kTestAppPackage, false); |
| 304 SendPackageAdded(kTestAppPackage, false); | 300 SendPackageAdded(kTestAppPackage, false); |
| 305 | 301 |
| 302 ChromeLauncherController* controller = ChromeLauncherController::instance(); |
| 306 const std::string app_id = GetTestApp1Id(kTestAppPackage); | 303 const std::string app_id = GetTestApp1Id(kTestAppPackage); |
| 307 ash::ShelfModel* shelf_model = ash::Shell::Get()->shelf_model(); | 304 const ash::ShelfID shelf_id(app_id); |
| 308 if (is_pinned()) { | 305 if (is_pinned()) { |
| 309 shelf_model->PinAppWithID(app_id); | 306 controller->PinAppWithID(app_id); |
| 310 const ash::ShelfID shelf_id = shelf_model->GetShelfIDForAppID(app_id); | 307 const ash::ShelfItem* item = controller->GetItem(shelf_id); |
| 311 EXPECT_FALSE(shelf_id.IsNull()); | |
| 312 const ash::ShelfItem* item = chrome_controller()->GetItem(shelf_id); | |
| 313 EXPECT_EQ(base::UTF8ToUTF16(kTestAppName), item->title); | 308 EXPECT_EQ(base::UTF8ToUTF16(kTestAppName), item->title); |
| 314 } else { | 309 } else { |
| 315 EXPECT_TRUE(shelf_model->GetShelfIDForAppID(app_id).IsNull()); | 310 EXPECT_FALSE(controller->GetItem(shelf_id)); |
| 316 } | 311 } |
| 317 | 312 |
| 318 StopInstance(); | 313 StopInstance(); |
| 319 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = | 314 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = |
| 320 app_prefs()->GetApp(app_id); | 315 app_prefs()->GetApp(app_id); |
| 321 EXPECT_FALSE(app_info); | 316 EXPECT_FALSE(app_info); |
| 322 | 317 |
| 323 // Restart instance. App should be taken from prefs but its state is non-ready | 318 // Restart instance. App should be taken from prefs but its state is non-ready |
| 324 // currently. | 319 // currently. |
| 325 StartInstance(); | 320 StartInstance(); |
| 326 app_info = app_prefs()->GetApp(app_id); | 321 app_info = app_prefs()->GetApp(app_id); |
| 327 ASSERT_TRUE(app_info); | 322 ASSERT_TRUE(app_info); |
| 328 EXPECT_FALSE(app_info->ready); | 323 EXPECT_FALSE(app_info->ready); |
| 329 EXPECT_NE(is_pinned(), shelf_model->GetShelfIDForAppID(app_id).IsNull()); | 324 EXPECT_EQ(is_pinned(), controller->GetItem(shelf_id) != nullptr); |
| 330 | 325 |
| 331 // Launching non-ready ARC app creates item on shelf and spinning animation. | 326 // Launching non-ready ARC app creates item on shelf and spinning animation. |
| 332 arc::LaunchApp(profile(), app_id, ui::EF_LEFT_MOUSE_BUTTON); | 327 arc::LaunchApp(profile(), app_id, ui::EF_LEFT_MOUSE_BUTTON); |
| 333 const ash::ShelfID shelf_id = shelf_model->GetShelfIDForAppID(app_id); | 328 const ash::ShelfItem* item = controller->GetItem(shelf_id); |
| 334 EXPECT_FALSE(shelf_id.IsNull()); | |
| 335 const ash::ShelfItem* item = chrome_controller()->GetItem(shelf_id); | |
| 336 EXPECT_EQ(base::UTF8ToUTF16(kTestAppName), item->title); | 329 EXPECT_EQ(base::UTF8ToUTF16(kTestAppName), item->title); |
| 337 AppAnimatedWaiter(app_id).Wait(); | 330 AppAnimatedWaiter(app_id).Wait(); |
| 338 | 331 |
| 339 switch (test_action()) { | 332 switch (test_action()) { |
| 340 case TEST_ACTION_START: | 333 case TEST_ACTION_START: |
| 341 // Now simulates that ARC is started and app list is refreshed. This | 334 // Now simulates that ARC is started and app list is refreshed. This |
| 342 // should stop animation and delete icon from the shelf. | 335 // should stop animation and delete icon from the shelf. |
| 343 InstallTestApps(kTestAppPackage, false); | 336 InstallTestApps(kTestAppPackage, false); |
| 344 SendPackageAdded(kTestAppPackage, false); | 337 SendPackageAdded(kTestAppPackage, false); |
| 345 EXPECT_TRUE(chrome_controller() | 338 EXPECT_TRUE(controller->GetArcDeferredLauncher() |
| 346 ->GetArcDeferredLauncher() | |
| 347 ->GetActiveTime(app_id) | 339 ->GetActiveTime(app_id) |
| 348 .is_zero()); | 340 .is_zero()); |
| 349 EXPECT_NE(is_pinned(), shelf_model->GetShelfIDForAppID(app_id).IsNull()); | 341 EXPECT_EQ(is_pinned(), controller->GetItem(shelf_id) != nullptr); |
| 350 break; | 342 break; |
| 351 case TEST_ACTION_EXIT: | 343 case TEST_ACTION_EXIT: |
| 352 // Just exit Chrome. | 344 // Just exit Chrome. |
| 353 break; | 345 break; |
| 354 case TEST_ACTION_CLOSE: | 346 case TEST_ACTION_CLOSE: |
| 355 { | 347 { |
| 356 // Close item during animation. | 348 // Close item during animation. |
| 357 ash::ShelfItemDelegate* delegate = GetShelfItemDelegate(app_id); | 349 ash::ShelfItemDelegate* delegate = GetShelfItemDelegate(app_id); |
| 358 ASSERT_TRUE(delegate); | 350 ASSERT_TRUE(delegate); |
| 359 delegate->Close(); | 351 delegate->Close(); |
| 360 EXPECT_TRUE(chrome_controller() | 352 EXPECT_TRUE(controller->GetArcDeferredLauncher() |
| 361 ->GetArcDeferredLauncher() | |
| 362 ->GetActiveTime(app_id) | 353 ->GetActiveTime(app_id) |
| 363 .is_zero()); | 354 .is_zero()); |
| 364 EXPECT_NE(is_pinned(), | 355 EXPECT_EQ(is_pinned(), controller->GetItem(shelf_id) != nullptr); |
| 365 shelf_model->GetShelfIDForAppID(app_id).IsNull()); | |
| 366 } | 356 } |
| 367 break; | 357 break; |
| 368 } | 358 } |
| 369 } | 359 } |
| 370 | 360 |
| 371 INSTANTIATE_TEST_CASE_P(ArcAppDeferredLauncherBrowserTestInstance, | 361 INSTANTIATE_TEST_CASE_P(ArcAppDeferredLauncherBrowserTestInstance, |
| 372 ArcAppDeferredLauncherBrowserTest, | 362 ArcAppDeferredLauncherBrowserTest, |
| 373 ::testing::ValuesIn(build_test_parameter)); | 363 ::testing::ValuesIn(build_test_parameter)); |
| 374 | 364 |
| 375 // This tests validates pin state on package update and remove. | 365 // This tests validates pin state on package update and remove. |
| 376 IN_PROC_BROWSER_TEST_F(ArcAppLauncherBrowserTest, PinOnPackageUpdateAndRemove) { | 366 IN_PROC_BROWSER_TEST_F(ArcAppLauncherBrowserTest, PinOnPackageUpdateAndRemove) { |
| 377 StartInstance(); | 367 StartInstance(); |
| 378 | 368 |
| 379 // Make use app list sync service is started. Normally it is started when | 369 // Make use app list sync service is started. Normally it is started when |
| 380 // sycing is initialized. | 370 // sycing is initialized. |
| 381 app_list::AppListSyncableServiceFactory::GetForProfile(profile())->GetModel(); | 371 app_list::AppListSyncableServiceFactory::GetForProfile(profile())->GetModel(); |
| 382 | 372 |
| 383 InstallTestApps(kTestAppPackage, true); | 373 InstallTestApps(kTestAppPackage, true); |
| 384 SendPackageAdded(kTestAppPackage, false); | 374 SendPackageAdded(kTestAppPackage, false); |
| 385 | 375 |
| 386 const std::string app_id1 = GetTestApp1Id(kTestAppPackage); | 376 const ash::ShelfID shelf_id1(GetTestApp1Id(kTestAppPackage)); |
| 387 const std::string app_id2 = GetTestApp2Id(kTestAppPackage); | 377 const ash::ShelfID shelf_id2(GetTestApp2Id(kTestAppPackage)); |
| 388 ash::ShelfModel* shelf_model = ash::Shell::Get()->shelf_model(); | 378 ChromeLauncherController* controller = ChromeLauncherController::instance(); |
| 389 shelf_model->PinAppWithID(app_id1); | 379 controller->PinAppWithID(shelf_id1.app_id); |
| 390 shelf_model->PinAppWithID(app_id2); | 380 controller->PinAppWithID(shelf_id2.app_id); |
| 391 const ash::ShelfID shelf_id1_before = | 381 EXPECT_TRUE(controller->GetItem(shelf_id1)); |
| 392 shelf_model->GetShelfIDForAppID(app_id1); | 382 EXPECT_TRUE(controller->GetItem(shelf_id2)); |
| 393 EXPECT_FALSE(shelf_id1_before.IsNull()); | |
| 394 EXPECT_FALSE(shelf_model->GetShelfIDForAppID(app_id2).IsNull()); | |
| 395 | 383 |
| 396 // Package contains only one app. App list is not shown for updated package. | 384 // Package contains only one app. App list is not shown for updated package. |
| 397 SendPackageUpdated(kTestAppPackage, false); | 385 SendPackageUpdated(kTestAppPackage, false); |
| 398 // Second pin should gone. | 386 // Second pin should gone. |
| 399 EXPECT_EQ(shelf_id1_before, shelf_model->GetShelfIDForAppID(app_id1)); | 387 EXPECT_TRUE(controller->GetItem(shelf_id1)); |
| 400 EXPECT_TRUE(shelf_model->GetShelfIDForAppID(app_id2).IsNull()); | 388 EXPECT_FALSE(controller->GetItem(shelf_id2)); |
| 401 | 389 |
| 402 // Package contains two apps. App list is not shown for updated package. | 390 // Package contains two apps. App list is not shown for updated package. |
| 403 SendPackageUpdated(kTestAppPackage, true); | 391 SendPackageUpdated(kTestAppPackage, true); |
| 404 // Second pin should not appear. | 392 // Second pin should not appear. |
| 405 EXPECT_EQ(shelf_id1_before, shelf_model->GetShelfIDForAppID(app_id1)); | 393 EXPECT_TRUE(controller->GetItem(shelf_id1)); |
| 406 EXPECT_TRUE(shelf_model->GetShelfIDForAppID(app_id2).IsNull()); | 394 EXPECT_FALSE(controller->GetItem(shelf_id2)); |
| 407 | 395 |
| 408 // Package removed. | 396 // Package removed. |
| 409 SendPackageRemoved(kTestAppPackage); | 397 SendPackageRemoved(kTestAppPackage); |
| 410 // No pin is expected. | 398 // No pin is expected. |
| 411 EXPECT_TRUE(shelf_model->GetShelfIDForAppID(app_id1).IsNull()); | 399 EXPECT_FALSE(controller->GetItem(shelf_id1)); |
| 412 EXPECT_TRUE(shelf_model->GetShelfIDForAppID(app_id2).IsNull()); | 400 EXPECT_FALSE(controller->GetItem(shelf_id2)); |
| 413 } | 401 } |
| 414 | 402 |
| 415 // This test validates that app list is shown on new package and not shown | 403 // This test validates that app list is shown on new package and not shown |
| 416 // on package update. | 404 // on package update. |
| 417 IN_PROC_BROWSER_TEST_F(ArcAppLauncherBrowserTest, AppListShown) { | 405 IN_PROC_BROWSER_TEST_F(ArcAppLauncherBrowserTest, AppListShown) { |
| 418 StartInstance(); | 406 StartInstance(); |
| 419 AppListService* app_list_service = AppListService::Get(); | 407 AppListService* app_list_service = AppListService::Get(); |
| 420 ASSERT_TRUE(app_list_service); | 408 ASSERT_TRUE(app_list_service); |
| 421 | 409 |
| 422 EXPECT_FALSE(app_list_service->IsAppListVisible()); | 410 EXPECT_FALSE(app_list_service->IsAppListVisible()); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 app_host()->OnTaskDestroyed(2); | 523 app_host()->OnTaskDestroyed(2); |
| 536 EXPECT_EQ(delegate2, GetShelfItemDelegate(shelf_id2)); | 524 EXPECT_EQ(delegate2, GetShelfItemDelegate(shelf_id2)); |
| 537 // Destroy task #2, this kills shelf group 2 | 525 // Destroy task #2, this kills shelf group 2 |
| 538 app_host()->OnTaskDestroyed(3); | 526 app_host()->OnTaskDestroyed(3); |
| 539 EXPECT_FALSE(GetShelfItemDelegate(shelf_id2)); | 527 EXPECT_FALSE(GetShelfItemDelegate(shelf_id2)); |
| 540 | 528 |
| 541 // Disable ARC, this removes app and as result kills shelf group 3. | 529 // Disable ARC, this removes app and as result kills shelf group 3. |
| 542 arc::SetArcPlayStoreEnabledForProfile(profile(), false); | 530 arc::SetArcPlayStoreEnabledForProfile(profile(), false); |
| 543 EXPECT_FALSE(GetShelfItemDelegate(shelf_id3)); | 531 EXPECT_FALSE(GetShelfItemDelegate(shelf_id3)); |
| 544 } | 532 } |
| OLD | NEW |