Bug 1283800 - Storage inspector throws unhandled exception trying to access localStorage on about:home r=mratcliffe

MozReview-Commit-ID: D5EVRMk8zEG
This commit is contained in:
Jarda Snajdr 2016-07-01 06:26:00 +02:00
parent ffcc65db73
commit 1071446650
4 changed files with 55 additions and 21 deletions

View File

@ -33,6 +33,7 @@ support-files =
[browser_storage_indexeddb_delete.js]
[browser_storage_indexeddb_delete_blocked.js]
[browser_storage_localstorage_edit.js]
[browser_storage_localstorage_error.js]
[browser_storage_overflow.js]
[browser_storage_search.js]
[browser_storage_sessionstorage_edit.js]

View File

@ -0,0 +1,24 @@
/* 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";
// Test that for pages where local/sessionStorage is not available (like about:home),
// the host still appears in the storage tree and no unhandled exception is thrown.
add_task(function* () {
yield openTabAndSetupStorage("about:home");
let itemsToOpen = [
["localStorage", "about:home"],
["sessionStorage", "about:home"]
];
for (let item of itemsToOpen) {
yield selectTreeItem(item);
ok(gUI.tree.isSelected(item), `Item ${item.join(" > ")} is present in the tree`);
}
yield finishTests();
});

View File

@ -213,8 +213,13 @@ function* finishTests() {
let windows = getAllWindows(content);
for (let win of windows) {
win.localStorage.clear();
win.sessionStorage.clear();
// Some windows (e.g., about: URLs) don't have storage available
try {
win.localStorage.clear();
win.sessionStorage.clear();
} catch (ex) {
// ignore
}
if (win.clear) {
yield win.clear();

View File

@ -968,7 +968,7 @@ function getObjectForLocalOrSessionStorage(type) {
return {
getNamesForHost(host) {
let storage = this.hostVsStores.get(host);
return Object.keys(storage);
return storage ? Object.keys(storage) : [];
},
getValuesForHost(host, name) {
@ -977,14 +977,16 @@ function getObjectForLocalOrSessionStorage(type) {
return [];
}
if (name) {
return [{name: name, value: storage.getItem(name)}];
let value = storage ? storage.getItem(name) : null;
return [{ name, value }];
}
return Object.keys(storage).map(key => {
return {
name: key,
value: storage.getItem(key)
};
});
if (!storage) {
return [];
}
return Object.keys(storage).map(key => ({
name: key,
value: storage.getItem(key)
}));
},
getHostName(location) {
@ -998,22 +1000,15 @@ function getObjectForLocalOrSessionStorage(type) {
try {
this.hostVsStores.set(host, window[type]);
} catch (ex) {
// Exceptions happen when local or session storage is inaccessible
console.warn(`Failed to enumerate ${type} for host ${host}: ${ex}`);
}
return null;
},
populateStoresForHosts() {
this.hostVsStores = new Map();
try {
for (let window of this.windows) {
this.hostVsStores.set(this.getHostName(window.location),
window[type]);
}
} catch (ex) {
// Exceptions happen when local or session storage is inaccessible
for (let window of this.windows) {
this.populateStoresForHost(this.getHostName(window.location), window);
}
return null;
},
/**
@ -1037,6 +1032,9 @@ function getObjectForLocalOrSessionStorage(type) {
*/
editItem: Task.async(function* ({host, field, oldValue, items}) {
let storage = this.hostVsStores.get(host);
if (!storage) {
return;
}
if (field === "name") {
storage.removeItem(oldValue);
@ -1047,11 +1045,17 @@ function getObjectForLocalOrSessionStorage(type) {
removeItem: Task.async(function* (host, name) {
let storage = this.hostVsStores.get(host);
if (!storage) {
return;
}
storage.removeItem(name);
}),
removeAll: Task.async(function* (host) {
let storage = this.hostVsStores.get(host);
if (!storage) {
return;
}
storage.clear();
}),
@ -1209,7 +1213,7 @@ StorageActors.createActor({
storeMap.set(name, (yield caches.open(name)));
}
} catch (ex) {
console.error(`Failed to enumerate CacheStorage for host ${host}:`, ex);
console.warn(`Failed to enumerate CacheStorage for host ${host}: ${ex}`);
}
this.hostVsStores.set(host, storeMap);
}),