在上一篇 中出现了一个问题,就是用 jsunit2.2alpha11.zip 包进行测试时,在firefox、safari 上不能进行测试,无法访问本地系统文件,经过在网上查找,发现了解决问题的办法,解决的原文如下:
2009年9月23日
Tried having a bash with
jsUnit today, and got instantly stuck when trying to run a basic test case.
FireFox simply hung, and I really had no idea why. For the first time, IE8 worked fine!
Thanks to
this post , it was straightforward enough to get working.
First you have to modify the
jsUnit TestManager.js file, and replace/insert the following code:
function isFF3() {
return (
navigator.userAgent.toLowerCase ().indexOf ("iceweasel/3" ) != -1 ||
navigator.userAgent.toLowerCase ().indexOf ("firefox/3" ) != -1
)
}
function browserSupportsReadingFullPathFromFileField() {
return !isOpera() && !isIE7() && !isFF3();
//return !isOpera() && !isIE7();
}
Secondly, you'll have to disable the draconian security that new FF introduces. Type about:config in your address bar and then set
security.fileuri.strict_origin_policy to false . This will allow FireFox to access local resources without a problem.
Now it will have disabled the browse to field, so the only way you can run your tests is directly via the address bar, as so:
<path to testrunner.html>?testpage=<path to mytests.html>
大概意思是:
首先,你必须修改jsUnitTestManager.js文件,并替换/插入下面的代码
function browserSupportsReadingFullPathFromFileField() {
return !isOpera() && !isIE7() && !isFF3();
//return !isOpera() && !isIE7();
}
function isFF3() {
return (
navigator.userAgent.toLowerCase().indexOf("iceweasel/3") != -1 ||
navigator.userAgent.toLowerCase().indexOf("firefox/3") != -1
)
}
其次,修改firefox的配置,打开ff3,在地址栏输入about:config,搜索security.fileuri.strict_origin_policy,双击就可修改,如下图:
修改完成后,我们重新来运行的测试
注:上面不是用jsunit的插件运行的,如果用插件运行的话,又报以下错误,唉~现还不知道如何解决,忘高手指点。
以上这样改后,firefox3可以通过测,但发现 safari 还是通不过,于是干脆把以上脚本作如下修改:
function browserSupportsReadingFullPathFromFileField() {
return false;
//return !isOpera() && !isIE7() && !isFF3();
//return !isOpera() && !isIE7();
}
再测试时发现可以了:
但还是遗憾的是 jsunit 插件 在ff3 safari 运行不起来。先留在这里以后解决吧~!