Bug 1363006 - Make it possible to add local and session storage entries to the storage inspector r=pbro
authorMichael Ratcliffe <mratcliffe@mozilla.com>
Mon, 08 May 2017 17:30:15 +0100
changeset 358527 819be40d930472ffccdcb4669c1207bcc1942e9c
parent 358526 fb7c67e56a8ea21227e64c92d54b2412c7f80e75
child 358528 69cc2c002805ca1f7ad7f3fe377a23ab1c6deb97
push id90352
push usercbook@mozilla.com
push dateTue, 16 May 2017 13:09:14 +0000
treeherdermozilla-inbound@8f89d291e303 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspbro
bugs1363006
milestone55.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 1363006 - Make it possible to add local and session storage entries to the storage inspector r=pbro MozReview-Commit-ID: IhXPD4C8HZO
devtools/client/storage/test/browser.ini
devtools/client/storage/test/browser_storage_localstorage_add.js
devtools/client/storage/test/browser_storage_sessionstorage_add.js
devtools/client/storage/test/head.js
devtools/client/storage/ui.js
devtools/server/actors/storage.js
devtools/shared/specs/storage.js
--- a/devtools/client/storage/test/browser.ini
+++ b/devtools/client/storage/test/browser.ini
@@ -44,18 +44,20 @@ tags = usercontextid
 [browser_storage_dom_cache_disabled.js]
 [browser_storage_dynamic_updates_cookies.js]
 [browser_storage_dynamic_updates_localStorage.js]
 [browser_storage_dynamic_updates_sessionStorage.js]
 [browser_storage_empty_objectstores.js]
 [browser_storage_indexeddb_delete.js]
 [browser_storage_indexeddb_delete_blocked.js]
 [browser_storage_indexeddb_duplicate_names.js]
+[browser_storage_localstorage_add.js]
 [browser_storage_localstorage_edit.js]
 [browser_storage_localstorage_error.js]
 [browser_storage_overflow.js]
 [browser_storage_search.js]
 [browser_storage_search_keyboard_trap.js]
