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