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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/fetch/Resource.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/fetch/ResourceTest.cpp
diff --git a/third_party/WebKit/Source/core/fetch/ResourceTest.cpp b/third_party/WebKit/Source/core/fetch/ResourceTest.cpp
index e55a87fd2bed0360124e9dd3d0fff2e6cfa97dad..2bbbc601d7c39c3867e0b1cce125ef4d5dbf59fa 100644
--- a/third_party/WebKit/Source/core/fetch/ResourceTest.cpp
+++ b/third_party/WebKit/Source/core/fetch/ResourceTest.cpp
@@ -5,6 +5,7 @@
#include "core/fetch/Resource.h"
#include "core/fetch/MemoryCache.h"
+#include "core/fetch/MockResourceClients.h"
#include "core/fetch/RawResource.h"
#include "platform/SharedBuffer.h"
#include "platform/network/ResourceRequest.h"
@@ -52,6 +53,25 @@ void createTestResourceAndSetCachedMetadata(const ResourceResponse& response) {
return;
}
+class TestProhibitAddRemoveClientResource final : public Resource {
+ public:
+ static TestProhibitAddRemoveClientResource* create() {
+ return new TestProhibitAddRemoveClientResource();
+ }
+ void testAddClient(ResourceClient* client) {
+ ProhibitAddRemoveClientInScope prohibitAddRemoveClient(this);
+ addClient(client);
+ }
+ void testRemoveClient(ResourceClient* client) {
+ ProhibitAddRemoveClientInScope prohibitAddRemoveClient(this);
+ removeClient(client);
+ }
+
+ private:
+ TestProhibitAddRemoveClientResource()
+ : Resource(ResourceRequest(), Resource::Raw, ResourceLoaderOptions()) {}
+};
+
} // anonymous namespace
TEST(ResourceTest, SetCachedMetadata_SendsMetadataToPlatform) {
@@ -90,4 +110,15 @@ TEST(ResourceTest, RevalidateWithFragment) {
resource->responseReceived(revalidatingResponse, nullptr);
}
+TEST(ResourceTest, ProhibitAddRemoveClientInScope) {
+ TestProhibitAddRemoveClientResource* resource =
+ TestProhibitAddRemoveClientResource::create();
+ Persistent<MockResourceClient> client = new MockResourceClient();
+ EXPECT_DEATH(resource->testAddClient(client),
+ "!m_isAddRemoveClientProhibited");
+ resource->addClient(client);
+ EXPECT_DEATH(resource->testRemoveClient(client),
+ "!m_isAddRemoveClientProhibited");
+}
+
} // namespace blink
« 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