Bug 1634157 [wpt PR 23324] - Remove assert_precondition from testharness.js, a=testonly
authorStephen McGruer <smcgruer@chromium.org>
Wed, 13 May 2020 09:39:22 +0000
changeset 531054 41e84eec6ab95581c52e4864bad75ec99b7fbf28
parent 531053 f2bbc0557cd8b626e3349e04ba8d3b7cc482761e
child 531055 19a7b343525ff50af27134cf96e315dffa2f9394
push id37435
push userapavel@mozilla.com
push dateWed, 20 May 2020 15:28:23 +0000
treeherdermozilla-central@5415da14ec9a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1634157, 23324
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 1634157 [wpt PR 23324] - Remove assert_precondition from testharness.js, a=testonly Automatic update from web-platform-tests Remove assert_precondition from testharness.js (#23324) This is being removed in favour of assert_implements / assert_implements_optional. See the RFC: https://github.com/web-platform-tests/rfcs/blob/master/rfcs/assert_precondition_rename.md -- wpt-commits: 5681e96ff1cc7f2516c73f377639011aee94bc26 wpt-pr: 23324
testing/web-platform/tests/docs/writing-tests/testharness-api.md
testing/web-platform/tests/infrastructure/expected-fail/precondition-in-promise.html
testing/web-platform/tests/infrastructure/expected-fail/precondition-in-setup.html
testing/web-platform/tests/infrastructure/expected-fail/precondition-without-setup.html
testing/web-platform/tests/infrastructure/expected-fail/precondition.html
testing/web-platform/tests/lint.ignore
testing/web-platform/tests/resources/testharness.js
--- a/testing/web-platform/tests/docs/writing-tests/testharness-api.md
+++ b/testing/web-platform/tests/docs/writing-tests/testharness-api.md
@@ -327,18 +327,18 @@ async_test((t) => {
   video.src = "multitrack.webm";
   // test something specific to multiple audio tracks in a WebM container
   t.done();
 }, "WebM with multiple audio tracks");
 ```
 
 A failing `assert_implements_optional` call is reported as a status of
 `PRECONDITION_FAILED` for the subtest. This unusual status code is a legacy
-leftover from the deprecated `assert_precondition`; see the [RFC that renamed
-it](https://github.com/web-platform-tests/rfcs/pull/48).
+leftover; see the [RFC that introduced
+`assert_implements_optional`](https://github.com/web-platform-tests/rfcs/pull/48).
 
 `assert_implements_optional` can also be used during test setup. For example:
 
 ```js
 setup(() => {
   assert_implements_optional("optionalfeature" in document.body,
                              "'optionalfeature' event supported");
 });
@@ -899,19 +899,16 @@ an event does not fire.
 ### `assert_any(assert_func, actual, expected_array, extra_arg_1, ... extra_arg_N)`
 asserts that one `assert_func(actual, expected_array_N, extra_arg1, ..., extra_arg_N)`
   is true for some `expected_array_N` in `expected_array`. This only works for `assert_func`
   with signature `assert_func(actual, expected, args_1, ..., args_N)`. Note that tests
   with multiple allowed pass conditions are bad practice unless the spec specifically
   allows multiple behaviours. Test authors should not use this method simply to hide
   UA bugs.
 
-### **DEPRECATED** `assert_precondition(condition, description)`
-Use `assert_implements` or `assert_implements_optional` instead.
-
 ## Utility functions ##
 
 ### **DEPRECATED** `on_event(object, event, callback)`
 
 Register a function as a DOM event listener to the given object for the event
 bubbling phase. New tests should not use this function. Instead, they should
 invoke the `addEventListener` method of the `object` value.
 
deleted file mode 100644
--- a/testing/web-platform/tests/infrastructure/expected-fail/precondition-in-promise.html
+++ /dev/null
@@ -1,10 +0,0 @@
-<!DOCTYPE html>
-<meta charset=utf-8>
-<title>Precondition in promise</title>
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script>
-new Promise(() => {
-  assert_precondition(false);
-});
-</script>
deleted file mode 100644
--- a/testing/web-platform/tests/infrastructure/expected-fail/precondition-in-setup.html
+++ /dev/null
@@ -1,10 +0,0 @@
-<!DOCTYPE html>
-<meta charset=utf-8>
-<title>Precondition in setup</title>
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script>
-setup(() => {
-  assert_precondition(false);
-});
-</script>
deleted file mode 100644
--- a/testing/web-platform/tests/infrastructure/expected-fail/precondition-without-setup.html
+++ /dev/null
@@ -1,8 +0,0 @@
-<!DOCTYPE html>
-<meta charset=utf-8>
-<title>Precondition without wrapping setup</title>
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script>
-assert_precondition(false);
-</script>
deleted file mode 100644
--- a/testing/web-platform/tests/infrastructure/expected-fail/precondition.html
+++ /dev/null
@@ -1,31 +0,0 @@
-<!DOCTYPE html>
-<meta charset=utf-8>
-<title>Preconditions in tests</title>
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script>
-test(() => {
-  assert_precondition(false, 'precondition 1');
-}, 'test');
-
-async_test((t) => {
-  assert_precondition(false, 'precondition 2');
-  t.done();
-}, 'async_test immediate');
-
-async_test((t) => {
-  t.step_timeout(() => {
-      assert_precondition(false, 'precondition 3');
-      t.done();
-  }, 100);
-}, 'async_test after timeout');
-
-promise_test(async () => {
-  assert_precondition(false, 'precondition 4');
-}, 'promise_test immediate');
-
-promise_test(async () => {
-  await Promise.resolve();
-  assert_precondition(false, 'precondition 5');
-}, 'promise_test after await');
-</script>
--- a/testing/web-platform/tests/lint.ignore
+++ b/testing/web-platform/tests/lint.ignore
@@ -751,15 +751,8 @@ TESTHARNESS-IN-OTHER-TYPE: html/semantic
 TESTHARNESS-IN-OTHER-TYPE: html/semantics/interactive-elements/the-summary-element/display-table-with-rt-crash.html
 TESTHARNESS-IN-OTHER-TYPE: html/semantics/text-level-semantics/the-ruby-element/rt-without-ruby-crash.html
 TESTHARNESS-IN-OTHER-TYPE: portals/portals-no-frame-crash.html
 TESTHARNESS-IN-OTHER-TYPE: quirks/table-replaced-descendant-percentage-height-crash.html
 TESTHARNESS-IN-OTHER-TYPE: svg/extensibility/foreignObject/foreign-object-circular-filter-reference-crash.html
 TESTHARNESS-IN-OTHER-TYPE: svg/extensibility/foreignObject/foreign-object-under-clip-path-crash.html
 TESTHARNESS-IN-OTHER-TYPE: svg/extensibility/foreignObject/foreign-object-under-defs-crash.html
 TESTHARNESS-IN-OTHER-TYPE: svg/svg-in-svg/svg-in-svg-circular-filter-reference-crash.html
-
-# TODO: Temporary inclusions while we deprecate assert_precondition
-# https://github.com/web-platform-tests/wpt/issues/21971
-ASSERT-PRECONDITION: infrastructure/expected-fail/precondition.html
-ASSERT-PRECONDITION: infrastructure/expected-fail/precondition-in-setup.html
-ASSERT-PRECONDITION: infrastructure/expected-fail/precondition-in-promise.html
-ASSERT-PRECONDITION: resources/testharness.js
--- a/testing/web-platform/tests/resources/testharness.js
+++ b/testing/web-platform/tests/resources/testharness.js
@@ -1862,34 +1862,21 @@ policies and contribution forms [3].
      *     assert_implements_optional(video.canPlayType("video/webm"),
      *                                "webm video playback not supported");
      *
      * @param {object} condition The truthy value to test
      * @param {string} description Error description for the case that the condition is not truthy.
      */
     function assert_implements_optional(condition, description) {
         if (!condition) {
-            // Due to the difficulty of changing logging statuses, we re-use
-            // the PRECONDITION_FAILED status for assert_implements_optional.
-            // See the RFC: https://github.com/web-platform-tests/rfcs/pull/48
-            //
-            // TODO(smcgruer): Once assert_precondition is removed, rename the
-            // exception and move this comment to where PRECONDITION_FAILED is used.
-            throw new PreconditionFailedError(description);
+            throw new OptionalFeatureUnsupportedError(description);
         }
     }
     expose(assert_implements_optional, "assert_implements_optional")
 
-    function assert_precondition(precondition, description) {
-        if (!precondition) {
-            throw new PreconditionFailedError(description);
-        }
-    }
-    expose(assert_precondition, "assert_precondition");
-
     function Test(name, properties)
     {
         if (tests.file_is_test && tests.tests.length) {
             throw new Error("Tried to create a test with file_is_test");
         }
         this.name = name;
 
         this.phase = (tests.is_aborted || tests.phase === tests.phases.COMPLETE) ?
@@ -1985,17 +1972,17 @@ policies and contribution forms [3].
         }
 
         try {
             return func.apply(this_obj, Array.prototype.slice.call(arguments, 2));
         } catch (e) {
             if (this.phase >= this.phases.HAS_RESULT) {
                 return;
             }
-            var status = e instanceof PreconditionFailedError ? this.PRECONDITION_FAILED : this.FAIL;
+            var status = e instanceof OptionalFeatureUnsupportedError ? this.PRECONDITION_FAILED : this.FAIL;
             var message = String((typeof e === "object" && e !== null) ? e.message : e);
             var stack = e.stack ? e.stack : null;
 
             this.set_status(status, message, stack);
             this.phase = this.phases.HAS_RESULT;
             this.done();
         }
     };
