Bug 1336124 - Only delete session if one exists when testing capabilities. r=maja_zf, a=test-only
authorAndreas Tolfsen <ato@mozilla.com>
Fri, 03 Feb 2017 16:53:31 +0000
changeset 375965 c758a3871aaabb9097adcacb5875fd5758183725
parent 375964 14f3c33992bab2db5821325a1571cce5d51fd025
child 375966 c2fbf32bde4af55e9a9530bc1b0debda0d19c974
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)
reviewersmaja_zf, test-only
bugs1336124
milestone53.0a2
Bug 1336124 - Only delete session if one exists when testing capabilities. r=maja_zf, a=test-only MozReview-Commit-ID: IEqHzADUQow
testing/marionette/harness/marionette_harness/tests/unit/test_capabilities.py
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_capabilities.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_capabilities.py
@@ -103,40 +103,44 @@ class TestCapabilities(MarionetteTestCas
 class TestCapabilityMatching(MarionetteTestCase):
     allowed = [None, "*"]
     disallowed = ["", 42, True, {}, []]
 
     def setUp(self):
         MarionetteTestCase.setUp(self)
         self.browser_name = self.marionette.session_capabilities["browserName"]
         self.platform_name = self.marionette.session_capabilities["platformName"]
-        self.marionette.delete_session()
+        self.delete_session()
+
+    def delete_session(self):
+        if self.marionette.session is not None:
+            self.marionette.delete_session()
 
     def test_browser_name_desired(self):
         self.marionette.start_session({"desiredCapabilities": {"browserName": self.browser_name}})
         self.assertEqual(self.marionette.session_capabilities["browserName"], self.browser_name)
 
     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.delete_session()
             self.marionette.start_session({"desiredCapabilities": {"browserName": typ}})
             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.delete_session()
             self.marionette.start_session({"requiredCapabilities": {"browserName": typ}})
             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}})
 
@@ -158,28 +162,28 @@ class TestCapabilityMatching(MarionetteT
         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.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.delete_session()
             self.marionette.start_session({"desiredCapabilities": {"platformName": typ}})
             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.delete_session()
             self.marionette.start_session({"requiredCapabilities": {"platformName": typ}})
             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}})
 
@@ -199,28 +203,28 @@ class TestCapabilityMatching(MarionetteT
     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.delete_session()
+        self.delete_session()
         self.marionette.start_session({"desiredCapabilities": {"acceptInsecureCerts": True}})
         self.assertTrue(self.marionette.session_capabilities["acceptInsecureCerts"])
-        self.marionette.delete_session()
+        self.delete_session()
         self.marionette.start_session({"requiredCapabilities": {"acceptInsecureCerts": True}})
 
         self.assertTrue(self.marionette.session_capabilities["acceptInsecureCerts"])
 
     def test_page_load_strategy(self):
         for strategy in ["none", "eager", "normal"]:
             print("valid strategy {}".format(strategy))
-            self.marionette.delete_session()
+            self.delete_session()
             self.marionette.start_session({"desiredCapabilities": {"pageLoadStrategy": strategy}})
             self.assertEqual(self.marionette.session_capabilities["pageLoadStrategy"], strategy)
 
         for value in ["", "EAGER", True, 42, {}, []]:
             print("invalid strategy {}".format(value))
             with self.assertRaises(SessionNotCreatedException):
                 self.marionette.start_session({"desiredCapabilities": {"pageLoadStrategy": value}})