| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/common/features/simple_feature.h" | 5 #include "extensions/common/features/simple_feature.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 EXPECT_EQ( | 501 EXPECT_EQ( |
| 502 Feature::IS_AVAILABLE, | 502 Feature::IS_AVAILABLE, |
| 503 feature.IsAvailableToManifest(std::string(), | 503 feature.IsAvailableToManifest(std::string(), |
| 504 Manifest::TYPE_UNKNOWN, | 504 Manifest::TYPE_UNKNOWN, |
| 505 Manifest::INVALID_LOCATION, | 505 Manifest::INVALID_LOCATION, |
| 506 7, | 506 7, |
| 507 Feature::UNSPECIFIED_PLATFORM).result()); | 507 Feature::UNSPECIFIED_PLATFORM).result()); |
| 508 } | 508 } |
| 509 | 509 |
| 510 TEST_F(SimpleFeatureTest, ParseNull) { | 510 TEST_F(SimpleFeatureTest, ParseNull) { |
| 511 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | 511 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); |
| 512 scoped_ptr<SimpleFeature> feature(new SimpleFeature()); | 512 std::unique_ptr<SimpleFeature> feature(new SimpleFeature()); |
| 513 feature->Parse(value.get()); | 513 feature->Parse(value.get()); |
| 514 EXPECT_TRUE(feature->whitelist()->empty()); | 514 EXPECT_TRUE(feature->whitelist()->empty()); |
| 515 EXPECT_TRUE(feature->extension_types()->empty()); | 515 EXPECT_TRUE(feature->extension_types()->empty()); |
| 516 EXPECT_TRUE(feature->contexts()->empty()); | 516 EXPECT_TRUE(feature->contexts()->empty()); |
| 517 EXPECT_EQ(SimpleFeature::UNSPECIFIED_LOCATION, feature->location()); | 517 EXPECT_EQ(SimpleFeature::UNSPECIFIED_LOCATION, feature->location()); |
| 518 EXPECT_TRUE(feature->platforms()->empty()); | 518 EXPECT_TRUE(feature->platforms()->empty()); |
| 519 EXPECT_EQ(0, feature->min_manifest_version()); | 519 EXPECT_EQ(0, feature->min_manifest_version()); |
| 520 EXPECT_EQ(0, feature->max_manifest_version()); | 520 EXPECT_EQ(0, feature->max_manifest_version()); |
| 521 } | 521 } |
| 522 | 522 |
| 523 TEST_F(SimpleFeatureTest, ParseWhitelist) { | 523 TEST_F(SimpleFeatureTest, ParseWhitelist) { |
| 524 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | 524 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); |
| 525 base::ListValue* whitelist = new base::ListValue(); | 525 base::ListValue* whitelist = new base::ListValue(); |
| 526 whitelist->Append(new base::StringValue("foo")); | 526 whitelist->Append(new base::StringValue("foo")); |
| 527 whitelist->Append(new base::StringValue("bar")); | 527 whitelist->Append(new base::StringValue("bar")); |
| 528 value->Set("whitelist", whitelist); | 528 value->Set("whitelist", whitelist); |
| 529 scoped_ptr<SimpleFeature> feature(new SimpleFeature()); | 529 std::unique_ptr<SimpleFeature> feature(new SimpleFeature()); |
| 530 feature->Parse(value.get()); | 530 feature->Parse(value.get()); |
| 531 EXPECT_EQ(2u, feature->whitelist()->size()); | 531 EXPECT_EQ(2u, feature->whitelist()->size()); |
| 532 EXPECT_TRUE(STLCount(*(feature->whitelist()), "foo")); | 532 EXPECT_TRUE(STLCount(*(feature->whitelist()), "foo")); |
| 533 EXPECT_TRUE(STLCount(*(feature->whitelist()), "bar")); | 533 EXPECT_TRUE(STLCount(*(feature->whitelist()), "bar")); |
| 534 } | 534 } |
| 535 | 535 |
| 536 TEST_F(SimpleFeatureTest, ParsePackageTypes) { | 536 TEST_F(SimpleFeatureTest, ParsePackageTypes) { |
| 537 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | 537 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); |
| 538 base::ListValue* extension_types = new base::ListValue(); | 538 base::ListValue* extension_types = new base::ListValue(); |
| 539 extension_types->Append(new base::StringValue("extension")); | 539 extension_types->Append(new base::StringValue("extension")); |
| 540 extension_types->Append(new base::StringValue("theme")); | 540 extension_types->Append(new base::StringValue("theme")); |
| 541 extension_types->Append(new base::StringValue("legacy_packaged_app")); | 541 extension_types->Append(new base::StringValue("legacy_packaged_app")); |
| 542 extension_types->Append(new base::StringValue("hosted_app")); | 542 extension_types->Append(new base::StringValue("hosted_app")); |
| 543 extension_types->Append(new base::StringValue("platform_app")); | 543 extension_types->Append(new base::StringValue("platform_app")); |
| 544 extension_types->Append(new base::StringValue("shared_module")); | 544 extension_types->Append(new base::StringValue("shared_module")); |
| 545 value->Set("extension_types", extension_types); | 545 value->Set("extension_types", extension_types); |
| 546 scoped_ptr<SimpleFeature> feature(new SimpleFeature()); | 546 std::unique_ptr<SimpleFeature> feature(new SimpleFeature()); |
| 547 feature->Parse(value.get()); | 547 feature->Parse(value.get()); |
| 548 EXPECT_EQ(6u, feature->extension_types()->size()); | 548 EXPECT_EQ(6u, feature->extension_types()->size()); |
| 549 EXPECT_TRUE( | 549 EXPECT_TRUE( |
| 550 STLCount(*(feature->extension_types()), Manifest::TYPE_EXTENSION)); | 550 STLCount(*(feature->extension_types()), Manifest::TYPE_EXTENSION)); |
| 551 EXPECT_TRUE( | 551 EXPECT_TRUE( |
| 552 STLCount(*(feature->extension_types()), Manifest::TYPE_THEME)); | 552 STLCount(*(feature->extension_types()), Manifest::TYPE_THEME)); |
| 553 EXPECT_TRUE( | 553 EXPECT_TRUE( |
| 554 STLCount( | 554 STLCount( |
| 555 *(feature->extension_types()), Manifest::TYPE_LEGACY_PACKAGED_APP)); | 555 *(feature->extension_types()), Manifest::TYPE_LEGACY_PACKAGED_APP)); |
| 556 EXPECT_TRUE( | 556 EXPECT_TRUE( |
| 557 STLCount(*(feature->extension_types()), Manifest::TYPE_HOSTED_APP)); | 557 STLCount(*(feature->extension_types()), Manifest::TYPE_HOSTED_APP)); |
| 558 EXPECT_TRUE( | 558 EXPECT_TRUE( |
| 559 STLCount(*(feature->extension_types()), Manifest::TYPE_PLATFORM_APP)); | 559 STLCount(*(feature->extension_types()), Manifest::TYPE_PLATFORM_APP)); |
| 560 EXPECT_TRUE( | 560 EXPECT_TRUE( |
| 561 STLCount(*(feature->extension_types()), Manifest::TYPE_SHARED_MODULE)); | 561 STLCount(*(feature->extension_types()), Manifest::TYPE_SHARED_MODULE)); |
| 562 | 562 |
| 563 value->SetString("extension_types", "all"); | 563 value->SetString("extension_types", "all"); |
| 564 scoped_ptr<SimpleFeature> feature2(new SimpleFeature()); | 564 std::unique_ptr<SimpleFeature> feature2(new SimpleFeature()); |
| 565 feature2->Parse(value.get()); | 565 feature2->Parse(value.get()); |
| 566 EXPECT_EQ(*(feature->extension_types()), *(feature2->extension_types())); | 566 EXPECT_EQ(*(feature->extension_types()), *(feature2->extension_types())); |
| 567 } | 567 } |
| 568 | 568 |
| 569 TEST_F(SimpleFeatureTest, ParseContexts) { | 569 TEST_F(SimpleFeatureTest, ParseContexts) { |
| 570 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | 570 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); |
| 571 base::ListValue* contexts = new base::ListValue(); | 571 base::ListValue* contexts = new base::ListValue(); |
| 572 contexts->Append(new base::StringValue("blessed_extension")); | 572 contexts->Append(new base::StringValue("blessed_extension")); |
| 573 contexts->Append(new base::StringValue("unblessed_extension")); | 573 contexts->Append(new base::StringValue("unblessed_extension")); |
| 574 contexts->Append(new base::StringValue("content_script")); | 574 contexts->Append(new base::StringValue("content_script")); |
| 575 contexts->Append(new base::StringValue("web_page")); | 575 contexts->Append(new base::StringValue("web_page")); |
| 576 contexts->Append(new base::StringValue("blessed_web_page")); | 576 contexts->Append(new base::StringValue("blessed_web_page")); |
| 577 contexts->Append(new base::StringValue("webui")); | 577 contexts->Append(new base::StringValue("webui")); |
| 578 value->Set("contexts", contexts); | 578 value->Set("contexts", contexts); |
| 579 scoped_ptr<SimpleFeature> feature(new SimpleFeature()); | 579 std::unique_ptr<SimpleFeature> feature(new SimpleFeature()); |
| 580 feature->Parse(value.get()); | 580 feature->Parse(value.get()); |
| 581 EXPECT_EQ(6u, feature->contexts()->size()); | 581 EXPECT_EQ(6u, feature->contexts()->size()); |
| 582 EXPECT_TRUE( | 582 EXPECT_TRUE( |
| 583 STLCount(*(feature->contexts()), Feature::BLESSED_EXTENSION_CONTEXT)); | 583 STLCount(*(feature->contexts()), Feature::BLESSED_EXTENSION_CONTEXT)); |
| 584 EXPECT_TRUE( | 584 EXPECT_TRUE( |
| 585 STLCount(*(feature->contexts()), Feature::UNBLESSED_EXTENSION_CONTEXT)); | 585 STLCount(*(feature->contexts()), Feature::UNBLESSED_EXTENSION_CONTEXT)); |
| 586 EXPECT_TRUE( | 586 EXPECT_TRUE( |
| 587 STLCount(*(feature->contexts()), Feature::CONTENT_SCRIPT_CONTEXT)); | 587 STLCount(*(feature->contexts()), Feature::CONTENT_SCRIPT_CONTEXT)); |
| 588 EXPECT_TRUE( | 588 EXPECT_TRUE( |
| 589 STLCount(*(feature->contexts()), Feature::WEB_PAGE_CONTEXT)); | 589 STLCount(*(feature->contexts()), Feature::WEB_PAGE_CONTEXT)); |
| 590 EXPECT_TRUE( | 590 EXPECT_TRUE( |
| 591 STLCount(*(feature->contexts()), Feature::BLESSED_WEB_PAGE_CONTEXT)); | 591 STLCount(*(feature->contexts()), Feature::BLESSED_WEB_PAGE_CONTEXT)); |
| 592 | 592 |
| 593 value->SetString("contexts", "all"); | 593 value->SetString("contexts", "all"); |
| 594 scoped_ptr<SimpleFeature> feature2(new SimpleFeature()); | 594 std::unique_ptr<SimpleFeature> feature2(new SimpleFeature()); |
| 595 feature2->Parse(value.get()); | 595 feature2->Parse(value.get()); |
| 596 EXPECT_EQ(*(feature->contexts()), *(feature2->contexts())); | 596 EXPECT_EQ(*(feature->contexts()), *(feature2->contexts())); |
| 597 } | 597 } |
| 598 | 598 |
| 599 TEST_F(SimpleFeatureTest, ParseLocation) { | 599 TEST_F(SimpleFeatureTest, ParseLocation) { |
| 600 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | 600 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); |
| 601 value->SetString("location", "component"); | 601 value->SetString("location", "component"); |
| 602 scoped_ptr<SimpleFeature> feature(new SimpleFeature()); | 602 std::unique_ptr<SimpleFeature> feature(new SimpleFeature()); |
| 603 feature->Parse(value.get()); | 603 feature->Parse(value.get()); |
| 604 EXPECT_EQ(SimpleFeature::COMPONENT_LOCATION, feature->location()); | 604 EXPECT_EQ(SimpleFeature::COMPONENT_LOCATION, feature->location()); |
| 605 } | 605 } |
| 606 | 606 |
| 607 TEST_F(SimpleFeatureTest, ParsePlatforms) { | 607 TEST_F(SimpleFeatureTest, ParsePlatforms) { |
| 608 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | 608 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); |
| 609 scoped_ptr<SimpleFeature> feature(new SimpleFeature()); | 609 std::unique_ptr<SimpleFeature> feature(new SimpleFeature()); |
| 610 base::ListValue* platforms = new base::ListValue(); | 610 base::ListValue* platforms = new base::ListValue(); |
| 611 value->Set("platforms", platforms); | 611 value->Set("platforms", platforms); |
| 612 feature->Parse(value.get()); | 612 feature->Parse(value.get()); |
| 613 EXPECT_TRUE(feature->platforms()->empty()); | 613 EXPECT_TRUE(feature->platforms()->empty()); |
| 614 | 614 |
| 615 platforms->AppendString("chromeos"); | 615 platforms->AppendString("chromeos"); |
| 616 feature->Parse(value.get()); | 616 feature->Parse(value.get()); |
| 617 EXPECT_FALSE(feature->platforms()->empty()); | 617 EXPECT_FALSE(feature->platforms()->empty()); |
| 618 EXPECT_EQ(Feature::CHROMEOS_PLATFORM, *feature->platforms()->begin()); | 618 EXPECT_EQ(Feature::CHROMEOS_PLATFORM, *feature->platforms()->begin()); |
| 619 | 619 |
| 620 platforms->Clear(); | 620 platforms->Clear(); |
| 621 platforms->AppendString("win"); | 621 platforms->AppendString("win"); |
| 622 feature->Parse(value.get()); | 622 feature->Parse(value.get()); |
| 623 EXPECT_FALSE(feature->platforms()->empty()); | 623 EXPECT_FALSE(feature->platforms()->empty()); |
| 624 EXPECT_EQ(Feature::WIN_PLATFORM, *feature->platforms()->begin()); | 624 EXPECT_EQ(Feature::WIN_PLATFORM, *feature->platforms()->begin()); |
| 625 | 625 |
| 626 platforms->Clear(); | 626 platforms->Clear(); |
| 627 platforms->AppendString("win"); | 627 platforms->AppendString("win"); |
| 628 platforms->AppendString("chromeos"); | 628 platforms->AppendString("chromeos"); |
| 629 feature->Parse(value.get()); | 629 feature->Parse(value.get()); |
| 630 std::vector<Feature::Platform> expected_platforms; | 630 std::vector<Feature::Platform> expected_platforms; |
| 631 expected_platforms.push_back(Feature::CHROMEOS_PLATFORM); | 631 expected_platforms.push_back(Feature::CHROMEOS_PLATFORM); |
| 632 expected_platforms.push_back(Feature::WIN_PLATFORM); | 632 expected_platforms.push_back(Feature::WIN_PLATFORM); |
| 633 | 633 |
| 634 EXPECT_FALSE(feature->platforms()->empty()); | 634 EXPECT_FALSE(feature->platforms()->empty()); |
| 635 EXPECT_EQ(expected_platforms, *feature->platforms()); | 635 EXPECT_EQ(expected_platforms, *feature->platforms()); |
| 636 } | 636 } |
| 637 | 637 |
| 638 TEST_F(SimpleFeatureTest, ParseManifestVersion) { | 638 TEST_F(SimpleFeatureTest, ParseManifestVersion) { |
| 639 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | 639 std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue()); |
| 640 value->SetInteger("min_manifest_version", 1); | 640 value->SetInteger("min_manifest_version", 1); |
| 641 value->SetInteger("max_manifest_version", 5); | 641 value->SetInteger("max_manifest_version", 5); |
| 642 scoped_ptr<SimpleFeature> feature(new SimpleFeature()); | 642 std::unique_ptr<SimpleFeature> feature(new SimpleFeature()); |
| 643 feature->Parse(value.get()); | 643 feature->Parse(value.get()); |
| 644 EXPECT_EQ(1, feature->min_manifest_version()); | 644 EXPECT_EQ(1, feature->min_manifest_version()); |
| 645 EXPECT_EQ(5, feature->max_manifest_version()); | 645 EXPECT_EQ(5, feature->max_manifest_version()); |
| 646 } | 646 } |
| 647 | 647 |
| 648 TEST_F(SimpleFeatureTest, Inheritance) { | 648 TEST_F(SimpleFeatureTest, Inheritance) { |
| 649 SimpleFeature feature; | 649 SimpleFeature feature; |
| 650 feature.whitelist()->push_back("foo"); | 650 feature.whitelist()->push_back("foo"); |
| 651 feature.extension_types()->push_back(Manifest::TYPE_THEME); | 651 feature.extension_types()->push_back(Manifest::TYPE_THEME); |
| 652 feature.contexts()->push_back(Feature::BLESSED_EXTENSION_CONTEXT); | 652 feature.contexts()->push_back(Feature::BLESSED_EXTENSION_CONTEXT); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 743 EXPECT_FALSE(SimpleFeature::IsIdInArray("", kIdArray, arraysize(kIdArray))); | 743 EXPECT_FALSE(SimpleFeature::IsIdInArray("", kIdArray, arraysize(kIdArray))); |
| 744 EXPECT_FALSE(SimpleFeature::IsIdInArray( | 744 EXPECT_FALSE(SimpleFeature::IsIdInArray( |
| 745 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", kIdArray, arraysize(kIdArray))); | 745 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", kIdArray, arraysize(kIdArray))); |
| 746 EXPECT_TRUE(SimpleFeature::IsIdInArray( | 746 EXPECT_TRUE(SimpleFeature::IsIdInArray( |
| 747 "bbbbccccdddddddddeeeeeeffffgghhh", kIdArray, arraysize(kIdArray))); | 747 "bbbbccccdddddddddeeeeeeffffgghhh", kIdArray, arraysize(kIdArray))); |
| 748 EXPECT_TRUE(SimpleFeature::IsIdInArray( | 748 EXPECT_TRUE(SimpleFeature::IsIdInArray( |
| 749 "aaaabbbbccccddddeeeeffffgggghhhh", kIdArray, arraysize(kIdArray))); | 749 "aaaabbbbccccddddeeeeffffgggghhhh", kIdArray, arraysize(kIdArray))); |
| 750 } | 750 } |
| 751 | 751 |
| 752 } // namespace extensions | 752 } // namespace extensions |
| OLD | NEW |