| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/fetch/Resource.h" | 5 #include "core/fetch/Resource.h" |
| 6 | 6 |
| 7 #include "core/fetch/ResourcePtr.h" | |
| 8 #include "platform/network/ResourceRequest.h" | 7 #include "platform/network/ResourceRequest.h" |
| 9 #include "platform/network/ResourceResponse.h" | 8 #include "platform/network/ResourceResponse.h" |
| 10 #include "platform/testing/TestingPlatformSupport.h" | 9 #include "platform/testing/TestingPlatformSupport.h" |
| 11 #include "platform/testing/URLTestHelpers.h" | 10 #include "platform/testing/URLTestHelpers.h" |
| 12 #include "public/platform/Platform.h" | 11 #include "public/platform/Platform.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "wtf/Vector.h" | 13 #include "wtf/Vector.h" |
| 15 | 14 |
| 16 namespace blink { | 15 namespace blink { |
| 17 | 16 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 41 { | 40 { |
| 42 ResourceResponse response; | 41 ResourceResponse response; |
| 43 response.setURL(URLTestHelpers::toKURL("https://example.com/")); | 42 response.setURL(URLTestHelpers::toKURL("https://example.com/")); |
| 44 response.setHTTPStatusCode(200); | 43 response.setHTTPStatusCode(200); |
| 45 return response; | 44 return response; |
| 46 } | 45 } |
| 47 | 46 |
| 48 void createTestResourceAndSetCachedMetadata(const ResourceResponse& response) | 47 void createTestResourceAndSetCachedMetadata(const ResourceResponse& response) |
| 49 { | 48 { |
| 50 const char testData[] = "test data"; | 49 const char testData[] = "test data"; |
| 51 ResourcePtr<Resource> resource = new Resource(ResourceRequest(response.url()
), Resource::Raw); | 50 RefPtrWillBeRawPtr<Resource> resource = Resource::create(ResourceRequest(res
ponse.url()), Resource::Raw); |
| 52 resource->setResponse(response); | 51 resource->setResponse(response); |
| 53 resource->cacheHandler()->setCachedMetadata(100, testData, sizeof(testData),
CachedMetadataHandler::SendToPlatform); | 52 resource->cacheHandler()->setCachedMetadata(100, testData, sizeof(testData),
CachedMetadataHandler::SendToPlatform); |
| 54 return; | 53 return; |
| 55 } | 54 } |
| 56 | 55 |
| 57 } // anonymous namespace | 56 } // anonymous namespace |
| 58 | 57 |
| 59 TEST(ResourceTest, SetCachedMetadata_SendsMetadataToPlatform) | 58 TEST(ResourceTest, SetCachedMetadata_SendsMetadataToPlatform) |
| 60 { | 59 { |
| 61 MockPlatform mock; | 60 MockPlatform mock; |
| 62 ResourceResponse response(createTestResourceResponse()); | 61 ResourceResponse response(createTestResourceResponse()); |
| 63 createTestResourceAndSetCachedMetadata(response); | 62 createTestResourceAndSetCachedMetadata(response); |
| 64 EXPECT_EQ(1u, mock.cachedURLs().size()); | 63 EXPECT_EQ(1u, mock.cachedURLs().size()); |
| 65 } | 64 } |
| 66 | 65 |
| 67 TEST(ResourceTest, SetCachedMetadata_DoesNotSendMetadataToPlatformWhenFetchedVia
ServiceWorker) | 66 TEST(ResourceTest, SetCachedMetadata_DoesNotSendMetadataToPlatformWhenFetchedVia
ServiceWorker) |
| 68 { | 67 { |
| 69 MockPlatform mock; | 68 MockPlatform mock; |
| 70 ResourceResponse response(createTestResourceResponse()); | 69 ResourceResponse response(createTestResourceResponse()); |
| 71 response.setWasFetchedViaServiceWorker(true); | 70 response.setWasFetchedViaServiceWorker(true); |
| 72 createTestResourceAndSetCachedMetadata(response); | 71 createTestResourceAndSetCachedMetadata(response); |
| 73 EXPECT_EQ(0u, mock.cachedURLs().size()); | 72 EXPECT_EQ(0u, mock.cachedURLs().size()); |
| 74 } | 73 } |
| 75 | 74 |
| 76 } // namespace blink | 75 } // namespace blink |
| OLD | NEW |