Layout Test media/W3C/audio/events/event_progress.html is flaky
https://bugs.webkit.org/show_bug.cgi?id=181966

Patch by Peng Liu <peng.liu6@apple.com> on 2019-10-11
Reviewed by Eric Carlson.

It is possible that video/audio elements fire "progress" event again
when the event handler is still processing the previous "progress" event.
We need to ignore all the events except the first one to make sure
the test cases generate consistent output.

In addition, this patch fixes some errors in JS file names and function parameters.

* http/tests/resources/js-test-pre.js:
(isSuccessfullyParsed):
* media/W3C/audio/events/event_order_loadstart_progress.html:
* media/W3C/audio/events/event_progress.html:
* media/W3C/audio/events/event_progress_manual.html:
* media/W3C/video/events/event_order_loadstart_progress.html:
* media/W3C/video/events/event_progress.html:
* media/W3C/video/events/event_progress_manual.html:
* media/W3C/w3cwrapper.js:
* platform/ios/TestExpectations:
* platform/mac/TestExpectations:
* resources/js-test-pre.js:
(isSuccessfullyParsed):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@251009 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index 91a216e..1d6d660 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,31 @@
+2019-10-11  Peng Liu  <peng.liu6@apple.com>
+
+        Layout Test media/W3C/audio/events/event_progress.html is flaky
+        https://bugs.webkit.org/show_bug.cgi?id=181966
+
+        Reviewed by Eric Carlson.
+
+        It is possible that video/audio elements fire "progress" event again
+        when the event handler is still processing the previous "progress" event.
+        We need to ignore all the events except the first one to make sure
+        the test cases generate consistent output.
+
+        In addition, this patch fixes some errors in JS file names and function parameters.
+
+        * http/tests/resources/js-test-pre.js:
+        (isSuccessfullyParsed):
+        * media/W3C/audio/events/event_order_loadstart_progress.html:
+        * media/W3C/audio/events/event_progress.html:
+        * media/W3C/audio/events/event_progress_manual.html:
+        * media/W3C/video/events/event_order_loadstart_progress.html:
+        * media/W3C/video/events/event_progress.html:
+        * media/W3C/video/events/event_progress_manual.html:
+        * media/W3C/w3cwrapper.js:
+        * platform/ios/TestExpectations:
+        * platform/mac/TestExpectations:
+        * resources/js-test-pre.js:
+        (isSuccessfullyParsed):
+
 2019-10-11  Bjorn Melinder  <bjornm@spotify.com>
 
         OfflineAudioContext does not validate allocation of destination buffer
diff --git a/LayoutTests/media/W3C/audio/events/event_order_loadstart_progress.html b/LayoutTests/media/W3C/audio/events/event_order_loadstart_progress.html
index 20ec1cb..608ea5b 100644
--- a/LayoutTests/media/W3C/audio/events/event_order_loadstart_progress.html
+++ b/LayoutTests/media/W3C/audio/events/event_order_loadstart_progress.html
@@ -3,7 +3,6 @@
  <head>
   <title>video events - loadstart, then progress</title>
   <script src="../../w3cwrapper.js"></script>
-  <script src="../../../Microsoft/common/media.js"></script>
  </head>
  <body>
   <p><a href="http://dev.w3.org/html5/spec/Overview.html#mediaevents">spec reference</a></p>
@@ -17,14 +16,19 @@
 a.addEventListener("loadstart", function() {
   found_loadstart = true;
 });
+
+var firstProgressEvent = true;
 a.addEventListener("progress", function() {
+  if (!firstProgressEvent) return;
+  firstProgressEvent = false;
+
   t.step(function() {
    assert_true(found_loadstart);
   });
   t.done();
   a.pause();
 });
-a.src = getAudioURI("http://media.w3.org/2010/05/sound/sound_5") + "?" + new Date() + Math.random();
+a.src = getAudioURI();
   </script>
  </body>
 </html>
diff --git a/LayoutTests/media/W3C/audio/events/event_progress.html b/LayoutTests/media/W3C/audio/events/event_progress.html
index c92debb8..e04cfc2 100644
--- a/LayoutTests/media/W3C/audio/events/event_progress.html
+++ b/LayoutTests/media/W3C/audio/events/event_progress.html
@@ -3,7 +3,6 @@
  <head>
   <title>video events - progress</title>
   <script src="../../w3cwrapper.js"></script>
