Chromium Code Reviews| 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 RequestSameResourceOnComplete(Resource* resource) | |
|
yhirano
2016/05/02 12:38:45
+explicit
Nate Chapin
2016/05/02 20:07:37
Done.
| |
| 221 : m_resource(resource) | |
| 222 { | |
| 223 } | |
| 224 | |
| 225 void notifyFinished(Resource* resource) override | |
| 226 { | |
| 227 ASSERT_EQ(m_resource, resource); | |
| 228 ResourceFetcherTestMockFetchContext* context = ResourceFetcherTestMockFe tchContext::create(); | |
| 229 context->setCachePolicy(CachePolicyRevalidate); | |
| 230 ResourceFetcher* fetcher2 = ResourceFetcher::create(context); | |
| 231 FetchRequest fetchRequest2(m_resource->url(), FetchInitiatorInfo()); | |
| 232 Resource* resource2 = fetcher2->requestResource(fetchRequest2, TestResou rceFactory(Resource::Image)); | |
| 233 EXPECT_EQ(m_resource, resource2); | |
| 234 } | |
| 235 String debugName() const override { return "RequestSameResourceOnComplete"; } | |
| 236 | |
| 237 private: | |
| 238 Persistent<Resource> m_resource; | |
| 239 }; | |
| 240 | |
| 241 TEST_F(ResourceFetcherTest, RevalidateWhileFinishingLoading) | |
| 219 { | 242 { |
| 220 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html"); | 243 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html"); |
| 221 Platform::current()->getURLLoaderMockFactory()->registerURL(url, WebURLRespo nse(), ""); | 244 ResourceResponse response; |
| 245 response.setURL(url); | |
| 246 response.setHTTPStatusCode(200); | |
| 247 response.setHTTPHeaderField(HTTPNames::Cache_Control, "max-age=3600"); | |
| 248 response.setHTTPHeaderField(HTTPNames::ETag, "1234567890"); | |
| 249 Platform::current()->getURLLoaderMockFactory()->registerURL(url, WrappedReso urceResponse(response), ""); | |
| 222 | 250 |
| 223 ResourceFetcher* fetcher1 = ResourceFetcher::create(ResourceFetcherTestMockF etchContext::create()); | 251 ResourceFetcher* fetcher1 = ResourceFetcher::create(ResourceFetcherTestMockF etchContext::create()); |
| 224 ResourceRequest request1(url); | 252 ResourceRequest request1(url); |
| 225 request1.setHTTPHeaderField(HTTPNames::Cache_Control, "no-cache"); | 253 request1.setHTTPHeaderField(HTTPNames::Cache_Control, "no-cache"); |
| 226 FetchRequest fetchRequest1 = FetchRequest(request1, FetchInitiatorInfo()); | 254 FetchRequest fetchRequest1 = FetchRequest(request1, FetchInitiatorInfo()); |
| 227 Resource* resource1 = fetcher1->requestResource(fetchRequest1, TestResourceF actory(Resource::Image)); | 255 Resource* resource1 = fetcher1->requestResource(fetchRequest1, TestResourceF actory(Resource::Image)); |
| 228 ResourceResponse response; | 256 RequestSameResourceOnComplete client(resource1); |
| 229 response.setURL(url); | 257 resource1->addClient(&client); |
| 230 response.setHTTPStatusCode(200); | 258 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests(); |
|
yhirano
2016/05/02 12:38:45
Can you verify that RequestSameResourceOnComplete:
yhirano
2016/05/02 12:38:45
+resource1->removeClient(&client);
Nate Chapin
2016/05/02 20:07:37
Done.
Nate Chapin
2016/05/02 20:07:37
Done.
| |
| 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); | 259 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url); |
| 260 memoryCache()->remove(resource1); | |
| 246 } | 261 } |
| 247 | 262 |
| 248 TEST_F(ResourceFetcherTest, DontReuseMediaDataUrl) | 263 TEST_F(ResourceFetcherTest, DontReuseMediaDataUrl) |
| 249 { | 264 { |
| 250 ResourceFetcher* fetcher = ResourceFetcher::create(ResourceFetcherTestMockFe tchContext::create()); | 265 ResourceFetcher* fetcher = ResourceFetcher::create(ResourceFetcherTestMockFe tchContext::create()); |
| 251 ResourceRequest request(KURL(ParsedURLString, "data:text/html,foo")); | 266 ResourceRequest request(KURL(ParsedURLString, "data:text/html,foo")); |
| 252 ResourceLoaderOptions options; | 267 ResourceLoaderOptions options; |
| 253 options.dataBufferingPolicy = DoNotBufferData; | 268 options.dataBufferingPolicy = DoNotBufferData; |
| 254 FetchRequest fetchRequest = FetchRequest(request, FetchInitiatorTypeNames::i nternal, options); | 269 FetchRequest fetchRequest = FetchRequest(request, FetchInitiatorTypeNames::i nternal, options); |
| 255 Resource* resource1 = fetcher->requestResource(fetchRequest, TestResourceFac tory(Resource::Media)); | 270 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()); | 309 ResourceFetcher* fetcher = ResourceFetcher::create(ResourceFetcherTestMockFe tchContext::create()); |
| 295 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo()); | 310 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo()); |
| 296 Resource* resource = fetcher->requestResource(fetchRequest, TestResourceFact ory(Resource::Raw)); | 311 Resource* resource = fetcher->requestResource(fetchRequest, TestResourceFact ory(Resource::Raw)); |
| 297 ServeRequestsOnCompleteClient client; | 312 ServeRequestsOnCompleteClient client; |
| 298 resource->addClient(&client); | 313 resource->addClient(&client); |
| 299 resource->loader()->cancel(); | 314 resource->loader()->cancel(); |
| 300 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url); | 315 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url); |
| 301 } | 316 } |
| 302 | 317 |
| 303 } // namespace blink | 318 } // namespace blink |
| OLD | NEW |