Skip to content

Commit

Permalink
Consolidate/simplify StorageEvent constructor tests
Browse files Browse the repository at this point in the history
The use of `async_test` was already unnecessary as `dispatchEvent`
synchronously invokes listeners, and use of `dispatcEvent` itself is
not necessary to test the constructor, so simplify to just `test`s.
  • Loading branch information
foolip committed Oct 5, 2018
1 parent c4fce5c commit bd5f340
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 129 deletions.
87 changes: 68 additions & 19 deletions webstorage/event_constructor.html
Original file line number Diff line number Diff line change
@@ -1,32 +1,81 @@
<!DOCTYPE HTML>
<html>
<head>
<title>WebStorage Test: StorageEvent - init value</title>
<title>WebStorage Test: StorageEvent - constructor</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<h1>event_session_Constructor</h1>
<div id="log"></div>
<script>
test(function() {
var t = async_test("storageeventinit test");
function onStorageEvent(event) {
t.step(function() {
assert_equals(event.type, 'storage');
assert_equals(event.key, null);
assert_equals(event.oldValue, null);
assert_equals(event.newValue, null);
assert_equals(event.url, '');
assert_equals(event.storageArea, null);
});
t.done();
}
assert_throws(new 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');

window.addEventListener('storage', onStorageEvent, false);
var event = new StorageEvent('storage');
window.dispatchEvent(event);
}, "The initial values of storage event properties.");
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');
</script>
</body>
</html>
34 changes: 0 additions & 34 deletions webstorage/event_constructor_eventinit.html

This file was deleted.

37 changes: 0 additions & 37 deletions webstorage/event_local_storageeventinit.html

This file was deleted.

36 changes: 0 additions & 36 deletions webstorage/event_session_storageeventinit.html

This file was deleted.

3 changes: 0 additions & 3 deletions webstorage/missing_arguments.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<h1>missing_arguments</h1>
<div id="log"></div>
<script>
var tests = [
function() { localStorage.key(); },
Expand All @@ -20,7 +18,6 @@ <h1>missing_arguments</h1>
function() { sessionStorage.setItem(); },
function() { sessionStorage.setItem("a"); },
function() { sessionStorage.removeItem(); },
function() { new StorageEvent(); }
];
tests.forEach(function(fun) {
test(function() {
Expand Down

0 comments on commit bd5f340

Please sign in to comment.