Bug 1466640 - [2.1] Add desktop mode test. r=snorp
authorEugen Sawin <esawin@mozilla.com>
Mon, 04 Jun 2018 23:30:52 +0200
changeset 475880 b4ed04cef6028caa777d31cc763843f982631f77
parent 475879 39b29d5990d3edf3f5ae1274eb2bae6746808768
child 475881 9250705be918a4e8a9ee35e353f42c048d5f1a15
push id9374
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:43:20 +0000
treeherdermozilla-beta@160e085dfb0b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1466640
milestone62.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1466640 - [2.1] Add desktop mode test. r=snorp
mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/NavigationDelegateTest.kt
--- 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
@@ -1,16 +1,17 @@
 /* -*- 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 org.mozilla.geckoview.GeckoResponse
 import org.mozilla.geckoview.GeckoSession
+import org.mozilla.geckoview.GeckoSessionSettings
 import org.mozilla.geckoview.GeckoSession.TrackingProtectionDelegate;
 import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.AssertCalled
 import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.NullDelegate
 import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.ReuseSession
 import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.Setting
 import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.WithDevToolsAPI
 import org.mozilla.geckoview.test.util.Callbacks
 
@@ -40,16 +41,50 @@ class NavigationDelegateTest : BaseSessi
                            categories,
                            equalTo(category))
                 assertThat("URI should not be null", uri, notNullValue())
                 assertThat("URI should match", uri, endsWith("trackertest.org/tracker.js"))
             }
         })
     }
 
+    @WithDevToolsAPI
+    @Test fun desktopMode() {
+        sessionRule.session.loadUri("https://example.com")
+        sessionRule.waitForPageStop()
+
+        val userAgentJs = "window.navigator.userAgent"
+        val mobileSubStr = "Mobile"
+        val desktopSubStr = "X11"
+
+        assertThat("User agent should be set to mobile",
+                   sessionRule.session.evaluateJS(userAgentJs) as String,
+                   containsString(mobileSubStr))
+
+        sessionRule.session.settings.setBoolean(
+            GeckoSessionSettings.USE_DESKTOP_MODE, true)
+
+        sessionRule.session.reload()
+        sessionRule.session.waitForPageStop()
+
+        assertThat("User agent should be set to desktop",
+                   sessionRule.session.evaluateJS(userAgentJs) as String,
+                   containsString(desktopSubStr))
+
+        sessionRule.session.settings.setBoolean(
+            GeckoSessionSettings.USE_DESKTOP_MODE, false)
+
+        sessionRule.session.reload()
+        sessionRule.session.waitForPageStop()
+
+        assertThat("User agent should be set to mobile",
+                   sessionRule.session.evaluateJS(userAgentJs) as String,
+                   containsString(mobileSubStr))
+    }
+
     @Test fun load() {
         sessionRule.session.loadTestPath(HELLO_HTML_PATH)
         sessionRule.waitForPageStop()
 
         sessionRule.forCallbacksDuringWait(object : Callbacks.NavigationDelegate {
             @AssertCalled(count = 1, order = [1])
             override fun onLoadRequest(session: GeckoSession, uri: String,
                                        where: Int,