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

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

Issue 2937623007: predictors: Move more methods from ResourcePrefetchPredictor into LoadingDataCollector. (Closed)
Patch Set: Tests migrated into LoadingDataCollectorTest Created 3 years, 6 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 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 #include "chrome/browser/predictors/loading_test_util.h" 5 #include "chrome/browser/predictors/loading_test_util.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <memory> 8 #include <memory>
9 #include <utility>
9 10
10 #include "content/public/browser/resource_request_info.h" 11 #include "content/public/browser/resource_request_info.h"
11 #include "net/http/http_response_headers.h" 12 #include "net/http/http_response_headers.h"
12 #include "net/url_request/url_request_test_util.h" 13 #include "net/url_request/url_request_test_util.h"
13 14
14 namespace { 15 namespace {
15 16
16 class EmptyURLRequestDelegate : public net::URLRequest::Delegate { 17 class EmptyURLRequestDelegate : public net::URLRequest::Delegate {
17 void OnResponseStarted(net::URLRequest* request, int net_error) override {} 18 void OnResponseStarted(net::URLRequest* request, int net_error) override {}
18 void OnReadCompleted(net::URLRequest* request, int bytes_read) override {} 19 void OnReadCompleted(net::URLRequest* request, int bytes_read) override {}
19 }; 20 };
20 21
21 EmptyURLRequestDelegate g_empty_url_request_delegate; 22 EmptyURLRequestDelegate g_empty_url_request_delegate;
22 23
23 bool AlmostEqual(const double x, const double y) { 24 bool AlmostEqual(const double x, const double y) {
24 return std::fabs(x - y) <= 1e-6; // Arbitrary but close enough. 25 return std::fabs(x - y) <= 1e-6; // Arbitrary but close enough.
25 } 26 }
26 27
27 } // namespace 28 } // namespace
28 29
29 namespace predictors { 30 namespace predictors {
30 31
31 using URLRequestSummary = ResourcePrefetchPredictor::URLRequestSummary;
32 using PageRequestSummary = ResourcePrefetchPredictor::PageRequestSummary;
33 using Prediction = ResourcePrefetchPredictor::Prediction; 32 using Prediction = ResourcePrefetchPredictor::Prediction;
34 33
35 MockResourcePrefetchPredictor::MockResourcePrefetchPredictor( 34 MockResourcePrefetchPredictor::MockResourcePrefetchPredictor(
36 const LoadingPredictorConfig& config, 35 const LoadingPredictorConfig& config,
37 Profile* profile) 36 Profile* profile)
38 : ResourcePrefetchPredictor(config, profile) {} 37 : ResourcePrefetchPredictor(config, profile) {}
39 38
40 MockResourcePrefetchPredictor::~MockResourcePrefetchPredictor() = default; 39 MockResourcePrefetchPredictor::~MockResourcePrefetchPredictor() = default;
41 40
41 MockResourcePrefetchPredictorTables::MockResourcePrefetchPredictorTables() =
42 default;
43
44 void MockResourcePrefetchPredictorTables::ScheduleDBTask(
45 const tracked_objects::Location& from_here,
46 DBTask task) {
47 ExecuteDBTaskOnDBThread(std::move(task));
48 }
49
50 void MockResourcePrefetchPredictorTables::ExecuteDBTaskOnDBThread(DBTask task) {
51 std::move(task).Run(nullptr);
52 }
53
54 GlowplugKeyValueTable<PrefetchData>*
55 MockResourcePrefetchPredictorTables::url_resource_table() {
56 return &url_resource_table_;
57 }
58
59 GlowplugKeyValueTable<RedirectData>*
60 MockResourcePrefetchPredictorTables::url_redirect_table() {
61 return &url_redirect_table_;
62 }
63
64 GlowplugKeyValueTable<PrefetchData>*
65 MockResourcePrefetchPredictorTables::host_resource_table() {
66 return &host_resource_table_;
67 }
68
69 GlowplugKeyValueTable<RedirectData>*
70 MockResourcePrefetchPredictorTables::host_redirect_table() {
71 return &host_redirect_table_;
72 }
73
74 GlowplugKeyValueTable<precache::PrecacheManifest>*
75 MockResourcePrefetchPredictorTables::manifest_table() {
76 return &manifest_table_;
77 }
78
79 GlowplugKeyValueTable<OriginData>*
80 MockResourcePrefetchPredictorTables::origin_table() {
81 return &origin_table_;
82 }
83
84 MockResourcePrefetchPredictorTables::~MockResourcePrefetchPredictorTables() =
85 default;
86
87 MockResourcePrefetchPredictorObserver::MockResourcePrefetchPredictorObserver(
88 ResourcePrefetchPredictor* predictor)
89 : TestObserver(predictor) {}
90
91 MockResourcePrefetchPredictorObserver::
92 ~MockResourcePrefetchPredictorObserver() {}
93
42 void InitializeResourceData(ResourceData* resource, 94 void InitializeResourceData(ResourceData* resource,
43 const std::string& resource_url, 95 const std::string& resource_url,
44 content::ResourceType resource_type, 96 content::ResourceType resource_type,
45 int number_of_hits, 97 int number_of_hits,
46 int number_of_misses, 98 int number_of_misses,
47 int consecutive_misses, 99 int consecutive_misses,
48 double average_position, 100 double average_position,
49 net::RequestPriority priority, 101 net::RequestPriority priority,
50 bool has_validators, 102 bool has_validators,
51 bool always_revalidate) { 103 bool always_revalidate) {
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 540
489 return equal; 541 return equal;
490 } 542 }
491 543
492 bool operator==(const PrecacheResource& lhs, const PrecacheResource& rhs) { 544 bool operator==(const PrecacheResource& lhs, const PrecacheResource& rhs) {
493 return lhs.url() == rhs.url() && 545 return lhs.url() == rhs.url() &&
494 AlmostEqual(lhs.weight_ratio(), rhs.weight_ratio()); 546 AlmostEqual(lhs.weight_ratio(), rhs.weight_ratio());
495 } 547 }
496 548
497 } // namespace precache 549 } // namespace precache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698