Commit 7476914d authored by kcarattini's avatar kcarattini Committed by Commit bot

Permission Action Reporting: Fix flaky Browsertest

This is my attempt to fix the flakiness of this browsertest by having the UI thread wait for the report to be sent on the IO thread.

BUG=613883,638316

Review-Url: https://codereview.chromium.org/2250163003
Cr-Commit-Position: refs/heads/master@{#414252}
parent 24e7ec45
......@@ -2,22 +2,50 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/run_loop.h"
#include "chrome/browser/safe_browsing/mock_permission_report_sender.h"
#include "content/public/browser/browser_thread.h"
namespace safe_browsing {
MockPermissionReportSender::MockPermissionReportSender()
: net::ReportSender(nullptr, DO_NOT_SEND_COOKIES) {
number_of_reports_ = 0;
: net::ReportSender(nullptr, DO_NOT_SEND_COOKIES),
number_of_reports_(0) {
DCHECK(quit_closure_.is_null());
}
MockPermissionReportSender::~MockPermissionReportSender() {}
MockPermissionReportSender::~MockPermissionReportSender() {
}
void MockPermissionReportSender::Send(const GURL& report_uri,
const std::string& report) {
latest_report_uri_ = report_uri;
latest_report_ = report;
number_of_reports_++;
// BrowserThreads aren't initialized in the unittest, so don't post tasks
// to them.
if (!content::BrowserThread::IsThreadInitialized(content::BrowserThread::UI))
return;
content::BrowserThread::PostTask(
content::BrowserThread::UI, FROM_HERE,
base::Bind(
&MockPermissionReportSender::NotifyReportSentOnUIThread,
base::Unretained(this)));
}
void MockPermissionReportSender::WaitForReportSent() {
base::RunLoop run_loop;
quit_closure_ = run_loop.QuitClosure();
run_loop.Run();
}
void MockPermissionReportSender::NotifyReportSentOnUIThread() {
if (!quit_closure_.is_null()) {
quit_closure_.Run();
quit_closure_.Reset();
}
}
const GURL& MockPermissionReportSender::latest_report_uri() {
......
......@@ -25,10 +25,15 @@ class MockPermissionReportSender : public net::ReportSender {
int GetAndResetNumberOfReportsSent();
void WaitForReportSent();
private:
GURL latest_report_uri_;
std::string latest_report_;
int number_of_reports_;
base::Closure quit_closure_;
void NotifyReportSentOnUIThread();
DISALLOW_COPY_AND_ASSIGN(MockPermissionReportSender);
};
......
......@@ -87,9 +87,8 @@ class PermissionReporterBrowserTest : public SyncTest {
};
// Test that permission action report will be sent if the user is opted into it.
// TODO(kcarattini): Address crbug/638316 to reenable this test.
IN_PROC_BROWSER_TEST_F(PermissionReporterBrowserTest,
DISABLED_PermissionActionReporting) {
PermissionActionReporting) {
// Set up the Sync client.
ASSERT_TRUE(SetupSync());
Profile* profile = GetProfile(0);
......@@ -110,8 +109,10 @@ IN_PROC_BROWSER_TEST_F(PermissionReporterBrowserTest,
EXPECT_TRUE(mock_permission_prompt_factory->is_visible());
AcceptBubble(browser);
EXPECT_FALSE(mock_permission_prompt_factory->is_visible());
// We need to wait for the report to be sent on the IO thread.
mock_report_sender()->WaitForReportSent();
EXPECT_EQ(1, mock_report_sender()->GetAndResetNumberOfReportsSent());
PermissionReport permission_report;
......
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