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

Unified Diff: chrome/browser/browsing_data/conditional_cache_counting_helper_browsertest.cc

Issue 2612033002: Count exact cache size for time ranges (Closed)
Patch Set: rebase Created 3 years, 11 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: chrome/browser/browsing_data/conditional_cache_counting_helper_browsertest.cc
diff --git a/chrome/browser/browsing_data/conditional_cache_counting_helper_browsertest.cc b/chrome/browser/browsing_data/conditional_cache_counting_helper_browsertest.cc
index 9dc94e417be6e8de2c29824708c6ed6a2b5631cd..f02673b632e3c49414ec25227415096ef4b8cfd4 100644
--- a/chrome/browser/browsing_data/conditional_cache_counting_helper_browsertest.cc
+++ b/chrome/browser/browsing_data/conditional_cache_counting_helper_browsertest.cc
@@ -59,6 +59,16 @@ class ConditionalCacheCountingHelperBrowserTest : public InProcessBrowserTest {
helper->CountAndDestroySelfWhenFinished(count_callback_);
}
+ void CountEntriesAndCancel(base::Time begin_time, base::Time end_time) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ last_size_ = -1;
+ auto helper = ConditionalCacheCountingHelper::CreateForRange(
+ cache_util_->partition(), begin_time, end_time);
+ // Cancel first to make sure we don't cancel after the IO thread finishes.
+ helper->CancelCounting();
+ helper->CountAndDestroySelfWhenFinished(count_callback_);
+ }
+
int64_t GetResult() {
DCHECK_GT(last_size_, 0);
return last_size_;
@@ -86,7 +96,7 @@ IN_PROC_BROWSER_TEST_F(ConditionalCacheCountingHelperBrowserTest, Count) {
GetCacheTestUtil()->CreateCacheEntries(keys1);
base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(kTimeoutMs));
- // base::Time t2 = base::Time::Now();
+ base::Time t2 = base::Time::Now();
std::set<std::string> keys2 = {"6", "7"};
GetCacheTestUtil()->CreateCacheEntries(keys2);
@@ -94,15 +104,39 @@ IN_PROC_BROWSER_TEST_F(ConditionalCacheCountingHelperBrowserTest, Count) {
base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(kTimeoutMs));
base::Time t3 = base::Time::Now();
- // TODO(dullweber): Add test for time ranges when GetEntrySize() is done.
+ // Count the size of the first set of entries.
+ CountEntries(t1, t2);
+ WaitForTasksOnIOThread();
+ int64_t size_1_2 = GetResult();
+
+ // Count the size of the second set of entries.
+ CountEntries(t2, t3);
+ WaitForTasksOnIOThread();
+ int64_t size_2_3 = GetResult();
// Count all entries.
CountEntries(t1, t3);
WaitForTasksOnIOThread();
int64_t size_1_3 = GetResult();
+ EXPECT_EQ(size_1_2 + size_2_3, size_1_3);
// Count everything
CountEntries(base::Time(), base::Time::Max());
WaitForTasksOnIOThread();
EXPECT_EQ(size_1_3, GetResult());
}
+
+// Tests that ConditionalCacheCountingHelper returns net::ERR_ABORTED when
+// cancelled.
+IN_PROC_BROWSER_TEST_F(ConditionalCacheCountingHelperBrowserTest,
+ CancelCounting) {
+ std::set<std::string> keys = {"1", "2", "3", "4", "5"};
+ base::Time t1 = base::Time::Now();
+ GetCacheTestUtil()->CreateCacheEntries(keys);
+ base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(kTimeoutMs));
+
+ // Count and cancel
+ CountEntriesAndCancel(t1, base::Time::Now());
+ WaitForTasksOnIOThread();
+ EXPECT_EQ(net::ERR_ABORTED, GetResultOrError());
+}

Powered by Google App Engine
This is Rietveld 408576698