| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/mock_browsing_data_indexed_db_helper.h" | 5 #include "chrome/browser/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 | 9 |
| 10 MockBrowsingDataIndexedDBHelper::MockBrowsingDataIndexedDBHelper( | 10 MockBrowsingDataIndexedDBHelper::MockBrowsingDataIndexedDBHelper() |
| 11 Profile* profile) | 11 : kOrigin1("http://idbhost1:1/"), |
| 12 : profile_(profile) { | 12 kOrigin2("http://idbhost2:2/"), |
| 13 origin1_deleted_(false), |
| 14 origin2_deleted_(false) { |
| 13 } | 15 } |
| 14 | 16 |
| 15 MockBrowsingDataIndexedDBHelper::~MockBrowsingDataIndexedDBHelper() { | 17 MockBrowsingDataIndexedDBHelper::~MockBrowsingDataIndexedDBHelper() { |
| 16 } | 18 } |
| 17 | 19 |
| 18 void MockBrowsingDataIndexedDBHelper::StartFetching( | 20 void MockBrowsingDataIndexedDBHelper::StartFetching( |
| 19 Callback1<const std::list<IndexedDBInfo>& >::Type* callback) { | 21 Callback1<const std::list<IndexedDBInfo>& >::Type* callback) { |
| 20 callback_.reset(callback); | 22 callback_.reset(callback); |
| 21 } | 23 } |
| 22 | 24 |
| 23 void MockBrowsingDataIndexedDBHelper::CancelNotification() { | 25 void MockBrowsingDataIndexedDBHelper::CancelNotification() { |
| 24 callback_.reset(NULL); | 26 callback_.reset(NULL); |
| 25 } | 27 } |
| 26 | 28 |
| 27 void MockBrowsingDataIndexedDBHelper::DeleteIndexedDBFile( | 29 void MockBrowsingDataIndexedDBHelper::DeleteIndexedDB( |
| 28 const FilePath& file_path) { | 30 const GURL& origin_url) { |
| 29 CHECK(files_.find(file_path.value()) != files_.end()); | 31 CHECK(origin_url == kOrigin1 || origin_url == kOrigin2); |
| 30 last_deleted_file_ = file_path; | 32 if (origin_url == kOrigin1) |
| 31 files_[file_path.value()] = false; | 33 origin1_deleted_ = true; |
| 34 else |
| 35 origin2_deleted_ = true; |
| 32 } | 36 } |
| 33 | 37 |
| 34 void MockBrowsingDataIndexedDBHelper::AddIndexedDBSamples() { | 38 void MockBrowsingDataIndexedDBHelper::AddIndexedDBSamples() { |
| 35 response_.push_back( | 39 response_.push_back( |
| 36 BrowsingDataIndexedDBHelper::IndexedDBInfo( | 40 BrowsingDataIndexedDBHelper::IndexedDBInfo( |
| 37 "http", "idbhost1", 1, "idb1", "http://idbhost1:1/", | 41 kOrigin1, 1, base::Time())); |
| 38 FilePath(FILE_PATH_LITERAL("file1")), 1, base::Time())); | |
| 39 files_[FILE_PATH_LITERAL("file1")] = true; | |
| 40 response_.push_back( | 42 response_.push_back( |
| 41 BrowsingDataIndexedDBHelper::IndexedDBInfo( | 43 BrowsingDataIndexedDBHelper::IndexedDBInfo( |
| 42 "http", "idbhost2", 2, "idb2", "http://idbhost2:2/", | 44 kOrigin2, 2, base::Time())); |
| 43 FilePath(FILE_PATH_LITERAL("file2")), 2, base::Time())); | |
| 44 files_[FILE_PATH_LITERAL("file2")] = true; | |
| 45 } | 45 } |
| 46 | 46 |
| 47 void MockBrowsingDataIndexedDBHelper::Notify() { | 47 void MockBrowsingDataIndexedDBHelper::Notify() { |
| 48 CHECK(callback_.get()); | 48 CHECK(callback_.get()); |
| 49 callback_->Run(response_); | 49 callback_->Run(response_); |
| 50 } | 50 } |
| 51 | 51 |
| 52 void MockBrowsingDataIndexedDBHelper::Reset() { | 52 void MockBrowsingDataIndexedDBHelper::Reset() { |
| 53 for (std::map<const FilePath::StringType, bool>::iterator i = files_.begin(); | 53 origin1_deleted_ = origin2_deleted_ = false; |
| 54 i != files_.end(); ++i) | |
| 55 i->second = true; | |
| 56 } | 54 } |
| 57 | 55 |
| 58 bool MockBrowsingDataIndexedDBHelper::AllDeleted() { | 56 bool MockBrowsingDataIndexedDBHelper::AllDeleted() { |
| 59 for (std::map<const FilePath::StringType, bool>::const_iterator i = | 57 return origin1_deleted_ && origin2_deleted_; |
| 60 files_.begin(); i != files_.end(); ++i) | |
| 61 if (i->second) | |
| 62 return false; | |
| 63 return true; | |
| 64 } | 58 } |
| OLD | NEW |