Bug 1336124 - Return error when there is no session; r?maja_zf draft
authorAndreas Tolfsen <ato@mozilla.com>
Thu, 02 Feb 2017 16:15:31 +0000
changeset 479426 7cd926394e4f9c5043edf8a843afbd3af6dbab4c
parent 479425 9161dbf2f4776e3d2730ef4bf2202cf68648ade9
child 479427 08f73dd825d8be4fbe5b3859979867c06eae7232
push id44249
push userbmo:ato@mozilla.com
push dateMon, 06 Feb 2017 16:53:35 +0000
reviewersmaja_zf
bugs1336124
milestone54.0a1
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()