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

Unified Diff: chrome/installer/setup/install_worker_unittest.cc

Issue 1213913002: Update Chrome's Active Setup version per component instead of as a single string. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@active_setup_onosup_addCB_API
Patch Set: parametrized test Created 5 years, 6 months 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/installer/setup/install_worker.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/installer/setup/install_worker_unittest.cc
diff --git a/chrome/installer/setup/install_worker_unittest.cc b/chrome/installer/setup/install_worker_unittest.cc
index 9cd28f086d8db0137ec9b6c6e623c343b4d516e7..5570620edf1620a8c025c8c4a3aac73abd80fd8c 100644
--- a/chrome/installer/setup/install_worker_unittest.cc
+++ b/chrome/installer/setup/install_worker_unittest.cc
@@ -4,22 +4,26 @@
#include "chrome/installer/setup/install_worker.h"
-#include "base/win/registry.h"
+#include <iostream>
+
+#include "base/test/test_reg_util_win.h"
#include "base/version.h"
+#include "base/win/registry.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/installer/setup/setup_util.h"
-#include "chrome/installer/util/delete_reg_key_work_item.h"
#include "chrome/installer/util/create_reg_key_work_item.h"
-#include "chrome/installer/util/helper.h"
+#include "chrome/installer/util/delete_reg_key_work_item.h"
#include "chrome/installer/util/google_update_constants.h"
+#include "chrome/installer/util/helper.h"
+#include "chrome/installer/util/install_util.h"
#include "chrome/installer/util/installation_state.h"
#include "chrome/installer/util/installer_state.h"
#include "chrome/installer/util/set_reg_value_work_item.h"
#include "chrome/installer/util/util_constants.h"
+#include "chrome/installer/util/work_item.h"
#include "chrome/installer/util/work_item_list.h"
-
-#include "testing/gtest/include/gtest/gtest.h"
#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
using base::win::RegKey;
using installer::InstallationState;
@@ -38,7 +42,7 @@ using ::testing::Return;
using ::testing::StrCaseEq;
using ::testing::StrEq;
using ::testing::StrictMock;
-using ::testing::Values;
+using ::testing::ValuesIn;
// Mock classes to help with testing
//------------------------------------------------------------------------------
@@ -166,7 +170,12 @@ class MockInstallerState : public InstallerState {
class InstallWorkerTest : public testing::Test {
public:
+ InstallWorkerTest() {}
+
void SetUp() override {
+ registry_override_manager_.OverrideRegistry(HKEY_CURRENT_USER);
+ registry_override_manager_.OverrideRegistry(HKEY_LOCAL_MACHINE);
+
current_version_.reset(new Version("1.0.0.0"));
new_version_.reset(new Version("42.0.0.0"));
@@ -424,6 +433,11 @@ class InstallWorkerTest : public testing::Test {
base::FilePath setup_path_;
base::FilePath src_path_;
base::FilePath temp_dir_;
+
+ private:
+ registry_util::RegistryOverrideManager registry_override_manager_;
+
+ DISALLOW_COPY_AND_ASSIGN(InstallWorkerTest);
};
// Tests
@@ -671,6 +685,109 @@ TEST_F(InstallWorkerTest, AddUsageStatsWorkItems) {
&work_item_list);
}
+struct ActiveSetupWorkerTestCase {
+ // The initial value to be set in the registry prior to simulating the update.
+ // No value will be set if this null.
+ const wchar_t* initial_value;
+
+ // The expected value after simulating the update.
+ const wchar_t* expected_result;
+};
+
+// Implements PrintTo in order for gtest to be able to print the problematic
+// ActiveSetupWorkerTestCase on failure.
+void PrintTo(const ActiveSetupWorkerTestCase& test_case, ::std::ostream* os) {
+ *os << "Initial value: "
+ << (test_case.initial_value ? test_case.initial_value : L"(empty)")
+ << ", expected result: " << test_case.expected_result;
+}
+
+class ActiveSetupWorkerTest
+ : public InstallWorkerTest,
+ public ::testing::WithParamInterface<ActiveSetupWorkerTestCase> {};
+
+// Test that active setup version installing/updating is handled properly.
+TEST_P(ActiveSetupWorkerTest, AddAndRunActiveSetupWorkItems) {
+ // Active Setup only makes sense at system-level.
+ const bool system_level = true;
+ const bool multi_install = false;
+
+ scoped_ptr<MockInstallationState> installation_state(
+ BuildChromeInstallationState(system_level, multi_install));
+
+ MockProductState chrome_state;
+ chrome_state.set_version(new Version(*current_version_));
+ chrome_state.set_multi_install(multi_install);
+
+ installation_state->SetProductState(
+ system_level, BrowserDistribution::CHROME_BROWSER, chrome_state);
+
+ scoped_ptr<MockInstallerState> installer_state(
+ BuildChromeInstallerState(system_level, multi_install,
+ *installation_state,
+ InstallerState::MULTI_INSTALL));
+
+
+ const HKEY kRoot = HKEY_LOCAL_MACHINE;
+ const std::wstring active_setup_path(InstallUtil::GetActiveSetupPath(
+ BrowserDistribution::GetSpecificDistribution(
+ BrowserDistribution::CHROME_BROWSER)));
+ RegKey test_key;
+
+ EXPECT_NE(ERROR_SUCCESS,
+ test_key.Open(kRoot, active_setup_path.c_str(), KEY_READ));
+
+ // Get the |test_case| which defines 3 steps:
+ // 1) Maybe set an initial Active Setup version.
+ // 2) Unconditionally execute the Active Setup work items.
+ // 3) Verify that the updated Active Setup version is as expected.
+ const ActiveSetupWorkerTestCase& test_case = GetParam();
+
+ if (test_case.initial_value) {
+ EXPECT_EQ(ERROR_SUCCESS,
+ test_key.Create(kRoot, active_setup_path.c_str(), KEY_SET_VALUE));
+ EXPECT_EQ(ERROR_SUCCESS,
+ test_key.WriteValue(L"Version", test_case.initial_value));
+ }
+
+ // Note: This performs real operations, it's *not* a MockWorkItemList like in
+ // the other tests (the registry itself is mocked in the fixture however so
+ // this is okay).
+ scoped_ptr<WorkItemList> work_item_list(WorkItem::CreateWorkItemList());
+ AddActiveSetupWorkItems(
+ *installer_state, *current_version_,
+ *installer_state->FindProduct(BrowserDistribution::CHROME_BROWSER),
+ work_item_list.get());
+ work_item_list->Do();
+
+ std::wstring version_out;
+ EXPECT_EQ(ERROR_SUCCESS,
+ test_key.Open(kRoot, active_setup_path.c_str(), KEY_QUERY_VALUE));
+ EXPECT_EQ(ERROR_SUCCESS, test_key.ReadValue(L"Version", &version_out));
+ EXPECT_EQ(test_case.expected_result, version_out);
+}
+
+const ActiveSetupWorkerTestCase kActiveSetupTestCases[] = {
+ // Initial install.
+ {nullptr, L"43,0,0,0"},
+ // No-op update.
+ {L"43.0.0.0", L"43,0,0,0"},
+ // Update only major component.
+ {L"24,1,2,3", L"43,1,2,3"},
+ // Reset from bogus value.
+ {L"zzz", L"43,0,0,0"},
+ // Reset from invalid version (too few components).
+ {L"1,2", L"43,0,0,0"},
+ // Reset from invalid version (too many components).
+ {L"43,1,2,3,10", L"43,0,0,0"},
+ // Reset from empty string.
+ {L"", L"43,0,0,0"},
+};
+
+INSTANTIATE_TEST_CASE_P(ActiveSetupWorkerTestInstance,
+ ActiveSetupWorkerTest,
+ ValuesIn(kActiveSetupTestCases));
+
// The Quick Enable tests only make sense for the Google Chrome build as it
// interacts with registry values that are specific to Google Update.
#if defined(GOOGLE_CHROME_BUILD)
« no previous file with comments | « chrome/installer/setup/install_worker.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698