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

Side by Side Diff: third_party/WebKit/Source/core/html/parser/HTMLPreloadScannerTest.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/HTMLPreloadScanner.h" 5 #include "core/html/parser/HTMLPreloadScanner.h"
6 6
7 #include "core/MediaTypeNames.h" 7 #include "core/MediaTypeNames.h"
8 #include "core/css/MediaValuesCached.h" 8 #include "core/css/MediaValuesCached.h"
9 #include "core/fetch/ClientHintsPreferences.h" 9 #include "core/fetch/ClientHintsPreferences.h"
10 #include "core/frame/Settings.h" 10 #include "core/frame/Settings.h"
11 #include "core/html/CrossOriginAttribute.h" 11 #include "core/html/CrossOriginAttribute.h"
12 #include "core/html/parser/HTMLParserOptions.h" 12 #include "core/html/parser/HTMLParserOptions.h"
13 #include "core/html/parser/HTMLResourcePreloader.h" 13 #include "core/html/parser/HTMLResourcePreloader.h"
14 #include "core/testing/DummyPageHolder.h" 14 #include "core/testing/DummyPageHolder.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include <memory>
17 16
18 namespace blink { 17 namespace blink {
19 18
20 struct TestCase { 19 struct TestCase {
21 const char* baseURL; 20 const char* baseURL;
22 const char* inputHTML; 21 const char* inputHTML;
23 const char* preloadedURL; // Or nullptr if no preload is expected. 22 const char* preloadedURL; // Or nullptr if no preload is expected.
24 const char* outputBaseURL; 23 const char* outputBaseURL;
25 Resource::Type type; 24 Resource::Type type;
26 int resourceWidth; 25 int resourceWidth;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 void preconnectRequestVerification(const String& host, CrossOriginAttributeV alue crossOrigin) 73 void preconnectRequestVerification(const String& host, CrossOriginAttributeV alue crossOrigin)
75 { 74 {
76 if (!host.isNull()) { 75 if (!host.isNull()) {
77 EXPECT_TRUE(m_preloadRequest->isPreconnect()); 76 EXPECT_TRUE(m_preloadRequest->isPreconnect());
78 EXPECT_STREQ(m_preloadRequest->resourceURL().ascii().data(), host.as cii().data()); 77 EXPECT_STREQ(m_preloadRequest->resourceURL().ascii().data(), host.as cii().data());
79 EXPECT_EQ(m_preloadRequest->crossOrigin(), crossOrigin); 78 EXPECT_EQ(m_preloadRequest->crossOrigin(), crossOrigin);
80 } 79 }
81 } 80 }
82 81
83 protected: 82 protected:
84 void preload(std::unique_ptr<PreloadRequest> preloadRequest, const NetworkHi ntsInterface&) override 83 void preload(PassOwnPtr<PreloadRequest> preloadRequest, const NetworkHintsIn terface&) override
85 { 84 {
86 m_preloadRequest = std::move(preloadRequest); 85 m_preloadRequest = std::move(preloadRequest);
87 } 86 }
88 87
89 private: 88 private:
90 std::unique_ptr<PreloadRequest> m_preloadRequest; 89 OwnPtr<PreloadRequest> m_preloadRequest;
91 }; 90 };
92 91
93 class HTMLPreloadScannerTest : public testing::Test { 92 class HTMLPreloadScannerTest : public testing::Test {
94 protected: 93 protected:
95 enum ViewportState { 94 enum ViewportState {
96 ViewportEnabled, 95 ViewportEnabled,
97 ViewportDisabled, 96 ViewportDisabled,
98 }; 97 };
99 98
100 enum PreloadState { 99 enum PreloadState {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 { 164 {
166 MockHTMLResourcePreloader preloader; 165 MockHTMLResourcePreloader preloader;
167 KURL baseURL(ParsedURLString, testCase.baseURL); 166 KURL baseURL(ParsedURLString, testCase.baseURL);
168 m_scanner->appendToEnd(String(testCase.inputHTML)); 167 m_scanner->appendToEnd(String(testCase.inputHTML));
169 m_scanner->scanAndPreload(&preloader, baseURL, nullptr); 168 m_scanner->scanAndPreload(&preloader, baseURL, nullptr);
170 169
171 preloader.preloadRequestVerification(testCase.type, testCase.preloadedUR L, testCase.outputBaseURL, testCase.resourceWidth, testCase.referrerPolicy); 170 preloader.preloadRequestVerification(testCase.type, testCase.preloadedUR L, testCase.outputBaseURL, testCase.resourceWidth, testCase.referrerPolicy);
172 } 171 }
173 172
174 private: 173 private:
175 std::unique_ptr<DummyPageHolder> m_dummyPageHolder; 174 OwnPtr<DummyPageHolder> m_dummyPageHolder;
176 std::unique_ptr<HTMLPreloadScanner> m_scanner; 175 OwnPtr<HTMLPreloadScanner> m_scanner;
177 }; 176 };
178 177
179 TEST_F(HTMLPreloadScannerTest, testImages) 178 TEST_F(HTMLPreloadScannerTest, testImages)
180 { 179 {
181 TestCase testCases[] = { 180 TestCase testCases[] = {
182 {"http://example.test", "<img src='bla.gif'>", "bla.gif", "http://exampl e.test/", Resource::Image, 0}, 181 {"http://example.test", "<img src='bla.gif'>", "bla.gif", "http://exampl e.test/", Resource::Image, 0},
183 {"http://example.test", "<img srcset='bla.gif 320w, blabla.gif 640w'>", "blabla.gif", "http://example.test/", Resource::Image, 0}, 182 {"http://example.test", "<img srcset='bla.gif 320w, blabla.gif 640w'>", "blabla.gif", "http://example.test/", Resource::Image, 0},
184 {"http://example.test", "<img sizes='50vw' src='bla.gif'>", "bla.gif", " http://example.test/", Resource::Image, 250}, 183 {"http://example.test", "<img sizes='50vw' src='bla.gif'>", "bla.gif", " http://example.test/", Resource::Image, 250},
185 {"http://example.test", "<img sizes='50vw' src='bla.gif' srcset='bla2.gi f 1x'>", "bla2.gif", "http://example.test/", Resource::Image, 250}, 184 {"http://example.test", "<img sizes='50vw' src='bla.gif' srcset='bla2.gi f 1x'>", "bla2.gif", "http://example.test/", Resource::Image, 250},
186 {"http://example.test", "<img sizes='50vw' src='bla.gif' srcset='bla2.gi f 0.5x'>", "bla.gif", "http://example.test/", Resource::Image, 250}, 185 {"http://example.test", "<img sizes='50vw' src='bla.gif' srcset='bla2.gi f 0.5x'>", "bla.gif", "http://example.test/", Resource::Image, 250},
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 {"http://example.test", "<link rel=preload href=bla as=track>", "bla", " http://example.test/", Resource::TextTrack, 0}, 407 {"http://example.test", "<link rel=preload href=bla as=track>", "bla", " http://example.test/", Resource::TextTrack, 0},
409 {"http://example.test", "<link rel=preload href=bla as=image media=\"(ma x-width: 800px)\">", "bla", "http://example.test/", Resource::Image, 0}, 408 {"http://example.test", "<link rel=preload href=bla as=image media=\"(ma x-width: 800px)\">", "bla", "http://example.test/", Resource::Image, 0},
410 {"http://example.test", "<link rel=preload href=bla as=image media=\"(ma x-width: 400px)\">", nullptr, "http://example.test/", Resource::Image, 0}, 409 {"http://example.test", "<link rel=preload href=bla as=image media=\"(ma x-width: 400px)\">", nullptr, "http://example.test/", Resource::Image, 0},
411 }; 410 };
412 411
413 for (const auto& testCase : testCases) 412 for (const auto& testCase : testCases)
414 test(testCase); 413 test(testCase);
415 } 414 }
416 415
417 } // namespace blink 416 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698