Skip to content

Commit bb0f376

Browse files
committed
manual test for nw.Window API
1 parent 6098672 commit bb0f376

File tree

3 files changed

+192
-0
lines changed

3 files changed

+192
-0
lines changed

test/manual/window/index.html

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<html>
2+
<head>
3+
<style>
4+
button {
5+
-webkit-app-region: no-drag;
6+
}
7+
</style>
8+
</head>
9+
<body style="-webkit-user-select: none; -webkit-app-region: drag">
10+
<script>
11+
var gui = nw;
12+
var win;
13+
gui.Window.open('popup.html', {
14+
x: 100, y: 100, width: 200, height: 300
15+
}, function(w) { win = w; });
16+
17+
win.on('closed', function() {
18+
console.log('popup window is closed.');
19+
win = null;
20+
});
21+
22+
win.on('loading', function() {
23+
console.log('start to load new window.');
24+
});
25+
26+
win.on('loaded', function() {
27+
console.log('new window loaded.');
28+
});
29+
30+
function takeSnapshot() {
31+
gui.Window.get().capturePage(function(img) {
32+
var image = win.window.document.getElementById('image');
33+
image.src = img;
34+
35+
}, 'png');
36+
}
37+
38+
gui.Window.get().on('close', function() {
39+
if (win != null)
40+
win.close(true);
41+
this.close(true);
42+
});
43+
44+
gui.Window.get().show();
45+
</script>
46+
<button onclick="win.focus()">Focus</button>
47+
<br/>
48+
<button onclick="win.blur()">Blur</button>
49+
<br/>
50+
<button onclick="win.show()">Show</button>
51+
<br/>
52+
<button onclick="win.hide()">Hide</button>
53+
<br/>
54+
<button onclick="win.maximize()">Maximize</button>
55+
<br/>
56+
<button onclick="win.unmaximize()">Unmaximize</button>
57+
<br/>
58+
<button onclick="win.minimize()">Minimize</button>
59+
<br/>
60+
<button onclick="win.restore()">Restore</button>
61+
<br/>
62+
<button onclick="win.enterFullscreen()">EnterFullscreen</button>
63+
<br/>
64+
<button onclick="win.leaveFullscreen()">LeaveFullscreen</button>
65+
<br/>
66+
<button onclick="win.close()">Close</button>
67+
<br/>
68+
<button onclick="win.close(true)">Force Close</button>
69+
<br/>
70+
<button onclick="win.showDevTools()">Open DevTools</button>
71+
<br/>
72+
<button onclick="win.setMinimumSize(100, 200)">setMinimumSize(100, 200)</button>
73+
<br/>
74+
<button onclick="win.setMaximumSize(200, 400)">setMaximumSize(200, 400)</button>
75+
<br/>
76+
<button onclick="win.moveTo(0, 0)">moveTo(0, 0)</button>
77+
<br/>
78+
<button onclick="win.moveBy(10, 20)">moveBy(10, 20)</button>
79+
<br/>
80+
<button onclick="win.resizeTo(100, 100)">resizeTo(100, 100)</button>
81+
<br/>
82+
<button onclick="win.resizeBy(10, 20)">resizeBy(10, 20)</button>
83+
<br/>
84+
<button onclick="win.setResizable(true)">setResizable(true)</button>
85+
<button onclick="win.setResizable(false)">(false)</button>
86+
<br/>
87+
<p>Focus another application within 2sec, popup window should on top.</p>
88+
<button onclick="setTimeout(function(){win.setAlwaysOnTop(true);},2000)">setAlwaysOnTop(true)</button>
89+
<button onclick="win.setAlwaysOnTop(false)">(false)</button>
90+
<br/>
91+
<button onclick="win.zoomLevel = 2">set zoomLevel to 2</button>
92+
<br/>
93+
<button onclick="win.zoomLevel = 0">set zoomLevel to 0</button>
94+
<br/>
95+
<button onclick="takeSnapshot()">takeSnapshot</button>
96+
<br/>
97+
Reload the window and do all tests again.
98+
<button onclick="win.reload()">Reload</button>
99+
</body>
100+
</html>

test/manual/window/package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "nw-test",
3+
"main": "index.html",
4+
"window": {
5+
"title": "Window Test",
6+
"toolbar": true,
7+
"position": "center",
8+
"width": 400,
9+
"height": 700,
10+
"resizable": false
11+
}
12+
}

test/manual/window/popup.html

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<html>
2+
<head>
3+
<meta http-equiv="content-type" content="text/html; charset=utf-8">
4+
<title>New Window</title>
5+
</head>
6+
<body style="margin:0">
7+
<div style="width: 100%; height: 50px; background-color: green; -webkit-app-region: drag;">
8+
</div>
9+
This is the popup window<br/>
10+
<script>
11+
var enable = false;
12+
var gui = require('nw.gui');
13+
var win = gui.Window.get();
14+
win.on('close', function() {
15+
if (enable)
16+
this.close(true);
17+
else
18+
console.log('This window can not be closed.');
19+
});
20+
21+
win.on('enter-fullscreen', function() {
22+
console.log('Enter fullscreen');
23+
});
24+
25+
win.on('leave-fullscreen', function() {
26+
console.log('Leave fullscreen');
27+
});
28+
29+
win.on('focus', function() {
30+
console.log('Window is focused');
31+
});
32+
33+
win.on('blur', function() {
34+
console.log('Window lost focus');
35+
});
36+
37+
win.on('minimize', function() {
38+
console.log('Window is minimized');
39+
});
40+
41+
win.on('restore', function() {
42+
console.log('Window is restored');
43+
});
44+
45+
win.on('maximize', function() {
46+
console.log('Window is maximized');
47+
});
48+
49+
win.on('move', function(x, y) {
50+
console.log('Window move: ' + x + ' ' + y);
51+
});
52+
53+
win.on('resize', function(w, h) {
54+
console.log('Window resize: ' + w + ' ' + h);
55+
});
56+
57+
win.on('unmaximize', function() {
58+
console.log('Window is unmaximized');
59+
});
60+
61+
win.on('zoom', function(level) {
62+
document.getElementById('zoom').innerText = level;
63+
});
64+
65+
window.onload = function() {
66+
gui.Window.get().show();
67+
}
68+
document.write("zoomLevel = <div id='zoom'>" + win.zoomLevel + '</div>');
69+
</script>
70+
<br/>
71+
72+
<button onclick="javascript:enable = true;">Enable to be closed</button>
73+
<br/>
74+
<button onclick="win.leaveFullscreen()">Leave fullscreen</button>
75+
76+
<div style="margin-top:10px;border-top: 1px solid #000;">
77+
<img id="image" width="400" />
78+
</div>
79+
</body>
80+
</html>

0 commit comments

Comments
 (0)