Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6435)

Unified Diff: chrome/browser/prerender/prerender_test_utils.cc

Issue 2434813004: Prerender: remove possible race in browser tests to improve flakiness. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/prerender/prerender_test_utils.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/prerender/prerender_test_utils.cc
diff --git a/chrome/browser/prerender/prerender_test_utils.cc b/chrome/browser/prerender/prerender_test_utils.cc
index e99b3a6aa14f3e10c50dea006b529455ab9c2596..23d1d2a88361b859f39d05666fd46f7d74c27b29 100644
--- a/chrome/browser/prerender/prerender_test_utils.cc
+++ b/chrome/browser/prerender/prerender_test_utils.cc
@@ -357,13 +357,35 @@ void DestructionWaiter::DestructionMarker::OnPrerenderStop(
}
TestPrerender::TestPrerender()
- : contents_(nullptr), number_of_loads_(0), expected_number_of_loads_(0) {}
+ : contents_(nullptr),
+ number_of_loads_(0),
+ expected_number_of_loads_(0),
+ started_(false),
+ stopped_(false) {}
TestPrerender::~TestPrerender() {
if (contents_)
contents_->RemoveObserver(this);
}
+void TestPrerender::WaitForCreate() {
+ if (contents_)
+ return;
+ create_loop_.Run();
+}
+
+void TestPrerender::WaitForStart() {
+ if (started_)
+ return;
+ start_loop_.Run();
+}
+
+void TestPrerender::WaitForStop() {
+ if (stopped_)
+ return;
+ stop_loop_.Run();
+}
+
void TestPrerender::WaitForLoads(int expected_number_of_loads) {
DCHECK(!load_waiter_);
DCHECK(!expected_number_of_loads_);
@@ -385,6 +407,7 @@ void TestPrerender::OnPrerenderCreated(TestPrerenderContents* contents) {
}
void TestPrerender::OnPrerenderStart(PrerenderContents* contents) {
+ started_ = true;
start_loop_.Quit();
}
@@ -397,6 +420,7 @@ void TestPrerender::OnPrerenderStopLoading(PrerenderContents* contents) {
void TestPrerender::OnPrerenderStop(PrerenderContents* contents) {
DCHECK(contents_);
contents_ = nullptr;
+ stopped_ = true;
stop_loop_.Quit();
// If there is a WaitForLoads call and it has yet to see the expected number
// of loads, stop the loop so the test fails instead of timing out.
« no previous file with comments | « chrome/browser/prerender/prerender_test_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698