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

Side by Side Diff: webkit/appcache/appcache_request_handler_unittest.cc

Issue 8343018: More groundwork for flat file based response storage. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/appcache/appcache_request_handler.cc ('k') | webkit/appcache/appcache_response.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stack> 5 #include <stack>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/threading/thread.h" 10 #include "base/threading/thread.h"
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 248
249 void Verify_MainResource_Miss() { 249 void Verify_MainResource_Miss() {
250 EXPECT_FALSE(job_->is_waiting()); 250 EXPECT_FALSE(job_->is_waiting());
251 EXPECT_TRUE(job_->is_delivering_network_response()); 251 EXPECT_TRUE(job_->is_delivering_network_response());
252 252
253 int64 cache_id = kNoCacheId; 253 int64 cache_id = kNoCacheId;
254 GURL manifest_url; 254 GURL manifest_url;
255 handler_->GetExtraResponseInfo(&cache_id, &manifest_url); 255 handler_->GetExtraResponseInfo(&cache_id, &manifest_url);
256 EXPECT_EQ(kNoCacheId, cache_id); 256 EXPECT_EQ(kNoCacheId, cache_id);
257 EXPECT_EQ(GURL(), manifest_url); 257 EXPECT_EQ(GURL(), manifest_url);
258 EXPECT_EQ(0, handler_->found_group_id_);
258 259
259 AppCacheURLRequestJob* fallback_job; 260 AppCacheURLRequestJob* fallback_job;
260 fallback_job = handler_->MaybeLoadFallbackForRedirect( 261 fallback_job = handler_->MaybeLoadFallbackForRedirect(
261 request_.get(), GURL("http://blah/redirect")); 262 request_.get(), GURL("http://blah/redirect"));
262 EXPECT_FALSE(fallback_job); 263 EXPECT_FALSE(fallback_job);
263 fallback_job = handler_->MaybeLoadFallbackForResponse(request_.get()); 264 fallback_job = handler_->MaybeLoadFallbackForResponse(request_.get());
264 EXPECT_FALSE(fallback_job); 265 EXPECT_FALSE(fallback_job);
265 266
266 EXPECT_TRUE(host_->preferred_manifest_url().is_empty()); 267 EXPECT_TRUE(host_->preferred_manifest_url().is_empty());
267 268
268 TestFinished(); 269 TestFinished();
269 } 270 }
270 271
271 // MainResource_Hit -------------------------------------------------- 272 // MainResource_Hit --------------------------------------------------
272 273
273 void MainResource_Hit() { 274 void MainResource_Hit() {
274 PushNextTask(NewRunnableMethod( 275 PushNextTask(NewRunnableMethod(
275 this, &AppCacheRequestHandlerTest::Verify_MainResource_Hit)); 276 this, &AppCacheRequestHandlerTest::Verify_MainResource_Hit));
276 277
277 request_.reset(new MockURLRequest(GURL("http://blah/"))); 278 request_.reset(new MockURLRequest(GURL("http://blah/")));
278 handler_.reset(host_->CreateRequestHandler(request_.get(), 279 handler_.reset(host_->CreateRequestHandler(request_.get(),
279 ResourceType::MAIN_FRAME)); 280 ResourceType::MAIN_FRAME));
280 EXPECT_TRUE(handler_.get()); 281 EXPECT_TRUE(handler_.get());
281 282
282 mock_storage()->SimulateFindMainResource( 283 mock_storage()->SimulateFindMainResource(
283 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), 284 AppCacheEntry(AppCacheEntry::EXPLICIT, 1),
284 GURL(), AppCacheEntry(), 285 GURL(), AppCacheEntry(),
285 1, GURL("http://blah/manifest/")); 286 1, 2, GURL("http://blah/manifest/"));
286 287
287 job_ = handler_->MaybeLoadResource(request_.get()); 288 job_ = handler_->MaybeLoadResource(request_.get());
288 EXPECT_TRUE(job_.get()); 289 EXPECT_TRUE(job_.get());
289 EXPECT_TRUE(job_->is_waiting()); 290 EXPECT_TRUE(job_->is_waiting());
290 291
291 // We have to wait for completion of storage->FindResponseForMainRequest. 292 // We have to wait for completion of storage->FindResponseForMainRequest.
292 ScheduleNextTask(); 293 ScheduleNextTask();
293 } 294 }
294 295
295 void Verify_MainResource_Hit() { 296 void Verify_MainResource_Hit() {
296 EXPECT_FALSE(job_->is_waiting()); 297 EXPECT_FALSE(job_->is_waiting());
297 EXPECT_TRUE(job_->is_delivering_appcache_response()); 298 EXPECT_TRUE(job_->is_delivering_appcache_response());
298 299
299 int64 cache_id = kNoCacheId; 300 int64 cache_id = kNoCacheId;
300 GURL manifest_url; 301 GURL manifest_url;
301 handler_->GetExtraResponseInfo(&cache_id, &manifest_url); 302 handler_->GetExtraResponseInfo(&cache_id, &manifest_url);
302 EXPECT_EQ(1, cache_id); 303 EXPECT_EQ(1, cache_id);
303 EXPECT_EQ(GURL("http://blah/manifest/"), manifest_url); 304 EXPECT_EQ(GURL("http://blah/manifest/"), manifest_url);
305 EXPECT_EQ(2, handler_->found_group_id_);
304 306
305 AppCacheURLRequestJob* fallback_job; 307 AppCacheURLRequestJob* fallback_job;
306 fallback_job = handler_->MaybeLoadFallbackForResponse(request_.get()); 308 fallback_job = handler_->MaybeLoadFallbackForResponse(request_.get());
307 EXPECT_FALSE(fallback_job); 309 EXPECT_FALSE(fallback_job);
308 310
309 EXPECT_EQ(GURL("http://blah/manifest/"), 311 EXPECT_EQ(GURL("http://blah/manifest/"),
310 host_->preferred_manifest_url()); 312 host_->preferred_manifest_url());
311 313
312 TestFinished(); 314 TestFinished();
313 } 315 }
314 316
315 // MainResource_Fallback -------------------------------------------------- 317 // MainResource_Fallback --------------------------------------------------
316 318
317 void MainResource_Fallback() { 319 void MainResource_Fallback() {
318 PushNextTask(NewRunnableMethod( 320 PushNextTask(NewRunnableMethod(
319 this, &AppCacheRequestHandlerTest::Verify_MainResource_Fallback)); 321 this, &AppCacheRequestHandlerTest::Verify_MainResource_Fallback));
320 322
321 request_.reset(new MockURLRequest(GURL("http://blah/"))); 323 request_.reset(new MockURLRequest(GURL("http://blah/")));
322 handler_.reset(host_->CreateRequestHandler(request_.get(), 324 handler_.reset(host_->CreateRequestHandler(request_.get(),
323 ResourceType::MAIN_FRAME)); 325 ResourceType::MAIN_FRAME));
324 EXPECT_TRUE(handler_.get()); 326 EXPECT_TRUE(handler_.get());
325 327
326 mock_storage()->SimulateFindMainResource( 328 mock_storage()->SimulateFindMainResource(
327 AppCacheEntry(), 329 AppCacheEntry(),
328 GURL("http://blah/fallbackurl"), 330 GURL("http://blah/fallbackurl"),
329 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), 331 AppCacheEntry(AppCacheEntry::EXPLICIT, 1),
330 1, GURL("http://blah/manifest/")); 332 1, 2, GURL("http://blah/manifest/"));
331 333
332 job_ = handler_->MaybeLoadResource(request_.get()); 334 job_ = handler_->MaybeLoadResource(request_.get());
333 EXPECT_TRUE(job_.get()); 335 EXPECT_TRUE(job_.get());
334 EXPECT_TRUE(job_->is_waiting()); 336 EXPECT_TRUE(job_->is_waiting());
335 337
336 // We have to wait for completion of storage->FindResponseForMainRequest. 338 // We have to wait for completion of storage->FindResponseForMainRequest.
337 ScheduleNextTask(); 339 ScheduleNextTask();
338 } 340 }
339 341
340 void Verify_MainResource_Fallback() { 342 void Verify_MainResource_Fallback() {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 379
378 request_.reset(new MockURLRequest(GURL("http://blah/fallback-override"))); 380 request_.reset(new MockURLRequest(GURL("http://blah/fallback-override")));
379 handler_.reset(host_->CreateRequestHandler(request_.get(), 381 handler_.reset(host_->CreateRequestHandler(request_.get(),
380 ResourceType::MAIN_FRAME)); 382 ResourceType::MAIN_FRAME));
381 EXPECT_TRUE(handler_.get()); 383 EXPECT_TRUE(handler_.get());
382 384
383 mock_storage()->SimulateFindMainResource( 385 mock_storage()->SimulateFindMainResource(
384 AppCacheEntry(), 386 AppCacheEntry(),
385 GURL("http://blah/fallbackurl"), 387 GURL("http://blah/fallbackurl"),
386 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), 388 AppCacheEntry(AppCacheEntry::EXPLICIT, 1),
387 1, GURL("http://blah/manifest/")); 389 1, 2, GURL("http://blah/manifest/"));
388 390
389 job_ = handler_->MaybeLoadResource(request_.get()); 391 job_ = handler_->MaybeLoadResource(request_.get());
390 EXPECT_TRUE(job_.get()); 392 EXPECT_TRUE(job_.get());
391 EXPECT_TRUE(job_->is_waiting()); 393 EXPECT_TRUE(job_->is_waiting());
392 394
393 // We have to wait for completion of storage->FindResponseForMainRequest. 395 // We have to wait for completion of storage->FindResponseForMainRequest.
394 ScheduleNextTask(); 396 ScheduleNextTask();
395 } 397 }
396 398
397 void Verify_MainResource_FallbackOverride() { 399 void Verify_MainResource_FallbackOverride() {
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 750
749 request_.reset(new MockURLRequest(GURL("http://blah/"))); 751 request_.reset(new MockURLRequest(GURL("http://blah/")));
750 handler_.reset(host_->CreateRequestHandler(request_.get(), 752 handler_.reset(host_->CreateRequestHandler(request_.get(),
751 ResourceType::MAIN_FRAME)); 753 ResourceType::MAIN_FRAME));
752 EXPECT_TRUE(handler_.get()); 754 EXPECT_TRUE(handler_.get());
753 755
754 mock_policy_->can_load_return_value_ = false; 756 mock_policy_->can_load_return_value_ = false;
755 mock_storage()->SimulateFindMainResource( 757 mock_storage()->SimulateFindMainResource(
756 AppCacheEntry(AppCacheEntry::EXPLICIT, 1), 758 AppCacheEntry(AppCacheEntry::EXPLICIT, 1),
757 GURL(), AppCacheEntry(), 759 GURL(), AppCacheEntry(),
758 1, GURL("http://blah/manifest/")); 760 1, 2, GURL("http://blah/manifest/"));
759 761
760 job_ = handler_->MaybeLoadResource(request_.get()); 762 job_ = handler_->MaybeLoadResource(request_.get());
761 EXPECT_TRUE(job_.get()); 763 EXPECT_TRUE(job_.get());
762 EXPECT_TRUE(job_->is_waiting()); 764 EXPECT_TRUE(job_->is_waiting());
763 765
764 // We have to wait for completion of storage->FindResponseForMainRequest. 766 // We have to wait for completion of storage->FindResponseForMainRequest.
765 ScheduleNextTask(); 767 ScheduleNextTask();
766 } 768 }
767 769
768 void Verify_MainResource_Blocked() { 770 void Verify_MainResource_Blocked() {
769 EXPECT_FALSE(job_->is_waiting()); 771 EXPECT_FALSE(job_->is_waiting());
770 EXPECT_FALSE(job_->is_delivering_appcache_response()); 772 EXPECT_FALSE(job_->is_delivering_appcache_response());
771 773
772 EXPECT_EQ(0, handler_->found_cache_id_); 774 EXPECT_EQ(0, handler_->found_cache_id_);
775 EXPECT_EQ(0, handler_->found_group_id_);
773 EXPECT_TRUE(handler_->found_manifest_url_.is_empty()); 776 EXPECT_TRUE(handler_->found_manifest_url_.is_empty());
774 EXPECT_TRUE(host_->preferred_manifest_url().is_empty()); 777 EXPECT_TRUE(host_->preferred_manifest_url().is_empty());
775 EXPECT_TRUE(host_->main_resource_blocked_); 778 EXPECT_TRUE(host_->main_resource_blocked_);
776 EXPECT_TRUE(host_->blocked_manifest_url_ == GURL("http://blah/manifest/")); 779 EXPECT_TRUE(host_->blocked_manifest_url_ == GURL("http://blah/manifest/"));
777 780
778 TestFinished(); 781 TestFinished();
779 } 782 }
780 783
781 // Test case helpers -------------------------------------------------- 784 // Test case helpers --------------------------------------------------
782 785
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 892
890 TEST_F(AppCacheRequestHandlerTest, MainResource_Blocked) { 893 TEST_F(AppCacheRequestHandlerTest, MainResource_Blocked) {
891 RunTestOnIOThread(&AppCacheRequestHandlerTest::MainResource_Blocked); 894 RunTestOnIOThread(&AppCacheRequestHandlerTest::MainResource_Blocked);
892 } 895 }
893 896
894 } // namespace appcache 897 } // namespace appcache
895 898
896 // AppCacheRequestHandlerTest is expected to always live longer than the 899 // AppCacheRequestHandlerTest is expected to always live longer than the
897 // runnable methods. This lets us call NewRunnableMethod on its instances. 900 // runnable methods. This lets us call NewRunnableMethod on its instances.
898 DISABLE_RUNNABLE_METHOD_REFCOUNT(appcache::AppCacheRequestHandlerTest); 901 DISABLE_RUNNABLE_METHOD_REFCOUNT(appcache::AppCacheRequestHandlerTest);
OLDNEW
« no previous file with comments | « webkit/appcache/appcache_request_handler.cc ('k') | webkit/appcache/appcache_response.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698