15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/notifications/notification_test_util.h" 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)MockNotificationDelegate::MockNotificationDelegate(const std::string& id) 85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) : id_(id) {} 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)MockNotificationDelegate::~MockNotificationDelegate() {} 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)std::string MockNotificationDelegate::id() const { return id_; } 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 140529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochcontent::WebContents* MockNotificationDelegate::GetWebContents() const { 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return NULL; 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)StubNotificationUIManager::StubNotificationUIManager(const GURL& welcome_origin) 195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) : notification_(GURL(), 205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) GURL(), 215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::string16(), 225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::string16(), 230529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch blink::WebTextDirectionDefault, 240529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch base::string16(), 250529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch base::string16(), 265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) new MockNotificationDelegate("stub")), 275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) welcome_origin_(welcome_origin), 285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) welcomed_(false), 295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) added_notifications_(0U) {} 305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)StubNotificationUIManager::~StubNotificationUIManager() {} 325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void StubNotificationUIManager::Add(const Notification& notification, 345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Profile* profile) { 355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Make a deep copy of the notification that we can inspect. 365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) notification_ = notification; 375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile_ = profile; 385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ++added_notifications_; 395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (notification.origin_url() == welcome_origin_) 415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) welcomed_ = true; 425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool StubNotificationUIManager::Update(const Notification& notification, 455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Profile* profile) { 465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Make a deep copy of the notification that we can inspect. 475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) notification_ = notification; 485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile_ = profile; 495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return true; 505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)const Notification* StubNotificationUIManager::FindById(const std::string& id) 535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const { 545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return (notification_.id() == id) ? ¬ification_ : NULL; 555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool StubNotificationUIManager::CancelById(const std::string& notification_id) { 585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) dismissed_id_ = notification_id; 595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return true; 605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)std::set<std::string> 635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)StubNotificationUIManager::GetAllIdsByProfileAndSourceOrigin( 645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Profile* profile, 655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const GURL& source) { 665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::set<std::string> notification_ids; 675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (source == notification_.origin_url() && profile->IsSameProfile(profile_)) 686d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) notification_ids.insert(notification_.delegate_id()); 695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return notification_ids; 705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool StubNotificationUIManager::CancelAllBySourceOrigin( 735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const GURL& source_origin) { 745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return false; 755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)bool StubNotificationUIManager::CancelAllByProfile(Profile* profile) { 785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return false; 795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void StubNotificationUIManager::CancelAll() {} 82