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

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

Issue 1982263002: Fix preloadScanner double download issue with link preload and media (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comment Created 4 years, 7 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
« no previous file with comments | « third_party/WebKit/Source/core/html/parser/HTMLPreloadScanner.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 }; 44 };
45 45
46 class MockHTMLResourcePreloader : public ResourcePreloader { 46 class MockHTMLResourcePreloader : public ResourcePreloader {
47 public: 47 public:
48 void preloadRequestVerification(Resource::Type type, const char* url, const char* baseURL, int width, const ClientHintsPreferences& preferences) 48 void preloadRequestVerification(Resource::Type type, const char* url, const char* baseURL, int width, const ClientHintsPreferences& preferences)
49 { 49 {
50 if (!url) { 50 if (!url) {
51 EXPECT_FALSE(m_preloadRequest); 51 EXPECT_FALSE(m_preloadRequest);
52 return; 52 return;
53 } 53 }
54 ASSERT(m_preloadRequest.get()); 54 EXPECT_NE(nullptr, m_preloadRequest.get());
55 EXPECT_FALSE(m_preloadRequest->isPreconnect()); 55 if (m_preloadRequest) {
56 EXPECT_EQ(type, m_preloadRequest->resourceType()); 56 EXPECT_FALSE(m_preloadRequest->isPreconnect());
57 EXPECT_STREQ(url, m_preloadRequest->resourceURL().ascii().data()); 57 EXPECT_EQ(type, m_preloadRequest->resourceType());
58 EXPECT_STREQ(baseURL, m_preloadRequest->baseURL().getString().ascii().da ta()); 58 EXPECT_STREQ(url, m_preloadRequest->resourceURL().ascii().data());
59 EXPECT_EQ(width, m_preloadRequest->resourceWidth()); 59 EXPECT_STREQ(baseURL, m_preloadRequest->baseURL().getString().ascii( ).data());
60 EXPECT_EQ(preferences.shouldSendDPR(), m_preloadRequest->preferences().s houldSendDPR()); 60 EXPECT_EQ(width, m_preloadRequest->resourceWidth());
61 EXPECT_EQ(preferences.shouldSendResourceWidth(), m_preloadRequest->prefe rences().shouldSendResourceWidth()); 61 EXPECT_EQ(preferences.shouldSendDPR(), m_preloadRequest->preferences ().shouldSendDPR());
62 EXPECT_EQ(preferences.shouldSendViewportWidth(), m_preloadRequest->prefe rences().shouldSendViewportWidth()); 62 EXPECT_EQ(preferences.shouldSendResourceWidth(), m_preloadRequest->p references().shouldSendResourceWidth());
63 EXPECT_EQ(preferences.shouldSendViewportWidth(), m_preloadRequest->p references().shouldSendViewportWidth());
64 }
63 } 65 }
64 66
65 void preloadRequestVerification(Resource::Type type, const char* url, const char* baseURL, int width, ReferrerPolicy referrerPolicy) 67 void preloadRequestVerification(Resource::Type type, const char* url, const char* baseURL, int width, ReferrerPolicy referrerPolicy)
66 { 68 {
67 preloadRequestVerification(type, url, baseURL, width, ClientHintsPrefere nces()); 69 preloadRequestVerification(type, url, baseURL, width, ClientHintsPrefere nces());
68 EXPECT_EQ(referrerPolicy, m_preloadRequest->getReferrerPolicy()); 70 EXPECT_EQ(referrerPolicy, m_preloadRequest->getReferrerPolicy());
69 } 71 }
70 72
71 void preconnectRequestVerification(const String& host, CrossOriginAttributeV alue crossOrigin) 73 void preconnectRequestVerification(const String& host, CrossOriginAttributeV alue crossOrigin)
72 { 74 {
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 TEST_F(HTMLPreloadScannerTest, testLinkRelPreload) 390 TEST_F(HTMLPreloadScannerTest, testLinkRelPreload)
389 { 391 {
390 TestCase testCases[] = { 392 TestCase testCases[] = {
391 {"http://example.test", "<link rel=preload href=bla>", "bla", "http://ex ample.test/", Resource::LinkPreload, 0}, 393 {"http://example.test", "<link rel=preload href=bla>", "bla", "http://ex ample.test/", Resource::LinkPreload, 0},
392 {"http://example.test", "<link rel=preload href=bla as=script>", "bla", "http://example.test/", Resource::Script, 0}, 394 {"http://example.test", "<link rel=preload href=bla as=script>", "bla", "http://example.test/", Resource::Script, 0},
393 {"http://example.test", "<link rel=preload href=bla as=style>", "bla", " http://example.test/", Resource::CSSStyleSheet, 0}, 395 {"http://example.test", "<link rel=preload href=bla as=style>", "bla", " http://example.test/", Resource::CSSStyleSheet, 0},
394 {"http://example.test", "<link rel=preload href=bla as=image>", "bla", " http://example.test/", Resource::Image, 0}, 396 {"http://example.test", "<link rel=preload href=bla as=image>", "bla", " http://example.test/", Resource::Image, 0},
395 {"http://example.test", "<link rel=preload href=bla as=font>", "bla", "h ttp://example.test/", Resource::Font, 0}, 397 {"http://example.test", "<link rel=preload href=bla as=font>", "bla", "h ttp://example.test/", Resource::Font, 0},
396 {"http://example.test", "<link rel=preload href=bla as=media>", "bla", " http://example.test/", Resource::Media, 0}, 398 {"http://example.test", "<link rel=preload href=bla as=media>", "bla", " http://example.test/", Resource::Media, 0},
397 {"http://example.test", "<link rel=preload href=bla as=track>", "bla", " http://example.test/", Resource::TextTrack, 0}, 399 {"http://example.test", "<link rel=preload href=bla as=track>", "bla", " http://example.test/", Resource::TextTrack, 0},
400 {"http://example.test", "<link rel=preload href=bla as=image media=\"(ma x-width: 800px)\">", "bla", "http://example.test/", Resource::Image, 0},
401 {"http://example.test", "<link rel=preload href=bla as=image media=\"(ma x-width: 400px)\">", nullptr, "http://example.test/", Resource::Image, 0},
398 }; 402 };
399 403
400 for (const auto& testCase : testCases) 404 for (const auto& testCase : testCases)
401 test(testCase); 405 test(testCase);
402 } 406 }
403 407
404 } // namespace blink 408 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/parser/HTMLPreloadScanner.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698