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

Side by Side Diff: content/browser/dom_storage/dom_storage_area_unittest.cc

Issue 896643002: [DOMStorage] Rate limiting writes to disk. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: code review comments Created 5 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 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/files/file_util.h" 6 #include "base/files/file_util.h"
7 #include "base/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/message_loop/message_loop_proxy.h" 9 #include "base/message_loop/message_loop_proxy.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 DOMStorageDatabase::GetJournalFilePath(parent.AppendASCII("file"))); 465 DOMStorageDatabase::GetJournalFilePath(parent.AppendASCII("file")));
466 EXPECT_EQ( 466 EXPECT_EQ(
467 base::FilePath().AppendASCII("-journal"), 467 base::FilePath().AppendASCII("-journal"),
468 DOMStorageDatabase::GetJournalFilePath(base::FilePath())); 468 DOMStorageDatabase::GetJournalFilePath(base::FilePath()));
469 EXPECT_EQ( 469 EXPECT_EQ(
470 base::FilePath().AppendASCII(".extensiononly-journal"), 470 base::FilePath().AppendASCII(".extensiononly-journal"),
471 DOMStorageDatabase::GetJournalFilePath( 471 DOMStorageDatabase::GetJournalFilePath(
472 base::FilePath().AppendASCII(".extensiononly"))); 472 base::FilePath().AppendASCII(".extensiononly")));
473 } 473 }
474 474
475 TEST_F(DOMStorageAreaTest, RateLimiter) {
476 // Limit to 1000 samples per second
477 DOMStorageArea::RateLimiter rate_limiter(
478 1000, base::TimeDelta::FromSeconds(1));
479
480 // No samples have been added so no time/delay should be needed.
481 EXPECT_EQ(base::TimeDelta(),
482 rate_limiter.ComputeTimeNeeded());
483 EXPECT_EQ(base::TimeDelta(),
484 rate_limiter.ComputeDelayNeeded(base::TimeDelta()));
485 EXPECT_EQ(base::TimeDelta(),
486 rate_limiter.ComputeDelayNeeded(base::TimeDelta::FromDays(1)));
487
488 // Add a seconds worth of samples.
489 rate_limiter.add_samples(1000);
490 EXPECT_EQ(base::TimeDelta::FromSeconds(1),
491 rate_limiter.ComputeTimeNeeded());
492 EXPECT_EQ(base::TimeDelta::FromSeconds(1),
493 rate_limiter.ComputeDelayNeeded(base::TimeDelta()));
494 EXPECT_EQ(base::TimeDelta(),
495 rate_limiter.ComputeDelayNeeded(base::TimeDelta::FromSeconds(1)));
496 EXPECT_EQ(base::TimeDelta::FromMilliseconds(250),
497 rate_limiter.ComputeDelayNeeded(
498 base::TimeDelta::FromMilliseconds(750)));
499 EXPECT_EQ(base::TimeDelta(),
500 rate_limiter.ComputeDelayNeeded(
501 base::TimeDelta::FromDays(1)));
502
503 // And another half seconds worth.
504 rate_limiter.add_samples(500);
505 EXPECT_EQ(base::TimeDelta::FromMilliseconds(1500),
506 rate_limiter.ComputeTimeNeeded());
507 EXPECT_EQ(base::TimeDelta::FromMilliseconds(1500),
508 rate_limiter.ComputeDelayNeeded(base::TimeDelta()));
509 EXPECT_EQ(base::TimeDelta::FromMilliseconds(500),
510 rate_limiter.ComputeDelayNeeded(base::TimeDelta::FromSeconds(1)));
511 EXPECT_EQ(base::TimeDelta::FromMilliseconds(750),
512 rate_limiter.ComputeDelayNeeded(
513 base::TimeDelta::FromMilliseconds(750)));
514 EXPECT_EQ(base::TimeDelta(),
515 rate_limiter.ComputeDelayNeeded(
516 base::TimeDelta::FromMilliseconds(1500)));
517 EXPECT_EQ(base::TimeDelta(),
518 rate_limiter.ComputeDelayNeeded(
519 base::TimeDelta::FromDays(1)));
520 }
521
475 } // namespace content 522 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698