| 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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 | 251 |
| 252 scoped_refptr<PermissionSet> set1; | 252 scoped_refptr<PermissionSet> set1; |
| 253 scoped_refptr<PermissionSet> set2; | 253 scoped_refptr<PermissionSet> set2; |
| 254 scoped_refptr<PermissionSet> union_set; | 254 scoped_refptr<PermissionSet> union_set; |
| 255 | 255 |
| 256 const APIPermissionInfo* permission_info = | 256 const APIPermissionInfo* permission_info = |
| 257 PermissionsInfo::GetInstance()->GetByID(APIPermission::kSocket); | 257 PermissionsInfo::GetInstance()->GetByID(APIPermission::kSocket); |
| 258 permission = permission_info->CreateAPIPermission(); | 258 permission = permission_info->CreateAPIPermission(); |
| 259 { | 259 { |
| 260 scoped_ptr<base::ListValue> value(new base::ListValue()); | 260 scoped_ptr<base::ListValue> value(new base::ListValue()); |
| 261 value->Append( | 261 value->Append(new base::StringValue("tcp-connect:*.example.com:80")); |
| 262 base::Value::CreateStringValue("tcp-connect:*.example.com:80")); | 262 value->Append(new base::StringValue("udp-bind::8080")); |
| 263 value->Append(base::Value::CreateStringValue("udp-bind::8080")); | 263 value->Append(new base::StringValue("udp-send-to::8888")); |
| 264 value->Append(base::Value::CreateStringValue("udp-send-to::8888")); | |
| 265 ASSERT_TRUE(permission->FromValue(value.get(), NULL, NULL)); | 264 ASSERT_TRUE(permission->FromValue(value.get(), NULL, NULL)); |
| 266 } | 265 } |
| 267 | 266 |
| 268 // Union with an empty set. | 267 // Union with an empty set. |
| 269 apis1.insert(APIPermission::kTab); | 268 apis1.insert(APIPermission::kTab); |
| 270 apis1.insert(APIPermission::kBackground); | 269 apis1.insert(APIPermission::kBackground); |
| 271 apis1.insert(permission->Clone()); | 270 apis1.insert(permission->Clone()); |
| 272 expected_apis.insert(APIPermission::kTab); | 271 expected_apis.insert(APIPermission::kTab); |
| 273 expected_apis.insert(APIPermission::kBackground); | 272 expected_apis.insert(APIPermission::kBackground); |
| 274 expected_apis.insert(permission); | 273 expected_apis.insert(permission); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 297 | 296 |
| 298 // Now use a real second set. | 297 // Now use a real second set. |
| 299 apis2.insert(APIPermission::kTab); | 298 apis2.insert(APIPermission::kTab); |
| 300 apis2.insert(APIPermission::kProxy); | 299 apis2.insert(APIPermission::kProxy); |
| 301 apis2.insert(APIPermission::kClipboardWrite); | 300 apis2.insert(APIPermission::kClipboardWrite); |
| 302 apis2.insert(APIPermission::kPlugin); | 301 apis2.insert(APIPermission::kPlugin); |
| 303 | 302 |
| 304 permission = permission_info->CreateAPIPermission(); | 303 permission = permission_info->CreateAPIPermission(); |
| 305 { | 304 { |
| 306 scoped_ptr<base::ListValue> value(new base::ListValue()); | 305 scoped_ptr<base::ListValue> value(new base::ListValue()); |
| 307 value->Append( | 306 value->Append(new base::StringValue("tcp-connect:*.example.com:80")); |
| 308 base::Value::CreateStringValue("tcp-connect:*.example.com:80")); | 307 value->Append(new base::StringValue("udp-send-to::8899")); |
| 309 value->Append(base::Value::CreateStringValue("udp-send-to::8899")); | |
| 310 ASSERT_TRUE(permission->FromValue(value.get(), NULL, NULL)); | 308 ASSERT_TRUE(permission->FromValue(value.get(), NULL, NULL)); |
| 311 } | 309 } |
| 312 apis2.insert(permission); | 310 apis2.insert(permission); |
| 313 | 311 |
| 314 expected_apis.insert(APIPermission::kTab); | 312 expected_apis.insert(APIPermission::kTab); |
| 315 expected_apis.insert(APIPermission::kProxy); | 313 expected_apis.insert(APIPermission::kProxy); |
| 316 expected_apis.insert(APIPermission::kClipboardWrite); | 314 expected_apis.insert(APIPermission::kClipboardWrite); |
| 317 expected_apis.insert(APIPermission::kPlugin); | 315 expected_apis.insert(APIPermission::kPlugin); |
| 318 | 316 |
| 319 permission = permission_info->CreateAPIPermission(); | 317 permission = permission_info->CreateAPIPermission(); |
| 320 { | 318 { |
| 321 scoped_ptr<base::ListValue> value(new base::ListValue()); | 319 scoped_ptr<base::ListValue> value(new base::ListValue()); |
| 322 value->Append( | 320 value->Append(new base::StringValue("tcp-connect:*.example.com:80")); |
| 323 base::Value::CreateStringValue("tcp-connect:*.example.com:80")); | 321 value->Append(new base::StringValue("udp-bind::8080")); |
| 324 value->Append(base::Value::CreateStringValue("udp-bind::8080")); | 322 value->Append(new base::StringValue("udp-send-to::8888")); |
| 325 value->Append(base::Value::CreateStringValue("udp-send-to::8888")); | 323 value->Append(new base::StringValue("udp-send-to::8899")); |
| 326 value->Append(base::Value::CreateStringValue("udp-send-to::8899")); | |
| 327 ASSERT_TRUE(permission->FromValue(value.get(), NULL, NULL)); | 324 ASSERT_TRUE(permission->FromValue(value.get(), NULL, NULL)); |
| 328 } | 325 } |
| 329 // Insert a new permission socket permisssion which will replace the old one. | 326 // Insert a new permission socket permisssion which will replace the old one. |
| 330 expected_apis.insert(permission); | 327 expected_apis.insert(permission); |
| 331 | 328 |
| 332 AddPattern(&explicit_hosts2, "http://*.example.com/*"); | 329 AddPattern(&explicit_hosts2, "http://*.example.com/*"); |
| 333 AddPattern(&scriptable_hosts2, "http://*.google.com/*"); | 330 AddPattern(&scriptable_hosts2, "http://*.google.com/*"); |
| 334 AddPattern(&expected_explicit_hosts, "http://*.example.com/*"); | 331 AddPattern(&expected_explicit_hosts, "http://*.example.com/*"); |
| 335 AddPattern(&expected_scriptable_hosts, "http://*.google.com/*"); | 332 AddPattern(&expected_scriptable_hosts, "http://*.google.com/*"); |
| 336 | 333 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 | 377 |
| 381 const APIPermissionInfo* permission_info = | 378 const APIPermissionInfo* permission_info = |
| 382 PermissionsInfo::GetInstance()->GetByID(APIPermission::kSocket); | 379 PermissionsInfo::GetInstance()->GetByID(APIPermission::kSocket); |
| 383 | 380 |
| 384 // Intersection with an empty set. | 381 // Intersection with an empty set. |
| 385 apis1.insert(APIPermission::kTab); | 382 apis1.insert(APIPermission::kTab); |
| 386 apis1.insert(APIPermission::kBackground); | 383 apis1.insert(APIPermission::kBackground); |
| 387 permission = permission_info->CreateAPIPermission(); | 384 permission = permission_info->CreateAPIPermission(); |
| 388 { | 385 { |
| 389 scoped_ptr<base::ListValue> value(new base::ListValue()); | 386 scoped_ptr<base::ListValue> value(new base::ListValue()); |
| 390 value->Append( | 387 value->Append(new base::StringValue("tcp-connect:*.example.com:80")); |
| 391 base::Value::CreateStringValue("tcp-connect:*.example.com:80")); | 388 value->Append(new base::StringValue("udp-bind::8080")); |
| 392 value->Append(base::Value::CreateStringValue("udp-bind::8080")); | 389 value->Append(new base::StringValue("udp-send-to::8888")); |
| 393 value->Append(base::Value::CreateStringValue("udp-send-to::8888")); | |
| 394 ASSERT_TRUE(permission->FromValue(value.get(), NULL, NULL)); | 390 ASSERT_TRUE(permission->FromValue(value.get(), NULL, NULL)); |
| 395 } | 391 } |
| 396 apis1.insert(permission); | 392 apis1.insert(permission); |
| 397 | 393 |
| 398 AddPattern(&explicit_hosts1, "http://*.google.com/*"); | 394 AddPattern(&explicit_hosts1, "http://*.google.com/*"); |
| 399 AddPattern(&scriptable_hosts1, "http://www.reddit.com/*"); | 395 AddPattern(&scriptable_hosts1, "http://www.reddit.com/*"); |
| 400 | 396 |
| 401 set1 = new PermissionSet(apis1, manifest_permissions, | 397 set1 = new PermissionSet(apis1, manifest_permissions, |
| 402 explicit_hosts1, scriptable_hosts1); | 398 explicit_hosts1, scriptable_hosts1); |
| 403 set2 = new PermissionSet(apis2, manifest_permissions, | 399 set2 = new PermissionSet(apis2, manifest_permissions, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 418 EXPECT_EQ(expected_explicit_hosts, new_set->effective_hosts()); | 414 EXPECT_EQ(expected_explicit_hosts, new_set->effective_hosts()); |
| 419 | 415 |
| 420 // Now use a real second set. | 416 // Now use a real second set. |
| 421 apis2.insert(APIPermission::kTab); | 417 apis2.insert(APIPermission::kTab); |
| 422 apis2.insert(APIPermission::kProxy); | 418 apis2.insert(APIPermission::kProxy); |
| 423 apis2.insert(APIPermission::kClipboardWrite); | 419 apis2.insert(APIPermission::kClipboardWrite); |
| 424 apis2.insert(APIPermission::kPlugin); | 420 apis2.insert(APIPermission::kPlugin); |
| 425 permission = permission_info->CreateAPIPermission(); | 421 permission = permission_info->CreateAPIPermission(); |
| 426 { | 422 { |
| 427 scoped_ptr<base::ListValue> value(new base::ListValue()); | 423 scoped_ptr<base::ListValue> value(new base::ListValue()); |
| 428 value->Append(base::Value::CreateStringValue("udp-bind::8080")); | 424 value->Append(new base::StringValue("udp-bind::8080")); |
| 429 value->Append(base::Value::CreateStringValue("udp-send-to::8888")); | 425 value->Append(new base::StringValue("udp-send-to::8888")); |
| 430 value->Append(base::Value::CreateStringValue("udp-send-to::8899")); | 426 value->Append(new base::StringValue("udp-send-to::8899")); |
| 431 ASSERT_TRUE(permission->FromValue(value.get(), NULL, NULL)); | 427 ASSERT_TRUE(permission->FromValue(value.get(), NULL, NULL)); |
| 432 } | 428 } |
| 433 apis2.insert(permission); | 429 apis2.insert(permission); |
| 434 | 430 |
| 435 expected_apis.insert(APIPermission::kTab); | 431 expected_apis.insert(APIPermission::kTab); |
| 436 permission = permission_info->CreateAPIPermission(); | 432 permission = permission_info->CreateAPIPermission(); |
| 437 { | 433 { |
| 438 scoped_ptr<base::ListValue> value(new base::ListValue()); | 434 scoped_ptr<base::ListValue> value(new base::ListValue()); |
| 439 value->Append(base::Value::CreateStringValue("udp-bind::8080")); | 435 value->Append(new base::StringValue("udp-bind::8080")); |
| 440 value->Append(base::Value::CreateStringValue("udp-send-to::8888")); | 436 value->Append(new base::StringValue("udp-send-to::8888")); |
| 441 ASSERT_TRUE(permission->FromValue(value.get(), NULL, NULL)); | 437 ASSERT_TRUE(permission->FromValue(value.get(), NULL, NULL)); |
| 442 } | 438 } |
| 443 expected_apis.insert(permission); | 439 expected_apis.insert(permission); |
| 444 | 440 |
| 445 AddPattern(&explicit_hosts2, "http://*.example.com/*"); | 441 AddPattern(&explicit_hosts2, "http://*.example.com/*"); |
| 446 AddPattern(&explicit_hosts2, "http://*.google.com/*"); | 442 AddPattern(&explicit_hosts2, "http://*.google.com/*"); |
| 447 AddPattern(&scriptable_hosts2, "http://*.google.com/*"); | 443 AddPattern(&scriptable_hosts2, "http://*.google.com/*"); |
| 448 AddPattern(&expected_explicit_hosts, "http://*.google.com/*"); | 444 AddPattern(&expected_explicit_hosts, "http://*.google.com/*"); |
| 449 | 445 |
| 450 effective_hosts.ClearPatterns(); | 446 effective_hosts.ClearPatterns(); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 | 489 |
| 494 const APIPermissionInfo* permission_info = | 490 const APIPermissionInfo* permission_info = |
| 495 PermissionsInfo::GetInstance()->GetByID(APIPermission::kSocket); | 491 PermissionsInfo::GetInstance()->GetByID(APIPermission::kSocket); |
| 496 | 492 |
| 497 // Difference with an empty set. | 493 // Difference with an empty set. |
| 498 apis1.insert(APIPermission::kTab); | 494 apis1.insert(APIPermission::kTab); |
| 499 apis1.insert(APIPermission::kBackground); | 495 apis1.insert(APIPermission::kBackground); |
| 500 permission = permission_info->CreateAPIPermission(); | 496 permission = permission_info->CreateAPIPermission(); |
| 501 { | 497 { |
| 502 scoped_ptr<base::ListValue> value(new base::ListValue()); | 498 scoped_ptr<base::ListValue> value(new base::ListValue()); |
| 503 value->Append( | 499 value->Append(new base::StringValue("tcp-connect:*.example.com:80")); |
| 504 base::Value::CreateStringValue("tcp-connect:*.example.com:80")); | 500 value->Append(new base::StringValue("udp-bind::8080")); |
| 505 value->Append(base::Value::CreateStringValue("udp-bind::8080")); | 501 value->Append(new base::StringValue("udp-send-to::8888")); |
| 506 value->Append(base::Value::CreateStringValue("udp-send-to::8888")); | |
| 507 ASSERT_TRUE(permission->FromValue(value.get(), NULL, NULL)); | 502 ASSERT_TRUE(permission->FromValue(value.get(), NULL, NULL)); |
| 508 } | 503 } |
| 509 apis1.insert(permission); | 504 apis1.insert(permission); |
| 510 | 505 |
| 511 AddPattern(&explicit_hosts1, "http://*.google.com/*"); | 506 AddPattern(&explicit_hosts1, "http://*.google.com/*"); |
| 512 AddPattern(&scriptable_hosts1, "http://www.reddit.com/*"); | 507 AddPattern(&scriptable_hosts1, "http://www.reddit.com/*"); |
| 513 | 508 |
| 514 set1 = new PermissionSet(apis1, manifest_permissions, | 509 set1 = new PermissionSet(apis1, manifest_permissions, |
| 515 explicit_hosts1, scriptable_hosts1); | 510 explicit_hosts1, scriptable_hosts1); |
| 516 set2 = new PermissionSet(apis2, manifest_permissions, | 511 set2 = new PermissionSet(apis2, manifest_permissions, |
| 517 explicit_hosts2, scriptable_hosts2); | 512 explicit_hosts2, scriptable_hosts2); |
| 518 new_set = PermissionSet::CreateDifference(set1.get(), set2.get()); | 513 new_set = PermissionSet::CreateDifference(set1.get(), set2.get()); |
| 519 EXPECT_EQ(*set1.get(), *new_set.get()); | 514 EXPECT_EQ(*set1.get(), *new_set.get()); |
| 520 | 515 |
| 521 // Now use a real second set. | 516 // Now use a real second set. |
| 522 apis2.insert(APIPermission::kTab); | 517 apis2.insert(APIPermission::kTab); |
| 523 apis2.insert(APIPermission::kProxy); | 518 apis2.insert(APIPermission::kProxy); |
| 524 apis2.insert(APIPermission::kClipboardWrite); | 519 apis2.insert(APIPermission::kClipboardWrite); |
| 525 apis2.insert(APIPermission::kPlugin); | 520 apis2.insert(APIPermission::kPlugin); |
| 526 permission = permission_info->CreateAPIPermission(); | 521 permission = permission_info->CreateAPIPermission(); |
| 527 { | 522 { |
| 528 scoped_ptr<base::ListValue> value(new base::ListValue()); | 523 scoped_ptr<base::ListValue> value(new base::ListValue()); |
| 529 value->Append( | 524 value->Append(new base::StringValue("tcp-connect:*.example.com:80")); |
| 530 base::Value::CreateStringValue("tcp-connect:*.example.com:80")); | 525 value->Append(new base::StringValue("udp-send-to::8899")); |
| 531 value->Append(base::Value::CreateStringValue("udp-send-to::8899")); | |
| 532 ASSERT_TRUE(permission->FromValue(value.get(), NULL, NULL)); | 526 ASSERT_TRUE(permission->FromValue(value.get(), NULL, NULL)); |
| 533 } | 527 } |
| 534 apis2.insert(permission); | 528 apis2.insert(permission); |
| 535 | 529 |
| 536 expected_apis.insert(APIPermission::kBackground); | 530 expected_apis.insert(APIPermission::kBackground); |
| 537 permission = permission_info->CreateAPIPermission(); | 531 permission = permission_info->CreateAPIPermission(); |
| 538 { | 532 { |
| 539 scoped_ptr<base::ListValue> value(new base::ListValue()); | 533 scoped_ptr<base::ListValue> value(new base::ListValue()); |
| 540 value->Append(base::Value::CreateStringValue("udp-bind::8080")); | 534 value->Append(new base::StringValue("udp-bind::8080")); |
| 541 value->Append(base::Value::CreateStringValue("udp-send-to::8888")); | 535 value->Append(new base::StringValue("udp-send-to::8888")); |
| 542 ASSERT_TRUE(permission->FromValue(value.get(), NULL, NULL)); | 536 ASSERT_TRUE(permission->FromValue(value.get(), NULL, NULL)); |
| 543 } | 537 } |
| 544 expected_apis.insert(permission); | 538 expected_apis.insert(permission); |
| 545 | 539 |
| 546 AddPattern(&explicit_hosts2, "http://*.example.com/*"); | 540 AddPattern(&explicit_hosts2, "http://*.example.com/*"); |
| 547 AddPattern(&explicit_hosts2, "http://*.google.com/*"); | 541 AddPattern(&explicit_hosts2, "http://*.google.com/*"); |
| 548 AddPattern(&scriptable_hosts2, "http://*.google.com/*"); | 542 AddPattern(&scriptable_hosts2, "http://*.google.com/*"); |
| 549 AddPattern(&expected_scriptable_hosts, "http://www.reddit.com/*"); | 543 AddPattern(&expected_scriptable_hosts, "http://www.reddit.com/*"); |
| 550 | 544 |
| 551 effective_hosts.ClearPatterns(); | 545 effective_hosts.ClearPatterns(); |
| (...skipping 1242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1794 scoped_refptr<const PermissionSet> permissions_dwr( | 1788 scoped_refptr<const PermissionSet> permissions_dwr( |
| 1795 extension_dwr->permissions_data()->active_permissions()); | 1789 extension_dwr->permissions_data()->active_permissions()); |
| 1796 | 1790 |
| 1797 EXPECT_FALSE(PermissionMessageProvider::Get()-> | 1791 EXPECT_FALSE(PermissionMessageProvider::Get()-> |
| 1798 IsPrivilegeIncrease(permissions.get(), | 1792 IsPrivilegeIncrease(permissions.get(), |
| 1799 permissions_dwr.get(), | 1793 permissions_dwr.get(), |
| 1800 extension->GetType())); | 1794 extension->GetType())); |
| 1801 } | 1795 } |
| 1802 | 1796 |
| 1803 } // namespace extensions | 1797 } // namespace extensions |
| OLD | NEW |