Skip to content

Commit a03aa3a

Browse files
committed
[test] add window-resizeto
1 parent 14079b4 commit a03aa3a

File tree

4 files changed

+178
-0
lines changed

4 files changed

+178
-0
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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('newpop.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+
31+
function takeSnapshot() {
32+
gui.Window.get().capturePage(function(img) {
33+
var image = win.window.document.getElementById('image');
34+
image.src = img;
35+
36+
}, 'png');
37+
}
38+
39+
gui.Window.get().on('close', function() {
40+
if (win != null)
41+
win.close(true);
42+
this.close(true);
43+
});
44+
45+
gui.Window.get().show();
46+
</script>
47+
<button onclick="win.focus()">Focus</button>
48+
<br/>
49+
<button onclick="win.blur()">Blur</button>
50+
<br/>
51+
<button onclick="win.show()">Show</button>
52+
<br/>
53+
<button onclick="win.hide()">Hide</button>
54+
<br/>
55+
<button onclick="win.maximize()">Maximize</button>
56+
<br/>
57+
<button onclick="win.unmaximize()">Unmaximize</button>
58+
<br/>
59+
<button onclick="win.minimize()">Minimize</button>
60+
<br/>
61+
<button onclick="win.restore()">Restore</button>
62+
<br/>
63+
<button onclick="win.enterFullscreen()">EnterFullscreen</button>
64+
<br/>
65+
<button onclick="win.leaveFullscreen()">LeaveFullscreen</button>
66+
<br/>
67+
<button onclick="win.close()">Close</button>
68+
<br/>
69+
<button onclick="win.close(true)">Force Close</button>
70+
<br/>
71+
<button onclick="win.showDevTools()">Open DevTools</button>
72+
<br/>
73+
<button onclick="win.setMinimumSize(100, 200)">setMinimumSize(100, 200)</button>
74+
<br/>
75+
<button onclick="win.setMaximumSize(200, 400)">setMaximumSize(200, 400)</button>
76+
<br/>
77+
<button onclick="win.moveTo(0, 0)">moveTo(0, 0)</button>
78+
<br/>
79+
<button onclick="win.moveBy(10, 20)">moveBy(10, 20)</button>
80+
<br/>
81+
<button id='btn_resizeto' onclick="win.resizeTo(180, 180)">resizeTo(180, 180)</button>
82+
<br/>
83+
<button onclick="win.resizeBy(10, 20)">resizeBy(10, 20)</button>
84+
<br/>
85+
<button onclick="win.setResizable(true)">setResizable(true)</button>
86+
<button onclick="win.setResizable(false)">(false)</button>
87+
<br/>
88+
<p>Focus another application within 2sec, popup window should on top.</p>
89+
<button onclick="setTimeout(function(){win.setAlwaysOnTop(true);},2000)">setAlwaysOnTop(true)</button>
90+
<button onclick="win.setAlwaysOnTop(false)">(false)</button>
91+
<br/>
92+
<button onclick="win.zoomLevel = 2">set zoomLevel to 2</button>
93+
<br/>
94+
<button onclick="win.zoomLevel = 0">set zoomLevel to 0</button>
95+
<br/>
96+
<button onclick="takeSnapshot()">takeSnapshot</button>
97+
<br/>
98+
Reload the window and do all tests again.
99+
<button onclick="win.reload()">Reload</button>
100+
</body>
101+
</html>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>5093 as a menu window</title>
5+
<meta charset="UTF-8">
6+
<style>
7+
html,
8+
body {
9+
width: 100%;
10+
height: 100%;
11+
margin: 0;
12+
padding: 0;
13+
background-color: blue;
14+
}
15+
#yellow {
16+
color: black;
17+
background-color: yellow;
18+
width: 800px;
19+
height: 600px;
20+
}
21+
</style>
22+
</head>
23+
<body>
24+
<div id="yellow"></div>
25+
</body>
26+
<script>
27+
window.onload = window.onresize = function() {
28+
var yellow = document.getElementById('yellow');
29+
yellow.innerHTML = window.innerWidth + ", " + window.innerHeight + ' - inner size';
30+
}
31+
</script>
32+
</html>
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/sanity/window-resizeto/test.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import time
2+
import os
3+
import subprocess
4+
import sys
5+
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
6+
from nw_util import *
7+
8+
from selenium import webdriver
9+
from selenium.webdriver.chrome.options import Options
10+
11+
chrome_options = Options()
12+
chrome_options.add_argument("nwapp=" + os.path.dirname(os.path.abspath(__file__)))
13+
14+
driver = webdriver.Chrome(executable_path=os.environ['CHROMEDRIVER'], chrome_options=chrome_options, service_log_path="log", service_args=["--verbose"])
15+
time.sleep(1)
16+
try:
17+
print driver.current_url
18+
driver.implicitly_wait(10)
19+
wait_window_handles(driver, 2)
20+
print 'switch to opened window'
21+
driver.switch_to_window(driver.window_handles[-1])
22+
result = driver.find_element_by_id('yellow').get_attribute('innerHTML')
23+
print 'window size: %s' % result
24+
assert('200, 300' in result)
25+
driver.switch_to_window(driver.window_handles[0])
26+
driver.find_element_by_id('btn_resizeto').click()
27+
driver.switch_to_window(driver.window_handles[-1])
28+
result = driver.find_element_by_id('yellow').get_attribute('innerHTML')
29+
print 'window size: %s' % result
30+
assert('180, 180' in result)
31+
32+
finally:
33+
driver.quit()

0 commit comments

Comments
 (0)