| 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 "config.h" | 5 #include "config.h" |
| 6 #include "core/html/parser/HTMLPreloadScanner.h" | 6 #include "core/html/parser/HTMLPreloadScanner.h" |
| 7 | 7 |
| 8 #include "core/MediaTypeNames.h" | 8 #include "core/MediaTypeNames.h" |
| 9 #include "core/css/MediaValuesCached.h" | 9 #include "core/css/MediaValuesCached.h" |
| 10 #include "core/fetch/ClientHintsPreferences.h" | 10 #include "core/fetch/ClientHintsPreferences.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 { | 49 { |
| 50 if (!host.isNull()) { | 50 if (!host.isNull()) { |
| 51 EXPECT_TRUE(m_preloadRequest->isPreconnect()); | 51 EXPECT_TRUE(m_preloadRequest->isPreconnect()); |
| 52 EXPECT_STREQ(m_preloadRequest->resourceURL().ascii().data(), host.as
cii().data()); | 52 EXPECT_STREQ(m_preloadRequest->resourceURL().ascii().data(), host.as
cii().data()); |
| 53 EXPECT_EQ(m_preloadRequest->isCORS(), crossOrigin != CrossOriginAttr
ibuteNotSet); | 53 EXPECT_EQ(m_preloadRequest->isCORS(), crossOrigin != CrossOriginAttr
ibuteNotSet); |
| 54 EXPECT_EQ(m_preloadRequest->isAllowCredentials(), crossOrigin == Cro
ssOriginAttributeUseCredentials); | 54 EXPECT_EQ(m_preloadRequest->isAllowCredentials(), crossOrigin == Cro
ssOriginAttributeUseCredentials); |
| 55 } | 55 } |
| 56 } | 56 } |
| 57 | 57 |
| 58 protected: | 58 protected: |
| 59 virtual void preload(PassOwnPtr<PreloadRequest> preloadRequest) | 59 void preload(PassOwnPtr<PreloadRequest> preloadRequest) override |
| 60 { | 60 { |
| 61 m_preloadRequest = preloadRequest; | 61 m_preloadRequest = preloadRequest; |
| 62 } | 62 } |
| 63 | 63 |
| 64 private: | 64 private: |
| 65 | |
| 66 OwnPtr<PreloadRequest> m_preloadRequest; | 65 OwnPtr<PreloadRequest> m_preloadRequest; |
| 67 }; | 66 }; |
| 68 | 67 |
| 69 class HTMLPreloadScannerTest : public testing::Test { | 68 class HTMLPreloadScannerTest : public testing::Test { |
| 70 protected: | 69 protected: |
| 71 HTMLPreloadScannerTest() | 70 HTMLPreloadScannerTest() |
| 72 : m_dummyPageHolder(DummyPageHolder::create()) | 71 : m_dummyPageHolder(DummyPageHolder::create()) |
| 73 { | 72 { |
| 74 } | 73 } |
| 75 | 74 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 94 | 93 |
| 95 void runSetUp(bool viewportEnabled) | 94 void runSetUp(bool viewportEnabled) |
| 96 { | 95 { |
| 97 HTMLParserOptions options(&m_dummyPageHolder->document()); | 96 HTMLParserOptions options(&m_dummyPageHolder->document()); |
| 98 KURL documentURL(ParsedURLString, "http://whatever.test/"); | 97 KURL documentURL(ParsedURLString, "http://whatever.test/"); |
| 99 m_dummyPageHolder->document().settings()->setViewportEnabled(viewportEna
bled); | 98 m_dummyPageHolder->document().settings()->setViewportEnabled(viewportEna
bled); |
| 100 m_dummyPageHolder->document().settings()->setViewportMetaEnabled(viewpor
tEnabled); | 99 m_dummyPageHolder->document().settings()->setViewportMetaEnabled(viewpor
tEnabled); |
| 101 m_scanner = HTMLPreloadScanner::create(options, documentURL, CachedDocum
entParameters::create(&m_dummyPageHolder->document(), createMediaValues())); | 100 m_scanner = HTMLPreloadScanner::create(options, documentURL, CachedDocum
entParameters::create(&m_dummyPageHolder->document(), createMediaValues())); |
| 102 } | 101 } |
| 103 | 102 |
| 104 virtual void SetUp() | 103 void SetUp() override |
| 105 { | 104 { |
| 106 runSetUp(true); | 105 runSetUp(true); |
| 107 } | 106 } |
| 108 | 107 |
| 109 void test(TestCase testCase) | 108 void test(TestCase testCase) |
| 110 { | 109 { |
| 111 MockHTMLResourcePreloader preloader; | 110 MockHTMLResourcePreloader preloader; |
| 112 KURL baseURL(ParsedURLString, testCase.baseURL); | 111 KURL baseURL(ParsedURLString, testCase.baseURL); |
| 113 m_scanner->appendToEnd(String(testCase.inputHTML)); | 112 m_scanner->appendToEnd(String(testCase.inputHTML)); |
| 114 m_scanner->scan(&preloader, baseURL); | 113 m_scanner->scan(&preloader, baseURL); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 {"http://example.test", "<link rel=preconnect href=http://example2.test
crossorigin=anonymous>", "http://example2.test", CrossOriginAttributeAnonymous}, | 238 {"http://example.test", "<link rel=preconnect href=http://example2.test
crossorigin=anonymous>", "http://example2.test", CrossOriginAttributeAnonymous}, |
| 240 {"http://example.test", "<link rel=preconnect href=http://example2.test
crossorigin='use-credentials'>", "http://example2.test", CrossOriginAttributeUse
Credentials}, | 239 {"http://example.test", "<link rel=preconnect href=http://example2.test
crossorigin='use-credentials'>", "http://example2.test", CrossOriginAttributeUse
Credentials}, |
| 241 {"http://example.test", "<link rel=preconnected href=http://example2.tes
t crossorigin='use-credentials'>", nullptr, CrossOriginAttributeNotSet}, | 240 {"http://example.test", "<link rel=preconnected href=http://example2.tes
t crossorigin='use-credentials'>", nullptr, CrossOriginAttributeNotSet}, |
| 242 {"http://example.test", "<link rel=preconnect href=ws://example2.test cr
ossorigin='use-credentials'>", nullptr, CrossOriginAttributeNotSet}, | 241 {"http://example.test", "<link rel=preconnect href=ws://example2.test cr
ossorigin='use-credentials'>", nullptr, CrossOriginAttributeNotSet}, |
| 243 }; | 242 }; |
| 244 | 243 |
| 245 for (const auto& testCase : testCases) | 244 for (const auto& testCase : testCases) |
| 246 test(testCase); | 245 test(testCase); |
| 247 } | 246 } |
| 248 | 247 |
| 249 } | 248 } // namespace blink |
| OLD | NEW |