mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1219073 - part 1 - Add to sdk/url#URL objects. r=gozala
This commit is contained in:
parent
4159ed0d2a
commit
ba3fbe3c69
@ -126,6 +126,15 @@ function URL(url, base) {
|
||||
}
|
||||
}
|
||||
|
||||
let fileName = "/";
|
||||
try {
|
||||
fileName = uri.QueryInterface(Ci.nsIURL).fileName;
|
||||
} catch (e) {
|
||||
if (e.result != Cr.NS_NOINTERFACE) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
let uriData = [uri.path, uri.path.length, {}, {}, {}, {}, {}, {}];
|
||||
URLParser.parsePath.apply(URLParser, uriData);
|
||||
let [{ value: filepathPos }, { value: filepathLen },
|
||||
@ -137,6 +146,7 @@ function URL(url, base) {
|
||||
let search = uri.path.substr(queryPos, queryLen);
|
||||
search = search ? "?" + search : "";
|
||||
|
||||
this.__defineGetter__("fileName", () => fileName);
|
||||
this.__defineGetter__("scheme", () => uri.scheme);
|
||||
this.__defineGetter__("userPass", () => userPass);
|
||||
this.__defineGetter__("host", () => host);
|
||||
|
@ -20,8 +20,6 @@ const { decode } = require('sdk/base64');
|
||||
const httpd = require('./lib/httpd');
|
||||
const port = 8099;
|
||||
|
||||
const defaultLocation = '{\'scheme\':\'about\',\'userPass\':null,\'host\':null,\'hostname\':null,\'port\':null,\'path\':\'addons\',\'pathname\':\'addons\',\'hash\':\'\',\'href\':\'about:addons\',\'origin\':\'about:\',\'protocol\':\'about:\',\'search\':\'\'}'.replace(/'/g, '"');
|
||||
|
||||
exports.testResolve = function(assert) {
|
||||
assert.equal(URL('bar', 'http://www.foo.com/').toString(),
|
||||
'http://www.foo.com/bar');
|
||||
@ -65,6 +63,7 @@ exports.testParseHttp = function(assert) {
|
||||
assert.equal(info.href, aUrl);
|
||||
assert.equal(info.hash, '#myhash');
|
||||
assert.equal(info.search, '?locale=en-US&otherArg=%20x%20');
|
||||
assert.equal(info.fileName, 'bar');
|
||||
};
|
||||
|
||||
exports.testParseHttpSearchAndHash = function (assert) {
|
||||
@ -109,6 +108,7 @@ exports.testParseChrome = function(assert) {
|
||||
assert.equal(info.port, null);
|
||||
assert.equal(info.userPass, null);
|
||||
assert.equal(info.path, '/content/blah');
|
||||
assert.equal(info.fileName, 'blah');
|
||||
};
|
||||
|
||||
exports.testParseAbout = function(assert) {
|
||||
@ -127,6 +127,7 @@ exports.testParseFTP = function(assert) {
|
||||
assert.equal(info.port, null);
|
||||
assert.equal(info.userPass, null);
|
||||
assert.equal(info.path, '/foo');
|
||||
assert.equal(info.fileName, 'foo');
|
||||
};
|
||||
|
||||
exports.testParseFTPWithUserPass = function(assert) {
|
||||
@ -216,7 +217,7 @@ exports.testStringInterface = function(assert) {
|
||||
|
||||
// make sure the standard URL properties are enumerable and not the String interface bits
|
||||
assert.equal(Object.keys(a),
|
||||
'scheme,userPass,host,hostname,port,path,pathname,hash,href,origin,protocol,search',
|
||||
'fileName,scheme,userPass,host,hostname,port,path,pathname,hash,href,origin,protocol,search',
|
||||
'enumerable key list check for URL.');
|
||||
assert.equal(
|
||||
JSON.stringify(a),
|
||||
@ -392,6 +393,20 @@ exports.testLocalURLwithInvalidURL = function(assert) {
|
||||
});
|
||||
}
|
||||
|
||||
exports.testFileName = function(assert) {
|
||||
let urls = [
|
||||
['https://foo/bar.js', 'bar.js'],
|
||||
['app://myfxosapp/file.js', 'file.js'],
|
||||
['http://localhost:8888/file.js', 'file.js'],
|
||||
['http://foo/bar.js#hash', 'bar.js'],
|
||||
['http://foo/bar.js?q=go&query=yeah', 'bar.js'],
|
||||
['chrome://browser/content/content.js', 'content.js'],
|
||||
['resource://gre/foo.js', 'foo.js'],
|
||||
];
|
||||
|
||||
urls.forEach(([url, fileName]) => assert.equal(URL(url).fileName, fileName, 'file names are equal'));
|
||||
};
|
||||
|
||||
function validURIs() {
|
||||
return [
|
||||
'http://foo.com/blah_blah',
|
||||
|
Loading…
Reference in New Issue
Block a user