Skip to content

Commit

Permalink
manual test for nw.Window API
Browse files Browse the repository at this point in the history
  • Loading branch information
ffanny authored and rogerwang committed Dec 28, 2018
1 parent 2827525 commit dad0fc8
Show file tree
Hide file tree
Showing 3 changed files with 192 additions and 0 deletions.
100 changes: 100 additions & 0 deletions test/manual/window/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<html>
<head>
<style>
button {
-webkit-app-region: no-drag;
}
</style>
</head>
<body style="-webkit-user-select: none; -webkit-app-region: drag">
<script>
var gui = nw;
var win;
gui.Window.open('popup.html', {
x: 100, y: 100, width: 200, height: 300
}, function(w) { win = w; });

win.on('closed', function() {
console.log('popup window is closed.');
win = null;
});

win.on('loading', function() {
console.log('start to load new window.');
});

win.on('loaded', function() {
console.log('new window loaded.');
});

function takeSnapshot() {
gui.Window.get().capturePage(function(img) {
var image = win.window.document.getElementById('image');
image.src = img;

}, 'png');
}

gui.Window.get().on('close', function() {
if (win != null)
win.close(true);
this.close(true);
});

gui.Window.get().show();
</script>
<button onclick="win.focus()">Focus</button>
<br/>
<button onclick="win.blur()">Blur</button>
<br/>
<button onclick="win.show()">Show</button>
<br/>
<button onclick="win.hide()">Hide</button>
<br/>
<button onclick="win.maximize()">Maximize</button>
<br/>
<button onclick="win.unmaximize()">Unmaximize</button>
<br/>
<button onclick="win.minimize()">Minimize</button>
<br/>
<button onclick="win.restore()">Restore</button>
<br/>
<button onclick="win.enterFullscreen()">EnterFullscreen</button>
<br/>
<button onclick="win.leaveFullscreen()">LeaveFullscreen</button>
<br/>
<button onclick="win.close()">Close</button>
<br/>
<button onclick="win.close(true)">Force Close</button>
<br/>
<button onclick="win.showDevTools()">Open DevTools</button>
<br/>
<button onclick="win.setMinimumSize(100, 200)">setMinimumSize(100, 200)</button>
<br/>
<button onclick="win.setMaximumSize(200, 400)">setMaximumSize(200, 400)</button>
<br/>
<button onclick="win.moveTo(0, 0)">moveTo(0, 0)</button>
<br/>
<button onclick="win.moveBy(10, 20)">moveBy(10, 20)</button>
<br/>
<button onclick="win.resizeTo(100, 100)">resizeTo(100, 100)</button>
<br/>
<button onclick="win.resizeBy(10, 20)">resizeBy(10, 20)</button>
<br/>
<button onclick="win.setResizable(true)">setResizable(true)</button>
<button onclick="win.setResizable(false)">(false)</button>
<br/>
<p>Focus another application within 2sec, popup window should on top.</p>
<button onclick="setTimeout(function(){win.setAlwaysOnTop(true);},2000)">setAlwaysOnTop(true)</button>
<button onclick="win.setAlwaysOnTop(false)">(false)</button>
<br/>
<button onclick="win.zoomLevel = 2">set zoomLevel to 2</button>
<br/>
<button onclick="win.zoomLevel = 0">set zoomLevel to 0</button>
<br/>
<button onclick="takeSnapshot()">takeSnapshot</button>
<br/>
Reload the window and do all tests again.
<button onclick="win.reload()">Reload</button>
</body>
</html>
12 changes: 12 additions & 0 deletions test/manual/window/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "nw-test",
"main": "index.html",
"window": {
"title": "Window Test",
"toolbar": true,
"position": "center",
"width": 400,
"height": 700,
"resizable": false
}
}
80 changes: 80 additions & 0 deletions test/manual/window/popup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>New Window</title>
</head>
<body style="margin:0">
<div style="width: 100%; height: 50px; background-color: green; -webkit-app-region: drag;">
</div>
This is the popup window<br/>
<script>
var enable = false;
var gui = require('nw.gui');
var win = gui.Window.get();
win.on('close', function() {
if (enable)
this.close(true);
else
console.log('This window can not be closed.');
});

win.on('enter-fullscreen', function() {
console.log('Enter fullscreen');
});

win.on('leave-fullscreen', function() {
console.log('Leave fullscreen');
});

win.on('focus', function() {
console.log('Window is focused');
});

win.on('blur', function() {
console.log('Window lost focus');
});

win.on('minimize', function() {
console.log('Window is minimized');
});

win.on('restore', function() {
console.log('Window is restored');
});

win.on('maximize', function() {
console.log('Window is maximized');
});

win.on('move', function(x, y) {
console.log('Window move: ' + x + ' ' + y);
});

win.on('resize', function(w, h) {
console.log('Window resize: ' + w + ' ' + h);
});

win.on('unmaximize', function() {
console.log('Window is unmaximized');
});

win.on('zoom', function(level) {
document.getElementById('zoom').innerText = level;
});

window.onload = function() {
gui.Window.get().show();
}
document.write("zoomLevel = <div id='zoom'>" + win.zoomLevel + '</div>');
</script>
<br/>

<button onclick="javascript:enable = true;">Enable to be closed</button>
<br/>
<button onclick="win.leaveFullscreen()">Leave fullscreen</button>

<div style="margin-top:10px;border-top: 1px solid #000;">
<img id="image" width="400" />
</div>
</body>
</html>

0 comments on commit dad0fc8

Please sign in to comment.