#include <shlwapi.h> // For SHDeleteKey.
#include "base/memory/scoped_ptr.h"
+#include "base/path_service.h"
#include "base/strings/utf_string_conversions.h"
+#include "base/test/scoped_path_override.h"
#include "base/test/test_reg_util_win.h"
#include "base/win/registry.h"
+#include "base/win/win_util.h"
#include "chrome/common/chrome_constants.h"
+#include "chrome/installer/util/app_registration_data.h"
#include "chrome/installer/util/browser_distribution.h"
#include "chrome/installer/util/channel_info.h"
#include "chrome/installer/util/fake_installation_state.h"
// and user settings.
class GoogleUpdateSettingsTest : public testing::Test {
protected:
- virtual void SetUp() OVERRIDE {
+ virtual void SetUp() override {
+ base::FilePath program_files_path;
+ PathService::Get(base::DIR_PROGRAM_FILES, &program_files_path);
+ program_files_override_.reset(new base::ScopedPathOverride(
+ base::DIR_PROGRAM_FILES, program_files_path));
+
registry_overrides_.OverrideRegistry(HKEY_LOCAL_MACHINE);
registry_overrides_.OverrideRegistry(HKEY_CURRENT_USER);
}
time_in_minutes) == ERROR_SUCCESS;
}
+ // Keep Program Files path so InstallUtil::IsPerUserInstall doesn't crash.
+ scoped_ptr<base::ScopedPathOverride> program_files_override_;
registry_util::RegistryOverrideManager registry_overrides_;
};
EXPECT_FALSE(is_overridden);
}
+TEST_F(GoogleUpdateSettingsTest, UpdateProfileCountsSystemInstall) {
+ // Pretend to be a system install for GoogleUpdateSettings::IsSystemInstall().
+ base::FilePath program_files_path;
+ PathService::Get(base::DIR_PROGRAM_FILES, &program_files_path);
+ base::ScopedPathOverride dir_module_override(base::DIR_MODULE,
+ program_files_path);
+
+ // No profile count keys present yet.
+ const base::string16& state_key = BrowserDistribution::GetDistribution()->
+ GetAppRegistrationData().GetStateMediumKey();
+ base::string16 num_profiles_path(state_key);
+ num_profiles_path.append(L"\\");
+ num_profiles_path.append(google_update::kRegProfilesActive);
+ base::string16 num_signed_in_path(state_key);
+ num_signed_in_path.append(L"\\");
+ num_signed_in_path.append(google_update::kRegProfilesSignedIn);
+
+ EXPECT_EQ(ERROR_FILE_NOT_FOUND,
+ RegKey().Open(HKEY_LOCAL_MACHINE,
+ num_profiles_path.c_str(),
+ KEY_QUERY_VALUE));
+ EXPECT_EQ(ERROR_FILE_NOT_FOUND,
+ RegKey().Open(HKEY_LOCAL_MACHINE,
+ num_signed_in_path.c_str(),
+ KEY_QUERY_VALUE));
+
+ // Show time! Write the values.
+ GoogleUpdateSettings::UpdateProfileCounts(3, 2);
+
+ // Verify the keys were created.
+ EXPECT_EQ(ERROR_SUCCESS,
+ RegKey().Open(HKEY_LOCAL_MACHINE,
+ num_profiles_path.c_str(),
+ KEY_QUERY_VALUE));
+ EXPECT_EQ(ERROR_SUCCESS,
+ RegKey().Open(HKEY_LOCAL_MACHINE,
+ num_signed_in_path.c_str(),
+ KEY_QUERY_VALUE));
+
+ base::string16 uniquename;
+ EXPECT_TRUE(base::win::GetUserSidString(&uniquename));
+
+ // Verify the values are accessible.
+ DWORD num_profiles = 0;
+ DWORD num_signed_in = 0;
+ base::string16 aggregate;
+ EXPECT_EQ(
+ ERROR_SUCCESS,
+ RegKey(HKEY_LOCAL_MACHINE, num_profiles_path.c_str(),
+ KEY_QUERY_VALUE).ReadValueDW(uniquename.c_str(),
+ &num_profiles));
+ EXPECT_EQ(
+ ERROR_SUCCESS,
+ RegKey(HKEY_LOCAL_MACHINE, num_signed_in_path.c_str(),
+ KEY_QUERY_VALUE).ReadValueDW(uniquename.c_str(),
+ &num_signed_in));
+ EXPECT_EQ(
+ ERROR_SUCCESS,
+ RegKey(HKEY_LOCAL_MACHINE, num_signed_in_path.c_str(),
+ KEY_QUERY_VALUE).ReadValue(google_update::kRegAggregateMethod,
+ &aggregate));
+
+ // Verify the correct values were written.
+ EXPECT_EQ(3, num_profiles);
+ EXPECT_EQ(2, num_signed_in);
+ EXPECT_EQ(L"sum()", aggregate);
+}
+
+TEST_F(GoogleUpdateSettingsTest, UpdateProfileCountsUserInstall) {
+ // Unit tests never operate as an installed application, so will never
+ // be a system install.
+
+ // No profile count values present yet.
+ const base::string16& state_key = BrowserDistribution::GetDistribution()->
+ GetAppRegistrationData().GetStateKey();
+
+ EXPECT_EQ(ERROR_FILE_NOT_FOUND,
+ RegKey().Open(HKEY_CURRENT_USER,
+ state_key.c_str(),
+ KEY_QUERY_VALUE));
+
+ // Show time! Write the values.
+ GoogleUpdateSettings::UpdateProfileCounts(4, 1);
+
+ // Verify the key was created.
+ EXPECT_EQ(ERROR_SUCCESS,
+ RegKey().Open(HKEY_CURRENT_USER,
+ state_key.c_str(),
+ KEY_QUERY_VALUE));
+
+ // Verify the values are accessible.
+ base::string16 num_profiles;
+ base::string16 num_signed_in;
+ EXPECT_EQ(
+ ERROR_SUCCESS,
+ RegKey(HKEY_CURRENT_USER, state_key.c_str(), KEY_QUERY_VALUE).
+ ReadValue(google_update::kRegProfilesActive, &num_profiles));
+ EXPECT_EQ(
+ ERROR_SUCCESS,
+ RegKey(HKEY_CURRENT_USER, state_key.c_str(), KEY_QUERY_VALUE).
+ ReadValue(google_update::kRegProfilesSignedIn, &num_signed_in));
+
+ // Verify the correct values were written.
+ EXPECT_EQ(L"4", num_profiles);
+ EXPECT_EQ(L"1", num_signed_in);
+}
+
#if defined(GOOGLE_CHROME_BUILD)
// Test that the default override is returned if no app-specific override is
}
TEST_F(GoogleUpdateSettingsTest, PerAppUpdatesDisabledByPolicy) {
+ BrowserDistribution* dist = BrowserDistribution::GetDistribution();
EXPECT_TRUE(
- SetUpdatePolicyForAppGuid(kTestProductGuid,
+ SetUpdatePolicyForAppGuid(dist->GetAppGuid(),
GoogleUpdateSettings::UPDATES_DISABLED));
bool is_overridden = false;
GoogleUpdateSettings::UpdatePolicy update_policy =
- GoogleUpdateSettings::GetAppUpdatePolicy(kTestProductGuid,
+ GoogleUpdateSettings::GetAppUpdatePolicy(dist->GetAppGuid(),
&is_overridden);
EXPECT_TRUE(is_overridden);
EXPECT_EQ(GoogleUpdateSettings::UPDATES_DISABLED, update_policy);
- EXPECT_FALSE(GoogleUpdateSettings::AreAutoupdatesEnabled(kTestProductGuid));
+ EXPECT_FALSE(GoogleUpdateSettings::AreAutoupdatesEnabled());
- EXPECT_TRUE(
- GoogleUpdateSettings::ReenableAutoupdatesForApp(kTestProductGuid));
- update_policy = GoogleUpdateSettings::GetAppUpdatePolicy(kTestProductGuid,
+ EXPECT_TRUE(GoogleUpdateSettings::ReenableAutoupdates());
+ update_policy = GoogleUpdateSettings::GetAppUpdatePolicy(dist->GetAppGuid(),
&is_overridden);
// Should still have a policy but now that policy should explicitly enable
// updates.
EXPECT_TRUE(is_overridden);
EXPECT_EQ(GoogleUpdateSettings::AUTOMATIC_UPDATES, update_policy);
- EXPECT_TRUE(GoogleUpdateSettings::AreAutoupdatesEnabled(kTestProductGuid));
+ EXPECT_TRUE(GoogleUpdateSettings::AreAutoupdatesEnabled());
}
TEST_F(GoogleUpdateSettingsTest, PerAppUpdatesEnabledWithGlobalDisabled) {
- // Disable updates globally but enable them for our specific app (the app-
- // specific setting should take precedence).
+ // Disable updates globally but enable them for Chrome (the app-specific
+ // setting should take precedence).
+ BrowserDistribution* dist = BrowserDistribution::GetDistribution();
+ BrowserDistribution* binaries = BrowserDistribution::GetSpecificDistribution(
+ BrowserDistribution::CHROME_BINARIES);
+ EXPECT_TRUE(
+ SetUpdatePolicyForAppGuid(dist->GetAppGuid(),
+ GoogleUpdateSettings::AUTOMATIC_UPDATES));
EXPECT_TRUE(
- SetUpdatePolicyForAppGuid(kTestProductGuid,
+ SetUpdatePolicyForAppGuid(binaries->GetAppGuid(),
GoogleUpdateSettings::AUTOMATIC_UPDATES));
EXPECT_TRUE(SetGlobalUpdatePolicy(GoogleUpdateSettings::UPDATES_DISABLED));
// Make sure we read this as still having updates enabled.
- EXPECT_TRUE(GoogleUpdateSettings::AreAutoupdatesEnabled(kTestProductGuid));
+ EXPECT_TRUE(GoogleUpdateSettings::AreAutoupdatesEnabled());
// Make sure that the reset action returns true and is a no-op.
- EXPECT_TRUE(
- GoogleUpdateSettings::ReenableAutoupdatesForApp(kTestProductGuid));
+ EXPECT_TRUE(GoogleUpdateSettings::ReenableAutoupdates());
+ EXPECT_EQ(GoogleUpdateSettings::AUTOMATIC_UPDATES,
+ GetUpdatePolicyForAppGuid(dist->GetAppGuid()));
EXPECT_EQ(GoogleUpdateSettings::AUTOMATIC_UPDATES,
- GetUpdatePolicyForAppGuid(kTestProductGuid));
+ GetUpdatePolicyForAppGuid(binaries->GetAppGuid()));
EXPECT_EQ(GoogleUpdateSettings::UPDATES_DISABLED, GetGlobalUpdatePolicy());
}
TEST_F(GoogleUpdateSettingsTest, GlobalUpdatesDisabledByPolicy) {
+ BrowserDistribution* dist = BrowserDistribution::GetDistribution();
EXPECT_TRUE(SetGlobalUpdatePolicy(GoogleUpdateSettings::UPDATES_DISABLED));
bool is_overridden = false;
// The contract for GetAppUpdatePolicy states that |is_overridden| should be
// set to false when updates are disabled on a non-app-specific basis.
GoogleUpdateSettings::UpdatePolicy update_policy =
- GoogleUpdateSettings::GetAppUpdatePolicy(kTestProductGuid,
+ GoogleUpdateSettings::GetAppUpdatePolicy(dist->GetAppGuid(),
&is_overridden);
EXPECT_FALSE(is_overridden);
EXPECT_EQ(GoogleUpdateSettings::UPDATES_DISABLED, update_policy);
- EXPECT_FALSE(GoogleUpdateSettings::AreAutoupdatesEnabled(kTestProductGuid));
+ EXPECT_FALSE(GoogleUpdateSettings::AreAutoupdatesEnabled());
- EXPECT_TRUE(
- GoogleUpdateSettings::ReenableAutoupdatesForApp(kTestProductGuid));
- update_policy = GoogleUpdateSettings::GetAppUpdatePolicy(kTestProductGuid,
+ EXPECT_TRUE(GoogleUpdateSettings::ReenableAutoupdates());
+ update_policy = GoogleUpdateSettings::GetAppUpdatePolicy(dist->GetAppGuid(),
&is_overridden);
// Policy should now be to enable updates, |is_overridden| should still be
// false.
EXPECT_FALSE(is_overridden);
EXPECT_EQ(GoogleUpdateSettings::AUTOMATIC_UPDATES, update_policy);
- EXPECT_TRUE(GoogleUpdateSettings::AreAutoupdatesEnabled(kTestProductGuid));
+ EXPECT_TRUE(GoogleUpdateSettings::AreAutoupdatesEnabled());
}
TEST_F(GoogleUpdateSettingsTest, UpdatesDisabledByTimeout) {
// Disable updates altogether.
EXPECT_TRUE(SetUpdateTimeoutOverride(0));
- EXPECT_FALSE(GoogleUpdateSettings::AreAutoupdatesEnabled(kTestProductGuid));
- EXPECT_TRUE(
- GoogleUpdateSettings::ReenableAutoupdatesForApp(kTestProductGuid));
- EXPECT_TRUE(GoogleUpdateSettings::AreAutoupdatesEnabled(kTestProductGuid));
+ EXPECT_FALSE(GoogleUpdateSettings::AreAutoupdatesEnabled());
+ EXPECT_TRUE(GoogleUpdateSettings::ReenableAutoupdates());
+ EXPECT_TRUE(GoogleUpdateSettings::AreAutoupdatesEnabled());
// Set the update period to something unreasonable.
EXPECT_TRUE(SetUpdateTimeoutOverride(
GoogleUpdateSettings::kCheckPeriodOverrideMinutesMax + 1));
- EXPECT_FALSE(GoogleUpdateSettings::AreAutoupdatesEnabled(kTestProductGuid));
- EXPECT_TRUE(
- GoogleUpdateSettings::ReenableAutoupdatesForApp(kTestProductGuid));
- EXPECT_TRUE(GoogleUpdateSettings::AreAutoupdatesEnabled(kTestProductGuid));
+ EXPECT_FALSE(GoogleUpdateSettings::AreAutoupdatesEnabled());
+ EXPECT_TRUE(GoogleUpdateSettings::ReenableAutoupdates());
+ EXPECT_TRUE(GoogleUpdateSettings::AreAutoupdatesEnabled());
}
TEST_F(GoogleUpdateSettingsTest, ExperimentsLabelHelperSystem) {
protected:
static const wchar_t kDummyCommand[];
- virtual void SetUp() OVERRIDE {
+ virtual void SetUp() override {
GoogleUpdateSettingsTest::SetUp();
system_install_ = GetParam();
root_key_ = system_install_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
protected:
static const wchar_t kDummyVersion[];
- virtual void SetUp() OVERRIDE {
+ virtual void SetUp() override {
GoogleUpdateSettingsTest::SetUp();
system_install_ = GetParam();
root_key_ = system_install_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
static void SetUpTestCase();
static void TearDownTestCase();
protected:
- virtual void SetUp() OVERRIDE;
+ virtual void SetUp() override;
static void MakeChromeMultiInstall(HKEY root_key);
static void ApplySetting(StatsState::StateSetting setting,
HKEY root_key,