Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / core / loader / FrameFetchContextTest.cpp
blobf1aef3701849bd1e6c611d6eaccdfb57978544e1
1 /*
2 * Copyright (c) 2015, Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include "config.h"
32 #include "core/loader/FrameFetchContext.h"
34 #include "core/fetch/FetchInitiatorInfo.h"
35 #include "core/frame/FrameHost.h"
36 #include "core/frame/FrameOwner.h"
37 #include "core/frame/FrameView.h"
38 #include "core/frame/Settings.h"
39 #include "core/html/HTMLDocument.h"
40 #include "core/loader/DocumentLoader.h"
41 #include "core/loader/EmptyClients.h"
42 #include "core/page/Page.h"
43 #include "core/testing/DummyPageHolder.h"
44 #include "platform/network/ResourceRequest.h"
45 #include "platform/weborigin/KURL.h"
46 #include <gtest/gtest.h>
48 namespace blink {
50 class StubFrameLoaderClientWithParent final : public EmptyFrameLoaderClient {
51 public:
52 static PassOwnPtrWillBeRawPtr<StubFrameLoaderClientWithParent> create(Frame* parent)
54 return adoptPtrWillBeNoop(new StubFrameLoaderClientWithParent(parent));
57 DEFINE_INLINE_VIRTUAL_TRACE()
59 visitor->trace(m_parent);
60 EmptyFrameLoaderClient::trace(visitor);
63 Frame* parent() const override { return m_parent.get(); }
65 private:
66 explicit StubFrameLoaderClientWithParent(Frame* parent)
67 : m_parent(parent)
71 RawPtrWillBeMember<Frame> m_parent;
74 class StubFrameOwner : public NoBaseWillBeGarbageCollectedFinalized<StubFrameOwner>, public FrameOwner {
75 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(StubFrameOwner);
76 public:
77 static PassOwnPtrWillBeRawPtr<StubFrameOwner> create()
79 return adoptPtrWillBeNoop(new StubFrameOwner);
82 DEFINE_INLINE_VIRTUAL_TRACE() { FrameOwner::trace(visitor); }
84 bool isLocal() const override { return false; }
85 SandboxFlags sandboxFlags() const override { return SandboxNone; }
86 void dispatchLoad() override { }
87 void renderFallbackContent() override { }
90 class FrameFetchContextTest : public ::testing::Test {
91 protected:
92 void SetUp() override
94 dummyPageHolder = DummyPageHolder::create(IntSize(500, 500));
95 dummyPageHolder->page().setDeviceScaleFactor(1.0);
96 documentLoader = DocumentLoader::create(&dummyPageHolder->frame(), ResourceRequest("http://www.example.com"), SubstituteData());
97 document = toHTMLDocument(&dummyPageHolder->document());
98 fetchContext = static_cast<FrameFetchContext*>(&documentLoader->fetcher()->context());
99 owner = StubFrameOwner::create();
100 FrameFetchContext::provideDocumentToContext(*fetchContext, document.get());
103 void TearDown() override
105 documentLoader->detachFromFrame();
106 documentLoader.clear();
108 if (childFrame) {
109 childDocumentLoader->detachFromFrame();
110 childDocumentLoader.clear();
111 childFrame->detach(FrameDetachType::Remove);
115 FrameFetchContext* createChildFrame()
117 childClient = StubFrameLoaderClientWithParent::create(document->frame());
118 childFrame = LocalFrame::create(childClient.get(), document->frame()->host(), owner.get());
119 childFrame->setView(FrameView::create(childFrame.get(), IntSize(500, 500)));
120 childFrame->init();
121 childDocumentLoader = DocumentLoader::create(childFrame.get(), ResourceRequest("http://www.example.com"), SubstituteData());
122 childDocument = childFrame->document();
123 FrameFetchContext* childFetchContext = static_cast<FrameFetchContext*>(&childDocumentLoader->fetcher()->context());
124 FrameFetchContext::provideDocumentToContext(*childFetchContext, childDocument.get());
125 return childFetchContext;
128 OwnPtr<DummyPageHolder> dummyPageHolder;
129 // We don't use the DocumentLoader directly in any tests, but need to keep it around as long
130 // as the ResourceFetcher and Document live due to indirect usage.
131 RefPtrWillBePersistent<DocumentLoader> documentLoader;
132 RefPtrWillBePersistent<Document> document;
133 Persistent<FrameFetchContext> fetchContext;
135 OwnPtrWillBePersistent<StubFrameLoaderClientWithParent> childClient;
136 RefPtrWillBePersistent<LocalFrame> childFrame;
137 RefPtrWillBePersistent<DocumentLoader> childDocumentLoader;
138 RefPtrWillBePersistent<Document> childDocument;
139 OwnPtrWillBePersistent<StubFrameOwner> owner;
142 class FrameFetchContextUpgradeTest : public FrameFetchContextTest {
143 public:
144 FrameFetchContextUpgradeTest()
145 : exampleOrigin(SecurityOrigin::create(KURL(ParsedURLString, "https://example.test/")))
146 , secureOrigin(SecurityOrigin::create(KURL(ParsedURLString, "https://secureorigin.test/image.png")))
150 protected:
151 void expectUpgrade(const char* input, const char* expected)
153 expectUpgrade(input, WebURLRequest::RequestContextScript, WebURLRequest::FrameTypeNone, expected);
156 void expectUpgrade(const char* input, WebURLRequest::RequestContext requestContext, WebURLRequest::FrameType frameType, const char* expected)
158 KURL inputURL(ParsedURLString, input);
159 KURL expectedURL(ParsedURLString, expected);
161 FetchRequest fetchRequest = FetchRequest(ResourceRequest(inputURL), FetchInitiatorInfo());
162 fetchRequest.mutableResourceRequest().setRequestContext(requestContext);
163 fetchRequest.mutableResourceRequest().setFrameType(frameType);
165 fetchContext->upgradeInsecureRequest(fetchRequest);
167 EXPECT_STREQ(expectedURL.string().utf8().data(), fetchRequest.resourceRequest().url().string().utf8().data());
168 EXPECT_EQ(expectedURL.protocol(), fetchRequest.resourceRequest().url().protocol());
169 EXPECT_EQ(expectedURL.host(), fetchRequest.resourceRequest().url().host());
170 EXPECT_EQ(expectedURL.port(), fetchRequest.resourceRequest().url().port());
171 EXPECT_EQ(expectedURL.hasPort(), fetchRequest.resourceRequest().url().hasPort());
172 EXPECT_EQ(expectedURL.path(), fetchRequest.resourceRequest().url().path());
175 void expectHTTPSHeader(const char* input, WebURLRequest::FrameType frameType, bool shouldPrefer)
177 KURL inputURL(ParsedURLString, input);
179 FetchRequest fetchRequest = FetchRequest(ResourceRequest(inputURL), FetchInitiatorInfo());
180 fetchRequest.mutableResourceRequest().setRequestContext(WebURLRequest::RequestContextScript);
181 fetchRequest.mutableResourceRequest().setFrameType(frameType);
183 fetchContext->upgradeInsecureRequest(fetchRequest);
185 EXPECT_STREQ(shouldPrefer ? "1" : "",
186 fetchRequest.resourceRequest().httpHeaderField("Upgrade-Insecure-Requests").utf8().data());
189 RefPtr<SecurityOrigin> exampleOrigin;
190 RefPtr<SecurityOrigin> secureOrigin;
193 TEST_F(FrameFetchContextUpgradeTest, UpgradeInsecureResourceRequests)
195 struct TestCase {
196 const char* original;
197 const char* upgraded;
198 } tests[] = {
199 { "http://example.test/image.png", "https://example.test/image.png" },
200 { "http://example.test:80/image.png", "https://example.test:443/image.png" },
201 { "http://example.test:1212/image.png", "https://example.test:1212/image.png" },
203 { "https://example.test/image.png", "https://example.test/image.png" },
204 { "https://example.test:80/image.png", "https://example.test:80/image.png" },
205 { "https://example.test:1212/image.png", "https://example.test:1212/image.png" },
207 { "ftp://example.test/image.png", "ftp://example.test/image.png" },
208 { "ftp://example.test:21/image.png", "ftp://example.test:21/image.png" },
209 { "ftp://example.test:1212/image.png", "ftp://example.test:1212/image.png" },
212 FrameFetchContext::provideDocumentToContext(*fetchContext, document.get());
213 document->setInsecureRequestsPolicy(SecurityContext::InsecureRequestsUpgrade);
215 for (const auto& test : tests) {
216 document->insecureNavigationsToUpgrade()->clear();
218 // We always upgrade for FrameTypeNone and FrameTypeNested.
219 expectUpgrade(test.original, WebURLRequest::RequestContextScript, WebURLRequest::FrameTypeNone, test.upgraded);
220 expectUpgrade(test.original, WebURLRequest::RequestContextScript, WebURLRequest::FrameTypeNested, test.upgraded);
222 // We do not upgrade for FrameTypeTopLevel or FrameTypeAuxiliary...
223 expectUpgrade(test.original, WebURLRequest::RequestContextScript, WebURLRequest::FrameTypeTopLevel, test.original);
224 expectUpgrade(test.original, WebURLRequest::RequestContextScript, WebURLRequest::FrameTypeAuxiliary, test.original);
226 // unless the request context is RequestContextForm.
227 expectUpgrade(test.original, WebURLRequest::RequestContextForm, WebURLRequest::FrameTypeTopLevel, test.upgraded);
228 expectUpgrade(test.original, WebURLRequest::RequestContextForm, WebURLRequest::FrameTypeAuxiliary, test.upgraded);
230 // Or unless the host of the resource is in the document's InsecureNavigationsSet:
231 document->addInsecureNavigationUpgrade(exampleOrigin->host().impl()->hash());
232 expectUpgrade(test.original, WebURLRequest::RequestContextScript, WebURLRequest::FrameTypeTopLevel, test.upgraded);
233 expectUpgrade(test.original, WebURLRequest::RequestContextScript, WebURLRequest::FrameTypeAuxiliary, test.upgraded);
237 TEST_F(FrameFetchContextUpgradeTest, DoNotUpgradeInsecureResourceRequests)
239 FrameFetchContext::provideDocumentToContext(*fetchContext, document.get());
240 document->setSecurityOrigin(secureOrigin);
241 document->setInsecureRequestsPolicy(SecurityContext::InsecureRequestsDoNotUpgrade);
243 expectUpgrade("http://example.test/image.png", "http://example.test/image.png");
244 expectUpgrade("http://example.test:80/image.png", "http://example.test:80/image.png");
245 expectUpgrade("http://example.test:1212/image.png", "http://example.test:1212/image.png");
247 expectUpgrade("https://example.test/image.png", "https://example.test/image.png");
248 expectUpgrade("https://example.test:80/image.png", "https://example.test:80/image.png");
249 expectUpgrade("https://example.test:1212/image.png", "https://example.test:1212/image.png");
251 expectUpgrade("ftp://example.test/image.png", "ftp://example.test/image.png");
252 expectUpgrade("ftp://example.test:21/image.png", "ftp://example.test:21/image.png");
253 expectUpgrade("ftp://example.test:1212/image.png", "ftp://example.test:1212/image.png");
256 TEST_F(FrameFetchContextUpgradeTest, SendHTTPSHeader)
258 struct TestCase {
259 const char* toRequest;
260 WebURLRequest::FrameType frameType;
261 bool shouldPrefer;
262 } tests[] = {
263 { "http://example.test/page.html", WebURLRequest::FrameTypeAuxiliary, true },
264 { "http://example.test/page.html", WebURLRequest::FrameTypeNested, true },
265 { "http://example.test/page.html", WebURLRequest::FrameTypeNone, false },
266 { "http://example.test/page.html", WebURLRequest::FrameTypeTopLevel, true },
267 { "https://example.test/page.html", WebURLRequest::FrameTypeAuxiliary, true },
268 { "https://example.test/page.html", WebURLRequest::FrameTypeNested, true },
269 { "https://example.test/page.html", WebURLRequest::FrameTypeNone, false },
270 { "https://example.test/page.html", WebURLRequest::FrameTypeTopLevel, true }
273 // This should work correctly both when the FrameFetchContext has a Document, and
274 // when it doesn't (e.g. during main frame navigations), so run through the tests
275 // both before and after providing a document to the context.
276 for (const auto& test : tests) {
277 document->setInsecureRequestsPolicy(SecurityContext::InsecureRequestsDoNotUpgrade);
278 expectHTTPSHeader(test.toRequest, test.frameType, test.shouldPrefer);
280 document->setInsecureRequestsPolicy(SecurityContext::InsecureRequestsUpgrade);
281 expectHTTPSHeader(test.toRequest, test.frameType, test.shouldPrefer);
284 FrameFetchContext::provideDocumentToContext(*fetchContext, document.get());
286 for (const auto& test : tests) {
287 document->setInsecureRequestsPolicy(SecurityContext::InsecureRequestsDoNotUpgrade);
288 expectHTTPSHeader(test.toRequest, test.frameType, test.shouldPrefer);
290 document->setInsecureRequestsPolicy(SecurityContext::InsecureRequestsUpgrade);
291 expectHTTPSHeader(test.toRequest, test.frameType, test.shouldPrefer);
295 class FrameFetchContextHintsTest : public FrameFetchContextTest {
296 public:
297 FrameFetchContextHintsTest() { }
299 protected:
300 void expectHeader(const char* input, const char* headerName, bool isPresent, const char* headerValue, float width = 0)
302 KURL inputURL(ParsedURLString, input);
303 FetchRequest fetchRequest = FetchRequest(ResourceRequest(inputURL), FetchInitiatorInfo());
304 if (width > 0) {
305 FetchRequest::ResourceWidth resourceWidth;
306 resourceWidth.width = width;
307 resourceWidth.isSet = true;
308 fetchRequest.setResourceWidth(resourceWidth);
310 fetchContext->addClientHintsIfNecessary(fetchRequest);
312 EXPECT_STREQ(isPresent ? headerValue : "",
313 fetchRequest.resourceRequest().httpHeaderField(headerName).utf8().data());
317 TEST_F(FrameFetchContextHintsTest, MonitorDPRHints)
319 expectHeader("http://www.example.com/1.gif", "DPR", false, "");
320 ClientHintsPreferences preferences;
321 preferences.setShouldSendDPR(true);
322 document->clientHintsPreferences().updateFrom(preferences);
323 expectHeader("http://www.example.com/1.gif", "DPR", true, "1");
324 dummyPageHolder->page().setDeviceScaleFactor(2.5);
325 expectHeader("http://www.example.com/1.gif", "DPR", true, "2.5");
326 expectHeader("http://www.example.com/1.gif", "Width", false, "");
327 expectHeader("http://www.example.com/1.gif", "Viewport-Width", false, "");
330 TEST_F(FrameFetchContextHintsTest, MonitorResourceWidthHints)
332 expectHeader("http://www.example.com/1.gif", "Width", false, "");
333 ClientHintsPreferences preferences;
334 preferences.setShouldSendResourceWidth(true);
335 document->clientHintsPreferences().updateFrom(preferences);
336 expectHeader("http://www.example.com/1.gif", "Width", true, "500", 500);
337 expectHeader("http://www.example.com/1.gif", "Width", true, "667", 666.6666);
338 expectHeader("http://www.example.com/1.gif", "DPR", false, "");
341 TEST_F(FrameFetchContextHintsTest, MonitorViewportWidthHints)
343 expectHeader("http://www.example.com/1.gif", "Viewport-Width", false, "");
344 ClientHintsPreferences preferences;
345 preferences.setShouldSendViewportWidth(true);
346 document->clientHintsPreferences().updateFrom(preferences);
347 expectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "500");
348 dummyPageHolder->frameView().setLayoutSizeFixedToFrameSize(false);
349 dummyPageHolder->frameView().setLayoutSize(IntSize(800, 800));
350 expectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "800");
351 expectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "800", 666.6666);
352 expectHeader("http://www.example.com/1.gif", "DPR", false, "");
355 TEST_F(FrameFetchContextHintsTest, MonitorAllHints)
357 expectHeader("http://www.example.com/1.gif", "DPR", false, "");
358 expectHeader("http://www.example.com/1.gif", "Viewport-Width", false, "");
359 expectHeader("http://www.example.com/1.gif", "Width", false, "");
361 ClientHintsPreferences preferences;
362 preferences.setShouldSendDPR(true);
363 preferences.setShouldSendResourceWidth(true);
364 preferences.setShouldSendViewportWidth(true);
365 document->clientHintsPreferences().updateFrom(preferences);
366 expectHeader("http://www.example.com/1.gif", "DPR", true, "1");
367 expectHeader("http://www.example.com/1.gif", "Width", true, "400", 400);
368 expectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "500");
371 TEST_F(FrameFetchContextTest, MainResource)
373 // Default case
374 ResourceRequest request("http://www.example.com");
375 EXPECT_EQ(UseProtocolCachePolicy, fetchContext->resourceRequestCachePolicy(request, Resource::MainResource));
377 // Post
378 ResourceRequest postRequest("http://www.example.com");
379 postRequest.setHTTPMethod("POST");
380 EXPECT_EQ(ReloadIgnoringCacheData, fetchContext->resourceRequestCachePolicy(postRequest, Resource::MainResource));
382 // Re-post
383 document->frame()->loader().setLoadType(FrameLoadTypeBackForward);
384 EXPECT_EQ(ReturnCacheDataDontLoad, fetchContext->resourceRequestCachePolicy(postRequest, Resource::MainResource));
386 // Enconding overriden
387 document->frame()->loader().setLoadType(FrameLoadTypeStandard);
388 document->frame()->host()->setOverrideEncoding("foo");
389 EXPECT_EQ(ReturnCacheDataElseLoad, fetchContext->resourceRequestCachePolicy(request, Resource::MainResource));
390 document->frame()->host()->setOverrideEncoding(AtomicString());
392 // FrameLoadTypeSame
393 document->frame()->loader().setLoadType(FrameLoadTypeSame);
394 EXPECT_EQ(ReloadIgnoringCacheData, fetchContext->resourceRequestCachePolicy(request, Resource::MainResource));
396 // Conditional request
397 document->frame()->loader().setLoadType(FrameLoadTypeStandard);
398 ResourceRequest conditional("http://www.example.com");
399 conditional.setHTTPHeaderField("If-Modified-Since", "foo");
400 EXPECT_EQ(ReloadIgnoringCacheData, fetchContext->resourceRequestCachePolicy(conditional, Resource::MainResource));
402 // Set up a child frame
403 FrameFetchContext* childFetchContext = createChildFrame();
405 // Child frame as part of back/forward
406 document->frame()->loader().setLoadType(FrameLoadTypeBackForward);
407 EXPECT_EQ(ReturnCacheDataElseLoad, childFetchContext->resourceRequestCachePolicy(request, Resource::MainResource));
409 // Child frame as part of reload
410 document->frame()->loader().setLoadType(FrameLoadTypeReload);
411 EXPECT_EQ(ReloadIgnoringCacheData, childFetchContext->resourceRequestCachePolicy(request, Resource::MainResource));
413 // Child frame as part of end to end reload
414 document->frame()->loader().setLoadType(FrameLoadTypeReloadFromOrigin);
415 EXPECT_EQ(ReloadBypassingCache, childFetchContext->resourceRequestCachePolicy(request, Resource::MainResource));
418 TEST_F(FrameFetchContextTest, ModifyPriorityForExperiments)
420 Settings* settings = document->frame()->settings();
421 FetchRequest request(ResourceRequest("http://www.example.com"), FetchInitiatorInfo());
423 FetchRequest preloadRequest(ResourceRequest("http://www.example.com"), FetchInitiatorInfo());
424 preloadRequest.setForPreload(true);
426 FetchRequest deferredRequest(ResourceRequest("http://www.example.com"), FetchInitiatorInfo());
427 deferredRequest.setDefer(FetchRequest::LazyLoad);
429 // Start with all experiments disabled.
430 settings->setFEtchIncreaseAsyncScriptPriority(false);
431 settings->setFEtchIncreaseFontPriority(false);
432 settings->setFEtchDeferLateScripts(false);
433 settings->setFEtchIncreasePriorities(false);
435 // Base case, no priority change. Note that this triggers m_imageFetched, which will matter for setFetchDeferLateScripts() case below.
436 EXPECT_EQ(ResourceLoadPriorityLow, fetchContext->modifyPriorityForExperiments(ResourceLoadPriorityLow, Resource::Image, request));
438 // Font priority with and without fetchIncreaseFontPriority()
439 EXPECT_EQ(ResourceLoadPriorityMedium, fetchContext->modifyPriorityForExperiments(ResourceLoadPriorityMedium, Resource::Font, request));
440 settings->setFEtchIncreaseFontPriority(true);
441 EXPECT_EQ(ResourceLoadPriorityHigh, fetchContext->modifyPriorityForExperiments(ResourceLoadPriorityMedium, Resource::Font, request));
443 // Basic script cases
444 EXPECT_EQ(ResourceLoadPriorityMedium, fetchContext->modifyPriorityForExperiments(ResourceLoadPriorityMedium, Resource::Script, request));
445 EXPECT_EQ(ResourceLoadPriorityMedium, fetchContext->modifyPriorityForExperiments(ResourceLoadPriorityMedium, Resource::Script, preloadRequest));
447 // Enable deferring late scripts. Preload priority should drop.
448 settings->setFEtchDeferLateScripts(true);
449 EXPECT_EQ(ResourceLoadPriorityLow, fetchContext->modifyPriorityForExperiments(ResourceLoadPriorityMedium, Resource::Script, preloadRequest));
451 // Enable increasing priority of async scripts.
452 EXPECT_EQ(ResourceLoadPriorityLow, fetchContext->modifyPriorityForExperiments(ResourceLoadPriorityMedium, Resource::Script, deferredRequest));
453 settings->setFEtchIncreaseAsyncScriptPriority(true);
454 EXPECT_EQ(ResourceLoadPriorityMedium, fetchContext->modifyPriorityForExperiments(ResourceLoadPriorityMedium, Resource::Script, deferredRequest));
456 // Enable increased priorities for the remainder.
457 settings->setFEtchIncreasePriorities(true);
459 // Re-test font priority with increased prioriries
460 settings->setFEtchIncreaseFontPriority(false);
461 EXPECT_EQ(ResourceLoadPriorityHigh, fetchContext->modifyPriorityForExperiments(ResourceLoadPriorityMedium, Resource::Font, request));
462 settings->setFEtchIncreaseFontPriority(true);
463 EXPECT_EQ(ResourceLoadPriorityVeryHigh, fetchContext->modifyPriorityForExperiments(ResourceLoadPriorityMedium, Resource::Font, request));
465 // Re-test basic script cases and deferring late script case with increased prioriries
466 settings->setFEtchIncreasePriorities(true);
467 settings->setFEtchDeferLateScripts(false);
468 EXPECT_EQ(ResourceLoadPriorityVeryHigh, fetchContext->modifyPriorityForExperiments(ResourceLoadPriorityMedium, Resource::Script, request));
469 EXPECT_EQ(ResourceLoadPriorityHigh, fetchContext->modifyPriorityForExperiments(ResourceLoadPriorityMedium, Resource::Script, preloadRequest));
471 // Re-test deferring late scripts.
472 settings->setFEtchDeferLateScripts(true);
473 EXPECT_EQ(ResourceLoadPriorityMedium, fetchContext->modifyPriorityForExperiments(ResourceLoadPriorityMedium, Resource::Script, preloadRequest));
475 // Re-test increasing priority of async scripts. Should ignore general incraesed priorities.
476 settings->setFEtchIncreaseAsyncScriptPriority(false);
477 EXPECT_EQ(ResourceLoadPriorityLow, fetchContext->modifyPriorityForExperiments(ResourceLoadPriorityMedium, Resource::Script, deferredRequest));
478 settings->setFEtchIncreaseAsyncScriptPriority(true);
479 EXPECT_EQ(ResourceLoadPriorityMedium, fetchContext->modifyPriorityForExperiments(ResourceLoadPriorityMedium, Resource::Script, deferredRequest));
481 // Ensure we don't go out of bounds
482 settings->setFEtchIncreasePriorities(true);
483 EXPECT_EQ(ResourceLoadPriorityVeryHigh, fetchContext->modifyPriorityForExperiments(ResourceLoadPriorityVeryHigh, Resource::Script, request));
484 settings->setFEtchIncreasePriorities(false);
485 settings->setFEtchDeferLateScripts(true);
486 EXPECT_EQ(ResourceLoadPriorityVeryLow, fetchContext->modifyPriorityForExperiments(ResourceLoadPriorityVeryLow, Resource::Script, preloadRequest));
489 TEST_F(FrameFetchContextTest, ModifyPriorityForLowPriorityIframes)
491 Settings* settings = document->frame()->settings();
492 settings->setLowPriorityIframes(false);
493 FetchRequest request(ResourceRequest("http://www.example.com"), FetchInitiatorInfo());
494 FrameFetchContext* childFetchContext = createChildFrame();
496 // No low priority iframes, expect default values.
497 EXPECT_EQ(ResourceLoadPriorityVeryHigh, childFetchContext->modifyPriorityForExperiments(ResourceLoadPriorityVeryHigh, Resource::MainResource, request));
498 EXPECT_EQ(ResourceLoadPriorityMedium, childFetchContext->modifyPriorityForExperiments(ResourceLoadPriorityMedium, Resource::Script, request));
500 // Low priority iframes enabled, everything should be low priority
501 settings->setLowPriorityIframes(true);
502 EXPECT_EQ(ResourceLoadPriorityVeryLow, childFetchContext->modifyPriorityForExperiments(ResourceLoadPriorityVeryHigh, Resource::MainResource, request));
503 EXPECT_EQ(ResourceLoadPriorityVeryLow, childFetchContext->modifyPriorityForExperiments(ResourceLoadPriorityMedium, Resource::Script, request));
506 } // namespace