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

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

Issue 2394793002: Resource: helper class to prohibit {add,remove}Client() calls in scope (Closed)
Patch Set: rebase 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/Resource.cpp ('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"
8 #include "core/fetch/RawResource.h" 9 #include "core/fetch/RawResource.h"
9 #include "platform/SharedBuffer.h" 10 #include "platform/SharedBuffer.h"
10 #include "platform/network/ResourceRequest.h" 11 #include "platform/network/ResourceRequest.h"
11 #include "platform/network/ResourceResponse.h" 12 #include "platform/network/ResourceResponse.h"
12 #include "platform/testing/TestingPlatformSupport.h" 13 #include "platform/testing/TestingPlatformSupport.h"
13 #include "platform/testing/URLTestHelpers.h" 14 #include "platform/testing/URLTestHelpers.h"
14 #include "public/platform/Platform.h" 15 #include "public/platform/Platform.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 #include "wtf/Vector.h" 17 #include "wtf/Vector.h"
17 18
(...skipping 27 matching lines...) Expand all
45 void createTestResourceAndSetCachedMetadata(const ResourceResponse& response) { 46 void createTestResourceAndSetCachedMetadata(const ResourceResponse& response) {
46 const char testData[] = "test data"; 47 const char testData[] = "test data";
47 Resource* resource = 48 Resource* resource =
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
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
55 } // anonymous namespace 75 } // anonymous namespace
56 76
57 TEST(ResourceTest, SetCachedMetadata_SendsMetadataToPlatform) { 77 TEST(ResourceTest, SetCachedMetadata_SendsMetadataToPlatform) {
58 MockPlatform mock; 78 MockPlatform mock;
59 ResourceResponse response(createTestResourceResponse()); 79 ResourceResponse response(createTestResourceResponse());
60 createTestResourceAndSetCachedMetadata(response); 80 createTestResourceAndSetCachedMetadata(response);
61 EXPECT_EQ(1u, mock.cachedURLs().size()); 81 EXPECT_EQ(1u, mock.cachedURLs().size());
62 } 82 }
63 83
64 TEST( 84 TEST(
(...skipping 18 matching lines...) Expand all
83 // Revalidating with a url that differs by only the fragment 103 // Revalidating with a url that differs by only the fragment
84 // shouldn't trigger a securiy check. 104 // shouldn't trigger a securiy check.
85 url.setFragmentIdentifier("bar"); 105 url.setFragmentIdentifier("bar");
86 resource->setRevalidatingRequest(ResourceRequest(url)); 106 resource->setRevalidatingRequest(ResourceRequest(url));
87 ResourceResponse revalidatingResponse; 107 ResourceResponse revalidatingResponse;
88 revalidatingResponse.setURL(url); 108 revalidatingResponse.setURL(url);
89 revalidatingResponse.setHTTPStatusCode(304); 109 revalidatingResponse.setHTTPStatusCode(304);
90 resource->responseReceived(revalidatingResponse, nullptr); 110 resource->responseReceived(revalidatingResponse, nullptr);
91 } 111 }
92 112
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
93 } // namespace blink 124 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/Resource.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698