| 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/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/json/json_file_value_serializer.h" | 6 #include "base/json/json_file_value_serializer.h" |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/common/chrome_paths.h" | 10 #include "chrome/common/chrome_paths.h" |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 permissions = extension->GetActivePermissions(); | 195 permissions = extension->GetActivePermissions(); |
| 196 EXPECT_FALSE(permissions->HasEffectiveAccessToURL(GURL("http://test/"))); | 196 EXPECT_FALSE(permissions->HasEffectiveAccessToURL(GURL("http://test/"))); |
| 197 EXPECT_TRUE(permissions->HasEffectiveAccessToURL(GURL("https://test/"))); | 197 EXPECT_TRUE(permissions->HasEffectiveAccessToURL(GURL("https://test/"))); |
| 198 EXPECT_TRUE( | 198 EXPECT_TRUE( |
| 199 permissions->HasEffectiveAccessToURL(GURL("http://www.google.com"))); | 199 permissions->HasEffectiveAccessToURL(GURL("http://www.google.com"))); |
| 200 EXPECT_TRUE(permissions->HasEffectiveAccessToAllHosts()); | 200 EXPECT_TRUE(permissions->HasEffectiveAccessToAllHosts()); |
| 201 } | 201 } |
| 202 | 202 |
| 203 TEST(PermissionsTest, ExplicitAccessToOrigin) { | 203 TEST(PermissionsTest, ExplicitAccessToOrigin) { |
| 204 APIPermissionSet apis; | 204 APIPermissionSet apis; |
| 205 ManifestPermissionSet manifest_permissions; |
| 205 URLPatternSet explicit_hosts; | 206 URLPatternSet explicit_hosts; |
| 206 URLPatternSet scriptable_hosts; | 207 URLPatternSet scriptable_hosts; |
| 207 | 208 |
| 208 AddPattern(&explicit_hosts, "http://*.google.com/*"); | 209 AddPattern(&explicit_hosts, "http://*.google.com/*"); |
| 209 // The explicit host paths should get set to /*. | 210 // The explicit host paths should get set to /*. |
| 210 AddPattern(&explicit_hosts, "http://www.example.com/a/particular/path/*"); | 211 AddPattern(&explicit_hosts, "http://www.example.com/a/particular/path/*"); |
| 211 | 212 |
| 212 scoped_refptr<PermissionSet> perm_set = new PermissionSet( | 213 scoped_refptr<PermissionSet> perm_set = new PermissionSet( |
| 213 apis, explicit_hosts, scriptable_hosts); | 214 apis, manifest_permissions, explicit_hosts, scriptable_hosts); |
| 214 ASSERT_TRUE(perm_set->HasExplicitAccessToOrigin( | 215 ASSERT_TRUE(perm_set->HasExplicitAccessToOrigin( |
| 215 GURL("http://www.google.com/"))); | 216 GURL("http://www.google.com/"))); |
| 216 ASSERT_TRUE(perm_set->HasExplicitAccessToOrigin( | 217 ASSERT_TRUE(perm_set->HasExplicitAccessToOrigin( |
| 217 GURL("http://test.google.com/"))); | 218 GURL("http://test.google.com/"))); |
| 218 ASSERT_TRUE(perm_set->HasExplicitAccessToOrigin( | 219 ASSERT_TRUE(perm_set->HasExplicitAccessToOrigin( |
| 219 GURL("http://www.example.com"))); | 220 GURL("http://www.example.com"))); |
| 220 ASSERT_TRUE(perm_set->HasEffectiveAccessToURL( | 221 ASSERT_TRUE(perm_set->HasEffectiveAccessToURL( |
| 221 GURL("http://www.example.com"))); | 222 GURL("http://www.example.com"))); |
| 222 ASSERT_FALSE(perm_set->HasExplicitAccessToOrigin( | 223 ASSERT_FALSE(perm_set->HasExplicitAccessToOrigin( |
| 223 GURL("http://test.example.com"))); | 224 GURL("http://test.example.com"))); |
| 224 } | 225 } |
| 225 | 226 |
| 226 TEST(PermissionsTest, CreateUnion) { | 227 TEST(PermissionsTest, CreateUnion) { |
| 227 APIPermission* permission = NULL; | 228 APIPermission* permission = NULL; |
| 228 | 229 |
| 230 ManifestPermissionSet manifest_permissions; |
| 229 APIPermissionSet apis1; | 231 APIPermissionSet apis1; |
| 230 APIPermissionSet apis2; | 232 APIPermissionSet apis2; |
| 231 APIPermissionSet expected_apis; | 233 APIPermissionSet expected_apis; |
| 232 | 234 |
| 233 URLPatternSet explicit_hosts1; | 235 URLPatternSet explicit_hosts1; |
| 234 URLPatternSet explicit_hosts2; | 236 URLPatternSet explicit_hosts2; |
| 235 URLPatternSet expected_explicit_hosts; | 237 URLPatternSet expected_explicit_hosts; |
| 236 | 238 |
| 237 URLPatternSet scriptable_hosts1; | 239 URLPatternSet scriptable_hosts1; |
| 238 URLPatternSet scriptable_hosts2; | 240 URLPatternSet scriptable_hosts2; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 263 apis1.insert(APIPermission::kBackground); | 265 apis1.insert(APIPermission::kBackground); |
| 264 apis1.insert(permission->Clone()); | 266 apis1.insert(permission->Clone()); |
| 265 expected_apis.insert(APIPermission::kTab); | 267 expected_apis.insert(APIPermission::kTab); |
| 266 expected_apis.insert(APIPermission::kBackground); | 268 expected_apis.insert(APIPermission::kBackground); |
| 267 expected_apis.insert(permission); | 269 expected_apis.insert(permission); |
| 268 | 270 |
| 269 AddPattern(&explicit_hosts1, "http://*.google.com/*"); | 271 AddPattern(&explicit_hosts1, "http://*.google.com/*"); |
| 270 AddPattern(&expected_explicit_hosts, "http://*.google.com/*"); | 272 AddPattern(&expected_explicit_hosts, "http://*.google.com/*"); |
| 271 AddPattern(&effective_hosts, "http://*.google.com/*"); | 273 AddPattern(&effective_hosts, "http://*.google.com/*"); |
| 272 | 274 |
| 273 set1 = new PermissionSet(apis1, explicit_hosts1, scriptable_hosts1); | 275 set1 = new PermissionSet(apis1, manifest_permissions, |
| 274 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2); | 276 explicit_hosts1, scriptable_hosts1); |
| 277 set2 = new PermissionSet(apis2, manifest_permissions, |
| 278 explicit_hosts2, scriptable_hosts2); |
| 275 union_set = PermissionSet::CreateUnion(set1.get(), set2.get()); | 279 union_set = PermissionSet::CreateUnion(set1.get(), set2.get()); |
| 276 EXPECT_TRUE(set1->Contains(*set2.get())); | 280 EXPECT_TRUE(set1->Contains(*set2.get())); |
| 277 EXPECT_TRUE(set1->Contains(*union_set.get())); | 281 EXPECT_TRUE(set1->Contains(*union_set.get())); |
| 278 EXPECT_FALSE(set2->Contains(*set1.get())); | 282 EXPECT_FALSE(set2->Contains(*set1.get())); |
| 279 EXPECT_FALSE(set2->Contains(*union_set.get())); | 283 EXPECT_FALSE(set2->Contains(*union_set.get())); |
| 280 EXPECT_TRUE(union_set->Contains(*set1.get())); | 284 EXPECT_TRUE(union_set->Contains(*set1.get())); |
| 281 EXPECT_TRUE(union_set->Contains(*set2.get())); | 285 EXPECT_TRUE(union_set->Contains(*set2.get())); |
| 282 | 286 |
| 283 EXPECT_FALSE(union_set->HasEffectiveFullAccess()); | 287 EXPECT_FALSE(union_set->HasEffectiveFullAccess()); |
| 284 EXPECT_EQ(expected_apis, union_set->apis()); | 288 EXPECT_EQ(expected_apis, union_set->apis()); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 expected_apis.insert(permission); | 329 expected_apis.insert(permission); |
| 326 | 330 |
| 327 AddPattern(&explicit_hosts2, "http://*.example.com/*"); | 331 AddPattern(&explicit_hosts2, "http://*.example.com/*"); |
| 328 AddPattern(&scriptable_hosts2, "http://*.google.com/*"); | 332 AddPattern(&scriptable_hosts2, "http://*.google.com/*"); |
| 329 AddPattern(&expected_explicit_hosts, "http://*.example.com/*"); | 333 AddPattern(&expected_explicit_hosts, "http://*.example.com/*"); |
| 330 AddPattern(&expected_scriptable_hosts, "http://*.google.com/*"); | 334 AddPattern(&expected_scriptable_hosts, "http://*.google.com/*"); |
| 331 | 335 |
| 332 URLPatternSet::CreateUnion( | 336 URLPatternSet::CreateUnion( |
| 333 explicit_hosts2, scriptable_hosts2, &effective_hosts); | 337 explicit_hosts2, scriptable_hosts2, &effective_hosts); |
| 334 | 338 |
| 335 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2); | 339 set2 = new PermissionSet(apis2, manifest_permissions, |
| 340 explicit_hosts2, scriptable_hosts2); |
| 336 union_set = PermissionSet::CreateUnion(set1.get(), set2.get()); | 341 union_set = PermissionSet::CreateUnion(set1.get(), set2.get()); |
| 337 | 342 |
| 338 EXPECT_FALSE(set1->Contains(*set2.get())); | 343 EXPECT_FALSE(set1->Contains(*set2.get())); |
| 339 EXPECT_FALSE(set1->Contains(*union_set.get())); | 344 EXPECT_FALSE(set1->Contains(*union_set.get())); |
| 340 EXPECT_FALSE(set2->Contains(*set1.get())); | 345 EXPECT_FALSE(set2->Contains(*set1.get())); |
| 341 EXPECT_FALSE(set2->Contains(*union_set.get())); | 346 EXPECT_FALSE(set2->Contains(*union_set.get())); |
| 342 EXPECT_TRUE(union_set->Contains(*set1.get())); | 347 EXPECT_TRUE(union_set->Contains(*set1.get())); |
| 343 EXPECT_TRUE(union_set->Contains(*set2.get())); | 348 EXPECT_TRUE(union_set->Contains(*set2.get())); |
| 344 | 349 |
| 345 EXPECT_TRUE(union_set->HasEffectiveFullAccess()); | 350 EXPECT_TRUE(union_set->HasEffectiveFullAccess()); |
| 346 EXPECT_TRUE(union_set->HasEffectiveAccessToAllHosts()); | 351 EXPECT_TRUE(union_set->HasEffectiveAccessToAllHosts()); |
| 347 EXPECT_EQ(expected_apis, union_set->apis()); | 352 EXPECT_EQ(expected_apis, union_set->apis()); |
| 348 EXPECT_EQ(expected_explicit_hosts, union_set->explicit_hosts()); | 353 EXPECT_EQ(expected_explicit_hosts, union_set->explicit_hosts()); |
| 349 EXPECT_EQ(expected_scriptable_hosts, union_set->scriptable_hosts()); | 354 EXPECT_EQ(expected_scriptable_hosts, union_set->scriptable_hosts()); |
| 350 EXPECT_EQ(effective_hosts, union_set->effective_hosts()); | 355 EXPECT_EQ(effective_hosts, union_set->effective_hosts()); |
| 351 } | 356 } |
| 352 | 357 |
| 353 TEST(PermissionsTest, CreateIntersection) { | 358 TEST(PermissionsTest, CreateIntersection) { |
| 354 APIPermission* permission = NULL; | 359 APIPermission* permission = NULL; |
| 355 | 360 |
| 361 ManifestPermissionSet manifest_permissions; |
| 356 APIPermissionSet apis1; | 362 APIPermissionSet apis1; |
| 357 APIPermissionSet apis2; | 363 APIPermissionSet apis2; |
| 358 APIPermissionSet expected_apis; | 364 APIPermissionSet expected_apis; |
| 359 | 365 |
| 360 URLPatternSet explicit_hosts1; | 366 URLPatternSet explicit_hosts1; |
| 361 URLPatternSet explicit_hosts2; | 367 URLPatternSet explicit_hosts2; |
| 362 URLPatternSet expected_explicit_hosts; | 368 URLPatternSet expected_explicit_hosts; |
| 363 | 369 |
| 364 URLPatternSet scriptable_hosts1; | 370 URLPatternSet scriptable_hosts1; |
| 365 URLPatternSet scriptable_hosts2; | 371 URLPatternSet scriptable_hosts2; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 386 value->Append(base::Value::CreateStringValue("udp-send-to::8888")); | 392 value->Append(base::Value::CreateStringValue("udp-send-to::8888")); |
| 387 if (!permission->FromValue(value.get())) { | 393 if (!permission->FromValue(value.get())) { |
| 388 NOTREACHED(); | 394 NOTREACHED(); |
| 389 } | 395 } |
| 390 } | 396 } |
| 391 apis1.insert(permission); | 397 apis1.insert(permission); |
| 392 | 398 |
| 393 AddPattern(&explicit_hosts1, "http://*.google.com/*"); | 399 AddPattern(&explicit_hosts1, "http://*.google.com/*"); |
| 394 AddPattern(&scriptable_hosts1, "http://www.reddit.com/*"); | 400 AddPattern(&scriptable_hosts1, "http://www.reddit.com/*"); |
| 395 | 401 |
| 396 set1 = new PermissionSet(apis1, explicit_hosts1, scriptable_hosts1); | 402 set1 = new PermissionSet(apis1, manifest_permissions, |
| 397 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2); | 403 explicit_hosts1, scriptable_hosts1); |
| 404 set2 = new PermissionSet(apis2, manifest_permissions, |
| 405 explicit_hosts2, scriptable_hosts2); |
| 398 new_set = PermissionSet::CreateIntersection(set1.get(), set2.get()); | 406 new_set = PermissionSet::CreateIntersection(set1.get(), set2.get()); |
| 399 EXPECT_TRUE(set1->Contains(*new_set.get())); | 407 EXPECT_TRUE(set1->Contains(*new_set.get())); |
| 400 EXPECT_TRUE(set2->Contains(*new_set.get())); | 408 EXPECT_TRUE(set2->Contains(*new_set.get())); |
| 401 EXPECT_TRUE(set1->Contains(*set2.get())); | 409 EXPECT_TRUE(set1->Contains(*set2.get())); |
| 402 EXPECT_FALSE(set2->Contains(*set1.get())); | 410 EXPECT_FALSE(set2->Contains(*set1.get())); |
| 403 EXPECT_FALSE(new_set->Contains(*set1.get())); | 411 EXPECT_FALSE(new_set->Contains(*set1.get())); |
| 404 EXPECT_TRUE(new_set->Contains(*set2.get())); | 412 EXPECT_TRUE(new_set->Contains(*set2.get())); |
| 405 | 413 |
| 406 EXPECT_TRUE(new_set->IsEmpty()); | 414 EXPECT_TRUE(new_set->IsEmpty()); |
| 407 EXPECT_FALSE(new_set->HasEffectiveFullAccess()); | 415 EXPECT_FALSE(new_set->HasEffectiveFullAccess()); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 expected_apis.insert(permission); | 448 expected_apis.insert(permission); |
| 441 | 449 |
| 442 AddPattern(&explicit_hosts2, "http://*.example.com/*"); | 450 AddPattern(&explicit_hosts2, "http://*.example.com/*"); |
| 443 AddPattern(&explicit_hosts2, "http://*.google.com/*"); | 451 AddPattern(&explicit_hosts2, "http://*.google.com/*"); |
| 444 AddPattern(&scriptable_hosts2, "http://*.google.com/*"); | 452 AddPattern(&scriptable_hosts2, "http://*.google.com/*"); |
| 445 AddPattern(&expected_explicit_hosts, "http://*.google.com/*"); | 453 AddPattern(&expected_explicit_hosts, "http://*.google.com/*"); |
| 446 | 454 |
| 447 effective_hosts.ClearPatterns(); | 455 effective_hosts.ClearPatterns(); |
| 448 AddPattern(&effective_hosts, "http://*.google.com/*"); | 456 AddPattern(&effective_hosts, "http://*.google.com/*"); |
| 449 | 457 |
| 450 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2); | 458 set2 = new PermissionSet(apis2, manifest_permissions, |
| 459 explicit_hosts2, scriptable_hosts2); |
| 451 new_set = PermissionSet::CreateIntersection(set1.get(), set2.get()); | 460 new_set = PermissionSet::CreateIntersection(set1.get(), set2.get()); |
| 452 | 461 |
| 453 EXPECT_TRUE(set1->Contains(*new_set.get())); | 462 EXPECT_TRUE(set1->Contains(*new_set.get())); |
| 454 EXPECT_TRUE(set2->Contains(*new_set.get())); | 463 EXPECT_TRUE(set2->Contains(*new_set.get())); |
| 455 EXPECT_FALSE(set1->Contains(*set2.get())); | 464 EXPECT_FALSE(set1->Contains(*set2.get())); |
| 456 EXPECT_FALSE(set2->Contains(*set1.get())); | 465 EXPECT_FALSE(set2->Contains(*set1.get())); |
| 457 EXPECT_FALSE(new_set->Contains(*set1.get())); | 466 EXPECT_FALSE(new_set->Contains(*set1.get())); |
| 458 EXPECT_FALSE(new_set->Contains(*set2.get())); | 467 EXPECT_FALSE(new_set->Contains(*set2.get())); |
| 459 | 468 |
| 460 EXPECT_FALSE(new_set->HasEffectiveFullAccess()); | 469 EXPECT_FALSE(new_set->HasEffectiveFullAccess()); |
| 461 EXPECT_FALSE(new_set->HasEffectiveAccessToAllHosts()); | 470 EXPECT_FALSE(new_set->HasEffectiveAccessToAllHosts()); |
| 462 EXPECT_EQ(expected_apis, new_set->apis()); | 471 EXPECT_EQ(expected_apis, new_set->apis()); |
| 463 EXPECT_EQ(expected_explicit_hosts, new_set->explicit_hosts()); | 472 EXPECT_EQ(expected_explicit_hosts, new_set->explicit_hosts()); |
| 464 EXPECT_EQ(expected_scriptable_hosts, new_set->scriptable_hosts()); | 473 EXPECT_EQ(expected_scriptable_hosts, new_set->scriptable_hosts()); |
| 465 EXPECT_EQ(effective_hosts, new_set->effective_hosts()); | 474 EXPECT_EQ(effective_hosts, new_set->effective_hosts()); |
| 466 } | 475 } |
| 467 | 476 |
| 468 TEST(PermissionsTest, CreateDifference) { | 477 TEST(PermissionsTest, CreateDifference) { |
| 469 APIPermission* permission = NULL; | 478 APIPermission* permission = NULL; |
| 470 | 479 |
| 480 ManifestPermissionSet manifest_permissions; |
| 471 APIPermissionSet apis1; | 481 APIPermissionSet apis1; |
| 472 APIPermissionSet apis2; | 482 APIPermissionSet apis2; |
| 473 APIPermissionSet expected_apis; | 483 APIPermissionSet expected_apis; |
| 474 | 484 |
| 475 URLPatternSet explicit_hosts1; | 485 URLPatternSet explicit_hosts1; |
| 476 URLPatternSet explicit_hosts2; | 486 URLPatternSet explicit_hosts2; |
| 477 URLPatternSet expected_explicit_hosts; | 487 URLPatternSet expected_explicit_hosts; |
| 478 | 488 |
| 479 URLPatternSet scriptable_hosts1; | 489 URLPatternSet scriptable_hosts1; |
| 480 URLPatternSet scriptable_hosts2; | 490 URLPatternSet scriptable_hosts2; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 501 value->Append(base::Value::CreateStringValue("udp-send-to::8888")); | 511 value->Append(base::Value::CreateStringValue("udp-send-to::8888")); |
| 502 if (!permission->FromValue(value.get())) { | 512 if (!permission->FromValue(value.get())) { |
| 503 NOTREACHED(); | 513 NOTREACHED(); |
| 504 } | 514 } |
| 505 } | 515 } |
| 506 apis1.insert(permission); | 516 apis1.insert(permission); |
| 507 | 517 |
| 508 AddPattern(&explicit_hosts1, "http://*.google.com/*"); | 518 AddPattern(&explicit_hosts1, "http://*.google.com/*"); |
| 509 AddPattern(&scriptable_hosts1, "http://www.reddit.com/*"); | 519 AddPattern(&scriptable_hosts1, "http://www.reddit.com/*"); |
| 510 | 520 |
| 511 set1 = new PermissionSet(apis1, explicit_hosts1, scriptable_hosts1); | 521 set1 = new PermissionSet(apis1, manifest_permissions, |
| 512 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2); | 522 explicit_hosts1, scriptable_hosts1); |
| 523 set2 = new PermissionSet(apis2, manifest_permissions, |
| 524 explicit_hosts2, scriptable_hosts2); |
| 513 new_set = PermissionSet::CreateDifference(set1.get(), set2.get()); | 525 new_set = PermissionSet::CreateDifference(set1.get(), set2.get()); |
| 514 EXPECT_EQ(*set1.get(), *new_set.get()); | 526 EXPECT_EQ(*set1.get(), *new_set.get()); |
| 515 | 527 |
| 516 // Now use a real second set. | 528 // Now use a real second set. |
| 517 apis2.insert(APIPermission::kTab); | 529 apis2.insert(APIPermission::kTab); |
| 518 apis2.insert(APIPermission::kProxy); | 530 apis2.insert(APIPermission::kProxy); |
| 519 apis2.insert(APIPermission::kClipboardWrite); | 531 apis2.insert(APIPermission::kClipboardWrite); |
| 520 apis2.insert(APIPermission::kPlugin); | 532 apis2.insert(APIPermission::kPlugin); |
| 521 permission = permission_info->CreateAPIPermission(); | 533 permission = permission_info->CreateAPIPermission(); |
| 522 { | 534 { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 543 expected_apis.insert(permission); | 555 expected_apis.insert(permission); |
| 544 | 556 |
| 545 AddPattern(&explicit_hosts2, "http://*.example.com/*"); | 557 AddPattern(&explicit_hosts2, "http://*.example.com/*"); |
| 546 AddPattern(&explicit_hosts2, "http://*.google.com/*"); | 558 AddPattern(&explicit_hosts2, "http://*.google.com/*"); |
| 547 AddPattern(&scriptable_hosts2, "http://*.google.com/*"); | 559 AddPattern(&scriptable_hosts2, "http://*.google.com/*"); |
| 548 AddPattern(&expected_scriptable_hosts, "http://www.reddit.com/*"); | 560 AddPattern(&expected_scriptable_hosts, "http://www.reddit.com/*"); |
| 549 | 561 |
| 550 effective_hosts.ClearPatterns(); | 562 effective_hosts.ClearPatterns(); |
| 551 AddPattern(&effective_hosts, "http://www.reddit.com/*"); | 563 AddPattern(&effective_hosts, "http://www.reddit.com/*"); |
| 552 | 564 |
| 553 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2); | 565 set2 = new PermissionSet(apis2, manifest_permissions, |
| 566 explicit_hosts2, scriptable_hosts2); |
| 554 new_set = PermissionSet::CreateDifference(set1.get(), set2.get()); | 567 new_set = PermissionSet::CreateDifference(set1.get(), set2.get()); |
| 555 | 568 |
| 556 EXPECT_TRUE(set1->Contains(*new_set.get())); | 569 EXPECT_TRUE(set1->Contains(*new_set.get())); |
| 557 EXPECT_FALSE(set2->Contains(*new_set.get())); | 570 EXPECT_FALSE(set2->Contains(*new_set.get())); |
| 558 | 571 |
| 559 EXPECT_FALSE(new_set->HasEffectiveFullAccess()); | 572 EXPECT_FALSE(new_set->HasEffectiveFullAccess()); |
| 560 EXPECT_FALSE(new_set->HasEffectiveAccessToAllHosts()); | 573 EXPECT_FALSE(new_set->HasEffectiveAccessToAllHosts()); |
| 561 EXPECT_EQ(expected_apis, new_set->apis()); | 574 EXPECT_EQ(expected_apis, new_set->apis()); |
| 562 EXPECT_EQ(expected_explicit_hosts, new_set->explicit_hosts()); | 575 EXPECT_EQ(expected_explicit_hosts, new_set->explicit_hosts()); |
| 563 EXPECT_EQ(expected_scriptable_hosts, new_set->scriptable_hosts()); | 576 EXPECT_EQ(expected_scriptable_hosts, new_set->scriptable_hosts()); |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 766 << "missing message_id for " << permission_info->name(); | 779 << "missing message_id for " << permission_info->name(); |
| 767 } | 780 } |
| 768 } | 781 } |
| 769 } | 782 } |
| 770 | 783 |
| 771 TEST(PermissionsTest, FileSystemPermissionMessages) { | 784 TEST(PermissionsTest, FileSystemPermissionMessages) { |
| 772 APIPermissionSet api_permissions; | 785 APIPermissionSet api_permissions; |
| 773 api_permissions.insert(APIPermission::kFileSystemWrite); | 786 api_permissions.insert(APIPermission::kFileSystemWrite); |
| 774 api_permissions.insert(APIPermission::kFileSystemDirectory); | 787 api_permissions.insert(APIPermission::kFileSystemDirectory); |
| 775 scoped_refptr<PermissionSet> permissions( | 788 scoped_refptr<PermissionSet> permissions( |
| 776 new PermissionSet(api_permissions, URLPatternSet(), URLPatternSet())); | 789 new PermissionSet(api_permissions, ManifestPermissionSet(), |
| 790 URLPatternSet(), URLPatternSet())); |
| 777 PermissionMessages messages = | 791 PermissionMessages messages = |
| 778 PermissionMessageProvider::Get()->GetPermissionMessages( | 792 PermissionMessageProvider::Get()->GetPermissionMessages( |
| 779 permissions, Manifest::TYPE_PLATFORM_APP); | 793 permissions, Manifest::TYPE_PLATFORM_APP); |
| 780 ASSERT_EQ(2u, messages.size()); | 794 ASSERT_EQ(2u, messages.size()); |
| 781 std::sort(messages.begin(), messages.end()); | 795 std::sort(messages.begin(), messages.end()); |
| 782 std::set<PermissionMessage::ID> ids; | 796 std::set<PermissionMessage::ID> ids; |
| 783 for (PermissionMessages::const_iterator it = messages.begin(); | 797 for (PermissionMessages::const_iterator it = messages.begin(); |
| 784 it != messages.end(); ++it) { | 798 it != messages.end(); ++it) { |
| 785 ids.insert(it->id()); | 799 ids.insert(it->id()); |
| 786 } | 800 } |
| 787 EXPECT_TRUE(ContainsKey(ids, PermissionMessage::kFileSystemDirectory)); | 801 EXPECT_TRUE(ContainsKey(ids, PermissionMessage::kFileSystemDirectory)); |
| 788 EXPECT_TRUE(ContainsKey(ids, PermissionMessage::kFileSystemWrite)); | 802 EXPECT_TRUE(ContainsKey(ids, PermissionMessage::kFileSystemWrite)); |
| 789 } | 803 } |
| 790 | 804 |
| 791 TEST(PermissionsTest, HiddenFileSystemPermissionMessages) { | 805 TEST(PermissionsTest, HiddenFileSystemPermissionMessages) { |
| 792 APIPermissionSet api_permissions; | 806 APIPermissionSet api_permissions; |
| 793 api_permissions.insert(APIPermission::kFileSystemWrite); | 807 api_permissions.insert(APIPermission::kFileSystemWrite); |
| 794 api_permissions.insert(APIPermission::kFileSystemDirectory); | 808 api_permissions.insert(APIPermission::kFileSystemDirectory); |
| 795 api_permissions.insert(APIPermission::kFileSystemWriteDirectory); | 809 api_permissions.insert(APIPermission::kFileSystemWriteDirectory); |
| 796 scoped_refptr<PermissionSet> permissions( | 810 scoped_refptr<PermissionSet> permissions( |
| 797 new PermissionSet(api_permissions, URLPatternSet(), URLPatternSet())); | 811 new PermissionSet(api_permissions, ManifestPermissionSet(), |
| 812 URLPatternSet(), URLPatternSet())); |
| 798 PermissionMessages messages = | 813 PermissionMessages messages = |
| 799 PermissionMessageProvider::Get()->GetPermissionMessages( | 814 PermissionMessageProvider::Get()->GetPermissionMessages( |
| 800 permissions, Manifest::TYPE_PLATFORM_APP); | 815 permissions, Manifest::TYPE_PLATFORM_APP); |
| 801 ASSERT_EQ(1u, messages.size()); | 816 ASSERT_EQ(1u, messages.size()); |
| 802 EXPECT_EQ(PermissionMessage::kFileSystemWriteDirectory, messages[0].id()); | 817 EXPECT_EQ(PermissionMessage::kFileSystemWriteDirectory, messages[0].id()); |
| 803 } | 818 } |
| 804 | 819 |
| 805 TEST(PermissionsTest, MergedFileSystemPermissionComparison) { | 820 TEST(PermissionsTest, MergedFileSystemPermissionComparison) { |
| 806 APIPermissionSet write_api_permissions; | 821 APIPermissionSet write_api_permissions; |
| 807 write_api_permissions.insert(APIPermission::kFileSystemWrite); | 822 write_api_permissions.insert(APIPermission::kFileSystemWrite); |
| 808 scoped_refptr<PermissionSet> write_permissions(new PermissionSet( | 823 scoped_refptr<PermissionSet> write_permissions( |
| 809 write_api_permissions, URLPatternSet(), URLPatternSet())); | 824 new PermissionSet(write_api_permissions, ManifestPermissionSet(), |
| 825 URLPatternSet(), URLPatternSet())); |
| 810 | 826 |
| 811 APIPermissionSet directory_api_permissions; | 827 APIPermissionSet directory_api_permissions; |
| 812 directory_api_permissions.insert(APIPermission::kFileSystemDirectory); | 828 directory_api_permissions.insert(APIPermission::kFileSystemDirectory); |
| 813 scoped_refptr<PermissionSet> directory_permissions(new PermissionSet( | 829 scoped_refptr<PermissionSet> directory_permissions( |
| 814 directory_api_permissions, URLPatternSet(), URLPatternSet())); | 830 new PermissionSet(directory_api_permissions, ManifestPermissionSet(), |
| 831 URLPatternSet(), URLPatternSet())); |
| 815 | 832 |
| 816 APIPermissionSet write_directory_api_permissions; | 833 APIPermissionSet write_directory_api_permissions; |
| 817 write_directory_api_permissions.insert( | 834 write_directory_api_permissions.insert( |
| 818 APIPermission::kFileSystemWriteDirectory); | 835 APIPermission::kFileSystemWriteDirectory); |
| 819 scoped_refptr<PermissionSet> write_directory_permissions(new PermissionSet( | 836 scoped_refptr<PermissionSet> write_directory_permissions( |
| 820 write_directory_api_permissions, URLPatternSet(), URLPatternSet())); | 837 new PermissionSet(write_directory_api_permissions, |
| 838 ManifestPermissionSet(), |
| 839 URLPatternSet(), |
| 840 URLPatternSet())); |
| 821 | 841 |
| 822 const PermissionMessageProvider* provider = PermissionMessageProvider::Get(); | 842 const PermissionMessageProvider* provider = PermissionMessageProvider::Get(); |
| 823 EXPECT_FALSE(provider->IsPrivilegeIncrease(write_directory_permissions, | 843 EXPECT_FALSE(provider->IsPrivilegeIncrease(write_directory_permissions, |
| 824 write_permissions, | 844 write_permissions, |
| 825 Manifest::TYPE_PLATFORM_APP)); | 845 Manifest::TYPE_PLATFORM_APP)); |
| 826 EXPECT_FALSE(provider->IsPrivilegeIncrease(write_directory_permissions, | 846 EXPECT_FALSE(provider->IsPrivilegeIncrease(write_directory_permissions, |
| 827 directory_permissions, | 847 directory_permissions, |
| 828 Manifest::TYPE_PLATFORM_APP)); | 848 Manifest::TYPE_PLATFORM_APP)); |
| 829 EXPECT_TRUE(provider->IsPrivilegeIncrease(write_permissions, | 849 EXPECT_TRUE(provider->IsPrivilegeIncrease(write_permissions, |
| 830 directory_permissions, | 850 directory_permissions, |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1154 | 1174 |
| 1155 explicit_hosts.AddPattern( | 1175 explicit_hosts.AddPattern( |
| 1156 URLPattern(URLPattern::SCHEME_HTTP, "http://*.google.com/*")); | 1176 URLPattern(URLPattern::SCHEME_HTTP, "http://*.google.com/*")); |
| 1157 scriptable_hosts.AddPattern( | 1177 scriptable_hosts.AddPattern( |
| 1158 URLPattern(URLPattern::SCHEME_HTTP, "http://*.example.com/*")); | 1178 URLPattern(URLPattern::SCHEME_HTTP, "http://*.example.com/*")); |
| 1159 | 1179 |
| 1160 expected.insert("*.google.com"); | 1180 expected.insert("*.google.com"); |
| 1161 expected.insert("*.example.com"); | 1181 expected.insert("*.example.com"); |
| 1162 | 1182 |
| 1163 scoped_refptr<PermissionSet> perm_set(new PermissionSet( | 1183 scoped_refptr<PermissionSet> perm_set(new PermissionSet( |
| 1164 empty_perms, explicit_hosts, scriptable_hosts)); | 1184 empty_perms, ManifestPermissionSet(), |
| 1185 explicit_hosts, scriptable_hosts)); |
| 1165 EXPECT_EQ(expected, | 1186 EXPECT_EQ(expected, |
| 1166 permission_message_util::GetDistinctHosts( | 1187 permission_message_util::GetDistinctHosts( |
| 1167 perm_set->effective_hosts(), true, true)); | 1188 perm_set->effective_hosts(), true, true)); |
| 1168 } | 1189 } |
| 1169 | 1190 |
| 1170 { | 1191 { |
| 1171 // We don't display warnings for file URLs because they are off by default. | 1192 // We don't display warnings for file URLs because they are off by default. |
| 1172 SCOPED_TRACE("file urls"); | 1193 SCOPED_TRACE("file urls"); |
| 1173 | 1194 |
| 1174 explicit_hosts.ClearPatterns(); | 1195 explicit_hosts.ClearPatterns(); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1261 std::set<std::string> expected; | 1282 std::set<std::string> expected; |
| 1262 expected.insert("www.foo.ca"); | 1283 expected.insert("www.foo.ca"); |
| 1263 EXPECT_EQ(expected, | 1284 EXPECT_EQ(expected, |
| 1264 permission_message_util::GetDistinctHosts( | 1285 permission_message_util::GetDistinctHosts( |
| 1265 explicit_hosts, true, true)); | 1286 explicit_hosts, true, true)); |
| 1266 } | 1287 } |
| 1267 | 1288 |
| 1268 TEST(PermissionsTest, IsHostPrivilegeIncrease) { | 1289 TEST(PermissionsTest, IsHostPrivilegeIncrease) { |
| 1269 Manifest::Type type = Manifest::TYPE_EXTENSION; | 1290 Manifest::Type type = Manifest::TYPE_EXTENSION; |
| 1270 const PermissionMessageProvider* provider = PermissionMessageProvider::Get(); | 1291 const PermissionMessageProvider* provider = PermissionMessageProvider::Get(); |
| 1292 ManifestPermissionSet empty_manifest_permissions; |
| 1271 URLPatternSet elist1; | 1293 URLPatternSet elist1; |
| 1272 URLPatternSet elist2; | 1294 URLPatternSet elist2; |
| 1273 URLPatternSet slist1; | 1295 URLPatternSet slist1; |
| 1274 URLPatternSet slist2; | 1296 URLPatternSet slist2; |
| 1275 scoped_refptr<PermissionSet> set1; | 1297 scoped_refptr<PermissionSet> set1; |
| 1276 scoped_refptr<PermissionSet> set2; | 1298 scoped_refptr<PermissionSet> set2; |
| 1277 APIPermissionSet empty_perms; | 1299 APIPermissionSet empty_perms; |
| 1278 elist1.AddPattern( | 1300 elist1.AddPattern( |
| 1279 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com.hk/path")); | 1301 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com.hk/path")); |
| 1280 elist1.AddPattern( | 1302 elist1.AddPattern( |
| 1281 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com/path")); | 1303 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com/path")); |
| 1282 | 1304 |
| 1283 // Test that the host order does not matter. | 1305 // Test that the host order does not matter. |
| 1284 elist2.AddPattern( | 1306 elist2.AddPattern( |
| 1285 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com/path")); | 1307 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com/path")); |
| 1286 elist2.AddPattern( | 1308 elist2.AddPattern( |
| 1287 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com.hk/path")); | 1309 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com.hk/path")); |
| 1288 | 1310 |
| 1289 set1 = new PermissionSet(empty_perms, elist1, slist1); | 1311 set1 = new PermissionSet(empty_perms, empty_manifest_permissions, |
| 1290 set2 = new PermissionSet(empty_perms, elist2, slist2); | 1312 elist1, slist1); |
| 1313 set2 = new PermissionSet(empty_perms, empty_manifest_permissions, |
| 1314 elist2, slist2); |
| 1291 | 1315 |
| 1292 EXPECT_FALSE(provider->IsPrivilegeIncrease(set1, set2, type)); | 1316 EXPECT_FALSE(provider->IsPrivilegeIncrease(set1, set2, type)); |
| 1293 EXPECT_FALSE(provider->IsPrivilegeIncrease(set2, set1, type)); | 1317 EXPECT_FALSE(provider->IsPrivilegeIncrease(set2, set1, type)); |
| 1294 | 1318 |
| 1295 // Test that paths are ignored. | 1319 // Test that paths are ignored. |
| 1296 elist2.ClearPatterns(); | 1320 elist2.ClearPatterns(); |
| 1297 elist2.AddPattern( | 1321 elist2.AddPattern( |
| 1298 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com/*")); | 1322 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com/*")); |
| 1299 set2 = new PermissionSet(empty_perms, elist2, slist2); | 1323 set2 = new PermissionSet(empty_perms, empty_manifest_permissions, |
| 1324 elist2, slist2); |
| 1300 EXPECT_FALSE(provider->IsPrivilegeIncrease(set1, set2, type)); | 1325 EXPECT_FALSE(provider->IsPrivilegeIncrease(set1, set2, type)); |
| 1301 EXPECT_FALSE(provider->IsPrivilegeIncrease(set2, set1, type)); | 1326 EXPECT_FALSE(provider->IsPrivilegeIncrease(set2, set1, type)); |
| 1302 | 1327 |
| 1303 // Test that RCDs are ignored. | 1328 // Test that RCDs are ignored. |
| 1304 elist2.ClearPatterns(); | 1329 elist2.ClearPatterns(); |
| 1305 elist2.AddPattern( | 1330 elist2.AddPattern( |
| 1306 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com.hk/*")); | 1331 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com.hk/*")); |
| 1307 set2 = new PermissionSet(empty_perms, elist2, slist2); | 1332 set2 = new PermissionSet(empty_perms, empty_manifest_permissions, |
| 1333 elist2, slist2); |
| 1308 EXPECT_FALSE(provider->IsPrivilegeIncrease(set1, set2, type)); | 1334 EXPECT_FALSE(provider->IsPrivilegeIncrease(set1, set2, type)); |
| 1309 EXPECT_FALSE(provider->IsPrivilegeIncrease(set2, set1, type)); | 1335 EXPECT_FALSE(provider->IsPrivilegeIncrease(set2, set1, type)); |
| 1310 | 1336 |
| 1311 // Test that subdomain wildcards are handled properly. | 1337 // Test that subdomain wildcards are handled properly. |
| 1312 elist2.ClearPatterns(); | 1338 elist2.ClearPatterns(); |
| 1313 elist2.AddPattern( | 1339 elist2.AddPattern( |
| 1314 URLPattern(URLPattern::SCHEME_HTTP, "http://*.google.com.hk/*")); | 1340 URLPattern(URLPattern::SCHEME_HTTP, "http://*.google.com.hk/*")); |
| 1315 set2 = new PermissionSet(empty_perms, elist2, slist2); | 1341 set2 = new PermissionSet(empty_perms, empty_manifest_permissions, |
| 1342 elist2, slist2); |
| 1316 EXPECT_TRUE(provider->IsPrivilegeIncrease(set1, set2, type)); | 1343 EXPECT_TRUE(provider->IsPrivilegeIncrease(set1, set2, type)); |
| 1317 // TODO(jstritar): Does not match subdomains properly. http://crbug.com/65337 | 1344 // TODO(jstritar): Does not match subdomains properly. http://crbug.com/65337 |
| 1318 // EXPECT_FALSE(provider->IsPrivilegeIncrease(set2, set1, type)); | 1345 // EXPECT_FALSE(provider->IsPrivilegeIncrease(set2, set1, type)); |
| 1319 | 1346 |
| 1320 // Test that different domains count as different hosts. | 1347 // Test that different domains count as different hosts. |
| 1321 elist2.ClearPatterns(); | 1348 elist2.ClearPatterns(); |
| 1322 elist2.AddPattern( | 1349 elist2.AddPattern( |
| 1323 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com/path")); | 1350 URLPattern(URLPattern::SCHEME_HTTP, "http://www.google.com/path")); |
| 1324 elist2.AddPattern( | 1351 elist2.AddPattern( |
| 1325 URLPattern(URLPattern::SCHEME_HTTP, "http://www.example.org/path")); | 1352 URLPattern(URLPattern::SCHEME_HTTP, "http://www.example.org/path")); |
| 1326 set2 = new PermissionSet(empty_perms, elist2, slist2); | 1353 set2 = new PermissionSet(empty_perms, empty_manifest_permissions, |
| 1354 elist2, slist2); |
| 1327 EXPECT_TRUE(provider->IsPrivilegeIncrease(set1, set2, type)); | 1355 EXPECT_TRUE(provider->IsPrivilegeIncrease(set1, set2, type)); |
| 1328 EXPECT_FALSE(provider->IsPrivilegeIncrease(set2, set1, type)); | 1356 EXPECT_FALSE(provider->IsPrivilegeIncrease(set2, set1, type)); |
| 1329 | 1357 |
| 1330 // Test that different subdomains count as different hosts. | 1358 // Test that different subdomains count as different hosts. |
| 1331 elist2.ClearPatterns(); | 1359 elist2.ClearPatterns(); |
| 1332 elist2.AddPattern( | 1360 elist2.AddPattern( |
| 1333 URLPattern(URLPattern::SCHEME_HTTP, "http://mail.google.com/*")); | 1361 URLPattern(URLPattern::SCHEME_HTTP, "http://mail.google.com/*")); |
| 1334 set2 = new PermissionSet(empty_perms, elist2, slist2); | 1362 set2 = new PermissionSet(empty_perms, empty_manifest_permissions, |
| 1363 elist2, slist2); |
| 1335 EXPECT_TRUE(provider->IsPrivilegeIncrease(set1, set2, type)); | 1364 EXPECT_TRUE(provider->IsPrivilegeIncrease(set1, set2, type)); |
| 1336 EXPECT_TRUE(provider->IsPrivilegeIncrease(set2, set1, type)); | 1365 EXPECT_TRUE(provider->IsPrivilegeIncrease(set2, set1, type)); |
| 1337 | 1366 |
| 1338 // Test that platform apps do not have host permissions increases. | 1367 // Test that platform apps do not have host permissions increases. |
| 1339 type = Manifest::TYPE_PLATFORM_APP; | 1368 type = Manifest::TYPE_PLATFORM_APP; |
| 1340 EXPECT_FALSE(provider->IsPrivilegeIncrease(set1, set2, type)); | 1369 EXPECT_FALSE(provider->IsPrivilegeIncrease(set1, set2, type)); |
| 1341 EXPECT_FALSE(provider->IsPrivilegeIncrease(set2, set1, type)); | 1370 EXPECT_FALSE(provider->IsPrivilegeIncrease(set2, set1, type)); |
| 1342 } | 1371 } |
| 1343 | 1372 |
| 1344 TEST(PermissionsTest, GetAPIsAsStrings) { | 1373 TEST(PermissionsTest, GetAPIsAsStrings) { |
| 1345 APIPermissionSet apis; | 1374 APIPermissionSet apis; |
| 1346 URLPatternSet empty_set; | 1375 URLPatternSet empty_set; |
| 1347 | 1376 |
| 1348 apis.insert(APIPermission::kProxy); | 1377 apis.insert(APIPermission::kProxy); |
| 1349 apis.insert(APIPermission::kBackground); | 1378 apis.insert(APIPermission::kBackground); |
| 1350 apis.insert(APIPermission::kNotification); | 1379 apis.insert(APIPermission::kNotification); |
| 1351 apis.insert(APIPermission::kTab); | 1380 apis.insert(APIPermission::kTab); |
| 1352 | 1381 |
| 1353 scoped_refptr<PermissionSet> perm_set = new PermissionSet( | 1382 scoped_refptr<PermissionSet> perm_set = new PermissionSet( |
| 1354 apis, empty_set, empty_set); | 1383 apis, ManifestPermissionSet(), empty_set, empty_set); |
| 1355 std::set<std::string> api_names = perm_set->GetAPIsAsStrings(); | 1384 std::set<std::string> api_names = perm_set->GetAPIsAsStrings(); |
| 1356 | 1385 |
| 1357 // The result is correct if it has the same number of elements | 1386 // The result is correct if it has the same number of elements |
| 1358 // and we can convert it back to the id set. | 1387 // and we can convert it back to the id set. |
| 1359 EXPECT_EQ(4u, api_names.size()); | 1388 EXPECT_EQ(4u, api_names.size()); |
| 1360 EXPECT_EQ(apis, | 1389 EXPECT_EQ(apis, |
| 1361 PermissionsInfo::GetInstance()->GetAllByName(api_names)); | 1390 PermissionsInfo::GetInstance()->GetAllByName(api_names)); |
| 1362 } | 1391 } |
| 1363 | 1392 |
| 1364 TEST(PermissionsTest, IsEmpty) { | 1393 TEST(PermissionsTest, IsEmpty) { |
| 1365 APIPermissionSet empty_apis; | 1394 APIPermissionSet empty_apis; |
| 1366 URLPatternSet empty_extent; | 1395 URLPatternSet empty_extent; |
| 1367 | 1396 |
| 1368 scoped_refptr<PermissionSet> empty = new PermissionSet(); | 1397 scoped_refptr<PermissionSet> empty = new PermissionSet(); |
| 1369 EXPECT_TRUE(empty->IsEmpty()); | 1398 EXPECT_TRUE(empty->IsEmpty()); |
| 1370 scoped_refptr<PermissionSet> perm_set; | 1399 scoped_refptr<PermissionSet> perm_set; |
| 1371 | 1400 |
| 1372 perm_set = new PermissionSet(empty_apis, empty_extent, empty_extent); | 1401 perm_set = new PermissionSet(empty_apis, ManifestPermissionSet(), |
| 1402 empty_extent, empty_extent); |
| 1373 EXPECT_TRUE(perm_set->IsEmpty()); | 1403 EXPECT_TRUE(perm_set->IsEmpty()); |
| 1374 | 1404 |
| 1375 APIPermissionSet non_empty_apis; | 1405 APIPermissionSet non_empty_apis; |
| 1376 non_empty_apis.insert(APIPermission::kBackground); | 1406 non_empty_apis.insert(APIPermission::kBackground); |
| 1377 perm_set = new PermissionSet( | 1407 perm_set = new PermissionSet(non_empty_apis, ManifestPermissionSet(), |
| 1378 non_empty_apis, empty_extent, empty_extent); | 1408 empty_extent, empty_extent); |
| 1379 EXPECT_FALSE(perm_set->IsEmpty()); | 1409 EXPECT_FALSE(perm_set->IsEmpty()); |
| 1380 | 1410 |
| 1381 // Try non standard host | 1411 // Try non standard host |
| 1382 URLPatternSet non_empty_extent; | 1412 URLPatternSet non_empty_extent; |
| 1383 AddPattern(&non_empty_extent, "http://www.google.com/*"); | 1413 AddPattern(&non_empty_extent, "http://www.google.com/*"); |
| 1384 | 1414 |
| 1385 perm_set = new PermissionSet( | 1415 perm_set = new PermissionSet(empty_apis, ManifestPermissionSet(), |
| 1386 empty_apis, non_empty_extent, empty_extent); | 1416 non_empty_extent, empty_extent); |
| 1387 EXPECT_FALSE(perm_set->IsEmpty()); | 1417 EXPECT_FALSE(perm_set->IsEmpty()); |
| 1388 | 1418 |
| 1389 perm_set = new PermissionSet( | 1419 perm_set = new PermissionSet(empty_apis, ManifestPermissionSet(), |
| 1390 empty_apis, empty_extent, non_empty_extent); | 1420 empty_extent, non_empty_extent); |
| 1391 EXPECT_FALSE(perm_set->IsEmpty()); | 1421 EXPECT_FALSE(perm_set->IsEmpty()); |
| 1392 } | 1422 } |
| 1393 | 1423 |
| 1394 TEST(PermissionsTest, ImpliedPermissions) { | 1424 TEST(PermissionsTest, ImpliedPermissions) { |
| 1395 URLPatternSet empty_extent; | 1425 URLPatternSet empty_extent; |
| 1396 APIPermissionSet apis; | 1426 APIPermissionSet apis; |
| 1397 apis.insert(APIPermission::kWebRequest); | 1427 apis.insert(APIPermission::kWebRequest); |
| 1398 apis.insert(APIPermission::kFileBrowserHandler); | 1428 apis.insert(APIPermission::kFileBrowserHandler); |
| 1399 EXPECT_EQ(2U, apis.size()); | 1429 EXPECT_EQ(2U, apis.size()); |
| 1400 | 1430 |
| 1401 scoped_refptr<PermissionSet> perm_set; | 1431 scoped_refptr<PermissionSet> perm_set; |
| 1402 perm_set = new PermissionSet(apis, empty_extent, empty_extent); | 1432 perm_set = new PermissionSet(apis, ManifestPermissionSet(), |
| 1433 empty_extent, empty_extent); |
| 1403 EXPECT_EQ(4U, perm_set->apis().size()); | 1434 EXPECT_EQ(4U, perm_set->apis().size()); |
| 1404 } | 1435 } |
| 1405 | 1436 |
| 1406 TEST(PermissionsTest, SyncFileSystemPermission) { | 1437 TEST(PermissionsTest, SyncFileSystemPermission) { |
| 1407 scoped_refptr<Extension> extension = LoadManifest( | 1438 scoped_refptr<Extension> extension = LoadManifest( |
| 1408 "permissions", "sync_file_system.json"); | 1439 "permissions", "sync_file_system.json"); |
| 1409 APIPermissionSet apis; | 1440 APIPermissionSet apis; |
| 1410 apis.insert(APIPermission::kSyncFileSystem); | 1441 apis.insert(APIPermission::kSyncFileSystem); |
| 1411 EXPECT_TRUE(extension->is_platform_app()); | 1442 EXPECT_TRUE(extension->is_platform_app()); |
| 1412 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSyncFileSystem)); | 1443 EXPECT_TRUE(extension->HasAPIPermission(APIPermission::kSyncFileSystem)); |
| 1413 std::vector<string16> warnings = | 1444 std::vector<string16> warnings = |
| 1414 PermissionsData::GetPermissionMessageStrings(extension.get()); | 1445 PermissionsData::GetPermissionMessageStrings(extension.get()); |
| 1415 EXPECT_TRUE(Contains(warnings, "Store data in your Google Drive account")); | 1446 EXPECT_TRUE(Contains(warnings, "Store data in your Google Drive account")); |
| 1416 ASSERT_EQ(1u, warnings.size()); | 1447 ASSERT_EQ(1u, warnings.size()); |
| 1417 } | 1448 } |
| 1418 | 1449 |
| 1419 // Make sure that we don't crash when we're trying to show the permissions | 1450 // Make sure that we don't crash when we're trying to show the permissions |
| 1420 // even though chrome://thumb (and everything that's not chrome://favicon with | 1451 // even though chrome://thumb (and everything that's not chrome://favicon with |
| 1421 // a chrome:// scheme) is not a valid permission. | 1452 // a chrome:// scheme) is not a valid permission. |
| 1422 // More details here: crbug/246314. | 1453 // More details here: crbug/246314. |
| 1423 TEST(PermissionsTest, ChromeURLs) { | 1454 TEST(PermissionsTest, ChromeURLs) { |
| 1424 URLPatternSet allowed_hosts; | 1455 URLPatternSet allowed_hosts; |
| 1425 allowed_hosts.AddPattern( | 1456 allowed_hosts.AddPattern( |
| 1426 URLPattern(URLPattern::SCHEME_ALL, "http://www.google.com/")); | 1457 URLPattern(URLPattern::SCHEME_ALL, "http://www.google.com/")); |
| 1427 allowed_hosts.AddPattern( | 1458 allowed_hosts.AddPattern( |
| 1428 URLPattern(URLPattern::SCHEME_ALL, "chrome://favicon/")); | 1459 URLPattern(URLPattern::SCHEME_ALL, "chrome://favicon/")); |
| 1429 allowed_hosts.AddPattern( | 1460 allowed_hosts.AddPattern( |
| 1430 URLPattern(URLPattern::SCHEME_ALL, "chrome://thumb/")); | 1461 URLPattern(URLPattern::SCHEME_ALL, "chrome://thumb/")); |
| 1431 scoped_refptr<PermissionSet> permissions( | 1462 scoped_refptr<PermissionSet> permissions( |
| 1432 new PermissionSet(APIPermissionSet(), allowed_hosts, URLPatternSet())); | 1463 new PermissionSet(APIPermissionSet(), ManifestPermissionSet(), |
| 1464 allowed_hosts, URLPatternSet())); |
| 1433 PermissionMessageProvider::Get()-> | 1465 PermissionMessageProvider::Get()-> |
| 1434 GetPermissionMessages(permissions, Manifest::TYPE_EXTENSION); | 1466 GetPermissionMessages(permissions, Manifest::TYPE_EXTENSION); |
| 1435 } | 1467 } |
| 1436 | 1468 |
| 1437 TEST(PermissionsTest, IsPrivilegeIncrease_DeclarativeWebRequest) { | 1469 TEST(PermissionsTest, IsPrivilegeIncrease_DeclarativeWebRequest) { |
| 1438 scoped_refptr<Extension> extension( | 1470 scoped_refptr<Extension> extension( |
| 1439 LoadManifest("permissions", "permissions_all_urls.json")); | 1471 LoadManifest("permissions", "permissions_all_urls.json")); |
| 1440 scoped_refptr<const PermissionSet> permissions( | 1472 scoped_refptr<const PermissionSet> permissions( |
| 1441 extension->GetActivePermissions()); | 1473 extension->GetActivePermissions()); |
| 1442 | 1474 |
| 1443 scoped_refptr<Extension> extension_dwr( | 1475 scoped_refptr<Extension> extension_dwr( |
| 1444 LoadManifest("permissions", "web_request_all_host_permissions.json")); | 1476 LoadManifest("permissions", "web_request_all_host_permissions.json")); |
| 1445 scoped_refptr<const PermissionSet> permissions_dwr( | 1477 scoped_refptr<const PermissionSet> permissions_dwr( |
| 1446 extension_dwr->GetActivePermissions()); | 1478 extension_dwr->GetActivePermissions()); |
| 1447 | 1479 |
| 1448 EXPECT_FALSE(PermissionMessageProvider::Get()-> | 1480 EXPECT_FALSE(PermissionMessageProvider::Get()-> |
| 1449 IsPrivilegeIncrease(permissions.get(), | 1481 IsPrivilegeIncrease(permissions.get(), |
| 1450 permissions_dwr.get(), | 1482 permissions_dwr.get(), |
| 1451 extension->GetType())); | 1483 extension->GetType())); |
| 1452 } | 1484 } |
| 1453 | 1485 |
| 1454 } // namespace extensions | 1486 } // namespace extensions |
| OLD | NEW |