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

Side by Side Diff: third_party/WebKit/Source/core/loader/LinkLoaderTest.cpp

Issue 1839473002: Centralize the setting of Accept headers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase again Created 4 years, 8 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "core/loader/LinkLoader.h" 5 #include "core/loader/LinkLoader.h"
6 6
7 #include "core/fetch/MemoryCache.h" 7 #include "core/fetch/MemoryCache.h"
8 #include "core/fetch/ResourceFetcher.h" 8 #include "core/fetch/ResourceFetcher.h"
9 #include "core/frame/Settings.h" 9 #include "core/frame/Settings.h"
10 #include "core/html/LinkRelAttribute.h" 10 #include "core/html/LinkRelAttribute.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 { 89 {
90 struct TestCase { 90 struct TestCase {
91 const char* href; 91 const char* href;
92 const char* as; 92 const char* as;
93 const char* type; 93 const char* type;
94 const char* media; 94 const char* media;
95 const ResourceLoadPriority priority; 95 const ResourceLoadPriority priority;
96 const WebURLRequest::RequestContext context; 96 const WebURLRequest::RequestContext context;
97 const bool linkLoaderShouldLoadValue; 97 const bool linkLoaderShouldLoadValue;
98 const bool expectingLoad; 98 const bool expectingLoad;
99 const char* accept;
100 } cases[] = { 99 } cases[] = {
101 {"http://example.test/cat.jpg", "image", "", "", ResourceLoadPriorityVer yLow, WebURLRequest::RequestContextImage, true, true, "image/webp,image/*,*/*;q= 0.8"}, 100 {"http://example.test/cat.jpg", "image", "", "", ResourceLoadPriorityVer yLow, WebURLRequest::RequestContextImage, true, true},
102 {"http://example.test/cat.js", "script", "", "", ResourceLoadPriorityMed ium, WebURLRequest::RequestContextScript, true, true, "*/*"}, 101 {"http://example.test/cat.js", "script", "", "", ResourceLoadPriorityMed ium, WebURLRequest::RequestContextScript, true, true},
103 {"http://example.test/cat.css", "style", "", "", ResourceLoadPriorityHig h, WebURLRequest::RequestContextStyle, true, true, "text/css,*/*;q=0.1"}, 102 {"http://example.test/cat.css", "style", "", "", ResourceLoadPriorityHig h, WebURLRequest::RequestContextStyle, true, true},
104 // TODO(yoav): It doesn't seem like the audio context is ever used. That should probably be fixed (or we can consolidate audio and video). 103 // TODO(yoav): It doesn't seem like the audio context is ever used. That should probably be fixed (or we can consolidate audio and video).
105 {"http://example.test/cat.wav", "media", "", "", ResourceLoadPriorityLow , WebURLRequest::RequestContextVideo, true, true, ""}, 104 {"http://example.test/cat.wav", "media", "", "", ResourceLoadPriorityLow , WebURLRequest::RequestContextVideo, true, true},
106 {"http://example.test/cat.mp4", "media", "", "", ResourceLoadPriorityLow , WebURLRequest::RequestContextVideo, true, true, ""}, 105 {"http://example.test/cat.mp4", "media", "", "", ResourceLoadPriorityLow , WebURLRequest::RequestContextVideo, true, true},
107 {"http://example.test/cat.vtt", "track", "", "", ResourceLoadPriorityLow , WebURLRequest::RequestContextTrack, true, true, ""}, 106 {"http://example.test/cat.vtt", "track", "", "", ResourceLoadPriorityLow , WebURLRequest::RequestContextTrack, true, true},
108 {"http://example.test/cat.woff", "font", "", "", ResourceLoadPriorityMed ium, WebURLRequest::RequestContextFont, true, true, ""}, 107 {"http://example.test/cat.woff", "font", "", "", ResourceLoadPriorityMed ium, WebURLRequest::RequestContextFont, true, true},
109 // TODO(yoav): subresource should be *very* low priority (rather than lo w). 108 // TODO(yoav): subresource should be *very* low priority (rather than lo w).
110 {"http://example.test/cat.empty", "", "", "", ResourceLoadPriorityLow, W ebURLRequest::RequestContextSubresource, true, true, ""}, 109 {"http://example.test/cat.empty", "", "", "", ResourceLoadPriorityLow, W ebURLRequest::RequestContextSubresource, true, true},
111 {"http://example.test/cat.blob", "blabla", "", "", ResourceLoadPriorityL ow, WebURLRequest::RequestContextSubresource, false, false, ""}, 110 {"http://example.test/cat.blob", "blabla", "", "", ResourceLoadPriorityL ow, WebURLRequest::RequestContextSubresource, false, false},
112 {"bla://example.test/cat.gif", "image", "", "", ResourceLoadPriorityUnre solved, WebURLRequest::RequestContextImage, false, false, ""}, 111 {"bla://example.test/cat.gif", "image", "", "", ResourceLoadPriorityUnre solved, WebURLRequest::RequestContextImage, false, false},
113 // MIME type tests 112 // MIME type tests
114 {"http://example.test/cat.webp", "image", "image/webp", "", ResourceLoad PriorityVeryLow, WebURLRequest::RequestContextImage, true, true, "image/webp,ima ge/*,*/*;q=0.8"}, 113 {"http://example.test/cat.webp", "image", "image/webp", "", ResourceLoad PriorityVeryLow, WebURLRequest::RequestContextImage, true, true},
115 {"http://example.test/cat.svg", "image", "image/svg+xml", "", ResourceLo adPriorityVeryLow, WebURLRequest::RequestContextImage, true, true, "image/webp,i mage/*,*/*;q=0.8"}, 114 {"http://example.test/cat.svg", "image", "image/svg+xml", "", ResourceLo adPriorityVeryLow, WebURLRequest::RequestContextImage, true, true},
116 {"http://example.test/cat.jxr", "image", "image/jxr", "", ResourceLoadPr iorityUnresolved, WebURLRequest::RequestContextImage, false, false, ""}, 115 {"http://example.test/cat.jxr", "image", "image/jxr", "", ResourceLoadPr iorityUnresolved, WebURLRequest::RequestContextImage, false, false},
117 {"http://example.test/cat.js", "script", "text/javascript", "", Resource LoadPriorityMedium, WebURLRequest::RequestContextScript, true, true, "*/*"}, 116 {"http://example.test/cat.js", "script", "text/javascript", "", Resource LoadPriorityMedium, WebURLRequest::RequestContextScript, true, true},
118 {"http://example.test/cat.js", "script", "text/coffeescript", "", Resour ceLoadPriorityUnresolved, WebURLRequest::RequestContextScript, false, false, ""} , 117 {"http://example.test/cat.js", "script", "text/coffeescript", "", Resour ceLoadPriorityUnresolved, WebURLRequest::RequestContextScript, false, false},
119 {"http://example.test/cat.css", "style", "text/css", "", ResourceLoadPri orityHigh, WebURLRequest::RequestContextStyle, true, true, "text/css,*/*;q=0.1"} , 118 {"http://example.test/cat.css", "style", "text/css", "", ResourceLoadPri orityHigh, WebURLRequest::RequestContextStyle, true, true},
120 {"http://example.test/cat.css", "style", "text/sass", "", ResourceLoadPr iorityUnresolved, WebURLRequest::RequestContextStyle, false, false, ""}, 119 {"http://example.test/cat.css", "style", "text/sass", "", ResourceLoadPr iorityUnresolved, WebURLRequest::RequestContextStyle, false, false},
121 {"http://example.test/cat.wav", "media", "audio/wav", "", ResourceLoadPr iorityLow, WebURLRequest::RequestContextVideo, true, true, ""}, 120 {"http://example.test/cat.wav", "media", "audio/wav", "", ResourceLoadPr iorityLow, WebURLRequest::RequestContextVideo, true, true},
122 {"http://example.test/cat.wav", "media", "audio/mp57", "", ResourceLoadP riorityUnresolved, WebURLRequest::RequestContextVideo, false, false, ""}, 121 {"http://example.test/cat.wav", "media", "audio/mp57", "", ResourceLoadP riorityUnresolved, WebURLRequest::RequestContextVideo, false, false},
123 {"http://example.test/cat.webm", "media", "video/webm", "", ResourceLoad PriorityLow, WebURLRequest::RequestContextVideo, true, true, ""}, 122 {"http://example.test/cat.webm", "media", "video/webm", "", ResourceLoad PriorityLow, WebURLRequest::RequestContextVideo, true, true},
124 {"http://example.test/cat.mp199", "media", "video/mp199", "", ResourceLo adPriorityUnresolved, WebURLRequest::RequestContextVideo, false, false, ""}, 123 {"http://example.test/cat.mp199", "media", "video/mp199", "", ResourceLo adPriorityUnresolved, WebURLRequest::RequestContextVideo, false, false},
125 {"http://example.test/cat.vtt", "track", "text/vtt", "", ResourceLoadPri orityLow, WebURLRequest::RequestContextTrack, true, true, ""}, 124 {"http://example.test/cat.vtt", "track", "text/vtt", "", ResourceLoadPri orityLow, WebURLRequest::RequestContextTrack, true, true},
126 {"http://example.test/cat.vtt", "track", "text/subtitlething", "", Resou rceLoadPriorityUnresolved, WebURLRequest::RequestContextTrack, false, false, ""} , 125 {"http://example.test/cat.vtt", "track", "text/subtitlething", "", Resou rceLoadPriorityUnresolved, WebURLRequest::RequestContextTrack, false, false},
127 {"http://example.test/cat.woff", "font", "font/woff2", "", ResourceLoadP riorityMedium, WebURLRequest::RequestContextFont, true, true, ""}, 126 {"http://example.test/cat.woff", "font", "font/woff2", "", ResourceLoadP riorityMedium, WebURLRequest::RequestContextFont, true, true},
128 {"http://example.test/cat.woff", "font", "font/woff84", "", ResourceLoad PriorityUnresolved, WebURLRequest::RequestContextFont, false, false, ""}, 127 {"http://example.test/cat.woff", "font", "font/woff84", "", ResourceLoad PriorityUnresolved, WebURLRequest::RequestContextFont, false, false},
129 {"http://example.test/cat.empty", "", "foo/bar", "", ResourceLoadPriorit yLow, WebURLRequest::RequestContextSubresource, true, true, ""}, 128 {"http://example.test/cat.empty", "", "foo/bar", "", ResourceLoadPriorit yLow, WebURLRequest::RequestContextSubresource, true, true},
130 {"http://example.test/cat.blob", "blabla", "foo/bar", "", ResourceLoadPr iorityLow, WebURLRequest::RequestContextSubresource, false, false, ""}, 129 {"http://example.test/cat.blob", "blabla", "foo/bar", "", ResourceLoadPr iorityLow, WebURLRequest::RequestContextSubresource, false, false},
131 // Media tests 130 // Media tests
132 {"http://example.test/cat.gif", "image", "image/gif", "(max-width: 600px )", ResourceLoadPriorityVeryLow, WebURLRequest::RequestContextImage, true, true, "image/webp,image/*,*/*;q=0.8"}, 131 {"http://example.test/cat.gif", "image", "image/gif", "(max-width: 600px )", ResourceLoadPriorityVeryLow, WebURLRequest::RequestContextImage, true, true} ,
133 {"http://example.test/cat.gif", "image", "image/gif", "(max-width: 400px )", ResourceLoadPriorityUnresolved, WebURLRequest::RequestContextImage, true, fa lse, ""}, 132 {"http://example.test/cat.gif", "image", "image/gif", "(max-width: 400px )", ResourceLoadPriorityUnresolved, WebURLRequest::RequestContextImage, true, fa lse},
134 {"http://example.test/cat.gif", "image", "image/gif", "(max-width: 600px )", ResourceLoadPriorityVeryLow, WebURLRequest::RequestContextImage, false, fals e, "image/webp,image/*,*/*;q=0.8"}, 133 {"http://example.test/cat.gif", "image", "image/gif", "(max-width: 600px )", ResourceLoadPriorityVeryLow, WebURLRequest::RequestContextImage, false, fals e},
135 }; 134 };
136 135
137 // Test the cases with a single header 136 // Test the cases with a single header
138 for (const auto& testCase : cases) { 137 for (const auto& testCase : cases) {
139 OwnPtr<DummyPageHolder> dummyPageHolder = DummyPageHolder::create(IntSiz e(500, 500)); 138 OwnPtr<DummyPageHolder> dummyPageHolder = DummyPageHolder::create(IntSiz e(500, 500));
140 dummyPageHolder->frame().settings()->setScriptEnabled(true); 139 dummyPageHolder->frame().settings()->setScriptEnabled(true);
141 Persistent<MockLinkLoaderClient> loaderClient = MockLinkLoaderClient::cr eate(testCase.linkLoaderShouldLoadValue); 140 Persistent<MockLinkLoaderClient> loaderClient = MockLinkLoaderClient::cr eate(testCase.linkLoaderShouldLoadValue);
142 LinkLoader* loader = LinkLoader::create(loaderClient.get()); 141 LinkLoader* loader = LinkLoader::create(loaderClient.get());
143 KURL hrefURL = KURL(KURL(), testCase.href); 142 KURL hrefURL = KURL(KURL(), testCase.href);
144 URLTestHelpers::registerMockedErrorURLLoad(hrefURL); 143 URLTestHelpers::registerMockedErrorURLLoad(hrefURL);
(...skipping 16 matching lines...) Expand all
161 } 160 }
162 if (preloads) { 161 if (preloads) {
163 if (testCase.priority == ResourceLoadPriorityUnresolved) { 162 if (testCase.priority == ResourceLoadPriorityUnresolved) {
164 ASSERT_EQ((unsigned)0, preloads->size()); 163 ASSERT_EQ((unsigned)0, preloads->size());
165 } else { 164 } else {
166 ASSERT_EQ((unsigned)1, preloads->size()); 165 ASSERT_EQ((unsigned)1, preloads->size());
167 if (preloads->size() > 0) { 166 if (preloads->size() > 0) {
168 Resource* resource = preloads->begin().get()->get(); 167 Resource* resource = preloads->begin().get()->get();
169 ASSERT_EQ(testCase.priority, resource->resourceRequest().pri ority()); 168 ASSERT_EQ(testCase.priority, resource->resourceRequest().pri ority());
170 ASSERT_EQ(testCase.context, resource->resourceRequest().requ estContext()); 169 ASSERT_EQ(testCase.context, resource->resourceRequest().requ estContext());
171 ASSERT_STREQ(testCase.accept, resource->accept().getString() .ascii().data());
172 } 170 }
173 } 171 }
174 dummyPageHolder->document().fetcher()->clearPreloads(); 172 dummyPageHolder->document().fetcher()->clearPreloads();
175 } 173 }
176 memoryCache()->evictResources(); 174 memoryCache()->evictResources();
177 Platform::current()->getURLLoaderMockFactory()->unregisterAllURLs(); 175 Platform::current()->getURLLoaderMockFactory()->unregisterAllURLs();
178 } 176 }
179 } 177 }
180 178
181 TEST(LinkLoaderTest, DNSPrefetch) 179 TEST(LinkLoaderTest, DNSPrefetch)
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 hrefURL, 240 hrefURL,
243 dummyPageHolder->document(), 241 dummyPageHolder->document(),
244 networkHints); 242 networkHints);
245 ASSERT_EQ(testCase.shouldLoad, networkHints.didPreconnect()); 243 ASSERT_EQ(testCase.shouldLoad, networkHints.didPreconnect());
246 ASSERT_EQ(testCase.isHTTPS, networkHints.isHTTPS()); 244 ASSERT_EQ(testCase.isHTTPS, networkHints.isHTTPS());
247 ASSERT_EQ(testCase.isCrossOrigin, networkHints.isCrossOrigin()); 245 ASSERT_EQ(testCase.isCrossOrigin, networkHints.isCrossOrigin());
248 } 246 }
249 } 247 }
250 248
251 } // namespace blink 249 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698