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 #include "chrome/browser/chromeos/extensions/file_browser_notifications.h" | 5 #include "chrome/browser/chromeos/extensions/file_browser_notifications.h" |
6 | 6 |
7 #include <gtest/gtest.h> | 7 #include <gtest/gtest.h> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 explicit MockFileBrowserNotifications(Profile* profile) | 23 explicit MockFileBrowserNotifications(Profile* profile) |
24 : FileBrowserNotifications(profile) { | 24 : FileBrowserNotifications(profile) { |
25 } | 25 } |
26 virtual ~MockFileBrowserNotifications() {} | 26 virtual ~MockFileBrowserNotifications() {} |
27 | 27 |
28 // Records the notification so we can force it to show later. | 28 // Records the notification so we can force it to show later. |
29 virtual void PostDelayedShowNotificationTask( | 29 virtual void PostDelayedShowNotificationTask( |
30 const std::string& notification_id, | 30 const std::string& notification_id, |
31 NotificationType type, | 31 NotificationType type, |
32 const string16& message, | 32 const string16& message, |
33 size_t delay_ms) OVERRIDE { | 33 base::TimeDelta delay) OVERRIDE { |
34 show_callback_data_.id = notification_id; | 34 show_callback_data_.id = notification_id; |
35 show_callback_data_.type = type; | 35 show_callback_data_.type = type; |
36 show_callback_data_.message = message; | 36 show_callback_data_.message = message; |
37 } | 37 } |
38 | 38 |
39 // Records the notification so we can force it to hide later. | 39 // Records the notification so we can force it to hide later. |
40 virtual void PostDelayedHideNotificationTask(NotificationType type, | 40 virtual void PostDelayedHideNotificationTask(NotificationType type, |
41 const std::string path, | 41 const std::string path, |
42 size_t delay_ms) OVERRIDE { | 42 base::TimeDelta delay) OVERRIDE { |
43 hide_callback_data_.type = type; | 43 hide_callback_data_.type = type; |
44 hide_callback_data_.path = path; | 44 hide_callback_data_.path = path; |
45 } | 45 } |
46 | 46 |
47 void ExecuteShow() { | 47 void ExecuteShow() { |
48 FileBrowserNotifications::ShowNotificationDelayedTask( | 48 FileBrowserNotifications::ShowNotificationDelayedTask( |
49 show_callback_data_.id, show_callback_data_.type, | 49 show_callback_data_.id, show_callback_data_.type, |
50 show_callback_data_.message, AsWeakPtr()); | 50 show_callback_data_.message, AsWeakPtr()); |
51 } | 51 } |
52 | 52 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 // TODO(jamescook): This test is flaky on linux_chromeos, occasionally causing | 161 // TODO(jamescook): This test is flaky on linux_chromeos, occasionally causing |
162 // this assertion failure inside Gtk: | 162 // this assertion failure inside Gtk: |
163 // "murrine_style_draw_box: assertion `height >= -1' failed" | 163 // "murrine_style_draw_box: assertion `height >= -1' failed" |
164 // There may be an underlying bug in the ChromeOS notification code. | 164 // There may be an underlying bug in the ChromeOS notification code. |
165 // I'm not marking it as FLAKY because this doesn't happen on the bots. | 165 // I'm not marking it as FLAKY because this doesn't happen on the bots. |
166 #define MAYBE_ShowDelayedTest ShowDelayedTest | 166 #define MAYBE_ShowDelayedTest ShowDelayedTest |
167 IN_PROC_BROWSER_TEST_F(FileBrowserNotificationsTest, ShowDelayedTest) { | 167 IN_PROC_BROWSER_TEST_F(FileBrowserNotificationsTest, ShowDelayedTest) { |
168 InitNotifications(); | 168 InitNotifications(); |
169 // Adding a delayed notification does not show a balloon. | 169 // Adding a delayed notification does not show a balloon. |
170 notifications_->ShowNotificationDelayed(FileBrowserNotifications::DEVICE, | 170 notifications_->ShowNotificationDelayed(FileBrowserNotifications::DEVICE, |
171 "path", 3000); | 171 "path", |
| 172 base::TimeDelta::FromSeconds(3)); |
172 EXPECT_EQ(0u, collection_->GetActiveBalloons().size()); | 173 EXPECT_EQ(0u, collection_->GetActiveBalloons().size()); |
173 | 174 |
174 // Forcing the show to happen makes the balloon appear. | 175 // Forcing the show to happen makes the balloon appear. |
175 notifications_->ExecuteShow(); | 176 notifications_->ExecuteShow(); |
176 ui_test_utils::RunAllPendingInMessageLoop(); | 177 ui_test_utils::RunAllPendingInMessageLoop(); |
177 EXPECT_EQ(1u, collection_->GetActiveBalloons().size()); | 178 EXPECT_EQ(1u, collection_->GetActiveBalloons().size()); |
178 EXPECT_TRUE(FindBalloon("Dpath")); | 179 EXPECT_TRUE(FindBalloon("Dpath")); |
179 | 180 |
180 // Showing a notification both immediately and delayed results in one | 181 // Showing a notification both immediately and delayed results in one |
181 // additional balloon. | 182 // additional balloon. |
182 notifications_->ShowNotificationDelayed(FileBrowserNotifications::DEVICE_FAIL, | 183 notifications_->ShowNotificationDelayed(FileBrowserNotifications::DEVICE_FAIL, |
183 "path", 3000); | 184 "path", |
| 185 base::TimeDelta::FromSeconds(3)); |
184 notifications_->ShowNotification(FileBrowserNotifications::DEVICE_FAIL, | 186 notifications_->ShowNotification(FileBrowserNotifications::DEVICE_FAIL, |
185 "path"); | 187 "path"); |
186 EXPECT_EQ(2u, collection_->GetActiveBalloons().size()); | 188 EXPECT_EQ(2u, collection_->GetActiveBalloons().size()); |
187 EXPECT_TRUE(FindBalloon("Dpath")); | 189 EXPECT_TRUE(FindBalloon("Dpath")); |
188 EXPECT_TRUE(FindBalloon("DFpath")); | 190 EXPECT_TRUE(FindBalloon("DFpath")); |
189 | 191 |
190 // When the delayed notification arrives, it's an update, so we still only | 192 // When the delayed notification arrives, it's an update, so we still only |
191 // have two balloons. | 193 // have two balloons. |
192 notifications_->ExecuteShow(); | 194 notifications_->ExecuteShow(); |
193 ui_test_utils::RunAllPendingInMessageLoop(); | 195 ui_test_utils::RunAllPendingInMessageLoop(); |
194 EXPECT_EQ(2u, collection_->GetActiveBalloons().size()); | 196 EXPECT_EQ(2u, collection_->GetActiveBalloons().size()); |
195 EXPECT_TRUE(FindBalloon("Dpath")); | 197 EXPECT_TRUE(FindBalloon("Dpath")); |
196 EXPECT_TRUE(FindBalloon("DFpath")); | 198 EXPECT_TRUE(FindBalloon("DFpath")); |
197 | 199 |
198 // If we schedule a show for later, then hide before it becomes visible, | 200 // If we schedule a show for later, then hide before it becomes visible, |
199 // the balloon should not be added. | 201 // the balloon should not be added. |
200 notifications_->ShowNotificationDelayed( | 202 notifications_->ShowNotificationDelayed(FileBrowserNotifications::FORMAT_FAIL, |
201 FileBrowserNotifications::FORMAT_FAIL, "path", 3000); | 203 "path", |
| 204 base::TimeDelta::FromSeconds(3)); |
202 notifications_->HideNotification(FileBrowserNotifications::FORMAT_FAIL, | 205 notifications_->HideNotification(FileBrowserNotifications::FORMAT_FAIL, |
203 "path"); | 206 "path"); |
204 EXPECT_EQ(2u, collection_->GetActiveBalloons().size()); | 207 EXPECT_EQ(2u, collection_->GetActiveBalloons().size()); |
205 EXPECT_TRUE(FindBalloon("Dpath")); | 208 EXPECT_TRUE(FindBalloon("Dpath")); |
206 EXPECT_TRUE(FindBalloon("DFpath")); | 209 EXPECT_TRUE(FindBalloon("DFpath")); |
207 EXPECT_FALSE(FindBalloon("Fpath")); | 210 EXPECT_FALSE(FindBalloon("Fpath")); |
208 | 211 |
209 // Even when we try to force the show, nothing appears, because the balloon | 212 // Even when we try to force the show, nothing appears, because the balloon |
210 // was explicitly hidden. | 213 // was explicitly hidden. |
211 notifications_->ExecuteShow(); | 214 notifications_->ExecuteShow(); |
212 ui_test_utils::RunAllPendingInMessageLoop(); | 215 ui_test_utils::RunAllPendingInMessageLoop(); |
213 EXPECT_EQ(2u, collection_->GetActiveBalloons().size()); | 216 EXPECT_EQ(2u, collection_->GetActiveBalloons().size()); |
214 EXPECT_TRUE(FindBalloon("Dpath")); | 217 EXPECT_TRUE(FindBalloon("Dpath")); |
215 EXPECT_TRUE(FindBalloon("DFpath")); | 218 EXPECT_TRUE(FindBalloon("DFpath")); |
216 EXPECT_FALSE(FindBalloon("Fpath")); | 219 EXPECT_FALSE(FindBalloon("Fpath")); |
217 } | 220 } |
218 | 221 |
219 IN_PROC_BROWSER_TEST_F(FileBrowserNotificationsTest, HideDelayedTest) { | 222 IN_PROC_BROWSER_TEST_F(FileBrowserNotificationsTest, HideDelayedTest) { |
220 InitNotifications(); | 223 InitNotifications(); |
221 // Showing now, and scheduling a hide for later, results in one balloon. | 224 // Showing now, and scheduling a hide for later, results in one balloon. |
222 notifications_->ShowNotification(FileBrowserNotifications::DEVICE, "path"); | 225 notifications_->ShowNotification(FileBrowserNotifications::DEVICE, "path"); |
223 notifications_->HideNotificationDelayed(FileBrowserNotifications::DEVICE, | 226 notifications_->HideNotificationDelayed(FileBrowserNotifications::DEVICE, |
224 "path", 3000); | 227 "path", |
| 228 base::TimeDelta::FromSeconds(3)); |
225 EXPECT_EQ(1u, collection_->GetActiveBalloons().size()); | 229 EXPECT_EQ(1u, collection_->GetActiveBalloons().size()); |
226 EXPECT_TRUE(FindBalloon("Dpath")); | 230 EXPECT_TRUE(FindBalloon("Dpath")); |
227 | 231 |
228 // Forcing the hide removes the balloon. | 232 // Forcing the hide removes the balloon. |
229 notifications_->ExecuteHide(); | 233 notifications_->ExecuteHide(); |
230 ui_test_utils::RunAllPendingInMessageLoop(); | 234 ui_test_utils::RunAllPendingInMessageLoop(); |
231 EXPECT_EQ(0u, collection_->GetActiveBalloons().size()); | 235 EXPECT_EQ(0u, collection_->GetActiveBalloons().size()); |
232 | 236 |
233 // Immediate show then hide results in no balloons. | 237 // Immediate show then hide results in no balloons. |
234 notifications_->ShowNotification(FileBrowserNotifications::DEVICE_FAIL, | 238 notifications_->ShowNotification(FileBrowserNotifications::DEVICE_FAIL, |
235 "path"); | 239 "path"); |
236 notifications_->HideNotification(FileBrowserNotifications::DEVICE_FAIL, | 240 notifications_->HideNotification(FileBrowserNotifications::DEVICE_FAIL, |
237 "path"); | 241 "path"); |
238 ui_test_utils::RunAllPendingInMessageLoop(); | 242 ui_test_utils::RunAllPendingInMessageLoop(); |
239 EXPECT_EQ(0u, collection_->GetActiveBalloons().size()); | 243 EXPECT_EQ(0u, collection_->GetActiveBalloons().size()); |
240 | 244 |
241 // Delayed hide for a notification that doesn't exist does nothing. | 245 // Delayed hide for a notification that doesn't exist does nothing. |
242 notifications_->HideNotificationDelayed(FileBrowserNotifications::DEVICE_FAIL, | 246 notifications_->HideNotificationDelayed(FileBrowserNotifications::DEVICE_FAIL, |
243 "path", 3000); | 247 "path", |
| 248 base::TimeDelta::FromSeconds(3)); |
244 notifications_->ExecuteHide(); | 249 notifications_->ExecuteHide(); |
245 ui_test_utils::RunAllPendingInMessageLoop(); | 250 ui_test_utils::RunAllPendingInMessageLoop(); |
246 EXPECT_EQ(0u, collection_->GetActiveBalloons().size()); | 251 EXPECT_EQ(0u, collection_->GetActiveBalloons().size()); |
247 } | 252 } |
248 | 253 |
249 } // namespace chromeos. | 254 } // namespace chromeos. |
OLD | NEW |