[email protected] | 3538533 | 2012-03-28 02:32:03 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | a01e0063 | 2010-11-05 16:58:14 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
mtomasz | f7d99a5c | 2014-09-15 16:23:46 | [diff] [blame] | 5 | #include "chrome/browser/extensions/crx_installer.h" |
| 6 | |
[email protected] | 5a145e8 | 2014-05-29 22:19:07 | [diff] [blame] | 7 | #include "base/at_exit.h" |
kalman | ae342c9 | 2014-12-12 22:04:23 | [diff] [blame] | 8 | #include "base/files/file_path.h" |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 9 | #include "base/memory/ref_counted.h" |
[email protected] | 253fc2bb | 2014-07-10 04:21:18 | [diff] [blame] | 10 | #include "base/strings/utf_string_conversions.h" |
[email protected] | bf2fcd5 | 2012-04-16 22:59:39 | [diff] [blame] | 11 | #include "chrome/browser/download/download_crx_util.h" |
[email protected] | 52b7659 | 2013-11-02 17:59:03 | [diff] [blame] | 12 | #include "chrome/browser/extensions/browser_action_test_util.h" |
[email protected] | a01e0063 | 2010-11-05 16:58:14 | [diff] [blame] | 13 | #include "chrome/browser/extensions/extension_browsertest.h" |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 14 | #include "chrome/browser/extensions/extension_install_prompt.h" |
pkotwicz | 2f18178 | 2014-10-29 17:33:45 | [diff] [blame] | 15 | #include "chrome/browser/extensions/extension_install_prompt_show_params.h" |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 16 | #include "chrome/browser/extensions/extension_service.h" |
mek | c95f9d06 | 2015-01-10 00:52:04 | [diff] [blame] | 17 | #include "chrome/browser/extensions/extension_tab_util.h" |
[email protected] | 658eae5 | 2014-06-14 20:28:05 | [diff] [blame] | 18 | #include "chrome/browser/extensions/extension_util.h" |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 19 | #include "chrome/browser/extensions/fake_safe_browsing_database_manager.h" |
gpdavis.chromium | 48f08c4 | 2014-09-18 22:09:34 | [diff] [blame] | 20 | #include "chrome/browser/extensions/test_extension_dir.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 21 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 2ad4a90 | 2010-11-17 06:05:13 | [diff] [blame] | 22 | #include "chrome/browser/ui/browser.h" |
[email protected] | 619f8618 | 2012-07-03 21:30:18 | [diff] [blame] | 23 | #include "chrome/browser/ui/browser_window.h" |
[email protected] | 91e51d61 | 2012-10-21 23:03:05 | [diff] [blame] | 24 | #include "chrome/browser/ui/tabs/tab_strip_model.h" |
[email protected] | af39f00 | 2014-08-22 10:18:18 | [diff] [blame] | 25 | #include "chrome/grit/generated_resources.h" |
[email protected] | af44e7fb | 2011-07-29 18:32:32 | [diff] [blame] | 26 | #include "chrome/test/base/ui_test_utils.h" |
[email protected] | 5a145e8 | 2014-05-29 22:19:07 | [diff] [blame] | 27 | #include "content/public/browser/browser_thread.h" |
[email protected] | f34efa2 | 2013-03-05 19:14:23 | [diff] [blame] | 28 | #include "content/public/browser/download_manager.h" |
[email protected] | 52b7659 | 2013-11-02 17:59:03 | [diff] [blame] | 29 | #include "content/public/browser/render_view_host.h" |
[email protected] | 8ffad4e | 2014-01-02 23:18:26 | [diff] [blame] | 30 | #include "content/public/test/browser_test_utils.h" |
[email protected] | 49b264f | 2012-08-14 17:12:26 | [diff] [blame] | 31 | #include "content/public/test/download_test_observer.h" |
mtomasz | f7d99a5c | 2014-09-15 16:23:46 | [diff] [blame] | 32 | #include "content/public/test/test_utils.h" |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 33 | #include "extensions/browser/extension_prefs.h" |
gpdavis.chromium | 48f08c4 | 2014-09-18 22:09:34 | [diff] [blame] | 34 | #include "extensions/browser/extension_registry.h" |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 35 | #include "extensions/browser/extension_system.h" |
ginkage | 47e603e | 2015-02-27 08:42:41 | [diff] [blame] | 36 | #include "extensions/browser/install/crx_install_error.h" |
[email protected] | 253fc2bb | 2014-07-10 04:21:18 | [diff] [blame] | 37 | #include "extensions/browser/management_policy.h" |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 38 | #include "extensions/browser/notification_types.h" |
[email protected] | e4452d3 | 2013-11-15 23:07:41 | [diff] [blame] | 39 | #include "extensions/common/extension.h" |
[email protected] | 5ef835a | 2013-11-08 20:42:57 | [diff] [blame] | 40 | #include "extensions/common/feature_switch.h" |
[email protected] | 85df9d1 | 2014-04-15 17:02:14 | [diff] [blame] | 41 | #include "extensions/common/file_util.h" |
kalman | ae342c9 | 2014-12-12 22:04:23 | [diff] [blame] | 42 | #include "extensions/common/permissions/api_permission.h" |
[email protected] | 5a55f3f | 2013-10-29 01:08:29 | [diff] [blame] | 43 | #include "extensions/common/permissions/permission_set.h" |
kalman | ae342c9 | 2014-12-12 22:04:23 | [diff] [blame] | 44 | #include "extensions/common/permissions/permissions_data.h" |
[email protected] | c8d0299 | 2013-07-31 22:16:51 | [diff] [blame] | 45 | #include "extensions/common/switches.h" |
[email protected] | a973689 | 2012-05-30 15:58:05 | [diff] [blame] | 46 | #include "ui/base/l10n/l10n_util.h" |
[email protected] | a01e0063 | 2010-11-05 16:58:14 | [diff] [blame] | 47 | |
[email protected] | 14a18bf | 2013-09-26 08:42:30 | [diff] [blame] | 48 | #if defined(OS_CHROMEOS) |
merkulova | 793f302 | 2015-02-04 10:18:30 | [diff] [blame] | 49 | #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 50 | #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
[email protected] | 5a145e8 | 2014-05-29 22:19:07 | [diff] [blame] | 51 | #include "chrome/browser/extensions/extension_assets_manager_chromeos.h" |
| 52 | #include "chromeos/chromeos_switches.h" |
[email protected] | 14a18bf | 2013-09-26 08:42:30 | [diff] [blame] | 53 | #endif |
| 54 | |
[email protected] | 7a5452f | 2010-12-13 23:03:19 | [diff] [blame] | 55 | class SkBitmap; |
| 56 | |
[email protected] | bf3d9df | 2012-07-24 23:20:27 | [diff] [blame] | 57 | namespace extensions { |
[email protected] | b70a2d9 | 2012-06-28 19:51:21 | [diff] [blame] | 58 | |
[email protected] | a01e0063 | 2010-11-05 16:58:14 | [diff] [blame] | 59 | namespace { |
| 60 | |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 61 | class MockInstallPrompt; |
| 62 | |
| 63 | // This class holds information about things that happen with a |
| 64 | // MockInstallPrompt. We create the MockInstallPrompt but need to pass |
| 65 | // ownership of it to CrxInstaller, so it isn't safe to hang this data on |
| 66 | // MockInstallPrompt itself becuase we can't guarantee it's lifetime. |
[email protected] | 658eae5 | 2014-06-14 20:28:05 | [diff] [blame] | 67 | class MockPromptProxy : public base::RefCountedThreadSafe<MockPromptProxy> { |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 68 | public: |
| 69 | explicit MockPromptProxy(content::WebContents* web_contents); |
| 70 | |
| 71 | bool did_succeed() const { return !extension_id_.empty(); } |
| 72 | const std::string& extension_id() { return extension_id_; } |
| 73 | bool confirmation_requested() const { return confirmation_requested_; } |
[email protected] | 439f1e3 | 2013-12-09 20:09:09 | [diff] [blame] | 74 | const base::string16& error() const { return error_; } |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 75 | |
| 76 | // To have any effect, this should be called before CreatePrompt. |
| 77 | void set_record_oauth2_grant(bool record_oauth2_grant) { |
| 78 | record_oauth2_grant_.reset(new bool(record_oauth2_grant)); |
| 79 | } |
| 80 | |
| 81 | void set_extension_id(const std::string& id) { extension_id_ = id; } |
| 82 | void set_confirmation_requested() { confirmation_requested_ = true; } |
[email protected] | 439f1e3 | 2013-12-09 20:09:09 | [diff] [blame] | 83 | void set_error(const base::string16& error) { error_ = error; } |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 84 | |
| 85 | scoped_ptr<ExtensionInstallPrompt> CreatePrompt(); |
| 86 | |
| 87 | private: |
| 88 | friend class base::RefCountedThreadSafe<MockPromptProxy>; |
| 89 | virtual ~MockPromptProxy(); |
| 90 | |
| 91 | // Data used to create a prompt. |
| 92 | content::WebContents* web_contents_; |
| 93 | scoped_ptr<bool> record_oauth2_grant_; |
| 94 | |
| 95 | // Data reported back to us by the prompt we created. |
| 96 | bool confirmation_requested_; |
| 97 | std::string extension_id_; |
[email protected] | 439f1e3 | 2013-12-09 20:09:09 | [diff] [blame] | 98 | base::string16 error_; |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 99 | }; |
[email protected] | bf2fcd5 | 2012-04-16 22:59:39 | [diff] [blame] | 100 | |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 101 | class MockInstallPrompt : public ExtensionInstallPrompt { |
[email protected] | a01e0063 | 2010-11-05 16:58:14 | [diff] [blame] | 102 | public: |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 103 | MockInstallPrompt(content::WebContents* web_contents, |
| 104 | MockPromptProxy* proxy) : |
[email protected] | 91e51d61 | 2012-10-21 23:03:05 | [diff] [blame] | 105 | ExtensionInstallPrompt(web_contents), |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 106 | proxy_(proxy) {} |
[email protected] | a01e0063 | 2010-11-05 16:58:14 | [diff] [blame] | 107 | |
[email protected] | b70a2d9 | 2012-06-28 19:51:21 | [diff] [blame] | 108 | void set_record_oauth2_grant(bool record) { record_oauth2_grant_ = record; } |
[email protected] | a01e0063 | 2010-11-05 16:58:14 | [diff] [blame] | 109 | |
| 110 | // Overriding some of the ExtensionInstallUI API. |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 111 | void ConfirmInstall(Delegate* delegate, |
| 112 | const Extension* extension, |
| 113 | const ShowDialogCallback& show_dialog_callback) override { |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 114 | proxy_->set_confirmation_requested(); |
[email protected] | a01e0063 | 2010-11-05 16:58:14 | [diff] [blame] | 115 | delegate->InstallUIProceed(); |
| 116 | } |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 117 | void OnInstallSuccess(const Extension* extension, SkBitmap* icon) override { |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 118 | proxy_->set_extension_id(extension->id()); |
ki.stfu | c4f8e24 | 2015-10-09 20:40:20 | [diff] [blame] | 119 | base::MessageLoopForUI::current()->QuitWhenIdle(); |
[email protected] | a01e0063 | 2010-11-05 16:58:14 | [diff] [blame] | 120 | } |
ginkage | 47e603e | 2015-02-27 08:42:41 | [diff] [blame] | 121 | void OnInstallFailure(const CrxInstallError& error) override { |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 122 | proxy_->set_error(error.message()); |
ki.stfu | c4f8e24 | 2015-10-09 20:40:20 | [diff] [blame] | 123 | base::MessageLoopForUI::current()->QuitWhenIdle(); |
[email protected] | a01e0063 | 2010-11-05 16:58:14 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | private: |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 127 | scoped_refptr<MockPromptProxy> proxy_; |
[email protected] | a01e0063 | 2010-11-05 16:58:14 | [diff] [blame] | 128 | }; |
| 129 | |
[email protected] | 658eae5 | 2014-06-14 20:28:05 | [diff] [blame] | 130 | MockPromptProxy::MockPromptProxy(content::WebContents* web_contents) |
| 131 | : web_contents_(web_contents), confirmation_requested_(false) { |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | MockPromptProxy::~MockPromptProxy() {} |
| 135 | |
| 136 | scoped_ptr<ExtensionInstallPrompt> MockPromptProxy::CreatePrompt() { |
| 137 | scoped_ptr<MockInstallPrompt> prompt( |
| 138 | new MockInstallPrompt(web_contents_, this)); |
| 139 | if (record_oauth2_grant_.get()) |
| 140 | prompt->set_record_oauth2_grant(*record_oauth2_grant_.get()); |
dcheng | cf850d36 | 2014-10-16 17:26:42 | [diff] [blame] | 141 | return prompt.Pass(); |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | |
| 145 | scoped_refptr<MockPromptProxy> CreateMockPromptProxyForBrowser( |
| 146 | Browser* browser) { |
| 147 | return new MockPromptProxy( |
[email protected] | 91e51d61 | 2012-10-21 23:03:05 | [diff] [blame] | 148 | browser->tab_strip_model()->GetActiveWebContents()); |
[email protected] | 619f8618 | 2012-07-03 21:30:18 | [diff] [blame] | 149 | } |
| 150 | |
[email protected] | 253fc2bb | 2014-07-10 04:21:18 | [diff] [blame] | 151 | class ManagementPolicyMock : public extensions::ManagementPolicy::Provider { |
| 152 | public: |
| 153 | ManagementPolicyMock() {} |
| 154 | |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 155 | std::string GetDebugPolicyProviderName() const override { |
[email protected] | 253fc2bb | 2014-07-10 04:21:18 | [diff] [blame] | 156 | return "ManagementPolicyMock"; |
| 157 | } |
| 158 | |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 159 | bool UserMayLoad(const Extension* extension, |
| 160 | base::string16* error) const override { |
[email protected] | 253fc2bb | 2014-07-10 04:21:18 | [diff] [blame] | 161 | *error = base::UTF8ToUTF16("Dummy error message"); |
| 162 | return false; |
| 163 | } |
| 164 | }; |
| 165 | |
kalman | ae342c9 | 2014-12-12 22:04:23 | [diff] [blame] | 166 | // Appends "enable-experimental-extension-apis" to the command line for the |
| 167 | // lifetime of this class. |
| 168 | class ScopedExperimentalCommandLine { |
| 169 | public: |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 170 | ScopedExperimentalCommandLine() |
| 171 | : saved_(*base::CommandLine::ForCurrentProcess()) { |
| 172 | base::CommandLine::ForCurrentProcess()->AppendSwitch( |
kalman | ae342c9 | 2014-12-12 22:04:23 | [diff] [blame] | 173 | switches::kEnableExperimentalExtensionApis); |
| 174 | } |
| 175 | |
| 176 | ~ScopedExperimentalCommandLine() { |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 177 | *base::CommandLine::ForCurrentProcess() = saved_; |
kalman | ae342c9 | 2014-12-12 22:04:23 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | private: |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 181 | base::CommandLine saved_; |
kalman | ae342c9 | 2014-12-12 22:04:23 | [diff] [blame] | 182 | }; |
| 183 | |
[email protected] | a01e0063 | 2010-11-05 16:58:14 | [diff] [blame] | 184 | } // namespace |
| 185 | |
| 186 | class ExtensionCrxInstallerTest : public ExtensionBrowserTest { |
kalman | ae342c9 | 2014-12-12 22:04:23 | [diff] [blame] | 187 | protected: |
[email protected] | 8529082 | 2013-08-23 20:27:38 | [diff] [blame] | 188 | scoped_ptr<WebstoreInstaller::Approval> GetApproval( |
| 189 | const char* manifest_dir, |
[email protected] | b70a2d9 | 2012-06-28 19:51:21 | [diff] [blame] | 190 | const std::string& id, |
[email protected] | 8529082 | 2013-08-23 20:27:38 | [diff] [blame] | 191 | bool strict_manifest_checks) { |
| 192 | scoped_ptr<WebstoreInstaller::Approval> result; |
| 193 | |
| 194 | base::FilePath ext_path = test_data_dir_.AppendASCII(manifest_dir); |
| 195 | std::string error; |
| 196 | scoped_ptr<base::DictionaryValue> parsed_manifest( |
[email protected] | 85df9d1 | 2014-04-15 17:02:14 | [diff] [blame] | 197 | file_util::LoadManifest(ext_path, &error)); |
[email protected] | 8529082 | 2013-08-23 20:27:38 | [diff] [blame] | 198 | if (!parsed_manifest.get() || !error.empty()) |
| 199 | return result.Pass(); |
| 200 | |
| 201 | return WebstoreInstaller::Approval::CreateWithNoInstallPrompt( |
| 202 | browser()->profile(), |
| 203 | id, |
| 204 | parsed_manifest.Pass(), |
| 205 | strict_manifest_checks); |
| 206 | } |
| 207 | |
| 208 | void RunCrxInstaller(const WebstoreInstaller::Approval* approval, |
| 209 | scoped_ptr<ExtensionInstallPrompt> prompt, |
| 210 | const base::FilePath& crx_path) { |
[email protected] | 06bdd2b | 2012-11-30 18:47:13 | [diff] [blame] | 211 | ExtensionService* service = extensions::ExtensionSystem::Get( |
| 212 | browser()->profile())->extension_service(); |
[email protected] | a01e0063 | 2010-11-05 16:58:14 | [diff] [blame] | 213 | scoped_refptr<CrxInstaller> installer( |
[email protected] | 8529082 | 2013-08-23 20:27:38 | [diff] [blame] | 214 | CrxInstaller::Create(service, prompt.Pass(), approval)); |
[email protected] | a01e0063 | 2010-11-05 16:58:14 | [diff] [blame] | 215 | installer->set_allow_silent_install(true); |
[email protected] | b1f04cc | 2010-11-10 22:59:30 | [diff] [blame] | 216 | installer->set_is_gallery_install(true); |
[email protected] | 8529082 | 2013-08-23 20:27:38 | [diff] [blame] | 217 | installer->InstallCrx(crx_path); |
[email protected] | 729eb63 | 2012-07-26 04:45:26 | [diff] [blame] | 218 | content::RunMessageLoop(); |
[email protected] | 8529082 | 2013-08-23 20:27:38 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | // Installs a crx from |crx_relpath| (a path relative to the extension test |
| 222 | // data dir) with expected id |id|. |
| 223 | void InstallWithPrompt(const char* ext_relpath, |
| 224 | const std::string& id, |
| 225 | scoped_refptr<MockPromptProxy> mock_install_prompt) { |
| 226 | base::FilePath ext_path = test_data_dir_.AppendASCII(ext_relpath); |
| 227 | |
| 228 | scoped_ptr<WebstoreInstaller::Approval> approval; |
| 229 | if (!id.empty()) |
| 230 | approval = GetApproval(ext_relpath, id, true); |
| 231 | |
| 232 | base::FilePath crx_path = PackExtension(ext_path); |
| 233 | EXPECT_FALSE(crx_path.empty()); |
| 234 | RunCrxInstaller(approval.get(), mock_install_prompt->CreatePrompt(), |
| 235 | crx_path); |
[email protected] | a01e0063 | 2010-11-05 16:58:14 | [diff] [blame] | 236 | |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 237 | EXPECT_TRUE(mock_install_prompt->did_succeed()); |
[email protected] | b70a2d9 | 2012-06-28 19:51:21 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | // Installs an extension and checks that it has scopes granted IFF |
| 241 | // |record_oauth2_grant| is true. |
| 242 | void CheckHasEmptyScopesAfterInstall(const std::string& ext_relpath, |
| 243 | bool record_oauth2_grant) { |
kalman | ae342c9 | 2014-12-12 22:04:23 | [diff] [blame] | 244 | ScopedExperimentalCommandLine scope; |
[email protected] | b70a2d9 | 2012-06-28 19:51:21 | [diff] [blame] | 245 | |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 246 | scoped_refptr<MockPromptProxy> mock_prompt = |
| 247 | CreateMockPromptProxyForBrowser(browser()); |
| 248 | |
[email protected] | b70a2d9 | 2012-06-28 19:51:21 | [diff] [blame] | 249 | mock_prompt->set_record_oauth2_grant(record_oauth2_grant); |
[email protected] | 8529082 | 2013-08-23 20:27:38 | [diff] [blame] | 250 | InstallWithPrompt("browsertest/scopes", std::string(), mock_prompt); |
[email protected] | b70a2d9 | 2012-06-28 19:51:21 | [diff] [blame] | 251 | |
rdevlin.cronin | e2d0fd0 | 2015-09-24 22:35:49 | [diff] [blame] | 252 | scoped_ptr<const PermissionSet> permissions = |
[email protected] | 7c82539c | 2014-02-19 06:09:17 | [diff] [blame] | 253 | ExtensionPrefs::Get(browser()->profile()) |
| 254 | ->GetGrantedPermissions(mock_prompt->extension_id()); |
[email protected] | b70a2d9 | 2012-06-28 19:51:21 | [diff] [blame] | 255 | ASSERT_TRUE(permissions.get()); |
[email protected] | a01e0063 | 2010-11-05 16:58:14 | [diff] [blame] | 256 | } |
kalman | ae342c9 | 2014-12-12 22:04:23 | [diff] [blame] | 257 | |
| 258 | // Returns a FilePath to an unpacked "experimental" extension (a test |
| 259 | // Extension which requests the "experimental" permission). |
| 260 | base::FilePath PackExperimentalExtension() { |
| 261 | // We must modify the command line temporarily in order to pack an |
| 262 | // extension that requests the experimental permission. |
| 263 | ScopedExperimentalCommandLine scope; |
| 264 | base::FilePath test_path = test_data_dir_.AppendASCII("experimental"); |
| 265 | base::FilePath crx_path = PackExtension(test_path); |
| 266 | CHECK(!crx_path.empty()) << "Extension not found at " << test_path.value(); |
| 267 | return crx_path; |
| 268 | } |
[email protected] | a01e0063 | 2010-11-05 16:58:14 | [diff] [blame] | 269 | }; |
| 270 | |
[email protected] | d4b4d7af | 2014-08-20 10:45:15 | [diff] [blame] | 271 | // This test is skipped on ChromeOS because it requires the NPAPI, |
| 272 | // which is not available on that platform. |
| 273 | #if !defined(OS_CHROMEOS) |
| 274 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, Whitelisting) { |
[email protected] | 21a5ad6 | 2012-04-03 04:48:45 | [diff] [blame] | 275 | std::string id = "hdgllgikmikobbofgnabhfimcfoopgnd"; |
gpdavis.chromium | 48f08c4 | 2014-09-18 22:09:34 | [diff] [blame] | 276 | ExtensionRegistry* registry = ExtensionRegistry::Get( |
| 277 | browser()->profile()); |
[email protected] | 21a5ad6 | 2012-04-03 04:48:45 | [diff] [blame] | 278 | |
| 279 | // Even whitelisted extensions with NPAPI should not prompt. |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 280 | scoped_refptr<MockPromptProxy> mock_prompt = |
| 281 | CreateMockPromptProxyForBrowser(browser()); |
[email protected] | 8529082 | 2013-08-23 20:27:38 | [diff] [blame] | 282 | InstallWithPrompt("uitest/plugins", id, mock_prompt); |
[email protected] | b70a2d9 | 2012-06-28 19:51:21 | [diff] [blame] | 283 | EXPECT_FALSE(mock_prompt->confirmation_requested()); |
gpdavis.chromium | 48f08c4 | 2014-09-18 22:09:34 | [diff] [blame] | 284 | EXPECT_TRUE(registry->enabled_extensions().GetByID(id)); |
[email protected] | a01e0063 | 2010-11-05 16:58:14 | [diff] [blame] | 285 | } |
[email protected] | d4b4d7af | 2014-08-20 10:45:15 | [diff] [blame] | 286 | #endif |
[email protected] | fc38935a | 2011-10-31 23:53:28 | [diff] [blame] | 287 | |
| 288 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, |
kalman | ae342c9 | 2014-12-12 22:04:23 | [diff] [blame] | 289 | ExperimentalExtensionFromGallery) { |
| 290 | // Gallery-installed extensions should have their experimental permission |
| 291 | // preserved, since we allow the Webstore to make that decision. |
| 292 | base::FilePath crx_path = PackExperimentalExtension(); |
| 293 | const Extension* extension = InstallExtensionFromWebstore(crx_path, 1); |
| 294 | ASSERT_TRUE(extension); |
| 295 | EXPECT_TRUE(extension->permissions_data()->HasAPIPermission( |
| 296 | APIPermission::kExperimental)); |
| 297 | } |
[email protected] | 240cc92a | 2011-12-01 01:22:24 | [diff] [blame] | 298 | |
kalman | ae342c9 | 2014-12-12 22:04:23 | [diff] [blame] | 299 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, |
| 300 | ExperimentalExtensionFromOutsideGallery) { |
| 301 | // Non-gallery-installed extensions should lose their experimental |
| 302 | // permission if the flag isn't enabled. |
| 303 | base::FilePath crx_path = PackExperimentalExtension(); |
| 304 | const Extension* extension = InstallExtension(crx_path, 1); |
| 305 | ASSERT_TRUE(extension); |
| 306 | EXPECT_FALSE(extension->permissions_data()->HasAPIPermission( |
| 307 | APIPermission::kExperimental)); |
| 308 | } |
[email protected] | 240cc92a | 2011-12-01 01:22:24 | [diff] [blame] | 309 | |
kalman | ae342c9 | 2014-12-12 22:04:23 | [diff] [blame] | 310 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, |
| 311 | ExperimentalExtensionFromOutsideGalleryWithFlag) { |
| 312 | // Non-gallery-installed extensions should maintain their experimental |
| 313 | // permission if the flag is enabled. |
| 314 | base::FilePath crx_path = PackExperimentalExtension(); |
| 315 | ScopedExperimentalCommandLine scope; |
| 316 | const Extension* extension = InstallExtension(crx_path, 1); |
| 317 | ASSERT_TRUE(extension); |
| 318 | EXPECT_TRUE(extension->permissions_data()->HasAPIPermission( |
| 319 | APIPermission::kExperimental)); |
[email protected] | fc38935a | 2011-10-31 23:53:28 | [diff] [blame] | 320 | } |
[email protected] | ee14cad | 2012-03-29 01:59:37 | [diff] [blame] | 321 | |
| 322 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, PlatformAppCrx) { |
kalman | ae342c9 | 2014-12-12 22:04:23 | [diff] [blame] | 323 | ScopedExperimentalCommandLine scope; |
[email protected] | ee14cad | 2012-03-29 01:59:37 | [diff] [blame] | 324 | EXPECT_TRUE(InstallExtension( |
[email protected] | dc37b00 | 2012-04-23 23:02:26 | [diff] [blame] | 325 | test_data_dir_.AppendASCII("minimal_platform_app.crx"), 1)); |
[email protected] | ee14cad | 2012-03-29 01:59:37 | [diff] [blame] | 326 | } |
[email protected] | bf2fcd5 | 2012-04-16 22:59:39 | [diff] [blame] | 327 | |
[email protected] | d4b4d7af | 2014-08-20 10:45:15 | [diff] [blame] | 328 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, PackAndInstallExtension) { |
[email protected] | 544471a | 2012-10-13 05:27:09 | [diff] [blame] | 329 | if (!FeatureSwitch::easy_off_store_install()->IsEnabled()) |
[email protected] | 89019d6 | 2012-05-17 18:47:09 | [diff] [blame] | 330 | return; |
| 331 | |
[email protected] | bf2fcd5 | 2012-04-16 22:59:39 | [diff] [blame] | 332 | const int kNumDownloadsExpected = 1; |
[email protected] | bf2fcd5 | 2012-04-16 22:59:39 | [diff] [blame] | 333 | |
| 334 | LOG(ERROR) << "PackAndInstallExtension: Packing extension"; |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 335 | base::FilePath crx_path = PackExtension( |
[email protected] | bf2fcd5 | 2012-04-16 22:59:39 | [diff] [blame] | 336 | test_data_dir_.AppendASCII("common/background_page")); |
| 337 | ASSERT_FALSE(crx_path.empty()); |
| 338 | std::string crx_path_string(crx_path.value().begin(), crx_path.value().end()); |
| 339 | GURL url = GURL(std::string("file:///").append(crx_path_string)); |
| 340 | |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 341 | scoped_refptr<MockPromptProxy> mock_prompt = |
| 342 | CreateMockPromptProxyForBrowser(browser()); |
| 343 | download_crx_util::SetMockInstallPromptForTesting( |
| 344 | mock_prompt->CreatePrompt()); |
[email protected] | bf2fcd5 | 2012-04-16 22:59:39 | [diff] [blame] | 345 | |
| 346 | LOG(ERROR) << "PackAndInstallExtension: Getting download manager"; |
| 347 | content::DownloadManager* download_manager = |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 348 | content::BrowserContext::GetDownloadManager(browser()->profile()); |
[email protected] | bf2fcd5 | 2012-04-16 22:59:39 | [diff] [blame] | 349 | |
| 350 | LOG(ERROR) << "PackAndInstallExtension: Setting observer"; |
[email protected] | 49b264f | 2012-08-14 17:12:26 | [diff] [blame] | 351 | scoped_ptr<content::DownloadTestObserver> observer( |
| 352 | new content::DownloadTestObserverTerminal( |
[email protected] | 4766544 | 2012-07-27 02:31:22 | [diff] [blame] | 353 | download_manager, kNumDownloadsExpected, |
[email protected] | 49b264f | 2012-08-14 17:12:26 | [diff] [blame] | 354 | content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
[email protected] | bf2fcd5 | 2012-04-16 22:59:39 | [diff] [blame] | 355 | LOG(ERROR) << "PackAndInstallExtension: Navigating to URL"; |
| 356 | ui_test_utils::NavigateToURLWithDisposition(browser(), url, CURRENT_TAB, |
| 357 | ui_test_utils::BROWSER_TEST_NONE); |
| 358 | |
[email protected] | 8c6af5b | 2012-06-15 20:10:26 | [diff] [blame] | 359 | EXPECT_TRUE(WaitForCrxInstallerDone()); |
[email protected] | bf2fcd5 | 2012-04-16 22:59:39 | [diff] [blame] | 360 | LOG(ERROR) << "PackAndInstallExtension: Extension install"; |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 361 | EXPECT_TRUE(mock_prompt->confirmation_requested()); |
[email protected] | bf2fcd5 | 2012-04-16 22:59:39 | [diff] [blame] | 362 | LOG(ERROR) << "PackAndInstallExtension: Extension install confirmed"; |
| 363 | } |
[email protected] | a973689 | 2012-05-30 15:58:05 | [diff] [blame] | 364 | |
[email protected] | b70a2d9 | 2012-06-28 19:51:21 | [diff] [blame] | 365 | // Tests that scopes are only granted if |record_oauth2_grant_| on the prompt is |
| 366 | // true. |
[email protected] | 7a56191 | 2012-08-21 21:06:05 | [diff] [blame] | 367 | #if defined(OS_WIN) |
[email protected] | 1e09ec8 | 2012-12-21 22:48:09 | [diff] [blame] | 368 | #define MAYBE_GrantScopes DISABLED_GrantScopes |
[email protected] | 7a56191 | 2012-08-21 21:06:05 | [diff] [blame] | 369 | #else |
| 370 | #define MAYBE_GrantScopes GrantScopes |
| 371 | #endif |
| 372 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, MAYBE_GrantScopes) { |
[email protected] | b70a2d9 | 2012-06-28 19:51:21 | [diff] [blame] | 373 | EXPECT_NO_FATAL_FAILURE(CheckHasEmptyScopesAfterInstall("browsertest/scopes", |
| 374 | true)); |
| 375 | } |
| 376 | |
| 377 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, DoNotGrantScopes) { |
| 378 | EXPECT_NO_FATAL_FAILURE(CheckHasEmptyScopesAfterInstall("browsertest/scopes", |
| 379 | false)); |
| 380 | } |
| 381 | |
[email protected] | d4b4d7af | 2014-08-20 10:45:15 | [diff] [blame] | 382 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, AllowOffStore) { |
[email protected] | 06bdd2b | 2012-11-30 18:47:13 | [diff] [blame] | 383 | ExtensionService* service = extensions::ExtensionSystem::Get( |
| 384 | browser()->profile())->extension_service(); |
[email protected] | a973689 | 2012-05-30 15:58:05 | [diff] [blame] | 385 | const bool kTestData[] = {false, true}; |
| 386 | |
| 387 | for (size_t i = 0; i < arraysize(kTestData); ++i) { |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 388 | scoped_refptr<MockPromptProxy> mock_prompt = |
| 389 | CreateMockPromptProxyForBrowser(browser()); |
| 390 | |
[email protected] | a973689 | 2012-05-30 15:58:05 | [diff] [blame] | 391 | scoped_refptr<CrxInstaller> crx_installer( |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 392 | CrxInstaller::Create(service, mock_prompt->CreatePrompt())); |
[email protected] | 7224dbd | 2012-06-05 15:21:50 | [diff] [blame] | 393 | crx_installer->set_install_cause( |
| 394 | extension_misc::INSTALL_CAUSE_USER_DOWNLOAD); |
[email protected] | d903981 | 2012-06-09 06:05:48 | [diff] [blame] | 395 | |
| 396 | if (kTestData[i]) { |
| 397 | crx_installer->set_off_store_install_allow_reason( |
| 398 | CrxInstaller::OffStoreInstallAllowedInTest); |
| 399 | } |
[email protected] | a973689 | 2012-05-30 15:58:05 | [diff] [blame] | 400 | |
| 401 | crx_installer->InstallCrx(test_data_dir_.AppendASCII("good.crx")); |
[email protected] | d4b4d7af | 2014-08-20 10:45:15 | [diff] [blame] | 402 | // The |mock_prompt| will quit running the loop once the |crx_installer| |
| 403 | // is done. |
| 404 | content::RunMessageLoop(); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 405 | EXPECT_EQ(kTestData[i], mock_prompt->did_succeed()); |
| 406 | EXPECT_EQ(kTestData[i], mock_prompt->confirmation_requested()) << |
| 407 | kTestData[i]; |
[email protected] | a973689 | 2012-05-30 15:58:05 | [diff] [blame] | 408 | if (kTestData[i]) { |
[email protected] | b959d7d4 | 2013-12-13 17:26:37 | [diff] [blame] | 409 | EXPECT_EQ(base::string16(), mock_prompt->error()) << kTestData[i]; |
[email protected] | a973689 | 2012-05-30 15:58:05 | [diff] [blame] | 410 | } else { |
| 411 | EXPECT_EQ(l10n_util::GetStringUTF16( |
| 412 | IDS_EXTENSION_INSTALL_DISALLOWED_ON_SITE), |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 413 | mock_prompt->error()) << kTestData[i]; |
[email protected] | a973689 | 2012-05-30 15:58:05 | [diff] [blame] | 414 | } |
| 415 | } |
[email protected] | a973689 | 2012-05-30 15:58:05 | [diff] [blame] | 416 | } |
[email protected] | bf3d9df | 2012-07-24 23:20:27 | [diff] [blame] | 417 | |
[email protected] | 90d3c04 | 2013-06-06 10:10:39 | [diff] [blame] | 418 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, HiDpiThemeTest) { |
| 419 | base::FilePath crx_path = test_data_dir_.AppendASCII("theme_hidpi_crx"); |
| 420 | crx_path = crx_path.AppendASCII("theme_hidpi.crx"); |
| 421 | |
[email protected] | 658eae5 | 2014-06-14 20:28:05 | [diff] [blame] | 422 | ASSERT_TRUE(InstallExtension(crx_path, 1)); |
[email protected] | 90d3c04 | 2013-06-06 10:10:39 | [diff] [blame] | 423 | |
| 424 | const std::string extension_id("gllekhaobjnhgeagipipnkpmmmpchacm"); |
gpdavis.chromium | 48f08c4 | 2014-09-18 22:09:34 | [diff] [blame] | 425 | ExtensionRegistry* registry = ExtensionRegistry::Get( |
| 426 | browser()->profile()); |
[email protected] | 90d3c04 | 2013-06-06 10:10:39 | [diff] [blame] | 427 | const extensions::Extension* extension = |
gpdavis.chromium | 48f08c4 | 2014-09-18 22:09:34 | [diff] [blame] | 428 | registry->enabled_extensions().GetByID(extension_id); |
[email protected] | 90d3c04 | 2013-06-06 10:10:39 | [diff] [blame] | 429 | ASSERT_TRUE(extension); |
| 430 | EXPECT_EQ(extension_id, extension->id()); |
| 431 | |
| 432 | UninstallExtension(extension_id); |
gpdavis.chromium | 48f08c4 | 2014-09-18 22:09:34 | [diff] [blame] | 433 | EXPECT_FALSE(registry->enabled_extensions().GetByID(extension_id)); |
[email protected] | 90d3c04 | 2013-06-06 10:10:39 | [diff] [blame] | 434 | } |
| 435 | |
[email protected] | 9e9c1d1 | 2013-07-31 01:58:12 | [diff] [blame] | 436 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, |
mek | c95f9d06 | 2015-01-10 00:52:04 | [diff] [blame] | 437 | InstallDelayedUntilNextUpdate) { |
[email protected] | 9e9c1d1 | 2013-07-31 01:58:12 | [diff] [blame] | 438 | const std::string extension_id("ldnnhddmnhbkjipkidpdiheffobcpfmf"); |
mek | c95f9d06 | 2015-01-10 00:52:04 | [diff] [blame] | 439 | base::FilePath base_path = test_data_dir_.AppendASCII("delayed_install"); |
| 440 | |
[email protected] | 9e9c1d1 | 2013-07-31 01:58:12 | [diff] [blame] | 441 | ExtensionSystem* extension_system = extensions::ExtensionSystem::Get( |
| 442 | browser()->profile()); |
| 443 | ExtensionService* service = extension_system->extension_service(); |
| 444 | ASSERT_TRUE(service); |
gpdavis.chromium | 48f08c4 | 2014-09-18 22:09:34 | [diff] [blame] | 445 | ExtensionRegistry* registry = ExtensionRegistry::Get( |
| 446 | browser()->profile()); |
| 447 | ASSERT_TRUE(registry); |
[email protected] | 9e9c1d1 | 2013-07-31 01:58:12 | [diff] [blame] | 448 | |
| 449 | // Install version 1 of the test extension. This extension does not have |
| 450 | // a background page but does have a browser action. |
mek | c95f9d06 | 2015-01-10 00:52:04 | [diff] [blame] | 451 | base::FilePath v1_path = PackExtension(base_path.AppendASCII("v1")); |
| 452 | ASSERT_FALSE(v1_path.empty()); |
| 453 | ASSERT_TRUE(InstallExtension(v1_path, 1)); |
[email protected] | 9e9c1d1 | 2013-07-31 01:58:12 | [diff] [blame] | 454 | const extensions::Extension* extension = |
gpdavis.chromium | 48f08c4 | 2014-09-18 22:09:34 | [diff] [blame] | 455 | registry->enabled_extensions().GetByID(extension_id); |
[email protected] | 9e9c1d1 | 2013-07-31 01:58:12 | [diff] [blame] | 456 | ASSERT_TRUE(extension); |
| 457 | ASSERT_EQ(extension_id, extension->id()); |
| 458 | ASSERT_EQ("1.0", extension->version()->GetString()); |
| 459 | |
mek | c95f9d06 | 2015-01-10 00:52:04 | [diff] [blame] | 460 | // Make test extension non-idle by opening the extension's options page. |
| 461 | ExtensionTabUtil::OpenOptionsPage(extension, browser()); |
| 462 | WaitForExtensionNotIdle(extension_id); |
[email protected] | 9e9c1d1 | 2013-07-31 01:58:12 | [diff] [blame] | 463 | |
| 464 | // Install version 2 of the extension and check that it is indeed delayed. |
mek | c95f9d06 | 2015-01-10 00:52:04 | [diff] [blame] | 465 | base::FilePath v2_path = PackExtension(base_path.AppendASCII("v2")); |
| 466 | ASSERT_FALSE(v2_path.empty()); |
| 467 | ASSERT_TRUE(UpdateExtensionWaitForIdle(extension_id, v2_path, 0)); |
[email protected] | 9e9c1d1 | 2013-07-31 01:58:12 | [diff] [blame] | 468 | |
| 469 | ASSERT_EQ(1u, service->delayed_installs()->size()); |
gpdavis.chromium | 48f08c4 | 2014-09-18 22:09:34 | [diff] [blame] | 470 | extension = registry->enabled_extensions().GetByID(extension_id); |
[email protected] | 9e9c1d1 | 2013-07-31 01:58:12 | [diff] [blame] | 471 | ASSERT_EQ("1.0", extension->version()->GetString()); |
| 472 | |
mek | c95f9d06 | 2015-01-10 00:52:04 | [diff] [blame] | 473 | // Make the extension idle again by navigating away from the options page. |
| 474 | // This should not trigger the delayed install. |
| 475 | ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); |
| 476 | WaitForExtensionIdle(extension_id); |
[email protected] | 9e9c1d1 | 2013-07-31 01:58:12 | [diff] [blame] | 477 | ASSERT_EQ(1u, service->delayed_installs()->size()); |
mek | c95f9d06 | 2015-01-10 00:52:04 | [diff] [blame] | 478 | extension = registry->enabled_extensions().GetByID(extension_id); |
| 479 | ASSERT_EQ("1.0", extension->version()->GetString()); |
[email protected] | 9e9c1d1 | 2013-07-31 01:58:12 | [diff] [blame] | 480 | |
| 481 | // Install version 3 of the extension. Because the extension is idle, |
| 482 | // this install should succeed. |
mek | c95f9d06 | 2015-01-10 00:52:04 | [diff] [blame] | 483 | base::FilePath v3_path = PackExtension(base_path.AppendASCII("v3")); |
| 484 | ASSERT_FALSE(v3_path.empty()); |
| 485 | ASSERT_TRUE(UpdateExtensionWaitForIdle(extension_id, v3_path, 0)); |
gpdavis.chromium | 48f08c4 | 2014-09-18 22:09:34 | [diff] [blame] | 486 | extension = registry->enabled_extensions().GetByID(extension_id); |
[email protected] | 9e9c1d1 | 2013-07-31 01:58:12 | [diff] [blame] | 487 | ASSERT_EQ("3.0", extension->version()->GetString()); |
| 488 | |
| 489 | // The version 2 delayed install should be cleaned up, and finishing |
| 490 | // delayed extension installation shouldn't break anything. |
| 491 | ASSERT_EQ(0u, service->delayed_installs()->size()); |
| 492 | service->MaybeFinishDelayedInstallations(); |
gpdavis.chromium | 48f08c4 | 2014-09-18 22:09:34 | [diff] [blame] | 493 | extension = registry->enabled_extensions().GetByID(extension_id); |
[email protected] | 9e9c1d1 | 2013-07-31 01:58:12 | [diff] [blame] | 494 | ASSERT_EQ("3.0", extension->version()->GetString()); |
| 495 | } |
| 496 | |
[email protected] | e3767aa | 2013-11-08 23:49:07 | [diff] [blame] | 497 | #if defined(FULL_SAFE_BROWSING) |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 498 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, Blacklist) { |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 499 | scoped_refptr<FakeSafeBrowsingDatabaseManager> blacklist_db( |
| 500 | new FakeSafeBrowsingDatabaseManager(true)); |
| 501 | Blacklist::ScopedDatabaseManagerForTest scoped_blacklist_db(blacklist_db); |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 502 | |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 503 | blacklist_db->SetUnsafe("gllekhaobjnhgeagipipnkpmmmpchacm"); |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 504 | |
| 505 | base::FilePath crx_path = test_data_dir_.AppendASCII("theme_hidpi_crx") |
| 506 | .AppendASCII("theme_hidpi.crx"); |
| 507 | EXPECT_FALSE(InstallExtension(crx_path, 0)); |
| 508 | } |
[email protected] | e3767aa | 2013-11-08 23:49:07 | [diff] [blame] | 509 | #endif |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 510 | |
[email protected] | 8529082 | 2013-08-23 20:27:38 | [diff] [blame] | 511 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, NonStrictManifestCheck) { |
| 512 | scoped_refptr<MockPromptProxy> mock_prompt = |
| 513 | CreateMockPromptProxyForBrowser(browser()); |
| 514 | |
| 515 | // We want to simulate the case where the webstore sends a more recent |
| 516 | // version of the manifest, but the downloaded .crx file is old since |
| 517 | // the newly published version hasn't fully propagated to all the download |
| 518 | // servers yet. So load the v2 manifest, but then install the v1 crx file. |
| 519 | std::string id = "lhnaeclnpobnlbjbgogdanmhadigfnjp"; |
| 520 | scoped_ptr<WebstoreInstaller::Approval> approval = |
| 521 | GetApproval("crx_installer/v2_no_permission_change/", id, false); |
| 522 | |
| 523 | RunCrxInstaller(approval.get(), mock_prompt->CreatePrompt(), |
| 524 | test_data_dir_.AppendASCII("crx_installer/v1.crx")); |
| 525 | |
| 526 | EXPECT_TRUE(mock_prompt->did_succeed()); |
| 527 | } |
| 528 | |
[email protected] | 14a18bf | 2013-09-26 08:42:30 | [diff] [blame] | 529 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, KioskOnlyTest) { |
| 530 | base::FilePath crx_path = |
| 531 | test_data_dir_.AppendASCII("kiosk/kiosk_only.crx"); |
| 532 | EXPECT_FALSE(InstallExtension(crx_path, 0)); |
| 533 | #if defined(OS_CHROMEOS) |
| 534 | // Simulate ChromeOS kiosk mode. |scoped_user_manager| will take over |
| 535 | // lifetime of |user_manager|. |
merkulova | 793f302 | 2015-02-04 10:18:30 | [diff] [blame] | 536 | chromeos::FakeChromeUserManager* fake_user_manager = |
| 537 | new chromeos::FakeChromeUserManager(); |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame^] | 538 | const AccountId account_id(AccountId::FromUserEmail("[email protected]")); |
| 539 | fake_user_manager->AddKioskAppUser(account_id); |
| 540 | fake_user_manager->LoginUser(account_id); |
[email protected] | 14a18bf | 2013-09-26 08:42:30 | [diff] [blame] | 541 | chromeos::ScopedUserManagerEnabler scoped_user_manager(fake_user_manager); |
| 542 | EXPECT_TRUE(InstallExtension(crx_path, 1)); |
| 543 | #endif |
| 544 | } |
| 545 | |
[email protected] | 5a145e8 | 2014-05-29 22:19:07 | [diff] [blame] | 546 | #if defined(OS_CHROMEOS) |
dpolukhin | cbd48d19 | 2015-06-04 14:09:37 | [diff] [blame] | 547 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, InstallToSharedLocation) { |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 548 | base::CommandLine::ForCurrentProcess()->AppendSwitch( |
[email protected] | 5a145e8 | 2014-05-29 22:19:07 | [diff] [blame] | 549 | chromeos::switches::kEnableExtensionAssetsSharing); |
| 550 | base::ScopedTempDir cache_dir; |
| 551 | ASSERT_TRUE(cache_dir.CreateUniqueTempDir()); |
| 552 | ExtensionAssetsManagerChromeOS::SetSharedInstallDirForTesting( |
| 553 | cache_dir.path()); |
| 554 | |
| 555 | base::FilePath crx_path = test_data_dir_.AppendASCII("crx_installer/v1.crx"); |
| 556 | const extensions::Extension* extension = InstallExtension( |
| 557 | crx_path, 1, extensions::Manifest::EXTERNAL_PREF); |
| 558 | base::FilePath extension_path = extension->path(); |
| 559 | EXPECT_TRUE(cache_dir.path().IsParent(extension_path)); |
| 560 | EXPECT_TRUE(base::PathExists(extension_path)); |
| 561 | |
| 562 | std::string extension_id = extension->id(); |
| 563 | UninstallExtension(extension_id); |
gpdavis.chromium | 48f08c4 | 2014-09-18 22:09:34 | [diff] [blame] | 564 | ExtensionRegistry* registry = ExtensionRegistry::Get( |
| 565 | browser()->profile()); |
| 566 | EXPECT_FALSE(registry->enabled_extensions().GetByID(extension_id)); |
[email protected] | 5a145e8 | 2014-05-29 22:19:07 | [diff] [blame] | 567 | |
mtomasz | f7d99a5c | 2014-09-15 16:23:46 | [diff] [blame] | 568 | content::RunAllBlockingPoolTasksUntilIdle(); |
[email protected] | 5a145e8 | 2014-05-29 22:19:07 | [diff] [blame] | 569 | |
| 570 | EXPECT_FALSE(base::PathExists(extension_path)); |
| 571 | } |
| 572 | #endif |
| 573 | |
[email protected] | 658eae5 | 2014-06-14 20:28:05 | [diff] [blame] | 574 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, DoNotSync) { |
| 575 | ExtensionService* service = extensions::ExtensionSystem::Get( |
| 576 | browser()->profile())->extension_service(); |
| 577 | scoped_refptr<CrxInstaller> crx_installer( |
| 578 | CrxInstaller::CreateSilent(service)); |
[email protected] | c30bda26 | 2014-06-19 04:10:13 | [diff] [blame] | 579 | crx_installer->set_do_not_sync(true); |
[email protected] | 658eae5 | 2014-06-14 20:28:05 | [diff] [blame] | 580 | crx_installer->InstallCrx(test_data_dir_.AppendASCII("good.crx")); |
| 581 | EXPECT_TRUE(WaitForCrxInstallerDone()); |
| 582 | ASSERT_TRUE(crx_installer->extension()); |
| 583 | |
| 584 | const ExtensionPrefs* extension_prefs = |
| 585 | ExtensionPrefs::Get(browser()->profile()); |
| 586 | EXPECT_TRUE(extension_prefs->DoNotSync(crx_installer->extension()->id())); |
treib | c644a1c | 2015-07-13 08:37:04 | [diff] [blame] | 587 | EXPECT_FALSE(extensions::util::ShouldSync(crx_installer->extension(), |
| 588 | browser()->profile())); |
[email protected] | 658eae5 | 2014-06-14 20:28:05 | [diff] [blame] | 589 | } |
| 590 | |
[email protected] | 253fc2bb | 2014-07-10 04:21:18 | [diff] [blame] | 591 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, ManagementPolicy) { |
| 592 | ManagementPolicyMock policy; |
| 593 | extensions::ExtensionSystem::Get(profile()) |
| 594 | ->management_policy() |
| 595 | ->RegisterProvider(&policy); |
| 596 | |
| 597 | base::FilePath crx_path = test_data_dir_.AppendASCII("crx_installer/v1.crx"); |
| 598 | EXPECT_FALSE(InstallExtension(crx_path, 0)); |
| 599 | } |
| 600 | |
[email protected] | bf3d9df | 2012-07-24 23:20:27 | [diff] [blame] | 601 | } // namespace extensions |