| 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/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 11 |
| 12 TEST(SwitchUtilsTest, RemoveSwitches) { | 12 TEST(SwitchUtilsTest, RemoveSwitches) { |
| 13 const CommandLine::CharType* argv[] = { | 13 const CommandLine::CharType* argv[] = { |
| 14 FILE_PATH_LITERAL("program"), | 14 FILE_PATH_LITERAL("program"), |
| 15 FILE_PATH_LITERAL("--app=http://www.google.com/"), | 15 FILE_PATH_LITERAL("--app=http://www.google.com/"), |
| 16 FILE_PATH_LITERAL("--force-first-run"), | 16 FILE_PATH_LITERAL("--force-first-run"), |
| 17 FILE_PATH_LITERAL("--import"), | |
| 18 FILE_PATH_LITERAL("--import-from-file=c:\\test.html"), | |
| 19 FILE_PATH_LITERAL("--make-default-browser"), | 17 FILE_PATH_LITERAL("--make-default-browser"), |
| 20 FILE_PATH_LITERAL("--foo"), | 18 FILE_PATH_LITERAL("--foo"), |
| 21 FILE_PATH_LITERAL("--bar")}; | 19 FILE_PATH_LITERAL("--bar")}; |
| 22 CommandLine cmd_line(arraysize(argv), argv); | 20 CommandLine cmd_line(arraysize(argv), argv); |
| 23 EXPECT_FALSE(cmd_line.GetCommandLineString().empty()); | 21 EXPECT_FALSE(cmd_line.GetCommandLineString().empty()); |
| 24 | 22 |
| 25 std::map<std::string, CommandLine::StringType> switches = | 23 std::map<std::string, CommandLine::StringType> switches = |
| 26 cmd_line.GetSwitches(); | 24 cmd_line.GetSwitches(); |
| 27 EXPECT_EQ(7U, switches.size()); | 25 EXPECT_EQ(5U, switches.size()); |
| 28 | 26 |
| 29 switches::RemoveSwitchesForAutostart(&switches); | 27 switches::RemoveSwitchesForAutostart(&switches); |
| 30 EXPECT_EQ(2U, switches.size()); | 28 EXPECT_EQ(2U, switches.size()); |
| 31 EXPECT_TRUE(cmd_line.HasSwitch("foo")); | 29 EXPECT_TRUE(cmd_line.HasSwitch("foo")); |
| 32 EXPECT_TRUE(cmd_line.HasSwitch("bar")); | 30 EXPECT_TRUE(cmd_line.HasSwitch("bar")); |
| 33 } | 31 } |
| 34 | 32 |
| 35 #if defined(OS_WIN) | 33 #if defined(OS_WIN) |
| 36 TEST(SwitchUtilsTest, RemoveSwitchesFromString) { | 34 TEST(SwitchUtilsTest, RemoveSwitchesFromString) { |
| 37 // All these command line args (except foo and bar) will | 35 // All these command line args (except foo and bar) will |
| 38 // be removed after RemoveSwitchesForAutostart: | 36 // be removed after RemoveSwitchesForAutostart: |
| 39 CommandLine cmd_line = CommandLine::FromString( | 37 CommandLine cmd_line = CommandLine::FromString( |
| 40 L"program" | 38 L"program" |
| 41 L" --app=http://www.google.com/" | 39 L" --app=http://www.google.com/" |
| 42 L" --force-first-run" | 40 L" --force-first-run" |
| 43 L" --import" | |
| 44 L" --import-from-file=c:\\test.html" | |
| 45 L" --make-default-browser" | 41 L" --make-default-browser" |
| 46 L" --foo" | 42 L" --foo" |
| 47 L" --bar"); | 43 L" --bar"); |
| 48 EXPECT_FALSE(cmd_line.GetCommandLineString().empty()); | 44 EXPECT_FALSE(cmd_line.GetCommandLineString().empty()); |
| 49 | 45 |
| 50 std::map<std::string, CommandLine::StringType> switches = | 46 std::map<std::string, CommandLine::StringType> switches = |
| 51 cmd_line.GetSwitches(); | 47 cmd_line.GetSwitches(); |
| 52 EXPECT_EQ(7U, switches.size()); | 48 EXPECT_EQ(5U, switches.size()); |
| 53 | 49 |
| 54 switches::RemoveSwitchesForAutostart(&switches); | 50 switches::RemoveSwitchesForAutostart(&switches); |
| 55 EXPECT_EQ(2U, switches.size()); | 51 EXPECT_EQ(2U, switches.size()); |
| 56 EXPECT_TRUE(cmd_line.HasSwitch("foo")); | 52 EXPECT_TRUE(cmd_line.HasSwitch("foo")); |
| 57 EXPECT_TRUE(cmd_line.HasSwitch("bar")); | 53 EXPECT_TRUE(cmd_line.HasSwitch("bar")); |
| 58 } | 54 } |
| 59 #endif | 55 #endif |
| OLD | NEW |