| Index: chrome/browser/predictors/resource_prefetch_predictor_unittest.cc
|
| diff --git a/chrome/browser/predictors/resource_prefetch_predictor_unittest.cc b/chrome/browser/predictors/resource_prefetch_predictor_unittest.cc
|
| index e67236a7527507f5f54f1ade746eb8fcf6d51c46..10123b30f0a516653d41915e9abec7da13d1f203 100644
|
| --- a/chrome/browser/predictors/resource_prefetch_predictor_unittest.cc
|
| +++ b/chrome/browser/predictors/resource_prefetch_predictor_unittest.cc
|
| @@ -15,8 +15,8 @@
|
| #include "base/time/time.h"
|
| #include "chrome/browser/history/history_service_factory.h"
|
| #include "chrome/browser/predictors/loading_predictor.h"
|
| +#include "chrome/browser/predictors/loading_test_util.h"
|
| #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h"
|
| -#include "chrome/browser/predictors/resource_prefetch_predictor_test_util.h"
|
| #include "chrome/browser/predictors/resource_prefetcher_manager.h"
|
| #include "chrome/test/base/testing_profile.h"
|
| #include "components/history/core/browser/history_service.h"
|
| @@ -47,86 +47,6 @@ using RedirectDataMap = std::map<std::string, RedirectData>;
|
| using OriginDataMap = std::map<std::string, OriginData>;
|
| using ManifestDataMap = std::map<std::string, precache::PrecacheManifest>;
|
|
|
| -scoped_refptr<net::HttpResponseHeaders> MakeResponseHeaders(
|
| - const char* headers) {
|
| - return make_scoped_refptr(new net::HttpResponseHeaders(
|
| - net::HttpUtil::AssembleRawHeaders(headers, strlen(headers))));
|
| -}
|
| -
|
| -class EmptyURLRequestDelegate : public net::URLRequest::Delegate {
|
| - void OnResponseStarted(net::URLRequest* request, int net_error) override {}
|
| - void OnReadCompleted(net::URLRequest* request, int bytes_read) override {}
|
| -};
|
| -
|
| -class MockURLRequestJob : public net::URLRequestJob {
|
| - public:
|
| - MockURLRequestJob(net::URLRequest* request,
|
| - const net::HttpResponseInfo& response_info,
|
| - const std::string& mime_type)
|
| - : net::URLRequestJob(request, nullptr),
|
| - response_info_(response_info),
|
| - mime_type_(mime_type) {}
|
| -
|
| - bool GetMimeType(std::string* mime_type) const override {
|
| - *mime_type = mime_type_;
|
| - return true;
|
| - }
|
| -
|
| - protected:
|
| - void Start() override { NotifyHeadersComplete(); }
|
| - void GetResponseInfo(net::HttpResponseInfo* info) override {
|
| - *info = response_info_;
|
| - }
|
| -
|
| - private:
|
| - net::HttpResponseInfo response_info_;
|
| - std::string mime_type_;
|
| -};
|
| -
|
| -class MockURLRequestJobFactory : public net::URLRequestJobFactory {
|
| - public:
|
| - MockURLRequestJobFactory() {}
|
| - ~MockURLRequestJobFactory() override {}
|
| -
|
| - net::URLRequestJob* MaybeCreateJobWithProtocolHandler(
|
| - const std::string& scheme,
|
| - net::URLRequest* request,
|
| - net::NetworkDelegate* network_delegate) const override {
|
| - return new MockURLRequestJob(request, response_info_, mime_type_);
|
| - }
|
| -
|
| - net::URLRequestJob* MaybeInterceptRedirect(
|
| - net::URLRequest* request,
|
| - net::NetworkDelegate* network_delegate,
|
| - const GURL& location) const override {
|
| - return nullptr;
|
| - }
|
| -
|
| - net::URLRequestJob* MaybeInterceptResponse(
|
| - net::URLRequest* request,
|
| - net::NetworkDelegate* network_delegate) const override {
|
| - return nullptr;
|
| - }
|
| -
|
| - bool IsHandledProtocol(const std::string& scheme) const override {
|
| - return true;
|
| - }
|
| -
|
| - bool IsSafeRedirectTarget(const GURL& location) const override {
|
| - return true;
|
| - }
|
| -
|
| - void set_response_info(const net::HttpResponseInfo& response_info) {
|
| - response_info_ = response_info;
|
| - }
|
| -
|
| - void set_mime_type(const std::string& mime_type) { mime_type_ = mime_type; }
|
| -
|
| - private:
|
| - net::HttpResponseInfo response_info_;
|
| - std::string mime_type_;
|
| -};
|
| -
|
| template <typename T>
|
| class FakeGlowplugKeyValueTable : public GlowplugKeyValueTable<T> {
|
| public:
|
| @@ -199,10 +119,9 @@ class MockResourcePrefetchPredictorTables
|
| ~MockResourcePrefetchPredictorTables() override = default;
|
| };
|
|
|
| -class MockResourcePrefetchPredictorObserver : public TestObserver {
|
| +class MockLoadingPredictorObserver : public TestObserver {
|
| public:
|
| - explicit MockResourcePrefetchPredictorObserver(
|
| - ResourcePrefetchPredictor* predictor)
|
| + explicit MockLoadingPredictorObserver(ResourcePrefetchPredictor* predictor)
|
| : TestObserver(predictor) {}
|
|
|
| MOCK_METHOD2(
|
| @@ -618,7 +537,7 @@ TEST_F(ResourcePrefetchPredictorTest, NavigationLowHistoryCount) {
|
| content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false);
|
| predictor_->RecordURLResponse(resource3);
|
|
|
| - StrictMock<MockResourcePrefetchPredictorObserver> mock_observer(predictor_);
|
| + StrictMock<MockLoadingPredictorObserver> mock_observer(predictor_);
|
| EXPECT_CALL(
|
| mock_observer,
|
| OnNavigationLearned(kVisitCount,
|
| @@ -717,7 +636,7 @@ TEST_F(ResourcePrefetchPredictorTest, NavigationUrlNotInDB) {
|
|
|
| predictor_->RecordURLResponse(redirected);
|
|
|
| - StrictMock<MockResourcePrefetchPredictorObserver> mock_observer(predictor_);
|
| + StrictMock<MockLoadingPredictorObserver> mock_observer(predictor_);
|
| EXPECT_CALL(mock_observer,
|
| OnNavigationLearned(
|
| kVisitCount, CreatePageRequestSummary("http://www.google.com",
|
| @@ -831,7 +750,7 @@ TEST_F(ResourcePrefetchPredictorTest, NavigationUrlInDB) {
|
| no_store.is_no_store = true;
|
| predictor_->RecordURLResponse(no_store);
|
|
|
| - StrictMock<MockResourcePrefetchPredictorObserver> mock_observer(predictor_);
|
| + StrictMock<MockLoadingPredictorObserver> mock_observer(predictor_);
|
| EXPECT_CALL(mock_observer,
|
| OnNavigationLearned(
|
| kVisitCount, CreatePageRequestSummary("http://www.google.com",
|
| @@ -933,7 +852,7 @@ TEST_F(ResourcePrefetchPredictorTest, NavigationUrlNotInDBAndDBFull) {
|
| content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false);
|
| predictor_->RecordURLResponse(resource2);
|
|
|
| - StrictMock<MockResourcePrefetchPredictorObserver> mock_observer(predictor_);
|
| + StrictMock<MockLoadingPredictorObserver> mock_observer(predictor_);
|
| EXPECT_CALL(mock_observer,
|
| OnNavigationLearned(
|
| kVisitCount, CreatePageRequestSummary(
|
| @@ -1003,7 +922,7 @@ TEST_F(ResourcePrefetchPredictorTest, RedirectUrlNotInDB) {
|
| predictor_->RecordURLRedirect(fb3);
|
| NavigationID fb_end = CreateNavigationID(1, "https://facebook.com/google");
|
|
|
| - StrictMock<MockResourcePrefetchPredictorObserver> mock_observer(predictor_);
|
| + StrictMock<MockLoadingPredictorObserver> mock_observer(predictor_);
|
| EXPECT_CALL(
|
| mock_observer,
|
| OnNavigationLearned(kVisitCount, CreatePageRequestSummary(
|
| @@ -1053,7 +972,7 @@ TEST_F(ResourcePrefetchPredictorTest, RedirectUrlInDB) {
|
| predictor_->RecordURLRedirect(fb3);
|
| NavigationID fb_end = CreateNavigationID(1, "https://facebook.com/google");
|
|
|
| - StrictMock<MockResourcePrefetchPredictorObserver> mock_observer(predictor_);
|
| + StrictMock<MockLoadingPredictorObserver> mock_observer(predictor_);
|
| EXPECT_CALL(
|
| mock_observer,
|
| OnNavigationLearned(kVisitCount, CreatePageRequestSummary(
|
| @@ -1470,197 +1389,6 @@ TEST_F(ResourcePrefetchPredictorTest, OnSubresourceResponse) {
|
| ->subresource_requests[2]);
|
| }
|
|
|
| -TEST_F(ResourcePrefetchPredictorTest, HandledResourceTypes) {
|
| - EXPECT_TRUE(ResourcePrefetchPredictor::IsHandledResourceType(
|
| - content::RESOURCE_TYPE_STYLESHEET, "bogus/mime-type"));
|
| - EXPECT_TRUE(ResourcePrefetchPredictor::IsHandledResourceType(
|
| - content::RESOURCE_TYPE_STYLESHEET, ""));
|
| - EXPECT_FALSE(ResourcePrefetchPredictor::IsHandledResourceType(
|
| - content::RESOURCE_TYPE_WORKER, "text/css"));
|
| - EXPECT_FALSE(ResourcePrefetchPredictor::IsHandledResourceType(
|
| - content::RESOURCE_TYPE_WORKER, ""));
|
| - EXPECT_TRUE(ResourcePrefetchPredictor::IsHandledResourceType(
|
| - content::RESOURCE_TYPE_PREFETCH, "text/css"));
|
| - EXPECT_FALSE(ResourcePrefetchPredictor::IsHandledResourceType(
|
| - content::RESOURCE_TYPE_PREFETCH, "bogus/mime-type"));
|
| - EXPECT_FALSE(ResourcePrefetchPredictor::IsHandledResourceType(
|
| - content::RESOURCE_TYPE_PREFETCH, ""));
|
| - EXPECT_TRUE(ResourcePrefetchPredictor::IsHandledResourceType(
|
| - content::RESOURCE_TYPE_PREFETCH, "application/font-woff"));
|
| - EXPECT_TRUE(ResourcePrefetchPredictor::IsHandledResourceType(
|
| - content::RESOURCE_TYPE_PREFETCH, "font/woff2"));
|
| - EXPECT_FALSE(ResourcePrefetchPredictor::IsHandledResourceType(
|
| - content::RESOURCE_TYPE_XHR, ""));
|
| - EXPECT_FALSE(ResourcePrefetchPredictor::IsHandledResourceType(
|
| - content::RESOURCE_TYPE_XHR, "bogus/mime-type"));
|
| - EXPECT_TRUE(ResourcePrefetchPredictor::IsHandledResourceType(
|
| - content::RESOURCE_TYPE_XHR, "application/javascript"));
|
| -}
|
| -
|
| -TEST_F(ResourcePrefetchPredictorTest, ShouldRecordRequestMainFrame) {
|
| - std::unique_ptr<net::URLRequest> http_request =
|
| - CreateURLRequest(GURL("http://www.google.com"), net::MEDIUM,
|
| - content::RESOURCE_TYPE_IMAGE, true);
|
| - EXPECT_TRUE(ResourcePrefetchPredictor::ShouldRecordRequest(
|
| - http_request.get(), content::RESOURCE_TYPE_MAIN_FRAME));
|
| -
|
| - std::unique_ptr<net::URLRequest> https_request =
|
| - CreateURLRequest(GURL("https://www.google.com"), net::MEDIUM,
|
| - content::RESOURCE_TYPE_IMAGE, true);
|
| - EXPECT_TRUE(ResourcePrefetchPredictor::ShouldRecordRequest(
|
| - https_request.get(), content::RESOURCE_TYPE_MAIN_FRAME));
|
| -
|
| - std::unique_ptr<net::URLRequest> file_request =
|
| - CreateURLRequest(GURL("file://www.google.com"), net::MEDIUM,
|
| - content::RESOURCE_TYPE_IMAGE, true);
|
| - EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordRequest(
|
| - file_request.get(), content::RESOURCE_TYPE_MAIN_FRAME));
|
| -
|
| - std::unique_ptr<net::URLRequest> https_request_with_port =
|
| - CreateURLRequest(GURL("https://www.google.com:666"), net::MEDIUM,
|
| - content::RESOURCE_TYPE_IMAGE, true);
|
| - EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordRequest(
|
| - https_request_with_port.get(), content::RESOURCE_TYPE_MAIN_FRAME));
|
| -}
|
| -
|
| -TEST_F(ResourcePrefetchPredictorTest, ShouldRecordRequestSubResource) {
|
| - std::unique_ptr<net::URLRequest> http_request =
|
| - CreateURLRequest(GURL("http://www.google.com/cat.png"), net::MEDIUM,
|
| - content::RESOURCE_TYPE_IMAGE, false);
|
| - EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordRequest(
|
| - http_request.get(), content::RESOURCE_TYPE_IMAGE));
|
| -
|
| - std::unique_ptr<net::URLRequest> https_request =
|
| - CreateURLRequest(GURL("https://www.google.com/cat.png"), net::MEDIUM,
|
| - content::RESOURCE_TYPE_IMAGE, false);
|
| - EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordRequest(
|
| - https_request.get(), content::RESOURCE_TYPE_IMAGE));
|
| -
|
| - std::unique_ptr<net::URLRequest> file_request =
|
| - CreateURLRequest(GURL("file://www.google.com/cat.png"), net::MEDIUM,
|
| - content::RESOURCE_TYPE_IMAGE, false);
|
| - EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordRequest(
|
| - file_request.get(), content::RESOURCE_TYPE_IMAGE));
|
| -
|
| - std::unique_ptr<net::URLRequest> https_request_with_port =
|
| - CreateURLRequest(GURL("https://www.google.com:666/cat.png"), net::MEDIUM,
|
| - content::RESOURCE_TYPE_IMAGE, false);
|
| - EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordRequest(
|
| - https_request_with_port.get(), content::RESOURCE_TYPE_IMAGE));
|
| -}
|
| -
|
| -TEST_F(ResourcePrefetchPredictorTest, ShouldRecordResponseMainFrame) {
|
| - net::HttpResponseInfo response_info;
|
| - response_info.headers = MakeResponseHeaders("");
|
| - url_request_job_factory_.set_response_info(response_info);
|
| -
|
| - std::unique_ptr<net::URLRequest> http_request =
|
| - CreateURLRequest(GURL("http://www.google.com"), net::MEDIUM,
|
| - content::RESOURCE_TYPE_MAIN_FRAME, true);
|
| - EXPECT_TRUE(
|
| - ResourcePrefetchPredictor::ShouldRecordResponse(http_request.get()));
|
| -
|
| - std::unique_ptr<net::URLRequest> https_request =
|
| - CreateURLRequest(GURL("https://www.google.com"), net::MEDIUM,
|
| - content::RESOURCE_TYPE_MAIN_FRAME, true);
|
| - EXPECT_TRUE(
|
| - ResourcePrefetchPredictor::ShouldRecordResponse(https_request.get()));
|
| -
|
| - std::unique_ptr<net::URLRequest> file_request =
|
| - CreateURLRequest(GURL("file://www.google.com"), net::MEDIUM,
|
| - content::RESOURCE_TYPE_MAIN_FRAME, true);
|
| - EXPECT_FALSE(
|
| - ResourcePrefetchPredictor::ShouldRecordResponse(file_request.get()));
|
| -
|
| - std::unique_ptr<net::URLRequest> https_request_with_port =
|
| - CreateURLRequest(GURL("https://www.google.com:666"), net::MEDIUM,
|
| - content::RESOURCE_TYPE_MAIN_FRAME, true);
|
| - EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordResponse(
|
| - https_request_with_port.get()));
|
| -}
|
| -
|
| -TEST_F(ResourcePrefetchPredictorTest, ShouldRecordResponseSubresource) {
|
| - net::HttpResponseInfo response_info;
|
| - response_info.headers =
|
| - MakeResponseHeaders("HTTP/1.1 200 OK\n\nSome: Headers\n");
|
| - response_info.was_cached = true;
|
| - url_request_job_factory_.set_response_info(response_info);
|
| -
|
| - // Protocol.
|
| - std::unique_ptr<net::URLRequest> http_image_request =
|
| - CreateURLRequest(GURL("http://www.google.com/cat.png"), net::MEDIUM,
|
| - content::RESOURCE_TYPE_IMAGE, true);
|
| - EXPECT_TRUE(ResourcePrefetchPredictor::ShouldRecordResponse(
|
| - http_image_request.get()));
|
| -
|
| - std::unique_ptr<net::URLRequest> https_image_request =
|
| - CreateURLRequest(GURL("https://www.google.com/cat.png"), net::MEDIUM,
|
| - content::RESOURCE_TYPE_IMAGE, true);
|
| - EXPECT_TRUE(ResourcePrefetchPredictor::ShouldRecordResponse(
|
| - https_image_request.get()));
|
| -
|
| - std::unique_ptr<net::URLRequest> https_image_request_with_port =
|
| - CreateURLRequest(GURL("https://www.google.com:666/cat.png"), net::MEDIUM,
|
| - content::RESOURCE_TYPE_IMAGE, true);
|
| - EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordResponse(
|
| - https_image_request_with_port.get()));
|
| -
|
| - std::unique_ptr<net::URLRequest> file_image_request =
|
| - CreateURLRequest(GURL("file://www.google.com/cat.png"), net::MEDIUM,
|
| - content::RESOURCE_TYPE_IMAGE, true);
|
| - EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordResponse(
|
| - file_image_request.get()));
|
| -
|
| - // ResourceType.
|
| - std::unique_ptr<net::URLRequest> sub_frame_request =
|
| - CreateURLRequest(GURL("http://www.google.com/frame.html"), net::MEDIUM,
|
| - content::RESOURCE_TYPE_SUB_FRAME, true);
|
| - EXPECT_FALSE(
|
| - ResourcePrefetchPredictor::ShouldRecordResponse(sub_frame_request.get()));
|
| -
|
| - std::unique_ptr<net::URLRequest> font_request =
|
| - CreateURLRequest(GURL("http://www.google.com/comic-sans-ms.woff"),
|
| - net::MEDIUM, content::RESOURCE_TYPE_FONT_RESOURCE, true);
|
| - EXPECT_TRUE(
|
| - ResourcePrefetchPredictor::ShouldRecordResponse(font_request.get()));
|
| -
|
| - // From MIME Type.
|
| - url_request_job_factory_.set_mime_type("image/png");
|
| - std::unique_ptr<net::URLRequest> prefetch_image_request =
|
| - CreateURLRequest(GURL("http://www.google.com/cat.png"), net::MEDIUM,
|
| - content::RESOURCE_TYPE_PREFETCH, true);
|
| - EXPECT_TRUE(ResourcePrefetchPredictor::ShouldRecordResponse(
|
| - prefetch_image_request.get()));
|
| -
|
| - url_request_job_factory_.set_mime_type("image/my-wonderful-format");
|
| - std::unique_ptr<net::URLRequest> prefetch_unknown_image_request =
|
| - CreateURLRequest(GURL("http://www.google.com/cat.png"), net::MEDIUM,
|
| - content::RESOURCE_TYPE_PREFETCH, true);
|
| - EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordResponse(
|
| - prefetch_unknown_image_request.get()));
|
| -
|
| - url_request_job_factory_.set_mime_type("font/woff");
|
| - std::unique_ptr<net::URLRequest> prefetch_font_request =
|
| - CreateURLRequest(GURL("http://www.google.com/comic-sans-ms.woff"),
|
| - net::MEDIUM, content::RESOURCE_TYPE_PREFETCH, true);
|
| - EXPECT_TRUE(ResourcePrefetchPredictor::ShouldRecordResponse(
|
| - prefetch_font_request.get()));
|
| -
|
| - url_request_job_factory_.set_mime_type("font/woff-woff");
|
| - std::unique_ptr<net::URLRequest> prefetch_unknown_font_request =
|
| - CreateURLRequest(GURL("http://www.google.com/comic-sans-ms.woff"),
|
| - net::MEDIUM, content::RESOURCE_TYPE_PREFETCH, true);
|
| - EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordResponse(
|
| - prefetch_unknown_font_request.get()));
|
| -
|
| - // Not main frame.
|
| - std::unique_ptr<net::URLRequest> font_request_sub_frame = CreateURLRequest(
|
| - GURL("http://www.google.com/comic-sans-ms.woff"), net::MEDIUM,
|
| - content::RESOURCE_TYPE_FONT_RESOURCE, false);
|
| - EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordResponse(
|
| - font_request_sub_frame.get()));
|
| -}
|
| -
|
| TEST_F(ResourcePrefetchPredictorTest, SummarizeResponse) {
|
| net::HttpResponseInfo response_info;
|
| response_info.headers =
|
|
|