Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 1426501 - Change JS code to use nsIURIMutator instead of the nsIU…
Browse files Browse the repository at this point in the history
…RI.spec setter r=mayhemer

MozReview-Commit-ID: FI6WrsQT2ke
  • Loading branch information
valenting committed Jan 8, 2018
1 parent 6b6c980 commit 4bd874a
Show file tree
Hide file tree
Showing 26 changed files with 167 additions and 133 deletions.
14 changes: 7 additions & 7 deletions chrome/test/unit/test_no_remote_registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ ProtocolHandler.prototype =
defaultPort: -1,
allowPort: () => false,
newURI(aSpec, aCharset, aBaseURI) {
let uri = Cc["@mozilla.org/network/standard-url;1"].
createInstance(Ci.nsIURI);
uri.spec = aSpec;
if (!uri.scheme) {
// We got a partial uri, so let's resolve it with the base one
uri.spec = aBaseURI.resolve(aSpec);
let mutator = Cc["@mozilla.org/network/standard-url-mutator;1"]
.createInstance(Ci.nsIURIMutator);
if (aBaseURI) {
mutator.setSpec(aBaseURI.resolve(aSpec));
} else {
mutator.setSpec(aSpec);
}
return uri;
return mutator.finalize();
},
newChannel2() { throw Cr.NS_ERROR_NOT_IMPLEMENTED; },
newChannel() { throw Cr.NS_ERROR_NOT_IMPLEMENTED; },
Expand Down
8 changes: 4 additions & 4 deletions dom/base/test/chrome/test_bug682305.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
var Cu = Components.utils;

Cu.import("resource://gre/modules/XPCOMUtils.jsm");
var SimpleURI = Cc["@mozilla.org/network/simple-uri;1"];
var ios = Cc["@mozilla.org/network/io-service;1"]
.getService(Ci.nsIIOService);
var contentSecManager = Cc["@mozilla.org/contentsecuritymanager;1"]
Expand Down Expand Up @@ -120,9 +119,10 @@
return false;
},
newURI: function newURI(spec, charset, baseURI) {
var uri = SimpleURI.createInstance(Ci.nsIURI)
uri.spec = spec;
return uri.QueryInterface(Ci.nsIURI);
return Cc["@mozilla.org/network/simple-uri-mutator;1"]
.createInstance(Ci.nsIURIMutator)
.setSpec(spec)
.finalize();
},
newChannel2: function newChannel2(URI, loadInfo) {
return new CustomChannel(URI, loadInfo);
Expand Down
7 changes: 4 additions & 3 deletions dom/base/test/test_bug422403-1.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
if(aCharset == undefined)
aCharset = 'UTF-8';

var baseUri = SpecialPowers.Cc['@mozilla.org/network/standard-url;1']
.createInstance(SpecialPowers.Ci.nsIURI);
baseUri.spec = window.location.href;
var baseUri = SpecialPowers.Cc['@mozilla.org/network/standard-url-mutator;1']
.createInstance(SpecialPowers.Ci.nsIURIMutator)
.setSpec(window.location.href)
.finalize();

var ios = SpecialPowers.Cc['@mozilla.org/network/io-service;1']
.getService(SpecialPowers.Ci.nsIIOService);
Expand Down
7 changes: 4 additions & 3 deletions dom/base/test/test_bug422403-2.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ function loadFileContent(aFile, aCharset) {
if(aCharset == undefined)
aCharset = 'UTF-8';

var baseUri = SpecialPowers.Cc['@mozilla.org/network/standard-url;1']
.createInstance(SpecialPowers.Ci.nsIURI);
baseUri.spec = window.location.href;
var baseUri = SpecialPowers.Cc['@mozilla.org/network/standard-url-mutator;1']
.createInstance(SpecialPowers.Ci.nsIURIMutator)
.setSpec(window.location.href)
.finalize();

var ios = SpecialPowers.Cc['@mozilla.org/network/io-service;1']
.getService(SpecialPowers.Ci.nsIIOService);
Expand Down
7 changes: 4 additions & 3 deletions dom/base/test/test_bug424359-1.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
if(aCharset == undefined)
aCharset = 'UTF-8';

var baseUri = SpecialPowers.Cc['@mozilla.org/network/standard-url;1']
.createInstance(SpecialPowers.Ci.nsIURI);
baseUri.spec = window.location.href;
var baseUri = SpecialPowers.Cc['@mozilla.org/network/standard-url-mutator;1']
.createInstance(SpecialPowers.Ci.nsIURIMutator)
.setSpec(window.location.href)
.finalize();

var ios = SpecialPowers.Cc['@mozilla.org/network/io-service;1']
.getService(SpecialPowers.Ci.nsIIOService);
Expand Down
7 changes: 4 additions & 3 deletions dom/base/test/test_bug424359-2.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
if(aCharset == undefined)
aCharset = 'UTF-8';

var baseUri = SpecialPowers.Cc['@mozilla.org/network/standard-url;1']
.createInstance(SpecialPowers.Ci.nsIURI);
baseUri.spec = window.location.href;
var baseUri = SpecialPowers.Cc['@mozilla.org/network/standard-url-mutator;1']
.createInstance(SpecialPowers.Ci.nsIURIMutator)
.setSpec(window.location.href)
.finalize();

var ios = SpecialPowers.Cc['@mozilla.org/network/io-service;1']
.getService(SpecialPowers.Ci.nsIIOService);
Expand Down
7 changes: 4 additions & 3 deletions dom/base/test/test_bug498433.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
if (aCharset == undefined)
aCharset = 'UTF-8';

var baseUri = SpecialPowers.Cc['@mozilla.org/network/standard-url;1']
.createInstance(SpecialPowers.Ci.nsIURI);
baseUri.spec = window.location.href;
var baseUri = SpecialPowers.Cc['@mozilla.org/network/standard-url-mutator;1']
.createInstance(SpecialPowers.Ci.nsIURIMutator)
.setSpec(window.location.href)
.finalize();

var ios = SpecialPowers.Cc['@mozilla.org/network/io-service;1']
.getService(SpecialPowers.Ci.nsIIOService);
Expand Down
7 changes: 4 additions & 3 deletions dom/tests/unit/test_bug465752.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ function run_test()
Assert.ok(!uri3.equals(uri2));
Assert.ok(!uri2.equals(uri3));

var simple = Components.classes["@mozilla.org/network/simple-uri;1"]
.createInstance(Components.interfaces.nsIURI);
simple.spec = str;
var simple = Components.classes["@mozilla.org/network/simple-uri-mutator;1"]
.createInstance(Components.interfaces.nsIURIMutator)
.setSpec(str)
.finalize();
Assert.equal(simple.spec, uri.spec);
Assert.ok(!simple.equals(uri));
Assert.ok(!uri.equals(simple));
Expand Down
4 changes: 2 additions & 2 deletions dom/xslt/tests/XSLTMark/XSLTMark-static.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ const nsIIOService = Components.interfaces.nsIIOService;
const SIS_CTRID = "@mozilla.org/scriptableinputstream;1";
const nsISIS = Components.interfaces.nsIScriptableInputStream;
const nsIFilePicker = Components.interfaces.nsIFilePicker;
const STDURL_CTRID = "@mozilla.org/network/standard-url;1";
const nsIURI = Components.interfaces.nsIURI;
const STDURLMUT_CTRID = "@mozilla.org/network/standard-url-mutator;1";
const nsIURIMutator = Components.interfaces.nsIURIMutator;

Components.utils.import("resource://gre/modules/NetUtil.jsm");

Expand Down
13 changes: 9 additions & 4 deletions dom/xslt/tests/XSLTMark/XSLTMark-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ var view =
var res = fp.show();

if (res == nsIFilePicker.returnOK) {
this.configUrl = Components.classes[STDURL_CTRID].createInstance(nsIURI);
this.configUrl.spec = fp.fileURL.spec;
this.configUrl = Components.classes[STDURLMUT_CTRID]
.createInstance(nsIURIMutator)
.setSpec(fp.fileURL.spec)
.finalize();
document.getElementById('config').setAttribute('value', this.configUrl.spec);
}
this.parseConfig();
Expand Down Expand Up @@ -153,8 +155,11 @@ var view =
enablePrivilege('UniversalXPConnect');
if (!this.testArray) {
if (!this.configUrl) {
this.configUrl = Components.classes[STDURL_CTRID].createInstance(nsIURI);
this.configUrl.spec = document.getElementById('config').value;
this.configUrl =
Components.classes[STDURLMUT_CTRID]
.createInstance(nsIURIMutator)
.setSpec(document.getElementById('config').value)
.finalize();
}
this.parseConfig();
}
Expand Down
8 changes: 4 additions & 4 deletions netwerk/test/browser/browser_nsIFormPOSTActionChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ CustomProtocolHandler.prototype = {
Ci.nsIProtocolHandler.URI_IS_LOCAL_RESOURCE;
},
newURI: function(aSpec, aOriginCharset, aBaseURI) {
var uri = Cc["@mozilla.org/network/standard-url;1"].
createInstance(Ci.nsIURI);
uri.spec = aSpec;
return uri;
return Cc["@mozilla.org/network/standard-url-mutator;1"]
.createInstance(Ci.nsIURIMutator)
.setSpec(aSpec)
.finalize()
},
newChannel2: function(aURI, aLoadInfo) {
return new CustomChannel(aURI, aLoadInfo);
Expand Down
7 changes: 4 additions & 3 deletions netwerk/test/unit/test_1351443-missing-NewChannel2.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ var contentSecManager = Cc["@mozilla.org/contentsecuritymanager;1"]
.getService(Ci.nsIContentSecurityManager);

function ProtocolHandler() {
this.uri = Cc["@mozilla.org/network/simple-uri;1"].
createInstance(Ci.nsIURI);
this.uri.spec = this.scheme + ":dummy";
this.uri = Cc["@mozilla.org/network/simple-uri-mutator;1"]
.createInstance(Ci.nsIURIMutator)
.setSpec(this.scheme + ":dummy")
.finalize();
this.uri.QueryInterface(Ci.nsIMutable).mutable = false;
}

Expand Down
22 changes: 14 additions & 8 deletions netwerk/test/unit/test_bug1177909.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,13 @@ add_task(async function testSocksProxy() {

add_task(async function testDirectProxy() {
// Do what |WebSocketChannel::AsyncOpen| do, but do not prefer https proxy.
let proxyURI = Cc["@mozilla.org/network/standard-url;1"].createInstance(Ci.nsIURI);
proxyURI.spec = "wss://ws.mozilla.org/";
let uri = proxyURI.clone();
uri.scheme = "https";
let proxyURI = Cc["@mozilla.org/network/standard-url-mutator;1"]
.createInstance(Ci.nsIURIMutator)
.setSpec("wss://ws.mozilla.org/")
.finalize();
let uri = proxyURI.mutate()
.setScheme("https")
.finalize();

let ioService = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService);
Expand All @@ -122,10 +125,13 @@ add_task(async function testDirectProxy() {

add_task(async function testWebSocketProxy() {
// Do what |WebSocketChannel::AsyncOpen| do
let proxyURI = Cc["@mozilla.org/network/standard-url;1"].createInstance(Ci.nsIURI);
proxyURI.spec = "wss://ws.mozilla.org/";
let uri = proxyURI.clone();
uri.scheme = "https";
let proxyURI = Cc["@mozilla.org/network/standard-url-mutator;1"]
.createInstance(Ci.nsIURIMutator)
.setSpec("wss://ws.mozilla.org/")
.finalize();
let uri = proxyURI.mutate()
.setScheme("https")
.finalize();

let proxyFlags = Ci.nsIProtocolProxyService.RESOLVE_PREFER_HTTPS_PROXY |
Ci.nsIProtocolProxyService.RESOLVE_ALWAYS_TUNNEL;
Expand Down
2 changes: 1 addition & 1 deletion netwerk/test/unit/test_bug261425.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function run_test() {

var success = false;
try {
newURI.spec = "http: //foo.com";
newURI = newURI.mutate().setSpec("http: //foo.com").finalize();
}
catch (e) {
success = e.result == Cr.NS_ERROR_MALFORMED_URI;
Expand Down
24 changes: 12 additions & 12 deletions netwerk/test/unit/test_bug412457.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,38 @@ function run_test() {
Assert.equal(newURI.asciiHost, "xn--kkr.com");

// escaped UTF8
newURI.spec = "http://%e5%8d%81.com";
newURI = newURI.mutate().setSpec("http://%e5%8d%81.com").finalize();
Assert.equal(newURI.asciiHost, "xn--kkr.com");

// There should be only allowed characters in hostname after
// unescaping and attempting to apply IDNA. "\x80" is illegal in
// UTF-8, so IDNA fails, and 0x80 is illegal in DNS too.
Assert.throws(() => { newURI.spec = "http://%80.com"; }, "illegal UTF character");
Assert.throws(() => { newURI = newURI.mutate().setSpec("http://%80.com").finalize(); }, "illegal UTF character");

// test parsing URL with all possible host terminators
newURI.spec = "http://example.com?foo";
newURI = newURI.mutate().setSpec("http://example.com?foo").finalize();
Assert.equal(newURI.asciiHost, "example.com");

newURI.spec = "http://example.com#foo";
newURI = newURI.mutate().setSpec("http://example.com#foo").finalize();
Assert.equal(newURI.asciiHost, "example.com");

newURI.spec = "http://example.com:80";
newURI = newURI.mutate().setSpec("http://example.com:80").finalize();
Assert.equal(newURI.asciiHost, "example.com");

newURI.spec = "http://example.com/foo";
newURI = newURI.mutate().setSpec("http://example.com/foo").finalize();
Assert.equal(newURI.asciiHost, "example.com");

// Characters that are invalid in the host, shouldn't be decoded.
newURI.spec = "http://example.com%3ffoo";
newURI = newURI.mutate().setSpec("http://example.com%3ffoo").finalize();
Assert.equal(newURI.asciiHost, "example.com%3ffoo");
newURI.spec = "http://example.com%23foo";
newURI = newURI.mutate().setSpec("http://example.com%23foo").finalize();
Assert.equal(newURI.asciiHost, "example.com%23foo");
newURI.spec = "http://example.com%3bfoo";
newURI = newURI.mutate().setSpec("http://example.com%3bfoo").finalize();
Assert.equal(newURI.asciiHost, "example.com%3bfoo");
newURI.spec = "http://example.com%3a80";
newURI = newURI.mutate().setSpec("http://example.com%3a80").finalize();
Assert.equal(newURI.asciiHost, "example.com%3a80");
newURI.spec = "http://example.com%2ffoo";
newURI = newURI.mutate().setSpec("http://example.com%2ffoo").finalize();
Assert.equal(newURI.asciiHost, "example.com%2ffoo");
newURI.spec = "http://example.com%00";
newURI = newURI.mutate().setSpec("http://example.com%00").finalize();
Assert.equal(newURI.asciiHost, "example.com%00");
}
24 changes: 12 additions & 12 deletions netwerk/test/unit/test_bug429347.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,33 @@ function run_test() {
var uri2 = ios.newURI("http://example.com/#bar");
Assert.ok(uri1.equals(uri2));

uri1.spec = "http://example.com?bar";
uri2.spec = "http://example.com/?bar";
uri1 = uri1.mutate().setSpec("http://example.com?bar").finalize();
uri2 = uri2.mutate().setSpec("http://example.com/?bar").finalize();
Assert.ok(uri1.equals(uri2));

// see https://bugzilla.mozilla.org/show_bug.cgi?id=665706
// ";" is not parsed as special anymore and thus ends up
// in the authority component (see RFC 3986)
uri1.spec = "http://example.com;bar";
uri2.spec = "http://example.com/;bar";
uri1 = uri1.mutate().setSpec("http://example.com;bar").finalize();
uri2 = uri2.mutate().setSpec("http://example.com/;bar").finalize();
Assert.ok(!uri1.equals(uri2));

uri1.spec = "http://example.com#";
uri2.spec = "http://example.com/#";
uri1 = uri1.mutate().setSpec("http://example.com#").finalize();
uri2 = uri2.mutate().setSpec("http://example.com/#").finalize();
Assert.ok(uri1.equals(uri2));

uri1.spec = "http://example.com?";
uri2.spec = "http://example.com/?";
uri1 = uri1.mutate().setSpec("http://example.com?").finalize();
uri2 = uri2.mutate().setSpec("http://example.com/?").finalize();
Assert.ok(uri1.equals(uri2));

// see https://bugzilla.mozilla.org/show_bug.cgi?id=665706
// ";" is not parsed as special anymore and thus ends up
// in the authority component (see RFC 3986)
uri1.spec = "http://example.com;";
uri2.spec = "http://example.com/;";
uri1 = uri1.mutate().setSpec("http://example.com;").finalize();
uri2 = uri2.mutate().setSpec("http://example.com/;").finalize();
Assert.ok(!uri1.equals(uri2));

uri1.spec = "http://example.com";
uri2.spec = "http://example.com/";
uri1 = uri1.mutate().setSpec("http://example.com").finalize();
uri2 = uri2.mutate().setSpec("http://example.com/").finalize();
Assert.ok(uri1.equals(uri2));
}
2 changes: 1 addition & 1 deletion netwerk/test/unit/test_bug479485.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function run_test() {
exception_threw = false;
newURI = ios.newURI("http://foo.com");
try {
newURI.spec = "http://foo.com"+port;
newURI = newURI.mutate().setSpec("http://foo.com"+port).finalize();
}
catch (e) {
exception_threw = e.result == Cr.NS_ERROR_MALFORMED_URI;
Expand Down
2 changes: 1 addition & 1 deletion netwerk/test/unit/test_bug660066.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function run_test()
do_check_uri_neq(simpleURI, fileDataURI);

do_info("Changing the nsSimpleURI spec to match the nsFileDataURI");
simpleURI.spec = BLOBURI_SPEC;
simpleURI = simpleURI.mutate().setSpec(BLOBURI_SPEC).finalize();

do_info("Verifying that .spec matches");
Assert.equal(simpleURI.spec, fileDataURI.spec);
Expand Down
7 changes: 4 additions & 3 deletions netwerk/test/unit/test_bug894586.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ var contentSecManager = Cc["@mozilla.org/contentsecuritymanager;1"]
.getService(Ci.nsIContentSecurityManager);

function ProtocolHandler() {
this.uri = Cc["@mozilla.org/network/simple-uri;1"].
createInstance(Ci.nsIURI);
this.uri.spec = this.scheme + ":dummy";
this.uri = Cc["@mozilla.org/network/simple-uri-mutator;1"]
.createInstance(Ci.nsIURIMutator)
.setSpec(this.scheme + ":dummy")
.finalize();
this.uri.QueryInterface(Ci.nsIMutable).mutable = false;
}

Expand Down
8 changes: 4 additions & 4 deletions netwerk/test/unit/test_protocolproxyservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ TestProtocolHandler.prototype = {
Components.interfaces.nsIProtocolHandler.ALLOWS_PROXY |
Components.interfaces.nsIProtocolHandler.URI_DANGEROUS_TO_LOAD,
newURI: function(spec, originCharset, baseURI) {
var uri = Components.classes["@mozilla.org/network/simple-uri;1"]
.createInstance(Components.interfaces.nsIURI);
uri.spec = spec;
return uri;
return Components.classes["@mozilla.org/network/simple-uri-mutator;1"]
.createInstance(Components.interfaces.nsIURIMutator)
.setSpec(spec)
.finalize();
},
newChannel2: function(uri, aLoadInfo) {
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
Expand Down
Loading

0 comments on commit 4bd874a

Please sign in to comment.