Bug 1336124 - Add assert.session for checking if session is active; r=maja_zf
authorAndreas Tolfsen <ato@mozilla.com>
Thu, 02 Feb 2017 16:09:14 +0000
changeset 340935 589a01fb47900ae737c74f6b288d3245cece847e
parent 340934 2c9ed54ef2e183336c4903c84d853dc0ff0a38ee
child 340936 c93a410adde07a4393778b1cbec7257bed7ef39e
push id36959
push useratolfsen@mozilla.com
push dateMon, 06 Feb 2017 16:56:36 +0000
treeherderautoland@c4441c1492fd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmaja_zf
bugs1336124
milestone54.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 1336124 - Add assert.session for checking if session is active; r=maja_zf MozReview-Commit-ID: CmHFag2q1V2
testing/marionette/assert.js
testing/marionette/test_assert.js
--- a/testing/marionette/assert.js
+++ b/testing/marionette/assert.js
@@ -17,16 +17,36 @@ this.EXPORTED_SYMBOLS = ["assert"];
 const isFennec = () => AppConstants.platform == "android";
 const isB2G = () => AppConstants.MOZ_B2G;
 const isFirefox = () => Services.appinfo.name == "Firefox";
 
 /** Shorthands for common assertions made in Marionette. */
 this.assert = {};
 
 /**
+ * Asserts that Marionette has a session.
+ *
+ * @param {GeckoDriver} driver
+ *     Marionette driver instance.
+ * @param {string=} msg
+ *     Custom error message.
+ *
+ * @return {string}
+ *     Session ID.
+ *
+ * @throws {InvalidSessionIdError}
+ *     If |driver| does not have a session ID.
+ */
+assert.session = function (driver, msg = "") {
+  assert.that(sessionID => sessionID,
+      msg, InvalidSessionIdError)(driver.sessionId);
+  return driver.sessionId;
+};
+
+/**
  * Asserts that the current browser is Firefox Desktop.
  *
  * @param {string=} msg
  *     Custom error message.
  *
  * @throws {UnsupportedOperationError}
  *     If current browser is not Firefox.
  */
--- a/testing/marionette/test_assert.js
+++ b/testing/marionette/test_assert.js
@@ -4,16 +4,25 @@
 
 "use strict";
 
 const {utils: Cu} = Components;
 
 Cu.import("chrome://marionette/content/assert.js");
 Cu.import("chrome://marionette/content/error.js");
 
+add_test(function test_session() {
+  assert.session({sessionId: "foo"});
+  for (let typ of [null, undefined, ""]) {
+    Assert.throws(() => assert.session({sessionId: typ}), InvalidSessionIdError);
+  }
+
+  run_next_test();
+});
+
 add_test(function test_platforms() {
   // at least one will fail
   let raised;
   for (let fn of [assert.firefox, assert.fennec, assert.b2g, assert.mobile]) {
     try {
       fn();
     } catch (e) {
       raised = e;