@@ -2571,17 +2558,17 @@ policies and contribution forms [3].
                 }
             }
         }
 
         if (func) {
             try {
                 func();
             } catch (e) {
-                this.status.status = e instanceof PreconditionFailedError ? this.status.PRECONDITION_FAILED : this.status.ERROR;
+                this.status.status = e instanceof OptionalFeatureUnsupportedError ? this.status.PRECONDITION_FAILED : this.status.ERROR;
                 this.status.message = String(e);
                 this.status.stack = e.stack ? e.stack : null;
                 this.complete();
             }
         }
         this.set_timeout();
     };
 
@@ -3113,24 +3100,24 @@ policies and contribution forms [3].
         if (heads.length) {
             heads[0].appendChild(stylesheet);
         }
 
         var status_text_harness = {};
         status_text_harness[harness_status.OK] = "OK";
         status_text_harness[harness_status.ERROR] = "Error";
         status_text_harness[harness_status.TIMEOUT] = "Timeout";
-        status_text_harness[harness_status.PRECONDITION_FAILED] = "Precondition Failed";
+        status_text_harness[harness_status.PRECONDITION_FAILED] = "Optional Feature Unsupported";
 
         var status_text = {};
         status_text[Test.prototype.PASS] = "Pass";
         status_text[Test.prototype.FAIL] = "Fail";
         status_text[Test.prototype.TIMEOUT] = "Timeout";
         status_text[Test.prototype.NOTRUN] = "Not Run";
