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

Side by Side Diff: third_party/WebKit/Source/core/loader/LinkLoaderTest.cpp

Issue 2050123002: Remove OwnPtr from Blink. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: First attempt to land. Created 4 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 unified diff | Download patch
OLDNEW
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 "core/loader/LinkLoader.h" 5 #include "core/loader/LinkLoader.h"
6 6
7 #include "core/fetch/MemoryCache.h" 7 #include "core/fetch/MemoryCache.h"
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/DocumentLoader.h"
12 #include "core/loader/LinkLoaderClient.h" 12 #include "core/loader/LinkLoaderClient.h"
13 #include "core/loader/NetworkHintsInterface.h" 13 #include "core/loader/NetworkHintsInterface.h"
14 #include "core/testing/DummyPageHolder.h" 14 #include "core/testing/DummyPageHolder.h"
15 #include "platform/network/ResourceLoadPriority.h" 15 #include "platform/network/ResourceLoadPriority.h"
16 #include "platform/testing/URLTestHelpers.h" 16 #include "platform/testing/URLTestHelpers.h"
17 #include "public/platform/Platform.h" 17 #include "public/platform/Platform.h"
18 #include "public/platform/WebURLLoaderMockFactory.h" 18 #include "public/platform/WebURLLoaderMockFactory.h"
19 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
20 #include <base/macros.h> 20 #include <base/macros.h>
21 #include <memory>
21 22
22 namespace blink { 23 namespace blink {
23 24
24 class MockLinkLoaderClient final : public GarbageCollectedFinalized<MockLinkLoad erClient>, public LinkLoaderClient { 25 class MockLinkLoaderClient final : public GarbageCollectedFinalized<MockLinkLoad erClient>, public LinkLoaderClient {
25 USING_GARBAGE_COLLECTED_MIXIN(MockLinkLoaderClient); 26 USING_GARBAGE_COLLECTED_MIXIN(MockLinkLoaderClient);
26 public: 27 public:
27 static MockLinkLoaderClient* create(bool shouldLoad) 28 static MockLinkLoaderClient* create(bool shouldLoad)
28 { 29 {
29 return new MockLinkLoaderClient(shouldLoad); 30 return new MockLinkLoaderClient(shouldLoad);
30 } 31 }
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 {"http://example.test/cat.empty", "", "foo/bar", "", ResourceLoadPriorit yLow, WebURLRequest::RequestContextSubresource, true, true}, 129 {"http://example.test/cat.empty", "", "foo/bar", "", ResourceLoadPriorit yLow, WebURLRequest::RequestContextSubresource, true, true},
129 {"http://example.test/cat.blob", "blabla", "foo/bar", "", ResourceLoadPr iorityLow, WebURLRequest::RequestContextSubresource, false, false}, 130 {"http://example.test/cat.blob", "blabla", "foo/bar", "", ResourceLoadPr iorityLow, WebURLRequest::RequestContextSubresource, false, false},
130 // Media tests 131 // Media tests
131 {"http://example.test/cat.gif", "image", "image/gif", "(max-width: 600px )", ResourceLoadPriorityLow, WebURLRequest::RequestContextImage, true, true}, 132 {"http://example.test/cat.gif", "image", "image/gif", "(max-width: 600px )", ResourceLoadPriorityLow, WebURLRequest::RequestContextImage, true, true},
132 {"http://example.test/cat.gif", "image", "image/gif", "(max-width: 400px )", ResourceLoadPriorityUnresolved, WebURLRequest::RequestContextImage, true, fa lse}, 133 {"http://example.test/cat.gif", "image", "image/gif", "(max-width: 400px )", ResourceLoadPriorityUnresolved, WebURLRequest::RequestContextImage, true, fa lse},
133 {"http://example.test/cat.gif", "image", "image/gif", "(max-width: 600px )", ResourceLoadPriorityLow, WebURLRequest::RequestContextImage, false, false}, 134 {"http://example.test/cat.gif", "image", "image/gif", "(max-width: 600px )", ResourceLoadPriorityLow, WebURLRequest::RequestContextImage, false, false},
134 }; 135 };
135 136
136 // Test the cases with a single header 137 // Test the cases with a single header
137 for (const auto& testCase : cases) { 138 for (const auto& testCase : cases) {
138 OwnPtr<DummyPageHolder> dummyPageHolder = DummyPageHolder::create(IntSiz e(500, 500)); 139 std::unique_ptr<DummyPageHolder> dummyPageHolder = DummyPageHolder::crea te(IntSize(500, 500));
139 dummyPageHolder->frame().settings()->setScriptEnabled(true); 140 dummyPageHolder->frame().settings()->setScriptEnabled(true);
140 Persistent<MockLinkLoaderClient> loaderClient = MockLinkLoaderClient::cr eate(testCase.linkLoaderShouldLoadValue); 141 Persistent<MockLinkLoaderClient> loaderClient = MockLinkLoaderClient::cr eate(testCase.linkLoaderShouldLoadValue);
141 LinkLoader* loader = LinkLoader::create(loaderClient.get()); 142 LinkLoader* loader = LinkLoader::create(loaderClient.get());
142 KURL hrefURL = KURL(KURL(), testCase.href); 143 KURL hrefURL = KURL(KURL(), testCase.href);
143 URLTestHelpers::registerMockedErrorURLLoad(hrefURL); 144 URLTestHelpers::registerMockedErrorURLLoad(hrefURL);
144 loader->loadLink(LinkRelAttribute("preload"), 145 loader->loadLink(LinkRelAttribute("preload"),
145 CrossOriginAttributeNotSet, 146 CrossOriginAttributeNotSet,
146 testCase.type, 147 testCase.type,
147 testCase.as, 148 testCase.as,
148 testCase.media, 149 testCase.media,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 } cases[] = { 185 } cases[] = {
185 {"http://example.com/", true}, 186 {"http://example.com/", true},
186 {"https://example.com/", true}, 187 {"https://example.com/", true},
187 {"//example.com/", true}, 188 {"//example.com/", true},
188 }; 189 };
189 190
190 // TODO(yoav): Test (and fix) shouldLoad = false 191 // TODO(yoav): Test (and fix) shouldLoad = false
191 192
192 // Test the cases with a single header 193 // Test the cases with a single header
193 for (const auto& testCase : cases) { 194 for (const auto& testCase : cases) {
194 OwnPtr<DummyPageHolder> dummyPageHolder = DummyPageHolder::create(IntSiz e(500, 500)); 195 std::unique_ptr<DummyPageHolder> dummyPageHolder = DummyPageHolder::crea te(IntSize(500, 500));
195 dummyPageHolder->document().settings()->setDNSPrefetchingEnabled(true); 196 dummyPageHolder->document().settings()->setDNSPrefetchingEnabled(true);
196 Persistent<MockLinkLoaderClient> loaderClient = MockLinkLoaderClient::cr eate(testCase.shouldLoad); 197 Persistent<MockLinkLoaderClient> loaderClient = MockLinkLoaderClient::cr eate(testCase.shouldLoad);
197 LinkLoader* loader = LinkLoader::create(loaderClient.get()); 198 LinkLoader* loader = LinkLoader::create(loaderClient.get());
198 KURL hrefURL = KURL(KURL(ParsedURLStringTag(), String("http://example.co m")), testCase.href); 199 KURL hrefURL = KURL(KURL(ParsedURLStringTag(), String("http://example.co m")), testCase.href);
199 NetworkHintsMock networkHints; 200 NetworkHintsMock networkHints;
200 loader->loadLink(LinkRelAttribute("dns-prefetch"), 201 loader->loadLink(LinkRelAttribute("dns-prefetch"),
201 CrossOriginAttributeNotSet, 202 CrossOriginAttributeNotSet,
202 String(), 203 String(),
203 String(), 204 String(),
204 String(), 205 String(),
(...skipping 15 matching lines...) Expand all
220 const bool isCrossOrigin; 221 const bool isCrossOrigin;
221 } cases[] = { 222 } cases[] = {
222 {"http://example.com/", CrossOriginAttributeNotSet, true, false, false}, 223 {"http://example.com/", CrossOriginAttributeNotSet, true, false, false},
223 {"https://example.com/", CrossOriginAttributeNotSet, true, true, false}, 224 {"https://example.com/", CrossOriginAttributeNotSet, true, true, false},
224 {"http://example.com/", CrossOriginAttributeAnonymous, true, false, true }, 225 {"http://example.com/", CrossOriginAttributeAnonymous, true, false, true },
225 {"//example.com/", CrossOriginAttributeNotSet, true, false, false}, 226 {"//example.com/", CrossOriginAttributeNotSet, true, false, false},
226 }; 227 };
227 228
228 // Test the cases with a single header 229 // Test the cases with a single header
229 for (const auto& testCase : cases) { 230 for (const auto& testCase : cases) {
230 OwnPtr<DummyPageHolder> dummyPageHolder = DummyPageHolder::create(IntSiz e(500, 500)); 231 std::unique_ptr<DummyPageHolder> dummyPageHolder = DummyPageHolder::crea te(IntSize(500, 500));
231 Persistent<MockLinkLoaderClient> loaderClient = MockLinkLoaderClient::cr eate(testCase.shouldLoad); 232 Persistent<MockLinkLoaderClient> loaderClient = MockLinkLoaderClient::cr eate(testCase.shouldLoad);
232 LinkLoader* loader = LinkLoader::create(loaderClient.get()); 233 LinkLoader* loader = LinkLoader::create(loaderClient.get());
233 KURL hrefURL = KURL(KURL(ParsedURLStringTag(), String("http://example.co m")), testCase.href); 234 KURL hrefURL = KURL(KURL(ParsedURLStringTag(), String("http://example.co m")), testCase.href);
234 NetworkHintsMock networkHints; 235 NetworkHintsMock networkHints;
235 loader->loadLink(LinkRelAttribute("preconnect"), 236 loader->loadLink(LinkRelAttribute("preconnect"),
236 testCase.crossOrigin, 237 testCase.crossOrigin,
237 String(), 238 String(),
238 String(), 239 String(),
239 String(), 240 String(),
240 hrefURL, 241 hrefURL,
241 dummyPageHolder->document(), 242 dummyPageHolder->document(),
242 networkHints); 243 networkHints);
243 ASSERT_EQ(testCase.shouldLoad, networkHints.didPreconnect()); 244 ASSERT_EQ(testCase.shouldLoad, networkHints.didPreconnect());
244 ASSERT_EQ(testCase.isHTTPS, networkHints.isHTTPS()); 245 ASSERT_EQ(testCase.isHTTPS, networkHints.isHTTPS());
245 ASSERT_EQ(testCase.isCrossOrigin, networkHints.isCrossOrigin()); 246 ASSERT_EQ(testCase.isCrossOrigin, networkHints.isCrossOrigin());
246 } 247 }
247 } 248 }
248 249
249 } // namespace blink 250 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/loader/LinkLoader.h ('k') | third_party/WebKit/Source/core/loader/MixedContentCheckerTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698