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

Side by Side Diff: chrome/browser/predictors/loading_data_collector_unittest.cc

Issue 2937623007: predictors: Move more methods from ResourcePrefetchPredictor into LoadingDataCollector. (Closed)
Patch Set: Address alexilin feedback. Created 3 years, 5 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "chrome/browser/predictors/loading_data_collector.h" 5 #include "chrome/browser/predictors/loading_data_collector.h"
6 6
7 #include <iostream> 7 #include <iostream>
8 #include <memory> 8 #include <memory>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "base/test/histogram_tester.h" 12 #include "base/test/histogram_tester.h"
13 #include "chrome/browser/history/history_service_factory.h" 13 #include "chrome/browser/history/history_service_factory.h"
14 #include "chrome/browser/predictors/loading_predictor_config.h"
14 #include "chrome/browser/predictors/loading_test_util.h" 15 #include "chrome/browser/predictors/loading_test_util.h"
15 #include "chrome/test/base/testing_profile.h" 16 #include "chrome/test/base/testing_profile.h"
16 #include "content/public/test/test_browser_thread_bundle.h" 17 #include "content/public/test/test_browser_thread_bundle.h"
17 #include "net/http/http_response_headers.h" 18 #include "net/http/http_response_headers.h"
18 #include "net/url_request/url_request_context.h" 19 #include "net/url_request/url_request_context.h"
19 #include "net/url_request/url_request_job.h" 20 #include "net/url_request/url_request_job.h"
20 #include "testing/gmock/include/gmock/gmock.h" 21 #include "testing/gmock/include/gmock/gmock.h"
21 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
22 23
23 using testing::StrictMock; 24 using testing::StrictMock;
24 25
25 namespace predictors { 26 namespace predictors {
26 27
27 class LoadingDataCollectorTest : public testing::Test { 28 class LoadingDataCollectorTest : public testing::Test {
28 public: 29 public:
30 LoadingDataCollectorTest() : profile_(new TestingProfile()) {
31 LoadingPredictorConfig config;
32 PopulateTestConfig(&config);
33 mock_predictor_ =
34 base::MakeUnique<StrictMock<MockResourcePrefetchPredictor>>(
35 config, profile_.get()),
36 collector_ = base::MakeUnique<LoadingDataCollector>(mock_predictor_.get(),
37 nullptr, config);
38 }
39
29 void SetUp() override { 40 void SetUp() override {
41 base::RunLoop loop;
alexilin 2017/06/30 14:58:49 nit: These two statements could be combined into o
trevordixon 2017/07/11 11:08:08 Done.
42 loop.RunUntilIdle(); // Runs the DB lookup.
43
30 url_request_job_factory_.Reset(); 44 url_request_job_factory_.Reset();
31 url_request_context_.set_job_factory(&url_request_job_factory_); 45 url_request_context_.set_job_factory(&url_request_job_factory_);
32 } 46 }
33 47
34 protected: 48 protected:
35 content::TestBrowserThreadBundle thread_bundle_; 49 content::TestBrowserThreadBundle thread_bundle_;
50 std::unique_ptr<TestingProfile> profile_;
36 net::TestURLRequestContext url_request_context_; 51 net::TestURLRequestContext url_request_context_;
37 MockURLRequestJobFactory url_request_job_factory_; 52 MockURLRequestJobFactory url_request_job_factory_;
53
54 std::unique_ptr<StrictMock<MockResourcePrefetchPredictor>> mock_predictor_;
55 std::unique_ptr<LoadingDataCollector> collector_;
38 }; 56 };
39 57
58 TEST_F(LoadingDataCollectorTest, SummarizeResponse) {
59 net::HttpResponseInfo response_info;
60 response_info.headers =
61 MakeResponseHeaders("HTTP/1.1 200 OK\n\nSome: Headers\n");
62 response_info.was_cached = true;
63 url_request_job_factory_.set_response_info(response_info);
64
65 GURL url("http://www.google.com/cat.png");
66 std::unique_ptr<net::URLRequest> request =
67 CreateURLRequest(url_request_context_, url, net::MEDIUM,
68 content::RESOURCE_TYPE_IMAGE, true);
69 URLRequestSummary summary;
70 EXPECT_TRUE(URLRequestSummary::SummarizeResponse(*request, &summary));
71 EXPECT_EQ(url, summary.resource_url);
72 EXPECT_EQ(content::RESOURCE_TYPE_IMAGE, summary.resource_type);
73 EXPECT_TRUE(summary.was_cached);
74 EXPECT_FALSE(summary.has_validators);
75 EXPECT_FALSE(summary.always_revalidate);
76
77 // Navigation_id elements should be unset by default.
78 EXPECT_EQ(-1, summary.navigation_id.tab_id);
79 EXPECT_EQ(GURL(), summary.navigation_id.main_frame_url);
80 }
81
82 TEST_F(LoadingDataCollectorTest, SummarizeResponseContentType) {
83 net::HttpResponseInfo response_info;
84 response_info.headers = MakeResponseHeaders(
85 "HTTP/1.1 200 OK\n\n"
86 "Some: Headers\n"
87 "Content-Type: image/whatever\n");
88 url_request_job_factory_.set_response_info(response_info);
89 url_request_job_factory_.set_mime_type("image/png");
90
91 std::unique_ptr<net::URLRequest> request = CreateURLRequest(
92 url_request_context_, GURL("http://www.google.com/cat.png"), net::MEDIUM,
93 content::RESOURCE_TYPE_PREFETCH, true);
94 URLRequestSummary summary;
95 EXPECT_TRUE(URLRequestSummary::SummarizeResponse(*request, &summary));
96 EXPECT_EQ(content::RESOURCE_TYPE_IMAGE, summary.resource_type);
97 }
98
99 TEST_F(LoadingDataCollectorTest, SummarizeResponseCachePolicy) {
100 net::HttpResponseInfo response_info;
101 response_info.headers = MakeResponseHeaders(
102 "HTTP/1.1 200 OK\n"
103 "Some: Headers\n");
104 url_request_job_factory_.set_response_info(response_info);
105
106 std::unique_ptr<net::URLRequest> request_no_validators = CreateURLRequest(
107 url_request_context_, GURL("http://www.google.com/cat.png"), net::MEDIUM,
108 content::RESOURCE_TYPE_PREFETCH, true);
109
110 URLRequestSummary summary;
111 EXPECT_TRUE(
112 URLRequestSummary::SummarizeResponse(*request_no_validators, &summary));
113 EXPECT_FALSE(summary.has_validators);
114
115 response_info.headers = MakeResponseHeaders(
116 "HTTP/1.1 200 OK\n"
117 "ETag: \"Cr66\"\n"
118 "Cache-Control: no-cache\n");
119 url_request_job_factory_.set_response_info(response_info);
120 std::unique_ptr<net::URLRequest> request_etag = CreateURLRequest(
121 url_request_context_, GURL("http://www.google.com/cat.png"), net::MEDIUM,
122 content::RESOURCE_TYPE_PREFETCH, true);
123 EXPECT_TRUE(URLRequestSummary::SummarizeResponse(*request_etag, &summary));
124 EXPECT_TRUE(summary.has_validators);
125 EXPECT_TRUE(summary.always_revalidate);
126 }
127
40 TEST_F(LoadingDataCollectorTest, HandledResourceTypes) { 128 TEST_F(LoadingDataCollectorTest, HandledResourceTypes) {
41 EXPECT_TRUE(LoadingDataCollector::IsHandledResourceType( 129 EXPECT_TRUE(LoadingDataCollector::IsHandledResourceType(
42 content::RESOURCE_TYPE_STYLESHEET, "bogus/mime-type")); 130 content::RESOURCE_TYPE_STYLESHEET, "bogus/mime-type"));
43 EXPECT_TRUE(LoadingDataCollector::IsHandledResourceType( 131 EXPECT_TRUE(LoadingDataCollector::IsHandledResourceType(
44 content::RESOURCE_TYPE_STYLESHEET, "")); 132 content::RESOURCE_TYPE_STYLESHEET, ""));
45 EXPECT_FALSE(LoadingDataCollector::IsHandledResourceType( 133 EXPECT_FALSE(LoadingDataCollector::IsHandledResourceType(
46 content::RESOURCE_TYPE_WORKER, "text/css")); 134 content::RESOURCE_TYPE_WORKER, "text/css"));
47 EXPECT_FALSE(LoadingDataCollector::IsHandledResourceType( 135 EXPECT_FALSE(LoadingDataCollector::IsHandledResourceType(
48 content::RESOURCE_TYPE_WORKER, "")); 136 content::RESOURCE_TYPE_WORKER, ""));
49 EXPECT_TRUE(LoadingDataCollector::IsHandledResourceType( 137 EXPECT_TRUE(LoadingDataCollector::IsHandledResourceType(
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 prefetch_unknown_font_request.get())); 308 prefetch_unknown_font_request.get()));
221 309
222 // Not main frame. 310 // Not main frame.
223 std::unique_ptr<net::URLRequest> font_request_sub_frame = CreateURLRequest( 311 std::unique_ptr<net::URLRequest> font_request_sub_frame = CreateURLRequest(
224 url_request_context_, GURL("http://www.google.com/comic-sans-ms.woff"), 312 url_request_context_, GURL("http://www.google.com/comic-sans-ms.woff"),
225 net::MEDIUM, content::RESOURCE_TYPE_FONT_RESOURCE, false); 313 net::MEDIUM, content::RESOURCE_TYPE_FONT_RESOURCE, false);
226 EXPECT_FALSE( 314 EXPECT_FALSE(
227 LoadingDataCollector::ShouldRecordResponse(font_request_sub_frame.get())); 315 LoadingDataCollector::ShouldRecordResponse(font_request_sub_frame.get()));
228 } 316 }
229 317
318 // Single navigation that will be recorded. Will check for duplicate
319 // resources and also for number of resources saved.
320 TEST_F(LoadingDataCollectorTest, SimpleNavigation) {
321 URLRequestSummary main_frame =
322 CreateURLRequestSummary(1, "http://www.google.com");
323 collector_->RecordURLRequest(main_frame);
324 EXPECT_EQ(1U, collector_->inflight_navigations_.size());
325
326 std::vector<URLRequestSummary> resources;
327 resources.push_back(CreateURLRequestSummary(
328 1, "http://www.google.com", "http://google.com/style1.css",
329 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", false));
330 collector_->RecordURLResponse(resources.back());
331 resources.push_back(CreateURLRequestSummary(
332 1, "http://www.google.com", "http://google.com/script1.js",
333 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false));
334 collector_->RecordURLResponse(resources.back());
335 resources.push_back(CreateURLRequestSummary(
336 1, "http://www.google.com", "http://google.com/script2.js",
337 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false));
338 collector_->RecordURLResponse(resources.back());
339 resources.push_back(CreateURLRequestSummary(
340 1, "http://www.google.com", "http://google.com/script1.js",
341 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", true));
342 collector_->RecordURLResponse(resources.back());
343 resources.push_back(CreateURLRequestSummary(
344 1, "http://www.google.com", "http://google.com/image1.png",
345 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false));
346 collector_->RecordURLResponse(resources.back());
347 resources.push_back(CreateURLRequestSummary(
348 1, "http://www.google.com", "http://google.com/image2.png",
349 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false));
350 collector_->RecordURLResponse(resources.back());
351 resources.push_back(CreateURLRequestSummary(
352 1, "http://www.google.com", "http://google.com/style2.css",
353 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true));
354 collector_->RecordURLResponse(resources.back());
355
356 auto no_store = CreateURLRequestSummary(
357 1, "http://www.google.com",
358 "http://static.google.com/style2-no-store.css",
359 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true);
360 no_store.is_no_store = true;
361 collector_->RecordURLResponse(no_store);
362
363 auto redirected = CreateURLRequestSummary(
364 1, "http://www.google.com", "http://reader.google.com/style.css",
365 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true);
366 redirected.redirect_url = GURL("http://dev.null.google.com/style.css");
367 collector_->RecordURLRedirect(redirected);
368
369 auto summary = CreatePageRequestSummary("http://www.google.com",
370 "http://www.google.com", resources);
371 summary.UpdateOrAddToOrigins(no_store);
372 summary.UpdateOrAddToOrigins(redirected);
373
374 redirected.is_no_store = true;
375 redirected.request_url = redirected.redirect_url;
376 redirected.redirect_url = GURL();
377 collector_->RecordURLResponse(redirected);
378 summary.UpdateOrAddToOrigins(redirected);
379
380 EXPECT_CALL(*mock_predictor_,
381 RecordPageRequestSummaryProxy(testing::Pointee(summary)));
382
383 collector_->RecordMainFrameLoadComplete(main_frame.navigation_id);
384 }
385
386 TEST_F(LoadingDataCollectorTest, SimpleRedirect) {
387 URLRequestSummary fb1 = CreateURLRequestSummary(1, "http://fb.com/google");
388 collector_->RecordURLRequest(fb1);
389 EXPECT_EQ(1U, collector_->inflight_navigations_.size());
390
391 URLRequestSummary fb2 = CreateRedirectRequestSummary(
392 1, "http://fb.com/google", "http://facebook.com/google");
393 collector_->RecordURLRedirect(fb2);
394 URLRequestSummary fb3 = CreateRedirectRequestSummary(
395 1, "http://facebook.com/google", "https://facebook.com/google");
396 collector_->RecordURLRedirect(fb3);
397 NavigationID fb_end = CreateNavigationID(1, "https://facebook.com/google");
398
399 EXPECT_CALL(
400 *mock_predictor_,
401 RecordPageRequestSummaryProxy(testing::Pointee(CreatePageRequestSummary(
402 "https://facebook.com/google", "http://fb.com/google",
403 std::vector<URLRequestSummary>()))));
404
405 collector_->RecordMainFrameLoadComplete(fb_end);
406 }
407
408 TEST_F(LoadingDataCollectorTest, OnMainFrameRequest) {
409 URLRequestSummary summary1 = CreateURLRequestSummary(
410 1, "http://www.google.com", "http://www.google.com",
411 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false);
412 URLRequestSummary summary2 = CreateURLRequestSummary(
413 2, "http://www.google.com", "http://www.google.com",
414 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false);
415 URLRequestSummary summary3 = CreateURLRequestSummary(
416 3, "http://www.yahoo.com", "http://www.yahoo.com",
417 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false);
418
419 collector_->RecordURLRequest(summary1);
420 EXPECT_EQ(1U, collector_->inflight_navigations_.size());
421 collector_->RecordURLRequest(summary2);
422 EXPECT_EQ(2U, collector_->inflight_navigations_.size());
423 collector_->RecordURLRequest(summary3);
424 EXPECT_EQ(3U, collector_->inflight_navigations_.size());
425
426 // Insert another with same navigation id. It should replace.
427 URLRequestSummary summary4 = CreateURLRequestSummary(
428 1, "http://www.nike.com", "http://www.nike.com",
429 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false);
430 URLRequestSummary summary5 = CreateURLRequestSummary(
431 2, "http://www.google.com", "http://www.google.com",
432 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false);
433
434 collector_->RecordURLRequest(summary4);
435 EXPECT_EQ(3U, collector_->inflight_navigations_.size());
436
437 // Change this creation time so that it will go away on the next insert.
438 summary5.navigation_id.creation_time =
439 base::TimeTicks::Now() - base::TimeDelta::FromDays(1);
440 collector_->RecordURLRequest(summary5);
441 EXPECT_EQ(3U, collector_->inflight_navigations_.size());
442
443 URLRequestSummary summary6 = CreateURLRequestSummary(
444 4, "http://www.shoes.com", "http://www.shoes.com",
445 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false);
446 collector_->RecordURLRequest(summary6);
447 EXPECT_EQ(3U, collector_->inflight_navigations_.size());
448
449 EXPECT_TRUE(collector_->inflight_navigations_.find(summary3.navigation_id) !=
450 collector_->inflight_navigations_.end());
451 EXPECT_TRUE(collector_->inflight_navigations_.find(summary4.navigation_id) !=
452 collector_->inflight_navigations_.end());
453 EXPECT_TRUE(collector_->inflight_navigations_.find(summary6.navigation_id) !=
454 collector_->inflight_navigations_.end());
455 }
456
457 TEST_F(LoadingDataCollectorTest, OnMainFrameRedirect) {
458 URLRequestSummary yahoo = CreateURLRequestSummary(1, "http://yahoo.com");
459
460 URLRequestSummary bbc1 = CreateURLRequestSummary(2, "http://bbc.com");
461 URLRequestSummary bbc2 =
462 CreateRedirectRequestSummary(2, "http://bbc.com", "https://www.bbc.com");
463 NavigationID bbc_end = CreateNavigationID(2, "https://www.bbc.com");
464
465 URLRequestSummary youtube1 = CreateURLRequestSummary(3, "http://youtube.com");
466 URLRequestSummary youtube2 = CreateRedirectRequestSummary(
467 3, "http://youtube.com", "https://youtube.com");
468 NavigationID youtube_end = CreateNavigationID(3, "https://youtube.com");
469
470 URLRequestSummary nyt1 = CreateURLRequestSummary(4, "http://nyt.com");
471 URLRequestSummary nyt2 =
472 CreateRedirectRequestSummary(4, "http://nyt.com", "http://nytimes.com");
473 URLRequestSummary nyt3 = CreateRedirectRequestSummary(4, "http://nytimes.com",
474 "http://m.nytimes.com");
475 NavigationID nyt_end = CreateNavigationID(4, "http://m.nytimes.com");
476
477 URLRequestSummary fb1 = CreateURLRequestSummary(5, "http://fb.com");
478 URLRequestSummary fb2 =
479 CreateRedirectRequestSummary(5, "http://fb.com", "http://facebook.com");
480 URLRequestSummary fb3 = CreateRedirectRequestSummary(5, "http://facebook.com",
481 "https://facebook.com");
482 URLRequestSummary fb4 = CreateRedirectRequestSummary(
483 5, "https://facebook.com",
484 "https://m.facebook.com/?refsrc=https%3A%2F%2Fwww.facebook.com%2F&_rdr");
485 NavigationID fb_end = CreateNavigationID(
486 5,
487 "https://m.facebook.com/?refsrc=https%3A%2F%2Fwww.facebook.com%2F&_rdr");
488
489 // Redirect with empty redirect_url will be deleted.
490 collector_->RecordURLRequest(yahoo);
491 EXPECT_EQ(1U, collector_->inflight_navigations_.size());
492 collector_->OnMainFrameRedirect(yahoo);
493 EXPECT_TRUE(collector_->inflight_navigations_.empty());
494
495 // Redirect without previous request works fine.
496 // collector_->RecordURLRequest(bbc1) missing.
497 collector_->OnMainFrameRedirect(bbc2);
498 EXPECT_EQ(1U, collector_->inflight_navigations_.size());
499 EXPECT_EQ(bbc1.navigation_id.main_frame_url,
500 collector_->inflight_navigations_[bbc_end]->initial_url);
501
502 // http://youtube.com -> https://youtube.com.
503 collector_->RecordURLRequest(youtube1);
504 EXPECT_EQ(2U, collector_->inflight_navigations_.size());
505 collector_->OnMainFrameRedirect(youtube2);
506 EXPECT_EQ(2U, collector_->inflight_navigations_.size());
507 EXPECT_EQ(youtube1.navigation_id.main_frame_url,
508 collector_->inflight_navigations_[youtube_end]->initial_url);
509
510 // http://nyt.com -> http://nytimes.com -> http://m.nytimes.com.
511 collector_->RecordURLRequest(nyt1);
512 EXPECT_EQ(3U, collector_->inflight_navigations_.size());
513 collector_->OnMainFrameRedirect(nyt2);
514 collector_->OnMainFrameRedirect(nyt3);
515 EXPECT_EQ(3U, collector_->inflight_navigations_.size());
516 EXPECT_EQ(nyt1.navigation_id.main_frame_url,
517 collector_->inflight_navigations_[nyt_end]->initial_url);
518
519 // http://fb.com -> http://facebook.com -> https://facebook.com ->
520 // https://m.facebook.com/?refsrc=https%3A%2F%2Fwww.facebook.com%2F&_rdr.
521 collector_->RecordURLRequest(fb1);
522 EXPECT_EQ(4U, collector_->inflight_navigations_.size());
523 collector_->OnMainFrameRedirect(fb2);
524 collector_->OnMainFrameRedirect(fb3);
525 collector_->OnMainFrameRedirect(fb4);
526 EXPECT_EQ(4U, collector_->inflight_navigations_.size());
527 EXPECT_EQ(fb1.navigation_id.main_frame_url,
528 collector_->inflight_navigations_[fb_end]->initial_url);
529 }
530
531 TEST_F(LoadingDataCollectorTest, OnSubresourceResponse) {
532 // If there is no inflight navigation, nothing happens.
533 URLRequestSummary resource1 = CreateURLRequestSummary(
534 1, "http://www.google.com", "http://google.com/style1.css",
535 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", false);
536 collector_->RecordURLResponse(resource1);
537 EXPECT_TRUE(collector_->inflight_navigations_.empty());
538
539 // Add an inflight navigation.
540 URLRequestSummary main_frame1 = CreateURLRequestSummary(
541 1, "http://www.google.com", "http://www.google.com",
542 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false);
543 collector_->RecordURLRequest(main_frame1);
544 EXPECT_EQ(1U, collector_->inflight_navigations_.size());
545
546 // Now add a few subresources.
547 URLRequestSummary resource2 = CreateURLRequestSummary(
548 1, "http://www.google.com", "http://google.com/script1.js",
549 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false);
550 URLRequestSummary resource3 = CreateURLRequestSummary(
551 1, "http://www.google.com", "http://google.com/script2.js",
552 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false);
553 collector_->RecordURLResponse(resource1);
554 collector_->RecordURLResponse(resource2);
555 collector_->RecordURLResponse(resource3);
556
557 EXPECT_EQ(1U, collector_->inflight_navigations_.size());
558 EXPECT_EQ(3U, collector_->inflight_navigations_[main_frame1.navigation_id]
559 ->subresource_requests.size());
560 EXPECT_EQ(resource1,
561 collector_->inflight_navigations_[main_frame1.navigation_id]
562 ->subresource_requests[0]);
563 EXPECT_EQ(resource2,
564 collector_->inflight_navigations_[main_frame1.navigation_id]
565 ->subresource_requests[1]);
566 EXPECT_EQ(resource3,
567 collector_->inflight_navigations_[main_frame1.navigation_id]
568 ->subresource_requests[2]);
569 }
570
571 TEST_F(LoadingDataCollectorTest, TestRecordFirstContentfulPaint) {
572 auto res1_time = base::TimeTicks::FromInternalValue(1);
573 auto res2_time = base::TimeTicks::FromInternalValue(2);
574 auto fcp_time = base::TimeTicks::FromInternalValue(3);
575 auto res3_time = base::TimeTicks::FromInternalValue(4);
576
577 URLRequestSummary main_frame =
578 CreateURLRequestSummary(1, "http://www.google.com");
579 collector_->RecordURLRequest(main_frame);
580 EXPECT_EQ(1U, collector_->inflight_navigations_.size());
581
582 URLRequestSummary resource1 = CreateURLRequestSummary(
583 1, "http://www.google.com", "http://google.com/style1.css",
584 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", false);
585 resource1.response_time = res1_time;
586 collector_->RecordURLResponse(resource1);
587 URLRequestSummary resource2 = CreateURLRequestSummary(
588 1, "http://www.google.com", "http://google.com/script1.js",
589 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false);
590 resource2.response_time = res2_time;
591 collector_->RecordURLResponse(resource2);
592 URLRequestSummary resource3 = CreateURLRequestSummary(
593 1, "http://www.google.com", "http://google.com/script2.js",
594 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false);
595 resource3.response_time = res3_time;
596 collector_->RecordURLResponse(resource3);
597
598 collector_->RecordFirstContentfulPaint(main_frame.navigation_id, fcp_time);
599
600 // Since res3_time is after fcp_time, we expect this field to have been set to
601 // false before RecordPageRequestSummary is called.
602 resource3.before_first_contentful_paint = false;
603 EXPECT_CALL(
604 *mock_predictor_,
605 RecordPageRequestSummaryProxy(testing::Pointee(CreatePageRequestSummary(
606 "http://www.google.com", "http://www.google.com",
607 {resource1, resource2, resource3}))));
608
609 collector_->RecordMainFrameLoadComplete(main_frame.navigation_id);
610 }
611
230 } // namespace predictors 612 } // namespace predictors
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698