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