Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(243)

Side by Side Diff: chrome/installer/util/master_preferences_unittest.cc

Issue 184563006: Move WriteFile and WriteFileDescriptor from file_util to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/file_util.h" 7 #include "base/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
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(file_util::WriteFile(prefs_file(), text, strlen(text))); 79 EXPECT_TRUE(base::WriteFile(prefs_file(), text, strlen(text)));
80 installer::MasterPreferences prefs(prefs_file()); 80 installer::MasterPreferences prefs(prefs_file());
81 EXPECT_TRUE(prefs.read_from_file()); 81 EXPECT_TRUE(prefs.read_from_file());
82 82
83 const char* expected_true[] = { 83 const char* expected_true[] = {
84 installer::master_preferences::kDistroImportSearchPref, 84 installer::master_preferences::kDistroImportSearchPref,
85 installer::master_preferences::kDistroImportHistoryPref, 85 installer::master_preferences::kDistroImportHistoryPref,
86 installer::master_preferences::kDistroImportBookmarksPref, 86 installer::master_preferences::kDistroImportBookmarksPref,
87 installer::master_preferences::kDistroImportHomePagePref, 87 installer::master_preferences::kDistroImportHomePagePref,
88 installer::master_preferences::kDoNotCreateAnyShortcuts, 88 installer::master_preferences::kDoNotCreateAnyShortcuts,
89 installer::master_preferences::kDoNotCreateDesktopShortcut, 89 installer::master_preferences::kDoNotCreateDesktopShortcut,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 " \"import_search_engine\": true,\n" 128 " \"import_search_engine\": true,\n"
129 " \"import_bookmarks\": false,\n" 129 " \"import_bookmarks\": false,\n"
130 " \"import_bookmarks_from_file\": \"\",\n" 130 " \"import_bookmarks_from_file\": \"\",\n"
131 " \"do_not_create_desktop_shortcut\": true,\n" 131 " \"do_not_create_desktop_shortcut\": true,\n"
132 " \"do_not_create_quick_launch_shortcut\": true,\n" 132 " \"do_not_create_quick_launch_shortcut\": true,\n"
133 " \"do_not_launch_chrome\": true,\n" 133 " \"do_not_launch_chrome\": true,\n"
134 " \"chrome_shortcut_icon_index\": \"bac\"\n" 134 " \"chrome_shortcut_icon_index\": \"bac\"\n"
135 " }\n" 135 " }\n"
136 "} \n"; 136 "} \n";
137 137
138 EXPECT_TRUE(file_util::WriteFile(prefs_file(), text, strlen(text))); 138 EXPECT_TRUE(base::WriteFile(prefs_file(), text, strlen(text)));
139 installer::MasterPreferences prefs(prefs_file()); 139 installer::MasterPreferences prefs(prefs_file());
140 EXPECT_TRUE(prefs.read_from_file()); 140 EXPECT_TRUE(prefs.read_from_file());
141 141
142 ExpectedBooleans expected_bool[] = { 142 ExpectedBooleans expected_bool[] = {
143 { installer::master_preferences::kDistroImportSearchPref, true }, 143 { installer::master_preferences::kDistroImportSearchPref, true },
144 { installer::master_preferences::kDistroImportBookmarksPref, false }, 144 { installer::master_preferences::kDistroImportBookmarksPref, false },
145 { installer::master_preferences::kDoNotCreateDesktopShortcut, true }, 145 { installer::master_preferences::kDoNotCreateDesktopShortcut, true },
146 { installer::master_preferences::kDoNotCreateQuickLaunchShortcut, true }, 146 { installer::master_preferences::kDoNotCreateQuickLaunchShortcut, true },
147 { installer::master_preferences::kDoNotLaunchChrome, true }, 147 { installer::master_preferences::kDoNotLaunchChrome, true },
148 }; 148 };
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 " \"distribution\": { \n" 187 " \"distribution\": { \n"
188 " \"something here\": true\n" 188 " \"something here\": true\n"
189 " },\n" 189 " },\n"
190 " \"first_run_tabs\": [\n" 190 " \"first_run_tabs\": [\n"
191 " \"http://google.com/f1\",\n" 191 " \"http://google.com/f1\",\n"
192 " \"https://google.com/f2\",\n" 192 " \"https://google.com/f2\",\n"
193 " \"new_tab_page\"\n" 193 " \"new_tab_page\"\n"
194 " ]\n" 194 " ]\n"
195 "} \n"; 195 "} \n";
196 196
197 EXPECT_TRUE(file_util::WriteFile(prefs_file(), text, strlen(text))); 197 EXPECT_TRUE(base::WriteFile(prefs_file(), text, strlen(text)));
198 installer::MasterPreferences prefs(prefs_file()); 198 installer::MasterPreferences prefs(prefs_file());
199 typedef std::vector<std::string> TabsVector; 199 typedef std::vector<std::string> TabsVector;
200 TabsVector tabs = prefs.GetFirstRunTabs(); 200 TabsVector tabs = prefs.GetFirstRunTabs();
201 ASSERT_EQ(3, tabs.size()); 201 ASSERT_EQ(3, tabs.size());
202 EXPECT_EQ("http://google.com/f1", tabs[0]); 202 EXPECT_EQ("http://google.com/f1", tabs[0]);
203 EXPECT_EQ("https://google.com/f2", tabs[1]); 203 EXPECT_EQ("https://google.com/f2", tabs[1]);
204 EXPECT_EQ("new_tab_page", tabs[2]); 204 EXPECT_EQ("new_tab_page", tabs[2]);
205 } 205 }
206 206
207 // 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
245 const char text[] = 245 const char text[] =
246 "{ \n" 246 "{ \n"
247 " \"distribution\": { \n" 247 " \"distribution\": { \n"
248 " \"do_not_create_desktop_shortcut\": false,\n" 248 " \"do_not_create_desktop_shortcut\": false,\n"
249 " \"do_not_create_quick_launch_shortcut\": false,\n" 249 " \"do_not_create_quick_launch_shortcut\": false,\n"
250 " \"do_not_launch_chrome\": true,\n" 250 " \"do_not_launch_chrome\": true,\n"
251 " \"system_level\": true,\n" 251 " \"system_level\": true,\n"
252 " \"verbose_logging\": false\n" 252 " \"verbose_logging\": false\n"
253 " }\n" 253 " }\n"
254 "} \n"; 254 "} \n";
255 EXPECT_TRUE(file_util::WriteFile(prefs_file, text, strlen(text))); 255 EXPECT_TRUE(base::WriteFile(prefs_file, text, strlen(text)));
256 256
257 // Make sure command line values override the values in master preferences. 257 // Make sure command line values override the values in master preferences.
258 std::wstring cmd_str( 258 std::wstring cmd_str(
259 L"setup.exe --installerdata=\"" + prefs_file.value() + L"\""); 259 L"setup.exe --installerdata=\"" + prefs_file.value() + L"\"");
260 cmd_str.append(L" --do-not-launch-chrome"); 260 cmd_str.append(L" --do-not-launch-chrome");
261 CommandLine cmd_line = CommandLine::FromString(cmd_str); 261 CommandLine cmd_line = CommandLine::FromString(cmd_str);
262 installer::MasterPreferences prefs(cmd_line); 262 installer::MasterPreferences prefs(cmd_line);
263 263
264 // Check prefs that do not have any equivalent command line option. 264 // Check prefs that do not have any equivalent command line option.
265 ExpectedBooleans expected_bool[] = { 265 ExpectedBooleans expected_bool[] = {
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 // The MasterPreferences dictionary should also conjure up the new setting 471 // The MasterPreferences dictionary should also conjure up the new setting
472 // as per EnforceLegacyPreferences. 472 // as per EnforceLegacyPreferences.
473 const base::ListValue* new_startup_urls_list = NULL; 473 const base::ListValue* new_startup_urls_list = NULL;
474 EXPECT_TRUE(master_dictionary.GetList(prefs::kURLsToRestoreOnStartup, 474 EXPECT_TRUE(master_dictionary.GetList(prefs::kURLsToRestoreOnStartup,
475 &new_startup_urls_list)); 475 &new_startup_urls_list));
476 ASSERT_TRUE(new_startup_urls_list != NULL); 476 ASSERT_TRUE(new_startup_urls_list != NULL);
477 std::string new_url_value; 477 std::string new_url_value;
478 EXPECT_TRUE(new_startup_urls_list->GetString(0, &new_url_value)); 478 EXPECT_TRUE(new_startup_urls_list->GetString(0, &new_url_value));
479 EXPECT_EQ("http://www.example.com", new_url_value); 479 EXPECT_EQ("http://www.example.com", new_url_value);
480 } 480 }
OLDNEW
« no previous file with comments | « chrome/installer/util/logging_installer_unittest.cc ('k') | chrome/installer/util/self_cleaning_temp_dir_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698