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

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

Issue 1025613003: Fix for ERROR:url_pattern_set.cc(240)] Invalid url pattern: chrome://print/* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes as per review comments. Created 5 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
« no previous file with comments | « no previous file | chrome/browser/extensions/test_extension_prefs.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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
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, "a")
926 .Set(manifest_keys::kVersion, "0.1"))
927 .SetLocation(Manifest::COMPONENT)
928 .SetPath(prefs_.extensions_dir().AppendASCII("a"))
929 .Build();
930 prefs_.AddExtension(component_extension_.get());
931
932 // Adding a non component extension.
933 no_component_extension_ =
934 ExtensionBuilder()
935 .SetManifest(DictionaryBuilder()
936 .Set(manifest_keys::kName, "b")
937 .Set(manifest_keys::kVersion, "0.1"))
938 .SetLocation(Manifest::INTERNAL)
939 .SetPath(prefs_.extensions_dir().AppendASCII("b"))
940 .Build();
941 prefs_.AddExtension(no_component_extension_.get());
942
943 APIPermissionSet api_perms;
944 api_perms.insert(APIPermission::kTab);
945 api_perms.insert(APIPermission::kBookmark);
946 api_perms.insert(APIPermission::kHistory);
947
948 ManifestPermissionSet empty_manifest_permissions;
949
950 URLPatternSet ehosts, shosts;
951 AddPattern(&shosts, "chrome://print/*");
952
953 active_perms_ = new PermissionSet(api_perms, empty_manifest_permissions,
954 ehosts, shosts);
955 // Set the active permissions.
956 prefs()->SetActivePermissions(component_extension_->id(),
957 active_perms_.get());
958 prefs()->SetActivePermissions(no_component_extension_->id(),
959 active_perms_.get());
960 }
961
962 void Verify() override {
963 // Component extension can access chrome://print/*.
964 scoped_refptr<PermissionSet> component_permissions(
965 prefs()->GetActivePermissions(component_extension_->id()));
966 EXPECT_EQ(1u, component_permissions->scriptable_hosts().size());
967
968 // Non Component extension can not access chrome://print/*.
969 scoped_refptr<PermissionSet> no_component_permissions(
970 prefs()->GetActivePermissions(no_component_extension_->id()));
971 EXPECT_EQ(0u, no_component_permissions->scriptable_hosts().size());
972
973 // |URLPattern::SCHEME_CHROMEUI| scheme will be added in valid_schemes for
974 // component extensions.
975 URLPatternSet scriptable_hosts;
976 std::string pref_key = "active_permissions.scriptable_host";
977 int valid_schemes = URLPattern::SCHEME_ALL & ~URLPattern::SCHEME_CHROMEUI;
978
979 EXPECT_TRUE(prefs()->ReadPrefAsURLPatternSet(component_extension_->id(),
980 pref_key, &scriptable_hosts,
981 valid_schemes));
982
983 EXPECT_FALSE(prefs()->ReadPrefAsURLPatternSet(no_component_extension_->id(),
984 pref_key, &scriptable_hosts,
985 valid_schemes));
986 }
987
988 private:
989 scoped_refptr<PermissionSet> active_perms_;
990 scoped_refptr<Extension> component_extension_;
991 scoped_refptr<Extension> no_component_extension_;
992 };
993 TEST_F(ExtensionPrefsComponentExtension, ExtensionPrefsComponentExtension) {
994 }
995
916 } // namespace extensions 996 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/test_extension_prefs.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698