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