test_setMozRelativePath.html (1389B)
1 <!DOCTYPE html> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=1973726 5 --> 6 <head> 7 <meta charset="utf-8"> 8 <title>Test for setMozRelativePath</title> 9 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 10 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/> 11 </head> 12 <body> 13 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1973726">Mozilla Bug 1973726</a> 14 <p id="display"></p> 15 <div id="content" style="display: none"></div> 16 <pre id="test"> 17 <script> 18 function createFileWithData(fileData) { 19 var testFile = Services.dirsvc.get("ProfD", Ci.nsIFile); 20 testFile.append("setMozRelativePath"); 21 22 var outStream = 23 Cc["@mozilla.org/network/file-output-stream;1"].createInstance(Ci.nsIFileOutputStream); 24 outStream.init(testFile, 0x02 | 0x08 | 0x20, // write, create, truncate 25 0o666, 0); 26 outStream.write(fileData, fileData.length); 27 outStream.close(); 28 29 return testFile; 30 } 31 32 add_task(async () => { 33 let testFile = createFileWithData("setMozRelativePath"); 34 let file = await File.createFromNsIFile(testFile); 35 36 file.setMozRelativePath("/test/relative/path"); 37 38 // Verify that the relative path was set correctly. 39 is(file.webkitRelativePath, "test/relative/path", 40 "The relative path should match the expected value."); 41 }); 42 </script> 43 </pre> 44 </body> 45 </html>