Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(620)

Side by Side Diff: third_party/WebKit/Source/core/loader/FrameFetchContextTest.cpp

Issue 2563423004: Always send a fail or finish notification for each navigation. (Closed)
Patch Set: Rebase Created 3 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 MOCK_METHOD1(didDisplayContentWithCertificateErrors, void(const KURL&)); 79 MOCK_METHOD1(didDisplayContentWithCertificateErrors, void(const KURL&));
80 MOCK_METHOD2(dispatchDidLoadResourceFromMemoryCache, 80 MOCK_METHOD2(dispatchDidLoadResourceFromMemoryCache,
81 void(const ResourceRequest&, const ResourceResponse&)); 81 void(const ResourceRequest&, const ResourceResponse&));
82 }; 82 };
83 83
84 class FrameFetchContextTest : public ::testing::Test { 84 class FrameFetchContextTest : public ::testing::Test {
85 protected: 85 protected:
86 void SetUp() override { 86 void SetUp() override {
87 dummyPageHolder = DummyPageHolder::create(IntSize(500, 500)); 87 dummyPageHolder = DummyPageHolder::create(IntSize(500, 500));
88 dummyPageHolder->page().setDeviceScaleFactor(1.0); 88 dummyPageHolder->page().setDeviceScaleFactor(1.0);
89 documentLoader = DocumentLoader::create(
90 &dummyPageHolder->frame(), ResourceRequest("http://www.example.com"),
91 SubstituteData(), ClientRedirectPolicy::NotClientRedirect);
92 document = &dummyPageHolder->document(); 89 document = &dummyPageHolder->document();
93 fetchContext = 90 fetchContext =
94 static_cast<FrameFetchContext*>(&documentLoader->fetcher()->context()); 91 static_cast<FrameFetchContext*>(&document->fetcher()->context());
95 owner = DummyFrameOwner::create(); 92 owner = DummyFrameOwner::create();
96 FrameFetchContext::provideDocumentToContext(*fetchContext, document.get()); 93 FrameFetchContext::provideDocumentToContext(*fetchContext, document.get());
97 } 94 }
98 95
99 void TearDown() override { 96 void TearDown() override {
100 documentLoader->detachFromFrame(); 97 if (childFrame)
101 documentLoader.clear();
102
103 if (childFrame) {
104 childDocumentLoader->detachFromFrame();
105 childDocumentLoader.clear();
106 childFrame->detach(FrameDetachType::Remove); 98 childFrame->detach(FrameDetachType::Remove);
107 }
108 } 99 }
109 100
110 FrameFetchContext* createChildFrame() { 101 FrameFetchContext* createChildFrame() {
111 childClient = StubFrameLoaderClientWithParent::create(document->frame()); 102 childClient = StubFrameLoaderClientWithParent::create(document->frame());
112 childFrame = LocalFrame::create(childClient.get(), 103 childFrame = LocalFrame::create(childClient.get(),
113 document->frame()->host(), owner.get()); 104 document->frame()->host(), owner.get());
114 childFrame->setView(FrameView::create(*childFrame, IntSize(500, 500))); 105 childFrame->setView(FrameView::create(*childFrame, IntSize(500, 500)));
115 childFrame->init(); 106 childFrame->init();
116 childDocumentLoader = DocumentLoader::create(
117 childFrame.get(), ResourceRequest("http://www.example.com"),
118 SubstituteData(), ClientRedirectPolicy::NotClientRedirect);
119 childDocument = childFrame->document(); 107 childDocument = childFrame->document();
120 FrameFetchContext* childFetchContext = static_cast<FrameFetchContext*>( 108 FrameFetchContext* childFetchContext = static_cast<FrameFetchContext*>(
121 &childDocumentLoader->fetcher()->context()); 109 &childFrame->loader().documentLoader()->fetcher()->context());
122 FrameFetchContext::provideDocumentToContext(*childFetchContext, 110 FrameFetchContext::provideDocumentToContext(*childFetchContext,
123 childDocument.get()); 111 childDocument.get());
124 return childFetchContext; 112 return childFetchContext;
125 } 113 }
126 114
127 std::unique_ptr<DummyPageHolder> dummyPageHolder; 115 std::unique_ptr<DummyPageHolder> dummyPageHolder;
128 // We don't use the DocumentLoader directly in any tests, but need to keep it 116 // We don't use the DocumentLoader directly in any tests, but need to keep it
129 // around as long as the ResourceFetcher and Document live due to indirect 117 // around as long as the ResourceFetcher and Document live due to indirect
130 // usage. 118 // usage.
131 Persistent<DocumentLoader> documentLoader;
132 Persistent<Document> document; 119 Persistent<Document> document;
133 Persistent<FrameFetchContext> fetchContext; 120 Persistent<FrameFetchContext> fetchContext;
134 121
135 Persistent<StubFrameLoaderClientWithParent> childClient; 122 Persistent<StubFrameLoaderClientWithParent> childClient;
136 Persistent<LocalFrame> childFrame; 123 Persistent<LocalFrame> childFrame;
137 Persistent<DocumentLoader> childDocumentLoader;
138 Persistent<Document> childDocument; 124 Persistent<Document> childDocument;
139 Persistent<DummyFrameOwner> owner; 125 Persistent<DummyFrameOwner> owner;
140 }; 126 };
141 127
142 // This test class sets up a mock frame loader client. 128 // This test class sets up a mock frame loader client.
143 class FrameFetchContextMockedFrameLoaderClientTest 129 class FrameFetchContextMockedFrameLoaderClientTest
144 : public FrameFetchContextTest { 130 : public FrameFetchContextTest {
145 protected: 131 protected:
146 void SetUp() override { 132 void SetUp() override {
147 url = KURL(KURL(), "https://example.test/foo"); 133 url = KURL(KURL(), "https://example.test/foo");
148 mainResourceUrl = KURL(KURL(), "https://www.example.test"); 134 mainResourceUrl = KURL(KURL(), "https://www.example.test");
149 client = new testing::NiceMock<MockFrameLoaderClient>(); 135 client = new testing::NiceMock<MockFrameLoaderClient>();
150 dummyPageHolder = 136 dummyPageHolder =
151 DummyPageHolder::create(IntSize(500, 500), nullptr, client); 137 DummyPageHolder::create(IntSize(500, 500), nullptr, client);
152 dummyPageHolder->page().setDeviceScaleFactor(1.0); 138 dummyPageHolder->page().setDeviceScaleFactor(1.0);
153 documentLoader = DocumentLoader::create(
154 &dummyPageHolder->frame(), ResourceRequest(mainResourceUrl),
155 SubstituteData(), ClientRedirectPolicy::NotClientRedirect);
156 document = &dummyPageHolder->document(); 139 document = &dummyPageHolder->document();
157 document->setURL(mainResourceUrl); 140 document->setURL(mainResourceUrl);
158 fetchContext = 141 fetchContext =
159 static_cast<FrameFetchContext*>(&documentLoader->fetcher()->context()); 142 static_cast<FrameFetchContext*>(&document->fetcher()->context());
160 owner = DummyFrameOwner::create(); 143 owner = DummyFrameOwner::create();
161 FrameFetchContext::provideDocumentToContext(*fetchContext, document.get()); 144 FrameFetchContext::provideDocumentToContext(*fetchContext, document.get());
162 } 145 }
163 146
164 KURL url; 147 KURL url;
165 KURL mainResourceUrl; 148 KURL mainResourceUrl;
166 149
167 Persistent<testing::NiceMock<MockFrameLoaderClient>> client; 150 Persistent<testing::NiceMock<MockFrameLoaderClient>> client;
168 }; 151 };
169 152
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 fetchContext->addAdditionalRequestHeaders(mainRequest, FetchMainResource); 810 fetchContext->addAdditionalRequestHeaders(mainRequest, FetchMainResource);
828 EXPECT_EQ(test.isExternalExpectation, mainRequest.isExternalRequest()); 811 EXPECT_EQ(test.isExternalExpectation, mainRequest.isExternalRequest());
829 812
830 ResourceRequest subRequest(test.url); 813 ResourceRequest subRequest(test.url);
831 fetchContext->addAdditionalRequestHeaders(subRequest, FetchSubresource); 814 fetchContext->addAdditionalRequestHeaders(subRequest, FetchSubresource);
832 EXPECT_EQ(test.isExternalExpectation, subRequest.isExternalRequest()); 815 EXPECT_EQ(test.isExternalExpectation, subRequest.isExternalRequest());
833 } 816 }
834 } 817 }
835 818
836 } // namespace blink 819 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/loader/DocumentLoader.cpp ('k') | third_party/WebKit/Source/core/loader/FrameLoader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698