[email protected] | 3538533 | 2012-03-28 02:32:03 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | a01e0063 | 2010-11-05 16:58:14 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
mtomasz | f7d99a5c | 2014-09-15 16:23:46 | [diff] [blame] | 5 | #include "chrome/browser/extensions/crx_installer.h" |
| 6 | |
avi | a2f4804a | 2015-12-24 23:11:13 | [diff] [blame] | 7 | #include <stddef.h> |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 8 | |
dcheng | 1fc00f1 | 2015-12-26 22:18:03 | [diff] [blame] | 9 | #include <utility> |
avi | a2f4804a | 2015-12-24 23:11:13 | [diff] [blame] | 10 | |
[email protected] | 5a145e8 | 2014-05-29 22:19:07 | [diff] [blame] | 11 | #include "base/at_exit.h" |
Sebastien Marchand | f1349f5 | 2019-01-25 03:16:41 | [diff] [blame] | 12 | #include "base/bind.h" |
kalman | ae342c9 | 2014-12-12 22:04:23 | [diff] [blame] | 13 | #include "base/files/file_path.h" |
Minh X. Nguyen | 2c17b398 | 2017-10-13 18:32:29 | [diff] [blame] | 14 | #include "base/files/scoped_temp_dir.h" |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 15 | #include "base/memory/ptr_util.h" |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 16 | #include "base/memory/ref_counted.h" |
Sergey Poromov | cc36238 | 2018-11-09 18:43:32 | [diff] [blame] | 17 | #include "base/optional.h" |
Gabriel Charette | 53a9ef81 | 2017-07-26 12:36:23 | [diff] [blame] | 18 | #include "base/run_loop.h" |
Avi Drissman | 5f0fb8c | 2018-12-25 23:20:49 | [diff] [blame] | 19 | #include "base/stl_util.h" |
[email protected] | 253fc2bb | 2014-07-10 04:21:18 | [diff] [blame] | 20 | #include "base/strings/utf_string_conversions.h" |
jam | 3f2d393 | 2017-04-26 20:28:51 | [diff] [blame] | 21 | #include "base/threading/thread_restrictions.h" |
avi | a2f4804a | 2015-12-24 23:11:13 | [diff] [blame] | 22 | #include "build/build_config.h" |
[email protected] | bf2fcd5 | 2012-04-16 22:59:39 | [diff] [blame] | 23 | #include "chrome/browser/download/download_crx_util.h" |
[email protected] | a01e0063 | 2010-11-05 16:58:14 | [diff] [blame] | 24 | #include "chrome/browser/extensions/extension_browsertest.h" |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 25 | #include "chrome/browser/extensions/extension_install_prompt.h" |
pkotwicz | 2f18178 | 2014-10-29 17:33:45 | [diff] [blame] | 26 | #include "chrome/browser/extensions/extension_install_prompt_show_params.h" |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 27 | #include "chrome/browser/extensions/extension_service.h" |
mek | c95f9d06 | 2015-01-10 00:52:04 | [diff] [blame] | 28 | #include "chrome/browser/extensions/extension_tab_util.h" |
[email protected] | 658eae5 | 2014-06-14 20:28:05 | [diff] [blame] | 29 | #include "chrome/browser/extensions/extension_util.h" |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 30 | #include "chrome/browser/extensions/fake_safe_browsing_database_manager.h" |
Oleg Davydov | c0086681 | 2019-04-04 10:47:27 | [diff] [blame] | 31 | #include "chrome/browser/extensions/forced_extensions/installation_reporter.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 32 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 2ad4a90 | 2010-11-17 06:05:13 | [diff] [blame] | 33 | #include "chrome/browser/ui/browser.h" |
[email protected] | 619f8618 | 2012-07-03 21:30:18 | [diff] [blame] | 34 | #include "chrome/browser/ui/browser_window.h" |
Christopher Lam | 851605b | 2018-02-09 05:24:04 | [diff] [blame] | 35 | #include "chrome/browser/ui/extensions/browser_action_test_util.h" |
[email protected] | 91e51d61 | 2012-10-21 23:03:05 | [diff] [blame] | 36 | #include "chrome/browser/ui/tabs/tab_strip_model.h" |
dominickn | 675536f | 2015-11-06 03:25:38 | [diff] [blame] | 37 | #include "chrome/common/web_application_info.h" |
[email protected] | af39f00 | 2014-08-22 10:18:18 | [diff] [blame] | 38 | #include "chrome/grit/generated_resources.h" |
[email protected] | af44e7fb | 2011-07-29 18:32:32 | [diff] [blame] | 39 | #include "chrome/test/base/ui_test_utils.h" |
Nico Weber | bc5b06f | 2019-07-26 14:00:13 | [diff] [blame] | 40 | #include "components/safe_browsing/buildflags.h" |
[email protected] | 5a145e8 | 2014-05-29 22:19:07 | [diff] [blame] | 41 | #include "content/public/browser/browser_thread.h" |
[email protected] | f34efa2 | 2013-03-05 19:14:23 | [diff] [blame] | 42 | #include "content/public/browser/download_manager.h" |
[email protected] | 52b7659 | 2013-11-02 17:59:03 | [diff] [blame] | 43 | #include "content/public/browser/render_view_host.h" |
[email protected] | 8ffad4e | 2014-01-02 23:18:26 | [diff] [blame] | 44 | #include "content/public/test/browser_test_utils.h" |
[email protected] | 49b264f | 2012-08-14 17:12:26 | [diff] [blame] | 45 | #include "content/public/test/download_test_observer.h" |
mtomasz | f7d99a5c | 2014-09-15 16:23:46 | [diff] [blame] | 46 | #include "content/public/test/test_utils.h" |
rdevlin.cronin | ca5bf2da | 2015-12-17 21:21:08 | [diff] [blame] | 47 | #include "extensions/browser/extension_dialog_auto_confirm.h" |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 48 | #include "extensions/browser/extension_prefs.h" |
gpdavis.chromium | 48f08c4 | 2014-09-18 22:09:34 | [diff] [blame] | 49 | #include "extensions/browser/extension_registry.h" |
[email protected] | 59b0e60 | 2014-01-30 00:41:24 | [diff] [blame] | 50 | #include "extensions/browser/extension_system.h" |
ginkage | 47e603e | 2015-02-27 08:42:41 | [diff] [blame] | 51 | #include "extensions/browser/install/crx_install_error.h" |
Minh X. Nguyen | 8803f4e | 2018-05-25 01:03:10 | [diff] [blame] | 52 | #include "extensions/browser/install/sandboxed_unpacker_failure_reason.h" |
[email protected] | 253fc2bb | 2014-07-10 04:21:18 | [diff] [blame] | 53 | #include "extensions/browser/management_policy.h" |
[email protected] | adf5a10 | 2014-07-31 12:44:06 | [diff] [blame] | 54 | #include "extensions/browser/notification_types.h" |
[email protected] | e4452d3 | 2013-11-15 23:07:41 | [diff] [blame] | 55 | #include "extensions/common/extension.h" |
Minh X. Nguyen | 3097534 | 2017-12-04 22:02:41 | [diff] [blame] | 56 | #include "extensions/common/extension_builder.h" |
[email protected] | 5ef835a | 2013-11-08 20:42:57 | [diff] [blame] | 57 | #include "extensions/common/feature_switch.h" |
[email protected] | 85df9d1 | 2014-04-15 17:02:14 | [diff] [blame] | 58 | #include "extensions/common/file_util.h" |
kalman | ae342c9 | 2014-12-12 22:04:23 | [diff] [blame] | 59 | #include "extensions/common/permissions/api_permission.h" |
[email protected] | 5a55f3f | 2013-10-29 01:08:29 | [diff] [blame] | 60 | #include "extensions/common/permissions/permission_set.h" |
kalman | ae342c9 | 2014-12-12 22:04:23 | [diff] [blame] | 61 | #include "extensions/common/permissions/permissions_data.h" |
[email protected] | c8d0299 | 2013-07-31 22:16:51 | [diff] [blame] | 62 | #include "extensions/common/switches.h" |
Devlin Cronin | 4f455a2 | 2018-01-25 01:36:45 | [diff] [blame] | 63 | #include "extensions/test/test_extension_dir.h" |
dominickn | 675536f | 2015-11-06 03:25:38 | [diff] [blame] | 64 | #include "third_party/skia/include/core/SkBitmap.h" |
[email protected] | a973689 | 2012-05-30 15:58:05 | [diff] [blame] | 65 | #include "ui/base/l10n/l10n_util.h" |
[email protected] | a01e0063 | 2010-11-05 16:58:14 | [diff] [blame] | 66 | |
[email protected] | 14a18bf | 2013-09-26 08:42:30 | [diff] [blame] | 67 | #if defined(OS_CHROMEOS) |
merkulova | 793f302 | 2015-02-04 10:18:30 | [diff] [blame] | 68 | #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" |
[email protected] | 5a145e8 | 2014-05-29 22:19:07 | [diff] [blame] | 69 | #include "chrome/browser/extensions/extension_assets_manager_chromeos.h" |
Steven Bennetts | 38e9bde2 | 2019-01-03 17:31:10 | [diff] [blame] | 70 | #include "chromeos/constants/chromeos_switches.h" |
Xiyuan Xia | dfe3a9f | 2017-11-13 21:46:26 | [diff] [blame] | 71 | #include "components/user_manager/scoped_user_manager.h" |
[email protected] | 14a18bf | 2013-09-26 08:42:30 | [diff] [blame] | 72 | #endif |
| 73 | |
[email protected] | 7a5452f | 2010-12-13 23:03:19 | [diff] [blame] | 74 | class SkBitmap; |
| 75 | |
dominickn | 675536f | 2015-11-06 03:25:38 | [diff] [blame] | 76 | namespace { |
| 77 | |
| 78 | const char kAppUrl[] = "http://www.google.com"; |
| 79 | const char kAppTitle[] = "Test title"; |
| 80 | const char kAppDescription[] = "Test description"; |
| 81 | |
| 82 | } // anonymous namespace |
| 83 | |
[email protected] | bf3d9df | 2012-07-24 23:20:27 | [diff] [blame] | 84 | namespace extensions { |
[email protected] | b70a2d9 | 2012-06-28 19:51:21 | [diff] [blame] | 85 | |
[email protected] | a01e0063 | 2010-11-05 16:58:14 | [diff] [blame] | 86 | namespace { |
| 87 | |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 88 | class 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.cronin | ca5bf2da | 2015-12-17 21:21:08 | [diff] [blame] | 94 | class MockPromptProxy { |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 95 | public: |
| 96 | explicit MockPromptProxy(content::WebContents* web_contents); |
rdevlin.cronin | ca5bf2da | 2015-12-17 21:21:08 | [diff] [blame] | 97 | ~MockPromptProxy(); |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 98 | |
| 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] | 439f1e3 | 2013-12-09 20:09:09 | [diff] [blame] | 102 | const base::string16& error() const { return error_; } |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 103 | |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 104 | void set_extension_id(const std::string& id) { extension_id_ = id; } |
rdevlin.cronin | ca5bf2da | 2015-12-17 21:21:08 | [diff] [blame] | 105 | void set_confirmation_requested(bool requested) { |
| 106 | confirmation_requested_ = requested; |
| 107 | } |
[email protected] | 439f1e3 | 2013-12-09 20:09:09 | [diff] [blame] | 108 | void set_error(const base::string16& error) { error_ = error; } |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 109 | |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 110 | std::unique_ptr<ExtensionInstallPrompt> CreatePrompt(); |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 111 | |
| 112 | private: |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 113 | |
| 114 | // Data used to create a prompt. |
| 115 | content::WebContents* web_contents_; |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 116 | |
| 117 | // Data reported back to us by the prompt we created. |
| 118 | bool confirmation_requested_; |
| 119 | std::string extension_id_; |
[email protected] | 439f1e3 | 2013-12-09 20:09:09 | [diff] [blame] | 120 | base::string16 error_; |
rdevlin.cronin | ca5bf2da | 2015-12-17 21:21:08 | [diff] [blame] | 121 | |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 122 | std::unique_ptr<ScopedTestDialogAutoConfirm> auto_confirm; |
rdevlin.cronin | ca5bf2da | 2015-12-17 21:21:08 | [diff] [blame] | 123 | |
| 124 | DISALLOW_COPY_AND_ASSIGN(MockPromptProxy); |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 125 | }; |
[email protected] | bf2fcd5 | 2012-04-16 22:59:39 | [diff] [blame] | 126 | |
dominickn | 675536f | 2015-11-06 03:25:38 | [diff] [blame] | 127 | SkBitmap CreateSquareBitmap(int size) { |
| 128 | SkBitmap bitmap; |
| 129 | bitmap.allocN32Pixels(size, size); |
| 130 | bitmap.eraseColor(SK_ColorRED); |
| 131 | return bitmap; |
| 132 | } |
| 133 | |
dominickn | 675536f | 2015-11-06 03:25:38 | [diff] [blame] | 134 | WebApplicationInfo CreateWebAppInfo(const char* title, |
| 135 | const char* description, |
| 136 | const char* app_url, |
| 137 | int size) { |
| 138 | WebApplicationInfo web_app_info; |
| 139 | web_app_info.title = base::UTF8ToUTF16(title); |
| 140 | web_app_info.description = base::UTF8ToUTF16(description); |
| 141 | web_app_info.app_url = GURL(app_url); |
Giovanni Ortuño Urquidi | e7e79d45 | 2017-08-03 10:16:15 | [diff] [blame] | 142 | web_app_info.scope = GURL(app_url); |
Alan Cutter | b891a62 | 2019-12-03 04:05:08 | [diff] [blame] | 143 | web_app_info.icon_bitmaps[size] = CreateSquareBitmap(size); |
dominickn | 675536f | 2015-11-06 03:25:38 | [diff] [blame] | 144 | |
| 145 | return web_app_info; |
| 146 | } |
| 147 | |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 148 | class MockInstallPrompt : public ExtensionInstallPrompt { |
[email protected] | a01e0063 | 2010-11-05 16:58:14 | [diff] [blame] | 149 | public: |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 150 | MockInstallPrompt(content::WebContents* web_contents, |
| 151 | MockPromptProxy* proxy) : |
[email protected] | 91e51d61 | 2012-10-21 23:03:05 | [diff] [blame] | 152 | ExtensionInstallPrompt(web_contents), |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 153 | proxy_(proxy) {} |
[email protected] | a01e0063 | 2010-11-05 16:58:14 | [diff] [blame] | 154 | |
[email protected] | a01e0063 | 2010-11-05 16:58:14 | [diff] [blame] | 155 | // Overriding some of the ExtensionInstallUI API. |
Dana Fried | c3c3022 | 2018-12-11 23:34:56 | [diff] [blame] | 156 | void OnInstallSuccess(scoped_refptr<const Extension> extension, |
| 157 | SkBitmap* icon) override { |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 158 | proxy_->set_extension_id(extension->id()); |
rdevlin.cronin | ca5bf2da | 2015-12-17 21:21:08 | [diff] [blame] | 159 | proxy_->set_confirmation_requested(did_call_show_dialog()); |
[email protected] | a01e0063 | 2010-11-05 16:58:14 | [diff] [blame] | 160 | } |
ginkage | 47e603e | 2015-02-27 08:42:41 | [diff] [blame] | 161 | void OnInstallFailure(const CrxInstallError& error) override { |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 162 | proxy_->set_error(error.message()); |
rdevlin.cronin | ca5bf2da | 2015-12-17 21:21:08 | [diff] [blame] | 163 | proxy_->set_confirmation_requested(did_call_show_dialog()); |
[email protected] | a01e0063 | 2010-11-05 16:58:14 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | private: |
rdevlin.cronin | ca5bf2da | 2015-12-17 21:21:08 | [diff] [blame] | 167 | MockPromptProxy* proxy_; |
| 168 | |
| 169 | DISALLOW_COPY_AND_ASSIGN(MockInstallPrompt); |
[email protected] | a01e0063 | 2010-11-05 16:58:14 | [diff] [blame] | 170 | }; |
| 171 | |
[email protected] | 658eae5 | 2014-06-14 20:28:05 | [diff] [blame] | 172 | MockPromptProxy::MockPromptProxy(content::WebContents* web_contents) |
rdevlin.cronin | ca5bf2da | 2015-12-17 21:21:08 | [diff] [blame] | 173 | : web_contents_(web_contents), |
| 174 | confirmation_requested_(false), |
| 175 | auto_confirm(new ScopedTestDialogAutoConfirm( |
| 176 | ScopedTestDialogAutoConfirm::ACCEPT)) { |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | MockPromptProxy::~MockPromptProxy() {} |
| 180 | |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 181 | std::unique_ptr<ExtensionInstallPrompt> MockPromptProxy::CreatePrompt() { |
| 182 | return std::unique_ptr<MockInstallPrompt>( |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 183 | new MockInstallPrompt(web_contents_, this)); |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 184 | } |
| 185 | |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 186 | std::unique_ptr<MockPromptProxy> CreateMockPromptProxyForBrowser( |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 187 | Browser* browser) { |
Jinho Bang | b5216cec | 2018-01-17 19:43:11 | [diff] [blame] | 188 | return std::make_unique<MockPromptProxy>( |
ricea | 91d6fc12 | 2016-08-30 08:47:14 | [diff] [blame] | 189 | browser->tab_strip_model()->GetActiveWebContents()); |
[email protected] | 619f8618 | 2012-07-03 21:30:18 | [diff] [blame] | 190 | } |
| 191 | |
[email protected] | 253fc2bb | 2014-07-10 04:21:18 | [diff] [blame] | 192 | class ManagementPolicyMock : public extensions::ManagementPolicy::Provider { |
| 193 | public: |
| 194 | ManagementPolicyMock() {} |
| 195 | |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 196 | std::string GetDebugPolicyProviderName() const override { |
[email protected] | 253fc2bb | 2014-07-10 04:21:18 | [diff] [blame] | 197 | return "ManagementPolicyMock"; |
| 198 | } |
| 199 | |
dcheng | ae36a4a | 2014-10-21 12:36:36 | [diff] [blame] | 200 | bool UserMayLoad(const Extension* extension, |
| 201 | base::string16* error) const override { |
Karan Bhatia | 2a11723 | 2017-08-23 00:24:56 | [diff] [blame] | 202 | if (error) |
| 203 | *error = base::UTF8ToUTF16("Dummy error message"); |
[email protected] | 253fc2bb | 2014-07-10 04:21:18 | [diff] [blame] | 204 | return false; |
| 205 | } |
| 206 | }; |
| 207 | |
[email protected] | a01e0063 | 2010-11-05 16:58:14 | [diff] [blame] | 208 | } // namespace |
| 209 | |
| 210 | class ExtensionCrxInstallerTest : public ExtensionBrowserTest { |
kalman | ae342c9 | 2014-12-12 22:04:23 | [diff] [blame] | 211 | protected: |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 212 | std::unique_ptr<WebstoreInstaller::Approval> GetApproval( |
[email protected] | 8529082 | 2013-08-23 20:27:38 | [diff] [blame] | 213 | const char* manifest_dir, |
[email protected] | b70a2d9 | 2012-06-28 19:51:21 | [diff] [blame] | 214 | const std::string& id, |
[email protected] | 8529082 | 2013-08-23 20:27:38 | [diff] [blame] | 215 | bool strict_manifest_checks) { |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 216 | std::unique_ptr<WebstoreInstaller::Approval> result; |
[email protected] | 8529082 | 2013-08-23 20:27:38 | [diff] [blame] | 217 | |
Minh X. Nguyen | 2c17b398 | 2017-10-13 18:32:29 | [diff] [blame] | 218 | base::ScopedAllowBlockingForTesting allow_io; |
[email protected] | 8529082 | 2013-08-23 20:27:38 | [diff] [blame] | 219 | base::FilePath ext_path = test_data_dir_.AppendASCII(manifest_dir); |
| 220 | std::string error; |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 221 | std::unique_ptr<base::DictionaryValue> parsed_manifest( |
[email protected] | 85df9d1 | 2014-04-15 17:02:14 | [diff] [blame] | 222 | file_util::LoadManifest(ext_path, &error)); |
[email protected] | 8529082 | 2013-08-23 20:27:38 | [diff] [blame] | 223 | if (!parsed_manifest.get() || !error.empty()) |
dcheng | 1fc00f1 | 2015-12-26 22:18:03 | [diff] [blame] | 224 | return result; |
[email protected] | 8529082 | 2013-08-23 20:27:38 | [diff] [blame] | 225 | |
| 226 | return WebstoreInstaller::Approval::CreateWithNoInstallPrompt( |
dcheng | 1fc00f1 | 2015-12-26 22:18:03 | [diff] [blame] | 227 | browser()->profile(), id, std::move(parsed_manifest), |
[email protected] | 8529082 | 2013-08-23 20:27:38 | [diff] [blame] | 228 | strict_manifest_checks); |
| 229 | } |
| 230 | |
Minh X. Nguyen | 3097534 | 2017-12-04 22:02:41 | [diff] [blame] | 231 | const Extension* GetInstalledExtension(const std::string& extension_id) { |
David Bertoni | 9f897c9 | 2019-09-20 17:46:35 | [diff] [blame] | 232 | return extension_registry()->GetInstalledExtension(extension_id); |
Minh X. Nguyen | 3097534 | 2017-12-04 22:02:41 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | std::unique_ptr<base::ScopedTempDir> UnpackedCrxTempDir() { |
| 236 | auto temp_dir = std::make_unique<base::ScopedTempDir>(); |
| 237 | EXPECT_TRUE(temp_dir->CreateUniqueTempDir()); |
| 238 | EXPECT_TRUE(base::PathExists(temp_dir->GetPath())); |
| 239 | |
Devlin Cronin | 19775cc | 2018-04-19 15:04:26 | [diff] [blame] | 240 | base::FilePath unpacked_path = |
| 241 | test_data_dir_.AppendASCII("simple_with_popup"); |
Minh X. Nguyen | 3097534 | 2017-12-04 22:02:41 | [diff] [blame] | 242 | EXPECT_TRUE(base::PathExists(unpacked_path)); |
| 243 | EXPECT_TRUE(base::CopyDirectory(unpacked_path, temp_dir->GetPath(), false)); |
| 244 | |
| 245 | return temp_dir; |
| 246 | } |
| 247 | |
| 248 | // Helper function that creates a file at |relative_path| within |directory| |
| 249 | // and fills it with |content|. |
| 250 | bool AddFileToDirectory(const base::FilePath& directory, |
| 251 | const base::FilePath& relative_path, |
| 252 | const std::string& content) const { |
| 253 | const base::FilePath full_path = directory.Append(relative_path); |
| 254 | if (!CreateDirectory(full_path.DirName())) |
| 255 | return false; |
| 256 | const int result = |
| 257 | base::WriteFile(full_path, content.data(), content.size()); |
| 258 | return (static_cast<size_t>(result) == content.size()); |
| 259 | } |
| 260 | |
| 261 | void AddExtension(const std::string& extension_id, |
| 262 | const std::string& version) { |
| 263 | base::ScopedTempDir temp_dir; |
| 264 | ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 265 | ASSERT_TRUE(base::PathExists(temp_dir.GetPath())); |
| 266 | |
| 267 | base::FilePath foo_js(FILE_PATH_LITERAL("foo.js")); |
| 268 | base::FilePath bar_html(FILE_PATH_LITERAL("bar/bar.html")); |
| 269 | ASSERT_TRUE(AddFileToDirectory(temp_dir.GetPath(), foo_js, "hello")) |
| 270 | << "Failed to write " << temp_dir.GetPath().value() << "/" |
| 271 | << foo_js.value(); |
| 272 | ASSERT_TRUE(AddFileToDirectory(temp_dir.GetPath(), bar_html, "world")); |
| 273 | |
| 274 | ExtensionBuilder builder; |
| 275 | builder.SetManifest(DictionaryBuilder() |
| 276 | .Set("name", "My First Extension") |
| 277 | .Set("version", version) |
| 278 | .Set("manifest_version", 2) |
| 279 | .Build()); |
| 280 | builder.SetID(extension_id); |
| 281 | builder.SetPath(temp_dir.GetPath()); |
| 282 | ExtensionRegistry::Get(browser()->profile())->AddEnabled(builder.Build()); |
| 283 | |
| 284 | const Extension* extension = GetInstalledExtension(extension_id); |
| 285 | ASSERT_NE(nullptr, extension); |
| 286 | ASSERT_EQ(version, extension->VersionString()); |
| 287 | } |
| 288 | |
| 289 | static void InstallerCallback(base::OnceClosure quit_closure, |
| 290 | CrxInstaller::InstallerResultCallback callback, |
Minh X. Nguyen | 8803f4e | 2018-05-25 01:03:10 | [diff] [blame] | 291 | const base::Optional<CrxInstallError>& error) { |
Minh X. Nguyen | 3097534 | 2017-12-04 22:02:41 | [diff] [blame] | 292 | if (!callback.is_null()) |
Minh X. Nguyen | 8803f4e | 2018-05-25 01:03:10 | [diff] [blame] | 293 | std::move(callback).Run(error); |
Minh X. Nguyen | 3097534 | 2017-12-04 22:02:41 | [diff] [blame] | 294 | std::move(quit_closure).Run(); |
| 295 | } |
| 296 | |
[email protected] | 8529082 | 2013-08-23 20:27:38 | [diff] [blame] | 297 | void RunCrxInstaller(const WebstoreInstaller::Approval* approval, |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 298 | std::unique_ptr<ExtensionInstallPrompt> prompt, |
Minh X. Nguyen | 2c17b398 | 2017-10-13 18:32:29 | [diff] [blame] | 299 | CrxInstaller::InstallerResultCallback callback, |
[email protected] | 8529082 | 2013-08-23 20:27:38 | [diff] [blame] | 300 | const base::FilePath& crx_path) { |
Minh X. Nguyen | 3097534 | 2017-12-04 22:02:41 | [diff] [blame] | 301 | base::RunLoop run_loop; |
| 302 | |
[email protected] | a01e0063 | 2010-11-05 16:58:14 | [diff] [blame] | 303 | scoped_refptr<CrxInstaller> installer( |
Minh X. Nguyen | 3097534 | 2017-12-04 22:02:41 | [diff] [blame] | 304 | CrxInstaller::Create(extension_service(), std::move(prompt), approval)); |
[email protected] | a01e0063 | 2010-11-05 16:58:14 | [diff] [blame] | 305 | installer->set_allow_silent_install(true); |
[email protected] | b1f04cc | 2010-11-10 22:59:30 | [diff] [blame] | 306 | installer->set_is_gallery_install(true); |
Minh X. Nguyen | 3097534 | 2017-12-04 22:02:41 | [diff] [blame] | 307 | installer->set_installer_callback( |
| 308 | base::BindOnce(&ExtensionCrxInstallerTest::InstallerCallback, |
| 309 | run_loop.QuitWhenIdleClosure(), std::move(callback))); |
[email protected] | 8529082 | 2013-08-23 20:27:38 | [diff] [blame] | 310 | installer->InstallCrx(crx_path); |
Minh X. Nguyen | 3097534 | 2017-12-04 22:02:41 | [diff] [blame] | 311 | |
| 312 | run_loop.Run(); |
[email protected] | 8529082 | 2013-08-23 20:27:38 | [diff] [blame] | 313 | } |
| 314 | |
Minh X. Nguyen | 2c17b398 | 2017-10-13 18:32:29 | [diff] [blame] | 315 | void RunCrxInstallerFromUnpackedDirectory( |
| 316 | std::unique_ptr<ExtensionInstallPrompt> prompt, |
| 317 | CrxInstaller::InstallerResultCallback callback, |
| 318 | const std::string& extension_id, |
| 319 | const std::string& public_key, |
| 320 | const base::FilePath& crx_directory) { |
Minh X. Nguyen | 3097534 | 2017-12-04 22:02:41 | [diff] [blame] | 321 | base::RunLoop run_loop; |
| 322 | |
Minh X. Nguyen | 2c17b398 | 2017-10-13 18:32:29 | [diff] [blame] | 323 | scoped_refptr<CrxInstaller> installer( |
Minh X. Nguyen | 3097534 | 2017-12-04 22:02:41 | [diff] [blame] | 324 | CrxInstaller::Create(extension_service(), std::move(prompt))); |
Minh X. Nguyen | 2c17b398 | 2017-10-13 18:32:29 | [diff] [blame] | 325 | installer->set_allow_silent_install(true); |
| 326 | installer->set_is_gallery_install(true); |
Minh X. Nguyen | 3097534 | 2017-12-04 22:02:41 | [diff] [blame] | 327 | installer->set_installer_callback( |
| 328 | base::BindOnce(&ExtensionCrxInstallerTest::InstallerCallback, |
| 329 | run_loop.QuitWhenIdleClosure(), std::move(callback))); |
Minh X. Nguyen | 2c17b398 | 2017-10-13 18:32:29 | [diff] [blame] | 330 | installer->set_delete_source(true); |
| 331 | installer->InstallUnpackedCrx(extension_id, public_key, crx_directory); |
Minh X. Nguyen | 3097534 | 2017-12-04 22:02:41 | [diff] [blame] | 332 | |
| 333 | run_loop.Run(); |
| 334 | } |
| 335 | |
| 336 | void RunUpdateExtension(std::unique_ptr<ExtensionInstallPrompt> prompt, |
| 337 | const std::string& extension_id, |
| 338 | const std::string& public_key, |
| 339 | const base::FilePath& unpacked_dir, |
| 340 | CrxInstaller::InstallerResultCallback callback) { |
| 341 | base::RunLoop run_loop; |
| 342 | |
| 343 | scoped_refptr<CrxInstaller> installer( |
| 344 | CrxInstaller::Create(extension_service(), std::move(prompt))); |
| 345 | installer->set_delete_source(true); |
| 346 | installer->set_installer_callback( |
| 347 | base::BindOnce(&ExtensionCrxInstallerTest::InstallerCallback, |
| 348 | run_loop.QuitWhenIdleClosure(), std::move(callback))); |
| 349 | installer->UpdateExtensionFromUnpackedCrx(extension_id, public_key, |
| 350 | unpacked_dir); |
| 351 | |
| 352 | run_loop.Run(); |
Minh X. Nguyen | 2c17b398 | 2017-10-13 18:32:29 | [diff] [blame] | 353 | } |
| 354 | |
[email protected] | 8529082 | 2013-08-23 20:27:38 | [diff] [blame] | 355 | // Installs a crx from |crx_relpath| (a path relative to the extension test |
| 356 | // data dir) with expected id |id|. |
| 357 | void InstallWithPrompt(const char* ext_relpath, |
| 358 | const std::string& id, |
Minh X. Nguyen | 2c17b398 | 2017-10-13 18:32:29 | [diff] [blame] | 359 | CrxInstaller::InstallerResultCallback callback, |
rdevlin.cronin | ca5bf2da | 2015-12-17 21:21:08 | [diff] [blame] | 360 | MockPromptProxy* mock_install_prompt) { |
[email protected] | 8529082 | 2013-08-23 20:27:38 | [diff] [blame] | 361 | base::FilePath ext_path = test_data_dir_.AppendASCII(ext_relpath); |
| 362 | |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 363 | std::unique_ptr<WebstoreInstaller::Approval> approval; |
[email protected] | 8529082 | 2013-08-23 20:27:38 | [diff] [blame] | 364 | if (!id.empty()) |
| 365 | approval = GetApproval(ext_relpath, id, true); |
| 366 | |
| 367 | base::FilePath crx_path = PackExtension(ext_path); |
| 368 | EXPECT_FALSE(crx_path.empty()); |
| 369 | RunCrxInstaller(approval.get(), mock_install_prompt->CreatePrompt(), |
Minh X. Nguyen | 2c17b398 | 2017-10-13 18:32:29 | [diff] [blame] | 370 | std::move(callback), crx_path); |
[email protected] | a01e0063 | 2010-11-05 16:58:14 | [diff] [blame] | 371 | |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 372 | EXPECT_TRUE(mock_install_prompt->did_succeed()); |
[email protected] | b70a2d9 | 2012-06-28 19:51:21 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | // Installs an extension and checks that it has scopes granted IFF |
| 376 | // |record_oauth2_grant| is true. |
Minh X. Nguyen | 2c17b398 | 2017-10-13 18:32:29 | [diff] [blame] | 377 | void CheckHasEmptyScopesAfterInstall( |
| 378 | const std::string& ext_relpath, |
| 379 | CrxInstaller::InstallerResultCallback callback, |
| 380 | bool record_oauth2_grant) { |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 381 | std::unique_ptr<MockPromptProxy> mock_prompt = |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 382 | CreateMockPromptProxyForBrowser(browser()); |
| 383 | |
Minh X. Nguyen | 2c17b398 | 2017-10-13 18:32:29 | [diff] [blame] | 384 | InstallWithPrompt("browsertest/scopes", std::string(), std::move(callback), |
| 385 | mock_prompt.get()); |
[email protected] | b70a2d9 | 2012-06-28 19:51:21 | [diff] [blame] | 386 | |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 387 | std::unique_ptr<const PermissionSet> permissions = |
[email protected] | 7c82539c | 2014-02-19 06:09:17 | [diff] [blame] | 388 | ExtensionPrefs::Get(browser()->profile()) |
| 389 | ->GetGrantedPermissions(mock_prompt->extension_id()); |
[email protected] | b70a2d9 | 2012-06-28 19:51:21 | [diff] [blame] | 390 | ASSERT_TRUE(permissions.get()); |
[email protected] | a01e0063 | 2010-11-05 16:58:14 | [diff] [blame] | 391 | } |
kalman | ae342c9 | 2014-12-12 22:04:23 | [diff] [blame] | 392 | |
dominickn | 675536f | 2015-11-06 03:25:38 | [diff] [blame] | 393 | void InstallWebAppAndVerifyNoErrors() { |
dominickn | 675536f | 2015-11-06 03:25:38 | [diff] [blame] | 394 | scoped_refptr<CrxInstaller> crx_installer( |
Minh X. Nguyen | 3097534 | 2017-12-04 22:02:41 | [diff] [blame] | 395 | CrxInstaller::CreateSilent(extension_service())); |
dominickn | 675536f | 2015-11-06 03:25:38 | [diff] [blame] | 396 | crx_installer->set_error_on_unsupported_requirements(true); |
| 397 | crx_installer->InstallWebApp( |
| 398 | CreateWebAppInfo(kAppTitle, kAppDescription, kAppUrl, 64)); |
| 399 | EXPECT_TRUE(WaitForCrxInstallerDone()); |
| 400 | ASSERT_TRUE(crx_installer->extension()); |
dominickn | 675536f | 2015-11-06 03:25:38 | [diff] [blame] | 401 | } |
[email protected] | a01e0063 | 2010-11-05 16:58:14 | [diff] [blame] | 402 | }; |
| 403 | |
voodoo | 6ede907 | 2016-03-09 07:47:53 | [diff] [blame] | 404 | class ExtensionCrxInstallerTestWithExperimentalApis |
| 405 | : public ExtensionCrxInstallerTest { |
| 406 | protected: |
| 407 | void SetUpCommandLine(base::CommandLine* command_line) override { |
| 408 | ExtensionCrxInstallerTest::SetUpCommandLine(command_line); |
| 409 | command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); |
| 410 | } |
| 411 | }; |
| 412 | |
[email protected] | fc38935a | 2011-10-31 23:53:28 | [diff] [blame] | 413 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, |
kalman | ae342c9 | 2014-12-12 22:04:23 | [diff] [blame] | 414 | ExperimentalExtensionFromGallery) { |
| 415 | // Gallery-installed extensions should have their experimental permission |
| 416 | // preserved, since we allow the Webstore to make that decision. |
voodoo | 6ede907 | 2016-03-09 07:47:53 | [diff] [blame] | 417 | const Extension* extension = InstallExtensionFromWebstore( |
| 418 | test_data_dir_.AppendASCII("experimental.crx"), 1); |
kalman | ae342c9 | 2014-12-12 22:04:23 | [diff] [blame] | 419 | ASSERT_TRUE(extension); |
| 420 | EXPECT_TRUE(extension->permissions_data()->HasAPIPermission( |
| 421 | APIPermission::kExperimental)); |
| 422 | } |
[email protected] | 240cc92a | 2011-12-01 01:22:24 | [diff] [blame] | 423 | |
kalman | ae342c9 | 2014-12-12 22:04:23 | [diff] [blame] | 424 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, |
| 425 | ExperimentalExtensionFromOutsideGallery) { |
| 426 | // Non-gallery-installed extensions should lose their experimental |
| 427 | // permission if the flag isn't enabled. |
voodoo | 6ede907 | 2016-03-09 07:47:53 | [diff] [blame] | 428 | const Extension* extension = InstallExtension( |
| 429 | test_data_dir_.AppendASCII("experimental.crx"), 1); |
kalman | ae342c9 | 2014-12-12 22:04:23 | [diff] [blame] | 430 | ASSERT_TRUE(extension); |
| 431 | EXPECT_FALSE(extension->permissions_data()->HasAPIPermission( |
| 432 | APIPermission::kExperimental)); |
| 433 | } |
[email protected] | 240cc92a | 2011-12-01 01:22:24 | [diff] [blame] | 434 | |
voodoo | 6ede907 | 2016-03-09 07:47:53 | [diff] [blame] | 435 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTestWithExperimentalApis, |
kalman | ae342c9 | 2014-12-12 22:04:23 | [diff] [blame] | 436 | ExperimentalExtensionFromOutsideGalleryWithFlag) { |
| 437 | // Non-gallery-installed extensions should maintain their experimental |
| 438 | // permission if the flag is enabled. |
voodoo | 6ede907 | 2016-03-09 07:47:53 | [diff] [blame] | 439 | const Extension* extension = InstallExtension( |
| 440 | test_data_dir_.AppendASCII("experimental.crx"), 1); |
kalman | ae342c9 | 2014-12-12 22:04:23 | [diff] [blame] | 441 | ASSERT_TRUE(extension); |
| 442 | EXPECT_TRUE(extension->permissions_data()->HasAPIPermission( |
| 443 | APIPermission::kExperimental)); |
[email protected] | fc38935a | 2011-10-31 23:53:28 | [diff] [blame] | 444 | } |
[email protected] | ee14cad | 2012-03-29 01:59:37 | [diff] [blame] | 445 | |
voodoo | 6ede907 | 2016-03-09 07:47:53 | [diff] [blame] | 446 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTestWithExperimentalApis, |
| 447 | PlatformAppCrx) { |
[email protected] | ee14cad | 2012-03-29 01:59:37 | [diff] [blame] | 448 | EXPECT_TRUE(InstallExtension( |
[email protected] | dc37b00 | 2012-04-23 23:02:26 | [diff] [blame] | 449 | test_data_dir_.AppendASCII("minimal_platform_app.crx"), 1)); |
[email protected] | ee14cad | 2012-03-29 01:59:37 | [diff] [blame] | 450 | } |
[email protected] | bf2fcd5 | 2012-04-16 22:59:39 | [diff] [blame] | 451 | |
meacer | b040d3a | 2016-09-09 03:20:20 | [diff] [blame] | 452 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, BlockedFileTypes) { |
| 453 | const Extension* extension = |
| 454 | InstallExtension(test_data_dir_.AppendASCII("blocked_file_types.crx"), 1); |
Minh X. Nguyen | 2c17b398 | 2017-10-13 18:32:29 | [diff] [blame] | 455 | base::ScopedAllowBlockingForTesting allow_io; |
meacer | b040d3a | 2016-09-09 03:20:20 | [diff] [blame] | 456 | EXPECT_TRUE(base::PathExists(extension->path().AppendASCII("test.html"))); |
| 457 | EXPECT_TRUE(base::PathExists(extension->path().AppendASCII("test.nexe"))); |
| 458 | EXPECT_FALSE(base::PathExists(extension->path().AppendASCII("test1.EXE"))); |
| 459 | EXPECT_FALSE(base::PathExists(extension->path().AppendASCII("test2.exe"))); |
| 460 | } |
| 461 | |
meacer | bd73506 | 2016-09-28 19:58:37 | [diff] [blame] | 462 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, AllowedThemeFileTypes) { |
| 463 | const Extension* extension = InstallExtension( |
| 464 | test_data_dir_.AppendASCII("theme_with_extension.crx"), 1); |
| 465 | ASSERT_TRUE(extension); |
| 466 | const base::FilePath& path = extension->path(); |
Minh X. Nguyen | 2c17b398 | 2017-10-13 18:32:29 | [diff] [blame] | 467 | base::ScopedAllowBlockingForTesting allow_io; |
meacer | bd73506 | 2016-09-28 19:58:37 | [diff] [blame] | 468 | EXPECT_TRUE( |
| 469 | base::PathExists(path.AppendASCII("images/theme_frame_camo.PNG"))); |
| 470 | EXPECT_TRUE( |
| 471 | base::PathExists(path.AppendASCII("images/theme_ntp_background.png"))); |
| 472 | EXPECT_TRUE(base::PathExists( |
| 473 | path.AppendASCII("images/theme_ntp_background_norepeat.png"))); |
| 474 | EXPECT_TRUE( |
| 475 | base::PathExists(path.AppendASCII("images/theme_toolbar_camo.png"))); |
| 476 | EXPECT_TRUE(base::PathExists(path.AppendASCII("images/redirect_target.GIF"))); |
| 477 | EXPECT_TRUE(base::PathExists(path.AppendASCII("test.image.bmp"))); |
| 478 | EXPECT_TRUE( |
| 479 | base::PathExists(path.AppendASCII("test_image_with_no_extension"))); |
| 480 | |
| 481 | EXPECT_FALSE(base::PathExists(path.AppendASCII("non_images/test.html"))); |
| 482 | EXPECT_FALSE(base::PathExists(path.AppendASCII("non_images/test.nexe"))); |
| 483 | EXPECT_FALSE(base::PathExists(path.AppendASCII("non_images/test1.EXE"))); |
| 484 | EXPECT_FALSE(base::PathExists(path.AppendASCII("non_images/test2.exe"))); |
| 485 | EXPECT_FALSE(base::PathExists(path.AppendASCII("non_images/test.txt"))); |
| 486 | EXPECT_FALSE(base::PathExists(path.AppendASCII("non_images/test.css"))); |
| 487 | } |
| 488 | |
rdevlin.cronin | 10f3454 | 2017-02-06 18:22:47 | [diff] [blame] | 489 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, |
| 490 | PackAndInstallExtensionFromDownload) { |
| 491 | std::unique_ptr<base::AutoReset<bool>> allow_offstore_install = |
| 492 | download_crx_util::OverrideOffstoreInstallAllowedForTesting(true); |
[email protected] | 89019d6 | 2012-05-17 18:47:09 | [diff] [blame] | 493 | |
[email protected] | bf2fcd5 | 2012-04-16 22:59:39 | [diff] [blame] | 494 | const int kNumDownloadsExpected = 1; |
[email protected] | bf2fcd5 | 2012-04-16 22:59:39 | [diff] [blame] | 495 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 496 | base::FilePath crx_path = PackExtension( |
[email protected] | bf2fcd5 | 2012-04-16 22:59:39 | [diff] [blame] | 497 | test_data_dir_.AppendASCII("common/background_page")); |
| 498 | ASSERT_FALSE(crx_path.empty()); |
| 499 | std::string crx_path_string(crx_path.value().begin(), crx_path.value().end()); |
| 500 | GURL url = GURL(std::string("file:///").append(crx_path_string)); |
| 501 | |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 502 | std::unique_ptr<MockPromptProxy> mock_prompt = |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 503 | CreateMockPromptProxyForBrowser(browser()); |
| 504 | download_crx_util::SetMockInstallPromptForTesting( |
| 505 | mock_prompt->CreatePrompt()); |
[email protected] | bf2fcd5 | 2012-04-16 22:59:39 | [diff] [blame] | 506 | |
[email protected] | bf2fcd5 | 2012-04-16 22:59:39 | [diff] [blame] | 507 | content::DownloadManager* download_manager = |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 508 | content::BrowserContext::GetDownloadManager(browser()->profile()); |
[email protected] | bf2fcd5 | 2012-04-16 22:59:39 | [diff] [blame] | 509 | |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 510 | std::unique_ptr<content::DownloadTestObserver> observer( |
[email protected] | 49b264f | 2012-08-14 17:12:26 | [diff] [blame] | 511 | new content::DownloadTestObserverTerminal( |
[email protected] | 4766544 | 2012-07-27 02:31:22 | [diff] [blame] | 512 | download_manager, kNumDownloadsExpected, |
[email protected] | 49b264f | 2012-08-14 17:12:26 | [diff] [blame] | 513 | content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
nick | 3b04f32 | 2016-08-31 19:29:19 | [diff] [blame] | 514 | ui_test_utils::NavigateToURLWithDisposition( |
| 515 | browser(), url, WindowOpenDisposition::CURRENT_TAB, |
[email protected] | bf2fcd5 | 2012-04-16 22:59:39 | [diff] [blame] | 516 | ui_test_utils::BROWSER_TEST_NONE); |
| 517 | |
[email protected] | 8c6af5b | 2012-06-15 20:10:26 | [diff] [blame] | 518 | EXPECT_TRUE(WaitForCrxInstallerDone()); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 519 | EXPECT_TRUE(mock_prompt->confirmation_requested()); |
[email protected] | bf2fcd5 | 2012-04-16 22:59:39 | [diff] [blame] | 520 | } |
[email protected] | a973689 | 2012-05-30 15:58:05 | [diff] [blame] | 521 | |
[email protected] | b70a2d9 | 2012-06-28 19:51:21 | [diff] [blame] | 522 | // Tests that scopes are only granted if |record_oauth2_grant_| on the prompt is |
| 523 | // true. |
[email protected] | 7a56191 | 2012-08-21 21:06:05 | [diff] [blame] | 524 | #if defined(OS_WIN) |
[email protected] | 1e09ec8 | 2012-12-21 22:48:09 | [diff] [blame] | 525 | #define MAYBE_GrantScopes DISABLED_GrantScopes |
Minh X. Nguyen | 2c17b398 | 2017-10-13 18:32:29 | [diff] [blame] | 526 | #define MAYBE_GrantScopes_WithCallback DISABLED_GrantScopes_WithCallback |
[email protected] | 7a56191 | 2012-08-21 21:06:05 | [diff] [blame] | 527 | #else |
| 528 | #define MAYBE_GrantScopes GrantScopes |
Minh X. Nguyen | 2c17b398 | 2017-10-13 18:32:29 | [diff] [blame] | 529 | #define MAYBE_GrantScopes_WithCallback GrantScopes_WithCallback |
[email protected] | 7a56191 | 2012-08-21 21:06:05 | [diff] [blame] | 530 | #endif |
voodoo | 6ede907 | 2016-03-09 07:47:53 | [diff] [blame] | 531 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTestWithExperimentalApis, |
| 532 | MAYBE_GrantScopes) { |
Minh X. Nguyen | 2c17b398 | 2017-10-13 18:32:29 | [diff] [blame] | 533 | EXPECT_NO_FATAL_FAILURE(CheckHasEmptyScopesAfterInstall( |
| 534 | "browsertest/scopes", CrxInstaller::InstallerResultCallback(), true)); |
| 535 | } |
| 536 | |
| 537 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTestWithExperimentalApis, |
| 538 | MAYBE_GrantScopes_WithCallback) { |
| 539 | EXPECT_NO_FATAL_FAILURE(CheckHasEmptyScopesAfterInstall( |
| 540 | "browsertest/scopes", |
Minh X. Nguyen | 8803f4e | 2018-05-25 01:03:10 | [diff] [blame] | 541 | base::BindOnce([](const base::Optional<CrxInstallError>& error) { |
| 542 | EXPECT_EQ(base::nullopt, error); |
| 543 | }), |
| 544 | true)); |
[email protected] | b70a2d9 | 2012-06-28 19:51:21 | [diff] [blame] | 545 | } |
| 546 | |
voodoo | 6ede907 | 2016-03-09 07:47:53 | [diff] [blame] | 547 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTestWithExperimentalApis, |
| 548 | DoNotGrantScopes) { |
Minh X. Nguyen | 2c17b398 | 2017-10-13 18:32:29 | [diff] [blame] | 549 | EXPECT_NO_FATAL_FAILURE(CheckHasEmptyScopesAfterInstall( |
| 550 | "browsertest/scopes", CrxInstaller::InstallerResultCallback(), false)); |
| 551 | } |
| 552 | |
| 553 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTestWithExperimentalApis, |
| 554 | DoNotGrantScopes_WithCallback) { |
| 555 | EXPECT_NO_FATAL_FAILURE(CheckHasEmptyScopesAfterInstall( |
| 556 | "browsertest/scopes", |
Minh X. Nguyen | 8803f4e | 2018-05-25 01:03:10 | [diff] [blame] | 557 | base::BindOnce([](const base::Optional<CrxInstallError>& error) { |
| 558 | EXPECT_EQ(base::nullopt, error); |
| 559 | }), |
| 560 | false)); |
[email protected] | b70a2d9 | 2012-06-28 19:51:21 | [diff] [blame] | 561 | } |
| 562 | |
[email protected] | d4b4d7af | 2014-08-20 10:45:15 | [diff] [blame] | 563 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, AllowOffStore) { |
[email protected] | a973689 | 2012-05-30 15:58:05 | [diff] [blame] | 564 | const bool kTestData[] = {false, true}; |
| 565 | |
Avi Drissman | 5f0fb8c | 2018-12-25 23:20:49 | [diff] [blame] | 566 | for (size_t i = 0; i < base::size(kTestData); ++i) { |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 567 | std::unique_ptr<MockPromptProxy> mock_prompt = |
[email protected] | f8636f9 | 2013-08-09 21:02:37 | [diff] [blame] | 568 | CreateMockPromptProxyForBrowser(browser()); |
| 569 | |
[email protected] | a973689 | 2012-05-30 15:58:05 | [diff] [blame] | 570 | scoped_refptr<CrxInstaller> crx_installer( |
Minh X. Nguyen | 3097534 | 2017-12-04 22:02:41 | [diff] [blame] | 571 | CrxInstaller::Create(extension_service(), mock_prompt->CreatePrompt())); |
[email protected] | 7224dbd | 2012-06-05 15:21:50 | [diff] [blame] | 572 | crx_installer->set_install_cause( |
| 573 | extension_misc::INSTALL_CAUSE_USER_DOWNLOAD); |
[email protected] | d903981 | 2012-06-09 06:05:48 | [diff] [blame] | 574 | |
| 575 | if (kTestData[i]) { |
| 576 | crx_installer->set_off_store_install_allow_reason( |
| 577 | CrxInstaller::OffStoreInstallAllowedInTest); |
| 578 | } |
[email protected] | a973689 | 2012-05-30 15:58:05 | [diff] [blame] | 579 | |
Minh X. Nguyen | 3097534 | 2017-12-04 22:02:41 | [diff] [blame] | 580 | base::RunLoop run_loop; |
| 581 | crx_installer->set_installer_callback( |
| 582 | base::BindOnce(&ExtensionCrxInstallerTest::InstallerCallback, |
| 583 | run_loop.QuitWhenIdleClosure(), |
| 584 | CrxInstaller::InstallerResultCallback())); |
[email protected] | a973689 | 2012-05-30 15:58:05 | [diff] [blame] | 585 | crx_installer->InstallCrx(test_data_dir_.AppendASCII("good.crx")); |
[email protected] | d4b4d7af | 2014-08-20 10:45:15 | [diff] [blame] | 586 | // The |mock_prompt| will quit running the loop once the |crx_installer| |
| 587 | // is done. |
Minh X. Nguyen | 3097534 | 2017-12-04 22:02:41 | [diff] [blame] | 588 | run_loop.Run(); |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 589 | EXPECT_EQ(kTestData[i], mock_prompt->did_succeed()); |
| 590 | EXPECT_EQ(kTestData[i], mock_prompt->confirmation_requested()) << |
| 591 | kTestData[i]; |
[email protected] | a973689 | 2012-05-30 15:58:05 | [diff] [blame] | 592 | if (kTestData[i]) { |
[email protected] | b959d7d4 | 2013-12-13 17:26:37 | [diff] [blame] | 593 | EXPECT_EQ(base::string16(), mock_prompt->error()) << kTestData[i]; |
[email protected] | a973689 | 2012-05-30 15:58:05 | [diff] [blame] | 594 | } else { |
| 595 | EXPECT_EQ(l10n_util::GetStringUTF16( |
| 596 | IDS_EXTENSION_INSTALL_DISALLOWED_ON_SITE), |
[email protected] | c82da8c4 | 2012-06-08 19:49:11 | [diff] [blame] | 597 | mock_prompt->error()) << kTestData[i]; |
[email protected] | a973689 | 2012-05-30 15:58:05 | [diff] [blame] | 598 | } |
| 599 | } |
[email protected] | a973689 | 2012-05-30 15:58:05 | [diff] [blame] | 600 | } |
[email protected] | bf3d9df | 2012-07-24 23:20:27 | [diff] [blame] | 601 | |
[email protected] | 90d3c04 | 2013-06-06 10:10:39 | [diff] [blame] | 602 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, HiDpiThemeTest) { |
| 603 | base::FilePath crx_path = test_data_dir_.AppendASCII("theme_hidpi_crx"); |
| 604 | crx_path = crx_path.AppendASCII("theme_hidpi.crx"); |
| 605 | |
[email protected] | 658eae5 | 2014-06-14 20:28:05 | [diff] [blame] | 606 | ASSERT_TRUE(InstallExtension(crx_path, 1)); |
[email protected] | 90d3c04 | 2013-06-06 10:10:39 | [diff] [blame] | 607 | |
| 608 | const std::string extension_id("gllekhaobjnhgeagipipnkpmmmpchacm"); |
gpdavis.chromium | 48f08c4 | 2014-09-18 22:09:34 | [diff] [blame] | 609 | ExtensionRegistry* registry = ExtensionRegistry::Get( |
| 610 | browser()->profile()); |
[email protected] | 90d3c04 | 2013-06-06 10:10:39 | [diff] [blame] | 611 | const extensions::Extension* extension = |
gpdavis.chromium | 48f08c4 | 2014-09-18 22:09:34 | [diff] [blame] | 612 | registry->enabled_extensions().GetByID(extension_id); |
[email protected] | 90d3c04 | 2013-06-06 10:10:39 | [diff] [blame] | 613 | ASSERT_TRUE(extension); |
| 614 | EXPECT_EQ(extension_id, extension->id()); |
| 615 | |
| 616 | UninstallExtension(extension_id); |
gpdavis.chromium | 48f08c4 | 2014-09-18 22:09:34 | [diff] [blame] | 617 | EXPECT_FALSE(registry->enabled_extensions().GetByID(extension_id)); |
[email protected] | 90d3c04 | 2013-06-06 10:10:39 | [diff] [blame] | 618 | } |
| 619 | |
[email protected] | 9e9c1d1 | 2013-07-31 01:58:12 | [diff] [blame] | 620 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, |
mek | c95f9d06 | 2015-01-10 00:52:04 | [diff] [blame] | 621 | InstallDelayedUntilNextUpdate) { |
[email protected] | 9e9c1d1 | 2013-07-31 01:58:12 | [diff] [blame] | 622 | const std::string extension_id("ldnnhddmnhbkjipkidpdiheffobcpfmf"); |
mek | c95f9d06 | 2015-01-10 00:52:04 | [diff] [blame] | 623 | base::FilePath base_path = test_data_dir_.AppendASCII("delayed_install"); |
| 624 | |
Minh X. Nguyen | 3097534 | 2017-12-04 22:02:41 | [diff] [blame] | 625 | ExtensionService* service = extension_service(); |
[email protected] | 9e9c1d1 | 2013-07-31 01:58:12 | [diff] [blame] | 626 | ASSERT_TRUE(service); |
gpdavis.chromium | 48f08c4 | 2014-09-18 22:09:34 | [diff] [blame] | 627 | ExtensionRegistry* registry = ExtensionRegistry::Get( |
| 628 | browser()->profile()); |
| 629 | ASSERT_TRUE(registry); |
[email protected] | 9e9c1d1 | 2013-07-31 01:58:12 | [diff] [blame] | 630 | |
| 631 | // Install version 1 of the test extension. This extension does not have |
| 632 | // a background page but does have a browser action. |
mek | c95f9d06 | 2015-01-10 00:52:04 | [diff] [blame] | 633 | base::FilePath v1_path = PackExtension(base_path.AppendASCII("v1")); |
| 634 | ASSERT_FALSE(v1_path.empty()); |
| 635 | ASSERT_TRUE(InstallExtension(v1_path, 1)); |
[email protected] | 9e9c1d1 | 2013-07-31 01:58:12 | [diff] [blame] | 636 | const extensions::Extension* extension = |
gpdavis.chromium | 48f08c4 | 2014-09-18 22:09:34 | [diff] [blame] | 637 | registry->enabled_extensions().GetByID(extension_id); |
[email protected] | 9e9c1d1 | 2013-07-31 01:58:12 | [diff] [blame] | 638 | ASSERT_TRUE(extension); |
| 639 | ASSERT_EQ(extension_id, extension->id()); |
Devlin Cronin | 03bf2d2 | 2017-12-20 08:21:05 | [diff] [blame] | 640 | ASSERT_EQ("1.0", extension->version().GetString()); |
[email protected] | 9e9c1d1 | 2013-07-31 01:58:12 | [diff] [blame] | 641 | |
mek | c95f9d06 | 2015-01-10 00:52:04 | [diff] [blame] | 642 | // Make test extension non-idle by opening the extension's options page. |
| 643 | ExtensionTabUtil::OpenOptionsPage(extension, browser()); |
| 644 | WaitForExtensionNotIdle(extension_id); |
[email protected] | 9e9c1d1 | 2013-07-31 01:58:12 | [diff] [blame] | 645 | |
| 646 | // Install version 2 of the extension and check that it is indeed delayed. |
mek | c95f9d06 | 2015-01-10 00:52:04 | [diff] [blame] | 647 | base::FilePath v2_path = PackExtension(base_path.AppendASCII("v2")); |
| 648 | ASSERT_FALSE(v2_path.empty()); |
| 649 | ASSERT_TRUE(UpdateExtensionWaitForIdle(extension_id, v2_path, 0)); |
[email protected] | 9e9c1d1 | 2013-07-31 01:58:12 | [diff] [blame] | 650 | |
| 651 | ASSERT_EQ(1u, service->delayed_installs()->size()); |
gpdavis.chromium | 48f08c4 | 2014-09-18 22:09:34 | [diff] [blame] | 652 | extension = registry->enabled_extensions().GetByID(extension_id); |
Devlin Cronin | 03bf2d2 | 2017-12-20 08:21:05 | [diff] [blame] | 653 | ASSERT_EQ("1.0", extension->version().GetString()); |
[email protected] | 9e9c1d1 | 2013-07-31 01:58:12 | [diff] [blame] | 654 | |
mek | c95f9d06 | 2015-01-10 00:52:04 | [diff] [blame] | 655 | // Make the extension idle again by navigating away from the options page. |
| 656 | // This should not trigger the delayed install. |
| 657 | ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); |
| 658 | WaitForExtensionIdle(extension_id); |
[email protected] | 9e9c1d1 | 2013-07-31 01:58:12 | [diff] [blame] | 659 | ASSERT_EQ(1u, service->delayed_installs()->size()); |
mek | c95f9d06 | 2015-01-10 00:52:04 | [diff] [blame] | 660 | extension = registry->enabled_extensions().GetByID(extension_id); |
Devlin Cronin | 03bf2d2 | 2017-12-20 08:21:05 | [diff] [blame] | 661 | ASSERT_EQ("1.0", extension->version().GetString()); |
[email protected] | 9e9c1d1 | 2013-07-31 01:58:12 | [diff] [blame] | 662 | |
| 663 | // Install version 3 of the extension. Because the extension is idle, |
| 664 | // this install should succeed. |
mek | c95f9d06 | 2015-01-10 00:52:04 | [diff] [blame] | 665 | base::FilePath v3_path = PackExtension(base_path.AppendASCII("v3")); |
| 666 | ASSERT_FALSE(v3_path.empty()); |
| 667 | ASSERT_TRUE(UpdateExtensionWaitForIdle(extension_id, v3_path, 0)); |
gpdavis.chromium | 48f08c4 | 2014-09-18 22:09:34 | [diff] [blame] | 668 | extension = registry->enabled_extensions().GetByID(extension_id); |
Devlin Cronin | 03bf2d2 | 2017-12-20 08:21:05 | [diff] [blame] | 669 | ASSERT_EQ("3.0", extension->version().GetString()); |
[email protected] | 9e9c1d1 | 2013-07-31 01:58:12 | [diff] [blame] | 670 | |
| 671 | // The version 2 delayed install should be cleaned up, and finishing |
| 672 | // delayed extension installation shouldn't break anything. |
| 673 | ASSERT_EQ(0u, service->delayed_installs()->size()); |
| 674 | service->MaybeFinishDelayedInstallations(); |
gpdavis.chromium | 48f08c4 | 2014-09-18 22:09:34 | [diff] [blame] | 675 | extension = registry->enabled_extensions().GetByID(extension_id); |
Devlin Cronin | 03bf2d2 | 2017-12-20 08:21:05 | [diff] [blame] | 676 | ASSERT_EQ("3.0", extension->version().GetString()); |
[email protected] | 9e9c1d1 | 2013-07-31 01:58:12 | [diff] [blame] | 677 | } |
| 678 | |
Nico Weber | bc5b06f | 2019-07-26 14:00:13 | [diff] [blame] | 679 | #if BUILDFLAG(FULL_SAFE_BROWSING) |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 680 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, Blacklist) { |
[email protected] | 3f2a2fa | 2013-09-24 02:55:25 | [diff] [blame] | 681 | scoped_refptr<FakeSafeBrowsingDatabaseManager> blacklist_db( |
| 682 | new FakeSafeBrowsingDatabaseManager(true)); |
| 683 | Blacklist::ScopedDatabaseManagerForTest scoped_blacklist_db(blacklist_db); |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 684 | |
Sergey Poromov | cc36238 | 2018-11-09 18:43:32 | [diff] [blame] | 685 | const std::string extension_id = "gllekhaobjnhgeagipipnkpmmmpchacm"; |
| 686 | blacklist_db->SetUnsafe(extension_id); |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 687 | |
| 688 | base::FilePath crx_path = test_data_dir_.AppendASCII("theme_hidpi_crx") |
| 689 | .AppendASCII("theme_hidpi.crx"); |
| 690 | EXPECT_FALSE(InstallExtension(crx_path, 0)); |
Sergey Poromov | cc36238 | 2018-11-09 18:43:32 | [diff] [blame] | 691 | |
| 692 | auto installation_failure = |
Oleg Davydov | 66246bd9 | 2019-09-26 16:31:51 | [diff] [blame] | 693 | InstallationReporter::Get(profile())->Get(extension_id); |
Oleg Davydov | c0086681 | 2019-04-04 10:47:27 | [diff] [blame] | 694 | EXPECT_EQ(InstallationReporter::FailureReason::CRX_INSTALL_ERROR_DECLINED, |
| 695 | installation_failure.failure_reason); |
Sergey Poromov | cc36238 | 2018-11-09 18:43:32 | [diff] [blame] | 696 | EXPECT_EQ(CrxInstallErrorDetail::EXTENSION_IS_BLOCKLISTED, |
Oleg Davydov | c0086681 | 2019-04-04 10:47:27 | [diff] [blame] | 697 | installation_failure.install_error_detail); |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 698 | } |
[email protected] | e3767aa | 2013-11-08 23:49:07 | [diff] [blame] | 699 | #endif |
[email protected] | 9f3c853 | 2013-07-31 19:52:07 | [diff] [blame] | 700 | |
[email protected] | 8529082 | 2013-08-23 20:27:38 | [diff] [blame] | 701 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, NonStrictManifestCheck) { |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 702 | std::unique_ptr<MockPromptProxy> mock_prompt = |
[email protected] | 8529082 | 2013-08-23 20:27:38 | [diff] [blame] | 703 | CreateMockPromptProxyForBrowser(browser()); |
| 704 | |
| 705 | // We want to simulate the case where the webstore sends a more recent |
| 706 | // version of the manifest, but the downloaded .crx file is old since |
| 707 | // the newly published version hasn't fully propagated to all the download |
| 708 | // servers yet. So load the v2 manifest, but then install the v1 crx file. |
Joshua Pawlicki | af97ca0 | 2018-11-12 17:17:02 | [diff] [blame] | 709 | std::string id = "ooklpoaelmiimcjipecogjfcejghbogp"; |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 710 | std::unique_ptr<WebstoreInstaller::Approval> approval = |
[email protected] | 8529082 | 2013-08-23 20:27:38 | [diff] [blame] | 711 | GetApproval("crx_installer/v2_no_permission_change/", id, false); |
| 712 | |
| 713 | RunCrxInstaller(approval.get(), mock_prompt->CreatePrompt(), |
Minh X. Nguyen | 2c17b398 | 2017-10-13 18:32:29 | [diff] [blame] | 714 | CrxInstaller::InstallerResultCallback(), |
[email protected] | 8529082 | 2013-08-23 20:27:38 | [diff] [blame] | 715 | test_data_dir_.AppendASCII("crx_installer/v1.crx")); |
| 716 | |
| 717 | EXPECT_TRUE(mock_prompt->did_succeed()); |
| 718 | } |
| 719 | |
Minh X. Nguyen | 2c17b398 | 2017-10-13 18:32:29 | [diff] [blame] | 720 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, |
| 721 | NonStrictManifestCheck_WithCallback) { |
| 722 | std::unique_ptr<MockPromptProxy> mock_prompt = |
| 723 | CreateMockPromptProxyForBrowser(browser()); |
| 724 | |
| 725 | // We want to simulate the case where the webstore sends a more recent |
| 726 | // version of the manifest, but the downloaded .crx file is old since |
| 727 | // the newly published version hasn't fully propagated to all the download |
| 728 | // servers yet. So load the v2 manifest, but then install the v1 crx file. |
Joshua Pawlicki | af97ca0 | 2018-11-12 17:17:02 | [diff] [blame] | 729 | const std::string id = "ooklpoaelmiimcjipecogjfcejghbogp"; |
Minh X. Nguyen | 2c17b398 | 2017-10-13 18:32:29 | [diff] [blame] | 730 | std::unique_ptr<WebstoreInstaller::Approval> approval = |
| 731 | GetApproval("crx_installer/v2_no_permission_change/", id, false); |
| 732 | |
Minh X. Nguyen | 8803f4e | 2018-05-25 01:03:10 | [diff] [blame] | 733 | RunCrxInstaller( |
| 734 | approval.get(), mock_prompt->CreatePrompt(), |
| 735 | base::BindOnce([](const base::Optional<CrxInstallError>& error) { |
| 736 | EXPECT_EQ(base::nullopt, error); |
| 737 | }), |
| 738 | test_data_dir_.AppendASCII("crx_installer/v1.crx")); |
Minh X. Nguyen | 2c17b398 | 2017-10-13 18:32:29 | [diff] [blame] | 739 | |
| 740 | EXPECT_TRUE(mock_prompt->did_succeed()); |
| 741 | } |
| 742 | |
| 743 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, |
| 744 | InstallUnpackedCrx_FolderDoesNotExist) { |
| 745 | base::ScopedAllowBlockingForTesting allow_io; |
| 746 | std::unique_ptr<MockPromptProxy> mock_prompt = |
| 747 | CreateMockPromptProxyForBrowser(browser()); |
| 748 | |
| 749 | base::ScopedTempDir temp_dir; |
| 750 | EXPECT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 751 | |
| 752 | const base::FilePath folder = temp_dir.GetPath().AppendASCII("abcdef"); |
| 753 | EXPECT_FALSE(base::PathExists(folder)); |
| 754 | |
| 755 | const std::string public_key = "123456"; |
| 756 | RunCrxInstallerFromUnpackedDirectory( |
| 757 | mock_prompt->CreatePrompt(), |
Minh X. Nguyen | 8803f4e | 2018-05-25 01:03:10 | [diff] [blame] | 758 | base::BindOnce([](const base::Optional<CrxInstallError>& error) { |
| 759 | ASSERT_NE(base::nullopt, error); |
| 760 | ASSERT_EQ(CrxInstallErrorType::SANDBOXED_UNPACKER_FAILURE, |
| 761 | error->type()); |
| 762 | EXPECT_EQ(SandboxedUnpackerFailureReason::DIRECTORY_MOVE_FAILED, |
| 763 | error->sandbox_failure_detail()); |
| 764 | }), |
Minh X. Nguyen | 2c17b398 | 2017-10-13 18:32:29 | [diff] [blame] | 765 | std::string(), public_key, folder); |
| 766 | |
| 767 | EXPECT_FALSE(mock_prompt->did_succeed()); |
| 768 | } |
| 769 | |
| 770 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, |
| 771 | InstallUnpackedCrx_EmptyFolder) { |
| 772 | base::ScopedAllowBlockingForTesting allow_io; |
| 773 | std::unique_ptr<MockPromptProxy> mock_prompt = |
| 774 | CreateMockPromptProxyForBrowser(browser()); |
| 775 | |
| 776 | base::ScopedTempDir temp_dir; |
| 777 | EXPECT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 778 | EXPECT_TRUE(base::PathExists(temp_dir.GetPath())); |
| 779 | |
| 780 | const std::string public_key = "123456"; |
| 781 | RunCrxInstallerFromUnpackedDirectory( |
| 782 | mock_prompt->CreatePrompt(), |
Minh X. Nguyen | 8803f4e | 2018-05-25 01:03:10 | [diff] [blame] | 783 | base::BindOnce([](const base::Optional<CrxInstallError>& error) { |
| 784 | ASSERT_NE(base::nullopt, error); |
| 785 | ASSERT_EQ(CrxInstallErrorType::SANDBOXED_UNPACKER_FAILURE, |
| 786 | error->type()); |
| 787 | EXPECT_EQ(SandboxedUnpackerFailureReason::UNPACKER_CLIENT_FAILED, |
| 788 | error->sandbox_failure_detail()); |
| 789 | }), |
Minh X. Nguyen | 2c17b398 | 2017-10-13 18:32:29 | [diff] [blame] | 790 | std::string(), public_key, temp_dir.GetPath()); |
| 791 | |
| 792 | EXPECT_FALSE(mock_prompt->did_succeed()); |
| 793 | EXPECT_FALSE(base::PathExists(temp_dir.GetPath())); |
| 794 | } |
| 795 | |
| 796 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, |
| 797 | InstallUnpackedCrx_InvalidPublicKey) { |
| 798 | base::ScopedAllowBlockingForTesting allow_io; |
| 799 | std::unique_ptr<MockPromptProxy> mock_prompt = |
| 800 | CreateMockPromptProxyForBrowser(browser()); |
| 801 | |
| 802 | base::ScopedTempDir temp_dir; |
| 803 | EXPECT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 804 | EXPECT_TRUE(base::PathExists(temp_dir.GetPath())); |
| 805 | |
| 806 | const base::FilePath unpacked_path = |
Devlin Cronin | 19775cc | 2018-04-19 15:04:26 | [diff] [blame] | 807 | test_data_dir_.AppendASCII("simple_with_popup"); |
Minh X. Nguyen | 2c17b398 | 2017-10-13 18:32:29 | [diff] [blame] | 808 | EXPECT_TRUE(base::PathExists(unpacked_path)); |
| 809 | EXPECT_TRUE(base::CopyDirectory(unpacked_path, temp_dir.GetPath(), false)); |
| 810 | |
| 811 | const std::string public_key = "123456"; |
| 812 | RunCrxInstallerFromUnpackedDirectory( |
| 813 | mock_prompt->CreatePrompt(), |
Minh X. Nguyen | 8803f4e | 2018-05-25 01:03:10 | [diff] [blame] | 814 | base::BindOnce([](const base::Optional<CrxInstallError>& error) { |
| 815 | ASSERT_NE(base::nullopt, error); |
| 816 | ASSERT_EQ(CrxInstallErrorType::SANDBOXED_UNPACKER_FAILURE, |
| 817 | error->type()); |
| 818 | EXPECT_EQ(SandboxedUnpackerFailureReason::INVALID_MANIFEST, |
| 819 | error->sandbox_failure_detail()); |
| 820 | }), |
Minh X. Nguyen | 2c17b398 | 2017-10-13 18:32:29 | [diff] [blame] | 821 | std::string(), public_key, temp_dir.GetPath()); |
| 822 | |
| 823 | EXPECT_FALSE(mock_prompt->did_succeed()); |
| 824 | EXPECT_FALSE(base::PathExists(temp_dir.GetPath())); |
| 825 | } |
| 826 | |
| 827 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, InstallUnpackedCrx_Success) { |
| 828 | base::ScopedAllowBlockingForTesting allow_io; |
| 829 | std::unique_ptr<MockPromptProxy> mock_prompt = |
| 830 | CreateMockPromptProxyForBrowser(browser()); |
| 831 | |
| 832 | base::ScopedTempDir temp_dir; |
| 833 | EXPECT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 834 | EXPECT_TRUE(base::PathExists(temp_dir.GetPath())); |
| 835 | |
| 836 | const base::FilePath unpacked_path = |
Devlin Cronin | 19775cc | 2018-04-19 15:04:26 | [diff] [blame] | 837 | test_data_dir_.AppendASCII("simple_with_popup"); |
Minh X. Nguyen | 2c17b398 | 2017-10-13 18:32:29 | [diff] [blame] | 838 | EXPECT_TRUE(base::PathExists(unpacked_path)); |
| 839 | EXPECT_TRUE(base::CopyDirectory(unpacked_path, temp_dir.GetPath(), false)); |
| 840 | |
| 841 | const std::string public_key = |
| 842 | "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC8c4fBSPZ6utYoZ8NiWF/" |
| 843 | "DSaimBhihjwgOsskyleFGaurhi3TDClTVSGPxNkgCzrz0wACML7M4aNjpd05qupdbR2d294j" |
| 844 | "kDuI7caxEGUucpP7GJRRHnm8Sx+" |
| 845 | "y0ury28n8jbN0PnInKKWcxpIXXmNQyC19HBuO3QIeUq9Dqc+7YFQIDAQAB"; |
| 846 | RunCrxInstallerFromUnpackedDirectory( |
| 847 | mock_prompt->CreatePrompt(), |
Minh X. Nguyen | 8803f4e | 2018-05-25 01:03:10 | [diff] [blame] | 848 | base::BindOnce([](const base::Optional<CrxInstallError>& error) { |
| 849 | EXPECT_EQ(base::nullopt, error); |
| 850 | }), |
| 851 | std::string(), public_key, temp_dir.GetPath()); |
Minh X. Nguyen | 2c17b398 | 2017-10-13 18:32:29 | [diff] [blame] | 852 | |
| 853 | EXPECT_TRUE(mock_prompt->did_succeed()); |
| 854 | EXPECT_FALSE(base::PathExists(temp_dir.GetPath())); |
| 855 | } |
| 856 | |
Minh X. Nguyen | 3097534 | 2017-12-04 22:02:41 | [diff] [blame] | 857 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, |
| 858 | UpdateExtensionFromUnpackedCrx_NewExtension) { |
| 859 | base::ScopedAllowBlockingForTesting allow_io; |
| 860 | std::unique_ptr<MockPromptProxy> mock_prompt = |
| 861 | CreateMockPromptProxyForBrowser(browser()); |
| 862 | |
| 863 | // Update won't work as the extension doesn't exist. |
| 864 | const std::string extension_id = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; |
| 865 | const std::string public_key = |
| 866 | "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC8c4fBSPZ6utYoZ8NiWF/" |
| 867 | "DSaimBhihjwgOsskyleFGaurhi3TDClTVSGPxNkgCzrz0wACML7M4aNjpd05qupdbR2d294j" |
| 868 | "kDuI7caxEGUucpP7GJRRHnm8Sx+" |
| 869 | "y0ury28n8jbN0PnInKKWcxpIXXmNQyC19HBuO3QIeUq9Dqc+7YFQIDAQAB"; |
| 870 | ASSERT_EQ(nullptr, GetInstalledExtension(extension_id)); |
| 871 | auto temp_dir = UnpackedCrxTempDir(); |
Minh X. Nguyen | 8803f4e | 2018-05-25 01:03:10 | [diff] [blame] | 872 | RunUpdateExtension( |
| 873 | mock_prompt->CreatePrompt(), extension_id, public_key, |
| 874 | temp_dir->GetPath(), |
| 875 | base::BindOnce([](const base::Optional<CrxInstallError>& error) { |
| 876 | ASSERT_NE(base::nullopt, error); |
| 877 | EXPECT_EQ(CrxInstallErrorType::OTHER, error->type()); |
| 878 | EXPECT_EQ(CrxInstallErrorDetail::UPDATE_NON_EXISTING_EXTENSION, |
| 879 | error->detail()); |
| 880 | })); |
Minh X. Nguyen | 3097534 | 2017-12-04 22:02:41 | [diff] [blame] | 881 | |
| 882 | // The unpacked folder should be deleted. |
| 883 | EXPECT_FALSE(mock_prompt->did_succeed()); |
| 884 | EXPECT_FALSE(base::PathExists(temp_dir->GetPath())); |
| 885 | EXPECT_EQ(nullptr, GetInstalledExtension(extension_id)); |
| 886 | } |
| 887 | |
| 888 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, |
| 889 | UpdateExtensionFromUnpackedCrx_UpdateExistingExtension) { |
| 890 | base::ScopedAllowBlockingForTesting allow_io; |
| 891 | std::unique_ptr<MockPromptProxy> mock_prompt = |
| 892 | CreateMockPromptProxyForBrowser(browser()); |
| 893 | |
| 894 | const std::string extension_id = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; |
| 895 | const std::string public_key = |
| 896 | "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC8c4fBSPZ6utYoZ8NiWF/" |
| 897 | "DSaimBhihjwgOsskyleFGaurhi3TDClTVSGPxNkgCzrz0wACML7M4aNjpd05qupdbR2d294j" |
| 898 | "kDuI7caxEGUucpP7GJRRHnm8Sx+" |
| 899 | "y0ury28n8jbN0PnInKKWcxpIXXmNQyC19HBuO3QIeUq9Dqc+7YFQIDAQAB"; |
| 900 | |
| 901 | // Test updating an existing extension. |
| 902 | AddExtension(extension_id, "0.0"); |
| 903 | |
| 904 | auto temp_dir = UnpackedCrxTempDir(); |
Minh X. Nguyen | 8803f4e | 2018-05-25 01:03:10 | [diff] [blame] | 905 | RunUpdateExtension( |
| 906 | mock_prompt->CreatePrompt(), extension_id, public_key, |
| 907 | temp_dir->GetPath(), |
| 908 | base::BindOnce([](const base::Optional<CrxInstallError>& error) { |
| 909 | EXPECT_EQ(base::nullopt, error); |
| 910 | })); |
Minh X. Nguyen | 3097534 | 2017-12-04 22:02:41 | [diff] [blame] | 911 | |
| 912 | EXPECT_TRUE(mock_prompt->did_succeed()); |
| 913 | |
| 914 | // The unpacked folder should be deleted. |
| 915 | EXPECT_FALSE(base::PathExists(temp_dir->GetPath())); |
| 916 | |
| 917 | const Extension* extension = GetInstalledExtension(extension_id); |
| 918 | ASSERT_NE(nullptr, extension); |
| 919 | EXPECT_EQ("1.0", extension->VersionString()); |
| 920 | } |
| 921 | |
| 922 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, |
| 923 | UpdateExtensionFromUnpackedCrx_InvalidPublicKey) { |
| 924 | base::ScopedAllowBlockingForTesting allow_io; |
| 925 | std::unique_ptr<MockPromptProxy> mock_prompt = |
| 926 | CreateMockPromptProxyForBrowser(browser()); |
| 927 | |
| 928 | const std::string extension_id = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; |
| 929 | const std::string public_key = "invalid public key"; |
| 930 | |
| 931 | // Test updating an existing extension. |
| 932 | AddExtension(extension_id, "0.0"); |
| 933 | |
| 934 | auto temp_dir = UnpackedCrxTempDir(); |
Minh X. Nguyen | 8803f4e | 2018-05-25 01:03:10 | [diff] [blame] | 935 | RunUpdateExtension( |
| 936 | mock_prompt->CreatePrompt(), extension_id, public_key, |
| 937 | temp_dir->GetPath(), |
| 938 | base::BindOnce([](const base::Optional<CrxInstallError>& error) { |
| 939 | ASSERT_NE(base::nullopt, error); |
| 940 | ASSERT_EQ(CrxInstallErrorType::SANDBOXED_UNPACKER_FAILURE, |
| 941 | error->type()); |
| 942 | EXPECT_EQ(SandboxedUnpackerFailureReason::INVALID_MANIFEST, |
| 943 | error->sandbox_failure_detail()); |
| 944 | })); |
Minh X. Nguyen | 3097534 | 2017-12-04 22:02:41 | [diff] [blame] | 945 | |
| 946 | EXPECT_FALSE(mock_prompt->did_succeed()); |
| 947 | |
| 948 | // The unpacked folder should be deleted. |
| 949 | EXPECT_FALSE(base::PathExists(temp_dir->GetPath())); |
| 950 | |
| 951 | const Extension* extension = GetInstalledExtension(extension_id); |
| 952 | ASSERT_NE(nullptr, extension); |
| 953 | EXPECT_EQ("0.0", extension->VersionString()); |
Sergey Poromov | cc36238 | 2018-11-09 18:43:32 | [diff] [blame] | 954 | |
| 955 | auto installation_failure = |
Oleg Davydov | 66246bd9 | 2019-09-26 16:31:51 | [diff] [blame] | 956 | InstallationReporter::Get(profile())->Get(extension_id); |
Oleg Davydov | c0086681 | 2019-04-04 10:47:27 | [diff] [blame] | 957 | EXPECT_EQ(InstallationReporter::FailureReason:: |
Sergey Poromov | cc36238 | 2018-11-09 18:43:32 | [diff] [blame] | 958 | CRX_INSTALL_ERROR_SANDBOXED_UNPACKER_FAILURE, |
Oleg Davydov | c0086681 | 2019-04-04 10:47:27 | [diff] [blame] | 959 | installation_failure.failure_reason); |
| 960 | EXPECT_EQ(base::nullopt, installation_failure.install_error_detail); |
Minh X. Nguyen | 3097534 | 2017-12-04 22:02:41 | [diff] [blame] | 961 | } |
| 962 | |
| 963 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, |
| 964 | UpdateExtensionFromUnpackedCrx_WrongPublicKey) { |
| 965 | base::ScopedAllowBlockingForTesting allow_io; |
| 966 | std::unique_ptr<MockPromptProxy> mock_prompt = |
| 967 | CreateMockPromptProxyForBrowser(browser()); |
| 968 | |
| 969 | const std::string extension_id = "gllekhaobjnhgeagipipnkpmmmpchacm"; |
| 970 | const std::string public_key = |
| 971 | "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC8c4fBSPZ6utYoZ8NiWF/" |
| 972 | "DSaimBhihjwgOsskyleFGaurhi3TDClTVSGPxNkgCzrz0wACML7M4aNjpd05qupdbR2d294j" |
| 973 | "kDuI7caxEGUucpP7GJRRHnm8Sx+" |
| 974 | "y0ury28n8jbN0PnInKKWcxpIXXmNQyC19HBuO3QIeUq9Dqc+7YFQIDAQAB"; |
| 975 | |
| 976 | // Test updating an existing extension. |
| 977 | AddExtension(extension_id, "0.0"); |
| 978 | |
| 979 | auto temp_dir = UnpackedCrxTempDir(); |
Minh X. Nguyen | 8803f4e | 2018-05-25 01:03:10 | [diff] [blame] | 980 | RunUpdateExtension( |
| 981 | mock_prompt->CreatePrompt(), extension_id, public_key, |
| 982 | temp_dir->GetPath(), |
| 983 | base::BindOnce([](const base::Optional<CrxInstallError>& error) { |
| 984 | ASSERT_NE(base::nullopt, error); |
| 985 | EXPECT_EQ(CrxInstallErrorType::OTHER, error->type()); |
| 986 | EXPECT_EQ(CrxInstallErrorDetail::UNEXPECTED_ID, error->detail()); |
| 987 | })); |
Minh X. Nguyen | 3097534 | 2017-12-04 22:02:41 | [diff] [blame] | 988 | |
| 989 | EXPECT_FALSE(mock_prompt->did_succeed()); |
| 990 | |
| 991 | // The unpacked folder should be deleted. |
| 992 | EXPECT_FALSE(base::PathExists(temp_dir->GetPath())); |
| 993 | |
| 994 | const Extension* extension = GetInstalledExtension(extension_id); |
| 995 | ASSERT_NE(nullptr, extension); |
| 996 | EXPECT_EQ("0.0", extension->VersionString()); |
Sergey Poromov | cc36238 | 2018-11-09 18:43:32 | [diff] [blame] | 997 | |
| 998 | auto installation_failure = |
Oleg Davydov | 66246bd9 | 2019-09-26 16:31:51 | [diff] [blame] | 999 | InstallationReporter::Get(profile())->Get(extension_id); |
Oleg Davydov | c0086681 | 2019-04-04 10:47:27 | [diff] [blame] | 1000 | EXPECT_EQ(InstallationReporter::FailureReason::CRX_INSTALL_ERROR_OTHER, |
| 1001 | installation_failure.failure_reason); |
| 1002 | EXPECT_EQ(CrxInstallErrorDetail::UNEXPECTED_ID, |
| 1003 | *installation_failure.install_error_detail); |
Minh X. Nguyen | 3097534 | 2017-12-04 22:02:41 | [diff] [blame] | 1004 | } |
| 1005 | |
limasdf | ebff7fd0 | 2015-12-25 14:45:31 | [diff] [blame] | 1006 | #if defined(OS_CHROMEOS) |
[email protected] | 14a18bf | 2013-09-26 08:42:30 | [diff] [blame] | 1007 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, KioskOnlyTest) { |
Sam McNally | fb8bfc3 | 2018-10-30 06:51:11 | [diff] [blame] | 1008 | base::ScopedAllowBlockingForTesting allow_io; |
limasdf | ebff7fd0 | 2015-12-25 14:45:31 | [diff] [blame] | 1009 | // kiosk_only is whitelisted from non-chromeos. |
[email protected] | 14a18bf | 2013-09-26 08:42:30 | [diff] [blame] | 1010 | base::FilePath crx_path = |
| 1011 | test_data_dir_.AppendASCII("kiosk/kiosk_only.crx"); |
| 1012 | EXPECT_FALSE(InstallExtension(crx_path, 0)); |
[email protected] | 14a18bf | 2013-09-26 08:42:30 | [diff] [blame] | 1013 | // Simulate ChromeOS kiosk mode. |scoped_user_manager| will take over |
| 1014 | // lifetime of |user_manager|. |
merkulova | 793f302 | 2015-02-04 10:18:30 | [diff] [blame] | 1015 | chromeos::FakeChromeUserManager* fake_user_manager = |
| 1016 | new chromeos::FakeChromeUserManager(); |
alemate | 3ffbde6f | 2015-11-03 02:02:55 | [diff] [blame] | 1017 | const AccountId account_id(AccountId::FromUserEmail("[email protected]")); |
| 1018 | fake_user_manager->AddKioskAppUser(account_id); |
| 1019 | fake_user_manager->LoginUser(account_id); |
Xiyuan Xia | dfe3a9f | 2017-11-13 21:46:26 | [diff] [blame] | 1020 | user_manager::ScopedUserManager scoped_user_manager( |
| 1021 | base::WrapUnique(fake_user_manager)); |
[email protected] | 14a18bf | 2013-09-26 08:42:30 | [diff] [blame] | 1022 | EXPECT_TRUE(InstallExtension(crx_path, 1)); |
[email protected] | 14a18bf | 2013-09-26 08:42:30 | [diff] [blame] | 1023 | } |
| 1024 | |
dpolukhin | cbd48d19 | 2015-06-04 14:09:37 | [diff] [blame] | 1025 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, InstallToSharedLocation) { |
Sam McNally | fb8bfc3 | 2018-10-30 06:51:11 | [diff] [blame] | 1026 | base::ScopedAllowBlockingForTesting allow_io; |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 1027 | base::CommandLine::ForCurrentProcess()->AppendSwitch( |
[email protected] | 5a145e8 | 2014-05-29 22:19:07 | [diff] [blame] | 1028 | chromeos::switches::kEnableExtensionAssetsSharing); |
| 1029 | base::ScopedTempDir cache_dir; |
| 1030 | ASSERT_TRUE(cache_dir.CreateUniqueTempDir()); |
| 1031 | ExtensionAssetsManagerChromeOS::SetSharedInstallDirForTesting( |
vabr | 9142fe2 | 2016-09-08 13:19:22 | [diff] [blame] | 1032 | cache_dir.GetPath()); |
[email protected] | 5a145e8 | 2014-05-29 22:19:07 | [diff] [blame] | 1033 | |
| 1034 | base::FilePath crx_path = test_data_dir_.AppendASCII("crx_installer/v1.crx"); |
| 1035 | const extensions::Extension* extension = InstallExtension( |
| 1036 | crx_path, 1, extensions::Manifest::EXTERNAL_PREF); |
| 1037 | base::FilePath extension_path = extension->path(); |
vabr | 9142fe2 | 2016-09-08 13:19:22 | [diff] [blame] | 1038 | EXPECT_TRUE(cache_dir.GetPath().IsParent(extension_path)); |
[email protected] | 5a145e8 | 2014-05-29 22:19:07 | [diff] [blame] | 1039 | EXPECT_TRUE(base::PathExists(extension_path)); |
| 1040 | |
| 1041 | std::string extension_id = extension->id(); |
| 1042 | UninstallExtension(extension_id); |
gpdavis.chromium | 48f08c4 | 2014-09-18 22:09:34 | [diff] [blame] | 1043 | ExtensionRegistry* registry = ExtensionRegistry::Get( |
| 1044 | browser()->profile()); |
| 1045 | EXPECT_FALSE(registry->enabled_extensions().GetByID(extension_id)); |
[email protected] | 5a145e8 | 2014-05-29 22:19:07 | [diff] [blame] | 1046 | |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 1047 | content::RunAllTasksUntilIdle(); |
[email protected] | 5a145e8 | 2014-05-29 22:19:07 | [diff] [blame] | 1048 | |
| 1049 | EXPECT_FALSE(base::PathExists(extension_path)); |
| 1050 | } |
| 1051 | #endif |
| 1052 | |
[email protected] | 658eae5 | 2014-06-14 20:28:05 | [diff] [blame] | 1053 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, DoNotSync) { |
[email protected] | 658eae5 | 2014-06-14 20:28:05 | [diff] [blame] | 1054 | scoped_refptr<CrxInstaller> crx_installer( |
Minh X. Nguyen | 3097534 | 2017-12-04 22:02:41 | [diff] [blame] | 1055 | CrxInstaller::CreateSilent(extension_service())); |
[email protected] | c30bda26 | 2014-06-19 04:10:13 | [diff] [blame] | 1056 | crx_installer->set_do_not_sync(true); |
[email protected] | 658eae5 | 2014-06-14 20:28:05 | [diff] [blame] | 1057 | crx_installer->InstallCrx(test_data_dir_.AppendASCII("good.crx")); |
| 1058 | EXPECT_TRUE(WaitForCrxInstallerDone()); |
| 1059 | ASSERT_TRUE(crx_installer->extension()); |
| 1060 | |
| 1061 | const ExtensionPrefs* extension_prefs = |
| 1062 | ExtensionPrefs::Get(browser()->profile()); |
| 1063 | EXPECT_TRUE(extension_prefs->DoNotSync(crx_installer->extension()->id())); |
treib | c644a1c | 2015-07-13 08:37:04 | [diff] [blame] | 1064 | EXPECT_FALSE(extensions::util::ShouldSync(crx_installer->extension(), |
| 1065 | browser()->profile())); |
[email protected] | 658eae5 | 2014-06-14 20:28:05 | [diff] [blame] | 1066 | } |
| 1067 | |
[email protected] | 253fc2bb | 2014-07-10 04:21:18 | [diff] [blame] | 1068 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, ManagementPolicy) { |
| 1069 | ManagementPolicyMock policy; |
| 1070 | extensions::ExtensionSystem::Get(profile()) |
| 1071 | ->management_policy() |
| 1072 | ->RegisterProvider(&policy); |
| 1073 | |
| 1074 | base::FilePath crx_path = test_data_dir_.AppendASCII("crx_installer/v1.crx"); |
| 1075 | EXPECT_FALSE(InstallExtension(crx_path, 0)); |
| 1076 | } |
| 1077 | |
dominickn | 675536f | 2015-11-06 03:25:38 | [diff] [blame] | 1078 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, InstallWebApp) { |
| 1079 | InstallWebAppAndVerifyNoErrors(); |
| 1080 | } |
| 1081 | |
| 1082 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, |
| 1083 | InstallWebAppSucceedsWithBlockPolicy) { |
| 1084 | // Verify that the install still works when a management policy blocking |
| 1085 | // extension installation is in force. Bookmark apps are special-cased to skip |
| 1086 | // these checks (see https://crbug.com/545541). |
| 1087 | ManagementPolicyMock policy; |
| 1088 | extensions::ExtensionSystem::Get(profile()) |
| 1089 | ->management_policy() |
| 1090 | ->RegisterProvider(&policy); |
| 1091 | |
| 1092 | InstallWebAppAndVerifyNoErrors(); |
| 1093 | } |
| 1094 | |
rob | bc66c4b | 2016-02-13 09:38:57 | [diff] [blame] | 1095 | IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest, UpdateWithFileAccess) { |
| 1096 | base::FilePath ext_source = |
| 1097 | test_data_dir_.AppendASCII("permissions").AppendASCII("files"); |
| 1098 | base::FilePath crx_with_file_permission = PackExtension(ext_source); |
| 1099 | ASSERT_FALSE(crx_with_file_permission.empty()); |
| 1100 | |
Minh X. Nguyen | 3097534 | 2017-12-04 22:02:41 | [diff] [blame] | 1101 | ExtensionService* service = extension_service(); |
rob | bc66c4b | 2016-02-13 09:38:57 | [diff] [blame] | 1102 | |
| 1103 | const std::string extension_id("bdkapipdccfifhdghmblnenbbncfcpid"); |
| 1104 | { |
| 1105 | // Install extension. |
| 1106 | scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(service)); |
| 1107 | installer->InstallCrx(crx_with_file_permission); |
| 1108 | EXPECT_TRUE(WaitForCrxInstallerDone()); |
| 1109 | const Extension* extension = installer->extension(); |
| 1110 | ASSERT_TRUE(extension); |
| 1111 | // IDs must match, otherwise the test doesn't make any sense. |
| 1112 | ASSERT_EQ(extension_id, extension->id()); |
| 1113 | // Sanity check: File access should be disabled by default. |
| 1114 | EXPECT_FALSE(ExtensionPrefs::Get(profile())->AllowFileAccess(extension_id)); |
| 1115 | EXPECT_FALSE(extension->creation_flags() & Extension::ALLOW_FILE_ACCESS); |
| 1116 | } |
| 1117 | |
| 1118 | { |
| 1119 | // Uninstall and re-install the extension. Any previously granted file |
| 1120 | // permissions should be gone. |
| 1121 | ExtensionPrefs::Get(profile())->SetAllowFileAccess(extension_id, true); |
| 1122 | EXPECT_TRUE(ExtensionPrefs::Get(profile())->AllowFileAccess(extension_id)); |
| 1123 | UninstallExtension(extension_id); |
| 1124 | EXPECT_FALSE(ExtensionPrefs::Get(profile())->AllowFileAccess(extension_id)); |
| 1125 | |
| 1126 | scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(service)); |
| 1127 | installer->InstallCrx(crx_with_file_permission); |
| 1128 | EXPECT_TRUE(WaitForCrxInstallerDone()); |
| 1129 | const Extension* extension = installer->extension(); |
| 1130 | ASSERT_TRUE(extension); |
| 1131 | ASSERT_EQ(extension_id, extension->id()); |
| 1132 | EXPECT_FALSE(ExtensionPrefs::Get(profile())->AllowFileAccess(extension_id)); |
| 1133 | EXPECT_FALSE(extension->creation_flags() & Extension::ALLOW_FILE_ACCESS); |
| 1134 | } |
| 1135 | |
| 1136 | { |
| 1137 | // Grant file access and update the extension. File access should be kept. |
| 1138 | ExtensionPrefs::Get(profile())->SetAllowFileAccess(extension_id, true); |
| 1139 | EXPECT_TRUE(ExtensionPrefs::Get(profile())->AllowFileAccess(extension_id)); |
| 1140 | base::FilePath crx_update_with_file_permission = PackExtension(ext_source); |
| 1141 | |
| 1142 | scoped_refptr<CrxInstaller> installer(CrxInstaller::CreateSilent(service)); |
| 1143 | installer->InstallCrx(crx_update_with_file_permission); |
| 1144 | EXPECT_TRUE(WaitForCrxInstallerDone()); |
| 1145 | const Extension* extension = installer->extension(); |
| 1146 | ASSERT_TRUE(extension); |
| 1147 | ASSERT_EQ(extension_id, extension->id()); |
| 1148 | EXPECT_TRUE(ExtensionPrefs::Get(profile())->AllowFileAccess(extension_id)); |
| 1149 | EXPECT_TRUE(extension->creation_flags() & Extension::ALLOW_FILE_ACCESS); |
| 1150 | } |
| 1151 | } |
| 1152 | |
[email protected] | bf3d9df | 2012-07-24 23:20:27 | [diff] [blame] | 1153 | } // namespace extensions |