OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.components.background_task_scheduler; |
| 6 |
| 7 import com.google.android.gms.gcm.GcmNetworkManager; |
| 8 import com.google.android.gms.gcm.GcmTaskService; |
| 9 import com.google.android.gms.gcm.Task; |
| 10 |
| 11 import org.robolectric.annotation.Implementation; |
| 12 import org.robolectric.annotation.Implements; |
| 13 |
| 14 /** |
| 15 * Custom shadow for the OS's GcmNetworkManager. We use this to hook the call t
o GcmNetworkManager |
| 16 * to make sure it was invoked as we expect. |
| 17 */ |
| 18 @Implements(GcmNetworkManager.class) |
| 19 public class ShadowGcmNetworkManager { |
| 20 private Task mTask; |
| 21 private Task mCanceledTask; |
| 22 |
| 23 @Implementation |
| 24 public void schedule(Task task) { |
| 25 mTask = task; |
| 26 mCanceledTask = null; |
| 27 } |
| 28 |
| 29 @Implementation |
| 30 public void cancelTask(String tag, Class<? extends GcmTaskService> gcmTaskSe
rvice) { |
| 31 if (mTask != null && mTask.getTag().equals(tag) |
| 32 && mTask.getServiceName().equals(gcmTaskService.getName())) { |
| 33 mCanceledTask = mTask; |
| 34 mTask = null; |
| 35 } |
| 36 } |
| 37 |
| 38 public Task getScheduledTask() { |
| 39 return mTask; |
| 40 } |
| 41 |
| 42 public Task getCanceledTask() { |
| 43 return mCanceledTask; |
| 44 } |
| 45 |
| 46 public void clear() { |
| 47 mTask = null; |
| 48 mCanceledTask = null; |
| 49 } |
| 50 } |
OLD | NEW |