Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(507)

Side by Side Diff: chrome/browser/extensions/extension_service_unittest.cc

Issue 8380006: Exempt component and policy-installed extensions from policy blacklist check. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase, add comment regarding policy check on startup. Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/extensions/extension_service.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/extensions/extension_service_unittest.h" 5 #include "chrome/browser/extensions/extension_service_unittest.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 2581 matching lines...) Expand 10 before | Expand all | Expand 10 after
2592 // Blacklist this extension. 2592 // Blacklist this extension.
2593 blacklist->Append(Value::CreateStringValue(good_crx)); 2593 blacklist->Append(Value::CreateStringValue(good_crx));
2594 prefs->ScheduleSavePersistentPrefs(); 2594 prefs->ScheduleSavePersistentPrefs();
2595 } 2595 }
2596 2596
2597 // Extension should not be running now. 2597 // Extension should not be running now.
2598 loop_.RunAllPending(); 2598 loop_.RunAllPending();
2599 EXPECT_EQ(0u, service_->extensions()->size()); 2599 EXPECT_EQ(0u, service_->extensions()->size());
2600 } 2600 }
2601 2601
2602 // Tests that component extensions are not blacklisted by policy.
2603 TEST_F(ExtensionServiceTest, ComponentExtensionWhitelisted) {
2604 InitializeEmptyExtensionService();
2605
2606 // Blacklist everything.
2607 {
2608 ListPrefUpdate update(profile_->GetPrefs(),
2609 prefs::kExtensionInstallDenyList);
2610 ListValue* blacklist = update.Get();
2611 blacklist->Append(Value::CreateStringValue("*"));
2612 }
2613
2614 // Install a component extension.
2615 FilePath path = data_dir_
2616 .AppendASCII("good")
2617 .AppendASCII("Extensions")
2618 .AppendASCII(good0)
2619 .AppendASCII("1.0.0.0");
2620 std::string manifest;
2621 ASSERT_TRUE(file_util::ReadFileToString(
2622 path.Append(Extension::kManifestFilename), &manifest));
2623 service_->register_component_extension(
2624 ExtensionService::ComponentExtensionInfo(manifest, path));
2625 service_->Init();
2626
2627 // Extension should be installed despite blacklist.
2628 ASSERT_EQ(1u, service_->extensions()->size());
2629 EXPECT_EQ(good0, service_->extensions()->at(0)->id());
2630
2631 // Poke external providers and make sure the extension is still present.
2632 service_->CheckForExternalUpdates();
2633 ASSERT_EQ(1u, service_->extensions()->size());
2634 EXPECT_EQ(good0, service_->extensions()->at(0)->id());
2635
2636 // Extension should not be uninstalled on blacklist changes.
2637 {
2638 ListPrefUpdate update(profile_->GetPrefs(),
2639 prefs::kExtensionInstallDenyList);
2640 ListValue* blacklist = update.Get();
2641 blacklist->Append(Value::CreateStringValue(good0));
2642 }
2643 loop_.RunAllPending();
2644 ASSERT_EQ(1u, service_->extensions()->size());
2645 EXPECT_EQ(good0, service_->extensions()->at(0)->id());
2646 }
2647
2648 // Tests that policy-installed extensions are not blacklisted by policy.
2649 TEST_F(ExtensionServiceTest, PolicyInstalledExtensionsWhitelisted) {
2650 InitializeEmptyExtensionService();
2651
2652 // Blacklist everything.
2653 {
2654 ListPrefUpdate update(profile_->GetPrefs(),
2655 prefs::kExtensionInstallDenyList);
2656 ListValue* blacklist = update.Get();
2657 blacklist->Append(Value::CreateStringValue("*"));
2658 }
2659
2660 // Have policy force-install an extension.
2661 MockExtensionProvider* provider =
2662 new MockExtensionProvider(service_,
2663 Extension::EXTERNAL_POLICY_DOWNLOAD);
2664 AddMockExternalProvider(provider);
2665 provider->UpdateOrAddExtension(good_crx, "1.0.0.0",
2666 data_dir_.AppendASCII("good.crx"));
2667
2668 // Reloading extensions should find our externally registered extension
2669 // and install it.
2670 service_->CheckForExternalUpdates();
2671 loop_.RunAllPending();
2672
2673 // Extension should be installed despite blacklist.
2674 ASSERT_EQ(1u, service_->extensions()->size());
2675 EXPECT_EQ(good_crx, service_->extensions()->at(0)->id());
2676
2677 // Blacklist update should not uninstall the extension.
2678 {
2679 ListPrefUpdate update(profile_->GetPrefs(),
2680 prefs::kExtensionInstallDenyList);
2681 ListValue* blacklist = update.Get();
2682 blacklist->Append(Value::CreateStringValue(good0));
2683 }
2684 loop_.RunAllPending();
2685 ASSERT_EQ(1u, service_->extensions()->size());
2686 EXPECT_EQ(good_crx, service_->extensions()->at(0)->id());
2687 }
2688
2602 // Tests disabling extensions 2689 // Tests disabling extensions
2603 TEST_F(ExtensionServiceTest, DisableExtension) { 2690 TEST_F(ExtensionServiceTest, DisableExtension) {
2604 InitializeEmptyExtensionService(); 2691 InitializeEmptyExtensionService();
2605 2692
2606 InstallCrx(data_dir_.AppendASCII("good.crx"), true); 2693 InstallCrx(data_dir_.AppendASCII("good.crx"), true);
2607 EXPECT_FALSE(service_->extensions()->empty()); 2694 EXPECT_FALSE(service_->extensions()->empty());
2608 EXPECT_TRUE(service_->GetExtensionById(good_crx, true) != NULL); 2695 EXPECT_TRUE(service_->GetExtensionById(good_crx, true) != NULL);
2609 EXPECT_TRUE(service_->GetExtensionById(good_crx, false) != NULL); 2696 EXPECT_TRUE(service_->GetExtensionById(good_crx, false) != NULL);
2610 EXPECT_TRUE(service_->disabled_extensions()->empty()); 2697 EXPECT_TRUE(service_->disabled_extensions()->empty());
2611 2698
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
3138 service_->OnExternalProviderReady(provider); 3225 service_->OnExternalProviderReady(provider);
3139 loop_.RunAllPending(); 3226 loop_.RunAllPending();
3140 ASSERT_EQ(0u, loaded_.size()); 3227 ASSERT_EQ(0u, loaded_.size());
3141 ValidatePrefKeyCount(0); 3228 ValidatePrefKeyCount(0);
3142 3229
3143 // The extension should also be gone from the install directory. 3230 // The extension should also be gone from the install directory.
3144 ASSERT_FALSE(file_util::PathExists(install_path)); 3231 ASSERT_FALSE(file_util::PathExists(install_path));
3145 3232
3146 // Now test the case where user uninstalls and then the extension is removed 3233 // Now test the case where user uninstalls and then the extension is removed
3147 // from the external provider. 3234 // from the external provider.
3148 3235 provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path);
3149 provider->UpdateOrAddExtension(good_crx, "1.0.0.1", source_path);
3150 service_->CheckForExternalUpdates(); 3236 service_->CheckForExternalUpdates();
3151 loop_.RunAllPending(); 3237 loop_.RunAllPending();
3152 3238
3153 ASSERT_EQ(1u, loaded_.size()); 3239 ASSERT_EQ(1u, loaded_.size());
3154 ASSERT_EQ(0u, GetErrors().size()); 3240 ASSERT_EQ(0u, GetErrors().size());
3155 3241
3156 // User uninstalls. 3242 // User uninstalls.
3157 loaded_.clear(); 3243 loaded_.clear();
3158 service_->UninstallExtension(id, false, NULL); 3244 service_->UninstallExtension(id, false, NULL);
3159 loop_.RunAllPending(); 3245 loop_.RunAllPending();
(...skipping 1074 matching lines...) Expand 10 before | Expand all | Expand 10 after
4234 ASSERT_FALSE(AddPendingSyncInstall()); 4320 ASSERT_FALSE(AddPendingSyncInstall());
4235 4321
4236 // Wait for the external source to install. 4322 // Wait for the external source to install.
4237 WaitForCrxInstall(crx_path_, true); 4323 WaitForCrxInstall(crx_path_, true);
4238 ASSERT_TRUE(IsCrxInstalled()); 4324 ASSERT_TRUE(IsCrxInstalled());
4239 4325
4240 // Now that the extension is installed, sync request should fail 4326 // Now that the extension is installed, sync request should fail
4241 // because the extension is already installed. 4327 // because the extension is already installed.
4242 ASSERT_FALSE(AddPendingSyncInstall()); 4328 ASSERT_FALSE(AddPendingSyncInstall());
4243 } 4329 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698