| 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "chrome/browser/apps/ephemeral_app_browsertest.h" | 7 #include "chrome/browser/apps/ephemeral_app_browsertest.h" |
| 8 #include "chrome/browser/apps/ephemeral_app_service.h" | 8 #include "chrome/browser/apps/ephemeral_app_service.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "content/public/test/test_utils.h" | 10 #include "content/public/test/test_utils.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 EphemeralAppService* ephemeral_service = EphemeralAppService::Get( | 42 EphemeralAppService* ephemeral_service = EphemeralAppService::Get( |
| 43 browser()->profile()); | 43 browser()->profile()); |
| 44 ASSERT_TRUE(ephemeral_service); | 44 ASSERT_TRUE(ephemeral_service); |
| 45 ephemeral_service->GarbageCollectApps(); | 45 ephemeral_service->GarbageCollectApps(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 void InitEphemeralAppCount(EphemeralAppService* ephemeral_service) { | 48 void InitEphemeralAppCount(EphemeralAppService* ephemeral_service) { |
| 49 ephemeral_service->InitEphemeralAppCount(); | 49 ephemeral_service->InitEphemeralAppCount(); |
| 50 } | 50 } |
| 51 | 51 |
| 52 void UnloadEphemeralAppsOnStartup() { |
| 53 EphemeralAppService* ephemeral_service = |
| 54 EphemeralAppService::Get(browser()->profile()); |
| 55 ASSERT_TRUE(ephemeral_service); |
| 56 ephemeral_service->UnloadEphemeralAppsOnStartup(); |
| 57 } |
| 58 |
| 52 std::vector<std::string> app_ids_; | 59 std::vector<std::string> app_ids_; |
| 53 }; | 60 }; |
| 54 | 61 |
| 55 // Verifies that inactive ephemeral apps are uninstalled and active apps are | 62 // Verifies that inactive ephemeral apps are uninstalled and active apps are |
| 56 // not removed. Extensive testing of the ephemeral app cache's replacement | 63 // not removed. Extensive testing of the ephemeral app cache's replacement |
| 57 // policies is done in the unit tests for EphemeralAppService. This is more | 64 // policies is done in the unit tests for EphemeralAppService. This is more |
| 58 // like an integration test. | 65 // like an integration test. |
| 59 IN_PROC_BROWSER_TEST_F(EphemeralAppServiceBrowserTest, | 66 IN_PROC_BROWSER_TEST_F(EphemeralAppServiceBrowserTest, |
| 60 GarbageCollectInactiveApps) { | 67 GarbageCollectInactiveApps) { |
| 61 EphemeralAppService* ephemeral_service = | 68 EphemeralAppService* ephemeral_service = |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 | 138 |
| 132 // Verify that the cache of ephemeral apps is correctly cleared. Running apps | 139 // Verify that the cache of ephemeral apps is correctly cleared. Running apps |
| 133 // should not be removed. | 140 // should not be removed. |
| 134 IN_PROC_BROWSER_TEST_F(EphemeralAppServiceBrowserTest, ClearCachedApps) { | 141 IN_PROC_BROWSER_TEST_F(EphemeralAppServiceBrowserTest, ClearCachedApps) { |
| 135 const Extension* running_app = | 142 const Extension* running_app = |
| 136 InstallAndLaunchEphemeralApp(kMessagingReceiverApp); | 143 InstallAndLaunchEphemeralApp(kMessagingReceiverApp); |
| 137 const Extension* inactive_app = | 144 const Extension* inactive_app = |
| 138 InstallAndLaunchEphemeralApp(kDispatchEventTestApp); | 145 InstallAndLaunchEphemeralApp(kDispatchEventTestApp); |
| 139 std::string inactive_app_id = inactive_app->id(); | 146 std::string inactive_app_id = inactive_app->id(); |
| 140 std::string running_app_id = running_app->id(); | 147 std::string running_app_id = running_app->id(); |
| 141 CloseApp(inactive_app_id); | 148 CloseAppWaitForUnload(inactive_app_id); |
| 142 | 149 |
| 143 EphemeralAppService* ephemeral_service = | 150 EphemeralAppService* ephemeral_service = |
| 144 EphemeralAppService::Get(browser()->profile()); | 151 EphemeralAppService::Get(browser()->profile()); |
| 145 ASSERT_TRUE(ephemeral_service); | 152 ASSERT_TRUE(ephemeral_service); |
| 146 EXPECT_EQ(2, ephemeral_service->ephemeral_app_count()); | 153 EXPECT_EQ(2, ephemeral_service->ephemeral_app_count()); |
| 147 | 154 |
| 148 ephemeral_service->ClearCachedApps(); | 155 ephemeral_service->ClearCachedApps(); |
| 149 | 156 |
| 150 ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); | 157 ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); |
| 151 ASSERT_TRUE(registry); | 158 ASSERT_TRUE(registry); |
| 152 EXPECT_FALSE(registry->GetExtensionById(inactive_app_id, | 159 EXPECT_FALSE(registry->GetExtensionById(inactive_app_id, |
| 153 ExtensionRegistry::EVERYTHING)); | 160 ExtensionRegistry::EVERYTHING)); |
| 154 EXPECT_TRUE(registry->GetExtensionById(running_app_id, | 161 EXPECT_TRUE(registry->GetExtensionById(running_app_id, |
| 155 ExtensionRegistry::EVERYTHING)); | 162 ExtensionRegistry::EVERYTHING)); |
| 156 | 163 |
| 157 EXPECT_EQ(1, ephemeral_service->ephemeral_app_count()); | 164 EXPECT_EQ(1, ephemeral_service->ephemeral_app_count()); |
| 158 } | 165 } |
| 166 |
| 167 // Verify that the service will unload and disable ephemeral apps on startup. |
| 168 IN_PROC_BROWSER_TEST_F(EphemeralAppServiceBrowserTest, |
| 169 UnloadEphemeralAppsOnStartup) { |
| 170 const Extension* installed_app = InstallPlatformApp(kNotificationsTestApp); |
| 171 const Extension* running_app = |
| 172 InstallAndLaunchEphemeralApp(kMessagingReceiverApp); |
| 173 const Extension* inactive_app = InstallEphemeralApp(kDispatchEventTestApp); |
| 174 ASSERT_TRUE(installed_app); |
| 175 ASSERT_TRUE(running_app); |
| 176 ASSERT_TRUE(inactive_app); |
| 177 |
| 178 ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); |
| 179 DCHECK(registry); |
| 180 EXPECT_TRUE(registry->enabled_extensions().Contains(installed_app->id())); |
| 181 EXPECT_TRUE(registry->enabled_extensions().Contains(running_app->id())); |
| 182 EXPECT_TRUE(registry->enabled_extensions().Contains(inactive_app->id())); |
| 183 |
| 184 UnloadEphemeralAppsOnStartup(); |
| 185 |
| 186 // Verify that the inactive app is disabled. |
| 187 EXPECT_TRUE(registry->enabled_extensions().Contains(installed_app->id())); |
| 188 EXPECT_TRUE(registry->enabled_extensions().Contains(running_app->id())); |
| 189 EXPECT_TRUE(registry->disabled_extensions().Contains(inactive_app->id())); |
| 190 } |
| OLD | NEW |