Bug 1592643 - [remote] Methods in Target domain have to raise for invalid "targetId" argument. r=remote-protocol-reviewers,ato
authorHenrik Skupin <mail@hskupin.info>
Thu, 07 Nov 2019 14:46:58 +0000
changeset 501127 1948116910ec6f3681010fd9e183f8f08982f076
parent 501126 923df8ec570ab7e97ed903b5570508e59b11c12b
child 501128 f2ade55c9d2c80d4cde6156b929d13c4c37e1bb4
push id114168
push userdluca@mozilla.com
push dateSun, 10 Nov 2019 03:08:55 +0000
treeherdermozilla-inbound@33f64c1ef3e4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersremote-protocol-reviewers, ato
bugs1592643
milestone72.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 1592643 - [remote] Methods in Target domain have to raise for invalid "targetId" argument. r=remote-protocol-reviewers,ato Differential Revision: https://phabricator.services.mozilla.com/D51999
remote/domains/parent/Target.jsm
remote/test/browser/target/browser_attachToTarget.js
remote/test/browser/target/browser_closeTarget.js
--- a/remote/domains/parent/Target.jsm
+++ b/remote/domains/parent/Target.jsm
@@ -90,24 +90,30 @@ class Target extends Domain {
       );
     }
     return { targetId: target.id };
   }
 
   closeTarget({ targetId }) {
     const { targets } = this.session.target;
     const target = targets.getById(targetId);
+
+    if (!target) {
+      throw new Error(`Unable to find target with id '${targetId}'`);
+    }
+
     TabManager.removeTab(target.tab);
   }
 
   attachToTarget({ targetId }) {
     const { targets } = this.session.target;
     const target = targets.getById(targetId);
+
     if (!target) {
-      return new Error(`Unable to find target with id '${targetId}'`);
+      throw new Error(`Unable to find target with id '${targetId}'`);
     }
 
     const tabSession = new TabSession(
       this.session.connection,
       target,
       sessionIds++
     );
     this.session.connection.registerSession(tabSession);
--- a/remote/test/browser/target/browser_attachToTarget.js
+++ b/remote/test/browser/target/browser_attachToTarget.js
@@ -1,13 +1,37 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
+add_task(async function raisesWithoutArguments({ Target }, _, tab) {
+  await getDiscoveredTargets(Target);
+
+  let errorThrown = false;
+  try {
+    await Target.attachToTarget();
+  } catch (e) {
+    errorThrown = true;
+  }
+  ok(errorThrown, "attachToTarget raised error without an argument");
+});
+
+add_task(async function raisesWithUnknownTargetId({ Target }, _, tab) {
+  await getDiscoveredTargets(Target);
+
+  let errorThrown = false;
+  try {
+    await Target.attachToTarget({ targetId: "-1" });
+  } catch (e) {
+    errorThrown = true;
+  }
+  ok(errorThrown, "attachToTarget raised error with unkown target id");
+});
+
 add_task(
   async function attachPageTarget({ Target }) {
     await getDiscoveredTargets(Target);
 
     const { targetInfo } = await openTab(Target);
 
     info("Attach new target");
     const { sessionId } = await Target.attachToTarget({
--- a/remote/test/browser/target/browser_closeTarget.js
+++ b/remote/test/browser/target/browser_closeTarget.js
@@ -1,13 +1,37 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
+add_task(async function raisesWithoutArguments({ Target }, _, tab) {
+  await getDiscoveredTargets(Target);
+
+  let exceptionThrown = false;
+  try {
+    await Target.closeTarget();
+  } catch (e) {
+    exceptionThrown = true;
+  }
+  ok(exceptionThrown, "closeTarget raised error without an argument");
+});
+
+add_task(async function raisesWithUnknownTargetId({ Target }, _, tab) {
+  await getDiscoveredTargets(Target);
+
+  let exceptionThrown = false;
+  try {
+    await Target.closeTarget({ targetId: "-1" });
+  } catch (e) {
+    exceptionThrown = true;
+  }
+  ok(exceptionThrown, "closeTarget raised error with unkown target id");
+});
+
 add_task(async function triggersTargetDestroyed({ Target }, _, tab) {
   await getDiscoveredTargets(Target);
   const { targetInfo, newTab } = await openTab(Target);
 
   const tabClosed = BrowserTestUtils.waitForEvent(newTab, "TabClose");
   const targetDestroyed = Target.targetDestroyed();
 
   info("Closing the target");