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

Fix DeepScanningDialogViewsCancelPendingScanBrowserTest flakiness

The test was flaky less than 1% of the time because of a race between
the "Cancel" button click propagating and the scan responses. The fix is
to set up the delegate so that those responses never come back.

Bug: 1059060
Change-Id: I5d6dd17bfe76f8a2120e3a8cd1cb312f8f5c1fac
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2090135Reviewed-by: default avatarDaniel Rubery <drubery@chromium.org>
Commit-Queue: Dominique Fauteux-Chapleau <domfc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#747792}
parent d011c2bb
...@@ -25,6 +25,39 @@ constexpr base::TimeDelta kMinimumPendingDelay = ...@@ -25,6 +25,39 @@ constexpr base::TimeDelta kMinimumPendingDelay =
constexpr base::TimeDelta kSuccessTimeout = constexpr base::TimeDelta kSuccessTimeout =
base::TimeDelta::FromMilliseconds(100); base::TimeDelta::FromMilliseconds(100);
class UnresponsiveDeepScanningDialogDelegate
: public FakeDeepScanningDialogDelegate {
public:
using FakeDeepScanningDialogDelegate::FakeDeepScanningDialogDelegate;
static std::unique_ptr<DeepScanningDialogDelegate> Create(
base::RepeatingClosure delete_closure,
StatusCallback status_callback,
EncryptionStatusCallback encryption_callback,
std::string dm_token,
content::WebContents* web_contents,
Data data,
CompletionCallback callback) {
auto ret = std::make_unique<UnresponsiveDeepScanningDialogDelegate>(
delete_closure, status_callback, encryption_callback,
std::move(dm_token), web_contents, std::move(data),
std::move(callback));
return ret;
}
private:
void UploadTextForDeepScanning(
std::unique_ptr<BinaryUploadService::Request> request) override {
// Do nothing.
}
void UploadFileForDeepScanning(
const base::FilePath& path,
std::unique_ptr<BinaryUploadService::Request> request) override {
// Do nothing.
}
};
} // namespace } // namespace
DeepScanningBrowserTestBase::DeepScanningBrowserTestBase() { DeepScanningBrowserTestBase::DeepScanningBrowserTestBase() {
...@@ -79,6 +112,17 @@ void DeepScanningBrowserTestBase::SetUpDelegate() { ...@@ -79,6 +112,17 @@ void DeepScanningBrowserTestBase::SetUpDelegate() {
kDmToken)); kDmToken));
} }
void DeepScanningBrowserTestBase::SetUpUnresponsiveDelegate() {
SetDMTokenForTesting(policy::DMToken::CreateValidTokenForTesting(kDmToken));
DeepScanningDialogDelegate::SetFactoryForTesting(base::BindRepeating(
&UnresponsiveDeepScanningDialogDelegate::Create, base::DoNothing(),
base::Bind(&DeepScanningBrowserTestBase::StatusCallback,
base::Unretained(this)),
base::Bind(&DeepScanningBrowserTestBase::EncryptionStatusCallback,
base::Unretained(this)),
kDmToken));
}
void DeepScanningBrowserTestBase::SetQuitClosure( void DeepScanningBrowserTestBase::SetQuitClosure(
base::RepeatingClosure quit_closure) { base::RepeatingClosure quit_closure) {
quit_closure_ = quit_closure; quit_closure_ = quit_closure;
......
...@@ -29,6 +29,9 @@ class DeepScanningBrowserTestBase : public InProcessBrowserTest { ...@@ -29,6 +29,9 @@ class DeepScanningBrowserTestBase : public InProcessBrowserTest {
// and EncryptionStatusCallback. Also sets up a test DM token. // and EncryptionStatusCallback. Also sets up a test DM token.
void SetUpDelegate(); void SetUpDelegate();
// Sets up a FakeDeepScanningDialogDelegate that never returns responses.
void SetUpUnresponsiveDelegate();
// Set up a quit closure to be called by the test. This is useful to control // Set up a quit closure to be called by the test. This is useful to control
// when the test ends. // when the test ends.
void SetQuitClosure(base::RepeatingClosure quit_closure); void SetQuitClosure(base::RepeatingClosure quit_closure);
......
...@@ -507,13 +507,8 @@ INSTANTIATE_TEST_SUITE_P( ...@@ -507,13 +507,8 @@ INSTANTIATE_TEST_SUITE_P(
/*response_delay*/ /*response_delay*/
testing::Values(kNoDelay, kSmallDelay, kNormalDelay))); testing::Values(kNoDelay, kSmallDelay, kNormalDelay)));
#if defined(OS_MACOSX)
#define MAYBE_Test DISABLED_Test
#else
#define MAYBE_Test Test
#endif
IN_PROC_BROWSER_TEST_F(DeepScanningDialogViewsCancelPendingScanBrowserTest, IN_PROC_BROWSER_TEST_F(DeepScanningDialogViewsCancelPendingScanBrowserTest,
MAYBE_Test) { Test) {
// Setup policies to enable deep scanning, its UI and the responses to be // Setup policies to enable deep scanning, its UI and the responses to be
// simulated. // simulated.
SetDlpPolicy(CHECK_UPLOADS); SetDlpPolicy(CHECK_UPLOADS);
...@@ -523,9 +518,10 @@ IN_PROC_BROWSER_TEST_F(DeepScanningDialogViewsCancelPendingScanBrowserTest, ...@@ -523,9 +518,10 @@ IN_PROC_BROWSER_TEST_F(DeepScanningDialogViewsCancelPendingScanBrowserTest,
// Always set this policy so the UI is shown. // Always set this policy so the UI is shown.
SetWaitPolicy(DELAY_UPLOADS); SetWaitPolicy(DELAY_UPLOADS);
// Set up delegate test values. // Set up delegate test values. An unresponsive delegate is set up to avoid
// a race between the file responses and the "Cancel" button being clicked.
FakeDeepScanningDialogDelegate::SetResponseDelay(kSmallDelay); FakeDeepScanningDialogDelegate::SetResponseDelay(kSmallDelay);
SetUpDelegate(); SetUpUnresponsiveDelegate();
bool called = false; bool called = false;
base::RunLoop run_loop; base::RunLoop run_loop;
......
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