Index: chrome/tools/disable_outdated_build_detector/disable_outdated_build_detector_unittest.cc |
diff --git a/chrome/tools/disable_outdated_build_detector/disable_outdated_build_detector_unittest.cc b/chrome/tools/disable_outdated_build_detector/disable_outdated_build_detector_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b64fc7b77705aa8bb8f4e08edb19cca4e31dffed |
--- /dev/null |
+++ b/chrome/tools/disable_outdated_build_detector/disable_outdated_build_detector_unittest.cc |
@@ -0,0 +1,145 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/tools/disable_outdated_build_detector/disable_outdated_build_detector.h" |
+ |
+#include "base/command_line.h" |
+#include "base/strings/string16.h" |
+#include "base/test/test_reg_util_win.h" |
+#include "chrome/installer/util/browser_distribution.h" |
+#include "chrome/tools/disable_outdated_build_detector/constants.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+class DisableOutdatedBuildDetectorTest : public ::testing::TestWithParam<bool> { |
+ protected: |
+ DisableOutdatedBuildDetectorTest() |
+ : command_line_(base::CommandLine::NO_PROGRAM), |
+ chrome_distribution_(BrowserDistribution::GetSpecificDistribution( |
+ BrowserDistribution::CHROME_BROWSER)), |
+ binaries_distribution_(BrowserDistribution::GetSpecificDistribution( |
+ BrowserDistribution::CHROME_BINARIES)), |
+ system_level_(GetParam()), |
+ root_(system_level_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER) { |
+ registry_override_manager_.OverrideRegistry(root_); |
+ if (system_level_) |
+ command_line_.AppendSwitch("system-level"); |
+ } |
+ |
+ void FakeChrome(bool multi_install, const wchar_t* brand) { |
+ base::win::RegKey key; |
+ ASSERT_EQ(ERROR_SUCCESS, |
+ key.Create(root_, chrome_distribution_->GetStateKey().c_str(), |
+ KEY_ALL_ACCESS | KEY_WOW64_32KEY)); |
+ base::string16 uninstall_arguments(L"--uninstall"); |
+ if (multi_install) |
+ uninstall_arguments += L"--chrome --multi-install"; |
+ ASSERT_EQ(ERROR_SUCCESS, key.WriteValue(L"brand", brand)); |
+ ASSERT_EQ(ERROR_SUCCESS, key.WriteValue(L"UninstallArguments", |
+ uninstall_arguments.c_str())); |
+ if (!multi_install) |
+ return; |
+ uninstall_arguments = L"--uninstall --multi-install"; |
+ ASSERT_EQ(ERROR_SUCCESS, |
+ key.Create(root_, binaries_distribution_->GetStateKey().c_str(), |
+ KEY_ALL_ACCESS | KEY_WOW64_32KEY)); |
+ ASSERT_EQ(ERROR_SUCCESS, key.WriteValue(L"brand", brand)); |
+ ASSERT_EQ(ERROR_SUCCESS, key.WriteValue(L"UninstallArguments", |
+ uninstall_arguments.c_str())); |
+ } |
+ |
+ bool HasBrand(BrowserDistribution* dist) { |
+ base::win::RegKey key(root_, dist->GetStateKey().c_str(), |
+ KEY_QUERY_VALUE | KEY_WOW64_32KEY); |
+ return key.Valid() && key.HasValue(L"brand"); |
+ } |
+ |
+ base::string16 ReadBrand(BrowserDistribution* dist) { |
+ base::win::RegKey key(root_, dist->GetStateKey().c_str(), |
+ KEY_QUERY_VALUE | KEY_WOW64_32KEY); |
+ base::string16 brand; |
+ if (!key.Valid() || key.ReadValue(L"brand", &brand) != ERROR_SUCCESS) |
+ return base::string16(); |
+ return brand; |
+ } |
+ |
+ base::CommandLine command_line_; |
+ BrowserDistribution* chrome_distribution_; |
+ BrowserDistribution* binaries_distribution_; |
+ |
+ private: |
+ const bool system_level_; |
+ const HKEY root_; |
+ registry_util::RegistryOverrideManager registry_override_manager_; |
+}; |
+ |
+TEST_P(DisableOutdatedBuildDetectorTest, NoChrome) { |
+ EXPECT_EQ(ExitCode::NO_CHROME, DisableOutdatedBuildDetector(&command_line_)); |
+} |
+ |
+TEST_P(DisableOutdatedBuildDetectorTest, SingleOrganicChrome) { |
+ // Fake single-install Chrome's ClientState key with an organic brand. |
+ FakeChrome(false /* single-install */, L"GGLS"); |
+ |
+ // Switch the brand. |
+ EXPECT_EQ(ExitCode::CHROME_BRAND_UPDATED, |
+ DisableOutdatedBuildDetector(&command_line_)); |
+ |
+ // Verify the new brand. |
+ EXPECT_STREQ(L"AOHY", ReadBrand(chrome_distribution_).c_str()); |
+ |
+ // And the binaries' ClientState key should not have been created. |
+ EXPECT_FALSE(HasBrand(binaries_distribution_)); |
+} |
+ |
+TEST_P(DisableOutdatedBuildDetectorTest, SingleInOrganicChrome) { |
+ static const wchar_t kBlorBrand[] = L"BLOR"; |
+ |
+ // Fake single-install Chrome's ClientState key with an inorganic brand. |
+ FakeChrome(false /* single-install */, kBlorBrand); |
+ |
+ // Switch the brand. |
+ EXPECT_EQ(ExitCode::NON_ORGANIC_BRAND, |
+ DisableOutdatedBuildDetector(&command_line_)); |
+ |
+ // Verify that the brand is unchanged. |
+ EXPECT_STREQ(kBlorBrand, ReadBrand(chrome_distribution_).c_str()); |
+ |
+ // And the binaries' ClientState key should not have been created. |
+ EXPECT_FALSE(HasBrand(binaries_distribution_)); |
+} |
+ |
+TEST_P(DisableOutdatedBuildDetectorTest, MultiOrganicChrome) { |
+ // Fake multi-install Chrome's ClientState key with an organic brand. |
+ FakeChrome(true /* multi-install */, L"GGLS"); |
+ |
+ // Switch the brand. |
+ EXPECT_EQ(ExitCode::BOTH_BRANDS_UPDATED, |
+ DisableOutdatedBuildDetector(&command_line_)); |
+ |
+ // Verify the new brand in Chrome and the binaries. |
+ EXPECT_STREQ(L"AOHY", ReadBrand(chrome_distribution_).c_str()); |
+ EXPECT_STREQ(L"AOHY", ReadBrand(binaries_distribution_).c_str()); |
+} |
+ |
+TEST_P(DisableOutdatedBuildDetectorTest, MultiInOrganicChrome) { |
+ static const wchar_t kBlorBrand[] = L"BLOR"; |
+ |
+ // Fake multi-install Chrome's ClientState key with an inorganic brand. |
+ FakeChrome(true /* multi-install */, kBlorBrand); |
+ |
+ // Switch the brand. |
+ EXPECT_EQ(ExitCode::NON_ORGANIC_BRAND, |
+ DisableOutdatedBuildDetector(&command_line_)); |
+ |
+ // Verify that the brand is unchanged in both apps. |
+ EXPECT_STREQ(kBlorBrand, ReadBrand(chrome_distribution_).c_str()); |
+ EXPECT_STREQ(kBlorBrand, ReadBrand(binaries_distribution_).c_str()); |
+} |
+ |
+INSTANTIATE_TEST_CASE_P(UserLevel, |
+ DisableOutdatedBuildDetectorTest, |
+ ::testing::Values(false)); |
+INSTANTIATE_TEST_CASE_P(SystemLevel, |
+ DisableOutdatedBuildDetectorTest, |
+ ::testing::Values(true)); |