| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/html/parser/HTMLResourcePreloader.h" | 5 #include "core/html/parser/HTMLResourcePreloader.h" |
| 6 | 6 |
| 7 #include "core/html/parser/PreloadRequest.h" | 7 #include "core/html/parser/PreloadRequest.h" |
| 8 #include "core/testing/DummyPageHolder.h" | 8 #include "core/testing/DummyPageHolder.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 class HTMLResourcePreloaderTest : public testing::Test { | 44 class HTMLResourcePreloaderTest : public testing::Test { |
| 45 protected: | 45 protected: |
| 46 HTMLResourcePreloaderTest() : m_dummyPageHolder(DummyPageHolder::create()) {} | 46 HTMLResourcePreloaderTest() : m_dummyPageHolder(DummyPageHolder::create()) {} |
| 47 | 47 |
| 48 void test(PreconnectTestCase testCase) { | 48 void test(PreconnectTestCase testCase) { |
| 49 // TODO(yoav): Need a mock loader here to verify things are happenning | 49 // TODO(yoav): Need a mock loader here to verify things are happenning |
| 50 // beyond preconnect. | 50 // beyond preconnect. |
| 51 PreloaderNetworkHintsMock networkHints; | 51 PreloaderNetworkHintsMock networkHints; |
| 52 std::unique_ptr<PreloadRequest> preloadRequest = PreloadRequest::create( | 52 auto preloadRequest = PreloadRequest::createIfNeeded( |
| 53 String(), TextPosition(), testCase.url, | 53 String(), TextPosition(), testCase.url, |
| 54 KURL(ParsedURLStringTag(), testCase.baseURL), Resource::Image, | 54 KURL(ParsedURLStringTag(), testCase.baseURL), Resource::Image, |
| 55 ReferrerPolicy(), FetchRequest::ResourceWidth(), | 55 ReferrerPolicy(), FetchRequest::ResourceWidth(), |
| 56 ClientHintsPreferences(), PreloadRequest::RequestTypePreconnect); | 56 ClientHintsPreferences(), PreloadRequest::RequestTypePreconnect); |
| 57 DCHECK(preloadRequest); |
| 57 if (testCase.isCORS) | 58 if (testCase.isCORS) |
| 58 preloadRequest->setCrossOrigin(CrossOriginAttributeAnonymous); | 59 preloadRequest->setCrossOrigin(CrossOriginAttributeAnonymous); |
| 59 HTMLResourcePreloader* preloader = | 60 HTMLResourcePreloader* preloader = |
| 60 HTMLResourcePreloader::create(m_dummyPageHolder->document()); | 61 HTMLResourcePreloader::create(m_dummyPageHolder->document()); |
| 61 preloader->preload(std::move(preloadRequest), networkHints); | 62 preloader->preload(std::move(preloadRequest), networkHints); |
| 62 ASSERT_TRUE(networkHints.didPreconnect()); | 63 ASSERT_TRUE(networkHints.didPreconnect()); |
| 63 ASSERT_EQ(testCase.isCORS, networkHints.isCrossOrigin()); | 64 ASSERT_EQ(testCase.isCORS, networkHints.isCrossOrigin()); |
| 64 ASSERT_EQ(testCase.isHTTPS, networkHints.isHTTPS()); | 65 ASSERT_EQ(testCase.isHTTPS, networkHints.isHTTPS()); |
| 65 } | 66 } |
| 66 | 67 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 78 {"http://example.test", "//example.com", true, false}, | 79 {"http://example.test", "//example.com", true, false}, |
| 79 {"https://example.test", "//example.com", false, true}, | 80 {"https://example.test", "//example.com", false, true}, |
| 80 {"https://example.test", "//example.com", true, true}, | 81 {"https://example.test", "//example.com", true, true}, |
| 81 }; | 82 }; |
| 82 | 83 |
| 83 for (const auto& testCase : testCases) | 84 for (const auto& testCase : testCases) |
| 84 test(testCase); | 85 test(testCase); |
| 85 } | 86 } |
| 86 | 87 |
| 87 } // namespace blink | 88 } // namespace blink |
| OLD | NEW |