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

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

Issue 2410753002: Remove ResourceTest.ProhibitAddRemoveClientInScope unit test (Closed)
Patch Set: Created 4 years, 2 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
« no previous file with comments | « third_party/WebKit/Source/core/fetch/MockResourceClients.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/MockResourceClients.h"
9 #include "core/fetch/RawResource.h" 8 #include "core/fetch/RawResource.h"
10 #include "platform/SharedBuffer.h" 9 #include "platform/SharedBuffer.h"
11 #include "platform/network/ResourceRequest.h" 10 #include "platform/network/ResourceRequest.h"
12 #include "platform/network/ResourceResponse.h" 11 #include "platform/network/ResourceResponse.h"
13 #include "platform/testing/TestingPlatformSupport.h" 12 #include "platform/testing/TestingPlatformSupport.h"
14 #include "platform/testing/URLTestHelpers.h" 13 #include "platform/testing/URLTestHelpers.h"
15 #include "public/platform/Platform.h" 14 #include "public/platform/Platform.h"
16 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
17 #include "wtf/Vector.h" 16 #include "wtf/Vector.h"
18 17
(...skipping 27 matching lines...) Expand all
46 void createTestResourceAndSetCachedMetadata(const ResourceResponse& response) { 45 void createTestResourceAndSetCachedMetadata(const ResourceResponse& response) {
47 const char testData[] = "test data"; 46 const char testData[] = "test data";
48 Resource* resource = 47 Resource* resource =
49 RawResource::create(ResourceRequest(response.url()), Resource::Raw); 48 RawResource::create(ResourceRequest(response.url()), Resource::Raw);
50 resource->setResponse(response); 49 resource->setResponse(response);
51 resource->cacheHandler()->setCachedMetadata( 50 resource->cacheHandler()->setCachedMetadata(
52 100, testData, sizeof(testData), CachedMetadataHandler::SendToPlatform); 51 100, testData, sizeof(testData), CachedMetadataHandler::SendToPlatform);
53 return; 52 return;
54 } 53 }
55 54
56 class TestProhibitAddRemoveClientResource final : public Resource {
57 public:
58 static TestProhibitAddRemoveClientResource* create() {
59 return new TestProhibitAddRemoveClientResource();
60 }
61 void testAddClient(ResourceClient* client) {
62 ProhibitAddRemoveClientInScope prohibitAddRemoveClient(this);
63 addClient(client);
64 }
65 void testRemoveClient(ResourceClient* client) {
66 ProhibitAddRemoveClientInScope prohibitAddRemoveClient(this);
67 removeClient(client);
68 }
69
70 private:
71 TestProhibitAddRemoveClientResource()
72 : Resource(ResourceRequest(), Resource::Raw, ResourceLoaderOptions()) {}
73 };
74
75 } // anonymous namespace 55 } // anonymous namespace
76 56
77 TEST(ResourceTest, SetCachedMetadata_SendsMetadataToPlatform) { 57 TEST(ResourceTest, SetCachedMetadata_SendsMetadataToPlatform) {
78 MockPlatform mock; 58 MockPlatform mock;
79 ResourceResponse response(createTestResourceResponse()); 59 ResourceResponse response(createTestResourceResponse());
80 createTestResourceAndSetCachedMetadata(response); 60 createTestResourceAndSetCachedMetadata(response);
81 EXPECT_EQ(1u, mock.cachedURLs().size()); 61 EXPECT_EQ(1u, mock.cachedURLs().size());
82 } 62 }
83 63
84 TEST( 64 TEST(
(...skipping 18 matching lines...) Expand all
103 // Revalidating with a url that differs by only the fragment 83 // Revalidating with a url that differs by only the fragment
104 // shouldn't trigger a securiy check. 84 // shouldn't trigger a securiy check.
105 url.setFragmentIdentifier("bar"); 85 url.setFragmentIdentifier("bar");
106 resource->setRevalidatingRequest(ResourceRequest(url)); 86 resource->setRevalidatingRequest(ResourceRequest(url));
107 ResourceResponse revalidatingResponse; 87 ResourceResponse revalidatingResponse;
108 revalidatingResponse.setURL(url); 88 revalidatingResponse.setURL(url);
109 revalidatingResponse.setHTTPStatusCode(304); 89 revalidatingResponse.setHTTPStatusCode(304);
110 resource->responseReceived(revalidatingResponse, nullptr); 90 resource->responseReceived(revalidatingResponse, nullptr);
111 } 91 }
112 92
113 TEST(ResourceTest, ProhibitAddRemoveClientInScope) {
114 TestProhibitAddRemoveClientResource* resource =
115 TestProhibitAddRemoveClientResource::create();
116 Persistent<MockResourceClient> client = new MockResourceClient();
117 EXPECT_DEATH(resource->testAddClient(client),
118 "!m_isAddRemoveClientProhibited");
119 resource->addClient(client);
120 EXPECT_DEATH(resource->testRemoveClient(client),
121 "!m_isAddRemoveClientProhibited");
122 }
123
124 } // namespace blink 93 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/MockResourceClients.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698