Bug 1496735 [wpt PR 13368] - Test StorageEvent constructor and initStorageEvent(), a=testonly
authorPhilip Jägenstedt <philip@foolip.org>
Thu, 11 Oct 2018 09:31:15 +0000
changeset 489251 e726946c50a836304adcf437ca93290e061e2a71
parent 489250 e9a34a40b5ed39b0a88dc1e2705cfa3682a1956d
child 489252 6d4ab386a8639ac055a96ebc4b6e56a4323bb1dc
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewerstestonly
bugs1496735, 13368
milestone64.0a1
Bug 1496735 [wpt PR 13368] - Test StorageEvent constructor and initStorageEvent(), a=testonly Automatic update from web-platform-testsTest initStorageEvent() Follows https://github.com/whatwg/html/pull/4063. -- Consolidate/simplify StorageEvent constructor tests 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. -- wpt-commits: c4fce5c3c37e30b192a596c4dc779e4192f1bc12, bd5f3403f34f8e83eecbdc172cd330039e12ab86 wpt-pr: 13368
testing/web-platform/tests/webstorage/event_constructor.html
testing/web-platform/tests/webstorage/event_constructor_eventinit.html
testing/web-platform/tests/webstorage/event_initstorageevent.html
testing/web-platform/tests/webstorage/event_local_storageeventinit.html
testing/web-platform/tests/webstorage/event_session_storageeventinit.html
testing/web-platform/tests/webstorage/missing_arguments.html
--- a/testing/web-platform/tests/webstorage/event_constructor.html
+++ b/testing/web-platform/tests/webstorage/event_constructor.html
@@ -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');
+
+        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
 
