mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 22:32:46 +00:00
Backed out changeset eb4233025be0 for xpcshell test failures
This commit is contained in:
parent
68c641d2fd
commit
4bf8f57ddf
@ -88,11 +88,8 @@ WBORecord.prototype = {
|
||||
// Take a base URI string, with trailing slash, and return the URI of this
|
||||
// WBO based on collection and ID.
|
||||
uri: function(base) {
|
||||
if (this.collection && this.id) {
|
||||
let url = Utils.makeURI(base + this.collection + "/" + this.id);
|
||||
url.QueryInterface(Ci.nsIURL);
|
||||
return url;
|
||||
}
|
||||
if (this.collection && this.id)
|
||||
return Utils.makeURL(base + this.collection + "/" + this.id);
|
||||
return null;
|
||||
},
|
||||
|
||||
|
@ -207,6 +207,28 @@ let Utils = {
|
||||
return !!guid && this._base64url_regex.test(guid);
|
||||
},
|
||||
|
||||
ensureOneOpen: let (windows = {}) function ensureOneOpen(window) {
|
||||
// Close the other window if it exists
|
||||
let url = window.location.href;
|
||||
let other = windows[url];
|
||||
if (other != null)
|
||||
other.close();
|
||||
|
||||
// Save the new window for future closure
|
||||
windows[url] = window;
|
||||
|
||||
// Actively clean up when the window is closed
|
||||
window.addEventListener("unload", function() windows[url] = null, false);
|
||||
},
|
||||
|
||||
// Returns a nsILocalFile representing a file relative to the current
|
||||
// user's profile directory. The argument should be a string with
|
||||
// unix-style slashes for directory names (these slashes are automatically
|
||||
// converted to platform-specific path separators).
|
||||
getProfileFile: function getProfileFile(path) {
|
||||
return FileUtils.getFile("ProfD", path.split("/"), true);
|
||||
},
|
||||
|
||||
/**
|
||||
* Add a simple getter/setter to an object that defers access of a property
|
||||
* to an inner property.
|
||||
@ -270,46 +292,70 @@ let Utils = {
|
||||
return true;
|
||||
},
|
||||
|
||||
deepCopy: function Weave_deepCopy(thing, noSort) {
|
||||
if (typeof(thing) != "object" || thing == null)
|
||||
return thing;
|
||||
let ret;
|
||||
|
||||
if (Array.isArray(thing)) {
|
||||
ret = [];
|
||||
for (let i = 0; i < thing.length; i++)
|
||||
ret.push(Utils.deepCopy(thing[i], noSort));
|
||||
|
||||
} else {
|
||||
ret = {};
|
||||
let props = [p for (p in thing)];
|
||||
if (!noSort)
|
||||
props = props.sort();
|
||||
props.forEach(function(k) ret[k] = Utils.deepCopy(thing[k], noSort));
|
||||
}
|
||||
|
||||
return ret;
|
||||
},
|
||||
|
||||
// Works on frames or exceptions, munges file:// URIs to shorten the paths
|
||||
// FIXME: filename munging is sort of hackish, might be confusing if
|
||||
// there are multiple extensions with similar filenames
|
||||
formatFrame: function Utils_formatFrame(frame) {
|
||||
let tmp = "<file:unknown>";
|
||||
|
||||
let file = frame.filename || frame.fileName;
|
||||
if (file)
|
||||
tmp = file.replace(/^(?:chrome|file):.*?([^\/\.]+\.\w+)$/, "$1");
|
||||
|
||||
if (frame.lineNumber)
|
||||
tmp += ":" + frame.lineNumber;
|
||||
if (frame.name)
|
||||
tmp = frame.name + "()@" + tmp;
|
||||
|
||||
return tmp;
|
||||
},
|
||||
|
||||
exceptionStr: function Weave_exceptionStr(e) {
|
||||
let message = e.message ? e.message : e;
|
||||
return message + " " + Utils.stackTrace(e);
|
||||
},
|
||||
|
||||
|
||||
stackTraceFromFrame: function Weave_stackTraceFromFrame(frame) {
|
||||
let output = [];
|
||||
while (frame) {
|
||||
let str = Utils.formatFrame(frame);
|
||||
if (str)
|
||||
output.push(str);
|
||||
frame = frame.caller;
|
||||
}
|
||||
return output.join(" < ");
|
||||
},
|
||||
|
||||
stackTrace: function Weave_stackTrace(e) {
|
||||
// Wrapped nsIException
|
||||
if (e.location){
|
||||
let frame = e.location;
|
||||
let output = [];
|
||||
while (frame) {
|
||||
// Works on frames or exceptions, munges file:// URIs to shorten the paths
|
||||
// FIXME: filename munging is sort of hackish, might be confusing if
|
||||
// there are multiple extensions with similar filenames
|
||||
let str = "<file:unknown>";
|
||||
if (e.location)
|
||||
return "Stack trace: " + Utils.stackTraceFromFrame(e.location);
|
||||
|
||||
let file = frame.filename || frame.fileName;
|
||||
if (file){
|
||||
str = file.replace(/^(?:chrome|file):.*?([^\/\.]+\.\w+)$/, "$1");
|
||||
}
|
||||
|
||||
if (frame.lineNumber){
|
||||
str += ":" + frame.lineNumber;
|
||||
}
|
||||
if (frame.name){
|
||||
str = frame.name + "()@" + str;
|
||||
}
|
||||
|
||||
if (str){
|
||||
output.push(str);
|
||||
}
|
||||
frame = frame.caller;
|
||||
}
|
||||
return "Stack trace: " + output.join(" < ");
|
||||
}
|
||||
// Standard JS exception
|
||||
if (e.stack){
|
||||
if (e.stack)
|
||||
return "JS Stack trace: " + e.stack.trim().replace(/\n/g, " < ").
|
||||
replace(/@[^@]*?([^\/\.]+\.\w+:)/g, "@$1");
|
||||
}
|
||||
|
||||
return "No traceback available";
|
||||
},
|
||||
@ -845,6 +891,12 @@ let Utils = {
|
||||
}
|
||||
},
|
||||
|
||||
makeURL: function Weave_makeURL(URIString) {
|
||||
let url = Utils.makeURI(URIString);
|
||||
url.QueryInterface(Ci.nsIURL);
|
||||
return url;
|
||||
},
|
||||
|
||||
/**
|
||||
* Load a json object from disk
|
||||
*
|
||||
@ -860,7 +912,7 @@ let Utils = {
|
||||
if (that._log)
|
||||
that._log.trace("Loading json from disk: " + filePath);
|
||||
|
||||
let file = FileUtils.getFile("ProfD", filePath.split("/"), true);
|
||||
let file = Utils.getProfileFile(filePath);
|
||||
if (!file.exists()) {
|
||||
callback.call(that);
|
||||
return;
|
||||
@ -905,7 +957,7 @@ let Utils = {
|
||||
if (that._log)
|
||||
that._log.trace("Saving json to disk: " + filePath);
|
||||
|
||||
let file = FileUtils.getFile("ProfD", filePath.split("/"), true);
|
||||
let file = Utils.getProfileFile(filePath);
|
||||
let json = typeof obj == "function" ? obj.call(that) : obj;
|
||||
let out = JSON.stringify(json);
|
||||
|
||||
|
@ -456,26 +456,3 @@ RotaryEngine.prototype = {
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
deepCopy: function deepCopy(thing, noSort) {
|
||||
if (typeof(thing) != "object" || thing == null){
|
||||
return thing;
|
||||
}
|
||||
let ret;
|
||||
|
||||
if (Array.isArray(thing)) {
|
||||
ret = [];
|
||||
for (let i = 0; i < thing.length; i++){
|
||||
ret.push(deepCopy(thing[i], noSort));
|
||||
}
|
||||
} else {
|
||||
ret = {};
|
||||
let props = [p for (p in thing)];
|
||||
if (!noSort){
|
||||
props = props.sort();
|
||||
}
|
||||
props.forEach(function(k) ret[k] = deepCopy(thing[k], noSort));
|
||||
}
|
||||
|
||||
return ret;
|
||||
};
|
@ -56,7 +56,7 @@ store.wipe();
|
||||
function makeLivemark(p, mintGUID) {
|
||||
let b = new Livemark("bookmarks", p.id);
|
||||
// Copy here, because tests mutate the contents.
|
||||
b.cleartext = deepCopy(p);
|
||||
b.cleartext = Utils.deepCopy(p);
|
||||
|
||||
if (mintGUID)
|
||||
b.id = Utils.makeGUID();
|
||||
|
@ -495,10 +495,8 @@ function run_test() {
|
||||
|
||||
let query = "?" + args.join("&");
|
||||
|
||||
let uri1 = Utils.makeURI("http://foo/" + query)
|
||||
.QueryInterface(Ci.nsIURL);
|
||||
let uri2 = Utils.makeURI("http://foo/")
|
||||
.QueryInterface(Ci.nsIURL);
|
||||
let uri1 = Utils.makeURL("http://foo/" + query);
|
||||
let uri2 = Utils.makeURL("http://foo/");
|
||||
uri2.query = query;
|
||||
do_check_eq(uri1.query, uri2.query);
|
||||
server.stop(do_test_finished);
|
||||
|
@ -661,10 +661,8 @@ add_test(function test_uri_construction() {
|
||||
|
||||
let query = "?" + args.join("&");
|
||||
|
||||
let uri1 = Utils.makeURI("http://foo/" + query)
|
||||
.QueryInterface(Ci.nsIURL);
|
||||
let uri2 = Utils.makeURI("http://foo/")
|
||||
.QueryInterface(Ci.nsIURL);
|
||||
let uri1 = Utils.makeURL("http://foo/" + query);
|
||||
let uri2 = Utils.makeURL("http://foo/");
|
||||
uri2.query = query;
|
||||
do_check_eq(uri1.query, uri2.query);
|
||||
|
||||
|
@ -80,7 +80,7 @@ function fakeSessionSvc(url, numtabs) {
|
||||
if (numtabs) {
|
||||
let tabs = obj.windows[0].tabs;
|
||||
for (let i = 0; i < numtabs-1; i++)
|
||||
tabs.push(deepCopy(tabs[0]));
|
||||
tabs.push(Utils.deepCopy(tabs[0]));
|
||||
}
|
||||
return JSON.stringify(obj);
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ Cu.import("resource://services-sync/util.js");
|
||||
|
||||
function run_test() {
|
||||
let thing = {o: {foo: "foo", bar: ["bar"]}, a: ["foo", {bar: "bar"}]};
|
||||
let ret = deepCopy(thing);
|
||||
let ret = Utils.deepCopy(thing);
|
||||
do_check_neq(ret, thing)
|
||||
do_check_neq(ret.o, thing.o);
|
||||
do_check_neq(ret.o.bar, thing.o.bar);
|
||||
|
@ -69,8 +69,7 @@ add_test(function test_load_logging() {
|
||||
_("Verify that reads and read errors are logged.");
|
||||
|
||||
// Write a file with some invalid JSON
|
||||
let filePath = "weave/log.json";
|
||||
let file = FileUtils.getFile("ProfD", filePath.split("/"), true);
|
||||
let file = Utils.getProfileFile("weave/log.json");
|
||||
let fos = Cc["@mozilla.org/network/file-output-stream;1"]
|
||||
.createInstance(Ci.nsIFileOutputStream);
|
||||
let flags = FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE
|
||||
|
@ -65,3 +65,35 @@ function _test_makeURI() {
|
||||
do_check_eq(Utils.makeURI("chrome://badstuff"), undefined);
|
||||
do_check_eq(Utils.makeURI("this is a test"), undefined);
|
||||
}
|
||||
|
||||
function _test_makeURL() {
|
||||
_("Check http uri");
|
||||
let uri = "http://mozillalabs.com/";
|
||||
do_check_true(Utils.makeURL(uri) instanceof Ci.nsIURL);
|
||||
|
||||
_("Check https uri");
|
||||
let uris = "https://mozillalabs.com/";
|
||||
do_check_true(Utils.makeURL(uris) instanceof Ci.nsIURL);
|
||||
|
||||
let uric = "chrome://browser/content/browser.xul";
|
||||
do_check_true(Utils.makeURL(uric) instanceof Ci.nsIURL);
|
||||
|
||||
_("Check about uri");
|
||||
let uria = "about:weave";
|
||||
let except1;
|
||||
try {
|
||||
Utils.makeURL(uria);
|
||||
} catch(e) {
|
||||
except1 = e;
|
||||
}
|
||||
do_check_true(!!except1);
|
||||
|
||||
_("Check invalid uri");
|
||||
let except2;
|
||||
try {
|
||||
Utils.makeURL("mozillalabs.com");
|
||||
} catch(e) {
|
||||
except2 = e;
|
||||
}
|
||||
do_check_true(!!except2);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user