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
--- 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", {})