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
)
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
,
37 notifications_
.push_back(std::make_pair(
38 notification
, NotificationUIManager::GetProfileID(profile
)));
40 if (!notification_added_callback_
.is_null()) {
41 notification_added_callback_
.Run();
42 notification_added_callback_
.Reset();
45 // Fire the Display() event on the delegate.
46 notification
.delegate()->Display();
49 bool StubNotificationUIManager::Update(const Notification
& notification
,
54 const Notification
* StubNotificationUIManager::FindById(
55 const std::string
& delegate_id
,
56 ProfileID profile_id
) const {
57 auto iter
= notifications_
.begin();
58 for (; iter
!= notifications_
.end(); ++iter
) {
59 if (iter
->first
.delegate_id() != delegate_id
|| iter
->second
!= profile_id
)
68 bool StubNotificationUIManager::CancelById(const std::string
& delegate_id
,
69 ProfileID profile_id
) {
70 auto iter
= notifications_
.begin();
71 for (; iter
!= notifications_
.end(); ++iter
) {
72 if (iter
->first
.delegate_id() != delegate_id
||
73 iter
->second
!= profile_id
)
76 iter
->first
.delegate()->Close(false /* by_user */);
77 notifications_
.erase(iter
);
85 StubNotificationUIManager::GetAllIdsByProfileAndSourceOrigin(
88 std::set
<std::string
> delegate_ids
;
89 for (const auto& pair
: notifications_
) {
90 if (pair
.second
== profile_id
&& pair
.first
.origin_url() == source
)
91 delegate_ids
.insert(pair
.first
.delegate_id());
96 std::set
<std::string
> StubNotificationUIManager::GetAllIdsByProfile(
97 ProfileID profile_id
) {
98 std::set
<std::string
> delegate_ids
;
99 for (const auto& pair
: notifications_
) {
100 if (pair
.second
== profile_id
)
101 delegate_ids
.insert(pair
.first
.delegate_id());
106 bool StubNotificationUIManager::CancelAllBySourceOrigin(
107 const GURL
& source_origin
) {
112 bool StubNotificationUIManager::CancelAllByProfile(ProfileID profile_id
) {
117 void StubNotificationUIManager::CancelAll() {
118 for (const auto& pair
: notifications_
)
119 pair
.first
.delegate()->Close(false /* by_user */);
120 notifications_
.clear();