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

Side by Side Diff: content/browser/download/download_browsertest.cc

Issue 17450008: [Downloads] Make DownloadTestObserverTerminal condition on IsDone (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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
« no previous file with comments | « no previous file | content/public/test/download_test_observer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // This file contains download browser tests that are known to be runnable 5 // This file contains download browser tests that are known to be runnable
6 // in a pure content context. Over time tests should be migrated here. 6 // in a pure content context. Over time tests should be migrated here.
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 } 548 }
549 549
550 // Create a DownloadTestObserverInProgress that will wait for the 550 // Create a DownloadTestObserverInProgress that will wait for the
551 // specified number of downloads to start. 551 // specified number of downloads to start.
552 DownloadCreateObserver* CreateInProgressWaiter( 552 DownloadCreateObserver* CreateInProgressWaiter(
553 Shell* shell, int num_downloads) { 553 Shell* shell, int num_downloads) {
554 DownloadManager* download_manager = DownloadManagerForShell(shell); 554 DownloadManager* download_manager = DownloadManagerForShell(shell);
555 return new DownloadCreateObserver(download_manager); 555 return new DownloadCreateObserver(download_manager);
556 } 556 }
557 557
558 DownloadTestObserver* CreateInterruptedWaiter(
559 Shell* shell, int num_downloads) {
560 DownloadManager* download_manager = DownloadManagerForShell(shell);
561 return new DownloadTestObserverInterrupted(download_manager, num_downloads,
562 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL);
563 }
564
558 // Note: Cannot be used with other alternative DownloadFileFactorys 565 // Note: Cannot be used with other alternative DownloadFileFactorys
559 void SetupEnsureNoPendingDownloads() { 566 void SetupEnsureNoPendingDownloads() {
560 DownloadManagerForShell(shell())->SetDownloadFileFactoryForTesting( 567 DownloadManagerForShell(shell())->SetDownloadFileFactoryForTesting(
561 scoped_ptr<DownloadFileFactory>( 568 scoped_ptr<DownloadFileFactory>(
562 new CountingDownloadFileFactory()).Pass()); 569 new CountingDownloadFileFactory()).Pass());
563 } 570 }
564 571
565 bool EnsureNoPendingDownloads() { 572 bool EnsureNoPendingDownloads() {
566 bool result = true; 573 bool result = true;
567 BrowserThread::PostTask( 574 BrowserThread::PostTask(
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 download, base::Bind(&DataReceivedFilter, size)); 636 download, base::Bind(&DataReceivedFilter, size));
630 data_observer.WaitForEvent(); 637 data_observer.WaitForEvent();
631 ASSERT_EQ(size, download->GetReceivedBytes()); 638 ASSERT_EQ(size, download->GetReceivedBytes());
632 ASSERT_EQ(DownloadItem::IN_PROGRESS, download->GetState()); 639 ASSERT_EQ(DownloadItem::IN_PROGRESS, download->GetState());
633 } 640 }
634 641
635 // Tell the test server to release a pending RST and confirm 642 // Tell the test server to release a pending RST and confirm
636 // that the interrupt is received properly (for download resumption 643 // that the interrupt is received properly (for download resumption
637 // testing). 644 // testing).
638 void ReleaseRSTAndConfirmInterruptForResume(DownloadItem* download) { 645 void ReleaseRSTAndConfirmInterruptForResume(DownloadItem* download) {
639 scoped_ptr<DownloadTestObserver> rst_observer(CreateWaiter(shell(), 1)); 646 scoped_ptr<DownloadTestObserver> rst_observer(
647 CreateInterruptedWaiter(shell(), 1));
640 NavigateToURL(shell(), test_server()->GetURL("download-finish")); 648 NavigateToURL(shell(), test_server()->GetURL("download-finish"));
641 rst_observer->WaitForFinished(); 649 rst_observer->WaitForFinished();
642 EXPECT_EQ(DownloadItem::INTERRUPTED, download->GetState()); 650 EXPECT_EQ(DownloadItem::INTERRUPTED, download->GetState());
643 } 651 }
644 652
645 // Confirm file status expected for the given location in a stream 653 // Confirm file status expected for the given location in a stream
646 // provided by the resume test server. 654 // provided by the resume test server.
647 void ConfirmFileStatusForResume( 655 void ConfirmFileStatusForResume(
648 DownloadItem* download, bool file_exists, 656 DownloadItem* download, bool file_exists,
649 int received_bytes, int total_bytes, 657 int received_bytes, int total_bytes,
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
1242 TestFileErrorInjector::FileErrorInfo err = { 1250 TestFileErrorInjector::FileErrorInfo err = {
1243 url.spec(), 1251 url.spec(),
1244 TestFileErrorInjector::FILE_OPERATION_INITIALIZE, 1252 TestFileErrorInjector::FILE_OPERATION_INITIALIZE,
1245 0, 1253 0,
1246 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE 1254 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE
1247 }; 1255 };
1248 injector->AddError(err); 1256 injector->AddError(err);
1249 injector->InjectErrors(); 1257 injector->InjectErrors();
1250 1258
1251 // Start and watch for interrupt. 1259 // Start and watch for interrupt.
1252 scoped_ptr<DownloadTestObserver> int_observer(CreateWaiter(shell(), 1)); 1260 scoped_ptr<DownloadTestObserver> int_observer(
1261 CreateInterruptedWaiter(shell(), 1));
1253 DownloadItem* download(StartDownloadAndReturnItem(url)); 1262 DownloadItem* download(StartDownloadAndReturnItem(url));
1254 int_observer->WaitForFinished(); 1263 int_observer->WaitForFinished();
1255 ASSERT_EQ(DownloadItem::INTERRUPTED, download->GetState()); 1264 ASSERT_EQ(DownloadItem::INTERRUPTED, download->GetState());
1256 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, 1265 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE,
1257 download->GetLastReason()); 1266 download->GetLastReason());
1258 EXPECT_EQ(0, download->GetReceivedBytes()); 1267 EXPECT_EQ(0, download->GetReceivedBytes());
1259 EXPECT_TRUE(download->GetFullPath().empty()); 1268 EXPECT_TRUE(download->GetFullPath().empty());
1260 EXPECT_TRUE(download->GetTargetFilePath().empty()); 1269 EXPECT_TRUE(download->GetTargetFilePath().empty());
1261 1270
1262 // We need to make sure that any cross-thread downloads communication has 1271 // We need to make sure that any cross-thread downloads communication has
(...skipping 29 matching lines...) Expand all
1292 TestFileErrorInjector::FileErrorInfo err = { 1301 TestFileErrorInjector::FileErrorInfo err = {
1293 url.spec(), 1302 url.spec(),
1294 TestFileErrorInjector::FILE_OPERATION_RENAME_UNIQUIFY, 1303 TestFileErrorInjector::FILE_OPERATION_RENAME_UNIQUIFY,
1295 0, 1304 0,
1296 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE 1305 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE
1297 }; 1306 };
1298 injector->AddError(err); 1307 injector->AddError(err);
1299 injector->InjectErrors(); 1308 injector->InjectErrors();
1300 1309
1301 // Start and watch for interrupt. 1310 // Start and watch for interrupt.
1302 scoped_ptr<DownloadTestObserver> int_observer(CreateWaiter(shell(), 1)); 1311 scoped_ptr<DownloadTestObserver> int_observer(
1312 CreateInterruptedWaiter(shell(), 1));
1303 DownloadItem* download(StartDownloadAndReturnItem(url)); 1313 DownloadItem* download(StartDownloadAndReturnItem(url));
1304 int_observer->WaitForFinished(); 1314 int_observer->WaitForFinished();
1305 ASSERT_EQ(DownloadItem::INTERRUPTED, download->GetState()); 1315 ASSERT_EQ(DownloadItem::INTERRUPTED, download->GetState());
1306 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, 1316 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE,
1307 download->GetLastReason()); 1317 download->GetLastReason());
1308 EXPECT_TRUE(download->GetFullPath().empty()); 1318 EXPECT_TRUE(download->GetFullPath().empty());
1309 // Target path will have been set after file name determination. GetFullPath() 1319 // Target path will have been set after file name determination. GetFullPath()
1310 // being empty is sufficient to signal that filename determination needs to be 1320 // being empty is sufficient to signal that filename determination needs to be
1311 // redone. 1321 // redone.
1312 EXPECT_FALSE(download->GetTargetFilePath().empty()); 1322 EXPECT_FALSE(download->GetTargetFilePath().empty());
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1344 TestFileErrorInjector::FileErrorInfo err = { 1354 TestFileErrorInjector::FileErrorInfo err = {
1345 url.spec(), 1355 url.spec(),
1346 TestFileErrorInjector::FILE_OPERATION_RENAME_ANNOTATE, 1356 TestFileErrorInjector::FILE_OPERATION_RENAME_ANNOTATE,
1347 0, 1357 0,
1348 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE 1358 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE
1349 }; 1359 };
1350 injector->AddError(err); 1360 injector->AddError(err);
1351 injector->InjectErrors(); 1361 injector->InjectErrors();
1352 1362
1353 // Start and watch for interrupt. 1363 // Start and watch for interrupt.
1354 scoped_ptr<DownloadTestObserver> int_observer(CreateWaiter(shell(), 1)); 1364 scoped_ptr<DownloadTestObserver> int_observer(
1365 CreateInterruptedWaiter(shell(), 1));
1355 DownloadItem* download(StartDownloadAndReturnItem(url)); 1366 DownloadItem* download(StartDownloadAndReturnItem(url));
1356 int_observer->WaitForFinished(); 1367 int_observer->WaitForFinished();
1357 ASSERT_EQ(DownloadItem::INTERRUPTED, download->GetState()); 1368 ASSERT_EQ(DownloadItem::INTERRUPTED, download->GetState());
1358 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, 1369 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE,
1359 download->GetLastReason()); 1370 download->GetLastReason());
1360 EXPECT_TRUE(download->GetFullPath().empty()); 1371 EXPECT_TRUE(download->GetFullPath().empty());
1361 // Target path should still be intact. 1372 // Target path should still be intact.
1362 EXPECT_FALSE(download->GetTargetFilePath().empty()); 1373 EXPECT_FALSE(download->GetTargetFilePath().empty());
1363 1374
1364 // We need to make sure that any cross-thread downloads communication has 1375 // We need to make sure that any cross-thread downloads communication has
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
1555 // Start the second download and wait until it's done. The test server is 1566 // Start the second download and wait until it's done. The test server is
1556 // single threaded. The response to this download request should follow the 1567 // single threaded. The response to this download request should follow the
1557 // response to the previous resumption request. 1568 // response to the previous resumption request.
1558 GURL url2(test_server()->GetURL("rangereset?size=100&rst_limit=0&token=x")); 1569 GURL url2(test_server()->GetURL("rangereset?size=100&rst_limit=0&token=x"));
1559 DownloadAndWait(shell(), url2, DownloadItem::COMPLETE); 1570 DownloadAndWait(shell(), url2, DownloadItem::COMPLETE);
1560 1571
1561 EXPECT_TRUE(EnsureNoPendingDownloads()); 1572 EXPECT_TRUE(EnsureNoPendingDownloads());
1562 } 1573 }
1563 1574
1564 } // namespace content 1575 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/public/test/download_test_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698