OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // Unit tests for master preferences related methods. | 5 // Unit tests for master preferences related methods. |
6 | 6 |
7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 " \"require_eula\": true,\n" | 69 " \"require_eula\": true,\n" |
70 " \"alternate_shortcut_text\": true,\n" | 70 " \"alternate_shortcut_text\": true,\n" |
71 " \"chrome_shortcut_icon_index\": 1,\n" | 71 " \"chrome_shortcut_icon_index\": 1,\n" |
72 " \"ping_delay\": 40\n" | 72 " \"ping_delay\": 40\n" |
73 " },\n" | 73 " },\n" |
74 " \"blah\": {\n" | 74 " \"blah\": {\n" |
75 " \"import_history\": false\n" | 75 " \"import_history\": false\n" |
76 " }\n" | 76 " }\n" |
77 "} \n"; | 77 "} \n"; |
78 | 78 |
79 EXPECT_TRUE(base::WriteFile(prefs_file(), text, strlen(text))); | 79 EXPECT_TRUE(base::WriteFile(prefs_file(), text, |
| 80 static_cast<int>(strlen(text)))); |
80 installer::MasterPreferences prefs(prefs_file()); | 81 installer::MasterPreferences prefs(prefs_file()); |
81 EXPECT_TRUE(prefs.read_from_file()); | 82 EXPECT_TRUE(prefs.read_from_file()); |
82 | 83 |
83 const char* const expected_true[] = { | 84 const char* const expected_true[] = { |
84 installer::master_preferences::kDistroImportSearchPref, | 85 installer::master_preferences::kDistroImportSearchPref, |
85 installer::master_preferences::kDistroImportHistoryPref, | 86 installer::master_preferences::kDistroImportHistoryPref, |
86 installer::master_preferences::kDistroImportBookmarksPref, | 87 installer::master_preferences::kDistroImportBookmarksPref, |
87 installer::master_preferences::kDistroImportHomePagePref, | 88 installer::master_preferences::kDistroImportHomePagePref, |
88 installer::master_preferences::kDoNotCreateAnyShortcuts, | 89 installer::master_preferences::kDoNotCreateAnyShortcuts, |
89 installer::master_preferences::kDoNotCreateDesktopShortcut, | 90 installer::master_preferences::kDoNotCreateDesktopShortcut, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 " \"import_search_engine\": true,\n" | 129 " \"import_search_engine\": true,\n" |
129 " \"import_bookmarks\": false,\n" | 130 " \"import_bookmarks\": false,\n" |
130 " \"import_bookmarks_from_file\": \"\",\n" | 131 " \"import_bookmarks_from_file\": \"\",\n" |
131 " \"do_not_create_desktop_shortcut\": true,\n" | 132 " \"do_not_create_desktop_shortcut\": true,\n" |
132 " \"do_not_create_quick_launch_shortcut\": true,\n" | 133 " \"do_not_create_quick_launch_shortcut\": true,\n" |
133 " \"do_not_launch_chrome\": true,\n" | 134 " \"do_not_launch_chrome\": true,\n" |
134 " \"chrome_shortcut_icon_index\": \"bac\"\n" | 135 " \"chrome_shortcut_icon_index\": \"bac\"\n" |
135 " }\n" | 136 " }\n" |
136 "} \n"; | 137 "} \n"; |
137 | 138 |
138 EXPECT_TRUE(base::WriteFile(prefs_file(), text, strlen(text))); | 139 EXPECT_TRUE(base::WriteFile(prefs_file(), text, |
| 140 static_cast<int>(strlen(text)))); |
139 installer::MasterPreferences prefs(prefs_file()); | 141 installer::MasterPreferences prefs(prefs_file()); |
140 EXPECT_TRUE(prefs.read_from_file()); | 142 EXPECT_TRUE(prefs.read_from_file()); |
141 | 143 |
142 ExpectedBooleans expected_bool[] = { | 144 ExpectedBooleans expected_bool[] = { |
143 { installer::master_preferences::kDistroImportSearchPref, true }, | 145 { installer::master_preferences::kDistroImportSearchPref, true }, |
144 { installer::master_preferences::kDistroImportBookmarksPref, false }, | 146 { installer::master_preferences::kDistroImportBookmarksPref, false }, |
145 { installer::master_preferences::kDoNotCreateDesktopShortcut, true }, | 147 { installer::master_preferences::kDoNotCreateDesktopShortcut, true }, |
146 { installer::master_preferences::kDoNotCreateQuickLaunchShortcut, true }, | 148 { installer::master_preferences::kDoNotCreateQuickLaunchShortcut, true }, |
147 { installer::master_preferences::kDoNotLaunchChrome, true }, | 149 { installer::master_preferences::kDoNotLaunchChrome, true }, |
148 }; | 150 }; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 " \"distribution\": { \n" | 189 " \"distribution\": { \n" |
188 " \"something here\": true\n" | 190 " \"something here\": true\n" |
189 " },\n" | 191 " },\n" |
190 " \"first_run_tabs\": [\n" | 192 " \"first_run_tabs\": [\n" |
191 " \"http://google.com/f1\",\n" | 193 " \"http://google.com/f1\",\n" |
192 " \"https://google.com/f2\",\n" | 194 " \"https://google.com/f2\",\n" |
193 " \"new_tab_page\"\n" | 195 " \"new_tab_page\"\n" |
194 " ]\n" | 196 " ]\n" |
195 "} \n"; | 197 "} \n"; |
196 | 198 |
197 EXPECT_TRUE(base::WriteFile(prefs_file(), text, strlen(text))); | 199 EXPECT_TRUE(base::WriteFile(prefs_file(), text, |
| 200 static_cast<int>(strlen(text)))); |
198 installer::MasterPreferences prefs(prefs_file()); | 201 installer::MasterPreferences prefs(prefs_file()); |
199 typedef std::vector<std::string> TabsVector; | 202 typedef std::vector<std::string> TabsVector; |
200 TabsVector tabs = prefs.GetFirstRunTabs(); | 203 TabsVector tabs = prefs.GetFirstRunTabs(); |
201 ASSERT_EQ(3, tabs.size()); | 204 ASSERT_EQ(3, tabs.size()); |
202 EXPECT_EQ("http://google.com/f1", tabs[0]); | 205 EXPECT_EQ("http://google.com/f1", tabs[0]); |
203 EXPECT_EQ("https://google.com/f2", tabs[1]); | 206 EXPECT_EQ("https://google.com/f2", tabs[1]); |
204 EXPECT_EQ("new_tab_page", tabs[2]); | 207 EXPECT_EQ("new_tab_page", tabs[2]); |
205 } | 208 } |
206 | 209 |
207 // In this test instead of using our synthetic json file, we use an | 210 // In this test instead of using our synthetic json file, we use an |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 const char text[] = | 248 const char text[] = |
246 "{ \n" | 249 "{ \n" |
247 " \"distribution\": { \n" | 250 " \"distribution\": { \n" |
248 " \"do_not_create_desktop_shortcut\": false,\n" | 251 " \"do_not_create_desktop_shortcut\": false,\n" |
249 " \"do_not_create_quick_launch_shortcut\": false,\n" | 252 " \"do_not_create_quick_launch_shortcut\": false,\n" |
250 " \"do_not_launch_chrome\": true,\n" | 253 " \"do_not_launch_chrome\": true,\n" |
251 " \"system_level\": true,\n" | 254 " \"system_level\": true,\n" |
252 " \"verbose_logging\": false\n" | 255 " \"verbose_logging\": false\n" |
253 " }\n" | 256 " }\n" |
254 "} \n"; | 257 "} \n"; |
255 EXPECT_TRUE(base::WriteFile(prefs_file, text, strlen(text))); | 258 EXPECT_TRUE(base::WriteFile(prefs_file, text, |
| 259 static_cast<int>(strlen(text)))); |
256 | 260 |
257 // Make sure command line values override the values in master preferences. | 261 // Make sure command line values override the values in master preferences. |
258 std::wstring cmd_str( | 262 std::wstring cmd_str( |
259 L"setup.exe --installerdata=\"" + prefs_file.value() + L"\""); | 263 L"setup.exe --installerdata=\"" + prefs_file.value() + L"\""); |
260 cmd_str.append(L" --do-not-launch-chrome"); | 264 cmd_str.append(L" --do-not-launch-chrome"); |
261 base::CommandLine cmd_line = base::CommandLine::FromString(cmd_str); | 265 base::CommandLine cmd_line = base::CommandLine::FromString(cmd_str); |
262 installer::MasterPreferences prefs(cmd_line); | 266 installer::MasterPreferences prefs(cmd_line); |
263 | 267 |
264 // Check prefs that do not have any equivalent command line option. | 268 // Check prefs that do not have any equivalent command line option. |
265 ExpectedBooleans expected_bool[] = { | 269 ExpectedBooleans expected_bool[] = { |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 // The MasterPreferences dictionary should also conjure up the new setting | 477 // The MasterPreferences dictionary should also conjure up the new setting |
474 // as per EnforceLegacyPreferences. | 478 // as per EnforceLegacyPreferences. |
475 const base::ListValue* new_startup_urls_list = NULL; | 479 const base::ListValue* new_startup_urls_list = NULL; |
476 EXPECT_TRUE(master_dictionary.GetList(prefs::kURLsToRestoreOnStartup, | 480 EXPECT_TRUE(master_dictionary.GetList(prefs::kURLsToRestoreOnStartup, |
477 &new_startup_urls_list)); | 481 &new_startup_urls_list)); |
478 ASSERT_TRUE(new_startup_urls_list != NULL); | 482 ASSERT_TRUE(new_startup_urls_list != NULL); |
479 std::string new_url_value; | 483 std::string new_url_value; |
480 EXPECT_TRUE(new_startup_urls_list->GetString(0, &new_url_value)); | 484 EXPECT_TRUE(new_startup_urls_list->GetString(0, &new_url_value)); |
481 EXPECT_EQ("http://www.example.com", new_url_value); | 485 EXPECT_EQ("http://www.example.com", new_url_value); |
482 } | 486 } |
OLD | NEW |