TEST(RawResourceTest, RevalidationSucceededForResourceWithoutBody) { ResourcePtr<Resource> resource = new RawResource(ResourceRequest("data:text/html,"), Resource::Raw); ResourceResponse response; response.setHTTPStatusCode(200); resource->responseReceived(response, nullptr); resource->finish(); memoryCache()->add(resource.get()); // Simulate a successful revalidation. resource->setRevalidatingRequest(ResourceRequest("data:text/html,")); OwnPtr<DummyClient> client = adoptPtr(new DummyClient); resource->addClient(client.get()); ResourceResponse revalidatingResponse; revalidatingResponse.setHTTPStatusCode(304); resource->responseReceived(revalidatingResponse, nullptr); EXPECT_FALSE(resource->isCacheValidator()); EXPECT_EQ(200, resource->response().httpStatusCode()); EXPECT_EQ(nullptr, resource->resourceBuffer()); EXPECT_EQ(memoryCache()->resourceForURL(KURL(ParsedURLString, "data:text/html,")), resource.get()); memoryCache()->remove(resource.get()); resource->removeClient(client.get()); EXPECT_FALSE(resource->hasClients()); EXPECT_FALSE(client->called()); EXPECT_EQ(0u, client->data().size()); }
void CSSCrossfadeValue::loadSubimages(ResourceFetcher* fetcher) { ResourcePtr<ImageResource> oldCachedFromImage = m_cachedFromImage; ResourcePtr<ImageResource> oldCachedToImage = m_cachedToImage; m_cachedFromImage = cachedImageForCSSValue(m_fromValue.get(), fetcher); m_cachedToImage = cachedImageForCSSValue(m_toValue.get(), fetcher); if (m_cachedFromImage != oldCachedFromImage) { if (oldCachedFromImage) oldCachedFromImage->removeClient(&m_crossfadeSubimageObserver); if (m_cachedFromImage) m_cachedFromImage->addClient(&m_crossfadeSubimageObserver); } if (m_cachedToImage != oldCachedToImage) { if (oldCachedToImage) oldCachedToImage->removeClient(&m_crossfadeSubimageObserver); if (m_cachedToImage) m_cachedToImage->addClient(&m_crossfadeSubimageObserver); } m_crossfadeSubimageObserver.setReady(true); }
TEST(RawResourceTest, AddClientDuringCallback) { ResourcePtr<Resource> raw = new RawResource(ResourceRequest("data:text/html,"), Resource::Raw); raw->setLoading(false); // Create a non-null response. ResourceResponse response = raw->response(); response.setURL(KURL(ParsedURLString, "http://600.613/")); raw->setResponse(response); EXPECT_FALSE(raw->response().isNull()); OwnPtr<DummyClient> dummyClient = adoptPtr(new DummyClient()); OwnPtr<AddingClient> addingClient = adoptPtr(new AddingClient(dummyClient.get(), raw.get())); raw->addClient(addingClient.get()); testing::runPendingTasks(); raw->removeClient(addingClient.get()); EXPECT_FALSE(dummyClient->called()); EXPECT_FALSE(raw->hasClients()); }