summaryrefslogtreecommitdiffstats
path: root/content/test/test_notification_tracker.cc
blob: 04de93f2251549b3c22ea115df51ca1d7776f23f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/test/test_notification_tracker.h"

#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h"

TestNotificationTracker::Event::Event()
    : type(content::NOTIFICATION_ALL),
      source(content::NotificationService::AllSources()),
      details(content::NotificationService::NoDetails()) {
}
TestNotificationTracker::Event::Event(int t,
                                      content::NotificationSource s,
                                      content::NotificationDetails d)
    : type(t),
      source(s),
      details(d) {
}

TestNotificationTracker::TestNotificationTracker() {
}

TestNotificationTracker::~TestNotificationTracker() {
}

void TestNotificationTracker::ListenFor(
    int type,
    const content::NotificationSource& source) {
  registrar_.Add(this, type, source);
}

void TestNotificationTracker::Reset() {
  events_.clear();
}

bool TestNotificationTracker::Check1AndReset(int type) {
  if (size() != 1) {
    Reset();
    return false;
  }
  bool success = events_[0].type == type;
  Reset();
  return success;
}

bool TestNotificationTracker::Check2AndReset(int type1,
                                             int type2) {
  if (size() != 2) {
    Reset();
    return false;
  }
  bool success = events_[0].type == type1 && events_[1].type == type2;
  Reset();
  return success;
}

bool TestNotificationTracker::Check3AndReset(int type1,
                                             int type2,
                                             int type3) {
  if (size() != 3) {
    Reset();
    return false;
  }
  bool success = events_[0].type == type1 &&
                 events_[1].type == type2 &&
                 events_[2].type == type3;
  Reset();
  return success;
}

void TestNotificationTracker::Observe(
    int type,
    const content::NotificationSource& source,
    const content::NotificationDetails& details) {
  events_.push_back(Event(type, source, details));
}