From 4bd874a326ef5d4edc92f9570c98a0cd98db4578 Mon Sep 17 00:00:00 2001 From: Valentin Gosu Date: Mon, 8 Jan 2018 15:20:29 +0100 Subject: [PATCH] Bug 1426501 - Change JS code to use nsIURIMutator instead of the nsIURI.spec setter r=mayhemer MozReview-Commit-ID: FI6WrsQT2ke --- .../test/unit/test_no_remote_registration.js | 14 ++-- dom/base/test/chrome/test_bug682305.html | 8 +- dom/base/test/test_bug422403-1.html | 7 +- dom/base/test/test_bug422403-2.xhtml | 7 +- dom/base/test/test_bug424359-1.html | 7 +- dom/base/test/test_bug424359-2.html | 7 +- dom/base/test/test_bug498433.html | 7 +- dom/tests/unit/test_bug465752.js | 7 +- dom/xslt/tests/XSLTMark/XSLTMark-static.js | 4 +- dom/xslt/tests/XSLTMark/XSLTMark-view.js | 13 +++- .../browser_nsIFormPOSTActionChannel.js | 8 +- .../unit/test_1351443-missing-NewChannel2.js | 7 +- netwerk/test/unit/test_bug1177909.js | 22 ++++-- netwerk/test/unit/test_bug261425.js | 2 +- netwerk/test/unit/test_bug412457.js | 24 +++--- netwerk/test/unit/test_bug429347.js | 24 +++--- netwerk/test/unit/test_bug479485.js | 2 +- netwerk/test/unit/test_bug660066.js | 2 +- netwerk/test/unit/test_bug894586.js | 7 +- .../test/unit/test_protocolproxyservice.js | 8 +- netwerk/test/unit/test_standardurl.js | 10 ++- netwerk/test/unit/test_standardurl_port.js | 4 +- .../test_SpecialPowersExtension.html | 7 +- .../mozprotocol/mozProtocolHandler.js | 9 ++- .../places/PageIconProtocolHandler.js | 7 +- .../tests/unit/test_taskbar_jumplistitems.js | 76 +++++++++++-------- 26 files changed, 167 insertions(+), 133 deletions(-) diff --git a/chrome/test/unit/test_no_remote_registration.js b/chrome/test/unit/test_no_remote_registration.js index e5be45977ef5..78a000c5a6a2 100644 --- a/chrome/test/unit/test_no_remote_registration.js +++ b/chrome/test/unit/test_no_remote_registration.js @@ -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; }, diff --git a/dom/base/test/chrome/test_bug682305.html b/dom/base/test/chrome/test_bug682305.html index fec4f013e49a..3046e4005d5d 100644 --- a/dom/base/test/chrome/test_bug682305.html +++ b/dom/base/test/chrome/test_bug682305.html @@ -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"] @@ -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); diff --git a/dom/base/test/test_bug422403-1.html b/dom/base/test/test_bug422403-1.html index fa6cbbd84a32..4e6bd2a2fe98 100644 --- a/dom/base/test/test_bug422403-1.html +++ b/dom/base/test/test_bug422403-1.html @@ -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); diff --git a/dom/base/test/test_bug422403-2.xhtml b/dom/base/test/test_bug422403-2.xhtml index 755cd7253251..fd61ad668fa7 100644 --- a/dom/base/test/test_bug422403-2.xhtml +++ b/dom/base/test/test_bug422403-2.xhtml @@ -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); diff --git a/dom/base/test/test_bug424359-1.html b/dom/base/test/test_bug424359-1.html index 1ee8164f6eff..93ea9e4be355 100644 --- a/dom/base/test/test_bug424359-1.html +++ b/dom/base/test/test_bug424359-1.html @@ -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); diff --git a/dom/base/test/test_bug424359-2.html b/dom/base/test/test_bug424359-2.html index 103e34e1c7ec..d46b92f42b56 100644 --- a/dom/base/test/test_bug424359-2.html +++ b/dom/base/test/test_bug424359-2.html @@ -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); diff --git a/dom/base/test/test_bug498433.html b/dom/base/test/test_bug498433.html index 5bafcd2ea61d..751bd60993fb 100644 --- a/dom/base/test/test_bug498433.html +++ b/dom/base/test/test_bug498433.html @@ -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); diff --git a/dom/tests/unit/test_bug465752.js b/dom/tests/unit/test_bug465752.js index 03a444f8b8d0..b29c46e2e5d8 100644 --- a/dom/tests/unit/test_bug465752.js +++ b/dom/tests/unit/test_bug465752.js @@ -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)); diff --git a/dom/xslt/tests/XSLTMark/XSLTMark-static.js b/dom/xslt/tests/XSLTMark/XSLTMark-static.js index d3284aac8ee4..138edb68888e 100644 --- a/dom/xslt/tests/XSLTMark/XSLTMark-static.js +++ b/dom/xslt/tests/XSLTMark/XSLTMark-static.js @@ -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"); diff --git a/dom/xslt/tests/XSLTMark/XSLTMark-view.js b/dom/xslt/tests/XSLTMark/XSLTMark-view.js index 7342d0d9ab2c..d24239ff10f5 100644 --- a/dom/xslt/tests/XSLTMark/XSLTMark-view.js +++ b/dom/xslt/tests/XSLTMark/XSLTMark-view.js @@ -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(); @@ -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(); } diff --git a/netwerk/test/browser/browser_nsIFormPOSTActionChannel.js b/netwerk/test/browser/browser_nsIFormPOSTActionChannel.js index e6669008b6f3..6d6b2fcb2dd2 100644 --- a/netwerk/test/browser/browser_nsIFormPOSTActionChannel.js +++ b/netwerk/test/browser/browser_nsIFormPOSTActionChannel.js @@ -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); diff --git a/netwerk/test/unit/test_1351443-missing-NewChannel2.js b/netwerk/test/unit/test_1351443-missing-NewChannel2.js index 0f024a4ebe11..3c4f001e7fc7 100644 --- a/netwerk/test/unit/test_1351443-missing-NewChannel2.js +++ b/netwerk/test/unit/test_1351443-missing-NewChannel2.js @@ -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; } diff --git a/netwerk/test/unit/test_bug1177909.js b/netwerk/test/unit/test_bug1177909.js index e6643c61c15e..5d1f0c63b163 100644 --- a/netwerk/test/unit/test_bug1177909.js +++ b/netwerk/test/unit/test_bug1177909.js @@ -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); @@ -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; diff --git a/netwerk/test/unit/test_bug261425.js b/netwerk/test/unit/test_bug261425.js index 1aa6d4bf96e0..a43a0f2fe176 100644 --- a/netwerk/test/unit/test_bug261425.js +++ b/netwerk/test/unit/test_bug261425.js @@ -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; diff --git a/netwerk/test/unit/test_bug412457.js b/netwerk/test/unit/test_bug412457.js index 7f9e6dd98da2..4343479126bc 100644 --- a/netwerk/test/unit/test_bug412457.js +++ b/netwerk/test/unit/test_bug412457.js @@ -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"); } \ No newline at end of file diff --git a/netwerk/test/unit/test_bug429347.js b/netwerk/test/unit/test_bug429347.js index b6244c86562a..df231e5737a9 100644 --- a/netwerk/test/unit/test_bug429347.js +++ b/netwerk/test/unit/test_bug429347.js @@ -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)); } diff --git a/netwerk/test/unit/test_bug479485.js b/netwerk/test/unit/test_bug479485.js index f8b018059d98..9791aaef46e5 100644 --- a/netwerk/test/unit/test_bug479485.js +++ b/netwerk/test/unit/test_bug479485.js @@ -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; diff --git a/netwerk/test/unit/test_bug660066.js b/netwerk/test/unit/test_bug660066.js index 91856f7aafeb..635928d9515b 100644 --- a/netwerk/test/unit/test_bug660066.js +++ b/netwerk/test/unit/test_bug660066.js @@ -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); diff --git a/netwerk/test/unit/test_bug894586.js b/netwerk/test/unit/test_bug894586.js index eef9b1470f4e..b02ebfa11c21 100644 --- a/netwerk/test/unit/test_bug894586.js +++ b/netwerk/test/unit/test_bug894586.js @@ -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; } diff --git a/netwerk/test/unit/test_protocolproxyservice.js b/netwerk/test/unit/test_protocolproxyservice.js index 05054f753d73..02b7d6e54eae 100644 --- a/netwerk/test/unit/test_protocolproxyservice.js +++ b/netwerk/test/unit/test_protocolproxyservice.js @@ -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; diff --git a/netwerk/test/unit/test_standardurl.js b/netwerk/test/unit/test_standardurl.js index 838fea88ae27..ea764e1bda58 100644 --- a/netwerk/test/unit/test_standardurl.js +++ b/netwerk/test/unit/test_standardurl.js @@ -218,8 +218,8 @@ add_test(function test_ipv6_fail() add_test(function test_clearedSpec() { var url = stringToURL("http://example.com/path"); - Assert.throws(() => { url.spec = "http: example"; }, "set bad spec"); - Assert.throws(() => { url.spec = ""; }, "set empty spec"); + Assert.throws(() => { url = url.mutate().setSpec("http: example").finalize(); }, "set bad spec"); + Assert.throws(() => { url = url.mutate().setSpec("").finalize(); }, "set empty spec"); Assert.equal(url.spec, "http://example.com/path"); url.host = "allizom.org"; @@ -359,9 +359,11 @@ add_test(function test_trim_C0_and_space() { var url = stringToURL("\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f http://example.com/ \x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f "); Assert.equal(url.spec, "http://example.com/"); - url.spec = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f http://test.com/ \x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f "; + url = url.mutate() + .setSpec("\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f http://test.com/ \x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f ") + .finalize(); Assert.equal(url.spec, "http://test.com/"); - Assert.throws(() => { url.spec = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19 "; }, "set empty spec"); + Assert.throws(() => { url = url.mutate().setSpec("\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19 ").finalize(); }, "set empty spec"); run_next_test(); }); diff --git a/netwerk/test/unit/test_standardurl_port.js b/netwerk/test/unit/test_standardurl_port.js index e7cb1dca5d80..a86f13132923 100644 --- a/netwerk/test/unit/test_standardurl_port.js +++ b/netwerk/test/unit/test_standardurl_port.js @@ -23,9 +23,9 @@ function run_test() { Assert.ok(!/80/.test(httpURI.spec)); // URL parsers shouldn't set ports to default value (bug 407538) - httpURI.spec = "http://foo.com:81"; + httpURI = httpURI.mutate().setSpec("http://foo.com:81").finalize(); Assert.equal(81, httpURI.port); - httpURI.spec = "http://foo.com:80"; + httpURI = httpURI.mutate().setSpec("http://foo.com:80").finalize(); Assert.equal(-1, httpURI.port); Assert.ok(!/80/.test(httpURI.spec)); diff --git a/testing/mochitest/tests/Harness_sanity/test_SpecialPowersExtension.html b/testing/mochitest/tests/Harness_sanity/test_SpecialPowersExtension.html index 299497e15707..4d770b79af24 100644 --- a/testing/mochitest/tests/Harness_sanity/test_SpecialPowersExtension.html +++ b/testing/mochitest/tests/Harness_sanity/test_SpecialPowersExtension.html @@ -95,9 +95,10 @@ // Try some basic stuff with XHR. var xhr2 = SpecialPowers.Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(SpecialPowers.Ci.nsIXMLHttpRequest); is(xhr2.readyState, XMLHttpRequest.UNSENT, "Should be able to get props off privileged objects"); - var testURI = SpecialPowers.Cc['@mozilla.org/network/standard-url;1'] - .createInstance(SpecialPowers.Ci.nsIURI); - testURI.spec = "http://www.foobar.org/"; + var testURI = SpecialPowers.Cc['@mozilla.org/network/standard-url-mutator;1'] + .createInstance(SpecialPowers.Ci.nsIURIMutator) + .setSpec("http://www.foobar.org/") + .finalize(); is(testURI.spec, "http://www.foobar.org/", "Getters/Setters should work correctly"); is(SpecialPowers.wrap(document).getElementsByTagName('details').length, 0, "Should work with proxy-based DOM bindings."); diff --git a/toolkit/components/mozprotocol/mozProtocolHandler.js b/toolkit/components/mozprotocol/mozProtocolHandler.js index 01c08a192784..9668b0ce9590 100644 --- a/toolkit/components/mozprotocol/mozProtocolHandler.js +++ b/toolkit/components/mozprotocol/mozProtocolHandler.js @@ -20,13 +20,14 @@ mozProtocolHandler.prototype = { protocolFlags: Ci.nsIProtocolHandler.URI_DANGEROUS_TO_LOAD, newURI(spec, charset, base) { - let uri = Cc["@mozilla.org/network/simple-uri;1"].createInstance(Ci.nsIURI); + let mutator = Cc["@mozilla.org/network/simple-uri-mutator;1"] + .createInstance(Ci.nsIURIMutator); if (base) { - uri.spec = base.resolve(spec); + mutator.setSpec(base.resolve(spec)); } else { - uri.spec = spec; + mutator.setSpec(spec); } - return uri; + return mutator.finalize(); }, newChannel2(uri, loadInfo) { diff --git a/toolkit/components/places/PageIconProtocolHandler.js b/toolkit/components/places/PageIconProtocolHandler.js index a7309f685cf8..779ddc2b20fa 100644 --- a/toolkit/components/places/PageIconProtocolHandler.js +++ b/toolkit/components/places/PageIconProtocolHandler.js @@ -73,9 +73,10 @@ PageIconProtocolHandler.prototype = { }, newURI(spec, originCharset, baseURI) { - let uri = Cc["@mozilla.org/network/simple-uri;1"].createInstance(Ci.nsIURI); - uri.spec = spec; - return uri; + return Cc["@mozilla.org/network/simple-uri-mutator;1"] + .createInstance(Ci.nsIURIMutator) + .setSpec(spec) + .finalize(); }, newChannel2(uri, loadInfo) { diff --git a/widget/tests/unit/test_taskbar_jumplistitems.js b/widget/tests/unit/test_taskbar_jumplistitems.js index 5e3407ba9574..dccbc34a3c72 100644 --- a/widget/tests/unit/test_taskbar_jumplistitems.js +++ b/widget/tests/unit/test_taskbar_jumplistitems.js @@ -58,44 +58,51 @@ function test_hashes() { var link = Cc["@mozilla.org/windows-jumplistlink;1"] .createInstance(Ci.nsIJumpListLink); - var uri1 = Cc["@mozilla.org/network/simple-uri;1"] - .createInstance(Ci.nsIURI); - var uri2 = Cc["@mozilla.org/network/simple-uri;1"] - .createInstance(Ci.nsIURI); - - uri1.spec = "http://www.123.com/"; - uri2.spec = "http://www.123.com/"; + var uri1 = Cc["@mozilla.org/network/simple-uri-mutator;1"] + .createInstance(Ci.nsIURIMutator) + .setSpec("http://www.123.com/") + .finalize(); + var uri2 = Cc["@mozilla.org/network/simple-uri-mutator;1"] + .createInstance(Ci.nsIURIMutator) + .setSpec("http://www.123.com/") + .finalize(); link.uri = uri1; Assert.ok(link.compareHash(uri2)) - uri2.spec = "http://www.456.com/"; + uri2 = uri2.mutate().setSpec("http://www.456.com/").finalize(); Assert.ok(!link.compareHash(uri2)) - uri2.spec = "http://www.123.com/"; + uri2 = uri2.mutate().setSpec("http://www.123.com/").finalize(); Assert.ok(link.compareHash(uri2)) - uri2.spec = "https://www.123.com/"; + uri2 = uri2.mutate().setSpec("https://www.123.com/").finalize(); Assert.ok(!link.compareHash(uri2)) - uri2.spec = "http://www.123.com/test/"; + uri2 = uri2.mutate().setSpec("http://www.123.com/test/").finalize(); Assert.ok(!link.compareHash(uri2)) - uri1.spec = "http://www.123.com/test/"; - uri2.spec = "http://www.123.com/test/"; + uri1 = uri1.mutate().setSpec("http://www.123.com/test/").finalize(); + link.uri = uri1; + uri2 = uri2.mutate().setSpec("http://www.123.com/test/").finalize(); Assert.ok(link.compareHash(uri2)) - uri1.spec = "https://www.123.com/test/"; - uri2.spec = "https://www.123.com/test/"; + uri1 = uri1.mutate().setSpec("https://www.123.com/test/").finalize(); + link.uri = uri1; + uri2 = uri2.mutate().setSpec("https://www.123.com/test/").finalize(); Assert.ok(link.compareHash(uri2)) - uri2.spec = "ftp://www.123.com/test/"; + uri2 = uri2.mutate().setSpec("ftp://www.123.com/test/").finalize(); Assert.ok(!link.compareHash(uri2)) - uri2.spec = "http://123.com/test/"; + uri2 = uri2.mutate().setSpec("http://123.com/test/").finalize(); Assert.ok(!link.compareHash(uri2)) - uri1.spec = "https://www.123.com/test/"; - uri2.spec = "https://www.123.com/Test/"; + uri1 = uri1.mutate().setSpec("https://www.123.com/test/").finalize(); + link.uri = uri1; + uri2 = uri2.mutate().setSpec("https://www.123.com/Test/").finalize(); Assert.ok(!link.compareHash(uri2)) - uri1.spec = "http://www.123.com/"; + uri1 = uri1.mutate().setSpec("http://www.123.com/").finalize(); + link.uri = uri1; Assert.equal(link.uriHash, "QGLmWuwuTozr3tOfXSf5mg=="); - uri1.spec = "http://www.123.com/test/"; + uri1 = uri1.mutate().setSpec("http://www.123.com/test/").finalize(); + link.uri = uri1; Assert.equal(link.uriHash, "AG87Ls+GmaUYSUJFETRr3Q=="); - uri1.spec = "https://www.123.com/"; + uri1 = uri1.mutate().setSpec("https://www.123.com/").finalize(); + link.uri = uri1; Assert.equal(link.uriHash, "iSx6UH1a9enVPzUA9JZ42g=="); var uri3 = Cc["@mozilla.org/network/simple-uri;1"] @@ -112,13 +119,14 @@ function test_links() var link2 = Cc["@mozilla.org/windows-jumplistlink;1"] .createInstance(Ci.nsIJumpListLink); - var uri1 = Cc["@mozilla.org/network/simple-uri;1"] - .createInstance(Ci.nsIURI); - var uri2 = Cc["@mozilla.org/network/simple-uri;1"] - .createInstance(Ci.nsIURI); - - uri1.spec = "http://www.test.com/"; - uri2.spec = "http://www.test.com/"; + var uri1 = Cc["@mozilla.org/network/simple-uri-mutator;1"] + .createInstance(Ci.nsIURIMutator) + .setSpec("http://www.test.com/") + .finalize(); + var uri2 = Cc["@mozilla.org/network/simple-uri-mutator;1"] + .createInstance(Ci.nsIURIMutator) + .setSpec("http://www.test.com/") + .finalize(); link1.uri = uri1; link1.uriTitle = "Test"; @@ -132,7 +140,8 @@ function test_links() Assert.ok(!link1.equals(link2)); link2.uriTitle = "Test"; - uri2.spec = "http://www.testing.com/"; + uri2 = uri2.mutate().setSpec("http://www.testing.com/").finalize(); + link2.uri = uri2; Assert.ok(!link1.equals(link2)); } @@ -153,9 +162,10 @@ function test_shortcuts() sc.iconIndex = 1; Assert.equal(sc.iconIndex, 1); - var faviconPageUri = Cc["@mozilla.org/network/simple-uri;1"] - .createInstance(Ci.nsIURI); - faviconPageUri.spec = "http://www.123.com/"; + var faviconPageUri = Cc["@mozilla.org/network/simple-uri-mutator;1"] + .createInstance(Ci.nsIURIMutator) + .setSpec("http://www.123.com/") + .finalize(); sc.faviconPageUri = faviconPageUri; Assert.equal(sc.faviconPageUri, faviconPageUri);