Bug 1336124 - Return error when there is no session. r=maja_zf, a=test-only
authorAndreas Tolfsen <ato@mozilla.com>
Thu, 02 Feb 2017 16:15:31 +0000
changeset 366922 4333619aa67d4e00b79b4368a9ac7b149d951fb3
parent 366921 246c07f0bf7db1459a159cf57b32cff385147c16
child 366923 9ee72b7bb80424b810d55de40a749338b6731a2b
push id6891
push userryanvm@gmail.com
push dateTue, 07 Feb 2017 17:32:45 +0000
treeherdermozilla-beta@be5204c4c3ee [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmaja_zf, test-only
bugs1336124
milestone52.0
Bug 1336124 - Return error when there is no session. r=maja_zf, a=test-only 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()