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 14 matching lines...) Expand all Loading... |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "core/loader/FrameFetchContext.h" | 32 #include "core/loader/FrameFetchContext.h" |
33 | 33 |
34 #include "core/fetch/FetchInitiatorInfo.h" | 34 #include "core/fetch/FetchInitiatorInfo.h" |
| 35 #include "core/frame/FrameHost.h" |
| 36 #include "core/frame/FrameOwner.h" |
35 #include "core/frame/FrameView.h" | 37 #include "core/frame/FrameView.h" |
36 #include "core/html/HTMLDocument.h" | 38 #include "core/html/HTMLDocument.h" |
37 #include "core/loader/DocumentLoader.h" | 39 #include "core/loader/DocumentLoader.h" |
| 40 #include "core/loader/EmptyClients.h" |
38 #include "core/page/Page.h" | 41 #include "core/page/Page.h" |
39 #include "core/testing/DummyPageHolder.h" | 42 #include "core/testing/DummyPageHolder.h" |
40 #include "platform/network/ResourceRequest.h" | 43 #include "platform/network/ResourceRequest.h" |
41 #include "platform/weborigin/KURL.h" | 44 #include "platform/weborigin/KURL.h" |
42 #include <gtest/gtest.h> | 45 #include <gtest/gtest.h> |
43 | 46 |
44 namespace blink { | 47 namespace blink { |
45 | 48 |
46 class FrameFetchContextUpgradeTest : public ::testing::Test { | 49 class FrameFetchContextUpgradeTest : public ::testing::Test { |
47 public: | 50 public: |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 ClientHintsPreferences preferences; | 316 ClientHintsPreferences preferences; |
314 preferences.setShouldSendDPR(true); | 317 preferences.setShouldSendDPR(true); |
315 preferences.setShouldSendResourceWidth(true); | 318 preferences.setShouldSendResourceWidth(true); |
316 preferences.setShouldSendViewportWidth(true); | 319 preferences.setShouldSendViewportWidth(true); |
317 document->setClientHintsPreferences(preferences); | 320 document->setClientHintsPreferences(preferences); |
318 expectHeader("http://www.example.com/1.gif", "DPR", true, "1"); | 321 expectHeader("http://www.example.com/1.gif", "DPR", true, "1"); |
319 expectHeader("http://www.example.com/1.gif", "Width", true, "400", 400); | 322 expectHeader("http://www.example.com/1.gif", "Width", true, "400", 400); |
320 expectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "500"); | 323 expectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "500"); |
321 } | 324 } |
322 | 325 |
| 326 class StubFrameLoaderClientWithParent : public EmptyFrameLoaderClient { |
| 327 public: |
| 328 explicit StubFrameLoaderClientWithParent(Frame* parent) |
| 329 : m_parent(parent) |
| 330 { |
| 331 } |
| 332 |
| 333 Frame* parent() const override { return m_parent; } |
| 334 |
| 335 private: |
| 336 Frame* m_parent; |
| 337 }; |
| 338 |
| 339 class StubFrameOwner : public NoBaseWillBeGarbageCollectedFinalized<StubFrameOwn
er>, public FrameOwner { |
| 340 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(StubFrameOwner); |
| 341 public: |
| 342 DEFINE_INLINE_VIRTUAL_TRACE() { FrameOwner::trace(visitor); } |
| 343 |
| 344 bool isLocal() const override { return false; } |
| 345 SandboxFlags sandboxFlags() const override { return SandboxNone; } |
| 346 void dispatchLoad() override { } |
| 347 void renderFallbackContent() override { } |
| 348 }; |
| 349 |
| 350 class FrameFetchContextCachePolicyTest : public ::testing::Test { |
| 351 public: |
| 352 FrameFetchContextCachePolicyTest() { } |
| 353 |
| 354 protected: |
| 355 void SetUp() override |
| 356 { |
| 357 dummyPageHolder = DummyPageHolder::create(IntSize(500, 500)); |
| 358 dummyPageHolder->page().setDeviceScaleFactor(1.0); |
| 359 documentLoader = DocumentLoader::create(&dummyPageHolder->frame(), Resou
rceRequest("http://www.example.com"), SubstituteData()); |
| 360 document = toHTMLDocument(&dummyPageHolder->document()); |
| 361 fetchContext = static_cast<FrameFetchContext*>(&documentLoader->fetcher(
)->context()); |
| 362 FrameFetchContext::provideDocumentToContext(*fetchContext, document.get(
)); |
| 363 } |
| 364 |
| 365 void TearDown() override |
| 366 { |
| 367 documentLoader->detachFromFrame(); |
| 368 documentLoader.clear(); |
| 369 } |
| 370 |
| 371 OwnPtr<DummyPageHolder> dummyPageHolder; |
| 372 // We don't use the DocumentLoader directly in any tests, but need to keep i
t around as long |
| 373 // as the ResourceFetcher and Document live due to indirect usage. |
| 374 RefPtrWillBePersistent<DocumentLoader> documentLoader; |
| 375 RefPtrWillBePersistent<Document> document; |
| 376 Persistent<FrameFetchContext> fetchContext; |
| 377 }; |
| 378 |
| 379 TEST_F(FrameFetchContextCachePolicyTest, MainResource) |
| 380 { |
| 381 // Default case |
| 382 ResourceRequest request("http://www.example.com"); |
| 383 EXPECT_EQ(UseProtocolCachePolicy, fetchContext->resourceRequestCachePolicy(r
equest, Resource::MainResource)); |
| 384 |
| 385 // Post |
| 386 ResourceRequest postRequest("http://www.example.com"); |
| 387 postRequest.setHTTPMethod("POST"); |
| 388 EXPECT_EQ(ReloadIgnoringCacheData, fetchContext->resourceRequestCachePolicy(
postRequest, Resource::MainResource)); |
| 389 |
| 390 // Re-post |
| 391 document->frame()->loader().setLoadType(FrameLoadTypeBackForward); |
| 392 EXPECT_EQ(ReturnCacheDataDontLoad, fetchContext->resourceRequestCachePolicy(
postRequest, Resource::MainResource)); |
| 393 |
| 394 // Enconding overriden |
| 395 document->frame()->loader().setLoadType(FrameLoadTypeStandard); |
| 396 document->frame()->host()->setOverrideEncoding("foo"); |
| 397 EXPECT_EQ(ReturnCacheDataElseLoad, fetchContext->resourceRequestCachePolicy(
request, Resource::MainResource)); |
| 398 document->frame()->host()->setOverrideEncoding(AtomicString()); |
| 399 |
| 400 // FrameLoadTypeSame |
| 401 document->frame()->loader().setLoadType(FrameLoadTypeSame); |
| 402 EXPECT_EQ(ReloadIgnoringCacheData, fetchContext->resourceRequestCachePolicy(
request, Resource::MainResource)); |
| 403 |
| 404 // Conditional request |
| 405 document->frame()->loader().setLoadType(FrameLoadTypeStandard); |
| 406 ResourceRequest conditional("http://www.example.com"); |
| 407 conditional.setHTTPHeaderField("If-Modified-Since", "foo"); |
| 408 EXPECT_EQ(ReloadIgnoringCacheData, fetchContext->resourceRequestCachePolicy(
conditional, Resource::MainResource)); |
| 409 |
| 410 // Set up a child frame |
| 411 StubFrameLoaderClientWithParent client(document->frame()); |
| 412 StubFrameOwner owner; |
| 413 RefPtrWillBeRawPtr<LocalFrame> childFrame = LocalFrame::create(&client, docu
ment->frame()->host(), &owner); |
| 414 childFrame->setView(FrameView::create(childFrame.get(), IntSize(500, 500))); |
| 415 childFrame->init(); |
| 416 RefPtrWillBePersistent<DocumentLoader> childDocumentLoader = |
| 417 DocumentLoader::create(childFrame.get(), ResourceRequest("http://www.exa
mple.com"), SubstituteData()); |
| 418 RefPtrWillBePersistent<Document> childDocument = childFrame->document(); |
| 419 FrameFetchContext* childFetchContext = static_cast<FrameFetchContext*>(&chil
dDocumentLoader->fetcher()->context()); |
| 420 FrameFetchContext::provideDocumentToContext(*childFetchContext, childDocumen
t.get()); |
| 421 |
| 422 // Child frame as part of back/forward |
| 423 document->frame()->loader().setLoadType(FrameLoadTypeBackForward); |
| 424 EXPECT_EQ(ReturnCacheDataElseLoad, childFetchContext->resourceRequestCachePo
licy(request, Resource::MainResource)); |
| 425 |
| 426 // Child frame as part of reload |
| 427 document->frame()->loader().setLoadType(FrameLoadTypeReload); |
| 428 EXPECT_EQ(ReloadIgnoringCacheData, childFetchContext->resourceRequestCachePo
licy(request, Resource::MainResource)); |
| 429 |
| 430 // Child frame as part of end to end reload |
| 431 document->frame()->loader().setLoadType(FrameLoadTypeReloadFromOrigin); |
| 432 EXPECT_EQ(ReloadBypassingCache, childFetchContext->resourceRequestCachePolic
y(request, Resource::MainResource)); |
| 433 |
| 434 childDocumentLoader->detachFromFrame(); |
| 435 childDocumentLoader.clear(); |
| 436 } |
| 437 |
323 } // namespace | 438 } // namespace |
OLD | NEW |