summaryrefslogtreecommitdiffstats
path: root/chrome/installer
diff options
context:
space:
mode:
authorkuchhal@chromium.org <kuchhal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-05 17:42:50 +0000
committerkuchhal@chromium.org <kuchhal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-05 17:42:50 +0000
commit937efca2308c6640b0cbee15051c50d3413760de (patch)
treeb7a5567c35711773a2909957554432bd978f7ce8 /chrome/installer
parentc9e45da0dec9692d8f59cef2e8c5cdac28baf51b (diff)
downloadchromium_src-937efca2308c6640b0cbee15051c50d3413760de.zip
chromium_src-937efca2308c6640b0cbee15051c50d3413760de.tar.gz
chromium_src-937efca2308c6640b0cbee15051c50d3413760de.tar.bz2
Add some unit tests for master preferences parsing code.
BUG=12849 TEST=none Review URL: http://codereview.chromium.org/160560 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22493 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/installer')
-rw-r--r--chrome/installer/installer.gyp2
-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
-rw-r--r--chrome/installer/util/browser_distribution_unittest.cc47
-rw-r--r--chrome/installer/util/google_chrome_distribution_unittest.cc123
-rw-r--r--chrome/installer/util/master_preferences_unittest.cc189
8 files changed, 359 insertions, 165 deletions
diff --git a/chrome/installer/installer.gyp b/chrome/installer/installer.gyp
index 33fe897..c926266 100644
--- a/chrome/installer/installer.gyp
+++ b/chrome/installer/installer.gyp
@@ -146,6 +146,7 @@
'sources': [
'setup/compat_checks_unittest.cc',
'setup/setup_constants.cc',
+ 'util/browser_distribution_unittest.cc',
'util/copy_tree_work_item_unittest.cc',
'util/create_dir_work_item_unittest.cc',
'util/create_reg_key_work_item_unittest.cc',
@@ -155,6 +156,7 @@
'util/helper_unittest.cc',
'util/installer_util_unittests.rc',
'util/installer_util_unittests_resource.h',
+ 'util/master_preferences_unittest.cc',
'util/move_tree_work_item_unittest.cc',
'util/run_all_unittests.cc',
'util/set_reg_value_work_item_unittest.cc',
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
diff --git a/chrome/installer/util/browser_distribution_unittest.cc b/chrome/installer/util/browser_distribution_unittest.cc
new file mode 100644
index 0000000..55d0d8f
--- /dev/null
+++ b/chrome/installer/util/browser_distribution_unittest.cc
@@ -0,0 +1,47 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+// Unit tests for BrowserDistribution class.
+
+#include "chrome/installer/util/browser_distribution.h"
+#include "chrome/installer/util/shell_util.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+class BrowserDistributionTest : public testing::Test {
+ protected:
+ virtual void SetUp() {
+ // Currently no setup required.
+ }
+
+ virtual void TearDown() {
+ // Currently no tear down required.
+ }
+};
+} // namespace
+
+// The distribution strings should not be empty. The unit tests are not linking
+// with the chrome resources so we cannot test official build.
+TEST(BrowserDistributionTest, StringsTest) {
+ BrowserDistribution *dist = BrowserDistribution::GetDistribution();
+ ASSERT_TRUE(dist != NULL);
+ std::wstring name = dist->GetApplicationName();
+ EXPECT_FALSE(name.empty());
+ std::wstring desc = dist->GetAppDescription();
+ EXPECT_FALSE(desc.empty());
+ std::wstring alt_name = dist->GetAlternateApplicationName();
+ EXPECT_FALSE(alt_name.empty());
+}
+
+// The shortcut strings obtained by the shell utility functions should not
+// be empty or be the same.
+TEST(BrowserDistributionTest, AlternateAndNormalShortcutName) {
+ std::wstring normal_name;
+ std::wstring alternate_name;
+ EXPECT_TRUE(ShellUtil::GetChromeShortcutName(&normal_name, false));
+ EXPECT_TRUE(ShellUtil::GetChromeShortcutName(&alternate_name, true));
+ EXPECT_NE(normal_name, alternate_name);
+ EXPECT_FALSE(normal_name.empty());
+ EXPECT_FALSE(alternate_name.empty());
+}
diff --git a/chrome/installer/util/google_chrome_distribution_unittest.cc b/chrome/installer/util/google_chrome_distribution_unittest.cc
index f84916b..23f174a 100644
--- a/chrome/installer/util/google_chrome_distribution_unittest.cc
+++ b/chrome/installer/util/google_chrome_distribution_unittest.cc
@@ -13,8 +13,6 @@
#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/master_preferences.h"
-#include "chrome/installer/util/shell_util.h"
#include "chrome/installer/util/work_item_list.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -229,124 +227,3 @@ TEST_F(GoogleChromeDistributionTest, TestExtractUninstallMetrics) {
EXPECT_EQ(expected_url_string, uninstall_metrics_string);
}
#endif
-
-// The distribution strings should not be empty. The unit tests are not linking
-// with the chrome resources so we cannot test official build.
-TEST(BrowserDistribution, StringsTest) {
- BrowserDistribution *dist = BrowserDistribution::GetDistribution();
- ASSERT_TRUE(dist != NULL);
- std::wstring name = dist->GetApplicationName();
- EXPECT_FALSE(name.empty());
- std::wstring desc = dist->GetAppDescription();
- EXPECT_FALSE(desc.empty());
- std::wstring alt_name = dist->GetAlternateApplicationName();
- EXPECT_FALSE(alt_name.empty());
-}
-
-// The shortcut strings obtained by the shell utility functions should not
-// be empty or be the same.
-TEST(BrowserDistribution, AlternateAndNormalShortcutName) {
- std::wstring normal_name;
- std::wstring alternate_name;
- EXPECT_TRUE(ShellUtil::GetChromeShortcutName(&normal_name, false));
- EXPECT_TRUE(ShellUtil::GetChromeShortcutName(&alternate_name, true));
- EXPECT_NE(normal_name, alternate_name);
- EXPECT_FALSE(normal_name.empty());
- EXPECT_FALSE(alternate_name.empty());
-}
-
-TEST(MasterPreferences, ParseDistroParams) {
- std::wstring prefs_file;
- ASSERT_TRUE(file_util::CreateTemporaryFileName(&prefs_file));
- const char text[] =
- "{ \n"
- " \"distribution\": { \n"
- " \"skip_first_run_ui\": true,\n"
- " \"show_welcome_page\": true,\n"
- " \"import_search_engine\": true,\n"
- " \"import_history\": true,\n"
- " \"import_bookmarks\": true,\n"
- " \"import_home_page\": true,\n"
- " \"create_all_shortcuts\": true,\n"
- " \"do_not_launch_chrome\": true,\n"
- " \"make_chrome_default\": true,\n"
- " \"make_chrome_default_for_user\": true,\n"
- " \"system_level\": true,\n"
- " \"verbose_logging\": true,\n"
- " \"require_eula\": true,\n"
- " \"alternate_shortcut_text\": true\n"
- "},\n"
- " \"blah\": {\n"
- " \"import_history\": false\n"
- " }\n"
- "} \n";
-
- EXPECT_TRUE(file_util::WriteFile(prefs_file, text, sizeof(text)));
- scoped_ptr<DictionaryValue> prefs(
- installer_util::ParseDistributionPreferences(
- FilePath::FromWStringHack(prefs_file)));
- EXPECT_TRUE(prefs.get() != NULL);
- EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
- installer_util::master_preferences::kDistroSkipFirstRunPref));
- EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
- installer_util::master_preferences::kDistroShowWelcomePage));
-
- EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
- installer_util::master_preferences::kDistroImportSearchPref));
- EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
- installer_util::master_preferences::kDistroImportHistoryPref));
- EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
- installer_util::master_preferences::kDistroImportBookmarksPref));
- EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
- installer_util::master_preferences::kDistroImportHomePagePref));
-
- 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::kMakeChromeDefault));
- EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
- installer_util::master_preferences::kMakeChromeDefaultForUser));
-
- EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
- installer_util::master_preferences::kSystemLevel));
- EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
- installer_util::master_preferences::kVerboseLogging));
- EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
- installer_util::master_preferences::kRequireEula));
- EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
- installer_util::master_preferences::kAltShortcutText));
-
- EXPECT_TRUE(file_util::Delete(prefs_file, false));
-}
-
-TEST(MasterPreferences, FirstRunTabs) {
- std::wstring prefs_file;
- ASSERT_TRUE(file_util::CreateTemporaryFileName(&prefs_file));
- const char text[] =
- "{ \n"
- " \"distribution\": { \n"
- " \"something here\": true\n"
- " },\n"
- " \"first_run_tabs\": [\n"
- " \"http://google.com/f1\",\n"
- " \"https://google.com/f2\",\n"
- " \"new_tab_page\"\n"
- " ]\n"
- "} \n";
-
- EXPECT_TRUE(file_util::WriteFile(prefs_file, text, sizeof(text)));
- scoped_ptr<DictionaryValue> prefs(
- installer_util::ParseDistributionPreferences(
- FilePath::FromWStringHack(prefs_file)));
- EXPECT_TRUE(prefs.get() != NULL);
-
- typedef std::vector<std::wstring> TabsVector;
- TabsVector tabs = installer_util::GetFirstRunTabs(prefs.get());
- ASSERT_EQ(3, tabs.size());
- EXPECT_EQ(L"http://google.com/f1", tabs[0]);
- EXPECT_EQ(L"https://google.com/f2", tabs[1]);
- EXPECT_EQ(L"new_tab_page", tabs[2]);
- EXPECT_TRUE(file_util::Delete(prefs_file, false));
-}
diff --git a/chrome/installer/util/master_preferences_unittest.cc b/chrome/installer/util/master_preferences_unittest.cc
new file mode 100644
index 0000000..8132374
--- /dev/null
+++ b/chrome/installer/util/master_preferences_unittest.cc
@@ -0,0 +1,189 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+// Unit tests for master preferences related methods.
+
+#include "base/scoped_ptr.h"
+#include "base/file_util.h"
+#include "chrome/common/json_value_serializer.h"
+#include "chrome/installer/util/master_preferences.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+class MasterPreferencesTest : public testing::Test {
+ protected:
+ virtual void SetUp() {
+ // Currently no setup required.
+ }
+
+ virtual void TearDown() {
+ // Currently no tear down required.
+ }
+};
+} // namespace
+
+TEST(MasterPreferencesTest, ParseDistroParams) {
+ std::wstring prefs_file;
+ ASSERT_TRUE(file_util::CreateTemporaryFileName(&prefs_file));
+ const char text[] =
+ "{ \n"
+ " \"distribution\": { \n"
+ " \"skip_first_run_ui\": true,\n"
+ " \"show_welcome_page\": true,\n"
+ " \"import_search_engine\": true,\n"
+ " \"import_history\": true,\n"
+ " \"import_bookmarks\": true,\n"
+ " \"import_home_page\": true,\n"
+ " \"create_all_shortcuts\": true,\n"
+ " \"do_not_launch_chrome\": true,\n"
+ " \"make_chrome_default\": true,\n"
+ " \"make_chrome_default_for_user\": true,\n"
+ " \"system_level\": true,\n"
+ " \"verbose_logging\": true,\n"
+ " \"require_eula\": true,\n"
+ " \"alternate_shortcut_text\": true,\n"
+ " \"oem_bubble\": true,\n"
+ " \"chrome_shortcut_icon_index\": 1,\n"
+ " \"ping_delay\": 40\n"
+ " },\n"
+ " \"blah\": {\n"
+ " \"import_history\": false\n"
+ " }\n"
+ "} \n";
+
+ EXPECT_TRUE(file_util::WriteFile(prefs_file, text, sizeof(text)));
+ scoped_ptr<DictionaryValue> prefs(
+ installer_util::ParseDistributionPreferences(
+ FilePath::FromWStringHack(prefs_file)));
+ EXPECT_TRUE(prefs.get() != NULL);
+ EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kDistroSkipFirstRunPref));
+ EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kDistroShowWelcomePage));
+
+ EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kDistroImportSearchPref));
+ EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kDistroImportHistoryPref));
+ EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kDistroImportBookmarksPref));
+ EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kDistroImportHomePagePref));
+
+ 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::kMakeChromeDefault));
+ EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kMakeChromeDefaultForUser));
+
+ EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kSystemLevel));
+ EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kVerboseLogging));
+ EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kRequireEula));
+ EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kAltShortcutText));
+
+ EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kAltFirstRunBubble));
+ int icon_index = 0;
+ EXPECT_TRUE(installer_util::GetDistroIntegerPreference(prefs.get(),
+ installer_util::master_preferences::kChromeShortcutIconIndex,
+ &icon_index));
+ EXPECT_EQ(icon_index, 1);
+ int ping_delay = 90;
+ EXPECT_TRUE(installer_util::GetDistroIntegerPreference(prefs.get(),
+ installer_util::master_preferences::kDistroPingDelay, &ping_delay));
+ EXPECT_EQ(ping_delay, 40);
+ EXPECT_TRUE(file_util::Delete(prefs_file, false));
+}
+
+TEST(MasterPreferencesTest, ParseMissingDistroParams) {
+ std::wstring prefs_file;
+ ASSERT_TRUE(file_util::CreateTemporaryFileName(&prefs_file));
+ const char text[] =
+ "{ \n"
+ " \"distribution\": { \n"
+ " \"skip_first_run_ui\": true,\n"
+ " \"import_search_engine\": true,\n"
+ " \"import_bookmarks\": false,\n"
+ " \"create_all_shortcuts\": true,\n"
+ " \"do_not_launch_chrome\": true,\n"
+ " \"chrome_shortcut_icon_index\": \"bac\"\n"
+ " }\n"
+ "} \n";
+
+ EXPECT_TRUE(file_util::WriteFile(prefs_file, text, sizeof(text)));
+ scoped_ptr<DictionaryValue> prefs(
+ installer_util::ParseDistributionPreferences(
+ FilePath::FromWStringHack(prefs_file)));
+ EXPECT_TRUE(prefs.get() != NULL);
+ EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kDistroSkipFirstRunPref));
+ EXPECT_FALSE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kDistroShowWelcomePage));
+
+ EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kDistroImportSearchPref));
+ EXPECT_FALSE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kDistroImportHistoryPref));
+ EXPECT_FALSE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kDistroImportBookmarksPref));
+ EXPECT_FALSE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kDistroImportHomePagePref));
+
+ 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_FALSE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kMakeChromeDefault));
+ EXPECT_FALSE(installer_util::GetDistroBooleanPreference(prefs.get(),
+ installer_util::master_preferences::kMakeChromeDefaultForUser));
+
+ int icon_index = 0;
+ EXPECT_FALSE(installer_util::GetDistroIntegerPreference(prefs.get(),
+ installer_util::master_preferences::kChromeShortcutIconIndex,
+ &icon_index));
+ EXPECT_EQ(icon_index, 0);
+ int ping_delay = 90;
+ EXPECT_FALSE(installer_util::GetDistroIntegerPreference(prefs.get(),
+ installer_util::master_preferences::kDistroPingDelay, &ping_delay));
+ EXPECT_EQ(ping_delay, 90);
+ EXPECT_TRUE(file_util::Delete(prefs_file, false));
+}
+
+TEST(MasterPreferencesTest, FirstRunTabs) {
+ std::wstring prefs_file;
+ ASSERT_TRUE(file_util::CreateTemporaryFileName(&prefs_file));
+ const char text[] =
+ "{ \n"
+ " \"distribution\": { \n"
+ " \"something here\": true\n"
+ " },\n"
+ " \"first_run_tabs\": [\n"
+ " \"http://google.com/f1\",\n"
+ " \"https://google.com/f2\",\n"
+ " \"new_tab_page\"\n"
+ " ]\n"
+ "} \n";
+
+ EXPECT_TRUE(file_util::WriteFile(prefs_file, text, sizeof(text)));
+ scoped_ptr<DictionaryValue> prefs(
+ installer_util::ParseDistributionPreferences(
+ FilePath::FromWStringHack(prefs_file)));
+ EXPECT_TRUE(prefs.get() != NULL);
+
+ typedef std::vector<std::wstring> TabsVector;
+ TabsVector tabs = installer_util::GetFirstRunTabs(prefs.get());
+ ASSERT_EQ(3, tabs.size());
+ EXPECT_EQ(L"http://google.com/f1", tabs[0]);
+ EXPECT_EQ(L"https://google.com/f2", tabs[1]);
+ EXPECT_EQ(L"new_tab_page", tabs[2]);
+ EXPECT_TRUE(file_util::Delete(prefs_file, false));
+}