Skip to content

Commit ff42fb8

Browse files
committed
add new test case "window-eval":
1 parent a2b14c7 commit ff42fb8

File tree

6 files changed

+110
-0
lines changed

6 files changed

+110
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>window eval test</title>
6+
</head>
7+
<body>
8+
<p>window eval test</p>
9+
10+
<script src="../res/mocha_util.js"></script>
11+
<script src="mocha_test.js"></script>
12+
13+
</body>
14+
15+
</html>
16+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf8">
5+
<title>test</title>
6+
</head>
7+
<body>
8+
<h1>iframe</h1>
9+
<script type="text/javascript">
10+
var iframe_window_flag = false;
11+
</script>
12+
</body>
13+
</html>
14+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf8">
5+
<title>test</title>
6+
</head>
7+
<body>
8+
<h1>it works!</h1>
9+
<iframe id="iframe" src="iframe.html"></iframe>
10+
<script type="text/javascript">
11+
var gui = require('nw.gui');
12+
var port = gui.App.argv[0]||13013;
13+
var result = 'fail';
14+
var local_window_flag = false;
15+
var win = gui.Window.get();
16+
win.eval(null,"local_window_flag = true;");
17+
var iframe = document.getElementById('iframe');
18+
iframe.onload = function(){
19+
win.eval(iframe,"iframe_window_flag = true;")
20+
setTimeout(function(){
21+
var iframe_window_flag = iframe.contentWindow.iframe_window_flag;
22+
if (local_window_flag && iframe_window_flag){
23+
result = 'success';
24+
}
25+
26+
var socket = require('net').connect({port: 13013});
27+
socket.setEncoding('utf8');
28+
socket.end(result);
29+
30+
},1000)
31+
};
32+
</script>
33+
</body>
34+
</html>
35+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name":"nw_1403254112",
3+
"main":"index.html",
4+
"dependencies":{}
5+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
var path = require('path');
2+
var assert = require('assert');
3+
var fs = require('fs-extra');
4+
var curDir = fs.realpathSync('.');
5+
6+
7+
describe('Window.eval',function(){
8+
var server, child, result;
9+
10+
before(function(done) {
11+
this.timeout(0);
12+
server = createTCPServer(13013);
13+
child = spawnChildProcess(path.join(curDir, 'internal'));
14+
server.on('connection', function(socket) {
15+
socket.setEncoding('utf8');
16+
socket.on('data', function(data) {
17+
result = (data.toString() == "success");
18+
child.kill();
19+
done();
20+
});
21+
});
22+
23+
});
24+
25+
after(function () {
26+
server.close();
27+
});
28+
29+
it("Window.eval should works",function(done){
30+
assert.equal(result,true);
31+
done();
32+
});
33+
});
34+
35+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name":"window_eval_wrapper",
3+
"main":"index.html"
4+
}
5+

0 commit comments

Comments
 (0)