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

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

Issue 2555713002: Don't use FetchRequest in FrameFetchContext (Closed)
Patch Set: a Created 3 years, 11 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 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 float width = 0) { 421 float width = 0) {
422 KURL inputURL(ParsedURLString, input); 422 KURL inputURL(ParsedURLString, input);
423 FetchRequest fetchRequest = 423 FetchRequest fetchRequest =
424 FetchRequest(ResourceRequest(inputURL), FetchInitiatorInfo()); 424 FetchRequest(ResourceRequest(inputURL), FetchInitiatorInfo());
425 if (width > 0) { 425 if (width > 0) {
426 FetchRequest::ResourceWidth resourceWidth; 426 FetchRequest::ResourceWidth resourceWidth;
427 resourceWidth.width = width; 427 resourceWidth.width = width;
428 resourceWidth.isSet = true; 428 resourceWidth.isSet = true;
429 fetchRequest.setResourceWidth(resourceWidth); 429 fetchRequest.setResourceWidth(resourceWidth);
430 } 430 }
431 fetchContext->addClientHintsIfNecessary(fetchRequest); 431 fetchContext->addClientHintsIfNecessary(
432 fetchRequest.clientHintsPreferences(), fetchRequest.getResourceWidth(),
433 fetchRequest.mutableResourceRequest());
432 434
433 EXPECT_EQ(isPresent ? String(headerValue) : String(), 435 EXPECT_EQ(isPresent ? String(headerValue) : String(),
434 fetchRequest.resourceRequest().httpHeaderField(headerName)); 436 fetchRequest.resourceRequest().httpHeaderField(headerName));
435 } 437 }
436 }; 438 };
437 439
438 TEST_F(FrameFetchContextHintsTest, MonitorDPRHints) { 440 TEST_F(FrameFetchContextHintsTest, MonitorDPRHints) {
439 expectHeader("http://www.example.com/1.gif", "DPR", false, ""); 441 expectHeader("http://www.example.com/1.gif", "DPR", false, "");
440 ClientHintsPreferences preferences; 442 ClientHintsPreferences preferences;
441 preferences.setShouldSendDPR(true); 443 preferences.setShouldSendDPR(true);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 childFetchContext->resourceRequestCachePolicy( 540 childFetchContext->resourceRequestCachePolicy(
539 request, Resource::MainResource, FetchRequest::NoDefer)); 541 request, Resource::MainResource, FetchRequest::NoDefer));
540 542
541 // Child frame as part of reload bypassing cache 543 // Child frame as part of reload bypassing cache
542 document->frame()->loader().setLoadType(FrameLoadTypeReloadBypassingCache); 544 document->frame()->loader().setLoadType(FrameLoadTypeReloadBypassingCache);
543 EXPECT_EQ(WebCachePolicy::BypassingCache, 545 EXPECT_EQ(WebCachePolicy::BypassingCache,
544 childFetchContext->resourceRequestCachePolicy( 546 childFetchContext->resourceRequestCachePolicy(
545 request, Resource::MainResource, FetchRequest::NoDefer)); 547 request, Resource::MainResource, FetchRequest::NoDefer));
546 } 548 }
547 549
548 TEST_F(FrameFetchContextTest, PopulateRequestData) { 550 TEST_F(FrameFetchContextTest, SetFirstPartyCookieAndRequestorOrigin) {
549 struct TestCase { 551 struct TestCase {
550 const char* documentURL; 552 const char* documentURL;
551 bool documentSandboxed; 553 bool documentSandboxed;
552 const char* requestorOrigin; // "" => unique origin 554 const char* requestorOrigin; // "" => unique origin
553 WebURLRequest::FrameType frameType; 555 WebURLRequest::FrameType frameType;
554 const char* serializedOrigin; // "" => unique origin 556 const char* serializedOrigin; // "" => unique origin
555 } cases[] = { 557 } cases[] = {
556 // No document origin => unique request origin 558 // No document origin => unique request origin
557 {"", false, "", WebURLRequest::FrameTypeNone, "null"}, 559 {"", false, "", WebURLRequest::FrameTypeNone, "null"},
558 {"", true, "", WebURLRequest::FrameTypeNone, "null"}, 560 {"", true, "", WebURLRequest::FrameTypeNone, "null"},
559 561
560 // Document origin => request origin 562 // Document origin => request origin
561 {"http://example.test", false, "", WebURLRequest::FrameTypeNone, 563 {"http://example.test", false, "", WebURLRequest::FrameTypeNone,
562 "http://example.test"}, 564 "http://example.test"},
563 {"http://example.test", true, "", WebURLRequest::FrameTypeNone, 565 {"http://example.test", true, "", WebURLRequest::FrameTypeNone,
564 "http://example.test"}, 566 "http://example.test"},
565 567
566 // If the request already has a requestor origin, then 568 // If the request already has a requestor origin, then
567 // 'populateRequestData' leaves it alone: 569 // 'setFirstPartyCookieAndRequestorOrigin' leaves it alone:
568 {"http://example.test", false, "http://not-example.test", 570 {"http://example.test", false, "http://not-example.test",
569 WebURLRequest::FrameTypeNone, "http://not-example.test"}, 571 WebURLRequest::FrameTypeNone, "http://not-example.test"},
570 {"http://example.test", true, "http://not-example.test", 572 {"http://example.test", true, "http://not-example.test",
571 WebURLRequest::FrameTypeNone, "http://not-example.test"}, 573 WebURLRequest::FrameTypeNone, "http://not-example.test"},
572 574
573 // If the request's frame type is not 'none', then 'populateRequestData' 575 // If the request's frame type is not 'none', then
576 // 'setFirstPartyCookieAndRequestorOrigin'
574 // leaves it alone: 577 // leaves it alone:
575 {"http://example.test", false, "", WebURLRequest::FrameTypeTopLevel, ""}, 578 {"http://example.test", false, "", WebURLRequest::FrameTypeTopLevel, ""},
576 {"http://example.test", false, "", WebURLRequest::FrameTypeAuxiliary, ""}, 579 {"http://example.test", false, "", WebURLRequest::FrameTypeAuxiliary, ""},
577 {"http://example.test", false, "", WebURLRequest::FrameTypeNested, ""}, 580 {"http://example.test", false, "", WebURLRequest::FrameTypeNested, ""},
578 }; 581 };
579 582
580 for (const auto& test : cases) { 583 for (const auto& test : cases) {
581 SCOPED_TRACE(::testing::Message() << test.documentURL << " => " 584 SCOPED_TRACE(::testing::Message() << test.documentURL << " => "
582 << test.serializedOrigin); 585 << test.serializedOrigin);
583 // Set up a new document to ensure sandbox flags are cleared: 586 // Set up a new document to ensure sandbox flags are cleared:
(...skipping 10 matching lines...) Expand all
594 document->enforceSandboxFlags(SandboxOrigin); 597 document->enforceSandboxFlags(SandboxOrigin);
595 598
596 ResourceRequest request("http://example.test/"); 599 ResourceRequest request("http://example.test/");
597 request.setFrameType(test.frameType); 600 request.setFrameType(test.frameType);
598 if (strlen(test.requestorOrigin) > 0) { 601 if (strlen(test.requestorOrigin) > 0) {
599 request.setRequestorOrigin( 602 request.setRequestorOrigin(
600 SecurityOrigin::create(KURL(ParsedURLString, test.requestorOrigin))); 603 SecurityOrigin::create(KURL(ParsedURLString, test.requestorOrigin)));
601 } 604 }
602 605
603 // Compare the populated |requestorOrigin| against |test.serializedOrigin| 606 // Compare the populated |requestorOrigin| against |test.serializedOrigin|
604 fetchContext->populateRequestData(request); 607 fetchContext->setFirstPartyCookieAndRequestorOrigin(request);
605 if (strlen(test.serializedOrigin) == 0) { 608 if (strlen(test.serializedOrigin) == 0) {
606 EXPECT_TRUE(request.requestorOrigin()->isUnique()); 609 EXPECT_TRUE(request.requestorOrigin()->isUnique());
607 } else { 610 } else {
608 EXPECT_EQ(String(test.serializedOrigin), 611 EXPECT_EQ(String(test.serializedOrigin),
609 request.requestorOrigin()->toString()); 612 request.requestorOrigin()->toString());
610 } 613 }
611 614
612 EXPECT_EQ(document->firstPartyForCookies(), request.firstPartyForCookies()); 615 EXPECT_EQ(document->firstPartyForCookies(), request.firstPartyForCookies());
613 } 616 }
614 } 617 }
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 fetchContext->addAdditionalRequestHeaders(mainRequest, FetchMainResource); 814 fetchContext->addAdditionalRequestHeaders(mainRequest, FetchMainResource);
812 EXPECT_EQ(test.isExternalExpectation, mainRequest.isExternalRequest()); 815 EXPECT_EQ(test.isExternalExpectation, mainRequest.isExternalRequest());
813 816
814 ResourceRequest subRequest(test.url); 817 ResourceRequest subRequest(test.url);
815 fetchContext->addAdditionalRequestHeaders(subRequest, FetchSubresource); 818 fetchContext->addAdditionalRequestHeaders(subRequest, FetchSubresource);
816 EXPECT_EQ(test.isExternalExpectation, subRequest.isExternalRequest()); 819 EXPECT_EQ(test.isExternalExpectation, subRequest.isExternalRequest());
817 } 820 }
818 } 821 }
819 822
820 } // namespace blink 823 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698