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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 // TODO(jamescook): This test is flaky on linux_chromeos, occasionally causing | 157 // TODO(jamescook): This test is flaky on linux_chromeos, occasionally causing |
158 // this assertion failure inside Gtk: | 158 // this assertion failure inside Gtk: |
159 // "murrine_style_draw_box: assertion `height >= -1' failed" | 159 // "murrine_style_draw_box: assertion `height >= -1' failed" |
160 // There may be an underlying bug in the ChromeOS notification code. | 160 // There may be an underlying bug in the ChromeOS notification code. |
161 // I'm not marking it as FLAKY because this doesn't happen on the bots. | 161 // I'm not marking it as FLAKY because this doesn't happen on the bots. |
162 #define MAYBE_ShowDelayedTest ShowDelayedTest | 162 #define MAYBE_ShowDelayedTest ShowDelayedTest |
163 IN_PROC_BROWSER_TEST_F(FileBrowserNotificationsTest, ShowDelayedTest) { | 163 IN_PROC_BROWSER_TEST_F(FileBrowserNotificationsTest, ShowDelayedTest) { |
164 InitNotifications(); | 164 InitNotifications(); |
165 // Adding a delayed notification does not show a balloon. | 165 // Adding a delayed notification does not show a balloon. |
166 notifications_->ShowNotificationDelayed(FileBrowserNotifications::DEVICE, | 166 notifications_->ShowNotificationDelayed(FileBrowserNotifications::DEVICE, |
167 "path", 3000); | 167 "path", |
| 168 base::TimeDelta::FromSeconds(3)); |
168 EXPECT_EQ(0u, collection_->GetActiveBalloons().size()); | 169 EXPECT_EQ(0u, collection_->GetActiveBalloons().size()); |
169 | 170 |
170 // Forcing the show to happen makes the balloon appear. | 171 // Forcing the show to happen makes the balloon appear. |
171 notifications_->ExecuteShow(); | 172 notifications_->ExecuteShow(); |
172 ui_test_utils::RunAllPendingInMessageLoop(); | 173 ui_test_utils::RunAllPendingInMessageLoop(); |
173 EXPECT_EQ(1u, collection_->GetActiveBalloons().size()); | 174 EXPECT_EQ(1u, collection_->GetActiveBalloons().size()); |
174 EXPECT_TRUE(FindBalloon("Dpath")); | 175 EXPECT_TRUE(FindBalloon("Dpath")); |
175 | 176 |
176 // Showing a notification both immediately and delayed results in one | 177 // Showing a notification both immediately and delayed results in one |
177 // additional balloon. | 178 // additional balloon. |
178 notifications_->ShowNotificationDelayed(FileBrowserNotifications::DEVICE_FAIL, | 179 notifications_->ShowNotificationDelayed(FileBrowserNotifications::DEVICE_FAIL, |
179 "path", 3000); | 180 "path", |
| 181 base::TimeDelta::FromSeconds(3)); |
180 notifications_->ShowNotification(FileBrowserNotifications::DEVICE_FAIL, | 182 notifications_->ShowNotification(FileBrowserNotifications::DEVICE_FAIL, |
181 "path"); | 183 "path"); |
182 EXPECT_EQ(2u, collection_->GetActiveBalloons().size()); | 184 EXPECT_EQ(2u, collection_->GetActiveBalloons().size()); |
183 EXPECT_TRUE(FindBalloon("Dpath")); | 185 EXPECT_TRUE(FindBalloon("Dpath")); |
184 EXPECT_TRUE(FindBalloon("DFpath")); | 186 EXPECT_TRUE(FindBalloon("DFpath")); |
185 | 187 |
186 // When the delayed notification arrives, it's an update, so we still only | 188 // When the delayed notification arrives, it's an update, so we still only |
187 // have two balloons. | 189 // have two balloons. |
188 notifications_->ExecuteShow(); | 190 notifications_->ExecuteShow(); |
189 ui_test_utils::RunAllPendingInMessageLoop(); | 191 ui_test_utils::RunAllPendingInMessageLoop(); |
190 EXPECT_EQ(2u, collection_->GetActiveBalloons().size()); | 192 EXPECT_EQ(2u, collection_->GetActiveBalloons().size()); |
191 EXPECT_TRUE(FindBalloon("Dpath")); | 193 EXPECT_TRUE(FindBalloon("Dpath")); |
192 EXPECT_TRUE(FindBalloon("DFpath")); | 194 EXPECT_TRUE(FindBalloon("DFpath")); |
193 | 195 |
194 // If we schedule a show for later, then hide before it becomes visible, | 196 // If we schedule a show for later, then hide before it becomes visible, |
195 // the balloon should not be added. | 197 // the balloon should not be added. |
196 notifications_->ShowNotificationDelayed( | 198 notifications_->ShowNotificationDelayed(FileBrowserNotifications::FORMAT_FAIL, |
197 FileBrowserNotifications::FORMAT_FAIL, "path", 3000); | 199 "path", |
| 200 base::TimeDelta::FromSeconds(3)); |
198 notifications_->HideNotification(FileBrowserNotifications::FORMAT_FAIL, | 201 notifications_->HideNotification(FileBrowserNotifications::FORMAT_FAIL, |
199 "path"); | 202 "path"); |
200 EXPECT_EQ(2u, collection_->GetActiveBalloons().size()); | 203 EXPECT_EQ(2u, collection_->GetActiveBalloons().size()); |
201 EXPECT_TRUE(FindBalloon("Dpath")); | 204 EXPECT_TRUE(FindBalloon("Dpath")); |
202 EXPECT_TRUE(FindBalloon("DFpath")); | 205 EXPECT_TRUE(FindBalloon("DFpath")); |
203 EXPECT_FALSE(FindBalloon("Fpath")); | 206 EXPECT_FALSE(FindBalloon("Fpath")); |
204 | 207 |
205 // Even when we try to force the show, nothing appears, because the balloon | 208 // Even when we try to force the show, nothing appears, because the balloon |
206 // was explicitly hidden. | 209 // was explicitly hidden. |
207 notifications_->ExecuteShow(); | 210 notifications_->ExecuteShow(); |
208 ui_test_utils::RunAllPendingInMessageLoop(); | 211 ui_test_utils::RunAllPendingInMessageLoop(); |
209 EXPECT_EQ(2u, collection_->GetActiveBalloons().size()); | 212 EXPECT_EQ(2u, collection_->GetActiveBalloons().size()); |
210 EXPECT_TRUE(FindBalloon("Dpath")); | 213 EXPECT_TRUE(FindBalloon("Dpath")); |
211 EXPECT_TRUE(FindBalloon("DFpath")); | 214 EXPECT_TRUE(FindBalloon("DFpath")); |
212 EXPECT_FALSE(FindBalloon("Fpath")); | 215 EXPECT_FALSE(FindBalloon("Fpath")); |
213 } | 216 } |
214 | 217 |
215 IN_PROC_BROWSER_TEST_F(FileBrowserNotificationsTest, HideDelayedTest) { | 218 IN_PROC_BROWSER_TEST_F(FileBrowserNotificationsTest, HideDelayedTest) { |
216 InitNotifications(); | 219 InitNotifications(); |
217 // Showing now, and scheduling a hide for later, results in one balloon. | 220 // Showing now, and scheduling a hide for later, results in one balloon. |
218 notifications_->ShowNotification(FileBrowserNotifications::DEVICE, "path"); | 221 notifications_->ShowNotification(FileBrowserNotifications::DEVICE, "path"); |
219 notifications_->HideNotificationDelayed(FileBrowserNotifications::DEVICE, | 222 notifications_->HideNotificationDelayed(FileBrowserNotifications::DEVICE, |
220 "path", 3000); | 223 "path", |
| 224 base::TimeDelta::FromSeconds(3)); |
221 EXPECT_EQ(1u, collection_->GetActiveBalloons().size()); | 225 EXPECT_EQ(1u, collection_->GetActiveBalloons().size()); |
222 EXPECT_TRUE(FindBalloon("Dpath")); | 226 EXPECT_TRUE(FindBalloon("Dpath")); |
223 | 227 |
224 // Forcing the hide removes the balloon. | 228 // Forcing the hide removes the balloon. |
225 notifications_->ExecuteHide(); | 229 notifications_->ExecuteHide(); |
226 ui_test_utils::RunAllPendingInMessageLoop(); | 230 ui_test_utils::RunAllPendingInMessageLoop(); |
227 EXPECT_EQ(0u, collection_->GetActiveBalloons().size()); | 231 EXPECT_EQ(0u, collection_->GetActiveBalloons().size()); |
228 | 232 |
229 // Immediate show then hide results in no balloons. | 233 // Immediate show then hide results in no balloons. |
230 notifications_->ShowNotification(FileBrowserNotifications::DEVICE_FAIL, | 234 notifications_->ShowNotification(FileBrowserNotifications::DEVICE_FAIL, |
231 "path"); | 235 "path"); |
232 notifications_->HideNotification(FileBrowserNotifications::DEVICE_FAIL, | 236 notifications_->HideNotification(FileBrowserNotifications::DEVICE_FAIL, |
233 "path"); | 237 "path"); |
234 ui_test_utils::RunAllPendingInMessageLoop(); | 238 ui_test_utils::RunAllPendingInMessageLoop(); |
235 EXPECT_EQ(0u, collection_->GetActiveBalloons().size()); | 239 EXPECT_EQ(0u, collection_->GetActiveBalloons().size()); |
236 | 240 |
237 // Delayed hide for a notification that doesn't exist does nothing. | 241 // Delayed hide for a notification that doesn't exist does nothing. |
238 notifications_->HideNotificationDelayed(FileBrowserNotifications::DEVICE_FAIL, | 242 notifications_->HideNotificationDelayed(FileBrowserNotifications::DEVICE_FAIL, |
239 "path", 3000); | 243 "path", |
| 244 base::TimeDelta::FromSeconds(3)); |
240 notifications_->ExecuteHide(); | 245 notifications_->ExecuteHide(); |
241 ui_test_utils::RunAllPendingInMessageLoop(); | 246 ui_test_utils::RunAllPendingInMessageLoop(); |
242 EXPECT_EQ(0u, collection_->GetActiveBalloons().size()); | 247 EXPECT_EQ(0u, collection_->GetActiveBalloons().size()); |
243 } | 248 } |
244 | 249 |
245 } // namespace chromeos. | 250 } // namespace chromeos. |
OLD | NEW |