| 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/saved_files_service.h" | 9 #include "apps/saved_files_service.h" |
| 10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| 11 #include "base/scoped_observer.h" | 11 #include "base/scoped_observer.h" |
| 12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "chrome/browser/apps/app_browsertest_util.h" | 13 #include "chrome/browser/apps/app_browsertest_util.h" |
| 14 #include "chrome/browser/apps/ephemeral_app_service.h" | |
| 15 #include "chrome/browser/extensions/api/file_system/file_system_api.h" | 14 #include "chrome/browser/extensions/api/file_system/file_system_api.h" |
| 16 #include "chrome/browser/extensions/app_sync_data.h" | 15 #include "chrome/browser/extensions/app_sync_data.h" |
| 17 #include "chrome/browser/extensions/extension_service.h" | 16 #include "chrome/browser/extensions/extension_service.h" |
| 18 #include "chrome/browser/extensions/extension_sync_service.h" | 17 #include "chrome/browser/extensions/extension_sync_service.h" |
| 19 #include "chrome/browser/extensions/extension_test_message_listener.h" | 18 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 20 #include "chrome/browser/extensions/extension_util.h" | 19 #include "chrome/browser/extensions/extension_util.h" |
| 21 #include "chrome/browser/notifications/desktop_notification_service.h" | 20 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 22 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 21 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
| 23 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
| 24 #include "chrome/common/extensions/api/alarms.h" | 23 #include "chrome/common/extensions/api/alarms.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 37 #include "sync/api/fake_sync_change_processor.h" | 36 #include "sync/api/fake_sync_change_processor.h" |
| 38 #include "sync/api/sync_change_processor_wrapper_for_test.h" | 37 #include "sync/api/sync_change_processor_wrapper_for_test.h" |
| 39 #include "sync/api/sync_error_factory_mock.h" | 38 #include "sync/api/sync_error_factory_mock.h" |
| 40 #include "ui/message_center/message_center.h" | 39 #include "ui/message_center/message_center.h" |
| 41 #include "ui/message_center/notifier_settings.h" | 40 #include "ui/message_center/notifier_settings.h" |
| 42 | 41 |
| 43 using extensions::AppSyncData; | 42 using extensions::AppSyncData; |
| 44 using extensions::Event; | 43 using extensions::Event; |
| 45 using extensions::EventRouter; | 44 using extensions::EventRouter; |
| 46 using extensions::Extension; | 45 using extensions::Extension; |
| 47 using extensions::ExtensionInfo; | |
| 48 using extensions::ExtensionPrefs; | 46 using extensions::ExtensionPrefs; |
| 49 using extensions::ExtensionRegistry; | 47 using extensions::ExtensionRegistry; |
| 50 using extensions::ExtensionRegistryObserver; | 48 using extensions::ExtensionRegistryObserver; |
| 51 using extensions::ExtensionSystem; | 49 using extensions::ExtensionSystem; |
| 52 using extensions::Manifest; | 50 using extensions::Manifest; |
| 53 | 51 |
| 54 namespace { | 52 namespace { |
| 55 | 53 |
| 56 namespace alarms = extensions::api::alarms; | 54 namespace alarms = extensions::api::alarms; |
| 57 | 55 |
| 58 const char kDispatchEventTestApp[] = "ephemeral_apps/dispatch_event"; | 56 const char kDispatchEventTestApp[] = "ephemeral_apps/dispatch_event"; |
| 59 const char kNotificationsTestApp[] = "ephemeral_apps/notification_settings"; | 57 const char kNotificationsTestApp[] = "ephemeral_apps/notification_settings"; |
| 60 const char kFileSystemTestApp[] = "ephemeral_apps/filesystem_retain_entries"; | 58 const char kFileSystemTestApp[] = "ephemeral_apps/filesystem_retain_entries"; |
| 61 const char kRetainDataApp[] = "ephemeral_apps/retain_data"; | |
| 62 | 59 |
| 63 typedef std::vector<message_center::Notifier*> NotifierList; | 60 typedef std::vector<message_center::Notifier*> NotifierList; |
| 64 | 61 |
| 65 bool IsNotifierInList(const message_center::NotifierId& notifier_id, | 62 bool IsNotifierInList(const message_center::NotifierId& notifier_id, |
| 66 const NotifierList& notifiers) { | 63 const NotifierList& notifiers) { |
| 67 for (NotifierList::const_iterator it = notifiers.begin(); | 64 for (NotifierList::const_iterator it = notifiers.begin(); |
| 68 it != notifiers.end(); ++it) { | 65 it != notifiers.end(); ++it) { |
| 69 const message_center::Notifier* notifier = *it; | 66 const message_center::Notifier* notifier = *it; |
| 70 if (notifier->notifier_id == notifier_id) | 67 if (notifier->notifier_id == notifier_id) |
| 71 return true; | 68 return true; |
| 72 } | 69 } |
| 73 | 70 |
| 74 return false; | 71 return false; |
| 75 } | 72 } |
| 76 | 73 |
| 77 bool IsAppInExtensionsInfo(const ExtensionPrefs::ExtensionsInfo& ext_info, | |
| 78 const std::string& extension_id) { | |
| 79 for (size_t i = 0; i < ext_info.size(); ++i) { | |
| 80 ExtensionInfo* info = ext_info.at(i).get(); | |
| 81 if (info->extension_id == extension_id) | |
| 82 return true; | |
| 83 } | |
| 84 | |
| 85 return false; | |
| 86 } | |
| 87 | |
| 88 // Saves some parameters from the extension installed notification in order | 74 // Saves some parameters from the extension installed notification in order |
| 89 // to verify them in tests. | 75 // to verify them in tests. |
| 90 class InstallObserver : public ExtensionRegistryObserver { | 76 class InstallObserver : public ExtensionRegistryObserver { |
| 91 public: | 77 public: |
| 92 struct InstallParameters { | 78 struct InstallParameters { |
| 93 std::string id; | 79 std::string id; |
| 94 bool is_update; | 80 bool is_update; |
| 95 bool from_ephemeral; | 81 bool from_ephemeral; |
| 96 | 82 |
| 97 InstallParameters( | 83 InstallParameters( |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 dummy_alarm.name = "test_alarm"; | 280 dummy_alarm.name = "test_alarm"; |
| 295 | 281 |
| 296 scoped_ptr<base::ListValue> args(new base::ListValue()); | 282 scoped_ptr<base::ListValue> args(new base::ListValue()); |
| 297 args->Append(dummy_alarm.ToValue().release()); | 283 args->Append(dummy_alarm.ToValue().release()); |
| 298 scoped_ptr<Event> event(new Event(alarms::OnAlarm::kEventName, | 284 scoped_ptr<Event> event(new Event(alarms::OnAlarm::kEventName, |
| 299 args.Pass())); | 285 args.Pass())); |
| 300 | 286 |
| 301 event_router->DispatchEventToExtension(app_id, event.Pass()); | 287 event_router->DispatchEventToExtension(app_id, event.Pass()); |
| 302 } | 288 } |
| 303 | 289 |
| 304 void GarbageCollectData() { | |
| 305 EphemeralAppService* service = | |
| 306 EphemeralAppService::Get(profile()); | |
| 307 ASSERT_TRUE(service); | |
| 308 service->GarbageCollectData(); | |
| 309 } | |
| 310 | |
| 311 const Extension* ReplaceEphemeralApp(const std::string& app_id, | 290 const Extension* ReplaceEphemeralApp(const std::string& app_id, |
| 312 const char* test_path) { | 291 const char* test_path) { |
| 313 return UpdateExtensionWaitForIdle(app_id, GetTestPath(test_path), 0); | 292 return UpdateExtensionWaitForIdle(app_id, GetTestPath(test_path), 0); |
| 314 } | 293 } |
| 315 | 294 |
| 316 void VerifyPromotedApp(const std::string& app_id, | 295 void VerifyPromotedApp(const std::string& app_id, |
| 317 ExtensionRegistry::IncludeFlag expected_set) { | 296 ExtensionRegistry::IncludeFlag expected_set) { |
| 318 const Extension* app = ExtensionRegistry::Get(profile())->GetExtensionById( | 297 const Extension* app = ExtensionRegistry::Get(profile())->GetExtensionById( |
| 319 app_id, expected_set); | 298 app_id, expected_set); |
| 320 ASSERT_TRUE(app); | 299 ASSERT_TRUE(app); |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 // flushed. | 512 // flushed. |
| 534 std::vector<apps::SavedFileEntry> file_entries = | 513 std::vector<apps::SavedFileEntry> file_entries = |
| 535 apps::SavedFilesService::Get(profile()) | 514 apps::SavedFilesService::Get(profile()) |
| 536 ->GetAllFileEntries(app->id()); | 515 ->GetAllFileEntries(app->id()); |
| 537 EXPECT_TRUE(file_entries.empty()); | 516 EXPECT_TRUE(file_entries.empty()); |
| 538 | 517 |
| 539 // The second test verifies that the file cannot be reopened. | 518 // The second test verifies that the file cannot be reopened. |
| 540 ASSERT_TRUE(LaunchAppAndRunTest(app, "RestoreRetainedFile")) << message_; | 519 ASSERT_TRUE(LaunchAppAndRunTest(app, "RestoreRetainedFile")) << message_; |
| 541 } | 520 } |
| 542 | 521 |
| 543 // Verify that once evicted from the cache, the data of ephemeral apps will not | |
| 544 // be deleted. | |
| 545 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, RetainData) { | |
| 546 // Phase 1 - Install the ephemeral app and write data to various storage. | |
| 547 const Extension* app = InstallEphemeralApp(kRetainDataApp); | |
| 548 ASSERT_TRUE(app); | |
| 549 ASSERT_TRUE(LaunchAppAndRunTest(app, "WriteData")) << message_; | |
| 550 | |
| 551 // Sanity check to ensure that the ReadData tests should pass before the app | |
| 552 // is removed. | |
| 553 ASSERT_TRUE(LaunchAppAndRunTest(app, "ReadData")) << message_; | |
| 554 | |
| 555 // Remove the app. | |
| 556 const std::string app_id = app->id(); | |
| 557 EvictApp(app->id()); | |
| 558 app = NULL; | |
| 559 | |
| 560 // The app should be in the list of evicted apps. | |
| 561 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); | |
| 562 ASSERT_TRUE(prefs); | |
| 563 scoped_ptr<ExtensionPrefs::ExtensionsInfo> extensions_info( | |
| 564 prefs->GetEvictedEphemeralAppsInfo()); | |
| 565 EXPECT_TRUE(IsAppInExtensionsInfo(*extensions_info, app_id)); | |
| 566 scoped_ptr<ExtensionInfo> single_extension_info( | |
| 567 prefs->GetEvictedEphemeralAppInfo(app_id)); | |
| 568 EXPECT_TRUE(single_extension_info.get()); | |
| 569 | |
| 570 // The app should not be in the list of installed extensions. | |
| 571 extensions_info = prefs->GetInstalledExtensionsInfo(); | |
| 572 EXPECT_FALSE(IsAppInExtensionsInfo(*extensions_info, app_id)); | |
| 573 EXPECT_FALSE(prefs->IsEphemeralApp(app_id)); | |
| 574 | |
| 575 // Ensure the evicted app is considered to have isolated storage. This will | |
| 576 // prevent its data from getting garbage collected by | |
| 577 // ExtensionService::GarbageCollectIsolatedStorage(). | |
| 578 GURL site_url = extensions::util::GetSiteForExtensionId( | |
| 579 app_id, profile()); | |
| 580 EXPECT_TRUE(extensions::util::SiteHasIsolatedStorage( | |
| 581 site_url, profile())); | |
| 582 | |
| 583 // Phase 2 - Reinstall the ephemeral app and verify that data still exists | |
| 584 // in the storage. | |
| 585 app = InstallEphemeralApp(kRetainDataApp); | |
| 586 ASSERT_TRUE(app); | |
| 587 EXPECT_TRUE(LaunchAppAndRunTest(app, "ReadData")) << message_; | |
| 588 | |
| 589 // The app should now be in the list of installed extensions, but not in the | |
| 590 // list of evicted apps. | |
| 591 extensions_info = prefs->GetInstalledExtensionsInfo(); | |
| 592 EXPECT_TRUE(IsAppInExtensionsInfo(*extensions_info, app_id)); | |
| 593 extensions_info = prefs->GetEvictedEphemeralAppsInfo(); | |
| 594 EXPECT_FALSE(IsAppInExtensionsInfo(*extensions_info, app_id)); | |
| 595 single_extension_info = prefs->GetEvictedEphemeralAppInfo(app_id); | |
| 596 EXPECT_FALSE(single_extension_info.get()); | |
| 597 EXPECT_TRUE(prefs->IsEphemeralApp(app_id)); | |
| 598 } | |
| 599 | |
| 600 // Verify that preferences are updated correctly when an evicted ephemeral app | |
| 601 // is re-installed permanently. | |
| 602 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, InstallEvictedEphemeralApp) { | |
| 603 const Extension* app = InstallEphemeralApp(kRetainDataApp); | |
| 604 ASSERT_TRUE(app); | |
| 605 | |
| 606 // Remove the app. | |
| 607 EvictApp(app->id()); | |
| 608 app = NULL; | |
| 609 | |
| 610 // Install the app permanently. | |
| 611 app = InstallPlatformApp(kRetainDataApp); | |
| 612 ASSERT_TRUE(app); | |
| 613 | |
| 614 // Verify that preferences are correct. | |
| 615 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); | |
| 616 ASSERT_TRUE(prefs); | |
| 617 EXPECT_FALSE(prefs->IsEphemeralApp(app->id())); | |
| 618 | |
| 619 scoped_ptr<ExtensionPrefs::ExtensionsInfo> extensions_info( | |
| 620 prefs->GetEvictedEphemeralAppsInfo()); | |
| 621 EXPECT_FALSE(IsAppInExtensionsInfo(*extensions_info, app->id())); | |
| 622 extensions_info = prefs->GetInstalledExtensionsInfo(); | |
| 623 EXPECT_TRUE(IsAppInExtensionsInfo(*extensions_info, app->id())); | |
| 624 } | |
| 625 | |
| 626 // Verify that the data of regular installed apps are deleted on uninstall. | |
| 627 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, RemoveInstalledData) { | |
| 628 // Install the ephemeral app and write data to various storage. | |
| 629 const Extension* app = InstallPlatformApp(kRetainDataApp); | |
| 630 ASSERT_TRUE(app); | |
| 631 ASSERT_TRUE(LaunchAppAndRunTest(app, "WriteData")) << message_; | |
| 632 | |
| 633 // Remove the app. | |
| 634 const std::string app_id = app->id(); | |
| 635 EvictApp(app->id()); | |
| 636 app = NULL; | |
| 637 | |
| 638 // The app should not be in the preferences. | |
| 639 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); | |
| 640 ASSERT_TRUE(prefs); | |
| 641 scoped_ptr<ExtensionPrefs::ExtensionsInfo> extensions_info( | |
| 642 prefs->GetEvictedEphemeralAppsInfo()); | |
| 643 EXPECT_FALSE(IsAppInExtensionsInfo(*extensions_info, app_id)); | |
| 644 extensions_info = prefs->GetInstalledExtensionsInfo(); | |
| 645 EXPECT_FALSE(IsAppInExtensionsInfo(*extensions_info, app_id)); | |
| 646 | |
| 647 // Reinstall the app and verify that all data has been reset. | |
| 648 app = InstallPlatformApp(kRetainDataApp); | |
| 649 ASSERT_TRUE(LaunchAppAndRunTest(app, "DataReset")) << message_; | |
| 650 } | |
| 651 | |
| 652 // Verify that once evicted from the cache, ephemeral apps will remain in | |
| 653 // extension prefs, but marked as evicted. After garbage collection of data, | |
| 654 // both their data and preferences should be removed. | |
| 655 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, GarbageCollectData) { | |
| 656 // Create two apps. Both will be evicted from the cache, but the data of | |
| 657 // one will be garbage collected. | |
| 658 const Extension* evict_app = InstallEphemeralApp(kRetainDataApp); | |
| 659 ASSERT_TRUE(evict_app); | |
| 660 ASSERT_TRUE(LaunchAppAndRunTest(evict_app, "WriteData")) << message_; | |
| 661 std::string evict_app_id = evict_app->id(); | |
| 662 EvictApp(evict_app_id); | |
| 663 evict_app = NULL; | |
| 664 | |
| 665 const Extension* retain_app = InstallEphemeralApp(kDispatchEventTestApp); | |
| 666 ASSERT_TRUE(retain_app); | |
| 667 std::string retain_app_id = retain_app->id(); | |
| 668 EvictApp(retain_app_id); | |
| 669 retain_app = NULL; | |
| 670 | |
| 671 ExtensionPrefs* prefs = ExtensionPrefs::Get(profile()); | |
| 672 ASSERT_TRUE(prefs); | |
| 673 | |
| 674 // Both apps should be in the list of evicted apps. | |
| 675 scoped_ptr<ExtensionPrefs::ExtensionsInfo> extensions_info( | |
| 676 prefs->GetEvictedEphemeralAppsInfo()); | |
| 677 EXPECT_TRUE(IsAppInExtensionsInfo(*extensions_info, retain_app_id)); | |
| 678 EXPECT_TRUE(IsAppInExtensionsInfo(*extensions_info, evict_app_id)); | |
| 679 | |
| 680 // Set a fake last launch time so that the ephemeral app's data will be | |
| 681 // garbage collected. | |
| 682 base::Time launch_time = | |
| 683 base::Time::Now() - base::TimeDelta::FromDays( | |
| 684 EphemeralAppService::kDataInactiveThreshold + 1); | |
| 685 prefs->SetLastLaunchTime(evict_app_id, launch_time); | |
| 686 prefs->SetLastLaunchTime(retain_app_id, base::Time::Now()); | |
| 687 | |
| 688 // Garbage collect data. | |
| 689 GarbageCollectData(); | |
| 690 | |
| 691 // The garbage collected app should no longer be in the preferences. | |
| 692 extensions_info = prefs->GetEvictedEphemeralAppsInfo(); | |
| 693 EXPECT_TRUE(IsAppInExtensionsInfo(*extensions_info, retain_app_id)); | |
| 694 ASSERT_FALSE(IsAppInExtensionsInfo(*extensions_info, evict_app_id)); | |
| 695 | |
| 696 // Reinstall the app and verify that all data has been reset. | |
| 697 evict_app = InstallEphemeralApp(kRetainDataApp); | |
| 698 ASSERT_TRUE(LaunchAppAndRunTest(evict_app, "DataReset")) << message_; | |
| 699 } | |
| 700 | |
| 701 // Checks the process of installing and then promoting an ephemeral app. | 522 // Checks the process of installing and then promoting an ephemeral app. |
| 702 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, PromoteEphemeralApp) { | 523 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, PromoteEphemeralApp) { |
| 703 InitSyncService(); | 524 InitSyncService(); |
| 704 | 525 |
| 705 const Extension* app = InstallEphemeralApp(kRetainDataApp); | 526 const Extension* app = InstallEphemeralApp(kNotificationsTestApp); |
| 706 ASSERT_TRUE(app); | 527 ASSERT_TRUE(app); |
| 707 | 528 |
| 708 // Ephemeral apps should not be synced. | 529 // Ephemeral apps should not be synced. |
| 709 scoped_ptr<AppSyncData> sync_change = GetFirstSyncChangeForApp(app->id()); | 530 scoped_ptr<AppSyncData> sync_change = GetFirstSyncChangeForApp(app->id()); |
| 710 EXPECT_FALSE(sync_change.get()); | 531 EXPECT_FALSE(sync_change.get()); |
| 711 | 532 |
| 712 // Promote the app to a regular installed app. | 533 // Promote the app to a regular installed app. |
| 713 InstallObserver installed_observer(profile()); | 534 InstallObserver installed_observer(profile()); |
| 714 PromoteEphemeralApp(app); | 535 PromoteEphemeralApp(app); |
| 715 VerifyPromotedApp(app->id(), ExtensionRegistry::ENABLED); | 536 VerifyPromotedApp(app->id(), ExtensionRegistry::ENABLED); |
| 716 | 537 |
| 717 // Check the notification parameters. | 538 // Check the notification parameters. |
| 718 const InstallObserver::InstallParameters& params = installed_observer.Last(); | 539 const InstallObserver::InstallParameters& params = installed_observer.Last(); |
| 719 EXPECT_EQ(app->id(), params.id); | 540 EXPECT_EQ(app->id(), params.id); |
| 720 EXPECT_TRUE(params.is_update); | 541 EXPECT_TRUE(params.is_update); |
| 721 EXPECT_TRUE(params.from_ephemeral); | 542 EXPECT_TRUE(params.from_ephemeral); |
| 722 | 543 |
| 723 // The installation should now be synced. | 544 // The installation should now be synced. |
| 724 sync_change = GetFirstSyncChangeForApp(app->id()); | 545 sync_change = GetFirstSyncChangeForApp(app->id()); |
| 725 VerifySyncChange(sync_change.get(), true); | 546 VerifySyncChange(sync_change.get(), true); |
| 726 } | 547 } |
| 727 | 548 |
| 728 // Verifies that promoting an ephemeral app will enable it. | 549 // Verifies that promoting an ephemeral app will enable it. |
| 729 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, PromoteEphemeralAppAndEnable) { | 550 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, PromoteEphemeralAppAndEnable) { |
| 730 InitSyncService(); | 551 InitSyncService(); |
| 731 | 552 |
| 732 const Extension* app = InstallEphemeralApp(kRetainDataApp); | 553 const Extension* app = InstallEphemeralApp(kNotificationsTestApp); |
| 733 ASSERT_TRUE(app); | 554 ASSERT_TRUE(app); |
| 734 | 555 |
| 735 // Disable the ephemeral app. | 556 // Disable the ephemeral app. |
| 736 ExtensionService* service = | 557 ExtensionService* service = |
| 737 ExtensionSystem::Get(profile())->extension_service(); | 558 ExtensionSystem::Get(profile())->extension_service(); |
| 738 service->DisableExtension(app->id(), Extension::DISABLE_PERMISSIONS_INCREASE); | 559 service->DisableExtension(app->id(), Extension::DISABLE_PERMISSIONS_INCREASE); |
| 739 ASSERT_TRUE(ExtensionRegistry::Get(profile())-> | 560 ASSERT_TRUE(ExtensionRegistry::Get(profile())-> |
| 740 GetExtensionById(app->id(), ExtensionRegistry::DISABLED)); | 561 GetExtensionById(app->id(), ExtensionRegistry::DISABLED)); |
| 741 | 562 |
| 742 // Promote to a regular installed app. It should be enabled. | 563 // Promote to a regular installed app. It should be enabled. |
| 743 PromoteEphemeralApp(app); | 564 PromoteEphemeralApp(app); |
| 744 VerifyPromotedApp(app->id(), ExtensionRegistry::ENABLED); | 565 VerifyPromotedApp(app->id(), ExtensionRegistry::ENABLED); |
| 745 | 566 |
| 746 scoped_ptr<AppSyncData> sync_change = GetFirstSyncChangeForApp(app->id()); | 567 scoped_ptr<AppSyncData> sync_change = GetFirstSyncChangeForApp(app->id()); |
| 747 VerifySyncChange(sync_change.get(), true); | 568 VerifySyncChange(sync_change.get(), true); |
| 748 } | 569 } |
| 749 | 570 |
| 750 // Verifies that promoting an ephemeral app that has unsupported requirements | 571 // Verifies that promoting an ephemeral app that has unsupported requirements |
| 751 // will not enable it. | 572 // will not enable it. |
| 752 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, | 573 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, |
| 753 PromoteUnsupportedEphemeralApp) { | 574 PromoteUnsupportedEphemeralApp) { |
| 754 InitSyncService(); | 575 InitSyncService(); |
| 755 | 576 |
| 756 const Extension* app = InstallEphemeralApp(kRetainDataApp); | 577 const Extension* app = InstallEphemeralApp(kNotificationsTestApp); |
| 757 ASSERT_TRUE(app); | 578 ASSERT_TRUE(app); |
| 758 | 579 |
| 759 // Disable the ephemeral app. | 580 // Disable the ephemeral app. |
| 760 ExtensionService* service = | 581 ExtensionService* service = |
| 761 ExtensionSystem::Get(profile())->extension_service(); | 582 ExtensionSystem::Get(profile())->extension_service(); |
| 762 service->DisableExtension( | 583 service->DisableExtension( |
| 763 app->id(), Extension::DISABLE_UNSUPPORTED_REQUIREMENT); | 584 app->id(), Extension::DISABLE_UNSUPPORTED_REQUIREMENT); |
| 764 ASSERT_TRUE(ExtensionRegistry::Get(profile())-> | 585 ASSERT_TRUE(ExtensionRegistry::Get(profile())-> |
| 765 GetExtensionById(app->id(), ExtensionRegistry::DISABLED)); | 586 GetExtensionById(app->id(), ExtensionRegistry::DISABLED)); |
| 766 | 587 |
| 767 // Promote to a regular installed app. It should remain disabled. | 588 // Promote to a regular installed app. It should remain disabled. |
| 768 PromoteEphemeralApp(app); | 589 PromoteEphemeralApp(app); |
| 769 VerifyPromotedApp(app->id(), ExtensionRegistry::DISABLED); | 590 VerifyPromotedApp(app->id(), ExtensionRegistry::DISABLED); |
| 770 | 591 |
| 771 scoped_ptr<AppSyncData> sync_change = GetFirstSyncChangeForApp(app->id()); | 592 scoped_ptr<AppSyncData> sync_change = GetFirstSyncChangeForApp(app->id()); |
| 772 VerifySyncChange(sync_change.get(), false); | 593 VerifySyncChange(sync_change.get(), false); |
| 773 } | 594 } |
| 774 | 595 |
| 775 // Checks the process of promoting an ephemeral app from sync. | 596 // Checks the process of promoting an ephemeral app from sync. |
| 776 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, PromoteEphemeralAppFromSync) { | 597 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, PromoteEphemeralAppFromSync) { |
| 777 InitSyncService(); | 598 InitSyncService(); |
| 778 | 599 |
| 779 const Extension* app = InstallEphemeralApp(kRetainDataApp); | 600 const Extension* app = InstallEphemeralApp(kNotificationsTestApp); |
| 780 ASSERT_TRUE(app); | 601 ASSERT_TRUE(app); |
| 781 std::string app_id = app->id(); | 602 std::string app_id = app->id(); |
| 782 | 603 |
| 783 // Simulate an install from sync. | 604 // Simulate an install from sync. |
| 784 const syncer::StringOrdinal kAppLaunchOrdinal("x"); | 605 const syncer::StringOrdinal kAppLaunchOrdinal("x"); |
| 785 const syncer::StringOrdinal kPageOrdinal("y"); | 606 const syncer::StringOrdinal kPageOrdinal("y"); |
| 786 AppSyncData app_sync_data( | 607 AppSyncData app_sync_data( |
| 787 *app, | 608 *app, |
| 788 true /* enabled */, | 609 true /* enabled */, |
| 789 false /* incognito enabled */, | 610 false /* incognito enabled */, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 805 kAppLaunchOrdinal)); | 626 kAppLaunchOrdinal)); |
| 806 EXPECT_TRUE(app_sorting->GetPageOrdinal(app_id).Equals(kPageOrdinal)); | 627 EXPECT_TRUE(app_sorting->GetPageOrdinal(app_id).Equals(kPageOrdinal)); |
| 807 } | 628 } |
| 808 | 629 |
| 809 // In most cases, ExtensionService::PromoteEphemeralApp() will be called to | 630 // In most cases, ExtensionService::PromoteEphemeralApp() will be called to |
| 810 // permanently install an ephemeral app. However, there may be cases where an | 631 // permanently install an ephemeral app. However, there may be cases where an |
| 811 // install occurs through the usual route of installing from the Web Store (due | 632 // install occurs through the usual route of installing from the Web Store (due |
| 812 // to race conditions). Ensure that the app is still installed correctly. | 633 // to race conditions). Ensure that the app is still installed correctly. |
| 813 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, | 634 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, |
| 814 ReplaceEphemeralAppWithInstalledApp) { | 635 ReplaceEphemeralAppWithInstalledApp) { |
| 815 const Extension* app = InstallEphemeralApp(kRetainDataApp); | 636 const Extension* app = InstallEphemeralApp(kNotificationsTestApp); |
| 816 ASSERT_TRUE(app); | 637 ASSERT_TRUE(app); |
| 817 std::string app_id = app->id(); | 638 std::string app_id = app->id(); |
| 818 app = NULL; | 639 app = NULL; |
| 819 | 640 |
| 820 InstallObserver installed_observer(profile()); | 641 InstallObserver installed_observer(profile()); |
| 821 ReplaceEphemeralApp(app_id, kRetainDataApp); | 642 ReplaceEphemeralApp(app_id, kNotificationsTestApp); |
| 822 VerifyPromotedApp(app_id, ExtensionRegistry::ENABLED); | 643 VerifyPromotedApp(app_id, ExtensionRegistry::ENABLED); |
| 823 | 644 |
| 824 // Check the notification parameters. | 645 // Check the notification parameters. |
| 825 const InstallObserver::InstallParameters& params = installed_observer.Last(); | 646 const InstallObserver::InstallParameters& params = installed_observer.Last(); |
| 826 EXPECT_EQ(app_id, params.id); | 647 EXPECT_EQ(app_id, params.id); |
| 827 EXPECT_TRUE(params.is_update); | 648 EXPECT_TRUE(params.is_update); |
| 828 EXPECT_TRUE(params.from_ephemeral); | 649 EXPECT_TRUE(params.from_ephemeral); |
| 829 } | 650 } |
| 830 | 651 |
| 831 // This is similar to ReplaceEphemeralAppWithInstalledApp, but installs will | 652 // This is similar to ReplaceEphemeralAppWithInstalledApp, but installs will |
| 832 // be delayed until the app is idle. | 653 // be delayed until the app is idle. |
| 833 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, | 654 IN_PROC_BROWSER_TEST_F(EphemeralAppBrowserTest, |
| 834 ReplaceEphemeralAppWithDelayedInstalledApp) { | 655 ReplaceEphemeralAppWithDelayedInstalledApp) { |
| 835 const Extension* app = InstallAndLaunchEphemeralApp(kRetainDataApp); | 656 const Extension* app = InstallAndLaunchEphemeralApp(kNotificationsTestApp); |
| 836 ASSERT_TRUE(app); | 657 ASSERT_TRUE(app); |
| 837 std::string app_id = app->id(); | 658 std::string app_id = app->id(); |
| 838 app = NULL; | 659 app = NULL; |
| 839 | 660 |
| 840 // Initiate install. | 661 // Initiate install. |
| 841 ReplaceEphemeralApp(app_id, kRetainDataApp); | 662 ReplaceEphemeralApp(app_id, kNotificationsTestApp); |
| 842 | 663 |
| 843 // The delayed installation will occur when the ephemeral app is closed. | 664 // The delayed installation will occur when the ephemeral app is closed. |
| 844 content::WindowedNotificationObserver installed_signal( | 665 content::WindowedNotificationObserver installed_signal( |
| 845 chrome::NOTIFICATION_EXTENSION_INSTALLED_DEPRECATED, | 666 chrome::NOTIFICATION_EXTENSION_INSTALLED_DEPRECATED, |
| 846 content::Source<Profile>(profile())); | 667 content::Source<Profile>(profile())); |
| 847 InstallObserver installed_observer(profile()); | 668 InstallObserver installed_observer(profile()); |
| 848 CloseApp(app_id); | 669 CloseApp(app_id); |
| 849 installed_signal.Wait(); | 670 installed_signal.Wait(); |
| 850 VerifyPromotedApp(app_id, ExtensionRegistry::ENABLED); | 671 VerifyPromotedApp(app_id, ExtensionRegistry::ENABLED); |
| 851 | 672 |
| 852 // Check the notification parameters. | 673 // Check the notification parameters. |
| 853 const InstallObserver::InstallParameters& params = installed_observer.Last(); | 674 const InstallObserver::InstallParameters& params = installed_observer.Last(); |
| 854 EXPECT_EQ(app_id, params.id); | 675 EXPECT_EQ(app_id, params.id); |
| 855 EXPECT_TRUE(params.is_update); | 676 EXPECT_TRUE(params.is_update); |
| 856 EXPECT_TRUE(params.from_ephemeral); | 677 EXPECT_TRUE(params.from_ephemeral); |
| 857 } | 678 } |
| OLD | NEW |