OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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_DESKTOP_NOTIFICATIONS_UNITTEST_H_ | 5 #ifndef CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATIONS_UNITTEST_H_ |
6 #define CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATIONS_UNITTEST_H_ | 6 #define CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATIONS_UNITTEST_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/prefs/testing_pref_service.h" | 12 #include "base/prefs/testing_pref_service.h" |
13 #include "chrome/browser/notifications/balloon_collection_impl.h" | 13 #include "chrome/browser/notifications/balloon_collection_impl.h" |
14 #include "chrome/browser/notifications/balloon_notification_ui_manager.h" | 14 #include "chrome/browser/notifications/balloon_notification_ui_manager.h" |
15 #include "chrome/browser/notifications/desktop_notification_service.h" | 15 #include "chrome/browser/notifications/desktop_notification_service.h" |
16 #include "chrome/browser/notifications/notification.h" | 16 #include "chrome/browser/notifications/notification.h" |
17 #include "chrome/browser/notifications/notification_test_util.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" | 18 #include "content/public/test/test_browser_thread.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "ui/message_center/message_center_util.h" |
| 21 |
| 22 #if defined(USE_AURA) |
| 23 #include "ui/aura/test/aura_test_helper.h" |
| 24 #include "ui/views/test/desktop_test_views_delegate.h" |
| 25 #endif |
22 | 26 |
23 class ActiveDesktopMonitor; | 27 class ActiveDesktopMonitor; |
24 class DesktopNotificationsTest; | 28 class DesktopNotificationsTest; |
25 typedef LoggingNotificationDelegate<DesktopNotificationsTest> | 29 typedef LoggingNotificationDelegate<DesktopNotificationsTest> |
26 LoggingNotificationProxy; | 30 LoggingNotificationProxy; |
| 31 class TestingProfileManager; |
| 32 class TestingProfile; |
| 33 |
| 34 #if !defined(RUN_MESSAGE_CENTER_TESTS) |
27 | 35 |
28 // Test version of the balloon collection which counts the number | 36 // Test version of the balloon collection which counts the number |
29 // of notifications that are added to it. | 37 // of notifications that are added to it. |
30 class MockBalloonCollection : public BalloonCollectionImpl { | 38 class MockBalloonCollection : public BalloonCollectionImpl { |
31 public: | 39 public: |
32 MockBalloonCollection(); | 40 MockBalloonCollection(); |
33 virtual ~MockBalloonCollection(); | 41 virtual ~MockBalloonCollection(); |
34 | 42 |
35 // Our mock collection has an area large enough for a fixed number | 43 // Our mock collection has an area large enough for a fixed number |
36 // of balloons. | 44 // of balloons. |
(...skipping 23 matching lines...) Expand all Loading... |
60 | 68 |
61 // Returns the bounding box. | 69 // Returns the bounding box. |
62 gfx::Rect GetBalloonsBoundingBox() { | 70 gfx::Rect GetBalloonsBoundingBox() { |
63 return BalloonCollectionImpl::GetBalloonsBoundingBox(); | 71 return BalloonCollectionImpl::GetBalloonsBoundingBox(); |
64 } | 72 } |
65 | 73 |
66 private: | 74 private: |
67 std::deque<Balloon*> balloons_; | 75 std::deque<Balloon*> balloons_; |
68 }; | 76 }; |
69 | 77 |
| 78 #endif // !defined(RUN_MESSAGE_CENTER_TESTS) |
| 79 |
70 class DesktopNotificationsTest : public testing::Test { | 80 class DesktopNotificationsTest : public testing::Test { |
71 public: | 81 public: |
72 DesktopNotificationsTest(); | 82 DesktopNotificationsTest(); |
73 virtual ~DesktopNotificationsTest(); | 83 virtual ~DesktopNotificationsTest(); |
74 | 84 |
75 static void log(const std::string& message) { | 85 static void log(const std::string& message); |
76 log_output_.append(message); | |
77 } | |
78 | 86 |
79 Profile* profile() { return profile_.get(); } | 87 TestingProfile* profile() { return profile_; } |
80 | 88 |
81 protected: | 89 protected: |
82 // testing::Test overrides | 90 // testing::Test overrides |
83 virtual void SetUp() OVERRIDE; | 91 virtual void SetUp() OVERRIDE; |
84 virtual void TearDown() OVERRIDE; | 92 virtual void TearDown() OVERRIDE; |
85 | 93 |
86 void AllowOrigin(const GURL& origin) { | 94 void AllowOrigin(const GURL& origin) { |
87 service_->GrantPermission(origin); | 95 service_->GrantPermission(origin); |
88 } | 96 } |
89 | 97 |
90 void DenyOrigin(const GURL& origin) { | 98 void DenyOrigin(const GURL& origin) { |
91 service_->DenyPermission(origin); | 99 service_->DenyPermission(origin); |
92 } | 100 } |
93 | 101 |
| 102 int GetNotificationCount(); |
| 103 |
94 // Constructs a notification parameter structure for use in tests. | 104 // Constructs a notification parameter structure for use in tests. |
95 content::ShowDesktopNotificationHostMsgParams StandardTestNotification(); | 105 content::ShowDesktopNotificationHostMsgParams StandardTestNotification(); |
96 | 106 |
97 // Create a message loop to allow notifications code to post tasks, | 107 // Create a message loop to allow notifications code to post tasks, |
98 // and a thread so that notifications code runs on the expected thread. | 108 // and a thread so that notifications code runs on the expected thread. |
99 base::MessageLoopForUI message_loop_; | 109 base::MessageLoopForUI message_loop_; |
100 content::TestBrowserThread ui_thread_; | 110 content::TestBrowserThread ui_thread_; |
101 | 111 |
| 112 #if defined(USE_AURA) |
| 113 // Used to create the Aura environment for testing. |
| 114 aura::test::AuraTestHelper aura_test_helper_; |
| 115 views::DesktopTestViewsDelegate views_delegate_; |
| 116 #endif |
| 117 |
102 // Local state mock. | 118 // Local state mock. |
103 TestingPrefServiceSimple local_state_; | 119 TestingPrefServiceSimple local_state_; |
104 | 120 |
105 // Test profile. | 121 // Creator of profiles. |
106 scoped_ptr<TestingProfile> profile_; | 122 scoped_ptr<TestingProfileManager> profile_manager_; |
107 | 123 |
| 124 // Default profile created from profile_manager_. |
| 125 TestingProfile* profile_; |
| 126 |
| 127 #if !defined(RUN_MESSAGE_CENTER_TESTS) |
108 // Mock balloon collection -- owned by the NotificationUIManager | 128 // Mock balloon collection -- owned by the NotificationUIManager |
109 MockBalloonCollection* balloon_collection_; | 129 MockBalloonCollection* balloon_collection_; |
| 130 #endif |
110 | 131 |
111 // Real UI manager. | 132 // Real UI manager. |
112 scoped_ptr<BalloonNotificationUIManager> ui_manager_; | 133 scoped_ptr<NotificationUIManager> ui_manager_; |
113 | 134 |
114 // Real DesktopNotificationService | 135 // Real DesktopNotificationService |
115 scoped_ptr<DesktopNotificationService> service_; | 136 scoped_ptr<DesktopNotificationService> service_; |
116 | 137 |
117 // Contains the cumulative output of the unit test. | 138 // Contains the cumulative output of the unit test. |
118 static std::string log_output_; | 139 static std::string log_output_; |
119 }; | 140 }; |
120 | 141 |
121 #endif // CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATIONS_UNITTEST_H_ | 142 #endif // CHROME_BROWSER_NOTIFICATIONS_DESKTOP_NOTIFICATIONS_UNITTEST_H_ |
OLD | NEW |