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

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

Issue 2511313002: transferSize implementation (Closed)
Patch Set: addressed comments Created 4 years 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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 url, WebURLResponse(), ""); 137 url, WebURLResponse(), "");
138 Resource* newResource = RawResource::fetch(fetchRequest, fetcher); 138 Resource* newResource = RawResource::fetch(fetchRequest, fetcher);
139 EXPECT_NE(resource, newResource); 139 EXPECT_NE(resource, newResource);
140 newResource->loader()->cancel(); 140 newResource->loader()->cancel();
141 memoryCache()->remove(newResource); 141 memoryCache()->remove(newResource);
142 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url); 142 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url);
143 143
144 memoryCache()->remove(resource); 144 memoryCache()->remove(resource);
145 } 145 }
146 146
147 TEST_F(ResourceFetcherTest, MainResourceTimingInfo) {
148 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html");
149 ResourceResponse response;
150 response.setURL(url);
151 response.setHTTPStatusCode(200);
152 long long encodedDataLength = 123;
153 response.setEncodedDataLength(encodedDataLength);
154
155 ResourceFetcher* fetcher = ResourceFetcher::create(
156 MockFetchContext::create(MockFetchContext::kShouldLoadNewResource));
157 ResourceRequest resourceRequest(url);
158 resourceRequest.setFrameType(WebURLRequest::FrameTypeNested);
159 resourceRequest.setRequestContext(WebURLRequest::RequestContextForm);
160 FetchRequest fetchRequest =
161 FetchRequest(resourceRequest, FetchInitiatorInfo());
162 Platform::current()->getURLLoaderMockFactory()->registerURL(
163 url, WebURLResponse(), "");
164 Resource* resource =
165 RawResource::fetchMainResource(fetchRequest, fetcher, SubstituteData());
166 resource->responseReceived(response, nullptr);
167 EXPECT_EQ(resource->getType(), Resource::MainResource);
168 ResourceTimingInfo* mainResourceTimingInfo =
169 fetcher->getMainResourceTimingInfo();
170 ASSERT_TRUE(mainResourceTimingInfo);
171 fetcher->didFinishLoading(resource, 0, ResourceFetcher::DidFinishLoading);
172 EXPECT_EQ(mainResourceTimingInfo->transferSize(), encodedDataLength);
173
174 // When an iframe is loaded.
175 Resource* iframeResource =
176 RawResource::create(ResourceRequest(), Resource::MainResource);
177 iframeResource->setIdentifier(resource->identifier() + 1);
178 ResourceResponse iframeResponse;
179 long long iframeEncodedDataLength = 123;
180 iframeResponse.setEncodedDataLength(iframeEncodedDataLength);
181 iframeResource->responseReceived(iframeResponse, nullptr);
182 fetcher->didFinishLoading(iframeResource, 0,
183 ResourceFetcher::DidFinishLoading);
184 EXPECT_EQ(mainResourceTimingInfo->transferSize(), encodedDataLength);
185
186 // When there are redirects.
187 KURL redirectURL(ParsedURLString, "http://127.0.0.1:8000/redirect.html");
188 ResourceResponse redirectResponse;
189 redirectResponse.setURL(redirectURL);
190 redirectResponse.setHTTPStatusCode(200);
191 long long redirectEncodedDataLength = 123;
192 redirectResponse.setEncodedDataLength(redirectEncodedDataLength);
193 ResourceRequest redirectResourceRequest(url);
194 fetcher->willFollowRedirect(resource, redirectResourceRequest,
195 redirectResponse);
196 EXPECT_EQ(mainResourceTimingInfo->transferSize(),
197 encodedDataLength + redirectEncodedDataLength);
198 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url);
199 }
200
147 TEST_F(ResourceFetcherTest, VaryOnBack) { 201 TEST_F(ResourceFetcherTest, VaryOnBack) {
148 MockFetchContext* context = 202 MockFetchContext* context =
149 MockFetchContext::create(MockFetchContext::kShouldLoadNewResource); 203 MockFetchContext::create(MockFetchContext::kShouldLoadNewResource);
150 context->setCachePolicy(CachePolicyHistoryBuffer); 204 context->setCachePolicy(CachePolicyHistoryBuffer);
151 ResourceFetcher* fetcher = ResourceFetcher::create(context); 205 ResourceFetcher* fetcher = ResourceFetcher::create(context);
152 206
153 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html"); 207 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html");
154 Resource* resource = RawResource::create(url, Resource::Raw); 208 Resource* resource = RawResource::create(url, Resource::Raw);
155 memoryCache()->add(resource); 209 memoryCache()->add(resource);
156 ResourceResponse response; 210 ResourceResponse response;
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 FetchRequest fetchRequest2 = FetchRequest(url, FetchInitiatorInfo()); 689 FetchRequest fetchRequest2 = FetchRequest(url, FetchInitiatorInfo());
636 Resource* newResource2 = ImageResource::fetch(fetchRequest2, fetcher2); 690 Resource* newResource2 = ImageResource::fetch(fetchRequest2, fetcher2);
637 Persistent<MockResourceClient> client2 = new MockResourceClient(newResource2); 691 Persistent<MockResourceClient> client2 = new MockResourceClient(newResource2);
638 EXPECT_EQ(resource, newResource2); 692 EXPECT_EQ(resource, newResource2);
639 EXPECT_FALSE(fetcher2->isFetching()); 693 EXPECT_FALSE(fetcher2->isFetching());
640 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests(); 694 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests();
641 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url); 695 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url);
642 } 696 }
643 697
644 } // namespace blink 698 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698