Bug 1336124 - Add assert.session for checking if session is active. r=maja_zf, a=test-only
authorAndreas Tolfsen <ato@mozilla.com>
Thu, 02 Feb 2017 16:09:14 +0000
changeset 375961 73551688c6ac22ec1d479ef77f519fd212a90cc9
parent 375960 9b8c5ed2e94a4311c450017696923fb52021880a
child 375962 8ab5323b26bd78946c40b631953c70b2c87a2b6c
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmaja_zf, test-only
bugs1336124
milestone53.0a2
Bug 1336124 - Add assert.session for checking if session is active. r=maja_zf, a=test-only 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;