Chromium Code Reviews| 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 "chrome/browser/extensions/extension_prefs_unittest.h" | 5 #include "chrome/browser/extensions/extension_prefs_unittest.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/prefs/mock_pref_change_callback.h" | 10 #include "base/prefs/mock_pref_change_callback.h" |
| 11 #include "base/prefs/pref_change_registrar.h" | 11 #include "base/prefs/pref_change_registrar.h" |
| 12 #include "base/prefs/scoped_user_pref_update.h" | 12 #include "base/prefs/scoped_user_pref_update.h" |
| 13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 17 #include "base/values.h" | 17 #include "base/values.h" |
| 18 #include "chrome/browser/prefs/pref_service_syncable.h" | 18 #include "chrome/browser/prefs/pref_service_syncable.h" |
| 19 #include "chrome/common/chrome_paths.h" | 19 #include "chrome/common/chrome_paths.h" |
| 20 #include "components/pref_registry/pref_registry_syncable.h" | 20 #include "components/pref_registry/pref_registry_syncable.h" |
| 21 #include "content/public/browser/notification_details.h" | 21 #include "content/public/browser/notification_details.h" |
| 22 #include "content/public/browser/notification_source.h" | 22 #include "content/public/browser/notification_source.h" |
| 23 #include "content/public/test/mock_notification_observer.h" | 23 #include "content/public/test/mock_notification_observer.h" |
| 24 #include "extensions/browser/extension_pref_value_map.h" | 24 #include "extensions/browser/extension_pref_value_map.h" |
| 25 #include "extensions/browser/extension_prefs.h" | 25 #include "extensions/browser/extension_prefs.h" |
| 26 #include "extensions/browser/install_flag.h" | 26 #include "extensions/browser/install_flag.h" |
| 27 #include "extensions/common/extension.h" | 27 #include "extensions/common/extension.h" |
| 28 #include "extensions/common/extension_builder.h" | |
| 28 #include "extensions/common/manifest_constants.h" | 29 #include "extensions/common/manifest_constants.h" |
| 29 #include "extensions/common/permissions/permission_set.h" | 30 #include "extensions/common/permissions/permission_set.h" |
| 30 #include "extensions/common/permissions/permissions_info.h" | 31 #include "extensions/common/permissions/permissions_info.h" |
| 31 #include "sync/api/string_ordinal.h" | 32 #include "sync/api/string_ordinal.h" |
| 32 | 33 |
| 33 using base::Time; | 34 using base::Time; |
| 34 using base::TimeDelta; | 35 using base::TimeDelta; |
| 35 using content::BrowserThread; | 36 using content::BrowserThread; |
| 36 | 37 |
| 37 namespace extensions { | 38 namespace extensions { |
| (...skipping 868 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 906 // Other preferences should be untouched. | 907 // Other preferences should be untouched. |
| 907 EXPECT_TRUE(prefs()->AllowFileAccess(extension_a_->id())); | 908 EXPECT_TRUE(prefs()->AllowFileAccess(extension_a_->id())); |
| 908 } | 909 } |
| 909 | 910 |
| 910 private: | 911 private: |
| 911 scoped_refptr<const Extension> extension_a_; | 912 scoped_refptr<const Extension> extension_a_; |
| 912 scoped_refptr<const Extension> extension_b_; | 913 scoped_refptr<const Extension> extension_b_; |
| 913 }; | 914 }; |
| 914 TEST_F(ExtensionPrefsClearLastLaunched, ExtensionPrefsClearLastLaunched) {} | 915 TEST_F(ExtensionPrefsClearLastLaunched, ExtensionPrefsClearLastLaunched) {} |
| 915 | 916 |
| 917 class ExtensionPrefsComponentExtension : public ExtensionPrefsTest { | |
| 918 public: | |
| 919 ~ExtensionPrefsComponentExtension() override {} | |
| 920 void Initialize() override { | |
| 921 // Adding a component extension. | |
| 922 component_extension_ = | |
| 923 ExtensionBuilder() | |
| 924 .SetManifest(DictionaryBuilder() | |
| 925 .Set(manifest_keys::kName, "test") | |
| 926 .Set(manifest_keys::kVersion, "0.1")) | |
| 927 .SetLocation(Manifest::COMPONENT) | |
| 928 .Build(); | |
| 929 prefs_.AddExtension(component_extension_.get()); | |
| 930 | |
| 931 // Adding a non component extension. | |
|
not at google - send to devlin
2015/04/13 17:24:35
It would be more consistent to set this up in the
Deepak
2015/04/14 05:05:42
Done.
| |
| 932 no_component_extension_ = prefs_.AddExtension("a"); | |
| 933 | |
| 934 APIPermissionSet api_perms; | |
| 935 api_perms.insert(APIPermission::kTab); | |
| 936 api_perms.insert(APIPermission::kBookmark); | |
| 937 api_perms.insert(APIPermission::kHistory); | |
| 938 | |
| 939 ManifestPermissionSet empty_manifest_permissions; | |
| 940 | |
| 941 URLPatternSet ehosts, shosts; | |
| 942 AddPattern(&shosts, "chrome://print/*"); | |
| 943 | |
| 944 active_perms_ = new PermissionSet(api_perms, empty_manifest_permissions, | |
| 945 ehosts, shosts); | |
| 946 // Set the active permissions. | |
| 947 prefs()->SetActivePermissions(component_extension_->id(), | |
| 948 active_perms_.get()); | |
| 949 prefs()->SetActivePermissions(no_component_extension_->id(), | |
| 950 active_perms_.get()); | |
| 951 } | |
| 952 | |
| 953 void Verify() override { | |
| 954 // Component extension can access chrome://print/*. | |
| 955 scoped_refptr<PermissionSet> component_permissions( | |
| 956 prefs()->GetActivePermissions(component_extension_->id())); | |
| 957 EXPECT_FALSE(component_permissions->scriptable_hosts().is_empty()); | |
|
not at google - send to devlin
2015/04/13 17:24:35
You should be able to EXPECT_EQ(1u, ....size());
Deepak
2015/04/14 05:05:42
Done.
| |
| 958 | |
| 959 // Non Component extension can not access chrome://print/*. | |
| 960 scoped_refptr<PermissionSet> no_component_permissions( | |
| 961 prefs()->GetActivePermissions(no_component_extension_->id())); | |
| 962 EXPECT_TRUE(no_component_permissions->scriptable_hosts().is_empty()); | |
| 963 | |
| 964 // |URLPattern::SCHEME_CHROMEUI| scheme will be added in valid_schemes for | |
| 965 // component extensions. | |
| 966 URLPatternSet scriptable_hosts; | |
| 967 std::string pref_key = "active_permissions.scriptable_host"; | |
| 968 EXPECT_TRUE(prefs()->ReadPrefAsURLPatternSet( | |
| 969 component_extension_->id(), pref_key, &scriptable_hosts, 15)); | |
|
not at google - send to devlin
2015/04/13 17:24:35
What is 15? Can you alias it to something meaningf
Deepak
2015/04/14 05:05:42
Done.
| |
| 970 | |
| 971 EXPECT_FALSE(prefs()->ReadPrefAsURLPatternSet( | |
| 972 no_component_extension_->id(), pref_key, &scriptable_hosts, 15)); | |
| 973 } | |
| 974 | |
| 975 private: | |
| 976 scoped_refptr<PermissionSet> active_perms_; | |
| 977 scoped_refptr<Extension> component_extension_; | |
| 978 scoped_refptr<Extension> no_component_extension_; | |
| 979 }; | |
| 980 TEST_F(ExtensionPrefsComponentExtension, ExtensionPrefsComponentExtension) { | |
| 981 } | |
| 982 | |
| 916 } // namespace extensions | 983 } // namespace extensions |
| OLD | NEW |