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

Side by Side Diff: webkit/browser/appcache/appcache_service_unittest.cc

Issue 137493003: Appcache::OnCorruptionDetected handling (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <string> 5 #include <string>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/pickle.h" 9 #include "base/pickle.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 SetupMockReader(true, true, false); 310 SetupMockReader(true, true, false);
311 base::RunLoop().RunUntilIdle(); 311 base::RunLoop().RunUntilIdle();
312 EXPECT_EQ(0, CountPendingHelpers()); 312 EXPECT_EQ(0, CountPendingHelpers());
313 EXPECT_FALSE(IsGroupStored(kManifestUrl)); 313 EXPECT_FALSE(IsGroupStored(kManifestUrl));
314 ResetStorage(); 314 ResetStorage();
315 315
316 service_.reset(); // Clean up. 316 service_.reset(); // Clean up.
317 base::RunLoop().RunUntilIdle(); 317 base::RunLoop().RunUntilIdle();
318 } 318 }
319 319
320 // Just tests the backoff scheduling function, not the actual reinit function.
321 TEST_F(AppCacheServiceTest, ScheduleReinitialize) {
322 const base::TimeDelta kNoDelay;
323 const base::TimeDelta kOneSecond(base::TimeDelta::FromSeconds(1));
324 const base::TimeDelta k30Seconds(base::TimeDelta::FromSeconds(30));
325 const base::TimeDelta kOneHour(base::TimeDelta::FromHours(1));
326
327 // Do things get initialized as expected?
328 scoped_ptr<AppCacheService> service(new AppCacheService(NULL));
329 EXPECT_TRUE(service->last_reinit_time_.is_null());
330 EXPECT_FALSE(service->reinit_timer_.IsRunning());
331 EXPECT_EQ(kNoDelay, service->next_reinit_delay_);
332
333 // Do we see artifacts of the timer pending and such?
334 service->ScheduleReinitialize();
335 EXPECT_TRUE(service->reinit_timer_.IsRunning());
336 EXPECT_EQ(kNoDelay, service->reinit_timer_.GetCurrentDelay());
337 EXPECT_EQ(k30Seconds, service->next_reinit_delay_);
338
339 // Nothing should change if already scheduled
340 service->ScheduleReinitialize();
341 EXPECT_TRUE(service->reinit_timer_.IsRunning());
342 EXPECT_EQ(kNoDelay, service->reinit_timer_.GetCurrentDelay());
343 EXPECT_EQ(k30Seconds, service->next_reinit_delay_);
344
345 // Does the delay increase as expected?
346 service->reinit_timer_.Stop();
347 service->last_reinit_time_ = base::Time::Now() - kOneSecond;
348 service->ScheduleReinitialize();
349 EXPECT_TRUE(service->reinit_timer_.IsRunning());
350 EXPECT_EQ(k30Seconds, service->reinit_timer_.GetCurrentDelay());
351 EXPECT_EQ(k30Seconds + k30Seconds, service->next_reinit_delay_);
352
353 // Does the delay reset as expected?
354 service->reinit_timer_.Stop();
355 service->last_reinit_time_ = base::Time::Now() -
356 base::TimeDelta::FromHours(2);
357 service->ScheduleReinitialize();
358 EXPECT_TRUE(service->reinit_timer_.IsRunning());
359 EXPECT_EQ(kNoDelay, service->reinit_timer_.GetCurrentDelay());
360 EXPECT_EQ(k30Seconds, service->next_reinit_delay_);
361
362 // Does the delay max out as expected?
363 service->reinit_timer_.Stop();
364 service->last_reinit_time_ = base::Time::Now() - kOneSecond;
365 service->next_reinit_delay_ = kOneHour;
366 service->ScheduleReinitialize();
367 EXPECT_TRUE(service->reinit_timer_.IsRunning());
368 EXPECT_EQ(kOneHour, service->reinit_timer_.GetCurrentDelay());
369 EXPECT_EQ(kOneHour, service->next_reinit_delay_);
370
371 // Fine to delete while pending.
372 service.reset(NULL);
373 }
374
375
376
320 } // namespace appcache 377 } // namespace appcache
OLDNEW
« no previous file with comments | « webkit/browser/appcache/appcache_service.cc ('k') | webkit/browser/appcache/appcache_storage_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698