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

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

Issue 2588403002: TestingPlatformSupport: register Platform instance correctly (Closed)
Patch Set: review #16 and merge master Created 3 years, 11 months 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 // 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/MemoryCache.h" 7 #include "core/fetch/MemoryCache.h"
8 #include "core/fetch/RawResource.h" 8 #include "core/fetch/RawResource.h"
9 #include "platform/SharedBuffer.h" 9 #include "platform/SharedBuffer.h"
10 #include "platform/network/ResourceRequest.h" 10 #include "platform/network/ResourceRequest.h"
11 #include "platform/network/ResourceResponse.h" 11 #include "platform/network/ResourceResponse.h"
12 #include "platform/testing/TestingPlatformSupport.h" 12 #include "platform/testing/TestingPlatformSupport.h"
13 #include "platform/testing/URLTestHelpers.h" 13 #include "platform/testing/URLTestHelpers.h"
14 #include "public/platform/Platform.h" 14 #include "public/platform/Platform.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "wtf/PtrUtil.h"
16 #include "wtf/Vector.h" 17 #include "wtf/Vector.h"
17 18
18 namespace blink { 19 namespace blink {
19 20
20 namespace { 21 namespace {
21 22
22 class MockPlatform final : public TestingPlatformSupport { 23 class MockPlatform final : public TestingPlatformSupport {
23 public: 24 public:
24 MockPlatform() {} 25 MockPlatform() {}
25 ~MockPlatform() override {} 26 ~MockPlatform() override {}
(...skipping 22 matching lines...) Expand all
48 RawResource::create(ResourceRequest(response.url()), Resource::Raw); 49 RawResource::create(ResourceRequest(response.url()), Resource::Raw);
49 resource->setResponse(response); 50 resource->setResponse(response);
50 resource->cacheHandler()->setCachedMetadata( 51 resource->cacheHandler()->setCachedMetadata(
51 100, testData, sizeof(testData), CachedMetadataHandler::SendToPlatform); 52 100, testData, sizeof(testData), CachedMetadataHandler::SendToPlatform);
52 return; 53 return;
53 } 54 }
54 55
55 } // anonymous namespace 56 } // anonymous namespace
56 57
57 TEST(ResourceTest, SetCachedMetadata_SendsMetadataToPlatform) { 58 TEST(ResourceTest, SetCachedMetadata_SendsMetadataToPlatform) {
58 MockPlatform mock; 59 ScopedTestingPlatformSupport<MockPlatform> mock(
60 WTF::makeUnique<MockPlatform>());
59 ResourceResponse response(createTestResourceResponse()); 61 ResourceResponse response(createTestResourceResponse());
60 createTestResourceAndSetCachedMetadata(response); 62 createTestResourceAndSetCachedMetadata(response);
61 EXPECT_EQ(1u, mock.cachedURLs().size()); 63 EXPECT_EQ(1u, mock->cachedURLs().size());
62 } 64 }
63 65
64 TEST( 66 TEST(
65 ResourceTest, 67 ResourceTest,
66 SetCachedMetadata_DoesNotSendMetadataToPlatformWhenFetchedViaServiceWorker) { 68 SetCachedMetadata_DoesNotSendMetadataToPlatformWhenFetchedViaServiceWorker) {
67 MockPlatform mock; 69 ScopedTestingPlatformSupport<MockPlatform> mock(
70 WTF::makeUnique<MockPlatform>());
68 ResourceResponse response(createTestResourceResponse()); 71 ResourceResponse response(createTestResourceResponse());
69 response.setWasFetchedViaServiceWorker(true); 72 response.setWasFetchedViaServiceWorker(true);
70 createTestResourceAndSetCachedMetadata(response); 73 createTestResourceAndSetCachedMetadata(response);
71 EXPECT_EQ(0u, mock.cachedURLs().size()); 74 EXPECT_EQ(0u, mock->cachedURLs().size());
72 } 75 }
73 76
74 TEST(ResourceTest, RevalidateWithFragment) { 77 TEST(ResourceTest, RevalidateWithFragment) {
75 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html"); 78 KURL url(ParsedURLString, "http://127.0.0.1:8000/foo.html");
76 ResourceResponse response; 79 ResourceResponse response;
77 response.setURL(url); 80 response.setURL(url);
78 response.setHTTPStatusCode(200); 81 response.setHTTPStatusCode(200);
79 Resource* resource = RawResource::create(url, Resource::Raw); 82 Resource* resource = RawResource::create(url, Resource::Raw);
80 resource->responseReceived(response, nullptr); 83 resource->responseReceived(response, nullptr);
81 resource->finish(); 84 resource->finish();
82 85
83 // Revalidating with a url that differs by only the fragment 86 // Revalidating with a url that differs by only the fragment
84 // shouldn't trigger a securiy check. 87 // shouldn't trigger a securiy check.
85 url.setFragmentIdentifier("bar"); 88 url.setFragmentIdentifier("bar");
86 resource->setRevalidatingRequest(ResourceRequest(url)); 89 resource->setRevalidatingRequest(ResourceRequest(url));
87 ResourceResponse revalidatingResponse; 90 ResourceResponse revalidatingResponse;
88 revalidatingResponse.setURL(url); 91 revalidatingResponse.setURL(url);
89 revalidatingResponse.setHTTPStatusCode(304); 92 revalidatingResponse.setHTTPStatusCode(304);
90 resource->responseReceived(revalidatingResponse, nullptr); 93 resource->responseReceived(revalidatingResponse, nullptr);
91 } 94 }
92 95
93 } // namespace blink 96 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698