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