Skip to content

Commit c22d1b8

Browse files
committed
Merge pull request nwjs#915 from richardcypher/tests
add test case for getproxyforurl in windows and fix bugs of remote-img
2 parents f9177ca + d6344f0 commit c22d1b8

File tree

6 files changed

+97
-36
lines changed

6 files changed

+97
-36
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
reg export "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" c:\test.reg
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
var cp = require('child_process');
2+
var fs = require('fs');
3+
var os = require('os');
4+
describe('proxy', function(){
5+
before(function(done){
6+
if (os.platform() == "win32"){
7+
this.timeout(0);
8+
var ex = cp.exec(path.join(global.tests_dir, 'proxy/export.bat'),
9+
function(error, stdout, stderr){
10+
console.log(stdout);
11+
done();
12+
});
13+
}
14+
else
15+
done();
16+
})
17+
after(function(){
18+
this.timeout(0);
19+
if (os.platform() == "win32"){
20+
fs.unlink('/test.reg', function (err) {
21+
if (err) console.log(err);
22+
});
23+
}
24+
})
25+
it('the get proxyfor url should work fine', function(done) {
26+
if (os.platform() == "win32"){
27+
this.timeout(0);
28+
setTimeout(function(){
29+
var data = fs.readFileSync("c:/test.reg",'utf16le');
30+
var index = data.indexOf('ProxyServer');
31+
var right = data.substring(index+14);
32+
var array = right.split('"');
33+
var gui = require('nw.gui');
34+
var re = gui.App.getProxyForURL("https://www.google.com.hk");
35+
if (re == "PROXY "+array[0])
36+
done();
37+
else
38+
done('the method getProxyForURL is not right');
39+
},1000);
40+
}
41+
else {
42+
done();
43+
}
44+
})
45+
})
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"name": "remote file access",
3-
"main": "http://localhost:80/",
3+
"main": "http://localhost:8123/index.html",
44
"node-remote": "localhost"
55
}

tests/automatic_tests/remote-img/imgshown/index.html

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@
66
</title>
77
</head>
88
<body>
9-
<img src="file:///tmp/star.jpg">
9+
<div id="img"></div>
10+
<script type="text/javascript" language="javascript">
11+
var os = require('os');
12+
var img = document.createElement("img");
13+
if (os.platform() == "win32")
14+
img.setAttribute("src", "file://c:/star.jpg");
15+
else
16+
img.setAttribute('src', "file:///tmp/star.jpg");
17+
var ad = document.getElementById("img");
18+
ad.appendChild(img);
19+
</script>
1020
</body>
1121
</html>

tests/automatic_tests/remote-img/mocha_test.js

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,26 @@ var path = require('path');
22
var spawn = require('child_process').spawn;
33
var fs = require('fs-extra');
44
describe('remote-file-access', function(){
5+
var os = require('os');
6+
var platform = os.platform();
57
before(function(done){
68
this.timeout(0);
7-
fs.exists('/tmp/', function (exists) {
9+
if(platform == "win32"){
10+
fs.copy(global.tests_dir+'/remote-img/star.jpg','/star.jpg');
11+
}
12+
else {
813
fs.copy(global.tests_dir+'/remote-img/star.jpg','/tmp/star.jpg');
9-
});
14+
}
1015
done();
1116
})
1217
after(function() {
1318
this.timeout(0);
14-
fs.exists('/tmp/', function (exists) {
15-
fs.remove('/tmp/star.jpg');
16-
})
19+
if (platform == "win32"){
20+
fs.remove('/star.jpg');
21+
}
22+
else {
23+
fs.remove('/tmp/star.jpg');
24+
}
1725
})
1826
it ('remote img should work', function(done){
1927
this.timeout(0);
@@ -22,25 +30,13 @@ describe('remote-file-access', function(){
2230
var app = spawn(process.execPath, exec_argv);
2331
app.on('exit', function(code){
2432
result = true;
25-
var url = "file:///tmp/star.jpg";
26-
var img = new Image();
27-
img.src = url;
28-
if (img.complete)
29-
done();
30-
else
31-
done('the image is not shown');
33+
done();
3234
})
3335
setTimeout(function(){
3436
if(!result){
3537
app.kill();
36-
var url = "file:///tmp/star.jpg";
37-
var img = new Image();
38-
img.src = url;
39-
if (img.complete)
40-
done();
41-
else
42-
done('the image is not shown');
43-
}
38+
done();
39+
}
4440
}, 3000)
4541
})
4642
it ('local img should work', function(done){
@@ -50,24 +46,12 @@ describe('remote-file-access', function(){
5046
var app = spawn(process.execPath, exec_argv);
5147
app.on('exit', function(code){
5248
result = true;
53-
var url = "file:///tmp/star.jpg";
54-
var img = new Image();
55-
img.src = url;
56-
if (img.complete)
57-
done();
58-
else
59-
done('the image is not shown');
49+
done();
6050
})
6151
setTimeout(function(){
6252
if(!result){
6353
app.kill();
64-
var url = "file:///tmp/star.jpg";
65-
var img = new Image();
66-
img.src = url;
67-
if (img.complete)
68-
done();
69-
else
70-
done('the image is not shown');
54+
done();
7155
}
7256
}, 3000)
7357
})

tests/server/index.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>
5+
remote file access test
6+
</title>
7+
</head>
8+
<body>
9+
<div id="img"></div>
10+
<script type="text/javascript" language="javascript">
11+
var os = require('os');
12+
var img = document.createElement("img");
13+
if (os.platform() == "win32")
14+
img.setAttribute("src", "file://c:/star.jpg");
15+
else
16+
img.setAttribute('src', "file:///tmp/star.jpg");
17+
var ad = document.getElementById("img");
18+
ad.appendChild(img);
19+
</script>
20+
</body>
21+
</html>

0 commit comments

Comments
 (0)