Bug 1610338 - Make popup blocking work in GeckoView r=geckoview-reviewers,agi

This also fixes the tests, and adds a utility method for waiting one
round trip between the UI and Gecko thread.

Differential Revision: https://phabricator.services.mozilla.com/D60724

--HG--
extra : moz-landing-system : lando
This commit is contained in:
James Willcox 2020-01-23 15:22:47 +00:00
Родитель e9029a6b3a
Коммит dcf1f45bdd
4 изменённых файлов: 24 добавлений и 23 удалений

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

@ -30,6 +30,8 @@ function PromptFactory() {
this.wrappedJSObject = this;
}
const { debug, warn } = GeckoViewUtils.initLogging("GeckoViewPrompt"); // eslint-disable-line no-unused-vars
PromptFactory.prototype = {
classID: Components.ID("{076ac188-23c1-4390-aa08-7ef1f78ca5d9}"),
@ -332,7 +334,7 @@ PromptFactory.prototype = {
_handlePopupBlocked: function(aEvent) {
const dwi = aEvent.requestingWindow;
const popupWindowURISpec = aEvent.popupWindowURI
? aEvent.popupWindowURI.spec
? aEvent.popupWindowURI.displaySpec
: "about:blank";
let prompt = new PromptDelegate(aEvent.requestingWindow);
@ -341,8 +343,8 @@ PromptFactory.prototype = {
type: "popup",
targetUri: popupWindowURISpec,
},
allowed => {
if (allowed && dwi) {
({ response }) => {
if (response && dwi) {
dwi.open(
popupWindowURISpec,
aEvent.popupWindowName,

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

@ -173,6 +173,8 @@ open class BaseSessionTest(noErrorCollector: Boolean = false) {
fun GeckoSession.waitForJS(js: String): Any? =
sessionRule.waitForJS(this, js)
fun GeckoSession.waitForRoundTrip() = sessionRule.waitForRoundTrip(this)
@Suppress("UNCHECKED_CAST")
fun Any?.asJsonArray(): JSONArray = this as JSONArray

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

@ -20,24 +20,6 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
@MediumTest
class PromptDelegateTest : BaseSessionTest() {
@Ignore("disable test for frequently failing Bug 1535423")
@Test fun popupTest() {
// Ensure popup blocking is enabled for this test.
sessionRule.setPrefsUntilTestEnd(mapOf("dom.disable_open_during_load" to true))
sessionRule.session.loadTestPath(POPUP_HTML_PATH)
sessionRule.waitUntilCalled(object : Callbacks.PromptDelegate {
@AssertCalled(count = 1)
override fun onPopupPrompt(session: GeckoSession, prompt: PromptDelegate.PopupPrompt)
: GeckoResult<PromptDelegate.PromptResponse>? {
assertThat("Session should not be null", session, notNullValue())
assertThat("URL should not be null", prompt.targetUri, notNullValue())
assertThat("URL should match", prompt.targetUri, endsWith(HELLO_HTML_PATH))
return null
}
})
}
@Test fun popupTestAllow() {
// Ensure popup blocking is enabled for this test.
sessionRule.setPrefsUntilTestEnd(mapOf("dom.disable_open_during_load" to true))
@ -60,6 +42,13 @@ class PromptDelegateTest : BaseSessionTest() {
assertThat("URL should match", request.uri, endsWith(forEachCall(POPUP_HTML_PATH, HELLO_HTML_PATH)))
return null
}
@AssertCalled(count = 1)
override fun onNewSession(session: GeckoSession, uri: String): GeckoResult<GeckoSession>? {
assertThat("URL should not be null", uri, notNullValue())
assertThat("URL should match", uri, endsWith(HELLO_HTML_PATH))
return null
}
})
sessionRule.session.loadTestPath(POPUP_HTML_PATH)
@ -70,7 +59,7 @@ class PromptDelegateTest : BaseSessionTest() {
// Ensure popup blocking is enabled for this test.
sessionRule.setPrefsUntilTestEnd(mapOf("dom.disable_open_during_load" to true))
sessionRule.delegateDuringNextWait(object : Callbacks.PromptDelegate, Callbacks.NavigationDelegate {
sessionRule.delegateUntilTestEnd(object : Callbacks.PromptDelegate, Callbacks.NavigationDelegate {
@AssertCalled(count = 1)
override fun onPopupPrompt(session: GeckoSession, prompt: PromptDelegate.PopupPrompt)
: GeckoResult<PromptDelegate.PromptResponse>? {
@ -96,7 +85,8 @@ class PromptDelegateTest : BaseSessionTest() {
})
sessionRule.session.loadTestPath(POPUP_HTML_PATH)
sessionRule.session.waitForPageStop()
sessionRule.waitForPageStop()
sessionRule.session.waitForRoundTrip()
}
@Ignore // TODO: Reenable when 1501574 is fixed.

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

@ -1321,6 +1321,13 @@ public class GeckoSessionTestRule implements TestRule {
};
}
/**
* This simply sends an empty message to the web content and waits for a reply.
*/
public void waitForRoundTrip(final GeckoSession session) {
waitForJS(session, "true");
}
/**
* Wait until a page load has finished on any session. A session must have started a
* page load since the last wait, or this method will wait indefinitely.