Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/download/DownloadNotificationServiceTest.java

Issue 2861863002: offline_items_collection : Added helper class to determine progress (Closed)
Patch Set: findbugs Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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;
11 import android.os.HandlerThread; 11 import android.os.HandlerThread;
12 import android.os.IBinder; 12 import android.os.IBinder;
13 import android.support.test.filters.SmallTest; 13 import android.support.test.filters.SmallTest;
14 import android.test.ServiceTestCase; 14 import android.test.ServiceTestCase;
15 15
16 import org.chromium.base.ContextUtils; 16 import org.chromium.base.ContextUtils;
17 import org.chromium.base.ThreadUtils; 17 import org.chromium.base.ThreadUtils;
18 import org.chromium.base.test.util.AdvancedMockContext; 18 import org.chromium.base.test.util.AdvancedMockContext;
19 import org.chromium.base.test.util.Feature; 19 import org.chromium.base.test.util.Feature;
20 import org.chromium.base.test.util.RetryOnFailure; 20 import org.chromium.base.test.util.RetryOnFailure;
21 import org.chromium.components.offline_items_collection.ContentId; 21 import org.chromium.components.offline_items_collection.ContentId;
22 import org.chromium.components.offline_items_collection.LegacyHelpers; 22 import org.chromium.components.offline_items_collection.LegacyHelpers;
23 import org.chromium.components.offline_items_collection.OfflineItem.Progress;
24 import org.chromium.components.offline_items_collection.OfflineItemProgressUnit;
23 25
24 import java.util.ArrayList; 26 import java.util.ArrayList;
25 import java.util.HashSet; 27 import java.util.HashSet;
26 import java.util.List; 28 import java.util.List;
27 import java.util.Set; 29 import java.util.Set;
28 import java.util.UUID; 30 import java.util.UUID;
29 31
30 /** 32 /**
31 * Tests of {@link DownloadNotificationService}. 33 * Tests of {@link DownloadNotificationService}.
32 */ 34 */
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 public void run() { 291 public void run() {
290 getService().updateNotificationsForShutdown(); 292 getService().updateNotificationsForShutdown();
291 } 293 }
292 }); 294 });
293 assertEquals(2, getService().getNotificationIds().size()); 295 assertEquals(2, getService().getNotificationIds().size());
294 assertTrue(getService().getNotificationIds().contains(3)); 296 assertTrue(getService().getNotificationIds().contains(3));
295 assertTrue(getService().getNotificationIds().contains(4)); 297 assertTrue(getService().getNotificationIds().contains(4));
296 298
297 DownloadNotificationService service = bindNotificationService(); 299 DownloadNotificationService service = bindNotificationService();
298 ContentId id3 = LegacyHelpers.buildLegacyContentId(false, UUID.randomUUI D().toString()); 300 ContentId id3 = LegacyHelpers.buildLegacyContentId(false, UUID.randomUUI D().toString());
299 service.notifyDownloadProgress(id3, "test", 1, 100L, 1L, 1L, true, true, false, null); 301 service.notifyDownloadProgress(id3, "test",
302 new Progress(1, 100L, OfflineItemProgressUnit.PERCENTAGE), 100L, 1L, 1L, true, true,
303 false, null);
300 assertEquals(3, getService().getNotificationIds().size()); 304 assertEquals(3, getService().getNotificationIds().size());
301 int lastNotificationId = getService().getLastAddedNotificationId(); 305 int lastNotificationId = getService().getLastAddedNotificationId();
302 Set<String> entries = DownloadManagerService.getStoredDownloadInfo( 306 Set<String> entries = DownloadManagerService.getStoredDownloadInfo(
303 sharedPrefs, DownloadSharedPreferenceHelper.KEY_PENDING_DOWNLOAD _NOTIFICATIONS); 307 sharedPrefs, DownloadSharedPreferenceHelper.KEY_PENDING_DOWNLOAD _NOTIFICATIONS);
304 assertEquals(3, entries.size()); 308 assertEquals(3, entries.size());
305 309
306 ContentId id1 = LegacyHelpers.buildLegacyContentId(false, guid1); 310 ContentId id1 = LegacyHelpers.buildLegacyContentId(false, guid1);
307 service.notifyDownloadSuccessful( 311 service.notifyDownloadSuccessful(
308 id1, "/path/to/success", "success", 100L, false, false, true, nu ll); 312 id1, "/path/to/success", "success", 100L, false, false, true, nu ll);
309 entries = DownloadManagerService.getStoredDownloadInfo( 313 entries = DownloadManagerService.getStoredDownloadInfo(
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 } 425 }
422 }); 426 });
423 427
424 assertTrue(getService().isPaused()); 428 assertTrue(getService().isPaused());
425 assertFalse(sharedPrefs.contains( 429 assertFalse(sharedPrefs.contains(
426 DownloadSharedPreferenceHelper.KEY_PENDING_DOWNLOAD_NOTIFICATION S)); 430 DownloadSharedPreferenceHelper.KEY_PENDING_DOWNLOAD_NOTIFICATION S));
427 } 431 }
428 432
429 @SmallTest 433 @SmallTest
430 @Feature({"Download"}) 434 @Feature({"Download"})
431 public void testFormatRemainingTime() { 435 public void testFormatRemainingTime() {
David Trainor- moved to gerrit 2017/05/09 05:36:01 Should we add a test validating the new DownloadUt
shaktisahu 2017/05/09 19:04:32 Done.
432 Context context = getSystemContext().getApplicationContext(); 436 Context context = getSystemContext().getApplicationContext();
433 assertEquals("0 secs left", DownloadNotificationService.formatRemainingT ime(context, 0)); 437 assertEquals("0 secs left", DownloadUtils.formatRemainingTime(context, 0 ));
434 assertEquals("1 sec left", DownloadNotificationService.formatRemainingTi me( 438 assertEquals("1 sec left", DownloadUtils.formatRemainingTime(context, MI LLIS_PER_SECOND));
435 context, MILLIS_PER_SECOND)); 439 assertEquals("1 min left",
436 assertEquals("1 min left", DownloadNotificationService.formatRemainingTi me(context, 440 DownloadUtils.formatRemainingTime(
437 DownloadNotificationService.SECONDS_PER_MINUTE * MILLIS_PER_SECO ND)); 441 context, DownloadUtils.SECONDS_PER_MINUTE * MILLIS_PER_S ECOND));
438 assertEquals("2 mins left", DownloadNotificationService.formatRemainingT ime(context, 442 assertEquals(
439 149 * MILLIS_PER_SECOND)); 443 "2 mins left", DownloadUtils.formatRemainingTime(context, 149 * MILLIS_PER_SECOND));
440 assertEquals("3 mins left", DownloadNotificationService.formatRemainingT ime(context, 444 assertEquals(
441 150 * MILLIS_PER_SECOND)); 445 "3 mins left", DownloadUtils.formatRemainingTime(context, 150 * MILLIS_PER_SECOND));
442 assertEquals("1 hour left", DownloadNotificationService.formatRemainingT ime(context, 446 assertEquals("1 hour left",
443 DownloadNotificationService.SECONDS_PER_HOUR * MILLIS_PER_SECOND )); 447 DownloadUtils.formatRemainingTime(
444 assertEquals("2 hours left", DownloadNotificationService.formatRemaining Time(context, 448 context, DownloadUtils.SECONDS_PER_HOUR * MILLIS_PER_SEC OND));
445 149 * DownloadNotificationService.SECONDS_PER_MINUTE * MILLIS_PE R_SECOND)); 449 assertEquals("2 hours left",
446 assertEquals("3 hours left", DownloadNotificationService.formatRemaining Time(context, 450 DownloadUtils.formatRemainingTime(
447 150 * DownloadNotificationService.SECONDS_PER_MINUTE * MILLIS_PE R_SECOND)); 451 context, 149 * DownloadUtils.SECONDS_PER_MINUTE * MILLIS _PER_SECOND));
448 assertEquals("1 day left", DownloadNotificationService.formatRemainingTi me(context, 452 assertEquals("3 hours left",
449 DownloadNotificationService.SECONDS_PER_DAY * MILLIS_PER_SECOND) ); 453 DownloadUtils.formatRemainingTime(
450 assertEquals("2 days left", DownloadNotificationService.formatRemainingT ime(context, 454 context, 150 * DownloadUtils.SECONDS_PER_MINUTE * MILLIS _PER_SECOND));
451 59 * DownloadNotificationService.SECONDS_PER_HOUR * MILLIS_PER_S ECOND)); 455 assertEquals("1 day left",
452 assertEquals("3 days left", DownloadNotificationService.formatRemainingT ime(context, 456 DownloadUtils.formatRemainingTime(
453 60 * DownloadNotificationService.SECONDS_PER_HOUR * MILLIS_PER_S ECOND)); 457 context, DownloadUtils.SECONDS_PER_DAY * MILLIS_PER_SECO ND));
458 assertEquals("2 days left",
459 DownloadUtils.formatRemainingTime(
460 context, 59 * DownloadUtils.SECONDS_PER_HOUR * MILLIS_PE R_SECOND));
461 assertEquals("3 days left",
462 DownloadUtils.formatRemainingTime(
463 context, 60 * DownloadUtils.SECONDS_PER_HOUR * MILLIS_PE R_SECOND));
454 } 464 }
455 465
456 // Tests that the downloaded bytes on the notification is correct. 466 // Tests that the downloaded bytes on the notification is correct.
457 @SmallTest 467 @SmallTest
458 @Feature({"Download"}) 468 @Feature({"Download"})
459 public void testFormatBytesReceived() { 469 public void testFormatBytesReceived() {
460 Context context = getSystemContext().getApplicationContext(); 470 Context context = getSystemContext().getApplicationContext();
461 assertEquals("Downloaded 0.0 KB", DownloadUtils.getStringForBytes( 471 assertEquals("Downloaded 0.0 KB", DownloadUtils.getStringForBytes(
462 context, DownloadUtils.BYTES_DOWNLOADED_STRINGS, 0)); 472 context, DownloadUtils.BYTES_DOWNLOADED_STRINGS, 0));
463 assertEquals("Downloaded 0.5 KB", DownloadUtils.getStringForBytes( 473 assertEquals("Downloaded 0.5 KB", DownloadUtils.getStringForBytes(
464 context, DownloadUtils.BYTES_DOWNLOADED_STRINGS, 512)); 474 context, DownloadUtils.BYTES_DOWNLOADED_STRINGS, 512));
465 assertEquals("Downloaded 1.0 KB", DownloadUtils.getStringForBytes( 475 assertEquals("Downloaded 1.0 KB", DownloadUtils.getStringForBytes(
466 context, DownloadUtils.BYTES_DOWNLOADED_STRINGS, 1024)); 476 context, DownloadUtils.BYTES_DOWNLOADED_STRINGS, 1024));
467 assertEquals("Downloaded 1.0 MB", DownloadUtils.getStringForBytes( 477 assertEquals("Downloaded 1.0 MB", DownloadUtils.getStringForBytes(
468 context, DownloadUtils.BYTES_DOWNLOADED_STRINGS, 1024 * 1024)); 478 context, DownloadUtils.BYTES_DOWNLOADED_STRINGS, 1024 * 1024));
469 assertEquals("Downloaded 1.0 GB", DownloadUtils.getStringForBytes( 479 assertEquals("Downloaded 1.0 GB", DownloadUtils.getStringForBytes(
470 context, DownloadUtils.BYTES_DOWNLOADED_STRINGS, 1024 * 1024 * 1 024)); 480 context, DownloadUtils.BYTES_DOWNLOADED_STRINGS, 1024 * 1024 * 1 024));
471 } 481 }
472 } 482 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698