diff options
author | kuchhal@chromium.org <kuchhal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-05 17:42:50 +0000 |
---|---|---|
committer | kuchhal@chromium.org <kuchhal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-05 17:42:50 +0000 |
commit | 937efca2308c6640b0cbee15051c50d3413760de (patch) | |
tree | b7a5567c35711773a2909957554432bd978f7ce8 /chrome/installer/setup/setup_util_unittest.cc | |
parent | c9e45da0dec9692d8f59cef2e8c5cdac28baf51b (diff) | |
download | chromium_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/setup/setup_util_unittest.cc')
-rw-r--r-- | chrome/installer/setup/setup_util_unittest.cc | 69 |
1 files changed, 69 insertions, 0 deletions
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 |