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