Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(360)

Side by Side Diff: chrome/browser/notifications/notification_test_util.cc

Issue 787193002: Move logic for displaying notifications to the ProfileNotificationServiceImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@n-total
Patch Set: tests Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/notifications/notification_test_util.h" 5 #include "chrome/browser/notifications/notification_test_util.h"
6 6
7 MockNotificationDelegate::MockNotificationDelegate(const std::string& id) 7 MockNotificationDelegate::MockNotificationDelegate(const std::string& id)
8 : id_(id) {} 8 : id_(id) {}
9 9
10 MockNotificationDelegate::~MockNotificationDelegate() {} 10 MockNotificationDelegate::~MockNotificationDelegate() {}
11 11
12 std::string MockNotificationDelegate::id() const { return id_; } 12 std::string MockNotificationDelegate::id() const { return id_; }
13 13
14 // TODO(peter): |notification_| should be initialized with the correct origin. 14 // -----------------------------------------------------------------------------
15 StubNotificationUIManager::StubNotificationUIManager(const GURL& welcome_origin) 15
16 : notification_(GURL(), 16 StubNotificationUIManager::StubNotificationUIManager() {}
17 base::string16(),
18 base::string16(),
19 gfx::Image(),
20 base::string16(),
21 base::string16(),
22 new MockNotificationDelegate("stub")),
23 profile_(NULL),
24 welcome_origin_(welcome_origin),
25 welcomed_(false),
26 added_notifications_(0U) {
27 }
28 17
29 StubNotificationUIManager::~StubNotificationUIManager() {} 18 StubNotificationUIManager::~StubNotificationUIManager() {}
30 19
20 unsigned int StubNotificationUIManager::GetNotificationCount() const {
21 return notifications_.size();
22 }
23
24 const Notification& StubNotificationUIManager::GetNotificationAt(
25 unsigned int index) const {
26 DCHECK_GT(GetNotificationCount(), index);
27 return notifications_[index].first;
28 }
29
31 void StubNotificationUIManager::Add(const Notification& notification, 30 void StubNotificationUIManager::Add(const Notification& notification,
32 Profile* profile) { 31 Profile* profile) {
33 // Make a deep copy of the notification that we can inspect. 32 notifications_.push_back(std::make_pair(notification, profile));
34 notification_ = notification;
35 profile_ = profile;
36 ++added_notifications_;
37 33
38 if (notification.origin_url() == welcome_origin_) 34 // Fire the Display() event on the delegate.
39 welcomed_ = true; 35 notification.delegate()->Display();
40 } 36 }
41 37
42 bool StubNotificationUIManager::Update(const Notification& notification, 38 bool StubNotificationUIManager::Update(const Notification& notification,
43 Profile* profile) { 39 Profile* profile) {
44 // Make a deep copy of the notification that we can inspect. 40 return false;
45 notification_ = notification;
46 profile_ = profile;
47 return true;
48 } 41 }
49 42
50 const Notification* StubNotificationUIManager::FindById( 43 const Notification* StubNotificationUIManager::FindById(
51 const std::string& delegate_id, 44 const std::string& delegate_id,
52 ProfileID profile_id) const { 45 ProfileID profile_id) const {
53 if (notification_.delegate_id() == delegate_id && profile_ == profile_id) 46 return nullptr;
54 return &notification_;
55 else
56 return NULL;
57 } 47 }
58 48
59 bool StubNotificationUIManager::CancelById(const std::string& delegate_id, 49 bool StubNotificationUIManager::CancelById(const std::string& delegate_id,
60 ProfileID profile_id) { 50 ProfileID profile_id) {
61 dismissed_id_ = delegate_id; 51 auto iter = notifications_.begin();
62 return true; 52 for (; iter != notifications_.end(); ++iter) {
53 if (iter->first.delegate_id() != delegate_id ||
54 iter->second != profile_id)
55 continue;
56
57 iter->first.delegate()->Close(false /* by_user */);
58 notifications_.erase(iter);
59 return true;
60 }
61
62 return false;
63 } 63 }
64 64
65 std::set<std::string> 65 std::set<std::string>
66 StubNotificationUIManager::GetAllIdsByProfileAndSourceOrigin( 66 StubNotificationUIManager::GetAllIdsByProfileAndSourceOrigin(
67 Profile* profile, 67 Profile* profile,
68 const GURL& source) { 68 const GURL& source) {
69 std::set<std::string> delegate_ids; 69 return std::set<std::string>();
70 if (source == notification_.origin_url() && profile->IsSameProfile(profile_))
71 delegate_ids.insert(notification_.delegate_id());
72 return delegate_ids;
73 } 70 }
74 71
75 bool StubNotificationUIManager::CancelAllBySourceOrigin( 72 bool StubNotificationUIManager::CancelAllBySourceOrigin(
76 const GURL& source_origin) { 73 const GURL& source_origin) {
77 return false; 74 return false;
78 } 75 }
79 76
80 bool StubNotificationUIManager::CancelAllByProfile(ProfileID profile_id) { 77 bool StubNotificationUIManager::CancelAllByProfile(ProfileID profile_id) {
81 return false; 78 return false;
82 } 79 }
83 80
84 void StubNotificationUIManager::CancelAll() {} 81 void StubNotificationUIManager::CancelAll() {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698