| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/browsing_data/mock_browsing_data_channel_id_helper.h" | 5 #include "chrome/browser/browsing_data/mock_browsing_data_channel_id_helper.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 MockBrowsingDataChannelIDHelper::MockBrowsingDataChannelIDHelper() | 14 MockBrowsingDataChannelIDHelper::MockBrowsingDataChannelIDHelper() |
| 15 : BrowsingDataChannelIDHelper() {} | 15 : BrowsingDataChannelIDHelper() {} |
| 16 | 16 |
| 17 MockBrowsingDataChannelIDHelper:: | 17 MockBrowsingDataChannelIDHelper:: |
| 18 ~MockBrowsingDataChannelIDHelper() {} | 18 ~MockBrowsingDataChannelIDHelper() {} |
| 19 | 19 |
| 20 void MockBrowsingDataChannelIDHelper::StartFetching( | 20 void MockBrowsingDataChannelIDHelper::StartFetching( |
| 21 const FetchResultCallback& callback) { | 21 const FetchResultCallback& callback) { |
| 22 ASSERT_FALSE(callback.is_null()); | 22 ASSERT_FALSE(callback.is_null()); |
| 23 ASSERT_TRUE(callback_.is_null()); | 23 ASSERT_TRUE(callback_.is_null()); |
| 24 callback_ = callback; | 24 callback_ = callback; |
| 25 } | 25 } |
| 26 | 26 |
| 27 void MockBrowsingDataChannelIDHelper::DeleteChannelID( | 27 void MockBrowsingDataChannelIDHelper::DeleteChannelID( |
| 28 const std::string& server_id) { | 28 const std::string& server_id) { |
| 29 ASSERT_FALSE(callback_.is_null()); | 29 ASSERT_FALSE(callback_.is_null()); |
| 30 ASSERT_TRUE(ContainsKey(channel_ids_, server_id)); | 30 ASSERT_TRUE(base::ContainsKey(channel_ids_, server_id)); |
| 31 channel_ids_[server_id] = false; | 31 channel_ids_[server_id] = false; |
| 32 } | 32 } |
| 33 | 33 |
| 34 void MockBrowsingDataChannelIDHelper::AddChannelIDSample( | 34 void MockBrowsingDataChannelIDHelper::AddChannelIDSample( |
| 35 const std::string& server_id) { | 35 const std::string& server_id) { |
| 36 ASSERT_FALSE(ContainsKey(channel_ids_, server_id)); | 36 ASSERT_FALSE(base::ContainsKey(channel_ids_, server_id)); |
| 37 std::unique_ptr<crypto::ECPrivateKey> key(crypto::ECPrivateKey::Create()); | 37 std::unique_ptr<crypto::ECPrivateKey> key(crypto::ECPrivateKey::Create()); |
| 38 channel_id_list_.push_back( | 38 channel_id_list_.push_back( |
| 39 net::ChannelIDStore::ChannelID(server_id, base::Time(), std::move(key))); | 39 net::ChannelIDStore::ChannelID(server_id, base::Time(), std::move(key))); |
| 40 channel_ids_[server_id] = true; | 40 channel_ids_[server_id] = true; |
| 41 } | 41 } |
| 42 | 42 |
| 43 void MockBrowsingDataChannelIDHelper::Notify() { | 43 void MockBrowsingDataChannelIDHelper::Notify() { |
| 44 net::ChannelIDStore::ChannelIDList channel_id_list; | 44 net::ChannelIDStore::ChannelIDList channel_id_list; |
| 45 for (const auto& channel_id : channel_id_list_) { | 45 for (const auto& channel_id : channel_id_list_) { |
| 46 if (channel_ids_.at(channel_id.server_identifier())) | 46 if (channel_ids_.at(channel_id.server_identifier())) |
| 47 channel_id_list.push_back(channel_id); | 47 channel_id_list.push_back(channel_id); |
| 48 } | 48 } |
| 49 callback_.Run(channel_id_list); | 49 callback_.Run(channel_id_list); |
| 50 } | 50 } |
| 51 | 51 |
| 52 void MockBrowsingDataChannelIDHelper::Reset() { | 52 void MockBrowsingDataChannelIDHelper::Reset() { |
| 53 for (auto& pair : channel_ids_) | 53 for (auto& pair : channel_ids_) |
| 54 pair.second = true; | 54 pair.second = true; |
| 55 } | 55 } |
| 56 | 56 |
| 57 bool MockBrowsingDataChannelIDHelper::AllDeleted() { | 57 bool MockBrowsingDataChannelIDHelper::AllDeleted() { |
| 58 for (const auto& pair : channel_ids_) { | 58 for (const auto& pair : channel_ids_) { |
| 59 if (pair.second) | 59 if (pair.second) |
| 60 return false; | 60 return false; |
| 61 } | 61 } |
| 62 return true; | 62 return true; |
| 63 } | 63 } |
| OLD | NEW |