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(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
,
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
)
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
)
75 iter
->first
.delegate()->Close(false /* by_user */);
76 notifications_
.erase(iter
);
84 StubNotificationUIManager::GetAllIdsByProfileAndSourceOrigin(
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());
95 std::set
<std::string
> StubNotificationUIManager::GetAllIdsByProfile(
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());
105 bool StubNotificationUIManager::CancelAllBySourceOrigin(
106 const GURL
& source_origin
) {
111 bool StubNotificationUIManager::CancelAllByProfile(ProfileID profile_id
) {
116 void StubNotificationUIManager::CancelAll() {
117 for (const auto& pair
: notifications_
)
118 pair
.first
.delegate()->Close(false /* by_user */);
119 notifications_
.clear();