Bug 1273265 - Test writing zone information for files with long names. r=jimm
authorPaolo Amadini <paolo.mozmail@amadzone.org>
Tue, 31 Oct 2017 14:43:53 +0000
changeset 389356 673af834eacb193873fabaffef1321fc164a2a21
parent 389355 f4d73d76887346106e850ef06d8091d75ba0b29f
child 389357 f8eb20e6a5e56c04952a8517d96710938a9f35f0
push id96844
push userpaolo.mozmail@amadzone.org
push dateTue, 31 Oct 2017 18:47:51 +0000
treeherdermozilla-inbound@673af834eacb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm
bugs1273265
milestone58.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1273265 - Test writing zone information for files with long names. r=jimm MozReview-Commit-ID: 7302E1j7tdq
toolkit/components/jsdownloads/test/unit/common_test_Download.js
toolkit/components/jsdownloads/test/unit/head.js
--- a/toolkit/components/jsdownloads/test/unit/common_test_Download.js
+++ b/toolkit/components/jsdownloads/test/unit/common_test_Download.js
@@ -324,16 +324,68 @@ add_task(async function test_unix_permis
     }
   }
 
   // Clean up the changes to the preference.
   Services.prefs.clearUserPref(kDeleteTempFileOnExit);
 });
 
 /**
+ * Tests the zone information of the final target once the download finished.
+ */
+add_task(async function test_windows_zoneInformation() {
+  // This test is only executed on Windows, and in order to work correctly it
+  // requires the local user applicaton data directory to be on an NTFS file
+  // system. We use this directory because it is more likely to be on the local
+  // system installation drive, while the temporary directory used by the test
+  // environment is on the same drive as the test sources.
+  if (Services.appinfo.OS != "WINNT") {
+    do_print("Skipping test.");
+    return;
+  }
+
+  let normalTargetFile = FileUtils.getFile("LocalAppData",
+                                           ["xpcshell-download-test.txt"]);
+
+  // The template file name lenght is more than MAX_PATH characters. The final
+  // full path will be shortened to MAX_PATH length by the createUnique call.
+  let longTargetFile = FileUtils.getFile("LocalAppData",
+                                         ["T".repeat(256) + ".txt"]);
+  longTargetFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0o600);
+
+  for (let targetFile of [normalTargetFile, longTargetFile]) {
+    try {
+      if (!gUseLegacySaver) {
+        let download = await Downloads.createDownload({
+          source: httpUrl("source.txt"),
+          target: targetFile.path,
+        });
+        await download.start();
+      } else {
+        let download = await promiseStartLegacyDownload(null, { targetFile });
+        await promiseDownloadStopped(download);
+      }
+      await promiseVerifyContents(targetFile.path, TEST_DATA_SHORT);
+
+      // Verify that the Alternate Data Stream has been written.
+      let file = await OS.File.open(targetFile.path + ":Zone.Identifier", {},
+                 { winAllowLengthBeyondMaxPathWithCaveats: true });
+      try {
+        do_check_eq(new TextDecoder().decode(await file.read()),
+                    "[ZoneTransfer]\r\nZoneId=3\r\n");
+      } finally {
+        file.close();
+      }
+    } finally {
+      await OS.File.remove(targetFile.path);
+    }
+  }
+});
+
+/**
  * Checks the referrer for downloads.
  */
 add_task(async function test_referrer() {
   let sourcePath = "/test_referrer.txt";
   let sourceUrl = httpUrl("test_referrer.txt");
   let targetPath = getTempFile(TEST_TARGET_FILE_NAME).path;
 
   function cleanup() {
--- a/toolkit/components/jsdownloads/test/unit/head.js
+++ b/toolkit/components/jsdownloads/test/unit/head.js
@@ -94,17 +94,17 @@ function run_test() {
  */
 var gHttpServer;
 
 /**
  * Given a file name, returns a string containing an URI that points to the file
  * on the currently running instance of the test HTTP server.
  */
 function httpUrl(aFileName) {
-  return "http://localhost:" + gHttpServer.identity.primaryPort + "/" +
+  return "http://www.example.com:" + gHttpServer.identity.primaryPort + "/" +
          aFileName;
 }
 
 /**
  * Returns a reference to a temporary file that is guaranteed not to exist and
  * is cleaned up later. See FileTestUtils.getTempFile for details.
  */
 function getTempFile(leafName) {
@@ -628,16 +628,24 @@ add_task(function test_common_initialize
     return new Promise(resolve => {
       // Ensure all the pending HTTP requests have a chance to finish.
       continueResponses();
       // Stop the HTTP server, calling resolve when it's done.
       gHttpServer.stop(resolve);
     });
   });
 
+  // Serve the downloads from a domain located in the Internet zone on Windows.
+  gHttpServer.identity.setPrimary("http", "www.example.com",
+                                  gHttpServer.identity.primaryPort);
+  Services.prefs.setCharPref("network.dns.localDomains", "www.example.com");
+  do_register_cleanup(function() {
+    Services.prefs.clearUserPref("network.dns.localDomains");
+  });
+
   // Cache locks might prevent concurrent requests to the same resource, and
   // this may block tests that use the interruptible handlers.
   Services.prefs.setBoolPref("browser.cache.disk.enable", false);
   Services.prefs.setBoolPref("browser.cache.memory.enable", false);
   do_register_cleanup(function() {
     Services.prefs.clearUserPref("browser.cache.disk.enable");
     Services.prefs.clearUserPref("browser.cache.memory.enable");
   });