Bug 1381590 - Make Storage Inspector work with file:// URLs r=pbro

MozReview-Commit-ID: I8QPDaovalG

--HG--
extra : rebase_source : f8b9578a9de89282dc0f14685e24b1f84ba008c8
This commit is contained in:
Mike Ratcliffe 2018-03-12 17:37:49 +00:00
parent 7744988cce
commit cbae55792f
4 changed files with 129 additions and 4 deletions

View File

@ -8,6 +8,7 @@ support-files =
storage-cookies.html
storage-cookies-samesite.html
storage-empty-objectstores.html
storage-file-url.html
storage-idb-delete-blocked.html
storage-indexeddb-duplicate-names.html
storage-listings.html
@ -50,6 +51,7 @@ tags = usercontextid
[browser_storage_dynamic_updates_localStorage.js]
[browser_storage_dynamic_updates_sessionStorage.js]
[browser_storage_empty_objectstores.js]
[browser_storage_file_url.js]
[browser_storage_indexeddb_delete.js]
[browser_storage_indexeddb_delete_blocked.js]
[browser_storage_indexeddb_duplicate_names.js]

View File

@ -0,0 +1,64 @@
/* 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/. */
/* import-globals-from head.js */
// Test to verify that various storage types work when using file:// URLs.
"use strict";
add_task(function* () {
const TESTPAGE = "storage-file-url.html";
// We need to load TESTPAGE using a file:// path so we need to get that from
// the current test path.
const testPath = getResolvedURI(gTestPath);
let dir = getChromeDir(testPath);
// Then append TESTPAGE to the test path.
dir.append(TESTPAGE);
// Then generate a FileURI to ensure the path is valid.
const uriString = Services.io.newFileURI(dir).spec;
// Now we have a valid file:// URL pointing to TESTPAGE.
yield openTabAndSetupStorage(uriString);
// uriString points to the test inside objdir e.g.
// `/path/to/fx/objDir/_tests/testing/mochitest/browser/devtools/client/
// storage/test/storage-file-url.html`.
//
// When opened in the browser this may resolve to a different path e.g.
// `path/to/fx/repo/devtools/client/storage/test/storage-file-url.html`.
//
// The easiest way to get the actual path is to request it from the content
// process.
let browser = gBrowser.selectedBrowser;
let actualPath = yield ContentTask.spawn(browser, null, () => {
return content.document.location.href;
});
const cookiePath = actualPath.substr(0, actualPath.lastIndexOf("/") + 1)
.replace(/file:\/\//g, "");
yield checkState([
[
["cookies", actualPath],
[
getCookieId("test1", "", cookiePath),
getCookieId("test2", "", cookiePath)
]
], [
["indexedDB", actualPath, "MyDatabase (default)", "MyObjectStore"],
[12345, 54321, 67890, 98765]
], [
["localStorage", actualPath],
["test3", "test4"]
], [
["sessionStorage", actualPath],
["test5", "test6"]
]
]);
yield finishTests();
});

View File

@ -0,0 +1,59 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Storage Test</title>
<script>
function init() {
createIndexedDB();
createCookies();
createLocalStorage();
createSessionStorage();
}
function createIndexedDB() {
var open = indexedDB.open("MyDatabase", 1);
open.onupgradeneeded = function () {
var db = open.result;
var store = db.createObjectStore("MyObjectStore", {keyPath: "id"});
var index = store.createIndex("NameIndex", ["name.last", "name.first"]);
};
open.onsuccess = function () {
var db = open.result;
var tx = db.transaction("MyObjectStore", "readwrite");
var store = tx.objectStore("MyObjectStore");
var index = store.index("NameIndex");
store.put({id: 12345, name: {first: "John", last: "Doe"}, age: 42});
store.put({id: 54321, name: {first: "Ralph", last: "Wood"}, age: 38});
store.put({id: 67890, name: {first: "Bob", last: "Smith"}, age: 35});
store.put({id: 98765, name: {first: "Freddie", last: "Krueger"}, age: 40});
tx.oncomplete = function () {
db.close();
};
};
}
function createCookies() {
document.cookie = "test1=Jean Dupond";
document.cookie = "test2=dnopuD naeJ";
}
function createLocalStorage() {
localStorage.setItem("test3", "John Doe");
localStorage.setItem("test4", "eoD nhoJ");
}
function createSessionStorage() {
sessionStorage.setItem("test5", "John Smith");
sessionStorage.setItem("test6", "htimS nhoJ");
}
</script>
</head>
<body onload="init();">
<h1>IndexedDB Test</h1>
</body>
</html>

View File

@ -167,11 +167,11 @@ StorageActors.defaults = function(typeName, observationTopics) {
// data: URLs do not support storage of any type.
return null;
case "about:":
// Fallthrough.
case "chrome:":
// Fallthrough.
case "file:":
return location.protocol + location.pathname;
case "chrome:":
return location.protocol + location.pathname;
case "file:":
return `${location.protocol}//${location.pathname}`;
case "resource:":
return location.origin + location.pathname;
case "moz-extension:":