| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 #include "platform/weborigin/KURL.h" | 49 #include "platform/weborigin/KURL.h" |
| 50 #include "public/platform/WebAddressSpace.h" | 50 #include "public/platform/WebAddressSpace.h" |
| 51 #include "public/platform/WebCachePolicy.h" | 51 #include "public/platform/WebCachePolicy.h" |
| 52 #include "public/platform/WebDocumentSubresourceFilter.h" | 52 #include "public/platform/WebDocumentSubresourceFilter.h" |
| 53 #include "public/platform/WebInsecureRequestPolicy.h" | 53 #include "public/platform/WebInsecureRequestPolicy.h" |
| 54 #include "testing/gmock/include/gmock/gmock.h" | 54 #include "testing/gmock/include/gmock/gmock.h" |
| 55 #include "testing/gtest/include/gtest/gtest.h" | 55 #include "testing/gtest/include/gtest/gtest.h" |
| 56 | 56 |
| 57 namespace blink { | 57 namespace blink { |
| 58 | 58 |
| 59 class StubFrameLoaderClientWithParent final : public EmptyLocalFrameClient { | 59 class StubLocalFrameClientWithParent final : public EmptyLocalFrameClient { |
| 60 public: | 60 public: |
| 61 static StubFrameLoaderClientWithParent* create(Frame* parent) { | 61 static StubLocalFrameClientWithParent* create(Frame* parent) { |
| 62 return new StubFrameLoaderClientWithParent(parent); | 62 return new StubLocalFrameClientWithParent(parent); |
| 63 } | 63 } |
| 64 | 64 |
| 65 DEFINE_INLINE_VIRTUAL_TRACE() { | 65 DEFINE_INLINE_VIRTUAL_TRACE() { |
| 66 visitor->trace(m_parent); | 66 visitor->trace(m_parent); |
| 67 EmptyLocalFrameClient::trace(visitor); | 67 EmptyLocalFrameClient::trace(visitor); |
| 68 } | 68 } |
| 69 | 69 |
| 70 Frame* parent() const override { return m_parent.get(); } | 70 Frame* parent() const override { return m_parent.get(); } |
| 71 | 71 |
| 72 private: | 72 private: |
| 73 explicit StubFrameLoaderClientWithParent(Frame* parent) : m_parent(parent) {} | 73 explicit StubLocalFrameClientWithParent(Frame* parent) : m_parent(parent) {} |
| 74 | 74 |
| 75 Member<Frame> m_parent; | 75 Member<Frame> m_parent; |
| 76 }; | 76 }; |
| 77 | 77 |
| 78 class MockFrameLoaderClient : public EmptyLocalFrameClient { | 78 class MockLocalFrameClient : public EmptyLocalFrameClient { |
| 79 public: | 79 public: |
| 80 MockFrameLoaderClient() : EmptyLocalFrameClient() {} | 80 MockLocalFrameClient() : EmptyLocalFrameClient() {} |
| 81 MOCK_METHOD1(didDisplayContentWithCertificateErrors, void(const KURL&)); | 81 MOCK_METHOD1(didDisplayContentWithCertificateErrors, void(const KURL&)); |
| 82 MOCK_METHOD2(dispatchDidLoadResourceFromMemoryCache, | 82 MOCK_METHOD2(dispatchDidLoadResourceFromMemoryCache, |
| 83 void(const ResourceRequest&, const ResourceResponse&)); | 83 void(const ResourceRequest&, const ResourceResponse&)); |
| 84 }; | 84 }; |
| 85 | 85 |
| 86 class FixedPolicySubresourceFilter : public WebDocumentSubresourceFilter { | 86 class FixedPolicySubresourceFilter : public WebDocumentSubresourceFilter { |
| 87 public: | 87 public: |
| 88 FixedPolicySubresourceFilter(LoadPolicy policy, int* filteredLoadCounter) | 88 FixedPolicySubresourceFilter(LoadPolicy policy, int* filteredLoadCounter) |
| 89 : m_policy(policy), m_filteredLoadCounter(filteredLoadCounter) {} | 89 : m_policy(policy), m_filteredLoadCounter(filteredLoadCounter) {} |
| 90 | 90 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 111 owner = DummyFrameOwner::create(); | 111 owner = DummyFrameOwner::create(); |
| 112 FrameFetchContext::provideDocumentToContext(*fetchContext, document.get()); | 112 FrameFetchContext::provideDocumentToContext(*fetchContext, document.get()); |
| 113 } | 113 } |
| 114 | 114 |
| 115 void TearDown() override { | 115 void TearDown() override { |
| 116 if (childFrame) | 116 if (childFrame) |
| 117 childFrame->detach(FrameDetachType::Remove); | 117 childFrame->detach(FrameDetachType::Remove); |
| 118 } | 118 } |
| 119 | 119 |
| 120 FrameFetchContext* createChildFrame() { | 120 FrameFetchContext* createChildFrame() { |
| 121 childClient = StubFrameLoaderClientWithParent::create(document->frame()); | 121 childClient = StubLocalFrameClientWithParent::create(document->frame()); |
| 122 childFrame = LocalFrame::create(childClient.get(), | 122 childFrame = LocalFrame::create(childClient.get(), |
| 123 document->frame()->host(), owner.get()); | 123 document->frame()->host(), owner.get()); |
| 124 childFrame->setView(FrameView::create(*childFrame, IntSize(500, 500))); | 124 childFrame->setView(FrameView::create(*childFrame, IntSize(500, 500))); |
| 125 childFrame->init(); | 125 childFrame->init(); |
| 126 childDocument = childFrame->document(); | 126 childDocument = childFrame->document(); |
| 127 FrameFetchContext* childFetchContext = static_cast<FrameFetchContext*>( | 127 FrameFetchContext* childFetchContext = static_cast<FrameFetchContext*>( |
| 128 &childFrame->loader().documentLoader()->fetcher()->context()); | 128 &childFrame->loader().documentLoader()->fetcher()->context()); |
| 129 FrameFetchContext::provideDocumentToContext(*childFetchContext, | 129 FrameFetchContext::provideDocumentToContext(*childFetchContext, |
| 130 childDocument.get()); | 130 childDocument.get()); |
| 131 return childFetchContext; | 131 return childFetchContext; |
| 132 } | 132 } |
| 133 | 133 |
| 134 std::unique_ptr<DummyPageHolder> dummyPageHolder; | 134 std::unique_ptr<DummyPageHolder> dummyPageHolder; |
| 135 // We don't use the DocumentLoader directly in any tests, but need to keep it | 135 // We don't use the DocumentLoader directly in any tests, but need to keep it |
| 136 // around as long as the ResourceFetcher and Document live due to indirect | 136 // around as long as the ResourceFetcher and Document live due to indirect |
| 137 // usage. | 137 // usage. |
| 138 Persistent<Document> document; | 138 Persistent<Document> document; |
| 139 Persistent<FrameFetchContext> fetchContext; | 139 Persistent<FrameFetchContext> fetchContext; |
| 140 | 140 |
| 141 Persistent<StubFrameLoaderClientWithParent> childClient; | 141 Persistent<StubLocalFrameClientWithParent> childClient; |
| 142 Persistent<LocalFrame> childFrame; | 142 Persistent<LocalFrame> childFrame; |
| 143 Persistent<Document> childDocument; | 143 Persistent<Document> childDocument; |
| 144 Persistent<DummyFrameOwner> owner; | 144 Persistent<DummyFrameOwner> owner; |
| 145 }; | 145 }; |
| 146 | 146 |
| 147 class FrameFetchContextSubresourceFilterTest : public FrameFetchContextTest { | 147 class FrameFetchContextSubresourceFilterTest : public FrameFetchContextTest { |
| 148 protected: | 148 protected: |
| 149 void SetUp() override { | 149 void SetUp() override { |
| 150 FrameFetchContextTest::SetUp(); | 150 FrameFetchContextTest::SetUp(); |
| 151 m_filteredLoadCallbackCounter = 0; | 151 m_filteredLoadCallbackCounter = 0; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 int m_filteredLoadCallbackCounter; | 187 int m_filteredLoadCallbackCounter; |
| 188 }; | 188 }; |
| 189 | 189 |
| 190 // This test class sets up a mock frame loader client. | 190 // This test class sets up a mock frame loader client. |
| 191 class FrameFetchContextMockedFrameLoaderClientTest | 191 class FrameFetchContextMockedFrameLoaderClientTest |
| 192 : public FrameFetchContextTest { | 192 : public FrameFetchContextTest { |
| 193 protected: | 193 protected: |
| 194 void SetUp() override { | 194 void SetUp() override { |
| 195 url = KURL(KURL(), "https://example.test/foo"); | 195 url = KURL(KURL(), "https://example.test/foo"); |
| 196 mainResourceUrl = KURL(KURL(), "https://www.example.test"); | 196 mainResourceUrl = KURL(KURL(), "https://www.example.test"); |
| 197 client = new testing::NiceMock<MockFrameLoaderClient>(); | 197 client = new testing::NiceMock<MockLocalFrameClient>(); |
| 198 dummyPageHolder = | 198 dummyPageHolder = |
| 199 DummyPageHolder::create(IntSize(500, 500), nullptr, client); | 199 DummyPageHolder::create(IntSize(500, 500), nullptr, client); |
| 200 dummyPageHolder->page().setDeviceScaleFactor(1.0); | 200 dummyPageHolder->page().setDeviceScaleFactor(1.0); |
| 201 document = &dummyPageHolder->document(); | 201 document = &dummyPageHolder->document(); |
| 202 document->setURL(mainResourceUrl); | 202 document->setURL(mainResourceUrl); |
| 203 fetchContext = | 203 fetchContext = |
| 204 static_cast<FrameFetchContext*>(&document->fetcher()->context()); | 204 static_cast<FrameFetchContext*>(&document->fetcher()->context()); |
| 205 owner = DummyFrameOwner::create(); | 205 owner = DummyFrameOwner::create(); |
| 206 FrameFetchContext::provideDocumentToContext(*fetchContext, document.get()); | 206 FrameFetchContext::provideDocumentToContext(*fetchContext, document.get()); |
| 207 } | 207 } |
| 208 | 208 |
| 209 KURL url; | 209 KURL url; |
| 210 KURL mainResourceUrl; | 210 KURL mainResourceUrl; |
| 211 | 211 |
| 212 Persistent<testing::NiceMock<MockFrameLoaderClient>> client; | 212 Persistent<testing::NiceMock<MockLocalFrameClient>> client; |
| 213 }; | 213 }; |
| 214 | 214 |
| 215 class FrameFetchContextModifyRequestTest : public FrameFetchContextTest { | 215 class FrameFetchContextModifyRequestTest : public FrameFetchContextTest { |
| 216 public: | 216 public: |
| 217 FrameFetchContextModifyRequestTest() | 217 FrameFetchContextModifyRequestTest() |
| 218 : exampleOrigin(SecurityOrigin::create( | 218 : exampleOrigin(SecurityOrigin::create( |
| 219 KURL(ParsedURLString, "https://example.test/"))), | 219 KURL(ParsedURLString, "https://example.test/"))), |
| 220 secureOrigin(SecurityOrigin::create( | 220 secureOrigin(SecurityOrigin::create( |
| 221 KURL(ParsedURLString, "https://secureorigin.test/image.png"))) {} | 221 KURL(ParsedURLString, "https://secureorigin.test/image.png"))) {} |
| 222 | 222 |
| (...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 901 setFilterPolicy(WebDocumentSubresourceFilter::WouldDisallow); | 901 setFilterPolicy(WebDocumentSubresourceFilter::WouldDisallow); |
| 902 | 902 |
| 903 EXPECT_EQ(ResourceRequestBlockedReason::None, canRequest()); | 903 EXPECT_EQ(ResourceRequestBlockedReason::None, canRequest()); |
| 904 EXPECT_EQ(0, getFilteredLoadCallCount()); | 904 EXPECT_EQ(0, getFilteredLoadCallCount()); |
| 905 | 905 |
| 906 EXPECT_EQ(ResourceRequestBlockedReason::None, canRequestPreload()); | 906 EXPECT_EQ(ResourceRequestBlockedReason::None, canRequestPreload()); |
| 907 EXPECT_EQ(0, getFilteredLoadCallCount()); | 907 EXPECT_EQ(0, getFilteredLoadCallCount()); |
| 908 } | 908 } |
| 909 | 909 |
| 910 } // namespace blink | 910 } // namespace blink |
| OLD | NEW |