Improve AudioOutputTest.AudioTogglePlaybackTest to avoid flakyness.

This commit is contained in:
Marshall Greenblatt 2020-06-10 13:27:51 -04:00
parent 790d248111
commit a9aef28966
1 changed files with 37 additions and 16 deletions

View File

@ -814,22 +814,43 @@ const char kTestHtml[] =
"style=\"display:none\"></audio></body></html>";
const char kToggleTestHtml[] =
"<!DOCTYPE html><html><head><meta "
"charset=\"utf-8\"/><script type=\"text/javascript\">var timeouts = [ "
"1950, 150, 2000, 150, 2050, 150, 2100, 150, 2200, 150 "
"]; function togglePlayback(el, playing, count) { if (count < 10) { var "
"timeout = "
"timeouts[count]; if (playing) { el.pause(); } else { el.play(); } "
"setTimeout(togglePlayback, timeout, el, !playing, ++count); } } function "
"loadHandler() { var audioStarted = false; var el = "
"document.getElementById(\"audio_output_frame\"); el.onplay = (event) => "
"{ if (audioStarted) { return; } audioStarted = true; "
"setTimeout(togglePlayback, 150, el, audioStarted, 0); "
"}; }</script></head><body "
"onload=\"loadHandler()\"><p>TEST</p><audio "
"id=\"audio_output_frame\" src=\"" AUDIO_DATA
"\" autoplay "
"style=\"display:none\"></audio></body></html>";
"<!DOCTYPE html><html><head><meta charset=\"utf-8\"/>"
"<script type=\"text/javascript\">"
"var timeouts = [150, 1950, 150, 2000, 150, 2050, 150, 2100, 150, 2200, "
"150];"
"var count = 0;"
"function togglePlayback(el, playing, count) {"
" if (playing) {"
// " console.log('togglePlayback pause (' + count + ')');"
" el.pause();"
" } else {"
// " console.log('togglePlayback play (' + count + ')');"
" el.play();"
" }"
"}"
"function loadHandler() {"
" var el = document.getElementById(\"audio_output_frame\");"
" el.onplay = (event) => {"
" var timeout = timeouts[count];"
// " console.log('loadHandler onplay (' + count + ') wait ' + timeout);"
" if (count < timeouts.length) {"
" setTimeout(togglePlayback, timeout, el, true, count);"
" count++;"
" }"
" };"
" el.onpause = (event) => {"
" var timeout = timeouts[count];"
// " console.log('loadHandler onpause (' + count + ') wait ' + timeout);"
" if (count < timeouts.length) {"
" setTimeout(togglePlayback, timeout, el, false, count);"
" count++;"
" }"
" };"
"}"
"</script></head>"
"<body onload=\"loadHandler()\"><p>TEST</p>"
"<audio id=\"audio_output_frame\" src=\"" AUDIO_DATA
"\" autoplay style=\"display:none\"></audio></body></html>";
class AudioOutputTest : public ClientAppBrowser::Delegate {
public: