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

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

Issue 2054463003: Schedule download resumption automatically (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix clang build Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/android/java_sources.gni ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/javatests/src/org/chromium/chrome/browser/download/DownloadNotificationServiceTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/download/DownloadNotificationServiceTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/download/DownloadNotificationServiceTest.java
index b6881c6ec8c06eb45a15c43db70063fa8e5946df..8a4cf72894a4c9e974c29d8b779ea63c865f3045 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/download/DownloadNotificationServiceTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/download/DownloadNotificationServiceTest.java
@@ -45,6 +45,24 @@ public class DownloadNotificationServiceTest extends
}
}
+ private static class MockDownloadResumptionScheduler extends DownloadResumptionScheduler {
+ boolean mScheduled;
+
+ public MockDownloadResumptionScheduler(Context context) {
+ super(context);
+ }
+
+ @Override
+ public void schedule(boolean allowMeteredConnection) {
+ mScheduled = true;
+ }
+
+ @Override
+ public void cancelTask() {
+ mScheduled = false;
+ }
+ }
+
public DownloadNotificationServiceTest() {
super(MockDownloadNotificationService.class);
}
@@ -54,6 +72,16 @@ public class DownloadNotificationServiceTest extends
super.setupService();
}
+ @Override
+ protected void tearDown() throws Exception {
+ super.setupService();
+ SharedPreferences sharedPrefs = ContextUtils.getAppSharedPreferences();
+ SharedPreferences.Editor editor = sharedPrefs.edit();
+ editor.remove(DownloadNotificationService.PENDING_DOWNLOAD_NOTIFICATIONS);
+ editor.apply();
+ super.tearDown();
+ }
+
private void startNotificationService() {
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
@@ -99,6 +127,51 @@ public class DownloadNotificationServiceTest extends
}
/**
+ * Tests that download resumption task is scheduled when notification service is started
+ * without any download action.
+ */
+ @SmallTest
+ @Feature({"Download"})
+ public void testResumptionScheduledWithoutDownloadOperationIntent() throws Exception {
+ MockDownloadResumptionScheduler scheduler = new MockDownloadResumptionScheduler(
+ getSystemContext().getApplicationContext());
+ DownloadResumptionScheduler.setDownloadResumptionScheduler(scheduler);
+ setupService();
+ Set<String> notifications = new HashSet<String>();
+ notifications.add(new DownloadSharedPreferenceEntry(1, true, true,
+ UUID.randomUUID().toString(), "test1").getSharedPreferenceString());
+ SharedPreferences sharedPrefs = ContextUtils.getAppSharedPreferences();
+ SharedPreferences.Editor editor = sharedPrefs.edit();
+ editor.putStringSet(
+ DownloadNotificationService.PENDING_DOWNLOAD_NOTIFICATIONS, notifications);
+ editor.apply();
+ startNotificationService();
+ assertTrue(scheduler.mScheduled);
+ }
+
+ /**
+ * Tests that download resumption task is not scheduled when notification service is started
+ * with a download action.
+ */
+ @SmallTest
+ @Feature({"Download"})
+ public void testResumptionNotScheduledWithDownloadOperationIntent() {
+ MockDownloadResumptionScheduler scheduler = new MockDownloadResumptionScheduler(
+ getSystemContext().getApplicationContext());
+ DownloadResumptionScheduler.setDownloadResumptionScheduler(scheduler);
+ setupService();
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ @Override
+ public void run() {
+ Intent intent = new Intent(getService(), MockDownloadNotificationService.class);
+ intent.setAction(DownloadNotificationService.ACTION_DOWNLOAD_RESUME_ALL);
+ startService(intent);
+ }
+ });
+ assertFalse(scheduler.mScheduled);
+ }
+
+ /**
* Tests that creating the service without launching chrome will pause all ongoing downloads.
*/
@SmallTest
« no previous file with comments | « chrome/android/java_sources.gni ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698