Bug 1014046 - Project Editor: Re-enable tests on Windows. r=harth
authorBrian Grinstead <bgrinstead@mozilla.com>
Fri, 20 Jun 2014 16:26:00 -0400
changeset 190646 92a4b7143c827133fc544ce6982caa5382f2b14c
parent 190645 838aa70f96c0a17fa37b4571409af4c72b89de30
child 190647 7d9d619896bf378f4c7df8cce717ed70d7c87dee
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersharth
bugs1014046
milestone33.0a1
Bug 1014046 - Project Editor: Re-enable tests on Windows. r=harth
browser/devtools/projecteditor/test/browser.ini
browser/devtools/projecteditor/test/head.js
--- a/browser/devtools/projecteditor/test/browser.ini
+++ b/browser/devtools/projecteditor/test/browser.ini
@@ -1,10 +1,9 @@
 [DEFAULT]
-skip-if = os == "win" && !debug # Bug 1014046
 subsuite = devtools
 support-files =
   head.js
   helper_homepage.html
 
 [browser_projecteditor_app_options.js]
 [browser_projecteditor_delete_file.js]
 [browser_projecteditor_editing_01.js]
--- a/browser/devtools/projecteditor/test/head.js
+++ b/browser/devtools/projecteditor/test/head.js
@@ -116,49 +116,49 @@ function buildTempDirectoryStructure() {
 
   FileUtils.getDir("TmpD", ["ProjectEditor", "css"], true);
   FileUtils.getDir("TmpD", ["ProjectEditor", "data"], true);
   FileUtils.getDir("TmpD", ["ProjectEditor", "img", "icons"], true);
   FileUtils.getDir("TmpD", ["ProjectEditor", "js"], true);
 
   let htmlFile = FileUtils.getFile("TmpD", ["ProjectEditor", "index.html"]);
   htmlFile.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE);
-  writeToFile(htmlFile, [
+  writeToFileSync(htmlFile, [
     '<!DOCTYPE html>',
     '<html lang="en">',
     ' <head>',
     '   <meta charset="utf-8" />',
     '   <title>ProjectEditor Temp File</title>',
     '   <link rel="stylesheet" href="style.css" />',
     ' </head>',
     ' <body id="home">',
     '   <p>ProjectEditor Temp File</p>',
     ' </body>',
     '</html>'].join("\n")
   );
 
   let readmeFile = FileUtils.getFile("TmpD", ["ProjectEditor", "README.md"]);
   readmeFile.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE);
-  writeToFile(readmeFile, [
+  writeToFileSync(readmeFile, [
     '## Readme'
     ].join("\n")
   );
 
   let licenseFile = FileUtils.getFile("TmpD", ["ProjectEditor", "LICENSE"]);
   licenseFile.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE);
-  writeToFile(licenseFile, [
+  writeToFileSync(licenseFile, [
    '/* This Source Code Form is subject to the terms of the Mozilla Public',
    ' * License, v. 2.0. If a copy of the MPL was not distributed with this',
    ' * file, You can obtain one at http://mozilla.org/MPL/2.0/. */'
     ].join("\n")
   );
 
   let cssFile = FileUtils.getFile("TmpD", ["ProjectEditor", "css", "styles.css"]);
   cssFile.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE);
-  writeToFile(cssFile, [
+  writeToFileSync(cssFile, [
     'body {',
     ' background: red;',
     '}'
     ].join("\n")
   );
 
   FileUtils.getFile("TmpD", ["ProjectEditor", "js", "script.js"]).createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE);
 
@@ -186,16 +186,39 @@ function writeToFile(file, data) {
   NetUtil.asyncCopy(istream, ostream, function(status) {
     if (!Components.isSuccessCode(status)) {
       // Handle error!
       info("ERROR WRITING TEMP FILE", status);
     }
   });
 }
 
+// This is used when setting up the test.
+// You should typically use the async version of this, writeToFile.
+// https://developer.mozilla.org/en-US/Add-ons/Code_snippets/File_I_O#More
+function writeToFileSync(file, data) {
+  // file is nsIFile, data is a string
+  var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"].
+                 createInstance(Components.interfaces.nsIFileOutputStream);
+
+  // use 0x02 | 0x10 to open file for appending.
+  foStream.init(file, 0x02 | 0x08 | 0x20, 0666, 0);
+  // write, create, truncate
+  // In a c file operation, we have no need to set file mode with or operation,
+  // directly using "r" or "w" usually.
+
+  // if you are sure there will never ever be any non-ascii text in data you can
+  // also call foStream.write(data, data.length) directly
+  var converter = Components.classes["@mozilla.org/intl/converter-output-stream;1"].
+                  createInstance(Components.interfaces.nsIConverterOutputStream);
+  converter.init(foStream, "UTF-8", 0, 0);
+  converter.writeString(data);
+  converter.close(); // this closes foStream
+}
+
 function getTempFile(path) {
   let parts = ["ProjectEditor"];
   parts = parts.concat(path.split("/"));
   return FileUtils.getFile("TmpD", parts);
 }
 
 // https://developer.mozilla.org/en-US/Add-ons/Code_snippets/File_I_O#Writing_to_a_file
 function* getFileData(path) {