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

Side by Side Diff: chrome/browser/prerender/prerender_test_utils.h

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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/prerender/prerender_test_utils.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_PRERENDER_PRERENDER_TEST_UTILS_H_ 5 #ifndef CHROME_BROWSER_PRERENDER_PRERENDER_TEST_UTILS_H_
6 #define CHROME_BROWSER_PRERENDER_PRERENDER_TEST_UTILS_H_ 6 #define CHROME_BROWSER_PRERENDER_PRERENDER_TEST_UTILS_H_
7 7
8 #include <functional> 8 #include <functional>
9 9
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 // tracking the final status, etc. 146 // tracking the final status, etc.
147 class TestPrerender : public PrerenderContents::Observer, 147 class TestPrerender : public PrerenderContents::Observer,
148 public base::SupportsWeakPtr<TestPrerender> { 148 public base::SupportsWeakPtr<TestPrerender> {
149 public: 149 public:
150 TestPrerender(); 150 TestPrerender();
151 ~TestPrerender() override; 151 ~TestPrerender() override;
152 152
153 TestPrerenderContents* contents() const { return contents_; } 153 TestPrerenderContents* contents() const { return contents_; }
154 int number_of_loads() const { return number_of_loads_; } 154 int number_of_loads() const { return number_of_loads_; }
155 155
156 void WaitForCreate() { create_loop_.Run(); } 156 void WaitForCreate();
157 void WaitForStart() { start_loop_.Run(); } 157 void WaitForStart();
158 void WaitForStop() { stop_loop_.Run(); } 158 void WaitForStop();
159 159
160 // Waits for |number_of_loads()| to be at least |expected_number_of_loads| OR 160 // Waits for |number_of_loads()| to be at least |expected_number_of_loads| OR
161 // for the prerender to stop running (just to avoid a timeout if the prerender 161 // for the prerender to stop running (just to avoid a timeout if the prerender
162 // dies). Note: this does not assert equality on the number of loads; the 162 // dies). Note: this does not assert equality on the number of loads; the
163 // caller must do it instead. 163 // caller must do it instead.
164 void WaitForLoads(int expected_number_of_loads); 164 void WaitForLoads(int expected_number_of_loads);
165 165
166 void OnPrerenderCreated(TestPrerenderContents* contents); 166 void OnPrerenderCreated(TestPrerenderContents* contents);
167 167
168 // PrerenderContents::Observer implementation: 168 // PrerenderContents::Observer implementation:
169 void OnPrerenderStart(PrerenderContents* contents) override; 169 void OnPrerenderStart(PrerenderContents* contents) override;
170 170
171 void OnPrerenderStopLoading(PrerenderContents* contents) override; 171 void OnPrerenderStopLoading(PrerenderContents* contents) override;
172 172
173 void OnPrerenderStop(PrerenderContents* contents) override; 173 void OnPrerenderStop(PrerenderContents* contents) override;
174 174
175 private: 175 private:
176 TestPrerenderContents* contents_; 176 TestPrerenderContents* contents_;
177 int number_of_loads_; 177 int number_of_loads_;
178 178
179 int expected_number_of_loads_; 179 int expected_number_of_loads_;
180 std::unique_ptr<base::RunLoop> load_waiter_; 180 std::unique_ptr<base::RunLoop> load_waiter_;
181 181
182 bool started_;
183 bool stopped_;
184
182 base::RunLoop create_loop_; 185 base::RunLoop create_loop_;
183 base::RunLoop start_loop_; 186 base::RunLoop start_loop_;
184 base::RunLoop stop_loop_; 187 base::RunLoop stop_loop_;
185 188
186 DISALLOW_COPY_AND_ASSIGN(TestPrerender); 189 DISALLOW_COPY_AND_ASSIGN(TestPrerender);
187 }; 190 };
188 191
189 // Blocks until a TestPrerenderContents has been destroyed with the given final 192 // Blocks until a TestPrerenderContents has been destroyed with the given final
190 // status. Should be created with a TestPrerenderContents, and then 193 // status. Should be created with a TestPrerenderContents, and then
191 // WaitForDestroy should be called and its return value checked. 194 // WaitForDestroy should be called and its return value checked.
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 const base::WeakPtr<RequestCounter>& counter); 377 const base::WeakPtr<RequestCounter>& counter);
375 378
376 // Makes |url| respond to requests with the contents of |file|. 379 // Makes |url| respond to requests with the contents of |file|.
377 void CreateMockInterceptorOnIO(const GURL& url, const base::FilePath& file); 380 void CreateMockInterceptorOnIO(const GURL& url, const base::FilePath& file);
378 381
379 } // namespace test_utils 382 } // namespace test_utils
380 383
381 } // namespace prerender 384 } // namespace prerender
382 385
383 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_TEST_UTILS_H_ 386 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_TEST_UTILS_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/prerender/prerender_test_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698