commit 9050781f98b3306415fa99ef2622136b2fdbff3d
parent fb70d4fe0ecd428400f1702e54b68b0dbcf1947c
Author: Jeff Boek <j@jboek.com>
Date: Thu, 2 Oct 2025 20:04:33 +0000
Bug 1818679 - Adds tests to confirm onLoadRequest isn't called r=geckoview-reviewers,tcampbell
Differential Revision: https://phabricator.services.mozilla.com/D263175
Diffstat:
5 files changed, 86 insertions(+), 0 deletions(-)
diff --git a/mobile/android/geckoview/src/androidTest/assets/www/iframe_sandbox_allow.html b/mobile/android/geckoview/src/androidTest/assets/www/iframe_sandbox_allow.html
@@ -0,0 +1,10 @@
+<!doctype html>
+<html>
+ <head>
+ <meta charset="utf-8" />
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+ </head>
+ <body>
+ <iframe id="iframe" src="iframe_sandbox_content.html"></iframe>
+ </body>
+</html>
diff --git a/mobile/android/geckoview/src/androidTest/assets/www/iframe_sandbox_block.html b/mobile/android/geckoview/src/androidTest/assets/www/iframe_sandbox_block.html
@@ -0,0 +1,14 @@
+<!doctype html>
+<html>
+ <head>
+ <meta charset="utf-8" />
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+ </head>
+ <body>
+ <iframe
+ id="iframe"
+ src="iframe_sandbox_content.html"
+ sandbox="allow-same-origin"
+ ></iframe>
+ </body>
+</html>
diff --git a/mobile/android/geckoview/src/androidTest/assets/www/iframe_sandbox_content.html b/mobile/android/geckoview/src/androidTest/assets/www/iframe_sandbox_content.html
@@ -0,0 +1,10 @@
+<!doctype html>
+<html>
+ <head>
+ <meta charset="utf-8" content="width=device-width, height=device-height" />
+ <title>Iframe sandbox content</title>
+ </head>
+ <body>
+ <a id="tel-button" href="tel:1">Call</a>
+ </body>
+</html>
diff --git a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/BaseSessionTest.kt b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/BaseSessionTest.kt
@@ -87,6 +87,8 @@ open class BaseSessionTest(
const val VIEWPORT_PATH = "/assets/www/viewport.html"
const val IFRAME_REDIRECT_LOCAL = "/assets/www/iframe_redirect_local.html"
const val IFRAME_REDIRECT_AUTOMATION = "/assets/www/iframe_redirect_automation.html"
+ const val IFRAME_SANDBOX_BLOCK = "/assets/www/iframe_sandbox_block.html"
+ const val IFRAME_SANDBOX_ALLOW = "/assets/www/iframe_sandbox_allow.html"
const val AUTOPLAY_PATH = "/assets/www/autoplay.html"
const val SIMPLE_SCROLL_TEST_PATH = "/assets/www/simple-scroll.html"
const val SCROLL_TEST_PATH = "/assets/www/scroll.html"
diff --git a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/NavigationDelegateTest.kt b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/NavigationDelegateTest.kt
@@ -916,6 +916,56 @@ class NavigationDelegateTest : BaseSessionTest() {
})
}
+ @Test fun sandboxCallNavigationDelegate() {
+ mainSession.loadTestPath(IFRAME_SANDBOX_ALLOW)
+ sessionRule.waitForPageStop()
+ mainSession.evaluateJS("document.getElementById('iframe').contentDocument.getElementById('tel-button').click();")
+ sessionRule.forCallbacksDuringWait(object : NavigationDelegate {
+ @AssertCalled(count = 1)
+ override fun onLoadRequest(
+ session: GeckoSession,
+ request: LoadRequest,
+ ): GeckoResult<AllowOrDeny>? {
+ assertThat("Session should not be null", session, notNullValue())
+ assertThat("URI should not be null", request.uri, notNullValue())
+ return null
+ }
+
+ @AssertCalled(count = 1)
+ override fun onSubframeLoadRequest(
+ session: GeckoSession,
+ request: LoadRequest,
+ ): GeckoResult<AllowOrDeny?>? {
+ assertThat("URI should not be null", request.uri, notNullValue())
+ assertThat("URI should not be null", request.uri, notNullValue())
+ return null
+ }
+ })
+ }
+
+ @Test fun sandboxDoesntCallNavigationDelegate() {
+ mainSession.loadTestPath(IFRAME_SANDBOX_BLOCK)
+ sessionRule.waitForPageStop()
+ mainSession.evaluateJS("document.getElementById('iframe').contentDocument.getElementById('tel-button').click();")
+ sessionRule.forCallbacksDuringWait(object : NavigationDelegate {
+ @AssertCalled(count = 1)
+ override fun onLoadRequest(
+ session: GeckoSession,
+ request: LoadRequest,
+ ): GeckoResult<AllowOrDeny>? {
+ return null
+ }
+
+ @AssertCalled(count = 0)
+ override fun onSubframeLoadRequest(
+ session: GeckoSession,
+ request: LoadRequest,
+ ): GeckoResult<AllowOrDeny?>? {
+ return null
+ }
+ })
+ }
+
@Test fun redirectLoadIframe() {
val path = if (sessionRule.env.isAutomation) {
IFRAME_REDIRECT_AUTOMATION