summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webstorage/event_constructor.window.js
blob: 13f4ca5e97ca45fd8ec4e55a4b955184e3414017 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
test(function() {
    assert_throws_js(
        TypeError,
        () => StorageEvent(""),
        "Calling StorageEvent constructor without 'new' must throw"
    );
}, "StorageEvent constructor called as normal function");

test(function() {
    assert_throws_js(TypeError, () => new StorageEvent());
    // should be redundant, but .length can be wrong with custom bindings
    assert_equals(StorageEvent.length, 1, 'StorageEvent.length');
}, 'constructor with no arguments');

test(function() {
    var event = new StorageEvent('type');
    assert_equals(event.type, 'type', 'type');
    assert_equals(event.key, null, 'key');
    assert_equals(event.oldValue, null, 'oldValue');
    assert_equals(event.newValue, null, 'newValue');
    assert_equals(event.url, '', 'url');
    assert_equals(event.storageArea, null, 'storageArea');
}, 'constructor with just type argument');

test(function() {
    assert_not_equals(localStorage, null, 'localStorage'); // precondition

    var event = new StorageEvent('storage', {
        bubbles: true,
        cancelable: true,
        key: 'key',
        oldValue: 'oldValue',
        newValue: 'newValue',
        url: 'url', // not an absolute URL to ensure it isn't resolved
        storageArea: localStorage
    });
    assert_equals(event.type, 'storage', 'type');
    assert_equals(event.bubbles, true, 'bubbles');
    assert_equals(event.cancelable, true, 'cancelable');
    assert_equals(event.key, 'key', 'key');
    assert_equals(event.oldValue, 'oldValue', 'oldValue');
    assert_equals(event.newValue, 'newValue', 'newValue');
    assert_equals(event.url, 'url', 'url');
    assert_equals(event.storageArea, localStorage, 'storageArea');
}, 'constructor with sensible type argument and members');

test(function() {
    var event = new StorageEvent(null, {
        key: null,
        oldValue: null,
        newValue: null,
        url: null,
        storageArea: null
    });
    assert_equals(event.type, 'null', 'type');
    assert_equals(event.key, null, 'key');
    assert_equals(event.oldValue, null, 'oldValue');
    assert_equals(event.newValue, null, 'newValue');
    assert_equals(event.url, 'null', 'url');
    assert_equals(event.storageArea, null, 'storageArea');
}, 'constructor with null type argument and members');

test(function() {
    var event = new StorageEvent(undefined, {
        key: undefined,
        oldValue: undefined,
        newValue: undefined,
        url: undefined,
        storageArea: undefined
    });
    assert_equals(event.type, 'undefined', 'type');
    assert_equals(event.key, null, 'key');
    assert_equals(event.oldValue, null, 'oldValue');
    assert_equals(event.newValue, null, 'newValue');
    assert_equals(event.url, '', 'url'); // not 'undefined'!
    assert_equals(event.storageArea, null, 'storageArea');
}, 'constructor with undefined type argument and members');