| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 { | 52 { |
| 53 } | 53 } |
| 54 | 54 |
| 55 protected: | 55 protected: |
| 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 = &static_cast<FrameFetchContext&>(documentLoader->fetcher(
)->context()); |
| 63 FrameFetchContext::provideDocumentToContext(*fetchContext, document.get(
)); | 63 fetchContext->setDocument(document.get()); |
| 64 } | 64 } |
| 65 | 65 |
| 66 void expectUpgrade(const char* input, const char* expected) | 66 void expectUpgrade(const char* input, const char* expected) |
| 67 { | 67 { |
| 68 expectUpgrade(input, WebURLRequest::RequestContextScript, WebURLRequest:
:FrameTypeNone, expected); | 68 expectUpgrade(input, WebURLRequest::RequestContextScript, WebURLRequest:
:FrameTypeNone, expected); |
| 69 } | 69 } |
| 70 | 70 |
| 71 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) |
| 72 { | 72 { |
| 73 KURL inputURL(ParsedURLString, input); | 73 KURL inputURL(ParsedURLString, input); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 103 | 103 |
| 104 KURL secureURL; | 104 KURL secureURL; |
| 105 RefPtr<SecurityOrigin> exampleOrigin; | 105 RefPtr<SecurityOrigin> exampleOrigin; |
| 106 RefPtr<SecurityOrigin> secureOrigin; | 106 RefPtr<SecurityOrigin> secureOrigin; |
| 107 | 107 |
| 108 OwnPtr<DummyPageHolder> dummyPageHolder; | 108 OwnPtr<DummyPageHolder> dummyPageHolder; |
| 109 // 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 |
| 110 // as the ResourceFetcher and Document live due to indirect usage. | 110 // as the ResourceFetcher and Document live due to indirect usage. |
| 111 RefPtr<DocumentLoader> documentLoader; | 111 RefPtr<DocumentLoader> documentLoader; |
| 112 RefPtrWillBePersistent<Document> document; | 112 RefPtrWillBePersistent<Document> document; |
| 113 FetchContext* fetchContext; | 113 FrameFetchContext* fetchContext; |
| 114 }; | 114 }; |
| 115 | 115 |
| 116 TEST_F(FrameFetchContextUpgradeTest, UpgradeInsecureResourceRequests) | 116 TEST_F(FrameFetchContextUpgradeTest, UpgradeInsecureResourceRequests) |
| 117 { | 117 { |
| 118 struct TestCase { | 118 struct TestCase { |
| 119 const char* original; | 119 const char* original; |
| 120 const char* upgraded; | 120 const char* upgraded; |
| 121 } tests[] = { | 121 } tests[] = { |
| 122 { "http://example.test/image.png", "https://example.test/image.png" }, | 122 { "http://example.test/image.png", "https://example.test/image.png" }, |
| 123 { "http://example.test:80/image.png", "https://example.test:443/image.pn
g" }, | 123 { "http://example.test:80/image.png", "https://example.test:443/image.pn
g" }, |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 public: | 204 public: |
| 205 FrameFetchContextHintsTest() { } | 205 FrameFetchContextHintsTest() { } |
| 206 | 206 |
| 207 protected: | 207 protected: |
| 208 virtual void SetUp() | 208 virtual void SetUp() |
| 209 { | 209 { |
| 210 dummyPageHolder = DummyPageHolder::create(IntSize(500, 500)); | 210 dummyPageHolder = DummyPageHolder::create(IntSize(500, 500)); |
| 211 dummyPageHolder->page().setDeviceScaleFactor(1.0); | 211 dummyPageHolder->page().setDeviceScaleFactor(1.0); |
| 212 documentLoader = DocumentLoader::create(&dummyPageHolder->frame(), Resou
rceRequest("http://www.example.com"), SubstituteData()); | 212 documentLoader = DocumentLoader::create(&dummyPageHolder->frame(), Resou
rceRequest("http://www.example.com"), SubstituteData()); |
| 213 document = toHTMLDocument(&dummyPageHolder->document()); | 213 document = toHTMLDocument(&dummyPageHolder->document()); |
| 214 fetchContext = &documentLoader->fetcher()->context(); | 214 fetchContext = &static_cast<FrameFetchContext&>(documentLoader->fetcher(
)->context()); |
| 215 FrameFetchContext::provideDocumentToContext(*fetchContext, document.get(
)); | 215 fetchContext->setDocument(document.get()); |
| 216 } | 216 } |
| 217 | 217 |
| 218 void expectHeader(const char* input, const char* headerName, bool isPresent,
const char* headerValue) | 218 void expectHeader(const char* input, const char* headerName, bool isPresent,
const char* headerValue) |
| 219 { | 219 { |
| 220 KURL inputURL(ParsedURLString, input); | 220 KURL inputURL(ParsedURLString, input); |
| 221 FetchRequest fetchRequest = FetchRequest(ResourceRequest(inputURL), Fetc
hInitiatorInfo()); | 221 FetchRequest fetchRequest = FetchRequest(ResourceRequest(inputURL), Fetc
hInitiatorInfo()); |
| 222 fetchContext->addClientHintsIfNecessary(fetchRequest); | 222 fetchContext->addClientHintsIfNecessary(fetchRequest); |
| 223 | 223 |
| 224 EXPECT_STREQ(isPresent ? headerValue : "", | 224 EXPECT_STREQ(isPresent ? headerValue : "", |
| 225 fetchRequest.resourceRequest().httpHeaderField(headerName).utf8().da
ta()); | 225 fetchRequest.resourceRequest().httpHeaderField(headerName).utf8().da
ta()); |
| 226 } | 226 } |
| 227 | 227 |
| 228 OwnPtr<DummyPageHolder> dummyPageHolder; | 228 OwnPtr<DummyPageHolder> dummyPageHolder; |
| 229 // We don't use the DocumentLoader directly in any tests, but need to keep i
t around as long | 229 // We don't use the DocumentLoader directly in any tests, but need to keep i
t around as long |
| 230 // as the ResourceFetcher and Document live due to indirect usage. | 230 // as the ResourceFetcher and Document live due to indirect usage. |
| 231 RefPtr<DocumentLoader> documentLoader; | 231 RefPtr<DocumentLoader> documentLoader; |
| 232 RefPtrWillBePersistent<Document> document; | 232 RefPtrWillBePersistent<Document> document; |
| 233 FetchContext* fetchContext; | 233 FrameFetchContext* fetchContext; |
| 234 }; | 234 }; |
| 235 | 235 |
| 236 TEST_F(FrameFetchContextHintsTest, MonitorDPRHints) | 236 TEST_F(FrameFetchContextHintsTest, MonitorDPRHints) |
| 237 { | 237 { |
| 238 expectHeader("http://www.example.com/1.gif", "DPR", false, ""); | 238 expectHeader("http://www.example.com/1.gif", "DPR", false, ""); |
| 239 dummyPageHolder->frame().setShouldSendDPRHint(); | 239 dummyPageHolder->frame().setShouldSendDPRHint(); |
| 240 expectHeader("http://www.example.com/1.gif", "DPR", true, "1"); | 240 expectHeader("http://www.example.com/1.gif", "DPR", true, "1"); |
| 241 dummyPageHolder->page().setDeviceScaleFactor(2.5); | 241 dummyPageHolder->page().setDeviceScaleFactor(2.5); |
| 242 expectHeader("http://www.example.com/1.gif", "DPR", true, "2.5"); | 242 expectHeader("http://www.example.com/1.gif", "DPR", true, "2.5"); |
| 243 expectHeader("http://www.example.com/1.gif", "RW", false, ""); | 243 expectHeader("http://www.example.com/1.gif", "RW", false, ""); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 260 expectHeader("http://www.example.com/1.gif", "RW", false, ""); | 260 expectHeader("http://www.example.com/1.gif", "RW", false, ""); |
| 261 | 261 |
| 262 dummyPageHolder->frame().setShouldSendDPRHint(); | 262 dummyPageHolder->frame().setShouldSendDPRHint(); |
| 263 dummyPageHolder->frame().setShouldSendRWHint(); | 263 dummyPageHolder->frame().setShouldSendRWHint(); |
| 264 expectHeader("http://www.example.com/1.gif", "DPR", true, "1"); | 264 expectHeader("http://www.example.com/1.gif", "DPR", true, "1"); |
| 265 expectHeader("http://www.example.com/1.gif", "RW", true, "500"); | 265 expectHeader("http://www.example.com/1.gif", "RW", true, "500"); |
| 266 } | 266 } |
| 267 | 267 |
| 268 } // namespace | 268 } // namespace |
| 269 | 269 |
| OLD | NEW |