Bug 1231155 - Make localstorage entry rows editable via double-click in storage inspector r=pbro
authorMichael Ratcliffe <mratcliffe@mozilla.com>
Fri, 18 Mar 2016 17:09:52 +0000
changeset 291348 7a71674ba4dd50bfaa2795bf2f7583ccf75a964c
parent 291347 a73c2c9f6872dab1423744a4aa905a826dcd3f49
child 291349 527346010e0fabf5a754308560c276ef36e0d05c
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspbro
bugs1231155
milestone48.0a1
Bug 1231155 - Make localstorage entry rows editable via double-click in storage inspector r=pbro MozReview-Commit-ID: 9SjhR1n5AYG
devtools/client/shared/widgets/TableWidget.js
devtools/client/storage/test/browser.ini
devtools/client/storage/test/browser_storage_localstorage_edit.js
devtools/client/storage/test/storage-localstorage.html
devtools/client/storage/ui.js
devtools/server/actors/storage.js
--- a/devtools/client/shared/widgets/TableWidget.js
+++ b/devtools/client/shared/widgets/TableWidget.js
@@ -218,16 +218,17 @@ TableWidget.prototype = {
     let itemIndex = column.cellNodes.indexOf(changedField);
     let items = {};
 
     for (let [name, col] of this.columns) {
       items[name] = col.cellNodes[itemIndex].value;
     }
 
     let change = {
+      host: this.host,
       key: uniqueId,
       field: colName,
       oldValue: data.change.oldValue,
       newValue: data.change.newValue,
       items: items
     };
 
     // A rows position in the table can change as the result of an edit. In
--- a/devtools/client/storage/test/browser.ini
+++ b/devtools/client/storage/test/browser.ini
@@ -1,23 +1,25 @@
 [DEFAULT]
 tags = devtools
 subsuite = devtools
 support-files =
   storage-cookies.html
   storage-complex-values.html
   storage-listings.html
+  storage-localstorage.html
   storage-overflow.html
   storage-search.html
   storage-secured-iframe.html
   storage-unsecured-iframe.html
   storage-updates.html
   head.js
 
 [browser_storage_basic.js]
 [browser_storage_dynamic_updates.js]
 [browser_storage_cookies_edit.js]
 [browser_storage_cookies_edit_keyboard.js]
 [browser_storage_cookies_tab_navigation.js]
+[browser_storage_localstorage_edit.js]
 [browser_storage_overflow.js]
 [browser_storage_search.js]
 [browser_storage_sidebar.js]
 [browser_storage_values.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/storage/test/browser_storage_localstorage_edit.js
@@ -0,0 +1,25 @@
+/* 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/. */
+
+// Basic test to check the editing of localStorage.
+
+"use strict";
+
+add_task(function*() {
+  yield openTabAndSetupStorage(MAIN_DOMAIN + "storage-localstorage.html");
+
+  yield selectTreeItem(["localStorage", "http://test1.example.org"]);
+  yield gUI.table.once(TableWidget.EVENTS.FIELDS_EDITABLE);
+
+  yield editCell("TestLS1", "name", "newTestLS1");
+  yield editCell("newTestLS1", "value", "newValueLS1");
+
+  yield editCell("TestLS3", "name", "newTestLS3");
+  yield editCell("newTestLS3", "value", "newValueLS3");
+
+  yield editCell("TestLS5", "name", "newTestLS5");
+  yield editCell("newTestLS5", "value", "newValueLS5");
+
+  yield finishTests();
+});
new file mode 100644
--- /dev/null
+++ b/devtools/client/storage/test/storage-localstorage.html
@@ -0,0 +1,23 @@
+<!doctype html>
+<html>
+  <!--
+  Bug 1231155 - Storage inspector front end - tests
+  -->
+  <head>
+    <meta charset="utf-8" />
+    <title>Storage inspector localStorage test</title>
+    <script type="application/javascript;version=1.7">
+      "use strict";
+
+      function setup() {
+        localStorage.setItem("TestLS1", "ValueLS1");
+        localStorage.setItem("TestLS2", "ValueLS2");
+        localStorage.setItem("TestLS3", "ValueLS3");
+        localStorage.setItem("TestLS4", "ValueLS4");
+        localStorage.setItem("TestLS5", "ValueLS5");
+      }
+    </script>
+  </head>
+  <body onload="setup()">
+  </body>
+</html>
--- a/devtools/client/storage/ui.js
+++ b/devtools/client/storage/ui.js
@@ -145,17 +145,18 @@ StorageUI.prototype = {
     let type = this.table.datatype;
 
     return this.storageTypes[type];
   },
 
   makeFieldsEditable: function() {
     let actor = this.getCurrentActor();
 
-    if (typeof actor.getEditableFields !== "undefined") {
+    if (typeof actor.getEditableFields !== "undefined" &&
+        this.table.datatype !== "sessionStorage") {
       actor.getEditableFields().then(fields => {
         this.table.makeFieldsEditable(fields);
       });
     } else if (this.table._editableFieldsEngine) {
       this.table._editableFieldsEngine.destroy();
     }
   },
 
@@ -370,16 +371,17 @@ StorageUI.prototype = {
     storageType.getStoreObjects(host, names, fetchOpts).then(({data}) => {
       if (!data.length) {
         this.emit("store-objects-updated");
         return;
       }
       if (this.shouldResetColumns) {
         this.resetColumns(data[0], type);
       }
+      this.table.host = host;
       this.populateTable(data, reason);
       this.emit("store-objects-updated");
 
       this.makeFieldsEditable();
     }, Cu.reportError);
   },
 
   /**
--- a/devtools/server/actors/storage.js
+++ b/devtools/server/actors/storage.js
@@ -748,16 +748,17 @@ var cookieHelpers = {
   },
 
   /**
    * Apply the results of a cookie edit.
    *
    * @param {Object} data
    *        An object in the following format:
    *        {
+   *          host: "http://www.mozilla.org",
    *          field: "value",
    *          key: "name",
    *          oldValue: "%7BHello%7D",
    *          newValue: "%7BHelloo%7D",
    *          items: {
    *            name: "optimizelyBuckets",
    *            path: "/",
    *            host: ".mozilla.org",
@@ -1023,16 +1024,55 @@ function getObjectForLocalOrSessionStora
                                 window[type]);
         }
       } catch (ex) {
         // Exceptions happen when local or session storage is inaccessible
       }
       return null;
     },
 
+    /**
+     * This method marks the fields as editable.
+     *
+     * @return {Array}
+     *         An array of field ids.
+     */
+    getEditableFields: method(Task.async(function*() {
+      return [
+        "name",
+        "value"
+      ];
+    }), {
+      request: {},
+      response: {
+        value: RetVal("json")
+      }
+    }),
+
+    /**
+     * Edit localStorage or sessionStorage fields.
+     *
+     * @param {Object} data
+     *        See editCookie() for format details.
+     */
+    editItem: method(Task.async(function*({host, field, oldValue, items}) {
+      let storage = this.hostVsStores.get(host);
+
+      if (field === "name") {
+        storage.removeItem(oldValue);
+      }
+
+      storage.setItem(items.name, items.value);
+    }), {
+      request: {
+        data: Arg(0, "json"),
+      },
+      response: {}
+    }),
+
     observe: function(subject, topic, data) {
       if (topic != "dom-storage2-changed" || data != type) {
         return null;
       }
 
       let host = this.getSchemaAndHost(subject.url);
 
       if (!this.hostVsStores.has(host)) {