Chromium Code Reviews| Index: chrome/browser/predictors/resource_prefetch_predictor_browsertest.cc |
| diff --git a/chrome/browser/predictors/resource_prefetch_predictor_browsertest.cc b/chrome/browser/predictors/resource_prefetch_predictor_browsertest.cc |
| index c8748d2368fdcb08e5642caf9eba844c1cc695de..341347acd0635488176f16fd438005786fbdd0ea 100644 |
| --- a/chrome/browser/predictors/resource_prefetch_predictor_browsertest.cc |
| +++ b/chrome/browser/predictors/resource_prefetch_predictor_browsertest.cc |
| @@ -24,22 +24,39 @@ namespace predictors { |
| namespace { |
| static const char kImagePath[] = "/predictors/image.png"; |
| +static const char kImagePath2[] = "/predictors/image2.png"; |
| static const char kStylePath[] = "/predictors/style.css"; |
| +static const char kStylePath2[] = "/predictors/style2.css"; |
|
pasko
2016/11/30 13:52:48
it would be nice (i.e. more readable with less sur
alexilin
2016/11/30 18:43:50
Done.
|
| static const char kScriptPath[] = "/predictors/script.js"; |
| +static const char kScriptPath2[] = "/predictors/script2.js"; |
| static const char kFontPath[] = "/predictors/font.ttf"; |
| static const char kHtmlSubresourcesPath[] = |
| "/predictors/html_subresources.html"; |
| static const char kRedirectPath[] = "/predictors/redirect.html"; |
| static const char kRedirectPath2[] = "/predictors/redirect2.html"; |
| static const char kRedirectPath3[] = "/predictors/redirect3.html"; |
| +static const char kHtmlScriptPath[] = "/predictors/html_script.html"; |
| +static const char kHtmlIframePath[] = "/predictors/html_iframe.html"; |
| struct ResourceSummary { |
| - ResourceSummary() : is_no_store(false), version(0) {} |
| + ResourceSummary() |
| + : is_no_store(false), version(0), should_be_recorded(true) {} |
| ResourcePrefetchPredictor::URLRequestSummary request; |
| std::string content; |
| bool is_no_store; |
| size_t version; |
| + bool should_be_recorded; |
| + |
| + ResourceSummary* WithContent(const std::string& i_content) { |
|
pasko
2016/11/30 13:52:47
we do not make prefixed names in chromium codebase
alexilin
2016/11/30 18:43:50
Not quite true:
https://cs.chromium.org/chromium/s
|
| + content = i_content; |
| + return this; |
| + } |
| + |
| + ResourceSummary* NotRecorded() { |
| + should_be_recorded = false; |
| + return this; |
|
pasko
2016/11/30 13:52:48
while I appreciate the added elegance, returning |
alexilin
2016/11/30 18:43:50
Done.
|
| + } |
| }; |
| struct RedirectEdge { |
| @@ -152,7 +169,7 @@ class ResourcePrefetchPredictorBrowserTest : public InProcessBrowserTest { |
| GURL endpoint_url = GetRedirectEndpoint(main_frame_url); |
| std::vector<URLRequestSummary> url_request_summaries; |
| for (const auto& kv : resources_) { |
| - if (kv.second.is_no_store) |
| + if (kv.second.is_no_store || !kv.second.should_be_recorded) |
|
pasko
2016/11/30 13:52:47
what does "should_be_recorded" mean? Can we EXPECT
alexilin
2016/11/30 18:43:50
It means that this resource should or should not b
|
| continue; |
| url_request_summaries.push_back( |
| GetURLRequestSummaryForResource(endpoint_url, kv.second)); |
| @@ -372,4 +389,57 @@ IN_PROC_BROWSER_TEST_F(ResourcePrefetchPredictorBrowserTest, |
| NavigateToURLAndCheckSubresources(GetURL(kRedirectPath)); |
| } |
| +IN_PROC_BROWSER_TEST_F(ResourcePrefetchPredictorBrowserTest, |
| + LearningJavascriptOriginated) { |
| + AddResource(GetURL(kScriptPath), content::RESOURCE_TYPE_SCRIPT, net::MEDIUM) |
| + ->WithContent( |
| + "document.write(\'<img src=\"image.png\">\');" |
|
pasko
2016/11/30 13:52:48
Code in one language containing code in another la
alexilin
2016/11/30 18:43:50
Acknowledged.
|
| + "document.write(\'<link rel=\"stylesheet\" href=\"style.css\">\');" |
|
pasko
2016/11/30 13:52:48
there are other ways for JS to request a resource:
alexilin
2016/11/30 18:43:50
I'm not sure that it's secure to perform DOM manip
|
| + "document.write(\'<script src=\"script2.js\"></script>\');"); |
|
pasko
2016/11/30 13:52:48
creating a file for this would be preferable. Is t
alexilin
2016/11/30 18:43:50
Done.
|
| + AddResource(GetURL(kImagePath), content::RESOURCE_TYPE_IMAGE, net::LOWEST); |
| + AddResource(GetURL(kStylePath), content::RESOURCE_TYPE_STYLESHEET, |
| + net::HIGHEST); |
| + AddResource(GetURL(kScriptPath2), content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); |
| + NavigateToURLAndCheckSubresources(GetURL(kHtmlScriptPath)); |
| +} |
| + |
| +// Javascript fetch requests are ignored by the ResourcePrefetchPredictor |
| +// because they have unsupported resource type content::RESOURCE_TYPE_XHR. |
|
pasko
2016/11/30 13:52:47
what's our status on fixing it? is there a bug? If
alexilin
2016/11/30 18:43:50
Well, I just discovered it by writing this test so
|
| +IN_PROC_BROWSER_TEST_F(ResourcePrefetchPredictorBrowserTest, |
| + LearningIgnoringJavascriptFetches) { |
| + AddResource(GetURL(kScriptPath), content::RESOURCE_TYPE_SCRIPT, net::MEDIUM) |
| + ->WithContent( |
| + "fetch(\"image.png\"); fetch(\"style.css\"); fetch(\"script2.js\")"); |
| + AddResource(GetURL(kImagePath), content::RESOURCE_TYPE_IMAGE, net::LOWEST) |
| + ->NotRecorded(); |
| + AddResource(GetURL(kStylePath), content::RESOURCE_TYPE_STYLESHEET, |
| + net::HIGHEST) |
| + ->NotRecorded(); |
| + AddResource(GetURL(kScriptPath2), content::RESOURCE_TYPE_SCRIPT, net::MEDIUM) |
| + ->NotRecorded(); |
| + NavigateToURLAndCheckSubresources(GetURL(kHtmlScriptPath)); |
| +} |
| + |
| +// ResourcePrefetchPredictor ignores all resources requested from subframes. |
| +IN_PROC_BROWSER_TEST_F(ResourcePrefetchPredictorBrowserTest, |
| + LearningWithIframe) { |
| + // Included from html_iframe.html. |
| + AddResource(GetURL(kImagePath2), content::RESOURCE_TYPE_IMAGE, net::LOWEST); |
| + AddResource(GetURL(kStylePath2), content::RESOURCE_TYPE_STYLESHEET, |
| + net::HIGHEST); |
| + AddResource(GetURL(kScriptPath2), content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); |
| + // Included from <iframe src="html_subresources.html"> and not recored. |
| + AddResource(GetURL(kImagePath), content::RESOURCE_TYPE_IMAGE, net::LOWEST) |
| + ->NotRecorded(); |
| + AddResource(GetURL(kStylePath), content::RESOURCE_TYPE_STYLESHEET, |
| + net::HIGHEST) |
| + ->NotRecorded(); |
| + AddResource(GetURL(kScriptPath), content::RESOURCE_TYPE_SCRIPT, net::MEDIUM) |
| + ->NotRecorded(); |
| + AddResource(GetURL(kFontPath), content::RESOURCE_TYPE_FONT_RESOURCE, |
| + net::HIGHEST) |
| + ->NotRecorded(); |
| + NavigateToURLAndCheckSubresources(GetURL(kHtmlIframePath)); |
| +} |
| + |
| } // namespace predictors |