Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "config.h" | 5 #include "config.h" |
| 6 #include "core/loader/LinkLoader.h" | 6 #include "core/loader/LinkLoader.h" |
| 7 | 7 |
| 8 #include "core/fetch/ResourceFetcher.h" | 8 #include "core/fetch/ResourceFetcher.h" |
| 9 #include "core/frame/Settings.h" | 9 #include "core/frame/Settings.h" |
| 10 #include "core/html/LinkRelAttribute.h" | 10 #include "core/html/LinkRelAttribute.h" |
| 11 #include "core/loader/DocumentLoader.h" | |
| 11 #include "core/loader/LinkLoaderClient.h" | 12 #include "core/loader/LinkLoaderClient.h" |
| 12 #include "core/loader/NetworkHintsInterface.h" | 13 #include "core/loader/NetworkHintsInterface.h" |
| 13 #include "core/testing/DummyPageHolder.h" | 14 #include "core/testing/DummyPageHolder.h" |
| 14 #include "platform/network/ResourceLoadPriority.h" | 15 #include "platform/network/ResourceLoadPriority.h" |
| 15 | 16 |
| 16 #include <base/macros.h> | 17 #include <base/macros.h> |
| 17 #include <gtest/gtest.h> | 18 #include <gtest/gtest.h> |
| 18 | 19 |
| 19 namespace blink { | 20 namespace blink { |
| 20 | 21 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 }; | 76 }; |
| 76 | 77 |
| 77 TEST(LinkLoaderTest, Preload) | 78 TEST(LinkLoaderTest, Preload) |
| 78 { | 79 { |
| 79 struct TestCase { | 80 struct TestCase { |
| 80 const char* href; | 81 const char* href; |
| 81 const char* as; | 82 const char* as; |
| 82 const ResourceLoadPriority priority; | 83 const ResourceLoadPriority priority; |
| 83 const bool shouldLoad; | 84 const bool shouldLoad; |
| 84 } cases[] = { | 85 } cases[] = { |
| 85 {"data://example.com/cat.jpg", "image", ResourceLoadPriorityVeryLow, tru e}, | 86 {"data://example.test/cat.jpg", "image", ResourceLoadPriorityVeryLow, tr ue}, |
| 86 {"data://example.com/cat.jpg", "script", ResourceLoadPriorityMedium, tru e}, | 87 {"data://example.test/cat.js", "script", ResourceLoadPriorityMedium, tru e}, |
| 87 {"data://example.com/cat.jpg", "stylesheet", ResourceLoadPriorityHigh, t rue}, | 88 {"data://example.test/cat.css", "stylesheet", ResourceLoadPriorityHigh, true}, |
| 88 {"data://example.com/cat.jpg", "blabla", ResourceLoadPriorityUnresolved, true}, | 89 {"data://example.test/cat.blob", "blabla", ResourceLoadPriorityUnresolve d, false}, |
| 89 {"data://example.com/cat.jpg", "image", ResourceLoadPriorityUnresolved, false}, | |
| 90 }; | 90 }; |
| 91 | 91 |
| 92 // Test the cases with a single header | 92 // Test the cases with a single header |
| 93 for (const auto& testCase : cases) { | 93 for (const auto& testCase : cases) { |
| 94 OwnPtr<DummyPageHolder> dummyPageHolder = DummyPageHolder::create(IntSiz e(500, 500)); | 94 OwnPtr<DummyPageHolder> dummyPageHolder = DummyPageHolder::create(IntSiz e(500, 500)); |
| 95 dummyPageHolder->frame().settings()->setScriptEnabled(true); | |
| 95 MockLinkLoaderClient loaderClient(testCase.shouldLoad); | 96 MockLinkLoaderClient loaderClient(testCase.shouldLoad); |
| 96 LinkLoader loader(&loaderClient); | 97 LinkLoader loader(&loaderClient); |
| 97 KURL hrefURL = KURL(KURL(), testCase.href); | 98 KURL hrefURL = KURL(KURL(), testCase.href); |
| 98 loader.loadLink(LinkRelAttribute("preload"), | 99 loader.loadLink(LinkRelAttribute("preload"), |
| 99 AtomicString(), | 100 AtomicString(), |
| 100 String(), | 101 String(), |
| 101 testCase.as, | 102 testCase.as, |
| 102 hrefURL, | 103 hrefURL, |
| 103 dummyPageHolder->document(), | 104 dummyPageHolder->document(), |
| 104 NetworkHintsMock()); | 105 NetworkHintsMock()); |
| 105 if (testCase.priority == ResourceLoadPriorityUnresolved) { | 106 ASSERT(dummyPageHolder->document().fetcher()); |
| 106 ASSERT(!loader.resource()); | 107 WillBeHeapListHashSet<RawPtrWillBeMember<Resource>>* preloads = dummyPag eHolder->document().fetcher()->preloads(); |
| 107 } else { | 108 if (testCase.shouldLoad) |
| 108 ASSERT(loader.resource()); | 109 ASSERT_LT(nullptr, preloads); |
|
Nate Chapin
2015/11/03 20:18:11
ASSERT_LT(nullptr, ...) looks fishy.
ASSERT_NE in
| |
| 109 ASSERT_EQ(testCase.priority, loader.resource()->resourceRequest().pr iority()); | 110 if (preloads) { |
| 111 if (testCase.priority == ResourceLoadPriorityUnresolved) { | |
| 112 ASSERT_EQ((unsigned)0, preloads->size()); | |
| 113 } else { | |
| 114 ASSERT_EQ((unsigned)1, preloads->size()); | |
| 115 if (preloads->size() > 0) | |
| 116 ASSERT_EQ(testCase.priority, preloads->begin().get()->get()- >resourceRequest().priority()); | |
| 117 } | |
| 110 } | 118 } |
| 111 } | 119 } |
| 112 } | 120 } |
| 113 | 121 |
| 114 TEST(LinkLoaderTest, DNSPrefetch) | 122 TEST(LinkLoaderTest, DNSPrefetch) |
| 115 { | 123 { |
| 116 struct { | 124 struct { |
| 117 const char* href; | 125 const char* href; |
| 118 const bool shouldLoad; | 126 const bool shouldLoad; |
| 119 } cases[] = { | 127 } cases[] = { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 hrefURL, | 181 hrefURL, |
| 174 dummyPageHolder->document(), | 182 dummyPageHolder->document(), |
| 175 networkHints); | 183 networkHints); |
| 176 ASSERT_EQ(testCase.shouldLoad, networkHints.didPreconnect()); | 184 ASSERT_EQ(testCase.shouldLoad, networkHints.didPreconnect()); |
| 177 ASSERT_EQ(testCase.isHTTPS, networkHints.isHTTPS()); | 185 ASSERT_EQ(testCase.isHTTPS, networkHints.isHTTPS()); |
| 178 ASSERT_EQ(testCase.isCrossOrigin, networkHints.isCrossOrigin()); | 186 ASSERT_EQ(testCase.isCrossOrigin, networkHints.isCrossOrigin()); |
| 179 } | 187 } |
| 180 } | 188 } |
| 181 | 189 |
| 182 } // namespace blink | 190 } // namespace blink |
| OLD | NEW |