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 3// found in the LICENSE file. 4 5#include "chrome/browser/browsing_data/mock_browsing_data_database_helper.h" 6 7#include "base/callback.h" 8#include "testing/gtest/include/gtest/gtest.h" 9 10MockBrowsingDataDatabaseHelper::MockBrowsingDataDatabaseHelper( 11 Profile* profile) 12 : BrowsingDataDatabaseHelper(profile) { 13} 14 15MockBrowsingDataDatabaseHelper::~MockBrowsingDataDatabaseHelper() { 16} 17 18void MockBrowsingDataDatabaseHelper::StartFetching( 19 const base::Callback<void(const std::list<DatabaseInfo>&)>& callback) { 20 ASSERT_FALSE(callback.is_null()); 21 ASSERT_TRUE(callback_.is_null()); 22 callback_ = callback; 23} 24 25void MockBrowsingDataDatabaseHelper::DeleteDatabase( 26 const std::string& origin, 27 const std::string& name) { 28 ASSERT_FALSE(callback_.is_null()); 29 std::string key = origin + ":" + name; 30 ASSERT_TRUE(databases_.find(key) != databases_.end()); 31 last_deleted_origin_ = origin; 32 last_deleted_db_ = name; 33 databases_[key] = false; 34} 35 36void MockBrowsingDataDatabaseHelper::AddDatabaseSamples() { 37 storage::DatabaseIdentifier id1 = 38 storage::DatabaseIdentifier::Parse("http_gdbhost1_1"); 39 response_.push_back(BrowsingDataDatabaseHelper::DatabaseInfo( 40 id1, "db1", "description 1", 1, base::Time())); 41 databases_["http_gdbhost1_1:db1"] = true; 42 storage::DatabaseIdentifier id2 = 43 storage::DatabaseIdentifier::Parse("http_gdbhost2_2"); 44 response_.push_back(BrowsingDataDatabaseHelper::DatabaseInfo( 45 id2, "db2", "description 2", 2, base::Time())); 46 databases_["http_gdbhost2_2:db2"] = true; 47} 48 49void MockBrowsingDataDatabaseHelper::Notify() { 50 callback_.Run(response_); 51} 52 53void MockBrowsingDataDatabaseHelper::Reset() { 54 for (std::map<const std::string, bool>::iterator i = databases_.begin(); 55 i != databases_.end(); ++i) 56 i->second = true; 57} 58 59bool MockBrowsingDataDatabaseHelper::AllDeleted() { 60 for (std::map<const std::string, bool>::const_iterator i = databases_.begin(); 61 i != databases_.end(); ++i) 62 if (i->second) 63 return false; 64 return true; 65} 66