-  <script src="../../../Microsoft/common/media.js"></script>
  </head>
  <body>
   <p><a href="http://dev.w3.org/html5/spec/Overview.html#mediaevents">spec reference</a></p>
@@ -13,14 +12,18 @@
   <script>
 var t = async_test("setting src attribute on autoplay video should trigger progress event", {timeout:30000});
 var a = document.getElementById("a");
+var firstProgressEvent = true;
+
 a.addEventListener("progress", function() {
+  if (!firstProgressEvent) return;
+  firstProgressEvent = false;
   t.step(function() {
    assert_true(true);
   });
   t.done();
   a.pause();
 });
-a.src = getAudioURI("http://media.w3.org/2010/05/sound/sound_5") + "?" + new Date() + Math.random();
+a.src = getAudioURI();
   </script>
  </body>
 </html>
diff --git a/LayoutTests/media/W3C/audio/events/event_progress_manual.html b/LayoutTests/media/W3C/audio/events/event_progress_manual.html
index b7a1cfb..bac3757 100644
--- a/LayoutTests/media/W3C/audio/events/event_progress_manual.html
+++ b/LayoutTests/media/W3C/audio/events/event_progress_manual.html
@@ -3,7 +3,6 @@
  <head>
   <title>video events - progress</title>
   <script src="../../w3cwrapper.js"></script>
-  <script src="../../../Microsoft/common/media.js"></script>
  </head>
  <body>
   <p><a href="http://dev.w3.org/html5/spec/Overview.html#mediaevents">spec reference</a></p>
@@ -13,13 +12,18 @@
   <script>
 var t = async_test("setting src attribute on non-autoplay video should trigger progress event", {timeout:30000});
 var a = document.getElementById("a");
+
+var firstProgressEvent = true;
 a.addEventListener("progress", function() {
+  if (!firstProgressEvent) return;
+  firstProgressEvent = false;
+
   t.step(function() {
    assert_true(true);
   });
   t.done();
 });
-a.src = getAudioURI("http://media.w3.org/2010/05/sound/sound_5") + "?" + new Date() + Math.random();
+a.src = getAudioURI();
   </script>
  </body>
 </html>
diff --git a/LayoutTests/media/W3C/video/events/event_order_loadstart_progress.html b/LayoutTests/media/W3C/video/events/event_order_loadstart_progress.html
index 03807ff..5f44ba8 100644
--- a/LayoutTests/media/W3C/video/events/event_order_loadstart_progress.html
+++ b/LayoutTests/media/W3C/video/events/event_order_loadstart_progress.html
@@ -16,14 +16,18 @@
 v.addEventListener("loadstart", function() {
   found_loadstart = true;
 });
+
+var firstProgressEvent = true;
 v.addEventListener("progress", function() {
+  if (!firstProgressEvent) return;
+  firstProgressEvent = false;
   t.step(function() {
    assert_true(found_loadstart);
   });
   t.done();
   v.pause();
 });
-v.src = getVideoURI("http://media.w3.org/2010/05/video/movie_300") + "?" + new Date() + Math.random();
+v.src = getVideoURI();
   </script>
  </body>
 </html>
diff --git a/LayoutTests/media/W3C/video/events/event_progress.html b/LayoutTests/media/W3C/video/events/event_progress.html
index 9adefc1..9d5312f 100644
--- a/LayoutTests/media/W3C/video/events/event_progress.html
+++ b/LayoutTests/media/W3C/video/events/event_progress.html
@@ -12,14 +12,19 @@
   <script>
 var t = async_test("setting src attribute on autoplay video should trigger progress event", {timeout:30000});
 var v = document.getElementById("v");
+
+var firstProgressEvent = true;
 v.addEventListener("progress", function() {
+  if (!firstProgressEvent) return;
+  firstProgressEvent = false;
+
   t.step(function() {
    assert_true(true);
   });
   t.done();
   v.pause();
 });
-v.src = getVideoURI("http://media.w3.org/2010/05/video/movie_300") + "?" + new Date() + Math.random();
+v.src = getVideoURI();
   </script>
  </body>
 </html>
diff --git a/LayoutTests/media/W3C/video/events/event_progress_manual.html b/LayoutTests/media/W3C/video/events/event_progress_manual.html
index 5728449..157f5b3 100644
--- a/LayoutTests/media/W3C/video/events/event_progress_manual.html
+++ b/LayoutTests/media/W3C/video/events/event_progress_manual.html
@@ -12,13 +12,18 @@
   <script>
 var t = async_test("setting src attribute on non-autoplay video should trigger progress event", {timeout:30000});
 var v = document.getElementById("v");
