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

Unified Diff: Source/core/html/parser/HTMLPreloadScannerTest.cpp

Issue 1196193005: Allow preload scanners to be disabled by Settings. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@minimaster
Patch Set: add unit test Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/html/parser/HTMLPreloadScanner.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/parser/HTMLPreloadScannerTest.cpp
diff --git a/Source/core/html/parser/HTMLPreloadScannerTest.cpp b/Source/core/html/parser/HTMLPreloadScannerTest.cpp
index d313e1c964db21bdd3437325a6635bf43c0e150c..7f2182cf11083bab6576ba57d9cdcd300460f829 100644
--- a/Source/core/html/parser/HTMLPreloadScannerTest.cpp
+++ b/Source/core/html/parser/HTMLPreloadScannerTest.cpp
@@ -17,31 +17,35 @@
namespace blink {
-typedef struct {
+struct TestCase {
const char* baseURL;
const char* inputHTML;
- const char* preloadedURL;
+ const char* preloadedURL; // Or nullptr if no preload is expected.
const char* outputBaseURL;
Resource::Type type;
int resourceWidth;
ClientHintsPreferences preferences;
-} TestCase;
+};
-typedef struct {
+struct PreconnectTestCase {
const char* baseURL;
const char* inputHTML;
const char* preconnectedHost;
CrossOriginAttributeValue crossOrigin;
-} PreconnectTestCase;
+};
class MockHTMLResourcePreloader : public ResourcePreloader {
public:
- void preloadRequestVerification(Resource::Type type, const String& url, const String& baseURL, int width, const ClientHintsPreferences& preferences)
+ void preloadRequestVerification(Resource::Type type, const char* url, const char* baseURL, int width, const ClientHintsPreferences& preferences)
{
+ if (!url) {
+ EXPECT_FALSE(m_preloadRequest);
+ return;
+ }
EXPECT_FALSE(m_preloadRequest->isPreconnect());
EXPECT_EQ(type, m_preloadRequest->resourceType());
- EXPECT_STREQ(url.ascii().data(), m_preloadRequest->resourceURL().ascii().data());
- EXPECT_STREQ(baseURL.ascii().data(), m_preloadRequest->baseURL().string().ascii().data());
+ EXPECT_STREQ(url, m_preloadRequest->resourceURL().ascii().data());
+ EXPECT_STREQ(baseURL, m_preloadRequest->baseURL().string().ascii().data());
EXPECT_EQ(width, m_preloadRequest->resourceWidth());
EXPECT_EQ(preferences.shouldSendDPR(), m_preloadRequest->preferences().shouldSendDPR());
EXPECT_EQ(preferences.shouldSendResourceWidth(), m_preloadRequest->preferences().shouldSendResourceWidth());
@@ -70,6 +74,16 @@ private:
class HTMLPreloadScannerTest : public testing::Test {
protected:
+ enum ViewportState {
+ ViewportEnabled,
+ ViewportDisabled,
+ };
+
+ enum PreloadState {
+ PreloadEnabled,
+ PreloadDisabled,
+ };
+
HTMLPreloadScannerTest()
: m_dummyPageHolder(DummyPageHolder::create())
{
@@ -94,18 +108,19 @@ protected:
return MediaValuesCached::create(data);
}
- void runSetUp(bool viewportEnabled)
+ void runSetUp(ViewportState viewportState, PreloadState preloadState = PreloadEnabled)
{
HTMLParserOptions options(&m_dummyPageHolder->document());
KURL documentURL(ParsedURLString, "http://whatever.test/");
- m_dummyPageHolder->document().settings()->setViewportEnabled(viewportEnabled);
- m_dummyPageHolder->document().settings()->setViewportMetaEnabled(viewportEnabled);
+ m_dummyPageHolder->document().settings()->setViewportEnabled(viewportState == ViewportEnabled);
+ m_dummyPageHolder->document().settings()->setViewportMetaEnabled(viewportState == ViewportEnabled);
+ m_dummyPageHolder->document().settings()->setDoHtmlPreloadScanning(preloadState == PreloadEnabled);
m_scanner = HTMLPreloadScanner::create(options, documentURL, CachedDocumentParameters::create(&m_dummyPageHolder->document(), createMediaValues()));
}
void SetUp() override
{
- runSetUp(true);
+ runSetUp(ViewportEnabled);
}
void test(TestCase testCase)
@@ -188,7 +203,7 @@ TEST_F(HTMLPreloadScannerTest, testImagesWithViewport)
TEST_F(HTMLPreloadScannerTest, testImagesWithViewportDisabled)
{
- runSetUp(false);
+ runSetUp(ViewportDisabled);
TestCase testCases[] = {
{"http://example.test", "<meta name=viewport content='width=160'><img src='bla.gif'>", "bla.gif", "http://example.test/", Resource::Image, 0},
{"http://example.test", "<img srcset='bla.gif 320w, blabla.gif 640w'>", "blabla.gif", "http://example.test/", Resource::Image, 0},
@@ -246,7 +261,7 @@ TEST_F(HTMLPreloadScannerTest, testMetaAcceptCH)
};
for (const auto& testCase : testCases) {
- runSetUp(false);
+ runSetUp(ViewportDisabled);
test(testCase);
}
}
@@ -265,4 +280,16 @@ TEST_F(HTMLPreloadScannerTest, testPreconnect)
test(testCase);
}
+TEST_F(HTMLPreloadScannerTest, testDisables)
+{
+ runSetUp(ViewportEnabled, PreloadDisabled);
+
+ TestCase testCases[] = {
+ {"http://example.test", "<img src='bla.gif'>"},
+ };
+
+ for (const auto& testCase : testCases)
+ test(testCase);
+}
+
} // namespace blink
« no previous file with comments | « Source/core/html/parser/HTMLPreloadScanner.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698