summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkuchhal@chromium.org <kuchhal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-09 23:07:24 +0000
committerkuchhal@chromium.org <kuchhal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-09 23:07:24 +0000
commitd9b168764a9e7ad7dcd2561791041f660a54cdde (patch)
treef7815b644713f5486cf582eba7101d88198e1c7e
parent93bfaa60ad72df01797729ecb8cfd4a35b9d401d (diff)
downloadchromium_src-d9b168764a9e7ad7dcd2561791041f660a54cdde.zip
chromium_src-d9b168764a9e7ad7dcd2561791041f660a54cdde.tar.gz
chromium_src-d9b168764a9e7ad7dcd2561791041f660a54cdde.tar.bz2
Create "ap" key to fallback on full installer even if the key didnt exist (for Google Chrome only).
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1943 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/installer/util/google_chrome_distribution.cc29
-rw-r--r--chrome/installer/util/google_chrome_distribution_unittest.cc113
2 files changed, 132 insertions, 10 deletions
diff --git a/chrome/installer/util/google_chrome_distribution.cc b/chrome/installer/util/google_chrome_distribution.cc
index 443ba43..e9c7b01 100644
--- a/chrome/installer/util/google_chrome_distribution.cc
+++ b/chrome/installer/util/google_chrome_distribution.cc
@@ -177,16 +177,25 @@ void GoogleChromeDistribution::UpdateDiffInstallStatus(bool system_install,
RegKey key;
std::wstring ap_key_value;
- std::wstring chrome_google_update_state_key(
- google_update::kRegPathClientState);
- chrome_google_update_state_key.append(L"\\");
- chrome_google_update_state_key.append(google_update::kChromeGuid);
- if (!key.Open(reg_root, chrome_google_update_state_key.c_str(),
- KEY_ALL_ACCESS) || !key.ReadValue(google_update::kRegApFieldName,
- &ap_key_value)) {
- LOG(INFO) << "Application key not found. Returning without changing it.";
- key.Close();
- return;
+ std::wstring reg_key(google_update::kRegPathClientState);
+ reg_key.append(L"\\");
+ reg_key.append(google_update::kChromeGuid);
+ if (!key.Open(reg_root, reg_key.c_str(), KEY_ALL_ACCESS) ||
+ !key.ReadValue(google_update::kRegApFieldName, &ap_key_value)) {
+ LOG(INFO) << "Application key not found.";
+ if (!incremental_install || !GetInstallReturnCode(install_status)) {
+ LOG(INFO) << "Returning without changing application key.";
+ key.Close();
+ return;
+ } else if (!key.Valid()) {
+ reg_key.assign(google_update::kRegPathClientState);
+ if (!key.Open(reg_root, reg_key.c_str(), KEY_ALL_ACCESS) ||
+ !key.CreateKey(google_update::kChromeGuid, KEY_ALL_ACCESS)) {
+ LOG(ERROR) << "Failed to create application key.";
+ key.Close();
+ return;
+ }
+ }
}
std::wstring new_value = GoogleChromeDistribution::GetNewGoogleUpdateApKey(
diff --git a/chrome/installer/util/google_chrome_distribution_unittest.cc b/chrome/installer/util/google_chrome_distribution_unittest.cc
index 3a156b9..be8f416 100644
--- a/chrome/installer/util/google_chrome_distribution_unittest.cc
+++ b/chrome/installer/util/google_chrome_distribution_unittest.cc
@@ -6,8 +6,12 @@
#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_chrome_distribution.h"
+#include "chrome/installer/util/work_item_list.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
@@ -20,6 +24,41 @@ class GoogleChromeDistributionTest : public testing::Test {
virtual void TearDown() {
// Currently no tear down required.
}
+
+ // Creates "ap" key with the value given as parameter. Also adds work
+ // items to work_item_list given so that they can be rollbed back later.
+ bool CreateApKey(WorkItemList* work_item_list, 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::kRegApFieldName, value.c_str(), true);
+ if (!work_item_list->Do()) {
+ work_item_list->Rollback();
+ return false;
+ }
+ return true;
+ }
+
+ // Returns the key path of "ap" key Google\Update\ClientState\<chrome-guid>
+ std::wstring GetApKeyPath() {
+ std::wstring reg_key(google_update::kRegPathClientState);
+ reg_key.append(L"\\");
+ reg_key.append(google_update::kChromeGuid);
+ 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::kRegApFieldName, &ap_key_value)) {
+ return ap_key_value;
+ }
+ return std::wstring();
+ }
};
} // namespace
@@ -67,5 +106,79 @@ TEST_F(GoogleChromeDistributionTest, GetNewGoogleUpdateApKeyTest) {
EXPECT_EQ(dist->GetNewGoogleUpdateApKey(false, f, L"1.1-dev-full"),
L"1.1-dev");
}
+
+TEST_F(GoogleChromeDistributionTest, UpdateDiffInstallStatusTest) {
+ // Get Google Chrome distribution
+ GoogleChromeDistribution* dist = static_cast<GoogleChromeDistribution*>(
+ BrowserDistribution::GetDistribution());
+
+ scoped_ptr<WorkItemList> work_item_list(WorkItem::CreateWorkItemList());
+ // Test incremental install failure
+ if (!CreateApKey(work_item_list.get(), L""))
+ GTEST_FATAL_FAILURE("Failed to create ap key.");
+ dist->UpdateDiffInstallStatus(false, true, installer_util::INSTALL_FAILED);
+ EXPECT_STREQ(ReadApKeyValue().c_str(), L"-full");
+ work_item_list->Rollback();
+
+ work_item_list.reset(WorkItem::CreateWorkItemList());
+ // Test incremental install success
+ if (!CreateApKey(work_item_list.get(), L""))
+ GTEST_FATAL_FAILURE("Failed to create ap key.");
+ dist->UpdateDiffInstallStatus(false, true,
+ installer_util::FIRST_INSTALL_SUCCESS);
+ EXPECT_STREQ(ReadApKeyValue().c_str(), L"");
+ work_item_list->Rollback();
+
+ work_item_list.reset(WorkItem::CreateWorkItemList());
+ // Test full install failure
+ if (!CreateApKey(work_item_list.get(), L"-full"))
+ GTEST_FATAL_FAILURE("Failed to create ap key.");
+ dist->UpdateDiffInstallStatus(false, false, installer_util::INSTALL_FAILED);
+ EXPECT_STREQ(ReadApKeyValue().c_str(), L"");
+ work_item_list->Rollback();
+
+ work_item_list.reset(WorkItem::CreateWorkItemList());
+ // Test full install success
+ if (!CreateApKey(work_item_list.get(), L"-full"))
+ GTEST_FATAL_FAILURE("Failed to create ap key.");
+ dist->UpdateDiffInstallStatus(false, false,
+ installer_util::FIRST_INSTALL_SUCCESS);
+ 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);
+ if (!work_item_list->Do())
+ GTEST_FATAL_FAILURE("Failed to create ClientState key.");
+ } else if (key.DeleteValue(google_update::kRegApFieldName)) {
+ ap_key_deleted = true;
+ }
+ // try differential installer
+ dist->UpdateDiffInstallStatus(false, true, installer_util::INSTALL_FAILED);
+ EXPECT_STREQ(ReadApKeyValue().c_str(), L"-full");
+ // try full installer now
+ dist->UpdateDiffInstallStatus(false, false, installer_util::INSTALL_FAILED);
+ 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::kRegApFieldName);
+ work_item_list->Rollback();
+ if (ap_key_deleted) {
+ work_item_list.reset(WorkItem::CreateWorkItemList());
+ if (!CreateApKey(work_item_list.get(), ap_key_value))
+ GTEST_FATAL_FAILURE("Failed to restore ap key.");
+ }
+
+}
#endif