Bug 1362464 - Fix feedback from Storage Inspector's head.js methods r?pbro draft
authorMichael Ratcliffe <mratcliffe@mozilla.com>
Fri, 05 May 2017 18:00:57 +0100
changeset 573370 e20b839a253597fbc8738b25a65fe7bc36adb436
parent 573359 23fe0b76a018a5077a0f7234cff91c41e4b6af64
child 627281 b709d8e81420d53b7b62c925b479d0e672530d90
push id57368
push userbmo:mratcliffe@mozilla.com
push dateFri, 05 May 2017 17:01:52 +0000
reviewerspbro
bugs1362464
milestone55.0a1
Bug 1362464 - Fix feedback from Storage Inspector's head.js methods r?pbro MozReview-Commit-ID: G5lOr9bU13B
devtools/client/storage/test/head.js
--- a/devtools/client/storage/test/head.js
+++ b/devtools/client/storage/test/head.js
@@ -616,63 +616,84 @@ function getRowValues(id, includeHidden 
  */
 function getRowCells(id, includeHidden = false) {
   let doc = gPanelWindow.document;
   let table = gUI.table;
   let item = doc.querySelector(".table-widget-column#" + table.uniqueId +
                                " .table-widget-cell[value='" + id + "']");
 
   if (!item) {
-    ok(false, "Row id '" + id + "' exists");
-
-    showAvailableIds();
+    ok(false, `The row id '${id}' that was passed to getRowCells() does not ` +
+              `exist. ${getAvailableIds()}`);
   }
 
   let index = table.columns.get(table.uniqueId).cellNodes.indexOf(item);
   let cells = {};
 
   for (let [name, column] of [...table.columns]) {
     if (!includeHidden && column.column.parentNode.hidden) {
       continue;
     }
     cells[name] = column.cellNodes[index];
   }
 
   return cells;
 }
 
 /**
- * Show available ids.
+ * Get available ids... useful for error reporting.
  */
-function showAvailableIds() {
+function getAvailableIds() {
   let doc = gPanelWindow.document;
   let table = gUI.table;
 
-  info("Available ids:");
+  let out = "Available ids:\n";
   let cells = doc.querySelectorAll(".table-widget-column#" + table.uniqueId +
                                    " .table-widget-cell");
   for (let cell of cells) {
-    info("  - " + cell.getAttribute("value"));
+    out += `  - ${cell.getAttribute("value")}\n`;
   }
+
+  return out;
+}
+
+/**
+ * Show available ids.
+ */
+function showAvailableIds() {
+  info(getAvailableIds);
 }
 
 /**
  * Get a cell value.
  *
  * @param {String} id
  *        The uniqueId of the row.
  * @param {String} column
  *        The id of the column
  *
  * @yield {String}
  *        The cell value.
  */
 function getCellValue(id, column) {
   let row = getRowValues(id, true);
 
+  if (typeof row[column] === "undefined") {
+    let out = "";
+    for (let key in row) {
+      let value = row[key];
+
+      out += `  - ${key} = ${value}\n`;
+    }
+
+    ok(false, `The column name '${column}' that was passed to ` +
+              `getCellValue() does not exist. Current column names and row ` +
+              `values are:\n${out}`);
+  }
+
   return row[column];
 }
 
 /**
  * Edit a cell value. The cell is assumed to be in edit mode, see startCellEdit.
  *
  * @param {String} id
  *        The uniqueId of the row.