Commit 28640451 authored by Dominique Fauteux-Chapleau's avatar Dominique Fauteux-Chapleau Committed by Commit Bot

Add browser tests for DeepScanningDialogDelegate

These tests use the least possible amount of overrides to ensure
DeepScanningDialogDelegate every requests/callbacks eventually resolves
and returns to the caller.

Also add code to handle the web contents being destroyed and avoid ASAN
issues.

Bug: 1041890
Change-Id: Ibfe232354f0591ae9e854bf5a0163ede68d6faf9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2083598
Commit-Queue: Dominique Fauteux-Chapleau <domfc@chromium.org>
Reviewed-by: default avatarDaniel Rubery <drubery@chromium.org>
Cr-Commit-Position: refs/heads/master@{#747713}
parent 1752cece
......@@ -163,7 +163,7 @@ class BinaryUploadService {
// Upload the given file contents for deep scanning. The results will be
// returned asynchronously by calling |request|'s |callback|. This must be
// called on the UI thread.
void UploadForDeepScanning(std::unique_ptr<Request> request);
virtual void UploadForDeepScanning(std::unique_ptr<Request> request);
void OnGetInstanceID(Request* request, const std::string& token);
......
......@@ -744,14 +744,17 @@ void DeepScanningDialogDelegate::FillAllResultsWith(bool status) {
std::fill(result_.paths_results.begin(), result_.paths_results.end(), status);
}
BinaryUploadService* DeepScanningDialogDelegate::GetBinaryUploadService() {
return g_browser_process->safe_browsing_service()->GetBinaryUploadService(
Profile::FromBrowserContext(web_contents_->GetBrowserContext()));
}
void DeepScanningDialogDelegate::UploadTextForDeepScanning(
std::unique_ptr<BinaryUploadService::Request> request) {
DCHECK_EQ(
DlpDeepScanningClientRequest::WEB_CONTENT_UPLOAD,
request->deep_scanning_request().dlp_scan_request().content_source());
BinaryUploadService* upload_service =
g_browser_process->safe_browsing_service()->GetBinaryUploadService(
Profile::FromBrowserContext(web_contents_->GetBrowserContext()));
BinaryUploadService* upload_service = GetBinaryUploadService();
if (upload_service)
upload_service->MaybeUploadForDeepScanning(std::move(request));
}
......@@ -763,9 +766,7 @@ void DeepScanningDialogDelegate::UploadFileForDeepScanning(
!data_.do_dlp_scan ||
(DlpDeepScanningClientRequest::FILE_UPLOAD ==
request->deep_scanning_request().dlp_scan_request().content_source()));
BinaryUploadService* upload_service =
g_browser_process->safe_browsing_service()->GetBinaryUploadService(
Profile::FromBrowserContext(web_contents_->GetBrowserContext()));
BinaryUploadService* upload_service = GetBinaryUploadService();
if (upload_service)
upload_service->MaybeUploadForDeepScanning(std::move(request));
}
......
......@@ -29,6 +29,7 @@ class Profile;
namespace safe_browsing {
class BinaryUploadService;
class DeepScanningDialogViews;
// A tab modal dialog delegate that informs the user of a background deep
......@@ -306,6 +307,10 @@ class DeepScanningDialogDelegate {
// DeepScanningFinalResult enum.
void UpdateFinalResult(DeepScanningFinalResult message);
// Returns the BinaryUploadService used to upload content for deep scanning.
// Virtual to override in tests.
virtual BinaryUploadService* GetBinaryUploadService();
// The web contents that is attempting to access the data.
content::WebContents* web_contents_ = nullptr;
......
......@@ -176,7 +176,8 @@ DeepScanningDialogViews::DeepScanningDialogViews(
content::WebContents* web_contents,
DeepScanAccessPoint access_point,
bool is_file_scan)
: delegate_(std::move(delegate)),
: content::WebContentsObserver(web_contents),
delegate_(std::move(delegate)),
web_contents_(web_contents),
access_point_(std::move(access_point)),
is_file_scan_(is_file_scan) {
......@@ -229,6 +230,10 @@ ui::ModalType DeepScanningDialogViews::GetModalType() const {
return ui::MODAL_TYPE_CHILD;
}
void DeepScanningDialogViews::WebContentsDestroyed() {
delete this;
}
void DeepScanningDialogViews::ShowResult(
DeepScanningDialogDelegate::DeepScanningFinalResult result) {
DCHECK(is_pending());
......
......@@ -11,6 +11,7 @@
#include "base/time/time.h"
#include "chrome/browser/safe_browsing/cloud_content_scanning/deep_scanning_dialog_delegate.h"
#include "chrome/browser/safe_browsing/cloud_content_scanning/deep_scanning_utils.h"
#include "content/public/browser/web_contents_observer.h"
#include "ui/views/animation/bounds_animator.h"
#include "ui/views/controls/label.h"
#include "ui/views/window/dialog_delegate.h"
......@@ -38,7 +39,8 @@ class DeepScanningMessageView;
// Dialog shown for Deep Scanning to offer the possibility of cancelling the
// upload to the user.
class DeepScanningDialogViews : public views::DialogDelegate {
class DeepScanningDialogViews : public views::DialogDelegate,
public content::WebContentsObserver {
public:
// Enum used to represent what the dialog is currently showing.
enum class DeepScanningDialogStatus {
......@@ -119,6 +121,9 @@ class DeepScanningDialogViews : public views::DialogDelegate {
void DeleteDelegate() override;
ui::ModalType GetModalType() const override;
// content::WebContentsObserver:
void WebContentsDestroyed() override;
// Updates the dialog with the result, and simply delete it from memory if
// nothing should be shown.
void ShowResult(DeepScanningDialogDelegate::DeepScanningFinalResult result);
......
......@@ -1165,6 +1165,7 @@ if (!is_android) {
"../browser/safe_browsing/chrome_cleaner/reporter_runner_browsertest_win.cc",
"../browser/safe_browsing/cloud_content_scanning/deep_scanning_browsertest_base.cc",
"../browser/safe_browsing/cloud_content_scanning/deep_scanning_browsertest_base.h",
"../browser/safe_browsing/cloud_content_scanning/deep_scanning_dialog_delegate_browsertest.cc",
"../browser/safe_browsing/cloud_content_scanning/deep_scanning_dialog_views_browsertest.cc",
"../browser/safe_browsing/download_protection/download_protection_service_browsertest.cc",
"../browser/safe_browsing/test_safe_browsing_database_helper.cc",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment