Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / browsing_data / mock_browsing_data_channel_id_helper.cc
blobe8a9a89ff7b12a388d5e3e7f6a930bbeb3226ece
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.
5 #include "chrome/browser/browsing_data/mock_browsing_data_channel_id_helper.h"
7 #include "base/logging.h"
8 #include "base/stl_util.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 MockBrowsingDataChannelIDHelper::MockBrowsingDataChannelIDHelper()
12 : BrowsingDataChannelIDHelper() {}
14 MockBrowsingDataChannelIDHelper::
15 ~MockBrowsingDataChannelIDHelper() {}
17 void MockBrowsingDataChannelIDHelper::StartFetching(
18 const FetchResultCallback& callback) {
19 ASSERT_FALSE(callback.is_null());
20 ASSERT_TRUE(callback_.is_null());
21 callback_ = callback;
24 void MockBrowsingDataChannelIDHelper::DeleteChannelID(
25 const std::string& server_id) {
26 ASSERT_FALSE(callback_.is_null());
27 ASSERT_TRUE(ContainsKey(channel_ids_, server_id));
28 channel_ids_[server_id] = false;
31 void MockBrowsingDataChannelIDHelper::AddChannelIDSample(
32 const std::string& server_id) {
33 ASSERT_FALSE(ContainsKey(channel_ids_, server_id));
34 scoped_ptr<crypto::ECPrivateKey> key(crypto::ECPrivateKey::Create());
35 channel_id_list_.push_back(
36 net::ChannelIDStore::ChannelID(server_id, base::Time(), key.Pass()));
37 channel_ids_[server_id] = true;
40 void MockBrowsingDataChannelIDHelper::Notify() {
41 net::ChannelIDStore::ChannelIDList channel_id_list;
42 for (const auto& channel_id : channel_id_list_) {
43 if (channel_ids_.at(channel_id.server_identifier()))
44 channel_id_list.push_back(channel_id);
46 callback_.Run(channel_id_list);
49 void MockBrowsingDataChannelIDHelper::Reset() {
50 for (auto& pair : channel_ids_)
51 pair.second = true;
54 bool MockBrowsingDataChannelIDHelper::AllDeleted() {
55 for (const auto& pair : channel_ids_) {
56 if (pair.second)
57 return false;
59 return true;