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 MockFrameLoaderClientWithParent : public EmptyFrameLoaderClient { | |
dcheng
2015/07/17 18:44:05
Nit: these are probably more of a Fake or a Stub t
Nate Chapin
2015/07/17 18:54:06
I can never remember which is which :( Stubbed.
| |
327 public: | |
328 MockFrameLoaderClientWithParent(Frame* parent) | |
dcheng
2015/07/17 18:44:05
explicit
Nate Chapin
2015/07/17 18:54:06
Done.
| |
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 MockFrameOwner : public FrameOwner { | |
340 public: | |
341 bool isLocal() const override { return false; } | |
342 SandboxFlags sandboxFlags() const override { return SandboxNone; } | |
343 void dispatchLoad() override { } | |
344 void renderFallbackContent() override { } | |
345 }; | |
346 | |
347 class FrameFetchContextCachePolicyTest : public ::testing::Test { | |
348 public: | |
349 FrameFetchContextCachePolicyTest() { } | |
350 | |
351 protected: | |
352 virtual void SetUp() | |
dcheng
2015/07/17 18:44:05
override instead of virtual here
Nate Chapin
2015/07/17 18:54:06
Done.
| |
353 { | |
354 dummyPageHolder = DummyPageHolder::create(IntSize(500, 500)); | |
355 dummyPageHolder->page().setDeviceScaleFactor(1.0); | |
356 documentLoader = DocumentLoader::create(&dummyPageHolder->frame(), Resou rceRequest("http://www.example.com"), SubstituteData()); | |
357 document = toHTMLDocument(&dummyPageHolder->document()); | |
358 fetchContext = static_cast<FrameFetchContext*>(&documentLoader->fetcher( )->context()); | |
359 FrameFetchContext::provideDocumentToContext(*fetchContext, document.get( )); | |
360 } | |
361 | |
362 OwnPtr<DummyPageHolder> dummyPageHolder; | |
363 // We don't use the DocumentLoader directly in any tests, but need to keep i t around as long | |
364 // as the ResourceFetcher and Document live due to indirect usage. | |
365 RefPtrWillBePersistent<DocumentLoader> documentLoader; | |
366 RefPtrWillBePersistent<Document> document; | |
367 Persistent<FrameFetchContext> fetchContext; | |
368 }; | |
369 | |
370 TEST_F(FrameFetchContextCachePolicyTest, MainResource) | |
371 { | |
372 // Default case | |
373 ResourceRequest request("http://www.example.com"); | |
374 EXPECT_EQ(UseProtocolCachePolicy, fetchContext->resourceRequestCachePolicy(r equest, Resource::MainResource)); | |
375 | |
376 // Post | |
377 ResourceRequest postRequest("http://www.example.com"); | |
378 postRequest.setHTTPMethod("POST"); | |
379 EXPECT_EQ(ReloadIgnoringCacheData, fetchContext->resourceRequestCachePolicy( postRequest, Resource::MainResource)); | |
380 | |
381 // Re-post | |
382 document->frame()->loader().setLoadType(FrameLoadTypeBackForward); | |
383 EXPECT_EQ(ReturnCacheDataDontLoad, fetchContext->resourceRequestCachePolicy( postRequest, Resource::MainResource)); | |
384 | |
385 // Enconding overriden | |
386 document->frame()->loader().setLoadType(FrameLoadTypeStandard); | |
387 document->frame()->host()->setOverrideEncoding("foo"); | |
388 EXPECT_EQ(ReturnCacheDataElseLoad, fetchContext->resourceRequestCachePolicy( request, Resource::MainResource)); | |
389 document->frame()->host()->setOverrideEncoding(AtomicString()); | |
390 | |
391 // FrameLoadTypeSame | |
392 document->frame()->loader().setLoadType(FrameLoadTypeSame); | |
393 EXPECT_EQ(ReloadIgnoringCacheData, fetchContext->resourceRequestCachePolicy( request, Resource::MainResource)); | |
394 | |
395 // Conditional request | |
396 document->frame()->loader().setLoadType(FrameLoadTypeStandard); | |
397 ResourceRequest conditional("http://www.example.com"); | |
398 conditional.setHTTPHeaderField("If-Modified-Since", "foo"); | |
399 EXPECT_EQ(ReloadIgnoringCacheData, fetchContext->resourceRequestCachePolicy( conditional, Resource::MainResource)); | |
400 | |
401 // Set up a child frame | |
402 MockFrameLoaderClientWithParent client(document->frame()); | |
403 MockFrameOwner owner; | |
404 RefPtrWillBeRawPtr<LocalFrame> childFrame = LocalFrame::create(&client, docu ment->frame()->host(), &owner); | |
405 RefPtrWillBePersistent<DocumentLoader> childDocumentLoader = | |
406 DocumentLoader::create(childFrame.get(), ResourceRequest("http://www.exa mple.com"), SubstituteData()); | |
407 RefPtrWillBePersistent<Document> childDocument = childFrame->document(); | |
408 FrameFetchContext* childFetchContext = static_cast<FrameFetchContext*>(&chil dDocumentLoader->fetcher()->context()); | |
409 FrameFetchContext::provideDocumentToContext(*childFetchContext, childDocumen t.get()); | |
410 | |
411 // Child frame as part of back/forward | |
412 document->frame()->loader().setLoadType(FrameLoadTypeBackForward); | |
413 EXPECT_EQ(ReturnCacheDataElseLoad, childFetchContext->resourceRequestCachePo licy(request, Resource::MainResource)); | |
414 | |
415 // Child frame as part of reload | |
416 document->frame()->loader().setLoadType(FrameLoadTypeReload); | |
417 EXPECT_EQ(ReloadIgnoringCacheData, childFetchContext->resourceRequestCachePo licy(request, Resource::MainResource)); | |
418 | |
419 // Child frame as part of end to end reload | |
420 document->frame()->loader().setLoadType(FrameLoadTypeReloadFromOrigin); | |
421 EXPECT_EQ(ReloadBypassingCache, childFetchContext->resourceRequestCachePolic y(request, Resource::MainResource)); | |
422 } | |
423 | |
323 } // namespace | 424 } // namespace |
OLD | NEW |