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