summaryrefslogtreecommitdiffstats
path: root/chrome/installer/setup
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/installer/setup')
-rw-r--r--chrome/installer/setup/setup_main.cc44
-rw-r--r--chrome/installer/setup/setup_util.cc43
-rw-r--r--chrome/installer/setup/setup_util.h7
-rw-r--r--chrome/installer/setup/setup_util_unittest.cc69
4 files changed, 121 insertions, 42 deletions
diff --git a/chrome/installer/setup/setup_main.cc b/chrome/installer/setup/setup_main.cc
index 3c314ff..f976653 100644
--- a/chrome/installer/setup/setup_main.cc
+++ b/chrome/installer/setup/setup_main.cc
@@ -204,47 +204,6 @@ installer_util::InstallStatus RenameChromeExecutables(bool system_install) {
return ret;
}
-// Parse command line and read master profile, if present, to get distribution
-// related install options.
-DictionaryValue* GetInstallPreferences(const CommandLine& cmd_line) {
- DictionaryValue* prefs = NULL;
-
- if (cmd_line.HasSwitch(installer_util::switches::kInstallerData)) {
- FilePath prefs_path(
- cmd_line.GetSwitchValue(installer_util::switches::kInstallerData));
- prefs = installer_util::ParseDistributionPreferences(prefs_path);
- }
-
- if (!prefs)
- prefs = new DictionaryValue();
-
- if (cmd_line.HasSwitch(installer_util::switches::kCreateAllShortcuts))
- installer_util::SetDistroBooleanPreference(
- prefs, installer_util::master_preferences::kCreateAllShortcuts, true);
-
- if (cmd_line.HasSwitch(installer_util::switches::kDoNotLaunchChrome))
- installer_util::SetDistroBooleanPreference(
- prefs, installer_util::master_preferences::kDoNotLaunchChrome, true);
-
- if (cmd_line.HasSwitch(installer_util::switches::kMakeChromeDefault))
- installer_util::SetDistroBooleanPreference(
- prefs, installer_util::master_preferences::kMakeChromeDefault, true);
-
- if (cmd_line.HasSwitch(installer_util::switches::kSystemLevel))
- installer_util::SetDistroBooleanPreference(
- prefs, installer_util::master_preferences::kSystemLevel, true);
-
- if (cmd_line.HasSwitch(installer_util::switches::kVerboseLogging))
- installer_util::SetDistroBooleanPreference(
- prefs, installer_util::master_preferences::kVerboseLogging, true);
-
- if (cmd_line.HasSwitch(installer_util::switches::kAltDesktopShortcut))
- installer_util::SetDistroBooleanPreference(
- prefs, installer_util::master_preferences::kAltShortcutText, true);
-
- return prefs;
-}
-
bool CheckPreInstallConditions(const installer::Version* installed_version,
bool system_install,
installer_util::InstallStatus& status) {
@@ -597,7 +556,8 @@ int WINAPI wWinMain(HINSTANCE instance, HINSTANCE prev_instance,
CommandLine::Init(0, NULL);
const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
installer::InitInstallerLogging(parsed_command_line);
- scoped_ptr<DictionaryValue> prefs(GetInstallPreferences(parsed_command_line));
+ scoped_ptr<DictionaryValue> prefs(setup_util::GetInstallPreferences(
+ parsed_command_line));
if (installer_util::GetDistroBooleanPreference(prefs.get(),
installer_util::master_preferences::kVerboseLogging))
logging::SetMinLogLevel(logging::LOG_INFO);
diff --git a/chrome/installer/setup/setup_util.cc b/chrome/installer/setup/setup_util.cc
index 7356ecf..985d704 100644
--- a/chrome/installer/setup/setup_util.cc
+++ b/chrome/installer/setup/setup_util.cc
@@ -8,6 +8,49 @@
#include "base/file_util.h"
#include "base/logging.h"
+#include "chrome/installer/util/master_preferences.h"
+#include "chrome/installer/util/util_constants.h"
+
+
+DictionaryValue* setup_util::GetInstallPreferences(
+ const CommandLine& cmd_line) {
+ DictionaryValue* prefs = NULL;
+
+ if (cmd_line.HasSwitch(installer_util::switches::kInstallerData)) {
+ FilePath prefs_path(
+ cmd_line.GetSwitchValue(installer_util::switches::kInstallerData));
+ prefs = installer_util::ParseDistributionPreferences(prefs_path);
+ }
+
+ if (!prefs)
+ prefs = new DictionaryValue();
+
+ if (cmd_line.HasSwitch(installer_util::switches::kCreateAllShortcuts))
+ installer_util::SetDistroBooleanPreference(
+ prefs, installer_util::master_preferences::kCreateAllShortcuts, true);
+
+ if (cmd_line.HasSwitch(installer_util::switches::kDoNotLaunchChrome))
+ installer_util::SetDistroBooleanPreference(
+ prefs, installer_util::master_preferences::kDoNotLaunchChrome, true);
+
+ if (cmd_line.HasSwitch(installer_util::switches::kMakeChromeDefault))
+ installer_util::SetDistroBooleanPreference(
+ prefs, installer_util::master_preferences::kMakeChromeDefault, true);
+
+ if (cmd_line.HasSwitch(installer_util::switches::kSystemLevel))
+ installer_util::SetDistroBooleanPreference(
+ prefs, installer_util::master_preferences::kSystemLevel, true);
+
+ if (cmd_line.HasSwitch(installer_util::switches::kVerboseLogging))
+ installer_util::SetDistroBooleanPreference(
+ prefs, installer_util::master_preferences::kVerboseLogging, true);
+
+ if (cmd_line.HasSwitch(installer_util::switches::kAltDesktopShortcut))
+ installer_util::SetDistroBooleanPreference(
+ prefs, installer_util::master_preferences::kAltShortcutText, true);
+
+ return prefs;
+}
installer::Version* setup_util::GetVersionFromDir(
const std::wstring& chrome_path) {
diff --git a/chrome/installer/setup/setup_util.h b/chrome/installer/setup/setup_util.h
index c9e067f..fc06482 100644
--- a/chrome/installer/setup/setup_util.h
+++ b/chrome/installer/setup/setup_util.h
@@ -7,9 +7,16 @@
#ifndef CHROME_INSTALLER_SETUP_SETUP_UTIL_H_
#define CHROME_INSTALLER_SETUP_SETUP_UTIL_H_
+#include "base/command_line.h"
+#include "base/values.h"
#include "chrome/installer/util/version.h"
namespace setup_util {
+ // Parse command line and read master preferences, if present, to get
+ // distribution related install options. Merge them if any command line
+ // options present (command line value takes precedence).
+ DictionaryValue* GetInstallPreferences(const CommandLine& cmd_line);
+
// Find the version of Chrome from an install source directory.
// Chrome_path should contain a version folder.
// Returns the first version found or NULL if no version is found.
diff --git a/chrome/installer/setup/setup_util_unittest.cc b/chrome/installer/setup/setup_util_unittest.cc
index 42cecdf..d163816 100644
--- a/chrome/installer/setup/setup_util_unittest.cc
+++ b/chrome/installer/setup/setup_util_unittest.cc
@@ -13,6 +13,7 @@
#include "base/process_util.h"
#include "base/string_util.h"
#include "chrome/installer/setup/setup_util.h"
+#include "chrome/installer/util/master_preferences.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
@@ -40,6 +41,74 @@ namespace {
};
};
+// Test that we are parsing master preferences correctly.
+TEST_F(SetupUtilTest, GetInstallPreferencesTest) {
+ // Create a temporary prefs file.
+ std::wstring prefs_file;
+ ASSERT_TRUE(file_util::CreateTemporaryFileName(&prefs_file));
+ const char text[] =
+ "{ \n"
+ " \"distribution\": { \n"
+ " \"skip_first_run_ui\": true,\n"
+ " \"create_all_shortcuts\": false,\n"
+ " \"do_not_launch_chrome\": true,\n"
+ " \"system_level\": true,\n"
+ " \"verbose_logging\": false\n"
+ " }\n"
+ "} \n";
+ EXPECT_TRUE(file_util::WriteFile(prefs_file, text, sizeof(text)));
+
+ // Make sure command line values override the values in master preferences.
+ std::wstring cmd_str(L"setup.exe --installerdata=\"" + prefs_file + L"\"");
+ cmd_str.append(L" --create-all-shortcuts");
+ cmd_str.append(L" --do-not-launch-chrome");
+ cmd_str.append(L" --alt-desktop-shortcut");
+ CommandLine cmd_line(L"");
+ cmd_line.ParseFromString(cmd_str);
+ scoped_ptr<DictionaryValue> prefs(
+ setup_util::GetInstallPreferences(cmd_line));
+ EXPECT_TRUE(prefs.get() != NULL);
+
+ // Check prefs that do not have any equivalent command line option.
+ EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kDistroSkipFirstRunPref));
+ EXPECT_FALSE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kDistroShowWelcomePage));
+
+ // Now check that prefs got merged correctly.
+ EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kCreateAllShortcuts));
+ EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kDoNotLaunchChrome));
+ EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kAltShortcutText));
+ EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kSystemLevel));
+ EXPECT_FALSE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kVerboseLogging));
+
+ // Delete temporary prefs file.
+ EXPECT_TRUE(file_util::Delete(prefs_file, false));
+
+ // Check that if master prefs doesn't exist, we can still parse the common
+ // prefs.
+ cmd_str = L"setup.exe --create-all-shortcuts --do-not-launch-chrome"
+ L" --alt-desktop-shortcut";
+ cmd_line.ParseFromString(cmd_str);
+ prefs.reset(setup_util::GetInstallPreferences(cmd_line));
+ EXPECT_TRUE(prefs.get() != NULL);
+ EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kCreateAllShortcuts));
+ EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kDoNotLaunchChrome));
+ EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kAltShortcutText));
+ EXPECT_FALSE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kSystemLevel));
+ EXPECT_FALSE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kVerboseLogging));
+}
+
// Test that we are parsing Chrome version correctly.
TEST_F(SetupUtilTest, GetVersionFromDirTest) {
// Create a version dir