| OLD | NEW |
| 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 16 matching lines...) Expand all Loading... |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "core/fetch/ResourceFetcher.h" | 31 #include "core/fetch/ResourceFetcher.h" |
| 32 | 32 |
| 33 #include "core/fetch/FetchInitiatorInfo.h" | 33 #include "core/fetch/FetchInitiatorInfo.h" |
| 34 #include "core/fetch/FetchInitiatorTypeNames.h" | 34 #include "core/fetch/FetchInitiatorTypeNames.h" |
| 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/ResourceLoader.h" | 38 #include "core/fetch/ResourceLoader.h" |
| 38 #include "platform/exported/WrappedResourceResponse.h" | 39 #include "platform/exported/WrappedResourceResponse.h" |
| 39 #include "platform/heap/Handle.h" | 40 #include "platform/heap/Handle.h" |
| 40 #include "platform/network/ResourceRequest.h" | 41 #include "platform/network/ResourceRequest.h" |
| 41 #include "platform/testing/URLTestHelpers.h" | 42 #include "platform/testing/URLTestHelpers.h" |
| 42 #include "platform/weborigin/KURL.h" | 43 #include "platform/weborigin/KURL.h" |
| 43 #include "public/platform/Platform.h" | 44 #include "public/platform/Platform.h" |
| 44 #include "public/platform/WebURLResponse.h" | 45 #include "public/platform/WebURLResponse.h" |
| 45 #include "public/platform/WebUnitTestSupport.h" | 46 #include "public/platform/WebUnitTestSupport.h" |
| 46 #include "testing/gtest/include/gtest/gtest.h" | 47 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 ResourceRequest request(KURL(ParsedURLString, "data:text/html,foo")); | 231 ResourceRequest request(KURL(ParsedURLString, "data:text/html,foo")); |
| 231 ResourceLoaderOptions options; | 232 ResourceLoaderOptions options; |
| 232 options.dataBufferingPolicy = DoNotBufferData; | 233 options.dataBufferingPolicy = DoNotBufferData; |
| 233 FetchRequest fetchRequest = FetchRequest(request, FetchInitiatorTypeNames::i
nternal, options); | 234 FetchRequest fetchRequest = FetchRequest(request, FetchInitiatorTypeNames::i
nternal, options); |
| 234 RefPtrWillBeRawPtr<Resource> resource1 = fetcher->requestResource(fetchReque
st, TestResourceFactory(Resource::Media)); | 235 RefPtrWillBeRawPtr<Resource> resource1 = fetcher->requestResource(fetchReque
st, TestResourceFactory(Resource::Media)); |
| 235 RefPtrWillBeRawPtr<Resource> resource2 = fetcher->requestResource(fetchReque
st, TestResourceFactory(Resource::Media)); | 236 RefPtrWillBeRawPtr<Resource> resource2 = fetcher->requestResource(fetchReque
st, TestResourceFactory(Resource::Media)); |
| 236 EXPECT_NE(resource1.get(), resource2.get()); | 237 EXPECT_NE(resource1.get(), resource2.get()); |
| 237 memoryCache()->remove(resource2.get()); | 238 memoryCache()->remove(resource2.get()); |
| 238 } | 239 } |
| 239 | 240 |
| 241 class ServeRequestsOnCompleteClient : public RawResourceClient { |
| 242 public: |
| 243 void notifyFinished(Resource*) override |
| 244 { |
| 245 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(
); |
| 246 } |
| 247 |
| 248 // No callbacks should be received except for the notifyFinished() |
| 249 // triggered by ResourceLoader::cancel(). |
| 250 void dataSent(Resource*, unsigned long long, unsigned long long) override {
ASSERT_TRUE(false); } |
| 251 void responseReceived(Resource*, const ResourceResponse&, PassOwnPtr<WebData
ConsumerHandle>) override { ASSERT_TRUE(false); } |
| 252 void setSerializedCachedMetadata(Resource*, const char*, size_t) override {
ASSERT_TRUE(false); } |
| 253 void dataReceived(Resource*, const char*, size_t) override { ASSERT_TRUE(fal
se); } |
| 254 void redirectReceived(Resource*, ResourceRequest&, const ResourceResponse&)
override { ASSERT_TRUE(false); } |
| 255 void dataDownloaded(Resource*, int) override { ASSERT_TRUE(false); } |
| 256 void didReceiveResourceTiming(Resource*, const ResourceTimingInfo&) override
{ ASSERT_TRUE(false); } |
| 257 |
| 258 String debugName() const override { return "ServeRequestsOnCompleteClient";
} |
| 259 }; |
| 260 |
| 261 // Regression test for http://crbug.com/594072. |
| 262 // This emulates a modal dialog triggering a nested run loop inside |
| 263 // ResourceLoader::cancel(). If the ResourceLoader doesn't promptly cancel its |
| 264 // WebURLLoader before notifying its clients, a nested run loop may send a |
| 265 // network response, leading to an invalid state transition in ResourceLoader. |
| 266 TEST_F(ResourceFetcherTest, ResponseOnCancel) |
| 267 { |
| 268 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html"); |
| 269 ResourceResponse response; |
| 270 response.setURL(url); |
| 271 response.setHTTPStatusCode(200); |
| 272 URLTestHelpers::registerMockedURLLoadWithCustomResponse(url, "white-1x1.png"
, WebString::fromUTF8(""), WrappedResourceResponse(response)); |
| 273 |
| 274 ResourceFetcher* fetcher = ResourceFetcher::create(ResourceFetcherTestMockFe
tchContext::create()); |
| 275 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo()); |
| 276 RefPtrWillBeRawPtr<Resource> resource = fetcher->requestResource(fetchReques
t, TestResourceFactory(Resource::Raw)); |
| 277 ServeRequestsOnCompleteClient client; |
| 278 resource->addClient(&client); |
| 279 resource->loader()->cancel(); |
| 280 Platform::current()->unitTestSupport()->unregisterMockedURL(url); |
| 281 } |
| 282 |
| 240 } // namespace blink | 283 } // namespace blink |
| OLD | NEW |