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 |