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

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

Issue 2511313002: transferSize implementation (Closed)
Patch Set: Got rid of DCHECKS cause they don't stand any more 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 FetchRequest fetchRequest =
159 FetchRequest(resourceRequest, FetchInitiatorInfo());
160 Platform::current()->getURLLoaderMockFactory()->registerURL(
161 url, WebURLResponse(), "");
162 Resource* resource =
163 RawResource::fetchMainResource(fetchRequest, fetcher, SubstituteData());
164 resource->responseReceived(response, nullptr);
165 EXPECT_EQ(resource->getType(), Resource::MainResource);
166 ResourceTimingInfo* mainResourceTimingInfo =
167 fetcher->getMainResourceTimingInfo();
168 ASSERT_TRUE(mainResourceTimingInfo);
169 fetcher->didFinishLoading(resource, 0, ResourceFetcher::DidFinishLoading);
170 EXPECT_EQ(mainResourceTimingInfo->transferSize(), encodedDataLength);
171
172 // When there are redirects.
173 KURL redirectURL(ParsedURLString, "http://127.0.0.1:8000/redirect.html");
174 ResourceResponse redirectResponse;
175 redirectResponse.setURL(redirectURL);
176 redirectResponse.setHTTPStatusCode(200);
177 long long redirectEncodedDataLength = 123;
178 redirectResponse.setEncodedDataLength(redirectEncodedDataLength);
179 ResourceRequest redirectResourceRequest(url);
180 fetcher->willFollowRedirect(resource, redirectResourceRequest,
181 redirectResponse);
182 EXPECT_EQ(mainResourceTimingInfo->transferSize(),
183 encodedDataLength + redirectEncodedDataLength);
184 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url);
185 }
186
147 TEST_F(ResourceFetcherTest, VaryOnBack) { 187 TEST_F(ResourceFetcherTest, VaryOnBack) {
148 MockFetchContext* context = 188 MockFetchContext* context =
149 MockFetchContext::create(MockFetchContext::kShouldLoadNewResource); 189 MockFetchContext::create(MockFetchContext::kShouldLoadNewResource);
150 context->setCachePolicy(CachePolicyHistoryBuffer); 190 context->setCachePolicy(CachePolicyHistoryBuffer);
151 ResourceFetcher* fetcher = ResourceFetcher::create(context); 191 ResourceFetcher* fetcher = ResourceFetcher::create(context);
152 192
153 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html"); 193 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html");
154 Resource* resource = RawResource::create(url, Resource::Raw); 194 Resource* resource = RawResource::create(url, Resource::Raw);
155 memoryCache()->add(resource); 195 memoryCache()->add(resource);
156 ResourceResponse response; 196 ResourceResponse response;
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 FetchRequest fetchRequest2 = FetchRequest(url, FetchInitiatorInfo()); 675 FetchRequest fetchRequest2 = FetchRequest(url, FetchInitiatorInfo());
636 Resource* newResource2 = ImageResource::fetch(fetchRequest2, fetcher2); 676 Resource* newResource2 = ImageResource::fetch(fetchRequest2, fetcher2);
637 Persistent<MockResourceClient> client2 = new MockResourceClient(newResource2); 677 Persistent<MockResourceClient> client2 = new MockResourceClient(newResource2);
638 EXPECT_EQ(resource, newResource2); 678 EXPECT_EQ(resource, newResource2);
639 EXPECT_FALSE(fetcher2->isFetching()); 679 EXPECT_FALSE(fetcher2->isFetching());
640 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests(); 680 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests();
641 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url); 681 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url);
642 } 682 }
643 683
644 } // namespace blink 684 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698