summaryrefslogtreecommitdiffstats
path: root/chrome/installer
diff options
context:
space:
mode:
authorcpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-26 20:21:40 +0000
committercpu@chromium.org <cpu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-26 20:21:40 +0000
commita5391559831871c15cb5239c06c39753efed209a (patch)
treeab81f5f083ab73587d3b93430e63529e21c6c21d /chrome/installer
parente3be97ce298466ce151ae856b3bf4164ec5a87c5 (diff)
downloadchromium_src-a5391559831871c15cb5239c06c39753efed209a.zip
chromium_src-a5391559831871c15cb5239c06c39753efed209a.tar.gz
chromium_src-a5391559831871c15cb5239c06c39753efed209a.tar.bz2
First part of the pre-set bookmarks feature
- master prefs format (just url) - defer actual bookmark fu, because early on the bookmarkmodel and other services are not yet running. - cleanup master prefs test, too much code duplication - cleanup ProcessMasterPreferences it had too many params BUG=32728 TEST=unit test included Review URL: http://codereview.chromium.org/660116 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40150 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/installer')
-rw-r--r--chrome/installer/util/master_preferences.cc42
-rw-r--r--chrome/installer/util/master_preferences.h16
-rw-r--r--chrome/installer/util/master_preferences_unittest.cc60
3 files changed, 82 insertions, 36 deletions
diff --git a/chrome/installer/util/master_preferences.cc b/chrome/installer/util/master_preferences.cc
index 176c2fb..cf26c3e 100644
--- a/chrome/installer/util/master_preferences.cc
+++ b/chrome/installer/util/master_preferences.cc
@@ -11,6 +11,27 @@
namespace {
const wchar_t* kDistroDict = L"distribution";
+
+std::vector<std::wstring> GetNamedList(const wchar_t* name,
+ const DictionaryValue* prefs) {
+ std::vector<std::wstring> list;
+ if (!prefs)
+ return list;
+ ListValue* value_list = NULL;
+ if (!prefs->GetList(name, &value_list))
+ return list;
+ for (size_t i = 0; i < value_list->GetSize(); ++i) {
+ Value* entry;
+ std::wstring str_entry;
+ if (!value_list->Get(i, &entry) || !entry->GetAsString(&str_entry)) {
+ NOTREACHED();
+ break;
+ }
+ list.push_back(str_entry);
+ }
+ return list;
+}
+
}
namespace installer_util {
@@ -92,22 +113,11 @@ DictionaryValue* ParseDistributionPreferences(
}
std::vector<std::wstring> GetFirstRunTabs(const DictionaryValue* prefs) {
- std::vector<std::wstring> launch_tabs;
- if (!prefs)
- return launch_tabs;
- ListValue* tabs_list = NULL;
- if (!prefs->GetList(L"first_run_tabs", &tabs_list))
- return launch_tabs;
- for (size_t i = 0; i < tabs_list->GetSize(); ++i) {
- Value* entry;
- std::wstring tab_entry;
- if (!tabs_list->Get(i, &entry) || !entry->GetAsString(&tab_entry)) {
- NOTREACHED();
- break;
- }
- launch_tabs.push_back(tab_entry);
- }
- return launch_tabs;
+ return GetNamedList(L"first_run_tabs", prefs);
+}
+
+std::vector<std::wstring> GetDefaultBookmarks(const DictionaryValue* prefs) {
+ return GetNamedList(L"default_bookmarks", prefs);
}
bool SetDistroBooleanPreference(DictionaryValue* prefs,
diff --git a/chrome/installer/util/master_preferences.h b/chrome/installer/util/master_preferences.h
index a809c97..ee750a4 100644
--- a/chrome/installer/util/master_preferences.h
+++ b/chrome/installer/util/master_preferences.h
@@ -140,6 +140,22 @@ DictionaryValue* ParseDistributionPreferences(
// preferences file does not contain such list the vector is empty.
std::vector<std::wstring> GetFirstRunTabs(const DictionaryValue* prefs);
+// As part of the master preferences an optional section indicates the
+// pre-installed bookmarks. An example is the following:
+//
+// {
+// "default_bookmarks": [
+// "http://google.com/b1",
+// "https://google.com/b2"
+// ]
+// }
+//
+// Note that the entries need to be urls.
+//
+// This function retuns the list as a vector of strings. If the master
+// preferences file does not contain such list the vector is empty.
+std::vector<std::wstring> GetDefaultBookmarks(const DictionaryValue* prefs);
+
// Sets the value of given boolean preference |name| in "distribution"
// dictionary inside |prefs| dictionary.
bool SetDistroBooleanPreference(DictionaryValue* prefs,
diff --git a/chrome/installer/util/master_preferences_unittest.cc b/chrome/installer/util/master_preferences_unittest.cc
index ad827eb..18e560f 100644
--- a/chrome/installer/util/master_preferences_unittest.cc
+++ b/chrome/installer/util/master_preferences_unittest.cc
@@ -14,18 +14,21 @@ namespace {
class MasterPreferencesTest : public testing::Test {
protected:
virtual void SetUp() {
- // Currently no setup required.
+ ASSERT_TRUE(file_util::CreateTemporaryFile(&prefs_file_));
}
virtual void TearDown() {
- // Currently no tear down required.
+ EXPECT_TRUE(file_util::Delete(prefs_file_, false));
}
+
+ const FilePath& prefs_file() const { return prefs_file_; }
+
+ private:
+ FilePath prefs_file_;
};
} // namespace
-TEST(MasterPreferencesTest, ParseDistroParams) {
- FilePath prefs_file;
- ASSERT_TRUE(file_util::CreateTemporaryFile(&prefs_file));
+TEST_F(MasterPreferencesTest, ParseDistroParams) {
const char text[] =
"{ \n"
" \"distribution\": { \n"
@@ -52,9 +55,9 @@ TEST(MasterPreferencesTest, ParseDistroParams) {
" }\n"
"} \n";
- EXPECT_TRUE(file_util::WriteFile(prefs_file, text, sizeof(text)));
+ EXPECT_TRUE(file_util::WriteFile(prefs_file(), text, sizeof(text)));
scoped_ptr<DictionaryValue> prefs(
- installer_util::ParseDistributionPreferences(prefs_file));
+ installer_util::ParseDistributionPreferences(prefs_file()));
EXPECT_TRUE(prefs.get() != NULL);
bool value = true;
EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
@@ -115,12 +118,9 @@ TEST(MasterPreferencesTest, ParseDistroParams) {
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) {
- FilePath prefs_file;
- ASSERT_TRUE(file_util::CreateTemporaryFile(&prefs_file));
+TEST_F(MasterPreferencesTest, ParseMissingDistroParams) {
const char text[] =
"{ \n"
" \"distribution\": { \n"
@@ -133,9 +133,9 @@ TEST(MasterPreferencesTest, ParseMissingDistroParams) {
" }\n"
"} \n";
- EXPECT_TRUE(file_util::WriteFile(prefs_file, text, sizeof(text)));
+ EXPECT_TRUE(file_util::WriteFile(prefs_file(), text, sizeof(text)));
scoped_ptr<DictionaryValue> prefs(
- installer_util::ParseDistributionPreferences(prefs_file));
+ installer_util::ParseDistributionPreferences(prefs_file()));
EXPECT_TRUE(prefs.get() != NULL);
bool value = false;
EXPECT_TRUE(installer_util::GetDistroBooleanPreference(prefs.get(),
@@ -178,12 +178,9 @@ TEST(MasterPreferencesTest, ParseMissingDistroParams) {
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) {
- FilePath prefs_file;
- ASSERT_TRUE(file_util::CreateTemporaryFile(&prefs_file));
+TEST_F(MasterPreferencesTest, FirstRunTabs) {
const char text[] =
"{ \n"
" \"distribution\": { \n"
@@ -196,9 +193,9 @@ TEST(MasterPreferencesTest, FirstRunTabs) {
" ]\n"
"} \n";
- EXPECT_TRUE(file_util::WriteFile(prefs_file, text, sizeof(text)));
+ EXPECT_TRUE(file_util::WriteFile(prefs_file(), text, sizeof(text)));
scoped_ptr<DictionaryValue> prefs(
- installer_util::ParseDistributionPreferences(prefs_file));
+ installer_util::ParseDistributionPreferences(prefs_file()));
EXPECT_TRUE(prefs.get() != NULL);
typedef std::vector<std::wstring> TabsVector;
@@ -207,5 +204,28 @@ TEST(MasterPreferencesTest, FirstRunTabs) {
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));
+}
+
+TEST_F(MasterPreferencesTest, FirstRunBookMarks) {
+ const char text[] =
+ "{ \n"
+ " \"distribution\": { \n"
+ " \"something here\": true\n"
+ " },\n"
+ " \"default_bookmarks\": [\n"
+ " \"http://google.com/b1\",\n"
+ " \"https://google.com/b2\"\n"
+ " ]\n"
+ "} \n";
+
+ EXPECT_TRUE(file_util::WriteFile(prefs_file(), text, sizeof(text)));
+ scoped_ptr<DictionaryValue> prefs(
+ installer_util::ParseDistributionPreferences(prefs_file()));
+ EXPECT_TRUE(prefs.get() != NULL);
+
+ typedef std::vector<std::wstring> BookmarksVector;
+ BookmarksVector bookmarks = installer_util::GetDefaultBookmarks(prefs.get());
+ ASSERT_EQ(2, bookmarks.size());
+ EXPECT_EQ(L"http://google.com/b1", bookmarks[0]);
+ EXPECT_EQ(L"https://google.com/b2", bookmarks[1]);
}