Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(159)

Side by Side Diff: extensions/common/features/simple_feature_unittest.cc

Issue 801603002: Add support for command line switches to Features, and as proof that it works, (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: test fixes Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « extensions/common/features/simple_feature.cc ('k') | extensions/common/manifest_constants.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <string> 7 #include <string>
8 8
9 #include "base/command_line.h"
9 #include "base/values.h" 10 #include "base/values.h"
10 #include "extensions/common/manifest.h" 11 #include "extensions/common/manifest.h"
11 #include "extensions/common/value_builder.h" 12 #include "extensions/common/value_builder.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 14
14 namespace extensions { 15 namespace extensions {
15 16
16 namespace { 17 namespace {
17 18
18 struct IsAvailableTestData { 19 struct IsAvailableTestData {
(...skipping 11 matching lines...) Expand all
30 feature.set_location(feature_location); 31 feature.set_location(feature_location);
31 Feature::AvailabilityResult availability_result = 32 Feature::AvailabilityResult availability_result =
32 feature.IsAvailableToManifest(std::string(), 33 feature.IsAvailableToManifest(std::string(),
33 Manifest::TYPE_UNKNOWN, 34 Manifest::TYPE_UNKNOWN,
34 manifest_location, 35 manifest_location,
35 -1, 36 -1,
36 Feature::UNSPECIFIED_PLATFORM).result(); 37 Feature::UNSPECIFIED_PLATFORM).result();
37 return availability_result == Feature::IS_AVAILABLE; 38 return availability_result == Feature::IS_AVAILABLE;
38 } 39 }
39 40
41 class ScopedCommandLineSwitch {
42 public:
43 explicit ScopedCommandLineSwitch(const std::string& arg)
44 : original_command_line_(*base::CommandLine::ForCurrentProcess()) {
45 base::CommandLine::ForCurrentProcess()->AppendSwitch(arg);
46 }
47
48 ~ScopedCommandLineSwitch() {
49 *base::CommandLine::ForCurrentProcess() = original_command_line_;
50 }
51
52 private:
53 base::CommandLine original_command_line_;
54 };
55
40 } // namespace 56 } // namespace
41 57
42 TEST(SimpleFeatureTest, IsAvailableNullCase) { 58 TEST(SimpleFeatureTest, IsAvailableNullCase) {
43 const IsAvailableTestData tests[] = { 59 const IsAvailableTestData tests[] = {
44 {"", Manifest::TYPE_UNKNOWN, Manifest::INVALID_LOCATION, 60 {"", Manifest::TYPE_UNKNOWN, Manifest::INVALID_LOCATION,
45 Feature::UNSPECIFIED_PLATFORM, -1, Feature::IS_AVAILABLE}, 61 Feature::UNSPECIFIED_PLATFORM, -1, Feature::IS_AVAILABLE},
46 {"random-extension", Manifest::TYPE_UNKNOWN, Manifest::INVALID_LOCATION, 62 {"random-extension", Manifest::TYPE_UNKNOWN, Manifest::INVALID_LOCATION,
47 Feature::UNSPECIFIED_PLATFORM, -1, Feature::IS_AVAILABLE}, 63 Feature::UNSPECIFIED_PLATFORM, -1, Feature::IS_AVAILABLE},
48 {"", Manifest::TYPE_LEGACY_PACKAGED_APP, Manifest::INVALID_LOCATION, 64 {"", Manifest::TYPE_LEGACY_PACKAGED_APP, Manifest::INVALID_LOCATION,
49 Feature::UNSPECIFIED_PLATFORM, -1, Feature::IS_AVAILABLE}, 65 Feature::UNSPECIFIED_PLATFORM, -1, Feature::IS_AVAILABLE},
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 EXPECT_EQ(1u, feature.extension_types()->size()); 658 EXPECT_EQ(1u, feature.extension_types()->size());
643 EXPECT_EQ(1u, feature.contexts()->size()); 659 EXPECT_EQ(1u, feature.contexts()->size());
644 EXPECT_EQ(1u, feature.whitelist()->count("bar")); 660 EXPECT_EQ(1u, feature.whitelist()->count("bar"));
645 EXPECT_EQ(1u, feature.extension_types()->count(Manifest::TYPE_EXTENSION)); 661 EXPECT_EQ(1u, feature.extension_types()->count(Manifest::TYPE_EXTENSION));
646 EXPECT_EQ(1u, 662 EXPECT_EQ(1u,
647 feature.contexts()->count(Feature::UNBLESSED_EXTENSION_CONTEXT)); 663 feature.contexts()->count(Feature::UNBLESSED_EXTENSION_CONTEXT));
648 EXPECT_EQ(2, feature.min_manifest_version()); 664 EXPECT_EQ(2, feature.min_manifest_version());
649 EXPECT_EQ(3, feature.max_manifest_version()); 665 EXPECT_EQ(3, feature.max_manifest_version());
650 } 666 }
651 667
668 TEST(SimpleFeatureTest, CommandLineSwitch) {
669 SimpleFeature feature;
670 feature.set_command_line_switch("laser-beams");
671 {
672 EXPECT_EQ(Feature::MISSING_COMMAND_LINE_SWITCH,
673 feature.IsAvailableToEnvironment().result());
674 }
675 {
676 ScopedCommandLineSwitch scoped_switch("laser-beams");
677 EXPECT_EQ(Feature::MISSING_COMMAND_LINE_SWITCH,
678 feature.IsAvailableToEnvironment().result());
679 }
680 {
681 ScopedCommandLineSwitch scoped_switch("enable-laser-beams");
682 EXPECT_EQ(Feature::IS_AVAILABLE,
683 feature.IsAvailableToEnvironment().result());
684 }
685 {
686 ScopedCommandLineSwitch scoped_switch("disable-laser-beams");
687 EXPECT_EQ(Feature::MISSING_COMMAND_LINE_SWITCH,
688 feature.IsAvailableToEnvironment().result());
689 }
690 {
691 ScopedCommandLineSwitch scoped_switch("laser-beams=1");
692 EXPECT_EQ(Feature::IS_AVAILABLE,
693 feature.IsAvailableToEnvironment().result());
694 }
695 {
696 ScopedCommandLineSwitch scoped_switch("laser-beams=0");
697 EXPECT_EQ(Feature::MISSING_COMMAND_LINE_SWITCH,
698 feature.IsAvailableToEnvironment().result());
699 }
700 }
701
652 } // namespace extensions 702 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/common/features/simple_feature.cc ('k') | extensions/common/manifest_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698