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 #include "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/file_path.h" | 6 #include "base/file_path.h" |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/string_split.h" | 9 #include "base/string_split.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 ASSERT_TRUE(test_server()->Start()); | 194 ASSERT_TRUE(test_server()->Start()); |
195 | 195 |
196 std::string urls_string = GetStringFromURLs(GetURLs());; | 196 std::string urls_string = GetStringFromURLs(GetURLs());; |
197 | 197 |
198 ASSERT_TRUE(file_util::WriteFile(urls_file(), urls_string.c_str(), | 198 ASSERT_TRUE(file_util::WriteFile(urls_file(), urls_string.c_str(), |
199 urls_string.size())); | 199 urls_string.size())); |
200 | 200 |
201 InitPageCycler(); | 201 InitPageCycler(); |
202 page_cycler()->Run(); | 202 page_cycler()->Run(); |
203 | 203 |
204 ui_test_utils::RunMessageLoop(); | 204 content::RunMessageLoop(); |
205 ASSERT_FALSE(file_util::PathExists(errors_file())); | 205 ASSERT_FALSE(file_util::PathExists(errors_file())); |
206 ASSERT_TRUE(file_util::PathExists(stats_file())); | 206 ASSERT_TRUE(file_util::PathExists(stats_file())); |
207 } | 207 } |
208 | 208 |
209 // Test to make sure that PageCycler will recognize unvisitable URLs, and will | 209 // Test to make sure that PageCycler will recognize unvisitable URLs, and will |
210 // handle them appropriately. | 210 // handle them appropriately. |
211 IN_PROC_BROWSER_TEST_F(PageCyclerBrowserTest, UnvisitableURL) { | 211 IN_PROC_BROWSER_TEST_F(PageCyclerBrowserTest, UnvisitableURL) { |
212 const size_t kNumErrors = 1; | 212 const size_t kNumErrors = 1; |
213 const char kFakeURL[] = "http://www.pleasenoonehavethisurlanytimeinthenext" | 213 const char kFakeURL[] = "http://www.pleasenoonehavethisurlanytimeinthenext" |
214 "century.com/gibberish"; | 214 "century.com/gibberish"; |
215 ScopedTempDir temp; | 215 ScopedTempDir temp; |
216 ASSERT_TRUE(temp.CreateUniqueTempDir()); | 216 ASSERT_TRUE(temp.CreateUniqueTempDir()); |
217 | 217 |
218 RegisterForNotifications(); | 218 RegisterForNotifications(); |
219 InitFilePaths(temp.path()); | 219 InitFilePaths(temp.path()); |
220 | 220 |
221 ASSERT_TRUE(test_server()->Start()); | 221 ASSERT_TRUE(test_server()->Start()); |
222 | 222 |
223 std::vector<GURL> urls = GetURLs(); | 223 std::vector<GURL> urls = GetURLs(); |
224 urls.push_back(GURL(kFakeURL)); | 224 urls.push_back(GURL(kFakeURL)); |
225 std::string urls_string = GetStringFromURLs(urls); | 225 std::string urls_string = GetStringFromURLs(urls); |
226 | 226 |
227 ASSERT_TRUE(file_util::WriteFile(urls_file(), urls_string.c_str(), | 227 ASSERT_TRUE(file_util::WriteFile(urls_file(), urls_string.c_str(), |
228 urls_string.size())); | 228 urls_string.size())); |
229 | 229 |
230 InitPageCycler(); | 230 InitPageCycler(); |
231 page_cycler()->Run(); | 231 page_cycler()->Run(); |
232 | 232 |
233 ui_test_utils::RunMessageLoop(); | 233 content::RunMessageLoop(); |
234 ASSERT_TRUE(file_util::PathExists(errors_file())); | 234 ASSERT_TRUE(file_util::PathExists(errors_file())); |
235 ASSERT_TRUE(file_util::PathExists(stats_file())); | 235 ASSERT_TRUE(file_util::PathExists(stats_file())); |
236 | 236 |
237 std::vector<std::string> errors = GetErrorsFromFile(); | 237 std::vector<std::string> errors = GetErrorsFromFile(); |
238 | 238 |
239 ASSERT_EQ(kNumErrors, errors.size()); | 239 ASSERT_EQ(kNumErrors, errors.size()); |
240 | 240 |
241 // Check that each error message contains the fake URL (i.e., that it wasn't | 241 // Check that each error message contains the fake URL (i.e., that it wasn't |
242 // from a valid URL, and that the fake URL was caught each time). | 242 // from a valid URL, and that the fake URL was caught each time). |
243 ASSERT_NE(std::string::npos, errors[0].find(kFakeURL)); | 243 ASSERT_NE(std::string::npos, errors[0].find(kFakeURL)); |
(...skipping 13 matching lines...) Expand all Loading... |
257 | 257 |
258 std::string urls_string = GetStringFromURLs(GetURLs()); | 258 std::string urls_string = GetStringFromURLs(GetURLs()); |
259 urls_string.append(kBadURL).append("\n"); | 259 urls_string.append(kBadURL).append("\n"); |
260 | 260 |
261 ASSERT_TRUE(file_util::WriteFile(urls_file(), urls_string.c_str(), | 261 ASSERT_TRUE(file_util::WriteFile(urls_file(), urls_string.c_str(), |
262 urls_string.size())); | 262 urls_string.size())); |
263 | 263 |
264 InitPageCycler(); | 264 InitPageCycler(); |
265 page_cycler()->Run(); | 265 page_cycler()->Run(); |
266 | 266 |
267 ui_test_utils::RunMessageLoop(); | 267 content::RunMessageLoop(); |
268 ASSERT_TRUE(file_util::PathExists(errors_file())); | 268 ASSERT_TRUE(file_util::PathExists(errors_file())); |
269 ASSERT_TRUE(file_util::PathExists(stats_file())); | 269 ASSERT_TRUE(file_util::PathExists(stats_file())); |
270 | 270 |
271 std::vector<std::string> errors = GetErrorsFromFile(); | 271 std::vector<std::string> errors = GetErrorsFromFile(); |
272 ASSERT_EQ(1u, errors.size()); | 272 ASSERT_EQ(1u, errors.size()); |
273 | 273 |
274 std::string expected_error = "Omitting invalid URL: "; | 274 std::string expected_error = "Omitting invalid URL: "; |
275 expected_error.append(kBadURL).append("."); | 275 expected_error.append(kBadURL).append("."); |
276 | 276 |
277 ASSERT_FALSE(errors[0].compare(expected_error)); | 277 ASSERT_FALSE(errors[0].compare(expected_error)); |
(...skipping 12 matching lines...) Expand all Loading... |
290 std::vector<GURL> urls = GetURLs(); | 290 std::vector<GURL> urls = GetURLs(); |
291 urls.push_back(GURL(content::kUnreachableWebDataURL)); | 291 urls.push_back(GURL(content::kUnreachableWebDataURL)); |
292 std::string urls_string = GetStringFromURLs(urls); | 292 std::string urls_string = GetStringFromURLs(urls); |
293 | 293 |
294 ASSERT_TRUE(file_util::WriteFile(urls_file(), urls_string.c_str(), | 294 ASSERT_TRUE(file_util::WriteFile(urls_file(), urls_string.c_str(), |
295 urls_string.size())); | 295 urls_string.size())); |
296 | 296 |
297 InitPageCycler(); | 297 InitPageCycler(); |
298 page_cycler()->Run(); | 298 page_cycler()->Run(); |
299 | 299 |
300 ui_test_utils::RunMessageLoop(); | 300 content::RunMessageLoop(); |
301 ASSERT_TRUE(file_util::PathExists(errors_file())); | 301 ASSERT_TRUE(file_util::PathExists(errors_file())); |
302 ASSERT_TRUE(file_util::PathExists(stats_file())); | 302 ASSERT_TRUE(file_util::PathExists(stats_file())); |
303 | 303 |
304 std::vector<std::string> errors = GetErrorsFromFile(); | 304 std::vector<std::string> errors = GetErrorsFromFile(); |
305 ASSERT_EQ(1u, errors.size()); | 305 ASSERT_EQ(1u, errors.size()); |
306 | 306 |
307 std::string expected_error = "Chrome error pages are not allowed as urls. " | 307 std::string expected_error = "Chrome error pages are not allowed as urls. " |
308 "Omitting url: "; | 308 "Omitting url: "; |
309 expected_error.append(content::kUnreachableWebDataURL).append("."); | 309 expected_error.append(content::kUnreachableWebDataURL).append("."); |
310 | 310 |
(...skipping 16 matching lines...) Expand all Loading... |
327 ScopedTempDir temp; | 327 ScopedTempDir temp; |
328 ASSERT_TRUE(temp.CreateUniqueTempDir()); | 328 ASSERT_TRUE(temp.CreateUniqueTempDir()); |
329 | 329 |
330 RegisterForNotifications(); | 330 RegisterForNotifications(); |
331 InitFilePaths(temp.path()); | 331 InitFilePaths(temp.path()); |
332 | 332 |
333 InitPageCycler(); | 333 InitPageCycler(); |
334 | 334 |
335 page_cycler()->Run(); | 335 page_cycler()->Run(); |
336 | 336 |
337 ui_test_utils::RunMessageLoop(); | 337 content::RunMessageLoop(); |
338 ASSERT_TRUE(file_util::PathExists(stats_file())); | 338 ASSERT_TRUE(file_util::PathExists(stats_file())); |
339 ASSERT_FALSE(file_util::PathExists(errors_file())); | 339 ASSERT_FALSE(file_util::PathExists(errors_file())); |
340 } | 340 } |
341 | 341 |
342 // Test that PageCycler will have a cache miss if a URL is missing from the | 342 // Test that PageCycler will have a cache miss if a URL is missing from the |
343 // cache directory while in playback mode. | 343 // cache directory while in playback mode. |
344 // Bug 131333: This test fails on a XP debug bot since Build 17609. | 344 // Bug 131333: This test fails on a XP debug bot since Build 17609. |
345 #if (defined(OS_WIN) || defined(OS_MACOSX)) && !defined(NDEBUG) | 345 #if (defined(OS_WIN) || defined(OS_MACOSX)) && !defined(NDEBUG) |
346 #define MAYBE_URLNotInCache DISABLED_URLNotInCache | 346 #define MAYBE_URLNotInCache DISABLED_URLNotInCache |
347 #else | 347 #else |
(...skipping 15 matching lines...) Expand all Loading... |
363 urls_string.append("\n").append(kCacheMissURL); | 363 urls_string.append("\n").append(kCacheMissURL); |
364 FilePath new_urls_file = temp.path().AppendASCII("urls"); | 364 FilePath new_urls_file = temp.path().AppendASCII("urls"); |
365 ASSERT_FALSE(file_util::PathExists(new_urls_file)); | 365 ASSERT_FALSE(file_util::PathExists(new_urls_file)); |
366 | 366 |
367 ASSERT_TRUE(file_util::WriteFile(new_urls_file, urls_string.c_str(), | 367 ASSERT_TRUE(file_util::WriteFile(new_urls_file, urls_string.c_str(), |
368 urls_string.size())); | 368 urls_string.size())); |
369 | 369 |
370 InitPageCycler(new_urls_file, errors_file(), stats_file()); | 370 InitPageCycler(new_urls_file, errors_file(), stats_file()); |
371 page_cycler()->Run(); | 371 page_cycler()->Run(); |
372 | 372 |
373 ui_test_utils::RunMessageLoop(); | 373 content::RunMessageLoop(); |
374 ASSERT_TRUE(file_util::PathExists(errors_file())); | 374 ASSERT_TRUE(file_util::PathExists(errors_file())); |
375 ASSERT_TRUE(file_util::PathExists(stats_file())); | 375 ASSERT_TRUE(file_util::PathExists(stats_file())); |
376 | 376 |
377 std::vector<std::string> errors = GetErrorsFromFile(); | 377 std::vector<std::string> errors = GetErrorsFromFile(); |
378 ASSERT_EQ(1u, errors.size()); | 378 ASSERT_EQ(1u, errors.size()); |
379 | 379 |
380 std::string expected_error; | 380 std::string expected_error; |
381 expected_error.append("Failed to load the page at: ") | 381 expected_error.append("Failed to load the page at: ") |
382 .append(kCacheMissURL) | 382 .append(kCacheMissURL) |
383 .append(": The requested entry was not found in the cache."); | 383 .append(": The requested entry was not found in the cache."); |
384 | 384 |
385 ASSERT_FALSE(errors[0].compare(expected_error)); | 385 ASSERT_FALSE(errors[0].compare(expected_error)); |
386 } | 386 } |
387 #endif | 387 #endif |
OLD | NEW |