| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/apps/ephemeral_app_browsertest.h" | 5 #include "chrome/browser/apps/ephemeral_app_browsertest.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "apps/app_restore_service.h" | 9 #include "apps/app_restore_service.h" |
| 10 #include "apps/saved_files_service.h" | 10 #include "apps/saved_files_service.h" |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 CloseAppWaitForUnload(app->id()); | 292 CloseAppWaitForUnload(app->id()); |
| 293 return result; | 293 return result; |
| 294 } | 294 } |
| 295 | 295 |
| 296 // Verify that the event page of the app has not been loaded. | 296 // Verify that the event page of the app has not been loaded. |
| 297 void VerifyAppNotLoaded(const std::string& app_id) { | 297 void VerifyAppNotLoaded(const std::string& app_id) { |
| 298 EXPECT_FALSE(ExtensionSystem::Get(profile())-> | 298 EXPECT_FALSE(ExtensionSystem::Get(profile())-> |
| 299 process_manager()->GetBackgroundHostForExtension(app_id)); | 299 process_manager()->GetBackgroundHostForExtension(app_id)); |
| 300 } | 300 } |
| 301 | 301 |
| 302 // Verify properties of ephemeral apps. |
| 303 void VerifyEphemeralApp(const std::string& app_id) { |
| 304 EXPECT_TRUE(extensions::util::IsEphemeralApp(app_id, profile())); |
| 305 |
| 306 // Ephemeral apps should not be synced. |
| 307 scoped_ptr<AppSyncData> sync_change = GetLastSyncChangeForApp(app_id); |
| 308 EXPECT_FALSE(sync_change.get()); |
| 309 |
| 310 // Ephemeral apps should not be assigned ordinals. |
| 311 extensions::AppSorting* app_sorting = |
| 312 ExtensionPrefs::Get(profile())->app_sorting(); |
| 313 EXPECT_FALSE(app_sorting->GetAppLaunchOrdinal(app_id).IsValid()); |
| 314 EXPECT_FALSE(app_sorting->GetPageOrdinal(app_id).IsValid()); |
| 315 } |
| 316 |
| 302 // Verify that after ephemeral apps stop running, they reside in extension | 317 // Verify that after ephemeral apps stop running, they reside in extension |
| 303 // system in a disabled and unloaded state. | 318 // system in a disabled and unloaded state. |
| 304 void VerifyInactiveEphemeralApp(const std::string& app_id) { | 319 void VerifyInactiveEphemeralApp(const std::string& app_id) { |
| 305 EXPECT_TRUE( | 320 EXPECT_TRUE( |
| 306 ExtensionRegistry::Get(profile())->disabled_extensions().Contains( | 321 ExtensionRegistry::Get(profile())->disabled_extensions().Contains( |
| 307 app_id)); | 322 app_id)); |
| 308 | 323 |
| 309 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); | 324 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); |
| 310 EXPECT_TRUE(prefs->IsExtensionDisabled(app_id)); | 325 EXPECT_TRUE(prefs->IsExtensionDisabled(app_id)); |
| 311 EXPECT_NE(0, | 326 EXPECT_NE(0, |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 | 388 |
| 374 ASSERT_TRUE( | 389 ASSERT_TRUE( |
| 375 ExtensionRegistry::Get(profile())->disabled_extensions().Contains( | 390 ExtensionRegistry::Get(profile())->disabled_extensions().Contains( |
| 376 app->id())); | 391 app->id())); |
| 377 } | 392 } |
| 378 | 393 |
| 379 void PromoteEphemeralAppAndVerify( | 394 void PromoteEphemeralAppAndVerify( |
| 380 const Extension* app, | 395 const Extension* app, |
| 381 ExtensionRegistry::IncludeFlag expected_set) { | 396 ExtensionRegistry::IncludeFlag expected_set) { |
| 382 ASSERT_TRUE(app); | 397 ASSERT_TRUE(app); |
| 383 | 398 VerifyEphemeralApp(app->id()); |
| 384 // Ephemeral apps should not be synced. | |
| 385 scoped_ptr<AppSyncData> sync_change = GetFirstSyncChangeForApp(app->id()); | |
| 386 EXPECT_FALSE(sync_change.get()); | |
| 387 | 399 |
| 388 // Promote the app to a regular installed app. | 400 // Promote the app to a regular installed app. |
| 389 InstallObserver installed_observer(profile()); | 401 InstallObserver installed_observer(profile()); |
| 390 PromoteEphemeralApp(app); | 402 PromoteEphemeralApp(app); |
| 391 VerifyPromotedApp(app->id(), expected_set); | 403 VerifyPromotedApp(app->id(), expected_set); |
| 392 | 404 |
| 393 // Check the notification parameters. | 405 // Check the notification parameters. |
| 394 const InstallObserver::InstallParameters& params = | 406 const InstallObserver::InstallParameters& params = |
| 395 installed_observer.Last(); | 407 installed_observer.Last(); |
| 396 EXPECT_EQ(app->id(), params.id); | 408 EXPECT_EQ(app->id(), params.id); |
| 397 EXPECT_TRUE(params.is_update); | 409 EXPECT_TRUE(params.is_update); |
| 398 EXPECT_TRUE(params.from_ephemeral); | 410 EXPECT_TRUE(params.from_ephemeral); |
| 399 | 411 |
| 400 // The installation should now be synced. | 412 // The installation should now be synced. |
| 401 sync_change = GetFirstSyncChangeForApp(app->id()); | 413 scoped_ptr<AppSyncData> sync_change = GetLastSyncChangeForApp(app->id()); |
| 402 VerifySyncChange(sync_change.get(), | 414 VerifySyncChange(sync_change.get(), |
| 403 expected_set == ExtensionRegistry::ENABLED); | 415 expected_set == ExtensionRegistry::ENABLED); |
| 404 } | 416 } |
| 405 | 417 |
| 406 void PromoteEphemeralAppFromSyncAndVerify( | 418 void PromoteEphemeralAppFromSyncAndVerify( |
| 407 const Extension* app, | 419 const Extension* app, |
| 408 bool enable_from_sync, | 420 bool enable_from_sync, |
| 409 ExtensionRegistry::IncludeFlag expected_set) { | 421 ExtensionRegistry::IncludeFlag expected_set) { |
| 410 ASSERT_TRUE(app); | 422 ASSERT_TRUE(app); |
| 423 VerifyEphemeralApp(app->id()); |
| 411 | 424 |
| 412 // Simulate an install from sync. | 425 // Simulate an install from sync. |
| 413 const syncer::StringOrdinal kAppLaunchOrdinal("x"); | 426 const syncer::StringOrdinal kAppLaunchOrdinal("x"); |
| 414 const syncer::StringOrdinal kPageOrdinal("y"); | 427 const syncer::StringOrdinal kPageOrdinal("y"); |
| 415 AppSyncData app_sync_data(*app, | 428 AppSyncData app_sync_data(*app, |
| 416 enable_from_sync, | 429 enable_from_sync, |
| 417 false /* incognito enabled */, | 430 false /* incognito enabled */, |
| 418 false /* remote install */, | 431 false /* remote install */, |
| 419 kAppLaunchOrdinal, | 432 kAppLaunchOrdinal, |
| 420 kPageOrdinal, | 433 kPageOrdinal, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 442 sync_service->MergeDataAndStartSyncing( | 455 sync_service->MergeDataAndStartSyncing( |
| 443 syncer::APPS, | 456 syncer::APPS, |
| 444 syncer::SyncDataList(), | 457 syncer::SyncDataList(), |
| 445 scoped_ptr<syncer::SyncChangeProcessor>( | 458 scoped_ptr<syncer::SyncChangeProcessor>( |
| 446 new syncer::SyncChangeProcessorWrapperForTest( | 459 new syncer::SyncChangeProcessorWrapperForTest( |
| 447 &mock_sync_processor_)), | 460 &mock_sync_processor_)), |
| 448 scoped_ptr<syncer::SyncErrorFactory>( | 461 scoped_ptr<syncer::SyncErrorFactory>( |
| 449 new syncer::SyncErrorFactoryMock())); | 462 new syncer::SyncErrorFactoryMock())); |
| 450 } | 463 } |
| 451 | 464 |
| 452 scoped_ptr<AppSyncData> GetFirstSyncChangeForApp(const std::string& id) { | 465 scoped_ptr<AppSyncData> GetLastSyncChangeForApp(const std::string& id) { |
| 453 scoped_ptr<AppSyncData> sync_data; | 466 scoped_ptr<AppSyncData> sync_data; |
| 454 for (syncer::SyncChangeList::iterator it = | 467 for (syncer::SyncChangeList::iterator it = |
| 455 mock_sync_processor_.changes().begin(); | 468 mock_sync_processor_.changes().begin(); |
| 456 it != mock_sync_processor_.changes().end(); ++it) { | 469 it != mock_sync_processor_.changes().end(); ++it) { |
| 457 sync_data.reset(new AppSyncData(*it)); | 470 scoped_ptr<AppSyncData> data(new AppSyncData(*it)); |
| 458 if (sync_data->id() == id) | 471 if (data->id() == id) |
| 459 return sync_data.Pass(); | 472 sync_data.reset(data.release()); |
| 460 } | 473 } |
| 461 | 474 |
| 462 return scoped_ptr<AppSyncData>(); | 475 return sync_data.Pass(); |
| 463 } | 476 } |
| 464 | 477 |
| 465 void VerifySyncChange(const AppSyncData* sync_change, bool expect_enabled) { | 478 void VerifySyncChange(const AppSyncData* sync_change, bool expect_enabled) { |
| 466 ASSERT_TRUE(sync_change); | 479 ASSERT_TRUE(sync_change); |
| 467 EXPECT_TRUE(sync_change->page_ordinal().IsValid()); | 480 EXPECT_TRUE(sync_change->page_ordinal().IsValid()); |
| 468 EXPECT_TRUE(sync_change->app_launch_ordinal().IsValid()); | 481 EXPECT_TRUE(sync_change->app_launch_ordinal().IsValid()); |
| 469 EXPECT_FALSE(sync_change->uninstalled()); | 482 EXPECT_FALSE(sync_change->uninstalled()); |
| 470 EXPECT_EQ(expect_enabled, sync_change->extension_sync_data().enabled()); | 483 EXPECT_EQ(expect_enabled, sync_change->extension_sync_data().enabled()); |
| 471 } | 484 } |
| 472 | 485 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 ExtensionPrefs::Get(profile())->SetExtensionRunning(app->id(), true); | 579 ExtensionPrefs::Get(profile())->SetExtensionRunning(app->id(), true); |
| 567 | 580 |
| 568 ExtensionTestMessageListener restart_listener("restarted", false); | 581 ExtensionTestMessageListener restart_listener("restarted", false); |
| 569 apps::AppRestoreService::Get(profile())->HandleStartup(true); | 582 apps::AppRestoreService::Get(profile())->HandleStartup(true); |
| 570 EXPECT_TRUE(restart_listener.WaitUntilSatisfied()); | 583 EXPECT_TRUE(restart_listener.WaitUntilSatisfied()); |
| 571 } | 584 } |
| 572 | 585 |
| 573 // Verify that an updated ephemeral app will still have its ephemeral flag | 586 // Verify that an updated ephemeral app will still have its ephemeral flag |
| 574 // enabled. | 587 // enabled. |
| 575 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, UpdateEphemeralApp) { | 588 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, UpdateEphemeralApp) { |
| 589 InitSyncService(); |
| 590 |
| 576 const Extension* app_v1 = InstallAndLaunchEphemeralApp(kMessagingReceiverApp); | 591 const Extension* app_v1 = InstallAndLaunchEphemeralApp(kMessagingReceiverApp); |
| 577 ASSERT_TRUE(app_v1); | 592 ASSERT_TRUE(app_v1); |
| 578 CloseAppWaitForUnload(app_v1->id()); | |
| 579 VerifyInactiveEphemeralApp(app_v1->id()); | |
| 580 | |
| 581 std::string app_id = app_v1->id(); | 593 std::string app_id = app_v1->id(); |
| 582 base::Version app_original_version = *app_v1->version(); | 594 base::Version app_original_version = *app_v1->version(); |
| 583 app_v1 = NULL; // The extension object will be destroyed during update. | 595 |
| 596 VerifyEphemeralApp(app_id); |
| 597 CloseAppWaitForUnload(app_id); |
| 598 VerifyInactiveEphemeralApp(app_id); |
| 584 | 599 |
| 585 // Update to version 2 of the app. | 600 // Update to version 2 of the app. |
| 601 app_v1 = NULL; // The extension object will be destroyed during update. |
| 586 InstallObserver installed_observer(profile()); | 602 InstallObserver installed_observer(profile()); |
| 587 const Extension* app_v2 = | 603 const Extension* app_v2 = |
| 588 UpdateEphemeralApp(app_id, | 604 UpdateEphemeralApp(app_id, |
| 589 GetTestPath(kMessagingReceiverAppV2), | 605 GetTestPath(kMessagingReceiverAppV2), |
| 590 GetTestPath(kMessagingReceiverApp) | 606 GetTestPath(kMessagingReceiverApp) |
| 591 .ReplaceExtension(FILE_PATH_LITERAL(".pem"))); | 607 .ReplaceExtension(FILE_PATH_LITERAL(".pem"))); |
| 592 | 608 |
| 593 // Check the notification parameters. | 609 // Check the notification parameters. |
| 594 const InstallObserver::InstallParameters& params = installed_observer.Last(); | 610 const InstallObserver::InstallParameters& params = installed_observer.Last(); |
| 595 EXPECT_EQ(app_id, params.id); | 611 EXPECT_EQ(app_id, params.id); |
| 596 EXPECT_TRUE(params.is_update); | 612 EXPECT_TRUE(params.is_update); |
| 597 EXPECT_FALSE(params.from_ephemeral); | 613 EXPECT_FALSE(params.from_ephemeral); |
| 598 | 614 |
| 599 // The ephemeral flag should still be set. | 615 // The ephemeral flag should still be set. |
| 600 ASSERT_TRUE(app_v2); | 616 ASSERT_TRUE(app_v2); |
| 601 EXPECT_GT(app_v2->version()->CompareTo(app_original_version), 0); | 617 EXPECT_GT(app_v2->version()->CompareTo(app_original_version), 0); |
| 602 EXPECT_TRUE(extensions::util::IsEphemeralApp(app_v2->id(), profile())); | 618 VerifyEphemeralApp(app_id); |
| 603 | 619 |
| 604 // The app should still be disabled in extension system. | 620 // The app should still be disabled in extension system. |
| 605 VerifyInactiveEphemeralApp(app_id); | 621 VerifyInactiveEphemeralApp(app_id); |
| 606 } | 622 } |
| 607 | 623 |
| 608 // Verify that if notifications have been disabled for an ephemeral app, it will | 624 // Verify that if notifications have been disabled for an ephemeral app, it will |
| 609 // remain disabled even after being evicted from the cache. | 625 // remain disabled even after being evicted from the cache. |
| 610 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, StickyNotificationSettings) { | 626 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, StickyNotificationSettings) { |
| 611 const Extension* app = InstallAndLaunchEphemeralApp(kNotificationsTestApp); | 627 const Extension* app = InstallAndLaunchEphemeralApp(kNotificationsTestApp); |
| 612 ASSERT_TRUE(app); | 628 ASSERT_TRUE(app); |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 773 ExtensionSystem::Get(profile())->extension_service(); | 789 ExtensionSystem::Get(profile())->extension_service(); |
| 774 service->BlacklistExtensionForTest(app->id()); | 790 service->BlacklistExtensionForTest(app->id()); |
| 775 ASSERT_TRUE( | 791 ASSERT_TRUE( |
| 776 ExtensionRegistry::Get(profile())->blacklisted_extensions().Contains( | 792 ExtensionRegistry::Get(profile())->blacklisted_extensions().Contains( |
| 777 app->id())); | 793 app->id())); |
| 778 | 794 |
| 779 // When promoted to a regular installed app, it should remain blacklisted. | 795 // When promoted to a regular installed app, it should remain blacklisted. |
| 780 PromoteEphemeralAppAndVerify(app, ExtensionRegistry::BLACKLISTED); | 796 PromoteEphemeralAppAndVerify(app, ExtensionRegistry::BLACKLISTED); |
| 781 | 797 |
| 782 // The app should be synced, but disabled. | 798 // The app should be synced, but disabled. |
| 783 scoped_ptr<AppSyncData> sync_change = GetFirstSyncChangeForApp(app->id()); | 799 scoped_ptr<AppSyncData> sync_change = GetLastSyncChangeForApp(app->id()); |
| 784 VerifySyncChange(sync_change.get(), false); | 800 VerifySyncChange(sync_change.get(), false); |
| 785 } | 801 } |
| 786 | 802 |
| 787 // Checks the process of promoting an ephemeral app from sync while the app is | 803 // Checks the process of promoting an ephemeral app from sync while the app is |
| 788 // running. | 804 // running. |
| 789 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, | 805 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, |
| 790 PromoteAppFromSyncWhileRunning) { | 806 PromoteAppFromSyncWhileRunning) { |
| 791 InitSyncService(); | 807 InitSyncService(); |
| 792 | 808 |
| 793 const Extension* app = InstallAndLaunchEphemeralApp(kNotificationsTestApp); | 809 const Extension* app = InstallAndLaunchEphemeralApp(kNotificationsTestApp); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 929 | 945 |
| 930 // Ensure that when the app is promoted to an installed app, the bit in the | 946 // Ensure that when the app is promoted to an installed app, the bit in the |
| 931 // creation flags is cleared. | 947 // creation flags is cleared. |
| 932 PromoteEphemeralApp(app); | 948 PromoteEphemeralApp(app); |
| 933 EXPECT_FALSE(extensions::util::IsEphemeralApp(app->id(), profile())); | 949 EXPECT_FALSE(extensions::util::IsEphemeralApp(app->id(), profile())); |
| 934 | 950 |
| 935 int creation_flags = | 951 int creation_flags = |
| 936 ExtensionPrefs::Get(profile())->GetCreationFlags(app->id()); | 952 ExtensionPrefs::Get(profile())->GetCreationFlags(app->id()); |
| 937 EXPECT_EQ(0, creation_flags & Extension::IS_EPHEMERAL); | 953 EXPECT_EQ(0, creation_flags & Extension::IS_EPHEMERAL); |
| 938 } | 954 } |
| OLD | NEW |