зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1368567 - Remove useless main-thread IO from XUL store; r=florian
This commit is contained in:
Родитель
53b79d09c3
Коммит
1f4d6b3ef6
|
@ -65,10 +65,11 @@ XULStore.prototype = {
|
|||
this._storeFile = Services.dirsvc.get("ProfD", Ci.nsIFile);
|
||||
this._storeFile.append(STOREDB_FILENAME);
|
||||
|
||||
if (!this._storeFile.exists()) {
|
||||
this.import();
|
||||
} else {
|
||||
try {
|
||||
this.readFile();
|
||||
} catch (e) {
|
||||
// If readFile() throws, it means that the file didn't exist.
|
||||
this.import();
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -93,9 +94,6 @@ XULStore.prototype = {
|
|||
let localStoreFile = Services.dirsvc.get("ProfD", Ci.nsIFile);
|
||||
|
||||
localStoreFile.append("localstore.rdf");
|
||||
if (!localStoreFile.exists()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const RDF = Cc["@mozilla.org/rdf/rdf-service;1"].getService(Ci.nsIRDFService);
|
||||
const persistKey = RDF.GetResource("http://home.netscape.com/NC-rdf#persist");
|
||||
|
@ -153,7 +151,9 @@ XULStore.prototype = {
|
|||
this._data = json.decodeFromStream(stream, stream.available());
|
||||
} catch (e) {
|
||||
this.log("Error reading JSON: " + e);
|
||||
// Ignore problem, we'll just continue on with an empty dataset.
|
||||
if (e.result == Cr.NS_ERROR_FILE_NOT_FOUND) {
|
||||
throw e; // Let the caller handle it!
|
||||
}
|
||||
} finally {
|
||||
stream.close();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/◦
|
||||
*/
|
||||
|
||||
"use strict"
|
||||
|
||||
function checkValue(uri, id, attr, reference) {
|
||||
let value = XULStore.getValue(uri, id, attr);
|
||||
do_check_eq(value, reference);
|
||||
}
|
||||
|
||||
function checkValueExists(uri, id, attr, exists) {
|
||||
do_check_eq(XULStore.hasValue(uri, id, attr), exists);
|
||||
}
|
||||
|
||||
function getIDs(uri) {
|
||||
let it = XULStore.getIDsEnumerator(uri);
|
||||
let result = [];
|
||||
|
||||
while (it.hasMore()) {
|
||||
let value = it.getNext();
|
||||
result.push(value);
|
||||
}
|
||||
|
||||
result.sort();
|
||||
return result;
|
||||
}
|
||||
|
||||
function getAttributes(uri, id) {
|
||||
let it = XULStore.getAttributeEnumerator(uri, id);
|
||||
|
||||
let result = [];
|
||||
|
||||
while (it.hasMore()) {
|
||||
let value = it.getNext();
|
||||
result.push(value);
|
||||
}
|
||||
|
||||
result.sort();
|
||||
return result;
|
||||
}
|
||||
|
||||
function checkArrays(a, b) {
|
||||
a.sort();
|
||||
b.sort();
|
||||
do_check_true(a.toString() == b.toString());
|
||||
}
|
||||
|
|
@ -20,48 +20,6 @@ function run_test() {
|
|||
run_next_test();
|
||||
}
|
||||
|
||||
function checkValue(uri, id, attr, reference) {
|
||||
let value = XULStore.getValue(uri, id, attr);
|
||||
do_check_true(value === reference);
|
||||
}
|
||||
|
||||
function checkValueExists(uri, id, attr, exists) {
|
||||
do_check_eq(XULStore.hasValue(uri, id, attr), exists);
|
||||
}
|
||||
|
||||
function getIDs(uri) {
|
||||
let it = XULStore.getIDsEnumerator(uri);
|
||||
let result = [];
|
||||
|
||||
while (it.hasMore()) {
|
||||
let value = it.getNext();
|
||||
result.push(value);
|
||||
}
|
||||
|
||||
result.sort();
|
||||
return result;
|
||||
}
|
||||
|
||||
function getAttributes(uri, id) {
|
||||
let it = XULStore.getAttributeEnumerator(uri, id);
|
||||
|
||||
let result = [];
|
||||
|
||||
while (it.hasMore()) {
|
||||
let value = it.getNext();
|
||||
result.push(value);
|
||||
}
|
||||
|
||||
result.sort();
|
||||
return result;
|
||||
}
|
||||
|
||||
function checkArrays(a, b) {
|
||||
a.sort();
|
||||
b.sort();
|
||||
do_check_true(a.toString() == b.toString());
|
||||
}
|
||||
|
||||
function checkOldStore() {
|
||||
checkArrays(["addon-bar", "main-window", "sidebar-title"], getIDs(browserURI));
|
||||
checkArrays(["collapsed"], getAttributes(browserURI, "addon-bar"));
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/◦
|
||||
*/
|
||||
|
||||
"use strict"
|
||||
|
||||
const Cc = Components.classes;
|
||||
const Ci = Components.interfaces;
|
||||
const Cu = Components.utils;
|
||||
const Cr = Components.results;
|
||||
|
||||
Cu.import("resource://gre/modules/osfile.jsm")
|
||||
|
||||
var XULStore = null;
|
||||
var browserURI = "chrome://browser/content/browser.xul";
|
||||
var aboutURI = "about:config";
|
||||
|
||||
function run_test() {
|
||||
do_get_profile();
|
||||
run_next_test();
|
||||
}
|
||||
|
||||
function checkOldStore() {
|
||||
checkArrays([], getIDs(browserURI));
|
||||
checkArrays([], getAttributes(browserURI, "addon-bar"));
|
||||
checkArrays([],
|
||||
getAttributes(browserURI, "main-window"));
|
||||
checkArrays([], getAttributes(browserURI, "sidebar-title"));
|
||||
|
||||
checkValue(browserURI, "addon-bar", "collapsed", "");
|
||||
checkValue(browserURI, "main-window", "width", "");
|
||||
checkValue(browserURI, "main-window", "height", "");
|
||||
checkValue(browserURI, "main-window", "screenX", "");
|
||||
checkValue(browserURI, "main-window", "screenY", "");
|
||||
checkValue(browserURI, "main-window", "sizemode", "");
|
||||
checkValue(browserURI, "sidebar-title", "value", "");
|
||||
|
||||
checkArrays([], getIDs(aboutURI));
|
||||
checkArrays([], getAttributes(aboutURI, "lockCol"));
|
||||
checkArrays([], getAttributes(aboutURI, "prefCol"));
|
||||
|
||||
checkValue(aboutURI, "prefCol", "ordinal", "");
|
||||
checkValue(aboutURI, "prefCol", "sortDirection", "");
|
||||
checkValue(aboutURI, "lockCol", "ordinal", "");
|
||||
}
|
||||
|
||||
add_task(async function testImportWithoutPreExistingLocalStoreRDF() {
|
||||
XULStore = Cc["@mozilla.org/xul/xulstore;1"].getService(Ci.nsIXULStore);
|
||||
checkOldStore();
|
||||
});
|
|
@ -1,6 +1,8 @@
|
|||
[DEFAULT]
|
||||
head = head.js
|
||||
skip-if = toolkit == 'android'
|
||||
support-files =
|
||||
localstore.rdf
|
||||
|
||||
[test_XULStore.js]
|
||||
[test_XULStoreImportWithoutPreExistingLocalStoreRDF.js]
|
||||
|
|
Загрузка…
Ссылка в новой задаче