-            window.addEventListener('storage', onStorageEvent, false);
-            var event = new StorageEvent('storage');
-            window.dispatchEvent(event);
-        }, "The initial values of storage event properties.");
+            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>
deleted file mode 100644
--- a/testing/web-platform/tests/webstorage/event_constructor_eventinit.html
+++ /dev/null
@@ -1,34 +0,0 @@
-<!DOCTYPE HTML>
-<html>
- <head>
-  <title>WebStorage Test: StorageEvent - StorageEventInit with null value</title>
-  <script src="/resources/testharness.js"></script>
-  <script src="/resources/testharnessreport.js"></script>
- </head>
- <body>
-    <h1>event_Constructor</h1>
-    <div id="log"></div>
-    <script>
-        async_test(function(t) {
-            function onStorageEvent(event) {
-                assert_equals(event.type, 'storage', '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');
-                t.done();
-            }
-
-            window.addEventListener('storage', t.step_func(onStorageEvent), false);
-            var event = new StorageEvent('storage', {
-                key: null,
-                oldValue: null,
-                newValue: null,
-                url: null
-            });
-            window.dispatchEvent(event);
-        }, "StorageEvent constructor and nulls - Construct StorageEvent with StorageEventInit.");
-    </script>
- </body>
-</html>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/webstorage/event_initstorageevent.html
@@ -0,0 +1,72 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+  <title>WebStorage Test: StorageEvent - initStorageEvent</title>
+  <script src="/resources/testharness.js"></script>
+  <script src="/resources/testharnessreport.js"></script>
+ </head>
+ <body>
+    <script>
+        test(() => {
+            const event = new StorageEvent('storage');
+            assert_throws(new TypeError, () => event.initStorageEvent());
+            // should be redundant, but .length can be wrong with custom bindings
+            assert_equals(event.initStorageEvent.length, 1, 'event.initStorageEvent.length');
+        }, 'initStorageEvent with 0 arguments');
+
+        test(() => {
+            const event = new StorageEvent('storage');
+            event.initStorageEvent('type');
+            assert_equals(event.type, 'type', 'event.type');
+            assert_equals(event.bubbles, false, 'event.bubbles');
+            assert_equals(event.cancelable, false, 'event.cancelable');
+            assert_equals(event.key, null, 'event.key');
+            assert_equals(event.oldValue, null, 'event.oldValue');
+            assert_equals(event.newValue, null, 'event.newValue');
+            assert_equals(event.url, '', 'event.url');
+            assert_equals(event.storageArea, null, 'event.storageArea');
+        }, 'initStorageEvent with 1 argument');
+
+        test(() => {
+            assert_not_equals(localStorage, null, 'localStorage'); // precondition
+
+            const event = new StorageEvent('storage');
+            event.initStorageEvent('type', true, true, 'key', 'oldValue', 'newValue', 'url', localStorage);
+            assert_equals(event.type, 'type', 'event.type');
+            assert_equals(event.bubbles, true, 'event.bubbles');
+            assert_equals(event.cancelable, true, 'event.cancelable');
+            assert_equals(event.key, 'key', 'event.key');
+            assert_equals(event.oldValue, 'oldValue', 'event.oldValue');
+            assert_equals(event.newValue, 'newValue', 'event.newValue');
+            assert_equals(event.url, 'url', 'event.url');
+            assert_equals(event.storageArea, localStorage, 'event.storageArea');
+        }, 'initStorageEvent with 8 sensible arguments');
+
+        test(() => {
+            const event = new StorageEvent('storage');
+            event.initStorageEvent(null, null, null, null, null, null, null, null);
+            assert_equals(event.type, 'null', 'event.type');
+            assert_equals(event.bubbles, false, 'event.bubbles');
+            assert_equals(event.cancelable, false, 'event.cancelable');
+            assert_equals(event.key, null, 'event.key');
+            assert_equals(event.oldValue, null, 'event.oldValue');
+            assert_equals(event.newValue, null, 'event.newValue');
+            assert_equals(event.url, 'null', 'event.url');
+            assert_equals(event.storageArea, null, 'event.storageArea');
+        }, 'initStorageEvent with 8 null arguments');
+
+        test(() => {
+            const event = new StorageEvent('storage');
+            event.initStorageEvent(undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined);
+            assert_equals(event.type, 'undefined', 'event.type');
+            assert_equals(event.bubbles, false, 'event.bubbles');
+            assert_equals(event.cancelable, false, 'event.cancelable');
+            assert_equals(event.key, null, 'event.key');
+            assert_equals(event.oldValue, null, 'event.oldValue');
+            assert_equals(event.newValue, null, 'event.newValue');
+            assert_equals(event.url, 'undefined', 'event.url');
+            assert_equals(event.storageArea, null, 'event.storageArea');
+        }, 'initStorageEvent with 8 undefined arguments');
+    </script>
+ </body>
+</html>
deleted file mode 100644
--- a/testing/web-platform/tests/webstorage/event_local_storageeventinit.html
+++ /dev/null
@@ -1,37 +0,0 @@
-<!DOCTYPE HTML>
-<html>
- <head>
-  <title>WebStorage Test: localStorage event - StorageEventInit</title>
-  <script src="/resources/testharness.js"></script>
-  <script src="/resources/testharnessreport.js"></script>
- </head>
- <body>
-    <h1>event_local_StorageEventInit</h1>
-    <div id="log"></div>
-    <script>
-        async_test(function(t) {
-
-            function onStorageEvent(event) {
-                assert_equals(event.key, 'key');
-                assert_equals(event.oldValue, 'oldValue');
-                assert_equals(event.newValue, 'newValue');
-                assert_equals(event.url, window.location.href);
-                assert_equals(event.storageArea, window.localStorage);
-                t.done();
-            }
-
-            window.addEventListener('storage', t.step_func(onStorageEvent), false);
-
-            var event = new StorageEvent('storage', {
-                key: 'key',
-                oldValue: 'oldValue',
-                newValue: 'newValue',
-                url: window.location.href,
-                storageArea: window.localStorage
-            });
-
-            window.dispatchEvent(event);
-        }, "storageeventinit test - Storage event is fired due to set values for StorageEventInit.");
-    </script>
- </body>
-</html>
deleted file mode 100644
--- a/testing/web-platform/tests/webstorage/event_session_storageeventinit.html
+++ /dev/null
@@ -1,36 +0,0 @@
-<!DOCTYPE HTML>
-<html>
- <head>
-  <title>WebStorage Test: sessionStorage event - StorageEventInit</title>
-  <script src="/resources/testharness.js"></script>
-  <script src="/resources/testharnessreport.js"></script>
- </head>
- <body>
-    <h1>event_session_StorageEventInit</h1>
-    <div id="log"></div>
-    <script>
-        async_test(function(t) {
-            function onStorageEvent(event) {
-                assert_equals(event.key, 'key');
-                assert_equals(event.oldValue, 'oldValue');
-                assert_equals(event.newValue, 'newValue');
-                assert_equals(event.url, window.location.href);
-                assert_equals(event.storageArea, window.sessionStorage);
-                t.done();
-            }
-
-            window.addEventListener('storage', t.step_func(onStorageEvent), false);
-
-            var event = new StorageEvent('storage', {
-                key: 'key',
-                oldValue: 'oldValue',
-                newValue: 'newValue',
-                url: window.location.href,
-                storageArea: window.sessionStorage
-            });
-
-            window.dispatchEvent(event);
-        }, "storageeventinit test - Storage event is fired due to set values for StorageEventInit.");
-    </script>
- </body>
-</html>
--- a/testing/web-platform/tests/webstorage/missing_arguments.html
+++ b/testing/web-platform/tests/webstorage/missing_arguments.html
@@ -1,31 +1,28 @@
 <!DOCTYPE HTML>
 <html>
  <head>
   <title>WebStorage Test: missing arguments</title>
   <script src="/resources/testharness.js"></script>
   <script src="/resources/testharnessreport.js"></script>
  </head>
  <body>
-    <h1>missing_arguments</h1>
-    <div id="log"></div>
     <script>
         var tests = [
             function() { localStorage.key(); },
             function() { localStorage.getItem(); },
             function() { localStorage.setItem(); },
             function() { localStorage.setItem("a"); },
             function() { localStorage.removeItem(); },
             function() { sessionStorage.key(); },
             function() { sessionStorage.getItem(); },
             function() { sessionStorage.setItem(); },
             function() { sessionStorage.setItem("a"); },
             function() { sessionStorage.removeItem(); },
-            function() { new StorageEvent(); }
         ];
         tests.forEach(function(fun) {
             test(function() {
                 assert_throws(new TypeError(), fun);
             }, "Should throw TypeError for " + format_value(fun) + ".");
         });
     </script>
  </body>