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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 SubstituteData()); | 114 SubstituteData()); |
115 childDocument = childFrame->document(); | 115 childDocument = childFrame->document(); |
116 FrameFetchContext* childFetchContext = static_cast<FrameFetchContext*>( | 116 FrameFetchContext* childFetchContext = static_cast<FrameFetchContext*>( |
117 &childDocumentLoader->fetcher()->context()); | 117 &childDocumentLoader->fetcher()->context()); |
118 FrameFetchContext::provideDocumentToContext(*childFetchContext, | 118 FrameFetchContext::provideDocumentToContext(*childFetchContext, |
119 childDocument.get()); | 119 childDocument.get()); |
120 return childFetchContext; | 120 return childFetchContext; |
121 } | 121 } |
122 | 122 |
123 std::unique_ptr<DummyPageHolder> dummyPageHolder; | 123 std::unique_ptr<DummyPageHolder> dummyPageHolder; |
124 // We don't use the DocumentLoader directly in any tests, but need to keep it
around as long | 124 // We don't use the DocumentLoader directly in any tests, but need to keep it |
125 // as the ResourceFetcher and Document live due to indirect usage. | 125 // around as long as the ResourceFetcher and Document live due to indirect |
| 126 // usage. |
126 Persistent<DocumentLoader> documentLoader; | 127 Persistent<DocumentLoader> documentLoader; |
127 Persistent<Document> document; | 128 Persistent<Document> document; |
128 Persistent<FrameFetchContext> fetchContext; | 129 Persistent<FrameFetchContext> fetchContext; |
129 | 130 |
130 Persistent<StubFrameLoaderClientWithParent> childClient; | 131 Persistent<StubFrameLoaderClientWithParent> childClient; |
131 Persistent<LocalFrame> childFrame; | 132 Persistent<LocalFrame> childFrame; |
132 Persistent<DocumentLoader> childDocumentLoader; | 133 Persistent<DocumentLoader> childDocumentLoader; |
133 Persistent<Document> childDocument; | 134 Persistent<Document> childDocument; |
134 Persistent<DummyFrameOwner> owner; | 135 Persistent<DummyFrameOwner> owner; |
135 }; | 136 }; |
136 | 137 |
137 // This test class sets up a mock frame loader client that expects a | 138 // This test class sets up a mock frame loader client that expects a call to |
138 // call to didDisplayContentWithCertificateErrors(). | 139 // didDisplayContentWithCertificateErrors(). |
139 class FrameFetchContextDisplayedCertificateErrorsTest | 140 class FrameFetchContextDisplayedCertificateErrorsTest |
140 : public FrameFetchContextTest { | 141 : public FrameFetchContextTest { |
141 protected: | 142 protected: |
142 void SetUp() override { | 143 void SetUp() override { |
143 url = KURL(KURL(), "https://example.test/foo"); | 144 url = KURL(KURL(), "https://example.test/foo"); |
144 mainResourceUrl = KURL(KURL(), "https://www.example.test"); | 145 mainResourceUrl = KURL(KURL(), "https://www.example.test"); |
145 MockFrameLoaderClient* client = new MockFrameLoaderClient; | 146 MockFrameLoaderClient* client = new MockFrameLoaderClient; |
146 EXPECT_CALL(*client, didDisplayContentWithCertificateErrors(url)); | 147 EXPECT_CALL(*client, didDisplayContentWithCertificateErrors(url)); |
147 dummyPageHolder = | 148 dummyPageHolder = |
148 DummyPageHolder::create(IntSize(500, 500), nullptr, client); | 149 DummyPageHolder::create(IntSize(500, 500), nullptr, client); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 fetchRequest.mutableResourceRequest().setRequestContext( | 212 fetchRequest.mutableResourceRequest().setRequestContext( |
212 WebURLRequest::RequestContextScript); | 213 WebURLRequest::RequestContextScript); |
213 fetchRequest.mutableResourceRequest().setFrameType(frameType); | 214 fetchRequest.mutableResourceRequest().setFrameType(frameType); |
214 | 215 |
215 fetchContext->upgradeInsecureRequest(fetchRequest.mutableResourceRequest()); | 216 fetchContext->upgradeInsecureRequest(fetchRequest.mutableResourceRequest()); |
216 | 217 |
217 EXPECT_EQ(shouldPrefer ? String("1") : String(), | 218 EXPECT_EQ(shouldPrefer ? String("1") : String(), |
218 fetchRequest.resourceRequest().httpHeaderField( | 219 fetchRequest.resourceRequest().httpHeaderField( |
219 HTTPNames::Upgrade_Insecure_Requests)); | 220 HTTPNames::Upgrade_Insecure_Requests)); |
220 | 221 |
221 // Calling upgradeInsecureRequest more than once shouldn't affect the header
. | 222 // Calling upgradeInsecureRequest more than once shouldn't affect the |
| 223 // header. |
222 if (shouldPrefer) { | 224 if (shouldPrefer) { |
223 fetchContext->upgradeInsecureRequest( | 225 fetchContext->upgradeInsecureRequest( |
224 fetchRequest.mutableResourceRequest()); | 226 fetchRequest.mutableResourceRequest()); |
225 EXPECT_EQ("1", fetchRequest.resourceRequest().httpHeaderField( | 227 EXPECT_EQ("1", fetchRequest.resourceRequest().httpHeaderField( |
226 HTTPNames::Upgrade_Insecure_Requests)); | 228 HTTPNames::Upgrade_Insecure_Requests)); |
227 } | 229 } |
228 } | 230 } |
229 | 231 |
230 RefPtr<SecurityOrigin> exampleOrigin; | 232 RefPtr<SecurityOrigin> exampleOrigin; |
231 RefPtr<SecurityOrigin> secureOrigin; | 233 RefPtr<SecurityOrigin> secureOrigin; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 WebURLRequest::FrameTypeTopLevel, test.original); | 273 WebURLRequest::FrameTypeTopLevel, test.original); |
272 expectUpgrade(test.original, WebURLRequest::RequestContextScript, | 274 expectUpgrade(test.original, WebURLRequest::RequestContextScript, |
273 WebURLRequest::FrameTypeAuxiliary, test.original); | 275 WebURLRequest::FrameTypeAuxiliary, test.original); |
274 | 276 |
275 // unless the request context is RequestContextForm. | 277 // unless the request context is RequestContextForm. |
276 expectUpgrade(test.original, WebURLRequest::RequestContextForm, | 278 expectUpgrade(test.original, WebURLRequest::RequestContextForm, |
277 WebURLRequest::FrameTypeTopLevel, test.upgraded); | 279 WebURLRequest::FrameTypeTopLevel, test.upgraded); |
278 expectUpgrade(test.original, WebURLRequest::RequestContextForm, | 280 expectUpgrade(test.original, WebURLRequest::RequestContextForm, |
279 WebURLRequest::FrameTypeAuxiliary, test.upgraded); | 281 WebURLRequest::FrameTypeAuxiliary, test.upgraded); |
280 | 282 |
281 // Or unless the host of the resource is in the document's InsecureNavigatio
nsSet: | 283 // Or unless the host of the resource is in the document's |
| 284 // InsecureNavigationsSet: |
282 document->addInsecureNavigationUpgrade( | 285 document->addInsecureNavigationUpgrade( |
283 exampleOrigin->host().impl()->hash()); | 286 exampleOrigin->host().impl()->hash()); |
284 expectUpgrade(test.original, WebURLRequest::RequestContextScript, | 287 expectUpgrade(test.original, WebURLRequest::RequestContextScript, |
285 WebURLRequest::FrameTypeTopLevel, test.upgraded); | 288 WebURLRequest::FrameTypeTopLevel, test.upgraded); |
286 expectUpgrade(test.original, WebURLRequest::RequestContextScript, | 289 expectUpgrade(test.original, WebURLRequest::RequestContextScript, |
287 WebURLRequest::FrameTypeAuxiliary, test.upgraded); | 290 WebURLRequest::FrameTypeAuxiliary, test.upgraded); |
288 } | 291 } |
289 } | 292 } |
290 | 293 |
291 TEST_F(FrameFetchContextUpgradeTest, DoNotUpgradeInsecureResourceRequests) { | 294 TEST_F(FrameFetchContextUpgradeTest, DoNotUpgradeInsecureResourceRequests) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 {"http://example.test/page.html", WebURLRequest::FrameTypeNested, true}, | 328 {"http://example.test/page.html", WebURLRequest::FrameTypeNested, true}, |
326 {"http://example.test/page.html", WebURLRequest::FrameTypeNone, false}, | 329 {"http://example.test/page.html", WebURLRequest::FrameTypeNone, false}, |
327 {"http://example.test/page.html", WebURLRequest::FrameTypeTopLevel, true}, | 330 {"http://example.test/page.html", WebURLRequest::FrameTypeTopLevel, true}, |
328 {"https://example.test/page.html", WebURLRequest::FrameTypeAuxiliary, | 331 {"https://example.test/page.html", WebURLRequest::FrameTypeAuxiliary, |
329 true}, | 332 true}, |
330 {"https://example.test/page.html", WebURLRequest::FrameTypeNested, true}, | 333 {"https://example.test/page.html", WebURLRequest::FrameTypeNested, true}, |
331 {"https://example.test/page.html", WebURLRequest::FrameTypeNone, false}, | 334 {"https://example.test/page.html", WebURLRequest::FrameTypeNone, false}, |
332 {"https://example.test/page.html", WebURLRequest::FrameTypeTopLevel, | 335 {"https://example.test/page.html", WebURLRequest::FrameTypeTopLevel, |
333 true}}; | 336 true}}; |
334 | 337 |
335 // This should work correctly both when the FrameFetchContext has a Document,
and | 338 // This should work correctly both when the FrameFetchContext has a Document, |
336 // when it doesn't (e.g. during main frame navigations), so run through the te
sts | 339 // and when it doesn't (e.g. during main frame navigations), so run through |
337 // both before and after providing a document to the context. | 340 // the tests both before and after providing a document to the context. |
338 for (const auto& test : tests) { | 341 for (const auto& test : tests) { |
339 document->setInsecureRequestPolicy(kLeaveInsecureRequestsAlone); | 342 document->setInsecureRequestPolicy(kLeaveInsecureRequestsAlone); |
340 expectHTTPSHeader(test.toRequest, test.frameType, test.shouldPrefer); | 343 expectHTTPSHeader(test.toRequest, test.frameType, test.shouldPrefer); |
341 | 344 |
342 document->setInsecureRequestPolicy(kUpgradeInsecureRequests); | 345 document->setInsecureRequestPolicy(kUpgradeInsecureRequests); |
343 expectHTTPSHeader(test.toRequest, test.frameType, test.shouldPrefer); | 346 expectHTTPSHeader(test.toRequest, test.frameType, test.shouldPrefer); |
344 } | 347 } |
345 | 348 |
346 FrameFetchContext::provideDocumentToContext(*fetchContext, document.get()); | 349 FrameFetchContext::provideDocumentToContext(*fetchContext, document.get()); |
347 | 350 |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 // No document origin => unique request origin | 504 // No document origin => unique request origin |
502 {"", false, "", WebURLRequest::FrameTypeNone, "null"}, | 505 {"", false, "", WebURLRequest::FrameTypeNone, "null"}, |
503 {"", true, "", WebURLRequest::FrameTypeNone, "null"}, | 506 {"", true, "", WebURLRequest::FrameTypeNone, "null"}, |
504 | 507 |
505 // Document origin => request origin | 508 // Document origin => request origin |
506 {"http://example.test", false, "", WebURLRequest::FrameTypeNone, | 509 {"http://example.test", false, "", WebURLRequest::FrameTypeNone, |
507 "http://example.test"}, | 510 "http://example.test"}, |
508 {"http://example.test", true, "", WebURLRequest::FrameTypeNone, | 511 {"http://example.test", true, "", WebURLRequest::FrameTypeNone, |
509 "http://example.test"}, | 512 "http://example.test"}, |
510 | 513 |
511 // If the request already has a requestor origin, then 'populateRequestDat
a' leaves it alone: | 514 // If the request already has a requestor origin, then |
| 515 // 'populateRequestData' leaves it alone: |
512 {"http://example.test", false, "http://not-example.test", | 516 {"http://example.test", false, "http://not-example.test", |
513 WebURLRequest::FrameTypeNone, "http://not-example.test"}, | 517 WebURLRequest::FrameTypeNone, "http://not-example.test"}, |
514 {"http://example.test", true, "http://not-example.test", | 518 {"http://example.test", true, "http://not-example.test", |
515 WebURLRequest::FrameTypeNone, "http://not-example.test"}, | 519 WebURLRequest::FrameTypeNone, "http://not-example.test"}, |
516 | 520 |
517 // If the request's frame type is not 'none', then 'populateRequestData' l
eaves it alone: | 521 // If the request's frame type is not 'none', then 'populateRequestData' |
| 522 // leaves it alone: |
518 {"http://example.test", false, "", WebURLRequest::FrameTypeTopLevel, ""}, | 523 {"http://example.test", false, "", WebURLRequest::FrameTypeTopLevel, ""}, |
519 {"http://example.test", false, "", WebURLRequest::FrameTypeAuxiliary, ""}, | 524 {"http://example.test", false, "", WebURLRequest::FrameTypeAuxiliary, ""}, |
520 {"http://example.test", false, "", WebURLRequest::FrameTypeNested, ""}, | 525 {"http://example.test", false, "", WebURLRequest::FrameTypeNested, ""}, |
521 }; | 526 }; |
522 | 527 |
523 for (const auto& test : cases) { | 528 for (const auto& test : cases) { |
524 SCOPED_TRACE(::testing::Message() << test.documentURL << " => " | 529 SCOPED_TRACE(::testing::Message() << test.documentURL << " => " |
525 << test.serializedOrigin); | 530 << test.serializedOrigin); |
526 // Set up a new document to ensure sandbox flags are cleared: | 531 // Set up a new document to ensure sandbox flags are cleared: |
527 dummyPageHolder = DummyPageHolder::create(IntSize(500, 500)); | 532 dummyPageHolder = DummyPageHolder::create(IntSize(500, 500)); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 fetchContext->addAdditionalRequestHeaders(resourceRequest, FetchMainResource); | 598 fetchContext->addAdditionalRequestHeaders(resourceRequest, FetchMainResource); |
594 EXPECT_EQ("on", resourceRequest.httpHeaderField("Save-Data")); | 599 EXPECT_EQ("on", resourceRequest.httpHeaderField("Save-Data")); |
595 } | 600 } |
596 | 601 |
597 TEST_F(FrameFetchContextTest, DisabledDataSaver) { | 602 TEST_F(FrameFetchContextTest, DisabledDataSaver) { |
598 ResourceRequest resourceRequest("http://www.example.com"); | 603 ResourceRequest resourceRequest("http://www.example.com"); |
599 fetchContext->addAdditionalRequestHeaders(resourceRequest, FetchMainResource); | 604 fetchContext->addAdditionalRequestHeaders(resourceRequest, FetchMainResource); |
600 EXPECT_EQ(String(), resourceRequest.httpHeaderField("Save-Data")); | 605 EXPECT_EQ(String(), resourceRequest.httpHeaderField("Save-Data")); |
601 } | 606 } |
602 | 607 |
603 // Tests that when a resource with certificate errors is loaded from the | 608 // Tests that when a resource with certificate errors is loaded from the memory |
604 // memory cache, the embedder is notified. | 609 // cache, the embedder is notified. |
605 TEST_F(FrameFetchContextDisplayedCertificateErrorsTest, | 610 TEST_F(FrameFetchContextDisplayedCertificateErrorsTest, |
606 MemoryCacheCertificateError) { | 611 MemoryCacheCertificateError) { |
607 ResourceRequest resourceRequest(url); | 612 ResourceRequest resourceRequest(url); |
608 ResourceResponse response; | 613 ResourceResponse response; |
609 response.setURL(url); | 614 response.setURL(url); |
610 response.setHasMajorCertificateErrors(true); | 615 response.setHasMajorCertificateErrors(true); |
611 Resource* resource = Resource::create(resourceRequest, Resource::Image); | 616 Resource* resource = Resource::create(resourceRequest, Resource::Image); |
612 resource->setResponse(response); | 617 resource->setResponse(response); |
613 fetchContext->dispatchDidLoadResourceFromMemoryCache( | 618 fetchContext->dispatchDidLoadResourceFromMemoryCache( |
614 createUniqueIdentifier(), resource, WebURLRequest::FrameTypeNone, | 619 createUniqueIdentifier(), resource, WebURLRequest::FrameTypeNone, |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 fetchContext->addAdditionalRequestHeaders(mainRequest, FetchMainResource); | 738 fetchContext->addAdditionalRequestHeaders(mainRequest, FetchMainResource); |
734 EXPECT_EQ(test.isExternalExpectation, mainRequest.isExternalRequest()); | 739 EXPECT_EQ(test.isExternalExpectation, mainRequest.isExternalRequest()); |
735 | 740 |
736 ResourceRequest subRequest(test.url); | 741 ResourceRequest subRequest(test.url); |
737 fetchContext->addAdditionalRequestHeaders(subRequest, FetchSubresource); | 742 fetchContext->addAdditionalRequestHeaders(subRequest, FetchSubresource); |
738 EXPECT_EQ(test.isExternalExpectation, subRequest.isExternalRequest()); | 743 EXPECT_EQ(test.isExternalExpectation, subRequest.isExternalRequest()); |
739 } | 744 } |
740 } | 745 } |
741 | 746 |
742 } // namespace blink | 747 } // namespace blink |
OLD | NEW |