Skip to content

Commit a76a1a0

Browse files
committed
Append nw-quit test case
1 parent a4de9e4 commit a76a1a0

File tree

7 files changed

+348
-0
lines changed

7 files changed

+348
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
exports.init = function(win, nwGui) {
2+
console.log('Setting up close handler');
3+
win.on('close', function(how) {
4+
console.log('Got CLOSE event in close-handler.js with "' + how + '"');
5+
win.hide();
6+
var http = require('http');
7+
http.get("http://localhost:9000/close");
8+
setTimeout(function() {
9+
console.log('Quitting from close handler');
10+
nwGui.App.quit();
11+
}, 5000);
12+
});
13+
};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<html>
2+
<head>
3+
<title>NW Quit Test Server</title>
4+
</head>
5+
<body>
6+
<p>This is a hidden window</p>
7+
<script>
8+
var nwGui = require('nw.gui');
9+
var win = nwGui.Window.get();
10+
var http = require('http');
11+
var method = global.method;
12+
13+
win.on('close', function(how) {
14+
console.log('Ignoring CLOSE event in index-server.html with "' + how + '"');
15+
});
16+
17+
setInterval(function() {
18+
http.get("http://localhost:9000/crontab")
19+
console.log('Server running');
20+
}, 200);
21+
</script>
22+
</body>
23+
</html>
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
<html>
2+
<head>
3+
<title>NW Quit Test</title>
4+
</head>
5+
<body>
6+
<h2 id="method"></h2>
7+
<input type="button" id="doquit" value="Quit">
8+
<script>
9+
var nwGui = require('nw.gui');
10+
var argv = nwGui.App.argv;
11+
12+
if (argv.length <4){
13+
nwGui.App.quit();
14+
} else {
15+
while(argv.length <4){
16+
argv.push(0);
17+
}
18+
}
19+
20+
var methodId = parseInt(argv.shift());
21+
var methodId2Text = function(id){
22+
id = parseInt(id);
23+
switch(id){
24+
case 0:
25+
return "Click Quit Button";
26+
break;
27+
case 1:
28+
return "Click native window red dot.";
29+
break;
30+
case 2:
31+
return "Press COMMAND-Q(MAC ONLY)";
32+
break;
33+
case 3:
34+
return "Press left top system menu node-webkit and click nw-quit.(MAC ONLY)";
35+
break;
36+
}
37+
};
38+
document.getElementById("method").innerHTML = methodId2Text(methodId);
39+
40+
41+
global.method = methodId;
42+
var closerMode = parseInt(argv[0]);
43+
var closeHandlerInNode = closerMode === 0?false:true; // true or false
44+
var splashMode = parseInt(argv[1]);
45+
var showSplashScreen = undefined; // 'close', 'hide', or 'none'
46+
switch(splashMode){
47+
case 0:
48+
showSplashScreen = 'close';
49+
break;
50+
case 1:
51+
showSplashScreen = 'hide';
52+
break;
53+
case 2:
54+
showSplashScreen = 'none';
55+
break;
56+
default:
57+
throw "Invalid splashMode";
58+
break;
59+
}
60+
var serverMode = parseInt(argv[2]);
61+
var startServer = serverMode===0?false:true;// true or false
62+
63+
console.log("<%s,%s,%s,%s>",methodId,closerMode,splashMode,serverMode);
64+
65+
66+
67+
68+
var win = nwGui.Window.get();
69+
70+
if (showSplashScreen === 'close') {
71+
var winSplash = nwGui.Window.open('splash.html');
72+
setTimeout(function() {
73+
console.log('Closing splash window');
74+
winSplash.close();
75+
}, 0);
76+
}
77+
else if (showSplashScreen === 'hide') {
78+
var winSplash = nwGui.Window.open('splash.html');
79+
setTimeout(function() {
80+
console.log('Hiding splash window');
81+
winSplash.hide();
82+
}, 0);
83+
}
84+
85+
if (startServer) {
86+
nwGui.Window.open('index-server.html', {'new-instance': true, show: false});
87+
}
88+
89+
if (closeHandlerInNode) {
90+
var closer = require('./close-handler');
91+
closer.init(win, nwGui);
92+
}
93+
else {
94+
console.log('Setting up close handler');
95+
win.on('close', function(how) {
96+
console.log('Got CLOSE event in index.html with "' + how + '"');
97+
win.hide();
98+
var http = require('http');
99+
http.get("http://localhost:9000/close");
100+
setTimeout(function() {
101+
console.log('Quitting from close handler');
102+
nwGui.App.quit();
103+
}, 2000);
104+
});
105+
}
106+
107+
var testButton = document.getElementById('doquit');
108+
testButton.onclick = function() {
109+
win.close();
110+
};
111+
var http = require('http');
112+
http.get("http://localhost:9000/crontab");//if we disable server, make look as it start
113+
114+
115+
var quitButton = document.getElementById("doquit");
116+
if (methodId === 0){
117+
setTimeout(function(){
118+
quitButton.click();
119+
},1000);
120+
} else {
121+
quitButton.style.display = "none";
122+
}
123+
</script>
124+
</body>
125+
</html>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "nw-quit",
3+
"main": "index.html"
4+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<html>
2+
<body>
3+
<p>Splash screen</p>
4+
</body>
5+
</html>

