Bug 1322277 - Marionette client should be able to set default capabilities. r=ato, a=test-only
authorHenrik Skupin <mail@hskupin.info>
Wed, 25 Jan 2017 16:29:40 +0100
changeset 375675 c39891c2a2f660d154d8218384e0b7f455bcd38b
parent 375674 2c33db0384377fc05c65ba710db5fbd5d58088a6
child 375676 e1949e439f0ea0a1edc865e5f595debdcc9d1d94
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato, test-only
bugs1322277
milestone53.0a2
Bug 1322277 - Marionette client should be able to set default capabilities. r=ato, a=test-only Some default values for capabilities as defined by the Webdriver spec do not match the expectations for Marionette client. Therefore we should add the possibility to override those defaults in start_session(), but also still allow consumers to set their own values. MozReview-Commit-ID: CTUycCRV5kg
testing/marionette/client/marionette_driver/marionette.py
testing/marionette/harness/marionette_harness/tests/unit/test_capabilities.py
--- a/testing/marionette/client/marionette_driver/marionette.py
+++ b/testing/marionette/client/marionette_driver/marionette.py
@@ -1,13 +1,14 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 import base64
+import copy
 import datetime
 import json
 import os
 import socket
 import sys
 import time
 import traceback
 import warnings
@@ -1273,17 +1274,35 @@ class Marionette(object):
             self.port,
             self.socket_timeout)
 
         # Call wait_for_port() before attempting to connect in
         # the event gecko hasn't started yet.
         self.wait_for_port(timeout=timeout)
         self.protocol, _ = self.client.connect()
 
-        body = {"capabilities": capabilities, "sessionId": session_id}
+        if capabilities is not None:
+            caps = copy.deepcopy(capabilities)
+        else:
+            caps = {}
+
+        # Bug 1322277 - Override some default capabilities which are defined by
+        # the Webdriver spec but which don't really apply to tests executed with
+        # the Marionette client. Using "desiredCapabilities" here will allow tests
+        # to override the settings via "desiredCapabilities" and requiredCapabilities".
+        if "desiredCapabilities" not in caps:
+            caps.update({
+                "desiredCapabilities": {
+                    "timeouts": {
+                        "page load": 60000,  # webdriver specifies 300000ms
+                    }
+                }
+            })
+
+        body = {"capabilities": caps, "sessionId": session_id}
         resp = self._send_message("newSession", body)
 
         self.session_id = resp["sessionId"]
         self.session = resp["value"] if self.protocol == 1 else resp["capabilities"]
         # fallback to processId can be removed in Firefox 55
         self.process_id = self.session.get("moz:processID", self.session.get("processId"))
         self.profile = self.session.get("moz:profile")
 
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_capabilities.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_capabilities.py
@@ -6,17 +6,24 @@ from marionette_driver.errors import Ses
 
 from marionette_harness import MarionetteTestCase
 
 
 class TestCapabilities(MarionetteTestCase):
 
     def setUp(self):
         super(TestCapabilities, self).setUp()
+
+        # Force default webdriver capabilities by default to test
+        # Marionette server.
+        self.marionette.delete_session()
+        self.marionette.start_session({"desiredCapabilities": {}})
+
         self.caps = self.marionette.session_capabilities
+
         with self.marionette.using_context("chrome"):
             self.appinfo = self.marionette.execute_script(
                 "return Services.appinfo")
             self.os_name = self.marionette.execute_script(
                 "return Services.sysinfo.getProperty('name')").lower()
             self.os_version = self.marionette.execute_script(
                 "return Services.sysinfo.getProperty('version')")
 
