Skip to content

Commit

Permalink
Bug 1591533 - Add GV API to enable DNS-over-HTTPS capability on Fenix…
Browse files Browse the repository at this point in the history
… r=geckoview-reviewers,calu,owlish

This PR adds a couple GeckoView API to setup and specific DoH TRR mode
and server URI, which enables the DNS-over-HTTPS capability on Firefox
Fenix.

Differential Revision: https://phabricator.services.mozilla.com/D121455
  • Loading branch information
cschanaj committed Jan 25, 2024
1 parent 2dc17b8 commit 9f3c471
Show file tree
Hide file tree
Showing 5 changed files with 324 additions and 1 deletion.
16 changes: 16 additions & 0 deletions mobile/android/geckoview/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,7 @@ package org.mozilla.geckoview {
method public boolean getGlobalPrivacyControlPrivateMode();
method public boolean getInputAutoZoomEnabled();
method public boolean getJavaScriptEnabled();
method @NonNull public int getLargeKeepaliveFactor();
method @Nullable public String[] getLocales();
method public boolean getLoginAutofillEnabled();
method public boolean getPauseForDebuggerEnabled();
Expand All @@ -884,6 +885,8 @@ package org.mozilla.geckoview {
method @Nullable public Rect getScreenSizeOverride();
method @Nullable public RuntimeTelemetry.Delegate getTelemetryDelegate();
method public boolean getTranslationsOfferPopup();
method @NonNull public String getTrustedRecursiveResolverUri();
method public int getTrustedRecusiveResolverMode();
method public boolean getUseMaxScreenDepth();
method public boolean getWebFontsEnabled();
method public boolean getWebManifestEnabled();
Expand All @@ -905,11 +908,14 @@ package org.mozilla.geckoview {
method @NonNull public GeckoRuntimeSettings setGlobalPrivacyControl(boolean);
method @NonNull public GeckoRuntimeSettings setInputAutoZoomEnabled(boolean);
method @NonNull public GeckoRuntimeSettings setJavaScriptEnabled(boolean);
method @NonNull public GeckoRuntimeSettings setLargeKeepaliveFactor(int);
method public void setLocales(@Nullable String[]);
method @NonNull public GeckoRuntimeSettings setLoginAutofillEnabled(boolean);
method @NonNull public GeckoRuntimeSettings setPreferredColorScheme(int);
method @NonNull public GeckoRuntimeSettings setRemoteDebuggingEnabled(boolean);
method @NonNull public GeckoRuntimeSettings setTranslationsOfferPopup(boolean);
method @NonNull public GeckoRuntimeSettings setTrustedRecursiveResolverMode(int);
method @NonNull public GeckoRuntimeSettings setTrustedRecursiveResolverUri(@NonNull String);
method @NonNull public GeckoRuntimeSettings setWebFontsEnabled(boolean);
method @NonNull public GeckoRuntimeSettings setWebManifestEnabled(boolean);
field public static final int ALLOW_ALL = 0;
Expand All @@ -919,6 +925,10 @@ package org.mozilla.geckoview {
field public static final Parcelable.Creator<GeckoRuntimeSettings> CREATOR;
field public static final int HTTPS_ONLY = 2;
field public static final int HTTPS_ONLY_PRIVATE = 1;
field public static final int TRR_MODE_DISABLED = 5;
field public static final int TRR_MODE_FIRST = 2;
field public static final int TRR_MODE_OFF = 0;
field public static final int TRR_MODE_ONLY = 3;
}

@AnyThread public static final class GeckoRuntimeSettings.Builder extends RuntimeSettings.Builder<GeckoRuntimeSettings> {
Expand Down Expand Up @@ -949,6 +959,7 @@ package org.mozilla.geckoview {
method @NonNull public GeckoRuntimeSettings.Builder globalPrivacyControlEnabled(boolean);
method @NonNull public GeckoRuntimeSettings.Builder inputAutoZoomEnabled(boolean);
method @NonNull public GeckoRuntimeSettings.Builder javaScriptEnabled(boolean);
method @NonNull public GeckoRuntimeSettings.Builder largeKeepaliveFactor(int);
method @NonNull public GeckoRuntimeSettings.Builder locales(@Nullable String[]);
method @NonNull public GeckoRuntimeSettings.Builder loginAutofillEnabled(boolean);
method @NonNull public GeckoRuntimeSettings.Builder pauseForDebugger(boolean);
Expand All @@ -957,6 +968,8 @@ package org.mozilla.geckoview {
method @NonNull public GeckoRuntimeSettings.Builder screenSizeOverride(int, int);
method @NonNull public GeckoRuntimeSettings.Builder telemetryDelegate(@NonNull RuntimeTelemetry.Delegate);
method @NonNull public GeckoRuntimeSettings.Builder translationsOfferPopup(boolean);
method @NonNull public GeckoRuntimeSettings.Builder trustedRecursiveResolverMode(int);
method @NonNull public GeckoRuntimeSettings.Builder trustedRecursiveResolverUri(@NonNull String);
method @NonNull public GeckoRuntimeSettings.Builder useMaxScreenDepth(boolean);
method @NonNull public GeckoRuntimeSettings.Builder webFontsEnabled(boolean);
method @NonNull public GeckoRuntimeSettings.Builder webManifest(boolean);
Expand All @@ -969,6 +982,9 @@ package org.mozilla.geckoview {
@Retention(value=RetentionPolicy.SOURCE) public static interface GeckoRuntimeSettings.HttpsOnlyMode {
}

@Retention(value=RetentionPolicy.SOURCE) public static interface GeckoRuntimeSettings.TrustedRecursiveResolverMode {
}

public class GeckoSession {
ctor public GeckoSession();
ctor public GeckoSession(@Nullable GeckoSessionSettings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import android.provider.Settings
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.MediumTest
import androidx.test.platform.app.InstrumentationRegistry
import junit.framework.TestCase.assertTrue
import org.hamcrest.Matchers.* // ktlint-disable no-wildcard-imports
import org.junit.Assume.assumeThat
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.geckoview.BuildConfig
import org.mozilla.geckoview.GeckoResult
import org.mozilla.geckoview.GeckoSession
import org.mozilla.geckoview.GeckoSession.NavigationDelegate
Expand Down Expand Up @@ -216,6 +218,50 @@ class RuntimeSettingsTest : BaseSessionTest() {
)
}

@Test
fun largeKeepaliveFactor() {
val defaultLargeKeepaliveFactor = 10
val settings = sessionRule.runtime.settings

val largeKeepaliveFactorPref = "network.http.largeKeepaliveFactor"
var prefValue = (sessionRule.getPrefs(largeKeepaliveFactorPref)[0] as Int)
assertThat(
"default LargeKeepaliveFactor should be 10",
prefValue,
`is`(defaultLargeKeepaliveFactor),
)

for (factor in 1..10) {
settings.setLargeKeepaliveFactor(factor)
prefValue = (sessionRule.getPrefs(largeKeepaliveFactorPref)[0] as Int)
assertThat(
"setting LargeKeepaliveFactor to an integer value between 1..10 should work",
prefValue,
`is`(factor),
)
}

val sanitizedDefaultLargeKeepaliveFactor = 1

/**
* Setting an invalid factor will cause an exception to be throw in debug build.
* otherwise, the factor will be reset to default when an invalid factor is given.
*/
try {
settings.setLargeKeepaliveFactor(128)
prefValue = (sessionRule.getPrefs(largeKeepaliveFactorPref)[0] as Int)
assertThat(
"set LargeKeepaliveFactor to default when input is invalid",
prefValue,
`is`(sanitizedDefaultLargeKeepaliveFactor),
)
} catch (e: Exception) {
if (BuildConfig.DEBUG_BUILD) {
assertTrue("Should have an exception in DEBUG_BUILD", true)
}
}
}

@Test
fun aboutConfig() {
// This is broken in automation because document channel is enabled by default
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */

package org.mozilla.geckoview.test

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.MediumTest
import org.hamcrest.Matchers.* // ktlint-disable no-wildcard-imports
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.geckoview.GeckoRuntimeSettings

@RunWith(AndroidJUnit4::class)
@MediumTest
class TrustedRecursiveResolverTest : BaseSessionTest() {

@Test fun trustedRecursiveResolverMode() {
val settings = sessionRule.runtime.settings
val trustedRecursiveResolverModePerf = "network.trr.mode"

var prefValue = (sessionRule.getPrefs(trustedRecursiveResolverModePerf)[0] as Int)
assertThat(
"Initial TRR mode should be TRR_MODE_OFF (0)",
prefValue,
`is`(0),
)

settings.setTrustedRecursiveResolverMode(GeckoRuntimeSettings.TRR_MODE_FIRST)
prefValue = (sessionRule.getPrefs(trustedRecursiveResolverModePerf)[0] as Int)

assertThat(
"Setting TRR mode to TRR_MODE_FIRST (2)",
prefValue,
`is`(2),
)

settings.setTrustedRecursiveResolverMode(GeckoRuntimeSettings.TRR_MODE_ONLY)
prefValue = (sessionRule.getPrefs(trustedRecursiveResolverModePerf)[0] as Int)

assertThat(
"Setting TRR mode to TRR_MODE_ONLY (3)",
prefValue,
`is`(3),
)

settings.setTrustedRecursiveResolverMode(GeckoRuntimeSettings.TRR_MODE_DISABLED)
prefValue = (sessionRule.getPrefs(trustedRecursiveResolverModePerf)[0] as Int)

assertThat(
"Setting TRR mode to TRR_MODE_DISABLED (5)",
prefValue,
`is`(5),
)

settings.setTrustedRecursiveResolverMode(GeckoRuntimeSettings.TRR_MODE_OFF)
prefValue = (sessionRule.getPrefs(trustedRecursiveResolverModePerf)[0] as Int)

assertThat(
"Setting TRR mode to TRR_MODE_OFF (0)",
prefValue,
`is`(0),
)
}

@Test fun trustedRecursiveResolverUrl() {
val settings = sessionRule.runtime.settings
val trustedRecursiveResolverUriPerf = "network.trr.uri"

var prefValue = (sessionRule.getPrefs(trustedRecursiveResolverUriPerf)[0] as String)
assertThat(
"Initial TRR Uri should be empty",
prefValue,
`is`(""),
)

val exampleValue = "https://mozilla.cloudflare-dns.com/dns-query"
settings.setTrustedRecursiveResolverUri(exampleValue)
prefValue = (sessionRule.getPrefs(trustedRecursiveResolverUriPerf)[0] as String)
assertThat(
"Setting custom TRR Uri should work",
prefValue,
`is`(exampleValue),
)
}
}
Loading

0 comments on commit 9f3c471

Please sign in to comment.