tests/manual_tests/quit/index.html

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf8">
5+
<title>test</title>
6+
<style type="text/css">
7+
tr{
8+
border-top: solid;
9+
border-bottom: solid;
10+
text-align: center;
11+
}
12+
td{
13+
border-left: solid;
14+
}
15+
</style>
16+
</head>
17+
<body>
18+
<div>
19+
<ol>
20+
<li>Click Quit Button(Automatical)</li>
21+
<li>Click native window red dot.(left top or right top)</li>
22+
<li>Press COMMAND-Q(MAC ONLY)</li>
23+
<li>Press left top system menu node-webkit and click nw-quit.(MAC ONLY)</li>
24+
</ol>
25+
</div>
26+
27+
<div>
28+
<table id="result">
29+
<thead>
30+
<tr>
31+
<td>Method</td>
32+
<td>closeHandlerInNode</td>
33+
<td>showSplashScreen</td>
34+
<td>startServer</td>
35+
<td>Result</td>
36+
</tr>
37+
</thead>
38+
<tbody id="result-body">
39+
</tbody>
40+
</table>
41+
</div>
42+
<script type="text/javascript">
43+
var os = require('os');
44+
var url = require('url');
45+
var http = require('http');
46+
var spawn = require('child_process').spawn;
47+
var resultFlag = 0;
48+
49+
var caseIndex = 1;
50+
var methodIndex = 0;
51+
var casesArgs = [
52+
[0,0,2],//false,none,true
53+
[1,0,0],//true,close,false
54+
[0,0,0],//false,close,false
55+
];
56+
57+
var updateStatus = function(pathname,query){
58+
if (pathname === '/crontab'){
59+
if (resultFlag === 0){
60+
resultFlag = 1;
61+
return;
62+
} else if (resultFlag === 2){
63+
resultFlag = 3;
64+
return;
65+
}
66+
} else if (pathname === "/close"){
67+
if (resultFlag === 1){
68+
resultFlag = 2;
69+
return;
70+
}
71+
}
72+
console.log("RESULT FLAG:"+resultFlag);
73+
};
74+
75+
var resultBody = document.getElementById('result-body');
76+
var methodId2Text = function(id){
77+
id = parseInt(id);
78+
switch(id){
79+
case 0:
80+
return "Click Quit Button";
81+
break;
82+
case 1:
83+
return "Click native window red dot.";
84+
break;
85+
case 2:
86+
return "Press COMMAND-Q(MAC ONLY)";
87+
break;
88+
case 3:
89+
return "Press left top system menu node-webkit and click nw-quit.(MAC ONLY)";
90+
break;
91+
}
92+
};
93+
var generateView = function(){
94+
var row = document.createElement("tr");
95+
var methodText = methodId2Text(methodIndex);
96+
var currentArgs = casesArgs[caseIndex].slice();
97+
var closerText = (parseInt(currentArgs[0]) === 0?false:true)+"";
98+
var splashMode = parseInt(currentArgs[1]);
99+
var splashText = undefined;
100+
switch(splashMode){
101+
case 0:
102+
splashText = "close";
103+
break;
104+
case 1:
105+
splashText = "none";
106+
break;
107+
case 2:
108+
splashText = "hide";
109+
break;
110+
}
111+
var serverText = (parseInt(currentArgs[2])==0?false:true)+"";
112+
113+
var resultText = undefined;
114+
if (resultFlag === 3){
115+
resultText = "SUCCESS";
116+
} else {
117+
resultText = "FAIL"
118+
}
119+
resultFlag = 0;
120+
121+
var rowHTML =
122+
"<tr> <td class='Method'>"+methodText+"</td> <td class='closeHandlerInNode'>"+closerText+"</td> <td class='showSplashScreen'>"+splashText+"</td> <td class='startServer'>"+serverText+"</td> <td class='Result'>"+resultText+"</td></tr>";
123+
resultBody.innerHTML += rowHTML;
124+
return;
125+
};
126+
var server = http.createServer(function(req,res){
127+
var location = url.parse(req.url,true);
128+
var pathname = location.pathname;
129+
var query = location.query;
130+
updateStatus(pathname,query);
131+
res.end();
132+
});
133+
server.listen(9000,function(){
134+
console.log("Result server is running on localhost:9000");
135+
});
136+
137+
var appNum = 2;
138+
if (os.platform() === 'darwin'){
139+
appNum = 3;//the last method should launch manual, could not as a child process.
140+
caseIndex = 0;//only mac need the first row args
141+
}
142+
143+
144+
145+
var next = function(){
146+
var args = casesArgs[caseIndex];
147+
if (args){
148+
args = args.slice();
149+
} else {
150+
return;
151+
}
152+
if (methodIndex < appNum){
153+
args.unshift(methodIndex);
154+
args.unshift("app");
155+
var app = spawn(process.execPath,args);
156+
app.on("exit",function(code,signal){
157+
generateView();
158+
++methodIndex;
159+
next();
160+
});
161+
} else {
162+
++caseIndex;
163+
methodIndex = 0;
164+
next();
165+
}
166+
}
167+
168+
169+
next();
170+
</script>
171+
</body>
172+
</html>
173+

tests/manual_tests/quit/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name":"test",
3+
"main":"index.html",
4+
"dependencies":{}
5+
}

0 commit comments

Comments
 (0)