Bug 960931: Throw SessionNotCreatedError when requesting 2nd Active Session r=ato
authorDavid Burns <dburns@mozilla.com>
Wed, 25 May 2016 15:04:40 +0100
changeset 338182 050485808a590c3db6c2bf001a1c18897d26db04
parent 338181 062491c6264039e58c2b300997ba9eef23dbc59a
child 338183 8e7bb0f5c506a5fadb406f9a598bfe2231298490
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato
bugs960931
milestone49.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 960931: Throw SessionNotCreatedError when requesting 2nd Active Session r=ato If we have a session we are expected to return a SessionNotCreatedError as part of step 2 of http://w3c.github.io/webdriver/webdriver-spec.html#new-session MozReview-Commit-ID: AVmQ4Kmuczm
testing/marionette/driver.js
testing/marionette/harness/marionette/tests/unit/test_session.py
--- a/testing/marionette/driver.js
+++ b/testing/marionette/driver.js
@@ -201,16 +201,17 @@ GeckoDriver.prototype.switchToGlobalMess
  * @param {string} name
  *     Suffix of the targetted message listener ({@code Marionette:<suffix>}).
  * @param {Object=} msg
  *     JSON serialisable object to send to the listener.
  * @param {number=} cmdId
  *     Command ID to ensure synchronisity.
  */
 GeckoDriver.prototype.sendAsync = function(name, msg, cmdId) {
+  logger.info(`sendAsync ${this.sessionId}`)
   let curRemoteFrame = this.curBrowser.frameManager.currentRemoteFrame;
   name = "Marionette:" + name;
 
   // TODO(ato): When proxy.AsyncMessageChannel
   // is used for all chrome <-> content communication
   // this can be removed.
   if (cmdId) {
     msg.command_id = cmdId;
@@ -305,16 +306,17 @@ GeckoDriver.prototype.addBrowser = funct
  * switch focus to the start frame when it registers.
  *
  * @param {nsIDOMWindow} win
  *     Window whose browser we need to access.
  * @param {boolean=false} isNewSession
  *     True if this is the first time we're talking to this browser.
  */
 GeckoDriver.prototype.startBrowser = function(win, isNewSession=false) {
+  logger.info(`startBrowser ${this.sessionId}`)
   this.mainFrame = win;
   this.curFrame = null;
   this.addBrowser(win);
   this.curBrowser.isNewSession = isNewSession;
   this.curBrowser.startSession(isNewSession, win, this.whenBrowserStarted.bind(this));
 };
 
 /**
@@ -463,16 +465,19 @@ GeckoDriver.prototype.listeningPromise =
       resolve();
     };
     this.mm.addMessageListener(li, cb);
   });
 };
 
 /** Create a new session. */
 GeckoDriver.prototype.newSession = function*(cmd, resp) {
+  if (this.sessionId) {
+    throw new SessionNotCreatedError("Maximum number of active sessions.")
+  }
   this.sessionId = cmd.parameters.sessionId ||
       cmd.parameters.session_id ||
       element.generateUUID();
 
   this.newSessionCommandId = cmd.id;
   this.setSessionCapabilities(cmd.parameters.capabilities);
   this.scriptTimeout = 10000;
 
--- a/testing/marionette/harness/marionette/tests/unit/test_session.py
+++ b/testing/marionette/harness/marionette/tests/unit/test_session.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/.
 
 from marionette import MarionetteTestCase
+from marionette_driver.errors import SessionNotCreatedException
 
 class TestSession(MarionetteTestCase):
     def setUp(self):
         super(TestSession, self).setUp()
         self.marionette.delete_session()
 
     def test_new_session_returns_capabilities(self):
         # Sends newSession
@@ -36,8 +37,13 @@ class TestSession(MarionetteTestCase):
         self.assertTrue(isinstance(self.marionette.session_id, unicode))
 
     def test_we_can_set_the_session_id(self):
         # Sends newSession
         caps = 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):
+        self.marionette.start_session()
+        self.assertTrue(isinstance(self.marionette.session_id, unicode))
+        self.assertRaises(SessionNotCreatedException, self.marionette._send_message, "newSession", {})