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

Side by Side Diff: third_party/WebKit/Source/core/fetch/ResourceFetcherTest.cpp

Issue 1893673004: Ensure RemoteFontFaceSource doesn't try to start a load in a detached document (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 /* 1 /*
2 * Copyright (c) 2013, Google Inc. All rights reserved. 2 * Copyright (c) 2013, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 24 matching lines...) Expand all
35 #include "core/fetch/FetchRequest.h" 35 #include "core/fetch/FetchRequest.h"
36 #include "core/fetch/MemoryCache.h" 36 #include "core/fetch/MemoryCache.h"
37 #include "core/fetch/RawResource.h" 37 #include "core/fetch/RawResource.h"
38 #include "core/fetch/ResourceLoader.h" 38 #include "core/fetch/ResourceLoader.h"
39 #include "platform/exported/WrappedResourceResponse.h" 39 #include "platform/exported/WrappedResourceResponse.h"
40 #include "platform/heap/Handle.h" 40 #include "platform/heap/Handle.h"
41 #include "platform/network/ResourceRequest.h" 41 #include "platform/network/ResourceRequest.h"
42 #include "platform/testing/URLTestHelpers.h" 42 #include "platform/testing/URLTestHelpers.h"
43 #include "platform/weborigin/KURL.h" 43 #include "platform/weborigin/KURL.h"
44 #include "public/platform/Platform.h" 44 #include "public/platform/Platform.h"
45 #include "public/platform/WebTaskRunner.h"
45 #include "public/platform/WebURLLoaderMockFactory.h" 46 #include "public/platform/WebURLLoaderMockFactory.h"
46 #include "public/platform/WebURLResponse.h" 47 #include "public/platform/WebURLResponse.h"
47 #include "testing/gtest/include/gtest/gtest.h" 48 #include "testing/gtest/include/gtest/gtest.h"
48 49
49 namespace blink { 50 namespace blink {
50 51
52 namespace {
53
54 class MockTaskRunner : public blink::WebTaskRunner {
55 void postTask(const WebTraceLocation&, Task*) override { }
56 void postDelayedTask(const WebTraceLocation&, Task*, double) override { }
57 WebTaskRunner* clone() override { return nullptr; }
58 double virtualTimeSeconds() const override { return 0.0; }
59 double monotonicallyIncreasingVirtualTimeSeconds() const override { return 0 .0; }
60 };
61
62 }
63
51 class ResourceFetcherTestMockFetchContext : public FetchContext { 64 class ResourceFetcherTestMockFetchContext : public FetchContext {
52 public: 65 public:
53 static ResourceFetcherTestMockFetchContext* create() 66 static ResourceFetcherTestMockFetchContext* create()
54 { 67 {
55 return new ResourceFetcherTestMockFetchContext; 68 return new ResourceFetcherTestMockFetchContext;
56 } 69 }
57 70
58 virtual ~ResourceFetcherTestMockFetchContext() { } 71 virtual ~ResourceFetcherTestMockFetchContext() { }
59 72
60 bool allowImage(bool imagesEnabled, const KURL&) const override { return tru e; } 73 bool allowImage(bool imagesEnabled, const KURL&) const override { return tru e; }
61 bool canRequest(Resource::Type, const ResourceRequest&, const KURL&, const R esourceLoaderOptions&, bool forPreload, FetchRequest::OriginRestriction) const o verride { return true; } 74 bool canRequest(Resource::Type, const ResourceRequest&, const KURL&, const R esourceLoaderOptions&, bool forPreload, FetchRequest::OriginRestriction) const o verride { return true; }
62 bool shouldLoadNewResource(Resource::Type) const override { return true; } 75 bool shouldLoadNewResource(Resource::Type) const override { return true; }
76 WebTaskRunner* loadingTaskRunner() const override { return m_runner.get(); }
63 77
64 void setCachePolicy(CachePolicy policy) { m_policy = policy; } 78 void setCachePolicy(CachePolicy policy) { m_policy = policy; }
65 CachePolicy getCachePolicy() const override { return m_policy; } 79 CachePolicy getCachePolicy() const override { return m_policy; }
66 80
67 private: 81 private:
68 ResourceFetcherTestMockFetchContext() 82 ResourceFetcherTestMockFetchContext()
69 : m_policy(CachePolicyVerify) 83 : m_policy(CachePolicyVerify)
84 , m_runner(adoptPtr(new MockTaskRunner))
70 { } 85 { }
71 86
72 CachePolicy m_policy; 87 CachePolicy m_policy;
88 OwnPtr<MockTaskRunner> m_runner;
73 }; 89 };
74 90
75 class ResourceFetcherTest : public ::testing::Test { 91 class ResourceFetcherTest : public ::testing::Test {
76 }; 92 };
77 93
78 class TestResourceFactory : public ResourceFactory { 94 class TestResourceFactory : public ResourceFactory {
79 public: 95 public:
80 TestResourceFactory(Resource::Type type = Resource::Raw) 96 TestResourceFactory(Resource::Type type = Resource::Raw)
81 : ResourceFactory(type) { } 97 : ResourceFactory(type) { }
82 98
83 Resource* create(const ResourceRequest& request, const ResourceLoaderOptions & options, const String& charset) const override 99 Resource* create(const ResourceRequest& request, const ResourceLoaderOptions & options, const String& charset) const override
84 { 100 {
85 return Resource::create(request, type(), options); 101 return Resource::create(request, type(), options);
86 } 102 }
87 }; 103 };
88 104
89 TEST_F(ResourceFetcherTest, StartLoadAfterFrameDetach) 105 TEST_F(ResourceFetcherTest, StartLoadAfterFrameDetach)
90 { 106 {
91 KURL secureURL(ParsedURLString, "https://secureorigin.test/image.png"); 107 KURL secureURL(ParsedURLString, "https://secureorigin.test/image.png");
92 // Try to request a url. The request should fail, no resource should be retu rned, 108 // Try to request a url. The request should fail, no resource should be retu rned,
93 // and no resource should be present in the cache. 109 // and no resource should be present in the cache.
94 ResourceFetcher* fetcher = ResourceFetcher::create(nullptr); 110 ResourceFetcher* fetcher = ResourceFetcher::create(nullptr);
95 FetchRequest fetchRequest = FetchRequest(ResourceRequest(secureURL), FetchIn itiatorInfo()); 111 FetchRequest fetchRequest = FetchRequest(ResourceRequest(secureURL), FetchIn itiatorInfo());
96 Resource* resource = fetcher->requestResource(fetchRequest, TestResourceFact ory()); 112 Resource* resource = fetcher->requestResource(fetchRequest, TestResourceFact ory());
97 EXPECT_EQ(resource, static_cast<Resource*>(nullptr)); 113 EXPECT_EQ(resource, static_cast<Resource*>(nullptr));
98 EXPECT_EQ(memoryCache()->resourceForURL(secureURL), static_cast<Resource*>(n ullptr)); 114 EXPECT_EQ(memoryCache()->resourceForURL(secureURL), static_cast<Resource*>(n ullptr));
115
116 // Try calling Resource::load directly. This shouldn't crash.
117 Resource* resource2 = Resource::create(secureURL, Resource::Raw);
118 resource2->load(fetcher);
99 } 119 }
100 120
101 TEST_F(ResourceFetcherTest, UseExistingResource) 121 TEST_F(ResourceFetcherTest, UseExistingResource)
102 { 122 {
103 ResourceFetcher* fetcher = ResourceFetcher::create(ResourceFetcherTestMockFe tchContext::create()); 123 ResourceFetcher* fetcher = ResourceFetcher::create(ResourceFetcherTestMockFe tchContext::create());
104 124
105 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html"); 125 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html");
106 Resource* resource = Resource::create(url, Resource::Image); 126 Resource* resource = Resource::create(url, Resource::Image);
107 memoryCache()->add(resource); 127 memoryCache()->add(resource);
108 ResourceResponse response; 128 ResourceResponse response;
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 ResourceFetcher* fetcher = ResourceFetcher::create(ResourceFetcherTestMockFe tchContext::create()); 294 ResourceFetcher* fetcher = ResourceFetcher::create(ResourceFetcherTestMockFe tchContext::create());
275 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo()); 295 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo());
276 Resource* resource = fetcher->requestResource(fetchRequest, TestResourceFact ory(Resource::Raw)); 296 Resource* resource = fetcher->requestResource(fetchRequest, TestResourceFact ory(Resource::Raw));
277 ServeRequestsOnCompleteClient client; 297 ServeRequestsOnCompleteClient client;
278 resource->addClient(&client); 298 resource->addClient(&client);
279 resource->loader()->cancel(); 299 resource->loader()->cancel();
280 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url); 300 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url);
281 } 301 }
282 302
283 } // namespace blink 303 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/Resource.cpp ('k') | third_party/WebKit/Source/platform/testing/weburl_loader_mock.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698