1 // Copyright (c) 2012 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 8 #include <string> 9 10 #include "chrome/browser/notifications/notification_object_proxy.h" 11 #include "chrome/browser/notifications/balloon.h" 12 #include "ui/gfx/size.h" 13 14 // NotificationDelegate which does nothing, useful for testing when 15 // the notification events are not important. 16 class MockNotificationDelegate : public NotificationDelegate { 17 public: 18 explicit MockNotificationDelegate(const std::string& id); 19 20 // NotificationDelegate interface. 21 virtual void Display() OVERRIDE {} 22 virtual void Error() OVERRIDE {} 23 virtual void Close(bool by_user) OVERRIDE {} 24 virtual void Click() OVERRIDE {} 25 virtual std::string id() const OVERRIDE; 26 virtual content::RenderViewHost* GetRenderViewHost() const OVERRIDE; 27 28 private: 29 virtual ~MockNotificationDelegate(); 30 31 std::string id_; 32 33 DISALLOW_COPY_AND_ASSIGN(MockNotificationDelegate); 34 }; 35 36 // Mock implementation of Javascript object proxy which logs events that 37 // would have been fired on it. Useful for tests where the sequence of 38 // notification events needs to be verified. 39 // 40 // |Logger| class provided in template must implement method 41 // static void log(string); 42 template<class Logger> 43 class LoggingNotificationDelegate : public NotificationDelegate { 44 public: 45 explicit LoggingNotificationDelegate(std::string id) 46 : notification_id_(id) { 47 } 48 49 // NotificationObjectProxy override 50 virtual void Display() OVERRIDE { 51 Logger::log("notification displayed\n"); 52 } 53 virtual void Error() OVERRIDE { 54 Logger::log("notification error\n"); 55 } 56 virtual void Click() OVERRIDE { 57 Logger::log("notification clicked\n"); 58 } 59 virtual void ButtonClick(int index) OVERRIDE { 60 Logger::log("notification button clicked\n"); 61 } 62 virtual void Close(bool by_user) OVERRIDE { 63 if (by_user) 64 Logger::log("notification closed by user\n"); 65 else 66 Logger::log("notification closed by script\n"); 67 } 68 virtual std::string id() const OVERRIDE { 69 return notification_id_; 70 } 71 virtual content::RenderViewHost* GetRenderViewHost() const OVERRIDE { 72 return NULL; 73 } 74 75 private: 76 std::string notification_id_; 77 78 DISALLOW_COPY_AND_ASSIGN(LoggingNotificationDelegate); 79 }; 80 81 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_TEST_UTIL_H_ 82