| 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 | 109 |
| 110 KURL secureURL; | 110 KURL secureURL; |
| 111 RefPtr<SecurityOrigin> exampleOrigin; | 111 RefPtr<SecurityOrigin> exampleOrigin; |
| 112 RefPtr<SecurityOrigin> secureOrigin; | 112 RefPtr<SecurityOrigin> secureOrigin; |
| 113 | 113 |
| 114 OwnPtr<DummyPageHolder> dummyPageHolder; | 114 OwnPtr<DummyPageHolder> dummyPageHolder; |
| 115 // 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 |
| 116 // as the ResourceFetcher and Document live due to indirect usage. | 116 // as the ResourceFetcher and Document live due to indirect usage. |
| 117 RefPtrWillBePersistent<DocumentLoader> documentLoader; | 117 RefPtrWillBePersistent<DocumentLoader> documentLoader; |
| 118 RefPtrWillBePersistent<Document> document; | 118 RefPtrWillBePersistent<Document> document; |
| 119 FetchContext* fetchContext; | 119 Persistent<FetchContext> fetchContext; |
| 120 }; | 120 }; |
| 121 | 121 |
| 122 TEST_F(FrameFetchContextUpgradeTest, UpgradeInsecureResourceRequests) | 122 TEST_F(FrameFetchContextUpgradeTest, UpgradeInsecureResourceRequests) |
| 123 { | 123 { |
| 124 struct TestCase { | 124 struct TestCase { |
| 125 const char* original; | 125 const char* original; |
| 126 const char* upgraded; | 126 const char* upgraded; |
| 127 } tests[] = { | 127 } tests[] = { |
| 128 { "http://example.test/image.png", "https://example.test/image.png" }, | 128 { "http://example.test/image.png", "https://example.test/image.png" }, |
| 129 { "http://example.test:80/image.png", "https://example.test:443/image.pn
g" }, | 129 { "http://example.test:80/image.png", "https://example.test:443/image.pn
g" }, |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 public: | 225 public: |
| 226 FrameFetchContextHintsTest() { } | 226 FrameFetchContextHintsTest() { } |
| 227 | 227 |
| 228 protected: | 228 protected: |
| 229 virtual void SetUp() | 229 virtual void SetUp() |
| 230 { | 230 { |
| 231 dummyPageHolder = DummyPageHolder::create(IntSize(500, 500)); | 231 dummyPageHolder = DummyPageHolder::create(IntSize(500, 500)); |
| 232 dummyPageHolder->page().setDeviceScaleFactor(1.0); | 232 dummyPageHolder->page().setDeviceScaleFactor(1.0); |
| 233 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()); |
| 234 document = toHTMLDocument(&dummyPageHolder->document()); | 234 document = toHTMLDocument(&dummyPageHolder->document()); |
| 235 fetchContext = &documentLoader->fetcher()->context(); | 235 fetchContext = static_cast<FrameFetchContext*>(&documentLoader->fetcher(
)->context()); |
| 236 FrameFetchContext::provideDocumentToContext(*fetchContext, document.get(
)); | 236 FrameFetchContext::provideDocumentToContext(*fetchContext, document.get(
)); |
| 237 } | 237 } |
| 238 | 238 |
| 239 virtual void TearDown() | 239 virtual void TearDown() |
| 240 { | 240 { |
| 241 documentLoader->detachFromFrame(); | 241 documentLoader->detachFromFrame(); |
| 242 documentLoader.clear(); | 242 documentLoader.clear(); |
| 243 } | 243 } |
| 244 | 244 |
| 245 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) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 256 | 256 |
| 257 EXPECT_STREQ(isPresent ? headerValue : "", | 257 EXPECT_STREQ(isPresent ? headerValue : "", |
| 258 fetchRequest.resourceRequest().httpHeaderField(headerName).utf8().da
ta()); | 258 fetchRequest.resourceRequest().httpHeaderField(headerName).utf8().da
ta()); |
| 259 } | 259 } |
| 260 | 260 |
| 261 OwnPtr<DummyPageHolder> dummyPageHolder; | 261 OwnPtr<DummyPageHolder> dummyPageHolder; |
| 262 // 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 |
| 263 // as the ResourceFetcher and Document live due to indirect usage. | 263 // as the ResourceFetcher and Document live due to indirect usage. |
| 264 RefPtrWillBePersistent<DocumentLoader> documentLoader; | 264 RefPtrWillBePersistent<DocumentLoader> documentLoader; |
| 265 RefPtrWillBePersistent<Document> document; | 265 RefPtrWillBePersistent<Document> document; |
| 266 FetchContext* fetchContext; | 266 Persistent<FrameFetchContext> fetchContext; |
| 267 }; | 267 }; |
| 268 | 268 |
| 269 TEST_F(FrameFetchContextHintsTest, MonitorDPRHints) | 269 TEST_F(FrameFetchContextHintsTest, MonitorDPRHints) |
| 270 { | 270 { |
| 271 expectHeader("http://www.example.com/1.gif", "DPR", false, ""); | 271 expectHeader("http://www.example.com/1.gif", "DPR", false, ""); |
| 272 ClientHintsPreferences preferences; | 272 ClientHintsPreferences preferences; |
| 273 preferences.setShouldSendDPR(true); | 273 preferences.setShouldSendDPR(true); |
| 274 document->setClientHintsPreferences(preferences); | 274 document->setClientHintsPreferences(preferences); |
| 275 expectHeader("http://www.example.com/1.gif", "DPR", true, "1"); | 275 expectHeader("http://www.example.com/1.gif", "DPR", true, "1"); |
| 276 dummyPageHolder->page().setDeviceScaleFactor(2.5); | 276 dummyPageHolder->page().setDeviceScaleFactor(2.5); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 preferences.setShouldSendDPR(true); | 314 preferences.setShouldSendDPR(true); |
| 315 preferences.setShouldSendResourceWidth(true); | 315 preferences.setShouldSendResourceWidth(true); |
| 316 preferences.setShouldSendViewportWidth(true); | 316 preferences.setShouldSendViewportWidth(true); |
| 317 document->setClientHintsPreferences(preferences); | 317 document->setClientHintsPreferences(preferences); |
| 318 expectHeader("http://www.example.com/1.gif", "DPR", true, "1"); | 318 expectHeader("http://www.example.com/1.gif", "DPR", true, "1"); |
| 319 expectHeader("http://www.example.com/1.gif", "Width", true, "400", 400); | 319 expectHeader("http://www.example.com/1.gif", "Width", true, "400", 400); |
| 320 expectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "500"); | 320 expectHeader("http://www.example.com/1.gif", "Viewport-Width", true, "500"); |
| 321 } | 321 } |
| 322 | 322 |
| 323 } // namespace | 323 } // namespace |
| OLD | NEW |