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

Side by Side Diff: chrome/browser/page_cycler/page_cycler_browsertest.cc

Issue 18286004: Move PathExists to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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 #include "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/strings/string_split.h" 9 #include "base/strings/string_split.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 } 44 }
45 45
46 // Initialize file paths within a temporary directory; this should be 46 // Initialize file paths within a temporary directory; this should be
47 // empty and nonexistent. 47 // empty and nonexistent.
48 virtual void InitFilePaths(base::FilePath temp_path) { 48 virtual void InitFilePaths(base::FilePath temp_path) {
49 temp_path_ = temp_path; 49 temp_path_ = temp_path;
50 urls_file_ = temp_path.AppendASCII("urls_file"); 50 urls_file_ = temp_path.AppendASCII("urls_file");
51 errors_file_ = temp_path.AppendASCII("errors"); 51 errors_file_ = temp_path.AppendASCII("errors");
52 stats_file_ = temp_path.AppendASCII("stats"); 52 stats_file_ = temp_path.AppendASCII("stats");
53 53
54 ASSERT_FALSE(file_util::PathExists(urls_file_)); 54 ASSERT_FALSE(base::PathExists(urls_file_));
55 ASSERT_FALSE(file_util::PathExists(errors_file_)); 55 ASSERT_FALSE(base::PathExists(errors_file_));
56 ASSERT_FALSE(file_util::PathExists(stats_file_)); 56 ASSERT_FALSE(base::PathExists(stats_file_));
57 } 57 }
58 58
59 // Initialize a PageCycler using either the base fields, or using provided 59 // Initialize a PageCycler using either the base fields, or using provided
60 // ones. 60 // ones.
61 void InitPageCycler() { 61 void InitPageCycler() {
62 page_cycler_ = new PageCycler(browser(), urls_file()); 62 page_cycler_ = new PageCycler(browser(), urls_file());
63 page_cycler_->set_errors_file(errors_file()); 63 page_cycler_->set_errors_file(errors_file());
64 page_cycler_->set_stats_file(stats_file()); 64 page_cycler_->set_stats_file(stats_file());
65 } 65 }
66 66
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 class PageCyclerCachedBrowserTest : public PageCyclerBrowserTest { 145 class PageCyclerCachedBrowserTest : public PageCyclerBrowserTest {
146 public: 146 public:
147 // For a cached test, we use the provided user data directory from the test 147 // For a cached test, we use the provided user data directory from the test
148 // directory. 148 // directory.
149 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 149 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
150 base::FilePath test_dir; 150 base::FilePath test_dir;
151 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir)); 151 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir));
152 test_dir = test_dir.AppendASCII("page_cycler"); 152 test_dir = test_dir.AppendASCII("page_cycler");
153 153
154 base::FilePath source_data_dir = test_dir.AppendASCII("cached_data_dir"); 154 base::FilePath source_data_dir = test_dir.AppendASCII("cached_data_dir");
155 CHECK(file_util::PathExists(source_data_dir)); 155 CHECK(base::PathExists(source_data_dir));
156 156
157 CHECK(user_data_dir_.CreateUniqueTempDir()); 157 CHECK(user_data_dir_.CreateUniqueTempDir());
158 158
159 base::FilePath dest_data_dir = 159 base::FilePath dest_data_dir =
160 user_data_dir_.path().AppendASCII("cached_data_dir"); 160 user_data_dir_.path().AppendASCII("cached_data_dir");
161 CHECK(!file_util::PathExists(dest_data_dir)); 161 CHECK(!base::PathExists(dest_data_dir));
162 162
163 CHECK(base::CopyDirectory(source_data_dir, user_data_dir_.path(), 163 CHECK(base::CopyDirectory(source_data_dir, user_data_dir_.path(),
164 true)); // recursive. 164 true)); // recursive.
165 CHECK(file_util::PathExists(dest_data_dir)); 165 CHECK(base::PathExists(dest_data_dir));
166 166
167 command_line->AppendSwitchPath(switches::kUserDataDir, 167 command_line->AppendSwitchPath(switches::kUserDataDir,
168 dest_data_dir); 168 dest_data_dir);
169 command_line->AppendSwitch(switches::kPlaybackMode); 169 command_line->AppendSwitch(switches::kPlaybackMode);
170 } 170 }
171 171
172 // Initialize the file paths to use the UserDataDir's urls file, instead 172 // Initialize the file paths to use the UserDataDir's urls file, instead
173 // of one to be written. 173 // of one to be written.
174 virtual void InitFilePaths(base::FilePath temp_path) OVERRIDE { 174 virtual void InitFilePaths(base::FilePath temp_path) OVERRIDE {
175 urls_file_ = user_data_dir_.path().AppendASCII("cached_data_dir") 175 urls_file_ = user_data_dir_.path().AppendASCII("cached_data_dir")
176 .AppendASCII("urls"); 176 .AppendASCII("urls");
177 errors_file_ = temp_path.AppendASCII("errors"); 177 errors_file_ = temp_path.AppendASCII("errors");
178 stats_file_ = temp_path.AppendASCII("stats"); 178 stats_file_ = temp_path.AppendASCII("stats");
179 179
180 ASSERT_TRUE(file_util::PathExists(urls_file_)); 180 ASSERT_TRUE(base::PathExists(urls_file_));
181 ASSERT_FALSE(file_util::PathExists(errors_file_)); 181 ASSERT_FALSE(base::PathExists(errors_file_));
182 ASSERT_FALSE(file_util::PathExists(stats_file_)); 182 ASSERT_FALSE(base::PathExists(stats_file_));
183 } 183 }
184 184
185 private: 185 private:
186 // The directory storing the copy of the UserDataDir. 186 // The directory storing the copy of the UserDataDir.
187 base::ScopedTempDir user_data_dir_; 187 base::ScopedTempDir user_data_dir_;
188 }; 188 };
189 189
190 // Sanity check; iterate through a series of URLs and make sure there are no 190 // Sanity check; iterate through a series of URLs and make sure there are no
191 // errors. 191 // errors.
192 IN_PROC_BROWSER_TEST_F(PageCyclerBrowserTest, BasicTest) { 192 IN_PROC_BROWSER_TEST_F(PageCyclerBrowserTest, BasicTest) {
193 base::ScopedTempDir temp; 193 base::ScopedTempDir temp;
194 ASSERT_TRUE(temp.CreateUniqueTempDir()); 194 ASSERT_TRUE(temp.CreateUniqueTempDir());
195 195
196 RegisterForNotifications(); 196 RegisterForNotifications();
197 InitFilePaths(temp.path()); 197 InitFilePaths(temp.path());
198 198
199 ASSERT_TRUE(test_server()->Start()); 199 ASSERT_TRUE(test_server()->Start());
200 200
201 std::string urls_string = GetStringFromURLs(GetURLs());; 201 std::string urls_string = GetStringFromURLs(GetURLs());;
202 202
203 ASSERT_TRUE(file_util::WriteFile(urls_file(), urls_string.c_str(), 203 ASSERT_TRUE(file_util::WriteFile(urls_file(), urls_string.c_str(),
204 urls_string.size())); 204 urls_string.size()));
205 205
206 InitPageCycler(); 206 InitPageCycler();
207 page_cycler()->Run(); 207 page_cycler()->Run();
208 208
209 content::RunMessageLoop(); 209 content::RunMessageLoop();
210 ASSERT_FALSE(file_util::PathExists(errors_file())); 210 ASSERT_FALSE(base::PathExists(errors_file()));
211 ASSERT_TRUE(file_util::PathExists(stats_file())); 211 ASSERT_TRUE(base::PathExists(stats_file()));
212 } 212 }
213 213
214 // Test to make sure that PageCycler will recognize unvisitable URLs, and will 214 // Test to make sure that PageCycler will recognize unvisitable URLs, and will
215 // handle them appropriately. 215 // handle them appropriately.
216 IN_PROC_BROWSER_TEST_F(PageCyclerBrowserTest, UnvisitableURL) { 216 IN_PROC_BROWSER_TEST_F(PageCyclerBrowserTest, UnvisitableURL) {
217 const size_t kNumErrors = 1; 217 const size_t kNumErrors = 1;
218 const char kFakeURL[] = "http://www.pleasenoonehavethisurlanytimeinthenext" 218 const char kFakeURL[] = "http://www.pleasenoonehavethisurlanytimeinthenext"
219 "century.com/gibberish"; 219 "century.com/gibberish";
220 base::ScopedTempDir temp; 220 base::ScopedTempDir temp;
221 ASSERT_TRUE(temp.CreateUniqueTempDir()); 221 ASSERT_TRUE(temp.CreateUniqueTempDir());
222 222
223 RegisterForNotifications(); 223 RegisterForNotifications();
224 InitFilePaths(temp.path()); 224 InitFilePaths(temp.path());
225 225
226 ASSERT_TRUE(test_server()->Start()); 226 ASSERT_TRUE(test_server()->Start());
227 227
228 std::vector<GURL> urls = GetURLs(); 228 std::vector<GURL> urls = GetURLs();
229 urls.push_back(GURL(kFakeURL)); 229 urls.push_back(GURL(kFakeURL));
230 std::string urls_string = GetStringFromURLs(urls); 230 std::string urls_string = GetStringFromURLs(urls);
231 231
232 ASSERT_TRUE(file_util::WriteFile(urls_file(), urls_string.c_str(), 232 ASSERT_TRUE(file_util::WriteFile(urls_file(), urls_string.c_str(),
233 urls_string.size())); 233 urls_string.size()));
234 234
235 InitPageCycler(); 235 InitPageCycler();
236 page_cycler()->Run(); 236 page_cycler()->Run();
237 237
238 content::RunMessageLoop(); 238 content::RunMessageLoop();
239 ASSERT_TRUE(file_util::PathExists(errors_file())); 239 ASSERT_TRUE(base::PathExists(errors_file()));
240 ASSERT_TRUE(file_util::PathExists(stats_file())); 240 ASSERT_TRUE(base::PathExists(stats_file()));
241 241
242 std::vector<std::string> errors = GetErrorsFromFile(); 242 std::vector<std::string> errors = GetErrorsFromFile();
243 243
244 ASSERT_EQ(kNumErrors, errors.size()); 244 ASSERT_EQ(kNumErrors, errors.size());
245 245
246 // Check that each error message contains the fake URL (i.e., that it wasn't 246 // Check that each error message contains the fake URL (i.e., that it wasn't
247 // from a valid URL, and that the fake URL was caught each time). 247 // from a valid URL, and that the fake URL was caught each time).
248 ASSERT_NE(std::string::npos, errors[0].find(kFakeURL)); 248 ASSERT_NE(std::string::npos, errors[0].find(kFakeURL));
249 } 249 }
250 250
(...skipping 12 matching lines...) Expand all
263 std::string urls_string = GetStringFromURLs(GetURLs()); 263 std::string urls_string = GetStringFromURLs(GetURLs());
264 urls_string.append(kBadURL).append("\n"); 264 urls_string.append(kBadURL).append("\n");
265 265
266 ASSERT_TRUE(file_util::WriteFile(urls_file(), urls_string.c_str(), 266 ASSERT_TRUE(file_util::WriteFile(urls_file(), urls_string.c_str(),
267 urls_string.size())); 267 urls_string.size()));
268 268
269 InitPageCycler(); 269 InitPageCycler();
270 page_cycler()->Run(); 270 page_cycler()->Run();
271 271
272 content::RunMessageLoop(); 272 content::RunMessageLoop();
273 ASSERT_TRUE(file_util::PathExists(errors_file())); 273 ASSERT_TRUE(base::PathExists(errors_file()));
274 ASSERT_TRUE(file_util::PathExists(stats_file())); 274 ASSERT_TRUE(base::PathExists(stats_file()));
275 275
276 std::vector<std::string> errors = GetErrorsFromFile(); 276 std::vector<std::string> errors = GetErrorsFromFile();
277 ASSERT_EQ(1u, errors.size()); 277 ASSERT_EQ(1u, errors.size());
278 278
279 std::string expected_error = "Omitting invalid URL: "; 279 std::string expected_error = "Omitting invalid URL: ";
280 expected_error.append(kBadURL).append("."); 280 expected_error.append(kBadURL).append(".");
281 281
282 ASSERT_FALSE(errors[0].compare(expected_error)); 282 ASSERT_FALSE(errors[0].compare(expected_error));
283 } 283 }
284 284
(...skipping 11 matching lines...) Expand all
296 urls.push_back(GURL(content::kUnreachableWebDataURL)); 296 urls.push_back(GURL(content::kUnreachableWebDataURL));
297 std::string urls_string = GetStringFromURLs(urls); 297 std::string urls_string = GetStringFromURLs(urls);
298 298
299 ASSERT_TRUE(file_util::WriteFile(urls_file(), urls_string.c_str(), 299 ASSERT_TRUE(file_util::WriteFile(urls_file(), urls_string.c_str(),
300 urls_string.size())); 300 urls_string.size()));
301 301
302 InitPageCycler(); 302 InitPageCycler();
303 page_cycler()->Run(); 303 page_cycler()->Run();
304 304
305 content::RunMessageLoop(); 305 content::RunMessageLoop();
306 ASSERT_TRUE(file_util::PathExists(errors_file())); 306 ASSERT_TRUE(base::PathExists(errors_file()));
307 ASSERT_TRUE(file_util::PathExists(stats_file())); 307 ASSERT_TRUE(base::PathExists(stats_file()));
308 308
309 std::vector<std::string> errors = GetErrorsFromFile(); 309 std::vector<std::string> errors = GetErrorsFromFile();
310 ASSERT_EQ(1u, errors.size()); 310 ASSERT_EQ(1u, errors.size());
311 311
312 std::string expected_error = "Chrome error pages are not allowed as urls. " 312 std::string expected_error = "Chrome error pages are not allowed as urls. "
313 "Omitting url: "; 313 "Omitting url: ";
314 expected_error.append(content::kUnreachableWebDataURL).append("."); 314 expected_error.append(content::kUnreachableWebDataURL).append(".");
315 315
316 ASSERT_FALSE(errors[0].compare(expected_error)); 316 ASSERT_FALSE(errors[0].compare(expected_error));
317 } 317 }
(...skipping 18 matching lines...) Expand all
336 ASSERT_TRUE(temp.CreateUniqueTempDir()); 336 ASSERT_TRUE(temp.CreateUniqueTempDir());
337 337
338 RegisterForNotifications(); 338 RegisterForNotifications();
339 InitFilePaths(temp.path()); 339 InitFilePaths(temp.path());
340 340
341 InitPageCycler(); 341 InitPageCycler();
342 342
343 page_cycler()->Run(); 343 page_cycler()->Run();
344 344
345 content::RunMessageLoop(); 345 content::RunMessageLoop();
346 ASSERT_TRUE(file_util::PathExists(stats_file())); 346 ASSERT_TRUE(base::PathExists(stats_file()));
347 ASSERT_FALSE(file_util::PathExists(errors_file())); 347 ASSERT_FALSE(base::PathExists(errors_file()));
348 } 348 }
349 #endif // !defined(OS_CHROMEOS) 349 #endif // !defined(OS_CHROMEOS)
350 350
351 #if !defined(OS_CHROMEOS) 351 #if !defined(OS_CHROMEOS)
352 // TODO(rdevlin.cronin): Perhaps page cycler isn't completely implemented on 352 // TODO(rdevlin.cronin): Perhaps page cycler isn't completely implemented on
353 // ChromeOS? 353 // ChromeOS?
354 354
355 // Test that PageCycler will have a cache miss if a URL is missing from the 355 // Test that PageCycler will have a cache miss if a URL is missing from the
356 // cache directory while in playback mode. 356 // cache directory while in playback mode.
357 // Bug 131333: This test fails on a XP debug bot since Build 17609. 357 // Bug 131333: This test fails on a XP debug bot since Build 17609.
358 #if (defined(OS_WIN) || defined(OS_MACOSX)) && !defined(NDEBUG) 358 #if (defined(OS_WIN) || defined(OS_MACOSX)) && !defined(NDEBUG)
359 #define MAYBE_URLNotInCache DISABLED_URLNotInCache 359 #define MAYBE_URLNotInCache DISABLED_URLNotInCache
360 #else 360 #else
361 #define MAYBE_URLNotInCache URLNotInCache 361 #define MAYBE_URLNotInCache URLNotInCache
362 #endif 362 #endif
363 IN_PROC_BROWSER_TEST_F(PageCyclerCachedBrowserTest, MAYBE_URLNotInCache) { 363 IN_PROC_BROWSER_TEST_F(PageCyclerCachedBrowserTest, MAYBE_URLNotInCache) {
364 const char kCacheMissURL[] = "http://www.images.google.com/"; 364 const char kCacheMissURL[] = "http://www.images.google.com/";
365 365
366 base::ScopedTempDir temp; 366 base::ScopedTempDir temp;
367 ASSERT_TRUE(temp.CreateUniqueTempDir()); 367 ASSERT_TRUE(temp.CreateUniqueTempDir());
368 368
369 RegisterForNotifications(); 369 RegisterForNotifications();
370 InitFilePaths(temp.path()); 370 InitFilePaths(temp.path());
371 371
372 // Only use a single URL that is not in cache. That's sufficient for the test 372 // Only use a single URL that is not in cache. That's sufficient for the test
373 // scenario, and makes things faster than needlessly cycling through all the 373 // scenario, and makes things faster than needlessly cycling through all the
374 // other URLs. 374 // other URLs.
375 375
376 base::FilePath new_urls_file = temp.path().AppendASCII("urls"); 376 base::FilePath new_urls_file = temp.path().AppendASCII("urls");
377 ASSERT_FALSE(file_util::PathExists(new_urls_file)); 377 ASSERT_FALSE(base::PathExists(new_urls_file));
378 378
379 ASSERT_TRUE(file_util::WriteFile(new_urls_file, kCacheMissURL, 379 ASSERT_TRUE(file_util::WriteFile(new_urls_file, kCacheMissURL,
380 sizeof(kCacheMissURL))); 380 sizeof(kCacheMissURL)));
381 381
382 InitPageCycler(new_urls_file, errors_file(), stats_file()); 382 InitPageCycler(new_urls_file, errors_file(), stats_file());
383 page_cycler()->Run(); 383 page_cycler()->Run();
384 384
385 content::RunMessageLoop(); 385 content::RunMessageLoop();
386 ASSERT_TRUE(file_util::PathExists(errors_file())); 386 ASSERT_TRUE(base::PathExists(errors_file()));
387 ASSERT_TRUE(file_util::PathExists(stats_file())); 387 ASSERT_TRUE(base::PathExists(stats_file()));
388 388
389 std::vector<std::string> errors = GetErrorsFromFile(); 389 std::vector<std::string> errors = GetErrorsFromFile();
390 ASSERT_EQ(1u, errors.size()); 390 ASSERT_EQ(1u, errors.size());
391 391
392 std::string expected_error; 392 std::string expected_error;
393 expected_error.append("Failed to load the page at: ") 393 expected_error.append("Failed to load the page at: ")
394 .append(kCacheMissURL) 394 .append(kCacheMissURL)
395 .append(": The requested entry was not found in the cache."); 395 .append(": The requested entry was not found in the cache.");
396 396
397 ASSERT_FALSE(errors[0].compare(expected_error)); 397 ASSERT_FALSE(errors[0].compare(expected_error));
398 } 398 }
399 #endif // !defined(OS_CHROMEOS) 399 #endif // !defined(OS_CHROMEOS)
OLDNEW
« no previous file with comments | « chrome/browser/page_cycler/page_cycler.cc ('k') | chrome/browser/page_cycler/page_cycler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698