| 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 21 matching lines...) Expand all Loading... |
| 32 EXPECT_FALSE(MatchPattern(L"Foo", L"F*b")); | 32 EXPECT_FALSE(MatchPattern(L"Foo", L"F*b")); |
| 33 EXPECT_TRUE(MatchPattern(L"abcd", L"*c*d")); | 33 EXPECT_TRUE(MatchPattern(L"abcd", L"*c*d")); |
| 34 EXPECT_TRUE(MatchPattern(L"abcd", L"*?c*d")); | 34 EXPECT_TRUE(MatchPattern(L"abcd", L"*?c*d")); |
| 35 EXPECT_FALSE(MatchPattern(L"abcd", L"abcd*efgh")); | 35 EXPECT_FALSE(MatchPattern(L"abcd", L"abcd*efgh")); |
| 36 EXPECT_TRUE(MatchPattern(L"foobarabc", L"*bar*")); | 36 EXPECT_TRUE(MatchPattern(L"foobarabc", L"*bar*")); |
| 37 } | 37 } |
| 38 | 38 |
| 39 // Tests the install_static::GetSwitchValueFromCommandLine function. | 39 // Tests the install_static::GetSwitchValueFromCommandLine function. |
| 40 TEST(InstallStaticTest, GetSwitchValueFromCommandLineTest) { | 40 TEST(InstallStaticTest, GetSwitchValueFromCommandLineTest) { |
| 41 // Simple case with one switch. | 41 // Simple case with one switch. |
| 42 std::wstring value = | 42 std::string value = |
| 43 GetSwitchValueFromCommandLine(L"c:\\temp\\bleh.exe --type=bar", L"type"); | 43 GetSwitchValueFromCommandLine("c:\\temp\\bleh.exe --type=bar", "type"); |
| 44 EXPECT_EQ(L"bar", value); | 44 EXPECT_EQ("bar", value); |
| 45 | 45 |
| 46 // Multiple switches with trailing spaces between them. | 46 // Multiple switches with trailing spaces between them. |
| 47 value = GetSwitchValueFromCommandLine( | 47 value = GetSwitchValueFromCommandLine( |
| 48 L"c:\\temp\\bleh.exe --type=bar --abc=def bleh", L"abc"); | 48 "c:\\temp\\bleh.exe --type=bar --abc=def bleh", "abc"); |
| 49 EXPECT_EQ(L"def", value); | 49 EXPECT_EQ("def", value); |
| 50 | 50 |
| 51 // Multiple switches with trailing spaces and tabs between them. | 51 // Multiple switches with trailing spaces and tabs between them. |
| 52 value = GetSwitchValueFromCommandLine( | 52 value = GetSwitchValueFromCommandLine( |
| 53 L"c:\\temp\\bleh.exe --type=bar \t\t\t --abc=def bleh", L"abc"); | 53 "c:\\temp\\bleh.exe --type=bar \t\t\t --abc=def bleh", "abc"); |
| 54 EXPECT_EQ(L"def", value); | 54 EXPECT_EQ("def", value); |
| 55 | 55 |
| 56 // Non existent switch. | 56 // Non existent switch. |
| 57 value = GetSwitchValueFromCommandLine( | 57 value = GetSwitchValueFromCommandLine( |
| 58 L"c:\\temp\\bleh.exe --foo=bar --abc=def bleh", L"type"); | 58 "c:\\temp\\bleh.exe --foo=bar --abc=def bleh", "type"); |
| 59 EXPECT_EQ(L"", value); | 59 EXPECT_EQ("", value); |
| 60 | 60 |
| 61 // Non existent switch. | 61 // Non existent switch. |
| 62 value = GetSwitchValueFromCommandLine(L"c:\\temp\\bleh.exe", L"type"); | 62 value = GetSwitchValueFromCommandLine("c:\\temp\\bleh.exe", "type"); |
| 63 EXPECT_EQ(L"", value); | 63 EXPECT_EQ("", value); |
| 64 | 64 |
| 65 // Non existent switch. | 65 // Non existent switch. |
| 66 value = | 66 value = GetSwitchValueFromCommandLine("c:\\temp\\bleh.exe type=bar", "type"); |
| 67 GetSwitchValueFromCommandLine(L"c:\\temp\\bleh.exe type=bar", L"type"); | 67 EXPECT_EQ("", value); |
| 68 EXPECT_EQ(L"", value); | |
| 69 | 68 |
| 70 // Trailing spaces after the switch. | 69 // Trailing spaces after the switch. |
| 71 value = GetSwitchValueFromCommandLine( | 70 value = GetSwitchValueFromCommandLine( |
| 72 L"c:\\temp\\bleh.exe --type=bar \t\t", L"type"); | 71 "c:\\temp\\bleh.exe --type=bar \t\t", "type"); |
| 73 EXPECT_EQ(L"bar", value); | 72 EXPECT_EQ("bar", value); |
| 74 | 73 |
| 75 // Multiple switches with trailing spaces and tabs between them. | 74 // Multiple switches with trailing spaces and tabs between them. |
| 76 value = GetSwitchValueFromCommandLine( | 75 value = GetSwitchValueFromCommandLine( |
| 77 L"c:\\temp\\bleh.exe --type=bar \t\t --foo=bleh", L"foo"); | 76 "c:\\temp\\bleh.exe --type=bar \t\t --foo=bleh", "foo"); |
| 78 EXPECT_EQ(L"bleh", value); | 77 EXPECT_EQ("bleh", value); |
| 79 | 78 |
| 80 // Nothing after a switch. | 79 // Nothing after a switch. |
| 81 value = GetSwitchValueFromCommandLine(L"c:\\temp\\bleh.exe --type=", L"type"); | 80 value = GetSwitchValueFromCommandLine("c:\\temp\\bleh.exe --type=", "type"); |
| 82 EXPECT_TRUE(value.empty()); | 81 EXPECT_TRUE(value.empty()); |
| 83 | 82 |
| 84 // Whitespace after a switch. | 83 // Whitespace after a switch. |
| 85 value = | 84 value = GetSwitchValueFromCommandLine("c:\\temp\\bleh.exe --type= ", "type"); |
| 86 GetSwitchValueFromCommandLine(L"c:\\temp\\bleh.exe --type= ", L"type"); | |
| 87 EXPECT_TRUE(value.empty()); | 85 EXPECT_TRUE(value.empty()); |
| 88 | 86 |
| 89 // Just tabs after a switch. | 87 // Just tabs after a switch. |
| 90 value = GetSwitchValueFromCommandLine(L"c:\\temp\\bleh.exe --type=\t\t\t", | 88 value = GetSwitchValueFromCommandLine("c:\\temp\\bleh.exe --type=\t\t\t", |
| 91 L"type"); | 89 "type"); |
| 92 EXPECT_TRUE(value.empty()); | 90 EXPECT_TRUE(value.empty()); |
| 93 | 91 |
| 94 // Whitespace after the "=" before the value. | 92 // Whitespace after the "=" before the value. |
| 95 value = | 93 value = GetSwitchValueFromCommandLine("c:\\temp\\bleh.exe --type= bar", |
| 96 GetSwitchValueFromCommandLine(L"c:\\temp\\bleh.exe --type= bar", L"type"); | 94 "type"); |
| 97 EXPECT_EQ(L"bar", value); | 95 EXPECT_EQ("bar", value); |
| 98 | 96 |
| 99 // Tabs after the "=" before the value. | 97 // Tabs after the "=" before the value. |
| 100 value = GetSwitchValueFromCommandLine(L"c:\\temp\\bleh.exe --type=\t\t\tbar", | 98 value = GetSwitchValueFromCommandLine("c:\\temp\\bleh.exe --type=\t\t\tbar", |
| 101 L"type"); | 99 "type"); |
| 102 EXPECT_EQ(value, L"bar"); | 100 EXPECT_EQ(value, "bar"); |
| 103 } | 101 } |
| 104 | 102 |
| 105 TEST(InstallStaticTest, BrowserProcessTest) { | 103 TEST(InstallStaticTest, BrowserProcessTest) { |
| 106 EXPECT_EQ(ProcessType::UNINITIALIZED, g_process_type); | 104 EXPECT_EQ(ProcessType::UNINITIALIZED, g_process_type); |
| 107 InitializeProcessType(); | 105 InitializeProcessType(); |
| 108 EXPECT_FALSE(IsNonBrowserProcess()); | 106 EXPECT_FALSE(IsNonBrowserProcess()); |
| 109 } | 107 } |
| 110 | 108 |
| 111 class InstallStaticUtilTest | 109 class InstallStaticUtilTest |
| 112 : public ::testing::TestWithParam< | 110 : public ::testing::TestWithParam< |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 std::wstring expected = default_channel(); | 268 std::wstring expected = default_channel(); |
| 271 if (multi_install()) { | 269 if (multi_install()) { |
| 272 if (expected.empty()) | 270 if (expected.empty()) |
| 273 expected = L"m"; | 271 expected = L"m"; |
| 274 else | 272 else |
| 275 expected += L"-m"; | 273 expected += L"-m"; |
| 276 } | 274 } |
| 277 EXPECT_EQ(expected, GetChromeChannelName(true)); | 275 EXPECT_EQ(expected, GetChromeChannelName(true)); |
| 278 } | 276 } |
| 279 | 277 |
| 278 TEST_P(InstallStaticUtilTest, GetDefaultUserDataDirectory) { |
| 279 std::wstring user_data_directory; |
| 280 ASSERT_TRUE(GetDefaultUserDataDirectory(&user_data_directory)); |
| 281 } |
| 282 |
| 280 #if defined(GOOGLE_CHROME_BUILD) | 283 #if defined(GOOGLE_CHROME_BUILD) |
| 281 // Stable supports multi-install at user and system levels. | 284 // Stable supports multi-install at user and system levels. |
| 282 INSTANTIATE_TEST_CASE_P(Stable, | 285 INSTANTIATE_TEST_CASE_P(Stable, |
| 283 InstallStaticUtilTest, | 286 InstallStaticUtilTest, |
| 284 testing::Combine(testing::Values(STABLE_INDEX), | 287 testing::Combine(testing::Values(STABLE_INDEX), |
| 285 testing::Values("user", "system"), | 288 testing::Values("user", "system"), |
| 286 testing::Values("single", "multi"))); | 289 testing::Values("single", "multi"))); |
| 287 // Canary is single-only at user level. | 290 // Canary is single-only at user level. |
| 288 INSTANTIATE_TEST_CASE_P(Canary, | 291 INSTANTIATE_TEST_CASE_P(Canary, |
| 289 InstallStaticUtilTest, | 292 InstallStaticUtilTest, |
| 290 testing::Combine(testing::Values(CANARY_INDEX), | 293 testing::Combine(testing::Values(CANARY_INDEX), |
| 291 testing::Values("user"), | 294 testing::Values("user"), |
| 292 testing::Values("single"))); | 295 testing::Values("single"))); |
| 293 #else // GOOGLE_CHROME_BUILD | 296 #else // GOOGLE_CHROME_BUILD |
| 294 // Chromium supports multi-install at user and system levels. | 297 // Chromium supports multi-install at user and system levels. |
| 295 INSTANTIATE_TEST_CASE_P(Chromium, | 298 INSTANTIATE_TEST_CASE_P(Chromium, |
| 296 InstallStaticUtilTest, | 299 InstallStaticUtilTest, |
| 297 testing::Combine(testing::Values(CHROMIUM_INDEX), | 300 testing::Combine(testing::Values(CHROMIUM_INDEX), |
| 298 testing::Values("user", "system"), | 301 testing::Values("user", "system"), |
| 299 testing::Values("single", "multi"))); | 302 testing::Values("single", "multi"))); |
| 300 #endif // !GOOGLE_CHROME_BUILD | 303 #endif // !GOOGLE_CHROME_BUILD |
| 301 | 304 |
| 302 } // namespace install_static | 305 } // namespace install_static |
| OLD | NEW |