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

Side by Side Diff: chrome/browser/extensions/api/management/management_browsertest.cc

Issue 140343002: extensions: Relocate pref name constants. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add missing include for mac Created 6 years, 11 months 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
OLDNEW
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/chrome_notification_types.h" 11 #include "chrome/browser/chrome_notification_types.h"
12 #include "chrome/browser/extensions/extension_browsertest.h" 12 #include "chrome/browser/extensions/extension_browsertest.h"
13 #include "chrome/browser/extensions/extension_host.h" 13 #include "chrome/browser/extensions/extension_host.h"
14 #include "chrome/browser/extensions/extension_service.h" 14 #include "chrome/browser/extensions/extension_service.h"
15 #include "chrome/browser/extensions/extension_system.h" 15 #include "chrome/browser/extensions/extension_system.h"
16 #include "chrome/browser/extensions/extension_test_message_listener.h" 16 #include "chrome/browser/extensions/extension_test_message_listener.h"
17 #include "chrome/browser/extensions/external_policy_loader.h" 17 #include "chrome/browser/extensions/external_policy_loader.h"
18 #include "chrome/browser/extensions/updater/extension_downloader.h" 18 #include "chrome/browser/extensions/updater/extension_downloader.h"
19 #include "chrome/browser/extensions/updater/extension_updater.h" 19 #include "chrome/browser/extensions/updater/extension_updater.h"
20 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/ui/browser.h" 21 #include "chrome/browser/ui/browser.h"
22 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
23 #include "chrome/common/url_constants.h" 23 #include "chrome/common/url_constants.h"
24 #include "chrome/test/base/ui_test_utils.h" 24 #include "chrome/test/base/ui_test_utils.h"
25 #include "content/public/browser/notification_service.h" 25 #include "content/public/browser/notification_service.h"
26 #include "content/public/browser/render_view_host.h" 26 #include "content/public/browser/render_view_host.h"
27 #include "content/public/test/browser_test_utils.h" 27 #include "content/public/test/browser_test_utils.h"
28 #include "content/test/net/url_request_prepackaged_interceptor.h" 28 #include "content/test/net/url_request_prepackaged_interceptor.h"
29 #include "extensions/browser/pref_names.h"
29 #include "net/url_request/url_fetcher.h" 30 #include "net/url_request/url_fetcher.h"
30 31
31 using extensions::Extension; 32 using extensions::Extension;
32 using extensions::Manifest; 33 using extensions::Manifest;
33 34
34 class ExtensionManagementTest : public ExtensionBrowserTest { 35 class ExtensionManagementTest : public ExtensionBrowserTest {
35 protected: 36 protected:
36 // Helper method that returns whether the extension is at the given version. 37 // Helper method that returns whether the extension is at the given version.
37 // This calls version(), which must be defined in the extension's bg page, 38 // This calls version(), which must be defined in the extension's bg page,
38 // as well as asking the extension itself. 39 // as well as asking the extension itself.
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 GURL("http://localhost/autoupdate/manifest"), 490 GURL("http://localhost/autoupdate/manifest"),
490 basedir.AppendASCII("manifest_v2.xml")); 491 basedir.AppendASCII("manifest_v2.xml"));
491 interceptor.SetResponseIgnoreQuery(GURL("http://localhost/autoupdate/v2.crx"), 492 interceptor.SetResponseIgnoreQuery(GURL("http://localhost/autoupdate/v2.crx"),
492 basedir.AppendASCII("v2.crx")); 493 basedir.AppendASCII("v2.crx"));
493 494
494 const size_t size_before = service->extensions()->size(); 495 const size_t size_before = service->extensions()->size();
495 ASSERT_TRUE(service->disabled_extensions()->is_empty()); 496 ASSERT_TRUE(service->disabled_extensions()->is_empty());
496 497
497 PrefService* prefs = browser()->profile()->GetPrefs(); 498 PrefService* prefs = browser()->profile()->GetPrefs();
498 const base::DictionaryValue* forcelist = 499 const base::DictionaryValue* forcelist =
499 prefs->GetDictionary(prefs::kExtensionInstallForceList); 500 prefs->GetDictionary(extensions::pref_names::kInstallForceList);
500 ASSERT_TRUE(forcelist->empty()) << kForceInstallNotEmptyHelp; 501 ASSERT_TRUE(forcelist->empty()) << kForceInstallNotEmptyHelp;
501 502
502 { 503 {
503 // Set the policy as a user preference and fire notification observers. 504 // Set the policy as a user preference and fire notification observers.
504 DictionaryPrefUpdate pref_update(prefs, prefs::kExtensionInstallForceList); 505 DictionaryPrefUpdate pref_update(prefs,
506 extensions::pref_names::kInstallForceList);
505 base::DictionaryValue* forcelist = pref_update.Get(); 507 base::DictionaryValue* forcelist = pref_update.Get();
506 extensions::ExternalPolicyLoader::AddExtension( 508 extensions::ExternalPolicyLoader::AddExtension(
507 forcelist, kExtensionId, "http://localhost/autoupdate/manifest"); 509 forcelist, kExtensionId, "http://localhost/autoupdate/manifest");
508 } 510 }
509 511
510 // Check if the extension got installed. 512 // Check if the extension got installed.
511 ASSERT_TRUE(WaitForExtensionInstall()); 513 ASSERT_TRUE(WaitForExtensionInstall());
512 ASSERT_EQ(size_before + 1, service->extensions()->size()); 514 ASSERT_EQ(size_before + 1, service->extensions()->size());
513 const Extension* extension = service->GetExtensionById(kExtensionId, false); 515 const Extension* extension = service->GetExtensionById(kExtensionId, false);
514 ASSERT_TRUE(extension); 516 ASSERT_TRUE(extension);
(...skipping 10 matching lines...) Expand all
525 527
526 // Now try to disable it through the management api, again failing. 528 // Now try to disable it through the management api, again failing.
527 ExtensionTestMessageListener listener1("ready", false); 529 ExtensionTestMessageListener listener1("ready", false);
528 ASSERT_TRUE(LoadExtension( 530 ASSERT_TRUE(LoadExtension(
529 test_data_dir_.AppendASCII("management/uninstall_extension"))); 531 test_data_dir_.AppendASCII("management/uninstall_extension")));
530 ASSERT_TRUE(listener1.WaitUntilSatisfied()); 532 ASSERT_TRUE(listener1.WaitUntilSatisfied());
531 EXPECT_EQ(size_before + 2, service->extensions()->size()); 533 EXPECT_EQ(size_before + 2, service->extensions()->size());
532 EXPECT_EQ(0u, service->disabled_extensions()->size()); 534 EXPECT_EQ(0u, service->disabled_extensions()->size());
533 535
534 // Check that emptying the list triggers uninstall. 536 // Check that emptying the list triggers uninstall.
535 prefs->ClearPref(prefs::kExtensionInstallForceList); 537 prefs->ClearPref(extensions::pref_names::kInstallForceList);
536 EXPECT_EQ(size_before + 1, service->extensions()->size()); 538 EXPECT_EQ(size_before + 1, service->extensions()->size());
537 EXPECT_FALSE(service->GetExtensionById(kExtensionId, true)); 539 EXPECT_FALSE(service->GetExtensionById(kExtensionId, true));
538 } 540 }
539 541
540 // See http://crbug.com/103371 and http://crbug.com/120640. 542 // See http://crbug.com/103371 and http://crbug.com/120640.
541 #if defined(ADDRESS_SANITIZER) || defined(OS_WIN) 543 #if defined(ADDRESS_SANITIZER) || defined(OS_WIN)
542 #define MAYBE_PolicyOverridesUserInstall DISABLED_PolicyOverridesUserInstall 544 #define MAYBE_PolicyOverridesUserInstall DISABLED_PolicyOverridesUserInstall
543 #else 545 #else
544 #define MAYBE_PolicyOverridesUserInstall PolicyOverridesUserInstall 546 #define MAYBE_PolicyOverridesUserInstall PolicyOverridesUserInstall
545 #endif 547 #endif
(...skipping 15 matching lines...) Expand all
561 563
562 interceptor.SetResponseIgnoreQuery( 564 interceptor.SetResponseIgnoreQuery(
563 GURL("http://localhost/autoupdate/manifest"), 565 GURL("http://localhost/autoupdate/manifest"),
564 basedir.AppendASCII("manifest_v2.xml")); 566 basedir.AppendASCII("manifest_v2.xml"));
565 interceptor.SetResponseIgnoreQuery(GURL("http://localhost/autoupdate/v2.crx"), 567 interceptor.SetResponseIgnoreQuery(GURL("http://localhost/autoupdate/v2.crx"),
566 basedir.AppendASCII("v2.crx")); 568 basedir.AppendASCII("v2.crx"));
567 569
568 // Check that the policy is initially empty. 570 // Check that the policy is initially empty.
569 PrefService* prefs = browser()->profile()->GetPrefs(); 571 PrefService* prefs = browser()->profile()->GetPrefs();
570 const base::DictionaryValue* forcelist = 572 const base::DictionaryValue* forcelist =
571 prefs->GetDictionary(prefs::kExtensionInstallForceList); 573 prefs->GetDictionary(extensions::pref_names::kInstallForceList);
572 ASSERT_TRUE(forcelist->empty()) << kForceInstallNotEmptyHelp; 574 ASSERT_TRUE(forcelist->empty()) << kForceInstallNotEmptyHelp;
573 575
574 // User install of the extension. 576 // User install of the extension.
575 ASSERT_TRUE(InstallExtension(basedir.AppendASCII("v2.crx"), 1)); 577 ASSERT_TRUE(InstallExtension(basedir.AppendASCII("v2.crx"), 1));
576 ASSERT_EQ(size_before + 1, service->extensions()->size()); 578 ASSERT_EQ(size_before + 1, service->extensions()->size());
577 const Extension* extension = service->GetExtensionById(kExtensionId, false); 579 const Extension* extension = service->GetExtensionById(kExtensionId, false);
578 ASSERT_TRUE(extension); 580 ASSERT_TRUE(extension);
579 EXPECT_EQ(Manifest::INTERNAL, extension->location()); 581 EXPECT_EQ(Manifest::INTERNAL, extension->location());
580 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); 582 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId));
581 583
582 // Setup the force install policy. It should override the location. 584 // Setup the force install policy. It should override the location.
583 { 585 {
584 DictionaryPrefUpdate pref_update(prefs, prefs::kExtensionInstallForceList); 586 DictionaryPrefUpdate pref_update(prefs,
587 extensions::pref_names::kInstallForceList);
585 extensions::ExternalPolicyLoader::AddExtension( 588 extensions::ExternalPolicyLoader::AddExtension(
586 pref_update.Get(), kExtensionId, 589 pref_update.Get(), kExtensionId,
587 "http://localhost/autoupdate/manifest"); 590 "http://localhost/autoupdate/manifest");
588 } 591 }
589 ASSERT_TRUE(WaitForExtensionInstall()); 592 ASSERT_TRUE(WaitForExtensionInstall());
590 ASSERT_EQ(size_before + 1, service->extensions()->size()); 593 ASSERT_EQ(size_before + 1, service->extensions()->size());
591 extension = service->GetExtensionById(kExtensionId, false); 594 extension = service->GetExtensionById(kExtensionId, false);
592 ASSERT_TRUE(extension); 595 ASSERT_TRUE(extension);
593 EXPECT_EQ(Manifest::EXTERNAL_POLICY_DOWNLOAD, extension->location()); 596 EXPECT_EQ(Manifest::EXTERNAL_POLICY_DOWNLOAD, extension->location());
594 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); 597 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId));
595 598
596 // Remove the policy, and verify that the extension was uninstalled. 599 // Remove the policy, and verify that the extension was uninstalled.
597 // TODO(joaodasilva): it would be nicer if the extension was kept instead, 600 // TODO(joaodasilva): it would be nicer if the extension was kept instead,
598 // and reverted location to INTERNAL or whatever it was before the policy 601 // and reverted location to INTERNAL or whatever it was before the policy
599 // was applied. 602 // was applied.
600 prefs->ClearPref(prefs::kExtensionInstallForceList); 603 prefs->ClearPref(extensions::pref_names::kInstallForceList);
601 ASSERT_EQ(size_before, service->extensions()->size()); 604 ASSERT_EQ(size_before, service->extensions()->size());
602 extension = service->GetExtensionById(kExtensionId, true); 605 extension = service->GetExtensionById(kExtensionId, true);
603 EXPECT_FALSE(extension); 606 EXPECT_FALSE(extension);
604 607
605 // User install again, but have it disabled too before setting the policy. 608 // User install again, but have it disabled too before setting the policy.
606 ASSERT_TRUE(InstallExtension(basedir.AppendASCII("v2.crx"), 1)); 609 ASSERT_TRUE(InstallExtension(basedir.AppendASCII("v2.crx"), 1));
607 ASSERT_EQ(size_before + 1, service->extensions()->size()); 610 ASSERT_EQ(size_before + 1, service->extensions()->size());
608 extension = service->GetExtensionById(kExtensionId, false); 611 extension = service->GetExtensionById(kExtensionId, false);
609 ASSERT_TRUE(extension); 612 ASSERT_TRUE(extension);
610 EXPECT_EQ(Manifest::INTERNAL, extension->location()); 613 EXPECT_EQ(Manifest::INTERNAL, extension->location());
611 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); 614 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId));
612 EXPECT_TRUE(service->disabled_extensions()->is_empty()); 615 EXPECT_TRUE(service->disabled_extensions()->is_empty());
613 616
614 DisableExtension(kExtensionId); 617 DisableExtension(kExtensionId);
615 EXPECT_EQ(1u, service->disabled_extensions()->size()); 618 EXPECT_EQ(1u, service->disabled_extensions()->size());
616 extension = service->GetExtensionById(kExtensionId, true); 619 extension = service->GetExtensionById(kExtensionId, true);
617 EXPECT_TRUE(extension); 620 EXPECT_TRUE(extension);
618 EXPECT_FALSE(service->IsExtensionEnabled(kExtensionId)); 621 EXPECT_FALSE(service->IsExtensionEnabled(kExtensionId));
619 622
620 // Install the policy again. It should overwrite the extension's location, 623 // Install the policy again. It should overwrite the extension's location,
621 // and force enable it too. 624 // and force enable it too.
622 { 625 {
623 DictionaryPrefUpdate pref_update(prefs, prefs::kExtensionInstallForceList); 626 DictionaryPrefUpdate pref_update(prefs,
627 extensions::pref_names::kInstallForceList);
624 base::DictionaryValue* forcelist = pref_update.Get(); 628 base::DictionaryValue* forcelist = pref_update.Get();
625 extensions::ExternalPolicyLoader::AddExtension( 629 extensions::ExternalPolicyLoader::AddExtension(
626 forcelist, kExtensionId, "http://localhost/autoupdate/manifest"); 630 forcelist, kExtensionId, "http://localhost/autoupdate/manifest");
627 } 631 }
628 ASSERT_TRUE(WaitForExtensionInstall()); 632 ASSERT_TRUE(WaitForExtensionInstall());
629 ASSERT_EQ(size_before + 1, service->extensions()->size()); 633 ASSERT_EQ(size_before + 1, service->extensions()->size());
630 extension = service->GetExtensionById(kExtensionId, false); 634 extension = service->GetExtensionById(kExtensionId, false);
631 ASSERT_TRUE(extension); 635 ASSERT_TRUE(extension);
632 EXPECT_EQ(Manifest::EXTERNAL_POLICY_DOWNLOAD, extension->location()); 636 EXPECT_EQ(Manifest::EXTERNAL_POLICY_DOWNLOAD, extension->location());
633 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId)); 637 EXPECT_TRUE(service->IsExtensionEnabled(kExtensionId));
634 EXPECT_TRUE(service->disabled_extensions()->is_empty()); 638 EXPECT_TRUE(service->disabled_extensions()->is_empty());
635 } 639 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698