-        status_text[Test.prototype.PRECONDITION_FAILED] = "Precondition Failed";
+        status_text[Test.prototype.PRECONDITION_FAILED] = "Optional Feature Unsupported";
 
         var status_number = {};
         forEach(tests,
                 function(test) {
                     var status = status_text[test.status];
                     if (status_number.hasOwnProperty(status)) {
                         status_number[status] += 1;
                     } else {
@@ -3502,22 +3489,22 @@ policies and contribution forms [3].
         // Paranoid check that we didn't skip all frames.  If so, return the original stack unmodified.
         if (i >= lines.length) {
             return stack;
         }
 
         return lines.slice(i).join("\n");
     }
 
-    function PreconditionFailedError(message)
+    function OptionalFeatureUnsupportedError(message)
     {
         AssertionError.call(this, message);
     }
-    PreconditionFailedError.prototype = Object.create(AssertionError.prototype);
-    expose(PreconditionFailedError, "PreconditionFailedError");
+    OptionalFeatureUnsupportedError.prototype = Object.create(AssertionError.prototype);
+    expose(OptionalFeatureUnsupportedError, "OptionalFeatureUnsupportedError");
 
     function make_message(function_name, description, error, substitutions)
     {
         for (var p in substitutions) {
             if (substitutions.hasOwnProperty(p)) {
                 substitutions[p] = format_value(substitutions[p]);
             }
         }
@@ -3737,27 +3724,27 @@ policies and contribution forms [3].
     /**
      * Setup globals
      */
 
     var tests = new Tests();
 
     if (global_scope.addEventListener) {
         var error_handler = function(error, message, stack) {
-            var precondition_failed = error instanceof PreconditionFailedError;
+            var optional_unsupported = error instanceof OptionalFeatureUnsupportedError;
             if (tests.file_is_test) {
                 var test = tests.tests[0];
                 if (test.phase >= test.phases.HAS_RESULT) {
                     return;
                 }
-                var status = precondition_failed ? test.PRECONDITION_FAILED : test.FAIL;
+                var status = optional_unsupported ? test.PRECONDITION_FAILED : test.FAIL;
                 test.set_status(status, message, stack);
                 test.phase = test.phases.HAS_RESULT;
             } else if (!tests.allow_uncaught_exception) {
-                var status = precondition_failed ? tests.status.PRECONDITION_FAILED : tests.status.ERROR;
+                var status = optional_unsupported ? tests.status.PRECONDITION_FAILED : tests.status.ERROR;
                 tests.status.status = status;
                 tests.status.message = message;
                 tests.status.stack = stack;
             }
 
             // Do not transition to the "complete" phase if the test has been
             // configured to allow uncaught exceptions. This gives the test an
             // opportunity to define subtests based on the exception reporting
@@ -3863,21 +3850,21 @@ tr.fail > td:first-child {\
 tr.timeout > td:first-child {\
     color:red;\
 }\
 \
 tr.notrun > td:first-child {\
     color:blue;\
 }\
 \
-tr.preconditionfailed > td:first-child {\
+tr.optionalunsupported > td:first-child {\
     color:blue;\
 }\
 \
-.pass > td:first-child, .fail > td:first-child, .timeout > td:first-child, .notrun > td:first-child, .preconditionfailed > td:first-child {\
+.pass > td:first-child, .fail > td:first-child, .timeout > td:first-child, .notrun > td:first-child, .optionalunsupported > td:first-child {\
     font-variant:small-caps;\
 }\
 \
 table#results span {\
     display:block;\
 }\
 \
 table#results span.expected {\