Bug 1441228 - Correct error returned for invalid input to capture.highlight_. r?maja_zf draft
authorAndreas Tolfsen <ato@sny.no>
Mon, 26 Feb 2018 17:42:56 +0000
changeset 759836 218d283e41ff0d9909867b57e35f63f4df68c87c
parent 759830 6d72eade26af359ffc3cd3e381fd79c88922b9b8
push id100482
push userbmo:ato@sny.no
push dateMon, 26 Feb 2018 17:44:11 +0000
reviewersmaja_zf
bugs1441228
milestone60.0a1
Bug 1441228 - Correct error returned for invalid input to capture.highlight_. r?maja_zf The WebDriver:TakeScreenshot command should return an invalid argument error when the input is malformed. MozReview-Commit-ID: HZFkq6QkWze
testing/marionette/capture.js
--- a/testing/marionette/capture.js
+++ b/testing/marionette/capture.js
@@ -1,14 +1,16 @@
 /* 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/. */
 
 "use strict";
 
+const {InvalidArgumentError} = ChromeUtils.import("chrome://marionette/content/error.js", {});
+
 Cu.importGlobalProperties(["crypto"]);
 
 this.EXPORTED_SYMBOLS = ["capture"];
 
 const CONTEXT_2D = "2d";
 const BG_COLOUR = "rgb(255,255,255)";
 const PNG_MIME = "image/png";
 const XHTML_NS = "http://www.w3.org/1999/xhtml";
@@ -135,18 +137,18 @@ capture.canvas = function(win, left, top
   if (highlights.length) {
     ctx = capture.highlight_(ctx, highlights, top, left);
   }
 
   return canvas;
 };
 
 capture.highlight_ = function(context, highlights, top = 0, left = 0) {
-  if (!highlights) {
-    throw new TypeError("Missing highlights");
+  if (typeof highlights == "undefined") {
+    throw new InvalidArgumentError("Missing highlights");
   }
 
   context.lineWidth = "2";
   context.strokeStyle = "red";
   context.save();
 
   for (let el of highlights) {
     let rect = el.getBoundingClientRect();