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

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

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

Powered by Google App Engine
This is Rietveld 408576698