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

Unified Diff: net/sdch/sdch_owner_unittest.cc

Issue 1051353003: SDCH: add TimeWeightedMemoryUse (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Improve test coverage Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: net/sdch/sdch_owner_unittest.cc
diff --git a/net/sdch/sdch_owner_unittest.cc b/net/sdch/sdch_owner_unittest.cc
index ebcbd02b3d358dddfa4206ea4655ada12c69c7d4..d02dd534c639a91d803e9b26bdab656d22488f81 100644
--- a/net/sdch/sdch_owner_unittest.cc
+++ b/net/sdch/sdch_owner_unittest.cc
@@ -4,8 +4,10 @@
#include "base/memory/memory_pressure_listener.h"
#include "base/prefs/testing_pref_store.h"
+#include "base/process/process_info.h"
#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
+#include "base/test/histogram_tester.h"
#include "base/test/simple_test_clock.h"
#include "base/values.h"
#include "net/base/net_log.h"
@@ -405,6 +407,10 @@ TEST_F(SdchOwnerTest, ConfirmAutoEviction) {
std::string server_hash_d2;
std::string server_hash_d3;
+ base::SimpleTestClock* test_clock = new base::SimpleTestClock();
+ sdch_owner().SetClockForTesting(make_scoped_ptr(test_clock));
+ test_clock->SetNow(base::Time::Now());
+
// Add two dictionaries, one recent, one more than a day in the past.
base::Time fresh(base::Time::Now() - base::TimeDelta::FromHours(23));
base::Time stale(base::Time::Now() - base::TimeDelta::FromHours(25));
@@ -417,11 +423,26 @@ TEST_F(SdchOwnerTest, ConfirmAutoEviction) {
EXPECT_TRUE(DictionaryPresentInManager(server_hash_d1));
EXPECT_TRUE(DictionaryPresentInManager(server_hash_d2));
+ base::HistogramTester tester;
+ const base::TimeDelta synthetic_delta = base::TimeDelta::FromSeconds(5);
+
+ test_clock->Advance(synthetic_delta);
+
EXPECT_TRUE(
CreateAndAddDictionary(kMaxSizeForTesting / 2, &server_hash_d3, fresh));
EXPECT_TRUE(DictionaryPresentInManager(server_hash_d1));
EXPECT_FALSE(DictionaryPresentInManager(server_hash_d2));
EXPECT_TRUE(DictionaryPresentInManager(server_hash_d3));
+
+ base::TimeDelta expected_dict_lifetime = synthetic_delta;
+ base::TimeDelta expected_proc_lifetime = synthetic_delta +
+ base::Time::Now() - base::CurrentProcessInfo::CreationTime();
+ size_t expected_value = ((kMaxSizeForTesting / 2) *
+ expected_dict_lifetime.InMilliseconds()) /
+ expected_proc_lifetime.InMilliseconds();
+
+ tester.ExpectTotalCount("Sdch3.TimeWeightedMemoryUse", 1);
+ tester.ExpectUniqueSample("Sdch3.TimeWeightedMemoryUse", expected_value, 1);
}
// Confirm auto-eviction happens if space is needed, with a more complicated

Powered by Google App Engine
This is Rietveld 408576698