+[browser_storage_sessionstorage_add.js]
 [browser_storage_sessionstorage_edit.js]
 [browser_storage_sidebar.js]
 [browser_storage_sidebar_toggle.js]
 [browser_storage_sidebar_update.js]
 [browser_storage_values.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/storage/test/browser_storage_localstorage_add.js
@@ -0,0 +1,20 @@
+/* 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 adding of localStorage entries.
+
+"use strict";
+
+add_task(function* () {
+  yield openTabAndSetupStorage(MAIN_DOMAIN + "storage-localstorage.html");
+  showAllColumns(true);
+
+  yield performAdd(["localStorage", "http://test1.example.org"]);
+  yield performAdd(["localStorage", "http://test1.example.org"]);
+  yield performAdd(["localStorage", "http://test1.example.org"]);
+  yield performAdd(["localStorage", "http://test1.example.org"]);
+  yield performAdd(["localStorage", "http://test1.example.org"]);
+
+  yield finishTests();
+});
new file mode 100644
--- /dev/null
+++ b/devtools/client/storage/test/browser_storage_sessionstorage_add.js
@@ -0,0 +1,20 @@
+/* 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 adding of sessionStorage entries.
+
+"use strict";
+
+add_task(function* () {
+  yield openTabAndSetupStorage(MAIN_DOMAIN + "storage-sessionstorage.html");
+  showAllColumns(true);
+
+  yield performAdd(["sessionStorage", "http://test1.example.org"]);
+  yield performAdd(["sessionStorage", "http://test1.example.org"]);
+  yield performAdd(["sessionStorage", "http://test1.example.org"]);
+  yield performAdd(["sessionStorage", "http://test1.example.org"]);
+  yield performAdd(["sessionStorage", "http://test1.example.org"]);
+
+  yield finishTests();
+});
--- a/devtools/client/storage/test/head.js
+++ b/devtools/client/storage/test/head.js
@@ -966,18 +966,19 @@ function sidebarToggleVisible() {
 
 /**
  * Add an item.
  * @param  {Array} store
  *         An array containing the path to the store to which we wish to add an
  *         item.
  */
 function* performAdd(store) {
+  let storeName = store.join(" > ");
   let toolbar = gPanelWindow.document.getElementById("storage-toolbar");
-  let storeName = store.join(" > ");
+  let type = store[0];
 
   yield selectTreeItem(store);
 
   let menuAdd = toolbar.querySelector(
     "#add-button");
 
   if (menuAdd.hidden) {
     is(menuAdd.hidden, false,
@@ -988,12 +989,13 @@ function* performAdd(store) {
   let eventEdit = gUI.table.once("row-edit");
   let eventWait = gUI.once("store-objects-updated");
 
   menuAdd.click();
 
   let rowId = yield eventEdit;
   yield eventWait;
 
-  let value = getCellValue(rowId, "uniqueKey");
+  let key = type === "cookies" ? "uniqueKey" : "name";
+  let value = getCellValue(rowId, key);
 
   is(rowId, value, `Row '${rowId}' was successfully added.`);
 }
--- a/devtools/client/storage/ui.js
+++ b/devtools/client/storage/ui.js
@@ -1122,21 +1122,22 @@ StorageUI.prototype = {
     }
   },
 
   /**
    * Handles adding an item from the storage
    */
   onAddItem: function () {
     let front = this.getCurrentFront();
+    let [, host] = this.tree.selectedItem;
 
     // Prepare to scroll into view.
     this.table.scrollIntoViewOnUpdate = true;
     this.table.editBookmark = createGUID();
-    front.addItem(this.table.editBookmark);
+    front.addItem(this.table.editBookmark, host);
   },
 
   /**
    * Handles removing an item from the storage
    */
   onRemoveItem: function () {
     let [, host, ...path] = this.tree.selectedItem;
     let front = this.getCurrentFront();
--- a/devtools/server/actors/storage.js
+++ b/devtools/server/actors/storage.js
@@ -10,16 +10,18 @@ const protocol = require("devtools/share
 const {LongStringActor} = require("devtools/server/actors/string");
 const {DebuggerServer} = require("devtools/server/main");
 const Services = require("Services");
 const promise = require("promise");
 const {isWindowIncluded} = require("devtools/shared/layout/utils");
 const specs = require("devtools/shared/specs/storage");
 const { Task } = require("devtools/shared/task");
 
+const DEFAULT_VALUE = "value";
+
 loader.lazyRequireGetter(this, "naturalSortCaseInsensitive",
   "devtools/client/shared/natural-sort", true);
 
 // GUID to be used as a separator in compound keys. This must match the same
 // constant in devtools/client/storage/ui.js,
 // devtools/client/storage/test/head.js and
 // devtools/server/tests/browser/head.js
 const SEPARATOR_GUID = "{9d414cc5-8319-0a04-0586-c0a6ae01670a}";
@@ -668,17 +670,17 @@ StorageActors.createActor({
     this.editCookie(data);
   }),
 
   addItem: Task.async(function* (guid) {
     let doc = this.storageActor.document;
     let time = new Date().getTime();
     let expiry = new Date(time + 3600 * 24 * 1000).toGMTString();
 
-    doc.cookie = `${guid}=value;expires=${expiry}`;
+    doc.cookie = `${guid}=${DEFAULT_VALUE};expires=${expiry}`;
   }),
 
   removeItem: Task.async(function* (host, name) {
     let doc = this.storageActor.document;
     this.removeCookie(host, name, doc.nodePrincipal
                                      .originAttributes);
   }),
 
@@ -1131,16 +1133,24 @@ function getObjectForLocalOrSessionStora
 
     getFields: Task.async(function* () {
       return [
         { name: "name", editable: true },
         { name: "value", editable: true }
       ];
     }),
 
+    addItem: Task.async(function* (guid, host) {
+      let storage = this.hostVsStores.get(host);
+      if (!storage) {
+        return;
+      }
+      storage.setItem(guid, DEFAULT_VALUE);
+    }),
+
     /**
      * Edit localStorage or sessionStorage fields.
      *
      * @param {Object} data
      *        See editCookie() for format details.
      */
     editItem: Task.async(function* ({host, field, oldValue, items}) {
       let storage = this.hostVsStores.get(host);
--- a/devtools/shared/specs/storage.js
+++ b/devtools/shared/specs/storage.js
@@ -113,16 +113,25 @@ types.addDictType("storageobject", {
   name: "string",
   value: "longstring"
 });
 
 // Common methods for local/session storage
 const storageMethods = Object.assign({},
   editRemoveMethods,
   {
+    addItem: {
+      request: {
+        guid: Arg(0, "string"),
+        host: Arg(1, "nullable:string")
+      },
+      response: {}
+    }
+  },
+  {
     removeAll: {
       request: {
         host: Arg(0, "string")
       },
       response: {}
     }
   }
 );