Home | History | Annotate | Download | only in notifications
      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.
      4 
      5 #include "chrome/browser/notifications/notification_test_util.h"
      6 
      7 MockNotificationDelegate::MockNotificationDelegate(const std::string& id)
      8     : id_(id) {}
      9 
     10 MockNotificationDelegate::~MockNotificationDelegate() {}
     11 
     12 std::string MockNotificationDelegate::id() const { return id_; }
     13 
     14 content::WebContents* MockNotificationDelegate::GetWebContents() const {
     15   return NULL;
     16 }
     17 
     18 StubNotificationUIManager::StubNotificationUIManager(const GURL& welcome_origin)
     19     : notification_(GURL(),
     20                     GURL(),
     21                     base::string16(),
     22                     base::string16(),
     23                     blink::WebTextDirectionDefault,
     24                     base::string16(),
     25                     base::string16(),
     26                     new MockNotificationDelegate("stub")),
     27       welcome_origin_(welcome_origin),
     28       welcomed_(false),
     29       added_notifications_(0U) {}
     30 
     31 StubNotificationUIManager::~StubNotificationUIManager() {}
     32 
     33 void StubNotificationUIManager::Add(const Notification& notification,
     34                                     Profile* profile) {
     35   // Make a deep copy of the notification that we can inspect.
     36   notification_ = notification;
     37   profile_ = profile;
     38   ++added_notifications_;
     39 
     40   if (notification.origin_url() == welcome_origin_)
     41     welcomed_ = true;
     42 }
     43 
     44 bool StubNotificationUIManager::Update(const Notification& notification,
     45                                        Profile* profile) {
     46   // Make a deep copy of the notification that we can inspect.
     47   notification_ = notification;
     48   profile_ = profile;
     49   return true;
     50 }
     51 
     52 const Notification* StubNotificationUIManager::FindById(const std::string& id)
     53     const {
     54   return (notification_.id() == id) ? &notification_ : NULL;
     55 }
     56 
     57 bool StubNotificationUIManager::CancelById(const std::string& notification_id) {
     58   dismissed_id_ = notification_id;
     59   return true;
     60 }
     61 
     62 std::set<std::string>
     63 StubNotificationUIManager::GetAllIdsByProfileAndSourceOrigin(
     64     Profile* profile,
     65     const GURL& source) {
     66   std::set<std::string> notification_ids;
     67   if (source == notification_.origin_url() && profile->IsSameProfile(profile_))
     68     notification_ids.insert(notification_.delegate_id());
     69   return notification_ids;
     70 }
     71 
     72 bool StubNotificationUIManager::CancelAllBySourceOrigin(
     73     const GURL& source_origin) {
     74   return false;
     75 }
     76 
     77 bool StubNotificationUIManager::CancelAllByProfile(Profile* profile) {
     78   return false;
     79 }
     80 
     81 void StubNotificationUIManager::CancelAll() {}
     82