Adding instrumentation to locate the source of jankiness
[chromium-blink-merge.git] / chrome / browser / notifications / notification_test_util.cc
blobfa8bdd4ab1ec7444c2a5d4f1aa6666601704a9a0
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 // TODO(peter): |notification_| should be initialized with the correct origin.
15 StubNotificationUIManager::StubNotificationUIManager(const GURL& welcome_origin)
16 : notification_(GURL(),
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) {
29 StubNotificationUIManager::~StubNotificationUIManager() {}
31 void StubNotificationUIManager::Add(const Notification& notification,
32 Profile* profile) {
33 // Make a deep copy of the notification that we can inspect.
34 notification_ = notification;
35 profile_ = profile;
36 ++added_notifications_;
38 if (notification.origin_url() == welcome_origin_)
39 welcomed_ = true;
42 bool StubNotificationUIManager::Update(const Notification& notification,
43 Profile* profile) {
44 // Make a deep copy of the notification that we can inspect.
45 notification_ = notification;
46 profile_ = profile;
47 return true;
50 const Notification* StubNotificationUIManager::FindById(
51 const std::string& delegate_id,
52 ProfileID profile_id) const {
53 if (notification_.delegate_id() == delegate_id && profile_ == profile_id)
54 return &notification_;
55 else
56 return NULL;
59 bool StubNotificationUIManager::CancelById(const std::string& delegate_id,
60 ProfileID profile_id) {
61 dismissed_id_ = delegate_id;
62 return true;
65 std::set<std::string>
66 StubNotificationUIManager::GetAllIdsByProfileAndSourceOrigin(
67 Profile* profile,
68 const GURL& source) {
69 std::set<std::string> delegate_ids;
70 if (source == notification_.origin_url() && profile->IsSameProfile(profile_))
71 delegate_ids.insert(notification_.delegate_id());
72 return delegate_ids;
75 bool StubNotificationUIManager::CancelAllBySourceOrigin(
76 const GURL& source_origin) {
77 return false;
80 bool StubNotificationUIManager::CancelAllByProfile(ProfileID profile_id) {
81 return false;
84 void StubNotificationUIManager::CancelAll() {}