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#ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_TEST_UTIL_H_
6#define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_TEST_UTIL_H_
7#pragma once
8
9#include <string>
10
11#include "chrome/browser/notifications/notification_object_proxy.h"
12#include "chrome/browser/notifications/balloon.h"
13#include "ui/gfx/size.h"
14
15// NotificationDelegate which does nothing, useful for testing when
16// the notification events are not important.
17class MockNotificationDelegate : public NotificationDelegate {
18 public:
19  explicit MockNotificationDelegate(const std::string& id);
20  virtual ~MockNotificationDelegate();
21
22  // NotificationDelegate interface.
23  virtual void Display() {}
24  virtual void Error() {}
25  virtual void Close(bool by_user) {}
26  virtual void Click() {}
27  virtual std::string id() const;
28
29 private:
30  std::string id_;
31
32  DISALLOW_COPY_AND_ASSIGN(MockNotificationDelegate);
33};
34
35// Mock implementation of Javascript object proxy which logs events that
36// would have been fired on it.  Useful for tests where the sequence of
37// notification events needs to be verified.
38//
39// |Logger| class provided in template must implement method
40// static void log(string);
41template<class Logger>
42class LoggingNotificationDelegate : public NotificationDelegate {
43 public:
44  explicit LoggingNotificationDelegate(std::string id)
45      : notification_id_(id) {
46  }
47
48  // NotificationObjectProxy override
49  virtual void Display() {
50    Logger::log("notification displayed\n");
51  }
52  virtual void Error() {
53    Logger::log("notification error\n");
54  }
55  virtual void Click() {
56    Logger::log("notification clicked\n");
57  }
58  virtual void Close(bool by_user) {
59    if (by_user)
60      Logger::log("notification closed by user\n");
61    else
62      Logger::log("notification closed by script\n");
63  }
64  virtual std::string id() const {
65    return notification_id_;
66  }
67 private:
68  std::string notification_id_;
69
70  DISALLOW_COPY_AND_ASSIGN(LoggingNotificationDelegate);
71};
72
73// Test version of a balloon view which doesn't do anything
74// viewable, but does know how to close itself the same as a regular
75// BalloonView.
76class MockBalloonView : public BalloonView {
77 public:
78  explicit MockBalloonView(Balloon * balloon) :
79      balloon_(balloon) {}
80
81  // BalloonView:
82  virtual void Show(Balloon* balloon) {}
83  virtual void Update() {}
84  virtual void RepositionToBalloon() {}
85  virtual void Close(bool by_user);
86  virtual gfx::Size GetSize() const;
87  virtual BalloonHost* GetHost() const;
88
89 private:
90  // Non-owned pointer.
91  Balloon* balloon_;
92};
93
94#endif  // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_TEST_UTIL_H_
95