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