Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: third_party/WebKit/Source/core/html/parser/HTMLResourcePreloaderTest.cpp

Issue 2080623002: Revert "Remove OwnPtr from Blink." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
11 10
12 namespace blink { 11 namespace blink {
13 12
14 struct PreconnectTestCase { 13 struct PreconnectTestCase {
15 const char* baseURL; 14 const char* baseURL;
16 const char* url; 15 const char* url;
17 bool isCORS; 16 bool isCORS;
18 bool isHTTPS; 17 bool isHTTPS;
19 }; 18 };
20 19
(...skipping 26 matching lines...) Expand all
47 protected: 46 protected:
48 HTMLResourcePreloaderTest() 47 HTMLResourcePreloaderTest()
49 : m_dummyPageHolder(DummyPageHolder::create()) 48 : m_dummyPageHolder(DummyPageHolder::create())
50 { 49 {
51 } 50 }
52 51
53 void test(PreconnectTestCase testCase) 52 void test(PreconnectTestCase testCase)
54 { 53 {
55 // TODO(yoav): Need a mock loader here to verify things are happenning b eyond preconnect. 54 // TODO(yoav): Need a mock loader here to verify things are happenning b eyond preconnect.
56 PreloaderNetworkHintsMock networkHints; 55 PreloaderNetworkHintsMock networkHints;
57 std::unique_ptr<PreloadRequest> preloadRequest = PreloadRequest::create( String(), 56 OwnPtr<PreloadRequest> preloadRequest = PreloadRequest::create(String(),
58 TextPosition(), 57 TextPosition(),
59 testCase.url, 58 testCase.url,
60 KURL(ParsedURLStringTag(), testCase.baseURL), 59 KURL(ParsedURLStringTag(), testCase.baseURL),
61 Resource::Image, 60 Resource::Image,
62 ReferrerPolicy(), 61 ReferrerPolicy(),
63 FetchRequest::ResourceWidth(), 62 FetchRequest::ResourceWidth(),
64 ClientHintsPreferences(), 63 ClientHintsPreferences(),
65 PreloadRequest::RequestTypePreconnect); 64 PreloadRequest::RequestTypePreconnect);
66 if (testCase.isCORS) 65 if (testCase.isCORS)
67 preloadRequest->setCrossOrigin(CrossOriginAttributeAnonymous); 66 preloadRequest->setCrossOrigin(CrossOriginAttributeAnonymous);
68 HTMLResourcePreloader* preloader = HTMLResourcePreloader::create(m_dummy PageHolder->document()); 67 HTMLResourcePreloader* preloader = HTMLResourcePreloader::create(m_dummy PageHolder->document());
69 preloader->preload(std::move(preloadRequest), networkHints); 68 preloader->preload(std::move(preloadRequest), networkHints);
70 ASSERT_TRUE(networkHints.didPreconnect()); 69 ASSERT_TRUE(networkHints.didPreconnect());
71 ASSERT_EQ(testCase.isCORS, networkHints.isCrossOrigin()); 70 ASSERT_EQ(testCase.isCORS, networkHints.isCrossOrigin());
72 ASSERT_EQ(testCase.isHTTPS, networkHints.isHTTPS()); 71 ASSERT_EQ(testCase.isHTTPS, networkHints.isHTTPS());
73 } 72 }
74 73
75 private: 74 private:
76 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; 75 OwnPtr<DummyPageHolder> m_dummyPageHolder;
77 }; 76 };
78 77
79 TEST_F(HTMLResourcePreloaderTest, testPreconnect) 78 TEST_F(HTMLResourcePreloaderTest, testPreconnect)
80 { 79 {
81 PreconnectTestCase testCases[] = { 80 PreconnectTestCase testCases[] = {
82 { "http://example.test", "http://example.com", false, false }, 81 { "http://example.test", "http://example.com", false, false },
83 { "http://example.test", "http://example.com", true, false }, 82 { "http://example.test", "http://example.com", true, false },
84 { "http://example.test", "https://example.com", true, true }, 83 { "http://example.test", "https://example.com", true, true },
85 { "http://example.test", "https://example.com", false, true }, 84 { "http://example.test", "https://example.com", false, true },
86 { "http://example.test", "//example.com", false, false }, 85 { "http://example.test", "//example.com", false, false },
87 { "http://example.test", "//example.com", true, false }, 86 { "http://example.test", "//example.com", true, false },
88 { "https://example.test", "//example.com", false, true }, 87 { "https://example.test", "//example.com", false, true },
89 { "https://example.test", "//example.com", true, true }, 88 { "https://example.test", "//example.com", true, true },
90 }; 89 };
91 90
92 for (const auto& testCase : testCases) 91 for (const auto& testCase : testCases)
93 test(testCase); 92 test(testCase);
94 } 93 }
95 94
96 } // namespace blink 95 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698