Bug 1640418 - Fix onBeforeUnload intermittent. r=esawin

The problem here is that sometimes the test clicks on the two links too quickly
and only the second click goes through the onBeforeUnload path and the first
one is ignored.

Differential Revision: https://phabricator.services.mozilla.com/D82442
This commit is contained in:
Agi Sferro 2020-07-07 16:57:09 +00:00
Родитель 6aaf11538a
Коммит c4f94e2e85
1 изменённых файлов: 10 добавлений и 8 удалений

Просмотреть файл

@ -16,7 +16,6 @@ import org.junit.Assert
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assume.assumeThat
@RunWith(AndroidJUnit4::class)
@MediumTest
@ -148,10 +147,8 @@ class PromptDelegateTest : BaseSessionTest() {
equalTo(false))
}
// disable test on opt for frequently failing Bug 1640418
@Test
fun onBeforeUnloadTest() {
assumeThat(sessionRule.env.isDebugBuild, equalTo(true))
sessionRule.setPrefsUntilTestEnd(mapOf(
"dom.require_user_interaction_for_beforeunload" to false
))
@ -166,12 +163,15 @@ class PromptDelegateTest : BaseSessionTest() {
}
})
var promptResult = GeckoResult<PromptDelegate.PromptResponse>()
val promptResult = GeckoResult<PromptDelegate.PromptResponse>()
val promptResult2 = GeckoResult<PromptDelegate.PromptResponse>()
sessionRule.delegateUntilTestEnd(object : Callbacks.PromptDelegate {
@AssertCalled(count = 2)
override fun onBeforeUnloadPrompt(session: GeckoSession, prompt: PromptDelegate.BeforeUnloadPrompt): GeckoResult<PromptDelegate.PromptResponse>? {
// We have to return something here because otherwise the delegate will be invoked
// before we have a chance to override it in the waitUntilCalled call below
return promptResult
return forEachCall(promptResult, promptResult2)
}
})
@ -186,18 +186,20 @@ class PromptDelegateTest : BaseSessionTest() {
}
})
sessionRule.waitForResult(promptResult)
// This request will go through and end the test. Doing the negative case first will
// ensure that if either of this tests fail the test will fail.
promptResult = GeckoResult()
sessionRule.session.evaluateJS("document.querySelector('#navigateAway2').click()")
sessionRule.waitUntilCalled(object : Callbacks.PromptDelegate {
@AssertCalled(count = 1)
override fun onBeforeUnloadPrompt(session: GeckoSession, prompt: PromptDelegate.BeforeUnloadPrompt): GeckoResult<PromptDelegate.PromptResponse>? {
promptResult.complete(prompt.confirm(AllowOrDeny.ALLOW))
return promptResult
promptResult2.complete(prompt.confirm(AllowOrDeny.ALLOW))
return promptResult2
}
})
sessionRule.waitForResult(promptResult2)
sessionRule.waitForResult(result)
}