blob: 74bc8af8c738f2891af3b9b6e1b2699ca41c884e [file] [log] [blame]
[email protected]2edc2862011-04-04 18:04:371// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]5c08f222010-09-22 09:37:212// 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]2edc2862011-04-04 18:04:377#include "base/basictypes.h"
[email protected]5c08f222010-09-22 09:37:218#include "base/command_line.h"
[email protected]a40ca4302011-05-14 01:10:249#include "base/file_path.h"
[email protected]5c08f222010-09-22 09:37:2110#include "testing/gtest/include/gtest/gtest.h"
11
12TEST(SwitchUtilsTest, RemoveSwitches) {
[email protected]a40ca4302011-05-14 01:10:2413 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]61a4c6f2011-07-20 04:54:5223 EXPECT_FALSE(cmd_line.GetCommandLineString().empty());
[email protected]a40ca4302011-05-14 01:10:2424
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]5c08f222010-09-22 09:37:2135#if defined(OS_WIN)
[email protected]a40ca4302011-05-14 01:10:2436TEST(SwitchUtilsTest, RemoveSwitchesFromString) {
[email protected]5c08f222010-09-22 09:37:2137 // 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]61a4c6f2011-07-20 04:54:5248 EXPECT_FALSE(cmd_line.GetCommandLineString().empty());
[email protected]5c08f222010-09-22 09:37:2149
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]a40ca4302011-05-14 01:10:2459#endif