content/browser/download/download_browsertest.cc
// Try to shutdown just after we release the download file, by delaying
// release.
Try to shutdown just after we release the download file, by delaying
release.
Try to shutdown just after we release the download file by delaying release .
IN_PROC_BROWSER_TEST_F(DownloadContentTest, ShutdownAtRelease) {
  DownloadManagerImpl* download_manager(DownloadManagerForShell(shell()));
  GetDownloadManagerDelegate(download_manager)->SetDelayedOpen(true);
  DownloadFileWithDelayFactory* file_factory =
      new DownloadFileWithDelayFactory();
  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());
  callbacks[0].Run();
  callbacks.clear();
  std::vector<DownloadItem*> items;
  DownloadManagerForShell(shell())->GetAllDownloads(&items);
  EXPECT_EQ(DownloadItem::IN_PROGRESS, items[0]->GetState());
  ASSERT_EQ(1u, items.size());
  items[0]->Cancel(true);
  EXPECT_EQ(DownloadItem::IN_PROGRESS, items[0]->GetState());
  RunAllPendingInMessageLoop();
  EXPECT_EQ(DownloadItem::IN_PROGRESS, items[0]->GetState());
  MockDownloadItemObserver observer;
  items[0]->AddObserver(&observer);
  EXPECT_CALL(observer, OnDownloadDestroyed(items[0]));
  DownloadManagerForShell(shell())->Shutdown();
}
IN_PROC_BROWSER_TEST_F ( DownloadContentTest , ShutdownAtRelease ) { DownloadManagerImpl * download_manager ( DownloadManagerForShell ( shell ( ) ) ) ; GetDownloadManagerDelegate ( download_manager ) -> SetDelayedOpen ( true ) ; DownloadFileWithDelayFactory * file_factory = new DownloadFileWithDelayFactory ( ) ; 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 ( ) ) ; callbacks [ 0 ] . Run ( ) ; callbacks . clear ( ) ; std :: vector < DownloadItem * > items ; DownloadManagerForShell ( shell ( ) ) -> GetAllDownloads ( & items ) ; EXPECT_EQ ( DownloadItem :: IN_PROGRESS , items [ 0 ] -> GetState ( ) ) ; ASSERT_EQ ( 1u , items . size ( ) ) ; items [ 0 ] -> Cancel ( true ) ; EXPECT_EQ ( DownloadItem :: IN_PROGRESS , items [ 0 ] -> GetState ( ) ) ; RunAllPendingInMessageLoop ( ) ; EXPECT_EQ ( DownloadItem :: IN_PROGRESS , items [ 0 ] -> GetState ( ) ) ; MockDownloadItemObserver observer ; items [ 0 ] -> AddObserver ( & observer ) ; EXPECT_CALL ( observer , OnDownloadDestroyed ( items [ 0 ] ) ) ; DownloadManagerForShell ( shell ( ) ) -> Shutdown ( ) ; }
Try to shutdown just after we release the download file, by delaying
release.
Try to shutdown just after we release the download file by delaying release .
// Mark delegate for delayed open. // 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. // Call it. // Confirm download isn't complete yet. // Cancel the download; confirm cancel fails anyway. // Shutdown the download manager.  Mostly this is confirming a lack of // crashes.