OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/browsing_data/mock_browsing_data_cache_storage_helper.h
" |
| 6 |
| 7 #include "base/callback.h" |
| 8 #include "base/logging.h" |
| 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "content/public/browser/browser_context.h" |
| 11 #include "content/public/browser/storage_partition.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 |
| 14 MockBrowsingDataCacheStorageHelper::MockBrowsingDataCacheStorageHelper( |
| 15 Profile* profile) |
| 16 : BrowsingDataCacheStorageHelper( |
| 17 content::BrowserContext::GetDefaultStoragePartition(profile) |
| 18 ->GetCacheStorageContext()) {} |
| 19 |
| 20 MockBrowsingDataCacheStorageHelper::~MockBrowsingDataCacheStorageHelper() {} |
| 21 |
| 22 void MockBrowsingDataCacheStorageHelper::StartFetching( |
| 23 const base::Callback< |
| 24 void(const std::list<content::CacheStorageUsageInfo>&)>& callback) { |
| 25 ASSERT_FALSE(callback.is_null()); |
| 26 ASSERT_TRUE(callback_.is_null()); |
| 27 callback_ = callback; |
| 28 } |
| 29 |
| 30 void MockBrowsingDataCacheStorageHelper::DeleteCacheStorage( |
| 31 const GURL& origin) { |
| 32 ASSERT_FALSE(callback_.is_null()); |
| 33 ASSERT_TRUE(origins_.find(origin) != origins_.end()); |
| 34 origins_[origin] = false; |
| 35 } |
| 36 |
| 37 void MockBrowsingDataCacheStorageHelper::AddCacheStorageSamples() { |
| 38 const GURL kOrigin1("https://cshost1:1/"); |
| 39 const GURL kOrigin2("https://cshost2:2/"); |
| 40 content::CacheStorageUsageInfo info1(kOrigin1, 1, base::Time()); |
| 41 response_.push_back(info1); |
| 42 origins_[kOrigin1] = true; |
| 43 content::CacheStorageUsageInfo info2(kOrigin2, 2, base::Time()); |
| 44 response_.push_back(info2); |
| 45 origins_[kOrigin2] = true; |
| 46 } |
| 47 |
| 48 void MockBrowsingDataCacheStorageHelper::Notify() { |
| 49 callback_.Run(response_); |
| 50 } |
| 51 |
| 52 void MockBrowsingDataCacheStorageHelper::Reset() { |
| 53 for (auto& pair : origins_) |
| 54 pair.second = true; |
| 55 } |
| 56 |
| 57 bool MockBrowsingDataCacheStorageHelper::AllDeleted() { |
| 58 for (const auto& pair : origins_) { |
| 59 if (pair.second) |
| 60 return false; |
| 61 } |
| 62 return true; |
| 63 } |
OLD | NEW |