OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.chrome.browser.omaha; |
| 6 |
| 7 import static junit.framework.Assert.assertNotNull; |
| 8 |
| 9 import android.app.AlarmManager; |
| 10 import android.app.PendingIntent; |
| 11 import android.content.Context; |
| 12 |
| 13 /** |
| 14 * Overrides the setAlarm function and allows changing the clock. |
| 15 */ |
| 16 public class MockExponentialBackoffScheduler extends ExponentialBackoffScheduler
{ |
| 17 private boolean mAlarmWasSet; |
| 18 private long mAlarmTimestamp; |
| 19 private long mCurrentTimestamp; |
| 20 |
| 21 public MockExponentialBackoffScheduler(String packageName, Context context, |
| 22 long baseMilliseconds, long maxMilliseconds) { |
| 23 super(packageName, context, baseMilliseconds, maxMilliseconds); |
| 24 } |
| 25 |
| 26 @Override |
| 27 protected void setAlarm(AlarmManager am, long timestamp, PendingIntent retry
PIntent) { |
| 28 // Getting the Intent from the PendingIntent is not straightforward. |
| 29 // The delay is checked by another unit test. |
| 30 assertNotNull(am); |
| 31 assertNotNull(retryPIntent); |
| 32 mAlarmWasSet = true; |
| 33 mAlarmTimestamp = timestamp; |
| 34 } |
| 35 |
| 36 @Override |
| 37 public long getCurrentTime() { |
| 38 return mCurrentTimestamp; |
| 39 } |
| 40 |
| 41 public void setCurrentTime(long timestamp) { |
| 42 mCurrentTimestamp = timestamp; |
| 43 } |
| 44 |
| 45 public boolean getAlarmWasSet() { |
| 46 return mAlarmWasSet; |
| 47 } |
| 48 |
| 49 public long getAlarmTimestamp() { |
| 50 return mAlarmTimestamp; |
| 51 } |
| 52 } |
OLD | NEW |