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 "base/files/file_path.h" | 5 #include "base/files/file_path.h" |
6 #include "base/json/json_file_value_serializer.h" | 6 #include "base/json/json_file_value_serializer.h" |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 hosts, URLPatternSet()); | 211 hosts, URLPatternSet()); |
212 | 212 |
213 PermissionsUpdaterListener listener; | 213 PermissionsUpdaterListener listener; |
214 PermissionsUpdater updater(profile_.get()); | 214 PermissionsUpdater updater(profile_.get()); |
215 updater.AddPermissions(extension.get(), delta.get()); | 215 updater.AddPermissions(extension.get(), delta.get()); |
216 | 216 |
217 listener.Wait(); | 217 listener.Wait(); |
218 | 218 |
219 // Verify that the permission notification was sent correctly. | 219 // Verify that the permission notification was sent correctly. |
220 ASSERT_TRUE(listener.received_notification()); | 220 ASSERT_TRUE(listener.received_notification()); |
221 ASSERT_EQ(extension, listener.extension()); | 221 ASSERT_EQ(extension.get(), listener.extension()); |
222 ASSERT_EQ(UpdatedExtensionPermissionsInfo::ADDED, listener.reason()); | 222 ASSERT_EQ(UpdatedExtensionPermissionsInfo::ADDED, listener.reason()); |
223 ASSERT_EQ(*delta.get(), *listener.permissions()); | 223 ASSERT_EQ(*delta.get(), *listener.permissions()); |
224 | 224 |
225 // Make sure the extension's active permissions reflect the change. | 225 // Make sure the extension's active permissions reflect the change. |
226 scoped_refptr<PermissionSet> active_permissions = | 226 scoped_refptr<PermissionSet> active_permissions = |
227 PermissionSet::CreateUnion(default_permissions.get(), delta.get()); | 227 PermissionSet::CreateUnion(default_permissions.get(), delta.get()); |
228 ASSERT_EQ(*active_permissions.get(), | 228 ASSERT_EQ(*active_permissions.get(), |
229 *extension->permissions_data()->active_permissions().get()); | 229 *extension->permissions_data()->active_permissions().get()); |
230 | 230 |
231 // Verify that the new granted and active permissions were also stored | 231 // Verify that the new granted and active permissions were also stored |
(...skipping 15 matching lines...) Expand all Loading... |
247 apis.erase(APIPermission::kNotifications); | 247 apis.erase(APIPermission::kNotifications); |
248 delta = new PermissionSet(apis, empty_manifest_permissions, | 248 delta = new PermissionSet(apis, empty_manifest_permissions, |
249 hosts, URLPatternSet()); | 249 hosts, URLPatternSet()); |
250 | 250 |
251 listener.Reset(); | 251 listener.Reset(); |
252 updater.RemovePermissions(extension.get(), delta.get()); | 252 updater.RemovePermissions(extension.get(), delta.get()); |
253 listener.Wait(); | 253 listener.Wait(); |
254 | 254 |
255 // Verify that the notification was correct. | 255 // Verify that the notification was correct. |
256 ASSERT_TRUE(listener.received_notification()); | 256 ASSERT_TRUE(listener.received_notification()); |
257 ASSERT_EQ(extension, listener.extension()); | 257 ASSERT_EQ(extension.get(), listener.extension()); |
258 ASSERT_EQ(UpdatedExtensionPermissionsInfo::REMOVED, listener.reason()); | 258 ASSERT_EQ(UpdatedExtensionPermissionsInfo::REMOVED, listener.reason()); |
259 ASSERT_EQ(*delta.get(), *listener.permissions()); | 259 ASSERT_EQ(*delta.get(), *listener.permissions()); |
260 | 260 |
261 // Make sure the extension's active permissions reflect the change. | 261 // Make sure the extension's active permissions reflect the change. |
262 active_permissions = | 262 active_permissions = |
263 PermissionSet::CreateDifference(active_permissions.get(), delta.get()); | 263 PermissionSet::CreateDifference(active_permissions.get(), delta.get()); |
264 ASSERT_EQ(*active_permissions.get(), | 264 ASSERT_EQ(*active_permissions.get(), |
265 *extension->permissions_data()->active_permissions().get()); | 265 *extension->permissions_data()->active_permissions().get()); |
266 | 266 |
267 // Verify that the extension prefs hold the new active permissions and the | 267 // Verify that the extension prefs hold the new active permissions and the |
(...skipping 29 matching lines...) Expand all Loading... |
297 safe_patterns.insert(google); | 297 safe_patterns.insert(google); |
298 safe_patterns.insert(sub_google); | 298 safe_patterns.insert(sub_google); |
299 | 299 |
300 std::set<URLPattern> all_patterns = base::STLSetUnion<std::set<URLPattern> >( | 300 std::set<URLPattern> all_patterns = base::STLSetUnion<std::set<URLPattern> >( |
301 all_host_patterns, safe_patterns); | 301 all_host_patterns, safe_patterns); |
302 | 302 |
303 scoped_refptr<const Extension> extension = CreateExtensionWithPermissions( | 303 scoped_refptr<const Extension> extension = CreateExtensionWithPermissions( |
304 all_patterns, all_patterns, Manifest::INTERNAL); | 304 all_patterns, all_patterns, Manifest::INTERNAL); |
305 const PermissionsData* permissions_data = extension->permissions_data(); | 305 const PermissionsData* permissions_data = extension->permissions_data(); |
306 PermissionsUpdater updater(profile_.get()); | 306 PermissionsUpdater updater(profile_.get()); |
307 updater.InitializePermissions(extension); | 307 updater.InitializePermissions(extension.get()); |
308 | 308 |
309 // At first, the active permissions should have only the safe patterns and | 309 // At first, the active permissions should have only the safe patterns and |
310 // the withheld permissions should have only the all host patterns. | 310 // the withheld permissions should have only the all host patterns. |
311 EXPECT_TRUE(SetsAreEqual( | 311 EXPECT_TRUE(SetsAreEqual( |
312 permissions_data->active_permissions()->scriptable_hosts().patterns(), | 312 permissions_data->active_permissions()->scriptable_hosts().patterns(), |
313 safe_patterns)); | 313 safe_patterns)); |
314 EXPECT_TRUE(SetsAreEqual( | 314 EXPECT_TRUE(SetsAreEqual( |
315 permissions_data->active_permissions()->explicit_hosts().patterns(), | 315 permissions_data->active_permissions()->explicit_hosts().patterns(), |
316 safe_patterns)); | 316 safe_patterns)); |
317 EXPECT_TRUE(SetsAreEqual( | 317 EXPECT_TRUE(SetsAreEqual( |
318 permissions_data->withheld_permissions()->scriptable_hosts().patterns(), | 318 permissions_data->withheld_permissions()->scriptable_hosts().patterns(), |
319 all_host_patterns)); | 319 all_host_patterns)); |
320 EXPECT_TRUE(SetsAreEqual( | 320 EXPECT_TRUE(SetsAreEqual( |
321 permissions_data->withheld_permissions()->explicit_hosts().patterns(), | 321 permissions_data->withheld_permissions()->explicit_hosts().patterns(), |
322 all_host_patterns)); | 322 all_host_patterns)); |
323 | 323 |
324 // Then, we grant the withheld all-hosts permissions. | 324 // Then, we grant the withheld all-hosts permissions. |
325 updater.GrantWithheldImpliedAllHosts(extension); | 325 updater.GrantWithheldImpliedAllHosts(extension.get()); |
326 // Now, active permissions should have all patterns, and withheld permissions | 326 // Now, active permissions should have all patterns, and withheld permissions |
327 // should have none. | 327 // should have none. |
328 EXPECT_TRUE(SetsAreEqual( | 328 EXPECT_TRUE(SetsAreEqual( |
329 permissions_data->active_permissions()->scriptable_hosts().patterns(), | 329 permissions_data->active_permissions()->scriptable_hosts().patterns(), |
330 all_patterns)); | 330 all_patterns)); |
331 EXPECT_TRUE(permissions_data->withheld_permissions() | 331 EXPECT_TRUE(permissions_data->withheld_permissions() |
332 ->scriptable_hosts() | 332 ->scriptable_hosts() |
333 .patterns() | 333 .patterns() |
334 .empty()); | 334 .empty()); |
335 EXPECT_TRUE(SetsAreEqual( | 335 EXPECT_TRUE(SetsAreEqual( |
336 permissions_data->active_permissions()->explicit_hosts().patterns(), | 336 permissions_data->active_permissions()->explicit_hosts().patterns(), |
337 all_patterns)); | 337 all_patterns)); |
338 EXPECT_TRUE(permissions_data->withheld_permissions() | 338 EXPECT_TRUE(permissions_data->withheld_permissions() |
339 ->explicit_hosts() | 339 ->explicit_hosts() |
340 .patterns() | 340 .patterns() |
341 .empty()); | 341 .empty()); |
342 | 342 |
343 // Finally, we revoke the all hosts permissions. | 343 // Finally, we revoke the all hosts permissions. |
344 updater.WithholdImpliedAllHosts(extension); | 344 updater.WithholdImpliedAllHosts(extension.get()); |
345 | 345 |
346 // We should be back to our initial state - all_hosts should be withheld, and | 346 // We should be back to our initial state - all_hosts should be withheld, and |
347 // the safe patterns should be granted. | 347 // the safe patterns should be granted. |
348 EXPECT_TRUE(SetsAreEqual( | 348 EXPECT_TRUE(SetsAreEqual( |
349 permissions_data->active_permissions()->scriptable_hosts().patterns(), | 349 permissions_data->active_permissions()->scriptable_hosts().patterns(), |
350 safe_patterns)); | 350 safe_patterns)); |
351 EXPECT_TRUE(SetsAreEqual( | 351 EXPECT_TRUE(SetsAreEqual( |
352 permissions_data->active_permissions()->explicit_hosts().patterns(), | 352 permissions_data->active_permissions()->explicit_hosts().patterns(), |
353 safe_patterns)); | 353 safe_patterns)); |
354 EXPECT_TRUE(SetsAreEqual( | 354 EXPECT_TRUE(SetsAreEqual( |
355 permissions_data->withheld_permissions()->scriptable_hosts().patterns(), | 355 permissions_data->withheld_permissions()->scriptable_hosts().patterns(), |
356 all_host_patterns)); | 356 all_host_patterns)); |
357 EXPECT_TRUE(SetsAreEqual( | 357 EXPECT_TRUE(SetsAreEqual( |
358 permissions_data->withheld_permissions()->explicit_hosts().patterns(), | 358 permissions_data->withheld_permissions()->explicit_hosts().patterns(), |
359 all_host_patterns)); | 359 all_host_patterns)); |
360 | 360 |
361 // Creating a component extension should result in no withheld permissions. | 361 // Creating a component extension should result in no withheld permissions. |
362 extension = CreateExtensionWithPermissions( | 362 extension = CreateExtensionWithPermissions( |
363 all_patterns, all_patterns, Manifest::COMPONENT); | 363 all_patterns, all_patterns, Manifest::COMPONENT); |
364 permissions_data = extension->permissions_data(); | 364 permissions_data = extension->permissions_data(); |
365 updater.InitializePermissions(extension); | 365 updater.InitializePermissions(extension.get()); |
366 EXPECT_TRUE(SetsAreEqual( | 366 EXPECT_TRUE(SetsAreEqual( |
367 permissions_data->active_permissions()->scriptable_hosts().patterns(), | 367 permissions_data->active_permissions()->scriptable_hosts().patterns(), |
368 all_patterns)); | 368 all_patterns)); |
369 EXPECT_TRUE(permissions_data->withheld_permissions() | 369 EXPECT_TRUE(permissions_data->withheld_permissions() |
370 ->scriptable_hosts() | 370 ->scriptable_hosts() |
371 .patterns() | 371 .patterns() |
372 .empty()); | 372 .empty()); |
373 EXPECT_TRUE(SetsAreEqual( | 373 EXPECT_TRUE(SetsAreEqual( |
374 permissions_data->active_permissions()->explicit_hosts().patterns(), | 374 permissions_data->active_permissions()->explicit_hosts().patterns(), |
375 all_patterns)); | 375 all_patterns)); |
376 EXPECT_TRUE(permissions_data->withheld_permissions() | 376 EXPECT_TRUE(permissions_data->withheld_permissions() |
377 ->explicit_hosts() | 377 ->explicit_hosts() |
378 .patterns() | 378 .patterns() |
379 .empty()); | 379 .empty()); |
380 | 380 |
381 // Without the switch, we shouldn't withhold anything. | 381 // Without the switch, we shouldn't withhold anything. |
382 switch_override.reset(); | 382 switch_override.reset(); |
383 extension = CreateExtensionWithPermissions( | 383 extension = CreateExtensionWithPermissions( |
384 all_patterns, all_patterns, Manifest::INTERNAL); | 384 all_patterns, all_patterns, Manifest::INTERNAL); |
385 permissions_data = extension->permissions_data(); | 385 permissions_data = extension->permissions_data(); |
386 updater.InitializePermissions(extension); | 386 updater.InitializePermissions(extension.get()); |
387 EXPECT_TRUE(SetsAreEqual( | 387 EXPECT_TRUE(SetsAreEqual( |
388 permissions_data->active_permissions()->scriptable_hosts().patterns(), | 388 permissions_data->active_permissions()->scriptable_hosts().patterns(), |
389 all_patterns)); | 389 all_patterns)); |
390 EXPECT_TRUE(permissions_data->withheld_permissions() | 390 EXPECT_TRUE(permissions_data->withheld_permissions() |
391 ->scriptable_hosts() | 391 ->scriptable_hosts() |
392 .patterns() | 392 .patterns() |
393 .empty()); | 393 .empty()); |
394 EXPECT_TRUE(SetsAreEqual( | 394 EXPECT_TRUE(SetsAreEqual( |
395 permissions_data->active_permissions()->explicit_hosts().patterns(), | 395 permissions_data->active_permissions()->explicit_hosts().patterns(), |
396 all_patterns)); | 396 all_patterns)); |
397 EXPECT_TRUE(permissions_data->withheld_permissions() | 397 EXPECT_TRUE(permissions_data->withheld_permissions() |
398 ->explicit_hosts() | 398 ->explicit_hosts() |
399 .patterns() | 399 .patterns() |
400 .empty()); | 400 .empty()); |
401 } | 401 } |
402 | 402 |
403 } // namespace extensions | 403 } // namespace extensions |
OLD | NEW |