1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/extensions/crx_installer.h"
7 #include "base/at_exit.h"
8 #include "base/files/file_path.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/browser/download/download_crx_util.h"
12 #include "chrome/browser/extensions/browser_action_test_util.h"
13 #include "chrome/browser/extensions/extension_browsertest.h"
14 #include "chrome/browser/extensions/extension_install_prompt.h"
15 #include "chrome/browser/extensions/extension_install_prompt_show_params.h"
16 #include "chrome/browser/extensions/extension_service.h"
17 #include "chrome/browser/extensions/extension_tab_util.h"
18 #include "chrome/browser/extensions/extension_util.h"
19 #include "chrome/browser/extensions/fake_safe_browsing_database_manager.h"
20 #include "chrome/browser/extensions/test_extension_dir.h"
21 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/ui/browser.h"
23 #include "chrome/browser/ui/browser_window.h"
24 #include "chrome/browser/ui/tabs/tab_strip_model.h"
25 #include "chrome/grit/generated_resources.h"
26 #include "chrome/test/base/ui_test_utils.h"
27 #include "content/public/browser/browser_thread.h"
28 #include "content/public/browser/download_manager.h"
29 #include "content/public/browser/render_view_host.h"
30 #include "content/public/test/browser_test_utils.h"
31 #include "content/public/test/download_test_observer.h"
32 #include "content/public/test/test_utils.h"
33 #include "extensions/browser/extension_prefs.h"
34 #include "extensions/browser/extension_registry.h"
35 #include "extensions/browser/extension_system.h"
36 #include "extensions/browser/install/crx_install_error.h"
37 #include "extensions/browser/management_policy.h"
38 #include "extensions/browser/notification_types.h"
39 #include "extensions/common/extension.h"
40 #include "extensions/common/feature_switch.h"
41 #include "extensions/common/file_util.h"
42 #include "extensions/common/permissions/api_permission.h"
43 #include "extensions/common/permissions/permission_set.h"
44 #include "extensions/common/permissions/permissions_data.h"
45 #include "extensions/common/switches.h"
46 #include "ui/base/l10n/l10n_util.h"
48 #if defined(OS_CHROMEOS)
49 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h"
50 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
51 #include "chrome/browser/extensions/extension_assets_manager_chromeos.h"
52 #include "chromeos/chromeos_switches.h"
57 namespace extensions
{
61 class MockInstallPrompt
;
63 // This class holds information about things that happen with a
64 // MockInstallPrompt. We create the MockInstallPrompt but need to pass
65 // ownership of it to CrxInstaller, so it isn't safe to hang this data on
66 // MockInstallPrompt itself becuase we can't guarantee it's lifetime.
67 class MockPromptProxy
: public base::RefCountedThreadSafe
<MockPromptProxy
> {
69 explicit MockPromptProxy(content::WebContents
* web_contents
);
71 bool did_succeed() const { return !extension_id_
.empty(); }
72 const std::string
& extension_id() { return extension_id_
; }
73 bool confirmation_requested() const { return confirmation_requested_
; }
74 const base::string16
& error() const { return error_
; }
76 // To have any effect, this should be called before CreatePrompt.
77 void set_record_oauth2_grant(bool record_oauth2_grant
) {
78 record_oauth2_grant_
.reset(new bool(record_oauth2_grant
));
81 void set_extension_id(const std::string
& id
) { extension_id_
= id
; }
82 void set_confirmation_requested() { confirmation_requested_
= true; }
83 void set_error(const base::string16
& error
) { error_
= error
; }
85 scoped_ptr
<ExtensionInstallPrompt
> CreatePrompt();
88 friend class base::RefCountedThreadSafe
<MockPromptProxy
>;
89 virtual ~MockPromptProxy();
91 // Data used to create a prompt.
92 content::WebContents
* web_contents_
;
93 scoped_ptr
<bool> record_oauth2_grant_
;
95 // Data reported back to us by the prompt we created.
96 bool confirmation_requested_
;
97 std::string extension_id_
;
98 base::string16 error_
;
101 class MockInstallPrompt
: public ExtensionInstallPrompt
{
103 MockInstallPrompt(content::WebContents
* web_contents
,
104 MockPromptProxy
* proxy
) :
105 ExtensionInstallPrompt(web_contents
),
108 void set_record_oauth2_grant(bool record
) { record_oauth2_grant_
= record
; }
110 // Overriding some of the ExtensionInstallUI API.
111 void ConfirmInstall(Delegate
* delegate
,
112 const Extension
* extension
,
113 const ShowDialogCallback
& show_dialog_callback
) override
{
114 proxy_
->set_confirmation_requested();
115 delegate
->InstallUIProceed();
117 void OnInstallSuccess(const Extension
* extension
, SkBitmap
* icon
) override
{
118 proxy_
->set_extension_id(extension
->id());
119 base::MessageLoopForUI::current()->Quit();
121 void OnInstallFailure(const CrxInstallError
& error
) override
{
122 proxy_
->set_error(error
.message());
123 base::MessageLoopForUI::current()->Quit();
127 scoped_refptr
<MockPromptProxy
> proxy_
;
130 MockPromptProxy::MockPromptProxy(content::WebContents
* web_contents
)
131 : web_contents_(web_contents
), confirmation_requested_(false) {
134 MockPromptProxy::~MockPromptProxy() {}
136 scoped_ptr
<ExtensionInstallPrompt
> MockPromptProxy::CreatePrompt() {
137 scoped_ptr
<MockInstallPrompt
> prompt(
138 new MockInstallPrompt(web_contents_
, this));
139 if (record_oauth2_grant_
.get())
140 prompt
->set_record_oauth2_grant(*record_oauth2_grant_
.get());
141 return prompt
.Pass();
145 scoped_refptr
<MockPromptProxy
> CreateMockPromptProxyForBrowser(
147 return new MockPromptProxy(
148 browser
->tab_strip_model()->GetActiveWebContents());
151 class ManagementPolicyMock
: public extensions::ManagementPolicy::Provider
{
153 ManagementPolicyMock() {}
155 std::string
GetDebugPolicyProviderName() const override
{
156 return "ManagementPolicyMock";
159 bool UserMayLoad(const Extension
* extension
,
160 base::string16
* error
) const override
{
161 *error
= base::UTF8ToUTF16("Dummy error message");
166 // Appends "enable-experimental-extension-apis" to the command line for the
167 // lifetime of this class.
168 class ScopedExperimentalCommandLine
{
170 ScopedExperimentalCommandLine()
171 : saved_(*base::CommandLine::ForCurrentProcess()) {
172 base::CommandLine::ForCurrentProcess()->AppendSwitch(
173 switches::kEnableExperimentalExtensionApis
);
176 ~ScopedExperimentalCommandLine() {
177 *base::CommandLine::ForCurrentProcess() = saved_
;
181 base::CommandLine saved_
;
186 class ExtensionCrxInstallerTest
: public ExtensionBrowserTest
{
188 scoped_ptr
<WebstoreInstaller::Approval
> GetApproval(
189 const char* manifest_dir
,
190 const std::string
& id
,
191 bool strict_manifest_checks
) {
192 scoped_ptr
<WebstoreInstaller::Approval
> result
;
194 base::FilePath ext_path
= test_data_dir_
.AppendASCII(manifest_dir
);
196 scoped_ptr
<base::DictionaryValue
> parsed_manifest(
197 file_util::LoadManifest(ext_path
, &error
));
198 if (!parsed_manifest
.get() || !error
.empty())
199 return result
.Pass();
201 return WebstoreInstaller::Approval::CreateWithNoInstallPrompt(
202 browser()->profile(),
204 parsed_manifest
.Pass(),
205 strict_manifest_checks
);
208 void RunCrxInstaller(const WebstoreInstaller::Approval
* approval
,
209 scoped_ptr
<ExtensionInstallPrompt
> prompt
,
210 const base::FilePath
& crx_path
) {
211 ExtensionService
* service
= extensions::ExtensionSystem::Get(
212 browser()->profile())->extension_service();
213 scoped_refptr
<CrxInstaller
> installer(
214 CrxInstaller::Create(service
, prompt
.Pass(), approval
));
215 installer
->set_allow_silent_install(true);
216 installer
->set_is_gallery_install(true);
217 installer
->InstallCrx(crx_path
);
218 content::RunMessageLoop();
221 // Installs a crx from |crx_relpath| (a path relative to the extension test
222 // data dir) with expected id |id|.
223 void InstallWithPrompt(const char* ext_relpath
,
224 const std::string
& id
,
225 scoped_refptr
<MockPromptProxy
> mock_install_prompt
) {
226 base::FilePath ext_path
= test_data_dir_
.AppendASCII(ext_relpath
);
228 scoped_ptr
<WebstoreInstaller::Approval
> approval
;
230 approval
= GetApproval(ext_relpath
, id
, true);
232 base::FilePath crx_path
= PackExtension(ext_path
);
233 EXPECT_FALSE(crx_path
.empty());
234 RunCrxInstaller(approval
.get(), mock_install_prompt
->CreatePrompt(),
237 EXPECT_TRUE(mock_install_prompt
->did_succeed());
240 // Installs an extension and checks that it has scopes granted IFF
241 // |record_oauth2_grant| is true.
242 void CheckHasEmptyScopesAfterInstall(const std::string
& ext_relpath
,
243 bool record_oauth2_grant
) {
244 ScopedExperimentalCommandLine scope
;
246 scoped_refptr
<MockPromptProxy
> mock_prompt
=
247 CreateMockPromptProxyForBrowser(browser());
249 mock_prompt
->set_record_oauth2_grant(record_oauth2_grant
);
250 InstallWithPrompt("browsertest/scopes", std::string(), mock_prompt
);
252 scoped_refptr
<PermissionSet
> permissions
=
253 ExtensionPrefs::Get(browser()->profile())
254 ->GetGrantedPermissions(mock_prompt
->extension_id());
255 ASSERT_TRUE(permissions
.get());
258 // Returns a FilePath to an unpacked "experimental" extension (a test
259 // Extension which requests the "experimental" permission).
260 base::FilePath
PackExperimentalExtension() {
261 // We must modify the command line temporarily in order to pack an
262 // extension that requests the experimental permission.
263 ScopedExperimentalCommandLine scope
;
264 base::FilePath test_path
= test_data_dir_
.AppendASCII("experimental");
265 base::FilePath crx_path
= PackExtension(test_path
);
266 CHECK(!crx_path
.empty()) << "Extension not found at " << test_path
.value();
271 // This test is skipped on ChromeOS because it requires the NPAPI,
272 // which is not available on that platform.
273 #if !defined(OS_CHROMEOS)
274 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest
, Whitelisting
) {
275 std::string id
= "hdgllgikmikobbofgnabhfimcfoopgnd";
276 ExtensionRegistry
* registry
= ExtensionRegistry::Get(
277 browser()->profile());
279 // Even whitelisted extensions with NPAPI should not prompt.
280 scoped_refptr
<MockPromptProxy
> mock_prompt
=
281 CreateMockPromptProxyForBrowser(browser());
282 InstallWithPrompt("uitest/plugins", id
, mock_prompt
);
283 EXPECT_FALSE(mock_prompt
->confirmation_requested());
284 EXPECT_TRUE(registry
->enabled_extensions().GetByID(id
));
288 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest
,
289 ExperimentalExtensionFromGallery
) {
290 // Gallery-installed extensions should have their experimental permission
291 // preserved, since we allow the Webstore to make that decision.
292 base::FilePath crx_path
= PackExperimentalExtension();
293 const Extension
* extension
= InstallExtensionFromWebstore(crx_path
, 1);
294 ASSERT_TRUE(extension
);
295 EXPECT_TRUE(extension
->permissions_data()->HasAPIPermission(
296 APIPermission::kExperimental
));
299 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest
,
300 ExperimentalExtensionFromOutsideGallery
) {
301 // Non-gallery-installed extensions should lose their experimental
302 // permission if the flag isn't enabled.
303 base::FilePath crx_path
= PackExperimentalExtension();
304 const Extension
* extension
= InstallExtension(crx_path
, 1);
305 ASSERT_TRUE(extension
);
306 EXPECT_FALSE(extension
->permissions_data()->HasAPIPermission(
307 APIPermission::kExperimental
));
310 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest
,
311 ExperimentalExtensionFromOutsideGalleryWithFlag
) {
312 // Non-gallery-installed extensions should maintain their experimental
313 // permission if the flag is enabled.
314 base::FilePath crx_path
= PackExperimentalExtension();
315 ScopedExperimentalCommandLine scope
;
316 const Extension
* extension
= InstallExtension(crx_path
, 1);
317 ASSERT_TRUE(extension
);
318 EXPECT_TRUE(extension
->permissions_data()->HasAPIPermission(
319 APIPermission::kExperimental
));
322 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest
, PlatformAppCrx
) {
323 ScopedExperimentalCommandLine scope
;
324 EXPECT_TRUE(InstallExtension(
325 test_data_dir_
.AppendASCII("minimal_platform_app.crx"), 1));
328 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest
, PackAndInstallExtension
) {
329 if (!FeatureSwitch::easy_off_store_install()->IsEnabled())
332 const int kNumDownloadsExpected
= 1;
334 LOG(ERROR
) << "PackAndInstallExtension: Packing extension";
335 base::FilePath crx_path
= PackExtension(
336 test_data_dir_
.AppendASCII("common/background_page"));
337 ASSERT_FALSE(crx_path
.empty());
338 std::string
crx_path_string(crx_path
.value().begin(), crx_path
.value().end());
339 GURL url
= GURL(std::string("file:///").append(crx_path_string
));
341 scoped_refptr
<MockPromptProxy
> mock_prompt
=
342 CreateMockPromptProxyForBrowser(browser());
343 download_crx_util::SetMockInstallPromptForTesting(
344 mock_prompt
->CreatePrompt());
346 LOG(ERROR
) << "PackAndInstallExtension: Getting download manager";
347 content::DownloadManager
* download_manager
=
348 content::BrowserContext::GetDownloadManager(browser()->profile());
350 LOG(ERROR
) << "PackAndInstallExtension: Setting observer";
351 scoped_ptr
<content::DownloadTestObserver
> observer(
352 new content::DownloadTestObserverTerminal(
353 download_manager
, kNumDownloadsExpected
,
354 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT
));
355 LOG(ERROR
) << "PackAndInstallExtension: Navigating to URL";
356 ui_test_utils::NavigateToURLWithDisposition(browser(), url
, CURRENT_TAB
,
357 ui_test_utils::BROWSER_TEST_NONE
);
359 EXPECT_TRUE(WaitForCrxInstallerDone());
360 LOG(ERROR
) << "PackAndInstallExtension: Extension install";
361 EXPECT_TRUE(mock_prompt
->confirmation_requested());
362 LOG(ERROR
) << "PackAndInstallExtension: Extension install confirmed";
365 // Tests that scopes are only granted if |record_oauth2_grant_| on the prompt is
368 #define MAYBE_GrantScopes DISABLED_GrantScopes
370 #define MAYBE_GrantScopes GrantScopes
372 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest
, MAYBE_GrantScopes
) {
373 EXPECT_NO_FATAL_FAILURE(CheckHasEmptyScopesAfterInstall("browsertest/scopes",
377 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest
, DoNotGrantScopes
) {
378 EXPECT_NO_FATAL_FAILURE(CheckHasEmptyScopesAfterInstall("browsertest/scopes",
382 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest
, AllowOffStore
) {
383 ExtensionService
* service
= extensions::ExtensionSystem::Get(
384 browser()->profile())->extension_service();
385 const bool kTestData
[] = {false, true};
387 for (size_t i
= 0; i
< arraysize(kTestData
); ++i
) {
388 scoped_refptr
<MockPromptProxy
> mock_prompt
=
389 CreateMockPromptProxyForBrowser(browser());
391 scoped_refptr
<CrxInstaller
> crx_installer(
392 CrxInstaller::Create(service
, mock_prompt
->CreatePrompt()));
393 crx_installer
->set_install_cause(
394 extension_misc::INSTALL_CAUSE_USER_DOWNLOAD
);
397 crx_installer
->set_off_store_install_allow_reason(
398 CrxInstaller::OffStoreInstallAllowedInTest
);
401 crx_installer
->InstallCrx(test_data_dir_
.AppendASCII("good.crx"));
402 // The |mock_prompt| will quit running the loop once the |crx_installer|
404 content::RunMessageLoop();
405 EXPECT_EQ(kTestData
[i
], mock_prompt
->did_succeed());
406 EXPECT_EQ(kTestData
[i
], mock_prompt
->confirmation_requested()) <<
409 EXPECT_EQ(base::string16(), mock_prompt
->error()) << kTestData
[i
];
411 EXPECT_EQ(l10n_util::GetStringUTF16(
412 IDS_EXTENSION_INSTALL_DISALLOWED_ON_SITE
),
413 mock_prompt
->error()) << kTestData
[i
];
418 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest
, HiDpiThemeTest
) {
419 base::FilePath crx_path
= test_data_dir_
.AppendASCII("theme_hidpi_crx");
420 crx_path
= crx_path
.AppendASCII("theme_hidpi.crx");
422 ASSERT_TRUE(InstallExtension(crx_path
, 1));
424 const std::string
extension_id("gllekhaobjnhgeagipipnkpmmmpchacm");
425 ExtensionRegistry
* registry
= ExtensionRegistry::Get(
426 browser()->profile());
427 const extensions::Extension
* extension
=
428 registry
->enabled_extensions().GetByID(extension_id
);
429 ASSERT_TRUE(extension
);
430 EXPECT_EQ(extension_id
, extension
->id());
432 UninstallExtension(extension_id
);
433 EXPECT_FALSE(registry
->enabled_extensions().GetByID(extension_id
));
436 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest
,
437 InstallDelayedUntilNextUpdate
) {
438 const std::string
extension_id("ldnnhddmnhbkjipkidpdiheffobcpfmf");
439 base::FilePath base_path
= test_data_dir_
.AppendASCII("delayed_install");
441 ExtensionSystem
* extension_system
= extensions::ExtensionSystem::Get(
442 browser()->profile());
443 ExtensionService
* service
= extension_system
->extension_service();
444 ASSERT_TRUE(service
);
445 ExtensionRegistry
* registry
= ExtensionRegistry::Get(
446 browser()->profile());
447 ASSERT_TRUE(registry
);
449 // Install version 1 of the test extension. This extension does not have
450 // a background page but does have a browser action.
451 base::FilePath v1_path
= PackExtension(base_path
.AppendASCII("v1"));
452 ASSERT_FALSE(v1_path
.empty());
453 ASSERT_TRUE(InstallExtension(v1_path
, 1));
454 const extensions::Extension
* extension
=
455 registry
->enabled_extensions().GetByID(extension_id
);
456 ASSERT_TRUE(extension
);
457 ASSERT_EQ(extension_id
, extension
->id());
458 ASSERT_EQ("1.0", extension
->version()->GetString());
460 // Make test extension non-idle by opening the extension's options page.
461 ExtensionTabUtil::OpenOptionsPage(extension
, browser());
462 WaitForExtensionNotIdle(extension_id
);
464 // Install version 2 of the extension and check that it is indeed delayed.
465 base::FilePath v2_path
= PackExtension(base_path
.AppendASCII("v2"));
466 ASSERT_FALSE(v2_path
.empty());
467 ASSERT_TRUE(UpdateExtensionWaitForIdle(extension_id
, v2_path
, 0));
469 ASSERT_EQ(1u, service
->delayed_installs()->size());
470 extension
= registry
->enabled_extensions().GetByID(extension_id
);
471 ASSERT_EQ("1.0", extension
->version()->GetString());
473 // Make the extension idle again by navigating away from the options page.
474 // This should not trigger the delayed install.
475 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
476 WaitForExtensionIdle(extension_id
);
477 ASSERT_EQ(1u, service
->delayed_installs()->size());
478 extension
= registry
->enabled_extensions().GetByID(extension_id
);
479 ASSERT_EQ("1.0", extension
->version()->GetString());
481 // Install version 3 of the extension. Because the extension is idle,
482 // this install should succeed.
483 base::FilePath v3_path
= PackExtension(base_path
.AppendASCII("v3"));
484 ASSERT_FALSE(v3_path
.empty());
485 ASSERT_TRUE(UpdateExtensionWaitForIdle(extension_id
, v3_path
, 0));
486 extension
= registry
->enabled_extensions().GetByID(extension_id
);
487 ASSERT_EQ("3.0", extension
->version()->GetString());
489 // The version 2 delayed install should be cleaned up, and finishing
490 // delayed extension installation shouldn't break anything.
491 ASSERT_EQ(0u, service
->delayed_installs()->size());
492 service
->MaybeFinishDelayedInstallations();
493 extension
= registry
->enabled_extensions().GetByID(extension_id
);
494 ASSERT_EQ("3.0", extension
->version()->GetString());
497 #if defined(FULL_SAFE_BROWSING)
498 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest
, Blacklist
) {
499 scoped_refptr
<FakeSafeBrowsingDatabaseManager
> blacklist_db(
500 new FakeSafeBrowsingDatabaseManager(true));
501 Blacklist::ScopedDatabaseManagerForTest
scoped_blacklist_db(blacklist_db
);
503 blacklist_db
->SetUnsafe("gllekhaobjnhgeagipipnkpmmmpchacm");
505 base::FilePath crx_path
= test_data_dir_
.AppendASCII("theme_hidpi_crx")
506 .AppendASCII("theme_hidpi.crx");
507 EXPECT_FALSE(InstallExtension(crx_path
, 0));
511 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest
, NonStrictManifestCheck
) {
512 scoped_refptr
<MockPromptProxy
> mock_prompt
=
513 CreateMockPromptProxyForBrowser(browser());
515 // We want to simulate the case where the webstore sends a more recent
516 // version of the manifest, but the downloaded .crx file is old since
517 // the newly published version hasn't fully propagated to all the download
518 // servers yet. So load the v2 manifest, but then install the v1 crx file.
519 std::string id
= "lhnaeclnpobnlbjbgogdanmhadigfnjp";
520 scoped_ptr
<WebstoreInstaller::Approval
> approval
=
521 GetApproval("crx_installer/v2_no_permission_change/", id
, false);
523 RunCrxInstaller(approval
.get(), mock_prompt
->CreatePrompt(),
524 test_data_dir_
.AppendASCII("crx_installer/v1.crx"));
526 EXPECT_TRUE(mock_prompt
->did_succeed());
529 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest
, KioskOnlyTest
) {
530 base::FilePath crx_path
=
531 test_data_dir_
.AppendASCII("kiosk/kiosk_only.crx");
532 EXPECT_FALSE(InstallExtension(crx_path
, 0));
533 #if defined(OS_CHROMEOS)
534 // Simulate ChromeOS kiosk mode. |scoped_user_manager| will take over
535 // lifetime of |user_manager|.
536 chromeos::FakeChromeUserManager
* fake_user_manager
=
537 new chromeos::FakeChromeUserManager();
538 fake_user_manager
->AddKioskAppUser("example@example.com");
539 fake_user_manager
->LoginUser("example@example.com");
540 chromeos::ScopedUserManagerEnabler
scoped_user_manager(fake_user_manager
);
541 EXPECT_TRUE(InstallExtension(crx_path
, 1));
545 #if defined(OS_CHROMEOS)
546 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest
, InstallToSharedLocation
) {
547 base::CommandLine::ForCurrentProcess()->AppendSwitch(
548 chromeos::switches::kEnableExtensionAssetsSharing
);
549 base::ScopedTempDir cache_dir
;
550 ASSERT_TRUE(cache_dir
.CreateUniqueTempDir());
551 ExtensionAssetsManagerChromeOS::SetSharedInstallDirForTesting(
554 base::FilePath crx_path
= test_data_dir_
.AppendASCII("crx_installer/v1.crx");
555 const extensions::Extension
* extension
= InstallExtension(
556 crx_path
, 1, extensions::Manifest::EXTERNAL_PREF
);
557 base::FilePath extension_path
= extension
->path();
558 EXPECT_TRUE(cache_dir
.path().IsParent(extension_path
));
559 EXPECT_TRUE(base::PathExists(extension_path
));
561 std::string extension_id
= extension
->id();
562 UninstallExtension(extension_id
);
563 ExtensionRegistry
* registry
= ExtensionRegistry::Get(
564 browser()->profile());
565 EXPECT_FALSE(registry
->enabled_extensions().GetByID(extension_id
));
567 content::RunAllBlockingPoolTasksUntilIdle();
569 EXPECT_FALSE(base::PathExists(extension_path
));
573 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest
, DoNotSync
) {
574 ExtensionService
* service
= extensions::ExtensionSystem::Get(
575 browser()->profile())->extension_service();
576 scoped_refptr
<CrxInstaller
> crx_installer(
577 CrxInstaller::CreateSilent(service
));
578 crx_installer
->set_do_not_sync(true);
579 crx_installer
->InstallCrx(test_data_dir_
.AppendASCII("good.crx"));
580 EXPECT_TRUE(WaitForCrxInstallerDone());
581 ASSERT_TRUE(crx_installer
->extension());
583 const ExtensionPrefs
* extension_prefs
=
584 ExtensionPrefs::Get(browser()->profile());
585 EXPECT_TRUE(extension_prefs
->DoNotSync(crx_installer
->extension()->id()));
586 EXPECT_FALSE(extensions::util::ShouldSync(crx_installer
->extension(),
587 browser()->profile()));
590 IN_PROC_BROWSER_TEST_F(ExtensionCrxInstallerTest
, ManagementPolicy
) {
591 ManagementPolicyMock policy
;
592 extensions::ExtensionSystem::Get(profile())
593 ->management_policy()
594 ->RegisterProvider(&policy
);
596 base::FilePath crx_path
= test_data_dir_
.AppendASCII("crx_installer/v1.crx");
597 EXPECT_FALSE(InstallExtension(crx_path
, 0));
600 } // namespace extensions