OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "base/message_loop.h" | 5 #include "base/message_loop.h" |
6 #include "base/ref_counted.h" | 6 #include "base/ref_counted.h" |
7 #include "chrome/browser/browser.h" | 7 #include "chrome/browser/browser.h" |
8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
9 #include "chrome/browser/chromeos/notifications/balloon_collection_impl.h" | 9 #include "chrome/browser/chromeos/notifications/balloon_collection_impl.h" |
10 #include "chrome/browser/chromeos/notifications/notification_panel.h" | 10 #include "chrome/browser/chromeos/notifications/notification_panel.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 EXPECT_EQ(0, tester->GetStickyNotificationCount()); | 71 EXPECT_EQ(0, tester->GetStickyNotificationCount()); |
72 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); | 72 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); |
73 | 73 |
74 collection->Add(NewMockNotification("2"), browser()->profile()); | 74 collection->Add(NewMockNotification("2"), browser()->profile()); |
75 | 75 |
76 EXPECT_EQ(2, tester->GetNewNotificationCount()); | 76 EXPECT_EQ(2, tester->GetNewNotificationCount()); |
77 EXPECT_EQ(2, tester->GetNotificationCount()); | 77 EXPECT_EQ(2, tester->GetNotificationCount()); |
78 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); | 78 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); |
79 | 79 |
80 collection->Remove(NewMockNotification("1")); | 80 collection->Remove(NewMockNotification("1")); |
81 RunAllPendingEvents(); | 81 ui_test_utils::RunAllPendingInMessageLoop(); |
82 | 82 |
83 EXPECT_EQ(1, tester->GetNewNotificationCount()); | 83 EXPECT_EQ(1, tester->GetNewNotificationCount()); |
84 EXPECT_EQ(1, tester->GetNotificationCount()); | 84 EXPECT_EQ(1, tester->GetNotificationCount()); |
85 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); | 85 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); |
86 | 86 |
87 collection->Remove(NewMockNotification("2")); | 87 collection->Remove(NewMockNotification("2")); |
88 RunAllPendingEvents(); | 88 ui_test_utils::RunAllPendingInMessageLoop(); |
89 EXPECT_EQ(0, tester->GetNewNotificationCount()); | 89 EXPECT_EQ(0, tester->GetNewNotificationCount()); |
90 EXPECT_EQ(0, tester->GetNotificationCount()); | 90 EXPECT_EQ(0, tester->GetNotificationCount()); |
91 EXPECT_EQ(NotificationPanel::CLOSED, tester->state()); | 91 EXPECT_EQ(NotificationPanel::CLOSED, tester->state()); |
92 } | 92 } |
93 | 93 |
94 // [CLOSED] -add->[STICKY_AND_NEW] -mouse-> [KEEP_SIZE] -remove-> | 94 // [CLOSED] -add->[STICKY_AND_NEW] -mouse-> [KEEP_SIZE] -remove-> |
95 // [CLOSED] -add-> [STICKY_AND_NEW] -remove-> [CLOSED] | 95 // [CLOSED] -add-> [STICKY_AND_NEW] -remove-> [CLOSED] |
96 IN_PROC_BROWSER_TEST_F(NotificationTest, TestKeepSizeState) { | 96 IN_PROC_BROWSER_TEST_F(NotificationTest, TestKeepSizeState) { |
97 BalloonCollectionImpl* collection = GetBalloonCollectionImpl(); | 97 BalloonCollectionImpl* collection = GetBalloonCollectionImpl(); |
98 NotificationPanel* panel = GetNotificationPanel(); | 98 NotificationPanel* panel = GetNotificationPanel(); |
99 NotificationPanelTester* tester = panel->GetTester(); | 99 NotificationPanelTester* tester = panel->GetTester(); |
100 | 100 |
101 EXPECT_EQ(NotificationPanel::CLOSED, tester->state()); | 101 EXPECT_EQ(NotificationPanel::CLOSED, tester->state()); |
102 | 102 |
103 // Using system notification as regular notification. | 103 // Using system notification as regular notification. |
104 collection->Add(NewMockNotification("1"), browser()->profile()); | 104 collection->Add(NewMockNotification("1"), browser()->profile()); |
105 collection->Add(NewMockNotification("2"), browser()->profile()); | 105 collection->Add(NewMockNotification("2"), browser()->profile()); |
106 | 106 |
107 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); | 107 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); |
108 | 108 |
109 panel->OnMouseMotion(); | 109 panel->OnMouseMotion(); |
110 EXPECT_EQ(NotificationPanel::KEEP_SIZE, tester->state()); | 110 EXPECT_EQ(NotificationPanel::KEEP_SIZE, tester->state()); |
111 | 111 |
112 collection->Remove(NewMockNotification("1")); | 112 collection->Remove(NewMockNotification("1")); |
113 RunAllPendingEvents(); | 113 ui_test_utils::RunAllPendingInMessageLoop(); |
114 EXPECT_EQ(1, tester->GetNewNotificationCount()); | 114 EXPECT_EQ(1, tester->GetNewNotificationCount()); |
115 EXPECT_EQ(1, tester->GetNotificationCount()); | 115 EXPECT_EQ(1, tester->GetNotificationCount()); |
116 EXPECT_EQ(NotificationPanel::KEEP_SIZE, tester->state()); | 116 EXPECT_EQ(NotificationPanel::KEEP_SIZE, tester->state()); |
117 | 117 |
118 collection->Remove(NewMockNotification("2")); | 118 collection->Remove(NewMockNotification("2")); |
119 RunAllPendingEvents(); | 119 ui_test_utils::RunAllPendingInMessageLoop(); |
120 EXPECT_EQ(0, tester->GetNotificationCount()); | 120 EXPECT_EQ(0, tester->GetNotificationCount()); |
121 EXPECT_EQ(NotificationPanel::CLOSED, tester->state()); | 121 EXPECT_EQ(NotificationPanel::CLOSED, tester->state()); |
122 | 122 |
123 collection->Add(NewMockNotification("3"), browser()->profile()); | 123 collection->Add(NewMockNotification("3"), browser()->profile()); |
124 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); | 124 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); |
125 collection->Remove(NewMockNotification("3")); | 125 collection->Remove(NewMockNotification("3")); |
126 | 126 |
127 RunAllPendingEvents(); | 127 ui_test_utils::RunAllPendingInMessageLoop(); |
128 EXPECT_EQ(0, tester->GetNotificationCount()); | 128 EXPECT_EQ(0, tester->GetNotificationCount()); |
129 EXPECT_EQ(NotificationPanel::CLOSED, tester->state()); | 129 EXPECT_EQ(NotificationPanel::CLOSED, tester->state()); |
130 } | 130 } |
131 | 131 |
132 IN_PROC_BROWSER_TEST_F(NotificationTest, TestSystemNotification) { | 132 IN_PROC_BROWSER_TEST_F(NotificationTest, TestSystemNotification) { |
133 BalloonCollectionImpl* collection = GetBalloonCollectionImpl(); | 133 BalloonCollectionImpl* collection = GetBalloonCollectionImpl(); |
134 NotificationPanel* panel = GetNotificationPanel(); | 134 NotificationPanel* panel = GetNotificationPanel(); |
135 scoped_refptr<MockNotificationDelegate> delegate( | 135 scoped_refptr<MockNotificationDelegate> delegate( |
136 new MockNotificationDelegate("power")); | 136 new MockNotificationDelegate("power")); |
137 NotificationPanelTester* tester = panel->GetTester(); | 137 NotificationPanelTester* tester = panel->GetTester(); |
138 | 138 |
139 Notification notify = NewMockNotification(delegate.get()); | 139 Notification notify = NewMockNotification(delegate.get()); |
140 collection->AddSystemNotification(notify, browser()->profile(), true, false); | 140 collection->AddSystemNotification(notify, browser()->profile(), true, false); |
141 | 141 |
142 EXPECT_EQ(1, tester->GetNewNotificationCount()); | 142 EXPECT_EQ(1, tester->GetNewNotificationCount()); |
143 EXPECT_EQ(1, tester->GetStickyNotificationCount()); | 143 EXPECT_EQ(1, tester->GetStickyNotificationCount()); |
144 | 144 |
145 Notification update = SystemNotificationFactory::Create( | 145 Notification update = SystemNotificationFactory::Create( |
146 GURL(), ASCIIToUTF16("Title"), ASCIIToUTF16("updated"), delegate.get()); | 146 GURL(), ASCIIToUTF16("Title"), ASCIIToUTF16("updated"), delegate.get()); |
147 collection->UpdateNotification(update); | 147 collection->UpdateNotification(update); |
148 | 148 |
149 EXPECT_EQ(1, tester->GetStickyNotificationCount()); | 149 EXPECT_EQ(1, tester->GetStickyNotificationCount()); |
150 | 150 |
151 // Dismiss the notification. | 151 // Dismiss the notification. |
152 // TODO(oshima): Consider updating API to Remove(NotificationDelegate) | 152 // TODO(oshima): Consider updating API to Remove(NotificationDelegate) |
153 // or Remove(std::string id); | 153 // or Remove(std::string id); |
154 collection->Remove(Notification(GURL(), GURL(), | 154 collection->Remove(Notification(GURL(), GURL(), |
155 std::wstring(), delegate.get())); | 155 std::wstring(), delegate.get())); |
156 RunAllPendingEvents(); | 156 ui_test_utils::RunAllPendingInMessageLoop(); |
157 | 157 |
158 EXPECT_EQ(0, tester->GetStickyNotificationCount()); | 158 EXPECT_EQ(0, tester->GetStickyNotificationCount()); |
159 EXPECT_EQ(0, tester->GetNewNotificationCount()); | 159 EXPECT_EQ(0, tester->GetNewNotificationCount()); |
160 // TODO(oshima): check content, etc.. | 160 // TODO(oshima): check content, etc.. |
161 } | 161 } |
162 | 162 |
163 // [CLOSED] -add,add->[STICKY_AND_NEW] -stale-> [MINIMIZED] -remove-> | 163 // [CLOSED] -add,add->[STICKY_AND_NEW] -stale-> [MINIMIZED] -remove-> |
164 // [MINIMIZED] -remove-> [CLOSED] | 164 // [MINIMIZED] -remove-> [CLOSED] |
165 IN_PROC_BROWSER_TEST_F(NotificationTest, TestStateTransition1) { | 165 IN_PROC_BROWSER_TEST_F(NotificationTest, TestStateTransition1) { |
166 BalloonCollectionImpl* collection = GetBalloonCollectionImpl(); | 166 BalloonCollectionImpl* collection = GetBalloonCollectionImpl(); |
167 NotificationPanel* panel = GetNotificationPanel(); | 167 NotificationPanel* panel = GetNotificationPanel(); |
168 NotificationPanelTester* tester = panel->GetTester(); | 168 NotificationPanelTester* tester = panel->GetTester(); |
169 | 169 |
170 tester->SetStaleTimeout(0); | 170 tester->SetStaleTimeout(0); |
171 EXPECT_EQ(NotificationPanel::CLOSED, tester->state()); | 171 EXPECT_EQ(NotificationPanel::CLOSED, tester->state()); |
172 | 172 |
173 collection->Add(NewMockNotification("1"), browser()->profile()); | 173 collection->Add(NewMockNotification("1"), browser()->profile()); |
174 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); | 174 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); |
175 | 175 |
176 collection->Add(NewMockNotification("2"), browser()->profile()); | 176 collection->Add(NewMockNotification("2"), browser()->profile()); |
177 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); | 177 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); |
178 | 178 |
179 RunAllPendingEvents(); | 179 ui_test_utils::RunAllPendingInMessageLoop(); |
180 EXPECT_EQ(NotificationPanel::MINIMIZED, tester->state()); | 180 EXPECT_EQ(NotificationPanel::MINIMIZED, tester->state()); |
181 | 181 |
182 collection->Remove(NewMockNotification("2")); | 182 collection->Remove(NewMockNotification("2")); |
183 RunAllPendingEvents(); | 183 ui_test_utils::RunAllPendingInMessageLoop(); |
184 EXPECT_EQ(NotificationPanel::MINIMIZED, tester->state()); | 184 EXPECT_EQ(NotificationPanel::MINIMIZED, tester->state()); |
185 | 185 |
186 collection->Remove(NewMockNotification("1")); | 186 collection->Remove(NewMockNotification("1")); |
187 RunAllPendingEvents(); | 187 ui_test_utils::RunAllPendingInMessageLoop(); |
188 EXPECT_EQ(0, tester->GetNotificationCount()); | 188 EXPECT_EQ(0, tester->GetNotificationCount()); |
189 EXPECT_EQ(NotificationPanel::CLOSED, tester->state()); | 189 EXPECT_EQ(NotificationPanel::CLOSED, tester->state()); |
190 } | 190 } |
191 | 191 |
192 // [CLOSED] -add->[STICKY_AND_NEW] -stale-> [MINIMIZED] -add-> | 192 // [CLOSED] -add->[STICKY_AND_NEW] -stale-> [MINIMIZED] -add-> |
193 // [STICKY_AND_NEW] -stale-> [MINIMIZED] -add sys-> [STICKY_NEW] | 193 // [STICKY_AND_NEW] -stale-> [MINIMIZED] -add sys-> [STICKY_NEW] |
194 // -stale-> [STICKY_NEW] -remove-> [STICKY_NEW] -remove sys-> | 194 // -stale-> [STICKY_NEW] -remove-> [STICKY_NEW] -remove sys-> |
195 // [MINIMIZED] -remove-> [CLOSED] | 195 // [MINIMIZED] -remove-> [CLOSED] |
196 IN_PROC_BROWSER_TEST_F(NotificationTest, TestStateTransition2) { | 196 IN_PROC_BROWSER_TEST_F(NotificationTest, TestStateTransition2) { |
197 BalloonCollectionImpl* collection = GetBalloonCollectionImpl(); | 197 BalloonCollectionImpl* collection = GetBalloonCollectionImpl(); |
198 NotificationPanel* panel = GetNotificationPanel(); | 198 NotificationPanel* panel = GetNotificationPanel(); |
199 NotificationPanelTester* tester = panel->GetTester(); | 199 NotificationPanelTester* tester = panel->GetTester(); |
200 | 200 |
201 tester->SetStaleTimeout(0); | 201 tester->SetStaleTimeout(0); |
202 | 202 |
203 EXPECT_EQ(NotificationPanel::CLOSED, tester->state()); | 203 EXPECT_EQ(NotificationPanel::CLOSED, tester->state()); |
204 | 204 |
205 collection->Add(NewMockNotification("1"), browser()->profile()); | 205 collection->Add(NewMockNotification("1"), browser()->profile()); |
206 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); | 206 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); |
207 | 207 |
208 RunAllPendingEvents(); | 208 ui_test_utils::RunAllPendingInMessageLoop(); |
209 EXPECT_EQ(NotificationPanel::MINIMIZED, tester->state()); | 209 EXPECT_EQ(NotificationPanel::MINIMIZED, tester->state()); |
210 | 210 |
211 collection->Add(NewMockNotification("2"), browser()->profile()); | 211 collection->Add(NewMockNotification("2"), browser()->profile()); |
212 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); | 212 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); |
213 | 213 |
214 RunAllPendingEvents(); | 214 ui_test_utils::RunAllPendingInMessageLoop(); |
215 EXPECT_EQ(NotificationPanel::MINIMIZED, tester->state()); | 215 EXPECT_EQ(NotificationPanel::MINIMIZED, tester->state()); |
216 | 216 |
217 collection->AddSystemNotification( | 217 collection->AddSystemNotification( |
218 NewMockNotification("3"), browser()->profile(), true, false); | 218 NewMockNotification("3"), browser()->profile(), true, false); |
219 EXPECT_EQ(3, tester->GetNotificationCount()); | 219 EXPECT_EQ(3, tester->GetNotificationCount()); |
220 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); | 220 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); |
221 | 221 |
222 RunAllPendingEvents(); | 222 ui_test_utils::RunAllPendingInMessageLoop(); |
223 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); | 223 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); |
224 | 224 |
225 collection->Remove(NewMockNotification("1")); | 225 collection->Remove(NewMockNotification("1")); |
226 RunAllPendingEvents(); | 226 ui_test_utils::RunAllPendingInMessageLoop(); |
227 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); | 227 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); |
228 | 228 |
229 collection->Remove(NewMockNotification("3")); | 229 collection->Remove(NewMockNotification("3")); |
230 RunAllPendingEvents(); | 230 ui_test_utils::RunAllPendingInMessageLoop(); |
231 EXPECT_EQ(1, tester->GetNotificationCount()); | 231 EXPECT_EQ(1, tester->GetNotificationCount()); |
232 EXPECT_EQ(NotificationPanel::MINIMIZED, tester->state()); | 232 EXPECT_EQ(NotificationPanel::MINIMIZED, tester->state()); |
233 | 233 |
234 collection->Remove(NewMockNotification("2")); | 234 collection->Remove(NewMockNotification("2")); |
235 RunAllPendingEvents(); | 235 ui_test_utils::RunAllPendingInMessageLoop(); |
236 EXPECT_EQ(0, tester->GetNotificationCount()); | 236 EXPECT_EQ(0, tester->GetNotificationCount()); |
237 EXPECT_EQ(NotificationPanel::CLOSED, tester->state()); | 237 EXPECT_EQ(NotificationPanel::CLOSED, tester->state()); |
238 } | 238 } |
239 | 239 |
240 IN_PROC_BROWSER_TEST_F(NotificationTest, TestStateTransition3) { | 240 IN_PROC_BROWSER_TEST_F(NotificationTest, TestStateTransition3) { |
241 } | 241 } |
242 | 242 |
243 } // namespace chromeos | 243 } // namespace chromeos |
OLD | NEW |