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

Unified Diff: chrome/browser/notifications/notification_test_util.h

Issue 787193002: Move logic for displaying notifications to the ProfileNotificationServiceImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@n-total
Patch Set: tests Created 6 years 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/notifications/notification_test_util.h
diff --git a/chrome/browser/notifications/notification_test_util.h b/chrome/browser/notifications/notification_test_util.h
index 9b308f736539c21f9c6874d67563694874e62906..cc46d4eed528fc76a2a5e9822b83c8cc4579ff93 100644
--- a/chrome/browser/notifications/notification_test_util.h
+++ b/chrome/browser/notifications/notification_test_util.h
@@ -7,13 +7,13 @@
#include <set>
#include <string>
+#include <utility>
+#include <vector>
#include "chrome/browser/notifications/notification.h"
-#include "chrome/browser/notifications/notification_object_proxy.h"
#include "chrome/browser/notifications/notification_ui_manager.h"
-#include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h"
-#include "chrome/browser/profiles/profile.h"
-#include "ui/gfx/size.h"
+
+class Profile;
// NotificationDelegate which does nothing, useful for testing when
// the notification events are not important.
@@ -32,96 +32,36 @@ class MockNotificationDelegate : public NotificationDelegate {
DISALLOW_COPY_AND_ASSIGN(MockNotificationDelegate);
};
-// Mock implementation of Javascript object proxy which logs events that
-// would have been fired on it. Useful for tests where the sequence of
-// notification events needs to be verified.
-//
-// |Logger| class provided in template must implement method
-// static void log(string);
-template<class Logger>
-class LoggingNotificationDelegate : public NotificationDelegate {
Peter Beverloo 2014/12/10 19:32:27 note: This was unused.
- public:
- explicit LoggingNotificationDelegate(std::string id) : notification_id_(id) {}
-
- // NotificationObjectProxy override
- virtual void Display() override {
- Logger::log("notification displayed\n");
- }
- virtual void Click() override {
- Logger::log("notification clicked\n");
- }
- virtual void ButtonClick(int index) override {
- Logger::log("notification button clicked\n");
- }
- virtual void Close(bool by_user) override {
- if (by_user)
- Logger::log("notification closed by user\n");
- else
- Logger::log("notification closed by script\n");
- }
- virtual std::string id() const override {
- return notification_id_;
- }
-
- private:
- std::string notification_id_;
-
- DISALLOW_COPY_AND_ASSIGN(LoggingNotificationDelegate);
-};
-
class StubNotificationUIManager : public NotificationUIManager {
Peter Beverloo 2014/12/10 19:32:27 note: This was unused, so I changed it to suit my
public:
- explicit StubNotificationUIManager(const GURL& welcome_origin);
+ StubNotificationUIManager();
~StubNotificationUIManager() override;
- // Adds a notification to be displayed. Virtual for unit test override.
+ // Returns the number of currently active notifications.
+ unsigned int GetNotificationCount() const;
+
+ // Returns a reference to the notification at index |index|.
+ const Notification& GetNotificationAt(unsigned int index) const;
+
+ // NotificationUIManager implementation.
void Add(const Notification& notification, Profile* profile) override;
bool Update(const Notification& notification, Profile* profile) override;
-
- // Returns NULL if no notifications match the supplied ID, either currently
- // displayed or in the queue.
const Notification* FindById(const std::string& delegate_id,
ProfileID profile_id) const override;
-
- // Removes any notifications matching the supplied ID, either currently
- // displayed or in the queue. Returns true if anything was removed.
bool CancelById(const std::string& delegate_id,
ProfileID profile_id) override;
-
- // Adds the delegate_id for each outstanding notification to the set
- // |delegate_ids| (must not be NULL).
std::set<std::string> GetAllIdsByProfileAndSourceOrigin(
Profile* profile,
const GURL& source) override;
-
- // Removes notifications matching the |source_origin| (which could be an
- // extension ID). Returns true if anything was removed.
bool CancelAllBySourceOrigin(const GURL& source_origin) override;
-
- // Removes notifications matching |profile|. Returns true if any were removed.
bool CancelAllByProfile(ProfileID profile_id) override;
-
- // Cancels all pending notifications and closes anything currently showing.
- // Used when the app is terminating.
void CancelAll() override;
- // Test hook to get the notification so we can check it
- const Notification& notification() const { return notification_; }
-
- // Test hook to check the ID of the last notification cancelled.
- std::string& dismissed_id() { return dismissed_id_; }
-
- size_t added_notifications() const { return added_notifications_; }
- bool welcomed() const { return welcomed_; }
-
private:
+ using NotificationPair = std::pair<Notification, ProfileID>;
+ std::vector<NotificationPair> notifications_;
+
DISALLOW_COPY_AND_ASSIGN(StubNotificationUIManager);
- Notification notification_;
- Profile* profile_;
- std::string dismissed_id_;
- GURL welcome_origin_;
- bool welcomed_;
- size_t added_notifications_;
};
#endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_TEST_UTIL_H_
« no previous file with comments | « chrome/browser/notifications/desktop_notification_service.cc ('k') | chrome/browser/notifications/notification_test_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698