OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "config.h" |
| 6 #include "core/loader/LinkLoader.h" |
| 7 |
| 8 #include "core/fetch/ResourceFetcher.h" |
| 9 #include "core/html/LinkRelAttribute.h" |
| 10 #include "core/loader/LinkLoaderClient.h" |
| 11 #include "core/testing/DummyPageHolder.h" |
| 12 #include "platform/network/ResourceLoadPriority.h" |
| 13 |
| 14 #include <base/macros.h> |
| 15 #include <gtest/gtest.h> |
| 16 |
| 17 namespace blink { |
| 18 |
| 19 class MockLinkLoaderClient : public LinkLoaderClient { |
| 20 public: |
| 21 MockLinkLoaderClient(bool shouldLoad) |
| 22 : m_shouldLoad(shouldLoad) |
| 23 { |
| 24 } |
| 25 |
| 26 virtual bool shouldLoadLink() override |
| 27 { |
| 28 return m_shouldLoad; |
| 29 } |
| 30 |
| 31 virtual void linkLoaded() override { } |
| 32 virtual void linkLoadingErrored() override { } |
| 33 virtual void didStartLinkPrerender() override { } |
| 34 virtual void didStopLinkPrerender() override { } |
| 35 virtual void didSendLoadForLinkPrerender() override { } |
| 36 virtual void didSendDOMContentLoadedForLinkPrerender() override { } |
| 37 |
| 38 private: |
| 39 bool m_shouldLoad; |
| 40 }; |
| 41 |
| 42 TEST(LinkLoaderTest, Preload) |
| 43 { |
| 44 struct TestCase { |
| 45 const char* href; |
| 46 const char* as; |
| 47 const ResourceLoadPriority priority; |
| 48 const bool shouldLoad; |
| 49 } cases[] = { |
| 50 {"data://example.com/cat.jpg", "image", ResourceLoadPriorityVeryLow, tru
e}, |
| 51 {"data://example.com/cat.jpg", "script", ResourceLoadPriorityMedium, tru
e}, |
| 52 {"data://example.com/cat.jpg", "stylesheet", ResourceLoadPriorityHigh, t
rue}, |
| 53 {"data://example.com/cat.jpg", "blabla", ResourceLoadPriorityUnresolved,
true}, |
| 54 {"data://example.com/cat.jpg", "image", ResourceLoadPriorityUnresolved,
false}, |
| 55 }; |
| 56 |
| 57 // Test the cases with a single header |
| 58 for (const auto& testCase : cases) { |
| 59 OwnPtr<DummyPageHolder> dummyPageHolder = DummyPageHolder::create(IntSiz
e(500, 500)); |
| 60 MockLinkLoaderClient loaderClient(testCase.shouldLoad); |
| 61 LinkLoader loader(&loaderClient); |
| 62 KURL hrefURL = KURL(KURL(), testCase.href); |
| 63 loader.loadLink(LinkRelAttribute("preload"), |
| 64 AtomicString(), |
| 65 String(), |
| 66 testCase.as, |
| 67 hrefURL, |
| 68 dummyPageHolder->document()); |
| 69 if (testCase.priority == ResourceLoadPriorityUnresolved) { |
| 70 ASSERT(!loader.resource()); |
| 71 } else { |
| 72 ASSERT(loader.resource()); |
| 73 ASSERT_EQ(testCase.priority, loader.resource()->resourceRequest().pr
iority()); |
| 74 } |
| 75 } |
| 76 } |
| 77 |
| 78 } // namespace blink |
OLD | NEW |