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

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

Issue 2332023002: Correctly set requestor origin for worker initiated requests. (Closed)
Patch Set: 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 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
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) 451 TEST_F(FrameFetchContextTest, PopulateRequestData)
452 { 452 {
453 struct TestCase { 453 struct TestCase {
454 const char* documentURL; 454 const char* documentURL;
455 bool documentSandboxed; 455 bool documentSandboxed;
456 const char* requestorOrigin; // "" => nullptr, "null" => unique origin 456 const char* requestorOrigin; // "" => unique origin
457 WebURLRequest::FrameType frameType; 457 WebURLRequest::FrameType frameType;
458 const char* serializedOrigin; // "" => nullptr, "null" => unique origin 458 const char* serializedOrigin; // "" => unique origin
459 } cases[] = { 459 } cases[] = {
460 // No document origin => unique request origin 460 // No document origin => unique request origin
461 { "", false, "", WebURLRequest::FrameTypeNone, "null" }, 461 { "", false, "", WebURLRequest::FrameTypeNone, "null" },
462 { "", true, "", WebURLRequest::FrameTypeNone, "null" }, 462 { "", true, "", WebURLRequest::FrameTypeNone, "null" },
463 463
464 // Document origin => request origin 464 // Document origin => request origin
465 { "http://example.test", false, "", WebURLRequest::FrameTypeNone, "http: //example.test" }, 465 { "http://example.test", false, "", WebURLRequest::FrameTypeNone, "http: //example.test" },
466 { "http://example.test", true, "", WebURLRequest::FrameTypeNone, "http:/ /example.test" }, 466 { "http://example.test", true, "", WebURLRequest::FrameTypeNone, "http:/ /example.test" },
467 467
468 // If the request already has a requestor origin, then 'populateRequestD ata' leaves it alone: 468 // If the request already has a requestor origin, then 'populateRequestD ata' leaves it alone:
(...skipping 17 matching lines...) Expand all
486 // Setup the test: 486 // Setup the test:
487 document->setURL(KURL(ParsedURLString, test.documentURL)); 487 document->setURL(KURL(ParsedURLString, test.documentURL));
488 document->setSecurityOrigin(SecurityOrigin::create(document->url())); 488 document->setSecurityOrigin(SecurityOrigin::create(document->url()));
489 489
490 if (test.documentSandboxed) 490 if (test.documentSandboxed)
491 document->enforceSandboxFlags(SandboxOrigin); 491 document->enforceSandboxFlags(SandboxOrigin);
492 492
493 ResourceRequest request("http://example.test/"); 493 ResourceRequest request("http://example.test/");
494 request.setFrameType(test.frameType); 494 request.setFrameType(test.frameType);
495 if (strlen(test.requestorOrigin) == 0) 495 if (strlen(test.requestorOrigin) == 0)
496 request.setRequestorOrigin(nullptr); 496 request.setRequestorOrigin(SecurityOrigin::createUnique());
497 else 497 else
498 request.setRequestorOrigin(SecurityOrigin::create(KURL(ParsedURLStri ng, test.requestorOrigin))); 498 request.setRequestorOrigin(SecurityOrigin::create(KURL(ParsedURLStri ng, test.requestorOrigin)));
499 499
500 // Compare the populated |requestorOrigin| against |test.serializedOrigi n| 500 // Compare the populated |requestorOrigin| against |test.serializedOrigi n|
501 fetchContext->populateRequestData(request); 501 fetchContext->populateRequestData(request);
502 if (strlen(test.serializedOrigin) == 0) 502 if (strlen(test.serializedOrigin) == 0)
503 EXPECT_EQ(nullptr, request.requestorOrigin().get()); 503 EXPECT_TRUE(request.requestorOrigin()->isUnique());
504 else 504 else
505 EXPECT_EQ(String(test.serializedOrigin), request.requestorOrigin()-> toString()); 505 EXPECT_EQ(String(test.serializedOrigin), request.requestorOrigin()-> toString());
506 506
507 EXPECT_EQ(document->firstPartyForCookies(), request.firstPartyForCookies ()); 507 EXPECT_EQ(document->firstPartyForCookies(), request.firstPartyForCookies ());
508 } 508 }
509 } 509 }
510 510
511 TEST_F(FrameFetchContextTest, ModifyPriorityForLowPriorityIframes) 511 TEST_F(FrameFetchContextTest, ModifyPriorityForLowPriorityIframes)
512 { 512 {
513 Settings* settings = document->frame()->settings(); 513 Settings* settings = document->frame()->settings();
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 fetchContext->addAdditionalRequestHeaders(mainRequest, FetchMainResource ); 696 fetchContext->addAdditionalRequestHeaders(mainRequest, FetchMainResource );
697 EXPECT_EQ(mainRequest.isExternalRequest(), test.isExternalExpectation); 697 EXPECT_EQ(mainRequest.isExternalRequest(), test.isExternalExpectation);
698 698
699 ResourceRequest subRequest(test.url); 699 ResourceRequest subRequest(test.url);
700 fetchContext->addAdditionalRequestHeaders(subRequest, FetchSubresource); 700 fetchContext->addAdditionalRequestHeaders(subRequest, FetchSubresource);
701 EXPECT_EQ(subRequest.isExternalRequest(), test.isExternalExpectation); 701 EXPECT_EQ(subRequest.isExternalRequest(), test.isExternalExpectation);
702 } 702 }
703 } 703 }
704 704
705 } // namespace blink 705 } // 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