[email protected] | 61a4c6f | 2011-07-20 04:54:52 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 00f6b77 | 2009-10-23 17:03:41 | [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 "base/command_line.h" |
[email protected] | 5d91c9e | 2010-07-28 17:25:28 | [diff] [blame] | 6 | #include "base/file_path.h" |
[email protected] | 00f6b77 | 2009-10-23 17:03:41 | [diff] [blame] | 7 | #include "chrome/common/chrome_switches.h" |
| 8 | #include "chrome_frame/chrome_launcher.h" |
| 9 | #include "testing/gtest/include/gtest/gtest.h" |
| 10 | |
[email protected] | 79b663c | 2010-05-28 17:27:17 | [diff] [blame] | 11 | TEST(ChromeLauncher, IsValidCommandLine) { |
[email protected] | b111f25 | 2009-10-26 23:39:20 | [diff] [blame] | 12 | CommandLine bad(FilePath(L"dummy.exe")); |
[email protected] | 7603d7f | 2010-03-25 19:15:37 | [diff] [blame] | 13 | bad.AppendSwitch(switches::kNoFirstRun); // in whitelist |
[email protected] | 00f6b77 | 2009-10-23 17:03:41 | [diff] [blame] | 14 | bad.AppendSwitch("no-such-switch"); // does not exist |
| 15 | bad.AppendSwitch(switches::kHomePage); // exists but not in whitelist |
| 16 | |
[email protected] | 79b663c | 2010-05-28 17:27:17 | [diff] [blame] | 17 | EXPECT_FALSE(chrome_launcher::IsValidCommandLine( |
[email protected] | 61a4c6f | 2011-07-20 04:54:52 | [diff] [blame] | 18 | bad.GetCommandLineString().c_str())); |
[email protected] | 00f6b77 | 2009-10-23 17:03:41 | [diff] [blame] | 19 | |
[email protected] | 79b663c | 2010-05-28 17:27:17 | [diff] [blame] | 20 | CommandLine good(FilePath(L"dummy.exe")); |
| 21 | good.AppendSwitch(switches::kNoFirstRun); // in whitelist |
[email protected] | 8cc6e41 | 2011-09-29 15:12:46 | [diff] [blame] | 22 | good.AppendSwitch(switches::kDisableBackgroundMode); // in whitelist |
[email protected] | 05076ba2 | 2010-07-30 05:59:57 | [diff] [blame] | 23 | good.AppendSwitchASCII(switches::kUserDataDir, "foo"); // in whitelist |
[email protected] | 79b663c | 2010-05-28 17:27:17 | [diff] [blame] | 24 | |
| 25 | EXPECT_TRUE(chrome_launcher::IsValidCommandLine( |
[email protected] | 61a4c6f | 2011-07-20 04:54:52 | [diff] [blame] | 26 | good.GetCommandLineString().c_str())); |
[email protected] | 79b663c | 2010-05-28 17:27:17 | [diff] [blame] | 27 | |
| 28 | CommandLine no_params(FilePath(L"dummy.exe")); |
| 29 | EXPECT_TRUE(chrome_launcher::IsValidCommandLine( |
[email protected] | 61a4c6f | 2011-07-20 04:54:52 | [diff] [blame] | 30 | no_params.GetCommandLineString().c_str())); |
[email protected] | 79b663c | 2010-05-28 17:27:17 | [diff] [blame] | 31 | |
| 32 | CommandLine empty(FilePath(L"")); |
| 33 | EXPECT_TRUE(chrome_launcher::IsValidCommandLine( |
[email protected] | 61a4c6f | 2011-07-20 04:54:52 | [diff] [blame] | 34 | empty.GetCommandLineString().c_str())); |
[email protected] | 00f6b77 | 2009-10-23 17:03:41 | [diff] [blame] | 35 | } |
| 36 | |
[email protected] | 79b663c | 2010-05-28 17:27:17 | [diff] [blame] | 37 | TEST(ChromeLauncher, TrimWhiteSpace) { |
| 38 | std::wstring trimmed(chrome_launcher::TrimWhiteSpace(L" \t some text \n\t")); |
| 39 | EXPECT_STREQ(L"some text", trimmed.c_str()); |
| 40 | |
| 41 | std::wstring now_empty(chrome_launcher::TrimWhiteSpace(L"\t\t \n\t")); |
| 42 | EXPECT_STREQ(L"", now_empty.c_str()); |
| 43 | |
| 44 | std::wstring empty(chrome_launcher::TrimWhiteSpace(L"")); |
| 45 | EXPECT_STREQ(L"", empty.c_str()); |
| 46 | |
| 47 | std::wstring not_trimmed(chrome_launcher::TrimWhiteSpace(L"foo bar")); |
| 48 | EXPECT_STREQ(L"foo bar", not_trimmed.c_str()); |
| 49 | |
| 50 | std::wstring trimmed_right(chrome_launcher::TrimWhiteSpace(L"foo bar\t")); |
| 51 | EXPECT_STREQ(L"foo bar", trimmed_right.c_str()); |
| 52 | |
| 53 | std::wstring trimmed_left(chrome_launcher::TrimWhiteSpace(L"\nfoo bar")); |
| 54 | EXPECT_STREQ(L"foo bar", trimmed_right.c_str()); |
| 55 | } |
| 56 | |
| 57 | TEST(ChromeLauncher, IsValidArgument) { |
| 58 | EXPECT_TRUE(chrome_launcher::IsValidArgument(L"--chrome-frame")); |
[email protected] | 8cc6e41 | 2011-09-29 15:12:46 | [diff] [blame] | 59 | EXPECT_TRUE(chrome_launcher::IsValidArgument(L"--disable-background-mode")); |
[email protected] | 79b663c | 2010-05-28 17:27:17 | [diff] [blame] | 60 | EXPECT_FALSE(chrome_launcher::IsValidArgument(L"--invalid-arg")); |
| 61 | |
| 62 | EXPECT_TRUE(chrome_launcher::IsValidArgument(L"--chrome-frame=")); |
| 63 | EXPECT_TRUE(chrome_launcher::IsValidArgument(L"--chrome-frame=foo")); |
| 64 | EXPECT_TRUE(chrome_launcher::IsValidArgument(L"--chrome-frame=foo=foo")); |
| 65 | |
| 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-frame")); |
| 69 | EXPECT_FALSE(chrome_launcher::IsValidArgument(L" --chrome-frame")); |
| 70 | EXPECT_FALSE(chrome_launcher::IsValidArgument(L"--chrome-framefoobar")); |
| 71 | EXPECT_FALSE(chrome_launcher::IsValidArgument(L"foobar--chrome-frame")); |
| 72 | EXPECT_FALSE(chrome_launcher::IsValidArgument(L"--chrome-frames")); |
| 73 | EXPECT_FALSE(chrome_launcher::IsValidArgument(L"--Chrome-frame")); |
| 74 | EXPECT_FALSE(chrome_launcher::IsValidArgument(L"")); |
| 75 | } |