| 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/apps/ephemeral_app_service.h" |
| 8 #include "chrome/browser/extensions/extension_install_checker.h" | 8 #include "chrome/browser/extensions/extension_install_checker.h" |
| 9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
| 10 #include "chrome/browser/extensions/install_tracker.h" | 10 #include "chrome/browser/extensions/install_tracker.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 class ExtensionInstallCheckerMock : public extensions::ExtensionInstallChecker { | 54 class ExtensionInstallCheckerMock : public extensions::ExtensionInstallChecker { |
| 55 public: | 55 public: |
| 56 ExtensionInstallCheckerMock(Profile* profile, | 56 ExtensionInstallCheckerMock(Profile* profile, |
| 57 const std::string& requirements_error) | 57 const std::string& requirements_error) |
| 58 : extensions::ExtensionInstallChecker(profile), | 58 : extensions::ExtensionInstallChecker(profile), |
| 59 requirements_error_(requirements_error) {} | 59 requirements_error_(requirements_error) {} |
| 60 | 60 |
| 61 virtual ~ExtensionInstallCheckerMock() {} | 61 virtual ~ExtensionInstallCheckerMock() {} |
| 62 | 62 |
| 63 private: | 63 private: |
| 64 virtual void CheckRequirements() OVERRIDE { | 64 virtual void CheckRequirements() override { |
| 65 // Simulate an asynchronous operation. | 65 // Simulate an asynchronous operation. |
| 66 base::MessageLoopProxy::current()->PostTask( | 66 base::MessageLoopProxy::current()->PostTask( |
| 67 FROM_HERE, | 67 FROM_HERE, |
| 68 base::Bind(&ExtensionInstallCheckerMock::RequirementsErrorCheckDone, | 68 base::Bind(&ExtensionInstallCheckerMock::RequirementsErrorCheckDone, |
| 69 base::Unretained(this), | 69 base::Unretained(this), |
| 70 current_sequence_number())); | 70 current_sequence_number())); |
| 71 } | 71 } |
| 72 | 72 |
| 73 void RequirementsErrorCheckDone(int sequence_number) { | 73 void RequirementsErrorCheckDone(int sequence_number) { |
| 74 std::vector<std::string> errors; | 74 std::vector<std::string> errors; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 97 bool install_prompt_created() const { return install_prompt_created_; } | 97 bool install_prompt_created() const { return install_prompt_created_; } |
| 98 | 98 |
| 99 void set_requirements_error(const std::string& error) { | 99 void set_requirements_error(const std::string& error) { |
| 100 requirements_check_error_ = error; | 100 requirements_check_error_ = error; |
| 101 } | 101 } |
| 102 | 102 |
| 103 private: | 103 private: |
| 104 // Override necessary functions for testing. | 104 // Override necessary functions for testing. |
| 105 | 105 |
| 106 virtual scoped_ptr<extensions::ExtensionInstallChecker> CreateInstallChecker() | 106 virtual scoped_ptr<extensions::ExtensionInstallChecker> CreateInstallChecker() |
| 107 OVERRIDE { | 107 override { |
| 108 if (requirements_check_error_.empty()) { | 108 if (requirements_check_error_.empty()) { |
| 109 return EphemeralAppLauncher::CreateInstallChecker(); | 109 return EphemeralAppLauncher::CreateInstallChecker(); |
| 110 } else { | 110 } else { |
| 111 return scoped_ptr<extensions::ExtensionInstallChecker>( | 111 return scoped_ptr<extensions::ExtensionInstallChecker>( |
| 112 new ExtensionInstallCheckerMock(profile(), | 112 new ExtensionInstallCheckerMock(profile(), |
| 113 requirements_check_error_)); | 113 requirements_check_error_)); |
| 114 } | 114 } |
| 115 } | 115 } |
| 116 | 116 |
| 117 virtual scoped_ptr<ExtensionInstallPrompt> CreateInstallUI() OVERRIDE { | 117 virtual scoped_ptr<ExtensionInstallPrompt> CreateInstallUI() override { |
| 118 install_prompt_created_ = true; | 118 install_prompt_created_ = true; |
| 119 return EphemeralAppLauncher::CreateInstallUI(); | 119 return EphemeralAppLauncher::CreateInstallUI(); |
| 120 } | 120 } |
| 121 | 121 |
| 122 virtual scoped_ptr<extensions::WebstoreInstaller::Approval> CreateApproval() | 122 virtual scoped_ptr<extensions::WebstoreInstaller::Approval> CreateApproval() |
| 123 const OVERRIDE { | 123 const override { |
| 124 install_initiated_ = true; | 124 install_initiated_ = true; |
| 125 return EphemeralAppLauncher::CreateApproval(); | 125 return EphemeralAppLauncher::CreateApproval(); |
| 126 } | 126 } |
| 127 | 127 |
| 128 private: | 128 private: |
| 129 virtual ~EphemeralAppLauncherForTest() {} | 129 virtual ~EphemeralAppLauncherForTest() {} |
| 130 friend class base::RefCountedThreadSafe<EphemeralAppLauncherForTest>; | 130 friend class base::RefCountedThreadSafe<EphemeralAppLauncherForTest>; |
| 131 | 131 |
| 132 mutable bool install_initiated_; | 132 mutable bool install_initiated_; |
| 133 std::string requirements_check_error_; | 133 std::string requirements_check_error_; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 bool done_; | 167 bool done_; |
| 168 bool waiting_; | 168 bool waiting_; |
| 169 webstore_install::Result result_; | 169 webstore_install::Result result_; |
| 170 std::string error_; | 170 std::string error_; |
| 171 }; | 171 }; |
| 172 | 172 |
| 173 class ManagementPolicyMock : public extensions::ManagementPolicy::Provider { | 173 class ManagementPolicyMock : public extensions::ManagementPolicy::Provider { |
| 174 public: | 174 public: |
| 175 ManagementPolicyMock() {} | 175 ManagementPolicyMock() {} |
| 176 | 176 |
| 177 virtual std::string GetDebugPolicyProviderName() const OVERRIDE { | 177 virtual std::string GetDebugPolicyProviderName() const override { |
| 178 return "ManagementPolicyMock"; | 178 return "ManagementPolicyMock"; |
| 179 } | 179 } |
| 180 | 180 |
| 181 virtual bool UserMayLoad(const Extension* extension, | 181 virtual bool UserMayLoad(const Extension* extension, |
| 182 base::string16* error) const OVERRIDE { | 182 base::string16* error) const override { |
| 183 return false; | 183 return false; |
| 184 } | 184 } |
| 185 }; | 185 }; |
| 186 | 186 |
| 187 } // namespace | 187 } // namespace |
| 188 | 188 |
| 189 class EphemeralAppLauncherTest : public WebstoreInstallerTest { | 189 class EphemeralAppLauncherTest : public WebstoreInstallerTest { |
| 190 public: | 190 public: |
| 191 EphemeralAppLauncherTest() | 191 EphemeralAppLauncherTest() |
| 192 : WebstoreInstallerTest(kWebstoreDomain, | 192 : WebstoreInstallerTest(kWebstoreDomain, |
| 193 kTestDataPath, | 193 kTestDataPath, |
| 194 kDefaultAppCrxFilename, | 194 kDefaultAppCrxFilename, |
| 195 kAppDomain, | 195 kAppDomain, |
| 196 kNonAppDomain) {} | 196 kNonAppDomain) {} |
| 197 | 197 |
| 198 virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE { | 198 virtual void SetUpCommandLine(base::CommandLine* command_line) override { |
| 199 WebstoreInstallerTest::SetUpCommandLine(command_line); | 199 WebstoreInstallerTest::SetUpCommandLine(command_line); |
| 200 | 200 |
| 201 // Make event pages get suspended immediately. | 201 // Make event pages get suspended immediately. |
| 202 extensions::ProcessManager::SetEventPageIdleTimeForTesting(1); | 202 extensions::ProcessManager::SetEventPageIdleTimeForTesting(1); |
| 203 extensions::ProcessManager::SetEventPageSuspendingTimeForTesting(1); | 203 extensions::ProcessManager::SetEventPageSuspendingTimeForTesting(1); |
| 204 | 204 |
| 205 // Enable ephemeral apps flag. | 205 // Enable ephemeral apps flag. |
| 206 command_line->AppendSwitch(switches::kEnableEphemeralApps); | 206 command_line->AppendSwitch(switches::kEnableEphemeralApps); |
| 207 } | 207 } |
| 208 | 208 |
| 209 virtual void SetUpOnMainThread() OVERRIDE { | 209 virtual void SetUpOnMainThread() override { |
| 210 WebstoreInstallerTest::SetUpOnMainThread(); | 210 WebstoreInstallerTest::SetUpOnMainThread(); |
| 211 | 211 |
| 212 // Disable ephemeral apps immediately after they stop running in tests. | 212 // Disable ephemeral apps immediately after they stop running in tests. |
| 213 EphemeralAppService::Get(profile())->set_disable_delay_for_test(0); | 213 EphemeralAppService::Get(profile())->set_disable_delay_for_test(0); |
| 214 } | 214 } |
| 215 | 215 |
| 216 base::FilePath GetTestPath(const char* test_name) { | 216 base::FilePath GetTestPath(const char* test_name) { |
| 217 return test_data_dir_.AppendASCII("platform_apps/ephemeral_launcher") | 217 return test_data_dir_.AppendASCII("platform_apps/ephemeral_launcher") |
| 218 .AppendASCII(test_name); | 218 .AppendASCII(test_name); |
| 219 } | 219 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 | 297 |
| 298 EXPECT_TRUE( | 298 EXPECT_TRUE( |
| 299 ExtensionRegistry::Get(profile())->disabled_extensions().Contains( | 299 ExtensionRegistry::Get(profile())->disabled_extensions().Contains( |
| 300 app->id())); | 300 app->id())); |
| 301 return app; | 301 return app; |
| 302 } | 302 } |
| 303 }; | 303 }; |
| 304 | 304 |
| 305 class EphemeralAppLauncherTestDisabled : public EphemeralAppLauncherTest { | 305 class EphemeralAppLauncherTestDisabled : public EphemeralAppLauncherTest { |
| 306 public: | 306 public: |
| 307 virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE { | 307 virtual void SetUpCommandLine(base::CommandLine* command_line) override { |
| 308 // Skip EphemeralAppLauncherTest as it enables the feature. | 308 // Skip EphemeralAppLauncherTest as it enables the feature. |
| 309 WebstoreInstallerTest::SetUpCommandLine(command_line); | 309 WebstoreInstallerTest::SetUpCommandLine(command_line); |
| 310 } | 310 } |
| 311 }; | 311 }; |
| 312 | 312 |
| 313 // Verifies that an ephemeral app will not be installed and launched if the | 313 // Verifies that an ephemeral app will not be installed and launched if the |
| 314 // feature is disabled. | 314 // feature is disabled. |
| 315 IN_PROC_BROWSER_TEST_F(EphemeralAppLauncherTestDisabled, FeatureDisabled) { | 315 IN_PROC_BROWSER_TEST_F(EphemeralAppLauncherTestDisabled, FeatureDisabled) { |
| 316 RunLaunchTest( | 316 RunLaunchTest( |
| 317 kDefaultAppCrxFilename, webstore_install::LAUNCH_FEATURE_DISABLED, false); | 317 kDefaultAppCrxFilename, webstore_install::LAUNCH_FEATURE_DISABLED, false); |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 } | 560 } |
| 561 | 561 |
| 562 // Verifies that a launch will fail if a duplicate launch is in progress. | 562 // Verifies that a launch will fail if a duplicate launch is in progress. |
| 563 IN_PROC_BROWSER_TEST_F(EphemeralAppLauncherTest, DuplicateLaunchInProgress) { | 563 IN_PROC_BROWSER_TEST_F(EphemeralAppLauncherTest, DuplicateLaunchInProgress) { |
| 564 extensions::ActiveInstallData install_data(kDefaultAppId); | 564 extensions::ActiveInstallData install_data(kDefaultAppId); |
| 565 install_data.is_ephemeral = true; | 565 install_data.is_ephemeral = true; |
| 566 InstallTracker::Get(profile())->AddActiveInstall(install_data); | 566 InstallTracker::Get(profile())->AddActiveInstall(install_data); |
| 567 | 567 |
| 568 RunLaunchTest(kDefaultAppId, webstore_install::LAUNCH_IN_PROGRESS, false); | 568 RunLaunchTest(kDefaultAppId, webstore_install::LAUNCH_IN_PROGRESS, false); |
| 569 } | 569 } |
| OLD | NEW |