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

Unified Diff: chrome/install_static/install_util_unittest.cc

Issue 2491463002: Revert of Windows install_static refactor. (Closed)
Patch Set: Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/install_static/install_util.cc ('k') | chrome/install_static/product_install_details.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/install_static/install_util_unittest.cc
diff --git a/chrome/install_static/install_util_unittest.cc b/chrome/install_static/install_util_unittest.cc
index b09241f39eb64718fee10aa1029a2a9bfd6e8ca4..ebb7a802f983535fcbdd0ae37d43840260615668 100644
--- a/chrome/install_static/install_util_unittest.cc
+++ b/chrome/install_static/install_util_unittest.cc
@@ -4,15 +4,6 @@
#include "chrome/install_static/install_util.h"
-#include <tuple>
-#include <utility>
-
-#include "base/memory/ptr_util.h"
-#include "base/test/test_reg_util_win.h"
-#include "chrome/install_static/install_details.h"
-#include "chrome/install_static/install_modes.h"
-#include "chrome/install_static/product_install_details.h"
-#include "chrome_elf/nt_registry/nt_registry.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -34,6 +25,109 @@
EXPECT_TRUE(MatchPattern(L"abcd", L"*?c*d"));
EXPECT_FALSE(MatchPattern(L"abcd", L"abcd*efgh"));
EXPECT_TRUE(MatchPattern(L"foobarabc", L"*bar*"));
+}
+
+// Tests the TokenizeString function in the install_static library.
+TEST(InstallStaticTest, TokenizeString) {
+ // Test if the string is tokenized correctly with all tokens stripped of
+ // leading and trailing spaces.
+ std::vector<std::string> results =
+ TokenizeString("un |deux\t|trois\n|quatre", '|', true);
+ ASSERT_EQ(4u, results.size());
+ EXPECT_THAT(results, ElementsAre("un", "deux", "trois", "quatre"));
+
+ // Test if the string is tokenized correctly with all tokens having
+ // leading and trailing spaces intact.
+ results = TokenizeString("un |deux\t|trois\n|quatre", '|', false);
+ ASSERT_EQ(4u, results.size());
+ EXPECT_THAT(results, ElementsAre("un ", "deux\t", "trois\n", "quatre"));
+
+ // Test if tokenize returns the original string if a string containing only
+ // one token and no delimiters is passed.
+ results = TokenizeString("un |deux\t|trois\n|quatre", '!', false);
+ ASSERT_EQ(1u, results.size());
+ ASSERT_EQ(results[0], "un |deux\t|trois\n|quatre");
+
+ // Test if tokenize handles a space character as delimiter.
+ results = TokenizeString("foo bar bleh blah boo", ' ', false);
+ ASSERT_EQ(5u, results.size());
+ EXPECT_THAT(results, ElementsAre("foo", "bar", "bleh", "blah", "boo"));
+
+ // Test string with only delimiters.
+ results = TokenizeString("||||", '|', false);
+ ASSERT_EQ(4u, results.size());
+ EXPECT_THAT(results, ElementsAre("", "", "", ""));
+
+ // Test string with spaces separated by delimiters.
+ results = TokenizeString(" | | | |", '|', false);
+ ASSERT_EQ(4u, results.size());
+ EXPECT_THAT(results, ElementsAre(" ", " ", " ", " "));
+
+ results = TokenizeString("one|two||four", '|', false);
+ ASSERT_EQ(4u, results.size());
+ EXPECT_THAT(results, ElementsAre("one", "two", "", "four"));
+
+ // TokenizeString16 tests.
+ // Test if the string is tokenized correctly with all tokens stripped of
+ // leading and trailing spaces.
+ std::vector<std::wstring> results16 =
+ TokenizeString16(L"un |deux\t|trois\n|quatre", L'|', true);
+ ASSERT_EQ(4u, results16.size());
+ EXPECT_THAT(results16, ElementsAre(L"un", L"deux", L"trois", L"quatre"));
+
+ // Test string with spaces separated by delimiters.
+ results16 = TokenizeString16(L"one|two||four", L'|', false);
+ ASSERT_EQ(4u, results16.size());
+ EXPECT_THAT(results16, ElementsAre(L"one", L"two", L"", L"four"));
+}
+
+// Tests the CompareVersionString function in the install_static library.
+TEST(InstallStaticTest, CompareVersions) {
+ // Case 1. Invalid versions.
+ int result = 0;
+ EXPECT_FALSE(CompareVersionStrings("", "", &result));
+ EXPECT_FALSE(CompareVersionStrings("0.0.0.0", "A.B.C.D", &result));
+ EXPECT_FALSE(CompareVersionStrings("A.0.0.0", "0.0.0.0", &result));
+
+ // Case 2. Equal versions.
+ EXPECT_TRUE(CompareVersionStrings("0.0.0.0", "0.0.0.0", &result));
+ EXPECT_EQ(0, result);
+
+ // Case 3. Version1 > Version 2.
+ EXPECT_TRUE(CompareVersionStrings("1.0.0.0", "0.0.0.0", &result));
+ EXPECT_EQ(1, result);
+
+ // Case 4. Version1 < Version 2.
+ EXPECT_TRUE(CompareVersionStrings("0.0.0.0", "1.0.0.0", &result));
+ EXPECT_EQ(-1, result);
+
+ // Case 5. Version1 < Version 2.
+ EXPECT_TRUE(CompareVersionStrings("0.0", "0.0.1.0", &result));
+ EXPECT_EQ(-1, result);
+
+ // Case 6. Version1 > Version 2.
+ EXPECT_TRUE(CompareVersionStrings("0.0.0.2", "0.0", &result));
+ EXPECT_EQ(1, result);
+
+ // Case 7. Version1 > Version 2.
+ EXPECT_TRUE(CompareVersionStrings("1.1.1.2", "1.1.1.1", &result));
+ EXPECT_EQ(1, result);
+
+ // Case 8. Version1 < Version2
+ EXPECT_TRUE(CompareVersionStrings("0.0.0.2", "0.0.0.3", &result));
+ EXPECT_EQ(-1, result);
+
+ // Case 9. Version1 > Version2
+ EXPECT_TRUE(CompareVersionStrings("0.0.0.4", "0.0.0.3", &result));
+ EXPECT_EQ(1, result);
+
+ // Case 10. Version1 > Version2. Multiple digit numbers.
+ EXPECT_TRUE(CompareVersionStrings("0.0.12.1", "0.0.10.3", &result));
+ EXPECT_EQ(1, result);
+
+ // Case 11. Version1 < Version2. Multiple digit number.
+ EXPECT_TRUE(CompareVersionStrings("10.11.12.13", "12.11.12.13", &result));
+ EXPECT_EQ(-1, result);
}
// Tests the install_static::GetSwitchValueFromCommandLine function.
@@ -100,206 +194,4 @@
EXPECT_EQ(value, "bar");
}
-TEST(InstallStaticTest, BrowserProcessTest) {
- EXPECT_EQ(ProcessType::UNINITIALIZED, g_process_type);
- InitializeProcessType();
- EXPECT_FALSE(IsNonBrowserProcess());
-}
-
-class InstallStaticUtilTest
- : public ::testing::TestWithParam<
- std::tuple<InstallConstantIndex, const char*, const char*>> {
- protected:
- InstallStaticUtilTest() {
- InstallConstantIndex mode_index;
- const char* level;
- const char* mode;
-
- std::tie(mode_index, level, mode) = GetParam();
-
- mode_ = &kInstallModes[mode_index];
- system_level_ = std::string(level) != "user";
- EXPECT_TRUE(!system_level_ || mode_->supports_system_level);
- multi_install_ = std::string(mode) != "single";
- EXPECT_TRUE(!multi_install_ || mode_->supports_multi_install);
- root_key_ = system_level_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
- nt_root_key_ = system_level_ ? nt::HKLM : nt::HKCU;
-
- std::unique_ptr<PrimaryInstallDetails> details =
- base::MakeUnique<PrimaryInstallDetails>();
- details->set_mode(mode_);
- details->set_channel(mode_->default_channel_name);
- details->set_system_level(system_level_);
- details->set_multi_install(multi_install_);
- InstallDetails::SetForProcess(std::move(details));
-
- base::string16 path;
- override_manager_.OverrideRegistry(root_key_, &path);
- nt::SetTestingOverride(nt_root_key_, path);
- }
-
- ~InstallStaticUtilTest() {
- InstallDetails::SetForProcess(nullptr);
- nt::SetTestingOverride(nt_root_key_, base::string16());
- }
-
- bool system_level() const { return system_level_; }
-
- bool multi_install() const { return multi_install_; }
-
- const wchar_t* default_channel() const { return mode_->default_channel_name; }
-
- void SetUsageStat(DWORD value, bool medium) {
- ASSERT_TRUE(!medium || system_level_);
- ASSERT_EQ(ERROR_SUCCESS,
- base::win::RegKey(root_key_, GetUsageStatsKeyPath(medium).c_str(),
- KEY_SET_VALUE | KEY_WOW64_32KEY)
- .WriteValue(L"usagestats", value));
- }
-
- void SetMetricsReportingPolicy(DWORD value) {
-#if defined(GOOGLE_CHROME_BUILD)
- static constexpr wchar_t kPolicyKey[] =
- L"Software\\Policies\\Google\\Chrome";
-#else
- static constexpr wchar_t kPolicyKey[] = L"Software\\Policies\\Chromium";
-#endif
-
- ASSERT_EQ(ERROR_SUCCESS,
- base::win::RegKey(root_key_, kPolicyKey, KEY_SET_VALUE)
- .WriteValue(L"MetricsReportingEnabled", value));
- }
-
- private:
- // Returns the registry path for the key holding the product's usagestats
- // value. |medium| = true returns the path for ClientStateMedium.
- std::wstring GetUsageStatsKeyPath(bool medium) {
- EXPECT_TRUE(!medium || system_level_);
-
- std::wstring result(L"Software\\");
- if (kUseGoogleUpdateIntegration) {
- result.append(L"Google\\Update\\ClientState");
- if (medium)
- result.append(L"Medium");
- result.push_back(L'\\');
- if (multi_install_)
- result.append(kBinariesAppGuid);
- else
- result.append(mode_->app_guid);
- } else if (multi_install_) {
- result.append(kBinariesPathName);
- } else {
- result.append(kProductPathName);
- }
- return result;
- }
-
- registry_util::RegistryOverrideManager override_manager_;
- HKEY root_key_ = nullptr;
- nt::ROOT_KEY nt_root_key_ = nt::AUTO;
- const InstallConstants* mode_ = nullptr;
- bool system_level_ = false;
- bool multi_install_ = false;
-
- DISALLOW_COPY_AND_ASSIGN(InstallStaticUtilTest);
-};
-
-TEST_P(InstallStaticUtilTest, UsageStatsAbsent) {
- EXPECT_FALSE(GetCollectStatsConsent());
-}
-
-TEST_P(InstallStaticUtilTest, UsageStatsZero) {
- SetUsageStat(0, false);
- EXPECT_FALSE(GetCollectStatsConsent());
-}
-
-TEST_P(InstallStaticUtilTest, UsageStatsZeroMedium) {
- if (!system_level())
- return;
- SetUsageStat(0, true);
- EXPECT_FALSE(GetCollectStatsConsent());
-}
-
-TEST_P(InstallStaticUtilTest, UsageStatsOne) {
- SetUsageStat(1, false);
- EXPECT_TRUE(GetCollectStatsConsent());
-}
-
-TEST_P(InstallStaticUtilTest, UsageStatsOneMedium) {
- if (!system_level())
- return;
- SetUsageStat(1, true);
- EXPECT_TRUE(GetCollectStatsConsent());
-}
-
-TEST_P(InstallStaticUtilTest, ReportingIsEnforcedByPolicy) {
- bool reporting_enabled = false;
- EXPECT_FALSE(ReportingIsEnforcedByPolicy(&reporting_enabled));
-
- SetMetricsReportingPolicy(0);
- EXPECT_TRUE(ReportingIsEnforcedByPolicy(&reporting_enabled));
- EXPECT_FALSE(reporting_enabled);
-
- SetMetricsReportingPolicy(1);
- EXPECT_TRUE(ReportingIsEnforcedByPolicy(&reporting_enabled));
- EXPECT_TRUE(reporting_enabled);
-}
-
-TEST_P(InstallStaticUtilTest, UsageStatsPolicy) {
- // Policy alone.
- SetMetricsReportingPolicy(0);
- EXPECT_FALSE(GetCollectStatsConsent());
-
- SetMetricsReportingPolicy(1);
- EXPECT_TRUE(GetCollectStatsConsent());
-
- // Policy trumps usagestats.
- SetMetricsReportingPolicy(1);
- SetUsageStat(0, false);
- EXPECT_TRUE(GetCollectStatsConsent());
-
- SetMetricsReportingPolicy(0);
- SetUsageStat(1, false);
- EXPECT_FALSE(GetCollectStatsConsent());
-}
-
-TEST_P(InstallStaticUtilTest, GetChromeChannelName) {
- EXPECT_EQ(default_channel(), GetChromeChannelName(false));
- std::wstring expected = default_channel();
- if (multi_install()) {
- if (expected.empty())
- expected = L"m";
- else
- expected += L"-m";
- }
- EXPECT_EQ(expected, GetChromeChannelName(true));
-}
-
-TEST_P(InstallStaticUtilTest, GetDefaultUserDataDirectory) {
- std::wstring user_data_directory;
- ASSERT_TRUE(GetDefaultUserDataDirectory(&user_data_directory));
-}
-
-#if defined(GOOGLE_CHROME_BUILD)
-// Stable supports multi-install at user and system levels.
-INSTANTIATE_TEST_CASE_P(Stable,
- InstallStaticUtilTest,
- testing::Combine(testing::Values(STABLE_INDEX),
- testing::Values("user", "system"),
- testing::Values("single", "multi")));
-// Canary is single-only at user level.
-INSTANTIATE_TEST_CASE_P(Canary,
- InstallStaticUtilTest,
- testing::Combine(testing::Values(CANARY_INDEX),
- testing::Values("user"),
- testing::Values("single")));
-#else // GOOGLE_CHROME_BUILD
-// Chromium supports multi-install at user and system levels.
-INSTANTIATE_TEST_CASE_P(Chromium,
- InstallStaticUtilTest,
- testing::Combine(testing::Values(CHROMIUM_INDEX),
- testing::Values("user", "system"),
- testing::Values("single", "multi")));
-#endif // !GOOGLE_CHROME_BUILD
-
} // namespace install_static
« no previous file with comments | « chrome/install_static/install_util.cc ('k') | chrome/install_static/product_install_details.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698