content/browser/download/download_browsertest.cc
// Try to cancel just before we release the download file, by delaying final
// rename callback.
Try to cancel just before we release the download file, by delaying final
rename callback.
Try to cancel just before we release the download file by delaying final rename callback .
IN_PROC_BROWSER_TEST_F(DownloadContentTest, CancelAtFinalRename) {
  DownloadFileWithDelayFactory* file_factory =
      new DownloadFileWithDelayFactory();
  DownloadManagerImpl* download_manager(DownloadManagerForShell(shell()));
  download_manager->SetDownloadFileFactoryForTesting(
      scoped_ptr<DownloadFileFactory>(file_factory).Pass());
  FilePath file(FILE_PATH_LITERAL("download-test.lib"));
  NavigateToURL(shell(), URLRequestMockHTTPJob::GetMockUrl(file));
  file_factory->WaitForSomeCallback();
  std::vector<base::Closure> callbacks;
  file_factory->GetAllRenameCallbacks(&callbacks);
  ASSERT_EQ(1u, callbacks.size());
  callbacks[0].Run();
  callbacks.clear();
  file_factory->WaitForSomeCallback();
  file_factory->GetAllRenameCallbacks(&callbacks);
  ASSERT_EQ(1u, callbacks.size());
  std::vector<DownloadItem*> items;
  download_manager->GetAllDownloads(&items);
  ASSERT_EQ(1u, items.size());
  items[0]->Cancel(true);
  RunAllPendingInMessageLoop();
  EXPECT_EQ(DownloadItem::CANCELLED, items[0]->GetState());
  callbacks[0].Run();
  callbacks.clear();
  EXPECT_EQ(DownloadItem::CANCELLED, items[0]->GetState());
}
IN_PROC_BROWSER_TEST_F ( DownloadContentTest , CancelAtFinalRename ) { DownloadFileWithDelayFactory * file_factory = new DownloadFileWithDelayFactory ( ) ; DownloadManagerImpl * download_manager ( DownloadManagerForShell ( shell ( ) ) ) ; download_manager -> SetDownloadFileFactoryForTesting ( scoped_ptr < DownloadFileFactory > ( file_factory ) . Pass ( ) ) ; FilePath file ( FILE_PATH_LITERAL ( " " ) ) ; NavigateToURL ( shell ( ) , URLRequestMockHTTPJob :: GetMockUrl ( file ) ) ; file_factory -> WaitForSomeCallback ( ) ; std :: vector < base :: Closure > callbacks ; file_factory -> GetAllRenameCallbacks ( & callbacks ) ; ASSERT_EQ ( 1u , callbacks . size ( ) ) ; callbacks [ 0 ] . Run ( ) ; callbacks . clear ( ) ; file_factory -> WaitForSomeCallback ( ) ; file_factory -> GetAllRenameCallbacks ( & callbacks ) ; ASSERT_EQ ( 1u , callbacks . size ( ) ) ; std :: vector < DownloadItem * > items ; download_manager -> GetAllDownloads ( & items ) ; ASSERT_EQ ( 1u , items . size ( ) ) ; items [ 0 ] -> Cancel ( true ) ; RunAllPendingInMessageLoop ( ) ; EXPECT_EQ ( DownloadItem :: CANCELLED , items [ 0 ] -> GetState ( ) ) ; callbacks [ 0 ] . Run ( ) ; callbacks . clear ( ) ; EXPECT_EQ ( DownloadItem :: CANCELLED , items [ 0 ] -> GetState ( ) ) ; }
Try to cancel just before we release the download file, by delaying final
rename callback.
Try to cancel just before we release the download file by delaying final rename callback .
// Setup new factory. // Create a download // Wait until the first (intermediate file) rename and execute the callback. // Wait until the second (final) rename callback is posted. // Cancel it. // Check state. // Run final rename callback. // Check state.