| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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.content.browser; | 5 package org.chromium.content.browser; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 import android.content.Intent; | 8 import android.content.Intent; |
| 9 | 9 |
| 10 import android.os.BatteryManager; | 10 import android.os.BatteryManager; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 @Override | 22 @Override |
| 23 public void setUp() throws Exception { | 23 public void setUp() throws Exception { |
| 24 super.setUp(); | 24 super.setUp(); |
| 25 mBatteryStatusManager = BatteryStatusManagerForTests.getInstance(getCont
ext()); | 25 mBatteryStatusManager = BatteryStatusManagerForTests.getInstance(getCont
ext()); |
| 26 } | 26 } |
| 27 | 27 |
| 28 @SmallTest | 28 @SmallTest |
| 29 public void testOnReceiveBatteryDischarging() { | 29 public void testOnReceiveBatteryDischarging() { |
| 30 Intent intent = new Intent(Intent.ACTION_BATTERY_CHANGED); | 30 Intent intent = new Intent(Intent.ACTION_BATTERY_CHANGED); |
| 31 intent.putExtra(BatteryManager.EXTRA_PRESENT, true); |
| 31 intent.putExtra(BatteryManager.EXTRA_LEVEL, 10); | 32 intent.putExtra(BatteryManager.EXTRA_LEVEL, 10); |
| 32 intent.putExtra(BatteryManager.EXTRA_SCALE, 100); | 33 intent.putExtra(BatteryManager.EXTRA_SCALE, 100); |
| 33 intent.putExtra(BatteryManager.EXTRA_STATUS, BatteryManager.BATTERY_STAT
US_DISCHARGING); | 34 intent.putExtra(BatteryManager.EXTRA_STATUS, BatteryManager.BATTERY_STAT
US_DISCHARGING); |
| 34 | 35 |
| 35 mBatteryStatusManager.onReceive(intent); | 36 mBatteryStatusManager.onReceive(intent); |
| 36 | 37 |
| 37 mBatteryStatusManager.verifyCalls("gotBatteryStatus"); | 38 mBatteryStatusManager.verifyCalls("gotBatteryStatus"); |
| 38 mBatteryStatusManager.verifyValues(false, Double.POSITIVE_INFINITY, | 39 mBatteryStatusManager.verifyValues(false, Double.POSITIVE_INFINITY, |
| 39 Double.POSITIVE_INFINITY, 0.1); | 40 Double.POSITIVE_INFINITY, 0.1); |
| 40 } | 41 } |
| 41 | 42 |
| 42 @SmallTest | 43 @SmallTest |
| 43 public void testOnReceiveBatteryCharging() { | 44 public void testOnReceiveBatteryCharging() { |
| 44 Intent intent = new Intent(Intent.ACTION_BATTERY_CHANGED); | 45 Intent intent = new Intent(Intent.ACTION_BATTERY_CHANGED); |
| 46 intent.putExtra(BatteryManager.EXTRA_PRESENT, true); |
| 45 intent.putExtra(BatteryManager.EXTRA_LEVEL, 50); | 47 intent.putExtra(BatteryManager.EXTRA_LEVEL, 50); |
| 46 intent.putExtra(BatteryManager.EXTRA_SCALE, 100); | 48 intent.putExtra(BatteryManager.EXTRA_SCALE, 100); |
| 47 intent.putExtra(BatteryManager.EXTRA_STATUS, BatteryManager.BATTERY_STAT
US_CHARGING); | 49 intent.putExtra(BatteryManager.EXTRA_STATUS, BatteryManager.BATTERY_STAT
US_CHARGING); |
| 48 | 50 |
| 49 mBatteryStatusManager.onReceive(intent); | 51 mBatteryStatusManager.onReceive(intent); |
| 50 | 52 |
| 51 mBatteryStatusManager.verifyCalls("gotBatteryStatus"); | 53 mBatteryStatusManager.verifyCalls("gotBatteryStatus"); |
| 52 mBatteryStatusManager.verifyValues(true, Double.POSITIVE_INFINITY, | 54 mBatteryStatusManager.verifyValues(true, Double.POSITIVE_INFINITY, |
| 53 Double.POSITIVE_INFINITY, 0.5); | 55 Double.POSITIVE_INFINITY, 0.5); |
| 54 } | 56 } |
| 55 | 57 |
| 56 @SmallTest | 58 @SmallTest |
| 57 public void testOnReceiveBatteryFull() { | 59 public void testOnReceiveBatteryFull() { |
| 58 Intent intent = new Intent(Intent.ACTION_BATTERY_CHANGED); | 60 Intent intent = new Intent(Intent.ACTION_BATTERY_CHANGED); |
| 61 intent.putExtra(BatteryManager.EXTRA_PRESENT, true); |
| 59 intent.putExtra(BatteryManager.EXTRA_LEVEL, 100); | 62 intent.putExtra(BatteryManager.EXTRA_LEVEL, 100); |
| 60 intent.putExtra(BatteryManager.EXTRA_SCALE, 100); | 63 intent.putExtra(BatteryManager.EXTRA_SCALE, 100); |
| 61 intent.putExtra(BatteryManager.EXTRA_STATUS, BatteryManager.BATTERY_STAT
US_FULL); | 64 intent.putExtra(BatteryManager.EXTRA_STATUS, BatteryManager.BATTERY_STAT
US_FULL); |
| 62 | 65 |
| 63 mBatteryStatusManager.onReceive(intent); | 66 mBatteryStatusManager.onReceive(intent); |
| 64 | 67 |
| 65 mBatteryStatusManager.verifyCalls("gotBatteryStatus"); | 68 mBatteryStatusManager.verifyCalls("gotBatteryStatus"); |
| 66 mBatteryStatusManager.verifyValues(true, 0, Double.POSITIVE_INFINITY, 1)
; | 69 mBatteryStatusManager.verifyValues(true, 0, Double.POSITIVE_INFINITY, 1)
; |
| 67 } | 70 } |
| 68 | 71 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 assertEquals(chargingTime, mChargingTime); | 110 assertEquals(chargingTime, mChargingTime); |
| 108 assertEquals(dischargingTime, mDischargingTime); | 111 assertEquals(dischargingTime, mDischargingTime); |
| 109 assertEquals(level, mLevel); | 112 assertEquals(level, mLevel); |
| 110 } | 113 } |
| 111 | 114 |
| 112 private void verifyCalls(String names) { | 115 private void verifyCalls(String names) { |
| 113 assertEquals(mCalls, names); | 116 assertEquals(mCalls, names); |
| 114 } | 117 } |
| 115 | 118 |
| 116 @Override | 119 @Override |
| 120 protected boolean batteryPresentByDefault() { |
| 121 return false; |
| 122 } |
| 123 |
| 124 @Override |
| 117 protected void gotBatteryStatus(boolean charging, double chargingTime, | 125 protected void gotBatteryStatus(boolean charging, double chargingTime, |
| 118 double dischargingTime, double level) { | 126 double dischargingTime, double level) { |
| 119 mCharging = charging; | 127 mCharging = charging; |
| 120 mChargingTime = chargingTime; | 128 mChargingTime = chargingTime; |
| 121 mDischargingTime = dischargingTime; | 129 mDischargingTime = dischargingTime; |
| 122 mLevel = level; | 130 mLevel = level; |
| 123 mCalls = mCalls.concat("gotBatteryStatus"); | 131 mCalls = mCalls.concat("gotBatteryStatus"); |
| 124 } | 132 } |
| 125 } | 133 } |
| 126 | 134 |
| 127 } | 135 } |
| OLD | NEW |