Index: content/browser/download/download_item_impl_unittest.cc |
diff --git a/content/browser/download/download_item_impl_unittest.cc b/content/browser/download/download_item_impl_unittest.cc |
index 4f84f66dfe6a49dddbb3aa677460d08ceb629da6..2ae0ef0dd8ac7ed673a033871921fbe26f7aecaf 100644 |
--- a/content/browser/download/download_item_impl_unittest.cc |
+++ b/content/browser/download/download_item_impl_unittest.cc |
@@ -486,6 +486,125 @@ TEST_F(DownloadItemTest, NotificationAfterDestroyed) { |
ASSERT_TRUE(observer.download_destroyed()); |
} |
+TEST_F(DownloadItemTest, NotificationAfterRemove) { |
+ DownloadItemImpl* item = CreateDownloadItem(); |
+ DownloadItemImplDelegate::DownloadTargetCallback target_callback; |
+ MockDownloadFile* download_file = |
+ CallDownloadItemStart(item, &target_callback); |
+ EXPECT_CALL(*download_file, Cancel()); |
+ EXPECT_CALL(*mock_delegate(), DownloadRemoved(_)); |
+ TestDownloadItemObserver observer(item); |
+ |
+ item->Remove(); |
+ ASSERT_TRUE(observer.CheckAndResetDownloadUpdated()); |
+ ASSERT_TRUE(observer.download_removed()); |
+} |
+ |
+TEST_F(DownloadItemTest, NotificationAfterOnContentCheckCompleted) { |
+ // Setting to NOT_DANGEROUS does not trigger a notification. |
+ DownloadItemImpl* safe_item = CreateDownloadItem(); |
+ MockDownloadFile* download_file = |
+ DoIntermediateRename(safe_item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); |
+ TestDownloadItemObserver safe_observer(safe_item); |
+ |
+ safe_item->OnAllDataSaved(0, std::unique_ptr<crypto::SecureHash>()); |
+ EXPECT_TRUE(safe_observer.CheckAndResetDownloadUpdated()); |
+ safe_item->OnContentCheckCompleted(DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); |
+ EXPECT_TRUE(safe_observer.CheckAndResetDownloadUpdated()); |
+ CleanupItem(safe_item, download_file, DownloadItem::IN_PROGRESS); |
+ |
+ // Setting to unsafe url or unsafe file should trigger a notification. |
+ DownloadItemImpl* unsafeurl_item = CreateDownloadItem(); |
+ download_file = |
+ DoIntermediateRename(unsafeurl_item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); |
+ TestDownloadItemObserver unsafeurl_observer(unsafeurl_item); |
+ |
+ unsafeurl_item->OnAllDataSaved(0, std::unique_ptr<crypto::SecureHash>()); |
+ EXPECT_TRUE(unsafeurl_observer.CheckAndResetDownloadUpdated()); |
+ unsafeurl_item->OnContentCheckCompleted(DOWNLOAD_DANGER_TYPE_DANGEROUS_URL); |
+ EXPECT_TRUE(unsafeurl_observer.CheckAndResetDownloadUpdated()); |
+ |
+ EXPECT_CALL(*mock_delegate(), ShouldCompleteDownload(_, _)) |
+ .WillOnce(Return(true)); |
+ EXPECT_CALL(*download_file, RenameAndAnnotate(_, _, _, _, _)); |
+ unsafeurl_item->ValidateDangerousDownload(); |
+ EXPECT_TRUE(unsafeurl_observer.CheckAndResetDownloadUpdated()); |
+ CleanupItem(unsafeurl_item, download_file, DownloadItem::IN_PROGRESS); |
+ |
+ DownloadItemImpl* unsafefile_item = CreateDownloadItem(); |
+ download_file = |
+ DoIntermediateRename(unsafefile_item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); |
+ TestDownloadItemObserver unsafefile_observer(unsafefile_item); |
+ |
+ unsafefile_item->OnAllDataSaved(0, std::unique_ptr<crypto::SecureHash>()); |
+ EXPECT_TRUE(unsafefile_observer.CheckAndResetDownloadUpdated()); |
+ unsafefile_item->OnContentCheckCompleted(DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE); |
+ EXPECT_TRUE(unsafefile_observer.CheckAndResetDownloadUpdated()); |
+ |
+ EXPECT_CALL(*mock_delegate(), ShouldCompleteDownload(_, _)) |
+ .WillOnce(Return(true)); |
+ EXPECT_CALL(*download_file, RenameAndAnnotate(_, _, _, _, _)); |
+ unsafefile_item->ValidateDangerousDownload(); |
+ EXPECT_TRUE(unsafefile_observer.CheckAndResetDownloadUpdated()); |
+ CleanupItem(unsafefile_item, download_file, DownloadItem::IN_PROGRESS); |
+} |
+ |
+// DownloadItemImpl::OnDownloadTargetDetermined will schedule a task to run |
+// DownloadFile::Rename(). Once the rename |
+// completes, DownloadItemImpl receives a notification with the new file |
+// name. Check that observers are updated when the new filename is available and |
+// not before. |
+TEST_F(DownloadItemTest, NotificationAfterOnDownloadTargetDetermined) { |
+ DownloadItemImpl* item = CreateDownloadItem(); |
+ DownloadItemImplDelegate::DownloadTargetCallback callback; |
+ MockDownloadFile* download_file = CallDownloadItemStart(item, &callback); |
+ TestDownloadItemObserver observer(item); |
+ base::FilePath target_path(kDummyTargetPath); |
+ base::FilePath intermediate_path(target_path.InsertBeforeExtensionASCII("x")); |
+ base::FilePath new_intermediate_path( |
+ target_path.InsertBeforeExtensionASCII("y")); |
+ EXPECT_CALL(*download_file, RenameAndUniquify(intermediate_path, _)) |
+ .WillOnce(ScheduleRenameAndUniquifyCallback( |
+ DOWNLOAD_INTERRUPT_REASON_NONE, new_intermediate_path)); |
+ |
+ // Currently, a notification would be generated if the danger type is anything |
+ // other than NOT_DANGEROUS. |
+ callback.Run(target_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
+ DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, intermediate_path); |
+ EXPECT_FALSE(observer.CheckAndResetDownloadUpdated()); |
+ RunAllPendingInMessageLoops(); |
+ EXPECT_TRUE(observer.CheckAndResetDownloadUpdated()); |
+ EXPECT_EQ(new_intermediate_path, item->GetFullPath()); |
+ |
+ CleanupItem(item, download_file, DownloadItem::IN_PROGRESS); |
+} |
+ |
+TEST_F(DownloadItemTest, NotificationAfterTogglePause) { |
+ DownloadItemImpl* item = CreateDownloadItem(); |
+ TestDownloadItemObserver observer(item); |
+ MockDownloadFile* mock_download_file(new MockDownloadFile); |
+ std::unique_ptr<DownloadFile> download_file(mock_download_file); |
+ std::unique_ptr<DownloadRequestHandleInterface> request_handle( |
+ new NiceMock<MockRequestHandle>); |
+ |
+ EXPECT_CALL(*mock_download_file, Initialize(_)); |
+ EXPECT_CALL(*mock_delegate(), DetermineDownloadTarget(_, _)); |
+ item->Start(std::move(download_file), std::move(request_handle), |
+ *create_info()); |
+ |
+ item->Pause(); |
+ ASSERT_TRUE(observer.CheckAndResetDownloadUpdated()); |
+ |
+ ASSERT_TRUE(item->IsPaused()); |
+ |
+ item->Resume(); |
+ ASSERT_TRUE(observer.CheckAndResetDownloadUpdated()); |
+ |
+ RunAllPendingInMessageLoops(); |
+ |
+ CleanupItem(item, mock_download_file, DownloadItem::IN_PROGRESS); |
+} |
+ |
// Test that a download is resumed automatcially after a continuable interrupt. |
TEST_F(DownloadItemTest, ContinueAfterInterrupted) { |
DownloadItemImpl* item = CreateDownloadItem(); |
@@ -728,127 +847,6 @@ TEST_F(DownloadItemTest, ResumeUsingFinalURL) { |
CleanupItem(item, nullptr, DownloadItem::IN_PROGRESS); |
} |
-TEST_F(DownloadItemTest, NotificationAfterRemove) { |
- DownloadItemImpl* item = CreateDownloadItem(); |
- DownloadItemImplDelegate::DownloadTargetCallback target_callback; |
- MockDownloadFile* download_file = |
- CallDownloadItemStart(item, &target_callback); |
- EXPECT_CALL(*download_file, Cancel()); |
- EXPECT_CALL(*mock_delegate(), DownloadRemoved(_)); |
- TestDownloadItemObserver observer(item); |
- |
- item->Remove(); |
- ASSERT_TRUE(observer.CheckAndResetDownloadUpdated()); |
- ASSERT_TRUE(observer.download_removed()); |
-} |
- |
-TEST_F(DownloadItemTest, NotificationAfterOnContentCheckCompleted) { |
- // Setting to NOT_DANGEROUS does not trigger a notification. |
- DownloadItemImpl* safe_item = CreateDownloadItem(); |
- MockDownloadFile* download_file = |
- DoIntermediateRename(safe_item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); |
- TestDownloadItemObserver safe_observer(safe_item); |
- |
- safe_item->OnAllDataSaved(0, std::unique_ptr<crypto::SecureHash>()); |
- EXPECT_TRUE(safe_observer.CheckAndResetDownloadUpdated()); |
- safe_item->OnContentCheckCompleted(DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); |
- EXPECT_TRUE(safe_observer.CheckAndResetDownloadUpdated()); |
- CleanupItem(safe_item, download_file, DownloadItem::IN_PROGRESS); |
- |
- // Setting to unsafe url or unsafe file should trigger a notification. |
- DownloadItemImpl* unsafeurl_item = |
- CreateDownloadItem(); |
- download_file = |
- DoIntermediateRename(unsafeurl_item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); |
- TestDownloadItemObserver unsafeurl_observer(unsafeurl_item); |
- |
- unsafeurl_item->OnAllDataSaved(0, std::unique_ptr<crypto::SecureHash>()); |
- EXPECT_TRUE(unsafeurl_observer.CheckAndResetDownloadUpdated()); |
- unsafeurl_item->OnContentCheckCompleted(DOWNLOAD_DANGER_TYPE_DANGEROUS_URL); |
- EXPECT_TRUE(unsafeurl_observer.CheckAndResetDownloadUpdated()); |
- |
- EXPECT_CALL(*mock_delegate(), ShouldCompleteDownload(_, _)) |
- .WillOnce(Return(true)); |
- EXPECT_CALL(*download_file, RenameAndAnnotate(_, _, _, _, _)); |
- unsafeurl_item->ValidateDangerousDownload(); |
- EXPECT_TRUE(unsafeurl_observer.CheckAndResetDownloadUpdated()); |
- CleanupItem(unsafeurl_item, download_file, DownloadItem::IN_PROGRESS); |
- |
- DownloadItemImpl* unsafefile_item = |
- CreateDownloadItem(); |
- download_file = |
- DoIntermediateRename(unsafefile_item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); |
- TestDownloadItemObserver unsafefile_observer(unsafefile_item); |
- |
- unsafefile_item->OnAllDataSaved(0, std::unique_ptr<crypto::SecureHash>()); |
- EXPECT_TRUE(unsafefile_observer.CheckAndResetDownloadUpdated()); |
- unsafefile_item->OnContentCheckCompleted(DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE); |
- EXPECT_TRUE(unsafefile_observer.CheckAndResetDownloadUpdated()); |
- |
- EXPECT_CALL(*mock_delegate(), ShouldCompleteDownload(_, _)) |
- .WillOnce(Return(true)); |
- EXPECT_CALL(*download_file, RenameAndAnnotate(_, _, _, _, _)); |
- unsafefile_item->ValidateDangerousDownload(); |
- EXPECT_TRUE(unsafefile_observer.CheckAndResetDownloadUpdated()); |
- CleanupItem(unsafefile_item, download_file, DownloadItem::IN_PROGRESS); |
-} |
- |
-// DownloadItemImpl::OnDownloadTargetDetermined will schedule a task to run |
-// DownloadFile::Rename(). Once the rename |
-// completes, DownloadItemImpl receives a notification with the new file |
-// name. Check that observers are updated when the new filename is available and |
-// not before. |
-TEST_F(DownloadItemTest, NotificationAfterOnDownloadTargetDetermined) { |
- DownloadItemImpl* item = CreateDownloadItem(); |
- DownloadItemImplDelegate::DownloadTargetCallback callback; |
- MockDownloadFile* download_file = CallDownloadItemStart(item, &callback); |
- TestDownloadItemObserver observer(item); |
- base::FilePath target_path(kDummyTargetPath); |
- base::FilePath intermediate_path(target_path.InsertBeforeExtensionASCII("x")); |
- base::FilePath new_intermediate_path( |
- target_path.InsertBeforeExtensionASCII("y")); |
- EXPECT_CALL(*download_file, RenameAndUniquify(intermediate_path, _)) |
- .WillOnce(ScheduleRenameAndUniquifyCallback( |
- DOWNLOAD_INTERRUPT_REASON_NONE, new_intermediate_path)); |
- |
- // Currently, a notification would be generated if the danger type is anything |
- // other than NOT_DANGEROUS. |
- callback.Run(target_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
- DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, intermediate_path); |
- EXPECT_FALSE(observer.CheckAndResetDownloadUpdated()); |
- RunAllPendingInMessageLoops(); |
- EXPECT_TRUE(observer.CheckAndResetDownloadUpdated()); |
- EXPECT_EQ(new_intermediate_path, item->GetFullPath()); |
- |
- CleanupItem(item, download_file, DownloadItem::IN_PROGRESS); |
-} |
- |
-TEST_F(DownloadItemTest, NotificationAfterTogglePause) { |
- DownloadItemImpl* item = CreateDownloadItem(); |
- TestDownloadItemObserver observer(item); |
- MockDownloadFile* mock_download_file(new MockDownloadFile); |
- std::unique_ptr<DownloadFile> download_file(mock_download_file); |
- std::unique_ptr<DownloadRequestHandleInterface> request_handle( |
- new NiceMock<MockRequestHandle>); |
- |
- EXPECT_CALL(*mock_download_file, Initialize(_)); |
- EXPECT_CALL(*mock_delegate(), DetermineDownloadTarget(_, _)); |
- item->Start(std::move(download_file), std::move(request_handle), |
- *create_info()); |
- |
- item->Pause(); |
- ASSERT_TRUE(observer.CheckAndResetDownloadUpdated()); |
- |
- ASSERT_TRUE(item->IsPaused()); |
- |
- item->Resume(); |
- ASSERT_TRUE(observer.CheckAndResetDownloadUpdated()); |
- |
- RunAllPendingInMessageLoops(); |
- |
- CleanupItem(item, mock_download_file, DownloadItem::IN_PROGRESS); |
-} |
- |
TEST_F(DownloadItemTest, DisplayName) { |
DownloadItemImpl* item = CreateDownloadItem(); |
DownloadItemImplDelegate::DownloadTargetCallback callback; |