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

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

Issue 2714383003: Reduce FetchContext::getCachePolicy() callers (Closed)
Patch Set: rebase Created 3 years, 9 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 #include "platform/network/ResourceRequest.h" 50 #include "platform/network/ResourceRequest.h"
51 #include "platform/network/ResourceTimingInfo.h" 51 #include "platform/network/ResourceTimingInfo.h"
52 #include "platform/scheduler/test/fake_web_task_runner.h" 52 #include "platform/scheduler/test/fake_web_task_runner.h"
53 #include "platform/testing/TestingPlatformSupport.h" 53 #include "platform/testing/TestingPlatformSupport.h"
54 #include "platform/testing/URLTestHelpers.h" 54 #include "platform/testing/URLTestHelpers.h"
55 #include "platform/testing/UnitTestHelpers.h" 55 #include "platform/testing/UnitTestHelpers.h"
56 #include "platform/testing/weburl_loader_mock.h" 56 #include "platform/testing/weburl_loader_mock.h"
57 #include "platform/testing/weburl_loader_mock_factory_impl.h" 57 #include "platform/testing/weburl_loader_mock_factory_impl.h"
58 #include "platform/weborigin/KURL.h" 58 #include "platform/weborigin/KURL.h"
59 #include "public/platform/Platform.h" 59 #include "public/platform/Platform.h"
60 #include "public/platform/WebCachePolicy.h"
60 #include "public/platform/WebURLLoader.h" 61 #include "public/platform/WebURLLoader.h"
61 #include "public/platform/WebURLLoaderMockFactory.h" 62 #include "public/platform/WebURLLoaderMockFactory.h"
62 #include "public/platform/WebURLResponse.h" 63 #include "public/platform/WebURLResponse.h"
63 #include "testing/gtest/include/gtest/gtest.h" 64 #include "testing/gtest/include/gtest/gtest.h"
64 #include "wtf/Allocator.h" 65 #include "wtf/Allocator.h"
65 #include "wtf/PtrUtil.h" 66 #include "wtf/PtrUtil.h"
66 #include "wtf/Vector.h" 67 #include "wtf/Vector.h"
67 68
68 namespace blink { 69 namespace blink {
69 70
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 redirectResponse.setHTTPStatusCode(200); 201 redirectResponse.setHTTPStatusCode(200);
201 long long redirectEncodedDataLength = 123; 202 long long redirectEncodedDataLength = 123;
202 redirectResponse.setEncodedDataLength(redirectEncodedDataLength); 203 redirectResponse.setEncodedDataLength(redirectEncodedDataLength);
203 ResourceRequest redirectResourceRequest(url); 204 ResourceRequest redirectResourceRequest(url);
204 fetcher->recordResourceTimingOnRedirect(resource, redirectResponse, false); 205 fetcher->recordResourceTimingOnRedirect(resource, redirectResponse, false);
205 EXPECT_EQ(navigationTimingInfo->transferSize(), 206 EXPECT_EQ(navigationTimingInfo->transferSize(),
206 encodedDataLength + redirectEncodedDataLength); 207 encodedDataLength + redirectEncodedDataLength);
207 } 208 }
208 209
209 TEST_F(ResourceFetcherTest, VaryOnBack) { 210 TEST_F(ResourceFetcherTest, VaryOnBack) {
210 context()->setCachePolicy(CachePolicyHistoryBuffer);
211 ResourceFetcher* fetcher = ResourceFetcher::create(context()); 211 ResourceFetcher* fetcher = ResourceFetcher::create(context());
212 212
213 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html"); 213 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html");
214 Resource* resource = RawResource::create(url, Resource::Raw); 214 Resource* resource = RawResource::create(url, Resource::Raw);
215 memoryCache()->add(resource); 215 memoryCache()->add(resource);
216 ResourceResponse response; 216 ResourceResponse response;
217 response.setURL(url); 217 response.setURL(url);
218 response.setHTTPStatusCode(200); 218 response.setHTTPStatusCode(200);
219 response.setHTTPHeaderField(HTTPNames::Cache_Control, "max-age=3600"); 219 response.setHTTPHeaderField(HTTPNames::Cache_Control, "max-age=3600");
220 response.setHTTPHeaderField(HTTPNames::Vary, "*"); 220 response.setHTTPHeaderField(HTTPNames::Vary, "*");
221 resource->responseReceived(response, nullptr); 221 resource->responseReceived(response, nullptr);
222 resource->finish(); 222 resource->finish();
223 ASSERT_TRUE(resource->mustReloadDueToVaryHeader(url)); 223 ASSERT_TRUE(resource->mustReloadDueToVaryHeader(url));
224 224
225 ResourceRequest resourceRequest(url); 225 ResourceRequest resourceRequest(url);
226 resourceRequest.setCachePolicy(WebCachePolicy::ReturnCacheDataElseLoad);
226 resourceRequest.setRequestContext(WebURLRequest::RequestContextInternal); 227 resourceRequest.setRequestContext(WebURLRequest::RequestContextInternal);
227 FetchRequest fetchRequest = 228 FetchRequest fetchRequest =
228 FetchRequest(resourceRequest, FetchInitiatorInfo()); 229 FetchRequest(resourceRequest, FetchInitiatorInfo());
229 Resource* newResource = RawResource::fetch(fetchRequest, fetcher); 230 Resource* newResource = RawResource::fetch(fetchRequest, fetcher);
230 EXPECT_EQ(resource, newResource); 231 EXPECT_EQ(resource, newResource);
231 } 232 }
232 233
233 TEST_F(ResourceFetcherTest, VaryResource) { 234 TEST_F(ResourceFetcherTest, VaryResource) {
234 ResourceFetcher* fetcher = ResourceFetcher::create(context()); 235 ResourceFetcher* fetcher = ResourceFetcher::create(context());
235 236
(...skipping 22 matching lines...) Expand all
258 USING_GARBAGE_COLLECTED_MIXIN(RequestSameResourceOnComplete); 259 USING_GARBAGE_COLLECTED_MIXIN(RequestSameResourceOnComplete);
259 260
260 public: 261 public:
261 explicit RequestSameResourceOnComplete(Resource* resource) 262 explicit RequestSameResourceOnComplete(Resource* resource)
262 : m_resource(resource), m_notifyFinishedCalled(false) {} 263 : m_resource(resource), m_notifyFinishedCalled(false) {}
263 264
264 void notifyFinished(Resource* resource) override { 265 void notifyFinished(Resource* resource) override {
265 EXPECT_EQ(m_resource, resource); 266 EXPECT_EQ(m_resource, resource);
266 MockFetchContext* context = 267 MockFetchContext* context =
267 MockFetchContext::create(MockFetchContext::kShouldLoadNewResource); 268 MockFetchContext::create(MockFetchContext::kShouldLoadNewResource);
268 context->setCachePolicy(CachePolicyRevalidate);
269 ResourceFetcher* fetcher2 = ResourceFetcher::create(context); 269 ResourceFetcher* fetcher2 = ResourceFetcher::create(context);
270 FetchRequest fetchRequest2(m_resource->url(), FetchInitiatorInfo()); 270 FetchRequest fetchRequest2(m_resource->url(), FetchInitiatorInfo());
271 fetchRequest2.mutableResourceRequest().setCachePolicy(
272 WebCachePolicy::ValidatingCacheData);
271 Resource* resource2 = MockResource::fetch(fetchRequest2, fetcher2); 273 Resource* resource2 = MockResource::fetch(fetchRequest2, fetcher2);
272 EXPECT_EQ(m_resource, resource2); 274 EXPECT_EQ(m_resource, resource2);
273 m_notifyFinishedCalled = true; 275 m_notifyFinishedCalled = true;
274 } 276 }
275 bool notifyFinishedCalled() const { return m_notifyFinishedCalled; } 277 bool notifyFinishedCalled() const { return m_notifyFinishedCalled; }
276 278
277 DEFINE_INLINE_TRACE() { 279 DEFINE_INLINE_TRACE() {
278 visitor->trace(m_resource); 280 visitor->trace(m_resource);
279 RawResourceClient::trace(visitor); 281 RawResourceClient::trace(visitor);
280 } 282 }
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 // Resource created by parser on the second fetcher 655 // Resource created by parser on the second fetcher
654 FetchRequest fetchRequest2 = FetchRequest(url, FetchInitiatorInfo()); 656 FetchRequest fetchRequest2 = FetchRequest(url, FetchInitiatorInfo());
655 Resource* newResource2 = MockResource::fetch(fetchRequest2, fetcher2); 657 Resource* newResource2 = MockResource::fetch(fetchRequest2, fetcher2);
656 Persistent<MockResourceClient> client2 = new MockResourceClient(newResource2); 658 Persistent<MockResourceClient> client2 = new MockResourceClient(newResource2);
657 EXPECT_NE(resource, newResource2); 659 EXPECT_NE(resource, newResource2);
658 EXPECT_FALSE(fetcher2->isFetching()); 660 EXPECT_FALSE(fetcher2->isFetching());
659 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests(); 661 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests();
660 } 662 }
661 663
662 } // namespace blink 664 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698