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

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

Issue 2147473002: Set 'ResourceRequest::requestorOrigin' in Blink for more request types. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: jochen Created 4 years, 5 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 /* 1 /*
2 * Copyright (c) 2015, Google Inc. All rights reserved. 2 * Copyright (c) 2015, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 441
442 // Child frame as part of reload 442 // Child frame as part of reload
443 document->frame()->loader().setLoadType(FrameLoadTypeReload); 443 document->frame()->loader().setLoadType(FrameLoadTypeReload);
444 EXPECT_EQ(WebCachePolicy::ValidatingCacheData, childFetchContext->resourceRe questCachePolicy(request, Resource::MainResource, FetchRequest::NoDefer)); 444 EXPECT_EQ(WebCachePolicy::ValidatingCacheData, childFetchContext->resourceRe questCachePolicy(request, Resource::MainResource, FetchRequest::NoDefer));
445 445
446 // Child frame as part of reload bypassing cache 446 // Child frame as part of reload bypassing cache
447 document->frame()->loader().setLoadType(FrameLoadTypeReloadBypassingCache); 447 document->frame()->loader().setLoadType(FrameLoadTypeReloadBypassingCache);
448 EXPECT_EQ(WebCachePolicy::BypassingCache, childFetchContext->resourceRequest CachePolicy(request, Resource::MainResource, FetchRequest::NoDefer)); 448 EXPECT_EQ(WebCachePolicy::BypassingCache, childFetchContext->resourceRequest CachePolicy(request, Resource::MainResource, FetchRequest::NoDefer));
449 } 449 }
450 450
451 TEST_F(FrameFetchContextTest, PopulateRequestData)
452 {
453 struct TestCase {
454 const char* documentURL;
455 bool documentSandboxed;
456 const char* requestorOrigin; // "" => nullptr, "null" => unique origin
457 WebURLRequest::FrameType frameType;
458 const char* serializedOrigin; // "" => nullptr, "null" => unique origin
459 } cases[] = {
460 // No document origin => unique request origin
461 { "", false, "", WebURLRequest::FrameTypeNone, "null" },
462 { "", true, "", WebURLRequest::FrameTypeNone, "null" },
463
464 // Document origin => request origin
465 { "http://example.test", false, "", WebURLRequest::FrameTypeNone, "http: //example.test" },
466 { "http://example.test", true, "", WebURLRequest::FrameTypeNone, "http:/ /example.test" },
467
468 // If the request already has a requestor origin, then 'populateRequestD ata' leaves it alone:
469 { "http://example.test", false, "http://not-example.test", WebURLRequest ::FrameTypeNone, "http://not-example.test" },
470 { "http://example.test", true, "http://not-example.test", WebURLRequest: :FrameTypeNone, "http://not-example.test" },
471
472 // If the request's frame type is not 'none', then 'populateRequestData' leaves it alone:
473 { "http://example.test", false, "", WebURLRequest::FrameTypeTopLevel, "" },
474 { "http://example.test", false, "", WebURLRequest::FrameTypeAuxiliary, " " },
475 { "http://example.test", false, "", WebURLRequest::FrameTypeNested, "" } ,
476 };
477
478 for (const auto& test : cases) {
479 SCOPED_TRACE(::testing::Message() << test.documentURL << " => " << test. serializedOrigin);
480 // Set up a new document to ensure sandbox flags are cleared:
481 dummyPageHolder = DummyPageHolder::create(IntSize(500, 500));
482 dummyPageHolder->page().setDeviceScaleFactor(1.0);
483 document = toHTMLDocument(&dummyPageHolder->document());
484 FrameFetchContext::provideDocumentToContext(*fetchContext, document.get( ));
485
486 // Setup the test:
487 document->setURL(KURL(ParsedURLString, test.documentURL));
488 document->setSecurityOrigin(SecurityOrigin::create(document->url()));
489
490 if (test.documentSandboxed)
491 document->enforceSandboxFlags(SandboxOrigin);
492
493 ResourceRequest request("http://example.test/");
494 request.setFrameType(test.frameType);
495 if (strlen(test.requestorOrigin) == 0)
496 request.setRequestorOrigin(nullptr);
497 else
498 request.setRequestorOrigin(SecurityOrigin::create(KURL(ParsedURLStri ng, test.requestorOrigin)));
499
500 // Compare the populated |requestorOrigin| against |test.serializedOrigi n|
501 fetchContext->populateRequestData(request);
502 if (strlen(test.serializedOrigin) == 0)
503 EXPECT_EQ(nullptr, request.requestorOrigin().get());
504 else
505 EXPECT_EQ(String(test.serializedOrigin), request.requestorOrigin()-> toString());
506
507 EXPECT_EQ(document->firstPartyForCookies(), request.firstPartyForCookies ());
508 }
509 }
510
451 TEST_F(FrameFetchContextTest, ModifyPriorityForLowPriorityIframes) 511 TEST_F(FrameFetchContextTest, ModifyPriorityForLowPriorityIframes)
452 { 512 {
453 Settings* settings = document->frame()->settings(); 513 Settings* settings = document->frame()->settings();
454 settings->setLowPriorityIframes(false); 514 settings->setLowPriorityIframes(false);
455 FetchRequest request(ResourceRequest("http://www.example.com"), FetchInitiat orInfo()); 515 FetchRequest request(ResourceRequest("http://www.example.com"), FetchInitiat orInfo());
456 FrameFetchContext* childFetchContext = createChildFrame(); 516 FrameFetchContext* childFetchContext = createChildFrame();
457 517
458 // No low priority iframes, expect default values. 518 // No low priority iframes, expect default values.
459 EXPECT_EQ(ResourceLoadPriorityVeryHigh, childFetchContext->modifyPriorityFor Experiments(ResourceLoadPriorityVeryHigh)); 519 EXPECT_EQ(ResourceLoadPriorityVeryHigh, childFetchContext->modifyPriorityFor Experiments(ResourceLoadPriorityVeryHigh));
460 EXPECT_EQ(ResourceLoadPriorityMedium, childFetchContext->modifyPriorityForEx periments(ResourceLoadPriorityMedium)); 520 EXPECT_EQ(ResourceLoadPriorityMedium, childFetchContext->modifyPriorityForEx periments(ResourceLoadPriorityMedium));
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 fetchContext->addAdditionalRequestHeaders(mainRequest, FetchMainResource ); 696 fetchContext->addAdditionalRequestHeaders(mainRequest, FetchMainResource );
637 EXPECT_EQ(mainRequest.isExternalRequest(), test.isExternalExpectation); 697 EXPECT_EQ(mainRequest.isExternalRequest(), test.isExternalExpectation);
638 698
639 ResourceRequest subRequest(test.url); 699 ResourceRequest subRequest(test.url);
640 fetchContext->addAdditionalRequestHeaders(subRequest, FetchSubresource); 700 fetchContext->addAdditionalRequestHeaders(subRequest, FetchSubresource);
641 EXPECT_EQ(subRequest.isExternalRequest(), test.isExternalExpectation); 701 EXPECT_EQ(subRequest.isExternalRequest(), test.isExternalExpectation);
642 } 702 }
643 } 703 }
644 704
645 } // namespace blink 705 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698