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

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

Issue 2423383002: [Prerender] first contentful paint histograms. (Closed)
Patch Set: comments Created 4 years 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
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 <deque> 8 #include <deque>
9 #include <functional> 9 #include <functional>
10 #include <memory> 10 #include <memory>
11 #include <set> 11 #include <set>
12 #include <string> 12 #include <string>
13 #include <unordered_map> 13 #include <unordered_map>
14 #include <vector> 14 #include <vector>
15 15
16 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
17 #include "base/run_loop.h" 17 #include "base/run_loop.h"
18 #include "base/test/histogram_tester.h" 18 #include "base/test/histogram_tester.h"
19 #include "chrome/browser/external_protocol/external_protocol_handler.h" 19 #include "chrome/browser/external_protocol/external_protocol_handler.h"
20 #include "chrome/browser/page_load_metrics/observers/prerender_page_load_metrics _observer.h"
20 #include "chrome/browser/prerender/prerender_contents.h" 21 #include "chrome/browser/prerender/prerender_contents.h"
21 #include "chrome/browser/prerender/prerender_manager.h" 22 #include "chrome/browser/prerender/prerender_manager.h"
22 #include "chrome/browser/safe_browsing/test_safe_browsing_service.h" 23 #include "chrome/browser/safe_browsing/test_safe_browsing_service.h"
23 #include "chrome/test/base/in_process_browser_test.h" 24 #include "chrome/test/base/in_process_browser_test.h"
24 #include "components/safe_browsing_db/test_database_manager.h" 25 #include "components/safe_browsing_db/test_database_manager.h"
25 #include "content/public/browser/browser_thread.h" 26 #include "content/public/browser/browser_thread.h"
26 #include "net/test/url_request/url_request_mock_http_job.h" 27 #include "net/test/url_request/url_request_mock_http_job.h"
27 #include "net/url_request/url_request_interceptor.h" 28 #include "net/url_request/url_request_interceptor.h"
28 #include "url/gurl.h" 29 #include "url/gurl.h"
29 30
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 void MarkDestruction(FinalStatus reason); 231 void MarkDestruction(FinalStatus reason);
231 232
232 base::RunLoop wait_loop_; 233 base::RunLoop wait_loop_;
233 FinalStatus expected_final_status_; 234 FinalStatus expected_final_status_;
234 bool saw_correct_status_; 235 bool saw_correct_status_;
235 std::unique_ptr<DestructionMarker> marker_; 236 std::unique_ptr<DestructionMarker> marker_;
236 237
237 DISALLOW_COPY_AND_ASSIGN(DestructionWaiter); 238 DISALLOW_COPY_AND_ASSIGN(DestructionWaiter);
238 }; 239 };
239 240
241 // Wait until a PrerenderManager has seen a first contentful paint.
242 class FirstContentfulPaintManagerWaiter : public PrerenderManagerObserver {
243 public:
244 // Create and return a pointer to a |FirstContentfulPaintManagerWaiter|. The
245 // instance is owned by the |PrerenderManager|.
246 static FirstContentfulPaintManagerWaiter* Create(PrerenderManager* manager);
247
248 ~FirstContentfulPaintManagerWaiter() override;
249
250 void OnFirstContentfulPaint() override;
251
252 // Wait for a first contentful paint to be seen by our PrerenderManager.
253 void Wait();
254
255 private:
256 FirstContentfulPaintManagerWaiter();
257
258 std::unique_ptr<base::RunLoop> waiter_;
259 bool saw_fcp_;
260 };
pasko 2016/12/20 19:33:34 nit: DISALLOW_COPY_AND_ASSIGN?
mattcary 2016/12/21 17:08:58 Done.
261
240 // PrerenderContentsFactory that uses TestPrerenderContents. 262 // PrerenderContentsFactory that uses TestPrerenderContents.
241 class TestPrerenderContentsFactory : public PrerenderContents::Factory { 263 class TestPrerenderContentsFactory : public PrerenderContents::Factory {
242 public: 264 public:
243 TestPrerenderContentsFactory(); 265 TestPrerenderContentsFactory();
244 266
245 ~TestPrerenderContentsFactory() override; 267 ~TestPrerenderContentsFactory() override;
246 268
247 std::unique_ptr<TestPrerender> ExpectPrerenderContents( 269 std::unique_ptr<TestPrerender> ExpectPrerenderContents(
248 FinalStatus final_status); 270 FinalStatus final_status);
249 271
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 safe_browsing_factory_; 378 safe_browsing_factory_;
357 TestPrerenderContentsFactory* prerender_contents_factory_; 379 TestPrerenderContentsFactory* prerender_contents_factory_;
358 Browser* explicitly_set_browser_; 380 Browser* explicitly_set_browser_;
359 bool autostart_test_server_; 381 bool autostart_test_server_;
360 base::HistogramTester histogram_tester_; 382 base::HistogramTester histogram_tester_;
361 std::unique_ptr<net::EmbeddedTestServer> https_src_server_; 383 std::unique_ptr<net::EmbeddedTestServer> https_src_server_;
362 384
363 DISALLOW_COPY_AND_ASSIGN(PrerenderInProcessBrowserTest); 385 DISALLOW_COPY_AND_ASSIGN(PrerenderInProcessBrowserTest);
364 }; 386 };
365 387
388 // A test observer that allows the observed navigation start time to be set.
389 class TestPrerenderPageLoadMetricsObserver
390 : public PrerenderPageLoadMetricsObserver {
391 public:
392 using PrerenderPageLoadMetricsObserver::PrerenderPageLoadMetricsObserver;
pasko 2016/12/20 19:33:34 thanks for letting me know about inherited constru
mattcary 2016/12/21 17:08:58 Ack I think it was actually from digit@ and notes
393
394 void SetNavigationStartTo(base::TimeTicks ticks) {
395 SetNavigationStartTicksForTesting(ticks);
pasko 2016/12/20 19:33:34 The only thing this class does is forwarding to th
mattcary 2016/12/21 17:08:59 It seems to be common to hide testing code with pr
pasko 2016/12/21 18:39:09 Ah, now I see where it is coming from. I think it
mattcary 2016/12/22 10:49:07 Acknowledged.
396 }
397 };
pasko 2016/12/20 19:33:34 nit: DISALLOW_COPY_AND_ASSIGN?
mattcary 2016/12/21 17:08:59 Done.
398
366 // Makes |url| respond to requests with the contents of |file|, counting the 399 // Makes |url| respond to requests with the contents of |file|, counting the
367 // number that start in |counter|. 400 // number that start in |counter|.
368 void CreateCountingInterceptorOnIO( 401 void CreateCountingInterceptorOnIO(
369 const GURL& url, 402 const GURL& url,
370 const base::FilePath& file, 403 const base::FilePath& file,
371 const base::WeakPtr<RequestCounter>& counter); 404 const base::WeakPtr<RequestCounter>& counter);
372 405
373 // When the |url| hits the net::URLRequestFilter (on the IO thread), executes 406 // When the |url| hits the net::URLRequestFilter (on the IO thread), executes
374 // the |callback_io| providing the request to it, also pings the |counter| on UI 407 // the |callback_io| providing the request to it, also pings the |counter| on UI
375 // thread. Does not modify the behavior or the request job. 408 // thread. Does not modify the behavior or the request job.
376 void InterceptRequestAndCount( 409 void InterceptRequestAndCount(
377 const GURL& url, 410 const GURL& url,
378 RequestCounter* counter, 411 RequestCounter* counter,
379 base::Callback<void(net::URLRequest*)> callback_io); 412 base::Callback<void(net::URLRequest*)> callback_io);
380 413
381 // Makes |url| respond to requests with the contents of |file|. 414 // Makes |url| respond to requests with the contents of |file|.
382 void CreateMockInterceptorOnIO(const GURL& url, const base::FilePath& file); 415 void CreateMockInterceptorOnIO(const GURL& url, const base::FilePath& file);
383 416
384 // Makes |url| never respond on the first load, and then with the contents of 417 // Makes |url| never respond on the first load, and then with the contents of
385 // |file| afterwards. When the first load has been scheduled, runs |callback| on 418 // |file| afterwards. When the first load has been scheduled, runs |callback| on
386 // the UI thread. 419 // the UI thread.
387 void CreateHangingFirstRequestInterceptorOnIO( 420 void CreateHangingFirstRequestInterceptorOnIO(
388 const GURL& url, const base::FilePath& file, base::Closure callback); 421 const GURL& url, const base::FilePath& file, base::Closure callback);
389 422
390 } // namespace test_utils 423 } // namespace test_utils
391 424
392 } // namespace prerender 425 } // namespace prerender
393 426
394 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_TEST_UTILS_H_ 427 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_TEST_UTILS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698