| 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/file_util.h" | 5 #include "base/file_util.h" |
| 6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
| 7 #include "base/string_split.h" | 7 #include "base/string_split.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/threading/sequenced_worker_pool.h" | 9 #include "base/threading/sequenced_worker_pool.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 FilePath test_data_dir_; | 191 FilePath test_data_dir_; |
| 192 FilePath stats_file_; | 192 FilePath stats_file_; |
| 193 FilePath errors_file_; | 193 FilePath errors_file_; |
| 194 FilePath urls_file_; | 194 FilePath urls_file_; |
| 195 }; | 195 }; |
| 196 | 196 |
| 197 TEST_F(PageCyclerTest, FailProvisionalLoads) { | 197 TEST_F(PageCyclerTest, FailProvisionalLoads) { |
| 198 const FilePath errors_expected_file = | 198 const FilePath errors_expected_file = |
| 199 test_data_dir().AppendASCII("errors_expected"); | 199 test_data_dir().AppendASCII("errors_expected"); |
| 200 | 200 |
| 201 ScopedTempDir temp; | 201 base::ScopedTempDir temp; |
| 202 ASSERT_TRUE(temp.CreateUniqueTempDir()); | 202 ASSERT_TRUE(temp.CreateUniqueTempDir()); |
| 203 InitFilePaths(temp.path()); | 203 InitFilePaths(temp.path()); |
| 204 | 204 |
| 205 ASSERT_TRUE(PathExists(errors_expected_file)); | 205 ASSERT_TRUE(PathExists(errors_expected_file)); |
| 206 ASSERT_TRUE(PathExists(urls_file())); | 206 ASSERT_TRUE(PathExists(urls_file())); |
| 207 | 207 |
| 208 set_page_cycler(new MockPageCycler(browser(), | 208 set_page_cycler(new MockPageCycler(browser(), |
| 209 urls_file(), | 209 urls_file(), |
| 210 errors_file())); | 210 errors_file())); |
| 211 RunPageCycler(); | 211 RunPageCycler(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 ASSERT_TRUE(file_util::ReadFileToString(errors_file(), | 257 ASSERT_TRUE(file_util::ReadFileToString(errors_file(), |
| 258 &errors_output)); | 258 &errors_output)); |
| 259 ASSERT_TRUE(file_util::ReadFileToString(errors_expected_file, | 259 ASSERT_TRUE(file_util::ReadFileToString(errors_expected_file, |
| 260 &errors_expected)); | 260 &errors_expected)); |
| 261 ASSERT_EQ(errors_output, errors_expected); | 261 ASSERT_EQ(errors_output, errors_expected); |
| 262 } | 262 } |
| 263 | 263 |
| 264 TEST_F(PageCyclerTest, StatsFile) { | 264 TEST_F(PageCyclerTest, StatsFile) { |
| 265 const int kNumLoads = 4; | 265 const int kNumLoads = 4; |
| 266 | 266 |
| 267 ScopedTempDir temp; | 267 base::ScopedTempDir temp; |
| 268 ASSERT_TRUE(temp.CreateUniqueTempDir()); | 268 ASSERT_TRUE(temp.CreateUniqueTempDir()); |
| 269 InitFilePaths(temp.path()); | 269 InitFilePaths(temp.path()); |
| 270 | 270 |
| 271 ASSERT_TRUE(PathExists(urls_file())); | 271 ASSERT_TRUE(PathExists(urls_file())); |
| 272 | 272 |
| 273 set_page_cycler(new MockPageCycler(browser(), urls_file(), | 273 set_page_cycler(new MockPageCycler(browser(), urls_file(), |
| 274 errors_file())); | 274 errors_file())); |
| 275 page_cycler()->set_stats_file(stats_file()); | 275 page_cycler()->set_stats_file(stats_file()); |
| 276 RunPageCycler(); | 276 RunPageCycler(); |
| 277 | 277 |
| 278 for (int i = 0; i < kNumLoads; ++i) { | 278 for (int i = 0; i < kNumLoads; ++i) { |
| 279 EXPECT_CALL(*page_cycler(), DidFinishLoad( | 279 EXPECT_CALL(*page_cycler(), DidFinishLoad( |
| 280 kFrameID, kAboutURL, kIsMainFrame, _)) | 280 kFrameID, kAboutURL, kIsMainFrame, _)) |
| 281 .WillOnce(Invoke(page_cycler(), | 281 .WillOnce(Invoke(page_cycler(), |
| 282 &MockPageCycler::PageCyclerDidFinishLoad)); | 282 &MockPageCycler::PageCyclerDidFinishLoad)); |
| 283 FinishLoad(); | 283 FinishLoad(); |
| 284 } | 284 } |
| 285 | 285 |
| 286 PumpLoop(); | 286 PumpLoop(); |
| 287 EXPECT_FALSE(PathExists(errors_file())); | 287 EXPECT_FALSE(PathExists(errors_file())); |
| 288 ASSERT_TRUE(PathExists(stats_file())); | 288 ASSERT_TRUE(PathExists(stats_file())); |
| 289 } | 289 } |
| 290 | 290 |
| 291 TEST_F(PageCyclerTest, KillBrowserAndAbort) { | 291 TEST_F(PageCyclerTest, KillBrowserAndAbort) { |
| 292 const FilePath errors_expected_file = | 292 const FilePath errors_expected_file = |
| 293 test_data_dir().AppendASCII("abort_expected"); | 293 test_data_dir().AppendASCII("abort_expected"); |
| 294 | 294 |
| 295 ScopedTempDir temp; | 295 base::ScopedTempDir temp; |
| 296 ASSERT_TRUE(temp.CreateUniqueTempDir()); | 296 ASSERT_TRUE(temp.CreateUniqueTempDir()); |
| 297 InitFilePaths(temp.path()); | 297 InitFilePaths(temp.path()); |
| 298 | 298 |
| 299 ASSERT_TRUE(PathExists(errors_expected_file)); | 299 ASSERT_TRUE(PathExists(errors_expected_file)); |
| 300 ASSERT_TRUE(PathExists(urls_file())); | 300 ASSERT_TRUE(PathExists(urls_file())); |
| 301 | 301 |
| 302 set_page_cycler(new MockPageCycler(browser(), | 302 set_page_cycler(new MockPageCycler(browser(), |
| 303 urls_file(), | 303 urls_file(), |
| 304 errors_file())); | 304 errors_file())); |
| 305 RunPageCycler(); | 305 RunPageCycler(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 320 ASSERT_TRUE(file_util::ReadFileToString(errors_file(), | 320 ASSERT_TRUE(file_util::ReadFileToString(errors_file(), |
| 321 &errors_output)); | 321 &errors_output)); |
| 322 ASSERT_TRUE(file_util::ReadFileToString(errors_expected_file, | 322 ASSERT_TRUE(file_util::ReadFileToString(errors_expected_file, |
| 323 &errors_expected)); | 323 &errors_expected)); |
| 324 ASSERT_EQ(errors_output, errors_expected); | 324 ASSERT_EQ(errors_output, errors_expected); |
| 325 } | 325 } |
| 326 | 326 |
| 327 TEST_F(PageCyclerTest, MultipleIterations) { | 327 TEST_F(PageCyclerTest, MultipleIterations) { |
| 328 const int kNumLoads = 4; | 328 const int kNumLoads = 4; |
| 329 | 329 |
| 330 ScopedTempDir temp; | 330 base::ScopedTempDir temp; |
| 331 ASSERT_TRUE(temp.CreateUniqueTempDir()); | 331 ASSERT_TRUE(temp.CreateUniqueTempDir()); |
| 332 InitFilePaths(temp.path()); | 332 InitFilePaths(temp.path()); |
| 333 | 333 |
| 334 ASSERT_TRUE(PathExists(urls_file())); | 334 ASSERT_TRUE(PathExists(urls_file())); |
| 335 | 335 |
| 336 set_page_cycler(new MockPageCycler(browser(), | 336 set_page_cycler(new MockPageCycler(browser(), |
| 337 urls_file(), | 337 urls_file(), |
| 338 errors_file())); | 338 errors_file())); |
| 339 page_cycler()->set_stats_file(stats_file()); | 339 page_cycler()->set_stats_file(stats_file()); |
| 340 RunPageCycler(); | 340 RunPageCycler(); |
| 341 | 341 |
| 342 EXPECT_CALL(*page_cycler(), | 342 EXPECT_CALL(*page_cycler(), |
| 343 DidFinishLoad(kFrameID, kAboutURL, kIsMainFrame, _)) | 343 DidFinishLoad(kFrameID, kAboutURL, kIsMainFrame, _)) |
| 344 .WillRepeatedly(Invoke(page_cycler(), | 344 .WillRepeatedly(Invoke(page_cycler(), |
| 345 &MockPageCycler::PageCyclerDidFinishLoad)); | 345 &MockPageCycler::PageCyclerDidFinishLoad)); |
| 346 | 346 |
| 347 for (int i = 0; i < kNumLoads; ++i) | 347 for (int i = 0; i < kNumLoads; ++i) |
| 348 FinishLoad(); | 348 FinishLoad(); |
| 349 | 349 |
| 350 PumpLoop(); | 350 PumpLoop(); |
| 351 EXPECT_FALSE(PathExists(errors_file())); | 351 EXPECT_FALSE(PathExists(errors_file())); |
| 352 ASSERT_TRUE(PathExists(stats_file())); | 352 ASSERT_TRUE(PathExists(stats_file())); |
| 353 } | 353 } |
| OLD | NEW |