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.
5 #ifndef CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATIONS_UNITTEST_H_
6 #define CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATIONS_UNITTEST_H_
11 #include "base/message_loop/message_loop.h"
12 #include "base/prefs/testing_pref_service.h"
13 #include "chrome/browser/notifications/balloon_collection_impl.h"
14 #include "chrome/browser/notifications/balloon_notification_ui_manager.h"
15 #include "chrome/browser/notifications/desktop_notification_service.h"
16 #include "chrome/browser/notifications/notification.h"
17 #include "chrome/browser/notifications/notification_test_util.h"
18 #include "chrome/test/base/testing_profile.h"
19 #include "content/public/test/render_view_test.h"
20 #include "content/public/test/test_browser_thread.h"
21 #include "testing/gtest/include/gtest/gtest.h"
23 class ActiveDesktopMonitor;
24 class DesktopNotificationsTest;
25 typedef LoggingNotificationDelegate<DesktopNotificationsTest>
26 LoggingNotificationProxy;
28 // Test version of the balloon collection which counts the number
29 // of notifications that are added to it.
30 class MockBalloonCollection : public BalloonCollectionImpl {
32 MockBalloonCollection();
33 virtual ~MockBalloonCollection();
35 // Our mock collection has an area large enough for a fixed number
37 static const int kMockBalloonSpace;
38 int max_balloon_count() const { return kMockBalloonSpace; }
40 // BalloonCollectionImpl overrides
41 virtual void Add(const Notification& notification,
42 Profile* profile) OVERRIDE;
43 virtual bool HasSpace() const OVERRIDE;
44 virtual Balloon* MakeBalloon(const Notification& notification,
45 Profile* profile) OVERRIDE;
46 virtual void DisplayChanged() OVERRIDE {}
47 virtual void OnBalloonClosed(Balloon* source) OVERRIDE;
48 virtual const BalloonCollection::Balloons& GetActiveBalloons() OVERRIDE;
50 // Number of balloons being shown.
51 std::deque<Balloon*>& balloons() { return balloons_; }
52 int count() const { return balloons_.size(); }
54 // Returns the highest y-coordinate of all the balloons in the collection.
55 int UppermostVerticalPosition();
57 // Returns the height bounds of a balloon.
58 int MinHeight() { return Layout::min_balloon_height(); }
59 int MaxHeight() { return Layout::max_balloon_height(); }
61 // Returns the bounding box.
62 gfx::Rect GetBalloonsBoundingBox() {
63 return BalloonCollectionImpl::GetBalloonsBoundingBox();
67 std::deque<Balloon*> balloons_;
70 class DesktopNotificationsTest : public testing::Test {
72 DesktopNotificationsTest();
73 virtual ~DesktopNotificationsTest();
75 static void log(const std::string& message) {
76 log_output_.append(message);
79 Profile* profile() { return profile_.get(); }
82 // testing::Test overrides
83 virtual void SetUp() OVERRIDE;
84 virtual void TearDown() OVERRIDE;
86 void AllowOrigin(const GURL& origin) {
87 service_->GrantPermission(origin);
90 void DenyOrigin(const GURL& origin) {
91 service_->DenyPermission(origin);
94 // Constructs a notification parameter structure for use in tests.
95 content::ShowDesktopNotificationHostMsgParams StandardTestNotification();
97 // Create a message loop to allow notifications code to post tasks,
98 // and a thread so that notifications code runs on the expected thread.
99 base::MessageLoopForUI message_loop_;
100 content::TestBrowserThread ui_thread_;
103 TestingPrefServiceSimple local_state_;
106 scoped_ptr<TestingProfile> profile_;
108 // Mock balloon collection -- owned by the NotificationUIManager
109 MockBalloonCollection* balloon_collection_;
112 scoped_ptr<BalloonNotificationUIManager> ui_manager_;
114 // Real DesktopNotificationService
115 scoped_ptr<DesktopNotificationService> service_;
117 // Contains the cumulative output of the unit test.
118 static std::string log_output_;
121 #endif // CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATIONS_UNITTEST_H_