OLD | NEW |
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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 namespace { | 39 namespace { |
40 | 40 |
41 const char kAllHostsPermission[] = "*://*/*"; | 41 const char kAllHostsPermission[] = "*://*/*"; |
42 | 42 |
43 bool CheckSocketPermission( | 43 bool CheckSocketPermission( |
44 scoped_refptr<Extension> extension, | 44 scoped_refptr<Extension> extension, |
45 SocketPermissionRequest::OperationType type, | 45 SocketPermissionRequest::OperationType type, |
46 const char* host, | 46 const char* host, |
47 int port) { | 47 int port) { |
48 SocketPermission::CheckParam param(type, host, port); | 48 SocketPermission::CheckParam param(type, host, port); |
49 return PermissionsData::CheckAPIPermissionWithParam( | 49 return PermissionsData::ForExtension(extension) |
50 extension.get(), APIPermission::kSocket, ¶m); | 50 ->CheckAPIPermissionWithParam(APIPermission::kSocket, ¶m); |
51 } | 51 } |
52 | 52 |
53 // Creates and returns an extension with the given |id|, |host_permissions|, and | 53 // Creates and returns an extension with the given |id|, |host_permissions|, and |
54 // manifest |location|. | 54 // manifest |location|. |
55 scoped_refptr<const Extension> GetExtensionWithHostPermission( | 55 scoped_refptr<const Extension> GetExtensionWithHostPermission( |
56 const std::string& id, | 56 const std::string& id, |
57 const std::string& host_permissions, | 57 const std::string& host_permissions, |
58 Manifest::Location location) { | 58 Manifest::Location location) { |
59 ListBuilder permissions; | 59 ListBuilder permissions; |
60 if (!host_permissions.empty()) | 60 if (!host_permissions.empty()) |
(...skipping 13 matching lines...) Expand all Loading... |
74 .Build(); | 74 .Build(); |
75 } | 75 } |
76 | 76 |
77 bool RequiresActionForScriptExecution(const std::string& extension_id, | 77 bool RequiresActionForScriptExecution(const std::string& extension_id, |
78 const std::string& host_permissions, | 78 const std::string& host_permissions, |
79 Manifest::Location location) { | 79 Manifest::Location location) { |
80 scoped_refptr<const Extension> extension = | 80 scoped_refptr<const Extension> extension = |
81 GetExtensionWithHostPermission(extension_id, | 81 GetExtensionWithHostPermission(extension_id, |
82 host_permissions, | 82 host_permissions, |
83 location); | 83 location); |
84 return PermissionsData::RequiresActionForScriptExecution( | 84 return PermissionsData::ForExtension(extension) |
85 extension, | 85 ->RequiresActionForScriptExecution(extension, |
86 -1, // Ignore tab id for these. | 86 -1, // Ignore tab id for these. |
87 GURL::EmptyGURL()); | 87 GURL::EmptyGURL()); |
88 } | 88 } |
89 | 89 |
90 } // namespace | 90 } // namespace |
91 | 91 |
92 TEST(ExtensionPermissionsTest, EffectiveHostPermissions) { | 92 TEST(ExtensionPermissionsTest, EffectiveHostPermissions) { |
93 scoped_refptr<Extension> extension; | 93 scoped_refptr<Extension> extension; |
94 URLPatternSet hosts; | 94 URLPatternSet hosts; |
95 | 95 |
96 extension = LoadManifest("effective_host_permissions", "empty.json"); | 96 extension = LoadManifest("effective_host_permissions", "empty.json"); |
97 EXPECT_EQ(0u, | 97 EXPECT_EQ(0u, |
98 PermissionsData::GetEffectiveHostPermissions(extension.get()) | 98 PermissionsData::ForExtension(extension) |
99 .patterns().size()); | 99 ->GetEffectiveHostPermissions() |
| 100 .patterns() |
| 101 .size()); |
100 EXPECT_FALSE(hosts.MatchesURL(GURL("http://www.google.com"))); | 102 EXPECT_FALSE(hosts.MatchesURL(GURL("http://www.google.com"))); |
101 EXPECT_FALSE(PermissionsData::HasEffectiveAccessToAllHosts(extension.get())); | 103 EXPECT_FALSE( |
| 104 PermissionsData::ForExtension(extension)->HasEffectiveAccessToAllHosts()); |
102 | 105 |
103 extension = LoadManifest("effective_host_permissions", "one_host.json"); | 106 extension = LoadManifest("effective_host_permissions", "one_host.json"); |
104 hosts = PermissionsData::GetEffectiveHostPermissions(extension.get()); | 107 hosts = |
| 108 PermissionsData::ForExtension(extension)->GetEffectiveHostPermissions(); |
105 EXPECT_TRUE(hosts.MatchesURL(GURL("http://www.google.com"))); | 109 EXPECT_TRUE(hosts.MatchesURL(GURL("http://www.google.com"))); |
106 EXPECT_FALSE(hosts.MatchesURL(GURL("https://www.google.com"))); | 110 EXPECT_FALSE(hosts.MatchesURL(GURL("https://www.google.com"))); |
107 EXPECT_FALSE(PermissionsData::HasEffectiveAccessToAllHosts(extension.get())); | 111 EXPECT_FALSE( |
| 112 PermissionsData::ForExtension(extension)->HasEffectiveAccessToAllHosts()); |
108 | 113 |
109 extension = LoadManifest("effective_host_permissions", | 114 extension = LoadManifest("effective_host_permissions", |
110 "one_host_wildcard.json"); | 115 "one_host_wildcard.json"); |
111 hosts = PermissionsData::GetEffectiveHostPermissions(extension.get()); | 116 hosts = |
| 117 PermissionsData::ForExtension(extension)->GetEffectiveHostPermissions(); |
112 EXPECT_TRUE(hosts.MatchesURL(GURL("http://google.com"))); | 118 EXPECT_TRUE(hosts.MatchesURL(GURL("http://google.com"))); |
113 EXPECT_TRUE(hosts.MatchesURL(GURL("http://foo.google.com"))); | 119 EXPECT_TRUE(hosts.MatchesURL(GURL("http://foo.google.com"))); |
114 EXPECT_FALSE(PermissionsData::HasEffectiveAccessToAllHosts(extension.get())); | 120 EXPECT_FALSE( |
| 121 PermissionsData::ForExtension(extension)->HasEffectiveAccessToAllHosts()); |
115 | 122 |
116 extension = LoadManifest("effective_host_permissions", "two_hosts.json"); | 123 extension = LoadManifest("effective_host_permissions", "two_hosts.json"); |
117 hosts = PermissionsData::GetEffectiveHostPermissions(extension.get()); | 124 hosts = |
| 125 PermissionsData::ForExtension(extension)->GetEffectiveHostPermissions(); |
118 EXPECT_TRUE(hosts.MatchesURL(GURL("http://www.google.com"))); | 126 EXPECT_TRUE(hosts.MatchesURL(GURL("http://www.google.com"))); |
119 EXPECT_TRUE(hosts.MatchesURL(GURL("http://www.reddit.com"))); | 127 EXPECT_TRUE(hosts.MatchesURL(GURL("http://www.reddit.com"))); |
120 EXPECT_FALSE(PermissionsData::HasEffectiveAccessToAllHosts(extension.get())); | 128 EXPECT_FALSE( |
| 129 PermissionsData::ForExtension(extension)->HasEffectiveAccessToAllHosts()); |
121 | 130 |
122 extension = LoadManifest("effective_host_permissions", | 131 extension = LoadManifest("effective_host_permissions", |
123 "https_not_considered.json"); | 132 "https_not_considered.json"); |
124 hosts = PermissionsData::GetEffectiveHostPermissions(extension.get()); | 133 hosts = |
| 134 PermissionsData::ForExtension(extension)->GetEffectiveHostPermissions(); |
125 EXPECT_TRUE(hosts.MatchesURL(GURL("http://google.com"))); | 135 EXPECT_TRUE(hosts.MatchesURL(GURL("http://google.com"))); |
126 EXPECT_TRUE(hosts.MatchesURL(GURL("https://google.com"))); | 136 EXPECT_TRUE(hosts.MatchesURL(GURL("https://google.com"))); |
127 EXPECT_FALSE(PermissionsData::HasEffectiveAccessToAllHosts(extension.get())); | 137 EXPECT_FALSE( |
| 138 PermissionsData::ForExtension(extension)->HasEffectiveAccessToAllHosts()); |
128 | 139 |
129 extension = LoadManifest("effective_host_permissions", | 140 extension = LoadManifest("effective_host_permissions", |
130 "two_content_scripts.json"); | 141 "two_content_scripts.json"); |
131 hosts = PermissionsData::GetEffectiveHostPermissions(extension.get()); | 142 hosts = |
| 143 PermissionsData::ForExtension(extension)->GetEffectiveHostPermissions(); |
132 EXPECT_TRUE(hosts.MatchesURL(GURL("http://google.com"))); | 144 EXPECT_TRUE(hosts.MatchesURL(GURL("http://google.com"))); |
133 EXPECT_TRUE(hosts.MatchesURL(GURL("http://www.reddit.com"))); | 145 EXPECT_TRUE(hosts.MatchesURL(GURL("http://www.reddit.com"))); |
134 EXPECT_TRUE(extension->GetActivePermissions()->HasEffectiveAccessToURL( | 146 EXPECT_TRUE(extension->GetActivePermissions()->HasEffectiveAccessToURL( |
135 GURL("http://www.reddit.com"))); | 147 GURL("http://www.reddit.com"))); |
136 EXPECT_TRUE(hosts.MatchesURL(GURL("http://news.ycombinator.com"))); | 148 EXPECT_TRUE(hosts.MatchesURL(GURL("http://news.ycombinator.com"))); |
137 EXPECT_TRUE(extension->GetActivePermissions()->HasEffectiveAccessToURL( | 149 EXPECT_TRUE(extension->GetActivePermissions()->HasEffectiveAccessToURL( |
138 GURL("http://news.ycombinator.com"))); | 150 GURL("http://news.ycombinator.com"))); |
139 EXPECT_FALSE(PermissionsData::HasEffectiveAccessToAllHosts(extension.get())); | 151 EXPECT_FALSE( |
| 152 PermissionsData::ForExtension(extension)->HasEffectiveAccessToAllHosts()); |
140 | 153 |
141 extension = LoadManifest("effective_host_permissions", "all_hosts.json"); | 154 extension = LoadManifest("effective_host_permissions", "all_hosts.json"); |
142 hosts = PermissionsData::GetEffectiveHostPermissions(extension.get()); | 155 hosts = |
| 156 PermissionsData::ForExtension(extension)->GetEffectiveHostPermissions(); |
143 EXPECT_TRUE(hosts.MatchesURL(GURL("http://test/"))); | 157 EXPECT_TRUE(hosts.MatchesURL(GURL("http://test/"))); |
144 EXPECT_FALSE(hosts.MatchesURL(GURL("https://test/"))); | 158 EXPECT_FALSE(hosts.MatchesURL(GURL("https://test/"))); |
145 EXPECT_TRUE(hosts.MatchesURL(GURL("http://www.google.com"))); | 159 EXPECT_TRUE(hosts.MatchesURL(GURL("http://www.google.com"))); |
146 EXPECT_TRUE(PermissionsData::HasEffectiveAccessToAllHosts(extension.get())); | 160 EXPECT_TRUE( |
| 161 PermissionsData::ForExtension(extension)->HasEffectiveAccessToAllHosts()); |
147 | 162 |
148 extension = LoadManifest("effective_host_permissions", "all_hosts2.json"); | 163 extension = LoadManifest("effective_host_permissions", "all_hosts2.json"); |
149 hosts = PermissionsData::GetEffectiveHostPermissions(extension.get()); | 164 hosts = |
| 165 PermissionsData::ForExtension(extension)->GetEffectiveHostPermissions(); |
150 EXPECT_TRUE(hosts.MatchesURL(GURL("http://test/"))); | 166 EXPECT_TRUE(hosts.MatchesURL(GURL("http://test/"))); |
151 EXPECT_TRUE(hosts.MatchesURL(GURL("http://www.google.com"))); | 167 EXPECT_TRUE(hosts.MatchesURL(GURL("http://www.google.com"))); |
152 EXPECT_TRUE(PermissionsData::HasEffectiveAccessToAllHosts(extension.get())); | 168 EXPECT_TRUE( |
| 169 PermissionsData::ForExtension(extension)->HasEffectiveAccessToAllHosts()); |
153 | 170 |
154 extension = LoadManifest("effective_host_permissions", "all_hosts3.json"); | 171 extension = LoadManifest("effective_host_permissions", "all_hosts3.json"); |
155 hosts = PermissionsData::GetEffectiveHostPermissions(extension.get()); | 172 hosts = |
| 173 PermissionsData::ForExtension(extension)->GetEffectiveHostPermissions(); |
156 EXPECT_FALSE(hosts.MatchesURL(GURL("http://test/"))); | 174 EXPECT_FALSE(hosts.MatchesURL(GURL("http://test/"))); |
157 EXPECT_TRUE(hosts.MatchesURL(GURL("https://test/"))); | 175 EXPECT_TRUE(hosts.MatchesURL(GURL("https://test/"))); |
158 EXPECT_TRUE(hosts.MatchesURL(GURL("http://www.google.com"))); | 176 EXPECT_TRUE(hosts.MatchesURL(GURL("http://www.google.com"))); |
159 EXPECT_TRUE(PermissionsData::HasEffectiveAccessToAllHosts(extension.get())); | 177 EXPECT_TRUE( |
| 178 PermissionsData::ForExtension(extension)->HasEffectiveAccessToAllHosts()); |
160 } | 179 } |
161 | 180 |
162 TEST(ExtensionPermissionsTest, SocketPermissions) { | 181 TEST(ExtensionPermissionsTest, SocketPermissions) { |
163 // Set feature current channel to appropriate value. | 182 // Set feature current channel to appropriate value. |
164 ScopedCurrentChannel scoped_channel(chrome::VersionInfo::CHANNEL_DEV); | 183 ScopedCurrentChannel scoped_channel(chrome::VersionInfo::CHANNEL_DEV); |
165 scoped_refptr<Extension> extension; | 184 scoped_refptr<Extension> extension; |
166 std::string error; | 185 std::string error; |
167 | 186 |
168 extension = LoadManifest("socket_permissions", "empty.json"); | 187 extension = LoadManifest("socket_permissions", "empty.json"); |
169 EXPECT_FALSE(CheckSocketPermission(extension, | 188 EXPECT_FALSE(CheckSocketPermission(extension, |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 kAllHostsPermission, | 243 kAllHostsPermission, |
225 Manifest::INTERNAL); | 244 Manifest::INTERNAL); |
226 URLPatternSet allowed_hosts; | 245 URLPatternSet allowed_hosts; |
227 allowed_hosts.AddPattern( | 246 allowed_hosts.AddPattern( |
228 URLPattern(URLPattern::SCHEME_HTTPS, "https://www.google.com/*")); | 247 URLPattern(URLPattern::SCHEME_HTTPS, "https://www.google.com/*")); |
229 scoped_refptr<PermissionSet> tab_permissions( | 248 scoped_refptr<PermissionSet> tab_permissions( |
230 new PermissionSet(APIPermissionSet(), | 249 new PermissionSet(APIPermissionSet(), |
231 ManifestPermissionSet(), | 250 ManifestPermissionSet(), |
232 allowed_hosts, | 251 allowed_hosts, |
233 URLPatternSet())); | 252 URLPatternSet())); |
234 PermissionsData::UpdateTabSpecificPermissions(extension, 0, tab_permissions); | 253 PermissionsData::ForExtension(extension) |
235 EXPECT_FALSE(PermissionsData::RequiresActionForScriptExecution( | 254 ->UpdateTabSpecificPermissions(0, tab_permissions); |
236 extension, 0, GURL("https://www.google.com/"))); | 255 EXPECT_FALSE(PermissionsData::ForExtension(extension) |
| 256 ->RequiresActionForScriptExecution( |
| 257 extension, 0, GURL("https://www.google.com/"))); |
237 } | 258 } |
238 | 259 |
239 TEST(ExtensionPermissionsTest, GetPermissionMessages_ManyAPIPermissions) { | 260 TEST(ExtensionPermissionsTest, GetPermissionMessages_ManyAPIPermissions) { |
240 scoped_refptr<Extension> extension; | 261 scoped_refptr<Extension> extension; |
241 extension = LoadManifest("permissions", "many-apis.json"); | 262 extension = LoadManifest("permissions", "many-apis.json"); |
242 std::vector<base::string16> warnings = | 263 std::vector<base::string16> warnings = |
243 PermissionsData::GetPermissionMessageStrings(extension.get()); | 264 PermissionsData::ForExtension(extension)->GetPermissionMessageStrings(); |
244 // Warning for "tabs" is suppressed by "history" permission. | 265 // Warning for "tabs" is suppressed by "history" permission. |
245 ASSERT_EQ(5u, warnings.size()); | 266 ASSERT_EQ(5u, warnings.size()); |
246 EXPECT_EQ("Read and modify your data on api.flickr.com", | 267 EXPECT_EQ("Read and modify your data on api.flickr.com", |
247 UTF16ToUTF8(warnings[0])); | 268 UTF16ToUTF8(warnings[0])); |
248 EXPECT_EQ("Read and modify your bookmarks", UTF16ToUTF8(warnings[1])); | 269 EXPECT_EQ("Read and modify your bookmarks", UTF16ToUTF8(warnings[1])); |
249 EXPECT_EQ("Detect your physical location", UTF16ToUTF8(warnings[2])); | 270 EXPECT_EQ("Detect your physical location", UTF16ToUTF8(warnings[2])); |
250 EXPECT_EQ("Read and modify your browsing history", UTF16ToUTF8(warnings[3])); | 271 EXPECT_EQ("Read and modify your browsing history", UTF16ToUTF8(warnings[3])); |
251 EXPECT_EQ("Manage your apps, extensions, and themes", | 272 EXPECT_EQ("Manage your apps, extensions, and themes", |
252 UTF16ToUTF8(warnings[4])); | 273 UTF16ToUTF8(warnings[4])); |
253 } | 274 } |
254 | 275 |
255 TEST(ExtensionPermissionsTest, GetPermissionMessages_ManyHostsPermissions) { | 276 TEST(ExtensionPermissionsTest, GetPermissionMessages_ManyHostsPermissions) { |
256 scoped_refptr<Extension> extension; | 277 scoped_refptr<Extension> extension; |
257 extension = LoadManifest("permissions", "more-than-3-hosts.json"); | 278 extension = LoadManifest("permissions", "more-than-3-hosts.json"); |
258 std::vector<base::string16> warnings = | 279 std::vector<base::string16> warnings = |
259 PermissionsData::GetPermissionMessageStrings(extension.get()); | 280 PermissionsData::ForExtension(extension)->GetPermissionMessageStrings(); |
260 std::vector<base::string16> warnings_details = | 281 std::vector<base::string16> warnings_details = |
261 PermissionsData::GetPermissionMessageDetailsStrings(extension.get()); | 282 PermissionsData::ForExtension(extension) |
| 283 ->GetPermissionMessageDetailsStrings(); |
262 ASSERT_EQ(1u, warnings.size()); | 284 ASSERT_EQ(1u, warnings.size()); |
263 ASSERT_EQ(1u, warnings_details.size()); | 285 ASSERT_EQ(1u, warnings_details.size()); |
264 EXPECT_EQ("Read and modify your data on 5 websites", | 286 EXPECT_EQ("Read and modify your data on 5 websites", |
265 UTF16ToUTF8(warnings[0])); | 287 UTF16ToUTF8(warnings[0])); |
266 EXPECT_EQ("- www.a.com\n- www.b.com\n- www.c.com\n- www.d.com\n- www.e.com", | 288 EXPECT_EQ("- www.a.com\n- www.b.com\n- www.c.com\n- www.d.com\n- www.e.com", |
267 UTF16ToUTF8(warnings_details[0])); | 289 UTF16ToUTF8(warnings_details[0])); |
268 } | 290 } |
269 | 291 |
270 TEST(ExtensionPermissionsTest, GetPermissionMessages_LocationApiPermission) { | 292 TEST(ExtensionPermissionsTest, GetPermissionMessages_LocationApiPermission) { |
271 scoped_refptr<Extension> extension; | 293 scoped_refptr<Extension> extension; |
272 extension = LoadManifest("permissions", | 294 extension = LoadManifest("permissions", |
273 "location-api.json", | 295 "location-api.json", |
274 Manifest::COMPONENT, | 296 Manifest::COMPONENT, |
275 Extension::NO_FLAGS); | 297 Extension::NO_FLAGS); |
276 std::vector<base::string16> warnings = | 298 std::vector<base::string16> warnings = |
277 PermissionsData::GetPermissionMessageStrings(extension.get()); | 299 PermissionsData::ForExtension(extension)->GetPermissionMessageStrings(); |
278 ASSERT_EQ(1u, warnings.size()); | 300 ASSERT_EQ(1u, warnings.size()); |
279 EXPECT_EQ("Detect your physical location", UTF16ToUTF8(warnings[0])); | 301 EXPECT_EQ("Detect your physical location", UTF16ToUTF8(warnings[0])); |
280 } | 302 } |
281 | 303 |
282 TEST(ExtensionPermissionsTest, GetPermissionMessages_ManyHosts) { | 304 TEST(ExtensionPermissionsTest, GetPermissionMessages_ManyHosts) { |
283 scoped_refptr<Extension> extension; | 305 scoped_refptr<Extension> extension; |
284 extension = LoadManifest("permissions", "many-hosts.json"); | 306 extension = LoadManifest("permissions", "many-hosts.json"); |
285 std::vector<base::string16> warnings = | 307 std::vector<base::string16> warnings = |
286 PermissionsData::GetPermissionMessageStrings(extension.get()); | 308 PermissionsData::ForExtension(extension)->GetPermissionMessageStrings(); |
287 ASSERT_EQ(1u, warnings.size()); | 309 ASSERT_EQ(1u, warnings.size()); |
288 EXPECT_EQ( | 310 EXPECT_EQ( |
289 "Read and modify your data on encrypted.google.com and www.google.com", | 311 "Read and modify your data on encrypted.google.com and www.google.com", |
290 UTF16ToUTF8(warnings[0])); | 312 UTF16ToUTF8(warnings[0])); |
291 } | 313 } |
292 | 314 |
293 TEST(ExtensionPermissionsTest, GetPermissionMessages_Plugins) { | 315 TEST(ExtensionPermissionsTest, GetPermissionMessages_Plugins) { |
294 scoped_refptr<Extension> extension; | 316 scoped_refptr<Extension> extension; |
295 extension = LoadManifest("permissions", "plugins.json"); | 317 extension = LoadManifest("permissions", "plugins.json"); |
296 std::vector<base::string16> warnings = | 318 std::vector<base::string16> warnings = |
297 PermissionsData::GetPermissionMessageStrings(extension.get()); | 319 PermissionsData::ForExtension(extension)->GetPermissionMessageStrings(); |
298 // We don't parse the plugins key on Chrome OS, so it should not ask for any | 320 // We don't parse the plugins key on Chrome OS, so it should not ask for any |
299 // permissions. | 321 // permissions. |
300 #if defined(OS_CHROMEOS) | 322 #if defined(OS_CHROMEOS) |
301 ASSERT_EQ(0u, warnings.size()); | 323 ASSERT_EQ(0u, warnings.size()); |
302 #else | 324 #else |
303 ASSERT_EQ(1u, warnings.size()); | 325 ASSERT_EQ(1u, warnings.size()); |
304 EXPECT_EQ( | 326 EXPECT_EQ( |
305 "Read and modify all your data on your computer and the websites you " | 327 "Read and modify all your data on your computer and the websites you " |
306 "visit", | 328 "visit", |
307 UTF16ToUTF8(warnings[0])); | 329 UTF16ToUTF8(warnings[0])); |
(...skipping 27 matching lines...) Expand all Loading... |
335 PermissionsData::SetPolicyDelegate(NULL); | 357 PermissionsData::SetPolicyDelegate(NULL); |
336 } | 358 } |
337 | 359 |
338 bool AllowedScript(const Extension* extension, const GURL& url, | 360 bool AllowedScript(const Extension* extension, const GURL& url, |
339 const GURL& top_url) { | 361 const GURL& top_url) { |
340 return AllowedScript(extension, url, top_url, -1); | 362 return AllowedScript(extension, url, top_url, -1); |
341 } | 363 } |
342 | 364 |
343 bool AllowedScript(const Extension* extension, const GURL& url, | 365 bool AllowedScript(const Extension* extension, const GURL& url, |
344 const GURL& top_url, int tab_id) { | 366 const GURL& top_url, int tab_id) { |
345 return PermissionsData::CanExecuteScriptOnPage( | 367 return PermissionsData::ForExtension(extension)->CanExecuteScriptOnPage( |
346 extension, url, top_url, tab_id, NULL, -1, NULL); | 368 extension, url, top_url, tab_id, NULL, -1, NULL); |
347 } | 369 } |
348 | 370 |
349 bool BlockedScript(const Extension* extension, const GURL& url, | 371 bool BlockedScript(const Extension* extension, const GURL& url, |
350 const GURL& top_url) { | 372 const GURL& top_url) { |
351 return !PermissionsData::CanExecuteScriptOnPage( | 373 return !PermissionsData::ForExtension(extension)->CanExecuteScriptOnPage( |
352 extension, url, top_url, -1, NULL, -1, NULL); | 374 extension, url, top_url, -1, NULL, -1, NULL); |
353 } | 375 } |
354 | 376 |
355 bool Allowed(const Extension* extension, const GURL& url) { | 377 bool Allowed(const Extension* extension, const GURL& url) { |
356 return Allowed(extension, url, -1); | 378 return Allowed(extension, url, -1); |
357 } | 379 } |
358 | 380 |
359 bool Allowed(const Extension* extension, const GURL& url, int tab_id) { | 381 bool Allowed(const Extension* extension, const GURL& url, int tab_id) { |
360 return (PermissionsData::CanExecuteScriptOnPage( | 382 return (PermissionsData::ForExtension(extension)->CanExecuteScriptOnPage( |
361 extension, url, url, tab_id, NULL, -1, NULL) && | 383 extension, url, url, tab_id, NULL, -1, NULL) && |
362 PermissionsData::CanCaptureVisiblePage( | 384 PermissionsData::ForExtension(extension) |
363 extension, tab_id, NULL)); | 385 ->CanCaptureVisiblePage(tab_id, NULL)); |
364 } | 386 } |
365 | 387 |
366 bool CaptureOnly(const Extension* extension, const GURL& url) { | 388 bool CaptureOnly(const Extension* extension, const GURL& url) { |
367 return CaptureOnly(extension, url, -1); | 389 return CaptureOnly(extension, url, -1); |
368 } | 390 } |
369 | 391 |
370 bool CaptureOnly(const Extension* extension, const GURL& url, int tab_id) { | 392 bool CaptureOnly(const Extension* extension, const GURL& url, int tab_id) { |
371 return !PermissionsData::CanExecuteScriptOnPage( | 393 return !PermissionsData::ForExtension(extension)->CanExecuteScriptOnPage( |
372 extension, url, url, tab_id, NULL, -1, NULL) && | 394 extension, url, url, tab_id, NULL, -1, NULL) && |
373 PermissionsData::CanCaptureVisiblePage(extension, tab_id, NULL); | 395 PermissionsData::ForExtension(extension) |
| 396 ->CanCaptureVisiblePage(tab_id, NULL); |
374 } | 397 } |
375 | 398 |
376 bool ScriptOnly(const Extension* extension, const GURL& url, | 399 bool ScriptOnly(const Extension* extension, const GURL& url, |
377 const GURL& top_url) { | 400 const GURL& top_url) { |
378 return ScriptOnly(extension, url, top_url, -1); | 401 return ScriptOnly(extension, url, top_url, -1); |
379 } | 402 } |
380 | 403 |
381 bool ScriptOnly(const Extension* extension, const GURL& url, | 404 bool ScriptOnly(const Extension* extension, const GURL& url, |
382 const GURL& top_url, int tab_id) { | 405 const GURL& top_url, int tab_id) { |
383 return AllowedScript(extension, url, top_url, tab_id) && | 406 return AllowedScript(extension, url, top_url, tab_id) && |
384 !PermissionsData::CanCaptureVisiblePage(extension, tab_id, NULL); | 407 !PermissionsData::ForExtension(extension) |
| 408 ->CanCaptureVisiblePage(tab_id, NULL); |
385 } | 409 } |
386 | 410 |
387 bool Blocked(const Extension* extension, const GURL& url) { | 411 bool Blocked(const Extension* extension, const GURL& url) { |
388 return Blocked(extension, url, -1); | 412 return Blocked(extension, url, -1); |
389 } | 413 } |
390 | 414 |
391 bool Blocked(const Extension* extension, const GURL& url, int tab_id) { | 415 bool Blocked(const Extension* extension, const GURL& url, int tab_id) { |
392 return !(PermissionsData::CanExecuteScriptOnPage( | 416 return !(PermissionsData::ForExtension(extension)->CanExecuteScriptOnPage( |
393 extension, url, url, tab_id, NULL, -1, NULL) || | 417 extension, url, url, tab_id, NULL, -1, NULL) || |
394 PermissionsData::CanCaptureVisiblePage( | 418 PermissionsData::ForExtension(extension) |
395 extension, tab_id, NULL)); | 419 ->CanCaptureVisiblePage(tab_id, NULL)); |
396 } | 420 } |
397 | 421 |
398 bool ScriptAllowedExclusivelyOnTab( | 422 bool ScriptAllowedExclusivelyOnTab( |
399 const Extension* extension, | 423 const Extension* extension, |
400 const std::set<GURL>& allowed_urls, | 424 const std::set<GURL>& allowed_urls, |
401 int tab_id) { | 425 int tab_id) { |
402 bool result = true; | 426 bool result = true; |
403 for (std::set<GURL>::iterator it = urls_.begin(); it != urls_.end(); ++it) { | 427 for (std::set<GURL>::iterator it = urls_.begin(); it != urls_.end(); ++it) { |
404 const GURL& url = *it; | 428 const GURL& url = *it; |
405 if (allowed_urls.count(url)) | 429 if (allowed_urls.count(url)) |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 | 470 |
447 // Test access to iframed content. | 471 // Test access to iframed content. |
448 GURL within_extension_url = extension->GetResourceURL("page.html"); | 472 GURL within_extension_url = extension->GetResourceURL("page.html"); |
449 EXPECT_TRUE(AllowedScript(extension.get(), http_url, http_url_with_path)); | 473 EXPECT_TRUE(AllowedScript(extension.get(), http_url, http_url_with_path)); |
450 EXPECT_TRUE(AllowedScript(extension.get(), https_url, http_url_with_path)); | 474 EXPECT_TRUE(AllowedScript(extension.get(), https_url, http_url_with_path)); |
451 EXPECT_TRUE(AllowedScript(extension.get(), http_url, within_extension_url)); | 475 EXPECT_TRUE(AllowedScript(extension.get(), http_url, within_extension_url)); |
452 EXPECT_TRUE(AllowedScript(extension.get(), https_url, within_extension_url)); | 476 EXPECT_TRUE(AllowedScript(extension.get(), https_url, within_extension_url)); |
453 EXPECT_TRUE(BlockedScript(extension.get(), http_url, extension_url)); | 477 EXPECT_TRUE(BlockedScript(extension.get(), http_url, extension_url)); |
454 EXPECT_TRUE(BlockedScript(extension.get(), https_url, extension_url)); | 478 EXPECT_TRUE(BlockedScript(extension.get(), https_url, extension_url)); |
455 | 479 |
| 480 EXPECT_FALSE(PermissionsData::ForExtension(extension) |
| 481 ->HasHostPermission(settings_url)); |
456 EXPECT_FALSE( | 482 EXPECT_FALSE( |
457 PermissionsData::HasHostPermission(extension.get(), settings_url)); | 483 PermissionsData::ForExtension(extension)->HasHostPermission(about_url)); |
458 EXPECT_FALSE(PermissionsData::HasHostPermission(extension.get(), about_url)); | 484 EXPECT_TRUE( |
459 EXPECT_TRUE(PermissionsData::HasHostPermission(extension.get(), favicon_url)); | 485 PermissionsData::ForExtension(extension)->HasHostPermission(favicon_url)); |
460 | 486 |
461 // Test * for scheme, which implies just the http/https schemes. | 487 // Test * for scheme, which implies just the http/https schemes. |
462 extension = LoadManifestStrict("script_and_capture", | 488 extension = LoadManifestStrict("script_and_capture", |
463 "extension_wildcard.json"); | 489 "extension_wildcard.json"); |
464 EXPECT_TRUE(ScriptOnly(extension.get(), http_url, http_url)); | 490 EXPECT_TRUE(ScriptOnly(extension.get(), http_url, http_url)); |
465 EXPECT_TRUE(ScriptOnly(extension.get(), https_url, https_url)); | 491 EXPECT_TRUE(ScriptOnly(extension.get(), https_url, https_url)); |
466 EXPECT_TRUE(Blocked(extension.get(), settings_url)); | 492 EXPECT_TRUE(Blocked(extension.get(), settings_url)); |
467 EXPECT_TRUE(Blocked(extension.get(), about_url)); | 493 EXPECT_TRUE(Blocked(extension.get(), about_url)); |
468 EXPECT_TRUE(Blocked(extension.get(), file_url)); | 494 EXPECT_TRUE(Blocked(extension.get(), file_url)); |
469 EXPECT_TRUE(Blocked(extension.get(), favicon_url)); | 495 EXPECT_TRUE(Blocked(extension.get(), favicon_url)); |
(...skipping 17 matching lines...) Expand all Loading... |
487 EXPECT_TRUE(Blocked(extension.get(), settings_url)); | 513 EXPECT_TRUE(Blocked(extension.get(), settings_url)); |
488 EXPECT_TRUE(Blocked(extension.get(), favicon_url)); | 514 EXPECT_TRUE(Blocked(extension.get(), favicon_url)); |
489 EXPECT_TRUE(Blocked(extension.get(), about_url)); | 515 EXPECT_TRUE(Blocked(extension.get(), about_url)); |
490 | 516 |
491 // Having chrome://favicon/* should not give you chrome://* | 517 // Having chrome://favicon/* should not give you chrome://* |
492 extension = LoadManifestStrict("script_and_capture", | 518 extension = LoadManifestStrict("script_and_capture", |
493 "extension_chrome_favicon_wildcard.json"); | 519 "extension_chrome_favicon_wildcard.json"); |
494 EXPECT_TRUE(Blocked(extension.get(), settings_url)); | 520 EXPECT_TRUE(Blocked(extension.get(), settings_url)); |
495 EXPECT_TRUE(Blocked(extension.get(), favicon_url)); | 521 EXPECT_TRUE(Blocked(extension.get(), favicon_url)); |
496 EXPECT_TRUE(Blocked(extension.get(), about_url)); | 522 EXPECT_TRUE(Blocked(extension.get(), about_url)); |
497 EXPECT_TRUE(PermissionsData::HasHostPermission(extension.get(), favicon_url)); | 523 EXPECT_TRUE( |
| 524 PermissionsData::ForExtension(extension)->HasHostPermission(favicon_url)); |
498 | 525 |
499 // Having http://favicon should not give you chrome://favicon | 526 // Having http://favicon should not give you chrome://favicon |
500 extension = LoadManifestStrict("script_and_capture", | 527 extension = LoadManifestStrict("script_and_capture", |
501 "extension_http_favicon.json"); | 528 "extension_http_favicon.json"); |
502 EXPECT_TRUE(Blocked(extension.get(), settings_url)); | 529 EXPECT_TRUE(Blocked(extension.get(), settings_url)); |
503 EXPECT_TRUE(Blocked(extension.get(), favicon_url)); | 530 EXPECT_TRUE(Blocked(extension.get(), favicon_url)); |
504 | 531 |
505 // Component extensions with <all_urls> should get everything. | 532 // Component extensions with <all_urls> should get everything. |
506 extension = LoadManifest("script_and_capture", "extension_component_all.json", | 533 extension = LoadManifest("script_and_capture", "extension_component_all.json", |
507 Manifest::COMPONENT, Extension::NO_FLAGS); | 534 Manifest::COMPONENT, Extension::NO_FLAGS); |
508 EXPECT_TRUE(Allowed(extension.get(), http_url)); | 535 EXPECT_TRUE(Allowed(extension.get(), http_url)); |
509 EXPECT_TRUE(Allowed(extension.get(), https_url)); | 536 EXPECT_TRUE(Allowed(extension.get(), https_url)); |
510 EXPECT_TRUE(Allowed(extension.get(), settings_url)); | 537 EXPECT_TRUE(Allowed(extension.get(), settings_url)); |
511 EXPECT_TRUE(Allowed(extension.get(), about_url)); | 538 EXPECT_TRUE(Allowed(extension.get(), about_url)); |
512 EXPECT_TRUE(Allowed(extension.get(), favicon_url)); | 539 EXPECT_TRUE(Allowed(extension.get(), favicon_url)); |
513 EXPECT_TRUE(PermissionsData::HasHostPermission(extension.get(), favicon_url)); | 540 EXPECT_TRUE( |
| 541 PermissionsData::ForExtension(extension)->HasHostPermission(favicon_url)); |
514 | 542 |
515 // Component extensions should only get access to what they ask for. | 543 // Component extensions should only get access to what they ask for. |
516 extension = LoadManifest("script_and_capture", | 544 extension = LoadManifest("script_and_capture", |
517 "extension_component_google.json", Manifest::COMPONENT, | 545 "extension_component_google.json", Manifest::COMPONENT, |
518 Extension::NO_FLAGS); | 546 Extension::NO_FLAGS); |
519 EXPECT_TRUE(ScriptOnly(extension.get(), http_url, http_url)); | 547 EXPECT_TRUE(ScriptOnly(extension.get(), http_url, http_url)); |
520 EXPECT_TRUE(Blocked(extension.get(), https_url)); | 548 EXPECT_TRUE(Blocked(extension.get(), https_url)); |
521 EXPECT_TRUE(Blocked(extension.get(), file_url)); | 549 EXPECT_TRUE(Blocked(extension.get(), file_url)); |
522 EXPECT_TRUE(Blocked(extension.get(), settings_url)); | 550 EXPECT_TRUE(Blocked(extension.get(), settings_url)); |
523 EXPECT_TRUE(Blocked(extension.get(), favicon_url)); | 551 EXPECT_TRUE(Blocked(extension.get(), favicon_url)); |
524 EXPECT_TRUE(Blocked(extension.get(), about_url)); | 552 EXPECT_TRUE(Blocked(extension.get(), about_url)); |
525 EXPECT_TRUE(Blocked(extension.get(), extension_url)); | 553 EXPECT_TRUE(Blocked(extension.get(), extension_url)); |
526 EXPECT_FALSE( | 554 EXPECT_FALSE(PermissionsData::ForExtension(extension) |
527 PermissionsData::HasHostPermission(extension.get(), settings_url)); | 555 ->HasHostPermission(settings_url)); |
528 } | 556 } |
529 | 557 |
530 TEST_F(ExtensionScriptAndCaptureVisibleTest, PermissionsWithChromeURLsEnabled) { | 558 TEST_F(ExtensionScriptAndCaptureVisibleTest, PermissionsWithChromeURLsEnabled) { |
531 CommandLine::ForCurrentProcess()->AppendSwitch( | 559 CommandLine::ForCurrentProcess()->AppendSwitch( |
532 switches::kExtensionsOnChromeURLs); | 560 switches::kExtensionsOnChromeURLs); |
533 | 561 |
534 scoped_refptr<Extension> extension; | 562 scoped_refptr<Extension> extension; |
535 | 563 |
536 // Test <all_urls> for regular extensions. | 564 // Test <all_urls> for regular extensions. |
537 extension = LoadManifestStrict("script_and_capture", | 565 extension = LoadManifestStrict("script_and_capture", |
538 "extension_regular_all.json"); | 566 "extension_regular_all.json"); |
539 EXPECT_TRUE(Allowed(extension.get(), http_url)); | 567 EXPECT_TRUE(Allowed(extension.get(), http_url)); |
540 EXPECT_TRUE(Allowed(extension.get(), https_url)); | 568 EXPECT_TRUE(Allowed(extension.get(), https_url)); |
541 EXPECT_TRUE(CaptureOnly(extension.get(), file_url)); | 569 EXPECT_TRUE(CaptureOnly(extension.get(), file_url)); |
542 EXPECT_TRUE(CaptureOnly(extension.get(), settings_url)); | 570 EXPECT_TRUE(CaptureOnly(extension.get(), settings_url)); |
543 EXPECT_TRUE(Allowed(extension.get(), favicon_url)); // chrome:// requested | 571 EXPECT_TRUE(Allowed(extension.get(), favicon_url)); // chrome:// requested |
544 EXPECT_TRUE(CaptureOnly(extension.get(), about_url)); | 572 EXPECT_TRUE(CaptureOnly(extension.get(), about_url)); |
545 EXPECT_TRUE(CaptureOnly(extension.get(), extension_url)); | 573 EXPECT_TRUE(CaptureOnly(extension.get(), extension_url)); |
546 | 574 |
547 // Test access to iframed content. | 575 // Test access to iframed content. |
548 GURL within_extension_url = extension->GetResourceURL("page.html"); | 576 GURL within_extension_url = extension->GetResourceURL("page.html"); |
549 EXPECT_TRUE(AllowedScript(extension.get(), http_url, http_url_with_path)); | 577 EXPECT_TRUE(AllowedScript(extension.get(), http_url, http_url_with_path)); |
550 EXPECT_TRUE(AllowedScript(extension.get(), https_url, http_url_with_path)); | 578 EXPECT_TRUE(AllowedScript(extension.get(), https_url, http_url_with_path)); |
551 EXPECT_TRUE(AllowedScript(extension.get(), http_url, within_extension_url)); | 579 EXPECT_TRUE(AllowedScript(extension.get(), http_url, within_extension_url)); |
552 EXPECT_TRUE(AllowedScript(extension.get(), https_url, within_extension_url)); | 580 EXPECT_TRUE(AllowedScript(extension.get(), https_url, within_extension_url)); |
553 EXPECT_TRUE(BlockedScript(extension.get(), http_url, extension_url)); | 581 EXPECT_TRUE(BlockedScript(extension.get(), http_url, extension_url)); |
554 EXPECT_TRUE(BlockedScript(extension.get(), https_url, extension_url)); | 582 EXPECT_TRUE(BlockedScript(extension.get(), https_url, extension_url)); |
555 | 583 |
556 EXPECT_FALSE( | 584 const PermissionsData* permissions_data = |
557 PermissionsData::HasHostPermission(extension.get(), settings_url)); | 585 PermissionsData::ForExtension(extension); |
558 EXPECT_FALSE(PermissionsData::HasHostPermission(extension.get(), about_url)); | 586 EXPECT_FALSE(permissions_data->HasHostPermission(settings_url)); |
559 EXPECT_TRUE(PermissionsData::HasHostPermission(extension.get(), favicon_url)); | 587 EXPECT_FALSE(permissions_data->HasHostPermission(about_url)); |
| 588 EXPECT_TRUE(permissions_data->HasHostPermission(favicon_url)); |
560 | 589 |
561 // Test * for scheme, which implies just the http/https schemes. | 590 // Test * for scheme, which implies just the http/https schemes. |
562 extension = LoadManifestStrict("script_and_capture", | 591 extension = LoadManifestStrict("script_and_capture", |
563 "extension_wildcard.json"); | 592 "extension_wildcard.json"); |
564 EXPECT_TRUE(ScriptOnly(extension.get(), http_url, http_url)); | 593 EXPECT_TRUE(ScriptOnly(extension.get(), http_url, http_url)); |
565 EXPECT_TRUE(ScriptOnly(extension.get(), https_url, https_url)); | 594 EXPECT_TRUE(ScriptOnly(extension.get(), https_url, https_url)); |
566 EXPECT_TRUE(Blocked(extension.get(), settings_url)); | 595 EXPECT_TRUE(Blocked(extension.get(), settings_url)); |
567 EXPECT_TRUE(Blocked(extension.get(), about_url)); | 596 EXPECT_TRUE(Blocked(extension.get(), about_url)); |
568 EXPECT_TRUE(Blocked(extension.get(), file_url)); | 597 EXPECT_TRUE(Blocked(extension.get(), file_url)); |
569 EXPECT_TRUE(Blocked(extension.get(), favicon_url)); | 598 EXPECT_TRUE(Blocked(extension.get(), favicon_url)); |
(...skipping 15 matching lines...) Expand all Loading... |
585 EXPECT_TRUE(Blocked(extension.get(), about_url)); | 614 EXPECT_TRUE(Blocked(extension.get(), about_url)); |
586 EXPECT_TRUE(Blocked(extension.get(), file_url)); | 615 EXPECT_TRUE(Blocked(extension.get(), file_url)); |
587 EXPECT_TRUE(ScriptOnly(extension.get(), favicon_url, favicon_url)); | 616 EXPECT_TRUE(ScriptOnly(extension.get(), favicon_url, favicon_url)); |
588 | 617 |
589 // Having chrome://favicon/* should not give you chrome://* | 618 // Having chrome://favicon/* should not give you chrome://* |
590 extension = LoadManifestStrict("script_and_capture", | 619 extension = LoadManifestStrict("script_and_capture", |
591 "extension_chrome_favicon_wildcard.json"); | 620 "extension_chrome_favicon_wildcard.json"); |
592 EXPECT_TRUE(Blocked(extension.get(), settings_url)); | 621 EXPECT_TRUE(Blocked(extension.get(), settings_url)); |
593 EXPECT_TRUE(ScriptOnly(extension.get(), favicon_url, favicon_url)); | 622 EXPECT_TRUE(ScriptOnly(extension.get(), favicon_url, favicon_url)); |
594 EXPECT_TRUE(Blocked(extension.get(), about_url)); | 623 EXPECT_TRUE(Blocked(extension.get(), about_url)); |
595 EXPECT_TRUE(PermissionsData::HasHostPermission(extension.get(), favicon_url)); | 624 EXPECT_TRUE( |
| 625 PermissionsData::ForExtension(extension)->HasHostPermission(favicon_url)); |
596 | 626 |
597 // Having http://favicon should not give you chrome://favicon | 627 // Having http://favicon should not give you chrome://favicon |
598 extension = LoadManifestStrict("script_and_capture", | 628 extension = LoadManifestStrict("script_and_capture", |
599 "extension_http_favicon.json"); | 629 "extension_http_favicon.json"); |
600 EXPECT_TRUE(Blocked(extension.get(), settings_url)); | 630 EXPECT_TRUE(Blocked(extension.get(), settings_url)); |
601 EXPECT_TRUE(Blocked(extension.get(), favicon_url)); | 631 EXPECT_TRUE(Blocked(extension.get(), favicon_url)); |
602 | 632 |
603 // Component extensions with <all_urls> should get everything. | 633 // Component extensions with <all_urls> should get everything. |
604 extension = LoadManifest("script_and_capture", "extension_component_all.json", | 634 extension = LoadManifest("script_and_capture", "extension_component_all.json", |
605 Manifest::COMPONENT, Extension::NO_FLAGS); | 635 Manifest::COMPONENT, Extension::NO_FLAGS); |
606 EXPECT_TRUE(Allowed(extension.get(), http_url)); | 636 EXPECT_TRUE(Allowed(extension.get(), http_url)); |
607 EXPECT_TRUE(Allowed(extension.get(), https_url)); | 637 EXPECT_TRUE(Allowed(extension.get(), https_url)); |
608 EXPECT_TRUE(Allowed(extension.get(), settings_url)); | 638 EXPECT_TRUE(Allowed(extension.get(), settings_url)); |
609 EXPECT_TRUE(Allowed(extension.get(), about_url)); | 639 EXPECT_TRUE(Allowed(extension.get(), about_url)); |
610 EXPECT_TRUE(Allowed(extension.get(), favicon_url)); | 640 EXPECT_TRUE(Allowed(extension.get(), favicon_url)); |
611 EXPECT_TRUE(PermissionsData::HasHostPermission(extension.get(), favicon_url)); | 641 EXPECT_TRUE( |
| 642 PermissionsData::ForExtension(extension)->HasHostPermission(favicon_url)); |
612 | 643 |
613 // Component extensions should only get access to what they ask for. | 644 // Component extensions should only get access to what they ask for. |
614 extension = LoadManifest("script_and_capture", | 645 extension = LoadManifest("script_and_capture", |
615 "extension_component_google.json", Manifest::COMPONENT, | 646 "extension_component_google.json", Manifest::COMPONENT, |
616 Extension::NO_FLAGS); | 647 Extension::NO_FLAGS); |
617 EXPECT_TRUE(ScriptOnly(extension.get(), http_url, http_url)); | 648 EXPECT_TRUE(ScriptOnly(extension.get(), http_url, http_url)); |
618 EXPECT_TRUE(Blocked(extension.get(), https_url)); | 649 EXPECT_TRUE(Blocked(extension.get(), https_url)); |
619 EXPECT_TRUE(Blocked(extension.get(), file_url)); | 650 EXPECT_TRUE(Blocked(extension.get(), file_url)); |
620 EXPECT_TRUE(Blocked(extension.get(), settings_url)); | 651 EXPECT_TRUE(Blocked(extension.get(), settings_url)); |
621 EXPECT_TRUE(Blocked(extension.get(), favicon_url)); | 652 EXPECT_TRUE(Blocked(extension.get(), favicon_url)); |
622 EXPECT_TRUE(Blocked(extension.get(), about_url)); | 653 EXPECT_TRUE(Blocked(extension.get(), about_url)); |
623 EXPECT_TRUE(Blocked(extension.get(), extension_url)); | 654 EXPECT_TRUE(Blocked(extension.get(), extension_url)); |
624 EXPECT_FALSE( | 655 EXPECT_FALSE(PermissionsData::ForExtension(extension) |
625 PermissionsData::HasHostPermission(extension.get(), settings_url)); | 656 ->HasHostPermission(settings_url)); |
626 } | 657 } |
627 | 658 |
628 TEST_F(ExtensionScriptAndCaptureVisibleTest, TabSpecific) { | 659 TEST_F(ExtensionScriptAndCaptureVisibleTest, TabSpecific) { |
629 scoped_refptr<Extension> extension = | 660 scoped_refptr<Extension> extension = |
630 LoadManifestStrict("script_and_capture", "tab_specific.json"); | 661 LoadManifestStrict("script_and_capture", "tab_specific.json"); |
631 | 662 |
632 EXPECT_FALSE(PermissionsData::GetTabSpecificPermissions(extension.get(), 0) | 663 const PermissionsData* permissions_data = |
633 .get()); | 664 PermissionsData::ForExtension(extension); |
634 EXPECT_FALSE(PermissionsData::GetTabSpecificPermissions(extension.get(), 1) | 665 EXPECT_FALSE(permissions_data->GetTabSpecificPermissionsForTesting(0)); |
635 .get()); | 666 EXPECT_FALSE(permissions_data->GetTabSpecificPermissionsForTesting(1)); |
636 EXPECT_FALSE(PermissionsData::GetTabSpecificPermissions(extension.get(), 2) | 667 EXPECT_FALSE(permissions_data->GetTabSpecificPermissionsForTesting(2)); |
637 .get()); | |
638 | 668 |
639 std::set<GURL> no_urls; | 669 std::set<GURL> no_urls; |
640 | 670 |
641 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), no_urls, 0)); | 671 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), no_urls, 0)); |
642 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), no_urls, 1)); | 672 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), no_urls, 1)); |
643 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), no_urls, 2)); | 673 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), no_urls, 2)); |
644 | 674 |
645 URLPatternSet allowed_hosts; | 675 URLPatternSet allowed_hosts; |
646 allowed_hosts.AddPattern(URLPattern(URLPattern::SCHEME_ALL, | 676 allowed_hosts.AddPattern(URLPattern(URLPattern::SCHEME_ALL, |
647 http_url.spec())); | 677 http_url.spec())); |
648 std::set<GURL> allowed_urls; | 678 std::set<GURL> allowed_urls; |
649 allowed_urls.insert(http_url); | 679 allowed_urls.insert(http_url); |
650 // http_url_with_path() will also be allowed, because Extension should be | 680 // http_url_with_path() will also be allowed, because Extension should be |
651 // considering the security origin of the URL not the URL itself, and | 681 // considering the security origin of the URL not the URL itself, and |
652 // http_url is in allowed_hosts. | 682 // http_url is in allowed_hosts. |
653 allowed_urls.insert(http_url_with_path); | 683 allowed_urls.insert(http_url_with_path); |
654 | 684 |
655 { | 685 { |
656 scoped_refptr<PermissionSet> permissions( | 686 scoped_refptr<PermissionSet> permissions( |
657 new PermissionSet(APIPermissionSet(), ManifestPermissionSet(), | 687 new PermissionSet(APIPermissionSet(), ManifestPermissionSet(), |
658 allowed_hosts, URLPatternSet())); | 688 allowed_hosts, URLPatternSet())); |
659 PermissionsData::UpdateTabSpecificPermissions( | 689 permissions_data->UpdateTabSpecificPermissions(0, permissions); |
660 extension.get(), 0, permissions); | |
661 EXPECT_EQ(permissions->explicit_hosts(), | 690 EXPECT_EQ(permissions->explicit_hosts(), |
662 PermissionsData::GetTabSpecificPermissions(extension.get(), 0) | 691 permissions_data->GetTabSpecificPermissionsForTesting(0) |
663 ->explicit_hosts()); | 692 ->explicit_hosts()); |
664 } | 693 } |
665 | 694 |
666 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), allowed_urls, 0)); | 695 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), allowed_urls, 0)); |
667 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), no_urls, 1)); | 696 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), no_urls, 1)); |
668 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), no_urls, 2)); | 697 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), no_urls, 2)); |
669 | 698 |
670 PermissionsData::ClearTabSpecificPermissions(extension.get(), 0); | 699 permissions_data->ClearTabSpecificPermissions(0); |
671 EXPECT_FALSE(PermissionsData::GetTabSpecificPermissions(extension.get(), 0) | 700 EXPECT_FALSE(permissions_data->GetTabSpecificPermissionsForTesting(0)); |
672 .get()); | |
673 | 701 |
674 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), no_urls, 0)); | 702 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), no_urls, 0)); |
675 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), no_urls, 1)); | 703 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), no_urls, 1)); |
676 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), no_urls, 2)); | 704 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), no_urls, 2)); |
677 | 705 |
678 std::set<GURL> more_allowed_urls = allowed_urls; | 706 std::set<GURL> more_allowed_urls = allowed_urls; |
679 more_allowed_urls.insert(https_url); | 707 more_allowed_urls.insert(https_url); |
680 URLPatternSet more_allowed_hosts = allowed_hosts; | 708 URLPatternSet more_allowed_hosts = allowed_hosts; |
681 more_allowed_hosts.AddPattern(URLPattern(URLPattern::SCHEME_ALL, | 709 more_allowed_hosts.AddPattern(URLPattern(URLPattern::SCHEME_ALL, |
682 https_url.spec())); | 710 https_url.spec())); |
683 | 711 |
684 { | 712 { |
685 scoped_refptr<PermissionSet> permissions( | 713 scoped_refptr<PermissionSet> permissions( |
686 new PermissionSet(APIPermissionSet(), ManifestPermissionSet(), | 714 new PermissionSet(APIPermissionSet(), ManifestPermissionSet(), |
687 allowed_hosts, URLPatternSet())); | 715 allowed_hosts, URLPatternSet())); |
688 PermissionsData::UpdateTabSpecificPermissions( | 716 permissions_data->UpdateTabSpecificPermissions(0, permissions); |
689 extension.get(), 0, permissions); | |
690 EXPECT_EQ(permissions->explicit_hosts(), | 717 EXPECT_EQ(permissions->explicit_hosts(), |
691 PermissionsData::GetTabSpecificPermissions(extension.get(), 0) | 718 permissions_data->GetTabSpecificPermissionsForTesting(0) |
692 ->explicit_hosts()); | 719 ->explicit_hosts()); |
693 | 720 |
694 permissions = new PermissionSet(APIPermissionSet(), | 721 permissions = new PermissionSet(APIPermissionSet(), |
695 ManifestPermissionSet(), | 722 ManifestPermissionSet(), |
696 more_allowed_hosts, | 723 more_allowed_hosts, |
697 URLPatternSet()); | 724 URLPatternSet()); |
698 PermissionsData::UpdateTabSpecificPermissions( | 725 permissions_data->UpdateTabSpecificPermissions(1, permissions); |
699 extension.get(), 1, permissions); | |
700 EXPECT_EQ(permissions->explicit_hosts(), | 726 EXPECT_EQ(permissions->explicit_hosts(), |
701 PermissionsData::GetTabSpecificPermissions(extension.get(), 1) | 727 permissions_data->GetTabSpecificPermissionsForTesting(1) |
702 ->explicit_hosts()); | 728 ->explicit_hosts()); |
703 } | 729 } |
704 | 730 |
705 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), allowed_urls, 0)); | 731 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), allowed_urls, 0)); |
706 EXPECT_TRUE( | 732 EXPECT_TRUE( |
707 ScriptAllowedExclusivelyOnTab(extension.get(), more_allowed_urls, 1)); | 733 ScriptAllowedExclusivelyOnTab(extension.get(), more_allowed_urls, 1)); |
708 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), no_urls, 2)); | 734 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), no_urls, 2)); |
709 | 735 |
710 PermissionsData::ClearTabSpecificPermissions(extension.get(), 0); | 736 permissions_data->ClearTabSpecificPermissions(0); |
711 EXPECT_FALSE(PermissionsData::GetTabSpecificPermissions(extension.get(), 0) | 737 EXPECT_FALSE(permissions_data->GetTabSpecificPermissionsForTesting(0)); |
712 .get()); | |
713 | 738 |
714 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), no_urls, 0)); | 739 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), no_urls, 0)); |
715 EXPECT_TRUE( | 740 EXPECT_TRUE( |
716 ScriptAllowedExclusivelyOnTab(extension.get(), more_allowed_urls, 1)); | 741 ScriptAllowedExclusivelyOnTab(extension.get(), more_allowed_urls, 1)); |
717 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), no_urls, 2)); | 742 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), no_urls, 2)); |
718 | 743 |
719 PermissionsData::ClearTabSpecificPermissions(extension.get(), 1); | 744 permissions_data->ClearTabSpecificPermissions(1); |
720 EXPECT_FALSE(PermissionsData::GetTabSpecificPermissions(extension.get(), 1) | 745 EXPECT_FALSE(permissions_data->GetTabSpecificPermissionsForTesting(1)); |
721 .get()); | |
722 | 746 |
723 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), no_urls, 0)); | 747 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), no_urls, 0)); |
724 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), no_urls, 1)); | 748 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), no_urls, 1)); |
725 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), no_urls, 2)); | 749 EXPECT_TRUE(ScriptAllowedExclusivelyOnTab(extension.get(), no_urls, 2)); |
726 } | 750 } |
727 | 751 |
728 } // namespace extensions | 752 } // namespace extensions |
OLD | NEW |