| 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 |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 14 #include "base/test/command_line_test_util.h" |
| 14 #include "base/values.h" | 15 #include "base/values.h" |
| 15 #include "extensions/common/manifest.h" | 16 #include "extensions/common/manifest.h" |
| 16 #include "extensions/common/value_builder.h" | 17 #include "extensions/common/value_builder.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 19 |
| 19 namespace extensions { | 20 namespace extensions { |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 struct IsAvailableTestData { | 24 struct IsAvailableTestData { |
| 24 std::string extension_id; | 25 std::string extension_id; |
| 25 Manifest::Type extension_type; | 26 Manifest::Type extension_type; |
| 26 Manifest::Location location; | 27 Manifest::Location location; |
| 27 Feature::Platform platform; | 28 Feature::Platform platform; |
| 28 int manifest_version; | 29 int manifest_version; |
| 29 Feature::AvailabilityResult expected_result; | 30 Feature::AvailabilityResult expected_result; |
| 30 }; | 31 }; |
| 31 | 32 |
| 32 class ScopedCommandLineSwitch { | |
| 33 public: | |
| 34 explicit ScopedCommandLineSwitch(const std::string& arg) | |
| 35 : original_command_line_(*base::CommandLine::ForCurrentProcess()) { | |
| 36 base::CommandLine::ForCurrentProcess()->AppendSwitch(arg); | |
| 37 } | |
| 38 | |
| 39 ~ScopedCommandLineSwitch() { | |
| 40 *base::CommandLine::ForCurrentProcess() = original_command_line_; | |
| 41 } | |
| 42 | |
| 43 private: | |
| 44 base::CommandLine original_command_line_; | |
| 45 }; | |
| 46 | |
| 47 } // namespace | 33 } // namespace |
| 48 | 34 |
| 49 class SimpleFeatureTest : public testing::Test { | 35 class SimpleFeatureTest : public testing::Test { |
| 50 protected: | 36 protected: |
| 51 bool LocationIsAvailable(SimpleFeature::Location feature_location, | 37 bool LocationIsAvailable(SimpleFeature::Location feature_location, |
| 52 Manifest::Location manifest_location) { | 38 Manifest::Location manifest_location) { |
| 53 SimpleFeature feature; | 39 SimpleFeature feature; |
| 54 feature.set_location(feature_location); | 40 feature.set_location(feature_location); |
| 55 Feature::AvailabilityResult availability_result = | 41 Feature::AvailabilityResult availability_result = |
| 56 feature.IsAvailableToManifest(std::string(), | 42 feature.IsAvailableToManifest(std::string(), |
| (...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 697 } | 683 } |
| 698 | 684 |
| 699 TEST_F(SimpleFeatureTest, CommandLineSwitch) { | 685 TEST_F(SimpleFeatureTest, CommandLineSwitch) { |
| 700 SimpleFeature feature; | 686 SimpleFeature feature; |
| 701 feature.set_command_line_switch("laser-beams"); | 687 feature.set_command_line_switch("laser-beams"); |
| 702 { | 688 { |
| 703 EXPECT_EQ(Feature::MISSING_COMMAND_LINE_SWITCH, | 689 EXPECT_EQ(Feature::MISSING_COMMAND_LINE_SWITCH, |
| 704 feature.IsAvailableToEnvironment().result()); | 690 feature.IsAvailableToEnvironment().result()); |
| 705 } | 691 } |
| 706 { | 692 { |
| 707 ScopedCommandLineSwitch scoped_switch("laser-beams"); | 693 base::test::ScopedCommandLine scoped_command_line; |
| 694 scoped_command_line.GetProcessCommandLine()->AppendSwitch("laser-beams"); |
| 708 EXPECT_EQ(Feature::MISSING_COMMAND_LINE_SWITCH, | 695 EXPECT_EQ(Feature::MISSING_COMMAND_LINE_SWITCH, |
| 709 feature.IsAvailableToEnvironment().result()); | 696 feature.IsAvailableToEnvironment().result()); |
| 710 } | 697 } |
| 711 { | 698 { |
| 712 ScopedCommandLineSwitch scoped_switch("enable-laser-beams"); | 699 base::test::ScopedCommandLine scoped_command_line; |
| 700 scoped_command_line.GetProcessCommandLine()->AppendSwitch( |
| 701 "enable-laser-beams"); |
| 713 EXPECT_EQ(Feature::IS_AVAILABLE, | 702 EXPECT_EQ(Feature::IS_AVAILABLE, |
| 714 feature.IsAvailableToEnvironment().result()); | 703 feature.IsAvailableToEnvironment().result()); |
| 715 } | 704 } |
| 716 { | 705 { |
| 717 ScopedCommandLineSwitch scoped_switch("disable-laser-beams"); | 706 base::test::ScopedCommandLine scoped_command_line; |
| 707 scoped_command_line.GetProcessCommandLine()->AppendSwitch( |
| 708 "disable-laser-beams"); |
| 718 EXPECT_EQ(Feature::MISSING_COMMAND_LINE_SWITCH, | 709 EXPECT_EQ(Feature::MISSING_COMMAND_LINE_SWITCH, |
| 719 feature.IsAvailableToEnvironment().result()); | 710 feature.IsAvailableToEnvironment().result()); |
| 720 } | 711 } |
| 721 { | 712 { |
| 722 ScopedCommandLineSwitch scoped_switch("laser-beams=1"); | 713 base::test::ScopedCommandLine scoped_command_line; |
| 714 scoped_command_line.GetProcessCommandLine()->AppendSwitch("laser-beams=1"); |
| 723 EXPECT_EQ(Feature::IS_AVAILABLE, | 715 EXPECT_EQ(Feature::IS_AVAILABLE, |
| 724 feature.IsAvailableToEnvironment().result()); | 716 feature.IsAvailableToEnvironment().result()); |
| 725 } | 717 } |
| 726 { | 718 { |
| 727 ScopedCommandLineSwitch scoped_switch("laser-beams=0"); | 719 base::test::ScopedCommandLine scoped_command_line; |
| 720 scoped_command_line.GetProcessCommandLine()->AppendSwitch("laser-beams=0"); |
| 728 EXPECT_EQ(Feature::MISSING_COMMAND_LINE_SWITCH, | 721 EXPECT_EQ(Feature::MISSING_COMMAND_LINE_SWITCH, |
| 729 feature.IsAvailableToEnvironment().result()); | 722 feature.IsAvailableToEnvironment().result()); |
| 730 } | 723 } |
| 731 } | 724 } |
| 732 | 725 |
| 733 TEST_F(SimpleFeatureTest, IsIdInArray) { | 726 TEST_F(SimpleFeatureTest, IsIdInArray) { |
| 734 EXPECT_FALSE(SimpleFeature::IsIdInArray("", {}, 0)); | 727 EXPECT_FALSE(SimpleFeature::IsIdInArray("", {}, 0)); |
| 735 EXPECT_FALSE(SimpleFeature::IsIdInArray( | 728 EXPECT_FALSE(SimpleFeature::IsIdInArray( |
| 736 "bbbbccccdddddddddeeeeeeffffgghhh", {}, 0)); | 729 "bbbbccccdddddddddeeeeeeffffgghhh", {}, 0)); |
| 737 | 730 |
| 738 const char* const kIdArray[] = { | 731 const char* const kIdArray[] = { |
| 739 "bbbbccccdddddddddeeeeeeffffgghhh", | 732 "bbbbccccdddddddddeeeeeeffffgghhh", |
| 740 // aaaabbbbccccddddeeeeffffgggghhhh | 733 // aaaabbbbccccddddeeeeffffgggghhhh |
| 741 "9A0417016F345C934A1A88F55CA17C05014EEEBA" | 734 "9A0417016F345C934A1A88F55CA17C05014EEEBA" |
| 742 }; | 735 }; |
| 743 EXPECT_FALSE(SimpleFeature::IsIdInArray("", kIdArray, arraysize(kIdArray))); | 736 EXPECT_FALSE(SimpleFeature::IsIdInArray("", kIdArray, arraysize(kIdArray))); |
| 744 EXPECT_FALSE(SimpleFeature::IsIdInArray( | 737 EXPECT_FALSE(SimpleFeature::IsIdInArray( |
| 745 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", kIdArray, arraysize(kIdArray))); | 738 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", kIdArray, arraysize(kIdArray))); |
| 746 EXPECT_TRUE(SimpleFeature::IsIdInArray( | 739 EXPECT_TRUE(SimpleFeature::IsIdInArray( |
| 747 "bbbbccccdddddddddeeeeeeffffgghhh", kIdArray, arraysize(kIdArray))); | 740 "bbbbccccdddddddddeeeeeeffffgghhh", kIdArray, arraysize(kIdArray))); |
| 748 EXPECT_TRUE(SimpleFeature::IsIdInArray( | 741 EXPECT_TRUE(SimpleFeature::IsIdInArray( |
| 749 "aaaabbbbccccddddeeeeffffgggghhhh", kIdArray, arraysize(kIdArray))); | 742 "aaaabbbbccccddddeeeeffffgggghhhh", kIdArray, arraysize(kIdArray))); |
| 750 } | 743 } |
| 751 | 744 |
| 752 } // namespace extensions | 745 } // namespace extensions |
| OLD | NEW |