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