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

Side by Side Diff: third_party/WebKit/Source/platform/loader/fetch/RawResourceTest.cpp

Issue 2701993002: DO NOT COMMIT: Results of running new (proposed) clang-format on Blink (Closed)
Patch Set: Created 3 years, 10 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
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013, Google Inc. All rights reserved. 2 * Copyright (c) 2013, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 166
167 // ResourceClient implementation. 167 // ResourceClient implementation.
168 void notifyFinished(Resource* resource) override { 168 void notifyFinished(Resource* resource) override {
169 // First schedule an asynchronous task to remove the client. 169 // First schedule an asynchronous task to remove the client.
170 // We do not expect a client to be called if the client is removed before 170 // We do not expect a client to be called if the client is removed before
171 // a callback invocation task queued inside addClient() is scheduled. 171 // a callback invocation task queued inside addClient() is scheduled.
172 Platform::current() 172 Platform::current()
173 ->currentThread() 173 ->currentThread()
174 ->scheduler() 174 ->scheduler()
175 ->loadingTaskRunner() 175 ->loadingTaskRunner()
176 ->postTask(BLINK_FROM_HERE, WTF::bind(&AddingClient::removeClient, 176 ->postTask(
177 wrapPersistent(this))); 177 BLINK_FROM_HERE,
178 WTF::bind(&AddingClient::removeClient, wrapPersistent(this)));
178 resource->addClient(m_dummyClient); 179 resource->addClient(m_dummyClient);
179 } 180 }
180 String debugName() const override { return "AddingClient"; } 181 String debugName() const override { return "AddingClient"; }
181 182
182 void removeClient() { m_resource->removeClient(m_dummyClient); } 183 void removeClient() { m_resource->removeClient(m_dummyClient); }
183 184
184 DEFINE_INLINE_VIRTUAL_TRACE() { 185 DEFINE_INLINE_VIRTUAL_TRACE() {
185 visitor->trace(m_dummyClient); 186 visitor->trace(m_dummyClient);
186 visitor->trace(m_resource); 187 visitor->trace(m_resource);
187 RawResourceClient::trace(visitor); 188 RawResourceClient::trace(visitor);
(...skipping 20 matching lines...) Expand all
208 209
209 Persistent<DummyClient> client = new DummyClient; 210 Persistent<DummyClient> client = new DummyClient;
210 resource->addClient(client); 211 resource->addClient(client);
211 212
212 ResourceResponse revalidatingResponse; 213 ResourceResponse revalidatingResponse;
213 revalidatingResponse.setHTTPStatusCode(304); 214 revalidatingResponse.setHTTPStatusCode(304);
214 resource->responseReceived(revalidatingResponse, nullptr); 215 resource->responseReceived(revalidatingResponse, nullptr);
215 EXPECT_FALSE(resource->isCacheValidator()); 216 EXPECT_FALSE(resource->isCacheValidator());
216 EXPECT_EQ(200, resource->response().httpStatusCode()); 217 EXPECT_EQ(200, resource->response().httpStatusCode());
217 EXPECT_EQ(4u, resource->resourceBuffer()->size()); 218 EXPECT_EQ(4u, resource->resourceBuffer()->size());
218 EXPECT_EQ(resource, memoryCache()->resourceForURL( 219 EXPECT_EQ(
219 KURL(ParsedURLString, "data:text/html,"))); 220 resource,
221 memoryCache()->resourceForURL(KURL(ParsedURLString, "data:text/html,")));
220 memoryCache()->remove(resource); 222 memoryCache()->remove(resource);
221 223
222 resource->removeClient(client); 224 resource->removeClient(client);
223 EXPECT_FALSE(resource->isAlive()); 225 EXPECT_FALSE(resource->isAlive());
224 EXPECT_FALSE(client->called()); 226 EXPECT_FALSE(client->called());
225 EXPECT_EQ("abcd", String(client->data().data(), client->data().size())); 227 EXPECT_EQ("abcd", String(client->data().data(), client->data().size()));
226 } 228 }
227 229
228 TEST_F(RawResourceTest, RevalidationSucceededForResourceWithoutBody) { 230 TEST_F(RawResourceTest, RevalidationSucceededForResourceWithoutBody) {
229 Resource* resource = 231 Resource* resource =
230 RawResource::create(ResourceRequest("data:text/html,"), Resource::Raw); 232 RawResource::create(ResourceRequest("data:text/html,"), Resource::Raw);
231 ResourceResponse response; 233 ResourceResponse response;
232 response.setHTTPStatusCode(200); 234 response.setHTTPStatusCode(200);
233 resource->responseReceived(response, nullptr); 235 resource->responseReceived(response, nullptr);
234 resource->finish(); 236 resource->finish();
235 memoryCache()->add(resource); 237 memoryCache()->add(resource);
236 238
237 // Simulate a successful revalidation. 239 // Simulate a successful revalidation.
238 resource->setRevalidatingRequest(ResourceRequest("data:text/html,")); 240 resource->setRevalidatingRequest(ResourceRequest("data:text/html,"));
239 241
240 Persistent<DummyClient> client = new DummyClient; 242 Persistent<DummyClient> client = new DummyClient;
241 resource->addClient(client); 243 resource->addClient(client);
242 244
243 ResourceResponse revalidatingResponse; 245 ResourceResponse revalidatingResponse;
244 revalidatingResponse.setHTTPStatusCode(304); 246 revalidatingResponse.setHTTPStatusCode(304);
245 resource->responseReceived(revalidatingResponse, nullptr); 247 resource->responseReceived(revalidatingResponse, nullptr);
246 EXPECT_FALSE(resource->isCacheValidator()); 248 EXPECT_FALSE(resource->isCacheValidator());
247 EXPECT_EQ(200, resource->response().httpStatusCode()); 249 EXPECT_EQ(200, resource->response().httpStatusCode());
248 EXPECT_FALSE(resource->resourceBuffer()); 250 EXPECT_FALSE(resource->resourceBuffer());
249 EXPECT_EQ(resource, memoryCache()->resourceForURL( 251 EXPECT_EQ(
250 KURL(ParsedURLString, "data:text/html,"))); 252 resource,
253 memoryCache()->resourceForURL(KURL(ParsedURLString, "data:text/html,")));
251 memoryCache()->remove(resource); 254 memoryCache()->remove(resource);
252 255
253 resource->removeClient(client); 256 resource->removeClient(client);
254 EXPECT_FALSE(resource->isAlive()); 257 EXPECT_FALSE(resource->isAlive());
255 EXPECT_FALSE(client->called()); 258 EXPECT_FALSE(client->called());
256 EXPECT_EQ(0u, client->data().size()); 259 EXPECT_EQ(0u, client->data().size());
257 } 260 }
258 261
259 TEST_F(RawResourceTest, RevalidationSucceededUpdateHeaders) { 262 TEST_F(RawResourceTest, RevalidationSucceededUpdateHeaders) {
260 Resource* resource = 263 Resource* resource =
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 resource->appendData(data2, 3); 383 resource->appendData(data2, 3);
381 resource->finish(); 384 resource->finish();
382 EXPECT_FALSE(resource->isCacheValidator()); 385 EXPECT_FALSE(resource->isCacheValidator());
383 EXPECT_EQ("https://example.com/1", 386 EXPECT_EQ("https://example.com/1",
384 resource->resourceRequest().url().getString()); 387 resource->resourceRequest().url().getString());
385 EXPECT_EQ("https://example.com/2", 388 EXPECT_EQ("https://example.com/2",
386 resource->lastResourceRequest().url().getString()); 389 resource->lastResourceRequest().url().getString());
387 EXPECT_FALSE(resource->isCacheValidator()); 390 EXPECT_FALSE(resource->isCacheValidator());
388 EXPECT_EQ(200, resource->response().httpStatusCode()); 391 EXPECT_EQ(200, resource->response().httpStatusCode());
389 EXPECT_EQ(3u, resource->resourceBuffer()->size()); 392 EXPECT_EQ(3u, resource->resourceBuffer()->size());
390 EXPECT_EQ(resource, memoryCache()->resourceForURL( 393 EXPECT_EQ(resource,
391 KURL(ParsedURLString, "https://example.com/1"))); 394 memoryCache()->resourceForURL(
395 KURL(ParsedURLString, "https://example.com/1")));
392 396
393 EXPECT_TRUE(client->called()); 397 EXPECT_TRUE(client->called());
394 EXPECT_EQ(1, client->numberOfRedirectsReceived()); 398 EXPECT_EQ(1, client->numberOfRedirectsReceived());
395 EXPECT_EQ("xyz", String(client->data().data(), client->data().size())); 399 EXPECT_EQ("xyz", String(client->data().data(), client->data().size()));
396 400
397 // Test the case where a client is added after revalidation is completed. 401 // Test the case where a client is added after revalidation is completed.
398 Persistent<DummyClient> client2 = new DummyClient; 402 Persistent<DummyClient> client2 = new DummyClient;
399 resource->addClient(client2); 403 resource->addClient(client2);
400 404
401 // Because RawResourceClient is added asynchronously, 405 // Because RawResourceClient is added asynchronously,
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 TEST_F(RawResourceTest, 577 TEST_F(RawResourceTest,
574 CanReuseDevToolsEmulateNetworkConditionsClientIdHeader) { 578 CanReuseDevToolsEmulateNetworkConditionsClientIdHeader) {
575 ResourceRequest request("data:text/html,"); 579 ResourceRequest request("data:text/html,");
576 request.setHTTPHeaderField( 580 request.setHTTPHeaderField(
577 HTTPNames::X_DevTools_Emulate_Network_Conditions_Client_Id, "Foo"); 581 HTTPNames::X_DevTools_Emulate_Network_Conditions_Client_Id, "Foo");
578 Resource* raw = RawResource::create(request, Resource::Raw); 582 Resource* raw = RawResource::create(request, Resource::Raw);
579 EXPECT_TRUE(raw->canReuse(ResourceRequest("data:text/html,"))); 583 EXPECT_TRUE(raw->canReuse(ResourceRequest("data:text/html,")));
580 } 584 }
581 585
582 } // namespace blink 586 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698