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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
177 | 177 |
178 void expectUpgrade(const char* input, WebURLRequest::RequestContext requestC ontext, WebURLRequest::FrameType frameType, const char* expected) | 178 void expectUpgrade(const char* input, WebURLRequest::RequestContext requestC ontext, WebURLRequest::FrameType frameType, const char* expected) |
179 { | 179 { |
180 KURL inputURL(ParsedURLString, input); | 180 KURL inputURL(ParsedURLString, input); |
181 KURL expectedURL(ParsedURLString, expected); | 181 KURL expectedURL(ParsedURLString, expected); |
182 | 182 |
183 FetchRequest fetchRequest = FetchRequest(ResourceRequest(inputURL), Fetc hInitiatorInfo()); | 183 FetchRequest fetchRequest = FetchRequest(ResourceRequest(inputURL), Fetc hInitiatorInfo()); |
184 fetchRequest.mutableResourceRequest().setRequestContext(requestContext); | 184 fetchRequest.mutableResourceRequest().setRequestContext(requestContext); |
185 fetchRequest.mutableResourceRequest().setFrameType(frameType); | 185 fetchRequest.mutableResourceRequest().setFrameType(frameType); |
186 | 186 |
187 fetchContext->upgradeInsecureRequest(fetchRequest.mutableResourceRequest ()); | 187 fetchContext->addOutgoingSecurityHeadersAndUpgradeRequest(fetchRequest.m utableResourceRequest()); |
Mike West
2016/10/06 08:00:51
Please add tests in this file for the header you'r
| |
188 | 188 |
189 EXPECT_EQ(expectedURL.getString(), fetchRequest.resourceRequest().url(). getString()); | 189 EXPECT_EQ(expectedURL.getString(), fetchRequest.resourceRequest().url(). getString()); |
190 EXPECT_EQ(expectedURL.protocol(), fetchRequest.resourceRequest().url().p rotocol()); | 190 EXPECT_EQ(expectedURL.protocol(), fetchRequest.resourceRequest().url().p rotocol()); |
191 EXPECT_EQ(expectedURL.host(), fetchRequest.resourceRequest().url().host( )); | 191 EXPECT_EQ(expectedURL.host(), fetchRequest.resourceRequest().url().host( )); |
192 EXPECT_EQ(expectedURL.port(), fetchRequest.resourceRequest().url().port( )); | 192 EXPECT_EQ(expectedURL.port(), fetchRequest.resourceRequest().url().port( )); |
193 EXPECT_EQ(expectedURL.hasPort(), fetchRequest.resourceRequest().url().ha sPort()); | 193 EXPECT_EQ(expectedURL.hasPort(), fetchRequest.resourceRequest().url().ha sPort()); |
194 EXPECT_EQ(expectedURL.path(), fetchRequest.resourceRequest().url().path( )); | 194 EXPECT_EQ(expectedURL.path(), fetchRequest.resourceRequest().url().path( )); |
195 } | 195 } |
196 | 196 |
197 void expectHTTPSHeader(const char* input, WebURLRequest::FrameType frameType , bool shouldPrefer) | 197 void expectHTTPSHeader(const char* input, WebURLRequest::FrameType frameType , bool shouldPrefer) |
Mike West
2016/10/06 08:00:51
Nit: While you're here, could you rename this to `
| |
198 { | 198 { |
199 KURL inputURL(ParsedURLString, input); | 199 KURL inputURL(ParsedURLString, input); |
200 | 200 |
201 FetchRequest fetchRequest = FetchRequest(ResourceRequest(inputURL), Fetc hInitiatorInfo()); | 201 FetchRequest fetchRequest = FetchRequest(ResourceRequest(inputURL), Fetc hInitiatorInfo()); |
202 fetchRequest.mutableResourceRequest().setRequestContext(WebURLRequest::R equestContextScript); | 202 fetchRequest.mutableResourceRequest().setRequestContext(WebURLRequest::R equestContextScript); |
203 fetchRequest.mutableResourceRequest().setFrameType(frameType); | 203 fetchRequest.mutableResourceRequest().setFrameType(frameType); |
204 | 204 |
205 fetchContext->upgradeInsecureRequest(fetchRequest.mutableResourceRequest ()); | 205 fetchContext->addOutgoingSecurityHeadersAndUpgradeRequest(fetchRequest.m utableResourceRequest()); |
206 | 206 |
207 EXPECT_EQ(shouldPrefer ? String("1") : String(), | 207 EXPECT_EQ(shouldPrefer ? String("1") : String(), |
208 fetchRequest.resourceRequest().httpHeaderField(HTTPNames::Upgrade_In secure_Requests)); | 208 fetchRequest.resourceRequest().httpHeaderField(HTTPNames::Upgrade_In secure_Requests)); |
209 | 209 |
210 // Calling upgradeInsecureRequest more than once shouldn't affect the he ader. | 210 // Calling upgradeInsecureRequest more than once shouldn't affect the he ader. |
211 if (shouldPrefer) { | 211 if (shouldPrefer) { |
212 fetchContext->upgradeInsecureRequest(fetchRequest.mutableResourceReq uest()); | 212 fetchContext->addOutgoingSecurityHeadersAndUpgradeRequest(fetchReque st.mutableResourceRequest()); |
213 EXPECT_EQ("1", fetchRequest.resourceRequest().httpHeaderField(HTTPNa mes::Upgrade_Insecure_Requests)); | 213 EXPECT_EQ("1", fetchRequest.resourceRequest().httpHeaderField(HTTPNa mes::Upgrade_Insecure_Requests)); |
214 } | 214 } |
215 } | 215 } |
216 | 216 |
217 RefPtr<SecurityOrigin> exampleOrigin; | 217 RefPtr<SecurityOrigin> exampleOrigin; |
218 RefPtr<SecurityOrigin> secureOrigin; | 218 RefPtr<SecurityOrigin> secureOrigin; |
219 }; | 219 }; |
220 | 220 |
221 TEST_F(FrameFetchContextUpgradeTest, UpgradeInsecureResourceRequests) | 221 TEST_F(FrameFetchContextUpgradeTest, UpgradeInsecureResourceRequests) |
222 { | 222 { |
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
687 fetchContext->addAdditionalRequestHeaders(mainRequest, FetchMainResource ); | 687 fetchContext->addAdditionalRequestHeaders(mainRequest, FetchMainResource ); |
688 EXPECT_EQ(test.isExternalExpectation, mainRequest.isExternalRequest()); | 688 EXPECT_EQ(test.isExternalExpectation, mainRequest.isExternalRequest()); |
689 | 689 |
690 ResourceRequest subRequest(test.url); | 690 ResourceRequest subRequest(test.url); |
691 fetchContext->addAdditionalRequestHeaders(subRequest, FetchSubresource); | 691 fetchContext->addAdditionalRequestHeaders(subRequest, FetchSubresource); |
692 EXPECT_EQ(test.isExternalExpectation, subRequest.isExternalRequest()); | 692 EXPECT_EQ(test.isExternalExpectation, subRequest.isExternalRequest()); |
693 } | 693 } |
694 } | 694 } |
695 | 695 |
696 } // namespace blink | 696 } // namespace blink |
OLD | NEW |