tor-browser

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

optional-event-properties.https.html (12004B)


      1 <!DOCTYPE html>
      2 <script src="/resources/testharness.js"></script>
      3 <script src="/resources/testharnessreport.js"></script>
      4 <script>
      5 'use strict';
      6 
      7 function ObjectThrowingException() {};
      8 ObjectThrowingException.prototype.valueOf = () => { throw new Error('valueOf threw exception'); }
      9 ObjectThrowingException.prototype.__defineGetter__("x", () => { throw new Error('x getter exception'); });
     10 ObjectThrowingException.prototype.__defineGetter__("alpha", () => { throw new Error('alpha getter exception'); });
     11 const objectThrowingException = new ObjectThrowingException();
     12 
     13 test(test => {
     14  event = document.createEvent('DeviceMotionEvent');
     15  assert_equals(event.type, "");
     16  assert_equals(event.acceleration, null);
     17  assert_equals(event.accelerationIncludingGravity, null);
     18  assert_equals(event.rotationRate, null);
     19  assert_equals(event.interval, 0);
     20 }, 'Tests creating a DeviceMotionEvent.');
     21 
     22 test(test => {
     23  event = new DeviceMotionEvent('foo', {acceleration: {x: 0, y: 1, z: 2},
     24                                     accelerationIncludingGravity: {x: 3, y: 4, z: 5},
     25                                     rotationRate: {alpha: 6, beta: 7, gamma: 8},
     26                                     interval: 9});
     27  assert_equals(event.type, "foo");
     28  assert_equals(event.acceleration.x, 0);
     29  assert_equals(event.acceleration.y, 1);
     30  assert_equals(event.acceleration.z, 2);
     31  assert_equals(event.accelerationIncludingGravity.x, 3);
     32  assert_equals(event.accelerationIncludingGravity.y, 4);
     33  assert_equals(event.accelerationIncludingGravity.z, 5);
     34  assert_equals(event.rotationRate.alpha, 6);
     35  assert_equals(event.rotationRate.beta, 7);
     36  assert_equals(event.rotationRate.gamma, 8);
     37  assert_equals(event.interval, 9);
     38 }, 'Tests no missing value.');
     39 
     40 test(test => {
     41  try {
     42    event = new DeviceMotionEvent('', {acceleration: objectThrowingException,
     43                                       accelerationIncludingGravity: {x: 3, z: 5},
     44                                       rotationRate: {gamma: 8, beta: 7},
     45                                       interval: 9});
     46    assert_unreached("Invalid acceleration, must throw an Error exception");
     47  } catch (e) {
     48    assert_equals(e.name, "Error");
     49    assert_equals(e.message, "x getter exception");
     50  }
     51 }, 'Tests invalid acceleration.');
     52 
     53 test(test => {
     54  try {
     55    event = new DeviceMotionEvent('', {acceleration: {x: 0, y: 1, z: 2},
     56                                       accelerationIncludingGravity: objectThrowingException,
     57                                       rotationRate: {gamma: 8, beta: 7},
     58                                       interval: 9});
     59    assert_unreached("Invalid acelerationIncludingGravity, must throw an Error exception");
     60  } catch (e) {
     61    assert_equals(e.name, "Error");
     62    assert_equals(e.message, "x getter exception");
     63  }
     64 }, 'Tests invalid acelerationIncludingGravity.');
     65 
     66 test(test => {
     67  try {
     68    event = new DeviceMotionEvent('', {acceleration: {x: 0, y: 1, z: 2},
     69                                       accelerationIncludingGravity: {x: 3, z: 5},
     70                                       rotationRate: objectThrowingException,
     71                                       interval: 9});
     72    assert_unreached("Invalid rotationRate, must throw an Error exception");
     73  } catch (e) {
     74    assert_equals(e.name, "Error");
     75    assert_equals(e.message, "alpha getter exception");
     76  }
     77 }, 'Tests invalid rotationRate.');
     78 
     79 test(test => {
     80  try {
     81    event = new DeviceMotionEvent('', {acceleration: {x: objectThrowingException, y: 1, z: 2},
     82                                       accelerationIncludingGravity: {x: 3, y: 4, z: 5},
     83                                       rotationRate: {alpha: 6, beta: 7, gamma: 8},
     84                                       interval: 9});
     85    assert_unreached("Invalid acceleration.x, must throw an Error exception");
     86  } catch (e) {
     87    assert_equals(e.name, "Error");
     88    assert_equals(e.message, "valueOf threw exception");
     89  }
     90 }, 'Tests invalid acceleration.x.');
     91 
     92 test(test => {
     93  try {
     94    event = new DeviceMotionEvent('', {acceleration: {x: 0, y: 1, z: 2},
     95                                       accelerationIncludingGravity: {x: 3, y: objectThrowingException, z: 5},
     96                                       rotationRate: {alpha: 6, beta: 7, gamma: 8},
     97                                       interval: 9});
     98    assert_unreached("Invalid accelerationIncludingGravity.y, must throw an Error exception");
     99  } catch (e) {
    100    assert_equals(e.name, "Error");
    101    assert_equals(e.message, "valueOf threw exception");
    102  }
    103 }, 'Tests invalid accelerationIncludingGravity.y.');
    104 
    105 test(test => {
    106  try {
    107    event = new DeviceMotionEvent('', {acceleration: {x: 0, y: 1, z: 2},
    108                                       accelerationIncludingGravity: {x: 3, y: 4, z: 5},
    109                                       rotationRate: {alpha: 6, beta: 7, gamma: objectThrowingException},
    110                                       interval: 9});
    111    assert_unreached("Invalid rotationRate.gamma, must throw an Error exception");
    112  } catch (e) {
    113    assert_equals(e.name, "Error");
    114    assert_equals(e.message, "valueOf threw exception");
    115  }
    116 }, 'Tests invalid rotationRate.gamma.');
    117 
    118 test(test => {
    119  event = new DeviceMotionEvent('', {acceleration: {y: 1, x: 0},
    120                                     accelerationIncludingGravity: {x: 3, z: 5},
    121                                     rotationRate: {gamma: 8, beta: 7},
    122                                     interval: 9});
    123  assert_equals(event.acceleration.x, 0);
    124  assert_equals(event.acceleration.y, 1);
    125  assert_equals(event.acceleration.z, null);
    126  assert_equals(event.accelerationIncludingGravity.x, 3);
    127  assert_equals(event.accelerationIncludingGravity.y, null);
    128  assert_equals(event.accelerationIncludingGravity.z, 5);
    129  assert_equals(event.rotationRate.alpha, null);
    130  assert_equals(event.rotationRate.beta, 7);
    131  assert_equals(event.rotationRate.gamma, 8);
    132  assert_equals(event.interval, 9);
    133 }, 'Tests missing fields should be null.');
    134 
    135 test(test => {
    136  event = new DeviceMotionEvent('');
    137  assert_equals(event.acceleration, null);
    138  assert_equals(event.accelerationIncludingGravity, null);
    139  assert_equals(event.rotationRate, null);
    140  assert_equals(event.interval, 0);
    141 }, 'Tests DeviceMotionEvent default constructor.');
    142 
    143 test(test => {
    144  event = new DeviceMotionEvent('', {acceleration: [],
    145                                     accelerationIncludingGravity: [],
    146                                     rotationRate: [],
    147                                     interval: []});
    148  assert_equals(event.acceleration.x, null);
    149  assert_equals(event.acceleration.y, null);
    150  assert_equals(event.acceleration.z, null);
    151  assert_equals(event.accelerationIncludingGravity.x, null);
    152  assert_equals(event.accelerationIncludingGravity.y, null);
    153  assert_equals(event.accelerationIncludingGravity.z, null);
    154  assert_equals(event.rotationRate.alpha, null);
    155  assert_equals(event.rotationRate.beta, null);
    156  assert_equals(event.rotationRate.gamma, null);
    157  assert_equals(event.interval, 0);
    158 }, 'Tests all values are empty array.');
    159 
    160 test(test => {
    161  event = new DeviceMotionEvent('', {acceleration: [],
    162                                     accelerationIncludingGravity: undefined,
    163                                     rotationRate: undefined,
    164                                     interval: undefined});
    165  assert_equals(event.acceleration.x, null);
    166  assert_equals(event.acceleration.y, null);
    167  assert_equals(event.acceleration.z, null);
    168  assert_equals(event.accelerationIncludingGravity, null);
    169  assert_equals(event.rotationRate, null);
    170  assert_equals(event.interval, 0);
    171 }, 'Tests some values are empty array and some values are undefined.');
    172 
    173 test(test => {
    174  event = new DeviceMotionEvent('', {acceleration: null,
    175                                     accelerationIncludingGravity: null,
    176                                     rotationRate: null,
    177                                     interval: null});
    178  assert_equals(event.acceleration.x, null);
    179  assert_equals(event.acceleration.y, null);
    180  assert_equals(event.acceleration.z, null);
    181  assert_equals(event.accelerationIncludingGravity.x, null);
    182  assert_equals(event.accelerationIncludingGravity.y, null);
    183  assert_equals(event.accelerationIncludingGravity.z, null);
    184  assert_equals(event.rotationRate.alpha, null);
    185  assert_equals(event.rotationRate.beta, null);
    186  assert_equals(event.rotationRate.gamma, null);
    187  assert_equals(event.interval, 0);
    188 }, "Tests all values are null.");
    189 
    190 test(test => {
    191  event = new DeviceMotionEvent('', {acceleration: {x: null, y: null, z: null},
    192                                     accelerationIncludingGravity: {x: null, y: null, z: null},
    193                                     rotationRate: {alpha: null, beta: null, gamma: null},
    194                                     interval: null});
    195  assert_equals(event.acceleration.x, null);
    196  assert_equals(event.acceleration.y, null);
    197  assert_equals(event.acceleration.z, null);
    198  assert_equals(event.accelerationIncludingGravity.x, null);
    199  assert_equals(event.accelerationIncludingGravity.y, null);
    200  assert_equals(event.accelerationIncludingGravity.z, null);
    201  assert_equals(event.rotationRate.alpha, null);
    202  assert_equals(event.rotationRate.beta, null);
    203  assert_equals(event.rotationRate.gamma, null);
    204  assert_equals(event.interval, 0);
    205 }, 'Tests all fields are null.');
    206 
    207 test(test => {
    208  event = new DeviceMotionEvent('', {acceleration: {x: null, y: null, z: 1},
    209                                     accelerationIncludingGravity: {x: null, y: null, z: 2},
    210                                     rotationRate: {alpha: null, beta: null, gamma: 3},
    211                                     interval: null});
    212  assert_equals(event.acceleration.x, null);
    213  assert_equals(event.acceleration.y, null);
    214  assert_equals(event.acceleration.z, 1);
    215  assert_equals(event.accelerationIncludingGravity.x, null);
    216  assert_equals(event.accelerationIncludingGravity.y, null);
    217  assert_equals(event.accelerationIncludingGravity.z, 2);
    218  assert_equals(event.rotationRate.alpha, null);
    219  assert_equals(event.rotationRate.beta, null);
    220  assert_equals(event.rotationRate.gamma, 3);
    221  assert_equals(event.interval, 0);
    222 }, 'Tests some fields are null.');
    223 
    224 test(test => {
    225  event = new DeviceMotionEvent('', {acceleration: {x: undefined, y: undefined, z: undefined},
    226                                     accelerationIncludingGravity: {x: undefined, y: undefined, z: undefined},
    227                                     rotationRate: {alpha: undefined, beta: undefined, gamma: undefined},
    228                                     interval: undefined});
    229  assert_equals(event.acceleration.x, null);
    230  assert_equals(event.acceleration.y, null);
    231  assert_equals(event.acceleration.z, null);
    232  assert_equals(event.accelerationIncludingGravity.x, null);
    233  assert_equals(event.accelerationIncludingGravity.y, null);
    234  assert_equals(event.accelerationIncludingGravity.z, null);
    235  assert_equals(event.rotationRate.alpha, null);
    236  assert_equals(event.rotationRate.beta, null);
    237  assert_equals(event.rotationRate.gamma, null);
    238  assert_equals(event.interval, 0);
    239 }, 'Tests all fields are undefined.');
    240 
    241 test(test => {
    242  event = new DeviceMotionEvent('', {acceleration: {x: undefined, y: undefined, z: 1},
    243                                     accelerationIncludingGravity: {x: undefined, y: undefined, z: 2},
    244                                     rotationRate: {alpha: undefined, beta: undefined, gamma: 3},
    245                                     interval: undefined});
    246  assert_equals(event.acceleration.x, null);
    247  assert_equals(event.acceleration.y, null);
    248  assert_equals(event.acceleration.z, 1);
    249  assert_equals(event.accelerationIncludingGravity.x, null);
    250  assert_equals(event.accelerationIncludingGravity.y, null);
    251  assert_equals(event.accelerationIncludingGravity.z, 2);
    252  assert_equals(event.rotationRate.alpha, null);
    253  assert_equals(event.rotationRate.beta, null);
    254  assert_equals(event.rotationRate.gamma, 3);
    255  assert_equals(event.interval, 0);
    256 }, 'Tests some fields are undefined.');
    257 </script>