Bug 1470646 - Return platformName as recommended by WebDriver. r?whimboo draft
authorAndreas Tolfsen <ato@sny.no>
Sat, 23 Jun 2018 14:31:00 +0100
changeset 813591 b64402b1ccbfa8ef68375a1732f117d513543f93
parent 813590 afe03fe50083e4e9da978015177f5e849f66ec4f
child 813592 f8800eebc06523680e96dece0acd4e5eda306200
push id114929
push userbmo:ato@sny.no
push dateTue, 03 Jul 2018 11:58:17 +0000
reviewerswhimboo
bugs1470646
milestone63.0a1
Bug 1470646 - Return platformName as recommended by WebDriver. r?whimboo The WebDriver standard recommends that we return one of "windows", "mac", or "linux". Additionally Marionette supports Fennec, for which we return "android": this is fine because the specification does not yet cover mobile browsers. MozReview-Commit-ID: EgZ9UKrbsrd
testing/marionette/capabilities.js
testing/marionette/test/unit/test_capabilities.js
--- a/testing/marionette/capabilities.js
+++ b/testing/marionette/capabilities.js
@@ -360,17 +360,17 @@ class Proxy {
 /** WebDriver session capabilities representation. */
 class Capabilities extends Map {
   /** @class */
   constructor() {
     super([
       // webdriver
       ["browserName", appinfo.name],
       ["browserVersion", appinfo.version],
-      ["platformName", Services.sysinfo.getProperty("name").toLowerCase()],
+      ["platformName", getWebDriverPlatformName()],
       ["platformVersion", Services.sysinfo.getProperty("version")],
       ["pageLoadStrategy", PageLoadStrategy.Normal],
       ["acceptInsecureCerts", false],
       ["timeouts", new Timeouts()],
       ["proxy", new Proxy()],
 
       // features
       ["rotatable", appinfo.name == "B2G"],
@@ -494,16 +494,31 @@ class Capabilities extends Map {
   }
 }
 
 this.Capabilities = Capabilities;
 this.PageLoadStrategy = PageLoadStrategy;
 this.Proxy = Proxy;
 this.Timeouts = Timeouts;
 
+function getWebDriverPlatformName() {
+  let name = Services.sysinfo.getProperty("name");
+
+  switch (name) {
+    case "Windows_NT":
+      return "windows";
+
+    case "Darwin":
+      return "mac";
+
+    default:
+      return name.toLowerCase();
+  }
+}
+
 // Specialisation of |JSON.stringify| that produces JSON-safe object
 // literals, dropping empty objects and entries which values are undefined
 // or null.  Objects are allowed to produce their own JSON representations
 // by implementing a |toJSON| function.
 function marshal(obj) {
   let rv = Object.create(null);
 
   function* iter(mapOrObject) {
--- a/testing/marionette/test/unit/test_capabilities.js
+++ b/testing/marionette/test/unit/test_capabilities.js
@@ -366,16 +366,17 @@ add_test(function test_Proxy_fromJSON() 
   run_next_test();
 });
 
 add_test(function test_Capabilities_ctor() {
   let caps = new Capabilities();
   ok(caps.has("browserName"));
   ok(caps.has("browserVersion"));
   ok(caps.has("platformName"));
+  ok(["linux", "mac", "windows", "android"].includes(caps.get("platformName")));
   ok(caps.has("platformVersion"));
   equal(PageLoadStrategy.Normal, caps.get("pageLoadStrategy"));
   equal(false, caps.get("acceptInsecureCerts"));
   ok(caps.get("timeouts") instanceof Timeouts);
   ok(caps.get("proxy") instanceof Proxy);
 
   ok(caps.has("rotatable"));