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/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "chrome/browser/extensions/extension_browsertest.h" | 10 #include "chrome/browser/extensions/extension_browsertest.h" |
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 interceptor.SetResponseIgnoreQuery( | 504 interceptor.SetResponseIgnoreQuery( |
505 GURL("http://localhost/autoupdate/manifest"), | 505 GURL("http://localhost/autoupdate/manifest"), |
506 basedir.AppendASCII("manifest_v2.xml")); | 506 basedir.AppendASCII("manifest_v2.xml")); |
507 interceptor.SetResponseIgnoreQuery(GURL("http://localhost/autoupdate/v2.crx"), | 507 interceptor.SetResponseIgnoreQuery(GURL("http://localhost/autoupdate/v2.crx"), |
508 basedir.AppendASCII("v2.crx")); | 508 basedir.AppendASCII("v2.crx")); |
509 | 509 |
510 const size_t size_before = service->extensions()->size(); | 510 const size_t size_before = service->extensions()->size(); |
511 ASSERT_TRUE(service->disabled_extensions()->is_empty()); | 511 ASSERT_TRUE(service->disabled_extensions()->is_empty()); |
512 | 512 |
513 PrefService* prefs = browser()->profile()->GetPrefs(); | 513 PrefService* prefs = browser()->profile()->GetPrefs(); |
514 const DictionaryValue* forcelist = | 514 const base::DictionaryValue* forcelist = |
515 prefs->GetDictionary(prefs::kExtensionInstallForceList); | 515 prefs->GetDictionary(prefs::kExtensionInstallForceList); |
516 ASSERT_TRUE(forcelist->empty()) << kForceInstallNotEmptyHelp; | 516 ASSERT_TRUE(forcelist->empty()) << kForceInstallNotEmptyHelp; |
517 | 517 |
518 { | 518 { |
519 // Set the policy as a user preference and fire notification observers. | 519 // Set the policy as a user preference and fire notification observers. |
520 DictionaryPrefUpdate pref_update(prefs, prefs::kExtensionInstallForceList); | 520 DictionaryPrefUpdate pref_update(prefs, prefs::kExtensionInstallForceList); |
521 DictionaryValue* forcelist = pref_update.Get(); | 521 base::DictionaryValue* forcelist = pref_update.Get(); |
522 extensions::ExternalPolicyLoader::AddExtension( | 522 extensions::ExternalPolicyLoader::AddExtension( |
523 forcelist, kExtensionId, "http://localhost/autoupdate/manifest"); | 523 forcelist, kExtensionId, "http://localhost/autoupdate/manifest"); |
524 } | 524 } |
525 | 525 |
526 // Check if the extension got installed. | 526 // Check if the extension got installed. |
527 ASSERT_TRUE(WaitForExtensionInstall()); | 527 ASSERT_TRUE(WaitForExtensionInstall()); |
528 ASSERT_EQ(size_before + 1, service->extensions()->size()); | 528 ASSERT_EQ(size_before + 1, service->extensions()->size()); |
529 const Extension* extension = service->GetExtensionById(kExtensionId, false); | 529 const Extension* extension = service->GetExtensionById(kExtensionId, false); |
530 ASSERT_TRUE(extension); | 530 ASSERT_TRUE(extension); |
531 ASSERT_EQ("2.0", extension->VersionString()); | 531 ASSERT_EQ("2.0", extension->VersionString()); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 net::URLFetcher::SetEnableInterceptionForTests(true); | 577 net::URLFetcher::SetEnableInterceptionForTests(true); |
578 | 578 |
579 interceptor.SetResponseIgnoreQuery( | 579 interceptor.SetResponseIgnoreQuery( |
580 GURL("http://localhost/autoupdate/manifest"), | 580 GURL("http://localhost/autoupdate/manifest"), |
581 basedir.AppendASCII("manifest_v2.xml")); | 581 basedir.AppendASCII("manifest_v2.xml")); |
582 interceptor.SetResponseIgnoreQuery(GURL("http://localhost/autoupdate/v2.crx"), | 582 interceptor.SetResponseIgnoreQuery(GURL("http://localhost/autoupdate/v2.crx"), |
583 basedir.AppendASCII("v2.crx")); | 583 basedir.AppendASCII("v2.crx")); |
584 | 584 |
585 // Check that the policy is initially empty. | 585 // Check that the policy is initially empty. |
586 PrefService* prefs = browser()->profile()->GetPrefs(); | 586 PrefService* prefs = browser()->profile()->GetPrefs(); |
587 const DictionaryValue* forcelist = | 587 const base::DictionaryValue* forcelist = |
588 prefs->GetDictionary(prefs::kExtensionInstallForceList); | 588 prefs->GetDictionary(prefs::kExtensionInstallForceList); |
589 ASSERT_TRUE(forcelist->empty()) << kForceInstallNotEmptyHelp; | 589 ASSERT_TRUE(forcelist->empty()) << kForceInstallNotEmptyHelp; |
590 | 590 |
591 // User install of the extension. | 591 // User install of the extension. |
592 ASSERT_TRUE(InstallExtension(basedir.AppendASCII("v2.crx"), 1)); | 592 ASSERT_TRUE(InstallExtension(basedir.AppendASCII("v2.crx"), 1)); |
593 ASSERT_EQ(size_before + 1, service->extensions()->size()); | 593 ASSERT_EQ(size_before + 1, service->extensions()->size()); |
594 const Extension* extension = service->GetExtensionById(kExtensionId, false); | 594 const Extension* extension = service->GetExtensionById(kExtensionId, false); |
595 ASSERT_TRUE(extension); | 595 ASSERT_TRUE(extension); |
596 EXPECT_EQ(Manifest::INTERNAL, extension->location()); | 596 EXPECT_EQ(Manifest::INTERNAL, extension->location()); |
597 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); | 597 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 DisableExtension(kExtensionId); | 631 DisableExtension(kExtensionId); |
632 EXPECT_EQ(1u, service->disabled_extensions()->size()); | 632 EXPECT_EQ(1u, service->disabled_extensions()->size()); |
633 extension = service->GetExtensionById(kExtensionId, true); | 633 extension = service->GetExtensionById(kExtensionId, true); |
634 EXPECT_TRUE(extension); | 634 EXPECT_TRUE(extension); |
635 EXPECT_FALSE(service->IsExtensionEnabled(kExtensionId)); | 635 EXPECT_FALSE(service->IsExtensionEnabled(kExtensionId)); |
636 | 636 |
637 // Install the policy again. It should overwrite the extension's location, | 637 // Install the policy again. It should overwrite the extension's location, |
638 // and force enable it too. | 638 // and force enable it too. |
639 { | 639 { |
640 DictionaryPrefUpdate pref_update(prefs, prefs::kExtensionInstallForceList); | 640 DictionaryPrefUpdate pref_update(prefs, prefs::kExtensionInstallForceList); |
641 DictionaryValue* forcelist = pref_update.Get(); | 641 base::DictionaryValue* forcelist = pref_update.Get(); |
642 extensions::ExternalPolicyLoader::AddExtension( | 642 extensions::ExternalPolicyLoader::AddExtension( |
643 forcelist, kExtensionId, "http://localhost/autoupdate/manifest"); | 643 forcelist, kExtensionId, "http://localhost/autoupdate/manifest"); |
644 } | 644 } |
645 ASSERT_TRUE(WaitForExtensionInstall()); | 645 ASSERT_TRUE(WaitForExtensionInstall()); |
646 ASSERT_EQ(size_before + 1, service->extensions()->size()); | 646 ASSERT_EQ(size_before + 1, service->extensions()->size()); |
647 extension = service->GetExtensionById(kExtensionId, false); | 647 extension = service->GetExtensionById(kExtensionId, false); |
648 ASSERT_TRUE(extension); | 648 ASSERT_TRUE(extension); |
649 EXPECT_EQ(Manifest::EXTERNAL_POLICY_DOWNLOAD, extension->location()); | 649 EXPECT_EQ(Manifest::EXTERNAL_POLICY_DOWNLOAD, extension->location()); |
650 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); | 650 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); |
651 EXPECT_TRUE(service->disabled_extensions()->is_empty()); | 651 EXPECT_TRUE(service->disabled_extensions()->is_empty()); |
652 } | 652 } |
OLD | NEW |