| OLD | NEW |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <memory> | 6 #include <memory> |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "chrome/browser/browsing_data/cache_test_util.h" | |
| 12 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/test/base/in_process_browser_test.h" | 13 #include "chrome/test/base/in_process_browser_test.h" |
| 15 #include "components/browsing_data/content/conditional_cache_counting_helper.h" | 14 #include "components/browsing_data/content/conditional_cache_counting_helper.h" |
| 16 #include "content/public/browser/browser_context.h" | 15 #include "content/public/browser/browser_context.h" |
| 17 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/test/cache_test_util.h" |
| 18 | 18 |
| 19 using browsing_data::ConditionalCacheCountingHelper; | 19 using browsing_data::ConditionalCacheCountingHelper; |
| 20 using content::BrowserThread; | 20 using content::BrowserThread; |
| 21 | 21 |
| 22 class ConditionalCacheCountingHelperBrowserTest : public InProcessBrowserTest { | 22 class ConditionalCacheCountingHelperBrowserTest : public InProcessBrowserTest { |
| 23 public: | 23 public: |
| 24 const int64_t kTimeoutMs = 1000; | 24 const int64_t kTimeoutMs = 1000; |
| 25 | 25 |
| 26 void SetUpOnMainThread() override { | 26 void SetUpOnMainThread() override { |
| 27 count_callback_ = | 27 count_callback_ = |
| 28 base::Bind(&ConditionalCacheCountingHelperBrowserTest::CountCallback, | 28 base::Bind(&ConditionalCacheCountingHelperBrowserTest::CountCallback, |
| 29 base::Unretained(this)); | 29 base::Unretained(this)); |
| 30 | 30 |
| 31 cache_util_ = base::MakeUnique<CacheTestUtil>( | 31 cache_util_ = base::MakeUnique<content::CacheTestUtil>( |
| 32 content::BrowserContext::GetDefaultStoragePartition( | 32 content::BrowserContext::GetDefaultStoragePartition( |
| 33 browser()->profile())); | 33 browser()->profile())); |
| 34 } | 34 } |
| 35 | 35 |
| 36 void TearDownOnMainThread() override { cache_util_.reset(); } | 36 void TearDownOnMainThread() override { cache_util_.reset(); } |
| 37 | 37 |
| 38 void CountCallback(int64_t size, bool is_upper_limit) { | 38 void CountCallback(int64_t size, bool is_upper_limit) { |
| 39 // Negative values represent an unexpected error. | 39 // Negative values represent an unexpected error. |
| 40 DCHECK(size >= 0 || size == net::ERR_ABORTED); | 40 DCHECK(size >= 0 || size == net::ERR_ABORTED); |
| 41 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 41 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 62 | 62 |
| 63 int64_t GetResult() { | 63 int64_t GetResult() { |
| 64 DCHECK_GT(last_size_, 0); | 64 DCHECK_GT(last_size_, 0); |
| 65 return last_size_; | 65 return last_size_; |
| 66 } | 66 } |
| 67 | 67 |
| 68 int64_t IsUpperLimit() { return last_is_upper_limit_; } | 68 int64_t IsUpperLimit() { return last_is_upper_limit_; } |
| 69 | 69 |
| 70 int64_t GetResultOrError() { return last_size_; } | 70 int64_t GetResultOrError() { return last_size_; } |
| 71 | 71 |
| 72 CacheTestUtil* GetCacheTestUtil() { return cache_util_.get(); } | 72 content::CacheTestUtil* GetCacheTestUtil() { return cache_util_.get(); } |
| 73 | 73 |
| 74 private: | 74 private: |
| 75 ConditionalCacheCountingHelper::CacheCountCallback count_callback_; | 75 ConditionalCacheCountingHelper::CacheCountCallback count_callback_; |
| 76 std::unique_ptr<base::RunLoop> run_loop_; | 76 std::unique_ptr<base::RunLoop> run_loop_; |
| 77 std::unique_ptr<CacheTestUtil> cache_util_; | 77 std::unique_ptr<content::CacheTestUtil> cache_util_; |
| 78 | 78 |
| 79 int64_t last_size_; | 79 int64_t last_size_; |
| 80 bool last_is_upper_limit_; | 80 bool last_is_upper_limit_; |
| 81 }; | 81 }; |
| 82 | 82 |
| 83 // Tests that ConditionalCacheCountingHelper only counts those cache entries | 83 // Tests that ConditionalCacheCountingHelper only counts those cache entries |
| 84 // that match the condition. | 84 // that match the condition. |
| 85 IN_PROC_BROWSER_TEST_F(ConditionalCacheCountingHelperBrowserTest, Count) { | 85 IN_PROC_BROWSER_TEST_F(ConditionalCacheCountingHelperBrowserTest, Count) { |
| 86 // Create 5 entries. | 86 // Create 5 entries. |
| 87 std::set<std::string> keys1 = {"1", "2", "3", "4", "5"}; | 87 std::set<std::string> keys1 = {"1", "2", "3", "4", "5"}; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 EXPECT_EQ(size_1_2, size_1_3); | 123 EXPECT_EQ(size_1_2, size_1_3); |
| 124 EXPECT_EQ(size_2_3, size_1_3); | 124 EXPECT_EQ(size_2_3, size_1_3); |
| 125 } else { | 125 } else { |
| 126 EXPECT_GT(size_1_2, 0); | 126 EXPECT_GT(size_1_2, 0); |
| 127 EXPECT_GT(size_2_3, 0); | 127 EXPECT_GT(size_2_3, 0); |
| 128 EXPECT_LT(size_1_2, size_1_3); | 128 EXPECT_LT(size_1_2, size_1_3); |
| 129 EXPECT_LT(size_2_3, size_1_3); | 129 EXPECT_LT(size_2_3, size_1_3); |
| 130 EXPECT_EQ(size_1_2 + size_2_3, size_1_3); | 130 EXPECT_EQ(size_1_2 + size_2_3, size_1_3); |
| 131 } | 131 } |
| 132 } | 132 } |
| OLD | NEW |