Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / chrome / browser / notifications / notification_test_util.cc
blob1cfdf9d5c04ae209b8493623dc32fc23cb23f29f
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/notifications/notification_test_util.h"
7 MockNotificationDelegate::MockNotificationDelegate(const std::string& id)
8 : id_(id) {}
10 MockNotificationDelegate::~MockNotificationDelegate() {}
12 std::string MockNotificationDelegate::id() const { return id_; }
14 // -----------------------------------------------------------------------------
16 StubNotificationUIManager::StubNotificationUIManager() {}
18 StubNotificationUIManager::~StubNotificationUIManager() {}
20 unsigned int StubNotificationUIManager::GetNotificationCount() const {
21 return notifications_.size();
24 const Notification& StubNotificationUIManager::GetNotificationAt(
25 unsigned int index) const {
26 DCHECK_GT(GetNotificationCount(), index);
27 return notifications_[index].first;
30 void StubNotificationUIManager::SetNotificationAddedCallback(
31 const base::Closure& callback) {
32 notification_added_callback_ = callback;
35 void StubNotificationUIManager::Add(const Notification& notification,
36 Profile* profile) {
37 notifications_.push_back(std::make_pair(notification, profile));
39 if (!notification_added_callback_.is_null()) {
40 notification_added_callback_.Run();
41 notification_added_callback_.Reset();
44 // Fire the Display() event on the delegate.
45 notification.delegate()->Display();
48 bool StubNotificationUIManager::Update(const Notification& notification,
49 Profile* profile) {
50 return false;
53 const Notification* StubNotificationUIManager::FindById(
54 const std::string& delegate_id,
55 ProfileID profile_id) const {
56 auto iter = notifications_.begin();
57 for (; iter != notifications_.end(); ++iter) {
58 if (iter->first.delegate_id() != delegate_id || iter->second != profile_id)
59 continue;
61 return &iter->first;
64 return nullptr;
67 bool StubNotificationUIManager::CancelById(const std::string& delegate_id,
68 ProfileID profile_id) {
69 auto iter = notifications_.begin();
70 for (; iter != notifications_.end(); ++iter) {
71 if (iter->first.delegate_id() != delegate_id ||
72 iter->second != profile_id)
73 continue;
75 iter->first.delegate()->Close(false /* by_user */);
76 notifications_.erase(iter);
77 return true;
80 return false;
83 std::set<std::string>
84 StubNotificationUIManager::GetAllIdsByProfileAndSourceOrigin(
85 Profile* profile,
86 const GURL& source) {
87 std::set<std::string> delegate_ids;
88 for (const auto& pair : notifications_) {
89 if (pair.second == profile && pair.first.origin_url() == source)
90 delegate_ids.insert(pair.first.delegate_id());
92 return delegate_ids;
95 std::set<std::string> StubNotificationUIManager::GetAllIdsByProfile(
96 Profile* profile) {
97 std::set<std::string> delegate_ids;
98 for (const auto& pair : notifications_) {
99 if (pair.second == profile)
100 delegate_ids.insert(pair.first.delegate_id());
102 return delegate_ids;
105 bool StubNotificationUIManager::CancelAllBySourceOrigin(
106 const GURL& source_origin) {
107 NOTIMPLEMENTED();
108 return false;
111 bool StubNotificationUIManager::CancelAllByProfile(ProfileID profile_id) {
112 NOTIMPLEMENTED();
113 return false;
116 void StubNotificationUIManager::CancelAll() {
117 for (const auto& pair : notifications_)
118 pair.first.delegate()->Close(false /* by_user */);
119 notifications_.clear();