1// Copyright (c) 2011 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 "content/public/test/test_notification_tracker.h" 6 7#include "content/public/browser/notification_service.h" 8#include "content/public/browser/notification_types.h" 9 10namespace content { 11 12TestNotificationTracker::Event::Event() 13 : type(NOTIFICATION_ALL), 14 source(NotificationService::AllSources()), 15 details(NotificationService::NoDetails()) { 16} 17TestNotificationTracker::Event::Event(int t, 18 NotificationSource s, 19 NotificationDetails d) 20 : type(t), 21 source(s), 22 details(d) { 23} 24 25TestNotificationTracker::TestNotificationTracker() { 26} 27 28TestNotificationTracker::~TestNotificationTracker() { 29} 30 31void TestNotificationTracker::ListenFor( 32 int type, 33 const NotificationSource& source) { 34 registrar_.Add(this, type, source); 35} 36 37void TestNotificationTracker::Reset() { 38 events_.clear(); 39} 40 41bool TestNotificationTracker::Check1AndReset(int type) { 42 if (size() != 1) { 43 Reset(); 44 return false; 45 } 46 bool success = events_[0].type == type; 47 Reset(); 48 return success; 49} 50 51bool TestNotificationTracker::Check2AndReset(int type1, 52 int type2) { 53 if (size() != 2) { 54 Reset(); 55 return false; 56 } 57 bool success = events_[0].type == type1 && events_[1].type == type2; 58 Reset(); 59 return success; 60} 61 62bool TestNotificationTracker::Check3AndReset(int type1, 63 int type2, 64 int type3) { 65 if (size() != 3) { 66 Reset(); 67 return false; 68 } 69 bool success = events_[0].type == type1 && 70 events_[1].type == type2 && 71 events_[2].type == type3; 72 Reset(); 73 return success; 74} 75 76void TestNotificationTracker::Observe( 77 int type, 78 const NotificationSource& source, 79 const NotificationDetails& details) { 80 events_.push_back(Event(type, source, details)); 81} 82 83} // namespace content 84