| 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 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 // Install app to remember existing apps. | 301 // Install app to remember existing apps. |
| 302 StartInstance(); | 302 StartInstance(); |
| 303 InstallTestApps(kTestAppPackage, false); | 303 InstallTestApps(kTestAppPackage, false); |
| 304 SendPackageAdded(kTestAppPackage, false); | 304 SendPackageAdded(kTestAppPackage, false); |
| 305 | 305 |
| 306 const std::string app_id = GetTestApp1Id(kTestAppPackage); | 306 const std::string app_id = GetTestApp1Id(kTestAppPackage); |
| 307 ash::ShelfModel* shelf_model = ash::Shell::Get()->shelf_model(); | 307 ash::ShelfModel* shelf_model = ash::Shell::Get()->shelf_model(); |
| 308 if (is_pinned()) { | 308 if (is_pinned()) { |
| 309 shelf_model->PinAppWithID(app_id); | 309 shelf_model->PinAppWithID(app_id); |
| 310 const ash::ShelfID shelf_id = shelf_model->GetShelfIDForAppID(app_id); | 310 const ash::ShelfID shelf_id = shelf_model->GetShelfIDForAppID(app_id); |
| 311 EXPECT_TRUE(shelf_id); | 311 EXPECT_FALSE(shelf_id.IsNull()); |
| 312 const ash::ShelfItem* item = chrome_controller()->GetItem(shelf_id); | 312 const ash::ShelfItem* item = chrome_controller()->GetItem(shelf_id); |
| 313 EXPECT_EQ(base::UTF8ToUTF16(kTestAppName), item->title); | 313 EXPECT_EQ(base::UTF8ToUTF16(kTestAppName), item->title); |
| 314 } else { | 314 } else { |
| 315 EXPECT_FALSE(shelf_model->GetShelfIDForAppID(app_id)); | 315 EXPECT_TRUE(shelf_model->GetShelfIDForAppID(app_id).IsNull()); |
| 316 } | 316 } |
| 317 | 317 |
| 318 StopInstance(); | 318 StopInstance(); |
| 319 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = | 319 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = |
| 320 app_prefs()->GetApp(app_id); | 320 app_prefs()->GetApp(app_id); |
| 321 EXPECT_FALSE(app_info); | 321 EXPECT_FALSE(app_info); |
| 322 | 322 |
| 323 // Restart instance. App should be taken from prefs but its state is non-ready | 323 // Restart instance. App should be taken from prefs but its state is non-ready |
| 324 // currently. | 324 // currently. |
| 325 StartInstance(); | 325 StartInstance(); |
| 326 app_info = app_prefs()->GetApp(app_id); | 326 app_info = app_prefs()->GetApp(app_id); |
| 327 ASSERT_TRUE(app_info); | 327 ASSERT_TRUE(app_info); |
| 328 EXPECT_FALSE(app_info->ready); | 328 EXPECT_FALSE(app_info->ready); |
| 329 if (is_pinned()) | 329 EXPECT_NE(is_pinned(), shelf_model->GetShelfIDForAppID(app_id).IsNull()); |
| 330 EXPECT_TRUE(shelf_model->GetShelfIDForAppID(app_id)); | |
| 331 else | |
| 332 EXPECT_FALSE(shelf_model->GetShelfIDForAppID(app_id)); | |
| 333 | 330 |
| 334 // Launching non-ready ARC app creates item on shelf and spinning animation. | 331 // Launching non-ready ARC app creates item on shelf and spinning animation. |
| 335 arc::LaunchApp(profile(), app_id, ui::EF_LEFT_MOUSE_BUTTON); | 332 arc::LaunchApp(profile(), app_id, ui::EF_LEFT_MOUSE_BUTTON); |
| 336 const ash::ShelfID shelf_id = shelf_model->GetShelfIDForAppID(app_id); | 333 const ash::ShelfID shelf_id = shelf_model->GetShelfIDForAppID(app_id); |
| 337 EXPECT_TRUE(shelf_id); | 334 EXPECT_FALSE(shelf_id.IsNull()); |
| 338 const ash::ShelfItem* item = chrome_controller()->GetItem(shelf_id); | 335 const ash::ShelfItem* item = chrome_controller()->GetItem(shelf_id); |
| 339 EXPECT_EQ(base::UTF8ToUTF16(kTestAppName), item->title); | 336 EXPECT_EQ(base::UTF8ToUTF16(kTestAppName), item->title); |
| 340 AppAnimatedWaiter(app_id).Wait(); | 337 AppAnimatedWaiter(app_id).Wait(); |
| 341 | 338 |
| 342 switch (test_action()) { | 339 switch (test_action()) { |
| 343 case TEST_ACTION_START: | 340 case TEST_ACTION_START: |
| 344 // Now simulates that ARC is started and app list is refreshed. This | 341 // Now simulates that ARC is started and app list is refreshed. This |
| 345 // should stop animation and delete icon from the shelf. | 342 // should stop animation and delete icon from the shelf. |
| 346 InstallTestApps(kTestAppPackage, false); | 343 InstallTestApps(kTestAppPackage, false); |
| 347 SendPackageAdded(kTestAppPackage, false); | 344 SendPackageAdded(kTestAppPackage, false); |
| 348 EXPECT_TRUE(chrome_controller() | 345 EXPECT_TRUE(chrome_controller() |
| 349 ->GetArcDeferredLauncher() | 346 ->GetArcDeferredLauncher() |
| 350 ->GetActiveTime(app_id) | 347 ->GetActiveTime(app_id) |
| 351 .is_zero()); | 348 .is_zero()); |
| 352 if (is_pinned()) | 349 EXPECT_NE(is_pinned(), shelf_model->GetShelfIDForAppID(app_id).IsNull()); |
| 353 EXPECT_TRUE(shelf_model->GetShelfIDForAppID(app_id)); | |
| 354 else | |
| 355 EXPECT_FALSE(shelf_model->GetShelfIDForAppID(app_id)); | |
| 356 break; | 350 break; |
| 357 case TEST_ACTION_EXIT: | 351 case TEST_ACTION_EXIT: |
| 358 // Just exist Chrome. | 352 // Just exit Chrome. |
| 359 break; | 353 break; |
| 360 case TEST_ACTION_CLOSE: | 354 case TEST_ACTION_CLOSE: |
| 361 // Close item during animation. | |
| 362 { | 355 { |
| 356 // Close item during animation. |
| 363 ash::ShelfItemDelegate* delegate = GetShelfItemDelegate(app_id); | 357 ash::ShelfItemDelegate* delegate = GetShelfItemDelegate(app_id); |
| 364 ASSERT_TRUE(delegate); | 358 ASSERT_TRUE(delegate); |
| 365 delegate->Close(); | 359 delegate->Close(); |
| 366 EXPECT_TRUE(chrome_controller() | 360 EXPECT_TRUE(chrome_controller() |
| 367 ->GetArcDeferredLauncher() | 361 ->GetArcDeferredLauncher() |
| 368 ->GetActiveTime(app_id) | 362 ->GetActiveTime(app_id) |
| 369 .is_zero()); | 363 .is_zero()); |
| 370 if (is_pinned()) | 364 EXPECT_NE(is_pinned(), |
| 371 EXPECT_TRUE(shelf_model->GetShelfIDForAppID(app_id)); | 365 shelf_model->GetShelfIDForAppID(app_id).IsNull()); |
| 372 else | |
| 373 EXPECT_FALSE(shelf_model->GetShelfIDForAppID(app_id)); | |
| 374 } | 366 } |
| 375 break; | 367 break; |
| 376 } | 368 } |
| 377 } | 369 } |
| 378 | 370 |
| 379 INSTANTIATE_TEST_CASE_P(ArcAppDeferredLauncherBrowserTestInstance, | 371 INSTANTIATE_TEST_CASE_P(ArcAppDeferredLauncherBrowserTestInstance, |
| 380 ArcAppDeferredLauncherBrowserTest, | 372 ArcAppDeferredLauncherBrowserTest, |
| 381 ::testing::ValuesIn(build_test_parameter)); | 373 ::testing::ValuesIn(build_test_parameter)); |
| 382 | 374 |
| 383 // This tests validates pin state on package update and remove. | 375 // This tests validates pin state on package update and remove. |
| 384 IN_PROC_BROWSER_TEST_F(ArcAppLauncherBrowserTest, PinOnPackageUpdateAndRemove) { | 376 IN_PROC_BROWSER_TEST_F(ArcAppLauncherBrowserTest, PinOnPackageUpdateAndRemove) { |
| 385 StartInstance(); | 377 StartInstance(); |
| 386 | 378 |
| 387 // Make use app list sync service is started. Normally it is started when | 379 // Make use app list sync service is started. Normally it is started when |
| 388 // sycing is initialized. | 380 // sycing is initialized. |
| 389 app_list::AppListSyncableServiceFactory::GetForProfile(profile())->GetModel(); | 381 app_list::AppListSyncableServiceFactory::GetForProfile(profile())->GetModel(); |
| 390 | 382 |
| 391 InstallTestApps(kTestAppPackage, true); | 383 InstallTestApps(kTestAppPackage, true); |
| 392 SendPackageAdded(kTestAppPackage, false); | 384 SendPackageAdded(kTestAppPackage, false); |
| 393 | 385 |
| 394 const std::string app_id1 = GetTestApp1Id(kTestAppPackage); | 386 const std::string app_id1 = GetTestApp1Id(kTestAppPackage); |
| 395 const std::string app_id2 = GetTestApp2Id(kTestAppPackage); | 387 const std::string app_id2 = GetTestApp2Id(kTestAppPackage); |
| 396 ash::ShelfModel* shelf_model = ash::Shell::Get()->shelf_model(); | 388 ash::ShelfModel* shelf_model = ash::Shell::Get()->shelf_model(); |
| 397 shelf_model->PinAppWithID(app_id1); | 389 shelf_model->PinAppWithID(app_id1); |
| 398 shelf_model->PinAppWithID(app_id2); | 390 shelf_model->PinAppWithID(app_id2); |
| 399 const ash::ShelfID shelf_id1_before = | 391 const ash::ShelfID shelf_id1_before = |
| 400 shelf_model->GetShelfIDForAppID(app_id1); | 392 shelf_model->GetShelfIDForAppID(app_id1); |
| 401 EXPECT_TRUE(shelf_id1_before); | 393 EXPECT_FALSE(shelf_id1_before.IsNull()); |
| 402 EXPECT_TRUE(shelf_model->GetShelfIDForAppID(app_id2)); | 394 EXPECT_FALSE(shelf_model->GetShelfIDForAppID(app_id2).IsNull()); |
| 403 | 395 |
| 404 // Package contains only one app. App list is not shown for updated package. | 396 // Package contains only one app. App list is not shown for updated package. |
| 405 SendPackageUpdated(kTestAppPackage, false); | 397 SendPackageUpdated(kTestAppPackage, false); |
| 406 // Second pin should gone. | 398 // Second pin should gone. |
| 407 EXPECT_EQ(shelf_id1_before, shelf_model->GetShelfIDForAppID(app_id1)); | 399 EXPECT_EQ(shelf_id1_before, shelf_model->GetShelfIDForAppID(app_id1)); |
| 408 EXPECT_FALSE(shelf_model->GetShelfIDForAppID(app_id2)); | 400 EXPECT_TRUE(shelf_model->GetShelfIDForAppID(app_id2).IsNull()); |
| 409 | 401 |
| 410 // Package contains two apps. App list is not shown for updated package. | 402 // Package contains two apps. App list is not shown for updated package. |
| 411 SendPackageUpdated(kTestAppPackage, true); | 403 SendPackageUpdated(kTestAppPackage, true); |
| 412 // Second pin should not appear. | 404 // Second pin should not appear. |
| 413 EXPECT_EQ(shelf_id1_before, shelf_model->GetShelfIDForAppID(app_id1)); | 405 EXPECT_EQ(shelf_id1_before, shelf_model->GetShelfIDForAppID(app_id1)); |
| 414 EXPECT_FALSE(shelf_model->GetShelfIDForAppID(app_id2)); | 406 EXPECT_TRUE(shelf_model->GetShelfIDForAppID(app_id2).IsNull()); |
| 415 | 407 |
| 416 // Package removed. | 408 // Package removed. |
| 417 SendPackageRemoved(kTestAppPackage); | 409 SendPackageRemoved(kTestAppPackage); |
| 418 // No pin is expected. | 410 // No pin is expected. |
| 419 EXPECT_FALSE(shelf_model->GetShelfIDForAppID(app_id1)); | 411 EXPECT_TRUE(shelf_model->GetShelfIDForAppID(app_id1).IsNull()); |
| 420 EXPECT_FALSE(shelf_model->GetShelfIDForAppID(app_id2)); | 412 EXPECT_TRUE(shelf_model->GetShelfIDForAppID(app_id2).IsNull()); |
| 421 } | 413 } |
| 422 | 414 |
| 423 // This test validates that app list is shown on new package and not shown | 415 // This test validates that app list is shown on new package and not shown |
| 424 // on package update. | 416 // on package update. |
| 425 IN_PROC_BROWSER_TEST_F(ArcAppLauncherBrowserTest, AppListShown) { | 417 IN_PROC_BROWSER_TEST_F(ArcAppLauncherBrowserTest, AppListShown) { |
| 426 StartInstance(); | 418 StartInstance(); |
| 427 AppListService* app_list_service = AppListService::Get(); | 419 AppListService* app_list_service = AppListService::Get(); |
| 428 ASSERT_TRUE(app_list_service); | 420 ASSERT_TRUE(app_list_service); |
| 429 | 421 |
| 430 EXPECT_FALSE(app_list_service->IsAppListVisible()); | 422 EXPECT_FALSE(app_list_service->IsAppListVisible()); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 app_host()->OnTaskDestroyed(2); | 535 app_host()->OnTaskDestroyed(2); |
| 544 EXPECT_EQ(delegate2, GetShelfItemDelegate(shelf_id2)); | 536 EXPECT_EQ(delegate2, GetShelfItemDelegate(shelf_id2)); |
| 545 // Destroy task #2, this kills shelf group 2 | 537 // Destroy task #2, this kills shelf group 2 |
| 546 app_host()->OnTaskDestroyed(3); | 538 app_host()->OnTaskDestroyed(3); |
| 547 EXPECT_FALSE(GetShelfItemDelegate(shelf_id2)); | 539 EXPECT_FALSE(GetShelfItemDelegate(shelf_id2)); |
| 548 | 540 |
| 549 // Disable ARC, this removes app and as result kills shelf group 3. | 541 // Disable ARC, this removes app and as result kills shelf group 3. |
| 550 arc::SetArcPlayStoreEnabledForProfile(profile(), false); | 542 arc::SetArcPlayStoreEnabledForProfile(profile(), false); |
| 551 EXPECT_FALSE(GetShelfItemDelegate(shelf_id3)); | 543 EXPECT_FALSE(GetShelfItemDelegate(shelf_id3)); |
| 552 } | 544 } |
| OLD | NEW |