| 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 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 ClientHintsPreferences preferences; | 541 ClientHintsPreferences preferences; |
| 542 preferences.setShouldSendDPR(true); | 542 preferences.setShouldSendDPR(true); |
| 543 preferences.setShouldSendResourceWidth(true); | 543 preferences.setShouldSendResourceWidth(true); |
| 544 preferences.setShouldSendViewportWidth(true); | 544 preferences.setShouldSendViewportWidth(true); |
| 545 document->clientHintsPreferences().updateFrom(preferences); | 545 document->clientHintsPreferences().updateFrom(preferences); |
| 546 expectHeader("http://www.example.com/1.gif", "DPR", true, "1"); | 546 expectHeader("http://www.example.com/1.gif", "DPR", true, "1"); |
| 547 expectHeader("http://www.example.com/1.gif", "Width", true, "400", 400); | 547 expectHeader("http://www.example.com/1.gif", "Width", true, "400", 400); |
| 548 expectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "500"); | 548 expectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "500"); |
| 549 } | 549 } |
| 550 | 550 |
| 551 TEST_F(FrameFetchContextTest, MainResource) { | 551 TEST_F(FrameFetchContextTest, MainResourceCachePolicy) { |
| 552 // Default case | 552 // Default case |
| 553 ResourceRequest request("http://www.example.com"); | 553 ResourceRequest request("http://www.example.com"); |
| 554 EXPECT_EQ(WebCachePolicy::UseProtocolCachePolicy, | 554 EXPECT_EQ(WebCachePolicy::UseProtocolCachePolicy, |
| 555 fetchContext->resourceRequestCachePolicy( | 555 fetchContext->resourceRequestCachePolicy( |
| 556 request, Resource::MainResource, FetchRequest::NoDefer)); | 556 request, Resource::MainResource, FetchRequest::NoDefer)); |
| 557 | 557 |
| 558 // Post | 558 // Post |
| 559 ResourceRequest postRequest("http://www.example.com"); | 559 ResourceRequest postRequest("http://www.example.com"); |
| 560 postRequest.setHTTPMethod("POST"); | 560 postRequest.setHTTPMethod("POST"); |
| 561 EXPECT_EQ(WebCachePolicy::ValidatingCacheData, | 561 EXPECT_EQ(WebCachePolicy::ValidatingCacheData, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 childFetchContext->resourceRequestCachePolicy( | 597 childFetchContext->resourceRequestCachePolicy( |
| 598 request, Resource::MainResource, FetchRequest::NoDefer)); | 598 request, Resource::MainResource, FetchRequest::NoDefer)); |
| 599 | 599 |
| 600 // Child frame as part of reload bypassing cache | 600 // Child frame as part of reload bypassing cache |
| 601 document->loader()->setLoadType(FrameLoadTypeReloadBypassingCache); | 601 document->loader()->setLoadType(FrameLoadTypeReloadBypassingCache); |
| 602 EXPECT_EQ(WebCachePolicy::BypassingCache, | 602 EXPECT_EQ(WebCachePolicy::BypassingCache, |
| 603 childFetchContext->resourceRequestCachePolicy( | 603 childFetchContext->resourceRequestCachePolicy( |
| 604 request, Resource::MainResource, FetchRequest::NoDefer)); | 604 request, Resource::MainResource, FetchRequest::NoDefer)); |
| 605 } | 605 } |
| 606 | 606 |
| 607 TEST_F(FrameFetchContextTest, SubResourceCachePolicy) { |
| 608 // Default case |
| 609 ResourceRequest request("http://www.example.com/mock"); |
| 610 EXPECT_EQ(WebCachePolicy::UseProtocolCachePolicy, |
| 611 fetchContext->resourceRequestCachePolicy(request, Resource::Mock, |
| 612 FetchRequest::NoDefer)); |
| 613 |
| 614 // FrameLoadTypeReload should not affect sub-resources |
| 615 document->loader()->setLoadType(FrameLoadTypeReload); |
| 616 EXPECT_EQ(WebCachePolicy::UseProtocolCachePolicy, |
| 617 fetchContext->resourceRequestCachePolicy(request, Resource::Mock, |
| 618 FetchRequest::NoDefer)); |
| 619 |
| 620 // Conditional request |
| 621 document->loader()->setLoadType(FrameLoadTypeStandard); |
| 622 ResourceRequest conditional("http://www.example.com/mock"); |
| 623 conditional.setHTTPHeaderField(HTTPNames::If_Modified_Since, "foo"); |
| 624 EXPECT_EQ(WebCachePolicy::ValidatingCacheData, |
| 625 fetchContext->resourceRequestCachePolicy( |
| 626 conditional, Resource::Mock, FetchRequest::NoDefer)); |
| 627 |
| 628 // FrameLoadTypeReloadBypassingCache |
| 629 document->loader()->setLoadType(FrameLoadTypeReloadBypassingCache); |
| 630 EXPECT_EQ(WebCachePolicy::BypassingCache, |
| 631 fetchContext->resourceRequestCachePolicy(request, Resource::Mock, |
| 632 FetchRequest::NoDefer)); |
| 633 |
| 634 // FrameLoadTypeReloadBypassingCache with a conditional request |
| 635 document->loader()->setLoadType(FrameLoadTypeReloadBypassingCache); |
| 636 EXPECT_EQ(WebCachePolicy::BypassingCache, |
| 637 fetchContext->resourceRequestCachePolicy( |
| 638 conditional, Resource::Mock, FetchRequest::NoDefer)); |
| 639 |
| 640 // Back/forward navigation |
| 641 document->loader()->setLoadType(FrameLoadTypeBackForward); |
| 642 EXPECT_EQ(WebCachePolicy::ReturnCacheDataElseLoad, |
| 643 fetchContext->resourceRequestCachePolicy(request, Resource::Mock, |
| 644 FetchRequest::NoDefer)); |
| 645 |
| 646 // Back/forward navigation with a conditional request |
| 647 document->loader()->setLoadType(FrameLoadTypeBackForward); |
| 648 EXPECT_EQ(WebCachePolicy::ReturnCacheDataElseLoad, |
| 649 fetchContext->resourceRequestCachePolicy( |
| 650 conditional, Resource::Mock, FetchRequest::NoDefer)); |
| 651 } |
| 652 |
| 607 TEST_F(FrameFetchContextTest, SetFirstPartyCookieAndRequestorOrigin) { | 653 TEST_F(FrameFetchContextTest, SetFirstPartyCookieAndRequestorOrigin) { |
| 608 struct TestCase { | 654 struct TestCase { |
| 609 const char* documentURL; | 655 const char* documentURL; |
| 610 bool documentSandboxed; | 656 bool documentSandboxed; |
| 611 const char* requestorOrigin; // "" => unique origin | 657 const char* requestorOrigin; // "" => unique origin |
| 612 WebURLRequest::FrameType frameType; | 658 WebURLRequest::FrameType frameType; |
| 613 const char* serializedOrigin; // "" => unique origin | 659 const char* serializedOrigin; // "" => unique origin |
| 614 } cases[] = { | 660 } cases[] = { |
| 615 // No document origin => unique request origin | 661 // No document origin => unique request origin |
| 616 {"", false, "", WebURLRequest::FrameTypeNone, "null"}, | 662 {"", false, "", WebURLRequest::FrameTypeNone, "null"}, |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 931 setFilterPolicy(WebDocumentSubresourceFilter::WouldDisallow); | 977 setFilterPolicy(WebDocumentSubresourceFilter::WouldDisallow); |
| 932 | 978 |
| 933 EXPECT_EQ(ResourceRequestBlockedReason::None, canRequest()); | 979 EXPECT_EQ(ResourceRequestBlockedReason::None, canRequest()); |
| 934 EXPECT_EQ(0, getFilteredLoadCallCount()); | 980 EXPECT_EQ(0, getFilteredLoadCallCount()); |
| 935 | 981 |
| 936 EXPECT_EQ(ResourceRequestBlockedReason::None, canRequestPreload()); | 982 EXPECT_EQ(ResourceRequestBlockedReason::None, canRequestPreload()); |
| 937 EXPECT_EQ(0, getFilteredLoadCallCount()); | 983 EXPECT_EQ(0, getFilteredLoadCallCount()); |
| 938 } | 984 } |
| 939 | 985 |
| 940 } // namespace blink | 986 } // namespace blink |
| OLD | NEW |