Commit aa6fbf0d authored by Simon Chae's avatar Simon Chae
Browse files

Issue #3666: Make Settings.useWideViewPort nullable

parent 3816e0c5
......@@ -49,6 +49,7 @@ class SystemEngineSession(
@Volatile internal var trackingProtectionPolicy: TrackingProtectionPolicy? = null
@Volatile internal var webFontsEnabled = true
@Volatile internal var currentUrl = ""
@Volatile internal var useWideViewPort: Boolean? = null
@Volatile internal var fullScreenCallback: WebChromeClient.CustomViewCallback? = null
// This is public for FFTV which needs access to the WebView instance. We can mark it internal once
......@@ -272,6 +273,11 @@ class SystemEngineSession(
webSettings.savePassword = false
}
private fun setUseWideViewPort(settings: WebSettings, useWideViewPort: Boolean?) {
this.useWideViewPort = useWideViewPort
useWideViewPort?.let { settings.useWideViewPort = it }
}
private fun initSettings(webView: WebView, s: WebSettings) {
internalSettings = object : Settings() {
override var javascriptEnabled by WebSetting(s::getJavaScriptEnabled, s::setJavaScriptEnabled)
......@@ -281,7 +287,9 @@ class SystemEngineSession(
override var userAgentString by WebSetting(s::getUserAgentString, s::setUserAgentString)
override var displayZoomControls by WebSetting(s::getDisplayZoomControls, s::setDisplayZoomControls)
override var loadWithOverviewMode by WebSetting(s::getLoadWithOverviewMode, s::setLoadWithOverviewMode)
override var useWideViewPort by WebSetting(s::getUseWideViewPort, s::setUseWideViewPort)
override var useWideViewPort: Boolean?
get() = this@SystemEngineSession.useWideViewPort
set(value) = setUseWideViewPort(s, value)
override var supportMultipleWindows by WebSetting(s::supportMultipleWindows, s::setSupportMultipleWindows)
override var allowFileAccessFromFileURLs by WebSetting(
s::getAllowFileAccessFromFileURLs, s::setAllowFileAccessFromFileURLs)
......@@ -344,7 +352,7 @@ class SystemEngineSession(
override fun toggleDesktopMode(enable: Boolean, reload: Boolean) {
val webSettings = webView.settings
webSettings.userAgentString = toggleDesktopUA(webSettings.userAgentString, enable)
webSettings.useWideViewPort = enable
webSettings.useWideViewPort = settings.useWideViewPort ?: enable
notifyObservers { onDesktopModeChange(enable) }
......
......@@ -306,9 +306,9 @@ class SystemEngineSessionTest {
engineSession.settings.loadWithOverviewMode = true
verify(webViewSettings).loadWithOverviewMode = true
assertFalse(engineSession.settings.useWideViewPort)
engineSession.settings.useWideViewPort = true
verify(webViewSettings).useWideViewPort = true
assertNull(engineSession.settings.useWideViewPort)
engineSession.settings.useWideViewPort = false
verify(webViewSettings).useWideViewPort = false
assertTrue(engineSession.settings.allowContentAccess)
engineSession.settings.allowContentAccess = false
......@@ -372,6 +372,7 @@ class SystemEngineSessionTest {
javaScriptCanOpenWindowsAutomatically = true,
displayZoomControls = true,
loadWithOverviewMode = true,
useWideViewPort = true,
supportMultipleWindows = true)
val engineSession = spy(SystemEngineSession(testContext, defaultSettings))
......@@ -390,6 +391,7 @@ class SystemEngineSessionTest {
verify(webViewSettings).javaScriptCanOpenWindowsAutomatically = true
verify(webViewSettings).displayZoomControls = true
verify(webViewSettings).loadWithOverviewMode = true
verify(webViewSettings).useWideViewPort = true
verify(webViewSettings).setSupportMultipleWindows(true)
verify(engineSession).enableTrackingProtection(EngineSession.TrackingProtectionPolicy.all())
assertFalse(engineSession.webFontsEnabled)
......@@ -637,8 +639,7 @@ class SystemEngineSessionTest {
@Test
fun desktopMode() {
val userAgentMobile = "Mozilla/5.0 (Linux; Android 9) AppleWebKit/537.36 Mobile Safari/537.36"
val defaultSettings = DefaultSettings()
val engineSession = spy(SystemEngineSession(testContext, defaultSettings))
val engineSession = spy(SystemEngineSession(testContext))
val webView = mock<WebView>()
val webViewSettings = mock<WebSettings>()
var desktopMode = false
......@@ -664,6 +665,22 @@ class SystemEngineSessionTest {
verify(webView).reload()
}
@Test
fun desktopModeWithProvidedWideViewPort() {
val userAgentMobile = "Mozilla/5.0 (Linux; Android 9) AppleWebKit/537.36 Mobile Safari/537.36"
val defaultSettings = DefaultSettings(useWideViewPort = true)
val engineSession = spy(SystemEngineSession(testContext, defaultSettings))
val webView = mock<WebView>()
val webViewSettings = mock<WebSettings>()
engineSession.webView = webView
whenever(webView.settings).thenReturn(webViewSettings)
whenever(webViewSettings.userAgentString).thenReturn(userAgentMobile)
engineSession.toggleDesktopMode(false)
verify(webViewSettings).useWideViewPort = true
}
@Test
fun desktopModeUA() {
val userAgentMobile = "Mozilla/5.0 (Linux; Android 9) AppleWebKit/537.36 Mobile Safari/537.36"
......
......@@ -88,7 +88,7 @@ abstract class Settings {
* should be used. If not null, this value overrides useWideViePort webSettings in
* [EngineSession.toggleDesktopMode].
*/
open var useWideViewPort: Boolean by UnsupportedSetting()
open var useWideViewPort: Boolean? by UnsupportedSetting()
/**
* Setting to control whether or not file access is allowed.
......@@ -182,7 +182,7 @@ data class DefaultSettings(
override var javaScriptCanOpenWindowsAutomatically: Boolean = false,
override var displayZoomControls: Boolean = true,
override var loadWithOverviewMode: Boolean = false,
override var useWideViewPort: Boolean = false,
override var useWideViewPort: Boolean? = null,
override var allowFileAccess: Boolean = true,
override var allowFileAccessFromFileURLs: Boolean = false,
override var allowUniversalAccessFromFileURLs: Boolean = false,
......
......@@ -50,7 +50,7 @@ class SettingsTest {
{ settings.loadWithOverviewMode },
{ settings.loadWithOverviewMode = false },
{ settings.useWideViewPort },
{ settings.useWideViewPort = false },
{ settings.useWideViewPort = null },
{ settings.allowFileAccess },
{ settings.allowFileAccess = false },
{ settings.allowContentAccess },
......@@ -103,7 +103,7 @@ class SettingsTest {
assertTrue(settings.automaticFontSizeAdjustment)
assertTrue(settings.automaticLanguageAdjustment)
assertFalse(settings.loadWithOverviewMode)
assertFalse(settings.useWideViewPort)
assertNull(settings.useWideViewPort)
assertTrue(settings.allowContentAccess)
assertTrue(settings.allowFileAccess)
assertFalse(settings.allowFileAccessFromFileURLs)
......@@ -165,7 +165,7 @@ class SettingsTest {
assertTrue(defaultSettings.javaScriptCanOpenWindowsAutomatically)
assertFalse(defaultSettings.displayZoomControls)
assertTrue(defaultSettings.loadWithOverviewMode)
assertTrue(defaultSettings.useWideViewPort)
assertEquals(defaultSettings.useWideViewPort, true)
assertFalse(defaultSettings.allowContentAccess)
assertFalse(defaultSettings.allowFileAccess)
assertTrue(defaultSettings.allowFileAccessFromFileURLs)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment