Bug 960931: Throw SessionNotCreatedError when requesting 2nd Active Session r=ato a=test-only
authorDavid Burns <dburns@mozilla.com>
Wed, 25 May 2016 15:04:40 +0100
changeset 333264 3d44cc6e4fb9a423472e0722b20a18053f1298c8
parent 333263 3f4ba9dccbd7d1f1a28e213985f6408adf92e498
child 333265 0bdbf947bce3d9eaecd44b1dd8e563a6c23b860e
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersato, test-only
bugs960931
milestone48.0a2
Bug 960931: Throw SessionNotCreatedError when requesting 2nd Active Session r=ato a=test-only 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
@@ -208,16 +208,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;
@@ -312,16 +313,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));
 };
 
 /**
@@ -470,16 +472,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", {})