Skip to content

Commit

Permalink
Format and improve tests for Battery Status API
Browse files Browse the repository at this point in the history
  • Loading branch information
kangxu committed Feb 11, 2015
1 parent db337b7 commit 8978c38
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 101 deletions.
74 changes: 38 additions & 36 deletions battery-status/battery-charging-manual.html
@@ -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>
74 changes: 38 additions & 36 deletions battery-status/battery-discharging-manual.html
@@ -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>
60 changes: 31 additions & 29 deletions battery-status/battery-full-manual.html
@@ -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>

0 comments on commit 8978c38

Please sign in to comment.