content/browser/download/download_browsertest.cc
// Check that downloading multiple (in this case, 2) files does not result in
// corrupted files.
Check that downloading multiple (in this case, 2) files does not result in
corrupted files.
Check that downloading multiple ( in this case 2 ) files does not result in corrupted files .
IN_PROC_BROWSER_TEST_F(DownloadContentTest, MultiDownload) {
  SetupEnsureNoPendingDownloads();
  scoped_ptr<DownloadTestObserver> observer1(
      CreateInProgressWaiter(shell(), 1));
  NavigateToURL(shell(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl));
  observer1->WaitForFinished();
  std::vector<DownloadItem*> downloads;
  DownloadManagerForShell(shell())->GetAllDownloads(&downloads);
  ASSERT_EQ(1u, downloads.size());
  ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->GetState());
  DownloadItem* download1 = downloads[0];  
  FilePath file(FILE_PATH_LITERAL("download-test.lib"));
  GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
  DownloadAndWait(shell(), url);
  downloads.clear();
  DownloadManagerForShell(shell())->GetAllDownloads(&downloads);
  ASSERT_EQ(2u, downloads.size());
  DownloadItem* download2 = downloads[(download1 == downloads[0]) ? 1 : 0];
  ASSERT_EQ(DownloadItem::IN_PROGRESS, download1->GetState());
  ASSERT_EQ(DownloadItem::COMPLETE, download2->GetState());
  scoped_ptr<DownloadTestObserver> observer2(CreateWaiter(shell(), 1));
  NavigateToURL(shell(), GURL(URLRequestSlowDownloadJob::kFinishDownloadUrl));
  observer2->WaitForFinished();  
  EXPECT_EQ(1u, observer2->NumDownloadsSeenInState(DownloadItem::COMPLETE));
  EXPECT_TRUE(EnsureNoPendingDownloads());
  FilePath file1(download1->GetFullPath());
  size_t file_size1 = URLRequestSlowDownloadJob::kFirstDownloadSize +
                      URLRequestSlowDownloadJob::kSecondDownloadSize;
  std::string expected_contents(file_size1, '*');
  ASSERT_TRUE(VerifyFile(file1, expected_contents, file_size1));
  FilePath file2(download2->GetFullPath());
  ASSERT_TRUE(file_util::ContentsEqual(
      file2, GetTestFilePath("download", "download-test.lib")));
}
IN_PROC_BROWSER_TEST_F ( DownloadContentTest , MultiDownload ) { SetupEnsureNoPendingDownloads ( ) ; scoped_ptr < DownloadTestObserver > observer1 ( CreateInProgressWaiter ( shell ( ) , 1 ) ) ; NavigateToURL ( shell ( ) , GURL ( URLRequestSlowDownloadJob :: kUnknownSizeUrl ) ) ; observer1 -> WaitForFinished ( ) ; std :: vector < DownloadItem * > downloads ; DownloadManagerForShell ( shell ( ) ) -> GetAllDownloads ( & downloads ) ; ASSERT_EQ ( 1u , downloads . size ( ) ) ; ASSERT_EQ ( DownloadItem :: IN_PROGRESS , downloads [ 0 ] -> GetState ( ) ) ; DownloadItem * download1 = downloads [ 0 ] ; FilePath file ( FILE_PATH_LITERAL ( " " ) ) ; GURL url ( URLRequestMockHTTPJob :: GetMockUrl ( file ) ) ; DownloadAndWait ( shell ( ) , url ) ; downloads . clear ( ) ; DownloadManagerForShell ( shell ( ) ) -> GetAllDownloads ( & downloads ) ; ASSERT_EQ ( 2u , downloads . size ( ) ) ; DownloadItem * download2 = downloads [ ( download1 == downloads [ 0 ] ) ? 1 : 0 ] ; ASSERT_EQ ( DownloadItem :: IN_PROGRESS , download1 -> GetState ( ) ) ; ASSERT_EQ ( DownloadItem :: COMPLETE , download2 -> GetState ( ) ) ; scoped_ptr < DownloadTestObserver > observer2 ( CreateWaiter ( shell ( ) , 1 ) ) ; NavigateToURL ( shell ( ) , GURL ( URLRequestSlowDownloadJob :: kFinishDownloadUrl ) ) ; observer2 -> WaitForFinished ( ) ; EXPECT_EQ ( 1u , observer2 -> NumDownloadsSeenInState ( DownloadItem :: COMPLETE ) ) ; EXPECT_TRUE ( EnsureNoPendingDownloads ( ) ) ; FilePath file1 ( download1 -> GetFullPath ( ) ) ; size_t file_size1 = URLRequestSlowDownloadJob :: kFirstDownloadSize + URLRequestSlowDownloadJob :: kSecondDownloadSize ; std :: string expected_contents ( file_size1 , ' ' ) ; ASSERT_TRUE ( VerifyFile ( file1 , expected_contents , file_size1 ) ) ; FilePath file2 ( download2 -> GetFullPath ( ) ) ; ASSERT_TRUE ( file_util :: ContentsEqual ( file2 , GetTestFilePath ( " " , " " ) ) ) ; }
Check that downloading multiple (in this case, 2) files does not result in
corrupted files.
Check that downloading multiple ( in this case 2 ) files does not result in corrupted files .
// Create a download, wait until it's started, and confirm // we're in the expected state. // The only download. // Start the second download and wait until it's done. // Download the file and wait. // Should now have 2 items on the manager. // We don't know the order of the downloads. // Allow the first request to finish. // Wait for the third request. // Get the important info from other threads and check it. // The |DownloadItem|s should now be done and have the final file names. // Verify that the files have the expected data and size. // |file1| should be full of '*'s, and |file2| should be the same as the // source file.