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

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

Issue 1563263002: Add HTMLPreloadScanner support for <link rel=preload> (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed a test as well as 2 bugs that other tests revealed Created 4 years, 11 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"
(...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_FALSE(m_preloadRequest->isPreconnect()); 55 EXPECT_FALSE(m_preloadRequest->isPreconnect());
55 EXPECT_EQ(type, m_preloadRequest->resourceType()); 56 EXPECT_EQ(type, m_preloadRequest->resourceType());
56 EXPECT_STREQ(url, m_preloadRequest->resourceURL().ascii().data()); 57 EXPECT_STREQ(url, m_preloadRequest->resourceURL().ascii().data());
57 EXPECT_STREQ(baseURL, m_preloadRequest->baseURL().string().ascii().data( )); 58 EXPECT_STREQ(baseURL, m_preloadRequest->baseURL().string().ascii().data( ));
58 EXPECT_EQ(width, m_preloadRequest->resourceWidth()); 59 EXPECT_EQ(width, m_preloadRequest->resourceWidth());
59 EXPECT_EQ(preferences.shouldSendDPR(), m_preloadRequest->preferences().s houldSendDPR()); 60 EXPECT_EQ(preferences.shouldSendDPR(), m_preloadRequest->preferences().s houldSendDPR());
60 EXPECT_EQ(preferences.shouldSendResourceWidth(), m_preloadRequest->prefe rences().shouldSendResourceWidth()); 61 EXPECT_EQ(preferences.shouldSendResourceWidth(), m_preloadRequest->prefe rences().shouldSendResourceWidth());
61 EXPECT_EQ(preferences.shouldSendViewportWidth(), m_preloadRequest->prefe rences().shouldSendViewportWidth()); 62 EXPECT_EQ(preferences.shouldSendViewportWidth(), m_preloadRequest->prefe rences().shouldSendViewportWidth());
62 } 63 }
63 64
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 { "http://example.test", "<meta name='referrer' content='no-referrer'><i mg referrerpolicy='origin' src='bla.gif'/>", "bla.gif", "http://example.test/", Resource::Image, 0, ReferrerPolicyOrigin }, 355 { "http://example.test", "<meta name='referrer' content='no-referrer'><i mg referrerpolicy='origin' src='bla.gif'/>", "bla.gif", "http://example.test/", Resource::Image, 0, ReferrerPolicyOrigin },
355 // The scanner's state is not reset between test cases, so all subsequen t test cases have a document referrer policy of no-referrer. 356 // The scanner's state is not reset between test cases, so all subsequen t test cases have a document referrer policy of no-referrer.
356 { "http://example.test", "<img referrerpolicy='not-a-valid-policy' src=' bla.gif'/>", "bla.gif", "http://example.test/", Resource::Image, 0, ReferrerPoli cyNever }, 357 { "http://example.test", "<img referrerpolicy='not-a-valid-policy' src=' bla.gif'/>", "bla.gif", "http://example.test/", Resource::Image, 0, ReferrerPoli cyNever },
357 { "http://example.test", "<img src='bla.gif'/>", "bla.gif", "http://exam ple.test/", Resource::Image, 0, ReferrerPolicyNever } 358 { "http://example.test", "<img src='bla.gif'/>", "bla.gif", "http://exam ple.test/", Resource::Image, 0, ReferrerPolicyNever }
358 }; 359 };
359 360
360 for (const auto& testCase : testCases) 361 for (const auto& testCase : testCases)
361 test(testCase); 362 test(testCase);
362 } 363 }
363 364
365 TEST_F(HTMLPreloadScannerTest, testLinkRelPreload)
366 {
367 TestCase testCases[] = {
368 {"http://example.test", "<link rel=preload href=bla>", "bla", "http://ex ample.test/", Resource::LinkSubresource, 0},
369 {"http://example.test", "<link rel=preload href=bla as=script>", "bla", "http://example.test/", Resource::Script, 0},
370 {"http://example.test", "<link rel=preload href=bla as=style>", "bla", " http://example.test/", Resource::CSSStyleSheet, 0},
371 {"http://example.test", "<link rel=preload href=bla as=image>", "bla", " http://example.test/", Resource::Image, 0},
372 {"http://example.test", "<link rel=preload href=bla as=font>", "bla", "h ttp://example.test/", Resource::Font, 0},
373 {"http://example.test", "<link rel=preload href=bla as=audio>", "bla", " http://example.test/", Resource::Media, 0},
374 {"http://example.test", "<link rel=preload href=bla as=video>", "bla", " http://example.test/", Resource::Media, 0},
375 {"http://example.test", "<link rel=preload href=bla as=track>", "bla", " http://example.test/", Resource::TextTrack, 0},
376 };
377
378 for (const auto& testCase : testCases)
379 test(testCase);
380 }
381
364 } // namespace blink 382 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698