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_browser_process.h"
19 #include "chrome/test/base/testing_profile.h"
20 #include "content/public/test/render_view_test.h"
21 #include "content/public/test/test_browser_thread.h"
22 #include "testing/gtest/include/gtest/gtest.h"
32 class ActiveDesktopMonitor
;
33 class DesktopNotificationsTest
;
34 typedef LoggingNotificationDelegate
<DesktopNotificationsTest
>
35 LoggingNotificationProxy
;
37 // Test version of the balloon collection which counts the number
38 // of notifications that are added to it.
39 class MockBalloonCollection
: public BalloonCollectionImpl
{
41 MockBalloonCollection();
42 virtual ~MockBalloonCollection();
44 // Our mock collection has an area large enough for a fixed number
46 static const int kMockBalloonSpace
;
47 int max_balloon_count() const { return kMockBalloonSpace
; }
49 // BalloonCollectionImpl overrides
50 virtual void Add(const Notification
& notification
,
51 Profile
* profile
) OVERRIDE
;
52 virtual bool HasSpace() const OVERRIDE
;
53 virtual Balloon
* MakeBalloon(const Notification
& notification
,
54 Profile
* profile
) OVERRIDE
;
55 virtual void DisplayChanged() OVERRIDE
{}
56 virtual void OnBalloonClosed(Balloon
* source
) OVERRIDE
;
57 virtual const BalloonCollection::Balloons
& GetActiveBalloons() OVERRIDE
;
59 // Number of balloons being shown.
60 std::deque
<Balloon
*>& balloons() { return balloons_
; }
61 int count() const { return balloons_
.size(); }
63 // Returns the highest y-coordinate of all the balloons in the collection.
64 int UppermostVerticalPosition();
66 // Returns the height bounds of a balloon.
67 int MinHeight() { return Layout::min_balloon_height(); }
68 int MaxHeight() { return Layout::max_balloon_height(); }
70 // Returns the bounding box.
71 gfx::Rect
GetBalloonsBoundingBox() {
72 return BalloonCollectionImpl::GetBalloonsBoundingBox();
76 std::deque
<Balloon
*> balloons_
;
79 class DesktopNotificationsTest
: public testing::Test
{
81 DesktopNotificationsTest();
82 virtual ~DesktopNotificationsTest();
84 static void log(const std::string
& message
) {
85 log_output_
.append(message
);
88 Profile
* profile() { return profile_
.get(); }
91 // testing::Test overrides
92 virtual void SetUp() OVERRIDE
;
93 virtual void TearDown() OVERRIDE
;
95 void AllowOrigin(const GURL
& origin
) {
96 service_
->GrantPermission(origin
);
99 void DenyOrigin(const GURL
& origin
) {
100 service_
->DenyPermission(origin
);
103 // Constructs a notification parameter structure for use in tests.
104 content::ShowDesktopNotificationHostMsgParams
StandardTestNotification();
106 // Must be first member. Because we're running a unit test in browser_tests
107 // we need to handle TestingBrowserProcess initialization ourselves.
108 TestingBrowserProcessInitializer initializer_
;
110 // Create a message loop to allow notifications code to post tasks,
111 // and a thread so that notifications code runs on the expected thread.
112 base::MessageLoopForUI message_loop_
;
113 content::TestBrowserThread ui_thread_
;
116 TestingPrefServiceSimple local_state_
;
119 scoped_ptr
<TestingProfile
> profile_
;
121 // Mock balloon collection -- owned by the NotificationUIManager
122 MockBalloonCollection
* balloon_collection_
;
125 scoped_ptr
<BalloonNotificationUIManager
> ui_manager_
;
127 // Real DesktopNotificationService
128 scoped_ptr
<DesktopNotificationService
> service_
;
130 // Contains the cumulative output of the unit test.
131 static std::string log_output_
;
134 #if defined(USE_AURA)
135 scoped_ptr
<views::corewm::WMState
> wm_state_
;
138 DISALLOW_COPY_AND_ASSIGN(DesktopNotificationsTest
);
141 #endif // CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATIONS_UNITTEST_H_