зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
e9029a6b3a
Коммит
dcf1f45bdd
|
@ -30,6 +30,8 @@ function PromptFactory() {
|
||||||
this.wrappedJSObject = this;
|
this.wrappedJSObject = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { debug, warn } = GeckoViewUtils.initLogging("GeckoViewPrompt"); // eslint-disable-line no-unused-vars
|
||||||
|
|
||||||
PromptFactory.prototype = {
|
PromptFactory.prototype = {
|
||||||
classID: Components.ID("{076ac188-23c1-4390-aa08-7ef1f78ca5d9}"),
|
classID: Components.ID("{076ac188-23c1-4390-aa08-7ef1f78ca5d9}"),
|
||||||
|
|
||||||
|
@ -332,7 +334,7 @@ PromptFactory.prototype = {
|
||||||
_handlePopupBlocked: function(aEvent) {
|
_handlePopupBlocked: function(aEvent) {
|
||||||
const dwi = aEvent.requestingWindow;
|
const dwi = aEvent.requestingWindow;
|
||||||
const popupWindowURISpec = aEvent.popupWindowURI
|
const popupWindowURISpec = aEvent.popupWindowURI
|
||||||
? aEvent.popupWindowURI.spec
|
? aEvent.popupWindowURI.displaySpec
|
||||||
: "about:blank";
|
: "about:blank";
|
||||||
|
|
||||||
let prompt = new PromptDelegate(aEvent.requestingWindow);
|
let prompt = new PromptDelegate(aEvent.requestingWindow);
|
||||||
|
@ -341,8 +343,8 @@ PromptFactory.prototype = {
|
||||||
type: "popup",
|
type: "popup",
|
||||||
targetUri: popupWindowURISpec,
|
targetUri: popupWindowURISpec,
|
||||||
},
|
},
|
||||||
allowed => {
|
({ response }) => {
|
||||||
if (allowed && dwi) {
|
if (response && dwi) {
|
||||||
dwi.open(
|
dwi.open(
|
||||||
popupWindowURISpec,
|
popupWindowURISpec,
|
||||||
aEvent.popupWindowName,
|
aEvent.popupWindowName,
|
||||||
|
|
|
@ -173,6 +173,8 @@ open class BaseSessionTest(noErrorCollector: Boolean = false) {
|
||||||
fun GeckoSession.waitForJS(js: String): Any? =
|
fun GeckoSession.waitForJS(js: String): Any? =
|
||||||
sessionRule.waitForJS(this, js)
|
sessionRule.waitForJS(this, js)
|
||||||
|
|
||||||
|
fun GeckoSession.waitForRoundTrip() = sessionRule.waitForRoundTrip(this)
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
fun Any?.asJsonArray(): JSONArray = this as JSONArray
|
fun Any?.asJsonArray(): JSONArray = this as JSONArray
|
||||||
|
|
||||||
|
|
|
@ -20,24 +20,6 @@ import org.junit.runner.RunWith
|
||||||
@RunWith(AndroidJUnit4::class)
|
@RunWith(AndroidJUnit4::class)
|
||||||
@MediumTest
|
@MediumTest
|
||||||
class PromptDelegateTest : BaseSessionTest() {
|
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() {
|
@Test fun popupTestAllow() {
|
||||||
// Ensure popup blocking is enabled for this test.
|
// Ensure popup blocking is enabled for this test.
|
||||||
sessionRule.setPrefsUntilTestEnd(mapOf("dom.disable_open_during_load" to true))
|
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)))
|
assertThat("URL should match", request.uri, endsWith(forEachCall(POPUP_HTML_PATH, HELLO_HTML_PATH)))
|
||||||
return null
|
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)
|
sessionRule.session.loadTestPath(POPUP_HTML_PATH)
|
||||||
|
@ -70,7 +59,7 @@ class PromptDelegateTest : BaseSessionTest() {
|
||||||
// Ensure popup blocking is enabled for this test.
|
// Ensure popup blocking is enabled for this test.
|
||||||
sessionRule.setPrefsUntilTestEnd(mapOf("dom.disable_open_during_load" to true))
|
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)
|
@AssertCalled(count = 1)
|
||||||
override fun onPopupPrompt(session: GeckoSession, prompt: PromptDelegate.PopupPrompt)
|
override fun onPopupPrompt(session: GeckoSession, prompt: PromptDelegate.PopupPrompt)
|
||||||
: GeckoResult<PromptDelegate.PromptResponse>? {
|
: GeckoResult<PromptDelegate.PromptResponse>? {
|
||||||
|
@ -96,7 +85,8 @@ class PromptDelegateTest : BaseSessionTest() {
|
||||||
})
|
})
|
||||||
|
|
||||||
sessionRule.session.loadTestPath(POPUP_HTML_PATH)
|
sessionRule.session.loadTestPath(POPUP_HTML_PATH)
|
||||||
sessionRule.session.waitForPageStop()
|
sessionRule.waitForPageStop()
|
||||||
|
sessionRule.session.waitForRoundTrip()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore // TODO: Reenable when 1501574 is fixed.
|
@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
|
* 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.
|
* page load since the last wait, or this method will wait indefinitely.
|
||||||
|
|
Загрузка…
Ссылка в новой задаче