Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Side by Side Diff: chrome/browser/notifications/notification_test_util.h

Issue 4635007: When an extension is uninstalled, close all desktop notifications from that e... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_TEST_UTIL_H_ 5 #ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_TEST_UTIL_H_
6 #define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_TEST_UTIL_H_ 6 #define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_TEST_UTIL_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string>
10
9 #include "chrome/browser/notifications/notification_object_proxy.h" 11 #include "chrome/browser/notifications/notification_object_proxy.h"
10 #include "chrome/browser/notifications/balloon.h" 12 #include "chrome/browser/notifications/balloon.h"
11 #include "gfx/size.h" 13 #include "gfx/size.h"
12 14
13 // NotificationDelegate which does nothing, useful for testing when 15 // NotificationDelegate which does nothing, useful for testing when
14 // the notification events are not important. 16 // the notification events are not important.
15 class MockNotificationDelegate : public NotificationDelegate { 17 class MockNotificationDelegate : public NotificationDelegate {
16 public: 18 public:
17 explicit MockNotificationDelegate(std::string id) : id_(id) {} 19 explicit MockNotificationDelegate(const std::string& id) : id_(id) {}
18 virtual ~MockNotificationDelegate() {} 20 virtual ~MockNotificationDelegate() {}
19 21
20 // NotificationDelegate interface. 22 // NotificationDelegate interface.
21 virtual void Display() {} 23 virtual void Display() {}
22 virtual void Error() {} 24 virtual void Error() {}
23 virtual void Close(bool by_user) {} 25 virtual void Close(bool by_user) {}
24 virtual void Click() {} 26 virtual void Click() {}
25 virtual std::string id() const { return id_; } 27 virtual std::string id() const { return id_; }
26 28
27 private: 29 private:
28 std::string id_; 30 std::string id_;
31
32 DISALLOW_COPY_AND_ASSIGN(MockNotificationDelegate);
29 }; 33 };
30 34
31 // Mock implementation of Javascript object proxy which logs events that 35 // Mock implementation of Javascript object proxy which logs events that
32 // would have been fired on it. Useful for tests where the sequence of 36 // would have been fired on it. Useful for tests where the sequence of
33 // notification events needs to be verified. 37 // notification events needs to be verified.
34 // 38 //
35 // |Logger| class provided in template must implement method 39 // |Logger| class provided in template must implement method
36 // static void log(string); 40 // static void log(string);
37 template<class Logger> 41 template<class Logger>
38 class LoggingNotificationProxyBase : public NotificationObjectProxy { 42 class LoggingNotificationDelegate : public NotificationDelegate {
39 public: 43 public:
40 LoggingNotificationProxyBase() : 44 explicit LoggingNotificationDelegate(std::string id)
41 NotificationObjectProxy(0, 0, 0, false) {} 45 : notification_id_(id) {
46 }
42 47
43 // NotificationObjectProxy override 48 // NotificationObjectProxy override
44 virtual void Display() { 49 virtual void Display() {
45 Logger::log("notification displayed\n"); 50 Logger::log("notification displayed\n");
46 } 51 }
47 virtual void Error() { 52 virtual void Error() {
48 Logger::log("notification error\n"); 53 Logger::log("notification error\n");
49 } 54 }
55 virtual void Click() {
56 Logger::log("notification clicked\n");
57 }
50 virtual void Close(bool by_user) { 58 virtual void Close(bool by_user) {
51 if (by_user) 59 if (by_user)
52 Logger::log("notification closed by user\n"); 60 Logger::log("notification closed by user\n");
53 else 61 else
54 Logger::log("notification closed by script\n"); 62 Logger::log("notification closed by script\n");
55 } 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);
56 }; 71 };
57 72
58 // Test version of a balloon view which doesn't do anything 73 // Test version of a balloon view which doesn't do anything
59 // viewable, but does know how to close itself the same as a regular 74 // viewable, but does know how to close itself the same as a regular
60 // BalloonView. 75 // BalloonView.
61 class MockBalloonView : public BalloonView { 76 class MockBalloonView : public BalloonView {
62 public: 77 public:
63 explicit MockBalloonView(Balloon * balloon) : 78 explicit MockBalloonView(Balloon * balloon) :
64 balloon_(balloon) {} 79 balloon_(balloon) {}
65 void Show(Balloon* balloon) {} 80 void Show(Balloon* balloon) {}
66 void Update() {} 81 void Update() {}
67 void RepositionToBalloon() {} 82 void RepositionToBalloon() {}
68 void Close(bool by_user) { balloon_->OnClose(by_user); } 83 void Close(bool by_user) { balloon_->OnClose(by_user); }
69 gfx::Size GetSize() const { return balloon_->content_size(); } 84 gfx::Size GetSize() const { return balloon_->content_size(); }
70 BalloonHost* GetHost() const { return NULL; } 85 BalloonHost* GetHost() const { return NULL; }
71 86
72 private: 87 private:
73 // Non-owned pointer. 88 // Non-owned pointer.
74 Balloon* balloon_; 89 Balloon* balloon_;
75 }; 90 };
76 91
77 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_TEST_UTIL_H_ 92 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_TEST_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698