1// Copyright 2014 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_channel_id_helper.h"
6
7#include "base/logging.h"
8#include "testing/gtest/include/gtest/gtest.h"
9
10MockBrowsingDataChannelIDHelper::MockBrowsingDataChannelIDHelper()
11    : BrowsingDataChannelIDHelper() {}
12
13MockBrowsingDataChannelIDHelper::
14~MockBrowsingDataChannelIDHelper() {}
15
16void MockBrowsingDataChannelIDHelper::StartFetching(
17    const FetchResultCallback& callback) {
18  ASSERT_FALSE(callback.is_null());
19  ASSERT_TRUE(callback_.is_null());
20  callback_ = callback;
21}
22
23void MockBrowsingDataChannelIDHelper::DeleteChannelID(
24    const std::string& server_id) {
25  ASSERT_FALSE(callback_.is_null());
26  ASSERT_TRUE(channel_ids_.find(server_id) != channel_ids_.end());
27  channel_ids_[server_id] = false;
28}
29
30void MockBrowsingDataChannelIDHelper::AddChannelIDSample(
31    const std::string& server_id) {
32  ASSERT_TRUE(channel_ids_.find(server_id) == channel_ids_.end());
33  channel_id_list_.push_back(
34      net::ChannelIDStore::ChannelID(
35          server_id, base::Time(), base::Time(), "key", "cert"));
36  channel_ids_[server_id] = true;
37}
38
39void MockBrowsingDataChannelIDHelper::Notify() {
40  net::ChannelIDStore::ChannelIDList channel_id_list;
41  for (net::ChannelIDStore::ChannelIDList::iterator i =
42       channel_id_list_.begin();
43       i != channel_id_list_.end(); ++i) {
44    if (channel_ids_[i->server_identifier()])
45      channel_id_list.push_back(*i);
46  }
47  callback_.Run(channel_id_list);
48}
49
50void MockBrowsingDataChannelIDHelper::Reset() {
51  for (std::map<const std::string, bool>::iterator i =
52       channel_ids_.begin();
53       i != channel_ids_.end(); ++i)
54    i->second = true;
55}
56
57bool MockBrowsingDataChannelIDHelper::AllDeleted() {
58  for (std::map<const std::string, bool>::const_iterator i =
59       channel_ids_.begin();
60       i != channel_ids_.end(); ++i)
61    if (i->second)
62      return false;
63  return true;
64}
65