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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 fetchRequest.mutableResourceRequest().setFrameType(frameType); | 78 fetchRequest.mutableResourceRequest().setFrameType(frameType); |
79 | 79 |
80 fetchContext->upgradeInsecureRequest(fetchRequest); | 80 fetchContext->upgradeInsecureRequest(fetchRequest); |
81 | 81 |
82 EXPECT_STREQ(expectedURL.string().utf8().data(), fetchRequest.resourceRe
quest().url().string().utf8().data()); | 82 EXPECT_STREQ(expectedURL.string().utf8().data(), fetchRequest.resourceRe
quest().url().string().utf8().data()); |
83 EXPECT_EQ(expectedURL.protocol(), fetchRequest.resourceRequest().url().p
rotocol()); | 83 EXPECT_EQ(expectedURL.protocol(), fetchRequest.resourceRequest().url().p
rotocol()); |
84 EXPECT_EQ(expectedURL.host(), fetchRequest.resourceRequest().url().host(
)); | 84 EXPECT_EQ(expectedURL.host(), fetchRequest.resourceRequest().url().host(
)); |
85 EXPECT_EQ(expectedURL.port(), fetchRequest.resourceRequest().url().port(
)); | 85 EXPECT_EQ(expectedURL.port(), fetchRequest.resourceRequest().url().port(
)); |
86 EXPECT_EQ(expectedURL.hasPort(), fetchRequest.resourceRequest().url().ha
sPort()); | 86 EXPECT_EQ(expectedURL.hasPort(), fetchRequest.resourceRequest().url().ha
sPort()); |
87 EXPECT_EQ(expectedURL.path(), fetchRequest.resourceRequest().url().path(
)); | 87 EXPECT_EQ(expectedURL.path(), fetchRequest.resourceRequest().url().path(
)); |
88 | |
89 bool expectUpgrade = inputURL != expectedURL; | |
90 | |
91 EXPECT_STREQ(expectUpgrade ? "1" : "", | |
92 fetchRequest.resourceRequest().httpHeaderField("Upgraded").utf8().da
ta()); | |
93 } | 88 } |
94 | 89 |
95 void expectPreferHeader(const char* input, WebURLRequest::FrameType frameTyp
e, bool shouldPrefer) | 90 void expectHTTPSHeader(const char* input, WebURLRequest::FrameType frameType
, bool shouldPrefer) |
96 { | 91 { |
97 KURL inputURL(ParsedURLString, input); | 92 KURL inputURL(ParsedURLString, input); |
98 | 93 |
99 FetchRequest fetchRequest = FetchRequest(ResourceRequest(inputURL), Fetc
hInitiatorInfo()); | 94 FetchRequest fetchRequest = FetchRequest(ResourceRequest(inputURL), Fetc
hInitiatorInfo()); |
100 fetchRequest.mutableResourceRequest().setRequestContext(WebURLRequest::R
equestContextScript); | 95 fetchRequest.mutableResourceRequest().setRequestContext(WebURLRequest::R
equestContextScript); |
101 fetchRequest.mutableResourceRequest().setFrameType(frameType); | 96 fetchRequest.mutableResourceRequest().setFrameType(frameType); |
102 | 97 |
103 fetchContext->upgradeInsecureRequest(fetchRequest); | 98 fetchContext->upgradeInsecureRequest(fetchRequest); |
104 | 99 |
105 EXPECT_STREQ(shouldPrefer ? "tls" : "", | 100 EXPECT_STREQ(shouldPrefer ? "1" : "", |
106 fetchRequest.resourceRequest().httpHeaderField("Prefer").utf8().data
()); | 101 fetchRequest.resourceRequest().httpHeaderField("HTTPS").utf8().data(
)); |
107 } | 102 } |
108 | 103 |
109 KURL secureURL; | 104 KURL secureURL; |
110 RefPtr<SecurityOrigin> exampleOrigin; | 105 RefPtr<SecurityOrigin> exampleOrigin; |
111 RefPtr<SecurityOrigin> secureOrigin; | 106 RefPtr<SecurityOrigin> secureOrigin; |
112 | 107 |
113 OwnPtr<DummyPageHolder> dummyPageHolder; | 108 OwnPtr<DummyPageHolder> dummyPageHolder; |
114 // We don't use the DocumentLoader directly in any tests, but need to keep i
t around as long | 109 // We don't use the DocumentLoader directly in any tests, but need to keep i
t around as long |
115 // as the ResourceFetcher and Document live due to indirect usage. | 110 // as the ResourceFetcher and Document live due to indirect usage. |
116 RefPtr<DocumentLoader> documentLoader; | 111 RefPtr<DocumentLoader> documentLoader; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 { | 178 { |
184 struct TestCase { | 179 struct TestCase { |
185 const char* toRequest; | 180 const char* toRequest; |
186 WebURLRequest::FrameType frameType; | 181 WebURLRequest::FrameType frameType; |
187 bool shouldPrefer; | 182 bool shouldPrefer; |
188 } tests[] = { | 183 } tests[] = { |
189 { "http://example.test/page.html", WebURLRequest::FrameTypeAuxiliary, tr
ue }, | 184 { "http://example.test/page.html", WebURLRequest::FrameTypeAuxiliary, tr
ue }, |
190 { "http://example.test/page.html", WebURLRequest::FrameTypeNested, true
}, | 185 { "http://example.test/page.html", WebURLRequest::FrameTypeNested, true
}, |
191 { "http://example.test/page.html", WebURLRequest::FrameTypeNone, false }
, | 186 { "http://example.test/page.html", WebURLRequest::FrameTypeNone, false }
, |
192 { "http://example.test/page.html", WebURLRequest::FrameTypeTopLevel, tru
e }, | 187 { "http://example.test/page.html", WebURLRequest::FrameTypeTopLevel, tru
e }, |
193 { "https://example.test/page.html", WebURLRequest::FrameTypeAuxiliary, f
alse }, | 188 { "https://example.test/page.html", WebURLRequest::FrameTypeAuxiliary, t
rue }, |
194 { "https://example.test/page.html", WebURLRequest::FrameTypeNested, fals
e }, | 189 { "https://example.test/page.html", WebURLRequest::FrameTypeNested, true
}, |
195 { "https://example.test/page.html", WebURLRequest::FrameTypeNone, false
}, | 190 { "https://example.test/page.html", WebURLRequest::FrameTypeNone, false
}, |
196 { "https://example.test/page.html", WebURLRequest::FrameTypeTopLevel, fa
lse } | 191 { "https://example.test/page.html", WebURLRequest::FrameTypeTopLevel, tr
ue } |
197 }; | 192 }; |
198 | 193 |
199 for (auto test : tests) { | 194 for (auto test : tests) { |
200 document->setInsecureRequestsPolicy(SecurityContext::InsecureRequestsDoN
otUpgrade); | 195 document->setInsecureRequestsPolicy(SecurityContext::InsecureRequestsDoN
otUpgrade); |
201 expectPreferHeader(test.toRequest, test.frameType, test.shouldPrefer); | 196 expectHTTPSHeader(test.toRequest, test.frameType, test.shouldPrefer); |
202 | 197 |
203 document->setInsecureRequestsPolicy(SecurityContext::InsecureRequestsUpg
rade); | 198 document->setInsecureRequestsPolicy(SecurityContext::InsecureRequestsUpg
rade); |
204 expectPreferHeader(test.toRequest, test.frameType, test.shouldPrefer); | 199 expectHTTPSHeader(test.toRequest, test.frameType, test.shouldPrefer); |
205 } | 200 } |
206 } | 201 } |
207 | 202 |
208 class FrameFetchContextHintsTest : public ::testing::Test { | 203 class FrameFetchContextHintsTest : public ::testing::Test { |
209 public: | 204 public: |
210 FrameFetchContextHintsTest() { } | 205 FrameFetchContextHintsTest() { } |
211 | 206 |
212 protected: | 207 protected: |
213 virtual void SetUp() | 208 virtual void SetUp() |
214 { | 209 { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 expectHeader("http://www.example.com/1.gif", "RW", false, ""); | 260 expectHeader("http://www.example.com/1.gif", "RW", false, ""); |
266 | 261 |
267 dummyPageHolder->frame().setShouldSendDPRHint(); | 262 dummyPageHolder->frame().setShouldSendDPRHint(); |
268 dummyPageHolder->frame().setShouldSendRWHint(); | 263 dummyPageHolder->frame().setShouldSendRWHint(); |
269 expectHeader("http://www.example.com/1.gif", "DPR", true, "1"); | 264 expectHeader("http://www.example.com/1.gif", "DPR", true, "1"); |
270 expectHeader("http://www.example.com/1.gif", "RW", true, "500"); | 265 expectHeader("http://www.example.com/1.gif", "RW", true, "500"); |
271 } | 266 } |
272 | 267 |
273 } // namespace | 268 } // namespace |
274 | 269 |
OLD | NEW |