Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Format and improve tests for Battery Status API
- Loading branch information
Showing
3 changed files
with
107 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,54 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>Battery Status Test: BatteryManager - charging</title> | ||
<link rel="author" title="Intel" href="http://www.intel.com"> | ||
<link rel="help" href="http://www.w3.org/TR/battery-status/"> | ||
<title>Battery Test: battery neither empty or full, charger plugged in</title> | ||
<meta name="flags" content="interact"> | ||
<meta name="assert" content="All of the navigator.battery attributes exist and are set to their correct values when battery is charging"> | ||
<link rel="author" title="Intel" href="http://www.intel.com"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<body> | ||
<h2>Preconditions</h2> | ||
<ol> | ||
<li> | ||
The device is plugged in to the charger before this test is run. | ||
</li> | ||
<li> | ||
The battery must neither be empty or full, nor reach empty or full capacity during the test. | ||
</li> | ||
<li> | ||
Waiting for battery level change to fire levelchange event, maybe need a long time | ||
</li> | ||
</ol> | ||
</body> | ||
|
||
<h2>Description</h2> | ||
<p> | ||
This test validates that all of the navigator.battery attributes exist and are set to their correct values when battery is charging. | ||
</p> | ||
|
||
<h2>Preconditions</h2> | ||
<ol> | ||
<li> | ||
The device is plugged in to the charger before this test is run. | ||
</li> | ||
<li> | ||
The battery must neither be empty or full, nor reach empty or full capacity during the test. | ||
</li> | ||
<li> | ||
Waiting for battery level change to fire levelchange event, maybe need a long time | ||
</li> | ||
</ol> | ||
|
||
<script> | ||
|
||
setup({ explicit_timeout: true }); | ||
|
||
async_test(function (t) { | ||
navigator.getBattery().then(function (battery) { | ||
t.step(function () { | ||
assert_true(battery.charging, 'The BatteryManager.charging must be set to true'); | ||
assert_less_than(battery.chargingTime, Infinity, 'The BatteryManager.chargingTime'); | ||
assert_equals(battery.dischargingTime, Infinity, 'The BatteryManager.dischargingTime'); | ||
assert_greater_than(battery.level, 0, 'The BatteryManager.level'); | ||
assert_less_than(battery.level, 1.0, 'The BatteryManager.level'); | ||
t.step(function () { | ||
assert_true(battery.charging, 'The BatteryManager.charging must be set to true'); | ||
assert_less_than(battery.chargingTime, Infinity, 'The BatteryManager.chargingTime'); | ||
assert_equals(battery.dischargingTime, Infinity, 'The BatteryManager.dischargingTime'); | ||
assert_greater_than(battery.level, 0, 'The BatteryManager.level'); | ||
assert_less_than(battery.level, 1.0, 'The BatteryManager.level'); | ||
|
||
var battery_level = battery.level; | ||
battery.onlevelchange = t.step_func(function (e) { | ||
assert_greater_than(e.level, battery_level, 'The value of the level attribute must increase'); | ||
t.done(); | ||
}); | ||
}); | ||
}, function (error) { | ||
t.step(function () { | ||
assert_unreached(error.message); | ||
var battery_level = battery.level; | ||
battery.onlevelchange = t.step_func(function (e) { | ||
assert_greater_than(battery.level, battery_level, 'The value of the level attribute must increase'); | ||
t.done(); | ||
}); | ||
t.done(); | ||
} | ||
) | ||
}); | ||
}, function (error) { | ||
t.step(function () { | ||
assert_unreached(error.message); | ||
}); | ||
t.done(); | ||
}); | ||
}, document.title); | ||
|
||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,54 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>Battery Status Test: BatteryManager - discharging</title> | ||
<link rel="author" title="Intel" href="http://www.intel.com"> | ||
<link rel="help" href="http://www.w3.org/TR/battery-status/"> | ||
<title>Battery Test: battery neither empty or full, charger unplugged in</title> | ||
<meta name="flags" content="interact"> | ||
<meta name="assert" content="All of the navigator.battery attributes exist and are set to their correct values when battery is discharging"> | ||
<link rel="author" title="Intel" href="http://www.intel.com"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<body> | ||
<h2>Preconditions</h2> | ||
<ol> | ||
<li> | ||
The device is unplugged from the charger before this test is run. | ||
</li> | ||
<li> | ||
The battery must neither be empty or full, nor reach empty or full capacity during the test. | ||
</li> | ||
<li> | ||
Waiting for battery level change to fire levelchange event, maybe need a long time | ||
</li> | ||
</ol> | ||
</body> | ||
|
||
<h2>Description</h2> | ||
<p> | ||
This test validates that all of the navigator.battery attributes exist and are set to their correct values when battery is discharging. | ||
</p> | ||
|
||
<h2>Preconditions</h2> | ||
<ol> | ||
<li> | ||
The device is unplugged from the charger before this test is run. | ||
</li> | ||
<li> | ||
The battery must neither be empty or full, nor reach empty or full capacity during the test. | ||
</li> | ||
<li> | ||
Waiting for battery level change to fire levelchange event, maybe need a long time | ||
</li> | ||
</ol> | ||
|
||
<script> | ||
|
||
setup({ explicit_timeout: true }); | ||
|
||
async_test(function (t) { | ||
navigator.getBattery().then(function (battery) { | ||
t.step(function () { | ||
assert_false(battery.charging, 'The BatteryManager.charging must be set to false'); | ||
assert_equals(battery.chargingTime, Infinity, 'The BatteryManager.chargingTime'); | ||
assert_less_than(battery.dischargingTime, Infinity, 'The BatteryManager.dischargingTime'); | ||
assert_greater_than(battery.level, 0, 'The BatteryManager.level'); | ||
assert_less_than(battery.level, 1.0, 'The BatteryManager.level'); | ||
t.step(function () { | ||
assert_false(battery.charging, 'The BatteryManager.charging must be set to false'); | ||
assert_equals(battery.chargingTime, Infinity, 'The BatteryManager.chargingTime'); | ||
assert_less_than(battery.dischargingTime, Infinity, 'The BatteryManager.dischargingTime'); | ||
assert_greater_than(battery.level, 0, 'The BatteryManager.level'); | ||
assert_less_than(battery.level, 1.0, 'The BatteryManager.level'); | ||
|
||
var battery_level = battery.level; | ||
battery.onlevelchange = t.step_func(function (e) { | ||
assert_less_than(e.level, battery_level, 'The value of the level attribute must decrease'); | ||
t.done(); | ||
}); | ||
}); | ||
}, function (error) { | ||
t.step(function () { | ||
assert_unreached(error.message); | ||
var battery_level = battery.level; | ||
battery.onlevelchange = t.step_func(function (e) { | ||
assert_less_than(battery.level, battery_level, 'The value of the level attribute must decrease'); | ||
t.done(); | ||
}); | ||
t.done(); | ||
} | ||
) | ||
}); | ||
}, function (error) { | ||
t.step(function () { | ||
assert_unreached(error.message); | ||
}); | ||
t.done(); | ||
}); | ||
}, document.title); | ||
|
||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,43 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>Battery Status Test: BatteryManager - full</title> | ||
<link rel="author" title="Intel" href="http://www.intel.com"> | ||
<link rel="help" href="http://www.w3.org/TR/battery-status/"> | ||
<title>Battery Test: battery full, charger plugged in</title> | ||
<meta name="flags" content="interact"> | ||
<meta name="assert" content="All of the navigator.battery attributes exist and are set to their correct values when battery is full"> | ||
<link rel="author" title="Intel" href="http://www.intel.com"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<body> | ||
<h2>Preconditions</h2> | ||
<ol> | ||
<li> | ||
The device is plugged in to the charger before this test is run. | ||
</li> | ||
<li> | ||
The battery is full. | ||
</li> | ||
</ol> | ||
</body> | ||
|
||
<h2>Description</h2> | ||
<p> | ||
This test validates that all of the navigator.battery attributes exist and are set to their correct values when battery is full. | ||
</p> | ||
|
||
<h2>Preconditions</h2> | ||
<ol> | ||
<li> | ||
The device is plugged in to the charger before this test is run. | ||
</li> | ||
<li> | ||
The battery is full. | ||
</li> | ||
</ol> | ||
|
||
<script> | ||
|
||
async_test(function (t) { | ||
navigator.getBattery().then(function (battery) { | ||
t.step(function () { | ||
assert_true(battery.charging, 'The BatteryManager.charging must be set to true'); | ||
assert_equals(battery.chargingTime, 0, 'The BatteryManager.chargingTime'); | ||
assert_equals(battery.dischargingTime, Infinity, 'The BatteryManager.dischargingTime'); | ||
assert_equals(battery.level, 1.0, 'The BatteryManager.level'); | ||
}); | ||
t.done(); | ||
}, function (error) { | ||
t.step(function () { | ||
assert_unreached(error.message); | ||
}); | ||
t.done(); | ||
} | ||
) | ||
t.step(function () { | ||
assert_true(battery.charging, 'The BatteryManager.charging must be set to true'); | ||
assert_equals(battery.chargingTime, 0, 'The BatteryManager.chargingTime'); | ||
assert_equals(battery.dischargingTime, Infinity, 'The BatteryManager.dischargingTime'); | ||
assert_equals(battery.level, 1.0, 'The BatteryManager.level'); | ||
}); | ||
t.done(); | ||
}, function (error) { | ||
t.step(function () { | ||
assert_unreached(error.message); | ||
}); | ||
t.done(); | ||
}); | ||
}, document.title); | ||
|
||
</script> |