Bug 1431913 - Port bug 1431204 to mailnews: Make nsIURI.spec readonly (JS part). rs=bustage-fix CLOSED TREE
authorJorg K <jorgk@jorgk.com>
Sun, 21 Jan 2018 20:56:50 +0100
changeset 30862 603955ee98d37a04c231db0c5025f20b7d934a1b
parent 30861 56a1e0215340d31f7e86c82a8102e65ec439d46f
child 30863 8624191ab58e13219569c078d7476b9ad682fe8f
push id382
push userclokep@gmail.com
push dateMon, 12 Mar 2018 19:05:34 +0000
reviewersbustage-fix
bugs1431913, 1431204
Bug 1431913 - Port bug 1431204 to mailnews: Make nsIURI.spec readonly (JS part). rs=bustage-fix CLOSED TREE
ldap/xpcom/tests/unit/test_nsLDAPURL.js
mailnews/extensions/newsblog/content/FeedUtils.jsm
mailnews/imap/test/unit/test_compactOfflineStore.js
mailnews/imap/test/unit/test_imapHdrStreaming.js
mailnews/imap/test/unit/test_imapStoreMsgOffline.js
mailnews/imap/test/unit/test_nsIMsgFolderListenerIMAP.js
mailnews/imap/test/unit/test_offlineCopy.js
mailnews/news/test/unit/test_bug540288.js
--- a/ldap/xpcom/tests/unit/test_nsLDAPURL.js
+++ b/ldap/xpcom/tests/unit/test_nsLDAPURL.js
@@ -185,17 +185,17 @@ function run_test() {
 
   // Test - Equals
 
   var url2 = ioService.newURI("ldap://localhost" + portAdpt + "/dc=short??one?(objectclass=*)")
                       .QueryInterface(Ci.nsILDAPURL);
 
   Assert.ok(url.equals(url2));
 
-  url2.spec = "ldap://localhost:389/dc=short??sub?(objectclass=*)";
+  url2 = url2.mutate().setSpec("ldap://localhost:389/dc=short??sub?(objectclass=*)").finalize();
 
   Assert.ok(!url.equals(url2));
 
   // Test Attributes
 
   Assert.equal(url.attributes.length, 0);
 
   // Nothing should happend if the attribute doesn't exist
@@ -256,29 +256,32 @@ function run_test() {
   url.attributes = "";
 
   Assert.equal(url.attributes.length, 0);
   Assert.equal(url.spec, "ldap://localhost" + portAdpt + "/dc=short??one?(objectclass=*)");
 
   // Set attributes via the url spec
 
   newAttrs = "abc,def,ghi,jkl";
-  url.spec = "ldap://localhost/dc=short?" + newAttrs + "?one?(objectclass=*)";
+  url = url.mutate().setSpec("ldap://localhost/dc=short?" + newAttrs + "?one?(objectclass=*)").finalize();
+  url instanceof Components.interfaces.nsILDAPURL;
 
   Assert.equal(url.attributes, newAttrs);
   Assert.equal(url.spec,
                "ldap://localhost/dc=short?" + newAttrs + "?one?(objectclass=*)");
 
-  url.spec = "ldap://localhost/dc=short??one?(objectclass=*)";
+  url = url.mutate().setSpec("ldap://localhost/dc=short??one?(objectclass=*)").finalize();
+  url instanceof Components.interfaces.nsILDAPURL;
 
-  attrs = url.attributes;
+  var attrs = url.attributes;
   Assert.equal(attrs.length, 0);
   Assert.equal(url.spec, "ldap://localhost/dc=short??one?(objectclass=*)");
 
   // Test - clone
 
-  url.spec = "ldap://localhost/dc=short?abc,def,ghi,jkl?one?(objectclass=*)";
+  url = url.mutate().setSpec("ldap://localhost/dc=short?abc,def,ghi,jkl?one?(objectclass=*)").finalize();
+
 
   var newUrl = url.clone();
 
   Assert.equal(newUrl.spec,
                "ldap://localhost/dc=short?abc,def,ghi,jkl?one?(objectclass=*)");
 }
--- a/mailnews/extensions/newsblog/content/FeedUtils.jsm
+++ b/mailnews/extensions/newsblog/content/FeedUtils.jsm
@@ -1489,44 +1489,43 @@ var FeedUtils = {
  *
  * @param  nsIDOMDataTransfer aDataTransfer  - the dnd event's dataTransfer.
  * @return nsIURI uri                        - a uri if valid, null if none.
  */
   getFeedUriFromDataTransfer: function(aDataTransfer) {
     let dt = aDataTransfer;
     let types = ["text/x-moz-url-data", "text/x-moz-url"];
     let validUri = false;
-    let uri = Cc["@mozilla.org/network/standard-url;1"].
-              createInstance(Ci.nsIURI);
+    let uri;
 
     if (dt.getData(types[0]))
     {
       // The url is the data.
-      uri.spec = dt.mozGetDataAt(types[0], 0);
+      uri = Services.io.newURI(dt.mozGetDataAt(types[0], 0));
       validUri = this.isValidScheme(uri);
       this.log.trace("getFeedUriFromDataTransfer: dropEffect:type:value - " +
                      dt.dropEffect + " : " + types[0] + " : " + uri.spec);
     }
     else if (dt.getData(types[1]))
     {
       // The url is the first part of the data, the second part is random.
-      uri.spec = dt.mozGetDataAt(types[1], 0).split("\n")[0];
+      uri = Services.io.newURI(dt.mozGetDataAt(types[1], 0).split("\n")[0]);
       validUri = this.isValidScheme(uri);
       this.log.trace("getFeedUriFromDataTransfer: dropEffect:type:value - " +
                      dt.dropEffect + " : " + types[0] + " : " + uri.spec);
     }
     else
     {
       // Go through the types and see if there's a url; get the first one.
       for (let i = 0; i < dt.types.length; i++) {
         let spec = dt.mozGetDataAt(dt.types[i], 0);
         this.log.trace("getFeedUriFromDataTransfer: dropEffect:index:type:value - " +
                        dt.dropEffect + " : " + i + " : " + dt.types[i] + " : "+spec);
         try {
-          uri.spec = spec;
+          uri = Services.io.newURI(spec);
           validUri = this.isValidScheme(uri);
         }
         catch(ex) {}
 
         if (validUri)
           break;
       };
     }
--- a/mailnews/imap/test/unit/test_compactOfflineStore.js
+++ b/mailnews/imap/test/unit/test_compactOfflineStore.js
@@ -30,27 +30,28 @@ var gMsgId2 = "200804111417.m3BEHTk40301
 var gMsgId3 = "4849BF7B.2030800@example.com";
 var gMsgId4 = "bugmail7.m47LtAEf007542@mrapp51.mozilla.org";
 var gMsgId5 = "bugmail6.m47LtAEf007542@mrapp51.mozilla.org";
 
 // Adds some messages directly to a mailbox (eg new mail)
 function addMessagesToServer(messages, mailbox)
 {
   // For every message we have, we need to convert it to a file:/// URI
+  let specs = [];
   messages.forEach(function (message)
   {
     let URI =
       Services.io.newFileURI(message.file).QueryInterface(Ci.nsIFileURL);
-    message.spec = URI.spec;
+    specs.push(URI.spec);
   });
 
   // Create the imapMessages and store them on the mailbox
-  messages.forEach(function (message)
+  specs.forEach(function (spec)
   {
-    mailbox.addMessage(new imapMessage(message.spec, mailbox.uidnext++, []));
+    mailbox.addMessage(new imapMessage(spec, mailbox.uidnext++, []));
   });
 }
 
 function addGeneratedMessagesToServer(messages, mailbox)
 {
   // Create the imapMessages and store them on the mailbox
   messages.forEach(function (message)
   {
--- a/mailnews/imap/test/unit/test_imapHdrStreaming.js
+++ b/mailnews/imap/test/unit/test_imapHdrStreaming.js
@@ -51,27 +51,28 @@ var streamListener =
     this._data += this._stream.read(aCount);
   }
 };
 
 // Adds some messages directly to a mailbox (eg new mail)
 function addMessagesToServer(messages, mailbox)
 {
   // For every message we have, we need to convert it to a file:/// URI
+  let specs = [];
   messages.forEach(function (message)
   {
     let URI =
       Services.io.newFileURI(message.file).QueryInterface(Ci.nsIFileURL);
-    message.spec = URI.spec;
+    specs.push(URI.spec);
   });
 
   // Create the imapMessages and store them on the mailbox
-  messages.forEach(function (message)
+  specs.forEach(function (spec)
   {
-    mailbox.addMessage(new imapMessage(message.spec, mailbox.uidnext++, []));
+    mailbox.addMessage(new imapMessage(spec, mailbox.uidnext++, []));
   });
 }
 
 var incomingServer, server;
 function run_test() {
 
   // Add a couple of messages to the INBOX
   // this is synchronous, afaik
--- a/mailnews/imap/test/unit/test_imapStoreMsgOffline.js
+++ b/mailnews/imap/test/unit/test_imapStoreMsgOffline.js
@@ -55,30 +55,31 @@ var streamListener =
 
     scriptStream.init(aInputStream);
 
     scriptStream.read(aCount);
   }
 };
 
 // Adds some messages directly to a mailbox (eg new mail)
-function addMessagesToServer(messages, mailbox, localFolder)
+function addMessagesToServer(messages, mailbox)
 {
   // For every message we have, we need to convert it to a file:/// URI
+  let specs = [];
   messages.forEach(function (message)
   {
     let URI =
       Services.io.newFileURI(message.file).QueryInterface(Ci.nsIFileURL);
-    message.spec = URI.spec;
+    specs.push(URI.spec);
   });
 
   // Create the imapMessages and store them on the mailbox
-  messages.forEach(function (message)
+  specs.forEach(function (spec)
   {
-    mailbox.addMessage(new imapMessage(message.spec, mailbox.uidnext++, []));
+    mailbox.addMessage(new imapMessage(spec, mailbox.uidnext++, []));
   });
 }
 
 function setup() {
   // We aren't interested in downloading messages automatically
   Services.prefs.setBoolPref("mail.server.server1.autosync_offline_stores", false);
   Services.prefs.setBoolPref("mail.server.server1.offline_download", true);
   // make small threshhold for mpod so our test messages don't have to be big.
--- a/mailnews/imap/test/unit/test_nsIMsgFolderListenerIMAP.js
+++ b/mailnews/imap/test/unit/test_nsIMsgFolderListenerIMAP.js
@@ -92,32 +92,33 @@ function doUpdateFolder(test)
   else
     do_timeout(1000, function(){doUpdateFolder(test);});
 }
 
 // Adds some messages directly to a mailbox (eg new mail)
 function addMessagesToServer(messages, mailbox, localFolder)
 {
   // For every message we have, we need to convert it to a file:/// URI
+  let specs = [];
   messages.forEach(function (message)
   {
     let URI =
       Services.io.newFileURI(message.file).QueryInterface(Ci.nsIFileURL);
-    message.spec = URI.spec;
+    specs.push(URI.spec);
     // We can't get the headers again, so just pass on the message id
     gExpectedEvents.push([gMFNService.msgAdded, {expectedMessageId: message.messageId}]);
   });
   gExpectedEvents.push([gMFNService.msgsClassified,
                         messages.map(hdr => hdr.messageId),
                         false, false]);
 
   // Create the imapMessages and store them on the mailbox
-  messages.forEach(function (message)
+  specs.forEach(function (spec)
   {
-    mailbox.addMessage(new imapMessage(message.spec, mailbox.uidnext++, []));
+    mailbox.addMessage(new imapMessage(spec, mailbox.uidnext++, []));
   });
 
   // No copy listener notification for this
   gCurrStatus |= kStatus.functionCallDone | kStatus.onStopCopyDone;
 
   gFolderBeingUpdated = localFolder;
   doUpdateFolder(gTest);
 }
--- a/mailnews/imap/test/unit/test_offlineCopy.js
+++ b/mailnews/imap/test/unit/test_offlineCopy.js
@@ -25,31 +25,34 @@ var gMsgId2 = "4A947F73.5030709@example.
 var gMsgFile3 = do_get_file("../../../data/SpamAssassinYes");
 var gMsg3Id = "bugmail7.m47LtAEf007543@mrapp51.mozilla.org";
 var gMsgFile4 = do_get_file("../../../data/bug460636");
 var gMsg4Id = "foo.12345@example";
 
 var gFolder1;
 
 // Adds some messages directly to a mailbox (eg new mail)
-function addMessagesToServer(messages, mailbox, localFolder)
+function addMessagesToServer(messages, mailbox)
 {
   // For every message we have, we need to convert it to a file:/// URI
+  let specs = [];
   messages.forEach(function (message)
   {
-    let URI = Services.io.newFileURI(message.file).QueryInterface(Ci.nsIFileURL);
-    message.spec = URI.spec;
+    let URI =
+      Services.io.newFileURI(message.file).QueryInterface(Ci.nsIFileURL);
+    specs.push(URI.spec);
   });
 
   // Create the imapMessages and store them on the mailbox
-  messages.forEach(function (message)
+  specs.forEach(function (spec)
   {
-    mailbox.addMessage(new imapMessage(message.spec, mailbox.uidnext++, []));
+    mailbox.addMessage(new imapMessage(spec, mailbox.uidnext++, []));
   });
 }
+
 var tests = [
   function *setup() {
     // Turn off autosync_offline_stores because
     // fetching messages is invoked after copying the messages.
     // (i.e. The fetching process will be invoked after OnStopCopy)
     // It will cause crash with an assertion
     // (ASSERTION: tried to add duplicate listener: 'index == -1') on teardown.
     Services.prefs.setBoolPref("mail.server.default.autosync_offline_stores", false);
--- a/mailnews/news/test/unit/test_bug540288.js
+++ b/mailnews/news/test/unit/test_bug540288.js
@@ -55,19 +55,17 @@ function doTestFinished() {
     do_test_finished();
 }
 
 
 function run_test() {
   server = makeServer(NNTP_RFC977_handler, daemon);
   server.start();
   localserver = setupLocalServer(server.port);
-  var uri = Cc["@mozilla.org/network/standard-url;1"]
-              .createInstance(Ci.nsIURI);
-  uri.spec = "news://localhost:" + server.port + "/TSS1%40nntp.test";
+  var uri = Services.io.newURI("news://localhost:" + server.port + "/TSS1%40nntp.test");
 
   try {
     // Add an empty message to the cache
     MailServices.nntp
                 .cacheStorage
                 .asyncOpenURI(uri, "", Ci.nsICacheStorage.OPEN_NORMALLY, {
       onCacheEntryAvailable: function(cacheEntry, isNew, appCache, status) {
         Assert.equal(status, Components.results.NS_OK);