本文整理汇总了C++中Persistent::called方法的典型用法代码示例。如果您正苦于以下问题:C++ Persistent::called方法的具体用法?C++ Persistent::called怎么用?C++ Persistent::called使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Persistent
的用法示例。
在下文中一共展示了Persistent::called方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: memoryCache
TEST(RawResourceTest, RevalidationSucceededForResourceWithoutBody)
{
Resource* resource = RawResource::create(ResourceRequest("data:text/html,"), Resource::Raw);
ResourceResponse response;
response.setHTTPStatusCode(200);
resource->responseReceived(response, nullptr);
resource->finish();
memoryCache()->add(resource);
// Simulate a successful revalidation.
resource->setRevalidatingRequest(ResourceRequest("data:text/html,"));
Persistent<DummyClient> client = new DummyClient;
resource->addClient(client);
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);
memoryCache()->remove(resource);
resource->removeClient(client);
EXPECT_FALSE(resource->hasClientsOrObservers());
EXPECT_FALSE(client->called());
EXPECT_EQ(0u, client->data().size());
}
示例2: DummyClient
TEST(RawResourceTest, AddClientDuringCallback)
{
Resource* raw = RawResource::create(ResourceRequest("data:text/html,"), Resource::Raw);
// Create a non-null response.
ResourceResponse response = raw->response();
response.setURL(KURL(ParsedURLString, "http://600.613/"));
raw->setResponse(response);
raw->finish();
EXPECT_FALSE(raw->response().isNull());
Persistent<DummyClient> dummyClient = new DummyClient();
Persistent<AddingClient> addingClient = new AddingClient(dummyClient.get(), raw);
raw->addClient(addingClient);
testing::runPendingTasks();
raw->removeClient(addingClient);
EXPECT_FALSE(dummyClient->called());
EXPECT_FALSE(raw->hasClientsOrObservers());
}
示例3: redirectedRevalidatingRequest
TEST(RawResourceTest, RedirectDuringRevalidation)
{
Resource* resource = RawResource::create(ResourceRequest("https://example.com/1"), Resource::Raw);
ResourceResponse response;
response.setURL(KURL(ParsedURLString, "https://example.com/1"));
response.setHTTPStatusCode(200);
resource->responseReceived(response, nullptr);
const char data[5] = "abcd";
resource->appendData(data, 4);
resource->finish();
memoryCache()->add(resource);
EXPECT_FALSE(resource->isCacheValidator());
EXPECT_EQ("https://example.com/1", resource->resourceRequest().url().getString());
EXPECT_EQ("https://example.com/1", resource->lastResourceRequest().url().getString());
// Simulate a revalidation.
resource->setRevalidatingRequest(ResourceRequest("https://example.com/1"));
EXPECT_TRUE(resource->isCacheValidator());
EXPECT_EQ("https://example.com/1", resource->resourceRequest().url().getString());
EXPECT_EQ("https://example.com/1", resource->lastResourceRequest().url().getString());
Persistent<DummyClient> client = new DummyClient;
resource->addClient(client);
// The revalidating request is redirected.
ResourceResponse redirectResponse;
redirectResponse.setURL(KURL(ParsedURLString, "https://example.com/1"));
redirectResponse.setHTTPHeaderField("location", "https://example.com/2");
redirectResponse.setHTTPStatusCode(308);
ResourceRequest redirectedRevalidatingRequest("https://example.com/2");
resource->willFollowRedirect(redirectedRevalidatingRequest, redirectResponse);
EXPECT_FALSE(resource->isCacheValidator());
EXPECT_EQ("https://example.com/1", resource->resourceRequest().url().getString());
EXPECT_EQ("https://example.com/2", resource->lastResourceRequest().url().getString());
// The final response is received.
ResourceResponse revalidatingResponse;
revalidatingResponse.setURL(KURL(ParsedURLString, "https://example.com/2"));
revalidatingResponse.setHTTPStatusCode(200);
resource->responseReceived(revalidatingResponse, nullptr);
const char data2[4] = "xyz";
resource->appendData(data2, 3);
resource->finish();
EXPECT_FALSE(resource->isCacheValidator());
EXPECT_EQ("https://example.com/1", resource->resourceRequest().url().getString());
EXPECT_EQ("https://example.com/2", resource->lastResourceRequest().url().getString());
EXPECT_FALSE(resource->isCacheValidator());
EXPECT_EQ(200, resource->response().httpStatusCode());
EXPECT_EQ(3u, resource->resourceBuffer()->size());
EXPECT_EQ(memoryCache()->resourceForURL(KURL(ParsedURLString, "https://example.com/1")), resource);
EXPECT_TRUE(client->called());
EXPECT_EQ(1, client->numberOfRedirectsReceived());
EXPECT_EQ("xyz", String(client->data().data(), client->data().size()));
// Test the case where a client is added after revalidation is completed.
Persistent<DummyClient> client2 = new DummyClient;
resource->addClient(client2);
// Because RawResourceClient is added asynchronously,
// |runPendingTasks()| is called to make |client2| to be notified.
testing::runPendingTasks();
EXPECT_TRUE(client2->called());
EXPECT_EQ(1, client2->numberOfRedirectsReceived());
EXPECT_EQ("xyz", String(client2->data().data(), client2->data().size()));
memoryCache()->remove(resource);
resource->removeClient(client);
resource->removeClient(client2);
EXPECT_FALSE(resource->hasClientsOrObservers());
}