Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: chrome/common/switch_utils_unittest.cc

Issue 6526040: CommandLine refactoring and cleanup. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Test Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 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/file_path.h"
8 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
9 10
10 TEST(SwitchUtilsTest, RemoveSwitches) { 11 TEST(SwitchUtilsTest, RemoveSwitches) {
12 const CommandLine::CharType* argv[] = {
13 FILE_PATH_LITERAL("program"),
14 FILE_PATH_LITERAL("--app=http://www.google.com/"),
15 FILE_PATH_LITERAL("--first-run"),
16 FILE_PATH_LITERAL("--import"),
17 FILE_PATH_LITERAL("--import-from-file=c:\\test.html"),
18 FILE_PATH_LITERAL("--make-default-browser"),
19 FILE_PATH_LITERAL("--foo"),
20 FILE_PATH_LITERAL("--bar")};
21 CommandLine cmd_line(arraysize(argv), argv);
22 EXPECT_FALSE(cmd_line.command_line_string().empty());
23
24 std::map<std::string, CommandLine::StringType> switches =
25 cmd_line.GetSwitches();
26 EXPECT_EQ(7U, switches.size());
27
28 switches::RemoveSwitchesForAutostart(&switches);
29 EXPECT_EQ(2U, switches.size());
30 EXPECT_TRUE(cmd_line.HasSwitch("foo"));
31 EXPECT_TRUE(cmd_line.HasSwitch("bar"));
32 }
33
11 #if defined(OS_WIN) 34 #if defined(OS_WIN)
35 TEST(SwitchUtilsTest, RemoveSwitchesFromString) {
12 // All these command line args (except foo and bar) will 36 // All these command line args (except foo and bar) will
13 // be removed after RemoveSwitchesForAutostart: 37 // be removed after RemoveSwitchesForAutostart:
14 CommandLine cmd_line = CommandLine::FromString( 38 CommandLine cmd_line = CommandLine::FromString(
15 L"program" 39 L"program"
16 L" --app=http://www.google.com/" 40 L" --app=http://www.google.com/"
17 L" --first-run" 41 L" --first-run"
18 L" --import" 42 L" --import"
19 L" --import-from-file=c:\\test.html" 43 L" --import-from-file=c:\\test.html"
20 L" --make-default-browser" 44 L" --make-default-browser"
21 L" --foo" 45 L" --foo"
22 L" --bar"); 46 L" --bar");
23 EXPECT_FALSE(cmd_line.command_line_string().empty()); 47 EXPECT_FALSE(cmd_line.command_line_string().empty());
24 #elif defined(OS_POSIX)
25 const char* argv[] = {
26 "program",
27 "--app=http://www.google.com/",
28 "--first-run",
29 "--import",
30 "--import-from-file=c:\\test.html",
31 "--make-default-browser",
32 "--foo",
33 "--bar"};
34 CommandLine cmd_line(arraysize(argv), argv);
35 #endif
36 48
37 std::map<std::string, CommandLine::StringType> switches = 49 std::map<std::string, CommandLine::StringType> switches =
38 cmd_line.GetSwitches(); 50 cmd_line.GetSwitches();
39 EXPECT_EQ(7U, switches.size()); 51 EXPECT_EQ(7U, switches.size());
40 52
41 switches::RemoveSwitchesForAutostart(&switches); 53 switches::RemoveSwitchesForAutostart(&switches);
42 EXPECT_EQ(2U, switches.size()); 54 EXPECT_EQ(2U, switches.size());
43 EXPECT_TRUE(cmd_line.HasSwitch("foo")); 55 EXPECT_TRUE(cmd_line.HasSwitch("foo"));
44 EXPECT_TRUE(cmd_line.HasSwitch("bar")); 56 EXPECT_TRUE(cmd_line.HasSwitch("bar"));
45 } 57 }
58 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698