Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
| 7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/prefs/scoped_user_pref_update.h" | 9 #include "base/prefs/scoped_user_pref_update.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 11 #include "chrome/browser/extensions/extension_browsertest.h" | 11 #include "chrome/browser/extensions/extension_browsertest.h" |
| 12 #include "chrome/browser/extensions/extension_management.h" | |
| 12 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
| 13 #include "chrome/browser/extensions/extension_test_message_listener.h" | 14 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 14 #include "chrome/browser/extensions/external_policy_loader.h" | 15 #include "chrome/browser/extensions/external_policy_loader.h" |
| 15 #include "chrome/browser/extensions/updater/extension_downloader.h" | 16 #include "chrome/browser/extensions/updater/extension_downloader.h" |
| 16 #include "chrome/browser/extensions/updater/extension_updater.h" | 17 #include "chrome/browser/extensions/updater/extension_updater.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
| 19 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
| 20 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
| 21 #include "chrome/test/base/ui_test_utils.h" | 22 #include "chrome/test/base/ui_test_utils.h" |
| (...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 502 GURL("http://localhost/autoupdate/manifest"), | 503 GURL("http://localhost/autoupdate/manifest"), |
| 503 basedir.AppendASCII("manifest_v2.xml")); | 504 basedir.AppendASCII("manifest_v2.xml")); |
| 504 interceptor.SetResponseIgnoreQuery(GURL("http://localhost/autoupdate/v2.crx"), | 505 interceptor.SetResponseIgnoreQuery(GURL("http://localhost/autoupdate/v2.crx"), |
| 505 basedir.AppendASCII("v2.crx")); | 506 basedir.AppendASCII("v2.crx")); |
| 506 | 507 |
| 507 ExtensionRegistry* registry = ExtensionRegistry::Get(browser()->profile()); | 508 ExtensionRegistry* registry = ExtensionRegistry::Get(browser()->profile()); |
| 508 const size_t size_before = registry->enabled_extensions().size(); | 509 const size_t size_before = registry->enabled_extensions().size(); |
| 509 ASSERT_TRUE(registry->disabled_extensions().is_empty()); | 510 ASSERT_TRUE(registry->disabled_extensions().is_empty()); |
| 510 | 511 |
| 511 PrefService* prefs = browser()->profile()->GetPrefs(); | 512 PrefService* prefs = browser()->profile()->GetPrefs(); |
| 513 extensions::ExtensionManagementFactory::GetForBrowserContext( | |
| 514 browser()->profile())->AllowUserPreferenceForTesting(); | |
|
Joao da Silva
2014/09/07 14:30:21
Don't do this. The right way to mock policies for
binjin
2014/09/08 12:59:39
It's browser tests for extensions system, user pre
Joao da Silva
2014/09/08 13:18:29
This test code needs to be updated, because it was
binjin
2014/09/08 14:52:05
Got it. Done.
| |
| 512 const base::DictionaryValue* forcelist = | 515 const base::DictionaryValue* forcelist = |
| 513 prefs->GetDictionary(extensions::pref_names::kInstallForceList); | 516 prefs->GetDictionary(extensions::pref_names::kInstallForceList); |
| 514 ASSERT_TRUE(forcelist->empty()) << kForceInstallNotEmptyHelp; | 517 ASSERT_TRUE(forcelist->empty()) << kForceInstallNotEmptyHelp; |
| 515 | 518 |
| 516 { | 519 { |
| 517 // Set the policy as a user preference and fire notification observers. | 520 // Set the policy as a user preference and fire notification observers. |
| 518 DictionaryPrefUpdate pref_update(prefs, | 521 DictionaryPrefUpdate pref_update(prefs, |
| 519 extensions::pref_names::kInstallForceList); | 522 extensions::pref_names::kInstallForceList); |
| 520 base::DictionaryValue* forcelist = pref_update.Get(); | 523 base::DictionaryValue* forcelist = pref_update.Get(); |
| 521 extensions::ExternalPolicyLoader::AddExtension( | 524 extensions::ExternalPolicyLoader::AddExtension( |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 576 net::URLFetcher::SetEnableInterceptionForTests(true); | 579 net::URLFetcher::SetEnableInterceptionForTests(true); |
| 577 | 580 |
| 578 interceptor.SetResponseIgnoreQuery( | 581 interceptor.SetResponseIgnoreQuery( |
| 579 GURL("http://localhost/autoupdate/manifest"), | 582 GURL("http://localhost/autoupdate/manifest"), |
| 580 basedir.AppendASCII("manifest_v2.xml")); | 583 basedir.AppendASCII("manifest_v2.xml")); |
| 581 interceptor.SetResponseIgnoreQuery(GURL("http://localhost/autoupdate/v2.crx"), | 584 interceptor.SetResponseIgnoreQuery(GURL("http://localhost/autoupdate/v2.crx"), |
| 582 basedir.AppendASCII("v2.crx")); | 585 basedir.AppendASCII("v2.crx")); |
| 583 | 586 |
| 584 // Check that the policy is initially empty. | 587 // Check that the policy is initially empty. |
| 585 PrefService* prefs = browser()->profile()->GetPrefs(); | 588 PrefService* prefs = browser()->profile()->GetPrefs(); |
| 589 extensions::ExtensionManagementFactory::GetForBrowserContext( | |
| 590 browser()->profile())->AllowUserPreferenceForTesting(); | |
| 586 const base::DictionaryValue* forcelist = | 591 const base::DictionaryValue* forcelist = |
| 587 prefs->GetDictionary(extensions::pref_names::kInstallForceList); | 592 prefs->GetDictionary(extensions::pref_names::kInstallForceList); |
| 588 ASSERT_TRUE(forcelist->empty()) << kForceInstallNotEmptyHelp; | 593 ASSERT_TRUE(forcelist->empty()) << kForceInstallNotEmptyHelp; |
| 589 | 594 |
| 590 // User install of the extension. | 595 // User install of the extension. |
| 591 ASSERT_TRUE(InstallExtension(basedir.AppendASCII("v2.crx"), 1)); | 596 ASSERT_TRUE(InstallExtension(basedir.AppendASCII("v2.crx"), 1)); |
| 592 ASSERT_EQ(size_before + 1, registry->enabled_extensions().size()); | 597 ASSERT_EQ(size_before + 1, registry->enabled_extensions().size()); |
| 593 const Extension* extension = service->GetExtensionById(kExtensionId, false); | 598 const Extension* extension = service->GetExtensionById(kExtensionId, false); |
| 594 ASSERT_TRUE(extension); | 599 ASSERT_TRUE(extension); |
| 595 EXPECT_EQ(Manifest::INTERNAL, extension->location()); | 600 EXPECT_EQ(Manifest::INTERNAL, extension->location()); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 644 forcelist, kExtensionId, "http://localhost/autoupdate/manifest"); | 649 forcelist, kExtensionId, "http://localhost/autoupdate/manifest"); |
| 645 } | 650 } |
| 646 ASSERT_TRUE(WaitForExtensionInstall()); | 651 ASSERT_TRUE(WaitForExtensionInstall()); |
| 647 ASSERT_EQ(size_before + 1, registry->enabled_extensions().size()); | 652 ASSERT_EQ(size_before + 1, registry->enabled_extensions().size()); |
| 648 extension = service->GetExtensionById(kExtensionId, false); | 653 extension = service->GetExtensionById(kExtensionId, false); |
| 649 ASSERT_TRUE(extension); | 654 ASSERT_TRUE(extension); |
| 650 EXPECT_EQ(Manifest::EXTERNAL_POLICY_DOWNLOAD, extension->location()); | 655 EXPECT_EQ(Manifest::EXTERNAL_POLICY_DOWNLOAD, extension->location()); |
| 651 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); | 656 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); |
| 652 EXPECT_TRUE(registry->disabled_extensions().is_empty()); | 657 EXPECT_TRUE(registry->disabled_extensions().is_empty()); |
| 653 } | 658 } |
| OLD | NEW |