michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: const Ci = Components.interfaces; michael@0: michael@0: function run_test() { michael@0: // throw if anything goes wrong michael@0: michael@0: // find the current directory path michael@0: var file = Components.classes["@mozilla.org/file/directory_service;1"] michael@0: .getService(Ci.nsIProperties) michael@0: .get("CurWorkD", Ci.nsIFile); michael@0: file.append("xpcshell.ini"); michael@0: michael@0: // should be able to construct a file michael@0: var f1 = File(file.path); michael@0: // with either constructor syntax michael@0: var f2 = new File(file.path); michael@0: // and with nsIFiles michael@0: var f3 = File(file); michael@0: var f4 = new File(file); michael@0: michael@0: // do some tests michael@0: do_check_true(f1 instanceof Ci.nsIDOMFile, "Should be a DOM File"); michael@0: do_check_true(f2 instanceof Ci.nsIDOMFile, "Should be a DOM File"); michael@0: do_check_true(f3 instanceof Ci.nsIDOMFile, "Should be a DOM File"); michael@0: do_check_true(f4 instanceof Ci.nsIDOMFile, "Should be a DOM File"); michael@0: michael@0: do_check_true(f1.name == "xpcshell.ini", "Should be the right file"); michael@0: do_check_true(f2.name == "xpcshell.ini", "Should be the right file"); michael@0: do_check_true(f3.name == "xpcshell.ini", "Should be the right file"); michael@0: do_check_true(f4.name == "xpcshell.ini", "Should be the right file"); michael@0: michael@0: do_check_true(f1.type == "", "Should be the right type"); michael@0: do_check_true(f2.type == "", "Should be the right type"); michael@0: do_check_true(f3.type == "", "Should be the right type"); michael@0: do_check_true(f4.type == "", "Should be the right type"); michael@0: michael@0: var threw = false; michael@0: try { michael@0: // Needs a ctor argument michael@0: var f7 = File(); michael@0: } catch (e) { michael@0: threw = true; michael@0: } michael@0: do_check_true(threw, "No ctor arguments should throw"); michael@0: michael@0: var threw = false; michael@0: try { michael@0: // Needs a valid ctor argument michael@0: var f7 = File(Date(132131532)); michael@0: } catch (e) { michael@0: threw = true; michael@0: } michael@0: do_check_true(threw, "Passing a random object should fail"); michael@0: michael@0: var threw = false michael@0: try { michael@0: // Directories fail michael@0: var dir = Components.classes["@mozilla.org/file/directory_service;1"] michael@0: .getService(Ci.nsIProperties) michael@0: .get("CurWorkD", Ci.nsIFile); michael@0: var f7 = File(dir) michael@0: } catch (e) { michael@0: threw = true; michael@0: } michael@0: do_check_true(threw, "Can't create a File object for a directory"); michael@0: }