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

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

Issue 2323143002: Correctly set requestor origin for worker initiated requests. (Closed)
Patch Set: rebase Created 4 years, 3 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
« no previous file with comments | « third_party/WebKit/Source/core/loader/FrameFetchContext.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 // Child frame as part of reload bypassing cache 438 // Child frame as part of reload bypassing cache
439 document->frame()->loader().setLoadType(FrameLoadTypeReloadBypassingCache); 439 document->frame()->loader().setLoadType(FrameLoadTypeReloadBypassingCache);
440 EXPECT_EQ(WebCachePolicy::BypassingCache, childFetchContext->resourceRequest CachePolicy(request, Resource::MainResource, FetchRequest::NoDefer)); 440 EXPECT_EQ(WebCachePolicy::BypassingCache, childFetchContext->resourceRequest CachePolicy(request, Resource::MainResource, FetchRequest::NoDefer));
441 } 441 }
442 442
443 TEST_F(FrameFetchContextTest, PopulateRequestData) 443 TEST_F(FrameFetchContextTest, PopulateRequestData)
444 { 444 {
445 struct TestCase { 445 struct TestCase {
446 const char* documentURL; 446 const char* documentURL;
447 bool documentSandboxed; 447 bool documentSandboxed;
448 const char* requestorOrigin; // "" => nullptr, "null" => unique origin 448 const char* requestorOrigin; // "" => unique origin
449 WebURLRequest::FrameType frameType; 449 WebURLRequest::FrameType frameType;
450 const char* serializedOrigin; // "" => nullptr, "null" => unique origin 450 const char* serializedOrigin; // "" => unique origin
451 } cases[] = { 451 } cases[] = {
452 // No document origin => unique request origin 452 // No document origin => unique request origin
453 { "", false, "", WebURLRequest::FrameTypeNone, "null" }, 453 { "", false, "", WebURLRequest::FrameTypeNone, "null" },
454 { "", true, "", WebURLRequest::FrameTypeNone, "null" }, 454 { "", true, "", WebURLRequest::FrameTypeNone, "null" },
455 455
456 // Document origin => request origin 456 // Document origin => request origin
457 { "http://example.test", false, "", WebURLRequest::FrameTypeNone, "http: //example.test" }, 457 { "http://example.test", false, "", WebURLRequest::FrameTypeNone, "http: //example.test" },
458 { "http://example.test", true, "", WebURLRequest::FrameTypeNone, "http:/ /example.test" }, 458 { "http://example.test", true, "", WebURLRequest::FrameTypeNone, "http:/ /example.test" },
459 459
460 // If the request already has a requestor origin, then 'populateRequestD ata' leaves it alone: 460 // If the request already has a requestor origin, then 'populateRequestD ata' leaves it alone:
(...skipping 17 matching lines...) Expand all
478 // Setup the test: 478 // Setup the test:
479 document->setURL(KURL(ParsedURLString, test.documentURL)); 479 document->setURL(KURL(ParsedURLString, test.documentURL));
480 document->setSecurityOrigin(SecurityOrigin::create(document->url())); 480 document->setSecurityOrigin(SecurityOrigin::create(document->url()));
481 481
482 if (test.documentSandboxed) 482 if (test.documentSandboxed)
483 document->enforceSandboxFlags(SandboxOrigin); 483 document->enforceSandboxFlags(SandboxOrigin);
484 484
485 ResourceRequest request("http://example.test/"); 485 ResourceRequest request("http://example.test/");
486 request.setFrameType(test.frameType); 486 request.setFrameType(test.frameType);
487 if (strlen(test.requestorOrigin) == 0) 487 if (strlen(test.requestorOrigin) == 0)
488 request.setRequestorOrigin(nullptr); 488 request.setRequestorOrigin(SecurityOrigin::createUnique());
489 else 489 else
490 request.setRequestorOrigin(SecurityOrigin::create(KURL(ParsedURLStri ng, test.requestorOrigin))); 490 request.setRequestorOrigin(SecurityOrigin::create(KURL(ParsedURLStri ng, test.requestorOrigin)));
491 491
492 // Compare the populated |requestorOrigin| against |test.serializedOrigi n| 492 // Compare the populated |requestorOrigin| against |test.serializedOrigi n|
493 fetchContext->populateRequestData(request); 493 fetchContext->populateRequestData(request);
494 if (strlen(test.serializedOrigin) == 0) 494 if (strlen(test.serializedOrigin) == 0)
495 EXPECT_FALSE(request.requestorOrigin().get()); 495 EXPECT_TRUE(request.requestorOrigin()->isUnique());
496 else 496 else
497 EXPECT_EQ(String(test.serializedOrigin), request.requestorOrigin()-> toString()); 497 EXPECT_EQ(String(test.serializedOrigin), request.requestorOrigin()-> toString());
498 498
499 EXPECT_EQ(document->firstPartyForCookies(), request.firstPartyForCookies ()); 499 EXPECT_EQ(document->firstPartyForCookies(), request.firstPartyForCookies ());
500 } 500 }
501 } 501 }
502 502
503 TEST_F(FrameFetchContextTest, ModifyPriorityForLowPriorityIframes) 503 TEST_F(FrameFetchContextTest, ModifyPriorityForLowPriorityIframes)
504 { 504 {
505 Settings* settings = document->frame()->settings(); 505 Settings* settings = document->frame()->settings();
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 fetchContext->addAdditionalRequestHeaders(mainRequest, FetchMainResource ); 687 fetchContext->addAdditionalRequestHeaders(mainRequest, FetchMainResource );
688 EXPECT_EQ(test.isExternalExpectation, mainRequest.isExternalRequest()); 688 EXPECT_EQ(test.isExternalExpectation, mainRequest.isExternalRequest());
689 689
690 ResourceRequest subRequest(test.url); 690 ResourceRequest subRequest(test.url);
691 fetchContext->addAdditionalRequestHeaders(subRequest, FetchSubresource); 691 fetchContext->addAdditionalRequestHeaders(subRequest, FetchSubresource);
692 EXPECT_EQ(test.isExternalExpectation, subRequest.isExternalRequest()); 692 EXPECT_EQ(test.isExternalExpectation, subRequest.isExternalRequest());
693 } 693 }
694 } 694 }
695 695
696 } // namespace blink 696 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/loader/FrameFetchContext.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698