tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

battery-plugging-in-manual.https.html (4020B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <title>Battery Test: battery not full, charger plugging in</title>
      4 <link rel="author" title="Intel" href="http://www.intel.com">
      5 <link rel="help" href="https://www.w3.org/TR/battery-status/">
      6 <meta name="flags" content="interact">
      7 <script src="/resources/testharness.js"></script>
      8 <script src="/resources/testharnessreport.js"></script>
      9 <style>
     10  #note {
     11    background-color: #fef1b5;
     12    border: solid 1px #cdab2d;
     13    padding: 5px;
     14    margin: 15px;
     15    display: block;
     16  }
     17 </style>
     18 
     19 <h2>Description</h2>
     20 <p>
     21  This test validates that all of the BatteryManager attributes exist and
     22  are set to correct values, with corresponding events fired,
     23  when the charger is plugged in.
     24 </p>
     25 
     26 <h2>Preconditions</h2>
     27 <ol>
     28  <li>
     29    The device is unplugged from the charger before this test is run.
     30  </li>
     31  <li>
     32    The battery must not be full or reach full capacity before the time the test is run.
     33  </li>
     34 </ol>
     35 
     36 <div id="note">
     37  <ol>
     38    <li>
     39      Plug in the charger and wait for all the tests to complete.
     40    </li>
     41    <li>
     42      The tests may take long time since the definition of how
     43      often the chargingtimechange, dischargingtimechange, and levelchange
     44      events are fired is left to the implementation.
     45    </li>
     46  </ol>
     47 </div>
     48 
     49 <div id="log"></div>
     50 
     51 <script>
     52 
     53 (function() {
     54 
     55  setup({ explicit_timeout: true });
     56 
     57  var onchargingchange_test = async_test(
     58      'When the device is plugged in and its charging state is updated, ' +
     59      'must set the charging attribute\'s value to true and ' +
     60      'fire a chargingchange event.');
     61  var onchargingtimechange_test = async_test(
     62      'When the device is plugged in and its charging time is updated, ' +
     63      'must set the chargingTime attribute\'s value and fire ' +
     64      'a chargingtimechange event.');
     65  var ondischargingtimechange_test = async_test(
     66      'When the device is plugged in and its discharging time is updated, ' +
     67      'must set the dischargingTime attribute\'s value to Infinity and ' +
     68      'fire a dischargingtimechange event.');
     69  var onlevelchange_test = async_test(
     70      'When the device is plugged in and the battery level is updated, ' +
     71      'must set the level attribute\'s value and fire a levelchange event.');
     72 
     73  var batterySuccess = function (battery) {
     74    battery.onchargingchange = onchargingchange_test.step_func(function () {
     75      assert_true(battery.charging, 'The charging attribute must be set to true.');
     76      onchargingchange_test.done();
     77    });
     78 
     79    var battery_chargingtime = battery.chargingTime;
     80    battery.onchargingtimechange = onchargingtimechange_test.step_func(function () {
     81      assert_less_than(battery.chargingTime, battery_chargingtime,
     82          'The value of the chargingTime attribute must decrease.');
     83      onchargingtimechange_test.done();
     84    });
     85 
     86    battery.ondischargingtimechange = ondischargingtimechange_test.step_func(function () {
     87      if (battery.charging) {
     88        assert_equals(battery.dischargingTime, Infinity,
     89            'The value of the dischargingTime attribute must be set to Infinity.');
     90        ondischargingtimechange_test.done();
     91      }
     92    });
     93 
     94    battery.onlevelchange = onlevelchange_test.step_func(function () {
     95      assert_greater_than(battery.level, 0);
     96      assert_less_than_equal(battery.level, 1.0);
     97      onlevelchange_test.done();
     98    });
     99  };
    100 
    101  var batteryFailure = function (error) {
    102    onchargingchange_test.step(function () {
    103      assert_unreached(error.message);
    104    });
    105    onchargingchange_test.done();
    106 
    107    onchargingtimechange_test.step(function () {
    108      assert_unreached(error.message);
    109    });
    110    onchargingtimechange_test.done();
    111 
    112    ondischargingtimechange_test.step(function () {
    113      assert_unreached(error.message);
    114    });
    115    ondischargingtimechange_test.done();
    116 
    117    onlevelchange_test.step(function () {
    118      assert_unreached(error.message);
    119     });
    120    onlevelchange_test.done();
    121  };
    122 
    123  navigator.getBattery().then(batterySuccess, batteryFailure);
    124 
    125 })();
    126 
    127 </script>