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

Unified Diff: chrome/installer/util/google_update_settings_unittest.cc

Issue 2773002: Fix problem whereby the "-full" magic value is removed from the "ap" value wh... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 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
Index: chrome/installer/util/google_update_settings_unittest.cc
===================================================================
--- chrome/installer/util/google_update_settings_unittest.cc (revision 49062)
+++ chrome/installer/util/google_update_settings_unittest.cc (working copy)
@@ -5,8 +5,11 @@
#include <windows.h>
#include "base/registry.h"
+#include "base/scoped_ptr.h"
#include "chrome/installer/util/browser_distribution.h"
+#include "chrome/installer/util/google_update_constants.h"
#include "chrome/installer/util/google_update_settings.h"
+#include "chrome/installer/util/work_item_list.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
@@ -15,6 +18,8 @@
const wchar_t* kHKLMReplacement =
L"Software\\Google\\InstallUtilUnittest\\HKLM";
+const wchar_t kTestProductGuid[] = L"{89F1B351-B15D-48D4-8F10-1298721CF13D}";
+
// This test fixture redirects the HKLM and HKCU registry hives for
// the duration of the test to make it independent of the machine
// and user settings.
@@ -117,6 +122,42 @@
}
}
+ // Creates "ap" key with the value given as parameter. Also adds work
+ // items to work_item_list given so that they can be rolled back later.
+ bool CreateApKey(WorkItemList* work_item_list, const std::wstring& value) {
+ HKEY reg_root = HKEY_CURRENT_USER;
+ std::wstring reg_key = GetApKeyPath();
+ work_item_list->AddCreateRegKeyWorkItem(reg_root, reg_key);
+ work_item_list->AddSetRegValueWorkItem(reg_root, reg_key,
+ google_update::kRegApField, value.c_str(), true);
+ if (!work_item_list->Do()) {
+ work_item_list->Rollback();
+ return false;
+ }
+ return true;
+ }
+
+ // Returns the key path of "ap" key, e.g.:
+ // Google\Update\ClientState\<kTestProductGuid>
+ std::wstring GetApKeyPath() {
+ std::wstring reg_key(google_update::kRegPathClientState);
+ reg_key.append(L"\\");
+ reg_key.append(kTestProductGuid);
+ return reg_key;
+ }
+
+ // Utility method to read "ap" key value
+ std::wstring ReadApKeyValue() {
+ RegKey key;
+ std::wstring ap_key_value;
+ std::wstring reg_key = GetApKeyPath();
+ if (key.Open(HKEY_CURRENT_USER, reg_key.c_str(), KEY_ALL_ACCESS) &&
+ key.ReadValue(google_update::kRegApField, &ap_key_value)) {
+ return ap_key_value;
+ }
+ return std::wstring();
+ }
+
RegKey hkcu_;
RegKey hklm_;
};
@@ -165,3 +206,145 @@
TEST_F(GoogleUpdateSettingsTest, CurrentChromeChannelVariousApValuesUser) {
TestCurrentChromeChannelWithVariousApValues(USER_INSTALL);
}
+
+TEST_F(GoogleUpdateSettingsTest, GetNewGoogleUpdateApKeyTest) {
+ installer_util::InstallStatus s = installer_util::FIRST_INSTALL_SUCCESS;
+ installer_util::InstallStatus f = installer_util::INSTALL_FAILED;
+
+ // Incremental Installer that worked.
+ EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(true, s, L""), L"");
+ EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(true, s, L"1.1"),
+ L"1.1");
+ EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(true, s, L"1.1-dev"),
+ L"1.1-dev");
+ EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(true, s, L"-full"),
+ L"");
+ EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(true, s, L"1.1-full"),
+ L"1.1");
+ EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(true, s,
+ L"1.1-dev-full"),
+ L"1.1-dev");
+
+ // Incremental Installer that failed.
+ EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(true, f, L""),
+ L"-full");
+ EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(true, f, L"1.1"),
+ L"1.1-full");
+ EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(true, f, L"1.1-dev"),
+ L"1.1-dev-full");
+ EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(true, f, L"-full"),
+ L"-full");
+ EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(true, f, L"1.1-full"),
+ L"1.1-full");
+ EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(true, f,
+ L"1.1-dev-full"),
+ L"1.1-dev-full");
+
+ // Full Installer that worked.
+ EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(false, s, L""), L"");
+ EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(false, s, L"1.1"),
+ L"1.1");
+ EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(false, s, L"1.1-dev"),
+ L"1.1-dev");
+ EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(false, s, L"-full"),
+ L"");
+ EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(false, s,
+ L"1.1-full"),
+ L"1.1");
+ EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(false, s,
+ L"1.1-dev-full"),
+ L"1.1-dev");
+
+ // Full Installer that failed.
+ EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(false, f, L""), L"");
+ EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(false, f, L"1.1"),
+ L"1.1");
+ EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(false, f, L"1.1-dev"),
+ L"1.1-dev");
+ EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(false, f, L"-full"),
+ L"");
+ EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(false, f,
+ L"1.1-full"),
+ L"1.1");
+ EXPECT_EQ(GoogleUpdateSettings::GetNewGoogleUpdateApKey(false, f,
+ L"1.1-dev-full"),
+ L"1.1-dev");
+}
+
+TEST_F(GoogleUpdateSettingsTest, UpdateDiffInstallStatusTest) {
+ scoped_ptr<WorkItemList> work_item_list(WorkItem::CreateWorkItemList());
+ // Test incremental install failure
+ ASSERT_TRUE(CreateApKey(work_item_list.get(), L""))
+ << "Failed to create ap key.";
+ GoogleUpdateSettings::UpdateDiffInstallStatus(false, true,
+ installer_util::INSTALL_FAILED,
+ kTestProductGuid);
+ EXPECT_STREQ(ReadApKeyValue().c_str(), L"-full");
+ work_item_list->Rollback();
+
+ work_item_list.reset(WorkItem::CreateWorkItemList());
+ // Test incremental install success
+ ASSERT_TRUE(CreateApKey(work_item_list.get(), L""))
+ << "Failed to create ap key.";
+ GoogleUpdateSettings::UpdateDiffInstallStatus(false, true,
+ installer_util::FIRST_INSTALL_SUCCESS,
+ kTestProductGuid);
+ EXPECT_STREQ(ReadApKeyValue().c_str(), L"");
+ work_item_list->Rollback();
+
+ work_item_list.reset(WorkItem::CreateWorkItemList());
+ // Test full install failure
+ ASSERT_TRUE(CreateApKey(work_item_list.get(), L"-full"))
+ << "Failed to create ap key.";
+ GoogleUpdateSettings::UpdateDiffInstallStatus(false, false,
+ installer_util::INSTALL_FAILED,
+ kTestProductGuid);
+ EXPECT_STREQ(ReadApKeyValue().c_str(), L"");
+ work_item_list->Rollback();
+
+ work_item_list.reset(WorkItem::CreateWorkItemList());
+ // Test full install success
+ ASSERT_TRUE(CreateApKey(work_item_list.get(), L"-full"))
+ << "Failed to create ap key.";
+ GoogleUpdateSettings::UpdateDiffInstallStatus(false, false,
+ installer_util::FIRST_INSTALL_SUCCESS,
+ kTestProductGuid);
+ EXPECT_STREQ(ReadApKeyValue().c_str(), L"");
+ work_item_list->Rollback();
+
+ work_item_list.reset(WorkItem::CreateWorkItemList());
+ // Test the case of when "ap" key doesnt exist at all
+ std::wstring ap_key_value = ReadApKeyValue();
+ std::wstring reg_key = GetApKeyPath();
+ HKEY reg_root = HKEY_CURRENT_USER;
+ bool ap_key_deleted = false;
+ RegKey key;
+ if (!key.Open(HKEY_CURRENT_USER, reg_key.c_str(), KEY_ALL_ACCESS)) {
+ work_item_list->AddCreateRegKeyWorkItem(reg_root, reg_key);
+ ASSERT_TRUE(work_item_list->Do()) << "Failed to create ClientState key.";
+ } else if (key.DeleteValue(google_update::kRegApField)) {
+ ap_key_deleted = true;
+ }
+ // try differential installer
+ GoogleUpdateSettings::UpdateDiffInstallStatus(false, true,
+ installer_util::INSTALL_FAILED,
+ kTestProductGuid);
+ EXPECT_STREQ(ReadApKeyValue().c_str(), L"-full");
+ // try full installer now
+ GoogleUpdateSettings::UpdateDiffInstallStatus(false, false,
+ installer_util::INSTALL_FAILED,
+ kTestProductGuid);
+ EXPECT_STREQ(ReadApKeyValue().c_str(), L"");
+ // Now cleanup to leave the system in unchanged state.
+ // - Diff installer creates an ap key if it didnt exist, so delete this ap key
+ // - If we created any reg key path for ap, roll it back
+ // - Finally restore the original value of ap key.
+ key.Open(HKEY_CURRENT_USER, reg_key.c_str(), KEY_ALL_ACCESS);
+ key.DeleteValue(google_update::kRegApField);
+ work_item_list->Rollback();
+ if (ap_key_deleted) {
+ work_item_list.reset(WorkItem::CreateWorkItemList());
+ ASSERT_TRUE(CreateApKey(work_item_list.get(), ap_key_value))
+ << "Failed to restore ap key.";
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698