| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013, Google Inc. All rights reserved. | 2 * Copyright (c) 2013, 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 | 74 |
| 75 void expectUpgrade(const char* input, WebURLRequest::RequestContext requestC
ontext, WebURLRequest::FrameType frameType, const char* expected) | 75 void expectUpgrade(const char* input, WebURLRequest::RequestContext requestC
ontext, WebURLRequest::FrameType frameType, const char* expected) |
| 76 { | 76 { |
| 77 KURL inputURL(ParsedURLString, input); | 77 KURL inputURL(ParsedURLString, input); |
| 78 KURL expectedURL(ParsedURLString, expected); | 78 KURL expectedURL(ParsedURLString, expected); |
| 79 | 79 |
| 80 FetchRequest fetchRequest = FetchRequest(ResourceRequest(inputURL), Fetc
hInitiatorInfo()); | 80 FetchRequest fetchRequest = FetchRequest(ResourceRequest(inputURL), Fetc
hInitiatorInfo()); |
| 81 fetchRequest.mutableResourceRequest().setRequestContext(requestContext); | 81 fetchRequest.mutableResourceRequest().setRequestContext(requestContext); |
| 82 fetchRequest.mutableResourceRequest().setFrameType(frameType); | 82 fetchRequest.mutableResourceRequest().setFrameType(frameType); |
| 83 | 83 |
| 84 fetcher->maybeUpgradeInsecureRequestURL(fetchRequest); | 84 fetcher->upgradeInsecureRequest(fetchRequest); |
| 85 | 85 |
| 86 EXPECT_STREQ(expectedURL.string().utf8().data(), fetchRequest.resourceRe
quest().url().string().utf8().data()); | 86 EXPECT_STREQ(expectedURL.string().utf8().data(), fetchRequest.resourceRe
quest().url().string().utf8().data()); |
| 87 EXPECT_EQ(expectedURL.protocol(), fetchRequest.resourceRequest().url().p
rotocol()); | 87 EXPECT_EQ(expectedURL.protocol(), fetchRequest.resourceRequest().url().p
rotocol()); |
| 88 EXPECT_EQ(expectedURL.host(), fetchRequest.resourceRequest().url().host(
)); | 88 EXPECT_EQ(expectedURL.host(), fetchRequest.resourceRequest().url().host(
)); |
| 89 EXPECT_EQ(expectedURL.port(), fetchRequest.resourceRequest().url().port(
)); | 89 EXPECT_EQ(expectedURL.port(), fetchRequest.resourceRequest().url().port(
)); |
| 90 EXPECT_EQ(expectedURL.hasPort(), fetchRequest.resourceRequest().url().ha
sPort()); | 90 EXPECT_EQ(expectedURL.hasPort(), fetchRequest.resourceRequest().url().ha
sPort()); |
| 91 EXPECT_EQ(expectedURL.path(), fetchRequest.resourceRequest().url().path(
)); | 91 EXPECT_EQ(expectedURL.path(), fetchRequest.resourceRequest().url().path(
)); |
| 92 } | 92 } |
| 93 | 93 |
| 94 void expectPreferHeader(const char* input, WebURLRequest::FrameType frameTyp
e, bool shouldPrefer) |
| 95 { |
| 96 KURL inputURL(ParsedURLString, input); |
| 97 |
| 98 FetchRequest fetchRequest = FetchRequest(ResourceRequest(inputURL), Fetc
hInitiatorInfo()); |
| 99 fetchRequest.mutableResourceRequest().setRequestContext(WebURLRequest::R
equestContextScript); |
| 100 fetchRequest.mutableResourceRequest().setFrameType(frameType); |
| 101 |
| 102 fetcher->upgradeInsecureRequest(fetchRequest); |
| 103 |
| 104 EXPECT_STREQ(shouldPrefer ? "return=secure-representation" : "", |
| 105 fetchRequest.resourceRequest().httpHeaderField("Prefer").utf8().data
()); |
| 106 } |
| 107 |
| 94 KURL secureURL; | 108 KURL secureURL; |
| 95 RefPtr<SecurityOrigin> exampleOrigin; | 109 RefPtr<SecurityOrigin> exampleOrigin; |
| 96 RefPtr<SecurityOrigin> secureOrigin; | 110 RefPtr<SecurityOrigin> secureOrigin; |
| 97 | 111 |
| 98 // We don't use the DocumentLoader directly in any tests, but need to keep i
t around as long | 112 // We don't use the DocumentLoader directly in any tests, but need to keep i
t around as long |
| 99 // as the ResourceFetcher and Document live due to indirect usage. | 113 // as the ResourceFetcher and Document live due to indirect usage. |
| 100 RefPtr<DocumentLoader> documentLoader; | 114 RefPtr<DocumentLoader> documentLoader; |
| 101 RefPtrWillBePersistent<ResourceFetcher> fetcher; | 115 RefPtrWillBePersistent<ResourceFetcher> fetcher; |
| 102 RefPtrWillBePersistent<Document> document; | 116 RefPtrWillBePersistent<Document> document; |
| 103 }; | 117 }; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 | 201 |
| 188 expectUpgrade("https://example.test/image.png", "https://example.test/image.
png"); | 202 expectUpgrade("https://example.test/image.png", "https://example.test/image.
png"); |
| 189 expectUpgrade("https://example.test:80/image.png", "https://example.test:80/
image.png"); | 203 expectUpgrade("https://example.test:80/image.png", "https://example.test:80/
image.png"); |
| 190 expectUpgrade("https://example.test:1212/image.png", "https://example.test:1
212/image.png"); | 204 expectUpgrade("https://example.test:1212/image.png", "https://example.test:1
212/image.png"); |
| 191 | 205 |
| 192 expectUpgrade("ftp://example.test/image.png", "ftp://example.test/image.png"
); | 206 expectUpgrade("ftp://example.test/image.png", "ftp://example.test/image.png"
); |
| 193 expectUpgrade("ftp://example.test:21/image.png", "ftp://example.test:21/imag
e.png"); | 207 expectUpgrade("ftp://example.test:21/image.png", "ftp://example.test:21/imag
e.png"); |
| 194 expectUpgrade("ftp://example.test:1212/image.png", "ftp://example.test:1212/
image.png"); | 208 expectUpgrade("ftp://example.test:1212/image.png", "ftp://example.test:1212/
image.png"); |
| 195 } | 209 } |
| 196 | 210 |
| 211 TEST_F(ResourceFetcherTest, SendPreferHeader) |
| 212 { |
| 213 struct TestCase { |
| 214 const char* toRequest; |
| 215 WebURLRequest::FrameType frameType; |
| 216 bool shouldPrefer; |
| 217 } tests[] = { |
| 218 { "http://example.test/page.html", WebURLRequest::FrameTypeAuxiliary, tr
ue }, |
| 219 { "http://example.test/page.html", WebURLRequest::FrameTypeNested, true
}, |
| 220 { "http://example.test/page.html", WebURLRequest::FrameTypeNone, false }
, |
| 221 { "http://example.test/page.html", WebURLRequest::FrameTypeTopLevel, tru
e }, |
| 222 { "https://example.test/page.html", WebURLRequest::FrameTypeAuxiliary, f
alse }, |
| 223 { "https://example.test/page.html", WebURLRequest::FrameTypeNested, fals
e }, |
| 224 { "https://example.test/page.html", WebURLRequest::FrameTypeNone, false
}, |
| 225 { "https://example.test/page.html", WebURLRequest::FrameTypeTopLevel, fa
lse } |
| 226 }; |
| 227 |
| 228 for (auto test : tests) { |
| 229 document->setInsecureContentPolicy(SecurityContext::InsecureContentDoNot
Upgrade); |
| 230 expectPreferHeader(test.toRequest, test.frameType, test.shouldPrefer); |
| 231 |
| 232 document->setInsecureContentPolicy(SecurityContext::InsecureContentUpgra
de); |
| 233 expectPreferHeader(test.toRequest, test.frameType, test.shouldPrefer); |
| 234 |
| 235 document->setInsecureContentPolicy(SecurityContext::InsecureContentMonit
or); |
| 236 expectPreferHeader(test.toRequest, test.frameType, test.shouldPrefer); |
| 237 } |
| 238 } |
| 239 |
| 197 } // namespace | 240 } // namespace |
| OLD | NEW |