OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "android_webview/browser/command_line_helper.h" |
| 6 |
| 7 #include "base/command_line.h" |
| 8 #include "base/feature_list.h" |
| 9 #include "base/files/file_path.h" |
| 10 #include "content/public/common/content_switches.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 |
| 13 using testing::Test; |
| 14 using base::CommandLine; |
| 15 |
| 16 const base::Feature kSomeSpecialFeature{"SomeSpecialFeature", |
| 17 base::FEATURE_DISABLED_BY_DEFAULT}; |
| 18 |
| 19 class CommandLineHelperTest : public Test { |
| 20 public: |
| 21 CommandLineHelperTest() {} |
| 22 |
| 23 void AddFeatureAndVerify(CommandLine& command_line, |
| 24 const std::string& enabled_expected, |
| 25 const std::string& disabled_expected) { |
| 26 CommandLineHelper::AddEnabledFeature(command_line, |
| 27 kSomeSpecialFeature.name); |
| 28 EXPECT_EQ(enabled_expected, |
| 29 command_line.GetSwitchValueASCII(switches::kEnableFeatures)); |
| 30 EXPECT_EQ(disabled_expected, |
| 31 command_line.GetSwitchValueASCII(switches::kDisableFeatures)); |
| 32 } |
| 33 }; |
| 34 |
| 35 TEST_F(CommandLineHelperTest, AddWithEmptyCommandLine) { |
| 36 CommandLine command_line(CommandLine::NO_PROGRAM); |
| 37 AddFeatureAndVerify(command_line, "SomeSpecialFeature", ""); |
| 38 } |
| 39 |
| 40 TEST_F(CommandLineHelperTest, AddWithNoEnabledFeatures) { |
| 41 const CommandLine::CharType* argv[] = {FILE_PATH_LITERAL("program")}; |
| 42 CommandLine command_line(arraysize(argv), argv); |
| 43 AddFeatureAndVerify(command_line, "SomeSpecialFeature", ""); |
| 44 } |
| 45 |
| 46 TEST_F(CommandLineHelperTest, AddWithEnabledTestFeature) { |
| 47 const CommandLine::CharType* argv[] = { |
| 48 FILE_PATH_LITERAL("program"), |
| 49 FILE_PATH_LITERAL("--enable-features=TestFeature")}; |
| 50 CommandLine command_line(arraysize(argv), argv); |
| 51 AddFeatureAndVerify(command_line, "TestFeature,SomeSpecialFeature", ""); |
| 52 } |
| 53 |
| 54 TEST_F(CommandLineHelperTest, AddWithEnabledSomeSpecialFeature) { |
| 55 const CommandLine::CharType* argv[] = { |
| 56 FILE_PATH_LITERAL("program"), |
| 57 FILE_PATH_LITERAL("--enable-features=SomeSpecialFeature,TestFeature")}; |
| 58 CommandLine command_line(arraysize(argv), argv); |
| 59 AddFeatureAndVerify(command_line, "SomeSpecialFeature,TestFeature", ""); |
| 60 } |
| 61 |
| 62 TEST_F(CommandLineHelperTest, AddWithDisabledSomeSpecialFeature) { |
| 63 const CommandLine::CharType* argv[] = { |
| 64 FILE_PATH_LITERAL("program"), |
| 65 FILE_PATH_LITERAL("--disable-features=SomeSpecialFeature")}; |
| 66 CommandLine command_line(arraysize(argv), argv); |
| 67 AddFeatureAndVerify(command_line, "", "SomeSpecialFeature"); |
| 68 } |
| 69 |
| 70 TEST_F(CommandLineHelperTest, AddWithDisabledTestFeature) { |
| 71 const CommandLine::CharType* argv[] = { |
| 72 FILE_PATH_LITERAL("program"), |
| 73 FILE_PATH_LITERAL("--disable-features=TestFeature")}; |
| 74 CommandLine command_line(arraysize(argv), argv); |
| 75 AddFeatureAndVerify(command_line, "SomeSpecialFeature", "TestFeature"); |
| 76 } |
OLD | NEW |