Commit 2dcec349 authored by Xing Liu's avatar Xing Liu Committed by Commit Bot

Fix DownloadHistoryCheck on windows continuous builder.

Currently it's flaky that a partial buffer is read through network
pipeline when the first history db record is generated.

This CL changed the observer to be able to optionally wait for a
certain number of bytes read from network IO.

Bug: 788160
Change-Id: I110653433e8c80c2dabf9f3162df99d7bb354e86
Reviewed-on: https://chromium-review.googlesource.com/790946Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Commit-Queue: Xing Liu <xingliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#519930}
parent 277f0bc7
......@@ -357,7 +357,8 @@ class HistoryObserver : public DownloadHistory::Observer {
explicit HistoryObserver(Profile* profile)
: profile_(profile),
waiting_(false),
seen_stored_(false) {
seen_stored_(false),
minimum_received_bytes_(kNoMinimumReceivedBytes) {
DownloadCoreServiceFactory::GetForBrowserContext(profile_)
->GetDownloadHistory()
->AddObserver(this);
......@@ -370,6 +371,10 @@ class HistoryObserver : public DownloadHistory::Observer {
service->GetDownloadHistory()->RemoveObserver(this);
}
void set_minimum_received_bytes(int64_t minimum_received_bytes) {
minimum_received_bytes_ = minimum_received_bytes;
}
void SetFilterCallback(const FilterCallback& callback) {
callback_ = callback;
}
......@@ -379,6 +384,11 @@ class HistoryObserver : public DownloadHistory::Observer {
if (!callback_.is_null() && (!callback_.Run(info)))
return;
if (minimum_received_bytes_ != kNoMinimumReceivedBytes &&
info.received_bytes < minimum_received_bytes_) {
return;
}
seen_stored_ = true;
if (waiting_)
base::RunLoop::QuitCurrentWhenIdleDeprecated();
......@@ -399,9 +409,11 @@ class HistoryObserver : public DownloadHistory::Observer {
}
private:
static const int64_t kNoMinimumReceivedBytes = -1;
Profile* profile_;
bool waiting_;
bool seen_stored_;
int64_t minimum_received_bytes_;
FilterCallback callback_;
DISALLOW_COPY_AND_ASSIGN(HistoryObserver);
......@@ -1841,13 +1853,7 @@ ServerRedirectRequestHandler(const net::test_server::HttpRequest& request) {
return std::move(response);
}
#if defined(OS_WIN)
// https://crbug.com/788160
#define MAYBE_DownloadHistoryCheck DISABLED_DownloadHistoryCheck
#else
#define MAYBE_DownloadHistoryCheck DownloadHistoryCheck
#endif
IN_PROC_BROWSER_TEST_F(DownloadTest, MAYBE_DownloadHistoryCheck) {
IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadHistoryCheck) {
// Rediret to the actual download URL.
embedded_test_server()->RegisterRequestHandler(
base::Bind(&ServerRedirectRequestHandler));
......@@ -1882,6 +1888,8 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, MAYBE_DownloadHistoryCheck) {
base::Time start(base::Time::Now());
HistoryObserver observer(browser()->profile());
observer.SetFilterCallback(base::Bind(&HasDataAndName));
observer.set_minimum_received_bytes(
content::SlowDownloadHttpResponse::kFirstDownloadSize);
ui_test_utils::NavigateToURL(browser(), redirect_url);
observer.WaitForStored();
......
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