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

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

Issue 2726423002: Fix DownloadNotificationService foreground state (Closed)
Patch Set: Fix spelling mistake Created 3 years, 9 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
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/download/SystemDownloadNotifier.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.app.Notification; 7 import android.app.Notification;
8 import android.content.Context; 8 import android.content.Context;
9 9
10 import org.chromium.base.BuildInfo;
10 import org.chromium.base.ThreadUtils; 11 import org.chromium.base.ThreadUtils;
11 12
12 import java.util.ArrayList; 13 import java.util.ArrayList;
13 import java.util.List; 14 import java.util.List;
14 import java.util.concurrent.Callable; 15 import java.util.concurrent.Callable;
15 16
16 /** 17 /**
17 * Mock class to DownloadNotificationService for testing purpose. 18 * Mock class to DownloadNotificationService for testing purpose.
18 */ 19 */
19 public class MockDownloadNotificationService extends DownloadNotificationService { 20 public class MockDownloadNotificationService extends DownloadNotificationService {
20 private final List<Integer> mNotificationIds = new ArrayList<Integer>(); 21 private final List<Integer> mNotificationIds = new ArrayList<Integer>();
21 private boolean mPaused = false; 22 private boolean mPaused = false;
22 private Context mContext; 23 private Context mContext;
23 private int mLastNotificationId; 24 private int mLastNotificationId;
24 25
25 void setContext(Context context) { 26 void setContext(Context context) {
26 mContext = context; 27 mContext = context;
27 } 28 }
28 29
29 @Override 30 @Override
30 public void stopForeground() {} 31 public void stopForegroundInternal(boolean killNotification) {
32 if (!BuildInfo.isAtLeastO()) return;
33 if (killNotification) mNotificationIds.clear();
34 }
31 35
32 @Override 36 @Override
33 public void startForeground() {} 37 public void startForegroundInternal() {}
34 38
35 @Override 39 @Override
36 public void cancelOffTheRecordDownloads() { 40 public void cancelOffTheRecordDownloads() {
37 super.cancelOffTheRecordDownloads(); 41 super.cancelOffTheRecordDownloads();
38 mPaused = true; 42 mPaused = true;
39 } 43 }
40 44
41 @Override 45 @Override
46 boolean hasDownloadNotifications(Integer notificationIdToIgnore) {
47 if (!BuildInfo.isAtLeastO()) return false;
48 // Cancelling notifications here is synchronous, so we don't really have to worry about
49 // {@code notificationIdToIgnore}, but address it properly anyway.
50 if (mNotificationIds.size() == 1 && notificationIdToIgnore != null) {
51 return !mNotificationIds.contains(notificationIdToIgnore);
52 }
53
54 return !mNotificationIds.isEmpty();
55 }
56
57 @Override
58 void cancelSummaryNotification() {}
59
60 @Override
42 void updateNotification(int id, Notification notification) { 61 void updateNotification(int id, Notification notification) {
43 if (!mNotificationIds.contains(id)) { 62 if (!mNotificationIds.contains(id)) {
44 mNotificationIds.add(id); 63 mNotificationIds.add(id);
45 mLastNotificationId = id; 64 mLastNotificationId = id;
46 } 65 }
47 } 66 }
48 67
49 public boolean isPaused() { 68 public boolean isPaused() {
50 return mPaused; 69 return mPaused;
51 } 70 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 public void notifyDownloadCanceled(final String downloadGuid) { 134 public void notifyDownloadCanceled(final String downloadGuid) {
116 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 135 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
117 @Override 136 @Override
118 public void run() { 137 public void run() {
119 MockDownloadNotificationService.super.notifyDownloadCanceled(dow nloadGuid); 138 MockDownloadNotificationService.super.notifyDownloadCanceled(dow nloadGuid);
120 } 139 }
121 }); 140 });
122 } 141 }
123 } 142 }
124 143
OLDNEW
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/download/SystemDownloadNotifier.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698