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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 }; | 114 }; |
| 115 | 115 |
| 116 TEST_F(ResourceFetcherTest, StartLoadAfterFrameDetach) | 116 TEST_F(ResourceFetcherTest, StartLoadAfterFrameDetach) |
| 117 { | 117 { |
| 118 KURL secureURL(ParsedURLString, "https://secureorigin.test/image.png"); | 118 KURL secureURL(ParsedURLString, "https://secureorigin.test/image.png"); |
| 119 // Try to request a url. The request should fail, no resource should be retu rned, | 119 // Try to request a url. The request should fail, no resource should be retu rned, |
| 120 // and no resource should be present in the cache. | 120 // and no resource should be present in the cache. |
| 121 ResourceFetcher* fetcher = ResourceFetcher::create(nullptr); | 121 ResourceFetcher* fetcher = ResourceFetcher::create(nullptr); |
| 122 FetchRequest fetchRequest = FetchRequest(ResourceRequest(secureURL), FetchIn itiatorInfo()); | 122 FetchRequest fetchRequest = FetchRequest(ResourceRequest(secureURL), FetchIn itiatorInfo()); |
| 123 Resource* resource = fetcher->requestResource(fetchRequest, TestResourceFact ory()); | 123 Resource* resource = fetcher->requestResource(fetchRequest, TestResourceFact ory()); |
| 124 EXPECT_EQ(resource, static_cast<Resource*>(nullptr)); | 124 EXPECT_FALSE(resource); |
| 125 EXPECT_EQ(memoryCache()->resourceForURL(secureURL), static_cast<Resource*>(n ullptr)); | 125 EXPECT_FALSE(memoryCache()->resourceForURL(secureURL)); |
| 126 | 126 |
| 127 // Start by calling startLoad() directly, rather than via requestResource(). | 127 // Start by calling startLoad() directly, rather than via requestResource(). |
| 128 // This shouldn't crash. | 128 // This shouldn't crash. |
| 129 fetcher->startLoad(Resource::create(secureURL, Resource::Raw)); | 129 fetcher->startLoad(Resource::create(secureURL, Resource::Raw)); |
| 130 } | 130 } |
| 131 | 131 |
| 132 TEST_F(ResourceFetcherTest, UseExistingResource) | 132 TEST_F(ResourceFetcherTest, UseExistingResource) |
| 133 { | 133 { |
| 134 ResourceFetcher* fetcher = ResourceFetcher::create(ResourceFetcherTestMockFe tchContext::create()); | 134 ResourceFetcher* fetcher = ResourceFetcher::create(ResourceFetcherTestMockFe tchContext::create()); |
| 135 | 135 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 154 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html"); | 154 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html"); |
| 155 Resource* resource = Resource::create(url, Resource::Raw); | 155 Resource* resource = Resource::create(url, Resource::Raw); |
| 156 memoryCache()->add(resource); | 156 memoryCache()->add(resource); |
| 157 ResourceResponse response; | 157 ResourceResponse response; |
| 158 response.setURL(url); | 158 response.setURL(url); |
| 159 response.setHTTPStatusCode(200); | 159 response.setHTTPStatusCode(200); |
| 160 response.setHTTPHeaderField(HTTPNames::Cache_Control, "max-age=3600"); | 160 response.setHTTPHeaderField(HTTPNames::Cache_Control, "max-age=3600"); |
| 161 response.setHTTPHeaderField(HTTPNames::Vary, "*"); | 161 response.setHTTPHeaderField(HTTPNames::Vary, "*"); |
| 162 resource->responseReceived(response, nullptr); | 162 resource->responseReceived(response, nullptr); |
| 163 resource->finish(); | 163 resource->finish(); |
| 164 ASSERT_TRUE(resource->hasVaryHeader()); | 164 ASSERT_TRUE(resource->hasVaryHeader()); |
|
yhirano
2016/09/09 07:34:47
expect?
hiroshige
2016/09/09 08:11:35
I leave this ASSERT because Vary-related tests wou
| |
| 165 | 165 |
| 166 ResourceFetcher* fetcher = ResourceFetcher::create(ResourceFetcherTestMockFe tchContext::create()); | 166 ResourceFetcher* fetcher = ResourceFetcher::create(ResourceFetcherTestMockFe tchContext::create()); |
| 167 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo()); | 167 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo()); |
| 168 Platform::current()->getURLLoaderMockFactory()->registerURL(url, WebURLRespo nse(), ""); | 168 Platform::current()->getURLLoaderMockFactory()->registerURL(url, WebURLRespo nse(), ""); |
| 169 Resource* newResource = fetcher->requestResource(fetchRequest, TestResourceF actory()); | 169 Resource* newResource = fetcher->requestResource(fetchRequest, TestResourceF actory()); |
| 170 EXPECT_NE(resource, newResource); | 170 EXPECT_NE(resource, newResource); |
| 171 newResource->loader()->cancel(); | 171 newResource->loader()->cancel(); |
| 172 memoryCache()->remove(newResource); | 172 memoryCache()->remove(newResource); |
| 173 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url); | 173 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url); |
| 174 | 174 |
| 175 memoryCache()->remove(resource); | 175 memoryCache()->remove(resource); |
| 176 } | 176 } |
| 177 | 177 |
| 178 TEST_F(ResourceFetcherTest, VaryOnBack) | 178 TEST_F(ResourceFetcherTest, VaryOnBack) |
| 179 { | 179 { |
| 180 ResourceFetcherTestMockFetchContext* context = ResourceFetcherTestMockFetchC ontext::create(); | 180 ResourceFetcherTestMockFetchContext* context = ResourceFetcherTestMockFetchC ontext::create(); |
| 181 context->setCachePolicy(CachePolicyHistoryBuffer); | 181 context->setCachePolicy(CachePolicyHistoryBuffer); |
| 182 ResourceFetcher* fetcher = ResourceFetcher::create(context); | 182 ResourceFetcher* fetcher = ResourceFetcher::create(context); |
| 183 | 183 |
| 184 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html"); | 184 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html"); |
| 185 Resource* resource = Resource::create(url, Resource::Raw); | 185 Resource* resource = Resource::create(url, Resource::Raw); |
| 186 memoryCache()->add(resource); | 186 memoryCache()->add(resource); |
| 187 ResourceResponse response; | 187 ResourceResponse response; |
| 188 response.setURL(url); | 188 response.setURL(url); |
| 189 response.setHTTPStatusCode(200); | 189 response.setHTTPStatusCode(200); |
| 190 response.setHTTPHeaderField(HTTPNames::Cache_Control, "max-age=3600"); | 190 response.setHTTPHeaderField(HTTPNames::Cache_Control, "max-age=3600"); |
| 191 response.setHTTPHeaderField(HTTPNames::Vary, "*"); | 191 response.setHTTPHeaderField(HTTPNames::Vary, "*"); |
| 192 resource->responseReceived(response, nullptr); | 192 resource->responseReceived(response, nullptr); |
| 193 resource->finish(); | 193 resource->finish(); |
| 194 ASSERT_TRUE(resource->hasVaryHeader()); | 194 ASSERT_TRUE(resource->hasVaryHeader()); |
|
yhirano
2016/09/09 07:34:47
ditto
hiroshige
2016/09/09 08:11:35
ditto.
| |
| 195 | 195 |
| 196 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo()); | 196 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo()); |
| 197 Resource* newResource = fetcher->requestResource(fetchRequest, TestResourceF actory()); | 197 Resource* newResource = fetcher->requestResource(fetchRequest, TestResourceF actory()); |
| 198 EXPECT_EQ(resource, newResource); | 198 EXPECT_EQ(resource, newResource); |
| 199 | 199 |
| 200 memoryCache()->remove(newResource); | 200 memoryCache()->remove(newResource); |
| 201 } | 201 } |
| 202 | 202 |
| 203 TEST_F(ResourceFetcherTest, VaryImage) | 203 TEST_F(ResourceFetcherTest, VaryImage) |
| 204 { | 204 { |
| 205 ResourceFetcher* fetcher = ResourceFetcher::create(ResourceFetcherTestMockFe tchContext::create()); | 205 ResourceFetcher* fetcher = ResourceFetcher::create(ResourceFetcherTestMockFe tchContext::create()); |
| 206 | 206 |
| 207 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html"); | 207 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html"); |
| 208 ResourceResponse response; | 208 ResourceResponse response; |
| 209 response.setURL(url); | 209 response.setURL(url); |
| 210 response.setHTTPStatusCode(200); | 210 response.setHTTPStatusCode(200); |
| 211 response.setHTTPHeaderField(HTTPNames::Cache_Control, "max-age=3600"); | 211 response.setHTTPHeaderField(HTTPNames::Cache_Control, "max-age=3600"); |
| 212 response.setHTTPHeaderField(HTTPNames::Vary, "*"); | 212 response.setHTTPHeaderField(HTTPNames::Vary, "*"); |
| 213 URLTestHelpers::registerMockedURLLoadWithCustomResponse(url, testImageFilena me, WebString::fromUTF8(""), WrappedResourceResponse(response)); | 213 URLTestHelpers::registerMockedURLLoadWithCustomResponse(url, testImageFilena me, WebString::fromUTF8(""), WrappedResourceResponse(response)); |
| 214 | 214 |
| 215 FetchRequest fetchRequestOriginal = FetchRequest(url, FetchInitiatorInfo()); | 215 FetchRequest fetchRequestOriginal = FetchRequest(url, FetchInitiatorInfo()); |
| 216 Resource* resource = fetcher->requestResource(fetchRequestOriginal, TestReso urceFactory(Resource::Image)); | 216 Resource* resource = fetcher->requestResource(fetchRequestOriginal, TestReso urceFactory(Resource::Image)); |
| 217 ASSERT_TRUE(resource); | 217 ASSERT_TRUE(resource); |
| 218 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests(); | 218 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequests(); |
| 219 ASSERT_TRUE(resource->hasVaryHeader()); | 219 ASSERT_TRUE(resource->hasVaryHeader()); |
|
yhirano
2016/09/09 07:34:47
ditto
hiroshige
2016/09/09 08:11:35
ditto.
| |
| 220 | 220 |
| 221 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo()); | 221 FetchRequest fetchRequest = FetchRequest(url, FetchInitiatorInfo()); |
| 222 Resource* newResource = fetcher->requestResource(fetchRequest, TestResourceF actory(Resource::Image)); | 222 Resource* newResource = fetcher->requestResource(fetchRequest, TestResourceF actory(Resource::Image)); |
| 223 EXPECT_EQ(resource, newResource); | 223 EXPECT_EQ(resource, newResource); |
| 224 | 224 |
| 225 memoryCache()->remove(newResource); | 225 memoryCache()->remove(newResource); |
| 226 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url); | 226 Platform::current()->getURLLoaderMockFactory()->unregisterURL(url); |
| 227 } | 227 } |
| 228 | 228 |
| 229 class RequestSameResourceOnComplete : public GarbageCollectedFinalized<RequestSa meResourceOnComplete>, public RawResourceClient { | 229 class RequestSameResourceOnComplete : public GarbageCollectedFinalized<RequestSa meResourceOnComplete>, public RawResourceClient { |
| 230 USING_GARBAGE_COLLECTED_MIXIN(RequestSameResourceOnComplete); | 230 USING_GARBAGE_COLLECTED_MIXIN(RequestSameResourceOnComplete); |
| 231 public: | 231 public: |
| 232 explicit RequestSameResourceOnComplete(Resource* resource) | 232 explicit RequestSameResourceOnComplete(Resource* resource) |
| 233 : m_resource(resource) | 233 : m_resource(resource) |
| 234 , m_notifyFinishedCalled(false) | 234 , m_notifyFinishedCalled(false) |
| 235 { | 235 { |
| 236 } | 236 } |
| 237 | 237 |
| 238 void notifyFinished(Resource* resource) override | 238 void notifyFinished(Resource* resource) override |
| 239 { | 239 { |
| 240 ASSERT_EQ(m_resource, resource); | 240 ASSERT_EQ(m_resource, resource); |
|
yhirano
2016/09/09 07:34:47
expect?
hiroshige
2016/09/09 08:11:35
Done.
| |
| 241 ResourceFetcherTestMockFetchContext* context = ResourceFetcherTestMockFe tchContext::create(); | 241 ResourceFetcherTestMockFetchContext* context = ResourceFetcherTestMockFe tchContext::create(); |
| 242 context->setCachePolicy(CachePolicyRevalidate); | 242 context->setCachePolicy(CachePolicyRevalidate); |
| 243 ResourceFetcher* fetcher2 = ResourceFetcher::create(context); | 243 ResourceFetcher* fetcher2 = ResourceFetcher::create(context); |
| 244 FetchRequest fetchRequest2(m_resource->url(), FetchInitiatorInfo()); | 244 FetchRequest fetchRequest2(m_resource->url(), FetchInitiatorInfo()); |
| 245 Resource* resource2 = fetcher2->requestResource(fetchRequest2, TestResou rceFactory(Resource::Image)); | 245 Resource* resource2 = fetcher2->requestResource(fetchRequest2, TestResou rceFactory(Resource::Image)); |
| 246 EXPECT_EQ(m_resource, resource2); | 246 EXPECT_EQ(m_resource, resource2); |
| 247 m_notifyFinishedCalled = true; | 247 m_notifyFinishedCalled = true; |
| 248 } | 248 } |
| 249 bool notifyFinishedCalled() const { return m_notifyFinishedCalled; } | 249 bool notifyFinishedCalled() const { return m_notifyFinishedCalled; } |
| 250 | 250 |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 510 FetchRequest request(url, FetchInitiatorInfo()); | 510 FetchRequest request(url, FetchInitiatorInfo()); |
| 511 request.makeSynchronous(); | 511 request.makeSynchronous(); |
| 512 Resource* resource = fetcher->requestResource(request, TestResourceFactory() ); | 512 Resource* resource = fetcher->requestResource(request, TestResourceFactory() ); |
| 513 EXPECT_TRUE(resource->isLoaded()); | 513 EXPECT_TRUE(resource->isLoaded()); |
| 514 EXPECT_EQ(ResourceLoadPriorityHighest, resource->resourceRequest().priority( )); | 514 EXPECT_EQ(ResourceLoadPriorityHighest, resource->resourceRequest().priority( )); |
| 515 | 515 |
| 516 memoryCache()->remove(resource); | 516 memoryCache()->remove(resource); |
| 517 } | 517 } |
| 518 | 518 |
| 519 } // namespace blink | 519 } // namespace blink |
| OLD | NEW |