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

Side by Side Diff: chrome/browser/predictors/resource_prefetch_predictor_test_util.h

Issue 2896713003: Create LoadingDataCollector class and have observers rely on it instead of ResourcePrefetchPredictor (Closed)
Patch Set: Rebase, merge loading_stats_collector. 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
(Empty)
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
3 // found in the LICENSE file.
4 #ifndef CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TEST_UTIL_H_
5 #define CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TEST_UTIL_H_
6
7 #include <set>
8 #include <string>
9 #include <vector>
10
11 #include "chrome/browser/predictors/resource_prefetch_predictor.h"
12 #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h"
13 #include "components/sessions/core/session_id.h"
14 #include "testing/gmock/include/gmock/gmock.h"
15
16 namespace predictors {
17
18 // Does nothing, controls which URLs are prefetchable.
19 class MockResourcePrefetchPredictor : public ResourcePrefetchPredictor {
20 public:
21 MockResourcePrefetchPredictor(const LoadingPredictorConfig& config,
22 Profile* profile);
23 ~MockResourcePrefetchPredictor();
24
25 bool IsUrlPrefetchable(const GURL& main_frame_url) const override {
26 return prefetchable_urls_.find(main_frame_url) != prefetchable_urls_.end();
27 }
28
29 void AddPrefetchableUrl(const GURL& url) { prefetchable_urls_.insert(url); }
30
31 MOCK_CONST_METHOD2(GetPrefetchData,
32 bool(const GURL& main_frame_url, Prediction* prediction));
33 MOCK_METHOD0(StartInitialization, void());
34 MOCK_METHOD0(Shutdown, void());
35 MOCK_METHOD1(StartPrefetching, void(const GURL&));
36 MOCK_METHOD1(StopPrefeching, void(const GURL&));
37
38 private:
39 std::set<GURL> prefetchable_urls_;
40 };
41
42 void InitializeResourceData(ResourceData* resource,
43 const std::string& resource_url,
44 content::ResourceType resource_type,
45 int number_of_hits,
46 int number_of_misses,
47 int consecutive_misses,
48 double average_position,
49 net::RequestPriority priority,
50 bool has_validators,
51 bool always_revalidate);
52
53 void InitializeRedirectStat(RedirectStat* redirect,
54 const std::string& url,
55 int number_of_hits,
56 int number_of_misses,
57 int consecutive_misses);
58
59 void InitializePrecacheResource(precache::PrecacheResource* resource,
60 const std::string& url,
61 double weight_ratio,
62 precache::PrecacheResource::Type type);
63
64 void InitializeOriginStat(OriginStat* origin_stat,
65 const std::string& origin,
66 int number_of_hits,
67 int number_of_misses,
68 int consecutive_misses,
69 double average_position,
70 bool always_access_network,
71 bool accessed_network);
72
73 void InitializeExperiment(precache::PrecacheManifest* manifest,
74 uint32_t experiment_id,
75 const std::vector<bool>& bitset);
76
77 PrefetchData CreatePrefetchData(const std::string& primary_key,
78 uint64_t last_visit_time = 0);
79 RedirectData CreateRedirectData(const std::string& primary_key,
80 uint64_t last_visit_time = 0);
81 precache::PrecacheManifest CreateManifestData(int64_t id = 0);
82 OriginData CreateOriginData(const std::string& host,
83 uint64_t last_visit_time = 0);
84
85 NavigationID CreateNavigationID(SessionID::id_type tab_id,
86 const std::string& main_frame_url);
87
88 ResourcePrefetchPredictor::PageRequestSummary CreatePageRequestSummary(
89 const std::string& main_frame_url,
90 const std::string& initial_url,
91 const std::vector<ResourcePrefetchPredictor::URLRequestSummary>&
92 subresource_requests);
93
94 ResourcePrefetchPredictor::URLRequestSummary CreateURLRequestSummary(
95 SessionID::id_type tab_id,
96 const std::string& main_frame_url,
97 const std::string& resource_url = std::string(),
98 content::ResourceType resource_type = content::RESOURCE_TYPE_MAIN_FRAME,
99 net::RequestPriority priority = net::MEDIUM,
100 const std::string& mime_type = std::string(),
101 bool was_cached = false,
102 const std::string& redirect_url = std::string(),
103 bool has_validators = false,
104 bool always_revalidate = false);
105
106 ResourcePrefetchPredictor::Prediction CreatePrediction(
107 const std::string& main_frame_key,
108 std::vector<GURL> subresource_urls);
109
110 void PopulateTestConfig(LoadingPredictorConfig* config, bool small_db = true);
111
112 // For printing failures nicely.
113 std::ostream& operator<<(std::ostream& stream, const PrefetchData& data);
114 std::ostream& operator<<(std::ostream& stream, const ResourceData& resource);
115 std::ostream& operator<<(std::ostream& stream, const RedirectData& data);
116 std::ostream& operator<<(std::ostream& stream, const RedirectStat& redirect);
117 std::ostream& operator<<(
118 std::ostream& stream,
119 const ResourcePrefetchPredictor::PageRequestSummary& summary);
120 std::ostream& operator<<(
121 std::ostream& stream,
122 const ResourcePrefetchPredictor::URLRequestSummary& summary);
123 std::ostream& operator<<(std::ostream& stream, const NavigationID& id);
124
125 std::ostream& operator<<(std::ostream& os, const OriginData& data);
126 std::ostream& operator<<(std::ostream& os, const OriginStat& redirect);
127
128 bool operator==(const PrefetchData& lhs, const PrefetchData& rhs);
129 bool operator==(const ResourceData& lhs, const ResourceData& rhs);
130 bool operator==(const RedirectData& lhs, const RedirectData& rhs);
131 bool operator==(const RedirectStat& lhs, const RedirectStat& rhs);
132 bool operator==(const ResourcePrefetchPredictor::PageRequestSummary& lhs,
133 const ResourcePrefetchPredictor::PageRequestSummary& rhs);
134 bool operator==(const ResourcePrefetchPredictor::URLRequestSummary& lhs,
135 const ResourcePrefetchPredictor::URLRequestSummary& rhs);
136 bool operator==(const OriginData& lhs, const OriginData& rhs);
137 bool operator==(const OriginStat& lhs, const OriginStat& rhs);
138
139 } // namespace predictors
140
141 namespace precache {
142
143 std::ostream& operator<<(std::ostream& stream,
144 const PrecacheManifest& manifest);
145 std::ostream& operator<<(std::ostream& stream,
146 const PrecacheResource& resource);
147
148 bool operator==(const PrecacheManifest& lhs, const PrecacheManifest& rhs);
149 bool operator==(const PrecacheResource& lhs, const PrecacheResource& rhs);
150
151 } // namespace precache
152
153 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TEST_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698