tor-browser

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

event_constructor.window.js (2878B)


      1 test(function() {
      2    assert_throws_js(
      3        TypeError,
      4        () => StorageEvent(""),
      5        "Calling StorageEvent constructor without 'new' must throw"
      6    );
      7 }, "StorageEvent constructor called as normal function");
      8 
      9 test(function() {
     10    assert_throws_js(TypeError, () => new StorageEvent());
     11    // should be redundant, but .length can be wrong with custom bindings
     12    assert_equals(StorageEvent.length, 1, 'StorageEvent.length');
     13 }, 'constructor with no arguments');
     14 
     15 test(function() {
     16    var event = new StorageEvent('type');
     17    assert_equals(event.type, 'type', 'type');
     18    assert_equals(event.key, null, 'key');
     19    assert_equals(event.oldValue, null, 'oldValue');
     20    assert_equals(event.newValue, null, 'newValue');
     21    assert_equals(event.url, '', 'url');
     22    assert_equals(event.storageArea, null, 'storageArea');
     23 }, 'constructor with just type argument');
     24 
     25 test(function() {
     26    assert_not_equals(localStorage, null, 'localStorage'); // precondition
     27 
     28    var event = new StorageEvent('storage', {
     29        bubbles: true,
     30        cancelable: true,
     31        key: 'key',
     32        oldValue: 'oldValue',
     33        newValue: 'newValue',
     34        url: 'url', // not an absolute URL to ensure it isn't resolved
     35        storageArea: localStorage
     36    });
     37    assert_equals(event.type, 'storage', 'type');
     38    assert_equals(event.bubbles, true, 'bubbles');
     39    assert_equals(event.cancelable, true, 'cancelable');
     40    assert_equals(event.key, 'key', 'key');
     41    assert_equals(event.oldValue, 'oldValue', 'oldValue');
     42    assert_equals(event.newValue, 'newValue', 'newValue');
     43    assert_equals(event.url, 'url', 'url');
     44    assert_equals(event.storageArea, localStorage, 'storageArea');
     45 }, 'constructor with sensible type argument and members');
     46 
     47 test(function() {
     48    var event = new StorageEvent(null, {
     49        key: null,
     50        oldValue: null,
     51        newValue: null,
     52        url: null,
     53        storageArea: null
     54    });
     55    assert_equals(event.type, 'null', 'type');
     56    assert_equals(event.key, null, 'key');
     57    assert_equals(event.oldValue, null, 'oldValue');
     58    assert_equals(event.newValue, null, 'newValue');
     59    assert_equals(event.url, 'null', 'url');
     60    assert_equals(event.storageArea, null, 'storageArea');
     61 }, 'constructor with null type argument and members');
     62 
     63 test(function() {
     64    var event = new StorageEvent(undefined, {
     65        key: undefined,
     66        oldValue: undefined,
     67        newValue: undefined,
     68        url: undefined,
     69        storageArea: undefined
     70    });
     71    assert_equals(event.type, 'undefined', 'type');
     72    assert_equals(event.key, null, 'key');
     73    assert_equals(event.oldValue, null, 'oldValue');
     74    assert_equals(event.newValue, null, 'newValue');
     75    assert_equals(event.url, '', 'url'); // not 'undefined'!
     76    assert_equals(event.storageArea, null, 'storageArea');
     77 }, 'constructor with undefined type argument and members');