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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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, NavigationTimingInfo) { |
| 148 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html"); |
| 149 ResourceResponse response; |
| 150 response.setURL(url); |
| 151 response.setHTTPStatusCode(200); |
| 152 |
| 153 ResourceFetcher* fetcher = ResourceFetcher::create( |
| 154 MockFetchContext::create(MockFetchContext::kShouldLoadNewResource)); |
| 155 ResourceRequest resourceRequest(url); |
| 156 resourceRequest.setFrameType(WebURLRequest::FrameTypeNested); |
| 157 resourceRequest.setRequestContext(WebURLRequest::RequestContextForm); |
| 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 |
| 167 ResourceTimingInfo* navigationTimingInfo = fetcher->getNavigationTimingInfo(); |
| 168 ASSERT_TRUE(navigationTimingInfo); |
| 169 long long encodedDataLength = 123; |
| 170 resource->loader()->didFinishLoading(0.0, encodedDataLength, 0); |
| 171 EXPECT_EQ(navigationTimingInfo->transferSize(), encodedDataLength); |
| 172 |
| 173 // When there are redirects. |
| 174 KURL redirectURL(ParsedURLString, "http://127.0.0.1:8000/redirect.html"); |
| 175 ResourceResponse redirectResponse; |
| 176 redirectResponse.setURL(redirectURL); |
| 177 redirectResponse.setHTTPStatusCode(200); |
| 178 long long redirectEncodedDataLength = 123; |
| 179 redirectResponse.setEncodedDataLength(redirectEncodedDataLength); |
| 180 ResourceRequest redirectResourceRequest(url); |
| 181 fetcher->willFollowRedirect(resource, redirectResourceRequest, |
| 182 redirectResponse); |
| 183 EXPECT_EQ(navigationTimingInfo->transferSize(), |
| 184 encodedDataLength + redirectEncodedDataLength); |
| 185 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url); |
| 186 } |
| 187 |
147 TEST_F(ResourceFetcherTest, VaryOnBack) { | 188 TEST_F(ResourceFetcherTest, VaryOnBack) { |
148 MockFetchContext* context = | 189 MockFetchContext* context = |
149 MockFetchContext::create(MockFetchContext::kShouldLoadNewResource); | 190 MockFetchContext::create(MockFetchContext::kShouldLoadNewResource); |
150 context->setCachePolicy(CachePolicyHistoryBuffer); | 191 context->setCachePolicy(CachePolicyHistoryBuffer); |
151 ResourceFetcher* fetcher = ResourceFetcher::create(context); | 192 ResourceFetcher* fetcher = ResourceFetcher::create(context); |
152 | 193 |
153 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html"); | 194 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html"); |
154 Resource* resource = RawResource::create(url, Resource::Raw); | 195 Resource* resource = RawResource::create(url, Resource::Raw); |
155 memoryCache()->add(resource); | 196 memoryCache()->add(resource); |
156 ResourceResponse response; | 197 ResourceResponse response; |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 FetchRequest fetchRequest2 = FetchRequest(url, FetchInitiatorInfo()); | 676 FetchRequest fetchRequest2 = FetchRequest(url, FetchInitiatorInfo()); |
636 Resource* newResource2 = ImageResource::fetch(fetchRequest2, fetcher2); | 677 Resource* newResource2 = ImageResource::fetch(fetchRequest2, fetcher2); |
637 Persistent<MockResourceClient> client2 = new MockResourceClient(newResource2); | 678 Persistent<MockResourceClient> client2 = new MockResourceClient(newResource2); |
638 EXPECT_EQ(resource, newResource2); | 679 EXPECT_EQ(resource, newResource2); |
639 EXPECT_FALSE(fetcher2->isFetching()); | 680 EXPECT_FALSE(fetcher2->isFetching()); |
640 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests(); | 681 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests(); |
641 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url); | 682 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url); |
642 } | 683 } |
643 | 684 |
644 } // namespace blink | 685 } // namespace blink |
OLD | NEW |