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

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

Issue 2777063003: Stop passing raw pointers to base::Value API in c/b/chromeos and c/b/extensions (Closed)
Patch Set: Fix SupervisedUserWhitelistInstaller 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/version.h" 40 #include "base/version.h"
jdoerrie 2017/04/06 14:25:51 #include "base/values.h"
vabr (Chromium) 2017/04/07 20:40:41 Done.
41 #include "build/build_config.h" 41 #include "build/build_config.h"
42 #include "chrome/browser/after_startup_task_utils.h" 42 #include "chrome/browser/after_startup_task_utils.h"
43 #include "chrome/browser/browser_process.h" 43 #include "chrome/browser/browser_process.h"
44 #include "chrome/browser/chrome_notification_types.h" 44 #include "chrome/browser/chrome_notification_types.h"
45 #include "chrome/browser/extensions/blacklist.h" 45 #include "chrome/browser/extensions/blacklist.h"
46 #include "chrome/browser/extensions/chrome_app_sorting.h" 46 #include "chrome/browser/extensions/chrome_app_sorting.h"
47 #include "chrome/browser/extensions/chrome_test_extension_loader.h" 47 #include "chrome/browser/extensions/chrome_test_extension_loader.h"
48 #include "chrome/browser/extensions/component_loader.h" 48 #include "chrome/browser/extensions/component_loader.h"
49 #include "chrome/browser/extensions/crx_installer.h" 49 #include "chrome/browser/extensions/crx_installer.h"
50 #include "chrome/browser/extensions/default_apps.h" 50 #include "chrome/browser/extensions/default_apps.h"
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 } 695 }
696 bool val; 696 bool val;
697 if (!pref->GetBoolean(pref_path, &val)) { 697 if (!pref->GetBoolean(pref_path, &val)) {
698 return false; 698 return false;
699 } 699 }
700 return true; 700 return true;
701 } 701 }
702 702
703 void SetPref(const std::string& extension_id, 703 void SetPref(const std::string& extension_id,
704 const std::string& pref_path, 704 const std::string& pref_path,
705 base::Value* value, 705 std::unique_ptr<base::Value> value,
706 const std::string& msg) { 706 const std::string& msg) {
707 DictionaryPrefUpdate update(profile()->GetPrefs(), "extensions.settings"); 707 DictionaryPrefUpdate update(profile()->GetPrefs(), "extensions.settings");
708 base::DictionaryValue* dict = update.Get(); 708 base::DictionaryValue* dict = update.Get();
709 ASSERT_TRUE(dict != NULL) << msg; 709 ASSERT_TRUE(dict != NULL) << msg;
710 base::DictionaryValue* pref = NULL; 710 base::DictionaryValue* pref = NULL;
711 ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg; 711 ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg;
712 EXPECT_TRUE(pref != NULL) << msg; 712 EXPECT_TRUE(pref != NULL) << msg;
713 pref->Set(pref_path, value); 713 pref->Set(pref_path, std::move(value));
714 } 714 }
715 715
716 void SetPrefInteg(const std::string& extension_id, 716 void SetPrefInteg(const std::string& extension_id,
717 const std::string& pref_path, 717 const std::string& pref_path,
718 int value) { 718 int value) {
719 std::string msg = " while setting: "; 719 std::string msg = " while setting: ";
720 msg += extension_id; 720 msg += extension_id;
721 msg += " "; 721 msg += " ";
722 msg += pref_path; 722 msg += pref_path;
723 msg += " = "; 723 msg += " = ";
724 msg += base::IntToString(value); 724 msg += base::IntToString(value);
725 725
726 SetPref(extension_id, pref_path, new base::Value(value), msg); 726 SetPref(extension_id, pref_path, base::MakeUnique<base::Value>(value), msg);
727 } 727 }
728 728
729 void SetPrefBool(const std::string& extension_id, 729 void SetPrefBool(const std::string& extension_id,
730 const std::string& pref_path, 730 const std::string& pref_path,
731 bool value) { 731 bool value) {
732 std::string msg = " while setting: "; 732 std::string msg = " while setting: ";
733 msg += extension_id + " " + pref_path; 733 msg += extension_id + " " + pref_path;
734 msg += " = "; 734 msg += " = ";
735 msg += (value ? "true" : "false"); 735 msg += (value ? "true" : "false");
736 736
737 SetPref(extension_id, pref_path, new base::Value(value), msg); 737 SetPref(extension_id, pref_path, base::MakeUnique<base::Value>(value), msg);
738 } 738 }
739 739
740 void ClearPref(const std::string& extension_id, 740 void ClearPref(const std::string& extension_id,
741 const std::string& pref_path) { 741 const std::string& pref_path) {
742 std::string msg = " while clearing: "; 742 std::string msg = " while clearing: ";
743 msg += extension_id + " " + pref_path; 743 msg += extension_id + " " + pref_path;
744 744
745 DictionaryPrefUpdate update(profile()->GetPrefs(), "extensions.settings"); 745 DictionaryPrefUpdate update(profile()->GetPrefs(), "extensions.settings");
746 base::DictionaryValue* dict = update.Get(); 746 base::DictionaryValue* dict = update.Get();
747 ASSERT_TRUE(dict != NULL) << msg; 747 ASSERT_TRUE(dict != NULL) << msg;
748 base::DictionaryValue* pref = NULL; 748 base::DictionaryValue* pref = NULL;
749 ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg; 749 ASSERT_TRUE(dict->GetDictionary(extension_id, &pref)) << msg;
750 EXPECT_TRUE(pref != NULL) << msg; 750 EXPECT_TRUE(pref != NULL) << msg;
751 pref->Remove(pref_path, NULL); 751 pref->Remove(pref_path, NULL);
752 } 752 }
753 753
754 void SetPrefStringSet(const std::string& extension_id, 754 void SetPrefStringSet(const std::string& extension_id,
755 const std::string& pref_path, 755 const std::string& pref_path,
756 const std::set<std::string>& value) { 756 const std::set<std::string>& value) {
757 std::string msg = " while setting: "; 757 std::string msg = " while setting: ";
758 msg += extension_id + " " + pref_path; 758 msg += extension_id + " " + pref_path;
759 759
760 base::ListValue* list_value = new base::ListValue(); 760 auto list_value = base::MakeUnique<base::ListValue>();
761 for (std::set<std::string>::const_iterator iter = value.begin(); 761 for (std::set<std::string>::const_iterator iter = value.begin();
762 iter != value.end(); ++iter) 762 iter != value.end(); ++iter)
763 list_value->AppendString(*iter); 763 list_value->AppendString(*iter);
764 764
765 SetPref(extension_id, pref_path, list_value, msg); 765 SetPref(extension_id, pref_path, std::move(list_value), msg);
766 } 766 }
767 767
768 void InitPluginService() { 768 void InitPluginService() {
769 #if BUILDFLAG(ENABLE_PLUGINS) 769 #if BUILDFLAG(ENABLE_PLUGINS)
770 PluginService::GetInstance()->Init(); 770 PluginService::GetInstance()->Init();
771 #endif 771 #endif
772 } 772 }
773 773
774 void InitializeEmptyExtensionServiceWithTestingPrefs() { 774 void InitializeEmptyExtensionServiceWithTestingPrefs() {
775 ExtensionServiceTestBase::ExtensionServiceInitParams params = 775 ExtensionServiceTestBase::ExtensionServiceInitParams params =
(...skipping 1011 matching lines...) Expand 10 before | Expand all | Expand 10 after
1787 AddPattern(&expected_host_permissions, "https://*.google.com/*"); 1787 AddPattern(&expected_host_permissions, "https://*.google.com/*");
1788 AddPattern(&expected_host_permissions, "http://*.google.com.hk/*"); 1788 AddPattern(&expected_host_permissions, "http://*.google.com.hk/*");
1789 AddPattern(&expected_host_permissions, "http://www.example.com/*"); 1789 AddPattern(&expected_host_permissions, "http://www.example.com/*");
1790 1790
1791 std::set<std::string> host_permissions; 1791 std::set<std::string> host_permissions;
1792 1792
1793 // Test that the extension is disabled when an API permission is missing from 1793 // Test that the extension is disabled when an API permission is missing from
1794 // the extension's granted api permissions preference. (This simulates 1794 // the extension's granted api permissions preference. (This simulates
1795 // updating the browser to a version which recognizes a new API permission). 1795 // updating the browser to a version which recognizes a new API permission).
1796 SetPref(extension_id, "granted_permissions.api", 1796 SetPref(extension_id, "granted_permissions.api",
1797 new base::ListValue(), "granted_permissions.api"); 1797 base::MakeUnique<base::ListValue>(), "granted_permissions.api");
1798 service()->ReloadExtensionsForTest(); 1798 service()->ReloadExtensionsForTest();
1799 1799
1800 EXPECT_EQ(1u, registry()->disabled_extensions().size()); 1800 EXPECT_EQ(1u, registry()->disabled_extensions().size());
1801 extension = registry()->disabled_extensions().begin()->get(); 1801 extension = registry()->disabled_extensions().begin()->get();
1802 1802
1803 ASSERT_TRUE(prefs->IsExtensionDisabled(extension_id)); 1803 ASSERT_TRUE(prefs->IsExtensionDisabled(extension_id));
1804 ASSERT_FALSE(service()->IsExtensionEnabled(extension_id)); 1804 ASSERT_FALSE(service()->IsExtensionEnabled(extension_id));
1805 ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id)); 1805 ASSERT_TRUE(prefs->DidExtensionEscalatePermissions(extension_id));
1806 1806
1807 // Now grant and re-enable the extension, making sure the prefs are updated. 1807 // Now grant and re-enable the extension, making sure the prefs are updated.
(...skipping 15 matching lines...) Expand all
1823 // the extension's granted host permissions preference. (This simulates 1823 // the extension's granted host permissions preference. (This simulates
1824 // updating the browser to a version which recognizes additional host 1824 // updating the browser to a version which recognizes additional host
1825 // permissions). 1825 // permissions).
1826 host_permissions.clear(); 1826 host_permissions.clear();
1827 current_perms = NULL; 1827 current_perms = NULL;
1828 1828
1829 host_permissions.insert("http://*.google.com/*"); 1829 host_permissions.insert("http://*.google.com/*");
1830 host_permissions.insert("https://*.google.com/*"); 1830 host_permissions.insert("https://*.google.com/*");
1831 host_permissions.insert("http://*.google.com.hk/*"); 1831 host_permissions.insert("http://*.google.com.hk/*");
1832 1832
1833 base::ListValue* api_permissions = new base::ListValue(); 1833 auto api_permissions = base::MakeUnique<base::ListValue>();
1834 api_permissions->AppendString("tabs"); 1834 api_permissions->AppendString("tabs");
1835 SetPref(extension_id, "granted_permissions.api", 1835 SetPref(extension_id, "granted_permissions.api", std::move(api_permissions),
1836 api_permissions, "granted_permissions.api"); 1836 "granted_permissions.api");
1837 SetPrefStringSet( 1837 SetPrefStringSet(
1838 extension_id, "granted_permissions.scriptable_host", host_permissions); 1838 extension_id, "granted_permissions.scriptable_host", host_permissions);
1839 1839
1840 service()->ReloadExtensionsForTest(); 1840 service()->ReloadExtensionsForTest();
1841 1841
1842 EXPECT_EQ(1u, registry()->disabled_extensions().size()); 1842 EXPECT_EQ(1u, registry()->disabled_extensions().size());
1843 extension = registry()->disabled_extensions().begin()->get(); 1843 extension = registry()->disabled_extensions().begin()->get();
1844 1844
1845 ASSERT_TRUE(prefs->IsExtensionDisabled(extension_id)); 1845 ASSERT_TRUE(prefs->IsExtensionDisabled(extension_id));
1846 ASSERT_FALSE(service()->IsExtensionEnabled(extension_id)); 1846 ASSERT_FALSE(service()->IsExtensionEnabled(extension_id));
(...skipping 5301 matching lines...) Expand 10 before | Expand all | Expand 10 after
7148 shared_module->manifest()->type()); 7148 shared_module->manifest()->type());
7149 EXPECT_TRUE(registry()->enabled_extensions().Contains(kExtensionId)); 7149 EXPECT_TRUE(registry()->enabled_extensions().Contains(kExtensionId));
7150 7150
7151 // Reload the extension and wait for it to complete. This previously crashed 7151 // Reload the extension and wait for it to complete. This previously crashed
7152 // (see crbug.com/676815). 7152 // (see crbug.com/676815).
7153 service()->ReloadExtension(kExtensionId); 7153 service()->ReloadExtension(kExtensionId);
7154 base::RunLoop().RunUntilIdle(); 7154 base::RunLoop().RunUntilIdle();
7155 // The shared module should be enabled. 7155 // The shared module should be enabled.
7156 EXPECT_TRUE(registry()->enabled_extensions().Contains(kExtensionId)); 7156 EXPECT_TRUE(registry()->enabled_extensions().Contains(kExtensionId));
7157 } 7157 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698