OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 package org.chromium.chrome.browser.download; | 5 package org.chromium.chrome.browser.download; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.content.Intent; | 8 import android.content.Intent; |
9 import android.content.SharedPreferences; | 9 import android.content.SharedPreferences; |
10 import android.os.Handler; | 10 import android.os.Handler; |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 public void run() { | 289 public void run() { |
290 getService().updateNotificationsForShutdown(); | 290 getService().updateNotificationsForShutdown(); |
291 } | 291 } |
292 }); | 292 }); |
293 assertEquals(2, getService().getNotificationIds().size()); | 293 assertEquals(2, getService().getNotificationIds().size()); |
294 assertTrue(getService().getNotificationIds().contains(3)); | 294 assertTrue(getService().getNotificationIds().contains(3)); |
295 assertTrue(getService().getNotificationIds().contains(4)); | 295 assertTrue(getService().getNotificationIds().contains(4)); |
296 | 296 |
297 DownloadNotificationService service = bindNotificationService(); | 297 DownloadNotificationService service = bindNotificationService(); |
298 ContentId id3 = LegacyHelpers.buildLegacyContentId(false, UUID.randomUUI
D().toString()); | 298 ContentId id3 = LegacyHelpers.buildLegacyContentId(false, UUID.randomUUI
D().toString()); |
299 service.notifyDownloadProgress(id3, "test", 1, 100L, 1L, 1L, true, true,
false); | 299 service.notifyDownloadProgress(id3, "test", 1, 100L, 1L, 1L, true, true,
false, null); |
300 assertEquals(3, getService().getNotificationIds().size()); | 300 assertEquals(3, getService().getNotificationIds().size()); |
301 int lastNotificationId = getService().getLastAddedNotificationId(); | 301 int lastNotificationId = getService().getLastAddedNotificationId(); |
302 Set<String> entries = DownloadManagerService.getStoredDownloadInfo( | 302 Set<String> entries = DownloadManagerService.getStoredDownloadInfo( |
303 sharedPrefs, DownloadSharedPreferenceHelper.KEY_PENDING_DOWNLOAD
_NOTIFICATIONS); | 303 sharedPrefs, DownloadSharedPreferenceHelper.KEY_PENDING_DOWNLOAD
_NOTIFICATIONS); |
304 assertEquals(3, entries.size()); | 304 assertEquals(3, entries.size()); |
305 | 305 |
306 ContentId id1 = LegacyHelpers.buildLegacyContentId(false, guid1); | 306 ContentId id1 = LegacyHelpers.buildLegacyContentId(false, guid1); |
307 service.notifyDownloadSuccessful( | 307 service.notifyDownloadSuccessful( |
308 id1, "/path/to/success", "success", 100L, false, false, true); | 308 id1, "/path/to/success", "success", 100L, false, false, true, nu
ll); |
309 entries = DownloadManagerService.getStoredDownloadInfo( | 309 entries = DownloadManagerService.getStoredDownloadInfo( |
310 sharedPrefs, DownloadSharedPreferenceHelper.KEY_PENDING_DOWNLOAD
_NOTIFICATIONS); | 310 sharedPrefs, DownloadSharedPreferenceHelper.KEY_PENDING_DOWNLOAD
_NOTIFICATIONS); |
311 assertEquals(2, entries.size()); | 311 assertEquals(2, entries.size()); |
312 | 312 |
313 ContentId id2 = LegacyHelpers.buildLegacyContentId(false, guid2); | 313 ContentId id2 = LegacyHelpers.buildLegacyContentId(false, guid2); |
314 service.notifyDownloadFailed(id2, "failed"); | 314 service.notifyDownloadFailed(id2, "failed", null); |
315 entries = DownloadManagerService.getStoredDownloadInfo( | 315 entries = DownloadManagerService.getStoredDownloadInfo( |
316 sharedPrefs, DownloadSharedPreferenceHelper.KEY_PENDING_DOWNLOAD
_NOTIFICATIONS); | 316 sharedPrefs, DownloadSharedPreferenceHelper.KEY_PENDING_DOWNLOAD
_NOTIFICATIONS); |
317 assertEquals(1, entries.size()); | 317 assertEquals(1, entries.size()); |
318 | 318 |
319 service.notifyDownloadCanceled(id3); | 319 service.notifyDownloadCanceled(id3); |
320 assertEquals(2, getService().getNotificationIds().size()); | 320 assertEquals(2, getService().getNotificationIds().size()); |
321 assertFalse(getService().getNotificationIds().contains(lastNotificationI
d)); | 321 assertFalse(getService().getNotificationIds().contains(lastNotificationI
d)); |
322 | 322 |
323 ContentId id4 = LegacyHelpers.buildLegacyContentId(false, UUID.randomUUI
D().toString()); | 323 ContentId id4 = LegacyHelpers.buildLegacyContentId(false, UUID.randomUUI
D().toString()); |
324 service.notifyDownloadSuccessful( | 324 service.notifyDownloadSuccessful( |
325 id4, "/path/to/success", "success", 100L, false, false, true); | 325 id4, "/path/to/success", "success", 100L, false, false, true, nu
ll); |
326 assertEquals(3, getService().getNotificationIds().size()); | 326 assertEquals(3, getService().getNotificationIds().size()); |
327 int nextNotificationId = getService().getLastAddedNotificationId(); | 327 int nextNotificationId = getService().getLastAddedNotificationId(); |
328 service.cancelNotification(nextNotificationId, id4); | 328 service.cancelNotification(nextNotificationId, id4); |
329 assertEquals(2, getService().getNotificationIds().size()); | 329 assertEquals(2, getService().getNotificationIds().size()); |
330 assertFalse(getService().getNotificationIds().contains(nextNotificationI
d)); | 330 assertFalse(getService().getNotificationIds().contains(nextNotificationI
d)); |
331 } | 331 } |
332 | 332 |
333 /** | 333 /** |
334 * Tests that notification is updated if download success comes without any
prior progress. | 334 * Tests that notification is updated if download success comes without any
prior progress. |
335 */ | 335 */ |
336 @SmallTest | 336 @SmallTest |
337 @Feature({"Download"}) | 337 @Feature({"Download"}) |
338 @RetryOnFailure | 338 @RetryOnFailure |
339 public void testDownloadSuccessNotification() { | 339 public void testDownloadSuccessNotification() { |
340 setupService(); | 340 setupService(); |
341 startNotificationService(); | 341 startNotificationService(); |
342 DownloadNotificationService service = bindNotificationService(); | 342 DownloadNotificationService service = bindNotificationService(); |
343 ContentId id = LegacyHelpers.buildLegacyContentId(false, UUID.randomUUID
().toString()); | 343 ContentId id = LegacyHelpers.buildLegacyContentId(false, UUID.randomUUID
().toString()); |
344 service.notifyDownloadSuccessful(id, "/path/to/test", "test", 100L, fals
e, false, true); | 344 service.notifyDownloadSuccessful( |
| 345 id, "/path/to/test", "test", 100L, false, false, true, null); |
345 assertEquals(1, getService().getNotificationIds().size()); | 346 assertEquals(1, getService().getNotificationIds().size()); |
346 } | 347 } |
347 | 348 |
348 /** | 349 /** |
349 * Tests resume all pending downloads. Only auto resumable downloads can res
ume. | 350 * Tests resume all pending downloads. Only auto resumable downloads can res
ume. |
350 */ | 351 */ |
351 @SmallTest | 352 @SmallTest |
352 @Feature({"Download"}) | 353 @Feature({"Download"}) |
353 @RetryOnFailure | 354 @RetryOnFailure |
354 public void testResumeAllPendingDownloads() throws Exception { | 355 public void testResumeAllPendingDownloads() throws Exception { |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 assertEquals("Downloaded 0.5 KB", DownloadUtils.getStringForBytes( | 463 assertEquals("Downloaded 0.5 KB", DownloadUtils.getStringForBytes( |
463 context, DownloadUtils.BYTES_DOWNLOADED_STRINGS, 512)); | 464 context, DownloadUtils.BYTES_DOWNLOADED_STRINGS, 512)); |
464 assertEquals("Downloaded 1.0 KB", DownloadUtils.getStringForBytes( | 465 assertEquals("Downloaded 1.0 KB", DownloadUtils.getStringForBytes( |
465 context, DownloadUtils.BYTES_DOWNLOADED_STRINGS, 1024)); | 466 context, DownloadUtils.BYTES_DOWNLOADED_STRINGS, 1024)); |
466 assertEquals("Downloaded 1.0 MB", DownloadUtils.getStringForBytes( | 467 assertEquals("Downloaded 1.0 MB", DownloadUtils.getStringForBytes( |
467 context, DownloadUtils.BYTES_DOWNLOADED_STRINGS, 1024 * 1024)); | 468 context, DownloadUtils.BYTES_DOWNLOADED_STRINGS, 1024 * 1024)); |
468 assertEquals("Downloaded 1.0 GB", DownloadUtils.getStringForBytes( | 469 assertEquals("Downloaded 1.0 GB", DownloadUtils.getStringForBytes( |
469 context, DownloadUtils.BYTES_DOWNLOADED_STRINGS, 1024 * 1024 * 1
024)); | 470 context, DownloadUtils.BYTES_DOWNLOADED_STRINGS, 1024 * 1024 * 1
024)); |
470 } | 471 } |
471 } | 472 } |
OLD | NEW |