@@ -28,20 +35,18 @@ class TestCapabilities(MarionetteTestCas
         self.assertIn("acceptInsecureCerts", self.caps)
         self.assertIn("timeouts", self.caps)
 
         self.assertEqual(self.caps["browserName"], self.appinfo["name"].lower())
         self.assertEqual(self.caps["browserVersion"], self.appinfo["version"])
         self.assertEqual(self.caps["platformName"], self.os_name)
         self.assertEqual(self.caps["platformVersion"], self.os_version)
         self.assertFalse(self.caps["acceptInsecureCerts"])
-        self.assertDictEqual(self.caps["timeouts"],
-                             {"implicit": 0,
-                              "page load": 300000,
-                              "script": 30000})
+        self.assertEqual(self.caps["timeouts"],
+                         {"implicit": 0, "page load": 300000, "script": 30000})
 
     def test_supported_features(self):
         self.assertIn("rotatable", self.caps)
 
     def test_additional_capabilities(self):
         self.assertIn("moz:processID", self.caps)
         self.assertEqual(self.caps["moz:processID"], self.appinfo["processID"])
         self.assertEqual(self.marionette.process_id, self.appinfo["processID"])
@@ -55,16 +60,24 @@ class TestCapabilities(MarionetteTestCas
             self.assertEqual(self.caps["moz:profile"], current_profile)
             self.assertEqual(self.marionette.profile, current_profile)
 
         self.assertIn("moz:accessibilityChecks", self.caps)
         self.assertFalse(self.caps["moz:accessibilityChecks"])
         self.assertIn("specificationLevel", self.caps)
         self.assertEqual(self.caps["specificationLevel"], 0)
 
+    def test_default_client_capabilities(self):
+        self.marionette.delete_session()
+        self.marionette.start_session()
+        caps = self.marionette.session_capabilities
+
+        self.assertEqual(caps["timeouts"],
+                         {"implicit": 0, "page load": 60000, "script": 30000})
+
     def test_set_specification_level(self):
         self.marionette.delete_session()
         self.marionette.start_session({"desiredCapabilities": {"specificationLevel": 2}})
         caps = self.marionette.session_capabilities
         self.assertEqual(2, caps["specificationLevel"])
 
         self.marionette.delete_session()
         self.marionette.start_session({"requiredCapabilities": {"specificationLevel": 3}})
@@ -117,97 +130,104 @@ class TestCapabilityMatching(MarionetteT
     def test_browser_name_required(self):
         self.marionette.start_session({"requiredCapabilities": {"browserName": self.browser_name}})
         self.assertEqual(self.marionette.session_capabilities["browserName"], self.browser_name)
 
     def test_browser_name_desired_allowed_types(self):
         for typ in self.allowed:
             self.marionette.delete_session()
             self.marionette.start_session({"desiredCapabilities": {"browserName": typ}})
-            self.assertEqual(self.marionette.session_capabilities["browserName"], self.browser_name)
+            self.assertEqual(self.marionette.session_capabilities["browserName"],
+                             self.browser_name)
 
     def test_browser_name_desired_disallowed_types(self):
         for typ in self.disallowed:
             with self.assertRaises(SessionNotCreatedException):
                 self.marionette.start_session({"desiredCapabilities": {"browserName": typ}})
 
     def test_browser_name_required_allowed_types(self):
         for typ in self.allowed:
             self.marionette.delete_session()
             self.marionette.start_session({"requiredCapabilities": {"browserName": typ}})
-            self.assertEqual(self.marionette.session_capabilities["browserName"], self.browser_name)
+            self.assertEqual(self.marionette.session_capabilities["browserName"],
+                             self.browser_name)
 
     def test_browser_name_requried_disallowed_types(self):
         for typ in self.disallowed:
             with self.assertRaises(SessionNotCreatedException):
                 self.marionette.start_session({"requiredCapabilities": {"browserName": typ}})
 
     def test_browser_name_prefers_required(self):
         caps = {"desiredCapabilities": {"browserName": "invalid"},
-                    "requiredCapabilities": {"browserName": "*"}}
+                "requiredCapabilities": {"browserName": "*"}}
         self.marionette.start_session(caps)
 
     def test_browser_name_error_on_invalid_required(self):
         with self.assertRaises(SessionNotCreatedException):
             caps = {"desiredCapabilities": {"browserName": "*"},
-                        "requiredCapabilities": {"browserName": "invalid"}}
+                    "requiredCapabilities": {"browserName": "invalid"}}
             self.marionette.start_session(caps)
 
     # TODO(ato): browser version comparison not implemented yet
 
     def test_platform_name_desired(self):
-        self.marionette.start_session({"desiredCapabilities": {"platformName": self.platform_name}})
+        self.marionette.start_session(
+            {"desiredCapabilities": {"platformName": self.platform_name}})
         self.assertEqual(self.marionette.session_capabilities["platformName"], self.platform_name)
 
     def test_platform_name_required(self):
-        self.marionette.start_session({"requiredCapabilities": {"platformName": self.platform_name}})
+        self.marionette.start_session(
+            {"requiredCapabilities": {"platformName": self.platform_name}})
         self.assertEqual(self.marionette.session_capabilities["platformName"], self.platform_name)
 
     def test_platform_name_desired_allowed_types(self):
         for typ in self.allowed:
             self.marionette.delete_session()
             self.marionette.start_session({"desiredCapabilities": {"platformName": typ}})
-            self.assertEqual(self.marionette.session_capabilities["platformName"], self.platform_name)
+            self.assertEqual(self.marionette.session_capabilities["platformName"],
+                             self.platform_name)
 
     def test_platform_name_desired_disallowed_types(self):
         for typ in self.disallowed:
             with self.assertRaises(SessionNotCreatedException):
                 self.marionette.start_session({"desiredCapabilities": {"platformName": typ}})
 
     def test_platform_name_required_allowed_types(self):
         for typ in self.allowed:
             self.marionette.delete_session()
             self.marionette.start_session({"requiredCapabilities": {"platformName": typ}})
-            self.assertEqual(self.marionette.session_capabilities["platformName"], self.platform_name)
+            self.assertEqual(self.marionette.session_capabilities["platformName"],
+                             self.platform_name)
 
     def test_platform_name_requried_disallowed_types(self):
         for typ in self.disallowed:
             with self.assertRaises(SessionNotCreatedException):
                 self.marionette.start_session({"requiredCapabilities": {"platformName": typ}})
 
     def test_platform_name_prefers_required(self):
         caps = {"desiredCapabilities": {"platformName": "invalid"},
-                    "requiredCapabilities": {"platformName": "*"}}
+                "requiredCapabilities": {"platformName": "*"}}
         self.marionette.start_session(caps)
 
     def test_platform_name_error_on_invalid_required(self):
         with self.assertRaises(SessionNotCreatedException):
             caps = {"desiredCapabilities": {"platformName": "*"},
-                        "requiredCapabilities": {"platformName": "invalid"}}
+                    "requiredCapabilities": {"platformName": "invalid"}}
             self.marionette.start_session(caps)
 
     # TODO(ato): platform version comparison not imlpemented yet
 
     def test_accept_insecure_certs(self):
         for capability_type in ["desiredCapabilities", "requiredCapabilities"]:
             print("testing {}".format(capability_type))
             for value in ["", 42, {}, []]:
                 print("  type {}".format(type(value)))
                 with self.assertRaises(SessionNotCreatedException):
