OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/install_static/install_util.h" | 5 #include "chrome/install_static/install_util.h" |
6 | 6 |
7 #include <tuple> | 7 #include <tuple> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 | 83 |
84 // Whitespace after a switch. | 84 // Whitespace after a switch. |
85 value = | 85 value = |
86 GetSwitchValueFromCommandLine(L"c:\\temp\\bleh.exe --type= ", L"type"); | 86 GetSwitchValueFromCommandLine(L"c:\\temp\\bleh.exe --type= ", L"type"); |
87 EXPECT_TRUE(value.empty()); | 87 EXPECT_TRUE(value.empty()); |
88 | 88 |
89 // Just tabs after a switch. | 89 // Just tabs after a switch. |
90 value = GetSwitchValueFromCommandLine(L"c:\\temp\\bleh.exe --type=\t\t\t", | 90 value = GetSwitchValueFromCommandLine(L"c:\\temp\\bleh.exe --type=\t\t\t", |
91 L"type"); | 91 L"type"); |
92 EXPECT_TRUE(value.empty()); | 92 EXPECT_TRUE(value.empty()); |
| 93 } |
93 | 94 |
94 // Whitespace after the "=" before the value. | 95 TEST(InstallStaticTest, SpacesAndQuotesInCommandLineArguments) { |
95 value = | 96 std::vector<std::wstring> tokenized; |
96 GetSwitchValueFromCommandLine(L"c:\\temp\\bleh.exe --type= bar", L"type"); | |
97 EXPECT_EQ(L"bar", value); | |
98 | 97 |
99 // Tabs after the "=" before the value. | 98 tokenized = TokenizeCommandLineToArray(L"\"C:\\a\\b.exe\""); |
100 value = GetSwitchValueFromCommandLine(L"c:\\temp\\bleh.exe --type=\t\t\tbar", | 99 ASSERT_EQ(1, tokenized.size()); |
101 L"type"); | 100 EXPECT_EQ(L"C:\\a\\b.exe", tokenized[0]); |
102 EXPECT_EQ(value, L"bar"); | 101 |
| 102 tokenized = TokenizeCommandLineToArray(L"x.exe"); |
| 103 ASSERT_EQ(1, tokenized.size()); |
| 104 EXPECT_EQ(L"x.exe", tokenized[0]); |
| 105 |
| 106 tokenized = TokenizeCommandLineToArray(L"\"c:\\with space\\something.exe\""); |
| 107 ASSERT_EQ(1, tokenized.size()); |
| 108 EXPECT_EQ(L"c:\\with space\\something.exe", tokenized[0]); |
| 109 |
| 110 tokenized = TokenizeCommandLineToArray(L"\"C:\\a\\b.exe\" arg"); |
| 111 ASSERT_EQ(2, tokenized.size()); |
| 112 EXPECT_EQ(L"C:\\a\\b.exe", tokenized[0]); |
| 113 EXPECT_EQ(L"arg", tokenized[1]); |
| 114 |
| 115 tokenized = TokenizeCommandLineToArray(L"\"C:\\with space\\b.exe\" \"arg\""); |
| 116 ASSERT_EQ(2, tokenized.size()); |
| 117 EXPECT_EQ(L"C:\\with space\\b.exe", tokenized[0]); |
| 118 EXPECT_EQ(L"arg", tokenized[1]); |
| 119 |
| 120 tokenized = TokenizeCommandLineToArray(L"\"C:\\a\\b.exe\" c:\\tmp\\"); |
| 121 ASSERT_EQ(2, tokenized.size()); |
| 122 EXPECT_EQ(L"C:\\a\\b.exe", tokenized[0]); |
| 123 EXPECT_EQ(L"c:\\tmp\\", tokenized[1]); |
| 124 |
| 125 tokenized = |
| 126 TokenizeCommandLineToArray(L"\"C:\\a\\b.exe\" \"c:\\some file path\\\""); |
| 127 ASSERT_EQ(2, tokenized.size()); |
| 128 EXPECT_EQ(L"C:\\a\\b.exe", tokenized[0]); |
| 129 EXPECT_EQ(L"c:\\some file path\"", tokenized[1]); |
| 130 |
| 131 tokenized = TokenizeCommandLineToArray( |
| 132 L"\"C:\\with space\\b.exe\" \\\\x\\\\ \\\\y\\\\"); |
| 133 ASSERT_EQ(3, tokenized.size()); |
| 134 EXPECT_EQ(L"C:\\with space\\b.exe", tokenized[0]); |
| 135 EXPECT_EQ(L"\\\\x\\\\", tokenized[1]); |
| 136 EXPECT_EQ(L"\\\\y\\\\", tokenized[2]); |
| 137 |
| 138 tokenized = TokenizeCommandLineToArray( |
| 139 L"\"C:\\with space\\b.exe\" \"\\\\space quoted\\\\\""); |
| 140 ASSERT_EQ(2, tokenized.size()); |
| 141 EXPECT_EQ(L"C:\\with space\\b.exe", tokenized[0]); |
| 142 EXPECT_EQ(L"\\\\space quoted\\", tokenized[1]); |
| 143 |
| 144 tokenized = TokenizeCommandLineToArray( |
| 145 L"\"C:\\with space\\b.exe\" --stuff -x -Y \"c:\\some thing\\\" " |
| 146 L"weewaa "); |
| 147 EXPECT_EQ(5, tokenized.size()); |
| 148 EXPECT_EQ(L"C:\\with space\\b.exe", tokenized[0]); |
| 149 EXPECT_EQ(L"--stuff", tokenized[1]); |
| 150 EXPECT_EQ(L"-x", tokenized[2]); |
| 151 EXPECT_EQ(L"-Y", tokenized[3]); |
| 152 EXPECT_EQ(L"c:\\some thing\" weewaa ", tokenized[4]); |
| 153 |
| 154 tokenized = TokenizeCommandLineToArray( |
| 155 L"\"C:\\with space\\b.exe\" --stuff=\"d:\\stuff and things\""); |
| 156 EXPECT_EQ(2, tokenized.size()); |
| 157 EXPECT_EQ(L"C:\\with space\\b.exe", tokenized[0]); |
| 158 EXPECT_EQ(L"--stuff=d:\\stuff and things", tokenized[1]); |
103 } | 159 } |
104 | 160 |
105 TEST(InstallStaticTest, BrowserProcessTest) { | 161 TEST(InstallStaticTest, BrowserProcessTest) { |
106 EXPECT_EQ(ProcessType::UNINITIALIZED, g_process_type); | 162 EXPECT_EQ(ProcessType::UNINITIALIZED, g_process_type); |
107 InitializeProcessType(); | 163 InitializeProcessType(); |
108 EXPECT_FALSE(IsNonBrowserProcess()); | 164 EXPECT_FALSE(IsNonBrowserProcess()); |
109 } | 165 } |
110 | 166 |
111 class InstallStaticUtilTest | 167 class InstallStaticUtilTest |
112 : public ::testing::TestWithParam< | 168 : public ::testing::TestWithParam< |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 #else // GOOGLE_CHROME_BUILD | 349 #else // GOOGLE_CHROME_BUILD |
294 // Chromium supports multi-install at user and system levels. | 350 // Chromium supports multi-install at user and system levels. |
295 INSTANTIATE_TEST_CASE_P(Chromium, | 351 INSTANTIATE_TEST_CASE_P(Chromium, |
296 InstallStaticUtilTest, | 352 InstallStaticUtilTest, |
297 testing::Combine(testing::Values(CHROMIUM_INDEX), | 353 testing::Combine(testing::Values(CHROMIUM_INDEX), |
298 testing::Values("user", "system"), | 354 testing::Values("user", "system"), |
299 testing::Values("single", "multi"))); | 355 testing::Values("single", "multi"))); |
300 #endif // !GOOGLE_CHROME_BUILD | 356 #endif // !GOOGLE_CHROME_BUILD |
301 | 357 |
302 } // namespace install_static | 358 } // namespace install_static |
OLD | NEW |