blob: f07e364cd7aae775e468c150bc58d4ef7348c89c [file] [log] [blame]
[email protected]35385332012-03-28 02:32:031// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]a01e00632010-11-05 16:58:142// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
mtomaszf7d99a5c2014-09-15 16:23:465#include "chrome/browser/extensions/crx_installer.h"
6
avia2f4804a2015-12-24 23:11:137#include <stddef.h>
dchengc963c7142016-04-08 03:55:228
dcheng1fc00f12015-12-26 22:18:039#include <utility>
avia2f4804a2015-12-24 23:11:1310
[email protected]5a145e82014-05-29 22:19:0711#include "base/at_exit.h"
Sebastien Marchandf1349f52019-01-25 03:16:4112#include "base/bind.h"
kalmanae342c92014-12-12 22:04:2313#include "base/files/file_path.h"
Minh X. Nguyen2c17b3982017-10-13 18:32:2914#include "base/files/scoped_temp_dir.h"
dchengc963c7142016-04-08 03:55:2215#include "base/memory/ptr_util.h"
[email protected]f8636f92013-08-09 21:02:3716#include "base/memory/ref_counted.h"
Sergey Poromovcc362382018-11-09 18:43:3217#include "base/optional.h"
Gabriel Charette53a9ef812017-07-26 12:36:2318#include "base/run_loop.h"
Avi Drissman5f0fb8c2018-12-25 23:20:4919#include "base/stl_util.h"
[email protected]253fc2bb2014-07-10 04:21:1820#include "base/strings/utf_string_conversions.h"
jam3f2d3932017-04-26 20:28:5121#include "base/threading/thread_restrictions.h"
avia2f4804a2015-12-24 23:11:1322#include "build/build_config.h"
[email protected]bf2fcd52012-04-16 22:59:3923#include "chrome/browser/download/download_crx_util.h"
[email protected]a01e00632010-11-05 16:58:1424#include "chrome/browser/extensions/extension_browsertest.h"
[email protected]c82da8c42012-06-08 19:49:1125#include "chrome/browser/extensions/extension_install_prompt.h"
pkotwicz2f181782014-10-29 17:33:4526#include "chrome/browser/extensions/extension_install_prompt_show_params.h"
[email protected]eaa7dd182010-12-14 11:09:0027#include "chrome/browser/extensions/extension_service.h"
mekc95f9d062015-01-10 00:52:0428#include "chrome/browser/extensions/extension_tab_util.h"
[email protected]658eae52014-06-14 20:28:0529#include "chrome/browser/extensions/extension_util.h"
[email protected]3f2a2fa2013-09-24 02:55:2530#include "chrome/browser/extensions/fake_safe_browsing_database_manager.h"
Oleg Davydovc00866812019-04-04 10:47:2731#include "chrome/browser/extensions/forced_extensions/installation_reporter.h"
[email protected]8ecad5e2010-12-02 21:18:3332#include "chrome/browser/profiles/profile.h"
[email protected]2ad4a902010-11-17 06:05:1333#include "chrome/browser/ui/browser.h"
[email protected]619f86182012-07-03 21:30:1834#include "chrome/browser/ui/browser_window.h"
Christopher Lam851605b2018-02-09 05:24:0435#include "chrome/browser/ui/extensions/browser_action_test_util.h"
[email protected]91e51d612012-10-21 23:03:0536#include "chrome/browser/ui/tabs/tab_strip_model.h"
dominickn675536f2015-11-06 03:25:3837#include "chrome/common/web_application_info.h"
[email protected]af39f002014-08-22 10:18:1838#include "chrome/grit/generated_resources.h"
[email protected]af44e7fb2011-07-29 18:32:3239#include "chrome/test/base/ui_test_utils.h"
Nico Weberbc5b06f2019-07-26 14:00:1340#include "components/safe_browsing/buildflags.h"
[email protected]5a145e82014-05-29 22:19:0741#include "content/public/browser/browser_thread.h"
[email protected]f34efa22013-03-05 19:14:2342#include "content/public/browser/download_manager.h"
[email protected]52b76592013-11-02 17:59:0343#include "content/public/browser/render_view_host.h"
[email protected]8ffad4e2014-01-02 23:18:2644#include "content/public/test/browser_test_utils.h"
[email protected]49b264f2012-08-14 17:12:2645#include "content/public/test/download_test_observer.h"
mtomaszf7d99a5c2014-09-15 16:23:4646#include "content/public/test/test_utils.h"
rdevlin.croninca5bf2da2015-12-17 21:21:0847#include "extensions/browser/extension_dialog_auto_confirm.h"
[email protected]dccba4f82014-05-29 00:52:5648#include "extensions/browser/extension_prefs.h"
gpdavis.chromium48f08c42014-09-18 22:09:3449#include "extensions/browser/extension_registry.h"
[email protected]59b0e602014-01-30 00:41:2450#include "extensions/browser/extension_system.h"
ginkage47e603e2015-02-27 08:42:4151#include "extensions/browser/install/crx_install_error.h"
Minh X. Nguyen8803f4e2018-05-25 01:03:1052#include "extensions/browser/install/sandboxed_unpacker_failure_reason.h"
[email protected]253fc2bb2014-07-10 04:21:1853#include "extensions/browser/management_policy.h"
[email protected]adf5a102014-07-31 12:44:0654#include "extensions/browser/notification_types.h"
[email protected]e4452d32013-11-15 23:07:4155#include "extensions/common/extension.h"
Minh X. Nguyen30975342017-12-04 22:02:4156#include "extensions/common/extension_builder.h"
[email protected]5ef835a2013-11-08 20:42:5757#include "extensions/common/feature_switch.h"
[email protected]85df9d12014-04-15 17:02:1458#include "extensions/common/file_util.h"
kalmanae342c92014-12-12 22:04:2359#include "extensions/common/permissions/api_permission.h"
[email protected]5a55f3f2013-10-29 01:08:2960#include "extensions/common/permissions/permission_set.h"
kalmanae342c92014-12-12 22:04:2361#include "extensions/common/permissions/permissions_data.h"
[email protected]c8d02992013-07-31 22:16:5162#include "extensions/common/switches.h"
Devlin Cronin4f455a22018-01-25 01:36:4563#include "extensions/test/test_extension_dir.h"
dominickn675536f2015-11-06 03:25:3864#include "third_party/skia/include/core/SkBitmap.h"
[email protected]a9736892012-05-30 15:58:0565#include "ui/base/l10n/l10n_util.h"
[email protected]a01e00632010-11-05 16:58:1466
[email protected]14a18bf2013-09-26 08:42:3067#if defined(OS_CHROMEOS)
merkulova793f3022015-02-04 10:18:3068#include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h"
[email protected]5a145e82014-05-29 22:19:0769#include "chrome/browser/extensions/extension_assets_manager_chromeos.h"
Steven Bennetts38e9bde22019-01-03 17:31:1070#include "chromeos/constants/chromeos_switches.h"
Xiyuan Xiadfe3a9f2017-11-13 21:46:2671#include "components/user_manager/scoped_user_manager.h"
[email protected]14a18bf2013-09-26 08:42:3072#endif
73
[email protected]7a5452f2010-12-13 23:03:1974class SkBitmap;
75
dominickn675536f2015-11-06 03:25:3876namespace {
77
78const char kAppUrl[] = "http://www.google.com";
79const char kAppTitle[] = "Test title";
80const char kAppDescription[] = "Test description";
81
82} // anonymous namespace
83
[email protected]bf3d9df2012-07-24 23:20:2784namespace extensions {
[email protected]b70a2d92012-06-28 19:51:2185
[email protected]a01e00632010-11-05 16:58:1486namespace {
87
[email protected]f8636f92013-08-09 21:02:3788class MockInstallPrompt;
89
90// This class holds information about things that happen with a
91// MockInstallPrompt. We create the MockInstallPrompt but need to pass
92// ownership of it to CrxInstaller, so it isn't safe to hang this data on
93// MockInstallPrompt itself becuase we can't guarantee it's lifetime.
rdevlin.croninca5bf2da2015-12-17 21:21:0894class MockPromptProxy {
[email protected]f8636f92013-08-09 21:02:3795 public:
96 explicit MockPromptProxy(content::WebContents* web_contents);
rdevlin.croninca5bf2da2015-12-17 21:21:0897 ~MockPromptProxy();
[email protected]f8636f92013-08-09 21:02:3798
99 bool did_succeed() const { return !extension_id_.empty(); }
100 const std::string& extension_id() { return extension_id_; }
101 bool confirmation_requested() const { return confirmation_requested_; }
[email protected]439f1e32013-12-09 20:09:09102 const base::string16& error() const { return error_; }
[email protected]f8636f92013-08-09 21:02:37103
[email protected]f8636f92013-08-09 21:02:37104 void set_extension_id(const std::string& id) { extension_id_ = id; }
rdevlin.croninca5bf2da2015-12-17 21:21:08105 void set_confirmation_requested(bool requested) {
106 confirmation_requested_ = requested;
107 }
[email protected]439f1e32013-12-09 20:09:09108 void set_error(const base::string16& error) { error_ = error; }
[email protected]f8636f92013-08-09 21:02:37109
dchengc963c7142016-04-08 03:55:22110 std::unique_ptr<ExtensionInstallPrompt> CreatePrompt();
[email protected]f8636f92013-08-09 21:02:37111
112 private:
[email protected]f8636f92013-08-09 21:02:37113
114 // Data used to create a prompt.
115 content::WebContents* web_contents_;
[email protected]f8636f92013-08-09 21:02:37116
117 // Data reported back to us by the prompt we created.
118 bool confirmation_requested_;
119 std::string extension_id_;
[email protected]439f1e32013-12-09 20:09:09120 base::string16 error_;
rdevlin.croninca5bf2da2015-12-17 21:21:08121
dchengc963c7142016-04-08 03:55:22122 std::unique_ptr<ScopedTestDialogAutoConfirm> auto_confirm;
rdevlin.croninca5bf2da2015-12-17 21:21:08123
124 DISALLOW_COPY_AND_ASSIGN(MockPromptProxy);
[email protected]f8636f92013-08-09 21:02:37125};
[email protected]bf2fcd52012-04-16 22:59:39126
dominickn675536f2015-11-06 03:25:38127SkBitmap CreateSquareBitmap(int size) {
128 SkBitmap bitmap;
129 bitmap.allocN32Pixels(size, size);
130 bitmap.eraseColor(SK_ColorRED);
131 return bitmap;
132}
133
134WebApplicationInfo::IconInfo CreateIconInfoWithBitmap(int size) {
135 WebApplicationInfo::IconInfo icon_info;
136 icon_info.width = size;
137 icon_info.height = size;
138 icon_info.data = CreateSquareBitmap(size);
139 return icon_info;
140}
141
142WebApplicationInfo CreateWebAppInfo(const char* title,
143 const char* description,
144 const char* app_url,
145 int size) {
146 WebApplicationInfo web_app_info;
147 web_app_info.title = base::UTF8ToUTF16(title);
148 web_app_info.description = base::UTF8ToUTF16(description);
149 web_app_info.app_url = GURL(app_url);
Giovanni Ortuño Urquidie7e79d452017-08-03 10:16:15150 web_app_info.scope = GURL(app_url);
dominickn675536f2015-11-06 03:25:38151
152 web_app_info.icons.push_back(CreateIconInfoWithBitmap(size));
153
154 return web_app_info;
155}
156
[email protected]c82da8c42012-06-08 19:49:11157class MockInstallPrompt : public ExtensionInstallPrompt {
[email protected]a01e00632010-11-05 16:58:14158 public:
[email protected]f8636f92013-08-09 21:02:37159 MockInstallPrompt(content::WebContents* web_contents,
160 MockPromptProxy* proxy) :
[email protected]91e51d612012-10-21 23:03:05161 ExtensionInstallPrompt(web_contents),
[email protected]f8636f92013-08-09 21:02:37162 proxy_(proxy) {}
[email protected]a01e00632010-11-05 16:58:14163
[email protected]a01e00632010-11-05 16:58:14164 // Overriding some of the ExtensionInstallUI API.
Dana Friedc3c30222018-12-11 23:34:56165 void OnInstallSuccess(scoped_refptr<const Extension> extension,
166 SkBitmap* icon) override {
[email protected]f8636f92013-08-09 21:02:37167 proxy_->set_extension_id(extension->id());
rdevlin.croninca5bf2da2015-12-17 21:21:08168 proxy_->set_confirmation_requested(did_call_show_dialog());
[email protected]a01e00632010-11-05 16:58:14169 }
ginkage47e603e2015-02-27 08:42:41170 void OnInstallFailure(const CrxInstallError& error) override {
[email protected]f8636f92013-08-09 21:02:37171 proxy_->set_error(error.message());
rdevlin.croninca5bf2da2015-12-17 21:21:08172 proxy_->set_confirmation_requested(did_call_show_dialog());
[email protected]a01e00632010-11-05 16:58:14173 }
174
175 private:
rdevlin.croninca5bf2da2015-12-17 21:21:08176 MockPromptProxy* proxy_;
177
178 DISALLOW_COPY_AND_ASSIGN(MockInstallPrompt);
[email protected]a01e00632010-11-05 16:58:14179};
180
[email protected]658eae52014-06-14 20:28:05181MockPromptProxy::MockPromptProxy(content::WebContents* web_contents)
rdevlin.croninca5bf2da2015-12-17 21:21:08182 : web_contents_(web_contents),
183 confirmation_requested_(false),
184 auto_confirm(new ScopedTestDialogAutoConfirm(
185 ScopedTestDialogAutoConfirm::ACCEPT)) {
[email protected]f8636f92013-08-09 21:02:37186}
187
188MockPromptProxy::~MockPromptProxy() {}
189
dchengc963c7142016-04-08 03:55:22190std::unique_ptr<ExtensionInstallPrompt> MockPromptProxy::CreatePrompt() {
191 return std::unique_ptr<MockInstallPrompt>(
[email protected]f8636f92013-08-09 21:02:37192 new MockInstallPrompt(web_contents_, this));
[email protected]f8636f92013-08-09 21:02:37193}
194
dchengc963c7142016-04-08 03:55:22195std::unique_ptr<MockPromptProxy> CreateMockPromptProxyForBrowser(
[email protected]f8636f92013-08-09 21:02:37196 Browser* browser) {
Jinho Bangb5216cec2018-01-17 19:43:11197 return std::make_unique<MockPromptProxy>(
ricea91d6fc122016-08-30 08:47:14198 browser->tab_strip_model()->GetActiveWebContents());
[email protected]619f86182012-07-03 21:30:18199}
200
[email protected]253fc2bb2014-07-10 04:21:18201class ManagementPolicyMock : public extensions::ManagementPolicy::Provider {
202 public:
203 ManagementPolicyMock() {}
204
dchengae36a4a2014-10-21 12:36:36205 std::string GetDebugPolicyProviderName() const override {
[email protected]253fc2bb2014-07-10 04:21:18206 return "ManagementPolicyMock";
207 }
208
dchengae36a4a2014-10-21 12:36:36209 bool UserMayLoad(const Extension* extension,
210 base::string16* error) const override {
Karan Bhatia2a117232017-08-23 00:24:56211 if (error)
212 *error = base::UTF8ToUTF16("Dummy error message");
[email protected]253fc2bb2014-07-10 04:21:18213 return false;
214 }
215};
216
[email protected]a01e00632010-11-05 16:58:14217} // namespace
218
219class ExtensionCrxInstallerTest : public ExtensionBrowserTest {
kalmanae342c92014-12-12 22:04:23220 protected:
dchengc963c7142016-04-08 03:55:22221 std::unique_ptr<WebstoreInstaller::Approval> GetApproval(
[email protected]85290822013-08-23 20:27:38222 const char* manifest_dir,
[email protected]b70a2d92012-06-28 19:51:21223 const std::string& id,
[email protected]85290822013-08-23 20:27:38224 bool strict_manifest_checks) {
dchengc963c7142016-04-08 03:55:22225 std::unique_ptr<WebstoreInstaller::Approval> result;
[email protected]85290822013-08-23 20:27:38226
Minh X. Nguyen2c17b3982017-10-13 18:32:29227 base::ScopedAllowBlockingForTesting allow_io;
[email protected]85290822013-08-23 20:27:38228 base::FilePath ext_path = test_data_dir_.AppendASCII(manifest_dir);
229 std::string error;
dchengc963c7142016-04-08 03:55:22230 std::unique_ptr<base::DictionaryValue> parsed_manifest(
[email protected]85df9d12014-04-15 17:02:14231 file_util::LoadManifest(ext_path, &error));
[email protected]85290822013-08-23 20:27:38232 if (!parsed_manifest.get() || !error.empty())
dcheng1fc00f12015-12-26 22:18:03233 return result;
[email protected]85290822013-08-23 20:27:38234
235 return WebstoreInstaller::Approval::CreateWithNoInstallPrompt(
dcheng1fc00f12015-12-26 22:18:03236 browser()->profile(), id, std::move(parsed_manifest),
[email protected]85290822013-08-23 20:27:38237 strict_manifest_checks);
238 }
239
Minh X. Nguyen30975342017-12-04 22:02:41240 ExtensionService* extension_service() {
241 return extensions::ExtensionSystem::Get(browser()->profile())
242 ->extension_service();
243 }
244
245 const Extension* GetInstalledExtension(const std::string& extension_id) {
246 return extension_service()->GetInstalledExtension(extension_id);
247 }
248
249 std::unique_ptr<base::ScopedTempDir> UnpackedCrxTempDir() {
250 auto temp_dir = std::make_unique<base::ScopedTempDir>();
251 EXPECT_TRUE(temp_dir->CreateUniqueTempDir());
252 EXPECT_TRUE(base::PathExists(temp_dir->GetPath()));
253
Devlin Cronin19775cc2018-04-19 15:04:26254 base::FilePath unpacked_path =
255 test_data_dir_.AppendASCII("simple_with_popup");
Minh X. Nguyen30975342017-12-04 22:02:41256 EXPECT_TRUE(base::PathExists(unpacked_path));
257 EXPECT_TRUE(base::CopyDirectory(unpacked_path, temp_dir->GetPath(), false));
258
259 return temp_dir;
260 }
261
262 // Helper function that creates a file at |relative_path| within |directory|
263 // and fills it with |content|.
264 bool AddFileToDirectory(const base::FilePath& directory,
265 const base::FilePath& relative_path,
266 const std::string& content) const {
267 const base::FilePath full_path = directory.Append(relative_path);
268 if (!CreateDirectory(full_path.DirName()))
269 return false;
270 const int result =
271 base::WriteFile(full_path, content.data(), content.size());
272 return (static_cast<size_t>(result) == content.size());
273 }
274
275 void AddExtension(const std::string& extension_id,
276 const std::string& version) {
277 base::ScopedTempDir temp_dir;
278 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
279 ASSERT_TRUE(base::PathExists(temp_dir.GetPath()));
280
281 base::FilePath foo_js(FILE_PATH_LITERAL("foo.js"));
282 base::FilePath bar_html(FILE_PATH_LITERAL("bar/bar.html"));
283 ASSERT_TRUE(AddFileToDirectory(temp_dir.GetPath(), foo_js, "hello"))
284 << "Failed to write " << temp_dir.GetPath().value() << "/"
285 << foo_js.value();
286 ASSERT_TRUE(AddFileToDirectory(temp_dir.GetPath(), bar_html, "world"));
287
288 ExtensionBuilder builder;
289 builder.SetManifest(DictionaryBuilder()
290 .Set("name", "My First Extension")
291 .Set("version", version)
292 .Set("manifest_version", 2)
293 .Build());
294 builder.SetID(extension_id);
295 builder.SetPath(temp_dir.GetPath());
296 ExtensionRegistry::Get(browser()->profile())->AddEnabled(builder.Build());
297
298 const Extension* extension = GetInstalledExtension(extension_id);
299 ASSERT_NE(nullptr, extension);
300 ASSERT_EQ(version, extension->VersionString());
301 }
302
303 static void InstallerCallback(base::OnceClosure quit_closure,
304 CrxInstaller::InstallerResultCallback callback,
Minh X. Nguyen8803f4e2018-05-25 01:03:10305 const base::Optional<CrxInstallError>& error) {
Minh X. Nguyen30975342017-12-04 22:02:41306 if (!callback.is_null())
Minh X. Nguyen8803f4e2018-05-25 01:03:10307 std::move(callback).Run(error);
Minh X. Nguyen30975342017-12-04 22:02:41308 std::move(quit_closure).Run();
309 }
310
[email protected]85290822013-08-23 20:27:38311 void RunCrxInstaller(const WebstoreInstaller::Approval* approval,
dchengc963c7142016-04-08 03:55:22312 std::unique_ptr<ExtensionInstallPrompt> prompt,
Minh X. Nguyen2c17b3982017-10-13 18:32:29313 CrxInstaller::InstallerResultCallback callback,
[email protected]85290822013-08-23 20:27:38314 const base::FilePath& crx_path) {
Minh X. Nguyen30975342017-12-04 22:02:41315 base::RunLoop run_loop;
316
[email protected]a01e00632010-11-05 16:58:14317 scoped_refptr<CrxInstaller> installer(
Minh X. Nguyen30975342017-12-04 22:02:41318 CrxInstaller::Create(extension_service(), std::move(prompt), approval));
[email protected]a01e00632010-11-05 16:58:14319 installer->set_allow_silent_install(true);
[email protected]b1f04cc2010-11-10 22:59:30320 installer->set_is_gallery_install(true);
Minh X. Nguyen30975342017-12-04 22:02:41321 installer->set_installer_callback(
322 base::BindOnce(&ExtensionCrxInstallerTest::InstallerCallback,
323 run_loop.QuitWhenIdleClosure(), std::move(callback)));
[email protected]85290822013-08-23 20:27:38324 installer->InstallCrx(crx_path);
Minh X. Nguyen30975342017-12-04 22:02:41325
326 run_loop.Run();
[email protected]85290822013-08-23 20:27:38327 }
328
Minh X. Nguyen2c17b3982017-10-13 18:32:29329 void RunCrxInstallerFromUnpackedDirectory(
330 std::unique_ptr<ExtensionInstallPrompt> prompt,
331 CrxInstaller::InstallerResultCallback callback,
332 const std::string& extension_id,
333 const std::string& public_key,
334 const base::FilePath& crx_directory) {
Minh X. Nguyen30975342017-12-04 22:02:41335 base::RunLoop run_loop;
336
Minh X. Nguyen2c17b3982017-10-13 18:32:29337 scoped_refptr<CrxInstaller> installer(
Minh X. Nguyen30975342017-12-04 22:02:41338 CrxInstaller::Create(extension_service(), std::move(prompt)));
Minh X. Nguyen2c17b3982017-10-13 18:32:29339 installer->set_allow_silent_install(true);
340 installer->set_is_gallery_install(true);
Minh X. Nguyen30975342017-12-04 22:02:41341 installer->set_installer_callback(
342 base::BindOnce(&ExtensionCrxInstallerTest::InstallerCallback,
343 run_loop.QuitWhenIdleClosure(), std::move(callback)));
Minh X. Nguyen2c17b3982017-10-13 18:32:29344 installer->set_delete_source(true);
345 installer->InstallUnpackedCrx(extension_id, public_key, crx_directory);
Minh X. Nguyen30975342017-12-04 22:02:41346
347 run_loop.Run();
348 }
349
350 void RunUpdateExtension(std::unique_ptr<ExtensionInstallPrompt> prompt,
351 const std::string& extension_id,
352 const std::string& public_key,
353 const base::FilePath& unpacked_dir,
354 CrxInstaller::InstallerResultCallback callback) {
355 base::RunLoop run_loop;
356
357 scoped_refptr<CrxInstaller> installer(
358 CrxInstaller::Create(extension_service(), std::move(prompt)));
359 installer->set_delete_source(true);
360 installer->set_installer_callback(
361 base::BindOnce(&ExtensionCrxInstallerTest::InstallerCallback,
362 run_loop.QuitWhenIdleClosure(), std::move(callback)));
363 installer->UpdateExtensionFromUnpackedCrx(extension_id, public_key,
364 unpacked_dir);
365
366 run_loop.Run();
Minh X. Nguyen2c17b3982017-10-13 18:32:29367 }
368
[email protected]85290822013-08-23 20:27:38369 // Installs a crx from |crx_relpath| (a path relative to the extension test
370 // data dir) with expected id |id|.
371 void InstallWithPrompt(const char* ext_relpath,
372 const std::string& id,
Minh X. Nguyen2c17b3982017-10-13 18:32:29373 CrxInstaller::InstallerResultCallback callback,
rdevlin.croninca5bf2da2015-12-17 21:21:08374 MockPromptProxy* mock_install_prompt) {
[email protected]85290822013-08-23 20:27:38375 base::FilePath ext_path = test_data_dir_.AppendASCII(ext_relpath);
376
dchengc963c7142016-04-08 03:55:22377 std::unique_ptr<WebstoreInstaller::Approval> approval;
[email protected]85290822013-08-23 20:27:38378 if (!id.empty())
379 approval = GetApproval(ext_relpath, id, true);
380
381 base::FilePath crx_path = PackExtension(ext_path);
382 EXPECT_FALSE(crx_path.empty());
383 RunCrxInstaller(approval.get(), mock_install_prompt->CreatePrompt(),
Minh X. Nguyen2c17b3982017-10-13 18:32:29384 std::move(callback), crx_path);
[email protected]a01e00632010-11-05 16:58:14385
[email protected]c82da8c42012-06-08 19:49:11386 EXPECT_TRUE(mock_install_prompt->did_succeed());
[email protected]b70a2d92012-06-28 19:51:21387 }
388
389 // Installs an extension and checks that it has scopes granted IFF
390 // |record_oauth2_grant| is true.
Minh X. Nguyen2c17b3982017-10-13 18:32:29391 void CheckHasEmptyScopesAfterInstall(
392 const std::string& ext_relpath,
393 CrxInstaller::InstallerResultCallback callback,
394 bool record_oauth2_grant) {
dchengc963c7142016-04-08 03:55:22395 std::unique_ptr<MockPromptProxy> mock_prompt =
[email protected]f8636f92013-08-09 21:02:37396 CreateMockPromptProxyForBrowser(browser());
397
Minh X. Nguyen2c17b3982017-10-13 18:32:29398 InstallWithPrompt("browsertest/scopes", std::string(), std::move(callback),
399 mock_prompt.get());
[email protected]b70a2d92012-06-28 19:51:21400
dchengc963c7142016-04-08 03:55:22401 std::unique_ptr<const PermissionSet> permissions =
[email protected]7c82539c2014-02-19 06:09:17402 ExtensionPrefs::Get(browser()->profile())
403 ->GetGrantedPermissions(mock_prompt->extension_id());
[email protected]b70a2d92012-06-28 19:51:21404 ASSERT_TRUE(permissions.get());
[email protected]a01e00632010-11-05 16:58:14405 }
kalmanae342c92014-12-12 22:04:23406
dominickn675536f2015-11-06 03:25:38407 void InstallWebAppAndVerifyNoErrors() {
dominickn675536f2015-11-06 03:25:38408 scoped_refptr<CrxInstaller> crx_installer(
Minh X. Nguyen30975342017-12-04 22:02:41409 CrxInstaller::CreateSilent(extension_service()));
dominickn675536f2015-11-06 03:25:38410 crx_installer->set_error_on_unsupported_requirements(true);
411 crx_installer->InstallWebApp(
412 CreateWebAppInfo(kAppTitle, kAppDescription, kAppUrl, 64));
413 EXPECT_TRUE(WaitForCrxInstallerDone());
414 ASSERT_TRUE(crx_installer->extension());
dominickn675536f2015-11-06 03:25:38415 }
[email protected]a01e00632010-11-05 16:58:14416};
417
voodoo6ede9072016-03-09 07:47:53418class ExtensionCrxInstallerTestWithExperimentalApis
419 : public ExtensionCrxInstallerTest {
420 protected:
421 void SetUpCommandLine(base::CommandLine* command_line) override {
422 ExtensionCrxInstallerTest::SetUpCommandLine(command_line);
423 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
424 }
425};
426
[email protected]fc38935a2011-10-31 23:53:28427IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest,
kalmanae342c92014-12-12 22:04:23428 ExperimentalExtensionFromGallery) {
429 // Gallery-installed extensions should have their experimental permission
430 // preserved, since we allow the Webstore to make that decision.
voodoo6ede9072016-03-09 07:47:53431 const Extension* extension = InstallExtensionFromWebstore(
432 test_data_dir_.AppendASCII("experimental.crx"), 1);
kalmanae342c92014-12-12 22:04:23433 ASSERT_TRUE(extension);
434 EXPECT_TRUE(extension->permissions_data()->HasAPIPermission(
435 APIPermission::kExperimental));
436}
[email protected]240cc92a2011-12-01 01:22:24437
kalmanae342c92014-12-12 22:04:23438IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest,
439 ExperimentalExtensionFromOutsideGallery) {
440 // Non-gallery-installed extensions should lose their experimental
441 // permission if the flag isn't enabled.
voodoo6ede9072016-03-09 07:47:53442 const Extension* extension = InstallExtension(
443 test_data_dir_.AppendASCII("experimental.crx"), 1);
kalmanae342c92014-12-12 22:04:23444 ASSERT_TRUE(extension);
445 EXPECT_FALSE(extension->permissions_data()->HasAPIPermission(
446 APIPermission::kExperimental));
447}
[email protected]240cc92a2011-12-01 01:22:24448
voodoo6ede9072016-03-09 07:47:53449IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTestWithExperimentalApis,
kalmanae342c92014-12-12 22:04:23450 ExperimentalExtensionFromOutsideGalleryWithFlag) {
451 // Non-gallery-installed extensions should maintain their experimental
452 // permission if the flag is enabled.
voodoo6ede9072016-03-09 07:47:53453 const Extension* extension = InstallExtension(
454 test_data_dir_.AppendASCII("experimental.crx"), 1);
kalmanae342c92014-12-12 22:04:23455 ASSERT_TRUE(extension);
456 EXPECT_TRUE(extension->permissions_data()->HasAPIPermission(
457 APIPermission::kExperimental));
[email protected]fc38935a2011-10-31 23:53:28458}
[email protected]ee14cad2012-03-29 01:59:37459
voodoo6ede9072016-03-09 07:47:53460IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTestWithExperimentalApis,
461 PlatformAppCrx) {
[email protected]ee14cad2012-03-29 01:59:37462 EXPECT_TRUE(InstallExtension(
[email protected]dc37b002012-04-23 23:02:26463 test_data_dir_.AppendASCII("minimal_platform_app.crx"), 1));
[email protected]ee14cad2012-03-29 01:59:37464}
[email protected]bf2fcd52012-04-16 22:59:39465
meacerb040d3a2016-09-09 03:20:20466IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, BlockedFileTypes) {
467 const Extension* extension =
468 InstallExtension(test_data_dir_.AppendASCII("blocked_file_types.crx"), 1);
Minh X. Nguyen2c17b3982017-10-13 18:32:29469 base::ScopedAllowBlockingForTesting allow_io;
meacerb040d3a2016-09-09 03:20:20470 EXPECT_TRUE(base::PathExists(extension->path().AppendASCII("test.html")));
471 EXPECT_TRUE(base::PathExists(extension->path().AppendASCII("test.nexe")));
472 EXPECT_FALSE(base::PathExists(extension->path().AppendASCII("test1.EXE")));
473 EXPECT_FALSE(base::PathExists(extension->path().AppendASCII("test2.exe")));
474}
475
meacerbd735062016-09-28 19:58:37476IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, AllowedThemeFileTypes) {
477 const Extension* extension = InstallExtension(
478 test_data_dir_.AppendASCII("theme_with_extension.crx"), 1);
479 ASSERT_TRUE(extension);
480 const base::FilePath& path = extension->path();
Minh X. Nguyen2c17b3982017-10-13 18:32:29481 base::ScopedAllowBlockingForTesting allow_io;
meacerbd735062016-09-28 19:58:37482 EXPECT_TRUE(
483 base::PathExists(path.AppendASCII("images/theme_frame_camo.PNG")));
484 EXPECT_TRUE(
485 base::PathExists(path.AppendASCII("images/theme_ntp_background.png")));
486 EXPECT_TRUE(base::PathExists(
487 path.AppendASCII("images/theme_ntp_background_norepeat.png")));
488 EXPECT_TRUE(
489 base::PathExists(path.AppendASCII("images/theme_toolbar_camo.png")));
490 EXPECT_TRUE(base::PathExists(path.AppendASCII("images/redirect_target.GIF")));
491 EXPECT_TRUE(base::PathExists(path.AppendASCII("test.image.bmp")));
492 EXPECT_TRUE(
493 base::PathExists(path.AppendASCII("test_image_with_no_extension")));
494
495 EXPECT_FALSE(base::PathExists(path.AppendASCII("non_images/test.html")));
496 EXPECT_FALSE(base::PathExists(path.AppendASCII("non_images/test.nexe")));
497 EXPECT_FALSE(base::PathExists(path.AppendASCII("non_images/test1.EXE")));
498 EXPECT_FALSE(base::PathExists(path.AppendASCII("non_images/test2.exe")));
499 EXPECT_FALSE(base::PathExists(path.AppendASCII("non_images/test.txt")));
500 EXPECT_FALSE(base::PathExists(path.AppendASCII("non_images/test.css")));
501}
502
rdevlin.cronin10f34542017-02-06 18:22:47503IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest,
504 PackAndInstallExtensionFromDownload) {
505 std::unique_ptr<base::AutoReset<bool>> allow_offstore_install =
506 download_crx_util::OverrideOffstoreInstallAllowedForTesting(true);
[email protected]89019d62012-05-17 18:47:09507
[email protected]bf2fcd52012-04-16 22:59:39508 const int kNumDownloadsExpected = 1;
[email protected]bf2fcd52012-04-16 22:59:39509
[email protected]650b2d52013-02-10 03:41:45510 base::FilePath crx_path = PackExtension(
[email protected]bf2fcd52012-04-16 22:59:39511 test_data_dir_.AppendASCII("common/background_page"));
512 ASSERT_FALSE(crx_path.empty());
513 std::string crx_path_string(crx_path.value().begin(), crx_path.value().end());
514 GURL url = GURL(std::string("file:///").append(crx_path_string));
515
dchengc963c7142016-04-08 03:55:22516 std::unique_ptr<MockPromptProxy> mock_prompt =
[email protected]f8636f92013-08-09 21:02:37517 CreateMockPromptProxyForBrowser(browser());
518 download_crx_util::SetMockInstallPromptForTesting(
519 mock_prompt->CreatePrompt());
[email protected]bf2fcd52012-04-16 22:59:39520
[email protected]bf2fcd52012-04-16 22:59:39521 content::DownloadManager* download_manager =
[email protected]b441a8492012-06-06 14:55:57522 content::BrowserContext::GetDownloadManager(browser()->profile());
[email protected]bf2fcd52012-04-16 22:59:39523
dchengc963c7142016-04-08 03:55:22524 std::unique_ptr<content::DownloadTestObserver> observer(
[email protected]49b264f2012-08-14 17:12:26525 new content::DownloadTestObserverTerminal(
[email protected]47665442012-07-27 02:31:22526 download_manager, kNumDownloadsExpected,
[email protected]49b264f2012-08-14 17:12:26527 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT));
nick3b04f322016-08-31 19:29:19528 ui_test_utils::NavigateToURLWithDisposition(
529 browser(), url, WindowOpenDisposition::CURRENT_TAB,
[email protected]bf2fcd52012-04-16 22:59:39530 ui_test_utils::BROWSER_TEST_NONE);
531
[email protected]8c6af5b2012-06-15 20:10:26532 EXPECT_TRUE(WaitForCrxInstallerDone());
[email protected]c82da8c42012-06-08 19:49:11533 EXPECT_TRUE(mock_prompt->confirmation_requested());
[email protected]bf2fcd52012-04-16 22:59:39534}
[email protected]a9736892012-05-30 15:58:05535
[email protected]b70a2d92012-06-28 19:51:21536// Tests that scopes are only granted if |record_oauth2_grant_| on the prompt is
537// true.
[email protected]7a561912012-08-21 21:06:05538#if defined(OS_WIN)
[email protected]1e09ec82012-12-21 22:48:09539#define MAYBE_GrantScopes DISABLED_GrantScopes
Minh X. Nguyen2c17b3982017-10-13 18:32:29540#define MAYBE_GrantScopes_WithCallback DISABLED_GrantScopes_WithCallback
[email protected]7a561912012-08-21 21:06:05541#else
542#define MAYBE_GrantScopes GrantScopes
Minh X. Nguyen2c17b3982017-10-13 18:32:29543#define MAYBE_GrantScopes_WithCallback GrantScopes_WithCallback
[email protected]7a561912012-08-21 21:06:05544#endif
voodoo6ede9072016-03-09 07:47:53545IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTestWithExperimentalApis,
546 MAYBE_GrantScopes) {
Minh X. Nguyen2c17b3982017-10-13 18:32:29547 EXPECT_NO_FATAL_FAILURE(CheckHasEmptyScopesAfterInstall(
548 "browsertest/scopes", CrxInstaller::InstallerResultCallback(), true));
549}
550
551IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTestWithExperimentalApis,
552 MAYBE_GrantScopes_WithCallback) {
553 EXPECT_NO_FATAL_FAILURE(CheckHasEmptyScopesAfterInstall(
554 "browsertest/scopes",
Minh X. Nguyen8803f4e2018-05-25 01:03:10555 base::BindOnce([](const base::Optional<CrxInstallError>& error) {
556 EXPECT_EQ(base::nullopt, error);
557 }),
558 true));
[email protected]b70a2d92012-06-28 19:51:21559}
560
voodoo6ede9072016-03-09 07:47:53561IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTestWithExperimentalApis,
562 DoNotGrantScopes) {
Minh X. Nguyen2c17b3982017-10-13 18:32:29563 EXPECT_NO_FATAL_FAILURE(CheckHasEmptyScopesAfterInstall(
564 "browsertest/scopes", CrxInstaller::InstallerResultCallback(), false));
565}
566
567IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTestWithExperimentalApis,
568 DoNotGrantScopes_WithCallback) {
569 EXPECT_NO_FATAL_FAILURE(CheckHasEmptyScopesAfterInstall(
570 "browsertest/scopes",
Minh X. Nguyen8803f4e2018-05-25 01:03:10571 base::BindOnce([](const base::Optional<CrxInstallError>& error) {
572 EXPECT_EQ(base::nullopt, error);
573 }),
574 false));
[email protected]b70a2d92012-06-28 19:51:21575}
576
[email protected]d4b4d7af2014-08-20 10:45:15577IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, AllowOffStore) {
[email protected]a9736892012-05-30 15:58:05578 const bool kTestData[] = {false, true};
579
Avi Drissman5f0fb8c2018-12-25 23:20:49580 for (size_t i = 0; i < base::size(kTestData); ++i) {
dchengc963c7142016-04-08 03:55:22581 std::unique_ptr<MockPromptProxy> mock_prompt =
[email protected]f8636f92013-08-09 21:02:37582 CreateMockPromptProxyForBrowser(browser());
583
[email protected]a9736892012-05-30 15:58:05584 scoped_refptr<CrxInstaller> crx_installer(
Minh X. Nguyen30975342017-12-04 22:02:41585 CrxInstaller::Create(extension_service(), mock_prompt->CreatePrompt()));
[email protected]7224dbd2012-06-05 15:21:50586 crx_installer->set_install_cause(
587 extension_misc::INSTALL_CAUSE_USER_DOWNLOAD);
[email protected]d9039812012-06-09 06:05:48588
589 if (kTestData[i]) {
590 crx_installer->set_off_store_install_allow_reason(
591 CrxInstaller::OffStoreInstallAllowedInTest);
592 }
[email protected]a9736892012-05-30 15:58:05593
Minh X. Nguyen30975342017-12-04 22:02:41594 base::RunLoop run_loop;
595 crx_installer->set_installer_callback(
596 base::BindOnce(&ExtensionCrxInstallerTest::InstallerCallback,
597 run_loop.QuitWhenIdleClosure(),
598 CrxInstaller::InstallerResultCallback()));
[email protected]a9736892012-05-30 15:58:05599 crx_installer->InstallCrx(test_data_dir_.AppendASCII("good.crx"));
[email protected]d4b4d7af2014-08-20 10:45:15600 // The |mock_prompt| will quit running the loop once the |crx_installer|
601 // is done.
Minh X. Nguyen30975342017-12-04 22:02:41602 run_loop.Run();
[email protected]c82da8c42012-06-08 19:49:11603 EXPECT_EQ(kTestData[i], mock_prompt->did_succeed());
604 EXPECT_EQ(kTestData[i], mock_prompt->confirmation_requested()) <<
605 kTestData[i];
[email protected]a9736892012-05-30 15:58:05606 if (kTestData[i]) {
[email protected]b959d7d42013-12-13 17:26:37607 EXPECT_EQ(base::string16(), mock_prompt->error()) << kTestData[i];
[email protected]a9736892012-05-30 15:58:05608 } else {
609 EXPECT_EQ(l10n_util::GetStringUTF16(
610 IDS_EXTENSION_INSTALL_DISALLOWED_ON_SITE),
[email protected]c82da8c42012-06-08 19:49:11611 mock_prompt->error()) << kTestData[i];
[email protected]a9736892012-05-30 15:58:05612 }
613 }
[email protected]a9736892012-05-30 15:58:05614}
[email protected]bf3d9df2012-07-24 23:20:27615
[email protected]90d3c042013-06-06 10:10:39616IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, HiDpiThemeTest) {
617 base::FilePath crx_path = test_data_dir_.AppendASCII("theme_hidpi_crx");
618 crx_path = crx_path.AppendASCII("theme_hidpi.crx");
619
[email protected]658eae52014-06-14 20:28:05620 ASSERT_TRUE(InstallExtension(crx_path, 1));
[email protected]90d3c042013-06-06 10:10:39621
622 const std::string extension_id("gllekhaobjnhgeagipipnkpmmmpchacm");
gpdavis.chromium48f08c42014-09-18 22:09:34623 ExtensionRegistry* registry = ExtensionRegistry::Get(
624 browser()->profile());
[email protected]90d3c042013-06-06 10:10:39625 const extensions::Extension* extension =
gpdavis.chromium48f08c42014-09-18 22:09:34626 registry->enabled_extensions().GetByID(extension_id);
[email protected]90d3c042013-06-06 10:10:39627 ASSERT_TRUE(extension);
628 EXPECT_EQ(extension_id, extension->id());
629
630 UninstallExtension(extension_id);
gpdavis.chromium48f08c42014-09-18 22:09:34631 EXPECT_FALSE(registry->enabled_extensions().GetByID(extension_id));
[email protected]90d3c042013-06-06 10:10:39632}
633
[email protected]9e9c1d12013-07-31 01:58:12634IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest,
mekc95f9d062015-01-10 00:52:04635 InstallDelayedUntilNextUpdate) {
[email protected]9e9c1d12013-07-31 01:58:12636 const std::string extension_id("ldnnhddmnhbkjipkidpdiheffobcpfmf");
mekc95f9d062015-01-10 00:52:04637 base::FilePath base_path = test_data_dir_.AppendASCII("delayed_install");
638
Minh X. Nguyen30975342017-12-04 22:02:41639 ExtensionService* service = extension_service();
[email protected]9e9c1d12013-07-31 01:58:12640 ASSERT_TRUE(service);
gpdavis.chromium48f08c42014-09-18 22:09:34641 ExtensionRegistry* registry = ExtensionRegistry::Get(
642 browser()->profile());
643 ASSERT_TRUE(registry);
[email protected]9e9c1d12013-07-31 01:58:12644
645 // Install version 1 of the test extension. This extension does not have
646 // a background page but does have a browser action.
mekc95f9d062015-01-10 00:52:04647 base::FilePath v1_path = PackExtension(base_path.AppendASCII("v1"));
648 ASSERT_FALSE(v1_path.empty());
649 ASSERT_TRUE(InstallExtension(v1_path, 1));
[email protected]9e9c1d12013-07-31 01:58:12650 const extensions::Extension* extension =
gpdavis.chromium48f08c42014-09-18 22:09:34651 registry->enabled_extensions().GetByID(extension_id);
[email protected]9e9c1d12013-07-31 01:58:12652 ASSERT_TRUE(extension);
653 ASSERT_EQ(extension_id, extension->id());
Devlin Cronin03bf2d22017-12-20 08:21:05654 ASSERT_EQ("1.0", extension->version().GetString());
[email protected]9e9c1d12013-07-31 01:58:12655
mekc95f9d062015-01-10 00:52:04656 // Make test extension non-idle by opening the extension's options page.
657 ExtensionTabUtil::OpenOptionsPage(extension, browser());
658 WaitForExtensionNotIdle(extension_id);
[email protected]9e9c1d12013-07-31 01:58:12659
660 // Install version 2 of the extension and check that it is indeed delayed.
mekc95f9d062015-01-10 00:52:04661 base::FilePath v2_path = PackExtension(base_path.AppendASCII("v2"));
662 ASSERT_FALSE(v2_path.empty());
663 ASSERT_TRUE(UpdateExtensionWaitForIdle(extension_id, v2_path, 0));
[email protected]9e9c1d12013-07-31 01:58:12664
665 ASSERT_EQ(1u, service->delayed_installs()->size());
gpdavis.chromium48f08c42014-09-18 22:09:34666 extension = registry->enabled_extensions().GetByID(extension_id);
Devlin Cronin03bf2d22017-12-20 08:21:05667 ASSERT_EQ("1.0", extension->version().GetString());
[email protected]9e9c1d12013-07-31 01:58:12668
mekc95f9d062015-01-10 00:52:04669 // Make the extension idle again by navigating away from the options page.
670 // This should not trigger the delayed install.
671 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
672 WaitForExtensionIdle(extension_id);
[email protected]9e9c1d12013-07-31 01:58:12673 ASSERT_EQ(1u, service->delayed_installs()->size());
mekc95f9d062015-01-10 00:52:04674 extension = registry->enabled_extensions().GetByID(extension_id);
Devlin Cronin03bf2d22017-12-20 08:21:05675 ASSERT_EQ("1.0", extension->version().GetString());
[email protected]9e9c1d12013-07-31 01:58:12676
677 // Install version 3 of the extension. Because the extension is idle,
678 // this install should succeed.
mekc95f9d062015-01-10 00:52:04679 base::FilePath v3_path = PackExtension(base_path.AppendASCII("v3"));
680 ASSERT_FALSE(v3_path.empty());
681 ASSERT_TRUE(UpdateExtensionWaitForIdle(extension_id, v3_path, 0));
gpdavis.chromium48f08c42014-09-18 22:09:34682 extension = registry->enabled_extensions().GetByID(extension_id);
Devlin Cronin03bf2d22017-12-20 08:21:05683 ASSERT_EQ("3.0", extension->version().GetString());
[email protected]9e9c1d12013-07-31 01:58:12684
685 // The version 2 delayed install should be cleaned up, and finishing
686 // delayed extension installation shouldn't break anything.
687 ASSERT_EQ(0u, service->delayed_installs()->size());
688 service->MaybeFinishDelayedInstallations();
gpdavis.chromium48f08c42014-09-18 22:09:34689 extension = registry->enabled_extensions().GetByID(extension_id);
Devlin Cronin03bf2d22017-12-20 08:21:05690 ASSERT_EQ("3.0", extension->version().GetString());
[email protected]9e9c1d12013-07-31 01:58:12691}
692
Nico Weberbc5b06f2019-07-26 14:00:13693#if BUILDFLAG(FULL_SAFE_BROWSING)
[email protected]9f3c8532013-07-31 19:52:07694IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, Blacklist) {
[email protected]3f2a2fa2013-09-24 02:55:25695 scoped_refptr<FakeSafeBrowsingDatabaseManager> blacklist_db(
696 new FakeSafeBrowsingDatabaseManager(true));
697 Blacklist::ScopedDatabaseManagerForTest scoped_blacklist_db(blacklist_db);
[email protected]9f3c8532013-07-31 19:52:07698
Sergey Poromovcc362382018-11-09 18:43:32699 const std::string extension_id = "gllekhaobjnhgeagipipnkpmmmpchacm";
700 blacklist_db->SetUnsafe(extension_id);
[email protected]9f3c8532013-07-31 19:52:07701
702 base::FilePath crx_path = test_data_dir_.AppendASCII("theme_hidpi_crx")
703 .AppendASCII("theme_hidpi.crx");
704 EXPECT_FALSE(InstallExtension(crx_path, 0));
Sergey Poromovcc362382018-11-09 18:43:32705
706 auto installation_failure =
Oleg Davydovc00866812019-04-04 10:47:27707 InstallationReporter::Get(profile(), extension_id);
708 EXPECT_EQ(InstallationReporter::FailureReason::CRX_INSTALL_ERROR_DECLINED,
709 installation_failure.failure_reason);
Sergey Poromovcc362382018-11-09 18:43:32710 EXPECT_EQ(CrxInstallErrorDetail::EXTENSION_IS_BLOCKLISTED,
Oleg Davydovc00866812019-04-04 10:47:27711 installation_failure.install_error_detail);
[email protected]9f3c8532013-07-31 19:52:07712}
[email protected]e3767aa2013-11-08 23:49:07713#endif
[email protected]9f3c8532013-07-31 19:52:07714
[email protected]85290822013-08-23 20:27:38715IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, NonStrictManifestCheck) {
dchengc963c7142016-04-08 03:55:22716 std::unique_ptr<MockPromptProxy> mock_prompt =
[email protected]85290822013-08-23 20:27:38717 CreateMockPromptProxyForBrowser(browser());
718
719 // We want to simulate the case where the webstore sends a more recent
720 // version of the manifest, but the downloaded .crx file is old since
721 // the newly published version hasn't fully propagated to all the download
722 // servers yet. So load the v2 manifest, but then install the v1 crx file.
Joshua Pawlickiaf97ca02018-11-12 17:17:02723 std::string id = "ooklpoaelmiimcjipecogjfcejghbogp";
dchengc963c7142016-04-08 03:55:22724 std::unique_ptr<WebstoreInstaller::Approval> approval =
[email protected]85290822013-08-23 20:27:38725 GetApproval("crx_installer/v2_no_permission_change/", id, false);
726
727 RunCrxInstaller(approval.get(), mock_prompt->CreatePrompt(),
Minh X. Nguyen2c17b3982017-10-13 18:32:29728 CrxInstaller::InstallerResultCallback(),
[email protected]85290822013-08-23 20:27:38729 test_data_dir_.AppendASCII("crx_installer/v1.crx"));
730
731 EXPECT_TRUE(mock_prompt->did_succeed());
732}
733
Minh X. Nguyen2c17b3982017-10-13 18:32:29734IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest,
735 NonStrictManifestCheck_WithCallback) {
736 std::unique_ptr<MockPromptProxy> mock_prompt =
737 CreateMockPromptProxyForBrowser(browser());
738
739 // We want to simulate the case where the webstore sends a more recent
740 // version of the manifest, but the downloaded .crx file is old since
741 // the newly published version hasn't fully propagated to all the download
742 // servers yet. So load the v2 manifest, but then install the v1 crx file.
Joshua Pawlickiaf97ca02018-11-12 17:17:02743 const std::string id = "ooklpoaelmiimcjipecogjfcejghbogp";
Minh X. Nguyen2c17b3982017-10-13 18:32:29744 std::unique_ptr<WebstoreInstaller::Approval> approval =
745 GetApproval("crx_installer/v2_no_permission_change/", id, false);
746
Minh X. Nguyen8803f4e2018-05-25 01:03:10747 RunCrxInstaller(
748 approval.get(), mock_prompt->CreatePrompt(),
749 base::BindOnce([](const base::Optional<CrxInstallError>& error) {
750 EXPECT_EQ(base::nullopt, error);
751 }),
752 test_data_dir_.AppendASCII("crx_installer/v1.crx"));
Minh X. Nguyen2c17b3982017-10-13 18:32:29753
754 EXPECT_TRUE(mock_prompt->did_succeed());
755}
756
757IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest,
758 InstallUnpackedCrx_FolderDoesNotExist) {
759 base::ScopedAllowBlockingForTesting allow_io;
760 std::unique_ptr<MockPromptProxy> mock_prompt =
761 CreateMockPromptProxyForBrowser(browser());
762
763 base::ScopedTempDir temp_dir;
764 EXPECT_TRUE(temp_dir.CreateUniqueTempDir());
765
766 const base::FilePath folder = temp_dir.GetPath().AppendASCII("abcdef");
767 EXPECT_FALSE(base::PathExists(folder));
768
769 const std::string public_key = "123456";
770 RunCrxInstallerFromUnpackedDirectory(
771 mock_prompt->CreatePrompt(),
Minh X. Nguyen8803f4e2018-05-25 01:03:10772 base::BindOnce([](const base::Optional<CrxInstallError>& error) {
773 ASSERT_NE(base::nullopt, error);
774 ASSERT_EQ(CrxInstallErrorType::SANDBOXED_UNPACKER_FAILURE,
775 error->type());
776 EXPECT_EQ(SandboxedUnpackerFailureReason::DIRECTORY_MOVE_FAILED,
777 error->sandbox_failure_detail());
778 }),
Minh X. Nguyen2c17b3982017-10-13 18:32:29779 std::string(), public_key, folder);
780
781 EXPECT_FALSE(mock_prompt->did_succeed());
782}
783
784IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest,
785 InstallUnpackedCrx_EmptyFolder) {
786 base::ScopedAllowBlockingForTesting allow_io;
787 std::unique_ptr<MockPromptProxy> mock_prompt =
788 CreateMockPromptProxyForBrowser(browser());
789
790 base::ScopedTempDir temp_dir;
791 EXPECT_TRUE(temp_dir.CreateUniqueTempDir());
792 EXPECT_TRUE(base::PathExists(temp_dir.GetPath()));
793
794 const std::string public_key = "123456";
795 RunCrxInstallerFromUnpackedDirectory(
796 mock_prompt->CreatePrompt(),
Minh X. Nguyen8803f4e2018-05-25 01:03:10797 base::BindOnce([](const base::Optional<CrxInstallError>& error) {
798 ASSERT_NE(base::nullopt, error);
799 ASSERT_EQ(CrxInstallErrorType::SANDBOXED_UNPACKER_FAILURE,
800 error->type());
801 EXPECT_EQ(SandboxedUnpackerFailureReason::UNPACKER_CLIENT_FAILED,
802 error->sandbox_failure_detail());
803 }),
Minh X. Nguyen2c17b3982017-10-13 18:32:29804 std::string(), public_key, temp_dir.GetPath());
805
806 EXPECT_FALSE(mock_prompt->did_succeed());
807 EXPECT_FALSE(base::PathExists(temp_dir.GetPath()));
808}
809
810IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest,
811 InstallUnpackedCrx_InvalidPublicKey) {
812 base::ScopedAllowBlockingForTesting allow_io;
813 std::unique_ptr<MockPromptProxy> mock_prompt =
814 CreateMockPromptProxyForBrowser(browser());
815
816 base::ScopedTempDir temp_dir;
817 EXPECT_TRUE(temp_dir.CreateUniqueTempDir());
818 EXPECT_TRUE(base::PathExists(temp_dir.GetPath()));
819
820 const base::FilePath unpacked_path =
Devlin Cronin19775cc2018-04-19 15:04:26821 test_data_dir_.AppendASCII("simple_with_popup");
Minh X. Nguyen2c17b3982017-10-13 18:32:29822 EXPECT_TRUE(base::PathExists(unpacked_path));
823 EXPECT_TRUE(base::CopyDirectory(unpacked_path, temp_dir.GetPath(), false));
824
825 const std::string public_key = "123456";
826 RunCrxInstallerFromUnpackedDirectory(
827 mock_prompt->CreatePrompt(),
Minh X. Nguyen8803f4e2018-05-25 01:03:10828 base::BindOnce([](const base::Optional<CrxInstallError>& error) {
829 ASSERT_NE(base::nullopt, error);
830 ASSERT_EQ(CrxInstallErrorType::SANDBOXED_UNPACKER_FAILURE,
831 error->type());
832 EXPECT_EQ(SandboxedUnpackerFailureReason::INVALID_MANIFEST,
833 error->sandbox_failure_detail());
834 }),
Minh X. Nguyen2c17b3982017-10-13 18:32:29835 std::string(), public_key, temp_dir.GetPath());
836
837 EXPECT_FALSE(mock_prompt->did_succeed());
838 EXPECT_FALSE(base::PathExists(temp_dir.GetPath()));
839}
840
841IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, InstallUnpackedCrx_Success) {
842 base::ScopedAllowBlockingForTesting allow_io;
843 std::unique_ptr<MockPromptProxy> mock_prompt =
844 CreateMockPromptProxyForBrowser(browser());
845
846 base::ScopedTempDir temp_dir;
847 EXPECT_TRUE(temp_dir.CreateUniqueTempDir());
848 EXPECT_TRUE(base::PathExists(temp_dir.GetPath()));
849
850 const base::FilePath unpacked_path =
Devlin Cronin19775cc2018-04-19 15:04:26851 test_data_dir_.AppendASCII("simple_with_popup");
Minh X. Nguyen2c17b3982017-10-13 18:32:29852 EXPECT_TRUE(base::PathExists(unpacked_path));
853 EXPECT_TRUE(base::CopyDirectory(unpacked_path, temp_dir.GetPath(), false));
854
855 const std::string public_key =
856 "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC8c4fBSPZ6utYoZ8NiWF/"
857 "DSaimBhihjwgOsskyleFGaurhi3TDClTVSGPxNkgCzrz0wACML7M4aNjpd05qupdbR2d294j"
858 "kDuI7caxEGUucpP7GJRRHnm8Sx+"
859 "y0ury28n8jbN0PnInKKWcxpIXXmNQyC19HBuO3QIeUq9Dqc+7YFQIDAQAB";
860 RunCrxInstallerFromUnpackedDirectory(
861 mock_prompt->CreatePrompt(),
Minh X. Nguyen8803f4e2018-05-25 01:03:10862 base::BindOnce([](const base::Optional<CrxInstallError>& error) {
863 EXPECT_EQ(base::nullopt, error);
864 }),
865 std::string(), public_key, temp_dir.GetPath());
Minh X. Nguyen2c17b3982017-10-13 18:32:29866
867 EXPECT_TRUE(mock_prompt->did_succeed());
868 EXPECT_FALSE(base::PathExists(temp_dir.GetPath()));
869}
870
Minh X. Nguyen30975342017-12-04 22:02:41871IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest,
872 UpdateExtensionFromUnpackedCrx_NewExtension) {
873 base::ScopedAllowBlockingForTesting allow_io;
874 std::unique_ptr<MockPromptProxy> mock_prompt =
875 CreateMockPromptProxyForBrowser(browser());
876
877 // Update won't work as the extension doesn't exist.
878 const std::string extension_id = "ldnnhddmnhbkjipkidpdiheffobcpfmf";
879 const std::string public_key =
880 "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC8c4fBSPZ6utYoZ8NiWF/"
881 "DSaimBhihjwgOsskyleFGaurhi3TDClTVSGPxNkgCzrz0wACML7M4aNjpd05qupdbR2d294j"
882 "kDuI7caxEGUucpP7GJRRHnm8Sx+"
883 "y0ury28n8jbN0PnInKKWcxpIXXmNQyC19HBuO3QIeUq9Dqc+7YFQIDAQAB";
884 ASSERT_EQ(nullptr, GetInstalledExtension(extension_id));
885 auto temp_dir = UnpackedCrxTempDir();
Minh X. Nguyen8803f4e2018-05-25 01:03:10886 RunUpdateExtension(
887 mock_prompt->CreatePrompt(), extension_id, public_key,
888 temp_dir->GetPath(),
889 base::BindOnce([](const base::Optional<CrxInstallError>& error) {
890 ASSERT_NE(base::nullopt, error);
891 EXPECT_EQ(CrxInstallErrorType::OTHER, error->type());
892 EXPECT_EQ(CrxInstallErrorDetail::UPDATE_NON_EXISTING_EXTENSION,
893 error->detail());
894 }));
Minh X. Nguyen30975342017-12-04 22:02:41895
896 // The unpacked folder should be deleted.
897 EXPECT_FALSE(mock_prompt->did_succeed());
898 EXPECT_FALSE(base::PathExists(temp_dir->GetPath()));
899 EXPECT_EQ(nullptr, GetInstalledExtension(extension_id));
900}
901
902IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest,
903 UpdateExtensionFromUnpackedCrx_UpdateExistingExtension) {
904 base::ScopedAllowBlockingForTesting allow_io;
905 std::unique_ptr<MockPromptProxy> mock_prompt =
906 CreateMockPromptProxyForBrowser(browser());
907
908 const std::string extension_id = "ldnnhddmnhbkjipkidpdiheffobcpfmf";
909 const std::string public_key =
910 "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC8c4fBSPZ6utYoZ8NiWF/"
911 "DSaimBhihjwgOsskyleFGaurhi3TDClTVSGPxNkgCzrz0wACML7M4aNjpd05qupdbR2d294j"
912 "kDuI7caxEGUucpP7GJRRHnm8Sx+"
913 "y0ury28n8jbN0PnInKKWcxpIXXmNQyC19HBuO3QIeUq9Dqc+7YFQIDAQAB";
914
915 // Test updating an existing extension.
916 AddExtension(extension_id, "0.0");
917
918 auto temp_dir = UnpackedCrxTempDir();
Minh X. Nguyen8803f4e2018-05-25 01:03:10919 RunUpdateExtension(
920 mock_prompt->CreatePrompt(), extension_id, public_key,
921 temp_dir->GetPath(),
922 base::BindOnce([](const base::Optional<CrxInstallError>& error) {
923 EXPECT_EQ(base::nullopt, error);
924 }));
Minh X. Nguyen30975342017-12-04 22:02:41925
926 EXPECT_TRUE(mock_prompt->did_succeed());
927
928 // The unpacked folder should be deleted.
929 EXPECT_FALSE(base::PathExists(temp_dir->GetPath()));
930
931 const Extension* extension = GetInstalledExtension(extension_id);
932 ASSERT_NE(nullptr, extension);
933 EXPECT_EQ("1.0", extension->VersionString());
934}
935
936IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest,
937 UpdateExtensionFromUnpackedCrx_InvalidPublicKey) {
938 base::ScopedAllowBlockingForTesting allow_io;
939 std::unique_ptr<MockPromptProxy> mock_prompt =
940 CreateMockPromptProxyForBrowser(browser());
941
942 const std::string extension_id = "ldnnhddmnhbkjipkidpdiheffobcpfmf";
943 const std::string public_key = "invalid public key";
944
945 // Test updating an existing extension.
946 AddExtension(extension_id, "0.0");
947
948 auto temp_dir = UnpackedCrxTempDir();
Minh X. Nguyen8803f4e2018-05-25 01:03:10949 RunUpdateExtension(
950 mock_prompt->CreatePrompt(), extension_id, public_key,
951 temp_dir->GetPath(),
952 base::BindOnce([](const base::Optional<CrxInstallError>& error) {
953 ASSERT_NE(base::nullopt, error);
954 ASSERT_EQ(CrxInstallErrorType::SANDBOXED_UNPACKER_FAILURE,
955 error->type());
956 EXPECT_EQ(SandboxedUnpackerFailureReason::INVALID_MANIFEST,
957 error->sandbox_failure_detail());
958 }));
Minh X. Nguyen30975342017-12-04 22:02:41959
960 EXPECT_FALSE(mock_prompt->did_succeed());
961
962 // The unpacked folder should be deleted.
963 EXPECT_FALSE(base::PathExists(temp_dir->GetPath()));
964
965 const Extension* extension = GetInstalledExtension(extension_id);
966 ASSERT_NE(nullptr, extension);
967 EXPECT_EQ("0.0", extension->VersionString());
Sergey Poromovcc362382018-11-09 18:43:32968
969 auto installation_failure =
Oleg Davydovc00866812019-04-04 10:47:27970 InstallationReporter::Get(profile(), extension_id);
971 EXPECT_EQ(InstallationReporter::FailureReason::
Sergey Poromovcc362382018-11-09 18:43:32972 CRX_INSTALL_ERROR_SANDBOXED_UNPACKER_FAILURE,
Oleg Davydovc00866812019-04-04 10:47:27973 installation_failure.failure_reason);
974 EXPECT_EQ(base::nullopt, installation_failure.install_error_detail);
Minh X. Nguyen30975342017-12-04 22:02:41975}
976
977IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest,
978 UpdateExtensionFromUnpackedCrx_WrongPublicKey) {
979 base::ScopedAllowBlockingForTesting allow_io;
980 std::unique_ptr<MockPromptProxy> mock_prompt =
981 CreateMockPromptProxyForBrowser(browser());
982
983 const std::string extension_id = "gllekhaobjnhgeagipipnkpmmmpchacm";
984 const std::string public_key =
985 "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC8c4fBSPZ6utYoZ8NiWF/"
986 "DSaimBhihjwgOsskyleFGaurhi3TDClTVSGPxNkgCzrz0wACML7M4aNjpd05qupdbR2d294j"
987 "kDuI7caxEGUucpP7GJRRHnm8Sx+"
988 "y0ury28n8jbN0PnInKKWcxpIXXmNQyC19HBuO3QIeUq9Dqc+7YFQIDAQAB";
989
990 // Test updating an existing extension.
991 AddExtension(extension_id, "0.0");
992
993 auto temp_dir = UnpackedCrxTempDir();
Minh X. Nguyen8803f4e2018-05-25 01:03:10994 RunUpdateExtension(
995 mock_prompt->CreatePrompt(), extension_id, public_key,
996 temp_dir->GetPath(),
997 base::BindOnce([](const base::Optional<CrxInstallError>& error) {
998 ASSERT_NE(base::nullopt, error);
999 EXPECT_EQ(CrxInstallErrorType::OTHER, error->type());
1000 EXPECT_EQ(CrxInstallErrorDetail::UNEXPECTED_ID, error->detail());
1001 }));
Minh X. Nguyen30975342017-12-04 22:02:411002
1003 EXPECT_FALSE(mock_prompt->did_succeed());
1004
1005 // The unpacked folder should be deleted.
1006 EXPECT_FALSE(base::PathExists(temp_dir->GetPath()));
1007
1008 const Extension* extension = GetInstalledExtension(extension_id);
1009 ASSERT_NE(nullptr, extension);
1010 EXPECT_EQ("0.0", extension->VersionString());
Sergey Poromovcc362382018-11-09 18:43:321011
1012 auto installation_failure =
Oleg Davydovc00866812019-04-04 10:47:271013 InstallationReporter::Get(profile(), extension_id);
1014 EXPECT_EQ(InstallationReporter::FailureReason::CRX_INSTALL_ERROR_OTHER,
1015 installation_failure.failure_reason);
1016 EXPECT_EQ(CrxInstallErrorDetail::UNEXPECTED_ID,
1017 *installation_failure.install_error_detail);
Minh X. Nguyen30975342017-12-04 22:02:411018}
1019
limasdfebff7fd02015-12-25 14:45:311020#if defined(OS_CHROMEOS)
[email protected]14a18bf2013-09-26 08:42:301021IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, KioskOnlyTest) {
Sam McNallyfb8bfc32018-10-30 06:51:111022 base::ScopedAllowBlockingForTesting allow_io;
limasdfebff7fd02015-12-25 14:45:311023 // kiosk_only is whitelisted from non-chromeos.
[email protected]14a18bf2013-09-26 08:42:301024 base::FilePath crx_path =
1025 test_data_dir_.AppendASCII("kiosk/kiosk_only.crx");
1026 EXPECT_FALSE(InstallExtension(crx_path, 0));
[email protected]14a18bf2013-09-26 08:42:301027 // Simulate ChromeOS kiosk mode. |scoped_user_manager| will take over
1028 // lifetime of |user_manager|.
merkulova793f3022015-02-04 10:18:301029 chromeos::FakeChromeUserManager* fake_user_manager =
1030 new chromeos::FakeChromeUserManager();
alemate3ffbde6f2015-11-03 02:02:551031 const AccountId account_id(AccountId::FromUserEmail("[email protected]"));
1032 fake_user_manager->AddKioskAppUser(account_id);
1033 fake_user_manager->LoginUser(account_id);
Xiyuan Xiadfe3a9f2017-11-13 21:46:261034 user_manager::ScopedUserManager scoped_user_manager(
1035 base::WrapUnique(fake_user_manager));
[email protected]14a18bf2013-09-26 08:42:301036 EXPECT_TRUE(InstallExtension(crx_path, 1));
[email protected]14a18bf2013-09-26 08:42:301037}
1038
dpolukhincbd48d192015-06-04 14:09:371039IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, InstallToSharedLocation) {
Sam McNallyfb8bfc32018-10-30 06:51:111040 base::ScopedAllowBlockingForTesting allow_io;
avi3ef9ec9e2014-12-22 22:50:171041 base::CommandLine::ForCurrentProcess()->AppendSwitch(
[email protected]5a145e82014-05-29 22:19:071042 chromeos::switches::kEnableExtensionAssetsSharing);
1043 base::ScopedTempDir cache_dir;
1044 ASSERT_TRUE(cache_dir.CreateUniqueTempDir());
1045 ExtensionAssetsManagerChromeOS::SetSharedInstallDirForTesting(
vabr9142fe22016-09-08 13:19:221046 cache_dir.GetPath());
[email protected]5a145e82014-05-29 22:19:071047
1048 base::FilePath crx_path = test_data_dir_.AppendASCII("crx_installer/v1.crx");
1049 const extensions::Extension* extension = InstallExtension(
1050 crx_path, 1, extensions::Manifest::EXTERNAL_PREF);
1051 base::FilePath extension_path = extension->path();
vabr9142fe22016-09-08 13:19:221052 EXPECT_TRUE(cache_dir.GetPath().IsParent(extension_path));
[email protected]5a145e82014-05-29 22:19:071053 EXPECT_TRUE(base::PathExists(extension_path));
1054
1055 std::string extension_id = extension->id();
1056 UninstallExtension(extension_id);
gpdavis.chromium48f08c42014-09-18 22:09:341057 ExtensionRegistry* registry = ExtensionRegistry::Get(
1058 browser()->profile());
1059 EXPECT_FALSE(registry->enabled_extensions().GetByID(extension_id));
[email protected]5a145e82014-05-29 22:19:071060
Gabriel Charette01507a22017-09-27 21:30:081061 content::RunAllTasksUntilIdle();
[email protected]5a145e82014-05-29 22:19:071062
1063 EXPECT_FALSE(base::PathExists(extension_path));
1064}
1065#endif
1066
[email protected]658eae52014-06-14 20:28:051067IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, DoNotSync) {
[email protected]658eae52014-06-14 20:28:051068 scoped_refptr<CrxInstaller> crx_installer(
Minh X. Nguyen30975342017-12-04 22:02:411069 CrxInstaller::CreateSilent(extension_service()));
[email protected]c30bda262014-06-19 04:10:131070 crx_installer->set_do_not_sync(true);
[email protected]658eae52014-06-14 20:28:051071 crx_installer->InstallCrx(test_data_dir_.AppendASCII("good.crx"));
1072 EXPECT_TRUE(WaitForCrxInstallerDone());
1073 ASSERT_TRUE(crx_installer->extension());
1074
1075 const ExtensionPrefs* extension_prefs =
1076 ExtensionPrefs::Get(browser()->profile());
1077 EXPECT_TRUE(extension_prefs->DoNotSync(crx_installer->extension()->id()));
treibc644a1c2015-07-13 08:37:041078 EXPECT_FALSE(extensions::util::ShouldSync(crx_installer->extension(),
1079 browser()->profile()));
[email protected]658eae52014-06-14 20:28:051080}
1081
[email protected]253fc2bb2014-07-10 04:21:181082IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, ManagementPolicy) {
1083 ManagementPolicyMock policy;
1084 extensions::ExtensionSystem::Get(profile())
1085 ->management_policy()
1086 ->RegisterProvider(&policy);
1087
1088 base::FilePath crx_path = test_data_dir_.AppendASCII("crx_installer/v1.crx");
1089 EXPECT_FALSE(InstallExtension(crx_path, 0));
1090}
1091
dominickn675536f2015-11-06 03:25:381092IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, InstallWebApp) {
1093 InstallWebAppAndVerifyNoErrors();
1094}
1095
1096IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest,
1097 InstallWebAppSucceedsWithBlockPolicy) {
1098 // Verify that the install still works when a management policy blocking
1099 // extension installation is in force. Bookmark apps are special-cased to skip
1100 // these checks (see https://crbug.com/545541).
1101 ManagementPolicyMock policy;
1102 extensions::ExtensionSystem::Get(profile())
1103 ->management_policy()
1104 ->RegisterProvider(&policy);
1105
1106 InstallWebAppAndVerifyNoErrors();
1107}
1108
robbc66c4b2016-02-13 09:38:571109IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, UpdateWithFileAccess) {
1110 base::FilePath ext_source =
1111 test_data_dir_.AppendASCII("permissions").AppendASCII("files");
1112 base::FilePath crx_with_file_permission = PackExtension(ext_source);
1113 ASSERT_FALSE(crx_with_file_permission.empty());
1114
Minh X. Nguyen30975342017-12-04 22:02:411115 ExtensionService* service = extension_service();
robbc66c4b2016-02-13 09:38:571116
1117 const std::string extension_id("bdkapipdccfifhdghmblnenbbncfcpid");
1118 {
1119 // Install extension.
1120 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(service));
1121 installer->InstallCrx(crx_with_file_permission);
1122 EXPECT_TRUE(WaitForCrxInstallerDone());
1123 const Extension* extension = installer->extension();
1124 ASSERT_TRUE(extension);
1125 // IDs must match, otherwise the test doesn't make any sense.
1126 ASSERT_EQ(extension_id, extension->id());
1127 // Sanity check: File access should be disabled by default.
1128 EXPECT_FALSE(ExtensionPrefs::Get(profile())->AllowFileAccess(extension_id));
1129 EXPECT_FALSE(extension->creation_flags() & Extension::ALLOW_FILE_ACCESS);
1130 }
1131
1132 {
1133 // Uninstall and re-install the extension. Any previously granted file
1134 // permissions should be gone.
1135 ExtensionPrefs::Get(profile())->SetAllowFileAccess(extension_id, true);
1136 EXPECT_TRUE(ExtensionPrefs::Get(profile())->AllowFileAccess(extension_id));
1137 UninstallExtension(extension_id);
1138 EXPECT_FALSE(ExtensionPrefs::Get(profile())->AllowFileAccess(extension_id));
1139
1140 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(service));
1141 installer->InstallCrx(crx_with_file_permission);
1142 EXPECT_TRUE(WaitForCrxInstallerDone());
1143 const Extension* extension = installer->extension();
1144 ASSERT_TRUE(extension);
1145 ASSERT_EQ(extension_id, extension->id());
1146 EXPECT_FALSE(ExtensionPrefs::Get(profile())->AllowFileAccess(extension_id));
1147 EXPECT_FALSE(extension->creation_flags() & Extension::ALLOW_FILE_ACCESS);
1148 }
1149
1150 {
1151 // Grant file access and update the extension. File access should be kept.
1152 ExtensionPrefs::Get(profile())->SetAllowFileAccess(extension_id, true);
1153 EXPECT_TRUE(ExtensionPrefs::Get(profile())->AllowFileAccess(extension_id));
1154 base::FilePath crx_update_with_file_permission = PackExtension(ext_source);
1155
1156 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(service));
1157 installer->InstallCrx(crx_update_with_file_permission);
1158 EXPECT_TRUE(WaitForCrxInstallerDone());
1159 const Extension* extension = installer->extension();
1160 ASSERT_TRUE(extension);
1161 ASSERT_EQ(extension_id, extension->id());
1162 EXPECT_TRUE(ExtensionPrefs::Get(profile())->AllowFileAccess(extension_id));
1163 EXPECT_TRUE(extension->creation_flags() & Extension::ALLOW_FILE_ACCESS);
1164 }
1165}
1166
[email protected]bf3d9df2012-07-24 23:20:271167} // namespace extensions