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 "base/message_loop/message_loop_proxy.h" | 5 #include "base/message_loop/message_loop_proxy.h" |
6 #include "chrome/browser/apps/ephemeral_app_launcher.h" | 6 #include "chrome/browser/apps/ephemeral_app_launcher.h" |
| 7 #include "chrome/browser/apps/ephemeral_app_service.h" |
7 #include "chrome/browser/extensions/extension_install_checker.h" | 8 #include "chrome/browser/extensions/extension_install_checker.h" |
8 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
9 #include "chrome/browser/extensions/extension_test_message_listener.h" | 10 #include "chrome/browser/extensions/extension_test_message_listener.h" |
10 #include "chrome/browser/extensions/test_blacklist.h" | 11 #include "chrome/browser/extensions/test_blacklist.h" |
11 #include "chrome/browser/extensions/webstore_installer_test.h" | 12 #include "chrome/browser/extensions/webstore_installer_test.h" |
12 #include "chrome/browser/ui/browser_finder.h" | 13 #include "chrome/browser/ui/browser_finder.h" |
13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
14 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
15 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
16 #include "content/public/test/test_utils.h" | 17 #include "content/public/test/test_utils.h" |
17 #include "extensions/browser/extension_prefs.h" | 18 #include "extensions/browser/extension_prefs.h" |
18 #include "extensions/browser/extension_registry.h" | 19 #include "extensions/browser/extension_registry.h" |
19 #include "extensions/browser/extension_system.h" | 20 #include "extensions/browser/extension_system.h" |
20 #include "extensions/browser/extension_util.h" | 21 #include "extensions/browser/extension_util.h" |
21 #include "extensions/browser/management_policy.h" | 22 #include "extensions/browser/management_policy.h" |
| 23 #include "extensions/common/switches.h" |
22 | 24 |
23 using extensions::Extension; | 25 using extensions::Extension; |
24 using extensions::ExtensionPrefs; | 26 using extensions::ExtensionPrefs; |
25 using extensions::ExtensionRegistry; | 27 using extensions::ExtensionRegistry; |
26 using extensions::ExtensionSystem; | 28 using extensions::ExtensionSystem; |
27 namespace webstore_install = extensions::webstore_install; | 29 namespace webstore_install = extensions::webstore_install; |
28 | 30 |
29 namespace { | 31 namespace { |
30 | 32 |
31 const char kWebstoreDomain[] = "cws.com"; | 33 const char kWebstoreDomain[] = "cws.com"; |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 EphemeralAppLauncherTest() | 188 EphemeralAppLauncherTest() |
187 : WebstoreInstallerTest(kWebstoreDomain, | 189 : WebstoreInstallerTest(kWebstoreDomain, |
188 kTestDataPath, | 190 kTestDataPath, |
189 kDefaultAppCrxFilename, | 191 kDefaultAppCrxFilename, |
190 kAppDomain, | 192 kAppDomain, |
191 kNonAppDomain) {} | 193 kNonAppDomain) {} |
192 | 194 |
193 virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE { | 195 virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE { |
194 WebstoreInstallerTest::SetUpCommandLine(command_line); | 196 WebstoreInstallerTest::SetUpCommandLine(command_line); |
195 | 197 |
| 198 // Make event pages get suspended immediately. |
| 199 command_line->AppendSwitchASCII(extensions::switches::kEventPageIdleTime, |
| 200 "10"); |
| 201 command_line->AppendSwitchASCII( |
| 202 extensions::switches::kEventPageSuspendingTime, "10"); |
| 203 |
196 // Enable ephemeral apps flag. | 204 // Enable ephemeral apps flag. |
197 command_line->AppendSwitch(switches::kEnableEphemeralApps); | 205 command_line->AppendSwitch(switches::kEnableEphemeralApps); |
198 } | 206 } |
199 | 207 |
| 208 virtual void SetUpOnMainThread() OVERRIDE { |
| 209 WebstoreInstallerTest::SetUpOnMainThread(); |
| 210 |
| 211 // Unload ephemeral apps immediately after they stop running in tests. |
| 212 EphemeralAppService::Get(profile())->set_unload_delay_for_test(0); |
| 213 } |
| 214 |
200 base::FilePath GetTestPath(const char* test_name) { | 215 base::FilePath GetTestPath(const char* test_name) { |
201 return test_data_dir_.AppendASCII("platform_apps/ephemeral_launcher") | 216 return test_data_dir_.AppendASCII("platform_apps/ephemeral_launcher") |
202 .AppendASCII(test_name); | 217 .AppendASCII(test_name); |
203 } | 218 } |
204 | 219 |
205 const Extension* GetInstalledExtension(const std::string& id) { | 220 const Extension* GetInstalledExtension(const std::string& id) { |
206 return ExtensionRegistry::Get(profile()) | 221 return ExtensionRegistry::Get(profile()) |
207 ->GetExtensionById(id, ExtensionRegistry::EVERYTHING); | 222 ->GetExtensionById(id, ExtensionRegistry::EVERYTHING); |
208 } | 223 } |
209 | 224 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 } | 269 } |
255 | 270 |
256 const Extension* InstallAndDisableApp( | 271 const Extension* InstallAndDisableApp( |
257 const char* test_path, | 272 const char* test_path, |
258 Extension::DisableReason disable_reason) { | 273 Extension::DisableReason disable_reason) { |
259 const Extension* app = InstallExtension(GetTestPath(test_path), 1); | 274 const Extension* app = InstallExtension(GetTestPath(test_path), 1); |
260 EXPECT_TRUE(app); | 275 EXPECT_TRUE(app); |
261 if (!app) | 276 if (!app) |
262 return NULL; | 277 return NULL; |
263 | 278 |
264 if (disable_reason == Extension::DISABLE_GREYLIST) { | |
265 ExtensionPrefs::Get(profile())->SetExtensionBlacklistState( | |
266 app->id(), extensions::BLACKLISTED_MALWARE); | |
267 } | |
268 | |
269 ExtensionService* service = | 279 ExtensionService* service = |
270 ExtensionSystem::Get(profile())->extension_service(); | 280 ExtensionSystem::Get(profile())->extension_service(); |
271 service->DisableExtension(app->id(), disable_reason); | 281 service->DisableExtension(app->id(), disable_reason); |
272 | 282 |
273 if (disable_reason == Extension::DISABLE_PERMISSIONS_INCREASE) { | 283 if (disable_reason == Extension::DISABLE_PERMISSIONS_INCREASE) { |
274 // When an extension is disabled due to a permissions increase, this | 284 // When an extension is disabled due to a permissions increase, this |
275 // flag needs to be set too, for some reason. | 285 // flag needs to be set too, for some reason. |
276 ExtensionPrefs::Get(profile()) | 286 ExtensionPrefs::Get(profile()) |
277 ->SetDidExtensionEscalatePermissions(app, true); | 287 ->SetDidExtensionEscalatePermissions(app, true); |
278 } | 288 } |
279 | 289 |
280 EXPECT_FALSE( | 290 EXPECT_TRUE( |
281 ExtensionRegistry::Get(profile())->enabled_extensions().Contains( | 291 ExtensionRegistry::Get(profile())->disabled_extensions().Contains( |
282 app->id())); | 292 app->id())); |
283 return app; | 293 return app; |
284 } | 294 } |
285 }; | 295 }; |
286 | 296 |
287 class EphemeralAppLauncherTestDisabled : public EphemeralAppLauncherTest { | 297 class EphemeralAppLauncherTestDisabled : public EphemeralAppLauncherTest { |
288 public: | 298 public: |
289 virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE { | 299 virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE { |
290 // Skip EphemeralAppLauncherTest as it enables the feature. | 300 // Skip EphemeralAppLauncherTest as it enables the feature. |
291 WebstoreInstallerTest::SetUpCommandLine(command_line); | 301 WebstoreInstallerTest::SetUpCommandLine(command_line); |
292 } | 302 } |
293 }; | 303 }; |
294 | 304 |
295 // Verifies that an ephemeral app will not be installed and launched if the | 305 // Verifies that an ephemeral app will not be installed and launched if the |
296 // feature is disabled. | 306 // feature is disabled. |
297 IN_PROC_BROWSER_TEST_F(EphemeralAppLauncherTestDisabled, FeatureDisabled) { | 307 IN_PROC_BROWSER_TEST_F(EphemeralAppLauncherTestDisabled, FeatureDisabled) { |
298 RunLaunchTest( | 308 RunLaunchTest( |
299 kDefaultAppCrxFilename, webstore_install::LAUNCH_FEATURE_DISABLED, false); | 309 kDefaultAppCrxFilename, webstore_install::LAUNCH_FEATURE_DISABLED, false); |
300 EXPECT_FALSE(GetInstalledExtension(kDefaultAppId)); | 310 EXPECT_FALSE(GetInstalledExtension(kDefaultAppId)); |
301 } | 311 } |
302 | 312 |
303 // Verifies that an app with no permission warnings will be installed | 313 // Verifies that an app with no permission warnings will be installed |
304 // ephemerally and launched without prompting the user. | 314 // ephemerally and launched without prompting the user. |
305 IN_PROC_BROWSER_TEST_F(EphemeralAppLauncherTest, | 315 IN_PROC_BROWSER_TEST_F(EphemeralAppLauncherTest, |
306 LaunchAppWithNoPermissionWarnings) { | 316 LaunchAppWithNoPermissionWarnings) { |
| 317 content::WindowedNotificationObserver unloaded_signal( |
| 318 chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, |
| 319 content::Source<Profile>(profile())); |
| 320 |
307 scoped_refptr<EphemeralAppLauncherForTest> launcher( | 321 scoped_refptr<EphemeralAppLauncherForTest> launcher( |
308 new EphemeralAppLauncherForTest(kDefaultAppId, profile())); | 322 new EphemeralAppLauncherForTest(kDefaultAppId, profile())); |
309 StartLauncherAndCheckResult(launcher.get(), webstore_install::SUCCESS, true); | 323 StartLauncherAndCheckResult(launcher.get(), webstore_install::SUCCESS, true); |
310 ValidateAppInstalledEphemerally(kDefaultAppId); | 324 ValidateAppInstalledEphemerally(kDefaultAppId); |
311 | 325 |
312 // Apps with no permission warnings should not result in a prompt. | 326 // Apps with no permission warnings should not result in a prompt. |
313 EXPECT_FALSE(launcher->install_prompt_created()); | 327 EXPECT_FALSE(launcher->install_prompt_created()); |
314 | 328 |
| 329 // Ephemeral apps are unloaded after they stop running. |
| 330 unloaded_signal.Wait(); |
| 331 |
315 // After an app has been installed ephemerally, it can be launched again | 332 // After an app has been installed ephemerally, it can be launched again |
316 // without installing from the web store. | 333 // without installing from the web store. |
317 RunLaunchTest(kDefaultAppId, webstore_install::SUCCESS, false); | 334 RunLaunchTest(kDefaultAppId, webstore_install::SUCCESS, false); |
318 } | 335 } |
319 | 336 |
320 // Verifies that an app with permission warnings will be installed | 337 // Verifies that an app with permission warnings will be installed |
321 // ephemerally and launched if accepted by the user. | 338 // ephemerally and launched if accepted by the user. |
322 IN_PROC_BROWSER_TEST_F(EphemeralAppLauncherTest, | 339 IN_PROC_BROWSER_TEST_F(EphemeralAppLauncherTest, |
323 LaunchAppWithPermissionsWarnings) { | 340 LaunchAppWithPermissionsWarnings) { |
324 SetCrxFilename(kAppWithPermissionsFilename); | 341 SetCrxFilename(kAppWithPermissionsFilename); |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 ManagementPolicyMock policy; | 512 ManagementPolicyMock policy; |
496 ExtensionSystem::Get(profile())->management_policy()->RegisterProvider( | 513 ExtensionSystem::Get(profile())->management_policy()->RegisterProvider( |
497 &policy); | 514 &policy); |
498 ExtensionSystem::Get(profile())->extension_service()->CheckManagementPolicy(); | 515 ExtensionSystem::Get(profile())->extension_service()->CheckManagementPolicy(); |
499 | 516 |
500 RunLaunchTest(app->id(), webstore_install::BLOCKED_BY_POLICY, false); | 517 RunLaunchTest(app->id(), webstore_install::BLOCKED_BY_POLICY, false); |
501 } | 518 } |
502 | 519 |
503 // Verifies that an installed blacklisted app cannot be launched. | 520 // Verifies that an installed blacklisted app cannot be launched. |
504 IN_PROC_BROWSER_TEST_F(EphemeralAppLauncherTest, LaunchBlacklistedApp) { | 521 IN_PROC_BROWSER_TEST_F(EphemeralAppLauncherTest, LaunchBlacklistedApp) { |
505 const Extension* app = | 522 const Extension* app = InstallExtension(GetTestPath(kDefaultAppTestPath), 1); |
506 InstallAndDisableApp(kDefaultAppTestPath, Extension::DISABLE_GREYLIST); | |
507 ASSERT_TRUE(app); | 523 ASSERT_TRUE(app); |
508 | 524 |
| 525 ExtensionService* service = |
| 526 ExtensionSystem::Get(profile())->extension_service(); |
| 527 service->BlacklistExtensionForTest(app->id()); |
| 528 ASSERT_TRUE( |
| 529 ExtensionRegistry::Get(profile())->blacklisted_extensions().Contains( |
| 530 app->id())); |
| 531 |
509 RunLaunchTest(app->id(), webstore_install::BLACKLISTED, false); | 532 RunLaunchTest(app->id(), webstore_install::BLACKLISTED, false); |
510 } | 533 } |
511 | 534 |
512 // Verifies that an installed app with unsupported requirements cannot be | 535 // Verifies that an installed app with unsupported requirements cannot be |
513 // launched. | 536 // launched. |
514 IN_PROC_BROWSER_TEST_F(EphemeralAppLauncherTest, | 537 IN_PROC_BROWSER_TEST_F(EphemeralAppLauncherTest, |
515 LaunchAppWithUnsupportedRequirements) { | 538 LaunchAppWithUnsupportedRequirements) { |
516 const Extension* app = InstallAndDisableApp( | 539 const Extension* app = InstallAndDisableApp( |
517 kDefaultAppTestPath, Extension::DISABLE_UNSUPPORTED_REQUIREMENT); | 540 kDefaultAppTestPath, Extension::DISABLE_UNSUPPORTED_REQUIREMENT); |
518 ASSERT_TRUE(app); | 541 ASSERT_TRUE(app); |
519 | 542 |
520 RunLaunchTest(app->id(), webstore_install::REQUIREMENT_VIOLATIONS, false); | 543 RunLaunchTest(app->id(), webstore_install::REQUIREMENT_VIOLATIONS, false); |
521 } | 544 } |
OLD | NEW |