Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / notifications / notification_test_util.cc
blob7961ea8cb1d6c838ffc3f04a51fc3cd1484dbc03
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 return nullptr;
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)
65 continue;
67 iter->first.delegate()->Close(false /* by_user */);
68 notifications_.erase(iter);
69 return true;
72 return false;
75 std::set<std::string>
76 StubNotificationUIManager::GetAllIdsByProfileAndSourceOrigin(
77 Profile* profile,
78 const GURL& source) {
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());
84 return delegate_ids;
87 bool StubNotificationUIManager::CancelAllBySourceOrigin(
88 const GURL& source_origin) {
89 NOTIMPLEMENTED();
90 return false;
93 bool StubNotificationUIManager::CancelAllByProfile(ProfileID profile_id) {
94 NOTIMPLEMENTED();
95 return false;
98 void StubNotificationUIManager::CancelAll() {
99 for (const auto& pair : notifications_)
100 pair.first.delegate()->Close(false /* by_user */);
101 notifications_.clear();