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

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_;
29 }; 31 };
30 32
31 // Mock implementation of Javascript object proxy which logs events that 33 // Mock implementation of Javascript object proxy which logs events that
32 // would have been fired on it. Useful for tests where the sequence of 34 // would have been fired on it. Useful for tests where the sequence of
33 // notification events needs to be verified. 35 // notification events needs to be verified.
34 // 36 //
35 // |Logger| class provided in template must implement method 37 // |Logger| class provided in template must implement method
36 // static void log(string); 38 // static void log(string);
37 template<class Logger> 39 template<class Logger>
38 class LoggingNotificationProxyBase : public NotificationObjectProxy { 40 class LoggingNotificationDelegate : public NotificationDelegate {
39 public: 41 public:
40 LoggingNotificationProxyBase() : 42 explicit LoggingNotificationDelegate(std::string id)
41 NotificationObjectProxy(0, 0, 0, false) {} 43 : notification_id_(id) {
44 }
42 45
43 // NotificationObjectProxy override 46 // NotificationObjectProxy override
44 virtual void Display() { 47 virtual void Display() {
45 Logger::log("notification displayed\n"); 48 Logger::log("notification displayed\n");
46 } 49 }
47 virtual void Error() { 50 virtual void Error() {
48 Logger::log("notification error\n"); 51 Logger::log("notification error\n");
49 } 52 }
53 virtual void Click() {
54 Logger::log("notification clicked\n");
55 }
50 virtual void Close(bool by_user) { 56 virtual void Close(bool by_user) {
51 if (by_user) 57 if (by_user)
52 Logger::log("notification closed by user\n"); 58 Logger::log("notification closed by user\n");
53 else 59 else
54 Logger::log("notification closed by script\n"); 60 Logger::log("notification closed by script\n");
55 } 61 }
62 virtual std::string id() const {
63 return notification_id_;
64 }
65 private:
66 std::string notification_id_;
56 }; 67 };
oshima 2010/11/11 19:00:17 DISALLOW_COPY_AND_ASSIGN
John Gregg 2010/11/11 23:17:46 Done.
57 68
58 // Test version of a balloon view which doesn't do anything 69 // 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 70 // viewable, but does know how to close itself the same as a regular
60 // BalloonView. 71 // BalloonView.
61 class MockBalloonView : public BalloonView { 72 class MockBalloonView : public BalloonView {
62 public: 73 public:
63 explicit MockBalloonView(Balloon * balloon) : 74 explicit MockBalloonView(Balloon * balloon) :
64 balloon_(balloon) {} 75 balloon_(balloon) {}
65 void Show(Balloon* balloon) {} 76 void Show(Balloon* balloon) {}
66 void Update() {} 77 void Update() {}
67 void RepositionToBalloon() {} 78 void RepositionToBalloon() {}
68 void Close(bool by_user) { balloon_->OnClose(by_user); } 79 void Close(bool by_user) { balloon_->OnClose(by_user); }
69 gfx::Size GetSize() const { return balloon_->content_size(); } 80 gfx::Size GetSize() const { return balloon_->content_size(); }
70 BalloonHost* GetHost() const { return NULL; } 81 BalloonHost* GetHost() const { return NULL; }
71 82
72 private: 83 private:
73 // Non-owned pointer. 84 // Non-owned pointer.
74 Balloon* balloon_; 85 Balloon* balloon_;
75 }; 86 };
76 87
77 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_TEST_UTIL_H_ 88 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_TEST_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698