Bug 1368492 - Add assert.browsingContext for parent process. draft
authorHenrik Skupin <mail@hskupin.info>
Wed, 31 May 2017 16:44:49 +0200
changeset 591707 899936e5d638e1292ed244cd567c17e3295b685e
parent 591677 1742b1bdadd13a02df95ca690bea9cc42ff40c91
child 591708 50c4ae664e21f42fab21a48b08411679000a5f42
child 591746 154dec0dbd59b45e6333c0521a14d227e641696a
child 591983 ce10712aa26d5ba62c31d2bee7a19791a01b813b
push id63139
push userbmo:hskupin@gmail.com
push dateFri, 09 Jun 2017 13:40:23 +0000
bugs1368492
milestone55.0a1
Bug 1368492 - Add assert.browsingContext for parent process. When accessing a property of the current content browser from the parent process, the current top-level browsing context has to be valid. MozReview-Commit-ID: BZHJTk1j5Nj
testing/marionette/assert.js
testing/marionette/driver.js
testing/marionette/test_assert.js
--- a/testing/marionette/assert.js
+++ b/testing/marionette/assert.js
@@ -110,16 +110,34 @@ assert.window = function (win, msg = "")
     // If the window is no longer available a TypeError is thrown.
     } catch (e if e.name === "TypeError") {
       return null;
     }
   }, msg, NoSuchWindowError)(win);
 };
 
 /**
+ * Asserts that |context| is a valid browsing context.
+ *
+ * @param {browser.Context} context
+ *     Browsing context to test.
+ * @param {string=} msg
+ *     Custom error message.
+ *
+ * @throws {NoSuchWindowError}
+ *     If |context| is invalid.
+ */
+assert.contentBrowser = function (context, msg = "") {
+  msg = msg || "Current window does not have a content browser";
+  assert.that(c => c && c.contentBrowser,
+      msg,
+      NoSuchWindowError)(context);
+};
+
+/**
  * Asserts that there is no current user prompt.
  *
  * @param {modal.Dialog} dialog
  *     Reference to current dialogue.
  * @param {string=} msg
  *     Custom error message.
  *
  * @throws {UnexpectedAlertOpenError}
--- a/testing/marionette/driver.js
+++ b/testing/marionette/driver.js
@@ -972,22 +972,18 @@ GeckoDriver.prototype.getCurrentUrl = fu
   const win = assert.window(this.getCurrentWindow());
   assert.noUserPrompt(this.dialog);
 
   switch (this.context) {
     case Context.CHROME:
       return win.location.href;
 
     case Context.CONTENT:
-      if (this.curBrowser.contentBrowser) {
-        return this.curBrowser.contentBrowser.currentURI.spec;
-      } else {
-        throw new NoSuchWindowError(
-          "Not a browser window, or no tab currently selected");
-      }
+      assert.contentBrowser(this.curBrowser);
+      return this.curBrowser.contentBrowser.currentURI.spec;
   }
 };
 
 /**
  * Gets the current title of the window.
  *
  * @return {string}
  *     Document title of the top-level browsing context.
--- a/testing/marionette/test_assert.js
+++ b/testing/marionette/test_assert.js
@@ -113,16 +113,26 @@ add_test(function test_window() {
 
   for (let typ of [null, undefined, deadWindow]) {
     Assert.throws(() => assert.window(typ), NoSuchWindowError);
   }
 
   run_next_test();
 });
 
+add_test(function test_contentBrowser() {
+  assert.contentBrowser({contentBrowser: 42});
+
+  for (let typ of [null, undefined, {contentBrowser: null}]) {
+    Assert.throws(() => assert.contentBrowser(typ), NoSuchWindowError);
+  }
+
+  run_next_test();
+});
+
 add_test(function test_object() {
   assert.object({});
   assert.object(new Object());
   for (let typ of [42, "foo", true, null, undefined]) {
     Assert.throws(() => assert.object(typ), InvalidArgumentError);
   }
 
   run_next_test();