| 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/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/common/chrome_paths.h" | 10 #include "chrome/common/chrome_paths.h" |
| 11 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/common/chrome_switches.h" |
| 12 #include "chrome/common/extensions/extension.h" | 12 #include "chrome/common/extensions/extension.h" |
| 13 #include "chrome/common/extensions/extension_manifest_constants.h" | 13 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 14 #include "chrome/common/extensions/extension_error_utils.h" | 14 #include "chrome/common/extensions/extension_error_utils.h" |
| 15 #include "chrome/common/extensions/permissions/permission_set.h" | 15 #include "chrome/common/extensions/permissions/permission_set.h" |
| 16 #include "chrome/common/extensions/permissions/permissions_info.h" | 16 #include "chrome/common/extensions/permissions/permissions_info.h" |
| 17 #include "chrome/common/extensions/permissions/socket_permission.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 19 |
| 19 using extensions::Extension; | 20 using extensions::Extension; |
| 20 | 21 |
| 21 namespace errors = extension_manifest_errors; | 22 namespace errors = extension_manifest_errors; |
| 22 namespace keys = extension_manifest_keys; | 23 namespace keys = extension_manifest_keys; |
| 23 namespace values = extension_manifest_values; | 24 namespace values = extension_manifest_values; |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| 26 static scoped_refptr<Extension> LoadManifest(const std::string& dir, | 27 static scoped_refptr<Extension> LoadManifest(const std::string& dir, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 } // namespace | 85 } // namespace |
| 85 | 86 |
| 86 namespace extensions { | 87 namespace extensions { |
| 87 | 88 |
| 88 class PermissionsTest : public testing::Test { | 89 class PermissionsTest : public testing::Test { |
| 89 }; | 90 }; |
| 90 | 91 |
| 91 // Tests GetByID. | 92 // Tests GetByID. |
| 92 TEST(PermissionsTest, GetByID) { | 93 TEST(PermissionsTest, GetByID) { |
| 93 PermissionsInfo* info = PermissionsInfo::GetInstance(); | 94 PermissionsInfo* info = PermissionsInfo::GetInstance(); |
| 94 APIPermissionSet ids = info->GetAll(); | 95 APIPermissionSet apis = info->GetAll(); |
| 95 for (APIPermissionSet::iterator i = ids.begin(); | 96 for (APIPermissionSet::const_iterator i = apis.begin(); |
| 96 i != ids.end(); ++i) { | 97 i != apis.end(); ++i) { |
| 97 EXPECT_EQ(*i, info->GetByID(*i)->id()); | 98 EXPECT_EQ(i->id(), i->permission()->id()); |
| 98 } | 99 } |
| 99 } | 100 } |
| 100 | 101 |
| 101 // Tests that GetByName works with normal permission names and aliases. | 102 // Tests that GetByName works with normal permission names and aliases. |
| 102 TEST(PermissionsTest, GetByName) { | 103 TEST(PermissionsTest, GetByName) { |
| 103 PermissionsInfo* info = PermissionsInfo::GetInstance(); | 104 PermissionsInfo* info = PermissionsInfo::GetInstance(); |
| 104 EXPECT_EQ(APIPermission::kTab, info->GetByName("tabs")->id()); | 105 EXPECT_EQ(APIPermission::kTab, info->GetByName("tabs")->id()); |
| 105 EXPECT_EQ(APIPermission::kManagement, | 106 EXPECT_EQ(APIPermission::kManagement, |
| 106 info->GetByName("management")->id()); | 107 info->GetByName("management")->id()); |
| 107 EXPECT_FALSE(info->GetByName("alsdkfjasldkfj")); | 108 EXPECT_FALSE(info->GetByName("alsdkfjasldkfj")); |
| 108 } | 109 } |
| 109 | 110 |
| 110 TEST(PermissionsTest, GetAll) { | 111 TEST(PermissionsTest, GetAll) { |
| 111 size_t count = 0; | 112 size_t count = 0; |
| 112 PermissionsInfo* info = PermissionsInfo::GetInstance(); | 113 PermissionsInfo* info = PermissionsInfo::GetInstance(); |
| 113 APIPermissionSet apis = info->GetAll(); | 114 APIPermissionSet apis = info->GetAll(); |
| 114 for (APIPermissionSet::iterator api = apis.begin(); | 115 for (APIPermissionSet::const_iterator api = apis.begin(); |
| 115 api != apis.end(); ++api) { | 116 api != apis.end(); ++api) { |
| 116 // Make sure only the valid permission IDs get returned. | 117 // Make sure only the valid permission IDs get returned. |
| 117 EXPECT_NE(APIPermission::kInvalid, *api); | 118 EXPECT_NE(APIPermission::kInvalid, api->id()); |
| 118 EXPECT_NE(APIPermission::kUnknown, *api); | 119 EXPECT_NE(APIPermission::kUnknown, api->id()); |
| 119 count++; | 120 count++; |
| 120 } | 121 } |
| 121 EXPECT_EQ(count, info->get_permission_count()); | 122 EXPECT_EQ(count, info->get_permission_count()); |
| 122 } | 123 } |
| 123 | 124 |
| 124 TEST(PermissionsTest, GetAllByName) { | 125 TEST(PermissionsTest, GetAllByName) { |
| 125 std::set<std::string> names; | 126 std::set<std::string> names; |
| 126 names.insert("background"); | 127 names.insert("background"); |
| 127 names.insert("management"); | 128 names.insert("management"); |
| 128 | 129 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 GURL("http://test.google.com/"))); | 254 GURL("http://test.google.com/"))); |
| 254 ASSERT_TRUE(perm_set->HasExplicitAccessToOrigin( | 255 ASSERT_TRUE(perm_set->HasExplicitAccessToOrigin( |
| 255 GURL("http://www.example.com"))); | 256 GURL("http://www.example.com"))); |
| 256 ASSERT_TRUE(perm_set->HasEffectiveAccessToURL( | 257 ASSERT_TRUE(perm_set->HasEffectiveAccessToURL( |
| 257 GURL("http://www.example.com"))); | 258 GURL("http://www.example.com"))); |
| 258 ASSERT_FALSE(perm_set->HasExplicitAccessToOrigin( | 259 ASSERT_FALSE(perm_set->HasExplicitAccessToOrigin( |
| 259 GURL("http://test.example.com"))); | 260 GURL("http://test.example.com"))); |
| 260 } | 261 } |
| 261 | 262 |
| 262 TEST(PermissionsTest, CreateUnion) { | 263 TEST(PermissionsTest, CreateUnion) { |
| 264 scoped_refptr<APIPermissionDetail> detail; |
| 265 |
| 263 APIPermissionSet apis1; | 266 APIPermissionSet apis1; |
| 264 APIPermissionSet apis2; | 267 APIPermissionSet apis2; |
| 265 APIPermissionSet expected_apis; | 268 APIPermissionSet expected_apis; |
| 266 | 269 |
| 267 URLPatternSet explicit_hosts1; | 270 URLPatternSet explicit_hosts1; |
| 268 URLPatternSet explicit_hosts2; | 271 URLPatternSet explicit_hosts2; |
| 269 URLPatternSet expected_explicit_hosts; | 272 URLPatternSet expected_explicit_hosts; |
| 270 | 273 |
| 271 URLPatternSet scriptable_hosts1; | 274 URLPatternSet scriptable_hosts1; |
| 272 URLPatternSet scriptable_hosts2; | 275 URLPatternSet scriptable_hosts2; |
| 273 URLPatternSet expected_scriptable_hosts; | 276 URLPatternSet expected_scriptable_hosts; |
| 274 | 277 |
| 275 URLPatternSet effective_hosts; | 278 URLPatternSet effective_hosts; |
| 276 | 279 |
| 277 scoped_refptr<PermissionSet> set1; | 280 scoped_refptr<PermissionSet> set1; |
| 278 scoped_refptr<PermissionSet> set2; | 281 scoped_refptr<PermissionSet> set2; |
| 279 scoped_refptr<PermissionSet> union_set; | 282 scoped_refptr<PermissionSet> union_set; |
| 280 | 283 |
| 284 APIPermission* permission = |
| 285 PermissionsInfo::GetInstance()->GetByID(APIPermission::kSocket); |
| 286 detail = permission->CreateDetail(); |
| 287 { |
| 288 scoped_ptr<ListValue> value(new ListValue()); |
| 289 value->Append(Value::CreateStringValue("tcp-connect:*.example.com:80")); |
| 290 value->Append(Value::CreateStringValue("udp-bind::8080")); |
| 291 value->Append(Value::CreateStringValue("udp-send-to::8888")); |
| 292 if (!detail->FromValue(value.get())) { |
| 293 NOTREACHED(); |
| 294 } |
| 295 } |
| 296 |
| 281 // Union with an empty set. | 297 // Union with an empty set. |
| 282 apis1.insert(APIPermission::kTab); | 298 apis1.insert(APIPermission::kTab); |
| 283 apis1.insert(APIPermission::kBackground); | 299 apis1.insert(APIPermission::kBackground); |
| 300 apis1.insert(detail); |
| 284 expected_apis.insert(APIPermission::kTab); | 301 expected_apis.insert(APIPermission::kTab); |
| 285 expected_apis.insert(APIPermission::kBackground); | 302 expected_apis.insert(APIPermission::kBackground); |
| 303 expected_apis.insert(detail); |
| 286 | 304 |
| 287 AddPattern(&explicit_hosts1, "http://*.google.com/*"); | 305 AddPattern(&explicit_hosts1, "http://*.google.com/*"); |
| 288 AddPattern(&expected_explicit_hosts, "http://*.google.com/*"); | 306 AddPattern(&expected_explicit_hosts, "http://*.google.com/*"); |
| 289 AddPattern(&effective_hosts, "http://*.google.com/*"); | 307 AddPattern(&effective_hosts, "http://*.google.com/*"); |
| 290 | 308 |
| 291 set1 = new PermissionSet(apis1, explicit_hosts1, scriptable_hosts1); | 309 set1 = new PermissionSet(apis1, explicit_hosts1, scriptable_hosts1); |
| 292 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2); | 310 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2); |
| 293 union_set = PermissionSet::CreateUnion(set1.get(), set2.get()); | 311 union_set = PermissionSet::CreateUnion(set1.get(), set2.get()); |
| 294 EXPECT_TRUE(set1->Contains(*set2)); | 312 EXPECT_TRUE(set1->Contains(*set2)); |
| 295 EXPECT_TRUE(set1->Contains(*union_set)); | 313 EXPECT_TRUE(set1->Contains(*union_set)); |
| 296 EXPECT_FALSE(set2->Contains(*set1)); | 314 EXPECT_FALSE(set2->Contains(*set1)); |
| 297 EXPECT_FALSE(set2->Contains(*union_set)); | 315 EXPECT_FALSE(set2->Contains(*union_set)); |
| 298 EXPECT_TRUE(union_set->Contains(*set1)); | 316 EXPECT_TRUE(union_set->Contains(*set1)); |
| 299 EXPECT_TRUE(union_set->Contains(*set2)); | 317 EXPECT_TRUE(union_set->Contains(*set2)); |
| 300 | 318 |
| 301 EXPECT_FALSE(union_set->HasEffectiveFullAccess()); | 319 EXPECT_FALSE(union_set->HasEffectiveFullAccess()); |
| 302 EXPECT_EQ(expected_apis, union_set->apis()); | 320 EXPECT_EQ(expected_apis, union_set->apis()); |
| 303 EXPECT_EQ(expected_explicit_hosts, union_set->explicit_hosts()); | 321 EXPECT_EQ(expected_explicit_hosts, union_set->explicit_hosts()); |
| 304 EXPECT_EQ(expected_scriptable_hosts, union_set->scriptable_hosts()); | 322 EXPECT_EQ(expected_scriptable_hosts, union_set->scriptable_hosts()); |
| 305 EXPECT_EQ(expected_explicit_hosts, union_set->effective_hosts()); | 323 EXPECT_EQ(expected_explicit_hosts, union_set->effective_hosts()); |
| 306 | 324 |
| 307 // Now use a real second set. | 325 // Now use a real second set. |
| 308 apis2.insert(APIPermission::kTab); | 326 apis2.insert(APIPermission::kTab); |
| 309 apis2.insert(APIPermission::kProxy); | 327 apis2.insert(APIPermission::kProxy); |
| 310 apis2.insert(APIPermission::kClipboardWrite); | 328 apis2.insert(APIPermission::kClipboardWrite); |
| 311 apis2.insert(APIPermission::kPlugin); | 329 apis2.insert(APIPermission::kPlugin); |
| 330 |
| 331 detail = permission->CreateDetail(); |
| 332 { |
| 333 scoped_ptr<ListValue> value(new ListValue()); |
| 334 value->Append(Value::CreateStringValue("tcp-connect:*.example.com:80")); |
| 335 value->Append(Value::CreateStringValue("udp-send-to::8899")); |
| 336 if (!detail->FromValue(value.get())) { |
| 337 NOTREACHED(); |
| 338 } |
| 339 } |
| 340 apis2.insert(detail); |
| 341 |
| 312 expected_apis.insert(APIPermission::kTab); | 342 expected_apis.insert(APIPermission::kTab); |
| 313 expected_apis.insert(APIPermission::kProxy); | 343 expected_apis.insert(APIPermission::kProxy); |
| 314 expected_apis.insert(APIPermission::kClipboardWrite); | 344 expected_apis.insert(APIPermission::kClipboardWrite); |
| 315 expected_apis.insert(APIPermission::kPlugin); | 345 expected_apis.insert(APIPermission::kPlugin); |
| 316 | 346 |
| 347 detail = permission->CreateDetail(); |
| 348 { |
| 349 scoped_ptr<ListValue> value(new ListValue()); |
| 350 value->Append(Value::CreateStringValue("tcp-connect:*.example.com:80")); |
| 351 value->Append(Value::CreateStringValue("udp-bind::8080")); |
| 352 value->Append(Value::CreateStringValue("udp-send-to::8888")); |
| 353 value->Append(Value::CreateStringValue("udp-send-to::8899")); |
| 354 if (!detail->FromValue(value.get())) { |
| 355 NOTREACHED(); |
| 356 } |
| 357 } |
| 358 // Insert a new detail socket permisssion which will replace the old one. |
| 359 expected_apis.insert(detail); |
| 360 |
| 317 AddPattern(&explicit_hosts2, "http://*.example.com/*"); | 361 AddPattern(&explicit_hosts2, "http://*.example.com/*"); |
| 318 AddPattern(&scriptable_hosts2, "http://*.google.com/*"); | 362 AddPattern(&scriptable_hosts2, "http://*.google.com/*"); |
| 319 AddPattern(&expected_explicit_hosts, "http://*.example.com/*"); | 363 AddPattern(&expected_explicit_hosts, "http://*.example.com/*"); |
| 320 AddPattern(&expected_scriptable_hosts, "http://*.google.com/*"); | 364 AddPattern(&expected_scriptable_hosts, "http://*.google.com/*"); |
| 321 | 365 |
| 322 URLPatternSet::CreateUnion( | 366 URLPatternSet::CreateUnion( |
| 323 explicit_hosts2, scriptable_hosts2, &effective_hosts); | 367 explicit_hosts2, scriptable_hosts2, &effective_hosts); |
| 324 | 368 |
| 325 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2); | 369 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2); |
| 326 union_set = PermissionSet::CreateUnion(set1.get(), set2.get()); | 370 union_set = PermissionSet::CreateUnion(set1.get(), set2.get()); |
| 327 | 371 |
| 328 EXPECT_FALSE(set1->Contains(*set2)); | 372 EXPECT_FALSE(set1->Contains(*set2)); |
| 329 EXPECT_FALSE(set1->Contains(*union_set)); | 373 EXPECT_FALSE(set1->Contains(*union_set)); |
| 330 EXPECT_FALSE(set2->Contains(*set1)); | 374 EXPECT_FALSE(set2->Contains(*set1)); |
| 331 EXPECT_FALSE(set2->Contains(*union_set)); | 375 EXPECT_FALSE(set2->Contains(*union_set)); |
| 332 EXPECT_TRUE(union_set->Contains(*set1)); | 376 EXPECT_TRUE(union_set->Contains(*set1)); |
| 333 EXPECT_TRUE(union_set->Contains(*set2)); | 377 EXPECT_TRUE(union_set->Contains(*set2)); |
| 334 | 378 |
| 335 EXPECT_TRUE(union_set->HasEffectiveFullAccess()); | 379 EXPECT_TRUE(union_set->HasEffectiveFullAccess()); |
| 336 EXPECT_TRUE(union_set->HasEffectiveAccessToAllHosts()); | 380 EXPECT_TRUE(union_set->HasEffectiveAccessToAllHosts()); |
| 337 EXPECT_EQ(expected_apis, union_set->apis()); | 381 EXPECT_EQ(expected_apis, union_set->apis()); |
| 338 EXPECT_EQ(expected_explicit_hosts, union_set->explicit_hosts()); | 382 EXPECT_EQ(expected_explicit_hosts, union_set->explicit_hosts()); |
| 339 EXPECT_EQ(expected_scriptable_hosts, union_set->scriptable_hosts()); | 383 EXPECT_EQ(expected_scriptable_hosts, union_set->scriptable_hosts()); |
| 340 EXPECT_EQ(effective_hosts, union_set->effective_hosts()); | 384 EXPECT_EQ(effective_hosts, union_set->effective_hosts()); |
| 341 } | 385 } |
| 342 | 386 |
| 343 TEST(PermissionsTest, CreateIntersection) { | 387 TEST(PermissionsTest, CreateIntersection) { |
| 388 scoped_refptr<APIPermissionDetail> detail; |
| 389 |
| 344 APIPermissionSet apis1; | 390 APIPermissionSet apis1; |
| 345 APIPermissionSet apis2; | 391 APIPermissionSet apis2; |
| 346 APIPermissionSet expected_apis; | 392 APIPermissionSet expected_apis; |
| 347 | 393 |
| 348 URLPatternSet explicit_hosts1; | 394 URLPatternSet explicit_hosts1; |
| 349 URLPatternSet explicit_hosts2; | 395 URLPatternSet explicit_hosts2; |
| 350 URLPatternSet expected_explicit_hosts; | 396 URLPatternSet expected_explicit_hosts; |
| 351 | 397 |
| 352 URLPatternSet scriptable_hosts1; | 398 URLPatternSet scriptable_hosts1; |
| 353 URLPatternSet scriptable_hosts2; | 399 URLPatternSet scriptable_hosts2; |
| 354 URLPatternSet expected_scriptable_hosts; | 400 URLPatternSet expected_scriptable_hosts; |
| 355 | 401 |
| 356 URLPatternSet effective_hosts; | 402 URLPatternSet effective_hosts; |
| 357 | 403 |
| 358 scoped_refptr<PermissionSet> set1; | 404 scoped_refptr<PermissionSet> set1; |
| 359 scoped_refptr<PermissionSet> set2; | 405 scoped_refptr<PermissionSet> set2; |
| 360 scoped_refptr<PermissionSet> new_set; | 406 scoped_refptr<PermissionSet> new_set; |
| 361 | 407 |
| 408 APIPermission* permission = |
| 409 PermissionsInfo::GetInstance()->GetByID(APIPermission::kSocket); |
| 410 |
| 362 // Intersection with an empty set. | 411 // Intersection with an empty set. |
| 363 apis1.insert(APIPermission::kTab); | 412 apis1.insert(APIPermission::kTab); |
| 364 apis1.insert(APIPermission::kBackground); | 413 apis1.insert(APIPermission::kBackground); |
| 414 detail = permission->CreateDetail(); |
| 415 { |
| 416 scoped_ptr<ListValue> value(new ListValue()); |
| 417 value->Append(Value::CreateStringValue("tcp-connect:*.example.com:80")); |
| 418 value->Append(Value::CreateStringValue("udp-bind::8080")); |
| 419 value->Append(Value::CreateStringValue("udp-send-to::8888")); |
| 420 if (!detail->FromValue(value.get())) { |
| 421 NOTREACHED(); |
| 422 } |
| 423 } |
| 424 apis1.insert(detail); |
| 365 | 425 |
| 366 AddPattern(&explicit_hosts1, "http://*.google.com/*"); | 426 AddPattern(&explicit_hosts1, "http://*.google.com/*"); |
| 367 AddPattern(&scriptable_hosts1, "http://www.reddit.com/*"); | 427 AddPattern(&scriptable_hosts1, "http://www.reddit.com/*"); |
| 368 | 428 |
| 369 set1 = new PermissionSet(apis1, explicit_hosts1, scriptable_hosts1); | 429 set1 = new PermissionSet(apis1, explicit_hosts1, scriptable_hosts1); |
| 370 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2); | 430 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2); |
| 371 new_set = PermissionSet::CreateIntersection(set1.get(), set2.get()); | 431 new_set = PermissionSet::CreateIntersection(set1.get(), set2.get()); |
| 372 EXPECT_TRUE(set1->Contains(*new_set)); | 432 EXPECT_TRUE(set1->Contains(*new_set)); |
| 373 EXPECT_TRUE(set2->Contains(*new_set)); | 433 EXPECT_TRUE(set2->Contains(*new_set)); |
| 374 EXPECT_TRUE(set1->Contains(*set2)); | 434 EXPECT_TRUE(set1->Contains(*set2)); |
| 375 EXPECT_FALSE(set2->Contains(*set1)); | 435 EXPECT_FALSE(set2->Contains(*set1)); |
| 376 EXPECT_FALSE(new_set->Contains(*set1)); | 436 EXPECT_FALSE(new_set->Contains(*set1)); |
| 377 EXPECT_TRUE(new_set->Contains(*set2)); | 437 EXPECT_TRUE(new_set->Contains(*set2)); |
| 378 | 438 |
| 379 EXPECT_TRUE(new_set->IsEmpty()); | 439 EXPECT_TRUE(new_set->IsEmpty()); |
| 380 EXPECT_FALSE(new_set->HasEffectiveFullAccess()); | 440 EXPECT_FALSE(new_set->HasEffectiveFullAccess()); |
| 381 EXPECT_EQ(expected_apis, new_set->apis()); | 441 EXPECT_EQ(expected_apis, new_set->apis()); |
| 382 EXPECT_EQ(expected_explicit_hosts, new_set->explicit_hosts()); | 442 EXPECT_EQ(expected_explicit_hosts, new_set->explicit_hosts()); |
| 383 EXPECT_EQ(expected_scriptable_hosts, new_set->scriptable_hosts()); | 443 EXPECT_EQ(expected_scriptable_hosts, new_set->scriptable_hosts()); |
| 384 EXPECT_EQ(expected_explicit_hosts, new_set->effective_hosts()); | 444 EXPECT_EQ(expected_explicit_hosts, new_set->effective_hosts()); |
| 385 | 445 |
| 386 // Now use a real second set. | 446 // Now use a real second set. |
| 387 apis2.insert(APIPermission::kTab); | 447 apis2.insert(APIPermission::kTab); |
| 388 apis2.insert(APIPermission::kProxy); | 448 apis2.insert(APIPermission::kProxy); |
| 389 apis2.insert(APIPermission::kClipboardWrite); | 449 apis2.insert(APIPermission::kClipboardWrite); |
| 390 apis2.insert(APIPermission::kPlugin); | 450 apis2.insert(APIPermission::kPlugin); |
| 451 detail = permission->CreateDetail(); |
| 452 { |
| 453 scoped_ptr<ListValue> value(new ListValue()); |
| 454 value->Append(Value::CreateStringValue("udp-bind::8080")); |
| 455 value->Append(Value::CreateStringValue("udp-send-to::8888")); |
| 456 value->Append(Value::CreateStringValue("udp-send-to::8899")); |
| 457 if (!detail->FromValue(value.get())) { |
| 458 NOTREACHED(); |
| 459 } |
| 460 } |
| 461 apis2.insert(detail); |
| 462 |
| 391 expected_apis.insert(APIPermission::kTab); | 463 expected_apis.insert(APIPermission::kTab); |
| 464 detail = permission->CreateDetail(); |
| 465 { |
| 466 scoped_ptr<ListValue> value(new ListValue()); |
| 467 value->Append(Value::CreateStringValue("udp-bind::8080")); |
| 468 value->Append(Value::CreateStringValue("udp-send-to::8888")); |
| 469 if (!detail->FromValue(value.get())) { |
| 470 NOTREACHED(); |
| 471 } |
| 472 } |
| 473 expected_apis.insert(detail); |
| 392 | 474 |
| 393 AddPattern(&explicit_hosts2, "http://*.example.com/*"); | 475 AddPattern(&explicit_hosts2, "http://*.example.com/*"); |
| 394 AddPattern(&explicit_hosts2, "http://*.google.com/*"); | 476 AddPattern(&explicit_hosts2, "http://*.google.com/*"); |
| 395 AddPattern(&scriptable_hosts2, "http://*.google.com/*"); | 477 AddPattern(&scriptable_hosts2, "http://*.google.com/*"); |
| 396 AddPattern(&expected_explicit_hosts, "http://*.google.com/*"); | 478 AddPattern(&expected_explicit_hosts, "http://*.google.com/*"); |
| 397 | 479 |
| 398 effective_hosts.ClearPatterns(); | 480 effective_hosts.ClearPatterns(); |
| 399 AddPattern(&effective_hosts, "http://*.google.com/*"); | 481 AddPattern(&effective_hosts, "http://*.google.com/*"); |
| 400 | 482 |
| 401 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2); | 483 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2); |
| 402 new_set = PermissionSet::CreateIntersection(set1.get(), set2.get()); | 484 new_set = PermissionSet::CreateIntersection(set1.get(), set2.get()); |
| 403 | 485 |
| 404 EXPECT_TRUE(set1->Contains(*new_set)); | 486 EXPECT_TRUE(set1->Contains(*new_set)); |
| 405 EXPECT_TRUE(set2->Contains(*new_set)); | 487 EXPECT_TRUE(set2->Contains(*new_set)); |
| 406 EXPECT_FALSE(set1->Contains(*set2)); | 488 EXPECT_FALSE(set1->Contains(*set2)); |
| 407 EXPECT_FALSE(set2->Contains(*set1)); | 489 EXPECT_FALSE(set2->Contains(*set1)); |
| 408 EXPECT_FALSE(new_set->Contains(*set1)); | 490 EXPECT_FALSE(new_set->Contains(*set1)); |
| 409 EXPECT_FALSE(new_set->Contains(*set2)); | 491 EXPECT_FALSE(new_set->Contains(*set2)); |
| 410 | 492 |
| 411 EXPECT_FALSE(new_set->HasEffectiveFullAccess()); | 493 EXPECT_FALSE(new_set->HasEffectiveFullAccess()); |
| 412 EXPECT_FALSE(new_set->HasEffectiveAccessToAllHosts()); | 494 EXPECT_FALSE(new_set->HasEffectiveAccessToAllHosts()); |
| 413 EXPECT_EQ(expected_apis, new_set->apis()); | 495 EXPECT_EQ(expected_apis, new_set->apis()); |
| 414 EXPECT_EQ(expected_explicit_hosts, new_set->explicit_hosts()); | 496 EXPECT_EQ(expected_explicit_hosts, new_set->explicit_hosts()); |
| 415 EXPECT_EQ(expected_scriptable_hosts, new_set->scriptable_hosts()); | 497 EXPECT_EQ(expected_scriptable_hosts, new_set->scriptable_hosts()); |
| 416 EXPECT_EQ(effective_hosts, new_set->effective_hosts()); | 498 EXPECT_EQ(effective_hosts, new_set->effective_hosts()); |
| 417 } | 499 } |
| 418 | 500 |
| 419 TEST(PermissionsTest, CreateDifference) { | 501 TEST(PermissionsTest, CreateDifference) { |
| 502 scoped_refptr<APIPermissionDetail> detail; |
| 503 |
| 420 APIPermissionSet apis1; | 504 APIPermissionSet apis1; |
| 421 APIPermissionSet apis2; | 505 APIPermissionSet apis2; |
| 422 APIPermissionSet expected_apis; | 506 APIPermissionSet expected_apis; |
| 423 | 507 |
| 424 URLPatternSet explicit_hosts1; | 508 URLPatternSet explicit_hosts1; |
| 425 URLPatternSet explicit_hosts2; | 509 URLPatternSet explicit_hosts2; |
| 426 URLPatternSet expected_explicit_hosts; | 510 URLPatternSet expected_explicit_hosts; |
| 427 | 511 |
| 428 URLPatternSet scriptable_hosts1; | 512 URLPatternSet scriptable_hosts1; |
| 429 URLPatternSet scriptable_hosts2; | 513 URLPatternSet scriptable_hosts2; |
| 430 URLPatternSet expected_scriptable_hosts; | 514 URLPatternSet expected_scriptable_hosts; |
| 431 | 515 |
| 432 URLPatternSet effective_hosts; | 516 URLPatternSet effective_hosts; |
| 433 | 517 |
| 434 scoped_refptr<PermissionSet> set1; | 518 scoped_refptr<PermissionSet> set1; |
| 435 scoped_refptr<PermissionSet> set2; | 519 scoped_refptr<PermissionSet> set2; |
| 436 scoped_refptr<PermissionSet> new_set; | 520 scoped_refptr<PermissionSet> new_set; |
| 437 | 521 |
| 522 APIPermission* permission = |
| 523 PermissionsInfo::GetInstance()->GetByID(APIPermission::kSocket); |
| 524 |
| 438 // Difference with an empty set. | 525 // Difference with an empty set. |
| 439 apis1.insert(APIPermission::kTab); | 526 apis1.insert(APIPermission::kTab); |
| 440 apis1.insert(APIPermission::kBackground); | 527 apis1.insert(APIPermission::kBackground); |
| 528 detail = permission->CreateDetail(); |
| 529 { |
| 530 scoped_ptr<ListValue> value(new ListValue()); |
| 531 value->Append(Value::CreateStringValue("tcp-connect:*.example.com:80")); |
| 532 value->Append(Value::CreateStringValue("udp-bind::8080")); |
| 533 value->Append(Value::CreateStringValue("udp-send-to::8888")); |
| 534 if (!detail->FromValue(value.get())) { |
| 535 NOTREACHED(); |
| 536 } |
| 537 } |
| 538 apis1.insert(detail); |
| 441 | 539 |
| 442 AddPattern(&explicit_hosts1, "http://*.google.com/*"); | 540 AddPattern(&explicit_hosts1, "http://*.google.com/*"); |
| 443 AddPattern(&scriptable_hosts1, "http://www.reddit.com/*"); | 541 AddPattern(&scriptable_hosts1, "http://www.reddit.com/*"); |
| 444 | 542 |
| 445 set1 = new PermissionSet(apis1, explicit_hosts1, scriptable_hosts1); | 543 set1 = new PermissionSet(apis1, explicit_hosts1, scriptable_hosts1); |
| 446 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2); | 544 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2); |
| 447 new_set = PermissionSet::CreateDifference(set1.get(), set2.get()); | 545 new_set = PermissionSet::CreateDifference(set1.get(), set2.get()); |
| 448 EXPECT_EQ(*set1, *new_set); | 546 EXPECT_EQ(*set1, *new_set); |
| 449 | 547 |
| 450 // Now use a real second set. | 548 // Now use a real second set. |
| 451 apis2.insert(APIPermission::kTab); | 549 apis2.insert(APIPermission::kTab); |
| 452 apis2.insert(APIPermission::kProxy); | 550 apis2.insert(APIPermission::kProxy); |
| 453 apis2.insert(APIPermission::kClipboardWrite); | 551 apis2.insert(APIPermission::kClipboardWrite); |
| 454 apis2.insert(APIPermission::kPlugin); | 552 apis2.insert(APIPermission::kPlugin); |
| 553 detail = permission->CreateDetail(); |
| 554 { |
| 555 scoped_ptr<ListValue> value(new ListValue()); |
| 556 value->Append(Value::CreateStringValue("tcp-connect:*.example.com:80")); |
| 557 value->Append(Value::CreateStringValue("udp-send-to::8899")); |
| 558 if (!detail->FromValue(value.get())) { |
| 559 NOTREACHED(); |
| 560 } |
| 561 } |
| 562 apis2.insert(detail); |
| 563 |
| 455 expected_apis.insert(APIPermission::kBackground); | 564 expected_apis.insert(APIPermission::kBackground); |
| 565 detail = permission->CreateDetail(); |
| 566 { |
| 567 scoped_ptr<ListValue> value(new ListValue()); |
| 568 value->Append(Value::CreateStringValue("udp-bind::8080")); |
| 569 value->Append(Value::CreateStringValue("udp-send-to::8888")); |
| 570 if (!detail->FromValue(value.get())) { |
| 571 NOTREACHED(); |
| 572 } |
| 573 } |
| 574 expected_apis.insert(detail); |
| 456 | 575 |
| 457 AddPattern(&explicit_hosts2, "http://*.example.com/*"); | 576 AddPattern(&explicit_hosts2, "http://*.example.com/*"); |
| 458 AddPattern(&explicit_hosts2, "http://*.google.com/*"); | 577 AddPattern(&explicit_hosts2, "http://*.google.com/*"); |
| 459 AddPattern(&scriptable_hosts2, "http://*.google.com/*"); | 578 AddPattern(&scriptable_hosts2, "http://*.google.com/*"); |
| 460 AddPattern(&expected_scriptable_hosts, "http://www.reddit.com/*"); | 579 AddPattern(&expected_scriptable_hosts, "http://www.reddit.com/*"); |
| 461 | 580 |
| 462 effective_hosts.ClearPatterns(); | 581 effective_hosts.ClearPatterns(); |
| 463 AddPattern(&effective_hosts, "http://www.reddit.com/*"); | 582 AddPattern(&effective_hosts, "http://www.reddit.com/*"); |
| 464 | 583 |
| 465 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2); | 584 set2 = new PermissionSet(apis2, explicit_hosts2, scriptable_hosts2); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 // permissions. | 680 // permissions. |
| 562 skip.insert(APIPermission::kCookie); | 681 skip.insert(APIPermission::kCookie); |
| 563 | 682 |
| 564 // The ime, proxy, and webRequest permissions are warned as part of host | 683 // The ime, proxy, and webRequest permissions are warned as part of host |
| 565 // permission checks. | 684 // permission checks. |
| 566 skip.insert(APIPermission::kProxy); | 685 skip.insert(APIPermission::kProxy); |
| 567 skip.insert(APIPermission::kWebRequest); | 686 skip.insert(APIPermission::kWebRequest); |
| 568 skip.insert(APIPermission::kWebRequestBlocking); | 687 skip.insert(APIPermission::kWebRequestBlocking); |
| 569 skip.insert(APIPermission::kDeclarativeWebRequest); | 688 skip.insert(APIPermission::kDeclarativeWebRequest); |
| 570 | 689 |
| 571 | |
| 572 // This permission requires explicit user action (context menu handler) | 690 // This permission requires explicit user action (context menu handler) |
| 573 // so we won't prompt for it for now. | 691 // so we won't prompt for it for now. |
| 574 skip.insert(APIPermission::kFileBrowserHandler); | 692 skip.insert(APIPermission::kFileBrowserHandler); |
| 575 | 693 |
| 576 // This permission requires explicit user action (shortcut) so we don't | 694 // This permission requires explicit user action (shortcut) so we don't |
| 577 // prompt for it. | 695 // prompt for it. |
| 578 skip.insert(APIPermission::kCommands); | 696 skip.insert(APIPermission::kCommands); |
| 579 | 697 |
| 580 // These permissions require explicit user action (configuration dialog) | 698 // These permissions require explicit user action (configuration dialog) |
| 581 // so we don't prompt for them at install time. | 699 // so we don't prompt for them at install time. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 608 | 726 |
| 609 // Platform apps. TODO(miket): must we skip? | 727 // Platform apps. TODO(miket): must we skip? |
| 610 skip.insert(APIPermission::kFileSystem); | 728 skip.insert(APIPermission::kFileSystem); |
| 611 skip.insert(APIPermission::kSerial); | 729 skip.insert(APIPermission::kSerial); |
| 612 skip.insert(APIPermission::kSocket); | 730 skip.insert(APIPermission::kSocket); |
| 613 | 731 |
| 614 PermissionsInfo* info = PermissionsInfo::GetInstance(); | 732 PermissionsInfo* info = PermissionsInfo::GetInstance(); |
| 615 APIPermissionSet permissions = info->GetAll(); | 733 APIPermissionSet permissions = info->GetAll(); |
| 616 for (APIPermissionSet::const_iterator i = permissions.begin(); | 734 for (APIPermissionSet::const_iterator i = permissions.begin(); |
| 617 i != permissions.end(); ++i) { | 735 i != permissions.end(); ++i) { |
| 618 APIPermission* permission = info->GetByID(*i); | 736 const APIPermission* permission = i->permission(); |
| 619 EXPECT_TRUE(permission); | 737 EXPECT_TRUE(permission); |
| 620 if (skip.count(*i)) { | 738 if (skip.count(i->id())) { |
| 621 EXPECT_EQ(PermissionMessage::kNone, permission->message_id()) | 739 EXPECT_EQ(PermissionMessage::kNone, permission->message_id()) |
| 622 << "unexpected message_id for " << permission->name(); | 740 << "unexpected message_id for " << permission->name(); |
| 623 } else { | 741 } else { |
| 624 EXPECT_NE(PermissionMessage::kNone, permission->message_id()) | 742 EXPECT_NE(PermissionMessage::kNone, permission->message_id()) |
| 625 << "missing message_id for " << permission->name(); | 743 << "missing message_id for " << permission->name(); |
| 626 } | 744 } |
| 627 } | 745 } |
| 628 } | 746 } |
| 629 | 747 |
| 630 // Tests the default permissions (empty API permission set). | 748 // Tests the default permissions (empty API permission set). |
| (...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1147 apis.insert(APIPermission::kWebRequest); | 1265 apis.insert(APIPermission::kWebRequest); |
| 1148 apis.insert(APIPermission::kFileBrowserHandler); | 1266 apis.insert(APIPermission::kFileBrowserHandler); |
| 1149 EXPECT_EQ(2U, apis.size()); | 1267 EXPECT_EQ(2U, apis.size()); |
| 1150 | 1268 |
| 1151 scoped_refptr<PermissionSet> perm_set; | 1269 scoped_refptr<PermissionSet> perm_set; |
| 1152 perm_set = new PermissionSet(apis, empty_extent, empty_extent); | 1270 perm_set = new PermissionSet(apis, empty_extent, empty_extent); |
| 1153 EXPECT_EQ(4U, perm_set->apis().size()); | 1271 EXPECT_EQ(4U, perm_set->apis().size()); |
| 1154 } | 1272 } |
| 1155 | 1273 |
| 1156 } // namespace extensions | 1274 } // namespace extensions |
| OLD | NEW |