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

Side by Side Diff: chrome_frame/chrome_launcher_unittest.cc

Issue 2278003: Rewrite of chrome_launcher.exe. ETW-based perf tests suggest that this is on ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 6 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
« no previous file with comments | « chrome_frame/chrome_launcher_main.cc ('k') | chrome_frame/chrome_launcher_utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "chrome/common/chrome_switches.h" 7 #include "chrome/common/chrome_switches.h"
8 #include "chrome_frame/chrome_launcher.h" 8 #include "chrome_frame/chrome_launcher.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
11 namespace { 11 TEST(ChromeLauncher, IsValidCommandLine) {
12
13 // Utility class to disable logging. Required to disable DCHECKs that some
14 // of our tests would otherwise trigger.
15 class LogDisabler {
16 public:
17 LogDisabler() {
18 initial_log_level_ = logging::GetMinLogLevel();
19 logging::SetMinLogLevel(logging::LOG_FATAL + 1);
20 }
21
22 ~LogDisabler() {
23 logging::SetMinLogLevel(initial_log_level_);
24 }
25
26 private:
27 int initial_log_level_;
28 };
29
30 } // namespace
31
32 TEST(ChromeLauncher, SanitizeCommandLine) {
33 CommandLine bad(FilePath(L"dummy.exe")); 12 CommandLine bad(FilePath(L"dummy.exe"));
34 bad.AppendSwitch(switches::kNoFirstRun); // in whitelist 13 bad.AppendSwitch(switches::kNoFirstRun); // in whitelist
35 bad.AppendSwitchWithValue(switches::kLoadExtension, L"foo"); // in whitelist
36 bad.AppendSwitch("no-such-switch"); // does not exist 14 bad.AppendSwitch("no-such-switch"); // does not exist
37 bad.AppendSwitch(switches::kHomePage); // exists but not in whitelist 15 bad.AppendSwitch(switches::kHomePage); // exists but not in whitelist
38 16
39 LogDisabler no_dchecks; 17 EXPECT_FALSE(chrome_launcher::IsValidCommandLine(
18 bad.command_line_string().c_str()));
40 19
41 CommandLine sanitized(FilePath(L"dumbo.exe")); 20 CommandLine good(FilePath(L"dummy.exe"));
42 chrome_launcher::SanitizeCommandLine(bad, &sanitized); 21 good.AppendSwitch(switches::kNoFirstRun); // in whitelist
43 EXPECT_TRUE(sanitized.HasSwitch(switches::kNoFirstRun)); 22 good.AppendSwitchWithValue(switches::kUserDataDir, L"foo"); // in whitelist
44 EXPECT_FALSE(sanitized.HasSwitch(switches::kLoadExtension)); 23
45 EXPECT_FALSE(sanitized.HasSwitch("no-such-switch")); 24 EXPECT_TRUE(chrome_launcher::IsValidCommandLine(
46 EXPECT_FALSE(sanitized.HasSwitch(switches::kHomePage)); 25 good.command_line_string().c_str()));
26
27 CommandLine no_params(FilePath(L"dummy.exe"));
28 EXPECT_TRUE(chrome_launcher::IsValidCommandLine(
29 no_params.command_line_string().c_str()));
30
31 CommandLine empty(FilePath(L""));
32 EXPECT_TRUE(chrome_launcher::IsValidCommandLine(
33 empty.command_line_string().c_str()));
47 } 34 }
48 35
36 TEST(ChromeLauncher, TrimWhiteSpace) {
37 std::wstring trimmed(chrome_launcher::TrimWhiteSpace(L" \t some text \n\t"));
38 EXPECT_STREQ(L"some text", trimmed.c_str());
39
40 std::wstring now_empty(chrome_launcher::TrimWhiteSpace(L"\t\t \n\t"));
41 EXPECT_STREQ(L"", now_empty.c_str());
42
43 std::wstring empty(chrome_launcher::TrimWhiteSpace(L""));
44 EXPECT_STREQ(L"", empty.c_str());
45
46 std::wstring not_trimmed(chrome_launcher::TrimWhiteSpace(L"foo bar"));
47 EXPECT_STREQ(L"foo bar", not_trimmed.c_str());
48
49 std::wstring trimmed_right(chrome_launcher::TrimWhiteSpace(L"foo bar\t"));
50 EXPECT_STREQ(L"foo bar", trimmed_right.c_str());
51
52 std::wstring trimmed_left(chrome_launcher::TrimWhiteSpace(L"\nfoo bar"));
53 EXPECT_STREQ(L"foo bar", trimmed_right.c_str());
54 }
55
56 TEST(ChromeLauncher, IsValidArgument) {
57 EXPECT_TRUE(chrome_launcher::IsValidArgument(L"--chrome-frame"));
58 EXPECT_FALSE(chrome_launcher::IsValidArgument(L"--invalid-arg"));
59
60 EXPECT_TRUE(chrome_launcher::IsValidArgument(L"--chrome-frame="));
61 EXPECT_TRUE(chrome_launcher::IsValidArgument(L"--chrome-frame=foo"));
62 EXPECT_TRUE(chrome_launcher::IsValidArgument(L"--chrome-frame=foo=foo"));
63
64 EXPECT_FALSE(chrome_launcher::IsValidArgument(L"chrome-frame"));
65 EXPECT_FALSE(chrome_launcher::IsValidArgument(L"-chrome-frame"));
66 EXPECT_FALSE(chrome_launcher::IsValidArgument(L"---chrome-frame"));
67 EXPECT_FALSE(chrome_launcher::IsValidArgument(L" --chrome-frame"));
68 EXPECT_FALSE(chrome_launcher::IsValidArgument(L"--chrome-framefoobar"));
69 EXPECT_FALSE(chrome_launcher::IsValidArgument(L"foobar--chrome-frame"));
70 EXPECT_FALSE(chrome_launcher::IsValidArgument(L"--chrome-frames"));
71 EXPECT_FALSE(chrome_launcher::IsValidArgument(L"--Chrome-frame"));
72 EXPECT_FALSE(chrome_launcher::IsValidArgument(L""));
73 }
OLDNEW
« no previous file with comments | « chrome_frame/chrome_launcher_main.cc ('k') | chrome_frame/chrome_launcher_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698