| 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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 | 179 |
| 180 void expectUpgrade(const char* input, WebURLRequest::RequestContext requestC
ontext, WebURLRequest::FrameType frameType, const char* expected) | 180 void expectUpgrade(const char* input, WebURLRequest::RequestContext requestC
ontext, WebURLRequest::FrameType frameType, const char* expected) |
| 181 { | 181 { |
| 182 KURL inputURL(ParsedURLString, input); | 182 KURL inputURL(ParsedURLString, input); |
| 183 KURL expectedURL(ParsedURLString, expected); | 183 KURL expectedURL(ParsedURLString, expected); |
| 184 | 184 |
| 185 FetchRequest fetchRequest = FetchRequest(ResourceRequest(inputURL), Fetc
hInitiatorInfo()); | 185 FetchRequest fetchRequest = FetchRequest(ResourceRequest(inputURL), Fetc
hInitiatorInfo()); |
| 186 fetchRequest.mutableResourceRequest().setRequestContext(requestContext); | 186 fetchRequest.mutableResourceRequest().setRequestContext(requestContext); |
| 187 fetchRequest.mutableResourceRequest().setFrameType(frameType); | 187 fetchRequest.mutableResourceRequest().setFrameType(frameType); |
| 188 | 188 |
| 189 fetchContext->upgradeInsecureRequest(fetchRequest); | 189 fetchContext->upgradeInsecureRequest(fetchRequest.mutableResourceRequest
()); |
| 190 | 190 |
| 191 EXPECT_STREQ(expectedURL.getString().utf8().data(), fetchRequest.resourc
eRequest().url().getString().utf8().data()); | 191 EXPECT_STREQ(expectedURL.getString().utf8().data(), fetchRequest.resourc
eRequest().url().getString().utf8().data()); |
| 192 EXPECT_EQ(expectedURL.protocol(), fetchRequest.resourceRequest().url().p
rotocol()); | 192 EXPECT_EQ(expectedURL.protocol(), fetchRequest.resourceRequest().url().p
rotocol()); |
| 193 EXPECT_EQ(expectedURL.host(), fetchRequest.resourceRequest().url().host(
)); | 193 EXPECT_EQ(expectedURL.host(), fetchRequest.resourceRequest().url().host(
)); |
| 194 EXPECT_EQ(expectedURL.port(), fetchRequest.resourceRequest().url().port(
)); | 194 EXPECT_EQ(expectedURL.port(), fetchRequest.resourceRequest().url().port(
)); |
| 195 EXPECT_EQ(expectedURL.hasPort(), fetchRequest.resourceRequest().url().ha
sPort()); | 195 EXPECT_EQ(expectedURL.hasPort(), fetchRequest.resourceRequest().url().ha
sPort()); |
| 196 EXPECT_EQ(expectedURL.path(), fetchRequest.resourceRequest().url().path(
)); | 196 EXPECT_EQ(expectedURL.path(), fetchRequest.resourceRequest().url().path(
)); |
| 197 } | 197 } |
| 198 | 198 |
| 199 void expectHTTPSHeader(const char* input, WebURLRequest::FrameType frameType
, bool shouldPrefer) | 199 void expectHTTPSHeader(const char* input, WebURLRequest::FrameType frameType
, bool shouldPrefer) |
| 200 { | 200 { |
| 201 KURL inputURL(ParsedURLString, input); | 201 KURL inputURL(ParsedURLString, input); |
| 202 | 202 |
| 203 FetchRequest fetchRequest = FetchRequest(ResourceRequest(inputURL), Fetc
hInitiatorInfo()); | 203 FetchRequest fetchRequest = FetchRequest(ResourceRequest(inputURL), Fetc
hInitiatorInfo()); |
| 204 fetchRequest.mutableResourceRequest().setRequestContext(WebURLRequest::R
equestContextScript); | 204 fetchRequest.mutableResourceRequest().setRequestContext(WebURLRequest::R
equestContextScript); |
| 205 fetchRequest.mutableResourceRequest().setFrameType(frameType); | 205 fetchRequest.mutableResourceRequest().setFrameType(frameType); |
| 206 | 206 |
| 207 fetchContext->upgradeInsecureRequest(fetchRequest); | 207 fetchContext->upgradeInsecureRequest(fetchRequest.mutableResourceRequest
()); |
| 208 | 208 |
| 209 EXPECT_STREQ(shouldPrefer ? "1" : "", | 209 EXPECT_STREQ(shouldPrefer ? "1" : "", |
| 210 fetchRequest.resourceRequest().httpHeaderField(HTTPNames::Upgrade_In
secure_Requests).utf8().data()); | 210 fetchRequest.resourceRequest().httpHeaderField(HTTPNames::Upgrade_In
secure_Requests).utf8().data()); |
| 211 |
| 212 // Calling upgradeInsecureRequest more than once shouldn't affect the he
ader. |
| 213 if (shouldPrefer) { |
| 214 fetchContext->upgradeInsecureRequest(fetchRequest.mutableResourceReq
uest()); |
| 215 EXPECT_STREQ("1", fetchRequest.resourceRequest().httpHeaderField(HTT
PNames::Upgrade_Insecure_Requests).utf8().data()); |
| 216 } |
| 211 } | 217 } |
| 212 | 218 |
| 213 RefPtr<SecurityOrigin> exampleOrigin; | 219 RefPtr<SecurityOrigin> exampleOrigin; |
| 214 RefPtr<SecurityOrigin> secureOrigin; | 220 RefPtr<SecurityOrigin> secureOrigin; |
| 215 }; | 221 }; |
| 216 | 222 |
| 217 TEST_F(FrameFetchContextUpgradeTest, UpgradeInsecureResourceRequests) | 223 TEST_F(FrameFetchContextUpgradeTest, UpgradeInsecureResourceRequests) |
| 218 { | 224 { |
| 219 struct TestCase { | 225 struct TestCase { |
| 220 const char* original; | 226 const char* original; |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 fetchContext->addAdditionalRequestHeaders(mainRequest, FetchMainResource
); | 636 fetchContext->addAdditionalRequestHeaders(mainRequest, FetchMainResource
); |
| 631 EXPECT_EQ(mainRequest.isExternalRequest(), test.isExternalExpectation); | 637 EXPECT_EQ(mainRequest.isExternalRequest(), test.isExternalExpectation); |
| 632 | 638 |
| 633 ResourceRequest subRequest(test.url); | 639 ResourceRequest subRequest(test.url); |
| 634 fetchContext->addAdditionalRequestHeaders(subRequest, FetchSubresource); | 640 fetchContext->addAdditionalRequestHeaders(subRequest, FetchSubresource); |
| 635 EXPECT_EQ(subRequest.isExternalRequest(), test.isExternalExpectation); | 641 EXPECT_EQ(subRequest.isExternalRequest(), test.isExternalExpectation); |
| 636 } | 642 } |
| 637 } | 643 } |
| 638 | 644 |
| 639 } // namespace blink | 645 } // namespace blink |
| OLD | NEW |