| 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 25 matching lines...) Expand all Loading... |
| 36 #include "core/frame/FrameView.h" | 36 #include "core/frame/FrameView.h" |
| 37 #include "core/frame/Settings.h" | 37 #include "core/frame/Settings.h" |
| 38 #include "core/html/HTMLDocument.h" | 38 #include "core/html/HTMLDocument.h" |
| 39 #include "core/loader/DocumentLoader.h" | 39 #include "core/loader/DocumentLoader.h" |
| 40 #include "core/loader/EmptyClients.h" | 40 #include "core/loader/EmptyClients.h" |
| 41 #include "core/page/Page.h" | 41 #include "core/page/Page.h" |
| 42 #include "core/testing/DummyPageHolder.h" | 42 #include "core/testing/DummyPageHolder.h" |
| 43 #include "platform/network/ResourceRequest.h" | 43 #include "platform/network/ResourceRequest.h" |
| 44 #include "platform/weborigin/KURL.h" | 44 #include "platform/weborigin/KURL.h" |
| 45 #include "public/platform/WebAddressSpace.h" | 45 #include "public/platform/WebAddressSpace.h" |
| 46 #include "public/platform/WebCachePolicy.h" |
| 46 #include "testing/gmock/include/gmock/gmock-generated-function-mockers.h" | 47 #include "testing/gmock/include/gmock/gmock-generated-function-mockers.h" |
| 47 #include "testing/gtest/include/gtest/gtest.h" | 48 #include "testing/gtest/include/gtest/gtest.h" |
| 48 | 49 |
| 49 namespace blink { | 50 namespace blink { |
| 50 | 51 |
| 51 class StubFrameLoaderClientWithParent final : public EmptyFrameLoaderClient { | 52 class StubFrameLoaderClientWithParent final : public EmptyFrameLoaderClient { |
| 52 public: | 53 public: |
| 53 static RawPtr<StubFrameLoaderClientWithParent> create(Frame* parent) | 54 static RawPtr<StubFrameLoaderClientWithParent> create(Frame* parent) |
| 54 { | 55 { |
| 55 return new StubFrameLoaderClientWithParent(parent); | 56 return new StubFrameLoaderClientWithParent(parent); |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 document->clientHintsPreferences().updateFrom(preferences); | 389 document->clientHintsPreferences().updateFrom(preferences); |
| 389 expectHeader("http://www.example.com/1.gif", "DPR", true, "1"); | 390 expectHeader("http://www.example.com/1.gif", "DPR", true, "1"); |
| 390 expectHeader("http://www.example.com/1.gif", "Width", true, "400", 400); | 391 expectHeader("http://www.example.com/1.gif", "Width", true, "400", 400); |
| 391 expectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "500"); | 392 expectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "500"); |
| 392 } | 393 } |
| 393 | 394 |
| 394 TEST_F(FrameFetchContextTest, MainResource) | 395 TEST_F(FrameFetchContextTest, MainResource) |
| 395 { | 396 { |
| 396 // Default case | 397 // Default case |
| 397 ResourceRequest request("http://www.example.com"); | 398 ResourceRequest request("http://www.example.com"); |
| 398 EXPECT_EQ(UseProtocolCachePolicy, fetchContext->resourceRequestCachePolicy(r
equest, Resource::MainResource)); | 399 EXPECT_EQ(WebCachePolicy::UseProtocolCachePolicy, fetchContext->resourceRequ
estCachePolicy(request, Resource::MainResource)); |
| 399 | 400 |
| 400 // Post | 401 // Post |
| 401 ResourceRequest postRequest("http://www.example.com"); | 402 ResourceRequest postRequest("http://www.example.com"); |
| 402 postRequest.setHTTPMethod("POST"); | 403 postRequest.setHTTPMethod("POST"); |
| 403 EXPECT_EQ(ValidatingCacheData, fetchContext->resourceRequestCachePolicy(post
Request, Resource::MainResource)); | 404 EXPECT_EQ(WebCachePolicy::ValidatingCacheData, fetchContext->resourceRequest
CachePolicy(postRequest, Resource::MainResource)); |
| 404 | 405 |
| 405 // Re-post | 406 // Re-post |
| 406 document->frame()->loader().setLoadType(FrameLoadTypeBackForward); | 407 document->frame()->loader().setLoadType(FrameLoadTypeBackForward); |
| 407 EXPECT_EQ(ReturnCacheDataDontLoad, fetchContext->resourceRequestCachePolicy(
postRequest, Resource::MainResource)); | 408 EXPECT_EQ(WebCachePolicy::ReturnCacheDataDontLoad, fetchContext->resourceReq
uestCachePolicy(postRequest, Resource::MainResource)); |
| 408 | 409 |
| 409 // Enconding overriden | 410 // Enconding overriden |
| 410 document->frame()->loader().setLoadType(FrameLoadTypeStandard); | 411 document->frame()->loader().setLoadType(FrameLoadTypeStandard); |
| 411 document->frame()->host()->setOverrideEncoding("foo"); | 412 document->frame()->host()->setOverrideEncoding("foo"); |
| 412 EXPECT_EQ(ReturnCacheDataElseLoad, fetchContext->resourceRequestCachePolicy(
request, Resource::MainResource)); | 413 EXPECT_EQ(WebCachePolicy::ReturnCacheDataElseLoad, fetchContext->resourceReq
uestCachePolicy(request, Resource::MainResource)); |
| 413 document->frame()->host()->setOverrideEncoding(AtomicString()); | 414 document->frame()->host()->setOverrideEncoding(AtomicString()); |
| 414 | 415 |
| 415 // FrameLoadTypeSame | 416 // FrameLoadTypeSame |
| 416 document->frame()->loader().setLoadType(FrameLoadTypeSame); | 417 document->frame()->loader().setLoadType(FrameLoadTypeSame); |
| 417 EXPECT_EQ(ValidatingCacheData, fetchContext->resourceRequestCachePolicy(requ
est, Resource::MainResource)); | 418 EXPECT_EQ(WebCachePolicy::ValidatingCacheData, fetchContext->resourceRequest
CachePolicy(request, Resource::MainResource)); |
| 418 | 419 |
| 419 // Conditional request | 420 // Conditional request |
| 420 document->frame()->loader().setLoadType(FrameLoadTypeStandard); | 421 document->frame()->loader().setLoadType(FrameLoadTypeStandard); |
| 421 ResourceRequest conditional("http://www.example.com"); | 422 ResourceRequest conditional("http://www.example.com"); |
| 422 conditional.setHTTPHeaderField(HTTPNames::If_Modified_Since, "foo"); | 423 conditional.setHTTPHeaderField(HTTPNames::If_Modified_Since, "foo"); |
| 423 EXPECT_EQ(ValidatingCacheData, fetchContext->resourceRequestCachePolicy(cond
itional, Resource::MainResource)); | 424 EXPECT_EQ(WebCachePolicy::ValidatingCacheData, fetchContext->resourceRequest
CachePolicy(conditional, Resource::MainResource)); |
| 424 | 425 |
| 425 // Set up a child frame | 426 // Set up a child frame |
| 426 FrameFetchContext* childFetchContext = createChildFrame(); | 427 FrameFetchContext* childFetchContext = createChildFrame(); |
| 427 | 428 |
| 428 // Child frame as part of back/forward | 429 // Child frame as part of back/forward |
| 429 document->frame()->loader().setLoadType(FrameLoadTypeBackForward); | 430 document->frame()->loader().setLoadType(FrameLoadTypeBackForward); |
| 430 EXPECT_EQ(ReturnCacheDataElseLoad, childFetchContext->resourceRequestCachePo
licy(request, Resource::MainResource)); | 431 EXPECT_EQ(WebCachePolicy::ReturnCacheDataElseLoad, childFetchContext->resour
ceRequestCachePolicy(request, Resource::MainResource)); |
| 431 | 432 |
| 432 // Child frame as part of reload | 433 // Child frame as part of reload |
| 433 document->frame()->loader().setLoadType(FrameLoadTypeReload); | 434 document->frame()->loader().setLoadType(FrameLoadTypeReload); |
| 434 EXPECT_EQ(ValidatingCacheData, childFetchContext->resourceRequestCachePolicy
(request, Resource::MainResource)); | 435 EXPECT_EQ(WebCachePolicy::ValidatingCacheData, childFetchContext->resourceRe
questCachePolicy(request, Resource::MainResource)); |
| 435 | 436 |
| 436 // Child frame as part of reload bypassing cache | 437 // Child frame as part of reload bypassing cache |
| 437 document->frame()->loader().setLoadType(FrameLoadTypeReloadBypassingCache); | 438 document->frame()->loader().setLoadType(FrameLoadTypeReloadBypassingCache); |
| 438 EXPECT_EQ(BypassingCache, childFetchContext->resourceRequestCachePolicy(requ
est, Resource::MainResource)); | 439 EXPECT_EQ(WebCachePolicy::BypassingCache, childFetchContext->resourceRequest
CachePolicy(request, Resource::MainResource)); |
| 439 } | 440 } |
| 440 | 441 |
| 441 TEST_F(FrameFetchContextTest, ModifyPriorityForExperiments) | 442 TEST_F(FrameFetchContextTest, ModifyPriorityForExperiments) |
| 442 { | 443 { |
| 443 Settings* settings = document->frame()->settings(); | 444 Settings* settings = document->frame()->settings(); |
| 444 FetchRequest request(ResourceRequest("http://www.example.com"), FetchInitiat
orInfo()); | 445 FetchRequest request(ResourceRequest("http://www.example.com"), FetchInitiat
orInfo()); |
| 445 | 446 |
| 446 FetchRequest preloadRequest(ResourceRequest("http://www.example.com"), Fetch
InitiatorInfo()); | 447 FetchRequest preloadRequest(ResourceRequest("http://www.example.com"), Fetch
InitiatorInfo()); |
| 447 preloadRequest.setForPreload(true); | 448 preloadRequest.setForPreload(true); |
| 448 | 449 |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 709 fetchContext->addAdditionalRequestHeaders(mainRequest, FetchMainResource
); | 710 fetchContext->addAdditionalRequestHeaders(mainRequest, FetchMainResource
); |
| 710 EXPECT_EQ(mainRequest.isExternalRequest(), test.isExternalExpectation); | 711 EXPECT_EQ(mainRequest.isExternalRequest(), test.isExternalExpectation); |
| 711 | 712 |
| 712 ResourceRequest subRequest(test.url); | 713 ResourceRequest subRequest(test.url); |
| 713 fetchContext->addAdditionalRequestHeaders(subRequest, FetchSubresource); | 714 fetchContext->addAdditionalRequestHeaders(subRequest, FetchSubresource); |
| 714 EXPECT_EQ(subRequest.isExternalRequest(), test.isExternalExpectation); | 715 EXPECT_EQ(subRequest.isExternalRequest(), test.isExternalExpectation); |
| 715 } | 716 } |
| 716 } | 717 } |
| 717 | 718 |
| 718 } // namespace blink | 719 } // namespace blink |
| OLD | NEW |