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

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

Issue 2040133003: Replace SecurityContext::InsecureRequestsPolicy with WebInsecureRequestPolicy. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@combine-uir-block
Patch Set: Ugh. Created 4 years, 6 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 26 matching lines...) Expand all
37 #include "core/frame/Settings.h" 37 #include "core/frame/Settings.h"
38 #include "core/html/HTMLDocument.h" 38 #include "core/html/HTMLDocument.h"
39 #include "core/loader/DocumentLoader.h" 39 #include "core/loader/DocumentLoader.h"
40 #include "core/loader/EmptyClients.h" 40 #include "core/loader/EmptyClients.h"
41 #include "core/page/Page.h" 41 #include "core/page/Page.h"
42 #include "core/testing/DummyPageHolder.h" 42 #include "core/testing/DummyPageHolder.h"
43 #include "platform/network/ResourceRequest.h" 43 #include "platform/network/ResourceRequest.h"
44 #include "platform/weborigin/KURL.h" 44 #include "platform/weborigin/KURL.h"
45 #include "public/platform/WebAddressSpace.h" 45 #include "public/platform/WebAddressSpace.h"
46 #include "public/platform/WebCachePolicy.h" 46 #include "public/platform/WebCachePolicy.h"
47 #include "public/platform/WebInsecureRequestPolicy.h"
47 #include "testing/gmock/include/gmock/gmock-generated-function-mockers.h" 48 #include "testing/gmock/include/gmock/gmock-generated-function-mockers.h"
48 #include "testing/gtest/include/gtest/gtest.h" 49 #include "testing/gtest/include/gtest/gtest.h"
49 50
50 namespace blink { 51 namespace blink {
51 52
52 class StubFrameLoaderClientWithParent final : public EmptyFrameLoaderClient { 53 class StubFrameLoaderClientWithParent final : public EmptyFrameLoaderClient {
53 public: 54 public:
54 static StubFrameLoaderClientWithParent* create(Frame* parent) 55 static StubFrameLoaderClientWithParent* create(Frame* parent)
55 { 56 {
56 return new StubFrameLoaderClientWithParent(parent); 57 return new StubFrameLoaderClientWithParent(parent);
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 { "https://example.test/image.png", "https://example.test/image.png" }, 225 { "https://example.test/image.png", "https://example.test/image.png" },
225 { "https://example.test:80/image.png", "https://example.test:80/image.pn g" }, 226 { "https://example.test:80/image.png", "https://example.test:80/image.pn g" },
226 { "https://example.test:1212/image.png", "https://example.test:1212/imag e.png" }, 227 { "https://example.test:1212/image.png", "https://example.test:1212/imag e.png" },
227 228
228 { "ftp://example.test/image.png", "ftp://example.test/image.png" }, 229 { "ftp://example.test/image.png", "ftp://example.test/image.png" },
229 { "ftp://example.test:21/image.png", "ftp://example.test:21/image.png" } , 230 { "ftp://example.test:21/image.png", "ftp://example.test:21/image.png" } ,
230 { "ftp://example.test:1212/image.png", "ftp://example.test:1212/image.pn g" }, 231 { "ftp://example.test:1212/image.png", "ftp://example.test:1212/image.pn g" },
231 }; 232 };
232 233
233 FrameFetchContext::provideDocumentToContext(*fetchContext, document.get()); 234 FrameFetchContext::provideDocumentToContext(*fetchContext, document.get());
234 document->setInsecureRequestsPolicy(SecurityContext::InsecureRequestsUpgrade ); 235 document->setInsecureRequestPolicy(kUpgradeInsecureRequests);
235 236
236 for (const auto& test : tests) { 237 for (const auto& test : tests) {
237 document->insecureNavigationsToUpgrade()->clear(); 238 document->insecureNavigationsToUpgrade()->clear();
238 239
239 // We always upgrade for FrameTypeNone and FrameTypeNested. 240 // We always upgrade for FrameTypeNone and FrameTypeNested.
240 expectUpgrade(test.original, WebURLRequest::RequestContextScript, WebURL Request::FrameTypeNone, test.upgraded); 241 expectUpgrade(test.original, WebURLRequest::RequestContextScript, WebURL Request::FrameTypeNone, test.upgraded);
241 expectUpgrade(test.original, WebURLRequest::RequestContextScript, WebURL Request::FrameTypeNested, test.upgraded); 242 expectUpgrade(test.original, WebURLRequest::RequestContextScript, WebURL Request::FrameTypeNested, test.upgraded);
242 243
243 // We do not upgrade for FrameTypeTopLevel or FrameTypeAuxiliary... 244 // We do not upgrade for FrameTypeTopLevel or FrameTypeAuxiliary...
244 expectUpgrade(test.original, WebURLRequest::RequestContextScript, WebURL Request::FrameTypeTopLevel, test.original); 245 expectUpgrade(test.original, WebURLRequest::RequestContextScript, WebURL Request::FrameTypeTopLevel, test.original);
245 expectUpgrade(test.original, WebURLRequest::RequestContextScript, WebURL Request::FrameTypeAuxiliary, test.original); 246 expectUpgrade(test.original, WebURLRequest::RequestContextScript, WebURL Request::FrameTypeAuxiliary, test.original);
246 247
247 // unless the request context is RequestContextForm. 248 // unless the request context is RequestContextForm.
248 expectUpgrade(test.original, WebURLRequest::RequestContextForm, WebURLRe quest::FrameTypeTopLevel, test.upgraded); 249 expectUpgrade(test.original, WebURLRequest::RequestContextForm, WebURLRe quest::FrameTypeTopLevel, test.upgraded);
249 expectUpgrade(test.original, WebURLRequest::RequestContextForm, WebURLRe quest::FrameTypeAuxiliary, test.upgraded); 250 expectUpgrade(test.original, WebURLRequest::RequestContextForm, WebURLRe quest::FrameTypeAuxiliary, test.upgraded);
250 251
251 // Or unless the host of the resource is in the document's InsecureNavig ationsSet: 252 // Or unless the host of the resource is in the document's InsecureNavig ationsSet:
252 document->addInsecureNavigationUpgrade(exampleOrigin->host().impl()->has h()); 253 document->addInsecureNavigationUpgrade(exampleOrigin->host().impl()->has h());
253 expectUpgrade(test.original, WebURLRequest::RequestContextScript, WebURL Request::FrameTypeTopLevel, test.upgraded); 254 expectUpgrade(test.original, WebURLRequest::RequestContextScript, WebURL Request::FrameTypeTopLevel, test.upgraded);
254 expectUpgrade(test.original, WebURLRequest::RequestContextScript, WebURL Request::FrameTypeAuxiliary, test.upgraded); 255 expectUpgrade(test.original, WebURLRequest::RequestContextScript, WebURL Request::FrameTypeAuxiliary, test.upgraded);
255 } 256 }
256 } 257 }
257 258
258 TEST_F(FrameFetchContextUpgradeTest, DoNotUpgradeInsecureResourceRequests) 259 TEST_F(FrameFetchContextUpgradeTest, DoNotUpgradeInsecureResourceRequests)
259 { 260 {
260 FrameFetchContext::provideDocumentToContext(*fetchContext, document.get()); 261 FrameFetchContext::provideDocumentToContext(*fetchContext, document.get());
261 document->setSecurityOrigin(secureOrigin); 262 document->setSecurityOrigin(secureOrigin);
262 document->setInsecureRequestsPolicy(SecurityContext::InsecureRequestsDoNotUp grade); 263 document->setInsecureRequestPolicy(kLeaveInsecureRequestsAlone);
263 264
264 expectUpgrade("http://example.test/image.png", "http://example.test/image.pn g"); 265 expectUpgrade("http://example.test/image.png", "http://example.test/image.pn g");
265 expectUpgrade("http://example.test:80/image.png", "http://example.test:80/im age.png"); 266 expectUpgrade("http://example.test:80/image.png", "http://example.test:80/im age.png");
266 expectUpgrade("http://example.test:1212/image.png", "http://example.test:121 2/image.png"); 267 expectUpgrade("http://example.test:1212/image.png", "http://example.test:121 2/image.png");
267 268
268 expectUpgrade("https://example.test/image.png", "https://example.test/image. png"); 269 expectUpgrade("https://example.test/image.png", "https://example.test/image. png");
269 expectUpgrade("https://example.test:80/image.png", "https://example.test:80/ image.png"); 270 expectUpgrade("https://example.test:80/image.png", "https://example.test:80/ image.png");
270 expectUpgrade("https://example.test:1212/image.png", "https://example.test:1 212/image.png"); 271 expectUpgrade("https://example.test:1212/image.png", "https://example.test:1 212/image.png");
271 272
272 expectUpgrade("ftp://example.test/image.png", "ftp://example.test/image.png" ); 273 expectUpgrade("ftp://example.test/image.png", "ftp://example.test/image.png" );
(...skipping 15 matching lines...) Expand all
288 { "https://example.test/page.html", WebURLRequest::FrameTypeAuxiliary, t rue }, 289 { "https://example.test/page.html", WebURLRequest::FrameTypeAuxiliary, t rue },
289 { "https://example.test/page.html", WebURLRequest::FrameTypeNested, true }, 290 { "https://example.test/page.html", WebURLRequest::FrameTypeNested, true },
290 { "https://example.test/page.html", WebURLRequest::FrameTypeNone, false }, 291 { "https://example.test/page.html", WebURLRequest::FrameTypeNone, false },
291 { "https://example.test/page.html", WebURLRequest::FrameTypeTopLevel, tr ue } 292 { "https://example.test/page.html", WebURLRequest::FrameTypeTopLevel, tr ue }
292 }; 293 };
293 294
294 // This should work correctly both when the FrameFetchContext has a Document , and 295 // This should work correctly both when the FrameFetchContext has a Document , and
295 // when it doesn't (e.g. during main frame navigations), so run through the tests 296 // when it doesn't (e.g. during main frame navigations), so run through the tests
296 // both before and after providing a document to the context. 297 // both before and after providing a document to the context.
297 for (const auto& test : tests) { 298 for (const auto& test : tests) {
298 document->setInsecureRequestsPolicy(SecurityContext::InsecureRequestsDoN otUpgrade); 299 document->setInsecureRequestPolicy(kLeaveInsecureRequestsAlone);
299 expectHTTPSHeader(test.toRequest, test.frameType, test.shouldPrefer); 300 expectHTTPSHeader(test.toRequest, test.frameType, test.shouldPrefer);
300 301
301 document->setInsecureRequestsPolicy(SecurityContext::InsecureRequestsUpg rade); 302 document->setInsecureRequestPolicy(kUpgradeInsecureRequests);
302 expectHTTPSHeader(test.toRequest, test.frameType, test.shouldPrefer); 303 expectHTTPSHeader(test.toRequest, test.frameType, test.shouldPrefer);
303 } 304 }
304 305
305 FrameFetchContext::provideDocumentToContext(*fetchContext, document.get()); 306 FrameFetchContext::provideDocumentToContext(*fetchContext, document.get());
306 307
307 for (const auto& test : tests) { 308 for (const auto& test : tests) {
308 document->setInsecureRequestsPolicy(SecurityContext::InsecureRequestsDoN otUpgrade); 309 document->setInsecureRequestPolicy(kLeaveInsecureRequestsAlone);
309 expectHTTPSHeader(test.toRequest, test.frameType, test.shouldPrefer); 310 expectHTTPSHeader(test.toRequest, test.frameType, test.shouldPrefer);
310 311
311 document->setInsecureRequestsPolicy(SecurityContext::InsecureRequestsUpg rade); 312 document->setInsecureRequestPolicy(kUpgradeInsecureRequests);
312 expectHTTPSHeader(test.toRequest, test.frameType, test.shouldPrefer); 313 expectHTTPSHeader(test.toRequest, test.frameType, test.shouldPrefer);
313 } 314 }
314 } 315 }
315 316
316 class FrameFetchContextHintsTest : public FrameFetchContextTest { 317 class FrameFetchContextHintsTest : public FrameFetchContextTest {
317 public: 318 public:
318 FrameFetchContextHintsTest() { } 319 FrameFetchContextHintsTest() { }
319 320
320 protected: 321 protected:
321 void expectHeader(const char* input, const char* headerName, bool isPresent, const char* headerValue, float width = 0) 322 void expectHeader(const char* input, const char* headerName, bool isPresent, const char* headerValue, float width = 0)
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 fetchContext->addAdditionalRequestHeaders(mainRequest, FetchMainResource ); 628 fetchContext->addAdditionalRequestHeaders(mainRequest, FetchMainResource );
628 EXPECT_EQ(mainRequest.isExternalRequest(), test.isExternalExpectation); 629 EXPECT_EQ(mainRequest.isExternalRequest(), test.isExternalExpectation);
629 630
630 ResourceRequest subRequest(test.url); 631 ResourceRequest subRequest(test.url);
631 fetchContext->addAdditionalRequestHeaders(subRequest, FetchSubresource); 632 fetchContext->addAdditionalRequestHeaders(subRequest, FetchSubresource);
632 EXPECT_EQ(subRequest.isExternalRequest(), test.isExternalExpectation); 633 EXPECT_EQ(subRequest.isExternalRequest(), test.isExternalExpectation);
633 } 634 }
634 } 635 }
635 636
636 } // namespace blink 637 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/loader/FrameFetchContext.cpp ('k') | third_party/WebKit/Source/core/loader/FrameLoader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698