| 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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 ASSERT_TRUE(resource->hasVaryHeader()); | 208 ASSERT_TRUE(resource->hasVaryHeader()); |
| 209 | 209 |
| 210 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo()); | 210 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo()); |
| 211 Resource* newResource = fetcher->requestResource(fetchRequest, TestResourceF
actory(Resource::Image)); | 211 Resource* newResource = fetcher->requestResource(fetchRequest, TestResourceF
actory(Resource::Image)); |
| 212 EXPECT_EQ(resource, newResource); | 212 EXPECT_EQ(resource, newResource); |
| 213 | 213 |
| 214 memoryCache()->remove(newResource); | 214 memoryCache()->remove(newResource); |
| 215 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url); | 215 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url); |
| 216 } | 216 } |
| 217 | 217 |
| 218 TEST_F(ResourceFetcherTest, RevalidateWhileLoading) | 218 class RequestSameResourceOnComplete : public RawResourceClient { |
| 219 public: |
| 220 explicit RequestSameResourceOnComplete(Resource* resource) |
| 221 : m_resource(resource) |
| 222 , m_notifyFinishedCalled(false) |
| 223 { |
| 224 } |
| 225 |
| 226 void notifyFinished(Resource* resource) override |
| 227 { |
| 228 ASSERT_EQ(m_resource, resource); |
| 229 ResourceFetcherTestMockFetchContext* context = ResourceFetcherTestMockFe
tchContext::create(); |
| 230 context->setCachePolicy(CachePolicyRevalidate); |
| 231 ResourceFetcher* fetcher2 = ResourceFetcher::create(context); |
| 232 FetchRequest fetchRequest2(m_resource->url(), FetchInitiatorInfo()); |
| 233 Resource* resource2 = fetcher2->requestResource(fetchRequest2, TestResou
rceFactory(Resource::Image)); |
| 234 EXPECT_EQ(m_resource, resource2); |
| 235 m_notifyFinishedCalled = true; |
| 236 } |
| 237 bool notifyFinishedCalled() const { return m_notifyFinishedCalled; } |
| 238 |
| 239 String debugName() const override { return "RequestSameResourceOnComplete";
} |
| 240 |
| 241 private: |
| 242 Persistent<Resource> m_resource; |
| 243 bool m_notifyFinishedCalled; |
| 244 }; |
| 245 |
| 246 TEST_F(ResourceFetcherTest, RevalidateWhileFinishingLoading) |
| 219 { | 247 { |
| 220 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html"); | 248 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html"); |
| 221 Platform::current()->getURLLoaderMockFactory()->registerURL(url, WebURLRespo
nse(), ""); | 249 ResourceResponse response; |
| 250 response.setURL(url); |
| 251 response.setHTTPStatusCode(200); |
| 252 response.setHTTPHeaderField(HTTPNames::Cache_Control, "max-age=3600"); |
| 253 response.setHTTPHeaderField(HTTPNames::ETag, "1234567890"); |
| 254 Platform::current()->getURLLoaderMockFactory()->registerURL(url, WrappedReso
urceResponse(response), ""); |
| 222 | 255 |
| 223 ResourceFetcher* fetcher1 = ResourceFetcher::create(ResourceFetcherTestMockF
etchContext::create()); | 256 ResourceFetcher* fetcher1 = ResourceFetcher::create(ResourceFetcherTestMockF
etchContext::create()); |
| 224 ResourceRequest request1(url); | 257 ResourceRequest request1(url); |
| 225 request1.setHTTPHeaderField(HTTPNames::Cache_Control, "no-cache"); | 258 request1.setHTTPHeaderField(HTTPNames::Cache_Control, "no-cache"); |
| 226 FetchRequest fetchRequest1 = FetchRequest(request1, FetchInitiatorInfo()); | 259 FetchRequest fetchRequest1 = FetchRequest(request1, FetchInitiatorInfo()); |
| 227 Resource* resource1 = fetcher1->requestResource(fetchRequest1, TestResourceF
actory(Resource::Image)); | 260 Resource* resource1 = fetcher1->requestResource(fetchRequest1, TestResourceF
actory(Resource::Image)); |
| 228 ResourceResponse response; | 261 RequestSameResourceOnComplete client(resource1); |
| 229 response.setURL(url); | 262 resource1->addClient(&client); |
| 230 response.setHTTPStatusCode(200); | 263 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests(); |
| 231 response.setHTTPHeaderField(HTTPNames::Cache_Control, "max-age=3600"); | |
| 232 response.setHTTPHeaderField(HTTPNames::ETag, "1234567890"); | |
| 233 resource1->responseReceived(response, nullptr); | |
| 234 resource1->finish(); | |
| 235 | |
| 236 ResourceFetcherTestMockFetchContext* context = ResourceFetcherTestMockFetchC
ontext::create(); | |
| 237 context->setCachePolicy(CachePolicyRevalidate); | |
| 238 ResourceFetcher* fetcher2 = ResourceFetcher::create(context); | |
| 239 FetchRequest fetchRequest2(url, FetchInitiatorInfo()); | |
| 240 Resource* resource2 = fetcher2->requestResource(fetchRequest2, TestResourceF
actory(Resource::Image)); | |
| 241 EXPECT_EQ(resource1, resource2); | |
| 242 | |
| 243 // Tidily(?) shut down the ResourceLoader. | |
| 244 resource1->loader()->cancel(); | |
| 245 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url); | 264 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url); |
| 265 EXPECT_TRUE(client.notifyFinishedCalled()); |
| 266 resource1->removeClient(&client); |
| 267 memoryCache()->remove(resource1); |
| 246 } | 268 } |
| 247 | 269 |
| 248 TEST_F(ResourceFetcherTest, DontReuseMediaDataUrl) | 270 TEST_F(ResourceFetcherTest, DontReuseMediaDataUrl) |
| 249 { | 271 { |
| 250 ResourceFetcher* fetcher = ResourceFetcher::create(ResourceFetcherTestMockFe
tchContext::create()); | 272 ResourceFetcher* fetcher = ResourceFetcher::create(ResourceFetcherTestMockFe
tchContext::create()); |
| 251 ResourceRequest request(KURL(ParsedURLString, "data:text/html,foo")); | 273 ResourceRequest request(KURL(ParsedURLString, "data:text/html,foo")); |
| 252 ResourceLoaderOptions options; | 274 ResourceLoaderOptions options; |
| 253 options.dataBufferingPolicy = DoNotBufferData; | 275 options.dataBufferingPolicy = DoNotBufferData; |
| 254 FetchRequest fetchRequest = FetchRequest(request, FetchInitiatorTypeNames::i
nternal, options); | 276 FetchRequest fetchRequest = FetchRequest(request, FetchInitiatorTypeNames::i
nternal, options); |
| 255 Resource* resource1 = fetcher->requestResource(fetchRequest, TestResourceFac
tory(Resource::Media)); | 277 Resource* resource1 = fetcher->requestResource(fetchRequest, TestResourceFac
tory(Resource::Media)); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 ResourceFetcher* fetcher = ResourceFetcher::create(ResourceFetcherTestMockFe
tchContext::create()); | 316 ResourceFetcher* fetcher = ResourceFetcher::create(ResourceFetcherTestMockFe
tchContext::create()); |
| 295 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo()); | 317 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo()); |
| 296 Resource* resource = fetcher->requestResource(fetchRequest, TestResourceFact
ory(Resource::Raw)); | 318 Resource* resource = fetcher->requestResource(fetchRequest, TestResourceFact
ory(Resource::Raw)); |
| 297 ServeRequestsOnCompleteClient client; | 319 ServeRequestsOnCompleteClient client; |
| 298 resource->addClient(&client); | 320 resource->addClient(&client); |
| 299 resource->loader()->cancel(); | 321 resource->loader()->cancel(); |
| 300 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url); | 322 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url); |
| 301 } | 323 } |
| 302 | 324 |
| 303 } // namespace blink | 325 } // namespace blink |
| OLD | NEW |