Bug 1336124 - Return error when there is no session; r=maja_zf
authorAndreas Tolfsen <ato@mozilla.com>
Thu, 02 Feb 2017 16:15:31 +0000
changeset 340949 6d17a85df7e32778362ba54466d1a4a224f645b8
parent 340948 ca0345ae33a42ffc2ec9f776c1a2fe1280d615e7
child 340950 c4441c1492fd729592539121f7400e565e53b75e
push id31321
push userkwierso@gmail.com
push dateTue, 07 Feb 2017 01:37:59 +0000
treeherdermozilla-central@4f8b2d44eaa0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmaja_zf
bugs1336124
milestone54.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 1336124 - Return error when there is no session; r=maja_zf Returns an invalid session id error when there is no current session and the requested command is not newSession. MozReview-Commit-ID: Dnu2PXDmeaG
testing/marionette/dispatcher.js
testing/marionette/harness/marionette_harness/tests/unit/test_session.py
--- a/testing/marionette/dispatcher.js
+++ b/testing/marionette/dispatcher.js
@@ -5,16 +5,17 @@
 "use strict";
 
 const {interfaces: Ci, utils: Cu} = Components;
 
 Cu.import("resource://gre/modules/Log.jsm");
 Cu.import("resource://gre/modules/Preferences.jsm");
 Cu.import("resource://gre/modules/Task.jsm");
 
+Cu.import("chrome://marionette/content/assert.js");
 Cu.import("chrome://marionette/content/driver.js");
 Cu.import("chrome://marionette/content/error.js");
 Cu.import("chrome://marionette/content/message.js");
 
 this.EXPORTED_SYMBOLS = ["Dispatcher"];
 
 const PROTOCOL_VERSION = 3;
 
@@ -115,16 +116,20 @@ Dispatcher.prototype.execute = function 
   let sendError = resp.sendError.bind(resp);
 
   let req = Task.spawn(function*() {
     let fn = this.driver.commands[cmd.name];
     if (typeof fn == "undefined") {
       throw new UnknownCommandError(cmd.name);
     }
 
+    if (cmd.name !== "newSession") {
+      assert.session(this.driver);
+    }
+
     let rv = yield fn.bind(this.driver)(cmd, resp);
 
     if (typeof rv != "undefined") {
       if (typeof rv != "object") {
         resp.body = {value: rv};
       } else {
         resp.body = rv;
       }
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_session.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_session.py
@@ -1,13 +1,13 @@
 # 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/.
 
-from marionette_driver.errors import SessionNotCreatedException
+from marionette_driver import errors
 
 from marionette_harness import MarionetteTestCase
 
 
 class TestSession(MarionetteTestCase):
     def setUp(self):
         super(TestSession, self).setUp()
         self.marionette.delete_session()
@@ -24,26 +24,33 @@ class TestSession(MarionetteTestCase):
         self.assertIn("browserName", caps)
         self.assertIn("browserVersion", caps)
         self.assertIn("platformName", caps)
         self.assertIn("platformVersion", caps)
 
         # Optional capabilities we want Marionette to support
         self.assertIn("rotatable", caps)
 
-    def test_we_can_get_the_session_id(self):
+    def test_get_session_id(self):
         # Sends newSession
         self.marionette.start_session()
 
         self.assertTrue(self.marionette.session_id is not None)
         self.assertTrue(isinstance(self.marionette.session_id, unicode))
 
-    def test_we_can_set_the_session_id(self):
+    def test_set_the_session_id(self):
         # Sends newSession
         self.marionette.start_session(session_id="ILoveCheese")
 
         self.assertEqual(self.marionette.session_id, "ILoveCheese")
         self.assertTrue(isinstance(self.marionette.session_id, unicode))
 
-    def test_we_only_support_one_active_session_at_a_time(self):
+    def test_session_already_started(self):
         self.marionette.start_session()
         self.assertTrue(isinstance(self.marionette.session_id, unicode))
-        self.assertRaises(SessionNotCreatedException, self.marionette._send_message, "newSession", {})
+        with self.assertRaises(errors.SessionNotCreatedException):
+            self.marionette._send_message("newSession", {})
+
+    def test_no_session(self):
+        with self.assertRaises(errors.InvalidSessionIdException):
+            self.marionette.get_url()
+        self.marionette.start_session()
+        self.marionette.get_url()