-                    self.marionette.start_session({capability_type: {"acceptInsecureCerts": value}})
+                    self.marionette.start_session(
+                        {capability_type: {"acceptInsecureCerts": value}})
 
         self.marionette.delete_session()
         self.marionette.start_session({"desiredCapabilities": {"acceptInsecureCerts": True}})
         self.assertTrue(self.marionette.session_capabilities["acceptInsecureCerts"])
         self.marionette.delete_session()
         self.marionette.start_session({"requiredCapabilities": {"acceptInsecureCerts": True}})
 
         self.assertTrue(self.marionette.session_capabilities["acceptInsecureCerts"])
@@ -236,14 +256,14 @@ class TestCapabilityMatching(MarionetteT
 
     def test_proxy_required(self):
         self.marionette.start_session({"requiredCapabilities": {"proxy": {"proxyType": "manual"}}})
         self.assertIn("proxy", self.marionette.session_capabilities)
         self.assertEqual(self.marionette.session_capabilities["proxy"]["proxyType"], "manual")
         self.assertEqual(self.marionette.get_pref("network.proxy.type"), 1)
 
     def test_timeouts(self):
-        timeouts = {u"implicit": 123, u"page load": 456, u"script": 789}
+        timeouts = {"implicit": 123, "page load": 456, "script": 789}
         caps = {"desiredCapabilities": {"timeouts": timeouts}}
         self.marionette.start_session(caps)
         self.assertIn("timeouts", self.marionette.session_capabilities)
-        self.assertDictEqual(self.marionette.session_capabilities["timeouts"], timeouts)
-        self.assertDictEqual(self.marionette._send_message("getTimeouts"), timeouts)
+        self.assertEqual(self.marionette.session_capabilities["timeouts"], timeouts)
+        self.assertEqual(self.marionette._send_message("getTimeouts"), timeouts)