Bug 1484391 - Update Mobile VR UA string in GeckoView r=agi,esawin
authorRandall Barker <rbarker@mozilla.com>
Wed, 31 Oct 2018 15:36:16 +0000
changeset 443760 bfe60bb8afc50931f130115099cbabebf4787e11
parent 443759 6c2a5ce9fad8b976bfa51fdc80908d1bbfd0e90f
child 443761 4610b4c5befa0f89360ab554efcf0dbd9a1e0a07
push id34969
push usercbrindusan@mozilla.com
push dateWed, 31 Oct 2018 21:39:53 +0000
treeherdermozilla-central@814414676c25 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersagi, esawin
bugs1484391
milestone65.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 1484391 - Update Mobile VR UA string in GeckoView r=agi,esawin Differential Revision: https://phabricator.services.mozilla.com/D10306
mobile/android/chrome/geckoview/GeckoViewContentSettings.js
mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/NavigationDelegateTest.kt
mobile/android/modules/geckoview/GeckoViewSettings.jsm
--- a/mobile/android/chrome/geckoview/GeckoViewContentSettings.js
+++ b/mobile/android/chrome/geckoview/GeckoViewContentSettings.js
@@ -7,16 +7,17 @@ ChromeUtils.import("resource://gre/modul
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 
 XPCOMUtils.defineLazyModuleGetters(this, {
   GeckoViewUtils: "resource://gre/modules/GeckoViewUtils.jsm",
 });
 
 // This needs to match GeckoSessionSettings.java
 const USER_AGENT_MODE_MOBILE = 0;
+const USER_AGENT_MODE_DESKTOP = 1;
 
 // Handles GeckoView content settings including:
 // * tracking protection
 // * user agent mode
 class GeckoViewContentSettings extends GeckoViewContentModule {
   onInit() {
     debug `onInit`;
     this._userAgentMode = USER_AGENT_MODE_MOBILE;
@@ -42,17 +43,17 @@ class GeckoViewContentSettings extends G
     return this._userAgentMode;
   }
 
   set userAgentMode(aMode) {
     if (this.userAgentMode === aMode) {
       return;
     }
     let utils = content.windowUtils;
-    utils.setDesktopModeViewport(aMode != USER_AGENT_MODE_MOBILE);
+    utils.setDesktopModeViewport(aMode === USER_AGENT_MODE_DESKTOP);
     this._userAgentMode = aMode;
   }
 
   get displayMode() {
     const docShell = content && GeckoViewUtils.getRootDocShell(content);
     return docShell ? docShell.displayMode
                     : Ci.nsIDocShell.DISPLAY_MODE_BROWSER;
   }
--- 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
@@ -376,16 +376,31 @@ class NavigationDelegateTest : BaseSessi
         assertThat("User agent should be set to mobile",
                    sessionRule.session.evaluateJS(userAgentJs) as String,
                    containsString(mobileSubStr))
 
         userAgent = sessionRule.waitForResult(sessionRule.session.getUserAgent());
         assertThat("User agent should be reported as mobile",
                     userAgent, containsString(mobileSubStr));
 
+        val vrSubStr = "Mobile VR"
+        sessionRule.session.settings.setInt(
+                GeckoSessionSettings.USER_AGENT_MODE, GeckoSessionSettings.USER_AGENT_MODE_VR)
+
+        sessionRule.session.reload()
+        sessionRule.session.waitForPageStop()
+
+        assertThat("User agent should be set to VR",
+                sessionRule.session.evaluateJS(userAgentJs) as String,
+                containsString(vrSubStr))
+
+        userAgent = sessionRule.waitForResult(sessionRule.session.getUserAgent())
+        assertThat("User agent should be reported as VR",
+                userAgent, containsString(vrSubStr))
+
     }
 
     @Test fun telemetrySnapshots() {
         sessionRule.session.loadTestPath(HELLO_HTML_PATH)
         sessionRule.waitForPageStop()
 
         val telemetry = sessionRule.runtime.telemetry
         val result = sessionRule.waitForResult(telemetry.getSnapshots(false))
--- a/mobile/android/modules/geckoview/GeckoViewSettings.jsm
+++ b/mobile/android/modules/geckoview/GeckoViewSettings.jsm
@@ -27,19 +27,17 @@ XPCOMUtils.defineLazyGetter(
     return MOBILE_USER_AGENT
            .replace(/Android \d.+?; [a-zA-Z]+/, "X11; Linux x86_64")
            .replace(/Gecko\/[0-9\.]+/, "Gecko/20100101");
   });
 
 XPCOMUtils.defineLazyGetter(
   this, "VR_USER_AGENT",
   function() {
-    return MOBILE_USER_AGENT
-           .getService(Ci.nsIHttpProtocolHandler).userAgent
-           .replace(/Android \d+; [a-zA-Z]+/, "VR");
+    return MOBILE_USER_AGENT.replace(/Mobile/, "Mobile VR");
   });
 
 // This needs to match GeckoSessionSettings.java
 const USER_AGENT_MODE_MOBILE = 0;
 const USER_AGENT_MODE_DESKTOP = 1;
 const USER_AGENT_MODE_VR = 2;
 
 // Handles GeckoView settings including: