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

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

Issue 2191633003: Move ResourceClient to Oilpan heap (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@onheap-raw-resource-client
Patch Set: build fix Created 4 years, 3 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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 ResourceResponse revalidatingResponse; 153 ResourceResponse revalidatingResponse;
154 revalidatingResponse.setHTTPStatusCode(304); 154 revalidatingResponse.setHTTPStatusCode(304);
155 resource->responseReceived(revalidatingResponse, nullptr); 155 resource->responseReceived(revalidatingResponse, nullptr);
156 EXPECT_FALSE(resource->isCacheValidator()); 156 EXPECT_FALSE(resource->isCacheValidator());
157 EXPECT_EQ(200, resource->response().httpStatusCode()); 157 EXPECT_EQ(200, resource->response().httpStatusCode());
158 EXPECT_EQ(4u, resource->resourceBuffer()->size()); 158 EXPECT_EQ(4u, resource->resourceBuffer()->size());
159 EXPECT_EQ(memoryCache()->resourceForURL(KURL(ParsedURLString, "data:text/htm l,")), resource); 159 EXPECT_EQ(memoryCache()->resourceForURL(KURL(ParsedURLString, "data:text/htm l,")), resource);
160 memoryCache()->remove(resource); 160 memoryCache()->remove(resource);
161 161
162 resource->removeClient(client); 162 resource->removeClient(client);
163 EXPECT_FALSE(resource->hasClientsOrObservers()); 163 EXPECT_FALSE(resource->isAlive());
164 EXPECT_FALSE(client->called()); 164 EXPECT_FALSE(client->called());
165 EXPECT_EQ("abcd", String(client->data().data(), client->data().size())); 165 EXPECT_EQ("abcd", String(client->data().data(), client->data().size()));
166 } 166 }
167 167
168 TEST(RawResourceTest, RevalidationSucceededForResourceWithoutBody) 168 TEST(RawResourceTest, RevalidationSucceededForResourceWithoutBody)
169 { 169 {
170 Resource* resource = RawResource::create(ResourceRequest("data:text/html,"), Resource::Raw); 170 Resource* resource = RawResource::create(ResourceRequest("data:text/html,"), Resource::Raw);
171 ResourceResponse response; 171 ResourceResponse response;
172 response.setHTTPStatusCode(200); 172 response.setHTTPStatusCode(200);
173 resource->responseReceived(response, nullptr); 173 resource->responseReceived(response, nullptr);
174 resource->finish(); 174 resource->finish();
175 memoryCache()->add(resource); 175 memoryCache()->add(resource);
176 176
177 // Simulate a successful revalidation. 177 // Simulate a successful revalidation.
178 resource->setRevalidatingRequest(ResourceRequest("data:text/html,")); 178 resource->setRevalidatingRequest(ResourceRequest("data:text/html,"));
179 179
180 Persistent<DummyClient> client = new DummyClient; 180 Persistent<DummyClient> client = new DummyClient;
181 resource->addClient(client); 181 resource->addClient(client);
182 182
183 ResourceResponse revalidatingResponse; 183 ResourceResponse revalidatingResponse;
184 revalidatingResponse.setHTTPStatusCode(304); 184 revalidatingResponse.setHTTPStatusCode(304);
185 resource->responseReceived(revalidatingResponse, nullptr); 185 resource->responseReceived(revalidatingResponse, nullptr);
186 EXPECT_FALSE(resource->isCacheValidator()); 186 EXPECT_FALSE(resource->isCacheValidator());
187 EXPECT_EQ(200, resource->response().httpStatusCode()); 187 EXPECT_EQ(200, resource->response().httpStatusCode());
188 EXPECT_EQ(nullptr, resource->resourceBuffer()); 188 EXPECT_EQ(nullptr, resource->resourceBuffer());
189 EXPECT_EQ(memoryCache()->resourceForURL(KURL(ParsedURLString, "data:text/htm l,")), resource); 189 EXPECT_EQ(memoryCache()->resourceForURL(KURL(ParsedURLString, "data:text/htm l,")), resource);
190 memoryCache()->remove(resource); 190 memoryCache()->remove(resource);
191 191
192 resource->removeClient(client); 192 resource->removeClient(client);
193 EXPECT_FALSE(resource->hasClientsOrObservers()); 193 EXPECT_FALSE(resource->isAlive());
194 EXPECT_FALSE(client->called()); 194 EXPECT_FALSE(client->called());
195 EXPECT_EQ(0u, client->data().size()); 195 EXPECT_EQ(0u, client->data().size());
196 } 196 }
197 197
198 TEST(RawResourceTest, RevalidationSucceededUpdateHeaders) 198 TEST(RawResourceTest, RevalidationSucceededUpdateHeaders)
199 { 199 {
200 Resource* resource = RawResource::create(ResourceRequest("data:text/html,"), Resource::Raw); 200 Resource* resource = RawResource::create(ResourceRequest("data:text/html,"), Resource::Raw);
201 ResourceResponse response; 201 ResourceResponse response;
202 response.setHTTPStatusCode(200); 202 response.setHTTPStatusCode(200);
203 response.addHTTPHeaderField("keep-alive", "keep-alive value"); 203 response.addHTTPHeaderField("keep-alive", "keep-alive value");
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 EXPECT_EQ("expires value", resource->response().httpHeaderField("expires")); 246 EXPECT_EQ("expires value", resource->response().httpHeaderField("expires"));
247 EXPECT_EQ("last-modified value", resource->response().httpHeaderField("last- modified")); 247 EXPECT_EQ("last-modified value", resource->response().httpHeaderField("last- modified"));
248 EXPECT_EQ("proxy-authenticate value", resource->response().httpHeaderField(" proxy-authenticate")); 248 EXPECT_EQ("proxy-authenticate value", resource->response().httpHeaderField(" proxy-authenticate"));
249 EXPECT_EQ("proxy-authenticate value", resource->response().httpHeaderField(" proxy-authenticate")); 249 EXPECT_EQ("proxy-authenticate value", resource->response().httpHeaderField(" proxy-authenticate"));
250 EXPECT_EQ("proxy-connection value", resource->response().httpHeaderField("pr oxy-connection")); 250 EXPECT_EQ("proxy-connection value", resource->response().httpHeaderField("pr oxy-connection"));
251 EXPECT_EQ("updated", resource->response().httpHeaderField("x-custom")); 251 EXPECT_EQ("updated", resource->response().httpHeaderField("x-custom"));
252 252
253 memoryCache()->remove(resource); 253 memoryCache()->remove(resource);
254 254
255 resource->removeClient(client); 255 resource->removeClient(client);
256 EXPECT_FALSE(resource->hasClientsOrObservers()); 256 EXPECT_FALSE(resource->isAlive());
257 EXPECT_FALSE(client->called()); 257 EXPECT_FALSE(client->called());
258 EXPECT_EQ(0u, client->data().size()); 258 EXPECT_EQ(0u, client->data().size());
259 } 259 }
260 260
261 TEST(RawResourceTest, RedirectDuringRevalidation) 261 TEST(RawResourceTest, RedirectDuringRevalidation)
262 { 262 {
263 Resource* resource = RawResource::create(ResourceRequest("https://example.co m/1"), Resource::Raw); 263 Resource* resource = RawResource::create(ResourceRequest("https://example.co m/1"), Resource::Raw);
264 ResourceResponse response; 264 ResourceResponse response;
265 response.setURL(KURL(ParsedURLString, "https://example.com/1")); 265 response.setURL(KURL(ParsedURLString, "https://example.com/1"));
266 response.setHTTPStatusCode(200); 266 response.setHTTPStatusCode(200);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 testing::runPendingTasks(); 323 testing::runPendingTasks();
324 324
325 EXPECT_TRUE(client2->called()); 325 EXPECT_TRUE(client2->called());
326 EXPECT_EQ(1, client2->numberOfRedirectsReceived()); 326 EXPECT_EQ(1, client2->numberOfRedirectsReceived());
327 EXPECT_EQ("xyz", String(client2->data().data(), client2->data().size())); 327 EXPECT_EQ("xyz", String(client2->data().data(), client2->data().size()));
328 328
329 memoryCache()->remove(resource); 329 memoryCache()->remove(resource);
330 330
331 resource->removeClient(client); 331 resource->removeClient(client);
332 resource->removeClient(client2); 332 resource->removeClient(client2);
333 EXPECT_FALSE(resource->hasClientsOrObservers()); 333 EXPECT_FALSE(resource->isAlive());
334 } 334 }
335 335
336 TEST(RawResourceTest, AddClientDuringCallback) 336 TEST(RawResourceTest, AddClientDuringCallback)
337 { 337 {
338 Resource* raw = RawResource::create(ResourceRequest("data:text/html,"), Reso urce::Raw); 338 Resource* raw = RawResource::create(ResourceRequest("data:text/html,"), Reso urce::Raw);
339 339
340 // Create a non-null response. 340 // Create a non-null response.
341 ResourceResponse response = raw->response(); 341 ResourceResponse response = raw->response();
342 response.setURL(KURL(ParsedURLString, "http://600.613/")); 342 response.setURL(KURL(ParsedURLString, "http://600.613/"));
343 raw->setResponse(response); 343 raw->setResponse(response);
344 raw->finish(); 344 raw->finish();
345 EXPECT_FALSE(raw->response().isNull()); 345 EXPECT_FALSE(raw->response().isNull());
346 346
347 Persistent<DummyClient> dummyClient = new DummyClient(); 347 Persistent<DummyClient> dummyClient = new DummyClient();
348 Persistent<AddingClient> addingClient = new AddingClient(dummyClient.get(), raw); 348 Persistent<AddingClient> addingClient = new AddingClient(dummyClient.get(), raw);
349 raw->addClient(addingClient); 349 raw->addClient(addingClient);
350 testing::runPendingTasks(); 350 testing::runPendingTasks();
351 raw->removeClient(addingClient); 351 raw->removeClient(addingClient);
352 EXPECT_FALSE(dummyClient->called()); 352 EXPECT_FALSE(dummyClient->called());
353 EXPECT_FALSE(raw->hasClientsOrObservers()); 353 EXPECT_FALSE(raw->isAlive());
354 } 354 }
355 355
356 // This client removes another client when notified. 356 // This client removes another client when notified.
357 class RemovingClient : public GarbageCollectedFinalized<RemovingClient>, public RawResourceClient { 357 class RemovingClient : public GarbageCollectedFinalized<RemovingClient>, public RawResourceClient {
358 USING_GARBAGE_COLLECTED_MIXIN(RemovingClient); 358 USING_GARBAGE_COLLECTED_MIXIN(RemovingClient);
359 public: 359 public:
360 RemovingClient(DummyClient* client) 360 RemovingClient(DummyClient* client)
361 : m_dummyClient(client) {} 361 : m_dummyClient(client) {}
362 362
363 ~RemovingClient() override {} 363 ~RemovingClient() override {}
(...skipping 24 matching lines...) Expand all
388 response.setURL(KURL(ParsedURLString, "http://600.613/")); 388 response.setURL(KURL(ParsedURLString, "http://600.613/"));
389 raw->setResponse(response); 389 raw->setResponse(response);
390 raw->finish(); 390 raw->finish();
391 EXPECT_FALSE(raw->response().isNull()); 391 EXPECT_FALSE(raw->response().isNull());
392 392
393 Persistent<DummyClient> dummyClient = new DummyClient(); 393 Persistent<DummyClient> dummyClient = new DummyClient();
394 Persistent<RemovingClient> removingClient = new RemovingClient(dummyClient.g et()); 394 Persistent<RemovingClient> removingClient = new RemovingClient(dummyClient.g et());
395 raw->addClient(dummyClient); 395 raw->addClient(dummyClient);
396 raw->addClient(removingClient); 396 raw->addClient(removingClient);
397 testing::runPendingTasks(); 397 testing::runPendingTasks();
398 EXPECT_FALSE(raw->hasClientsOrObservers()); 398 EXPECT_FALSE(raw->isAlive());
399 } 399 }
400 400
401 TEST(RawResourceTest, CanReuseDevToolsEmulateNetworkConditionsClientIdHeader) 401 TEST(RawResourceTest, CanReuseDevToolsEmulateNetworkConditionsClientIdHeader)
402 { 402 {
403 ResourceRequest request("data:text/html,"); 403 ResourceRequest request("data:text/html,");
404 request.setHTTPHeaderField(HTTPNames::X_DevTools_Emulate_Network_Conditions_ Client_Id, "Foo"); 404 request.setHTTPHeaderField(HTTPNames::X_DevTools_Emulate_Network_Conditions_ Client_Id, "Foo");
405 Resource* raw = RawResource::create(request, Resource::Raw); 405 Resource* raw = RawResource::create(request, Resource::Raw);
406 EXPECT_TRUE(raw->canReuse(ResourceRequest("data:text/html,"))); 406 EXPECT_TRUE(raw->canReuse(ResourceRequest("data:text/html,")));
407 } 407 }
408 408
409 } // namespace blink 409 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/RawResource.cpp ('k') | third_party/WebKit/Source/core/fetch/Resource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698