Skip to content

Commit 4d20ee9

Browse files
committed
Merge pull request nwjs#954 from kingFighter/window
Test case for nwjs#948:
2 parents 008d981 + 445fb69 commit 4d20ee9

File tree

5 files changed

+119
-0
lines changed

5 files changed

+119
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Test Case for 'Window.focus'</title>
6+
<script>
7+
var gui = require('nw.gui');
8+
var win = gui.Window.get();
9+
var win_c = new Array();
10+
var win2_clicked = false, win1_clicked = false;
11+
12+
for (var i = 0; i < 3; i++)
13+
win_c[i] = 0;
14+
15+
localStorage.win1 = 0;
16+
17+
var win1 = gui.Window.open('index1.html', {
18+
'new-instance': true
19+
});
20+
21+
var win2 = gui.Window.open('index2.html');
22+
23+
win.on('focus', function() {
24+
console.log('win');
25+
win_c[0]++;
26+
});
27+
28+
win2.on('focus', function() {
29+
console.log('win2');
30+
win_c[2]++;
31+
win2_clicked = true;
32+
});
33+
34+
function focus1() {
35+
win1_clicked = true;
36+
win_c[1] = localStorage.win1;
37+
}
38+
39+
function done() {
40+
if (win1_clicked && win2_clicked) {
41+
var client = require('../../nw_test_app').createClient({
42+
argv: gui.App.argv,
43+
data: win_c
44+
});
45+
} else
46+
setTimeout(done, 2000);
47+
}
48+
49+
done();
50+
</script>
51+
</head>
52+
<body>
53+
<p id="wait" style="font-size:1.5em">For now you should manually click the button to test the case</p>
54+
<button onclick="focus1()">You should click this only after you focused win1</button>
55+
<button onclick="win2.focus()">win2 Focus</button>
56+
</body>
57+
</html>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>new_win1</title>
6+
<script>
7+
var gui = require('nw.gui');
8+
var win1 = gui.Window.get();
9+
localStorage.win1 = 0;
10+
win1.on('focus', function() {
11+
localStorage.win1++;
12+
console.log('win1');
13+
});
14+
</script>
15+
</head>
16+
<body>
17+
<p id="wait" style="font-size:1.5em">Please focus this before click the according button .</p>
18+
</body>
19+
</html>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>new_win2</title>
6+
</head>
7+
<body>
8+
<p id="wait" style="font-size:1.5em">Please wait to be closed.</p>
9+
</body>
10+
</html>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
var path = require('path');
2+
var app_test = require('./nw_test_app');
3+
var assert = require('assert');
4+
var window_counts = 3;
5+
var results;
6+
7+
describe('windoww', function() {
8+
this.timeout(0);
9+
before(function(done) {
10+
this.timeout(0);
11+
var child = app_test.createChildProcess({
12+
execPath: process.execPath,
13+
appPath: path.join(global.tests_dir, 'window'),
14+
end: function(data, app) {
15+
results = data;
16+
app.kill();
17+
done();
18+
}
19+
});
20+
21+
});
22+
describe('focus()', function() {
23+
it('should focus on the window', function() {
24+
for (var i = 0; i < window_counts; i++)
25+
assert.notEqual(results[i], 0)
26+
});
27+
})
28+
})
29+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "nw-window-test",
3+
"main": "index.html"
4+
}

0 commit comments

Comments
 (0)