Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/common/switch_utils.h" | 5 #include "chrome/common/switch_utils.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 TEST(SwitchUtilsTest, RemoveSwitches) { | 13 TEST(SwitchUtilsTest, RemoveSwitches) { |
| 14 const base::CommandLine::CharType* argv[] = { | 14 static const base::CommandLine::CharType* argv[] = { |
| 15 FILE_PATH_LITERAL("program"), | 15 FILE_PATH_LITERAL("program"), |
| 16 FILE_PATH_LITERAL("--app=http://www.google.com/"), | 16 FILE_PATH_LITERAL("--app=http://www.google.com/"), |
| 17 FILE_PATH_LITERAL("--force-first-run"), | 17 FILE_PATH_LITERAL("--force-first-run"), |
| 18 FILE_PATH_LITERAL("--make-default-browser"), | 18 FILE_PATH_LITERAL("--make-default-browser"), |
| 19 FILE_PATH_LITERAL("--foo"), | 19 FILE_PATH_LITERAL("--foo"), |
| 20 FILE_PATH_LITERAL("--bar")}; | 20 FILE_PATH_LITERAL("--bar")}; |
| 21 base::CommandLine cmd_line(arraysize(argv), argv); | 21 base::CommandLine cmd_line(arraysize(argv), argv); |
| 22 EXPECT_FALSE(cmd_line.GetCommandLineString().empty()); | 22 EXPECT_FALSE(cmd_line.GetCommandLineString().empty()); |
| 23 | 23 |
| 24 std::map<std::string, base::CommandLine::StringType> switches = | 24 std::map<std::string, base::CommandLine::StringType> switches = |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 46 | 46 |
| 47 std::map<std::string, base::CommandLine::StringType> switches = | 47 std::map<std::string, base::CommandLine::StringType> switches = |
| 48 cmd_line.GetSwitches(); | 48 cmd_line.GetSwitches(); |
| 49 EXPECT_EQ(5U, switches.size()); | 49 EXPECT_EQ(5U, switches.size()); |
| 50 | 50 |
| 51 switches::RemoveSwitchesForAutostart(&switches); | 51 switches::RemoveSwitchesForAutostart(&switches); |
| 52 EXPECT_EQ(2U, switches.size()); | 52 EXPECT_EQ(2U, switches.size()); |
| 53 EXPECT_TRUE(cmd_line.HasSwitch("foo")); | 53 EXPECT_TRUE(cmd_line.HasSwitch("foo")); |
| 54 EXPECT_TRUE(cmd_line.HasSwitch("bar")); | 54 EXPECT_TRUE(cmd_line.HasSwitch("bar")); |
| 55 } | 55 } |
| 56 | |
| 57 TEST(SwitchUtilsTest, RemovePrefetchSwitch) { | |
| 58 static const base::CommandLine::CharType* argv[] = { | |
| 59 FILE_PATH_LITERAL("program"), | |
| 60 FILE_PATH_LITERAL("--foo"), | |
| 61 FILE_PATH_LITERAL("/prefetch:1"), | |
| 62 FILE_PATH_LITERAL("--bar")}; | |
| 63 base::CommandLine cmd_line(arraysize(argv), argv); | |
| 64 EXPECT_FALSE(cmd_line.GetCommandLineString().empty()); | |
| 65 | |
| 66 std::map<std::string, base::CommandLine::StringType> switches = | |
| 67 cmd_line.GetSwitches(); | |
| 68 EXPECT_EQ(3U, switches.size()); | |
| 69 | |
| 70 switches::RemoveSwitchesForAutostart(&switches); | |
| 71 EXPECT_EQ(2U, switches.size()); | |
| 72 EXPECT_TRUE(cmd_line.HasSwitch("foo")); | |
| 73 EXPECT_TRUE(cmd_line.HasSwitch("bar")); | |
| 74 } | |
| 75 | |
| 76 TEST(SwitchUtilsTest, RemovePrefetchSwitches) { | |
| 77 static const base::CommandLine::CharType* argv[] = { | |
| 78 FILE_PATH_LITERAL("program"), | |
| 79 FILE_PATH_LITERAL("--foo"), | |
| 80 FILE_PATH_LITERAL("/prefetch:1"), | |
| 81 FILE_PATH_LITERAL("/prefetch:2"), | |
|
gab
2016/02/25 20:22:23
As mentioned above, don't think we should support
fdoray
2016/02/26 18:10:36
Done.
| |
| 82 FILE_PATH_LITERAL("--bar")}; | |
| 83 base::CommandLine cmd_line(arraysize(argv), argv); | |
| 84 EXPECT_FALSE(cmd_line.GetCommandLineString().empty()); | |
| 85 | |
| 86 std::map<std::string, base::CommandLine::StringType> switches = | |
| 87 cmd_line.GetSwitches(); | |
| 88 EXPECT_EQ(4U, switches.size()); | |
| 89 | |
| 90 switches::RemoveSwitchesForAutostart(&switches); | |
| 91 EXPECT_EQ(2U, switches.size()); | |
| 92 EXPECT_TRUE(cmd_line.HasSwitch("foo")); | |
| 93 EXPECT_TRUE(cmd_line.HasSwitch("bar")); | |
| 94 } | |
| 95 | |
| 96 TEST(SwitchUtilsTest, RemovePrefetchSwitchAndNormalSwitch) { | |
| 97 static const base::CommandLine::CharType* argv[] = { | |
| 98 FILE_PATH_LITERAL("program"), | |
| 99 FILE_PATH_LITERAL("--foo"), | |
| 100 FILE_PATH_LITERAL("/prefetch:1"), | |
| 101 FILE_PATH_LITERAL("--force-first-run"), | |
| 102 FILE_PATH_LITERAL("--bar")}; | |
| 103 base::CommandLine cmd_line(arraysize(argv), argv); | |
| 104 EXPECT_FALSE(cmd_line.GetCommandLineString().empty()); | |
| 105 | |
| 106 std::map<std::string, base::CommandLine::StringType> switches = | |
| 107 cmd_line.GetSwitches(); | |
| 108 EXPECT_EQ(4U, switches.size()); | |
| 109 | |
| 110 switches::RemoveSwitchesForAutostart(&switches); | |
| 111 EXPECT_EQ(2U, switches.size()); | |
| 112 EXPECT_TRUE(cmd_line.HasSwitch("foo")); | |
| 113 EXPECT_TRUE(cmd_line.HasSwitch("bar")); | |
| 114 } | |
| 56 #endif | 115 #endif |
| OLD | NEW |