Bug 381499 - Components.utils.import reports NS_ERROR_FAILURE when the file not exists

switch to NS_ERROR_FILE_NOT_FOUND and update tests
r=sayrer, sr=brendan


git-svn-id: svn://10.0.0.236/trunk@227675 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
asqueella%gmail.com 2007-06-07 22:34:06 +00:00
parent a9271269d5
commit daf644428e
3 changed files with 22 additions and 13 deletions

View File

@ -1421,7 +1421,7 @@ mozJSComponentLoader::ImportInto(const nsACString & aLocation,
&newEntry->location);
if (NS_FAILED(rv)) {
*_retval = nsnull;
return NS_ERROR_FAILURE;
return NS_ERROR_FILE_NOT_FOUND;
}
mod = newEntry;

View File

@ -36,22 +36,26 @@
*
* ***** END LICENSE BLOCK ***** */
function test_BrokenFile(path, shouldThrow) {
var f = do_get_file(path);
function test_BrokenFile(path, shouldThrow, expectedName) {
var f = do_get_file(path, true);
var uri = "abs:" + f.path;
print(uri);
var didThrow = false;
var didThrow;
try {
Components.utils.import(uri);
Components.utils.import(uri);
} catch (ex) {
print("ex: " + ex);
didThrow = true;
var exceptionName = ex.name;
print("ex: " + ex + "; name = " + ex.name);
didThrow = true;
}
do_check_true(didThrow == shouldThrow);
do_check_eq(didThrow, shouldThrow);
if (didThrow)
do_check_eq(exceptionName, expectedName);
}
function run_test() {
test_BrokenFile("js/src/xpconnect/tests/unit/bogus_exports_type.jsm", true);
test_BrokenFile("js/src/xpconnect/tests/unit/bogus_element_type.jsm", true);
test_BrokenFile("js/src/xpconnect/tests/unit/bogus_exports_type.jsm", true, "Error");
test_BrokenFile("js/src/xpconnect/tests/unit/bogus_element_type.jsm", true, "Error");
test_BrokenFile("js/src/xpconnect/tests/unit/non_existing.jsm", true, "NS_ERROR_FILE_NOT_FOUND");
}

View File

@ -142,7 +142,7 @@ function do_import_script(topsrcdirRelativePath) {
load(scriptPath);
}
function do_get_file(path) {
function do_get_file(path, allowInexistent) {
var comps = path.split("/");
try {
// The following always succeeds on Windows because we use cygpath with
@ -168,7 +168,12 @@ function do_get_file(path) {
lf.append(comps[i]);
}
do_check_true(lf.exists());
if (!allowInexistent) {
if (!lf.exists()) {
print(lf.path + " doesn't exist\n");
}
do_check_true(lf.exists());
}
return lf;
}