Skip to content

Commit

Permalink
Bug 1640418 - Fix onBeforeUnload intermittent. r=esawin
Browse files Browse the repository at this point in the history
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
  • Loading branch information
agi committed Jul 7, 2020
1 parent 3a47358 commit 9020761
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
))
Expand All @@ -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)
}
})

Expand All @@ -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)
}

Expand Down

0 comments on commit 9020761

Please sign in to comment.