| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 protected: | 45 protected: |
| 46 HTMLResourcePreloaderTest() : dummy_page_holder_(DummyPageHolder::Create()) {} | 46 HTMLResourcePreloaderTest() : dummy_page_holder_(DummyPageHolder::Create()) {} |
| 47 | 47 |
| 48 void Test(PreconnectTestCase test_case) { | 48 void Test(PreconnectTestCase test_case) { |
| 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 network_hints; | 51 PreloaderNetworkHintsMock network_hints; |
| 52 auto preload_request = PreloadRequest::CreateIfNeeded( | 52 auto preload_request = PreloadRequest::CreateIfNeeded( |
| 53 String(), TextPosition(), test_case.url, | 53 String(), TextPosition(), test_case.url, |
| 54 KURL(ParsedURLStringTag(), test_case.base_url), Resource::kImage, | 54 KURL(ParsedURLStringTag(), test_case.base_url), Resource::kImage, |
| 55 ReferrerPolicy(), FetchRequest::ResourceWidth(), | 55 ReferrerPolicy(), PreloadRequest::kDocumentIsReferrer, |
| 56 ClientHintsPreferences(), PreloadRequest::kRequestTypePreconnect); | 56 FetchRequest::ResourceWidth(), ClientHintsPreferences(), |
| 57 PreloadRequest::kRequestTypePreconnect); |
| 57 DCHECK(preload_request); | 58 DCHECK(preload_request); |
| 58 if (test_case.is_cors) | 59 if (test_case.is_cors) |
| 59 preload_request->SetCrossOrigin(kCrossOriginAttributeAnonymous); | 60 preload_request->SetCrossOrigin(kCrossOriginAttributeAnonymous); |
| 60 HTMLResourcePreloader* preloader = | 61 HTMLResourcePreloader* preloader = |
| 61 HTMLResourcePreloader::Create(dummy_page_holder_->GetDocument()); | 62 HTMLResourcePreloader::Create(dummy_page_holder_->GetDocument()); |
| 62 preloader->Preload(std::move(preload_request), network_hints); | 63 preloader->Preload(std::move(preload_request), network_hints); |
| 63 ASSERT_TRUE(network_hints.DidPreconnect()); | 64 ASSERT_TRUE(network_hints.DidPreconnect()); |
| 64 ASSERT_EQ(test_case.is_cors, network_hints.IsCrossOrigin()); | 65 ASSERT_EQ(test_case.is_cors, network_hints.IsCrossOrigin()); |
| 65 ASSERT_EQ(test_case.is_https, network_hints.IsHTTPS()); | 66 ASSERT_EQ(test_case.is_https, network_hints.IsHTTPS()); |
| 66 } | 67 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 79 {"http://example.test", "//example.com", true, false}, | 80 {"http://example.test", "//example.com", true, false}, |
| 80 {"https://example.test", "//example.com", false, true}, | 81 {"https://example.test", "//example.com", false, true}, |
| 81 {"https://example.test", "//example.com", true, true}, | 82 {"https://example.test", "//example.com", true, true}, |
| 82 }; | 83 }; |
| 83 | 84 |
| 84 for (const auto& test_case : test_cases) | 85 for (const auto& test_case : test_cases) |
| 85 Test(test_case); | 86 Test(test_case); |
| 86 } | 87 } |
| 87 | 88 |
| 88 } // namespace blink | 89 } // namespace blink |
| OLD | NEW |