| OLD | NEW |
| 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 #ifndef CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TEST_UTIL_H_ | 4 #ifndef CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TEST_UTIL_H_ |
| 5 #define CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TEST_UTIL_H_ | 5 #define CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TEST_UTIL_H_ |
| 6 | 6 |
| 7 #include <set> | |
| 8 #include <string> | 7 #include <string> |
| 9 #include <vector> | 8 #include <vector> |
| 10 | 9 |
| 11 #include "chrome/browser/predictors/resource_prefetch_predictor.h" | 10 #include "chrome/browser/predictors/resource_prefetch_predictor.h" |
| 12 #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h" | 11 #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h" |
| 13 #include "components/sessions/core/session_id.h" | 12 #include "components/sessions/core/session_id.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
| 15 | 14 |
| 16 namespace predictors { | 15 namespace predictors { |
| 17 | 16 |
| 18 // Does nothing, controls which URLs are prefetchable. | 17 // Does nothing, controls which URLs are prefetchable. |
| 19 class MockResourcePrefetchPredictor : public ResourcePrefetchPredictor { | 18 class MockResourcePrefetchPredictor : public ResourcePrefetchPredictor { |
| 20 public: | 19 public: |
| 21 MockResourcePrefetchPredictor(const LoadingPredictorConfig& config, | 20 MockResourcePrefetchPredictor(const LoadingPredictorConfig& config, |
| 22 Profile* profile); | 21 Profile* profile); |
| 23 ~MockResourcePrefetchPredictor(); | 22 ~MockResourcePrefetchPredictor(); |
| 24 | 23 |
| 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, | 24 MOCK_CONST_METHOD2(GetPrefetchData, |
| 32 bool(const GURL& main_frame_url, Prediction* prediction)); | 25 bool(const GURL&, ResourcePrefetchPredictor::Prediction*)); |
| 33 MOCK_METHOD0(StartInitialization, void()); | 26 MOCK_METHOD0(StartInitialization, void()); |
| 34 MOCK_METHOD0(Shutdown, void()); | 27 MOCK_METHOD0(Shutdown, void()); |
| 35 MOCK_METHOD1(StartPrefetching, void(const GURL&)); | 28 MOCK_METHOD2(StartPrefetching, |
| 29 void(const GURL&, const ResourcePrefetchPredictor::Prediction&)); |
| 36 MOCK_METHOD1(StopPrefeching, void(const GURL&)); | 30 MOCK_METHOD1(StopPrefeching, void(const GURL&)); |
| 37 | |
| 38 private: | |
| 39 std::set<GURL> prefetchable_urls_; | |
| 40 }; | 31 }; |
| 41 | 32 |
| 42 void InitializeResourceData(ResourceData* resource, | 33 void InitializeResourceData(ResourceData* resource, |
| 43 const std::string& resource_url, | 34 const std::string& resource_url, |
| 44 content::ResourceType resource_type, | 35 content::ResourceType resource_type, |
| 45 int number_of_hits, | 36 int number_of_hits, |
| 46 int number_of_misses, | 37 int number_of_misses, |
| 47 int consecutive_misses, | 38 int consecutive_misses, |
| 48 double average_position, | 39 double average_position, |
| 49 net::RequestPriority priority, | 40 net::RequestPriority priority, |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 const PrecacheManifest& manifest); | 135 const PrecacheManifest& manifest); |
| 145 std::ostream& operator<<(std::ostream& stream, | 136 std::ostream& operator<<(std::ostream& stream, |
| 146 const PrecacheResource& resource); | 137 const PrecacheResource& resource); |
| 147 | 138 |
| 148 bool operator==(const PrecacheManifest& lhs, const PrecacheManifest& rhs); | 139 bool operator==(const PrecacheManifest& lhs, const PrecacheManifest& rhs); |
| 149 bool operator==(const PrecacheResource& lhs, const PrecacheResource& rhs); | 140 bool operator==(const PrecacheResource& lhs, const PrecacheResource& rhs); |
| 150 | 141 |
| 151 } // namespace precache | 142 } // namespace precache |
| 152 | 143 |
| 153 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TEST_UTIL_H_ | 144 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TEST_UTIL_H_ |
| OLD | NEW |