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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 virtual void SetUp() | 56 virtual void SetUp() |
57 { | 57 { |
58 dummyPageHolder = DummyPageHolder::create(IntSize(500, 500)); | 58 dummyPageHolder = DummyPageHolder::create(IntSize(500, 500)); |
59 dummyPageHolder->page().setDeviceScaleFactor(1.0); | 59 dummyPageHolder->page().setDeviceScaleFactor(1.0); |
60 documentLoader = DocumentLoader::create(&dummyPageHolder->frame(), Resou
rceRequest("http://www.example.com"), SubstituteData()); | 60 documentLoader = DocumentLoader::create(&dummyPageHolder->frame(), Resou
rceRequest("http://www.example.com"), SubstituteData()); |
61 document = toHTMLDocument(&dummyPageHolder->document()); | 61 document = toHTMLDocument(&dummyPageHolder->document()); |
62 fetchContext = &documentLoader->fetcher()->context(); | 62 fetchContext = &documentLoader->fetcher()->context(); |
63 FrameFetchContext::provideDocumentToContext(*fetchContext, document.get(
)); | 63 FrameFetchContext::provideDocumentToContext(*fetchContext, document.get(
)); |
64 } | 64 } |
65 | 65 |
| 66 virtual void TearDown() |
| 67 { |
| 68 documentLoader->detachFromFrame(); |
| 69 documentLoader.clear(); |
| 70 } |
| 71 |
66 void expectUpgrade(const char* input, const char* expected) | 72 void expectUpgrade(const char* input, const char* expected) |
67 { | 73 { |
68 expectUpgrade(input, WebURLRequest::RequestContextScript, WebURLRequest:
:FrameTypeNone, expected); | 74 expectUpgrade(input, WebURLRequest::RequestContextScript, WebURLRequest:
:FrameTypeNone, expected); |
69 } | 75 } |
70 | 76 |
71 void expectUpgrade(const char* input, WebURLRequest::RequestContext requestC
ontext, WebURLRequest::FrameType frameType, const char* expected) | 77 void expectUpgrade(const char* input, WebURLRequest::RequestContext requestC
ontext, WebURLRequest::FrameType frameType, const char* expected) |
72 { | 78 { |
73 KURL inputURL(ParsedURLString, input); | 79 KURL inputURL(ParsedURLString, input); |
74 KURL expectedURL(ParsedURLString, expected); | 80 KURL expectedURL(ParsedURLString, expected); |
75 | 81 |
(...skipping 25 matching lines...) Expand all Loading... |
101 fetchRequest.resourceRequest().httpHeaderField("HTTPS").utf8().data(
)); | 107 fetchRequest.resourceRequest().httpHeaderField("HTTPS").utf8().data(
)); |
102 } | 108 } |
103 | 109 |
104 KURL secureURL; | 110 KURL secureURL; |
105 RefPtr<SecurityOrigin> exampleOrigin; | 111 RefPtr<SecurityOrigin> exampleOrigin; |
106 RefPtr<SecurityOrigin> secureOrigin; | 112 RefPtr<SecurityOrigin> secureOrigin; |
107 | 113 |
108 OwnPtr<DummyPageHolder> dummyPageHolder; | 114 OwnPtr<DummyPageHolder> dummyPageHolder; |
109 // We don't use the DocumentLoader directly in any tests, but need to keep i
t around as long | 115 // We don't use the DocumentLoader directly in any tests, but need to keep i
t around as long |
110 // as the ResourceFetcher and Document live due to indirect usage. | 116 // as the ResourceFetcher and Document live due to indirect usage. |
111 RefPtr<DocumentLoader> documentLoader; | 117 RefPtrWillBePersistent<DocumentLoader> documentLoader; |
112 RefPtrWillBePersistent<Document> document; | 118 RefPtrWillBePersistent<Document> document; |
113 FetchContext* fetchContext; | 119 FetchContext* fetchContext; |
114 }; | 120 }; |
115 | 121 |
116 TEST_F(FrameFetchContextUpgradeTest, UpgradeInsecureResourceRequests) | 122 TEST_F(FrameFetchContextUpgradeTest, UpgradeInsecureResourceRequests) |
117 { | 123 { |
118 struct TestCase { | 124 struct TestCase { |
119 const char* original; | 125 const char* original; |
120 const char* upgraded; | 126 const char* upgraded; |
121 } tests[] = { | 127 } tests[] = { |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 virtual void SetUp() | 229 virtual void SetUp() |
224 { | 230 { |
225 dummyPageHolder = DummyPageHolder::create(IntSize(500, 500)); | 231 dummyPageHolder = DummyPageHolder::create(IntSize(500, 500)); |
226 dummyPageHolder->page().setDeviceScaleFactor(1.0); | 232 dummyPageHolder->page().setDeviceScaleFactor(1.0); |
227 documentLoader = DocumentLoader::create(&dummyPageHolder->frame(), Resou
rceRequest("http://www.example.com"), SubstituteData()); | 233 documentLoader = DocumentLoader::create(&dummyPageHolder->frame(), Resou
rceRequest("http://www.example.com"), SubstituteData()); |
228 document = toHTMLDocument(&dummyPageHolder->document()); | 234 document = toHTMLDocument(&dummyPageHolder->document()); |
229 fetchContext = &documentLoader->fetcher()->context(); | 235 fetchContext = &documentLoader->fetcher()->context(); |
230 FrameFetchContext::provideDocumentToContext(*fetchContext, document.get(
)); | 236 FrameFetchContext::provideDocumentToContext(*fetchContext, document.get(
)); |
231 } | 237 } |
232 | 238 |
| 239 virtual void TearDown() |
| 240 { |
| 241 documentLoader->detachFromFrame(); |
| 242 documentLoader.clear(); |
| 243 } |
| 244 |
233 void expectHeader(const char* input, const char* headerName, bool isPresent,
const char* headerValue, float width = 0) | 245 void expectHeader(const char* input, const char* headerName, bool isPresent,
const char* headerValue, float width = 0) |
234 { | 246 { |
235 KURL inputURL(ParsedURLString, input); | 247 KURL inputURL(ParsedURLString, input); |
236 FetchRequest fetchRequest = FetchRequest(ResourceRequest(inputURL), Fetc
hInitiatorInfo()); | 248 FetchRequest fetchRequest = FetchRequest(ResourceRequest(inputURL), Fetc
hInitiatorInfo()); |
237 if (width > 0) { | 249 if (width > 0) { |
238 FetchRequest::ResourceWidth resourceWidth; | 250 FetchRequest::ResourceWidth resourceWidth; |
239 resourceWidth.width = width; | 251 resourceWidth.width = width; |
240 resourceWidth.isSet = true; | 252 resourceWidth.isSet = true; |
241 fetchRequest.setResourceWidth(resourceWidth); | 253 fetchRequest.setResourceWidth(resourceWidth); |
242 } | 254 } |
243 fetchContext->addClientHintsIfNecessary(fetchRequest); | 255 fetchContext->addClientHintsIfNecessary(fetchRequest); |
244 | 256 |
245 EXPECT_STREQ(isPresent ? headerValue : "", | 257 EXPECT_STREQ(isPresent ? headerValue : "", |
246 fetchRequest.resourceRequest().httpHeaderField(headerName).utf8().da
ta()); | 258 fetchRequest.resourceRequest().httpHeaderField(headerName).utf8().da
ta()); |
247 } | 259 } |
248 | 260 |
249 OwnPtr<DummyPageHolder> dummyPageHolder; | 261 OwnPtr<DummyPageHolder> dummyPageHolder; |
250 // We don't use the DocumentLoader directly in any tests, but need to keep i
t around as long | 262 // We don't use the DocumentLoader directly in any tests, but need to keep i
t around as long |
251 // as the ResourceFetcher and Document live due to indirect usage. | 263 // as the ResourceFetcher and Document live due to indirect usage. |
252 RefPtr<DocumentLoader> documentLoader; | 264 RefPtrWillBePersistent<DocumentLoader> documentLoader; |
253 RefPtrWillBePersistent<Document> document; | 265 RefPtrWillBePersistent<Document> document; |
254 FetchContext* fetchContext; | 266 FetchContext* fetchContext; |
255 }; | 267 }; |
256 | 268 |
257 TEST_F(FrameFetchContextHintsTest, MonitorDPRHints) | 269 TEST_F(FrameFetchContextHintsTest, MonitorDPRHints) |
258 { | 270 { |
259 expectHeader("http://www.example.com/1.gif", "DPR", false, ""); | 271 expectHeader("http://www.example.com/1.gif", "DPR", false, ""); |
260 ClientHintsPreferences preferences; | 272 ClientHintsPreferences preferences; |
261 preferences.setShouldSendDPR(true); | 273 preferences.setShouldSendDPR(true); |
262 document->setClientHintsPreferences(preferences); | 274 document->setClientHintsPreferences(preferences); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 preferences.setShouldSendDPR(true); | 314 preferences.setShouldSendDPR(true); |
303 preferences.setShouldSendResourceWidth(true); | 315 preferences.setShouldSendResourceWidth(true); |
304 preferences.setShouldSendViewportWidth(true); | 316 preferences.setShouldSendViewportWidth(true); |
305 document->setClientHintsPreferences(preferences); | 317 document->setClientHintsPreferences(preferences); |
306 expectHeader("http://www.example.com/1.gif", "DPR", true, "1"); | 318 expectHeader("http://www.example.com/1.gif", "DPR", true, "1"); |
307 expectHeader("http://www.example.com/1.gif", "Width", true, "400", 400); | 319 expectHeader("http://www.example.com/1.gif", "Width", true, "400", 400); |
308 expectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "500"); | 320 expectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "500"); |
309 } | 321 } |
310 | 322 |
311 } // namespace | 323 } // namespace |
312 | |
OLD | NEW |