Skip to content

Commit 17fbb85

Browse files
committed
add new test caset "snapshot"
1 parent 954bd08 commit 17fbb85

File tree

11 files changed

+1698
-0
lines changed

11 files changed

+1698
-0
lines changed

tests/automation/snapshot/index.html

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>snapshort test</title>
6+
</head>
7+
<body>
8+
<p>snapshort 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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
var sampleFunction;
2+
3+
(function()
4+
{
5+
var privateVar = 'private';
6+
7+
sampleFunction = function()
8+
{
9+
return privateVar+'67868';
10+
};
11+
})();
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>snapshot test</title>
6+
<style>
7+
#content
8+
{
9+
font:10px Verdana;
10+
}
11+
</style>
12+
</head>
13+
<body>
14+
<div id="content">Data...</div>
15+
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
16+
<script src="script.js"></script>
17+
<script>
18+
var fs = require('fs');
19+
fs.openSync('./tmp', 'w')
20+
setTimeout(function() {
21+
var gui = require('nw.gui');
22+
gui.App.quit();
23+
}, 2000);
24+
</script>
25+
</body>
26+
</html>

tests/automation/snapshot/internal/1266-snapshot-crash-start/isolate-0x1f73bd0-v8.log

Lines changed: 1480 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "nw-demo",
3+
"main": "index.html",
4+
"snapshot" : "app.bin"
5+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
$(document).ready(function()
2+
{
3+
$('#content').html(sampleFunction());
4+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<html><head>
2+
<title>snapshot demo</title>
3+
</head>
4+
<body>
5+
6+
<script src="mytest.js"></script>
7+
<script>
8+
mytest(2);
9+
</script>
10+
</body></html>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function mytest(a) {
2+
document.write(a + 42);
3+
4+
var gui = require('nw.gui');
5+
var result = { ok: true };
6+
7+
var socket = require('net').connect({port: 13013});
8+
socket.setEncoding('utf8');
9+
socket.end(JSON.stringify(result));
10+
11+
12+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "nw-demo",
3+
"main": "index.html",
4+
"snapshot": "mytest.bin"
5+
}
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
var path = require('path');
2+
var os = require('os');
3+
var fs = require('fs-extra');
4+
var cp = require('child_process');
5+
var curDir = fs.realpathSync('.');
6+
7+
var myTestJSPath = path.join(curDir, 'internal', 'mytest.js');
8+
var myTestBinPath = path.join(curDir, 'internal', 'mytest.bin');
9+
10+
var snapshotPath;
11+
var server;
12+
13+
describe('snapshot', function() {
14+
15+
/////////// 1
16+
17+
describe('demo should work fine', function() {
18+
before(function(done) {
19+
var snapshotExec;
20+
if (os.platform() == 'darwin') {
21+
snapshotExec = '../../../../../../nwsnapshot';
22+
}
23+
if (os.platform() == 'linux') {
24+
snapshotExec = 'nwsnapshot';
25+
}
26+
if (os.platform() == 'win32') {
27+
snapshotExec = 'nwsnapshot.exe';
28+
}
29+
30+
snapshotPath = path.join(process.execPath, '..', snapshotExec);
31+
console.log("snapshotPath: " + snapshotPath);
32+
33+
cp.execFile(snapshotPath,
34+
['--extra_code', myTestJSPath, myTestBinPath],
35+
{cwd: curDir},
36+
function (error, stdout, stderr) {
37+
38+
server = createTCPServer(13013);
39+
40+
done();
41+
}
42+
);
43+
44+
});
45+
46+
after(function() {
47+
fs.unlink(myTestBinPath, function(err) {if(err && err.code !== 'ENOENT') throw err});
48+
fs.unlink(path.join(curDir, 'internal', 'v8.log'), function(err) {if(err && err.code !== 'ENOENT') throw err});
49+
server.close();
50+
});
51+
52+
it('the native code could be exectuted',
53+
function(done) {
54+
this.timeout(0);
55+
var result = false;
56+
57+
58+
var child = spawnChildProcess(path.join(curDir, 'internal'));
59+
server.on('connection', function(socket) {
60+
socket.setEncoding('utf8');
61+
socket.on('data', function(data) {
62+
result = true;
63+
child.kill();
64+
done();
65+
});
66+
});
67+
68+
69+
setTimeout(function(){
70+
if (!result) {
71+
done('the native code does not been executed');
72+
child.close();
73+
//child.removeConnection();
74+
//child.app.kill();
75+
}
76+
}, 3000);
77+
//child.app.stderr.on('data', function(d){ console.log ('app' + d);});
78+
79+
});
80+
});
81+
82+
83+
////////////////// 2
84+
85+
86+
describe('1266-snapshot-crash-start', function() {
87+
before(function(done) {
88+
cp.execFile(snapshotPath,
89+
['--extra_code', 'file_to_snapshot_to_app.bin.js', 'app.bin'],
90+
{cwd: path.join(curDir, 'internal', '1266-snapshot-crash-start')},
91+
function (error, stdout, stderr) {
92+
done();
93+
}
94+
95+
);
96+
});
97+
98+
after(function() {
99+
fs.unlink(path.join(curDir, 'internal','1266-snapshot-crash-start', 'app.bin'), function(err) {if(err && err.code !== 'ENOENT') throw err});
100+
fs.unlink(path.join(curDir, 'internal','1266-snapshot-crash-start', 'v8.log'), function(err) {if(err && err.code !== 'ENOENT') throw err});
101+
fs.unlink(path.join(curDir, 'internal','1266-snapshot-crash-start','tmp'), function(err) {if(err && err.code !== 'ENOENT') throw err});
102+
});
103+
104+
it('another demo should close nomally', function(done) {
105+
this.timeout(0);
106+
var ppath = process.execPath + " " + path.join(curDir, 'internal', '1266-snapshot-crash-start');
107+
cp.exec(ppath, function(err, stdout, stderr) {
108+
});
109+
setTimeout(function(){
110+
fs.exists(path.join(curDir, 'internal', '1266-snapshot-crash-start', 'tmp'), function(exists) {
111+
if (exists)
112+
done();
113+
else
114+
done('another demo fails');
115+
});
116+
}, 3000);
117+
});
118+
});
119+
120+
121+
122+
});
123+
124+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name":"snapshort_wrapper",
3+
"main":"index.html"
4+
}
5+

0 commit comments

Comments
 (0)