Bug 1641553 - Use `step_func` correctly in cookies/samesite WPTs, r=annevk
authorAndrea Marchesini <amarchesini@mozilla.com>
Fri, 29 May 2020 15:57:29 +0000
changeset 533014 af82aaf40744bdc87d2d846e730cc9178a060580
parent 533013 0c78e618f7eb5bff1b31255746d61f47650f6b8d
child 533015 4f08aad8bfd8ff567aa9bd8d65cc215fc50efb26
push id37461
push userccoroiu@mozilla.com
push dateFri, 29 May 2020 21:46:31 +0000
treeherdermozilla-central@a58cc68b0c51 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersannevk
bugs1641553
milestone78.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1641553 - Use `step_func` correctly in cookies/samesite WPTs, r=annevk Differential Revision: https://phabricator.services.mozilla.com/D77251
testing/web-platform/tests/cookies/samesite/form-get-blank-reload.https.html
testing/web-platform/tests/cookies/samesite/form-get-blank.https.html
testing/web-platform/tests/cookies/samesite/form-post-blank-reload.https.html
testing/web-platform/tests/cookies/samesite/form-post-blank.https.html
testing/web-platform/tests/cookies/samesite/iframe-reload.https.html
testing/web-platform/tests/cookies/samesite/iframe.document.html
testing/web-platform/tests/cookies/samesite/iframe.https.html
testing/web-platform/tests/cookies/samesite/window-open-reload.https.html
testing/web-platform/tests/cookies/samesite/window-open.https.html
--- a/testing/web-platform/tests/cookies/samesite/form-get-blank-reload.https.html
+++ b/testing/web-platform/tests/cookies/samesite/form-get-blank-reload.https.html
@@ -6,49 +6,45 @@
 <script src="/resources/testharnessreport.js"></script>
 <script src="/cookies/resources/cookie-helper.sub.js"></script>
 <script>
   function create_test(origin, target, expectedStatus, title) {
     promise_test(t => {
       var value = "" + Math.random();
       return resetSameSiteCookies(origin, value)
         .then(_ => {
-          return new Promise((resolve, reject) => {
+          return new Promise(resolve => {
             var f = document.createElement('form');
             f.action = target + "/cookies/resources/postToParent.py";
             f.target = "_blank";
             f.method = "GET";
 
             // If |target| contains a `redir` parameter, extract it, and add it
             // to the form so it doesn't get dropped in the submission.
             var url = new URL(f.action);
             if (url.pathname = "/cookies/rfc6265/resources/redirectWithCORSHeaders.py") {
               var i = document.createElement("input");
               i.name = "location";
               i.value = url.searchParams.get("location");
               i.type = "hidden";
               f.appendChild(i);
             }
             var reloaded = false;
-            var msgHandler = e => {
-              try {
-                getSameSiteVerifier()(expectedStatus, value, e.data, DomSameSiteStatus.SAME_SITE);
-              } catch (e) {
-                reject(e);
-              }
+            var msgHandler = t.step_func(e => {
+              getSameSiteVerifier()(expectedStatus, value, e.data, DomSameSiteStatus.SAME_SITE);
 
               if (reloaded) {
                 window.removeEventListener("message", msgHandler);
                 e.source.close();
                 resolve("Popup received the cookie.");
               } else {
                 reloaded = true;
                 e.source.postMessage("reload", "*");
               }
-            };
+            });
             window.addEventListener("message", msgHandler);
             document.body.appendChild(f);
 
             f.submit();
           });
         });
     }, title);
   }
--- a/testing/web-platform/tests/cookies/samesite/form-get-blank.https.html
+++ b/testing/web-platform/tests/cookies/samesite/form-get-blank.https.html
@@ -7,43 +7,40 @@
 <script src="/resources/testharnessreport.js"></script>
 <script src="/cookies/resources/cookie-helper.sub.js"></script>
 <script>
   function create_test(origin, target, expectedStatus, title) {
     promise_test(t => {
       var value = "" + Math.random();
       return resetSameSiteCookies(origin, value)
         .then(_ => {
-          return new Promise((resolve, reject) => {
+          return new Promise(resolve => {
             var f = document.createElement('form');
             f.action = target + "/cookies/resources/postToParent.py";
             f.target = "_blank";
             f.method = "GET";
 
             // If |target| contains a `redir` parameter, extract it, and add it
             // to the form so it doesn't get dropped in the submission.
             var url = new URL(f.action);
             if (url.pathname == "/cookies/resources/redirectWithCORSHeaders.py") {
               var i = document.createElement("input");
               i.name = "location";
               i.type="hidden";
               i.value = url.searchParams.get("location");
               f.appendChild(i);
             }
 
-            var msgHandler = e => {
+            var msgHandler = t.step_func(e => {
               window.removeEventListener("message", msgHandler);
               e.source.close();
-              try {
-                getSameSiteVerifier()(expectedStatus, value, e.data, DomSameSiteStatus.SAME_SITE);
-                resolve("Popup received the cookie.");
-              } catch (e) {
-                reject(e);
-              }
-            };
+
+              getSameSiteVerifier()(expectedStatus, value, e.data, DomSameSiteStatus.SAME_SITE);
+              resolve("Popup received the cookie.");
+            });
             window.addEventListener("message", msgHandler);
             document.body.appendChild(f);
             f.submit();
           });
         });
     }, title);
   }
 
--- a/testing/web-platform/tests/cookies/samesite/form-post-blank-reload.https.html
+++ b/testing/web-platform/tests/cookies/samesite/form-post-blank-reload.https.html
@@ -6,39 +6,35 @@
 <script src="/resources/testharnessreport.js"></script>
 <script src="/cookies/resources/cookie-helper.sub.js"></script>
 <script>
   function create_test(origin, target, expectedStatus, title) {
     promise_test(t => {
       var value = "" + Math.random();
       return resetSameSiteCookies(origin, value)
         .then(_ => {
-          return new Promise((resolve, reject) => {
+          return new Promise(resolve => {
             var f = document.createElement('form');
             f.action = target + "/cookies/resources/postToParent.py";
             f.target = "_blank";
             f.method = "POST";
 
             var reloaded = false;
-            var msgHandler = e => {
-              try {
-                getSameSiteVerifier()(expectedStatus, value, e.data, DomSameSiteStatus.SAME_SITE);
-              } catch (e) {
-                reject(e);
-              }
+            var msgHandler = t.step_func(e => {
+              getSameSiteVerifier()(expectedStatus, value, e.data, DomSameSiteStatus.SAME_SITE);
 
               if (reloaded) {
                 window.removeEventListener("message", msgHandler);
                 e.source.close();
                 resolve("Popup received the cookie.");
               } else {
                 reloaded = true;
                 e.source.postMessage("reload", "*");
               }
-            };
+            });
             window.addEventListener("message", msgHandler);
 
             document.body.appendChild(f);
             f.submit();
           });
         });
     }, title);
   }
--- a/testing/web-platform/tests/cookies/samesite/form-post-blank.https.html
+++ b/testing/web-platform/tests/cookies/samesite/form-post-blank.https.html
@@ -7,32 +7,28 @@
 <script src="/resources/testharnessreport.js"></script>
 <script src="/cookies/resources/cookie-helper.sub.js"></script>
 <script>
   function create_test(origin, target, expectedStatus, title) {
     promise_test(t => {
       var value = "" + Math.random();
       return resetSameSiteCookies(origin, value)
         .then(_ => {
-          return new Promise((resolve, reject) => {
+          return new Promise(resolve => {
             var f = document.createElement('form');
             f.action = target + "/cookies/resources/postToParent.py";
             f.target = "_blank";
             f.method = "POST";
 
-            var msgHandler = e => {
+            var msgHandler = t.step_func(e => {
               window.removeEventListener("message", msgHandler);
               e.source.close();
-              try {
-                getSameSiteVerifier()(expectedStatus, value, e.data, DomSameSiteStatus.SAME_SITE);
-                resolve("Popup received the cookie.");
-              } catch (e) {
-                reject(e);
-              }
-            };
+              getSameSiteVerifier()(expectedStatus, value, e.data, DomSameSiteStatus.SAME_SITE);
+              resolve("Popup received the cookie.");
+            });
             window.addEventListener("message", msgHandler);
             document.body.appendChild(f);
             f.submit();
           });
         });
     }, title);
   }
 
--- a/testing/web-platform/tests/cookies/samesite/iframe-reload.https.html
+++ b/testing/web-platform/tests/cookies/samesite/iframe-reload.https.html
@@ -9,37 +9,32 @@
 <!-- We're appending an <iframe> to the document's body, so execute tests after we have a body -->
 <body>
 <script>
   function create_test(origin, target, expectedStatus, expectedDomStatus, title) {
     promise_test(t => {
       var value = "" + Math.random();
       return resetSameSiteCookies(origin, value)
         .then(_ => {
-          return new Promise((resolve, reject) => {
+          return new Promise(resolve => {
             var iframe = document.createElement("iframe");
-            iframe.onerror = _ => reject("IFrame could not be loaded.");
 
             var reloaded = false;
-            var msgHandler = e => {
-              try {
-                getSameSiteVerifier()(expectedStatus, value, e.data, expectedDomStatus);
-              } catch (e) {
-                reject(e);
-              }
+            var msgHandler = t.step_func(e => {
+              getSameSiteVerifier()(expectedStatus, value, e.data, expectedDomStatus);
 
               if (reloaded) {
                 window.removeEventListener("message", msgHandler);
                 document.body.removeChild(iframe);
                 resolve("IFrame received the cookie.");
               } else {
                 reloaded = true;
                 e.source.postMessage("reload", "*");
               }
-            };
+            });
             window.addEventListener("message", msgHandler);
 
             iframe.src = target + "/cookies/resources/postToParent.py";
             document.body.appendChild(iframe);
           });
         });
     }, title);
   }
--- a/testing/web-platform/tests/cookies/samesite/iframe.document.html
+++ b/testing/web-platform/tests/cookies/samesite/iframe.document.html
@@ -4,31 +4,31 @@
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
 <script src="/cookies/resources/cookie-helper.sub.js"></script>
 <!-- We're appending an <iframe> to the document's body, so execute tests after we have a body -->
 <body>
 <script>
   function create_test(target, expectedDomStatus, title) {
     promise_test(async t => {
-      let cookieValue = await new Promise((resolve, reject) => {
+      let cookieValue = await new Promise(resolve => {
         var iframe = document.createElement("iframe");
 
         window.onmessage = t.step_func(e => {
           if (e.source == iframe.contentWindow) {
             document.body.removeChild(iframe);
             resolve(e.data.value);
           }
         });
 
         iframe.src = target + "/cookies/samesite/resources/iframe.document.html";
         document.body.appendChild(iframe);
       });
 
-      await new Promise((resolve, reject) => {
+      await new Promise(resolve => {
         var iframe = document.createElement("iframe");
 
         window.onmessage = t.step_func(e => {
           if (e.source == iframe.contentWindow) {
             // Cleanup, then verify cookie state:
             document.body.removeChild(iframe);
 
             const cookies = e.data;
--- a/testing/web-platform/tests/cookies/samesite/iframe.https.html
+++ b/testing/web-platform/tests/cookies/samesite/iframe.https.html
@@ -9,33 +9,28 @@
 <!-- We're appending an <iframe> to the document's body, so execute tests after we have a body -->
 <body>
 <script>
   function create_test(origin, target, expectedStatus, expectedDomStatus, title) {
     promise_test(t => {
       var value = "" + Math.random();
       return resetSameSiteCookies(origin, value)
         .then(_ => {
-          return new Promise((resolve, reject) => {
+          return new Promise(resolve => {
             var iframe = document.createElement("iframe");
-            iframe.onerror = _ => reject("IFrame could not be loaded.");
 
-            var msgHandler = e => {
+            var msgHandler = t.step_func(e => {
               if (e.source == iframe.contentWindow) {
                 // Cleanup, then verify cookie state:
                 document.body.removeChild(iframe);
                 window.removeEventListener("message", msgHandler);
-                try {
-                  getSameSiteVerifier()(expectedStatus, value, e.data, expectedDomStatus);
-                  resolve();
-                } catch(e) {
-                  reject(e);
-                }
+                getSameSiteVerifier()(expectedStatus, value, e.data, expectedDomStatus);
+                resolve();
               }
-            };
+            });
             window.addEventListener("message", msgHandler);
 
             iframe.src = target + "/cookies/resources/postToParent.py";
             document.body.appendChild(iframe);
           });
         });
     }, title);
   }
--- a/testing/web-platform/tests/cookies/samesite/window-open-reload.https.html
+++ b/testing/web-platform/tests/cookies/samesite/window-open-reload.https.html
@@ -10,32 +10,28 @@
     promise_test(t => {
       var value = "" + Math.random();
       return resetSameSiteCookies(origin, value)
         .then(_ => {
           return new Promise((resolve, reject) => {
             var w = window.open(origin + "/cookies/resources/postToParent.py");
 
             var reloaded = false;
-            var msgHandler = e => {
-              try {
-                getSameSiteVerifier()(expectedStatus, value, e.data, DomSameSiteStatus.SAME_SITE);
-              } catch (e) {
-                reject(e);
-              }
+            var msgHandler = t.step_func(e => {
+              getSameSiteVerifier()(expectedStatus, value, e.data, DomSameSiteStatus.SAME_SITE);
 
               if (reloaded) {
                 window.removeEventListener("message", msgHandler);
                 w.close();
                 resolve("Popup received the cookie.");
               } else {
                 reloaded = true;
                 w.postMessage("reload", "*");
               }
-            };
+            });
             window.addEventListener("message", msgHandler);
 
             if (!w)
               reject("Popup could not be opened (did you allow the test site in your popup blocker?).");
           });
         });
     }, title);
   }
--- a/testing/web-platform/tests/cookies/samesite/window-open.https.html
+++ b/testing/web-platform/tests/cookies/samesite/window-open.https.html
@@ -10,26 +10,22 @@
   function create_test(origin, target, expectedStatus, title) {
     promise_test(t => {
       var value = "" + Math.random();
       return resetSameSiteCookies(origin, value)
         .then(_ => {
           return new Promise((resolve, reject) => {
             var w = window.open(origin + "/cookies/resources/postToParent.py");
 
-            var msgHandler = e => {
+            var msgHandler = t.step_func(e => {
               window.removeEventListener("message", msgHandler);
               w.close();
-              try {
-                getSameSiteVerifier()(expectedStatus, value, e.data, DomSameSiteStatus.SAME_SITE);
-                resolve("Popup received the cookie.");
-              } catch (e) {
-                reject(e);
-              }
-            };
+              getSameSiteVerifier()(expectedStatus, value, e.data, DomSameSiteStatus.SAME_SITE);
+              resolve("Popup received the cookie.");
+            });
             window.addEventListener("message", msgHandler);
 
             if (!w)
               reject("Popup could not be opened (did you allow the test site in your popup blocker?).");
           });
         });
     }, title);
   }