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

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

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

Powered by Google App Engine
This is Rietveld 408576698