Commit eded5d09 authored by Peter Boström's avatar Peter Boström Committed by Commit Bot

Add interactive tests for DownloadDangerPrompt.

Exposes all current window titles, message bodies and cancel-button
text.

Also fixing crash when DownloadDangerPromptViews is destructed without
triggering an action. This happens at least when browser_tests are run
without --interactive, though possibly also when a tab gets closed
without closing the dialog first.

Bug: chromium:654142
Change-Id: I7339ffec27cb41d50ddc97aece2ca4fdf403cbb5
Reviewed-on: https://chromium-review.googlesource.com/731617
Commit-Queue: Peter Boström <pbos@chromium.org>
Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Reviewed-by: default avatarBret Sepulveda <bsep@chromium.org>
Cr-Commit-Position: refs/heads/master@{#512660}
parent a874a676
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "chrome/browser/ui/browser_commands.h" #include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_tabstrip.h" #include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/test/test_browser_dialog.h"
#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h" #include "chrome/test/base/ui_test_utils.h"
#include "components/safe_browsing/db/database_manager.h" #include "components/safe_browsing/db/database_manager.h"
...@@ -342,4 +343,86 @@ INSTANTIATE_TEST_CASE_P(, ...@@ -342,4 +343,86 @@ INSTANTIATE_TEST_CASE_P(,
SecondaryUiMd::DISABLED), SecondaryUiMd::DISABLED),
&SecondaryUiMdStatusToString); &SecondaryUiMdStatusToString);
// Class for testing interactive dialogs.
class DownloadDangerPromptBrowserTest : public DialogBrowserTest {
protected:
enum InvocationType { USER_INITIATED, FROM_DOWNLOAD_API };
DownloadDangerPromptBrowserTest() : download_url_(kTestDownloadUrl) {}
void RunTest(content::DownloadDangerType danger_type,
InvocationType invocation_type) {
danger_type_ = danger_type;
invocation_type_ = invocation_type;
RunDialog();
}
private:
void ShowDialog(const std::string& name) override {
ON_CALL(download_, GetURL()).WillByDefault(ReturnRef(download_url_));
ON_CALL(download_, GetReferrerUrl())
.WillByDefault(ReturnRef(GURL::EmptyGURL()));
ON_CALL(download_, GetBrowserContext())
.WillByDefault(Return(browser()->profile()));
ON_CALL(download_, GetTargetFilePath())
.WillByDefault(ReturnRef(empty_file_path_));
ON_CALL(download_, IsDangerous()).WillByDefault(Return(true));
ON_CALL(download_, GetFileNameToReportUser())
.WillByDefault(Return(base::FilePath(FILE_PATH_LITERAL("evil.exe"))));
// Set up test-specific parameters
ON_CALL(download_, GetDangerType()).WillByDefault(Return(danger_type_));
DownloadDangerPrompt::Create(
&download_, browser()->tab_strip_model()->GetActiveWebContents(),
invocation_type_ == FROM_DOWNLOAD_API, DownloadDangerPrompt::OnDone());
}
const GURL download_url_;
const base::FilePath empty_file_path_;
content::DownloadDangerType danger_type_;
InvocationType invocation_type_;
content::MockDownloadItem download_;
DISALLOW_COPY_AND_ASSIGN(DownloadDangerPromptBrowserTest);
};
IN_PROC_BROWSER_TEST_F(DownloadDangerPromptBrowserTest,
InvokeDialog_DangerousFile) {
RunTest(content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, USER_INITIATED);
}
IN_PROC_BROWSER_TEST_F(DownloadDangerPromptBrowserTest,
InvokeDialog_DangerousFileFromApi) {
RunTest(content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, FROM_DOWNLOAD_API);
}
IN_PROC_BROWSER_TEST_F(DownloadDangerPromptBrowserTest,
InvokeDialog_DangerousUrl) {
RunTest(content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL, USER_INITIATED);
}
IN_PROC_BROWSER_TEST_F(DownloadDangerPromptBrowserTest,
InvokeDialog_DangerousUrlFromApi) {
RunTest(content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL, FROM_DOWNLOAD_API);
}
IN_PROC_BROWSER_TEST_F(DownloadDangerPromptBrowserTest,
InvokeDialog_UncommonContent) {
RunTest(content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT, USER_INITIATED);
}
IN_PROC_BROWSER_TEST_F(DownloadDangerPromptBrowserTest,
InvokeDialog_UncommonContentFromApi) {
RunTest(content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT, FROM_DOWNLOAD_API);
}
IN_PROC_BROWSER_TEST_F(DownloadDangerPromptBrowserTest,
InvokeDialog_PotentiallyUnwanted) {
RunTest(content::DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED, USER_INITIATED);
}
IN_PROC_BROWSER_TEST_F(DownloadDangerPromptBrowserTest,
InvokeDialog_PotentiallyUnwantedFromApi) {
RunTest(content::DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED,
FROM_DOWNLOAD_API);
}
} // namespace safe_browsing } // namespace safe_browsing
...@@ -80,7 +80,6 @@ DownloadDangerPromptImpl::DownloadDangerPromptImpl( ...@@ -80,7 +80,6 @@ DownloadDangerPromptImpl::DownloadDangerPromptImpl(
download_(download), download_(download),
show_context_(show_context), show_context_(show_context),
done_(done) { done_(done) {
DCHECK(!done_.is_null());
download_->AddObserver(this); download_->AddObserver(this);
RecordOpenedDangerousConfirmDialog(download_->GetDangerType()); RecordOpenedDangerousConfirmDialog(download_->GetDangerType());
......
...@@ -46,6 +46,7 @@ class DownloadDangerPromptViews : public DownloadDangerPrompt, ...@@ -46,6 +46,7 @@ class DownloadDangerPromptViews : public DownloadDangerPrompt,
DownloadDangerPromptViews(content::DownloadItem* item, DownloadDangerPromptViews(content::DownloadItem* item,
bool show_context, bool show_context,
const OnDone& done); const OnDone& done);
~DownloadDangerPromptViews() override;
// DownloadDangerPrompt: // DownloadDangerPrompt:
void InvokeActionForTesting(Action action) override; void InvokeActionForTesting(Action action) override;
...@@ -91,7 +92,6 @@ DownloadDangerPromptViews::DownloadDangerPromptViews( ...@@ -91,7 +92,6 @@ DownloadDangerPromptViews::DownloadDangerPromptViews(
show_context_(show_context), show_context_(show_context),
done_(done), done_(done),
contents_view_(NULL) { contents_view_(NULL) {
DCHECK(!done_.is_null());
download_->AddObserver(this); download_->AddObserver(this);
contents_view_ = new views::View; contents_view_ = new views::View;
...@@ -126,6 +126,11 @@ DownloadDangerPromptViews::DownloadDangerPromptViews( ...@@ -126,6 +126,11 @@ DownloadDangerPromptViews::DownloadDangerPromptViews(
chrome::DialogIdentifier::DOWNLOAD_DANGER_PROMPT); chrome::DialogIdentifier::DOWNLOAD_DANGER_PROMPT);
} }
DownloadDangerPromptViews::~DownloadDangerPromptViews() {
if (download_)
download_->RemoveObserver(this);
}
// DownloadDangerPrompt methods: // DownloadDangerPrompt methods:
void DownloadDangerPromptViews::InvokeActionForTesting(Action action) { void DownloadDangerPromptViews::InvokeActionForTesting(Action action) {
switch (action) { switch (action) {
......
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