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
3// found in the LICENSE file.
4
5#include "chrome/common/switch_utils.h"
6
7#include "base/basictypes.h"
8#include "base/command_line.h"
9#include "testing/gtest/include/gtest/gtest.h"
10
11TEST(SwitchUtilsTest, RemoveSwitches) {
12#if defined(OS_WIN)
13  // All these command line args (except foo and bar) will
14  // be removed after RemoveSwitchesForAutostart:
15  CommandLine cmd_line = CommandLine::FromString(
16      L"program"
17      L" --app=http://www.google.com/"
18      L" --first-run"
19      L" --import"
20      L" --import-from-file=c:\\test.html"
21      L" --make-default-browser"
22      L" --foo"
23      L" --bar");
24  EXPECT_FALSE(cmd_line.command_line_string().empty());
25#elif defined(OS_POSIX)
26  const char* argv[] = {
27    "program",
28    "--app=http://www.google.com/",
29    "--first-run",
30    "--import",
31    "--import-from-file=c:\\test.html",
32    "--make-default-browser",
33    "--foo",
34    "--bar"};
35  CommandLine cmd_line(arraysize(argv), argv);
36#endif
37
38  std::map<std::string, CommandLine::StringType> switches =
39      cmd_line.GetSwitches();
40  EXPECT_EQ(7U, switches.size());
41
42  switches::RemoveSwitchesForAutostart(&switches);
43  EXPECT_EQ(2U, switches.size());
44  EXPECT_TRUE(cmd_line.HasSwitch("foo"));
45  EXPECT_TRUE(cmd_line.HasSwitch("bar"));
46}
47