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 {
59 bool StubNotificationUIManager::CancelById(const std::string
& delegate_id
,
60 ProfileID profile_id
) {
61 auto iter
= notifications_
.begin();
62 for (; iter
!= notifications_
.end(); ++iter
) {
63 if (iter
->first
.delegate_id() != delegate_id
||
64 iter
->second
!= profile_id
)
67 iter
->first
.delegate()->Close(false /* by_user */);
68 notifications_
.erase(iter
);
76 StubNotificationUIManager::GetAllIdsByProfileAndSourceOrigin(
79 std::set
<std::string
> delegate_ids
;
80 for (const auto& pair
: notifications_
) {
81 if (pair
.second
== profile
&& pair
.first
.origin_url() == source
)
82 delegate_ids
.insert(pair
.first
.delegate_id());
87 bool StubNotificationUIManager::CancelAllBySourceOrigin(
88 const GURL
& source_origin
) {
93 bool StubNotificationUIManager::CancelAllByProfile(ProfileID profile_id
) {
98 void StubNotificationUIManager::CancelAll() {
99 for (const auto& pair
: notifications_
)
100 pair
.first
.delegate()->Close(false /* by_user */);
101 notifications_
.clear();