| 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 | 11 |
| 11 namespace blink { | 12 namespace blink { |
| 12 | 13 |
| 13 struct PreconnectTestCase { | 14 struct PreconnectTestCase { |
| 14 const char* baseURL; | 15 const char* baseURL; |
| 15 const char* url; | 16 const char* url; |
| 16 bool isCORS; | 17 bool isCORS; |
| 17 bool isHTTPS; | 18 bool isHTTPS; |
| 18 }; | 19 }; |
| 19 | 20 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 46 protected: | 47 protected: |
| 47 HTMLResourcePreloaderTest() | 48 HTMLResourcePreloaderTest() |
| 48 : m_dummyPageHolder(DummyPageHolder::create()) | 49 : m_dummyPageHolder(DummyPageHolder::create()) |
| 49 { | 50 { |
| 50 } | 51 } |
| 51 | 52 |
| 52 void test(PreconnectTestCase testCase) | 53 void test(PreconnectTestCase testCase) |
| 53 { | 54 { |
| 54 // TODO(yoav): Need a mock loader here to verify things are happenning b
eyond preconnect. | 55 // TODO(yoav): Need a mock loader here to verify things are happenning b
eyond preconnect. |
| 55 PreloaderNetworkHintsMock networkHints; | 56 PreloaderNetworkHintsMock networkHints; |
| 56 OwnPtr<PreloadRequest> preloadRequest = PreloadRequest::create(String(), | 57 std::unique_ptr<PreloadRequest> preloadRequest = PreloadRequest::create(
String(), |
| 57 TextPosition(), | 58 TextPosition(), |
| 58 testCase.url, | 59 testCase.url, |
| 59 KURL(ParsedURLStringTag(), testCase.baseURL), | 60 KURL(ParsedURLStringTag(), testCase.baseURL), |
| 60 Resource::Image, | 61 Resource::Image, |
| 61 ReferrerPolicy(), | 62 ReferrerPolicy(), |
| 62 FetchRequest::ResourceWidth(), | 63 FetchRequest::ResourceWidth(), |
| 63 ClientHintsPreferences(), | 64 ClientHintsPreferences(), |
| 64 PreloadRequest::RequestTypePreconnect); | 65 PreloadRequest::RequestTypePreconnect); |
| 65 if (testCase.isCORS) | 66 if (testCase.isCORS) |
| 66 preloadRequest->setCrossOrigin(CrossOriginAttributeAnonymous); | 67 preloadRequest->setCrossOrigin(CrossOriginAttributeAnonymous); |
| 67 HTMLResourcePreloader* preloader = HTMLResourcePreloader::create(m_dummy
PageHolder->document()); | 68 HTMLResourcePreloader* preloader = HTMLResourcePreloader::create(m_dummy
PageHolder->document()); |
| 68 preloader->preload(std::move(preloadRequest), networkHints); | 69 preloader->preload(std::move(preloadRequest), networkHints); |
| 69 ASSERT_TRUE(networkHints.didPreconnect()); | 70 ASSERT_TRUE(networkHints.didPreconnect()); |
| 70 ASSERT_EQ(testCase.isCORS, networkHints.isCrossOrigin()); | 71 ASSERT_EQ(testCase.isCORS, networkHints.isCrossOrigin()); |
| 71 ASSERT_EQ(testCase.isHTTPS, networkHints.isHTTPS()); | 72 ASSERT_EQ(testCase.isHTTPS, networkHints.isHTTPS()); |
| 72 } | 73 } |
| 73 | 74 |
| 74 private: | 75 private: |
| 75 OwnPtr<DummyPageHolder> m_dummyPageHolder; | 76 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; |
| 76 }; | 77 }; |
| 77 | 78 |
| 78 TEST_F(HTMLResourcePreloaderTest, testPreconnect) | 79 TEST_F(HTMLResourcePreloaderTest, testPreconnect) |
| 79 { | 80 { |
| 80 PreconnectTestCase testCases[] = { | 81 PreconnectTestCase testCases[] = { |
| 81 { "http://example.test", "http://example.com", false, false }, | 82 { "http://example.test", "http://example.com", false, false }, |
| 82 { "http://example.test", "http://example.com", true, false }, | 83 { "http://example.test", "http://example.com", true, false }, |
| 83 { "http://example.test", "https://example.com", true, true }, | 84 { "http://example.test", "https://example.com", true, true }, |
| 84 { "http://example.test", "https://example.com", false, true }, | 85 { "http://example.test", "https://example.com", false, true }, |
| 85 { "http://example.test", "//example.com", false, false }, | 86 { "http://example.test", "//example.com", false, false }, |
| 86 { "http://example.test", "//example.com", true, false }, | 87 { "http://example.test", "//example.com", true, false }, |
| 87 { "https://example.test", "//example.com", false, true }, | 88 { "https://example.test", "//example.com", false, true }, |
| 88 { "https://example.test", "//example.com", true, true }, | 89 { "https://example.test", "//example.com", true, true }, |
| 89 }; | 90 }; |
| 90 | 91 |
| 91 for (const auto& testCase : testCases) | 92 for (const auto& testCase : testCases) |
| 92 test(testCase); | 93 test(testCase); |
| 93 } | 94 } |
| 94 | 95 |
| 95 } // namespace blink | 96 } // namespace blink |
| OLD | NEW |