Skip to content

Commit 068a8a4

Browse files
committed
test case for setting file input value
1 parent 008d981 commit 068a8a4

File tree

5 files changed

+61
-1
lines changed

5 files changed

+61
-1
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>
5+
test setting file input value
6+
</title>
7+
</head>
8+
<body>
9+
<input id = 'input0' type = 'file'/>
10+
<script type="text/javascript">
11+
var gui = require('nw.gui');
12+
var win = gui.Window.get();
13+
var path = require('path');
14+
win.on('loaded',function(){
15+
try{
16+
var f = new File(global.tests_dir+'filevalue/testfile', 'mytestfile');
17+
var files = new FileList();
18+
files.append(f);
19+
document.getElementById('input0').files = files;
20+
} catch(er){
21+
console.log(er);
22+
} finally{
23+
var info = 'wrong';
24+
if(document.getElementById('input0').files[0] != null)
25+
info = document.getElementById('input0').files[0].name;
26+
var client = require('../../nw_test_app').createClient({
27+
argv : gui.App.argv,
28+
data : info,
29+
})
30+
}
31+
})
32+
</script>
33+
</body>
34+
</html>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
var app_test = require('./nw_test_app');
2+
var path = require('path');
3+
4+
describe('file input',function(){
5+
describe('set value',function(){
6+
it('the value should be set without exception',function(done){
7+
this.timeout(0);
8+
var child = app_test.createChildProcess({
9+
execPath : process.execPath,
10+
appPath : path.join(global.tests_dir, 'filevalue'),
11+
end: function(data, app){
12+
app.kill();
13+
if (data == 'mytestfile')
14+
done();
15+
else
16+
done('the value of the file input is not set correctly');
17+
}
18+
})
19+
})
20+
})
21+
})
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name":"nw-file-input-value",
3+
"main":"index.html"
4+
}

tests/automatic_tests/filevalue/testfile

Whitespace-only changes.

tests/automatic_tests/user-agent-app/mocha_test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ describe('user-agent-app', function() {
1414
end: function(data, app) {
1515
result = true;
1616
var package_info = JSON.parse(fs.readFileSync('package.json', 'utf8'));
17-
if (data == package_info.name) {
17+
app.kill();
18+
if (data == package_info.name) {
1819
done();
1920
}
2021
else{

0 commit comments

Comments
 (0)