From 9a06a7e69f13ce6e1e3087c6d1d5097769682b25 Mon Sep 17 00:00:00 2001 From: Ryosuke Niwa Date: Sat, 2 Sep 2023 16:30:24 -0700 Subject: [PATCH] Fix html/semantics/embedded-content/media-elements/location-of-the-media-resource/currentSrc.html (#41782) The flakiness was caused by the 0s timer sometimes firing before the media task had a chance to run til completion. Avoid this non-determinism by waiting for loadstart event before scheduling the 0s timer. --- .../currentSrc.html | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/html/semantics/embedded-content/media-elements/location-of-the-media-resource/currentSrc.html b/html/semantics/embedded-content/media-elements/location-of-the-media-resource/currentSrc.html index cd1ebb9e492673..be4d09f7395498 100644 --- a/html/semantics/embedded-content/media-elements/location-of-the-media-resource/currentSrc.html +++ b/html/semantics/embedded-content/media-elements/location-of-the-media-resource/currentSrc.html @@ -14,14 +14,16 @@ var e = document.createElement(tagName); e.src = src; assert_equals(e.currentSrc, ''); - t.step_timeout(function() { - if (src == '') { - assert_equals(e.currentSrc, ''); - } else { - assert_equals(e.currentSrc, e.src); - } - t.done(); - }, 0); + e.addEventListener('loadstart', function () { + t.step_timeout(function () { + if (src == '') { + assert_equals(e.currentSrc, ''); + } else { + assert_equals(e.currentSrc, e.src); + } + t.done(); + }, 0); + }) }, tagName + '.currentSrc after setting src attribute "' + src + '"'); async_test(function(t) { @@ -30,14 +32,16 @@ s.src = src; e.appendChild(s); assert_equals(e.currentSrc, ''); - t.step_timeout(function() { - if (src == '') { - assert_equals(e.currentSrc, ''); - } else { - assert_equals(e.currentSrc, s.src); - } - t.done(); - }, 0); + e.addEventListener('loadstart', function() { + t.step_timeout(function () { + if (src == '') { + assert_equals(e.currentSrc, ''); + } else { + assert_equals(e.currentSrc, s.src); + } + t.done(); + }, 0); + }); }, tagName + '.currentSrc after adding source element with src attribute "' + src + '"'); }); });