blob: 53c1b8b771d7c4d10687e8433a20860f455c5a1f [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"
kalmanae342c92014-12-12 22:04:2312#include "base/files/file_path.h"
avia2f4804a2015-12-24 23:11:1313#include "base/macros.h"
dchengc963c7142016-04-08 03:55:2214#include "base/memory/ptr_util.h"
[email protected]f8636f92013-08-09 21:02:3715#include "base/memory/ref_counted.h"
gabf64a25e2017-05-12 19:42:5616#include "base/message_loop/message_loop.h"
Gabriel Charette53a9ef812017-07-26 12:36:2317#include "base/run_loop.h"
[email protected]253fc2bb2014-07-10 04:21:1818#include "base/strings/utf_string_conversions.h"
jam3f2d3932017-04-26 20:28:5119#include "base/threading/thread_restrictions.h"
avia2f4804a2015-12-24 23:11:1320#include "build/build_config.h"
[email protected]bf2fcd52012-04-16 22:59:3921#include "chrome/browser/download/download_crx_util.h"
[email protected]52b76592013-11-02 17:59:0322#include "chrome/browser/extensions/browser_action_test_util.h"
[email protected]a01e00632010-11-05 16:58:1423#include "chrome/browser/extensions/extension_browsertest.h"
[email protected]c82da8c42012-06-08 19:49:1124#include "chrome/browser/extensions/extension_install_prompt.h"
pkotwicz2f181782014-10-29 17:33:4525#include "chrome/browser/extensions/extension_install_prompt_show_params.h"
[email protected]eaa7dd182010-12-14 11:09:0026#include "chrome/browser/extensions/extension_service.h"
mekc95f9d062015-01-10 00:52:0427#include "chrome/browser/extensions/extension_tab_util.h"
[email protected]658eae52014-06-14 20:28:0528#include "chrome/browser/extensions/extension_util.h"
[email protected]3f2a2fa2013-09-24 02:55:2529#include "chrome/browser/extensions/fake_safe_browsing_database_manager.h"
gpdavis.chromium48f08c42014-09-18 22:09:3430#include "chrome/browser/extensions/test_extension_dir.h"
[email protected]8ecad5e2010-12-02 21:18:3331#include "chrome/browser/profiles/profile.h"
[email protected]2ad4a902010-11-17 06:05:1332#include "chrome/browser/ui/browser.h"
[email protected]619f86182012-07-03 21:30:1833#include "chrome/browser/ui/browser_window.h"
[email protected]91e51d612012-10-21 23:03:0534#include "chrome/browser/ui/tabs/tab_strip_model.h"
dominickn675536f2015-11-06 03:25:3835#include "chrome/common/web_application_info.h"
[email protected]af39f002014-08-22 10:18:1836#include "chrome/grit/generated_resources.h"
[email protected]af44e7fb2011-07-29 18:32:3237#include "chrome/test/base/ui_test_utils.h"
[email protected]5a145e82014-05-29 22:19:0738#include "content/public/browser/browser_thread.h"
[email protected]f34efa22013-03-05 19:14:2339#include "content/public/browser/download_manager.h"
[email protected]52b76592013-11-02 17:59:0340#include "content/public/browser/render_view_host.h"
[email protected]8ffad4e2014-01-02 23:18:2641#include "content/public/test/browser_test_utils.h"
[email protected]49b264f2012-08-14 17:12:2642#include "content/public/test/download_test_observer.h"
mtomaszf7d99a5c2014-09-15 16:23:4643#include "content/public/test/test_utils.h"
rdevlin.croninca5bf2da2015-12-17 21:21:0844#include "extensions/browser/extension_dialog_auto_confirm.h"
[email protected]dccba4f82014-05-29 00:52:5645#include "extensions/browser/extension_prefs.h"
gpdavis.chromium48f08c42014-09-18 22:09:3446#include "extensions/browser/extension_registry.h"
[email protected]59b0e602014-01-30 00:41:2447#include "extensions/browser/extension_system.h"
ginkage47e603e2015-02-27 08:42:4148#include "extensions/browser/install/crx_install_error.h"
[email protected]253fc2bb2014-07-10 04:21:1849#include "extensions/browser/management_policy.h"
[email protected]adf5a102014-07-31 12:44:0650#include "extensions/browser/notification_types.h"
[email protected]e4452d32013-11-15 23:07:4151#include "extensions/common/extension.h"
[email protected]5ef835a2013-11-08 20:42:5752#include "extensions/common/feature_switch.h"
[email protected]85df9d12014-04-15 17:02:1453#include "extensions/common/file_util.h"
kalmanae342c92014-12-12 22:04:2354#include "extensions/common/permissions/api_permission.h"
[email protected]5a55f3f2013-10-29 01:08:2955#include "extensions/common/permissions/permission_set.h"
kalmanae342c92014-12-12 22:04:2356#include "extensions/common/permissions/permissions_data.h"
[email protected]c8d02992013-07-31 22:16:5157#include "extensions/common/switches.h"
dominickn675536f2015-11-06 03:25:3858#include "third_party/skia/include/core/SkBitmap.h"
[email protected]a9736892012-05-30 15:58:0559#include "ui/base/l10n/l10n_util.h"
[email protected]a01e00632010-11-05 16:58:1460
[email protected]14a18bf2013-09-26 08:42:3061#if defined(OS_CHROMEOS)
merkulova793f3022015-02-04 10:18:3062#include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h"
[email protected]4d390782014-08-15 09:22:5863#include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
[email protected]5a145e82014-05-29 22:19:0764#include "chrome/browser/extensions/extension_assets_manager_chromeos.h"
65#include "chromeos/chromeos_switches.h"
[email protected]14a18bf2013-09-26 08:42:3066#endif
67
[email protected]7a5452f2010-12-13 23:03:1968class SkBitmap;
69
dominickn675536f2015-11-06 03:25:3870namespace {
71
72const char kAppUrl[] = "http://www.google.com";
73const char kAppTitle[] = "Test title";
74const char kAppDescription[] = "Test description";
75
76} // anonymous namespace
77
[email protected]bf3d9df2012-07-24 23:20:2778namespace extensions {
[email protected]b70a2d92012-06-28 19:51:2179
[email protected]a01e00632010-11-05 16:58:1480namespace {
81
[email protected]f8636f92013-08-09 21:02:3782class MockInstallPrompt;
83
84// This class holds information about things that happen with a
85// MockInstallPrompt. We create the MockInstallPrompt but need to pass
86// ownership of it to CrxInstaller, so it isn't safe to hang this data on
87// MockInstallPrompt itself becuase we can't guarantee it's lifetime.
rdevlin.croninca5bf2da2015-12-17 21:21:0888class MockPromptProxy {
[email protected]f8636f92013-08-09 21:02:3789 public:
90 explicit MockPromptProxy(content::WebContents* web_contents);
rdevlin.croninca5bf2da2015-12-17 21:21:0891 ~MockPromptProxy();
[email protected]f8636f92013-08-09 21:02:3792
93 bool did_succeed() const { return !extension_id_.empty(); }
94 const std::string& extension_id() { return extension_id_; }
95 bool confirmation_requested() const { return confirmation_requested_; }
[email protected]439f1e32013-12-09 20:09:0996 const base::string16& error() const { return error_; }
[email protected]f8636f92013-08-09 21:02:3797
[email protected]f8636f92013-08-09 21:02:3798 void set_extension_id(const std::string& id) { extension_id_ = id; }
rdevlin.croninca5bf2da2015-12-17 21:21:0899 void set_confirmation_requested(bool requested) {
100 confirmation_requested_ = requested;
101 }
[email protected]439f1e32013-12-09 20:09:09102 void set_error(const base::string16& error) { error_ = error; }
[email protected]f8636f92013-08-09 21:02:37103
dchengc963c7142016-04-08 03:55:22104 std::unique_ptr<ExtensionInstallPrompt> CreatePrompt();
[email protected]f8636f92013-08-09 21:02:37105
106 private:
[email protected]f8636f92013-08-09 21:02:37107
108 // Data used to create a prompt.
109 content::WebContents* web_contents_;
[email protected]f8636f92013-08-09 21:02:37110
111 // Data reported back to us by the prompt we created.
112 bool confirmation_requested_;
113 std::string extension_id_;
[email protected]439f1e32013-12-09 20:09:09114 base::string16 error_;
rdevlin.croninca5bf2da2015-12-17 21:21:08115
dchengc963c7142016-04-08 03:55:22116 std::unique_ptr<ScopedTestDialogAutoConfirm> auto_confirm;
rdevlin.croninca5bf2da2015-12-17 21:21:08117
118 DISALLOW_COPY_AND_ASSIGN(MockPromptProxy);
[email protected]f8636f92013-08-09 21:02:37119};
[email protected]bf2fcd52012-04-16 22:59:39120
dominickn675536f2015-11-06 03:25:38121SkBitmap CreateSquareBitmap(int size) {
122 SkBitmap bitmap;
123 bitmap.allocN32Pixels(size, size);
124 bitmap.eraseColor(SK_ColorRED);
125 return bitmap;
126}
127
128WebApplicationInfo::IconInfo CreateIconInfoWithBitmap(int size) {
129 WebApplicationInfo::IconInfo icon_info;
130 icon_info.width = size;
131 icon_info.height = size;
132 icon_info.data = CreateSquareBitmap(size);
133 return icon_info;
134}
135
136WebApplicationInfo CreateWebAppInfo(const char* title,
137 const char* description,
138 const char* app_url,
139 int size) {
140 WebApplicationInfo web_app_info;
141 web_app_info.title = base::UTF8ToUTF16(title);
142 web_app_info.description = base::UTF8ToUTF16(description);
143 web_app_info.app_url = GURL(app_url);
Giovanni Ortuño Urquidie7e79d452017-08-03 10:16:15144 web_app_info.scope = GURL(app_url);
dominickn675536f2015-11-06 03:25:38145
146 web_app_info.icons.push_back(CreateIconInfoWithBitmap(size));
147
148 return web_app_info;
149}
150
[email protected]c82da8c42012-06-08 19:49:11151class MockInstallPrompt : public ExtensionInstallPrompt {
[email protected]a01e00632010-11-05 16:58:14152 public:
[email protected]f8636f92013-08-09 21:02:37153 MockInstallPrompt(content::WebContents* web_contents,
154 MockPromptProxy* proxy) :
[email protected]91e51d612012-10-21 23:03:05155 ExtensionInstallPrompt(web_contents),
[email protected]f8636f92013-08-09 21:02:37156 proxy_(proxy) {}
[email protected]a01e00632010-11-05 16:58:14157
[email protected]a01e00632010-11-05 16:58:14158 // Overriding some of the ExtensionInstallUI API.
dchengae36a4a2014-10-21 12:36:36159 void OnInstallSuccess(const Extension* extension, SkBitmap* icon) override {
[email protected]f8636f92013-08-09 21:02:37160 proxy_->set_extension_id(extension->id());
rdevlin.croninca5bf2da2015-12-17 21:21:08161 proxy_->set_confirmation_requested(did_call_show_dialog());
Gabriel Charette53a9ef812017-07-26 12:36:23162 base::RunLoop::QuitCurrentWhenIdleDeprecated();
[email protected]a01e00632010-11-05 16:58:14163 }
ginkage47e603e2015-02-27 08:42:41164 void OnInstallFailure(const CrxInstallError& error) override {
[email protected]f8636f92013-08-09 21:02:37165 proxy_->set_error(error.message());
rdevlin.croninca5bf2da2015-12-17 21:21:08166 proxy_->set_confirmation_requested(did_call_show_dialog());
Gabriel Charette53a9ef812017-07-26 12:36:23167 base::RunLoop::QuitCurrentWhenIdleDeprecated();
[email protected]a01e00632010-11-05 16:58:14168 }
169
170 private:
rdevlin.croninca5bf2da2015-12-17 21:21:08171 MockPromptProxy* proxy_;
172
173 DISALLOW_COPY_AND_ASSIGN(MockInstallPrompt);
[email protected]a01e00632010-11-05 16:58:14174};
175
[email protected]658eae52014-06-14 20:28:05176MockPromptProxy::MockPromptProxy(content::WebContents* web_contents)
rdevlin.croninca5bf2da2015-12-17 21:21:08177 : web_contents_(web_contents),
178 confirmation_requested_(false),
179 auto_confirm(new ScopedTestDialogAutoConfirm(
180 ScopedTestDialogAutoConfirm::ACCEPT)) {
[email protected]f8636f92013-08-09 21:02:37181}
182
183MockPromptProxy::~MockPromptProxy() {}
184
dchengc963c7142016-04-08 03:55:22185std::unique_ptr<ExtensionInstallPrompt> MockPromptProxy::CreatePrompt() {
186 return std::unique_ptr<MockInstallPrompt>(
[email protected]f8636f92013-08-09 21:02:37187 new MockInstallPrompt(web_contents_, this));
[email protected]f8636f92013-08-09 21:02:37188}
189
dchengc963c7142016-04-08 03:55:22190std::unique_ptr<MockPromptProxy> CreateMockPromptProxyForBrowser(
[email protected]f8636f92013-08-09 21:02:37191 Browser* browser) {
ricea91d6fc122016-08-30 08:47:14192 return base::MakeUnique<MockPromptProxy>(
193 browser->tab_strip_model()->GetActiveWebContents());
[email protected]619f86182012-07-03 21:30:18194}
195
[email protected]253fc2bb2014-07-10 04:21:18196class ManagementPolicyMock : public extensions::ManagementPolicy::Provider {
197 public:
198 ManagementPolicyMock() {}
199
dchengae36a4a2014-10-21 12:36:36200 std::string GetDebugPolicyProviderName() const override {
[email protected]253fc2bb2014-07-10 04:21:18201 return "ManagementPolicyMock";
202 }
203
dchengae36a4a2014-10-21 12:36:36204 bool UserMayLoad(const Extension* extension,
205 base::string16* error) const override {
Karan Bhatia2a117232017-08-23 00:24:56206 if (error)
207 *error = base::UTF8ToUTF16("Dummy error message");
[email protected]253fc2bb2014-07-10 04:21:18208 return false;
209 }
210};
211
[email protected]a01e00632010-11-05 16:58:14212} // namespace
213
214class ExtensionCrxInstallerTest : public ExtensionBrowserTest {
kalmanae342c92014-12-12 22:04:23215 protected:
dchengc963c7142016-04-08 03:55:22216 std::unique_ptr<WebstoreInstaller::Approval> GetApproval(
[email protected]85290822013-08-23 20:27:38217 const char* manifest_dir,
[email protected]b70a2d92012-06-28 19:51:21218 const std::string& id,
[email protected]85290822013-08-23 20:27:38219 bool strict_manifest_checks) {
dchengc963c7142016-04-08 03:55:22220 std::unique_ptr<WebstoreInstaller::Approval> result;
[email protected]85290822013-08-23 20:27:38221
jam3f2d3932017-04-26 20:28:51222 base::ThreadRestrictions::ScopedAllowIO allow_io;
[email protected]85290822013-08-23 20:27:38223 base::FilePath ext_path = test_data_dir_.AppendASCII(manifest_dir);
224 std::string error;
dchengc963c7142016-04-08 03:55:22225 std::unique_ptr<base::DictionaryValue> parsed_manifest(
[email protected]85df9d12014-04-15 17:02:14226 file_util::LoadManifest(ext_path, &error));
[email protected]85290822013-08-23 20:27:38227 if (!parsed_manifest.get() || !error.empty())
dcheng1fc00f12015-12-26 22:18:03228 return result;
[email protected]85290822013-08-23 20:27:38229
230 return WebstoreInstaller::Approval::CreateWithNoInstallPrompt(
dcheng1fc00f12015-12-26 22:18:03231 browser()->profile(), id, std::move(parsed_manifest),
[email protected]85290822013-08-23 20:27:38232 strict_manifest_checks);
233 }
234
235 void RunCrxInstaller(const WebstoreInstaller::Approval* approval,
dchengc963c7142016-04-08 03:55:22236 std::unique_ptr<ExtensionInstallPrompt> prompt,
[email protected]85290822013-08-23 20:27:38237 const base::FilePath& crx_path) {
[email protected]06bdd2b2012-11-30 18:47:13238 ExtensionService* service = extensions::ExtensionSystem::Get(
239 browser()->profile())->extension_service();
[email protected]a01e00632010-11-05 16:58:14240 scoped_refptr<CrxInstaller> installer(
dcheng1fc00f12015-12-26 22:18:03241 CrxInstaller::Create(service, std::move(prompt), approval));
[email protected]a01e00632010-11-05 16:58:14242 installer->set_allow_silent_install(true);
[email protected]b1f04cc2010-11-10 22:59:30243 installer->set_is_gallery_install(true);
[email protected]85290822013-08-23 20:27:38244 installer->InstallCrx(crx_path);
[email protected]729eb632012-07-26 04:45:26245 content::RunMessageLoop();
[email protected]85290822013-08-23 20:27:38246 }
247
248 // Installs a crx from |crx_relpath| (a path relative to the extension test
249 // data dir) with expected id |id|.
250 void InstallWithPrompt(const char* ext_relpath,
251 const std::string& id,
rdevlin.croninca5bf2da2015-12-17 21:21:08252 MockPromptProxy* mock_install_prompt) {
[email protected]85290822013-08-23 20:27:38253 base::FilePath ext_path = test_data_dir_.AppendASCII(ext_relpath);
254
dchengc963c7142016-04-08 03:55:22255 std::unique_ptr<WebstoreInstaller::Approval> approval;
[email protected]85290822013-08-23 20:27:38256 if (!id.empty())
257 approval = GetApproval(ext_relpath, id, true);
258
259 base::FilePath crx_path = PackExtension(ext_path);
260 EXPECT_FALSE(crx_path.empty());
261 RunCrxInstaller(approval.get(), mock_install_prompt->CreatePrompt(),
262 crx_path);
[email protected]a01e00632010-11-05 16:58:14263
[email protected]c82da8c42012-06-08 19:49:11264 EXPECT_TRUE(mock_install_prompt->did_succeed());
[email protected]b70a2d92012-06-28 19:51:21265 }
266
267 // Installs an extension and checks that it has scopes granted IFF
268 // |record_oauth2_grant| is true.
269 void CheckHasEmptyScopesAfterInstall(const std::string& ext_relpath,
270 bool record_oauth2_grant) {
dchengc963c7142016-04-08 03:55:22271 std::unique_ptr<MockPromptProxy> mock_prompt =
[email protected]f8636f92013-08-09 21:02:37272 CreateMockPromptProxyForBrowser(browser());
273
rdevlin.croninca5bf2da2015-12-17 21:21:08274 InstallWithPrompt("browsertest/scopes", std::string(), mock_prompt.get());
[email protected]b70a2d92012-06-28 19:51:21275
dchengc963c7142016-04-08 03:55:22276 std::unique_ptr<const PermissionSet> permissions =
[email protected]7c82539c2014-02-19 06:09:17277 ExtensionPrefs::Get(browser()->profile())
278 ->GetGrantedPermissions(mock_prompt->extension_id());
[email protected]b70a2d92012-06-28 19:51:21279 ASSERT_TRUE(permissions.get());
[email protected]a01e00632010-11-05 16:58:14280 }
kalmanae342c92014-12-12 22:04:23281
dominickn675536f2015-11-06 03:25:38282 void InstallWebAppAndVerifyNoErrors() {
283 ExtensionService* service =
284 extensions::ExtensionSystem::Get(browser()->profile())
285 ->extension_service();
286 scoped_refptr<CrxInstaller> crx_installer(
287 CrxInstaller::CreateSilent(service));
288 crx_installer->set_error_on_unsupported_requirements(true);
289 crx_installer->InstallWebApp(
290 CreateWebAppInfo(kAppTitle, kAppDescription, kAppUrl, 64));
291 EXPECT_TRUE(WaitForCrxInstallerDone());
292 ASSERT_TRUE(crx_installer->extension());
dominickn675536f2015-11-06 03:25:38293 }
[email protected]a01e00632010-11-05 16:58:14294};
295
voodoo6ede9072016-03-09 07:47:53296class ExtensionCrxInstallerTestWithExperimentalApis
297 : public ExtensionCrxInstallerTest {
298 protected:
299 void SetUpCommandLine(base::CommandLine* command_line) override {
300 ExtensionCrxInstallerTest::SetUpCommandLine(command_line);
301 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
302 }
303};
304
[email protected]fc38935a2011-10-31 23:53:28305IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest,
kalmanae342c92014-12-12 22:04:23306 ExperimentalExtensionFromGallery) {
307 // Gallery-installed extensions should have their experimental permission
308 // preserved, since we allow the Webstore to make that decision.
voodoo6ede9072016-03-09 07:47:53309 const Extension* extension = InstallExtensionFromWebstore(
310 test_data_dir_.AppendASCII("experimental.crx"), 1);
kalmanae342c92014-12-12 22:04:23311 ASSERT_TRUE(extension);
312 EXPECT_TRUE(extension->permissions_data()->HasAPIPermission(
313 APIPermission::kExperimental));
314}
[email protected]240cc92a2011-12-01 01:22:24315
kalmanae342c92014-12-12 22:04:23316IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest,
317 ExperimentalExtensionFromOutsideGallery) {
318 // Non-gallery-installed extensions should lose their experimental
319 // permission if the flag isn't enabled.
voodoo6ede9072016-03-09 07:47:53320 const Extension* extension = InstallExtension(
321 test_data_dir_.AppendASCII("experimental.crx"), 1);
kalmanae342c92014-12-12 22:04:23322 ASSERT_TRUE(extension);
323 EXPECT_FALSE(extension->permissions_data()->HasAPIPermission(
324 APIPermission::kExperimental));
325}
[email protected]240cc92a2011-12-01 01:22:24326
voodoo6ede9072016-03-09 07:47:53327IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTestWithExperimentalApis,
kalmanae342c92014-12-12 22:04:23328 ExperimentalExtensionFromOutsideGalleryWithFlag) {
329 // Non-gallery-installed extensions should maintain their experimental
330 // permission if the flag is enabled.
voodoo6ede9072016-03-09 07:47:53331 const Extension* extension = InstallExtension(
332 test_data_dir_.AppendASCII("experimental.crx"), 1);
kalmanae342c92014-12-12 22:04:23333 ASSERT_TRUE(extension);
334 EXPECT_TRUE(extension->permissions_data()->HasAPIPermission(
335 APIPermission::kExperimental));
[email protected]fc38935a2011-10-31 23:53:28336}
[email protected]ee14cad2012-03-29 01:59:37337
voodoo6ede9072016-03-09 07:47:53338IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTestWithExperimentalApis,
339 PlatformAppCrx) {
[email protected]ee14cad2012-03-29 01:59:37340 EXPECT_TRUE(InstallExtension(
[email protected]dc37b002012-04-23 23:02:26341 test_data_dir_.AppendASCII("minimal_platform_app.crx"), 1));
[email protected]ee14cad2012-03-29 01:59:37342}
[email protected]bf2fcd52012-04-16 22:59:39343
meacerb040d3a2016-09-09 03:20:20344IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, BlockedFileTypes) {
345 const Extension* extension =
346 InstallExtension(test_data_dir_.AppendASCII("blocked_file_types.crx"), 1);
jam3f2d3932017-04-26 20:28:51347 base::ThreadRestrictions::ScopedAllowIO allow_io;
meacerb040d3a2016-09-09 03:20:20348 EXPECT_TRUE(base::PathExists(extension->path().AppendASCII("test.html")));
349 EXPECT_TRUE(base::PathExists(extension->path().AppendASCII("test.nexe")));
350 EXPECT_FALSE(base::PathExists(extension->path().AppendASCII("test1.EXE")));
351 EXPECT_FALSE(base::PathExists(extension->path().AppendASCII("test2.exe")));
352}
353
meacerbd735062016-09-28 19:58:37354IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, AllowedThemeFileTypes) {
355 const Extension* extension = InstallExtension(
356 test_data_dir_.AppendASCII("theme_with_extension.crx"), 1);
357 ASSERT_TRUE(extension);
358 const base::FilePath& path = extension->path();
jam3f2d3932017-04-26 20:28:51359 base::ThreadRestrictions::ScopedAllowIO allow_io;
meacerbd735062016-09-28 19:58:37360 EXPECT_TRUE(
361 base::PathExists(path.AppendASCII("images/theme_frame_camo.PNG")));
362 EXPECT_TRUE(
363 base::PathExists(path.AppendASCII("images/theme_ntp_background.png")));
364 EXPECT_TRUE(base::PathExists(
365 path.AppendASCII("images/theme_ntp_background_norepeat.png")));
366 EXPECT_TRUE(
367 base::PathExists(path.AppendASCII("images/theme_toolbar_camo.png")));
368 EXPECT_TRUE(base::PathExists(path.AppendASCII("images/redirect_target.GIF")));
369 EXPECT_TRUE(base::PathExists(path.AppendASCII("test.image.bmp")));
370 EXPECT_TRUE(
371 base::PathExists(path.AppendASCII("test_image_with_no_extension")));
372
373 EXPECT_FALSE(base::PathExists(path.AppendASCII("non_images/test.html")));
374 EXPECT_FALSE(base::PathExists(path.AppendASCII("non_images/test.nexe")));
375 EXPECT_FALSE(base::PathExists(path.AppendASCII("non_images/test1.EXE")));
376 EXPECT_FALSE(base::PathExists(path.AppendASCII("non_images/test2.exe")));
377 EXPECT_FALSE(base::PathExists(path.AppendASCII("non_images/test.txt")));
378 EXPECT_FALSE(base::PathExists(path.AppendASCII("non_images/test.css")));
379}
380
rdevlin.cronin10f34542017-02-06 18:22:47381IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest,
382 PackAndInstallExtensionFromDownload) {
383 std::unique_ptr<base::AutoReset<bool>> allow_offstore_install =
384 download_crx_util::OverrideOffstoreInstallAllowedForTesting(true);
[email protected]89019d62012-05-17 18:47:09385
[email protected]bf2fcd52012-04-16 22:59:39386 const int kNumDownloadsExpected = 1;
[email protected]bf2fcd52012-04-16 22:59:39387
[email protected]650b2d52013-02-10 03:41:45388 base::FilePath crx_path = PackExtension(
[email protected]bf2fcd52012-04-16 22:59:39389 test_data_dir_.AppendASCII("common/background_page"));
390 ASSERT_FALSE(crx_path.empty());
391 std::string crx_path_string(crx_path.value().begin(), crx_path.value().end());
392 GURL url = GURL(std::string("file:///").append(crx_path_string));
393
dchengc963c7142016-04-08 03:55:22394 std::unique_ptr<MockPromptProxy> mock_prompt =
[email protected]f8636f92013-08-09 21:02:37395 CreateMockPromptProxyForBrowser(browser());
396 download_crx_util::SetMockInstallPromptForTesting(
397 mock_prompt->CreatePrompt());
[email protected]bf2fcd52012-04-16 22:59:39398
[email protected]bf2fcd52012-04-16 22:59:39399 content::DownloadManager* download_manager =
[email protected]b441a8492012-06-06 14:55:57400 content::BrowserContext::GetDownloadManager(browser()->profile());
[email protected]bf2fcd52012-04-16 22:59:39401
dchengc963c7142016-04-08 03:55:22402 std::unique_ptr<content::DownloadTestObserver> observer(
[email protected]49b264f2012-08-14 17:12:26403 new content::DownloadTestObserverTerminal(
[email protected]47665442012-07-27 02:31:22404 download_manager, kNumDownloadsExpected,
[email protected]49b264f2012-08-14 17:12:26405 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT));
nick3b04f322016-08-31 19:29:19406 ui_test_utils::NavigateToURLWithDisposition(
407 browser(), url, WindowOpenDisposition::CURRENT_TAB,
[email protected]bf2fcd52012-04-16 22:59:39408 ui_test_utils::BROWSER_TEST_NONE);
409
[email protected]8c6af5b2012-06-15 20:10:26410 EXPECT_TRUE(WaitForCrxInstallerDone());
[email protected]c82da8c42012-06-08 19:49:11411 EXPECT_TRUE(mock_prompt->confirmation_requested());
[email protected]bf2fcd52012-04-16 22:59:39412}
[email protected]a9736892012-05-30 15:58:05413
[email protected]b70a2d92012-06-28 19:51:21414// Tests that scopes are only granted if |record_oauth2_grant_| on the prompt is
415// true.
[email protected]7a561912012-08-21 21:06:05416#if defined(OS_WIN)
[email protected]1e09ec82012-12-21 22:48:09417#define MAYBE_GrantScopes DISABLED_GrantScopes
[email protected]7a561912012-08-21 21:06:05418#else
419#define MAYBE_GrantScopes GrantScopes
420#endif
voodoo6ede9072016-03-09 07:47:53421IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTestWithExperimentalApis,
422 MAYBE_GrantScopes) {
[email protected]b70a2d92012-06-28 19:51:21423 EXPECT_NO_FATAL_FAILURE(CheckHasEmptyScopesAfterInstall("browsertest/scopes",
424 true));
425}
426
voodoo6ede9072016-03-09 07:47:53427IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTestWithExperimentalApis,
428 DoNotGrantScopes) {
[email protected]b70a2d92012-06-28 19:51:21429 EXPECT_NO_FATAL_FAILURE(CheckHasEmptyScopesAfterInstall("browsertest/scopes",
430 false));
431}
432
[email protected]d4b4d7af2014-08-20 10:45:15433IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, AllowOffStore) {
[email protected]06bdd2b2012-11-30 18:47:13434 ExtensionService* service = extensions::ExtensionSystem::Get(
435 browser()->profile())->extension_service();
[email protected]a9736892012-05-30 15:58:05436 const bool kTestData[] = {false, true};
437
438 for (size_t i = 0; i < arraysize(kTestData); ++i) {
dchengc963c7142016-04-08 03:55:22439 std::unique_ptr<MockPromptProxy> mock_prompt =
[email protected]f8636f92013-08-09 21:02:37440 CreateMockPromptProxyForBrowser(browser());
441
[email protected]a9736892012-05-30 15:58:05442 scoped_refptr<CrxInstaller> crx_installer(
[email protected]f8636f92013-08-09 21:02:37443 CrxInstaller::Create(service, mock_prompt->CreatePrompt()));
[email protected]7224dbd2012-06-05 15:21:50444 crx_installer->set_install_cause(
445 extension_misc::INSTALL_CAUSE_USER_DOWNLOAD);
[email protected]d9039812012-06-09 06:05:48446
447 if (kTestData[i]) {
448 crx_installer->set_off_store_install_allow_reason(
449 CrxInstaller::OffStoreInstallAllowedInTest);
450 }
[email protected]a9736892012-05-30 15:58:05451
452 crx_installer->InstallCrx(test_data_dir_.AppendASCII("good.crx"));
[email protected]d4b4d7af2014-08-20 10:45:15453 // The |mock_prompt| will quit running the loop once the |crx_installer|
454 // is done.
455 content::RunMessageLoop();
[email protected]c82da8c42012-06-08 19:49:11456 EXPECT_EQ(kTestData[i], mock_prompt->did_succeed());
457 EXPECT_EQ(kTestData[i], mock_prompt->confirmation_requested()) <<
458 kTestData[i];
[email protected]a9736892012-05-30 15:58:05459 if (kTestData[i]) {
[email protected]b959d7d42013-12-13 17:26:37460 EXPECT_EQ(base::string16(), mock_prompt->error()) << kTestData[i];
[email protected]a9736892012-05-30 15:58:05461 } else {
462 EXPECT_EQ(l10n_util::GetStringUTF16(
463 IDS_EXTENSION_INSTALL_DISALLOWED_ON_SITE),
[email protected]c82da8c42012-06-08 19:49:11464 mock_prompt->error()) << kTestData[i];
[email protected]a9736892012-05-30 15:58:05465 }
466 }
[email protected]a9736892012-05-30 15:58:05467}
[email protected]bf3d9df2012-07-24 23:20:27468
[email protected]90d3c042013-06-06 10:10:39469IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, HiDpiThemeTest) {
470 base::FilePath crx_path = test_data_dir_.AppendASCII("theme_hidpi_crx");
471 crx_path = crx_path.AppendASCII("theme_hidpi.crx");
472
[email protected]658eae52014-06-14 20:28:05473 ASSERT_TRUE(InstallExtension(crx_path, 1));
[email protected]90d3c042013-06-06 10:10:39474
475 const std::string extension_id("gllekhaobjnhgeagipipnkpmmmpchacm");
gpdavis.chromium48f08c42014-09-18 22:09:34476 ExtensionRegistry* registry = ExtensionRegistry::Get(
477 browser()->profile());
[email protected]90d3c042013-06-06 10:10:39478 const extensions::Extension* extension =
gpdavis.chromium48f08c42014-09-18 22:09:34479 registry->enabled_extensions().GetByID(extension_id);
[email protected]90d3c042013-06-06 10:10:39480 ASSERT_TRUE(extension);
481 EXPECT_EQ(extension_id, extension->id());
482
483 UninstallExtension(extension_id);
gpdavis.chromium48f08c42014-09-18 22:09:34484 EXPECT_FALSE(registry->enabled_extensions().GetByID(extension_id));
[email protected]90d3c042013-06-06 10:10:39485}
486
[email protected]9e9c1d12013-07-31 01:58:12487IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest,
mekc95f9d062015-01-10 00:52:04488 InstallDelayedUntilNextUpdate) {
[email protected]9e9c1d12013-07-31 01:58:12489 const std::string extension_id("ldnnhddmnhbkjipkidpdiheffobcpfmf");
mekc95f9d062015-01-10 00:52:04490 base::FilePath base_path = test_data_dir_.AppendASCII("delayed_install");
491
[email protected]9e9c1d12013-07-31 01:58:12492 ExtensionSystem* extension_system = extensions::ExtensionSystem::Get(
493 browser()->profile());
494 ExtensionService* service = extension_system->extension_service();
495 ASSERT_TRUE(service);
gpdavis.chromium48f08c42014-09-18 22:09:34496 ExtensionRegistry* registry = ExtensionRegistry::Get(
497 browser()->profile());
498 ASSERT_TRUE(registry);
[email protected]9e9c1d12013-07-31 01:58:12499
500 // Install version 1 of the test extension. This extension does not have
501 // a background page but does have a browser action.
mekc95f9d062015-01-10 00:52:04502 base::FilePath v1_path = PackExtension(base_path.AppendASCII("v1"));
503 ASSERT_FALSE(v1_path.empty());
504 ASSERT_TRUE(InstallExtension(v1_path, 1));
[email protected]9e9c1d12013-07-31 01:58:12505 const extensions::Extension* extension =
gpdavis.chromium48f08c42014-09-18 22:09:34506 registry->enabled_extensions().GetByID(extension_id);
[email protected]9e9c1d12013-07-31 01:58:12507 ASSERT_TRUE(extension);
508 ASSERT_EQ(extension_id, extension->id());
509 ASSERT_EQ("1.0", extension->version()->GetString());
510
mekc95f9d062015-01-10 00:52:04511 // Make test extension non-idle by opening the extension's options page.
512 ExtensionTabUtil::OpenOptionsPage(extension, browser());
513 WaitForExtensionNotIdle(extension_id);
[email protected]9e9c1d12013-07-31 01:58:12514
515 // Install version 2 of the extension and check that it is indeed delayed.
mekc95f9d062015-01-10 00:52:04516 base::FilePath v2_path = PackExtension(base_path.AppendASCII("v2"));
517 ASSERT_FALSE(v2_path.empty());
518 ASSERT_TRUE(UpdateExtensionWaitForIdle(extension_id, v2_path, 0));
[email protected]9e9c1d12013-07-31 01:58:12519
520 ASSERT_EQ(1u, service->delayed_installs()->size());
gpdavis.chromium48f08c42014-09-18 22:09:34521 extension = registry->enabled_extensions().GetByID(extension_id);
[email protected]9e9c1d12013-07-31 01:58:12522 ASSERT_EQ("1.0", extension->version()->GetString());
523
mekc95f9d062015-01-10 00:52:04524 // Make the extension idle again by navigating away from the options page.
525 // This should not trigger the delayed install.
526 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
527 WaitForExtensionIdle(extension_id);
[email protected]9e9c1d12013-07-31 01:58:12528 ASSERT_EQ(1u, service->delayed_installs()->size());
mekc95f9d062015-01-10 00:52:04529 extension = registry->enabled_extensions().GetByID(extension_id);
530 ASSERT_EQ("1.0", extension->version()->GetString());
[email protected]9e9c1d12013-07-31 01:58:12531
532 // Install version 3 of the extension. Because the extension is idle,
533 // this install should succeed.
mekc95f9d062015-01-10 00:52:04534 base::FilePath v3_path = PackExtension(base_path.AppendASCII("v3"));
535 ASSERT_FALSE(v3_path.empty());
536 ASSERT_TRUE(UpdateExtensionWaitForIdle(extension_id, v3_path, 0));
gpdavis.chromium48f08c42014-09-18 22:09:34537 extension = registry->enabled_extensions().GetByID(extension_id);
[email protected]9e9c1d12013-07-31 01:58:12538 ASSERT_EQ("3.0", extension->version()->GetString());
539
540 // The version 2 delayed install should be cleaned up, and finishing
541 // delayed extension installation shouldn't break anything.
542 ASSERT_EQ(0u, service->delayed_installs()->size());
543 service->MaybeFinishDelayedInstallations();
gpdavis.chromium48f08c42014-09-18 22:09:34544 extension = registry->enabled_extensions().GetByID(extension_id);
[email protected]9e9c1d12013-07-31 01:58:12545 ASSERT_EQ("3.0", extension->version()->GetString());
546}
547
[email protected]e3767aa2013-11-08 23:49:07548#if defined(FULL_SAFE_BROWSING)
[email protected]9f3c8532013-07-31 19:52:07549IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, Blacklist) {
[email protected]3f2a2fa2013-09-24 02:55:25550 scoped_refptr<FakeSafeBrowsingDatabaseManager> blacklist_db(
551 new FakeSafeBrowsingDatabaseManager(true));
552 Blacklist::ScopedDatabaseManagerForTest scoped_blacklist_db(blacklist_db);
[email protected]9f3c8532013-07-31 19:52:07553
[email protected]3f2a2fa2013-09-24 02:55:25554 blacklist_db->SetUnsafe("gllekhaobjnhgeagipipnkpmmmpchacm");
[email protected]9f3c8532013-07-31 19:52:07555
556 base::FilePath crx_path = test_data_dir_.AppendASCII("theme_hidpi_crx")
557 .AppendASCII("theme_hidpi.crx");
558 EXPECT_FALSE(InstallExtension(crx_path, 0));
559}
[email protected]e3767aa2013-11-08 23:49:07560#endif
[email protected]9f3c8532013-07-31 19:52:07561
[email protected]85290822013-08-23 20:27:38562IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, NonStrictManifestCheck) {
dchengc963c7142016-04-08 03:55:22563 std::unique_ptr<MockPromptProxy> mock_prompt =
[email protected]85290822013-08-23 20:27:38564 CreateMockPromptProxyForBrowser(browser());
565
566 // We want to simulate the case where the webstore sends a more recent
567 // version of the manifest, but the downloaded .crx file is old since
568 // the newly published version hasn't fully propagated to all the download
569 // servers yet. So load the v2 manifest, but then install the v1 crx file.
570 std::string id = "lhnaeclnpobnlbjbgogdanmhadigfnjp";
dchengc963c7142016-04-08 03:55:22571 std::unique_ptr<WebstoreInstaller::Approval> approval =
[email protected]85290822013-08-23 20:27:38572 GetApproval("crx_installer/v2_no_permission_change/", id, false);
573
574 RunCrxInstaller(approval.get(), mock_prompt->CreatePrompt(),
575 test_data_dir_.AppendASCII("crx_installer/v1.crx"));
576
577 EXPECT_TRUE(mock_prompt->did_succeed());
578}
579
limasdfebff7fd02015-12-25 14:45:31580#if defined(OS_CHROMEOS)
[email protected]14a18bf2013-09-26 08:42:30581IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, KioskOnlyTest) {
limasdfebff7fd02015-12-25 14:45:31582 // kiosk_only is whitelisted from non-chromeos.
[email protected]14a18bf2013-09-26 08:42:30583 base::FilePath crx_path =
584 test_data_dir_.AppendASCII("kiosk/kiosk_only.crx");
585 EXPECT_FALSE(InstallExtension(crx_path, 0));
[email protected]14a18bf2013-09-26 08:42:30586 // Simulate ChromeOS kiosk mode. |scoped_user_manager| will take over
587 // lifetime of |user_manager|.
merkulova793f3022015-02-04 10:18:30588 chromeos::FakeChromeUserManager* fake_user_manager =
589 new chromeos::FakeChromeUserManager();
alemate3ffbde6f2015-11-03 02:02:55590 const AccountId account_id(AccountId::FromUserEmail("[email protected]"));
591 fake_user_manager->AddKioskAppUser(account_id);
592 fake_user_manager->LoginUser(account_id);
[email protected]14a18bf2013-09-26 08:42:30593 chromeos::ScopedUserManagerEnabler scoped_user_manager(fake_user_manager);
594 EXPECT_TRUE(InstallExtension(crx_path, 1));
[email protected]14a18bf2013-09-26 08:42:30595}
596
dpolukhincbd48d192015-06-04 14:09:37597IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, InstallToSharedLocation) {
avi3ef9ec9e2014-12-22 22:50:17598 base::CommandLine::ForCurrentProcess()->AppendSwitch(
[email protected]5a145e82014-05-29 22:19:07599 chromeos::switches::kEnableExtensionAssetsSharing);
600 base::ScopedTempDir cache_dir;
601 ASSERT_TRUE(cache_dir.CreateUniqueTempDir());
602 ExtensionAssetsManagerChromeOS::SetSharedInstallDirForTesting(
vabr9142fe22016-09-08 13:19:22603 cache_dir.GetPath());
[email protected]5a145e82014-05-29 22:19:07604
605 base::FilePath crx_path = test_data_dir_.AppendASCII("crx_installer/v1.crx");
606 const extensions::Extension* extension = InstallExtension(
607 crx_path, 1, extensions::Manifest::EXTERNAL_PREF);
608 base::FilePath extension_path = extension->path();
vabr9142fe22016-09-08 13:19:22609 EXPECT_TRUE(cache_dir.GetPath().IsParent(extension_path));
jam3f2d3932017-04-26 20:28:51610 base::ThreadRestrictions::ScopedAllowIO allow_io;
[email protected]5a145e82014-05-29 22:19:07611 EXPECT_TRUE(base::PathExists(extension_path));
612
613 std::string extension_id = extension->id();
614 UninstallExtension(extension_id);
gpdavis.chromium48f08c42014-09-18 22:09:34615 ExtensionRegistry* registry = ExtensionRegistry::Get(
616 browser()->profile());
617 EXPECT_FALSE(registry->enabled_extensions().GetByID(extension_id));
[email protected]5a145e82014-05-29 22:19:07618
mtomaszf7d99a5c2014-09-15 16:23:46619 content::RunAllBlockingPoolTasksUntilIdle();
[email protected]5a145e82014-05-29 22:19:07620
621 EXPECT_FALSE(base::PathExists(extension_path));
622}
623#endif
624
[email protected]658eae52014-06-14 20:28:05625IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, DoNotSync) {
626 ExtensionService* service = extensions::ExtensionSystem::Get(
627 browser()->profile())->extension_service();
628 scoped_refptr<CrxInstaller> crx_installer(
629 CrxInstaller::CreateSilent(service));
[email protected]c30bda262014-06-19 04:10:13630 crx_installer->set_do_not_sync(true);
[email protected]658eae52014-06-14 20:28:05631 crx_installer->InstallCrx(test_data_dir_.AppendASCII("good.crx"));
632 EXPECT_TRUE(WaitForCrxInstallerDone());
633 ASSERT_TRUE(crx_installer->extension());
634
635 const ExtensionPrefs* extension_prefs =
636 ExtensionPrefs::Get(browser()->profile());
637 EXPECT_TRUE(extension_prefs->DoNotSync(crx_installer->extension()->id()));
treibc644a1c2015-07-13 08:37:04638 EXPECT_FALSE(extensions::util::ShouldSync(crx_installer->extension(),
639 browser()->profile()));
[email protected]658eae52014-06-14 20:28:05640}
641
[email protected]253fc2bb2014-07-10 04:21:18642IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, ManagementPolicy) {
643 ManagementPolicyMock policy;
644 extensions::ExtensionSystem::Get(profile())
645 ->management_policy()
646 ->RegisterProvider(&policy);
647
648 base::FilePath crx_path = test_data_dir_.AppendASCII("crx_installer/v1.crx");
649 EXPECT_FALSE(InstallExtension(crx_path, 0));
650}
651
dominickn675536f2015-11-06 03:25:38652IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, InstallWebApp) {
653 InstallWebAppAndVerifyNoErrors();
654}
655
656IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest,
657 InstallWebAppSucceedsWithBlockPolicy) {
658 // Verify that the install still works when a management policy blocking
659 // extension installation is in force. Bookmark apps are special-cased to skip
660 // these checks (see https://crbug.com/545541).
661 ManagementPolicyMock policy;
662 extensions::ExtensionSystem::Get(profile())
663 ->management_policy()
664 ->RegisterProvider(&policy);
665
666 InstallWebAppAndVerifyNoErrors();
667}
668
robbc66c4b2016-02-13 09:38:57669IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, UpdateWithFileAccess) {
670 base::FilePath ext_source =
671 test_data_dir_.AppendASCII("permissions").AppendASCII("files");
672 base::FilePath crx_with_file_permission = PackExtension(ext_source);
673 ASSERT_FALSE(crx_with_file_permission.empty());
674
675 ExtensionService* service =
676 extensions::ExtensionSystem::Get(browser()->profile())
677 ->extension_service();
678
679 const std::string extension_id("bdkapipdccfifhdghmblnenbbncfcpid");
680 {
681 // Install extension.
682 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(service));
683 installer->InstallCrx(crx_with_file_permission);
684 EXPECT_TRUE(WaitForCrxInstallerDone());
685 const Extension* extension = installer->extension();
686 ASSERT_TRUE(extension);
687 // IDs must match, otherwise the test doesn't make any sense.
688 ASSERT_EQ(extension_id, extension->id());
689 // Sanity check: File access should be disabled by default.
690 EXPECT_FALSE(ExtensionPrefs::Get(profile())->AllowFileAccess(extension_id));
691 EXPECT_FALSE(extension->creation_flags() & Extension::ALLOW_FILE_ACCESS);
692 }
693
694 {
695 // Uninstall and re-install the extension. Any previously granted file
696 // permissions should be gone.
697 ExtensionPrefs::Get(profile())->SetAllowFileAccess(extension_id, true);
698 EXPECT_TRUE(ExtensionPrefs::Get(profile())->AllowFileAccess(extension_id));
699 UninstallExtension(extension_id);
700 EXPECT_FALSE(ExtensionPrefs::Get(profile())->AllowFileAccess(extension_id));
701
702 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(service));
703 installer->InstallCrx(crx_with_file_permission);
704 EXPECT_TRUE(WaitForCrxInstallerDone());
705 const Extension* extension = installer->extension();
706 ASSERT_TRUE(extension);
707 ASSERT_EQ(extension_id, extension->id());
708 EXPECT_FALSE(ExtensionPrefs::Get(profile())->AllowFileAccess(extension_id));
709 EXPECT_FALSE(extension->creation_flags() & Extension::ALLOW_FILE_ACCESS);
710 }
711
712 {
713 // Grant file access and update the extension. File access should be kept.
714 ExtensionPrefs::Get(profile())->SetAllowFileAccess(extension_id, true);
715 EXPECT_TRUE(ExtensionPrefs::Get(profile())->AllowFileAccess(extension_id));
716 base::FilePath crx_update_with_file_permission = PackExtension(ext_source);
717
718 scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(service));
719 installer->InstallCrx(crx_update_with_file_permission);
720 EXPECT_TRUE(WaitForCrxInstallerDone());
721 const Extension* extension = installer->extension();
722 ASSERT_TRUE(extension);
723 ASSERT_EQ(extension_id, extension->id());
724 EXPECT_TRUE(ExtensionPrefs::Get(profile())->AllowFileAccess(extension_id));
725 EXPECT_TRUE(extension->creation_flags() & Extension::ALLOW_FILE_ACCESS);
726 }
727}
728
[email protected]bf3d9df2012-07-24 23:20:27729} // namespace extensions