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

Unified Diff: Source/core/loader/LinkLoaderTest.cpp

Issue 1141883003: Enable `as` based priorities for <link rel=preload> (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Review comments Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/loader/LinkLoader.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/loader/LinkLoaderTest.cpp
diff --git a/Source/core/loader/LinkLoaderTest.cpp b/Source/core/loader/LinkLoaderTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..c9a8215753a134974b644f8efb2a3d1fdb90c4fe
--- /dev/null
+++ b/Source/core/loader/LinkLoaderTest.cpp
@@ -0,0 +1,78 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+#include "core/loader/LinkLoader.h"
+
+#include "core/fetch/ResourceFetcher.h"
+#include "core/html/LinkRelAttribute.h"
+#include "core/loader/LinkLoaderClient.h"
+#include "core/testing/DummyPageHolder.h"
+#include "platform/network/ResourceLoadPriority.h"
+
+#include <base/macros.h>
+#include <gtest/gtest.h>
+
+namespace blink {
+
+class MockLinkLoaderClient : public LinkLoaderClient {
+public:
+ MockLinkLoaderClient(bool shouldLoad)
+ : m_shouldLoad(shouldLoad)
+ {
+ }
+
+ virtual bool shouldLoadLink() override
+ {
+ return m_shouldLoad;
+ }
+
+ virtual void linkLoaded() override { }
+ virtual void linkLoadingErrored() override { }
+ virtual void didStartLinkPrerender() override { }
+ virtual void didStopLinkPrerender() override { }
+ virtual void didSendLoadForLinkPrerender() override { }
+ virtual void didSendDOMContentLoadedForLinkPrerender() override { }
+
+private:
+ bool m_shouldLoad;
+};
+
+TEST(LinkLoaderTest, Preload)
+{
+ struct TestCase {
+ const char* href;
+ const char* as;
+ const ResourceLoadPriority priority;
+ const bool shouldLoad;
+ } cases[] = {
+ {"data://example.com/cat.jpg", "image", ResourceLoadPriorityVeryLow, true},
+ {"data://example.com/cat.jpg", "script", ResourceLoadPriorityMedium, true},
+ {"data://example.com/cat.jpg", "stylesheet", ResourceLoadPriorityHigh, true},
+ {"data://example.com/cat.jpg", "blabla", ResourceLoadPriorityUnresolved, true},
+ {"data://example.com/cat.jpg", "image", ResourceLoadPriorityUnresolved, false},
+ };
+
+ // Test the cases with a single header
+ for (const auto& testCase : cases) {
+ OwnPtr<DummyPageHolder> dummyPageHolder = DummyPageHolder::create(IntSize(500, 500));
+ MockLinkLoaderClient loaderClient(testCase.shouldLoad);
+ LinkLoader loader(&loaderClient);
+ KURL hrefURL = KURL(KURL(), testCase.href);
+ loader.loadLink(LinkRelAttribute("preload"),
+ AtomicString(),
+ String(),
+ testCase.as,
+ hrefURL,
+ dummyPageHolder->document());
+ if (testCase.priority == ResourceLoadPriorityUnresolved) {
+ ASSERT(!loader.resource());
+ } else {
+ ASSERT(loader.resource());
+ ASSERT_EQ(testCase.priority, loader.resource()->resourceRequest().priority());
+ }
+ }
+}
+
+} // namespace blink
« no previous file with comments | « Source/core/loader/LinkLoader.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698