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