Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / browsing_data / mock_browsing_data_database_helper.cc
blobcf53c37b18159ea0de57ecbe00b1d0935ec01abc
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.
5 #include "chrome/browser/browsing_data/mock_browsing_data_database_helper.h"
7 #include "base/callback.h"
8 #include "base/stl_util.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 MockBrowsingDataDatabaseHelper::MockBrowsingDataDatabaseHelper(
12 Profile* profile)
13 : BrowsingDataDatabaseHelper(profile) {
16 MockBrowsingDataDatabaseHelper::~MockBrowsingDataDatabaseHelper() {
19 void MockBrowsingDataDatabaseHelper::StartFetching(
20 const FetchCallback& callback) {
21 ASSERT_FALSE(callback.is_null());
22 ASSERT_TRUE(callback_.is_null());
23 callback_ = callback;
26 void MockBrowsingDataDatabaseHelper::DeleteDatabase(
27 const std::string& origin,
28 const std::string& name) {
29 ASSERT_FALSE(callback_.is_null());
30 std::string key = origin + ":" + name;
31 ASSERT_TRUE(ContainsKey(databases_, key));
32 last_deleted_origin_ = origin;
33 last_deleted_db_ = name;
34 databases_[key] = false;
37 void MockBrowsingDataDatabaseHelper::AddDatabaseSamples() {
38 storage::DatabaseIdentifier id1 =
39 storage::DatabaseIdentifier::Parse("http_gdbhost1_1");
40 response_.push_back(BrowsingDataDatabaseHelper::DatabaseInfo(
41 id1, "db1", "description 1", 1, base::Time()));
42 databases_["http_gdbhost1_1:db1"] = true;
43 storage::DatabaseIdentifier id2 =
44 storage::DatabaseIdentifier::Parse("http_gdbhost2_2");
45 response_.push_back(BrowsingDataDatabaseHelper::DatabaseInfo(
46 id2, "db2", "description 2", 2, base::Time()));
47 databases_["http_gdbhost2_2:db2"] = true;
50 void MockBrowsingDataDatabaseHelper::Notify() {
51 callback_.Run(response_);
54 void MockBrowsingDataDatabaseHelper::Reset() {
55 for (auto& pair : databases_)
56 pair.second = true;
59 bool MockBrowsingDataDatabaseHelper::AllDeleted() {
60 for (const auto& pair : databases_) {
61 if (pair.second)
62 return false;
64 return true;