blob: 19b1fd7c56d3a2508abae688b48d3501c9f9f491 [file] [log] [blame]
[email protected]8d167c22011-02-15 22:10:011// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]f83198c2010-03-16 09:30:322// 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_
[email protected]32b76ef2010-07-26 23:08:247#pragma once
[email protected]f83198c2010-03-16 09:30:328
[email protected]24c5013f2010-11-19 22:21:089#include <string>
10
[email protected]f83198c2010-03-16 09:30:3211#include "chrome/browser/notifications/notification_object_proxy.h"
12#include "chrome/browser/notifications/balloon.h"
[email protected]08397d52011-02-05 01:53:3813#include "ui/gfx/size.h"
[email protected]f83198c2010-03-16 09:30:3214
[email protected]38baba42010-11-04 21:12:0015// NotificationDelegate which does nothing, useful for testing when
16// the notification events are not important.
17class MockNotificationDelegate : public NotificationDelegate {
18 public:
[email protected]8d167c22011-02-15 22:10:0119 explicit MockNotificationDelegate(const std::string& id);
20 virtual ~MockNotificationDelegate();
[email protected]38baba42010-11-04 21:12:0021
22 // NotificationDelegate interface.
23 virtual void Display() {}
24 virtual void Error() {}
25 virtual void Close(bool by_user) {}
26 virtual void Click() {}
[email protected]8d167c22011-02-15 22:10:0127 virtual std::string id() const;
[email protected]38baba42010-11-04 21:12:0028
29 private:
30 std::string id_;
[email protected]24c5013f2010-11-19 22:21:0831
32 DISALLOW_COPY_AND_ASSIGN(MockNotificationDelegate);
[email protected]38baba42010-11-04 21:12:0033};
34
[email protected]f83198c2010-03-16 09:30:3235// Mock implementation of Javascript object proxy which logs events that
[email protected]38baba42010-11-04 21:12:0036// 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);
[email protected]f83198c2010-03-16 09:30:3241template<class Logger>
[email protected]24c5013f2010-11-19 22:21:0842class LoggingNotificationDelegate : public NotificationDelegate {
[email protected]f83198c2010-03-16 09:30:3243 public:
[email protected]24c5013f2010-11-19 22:21:0844 explicit LoggingNotificationDelegate(std::string id)
45 : notification_id_(id) {
46 }
[email protected]f83198c2010-03-16 09:30:3247
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 }
[email protected]24c5013f2010-11-19 22:21:0855 virtual void Click() {
56 Logger::log("notification clicked\n");
57 }
[email protected]f83198c2010-03-16 09:30:3258 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 }
[email protected]24c5013f2010-11-19 22:21:0864 virtual std::string id() const {
65 return notification_id_;
66 }
67 private:
68 std::string notification_id_;
69
70 DISALLOW_COPY_AND_ASSIGN(LoggingNotificationDelegate);
[email protected]f83198c2010-03-16 09:30:3271};
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) {}
[email protected]8d167c22011-02-15 22:10:0180
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;
[email protected]f83198c2010-03-16 09:30:3288
89 private:
90 // Non-owned pointer.
91 Balloon* balloon_;
92};
93
94#endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_TEST_UTIL_H_