| OLD | NEW |
| 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 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 float width = 0) { | 437 float width = 0) { |
| 438 KURL inputURL(ParsedURLString, input); | 438 KURL inputURL(ParsedURLString, input); |
| 439 FetchRequest fetchRequest = | 439 FetchRequest fetchRequest = |
| 440 FetchRequest(ResourceRequest(inputURL), FetchInitiatorInfo()); | 440 FetchRequest(ResourceRequest(inputURL), FetchInitiatorInfo()); |
| 441 if (width > 0) { | 441 if (width > 0) { |
| 442 FetchRequest::ResourceWidth resourceWidth; | 442 FetchRequest::ResourceWidth resourceWidth; |
| 443 resourceWidth.width = width; | 443 resourceWidth.width = width; |
| 444 resourceWidth.isSet = true; | 444 resourceWidth.isSet = true; |
| 445 fetchRequest.setResourceWidth(resourceWidth); | 445 fetchRequest.setResourceWidth(resourceWidth); |
| 446 } | 446 } |
| 447 fetchContext->addClientHintsIfNecessary(fetchRequest); | 447 fetchContext->addClientHintsIfNecessary( |
| 448 fetchRequest.clientHintsPreferences(), fetchRequest.getResourceWidth(), |
| 449 fetchRequest.mutableResourceRequest()); |
| 448 | 450 |
| 449 EXPECT_EQ(isPresent ? String(headerValue) : String(), | 451 EXPECT_EQ(isPresent ? String(headerValue) : String(), |
| 450 fetchRequest.resourceRequest().httpHeaderField(headerName)); | 452 fetchRequest.resourceRequest().httpHeaderField(headerName)); |
| 451 } | 453 } |
| 452 }; | 454 }; |
| 453 | 455 |
| 454 TEST_F(FrameFetchContextHintsTest, MonitorDPRHints) { | 456 TEST_F(FrameFetchContextHintsTest, MonitorDPRHints) { |
| 455 expectHeader("http://www.example.com/1.gif", "DPR", false, ""); | 457 expectHeader("http://www.example.com/1.gif", "DPR", false, ""); |
| 456 ClientHintsPreferences preferences; | 458 ClientHintsPreferences preferences; |
| 457 preferences.setShouldSendDPR(true); | 459 preferences.setShouldSendDPR(true); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 childFetchContext->resourceRequestCachePolicy( | 556 childFetchContext->resourceRequestCachePolicy( |
| 555 request, Resource::MainResource, FetchRequest::NoDefer)); | 557 request, Resource::MainResource, FetchRequest::NoDefer)); |
| 556 | 558 |
| 557 // Child frame as part of reload bypassing cache | 559 // Child frame as part of reload bypassing cache |
| 558 document->frame()->loader().setLoadType(FrameLoadTypeReloadBypassingCache); | 560 document->frame()->loader().setLoadType(FrameLoadTypeReloadBypassingCache); |
| 559 EXPECT_EQ(WebCachePolicy::BypassingCache, | 561 EXPECT_EQ(WebCachePolicy::BypassingCache, |
| 560 childFetchContext->resourceRequestCachePolicy( | 562 childFetchContext->resourceRequestCachePolicy( |
| 561 request, Resource::MainResource, FetchRequest::NoDefer)); | 563 request, Resource::MainResource, FetchRequest::NoDefer)); |
| 562 } | 564 } |
| 563 | 565 |
| 564 TEST_F(FrameFetchContextTest, PopulateRequestData) { | 566 TEST_F(FrameFetchContextTest, SetFirstPartyCookieAndRequestorOrigin) { |
| 565 struct TestCase { | 567 struct TestCase { |
| 566 const char* documentURL; | 568 const char* documentURL; |
| 567 bool documentSandboxed; | 569 bool documentSandboxed; |
| 568 const char* requestorOrigin; // "" => unique origin | 570 const char* requestorOrigin; // "" => unique origin |
| 569 WebURLRequest::FrameType frameType; | 571 WebURLRequest::FrameType frameType; |
| 570 const char* serializedOrigin; // "" => unique origin | 572 const char* serializedOrigin; // "" => unique origin |
| 571 } cases[] = { | 573 } cases[] = { |
| 572 // No document origin => unique request origin | 574 // No document origin => unique request origin |
| 573 {"", false, "", WebURLRequest::FrameTypeNone, "null"}, | 575 {"", false, "", WebURLRequest::FrameTypeNone, "null"}, |
| 574 {"", true, "", WebURLRequest::FrameTypeNone, "null"}, | 576 {"", true, "", WebURLRequest::FrameTypeNone, "null"}, |
| 575 | 577 |
| 576 // Document origin => request origin | 578 // Document origin => request origin |
| 577 {"http://example.test", false, "", WebURLRequest::FrameTypeNone, | 579 {"http://example.test", false, "", WebURLRequest::FrameTypeNone, |
| 578 "http://example.test"}, | 580 "http://example.test"}, |
| 579 {"http://example.test", true, "", WebURLRequest::FrameTypeNone, | 581 {"http://example.test", true, "", WebURLRequest::FrameTypeNone, |
| 580 "http://example.test"}, | 582 "http://example.test"}, |
| 581 | 583 |
| 582 // If the request already has a requestor origin, then | 584 // If the request already has a requestor origin, then |
| 583 // 'populateRequestData' leaves it alone: | 585 // 'setFirstPartyCookieAndRequestorOrigin' leaves it alone: |
| 584 {"http://example.test", false, "http://not-example.test", | 586 {"http://example.test", false, "http://not-example.test", |
| 585 WebURLRequest::FrameTypeNone, "http://not-example.test"}, | 587 WebURLRequest::FrameTypeNone, "http://not-example.test"}, |
| 586 {"http://example.test", true, "http://not-example.test", | 588 {"http://example.test", true, "http://not-example.test", |
| 587 WebURLRequest::FrameTypeNone, "http://not-example.test"}, | 589 WebURLRequest::FrameTypeNone, "http://not-example.test"}, |
| 588 | 590 |
| 589 // If the request's frame type is not 'none', then 'populateRequestData' | 591 // If the request's frame type is not 'none', then |
| 592 // 'setFirstPartyCookieAndRequestorOrigin' |
| 590 // leaves it alone: | 593 // leaves it alone: |
| 591 {"http://example.test", false, "", WebURLRequest::FrameTypeTopLevel, ""}, | 594 {"http://example.test", false, "", WebURLRequest::FrameTypeTopLevel, ""}, |
| 592 {"http://example.test", false, "", WebURLRequest::FrameTypeAuxiliary, ""}, | 595 {"http://example.test", false, "", WebURLRequest::FrameTypeAuxiliary, ""}, |
| 593 {"http://example.test", false, "", WebURLRequest::FrameTypeNested, ""}, | 596 {"http://example.test", false, "", WebURLRequest::FrameTypeNested, ""}, |
| 594 }; | 597 }; |
| 595 | 598 |
| 596 for (const auto& test : cases) { | 599 for (const auto& test : cases) { |
| 597 SCOPED_TRACE(::testing::Message() << test.documentURL << " => " | 600 SCOPED_TRACE(::testing::Message() << test.documentURL << " => " |
| 598 << test.serializedOrigin); | 601 << test.serializedOrigin); |
| 599 // Set up a new document to ensure sandbox flags are cleared: | 602 // Set up a new document to ensure sandbox flags are cleared: |
| (...skipping 10 matching lines...) Expand all Loading... |
| 610 document->enforceSandboxFlags(SandboxOrigin); | 613 document->enforceSandboxFlags(SandboxOrigin); |
| 611 | 614 |
| 612 ResourceRequest request("http://example.test/"); | 615 ResourceRequest request("http://example.test/"); |
| 613 request.setFrameType(test.frameType); | 616 request.setFrameType(test.frameType); |
| 614 if (strlen(test.requestorOrigin) > 0) { | 617 if (strlen(test.requestorOrigin) > 0) { |
| 615 request.setRequestorOrigin( | 618 request.setRequestorOrigin( |
| 616 SecurityOrigin::create(KURL(ParsedURLString, test.requestorOrigin))); | 619 SecurityOrigin::create(KURL(ParsedURLString, test.requestorOrigin))); |
| 617 } | 620 } |
| 618 | 621 |
| 619 // Compare the populated |requestorOrigin| against |test.serializedOrigin| | 622 // Compare the populated |requestorOrigin| against |test.serializedOrigin| |
| 620 fetchContext->populateRequestData(request); | 623 fetchContext->setFirstPartyCookieAndRequestorOrigin(request); |
| 621 if (strlen(test.serializedOrigin) == 0) { | 624 if (strlen(test.serializedOrigin) == 0) { |
| 622 EXPECT_TRUE(request.requestorOrigin()->isUnique()); | 625 EXPECT_TRUE(request.requestorOrigin()->isUnique()); |
| 623 } else { | 626 } else { |
| 624 EXPECT_EQ(String(test.serializedOrigin), | 627 EXPECT_EQ(String(test.serializedOrigin), |
| 625 request.requestorOrigin()->toString()); | 628 request.requestorOrigin()->toString()); |
| 626 } | 629 } |
| 627 | 630 |
| 628 EXPECT_EQ(document->firstPartyForCookies(), request.firstPartyForCookies()); | 631 EXPECT_EQ(document->firstPartyForCookies(), request.firstPartyForCookies()); |
| 629 } | 632 } |
| 630 } | 633 } |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 827 fetchContext->addAdditionalRequestHeaders(mainRequest, FetchMainResource); | 830 fetchContext->addAdditionalRequestHeaders(mainRequest, FetchMainResource); |
| 828 EXPECT_EQ(test.isExternalExpectation, mainRequest.isExternalRequest()); | 831 EXPECT_EQ(test.isExternalExpectation, mainRequest.isExternalRequest()); |
| 829 | 832 |
| 830 ResourceRequest subRequest(test.url); | 833 ResourceRequest subRequest(test.url); |
| 831 fetchContext->addAdditionalRequestHeaders(subRequest, FetchSubresource); | 834 fetchContext->addAdditionalRequestHeaders(subRequest, FetchSubresource); |
| 832 EXPECT_EQ(test.isExternalExpectation, subRequest.isExternalRequest()); | 835 EXPECT_EQ(test.isExternalExpectation, subRequest.isExternalRequest()); |
| 833 } | 836 } |
| 834 } | 837 } |
| 835 | 838 |
| 836 } // namespace blink | 839 } // namespace blink |
| OLD | NEW |