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

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

Issue 2806283002: Revert of Stop passing raw pointers to base::Value API in c/b/chromeos and c/b/extensions (Closed)
Patch Set: Created 3 years, 8 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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.h" 5 #include "chrome/browser/extensions/extension_service.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 19 matching lines...) Expand all
30 #include "base/memory/weak_ptr.h" 30 #include "base/memory/weak_ptr.h"
31 #include "base/run_loop.h" 31 #include "base/run_loop.h"
32 #include "base/single_thread_task_runner.h" 32 #include "base/single_thread_task_runner.h"
33 #include "base/stl_util.h" 33 #include "base/stl_util.h"
34 #include "base/strings/pattern.h" 34 #include "base/strings/pattern.h"
35 #include "base/strings/string16.h" 35 #include "base/strings/string16.h"
36 #include "base/strings/string_number_conversions.h" 36 #include "base/strings/string_number_conversions.h"
37 #include "base/strings/string_util.h" 37 #include "base/strings/string_util.h"
38 #include "base/strings/utf_string_conversions.h" 38 #include "base/strings/utf_string_conversions.h"
39 #include "base/threading/thread_task_runner_handle.h" 39 #include "base/threading/thread_task_runner_handle.h"
40 #include "base/values.h"
41 #include "base/version.h" 40 #include "base/version.h"
42 #include "build/build_config.h" 41 #include "build/build_config.h"
43 #include "chrome/browser/after_startup_task_utils.h" 42 #include "chrome/browser/after_startup_task_utils.h"
44 #include "chrome/browser/browser_process.h" 43 #include "chrome/browser/browser_process.h"
45 #include "chrome/browser/chrome_notification_types.h" 44 #include "chrome/browser/chrome_notification_types.h"
46 #include "chrome/browser/extensions/blacklist.h" 45 #include "chrome/browser/extensions/blacklist.h"
47 #include "chrome/browser/extensions/chrome_app_sorting.h" 46 #include "chrome/browser/extensions/chrome_app_sorting.h"
48 #include "chrome/browser/extensions/chrome_test_extension_loader.h" 47 #include "chrome/browser/extensions/chrome_test_extension_loader.h"
49 #include "chrome/browser/extensions/component_loader.h" 48 #include "chrome/browser/extensions/component_loader.h"
50 #include "chrome/browser/extensions/crx_installer.h" 49 #include "chrome/browser/extensions/crx_installer.h"
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 } 615 }
617 bool val; 616 bool val;
618 if (!pref->GetBoolean(pref_path, &val)) { 617 if (!pref->GetBoolean(pref_path, &val)) {
619 return false; 618 return false;
620 } 619 }
621 return true; 620 return true;
622 } 621 }
623 622
624 void SetPref(const std::string& extension_id, 623 void SetPref(const std::string& extension_id,
625 const std::string& pref_path, 624 const std::string& pref_path,
626 std::unique_ptr<base::Value> value, 625 base::Value* value,
627 const std::string& msg) { 626 const std::string& msg) {
628 DictionaryPrefUpdate update(profile()->GetPrefs(), "extensions.settings"); 627 DictionaryPrefUpdate update(profile()->GetPrefs(), "extensions.settings");
629 base::DictionaryValue* dict = update.Get(); 628 base::DictionaryValue* dict = update.Get();
630 ASSERT_TRUE(dict != NULL) << msg; 629 ASSERT_TRUE(dict != NULL) << msg;
631 base::DictionaryValue* pref = NULL; 630 base::DictionaryValue* pref = NULL;
632 ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg; 631 ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg;
633 EXPECT_TRUE(pref != NULL) << msg; 632 EXPECT_TRUE(pref != NULL) << msg;
634 pref->Set(pref_path, std::move(value)); 633 pref->Set(pref_path, value);
635 } 634 }
636 635
637 void SetPrefInteg(const std::string& extension_id, 636 void SetPrefInteg(const std::string& extension_id,
638 const std::string& pref_path, 637 const std::string& pref_path,
639 int value) { 638 int value) {
640 std::string msg = " while setting: "; 639 std::string msg = " while setting: ";
641 msg += extension_id; 640 msg += extension_id;
642 msg += " "; 641 msg += " ";
643 msg += pref_path; 642 msg += pref_path;
644 msg += " = "; 643 msg += " = ";
645 msg += base::IntToString(value); 644 msg += base::IntToString(value);
646 645
647 SetPref(extension_id, pref_path, base::MakeUnique<base::Value>(value), msg); 646 SetPref(extension_id, pref_path, new base::Value(value), msg);
648 } 647 }
649 648
650 void SetPrefBool(const std::string& extension_id, 649 void SetPrefBool(const std::string& extension_id,
651 const std::string& pref_path, 650 const std::string& pref_path,
652 bool value) { 651 bool value) {
653 std::string msg = " while setting: "; 652 std::string msg = " while setting: ";
654 msg += extension_id + " " + pref_path; 653 msg += extension_id + " " + pref_path;
655 msg += " = "; 654 msg += " = ";
656 msg += (value ? "true" : "false"); 655 msg += (value ? "true" : "false");
657 656
658 SetPref(extension_id, pref_path, base::MakeUnique<base::Value>(value), msg); 657 SetPref(extension_id, pref_path, new base::Value(value), msg);
659 } 658 }
660 659
661 void ClearPref(const std::string& extension_id, 660 void ClearPref(const std::string& extension_id,
662 const std::string& pref_path) { 661 const std::string& pref_path) {
663 std::string msg = " while clearing: "; 662 std::string msg = " while clearing: ";
664 msg += extension_id + " " + pref_path; 663 msg += extension_id + " " + pref_path;
665 664
666 DictionaryPrefUpdate update(profile()->GetPrefs(), "extensions.settings"); 665 DictionaryPrefUpdate update(profile()->GetPrefs(), "extensions.settings");
667 base::DictionaryValue* dict = update.Get(); 666 base::DictionaryValue* dict = update.Get();
668 ASSERT_TRUE(dict != NULL) << msg; 667 ASSERT_TRUE(dict != NULL) << msg;
669 base::DictionaryValue* pref = NULL; 668 base::DictionaryValue* pref = NULL;
670 ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg; 669 ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg;
671 EXPECT_TRUE(pref != NULL) << msg; 670 EXPECT_TRUE(pref != NULL) << msg;
672 pref->Remove(pref_path, NULL); 671 pref->Remove(pref_path, NULL);
673 } 672 }
674 673
675 void SetPrefStringSet(const std::string& extension_id, 674 void SetPrefStringSet(const std::string& extension_id,
676 const std::string& pref_path, 675 const std::string& pref_path,
677 const std::set<std::string>& value) { 676 const std::set<std::string>& value) {
678 std::string msg = " while setting: "; 677 std::string msg = " while setting: ";
679 msg += extension_id + " " + pref_path; 678 msg += extension_id + " " + pref_path;
680 679
681 auto list_value = base::MakeUnique<base::ListValue>(); 680 base::ListValue* list_value = new base::ListValue();
682 for (std::set<std::string>::const_iterator iter = value.begin(); 681 for (std::set<std::string>::const_iterator iter = value.begin();
683 iter != value.end(); ++iter) 682 iter != value.end(); ++iter)
684 list_value->AppendString(*iter); 683 list_value->AppendString(*iter);
685 684
686 SetPref(extension_id, pref_path, std::move(list_value), msg); 685 SetPref(extension_id, pref_path, list_value, msg);
687 } 686 }
688 687
689 void InitPluginService() { 688 void InitPluginService() {
690 #if BUILDFLAG(ENABLE_PLUGINS) 689 #if BUILDFLAG(ENABLE_PLUGINS)
691 PluginService::GetInstance()->Init(); 690 PluginService::GetInstance()->Init();
692 #endif 691 #endif
693 } 692 }
694 693
695 void InitializeEmptyExtensionServiceWithTestingPrefs() { 694 void InitializeEmptyExtensionServiceWithTestingPrefs() {
696 ExtensionServiceTestBase::ExtensionServiceInitParams params = 695 ExtensionServiceTestBase::ExtensionServiceInitParams params =
(...skipping 1011 matching lines...) Expand 10 before | Expand all | Expand 10 after
1708 AddPattern(&expected_host_permissions, "https://*.google.com/*"); 1707 AddPattern(&expected_host_permissions, "https://*.google.com/*");
1709 AddPattern(&expected_host_permissions, "http://*.google.com.hk/*"); 1708 AddPattern(&expected_host_permissions, "http://*.google.com.hk/*");
1710 AddPattern(&expected_host_permissions, "http://www.example.com/*"); 1709 AddPattern(&expected_host_permissions, "http://www.example.com/*");
1711 1710
1712 std::set<std::string> host_permissions; 1711 std::set<std::string> host_permissions;
1713 1712
1714 // Test that the extension is disabled when an API permission is missing from 1713 // Test that the extension is disabled when an API permission is missing from
1715 // the extension's granted api permissions preference. (This simulates 1714 // the extension's granted api permissions preference. (This simulates
1716 // updating the browser to a version which recognizes a new API permission). 1715 // updating the browser to a version which recognizes a new API permission).
1717 SetPref(extension_id, "granted_permissions.api", 1716 SetPref(extension_id, "granted_permissions.api",
1718 base::MakeUnique<base::ListValue>(), "granted_permissions.api"); 1717 new base::ListValue(), "granted_permissions.api");
1719 service()->ReloadExtensionsForTest(); 1718 service()->ReloadExtensionsForTest();
1720 1719
1721 EXPECT_EQ(1u, registry()->disabled_extensions().size()); 1720 EXPECT_EQ(1u, registry()->disabled_extensions().size());
1722 extension = registry()->disabled_extensions().begin()->get(); 1721 extension = registry()->disabled_extensions().begin()->get();
1723 1722
1724 ASSERT_TRUE(prefs->IsExtensionDisabled(extension_id)); 1723 ASSERT_TRUE(prefs->IsExtensionDisabled(extension_id));
1725 ASSERT_FALSE(service()->IsExtensionEnabled(extension_id)); 1724 ASSERT_FALSE(service()->IsExtensionEnabled(extension_id));
1726 ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id)); 1725 ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id));
1727 1726
1728 // Now grant and re-enable the extension, making sure the prefs are updated. 1727 // Now grant and re-enable the extension, making sure the prefs are updated.
(...skipping 15 matching lines...) Expand all
1744 // the extension's granted host permissions preference. (This simulates 1743 // the extension's granted host permissions preference. (This simulates
1745 // updating the browser to a version which recognizes additional host 1744 // updating the browser to a version which recognizes additional host
1746 // permissions). 1745 // permissions).
1747 host_permissions.clear(); 1746 host_permissions.clear();
1748 current_perms = NULL; 1747 current_perms = NULL;
1749 1748
1750 host_permissions.insert("http://*.google.com/*"); 1749 host_permissions.insert("http://*.google.com/*");
1751 host_permissions.insert("https://*.google.com/*"); 1750 host_permissions.insert("https://*.google.com/*");
1752 host_permissions.insert("http://*.google.com.hk/*"); 1751 host_permissions.insert("http://*.google.com.hk/*");
1753 1752
1754 auto api_permissions = base::MakeUnique<base::ListValue>(); 1753 base::ListValue* api_permissions = new base::ListValue();
1755 api_permissions->AppendString("tabs"); 1754 api_permissions->AppendString("tabs");
1756 SetPref(extension_id, "granted_permissions.api", std::move(api_permissions), 1755 SetPref(extension_id, "granted_permissions.api",
1757 "granted_permissions.api"); 1756 api_permissions, "granted_permissions.api");
1758 SetPrefStringSet( 1757 SetPrefStringSet(
1759 extension_id, "granted_permissions.scriptable_host", host_permissions); 1758 extension_id, "granted_permissions.scriptable_host", host_permissions);
1760 1759
1761 service()->ReloadExtensionsForTest(); 1760 service()->ReloadExtensionsForTest();
1762 1761
1763 EXPECT_EQ(1u, registry()->disabled_extensions().size()); 1762 EXPECT_EQ(1u, registry()->disabled_extensions().size());
1764 extension = registry()->disabled_extensions().begin()->get(); 1763 extension = registry()->disabled_extensions().begin()->get();
1765 1764
1766 ASSERT_TRUE(prefs->IsExtensionDisabled(extension_id)); 1765 ASSERT_TRUE(prefs->IsExtensionDisabled(extension_id));
1767 ASSERT_FALSE(service()->IsExtensionEnabled(extension_id)); 1766 ASSERT_FALSE(service()->IsExtensionEnabled(extension_id));
(...skipping 5301 matching lines...) Expand 10 before | Expand all | Expand 10 after
7069 shared_module->manifest()->type()); 7068 shared_module->manifest()->type());
7070 EXPECT_TRUE(registry()->enabled_extensions().Contains(kExtensionId)); 7069 EXPECT_TRUE(registry()->enabled_extensions().Contains(kExtensionId));
7071 7070
7072 // Reload the extension and wait for it to complete. This previously crashed 7071 // Reload the extension and wait for it to complete. This previously crashed
7073 // (see crbug.com/676815). 7072 // (see crbug.com/676815).
7074 service()->ReloadExtension(kExtensionId); 7073 service()->ReloadExtension(kExtensionId);
7075 base::RunLoop().RunUntilIdle(); 7074 base::RunLoop().RunUntilIdle();
7076 // The shared module should be enabled. 7075 // The shared module should be enabled.
7077 EXPECT_TRUE(registry()->enabled_extensions().Contains(kExtensionId)); 7076 EXPECT_TRUE(registry()->enabled_extensions().Contains(kExtensionId));
7078 } 7077 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698