| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/browsing_data/mock_browsing_data_indexed_db_helper.h" | 5 #include "chrome/browser/browsing_data/mock_browsing_data_indexed_db_helper.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "content/public/browser/browser_context.h" | 10 #include "content/public/browser/browser_context.h" |
| 11 #include "content/public/browser/storage_partition.h" | 11 #include "content/public/browser/storage_partition.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 13 |
| 13 MockBrowsingDataIndexedDBHelper::MockBrowsingDataIndexedDBHelper( | 14 MockBrowsingDataIndexedDBHelper::MockBrowsingDataIndexedDBHelper( |
| 14 Profile* profile) | 15 Profile* profile) |
| 15 : BrowsingDataIndexedDBHelper( | 16 : BrowsingDataIndexedDBHelper( |
| 16 content::BrowserContext::GetDefaultStoragePartition(profile)-> | 17 content::BrowserContext::GetDefaultStoragePartition(profile)-> |
| 17 GetIndexedDBContext()) { | 18 GetIndexedDBContext()) { |
| 18 } | 19 } |
| 19 | 20 |
| 20 MockBrowsingDataIndexedDBHelper::~MockBrowsingDataIndexedDBHelper() { | 21 MockBrowsingDataIndexedDBHelper::~MockBrowsingDataIndexedDBHelper() { |
| 21 } | 22 } |
| 22 | 23 |
| 23 void MockBrowsingDataIndexedDBHelper::StartFetching( | 24 void MockBrowsingDataIndexedDBHelper::StartFetching( |
| 24 const base::Callback<void(const std::list<content::IndexedDBInfo>&)>& | 25 const base::Callback<void(const std::list<content::IndexedDBInfo>&)>& |
| 25 callback) { | 26 callback) { |
| 27 ASSERT_FALSE(callback.is_null()); |
| 28 ASSERT_TRUE(callback_.is_null()); |
| 26 callback_ = callback; | 29 callback_ = callback; |
| 27 } | 30 } |
| 28 | 31 |
| 29 void MockBrowsingDataIndexedDBHelper::DeleteIndexedDB( | 32 void MockBrowsingDataIndexedDBHelper::DeleteIndexedDB( |
| 30 const GURL& origin) { | 33 const GURL& origin) { |
| 31 CHECK(origins_.find(origin) != origins_.end()); | 34 ASSERT_FALSE(callback_.is_null()); |
| 35 ASSERT_TRUE(origins_.find(origin) != origins_.end()); |
| 32 origins_[origin] = false; | 36 origins_[origin] = false; |
| 33 } | 37 } |
| 34 | 38 |
| 35 void MockBrowsingDataIndexedDBHelper::AddIndexedDBSamples() { | 39 void MockBrowsingDataIndexedDBHelper::AddIndexedDBSamples() { |
| 36 const GURL kOrigin1("http://idbhost1:1/"); | 40 const GURL kOrigin1("http://idbhost1:1/"); |
| 37 const GURL kOrigin2("http://idbhost2:2/"); | 41 const GURL kOrigin2("http://idbhost2:2/"); |
| 38 content::IndexedDBInfo info1(kOrigin1, 1, base::Time(), base::FilePath(), 0); | 42 content::IndexedDBInfo info1(kOrigin1, 1, base::Time(), base::FilePath(), 0); |
| 39 response_.push_back(info1); | 43 response_.push_back(info1); |
| 40 origins_[kOrigin1] = true; | 44 origins_[kOrigin1] = true; |
| 41 content::IndexedDBInfo info2(kOrigin2, 2, base::Time(), base::FilePath(), 0); | 45 content::IndexedDBInfo info2(kOrigin2, 2, base::Time(), base::FilePath(), 0); |
| 42 response_.push_back(info2); | 46 response_.push_back(info2); |
| 43 origins_[kOrigin2] = true; | 47 origins_[kOrigin2] = true; |
| 44 } | 48 } |
| 45 | 49 |
| 46 void MockBrowsingDataIndexedDBHelper::Notify() { | 50 void MockBrowsingDataIndexedDBHelper::Notify() { |
| 47 CHECK_EQ(false, callback_.is_null()); | |
| 48 callback_.Run(response_); | 51 callback_.Run(response_); |
| 49 } | 52 } |
| 50 | 53 |
| 51 void MockBrowsingDataIndexedDBHelper::Reset() { | 54 void MockBrowsingDataIndexedDBHelper::Reset() { |
| 52 for (std::map<GURL, bool>::iterator i = origins_.begin(); | 55 for (std::map<GURL, bool>::iterator i = origins_.begin(); |
| 53 i != origins_.end(); ++i) | 56 i != origins_.end(); ++i) |
| 54 i->second = true; | 57 i->second = true; |
| 55 } | 58 } |
| 56 | 59 |
| 57 bool MockBrowsingDataIndexedDBHelper::AllDeleted() { | 60 bool MockBrowsingDataIndexedDBHelper::AllDeleted() { |
| 58 for (std::map<GURL, bool>::const_iterator i = origins_.begin(); | 61 for (std::map<GURL, bool>::const_iterator i = origins_.begin(); |
| 59 i != origins_.end(); ++i) | 62 i != origins_.end(); ++i) |
| 60 if (i->second) | 63 if (i->second) |
| 61 return false; | 64 return false; |
| 62 return true; | 65 return true; |
| 63 } | 66 } |
| OLD | NEW |