1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/base/test/chrome/test_fileconstructor.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,79 @@ 1.4 +<?xml version="1.0"?> 1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?> 1.6 +<?xml-stylesheet 1.7 + href="chrome://mochikit/content/tests/SimpleTest/test.css" 1.8 + type="text/css"?> 1.9 +<!-- 1.10 +https://bugzilla.mozilla.org/show_bug.cgi?id=607114.xul 1.11 +--> 1.12 +<window title="Mozilla Bug 607114" 1.13 + xmlns:html="http://www.w3.org/1999/xhtml" 1.14 + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 1.15 + 1.16 + <script type="application/javascript" 1.17 + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 1.18 + 1.19 +<body xmlns="http://www.w3.org/1999/xhtml"> 1.20 +<a target="_blank" 1.21 + href="https://bugzilla.mozilla.org/show_bug.cgi?id=607114"> 1.22 + Mozilla Bug 607114</a> 1.23 +<p id="display"></p> 1.24 +<div id="content" style="display: none"> 1.25 + 1.26 +</div> 1.27 +<pre id="test"> 1.28 +</pre> 1.29 +</body> 1.30 + 1.31 +<script class="testbody" type="application/javascript"> 1.32 +<![CDATA[ 1.33 + 1.34 +/** Test for Bug 607114 **/ 1.35 + 1.36 +var file = Components.classes["@mozilla.org/file/directory_service;1"] 1.37 + .getService(Components.interfaces.nsIProperties) 1.38 + .get("CurWorkD", Components.interfaces.nsIFile); 1.39 + 1.40 +// man I wish this were simpler ... 1.41 +file.append("chrome"); 1.42 +file.append("content"); 1.43 +file.append("base"); 1.44 +file.append("test"); 1.45 +file.append("chrome"); 1.46 +file.append("fileconstructor_file.png"); 1.47 + 1.48 +doTest(new File(file.path)); 1.49 +doTest(new File(file)); 1.50 +function doTest(domfile) { 1.51 + ok(domfile instanceof File, "File() should return a File"); 1.52 + is(domfile.type, "image/png", "File should be a PNG"); 1.53 + is(domfile.size, 95, "File has size 95 (and more importantly we can read it)"); 1.54 +} 1.55 + 1.56 +try { 1.57 + var boomfile = new File(); 1.58 + ok(false, "This should never be reached!"); 1.59 +} catch (e) { 1.60 + ok(true, "Botched file constructor attempts throw and do not crash."); 1.61 +} 1.62 + 1.63 +try { 1.64 + var nonexistentfile = new File("i/sure/hope/this/does/not/exist/anywhere.txt"); 1.65 + ok(false, "This should never be reached!"); 1.66 +} catch (e) { 1.67 + ok(true, "Attempt to construct a non-existent file should fail."); 1.68 +} 1.69 + 1.70 +try { 1.71 + var dir = Components.classes["@mozilla.org/file/directory_service;1"] 1.72 + .getService(Components.interfaces.nsIProperties) 1.73 + .get("CurWorkD", Components.interfaces.nsIFile); 1.74 + var dirfile = new File(dir); 1.75 + ok(false, "This should never be reached!"); 1.76 +} catch (e) { 1.77 + ok(true, "Attempt to construct a file from a directory should fail."); 1.78 +} 1.79 +]]> 1.80 +</script> 1.81 + 1.82 +</window>