+
+var firstProgressEvent = true;
 v.addEventListener("progress", function() {
+  if (!firstProgressEvent) return;
+  firstProgressEvent = false;
+
   t.step(function() {
    assert_true(true);
   });
   t.done();
 });
-v.src = getVideoURI("http://media.w3.org/2010/05/video/movie_300") + "?" + new Date() + Math.random();
+v.src = getVideoURI();
   </script>
  </body>
 </html>
diff --git a/LayoutTests/media/W3C/w3cwrapper.js b/LayoutTests/media/W3C/w3cwrapper.js
index 19f0d93..0c1d97b 100644
--- a/LayoutTests/media/W3C/w3cwrapper.js
+++ b/LayoutTests/media/W3C/w3cwrapper.js
@@ -53,7 +53,6 @@
 
 document.write("<p id=description></p><div id=console></div>");
 document.write("<scr" + "ipt src='../../../../resources/js-test-pre.js'></" + "script>");
-document.write("<scr" + "ipt src='../../../../resources/js-test-post-function.js'></" + "script>");
 
 assert_equals = function(a, b) { shouldBe('"' + a + '"', '"' + b + '"'); }
 assert_true = function(a) { shouldBeTrue("" + a); }
diff --git a/LayoutTests/platform/ios/TestExpectations b/LayoutTests/platform/ios/TestExpectations
index ff66a57..148609f 100644
--- a/LayoutTests/platform/ios/TestExpectations
+++ b/LayoutTests/platform/ios/TestExpectations
@@ -3225,8 +3225,6 @@
 
 webkit.org/b/197473 imported/w3c/web-platform-tests/resource-timing/resource-timing-level1.sub.html [ Pass Failure ]
 
-webkit.org/b/175678 media/W3C/video/events/event_progress.html [ Pass Failure ]
-
 # These tests depend on the implementation of "modern compatibility mode" in WebKitAdditions.
 platform/ipad/fast/css/webkit-overflow-scrolling-parsing-modern-compatibility-mode.html [ Skip ]
 
diff --git a/LayoutTests/platform/mac/TestExpectations b/LayoutTests/platform/mac/TestExpectations
index 5b4cbfd..f312a5b 100644
--- a/LayoutTests/platform/mac/TestExpectations
+++ b/LayoutTests/platform/mac/TestExpectations
@@ -1622,9 +1622,6 @@
 webkit.org/b/181565 imported/w3c/web-platform-tests/media-source/mediasource-config-change-mp4-v-bitrate.html [ Pass Failure ]
 webkit.org/b/181565 imported/w3c/web-platform-tests/media-source/mediasource-config-change-mp4-v-framesize.html [ Pass Failure ]
 
-webkit.org/b/181966 [ Debug ] media/W3C/audio/events/event_progress.html [ Pass Failure ]
-webkit.org/b/181966 media/W3C/video/events/event_order_loadstart_progress.html [ Pass Failure ]
-
 webkit.org/b/181969 fast/events/message-port.html [ Skip ]
 
 webkit.org/b/181831 [ HighSierra+ ] fast/forms/searchfield-heights.html [ Pass Failure ]
@@ -1815,8 +1812,6 @@
 
 webkit.org/b/196517 imported/w3c/web-platform-tests/mst-content-hint/MediaStreamTrack-contentHint.html [ Skip ]
 
-webkit.org/b/177663 media/W3C/video/events/event_progress_manual.html [ Pass Failure ]
-
 # Skip iOS-specific Pointer Events WPT tests.
 imported/w3c/web-platform-tests/pointerevents/pointerevent_change-touch-action-onpointerdown_touch.html [ Skip ]
 imported/w3c/web-platform-tests/pointerevents/pointerevent_pointercancel_touch.html [ Skip ]
@@ -1885,8 +1880,6 @@
 
 webkit.org/b/136627 [ Mojave+ ] media/track/track-cue-rendering-vertical.html [ Failure ]
 
-webkit.org/b/175678 media/W3C/video/events/event_progress.html [ Pass Failure ]
-
 # <rdar://problem/46000736>
 [ Mojave+ ] webgl/2.0.0/conformance/extensions/angle-instanced-arrays.html [ Failure ]
 [ Mojave+ ] webgl/2.0.0/conformance2/extensions/promoted-extensions-in-shaders.html [ Failure ]