Skip to content

Commit

Permalink
Fix window open size
Browse files Browse the repository at this point in the history
This patch contains doc changes and test case. The real fix in on
Chromium side.

Partial fix for nwjs#4493
  • Loading branch information
Cong Liu committed Mar 9, 2016
1 parent f8a6967 commit d715f34
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/For Users/Migration/From 0.12 to 0.13.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

### Window

+ There is an id to identify each window. This will be used to remember the size and position of the window and restore that geometry when a window with the same id is later opened. The default id is `.main`. It could be specified in [Window.open](../../References/Window.md#windowopenurl-options-callback)
+ There is an `id` to identify each window. This will be used to remember the size and position of the window and restore that geometry when a window with the same `id` is later opened. It could be specified in [Window.open](../../References/Window.md#windowopenurl-options-callback) or [window subfields in manifest](../../References/Manifest Format.md#id)
+ Event `capturepagedone` of [`Window` API](../../References/Window.md#event-capturepagedone) is **deprecated**.Use the callback with the [`win.capturePage(callback [, config ])`](../../References/Window.md#wincapturepagecallback--config-) instead.
+ [Window.open](../../References/Window.md#windowopenurl-options-callback) is changed to passing the created window as the argument of the callback.
+ [Window.showDevtools](../../References/Window.md#winshowdevtoolsiframe-headless-callback) is changed to passing the created window as the argument of the callback.
Expand Down
4 changes: 4 additions & 0 deletions docs/References/Manifest Format.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ Most of window subfields are inherited by sub windows opened by `window.open()`

All of the window subfields can be overwritten by using [`new-win-policy` event](Window.md#event-new-win-policy-frame-url-policy).

### id

* `{String}` the `id` used to identify the window. This will be used to remember the size and position of the window and restore that geometry when a window with the same id is later opened. [See also the Chrome App documentation](https://developer.chrome.com/apps/app_window#type-CreateWindowOptions)

### title

* `{String}` the default title of window created by NW.js, it's very useful if you want to show your own title when the app is starting.
Expand Down
2 changes: 1 addition & 1 deletion docs/References/Window.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ nw.Window.open('https://github.com/nwjs/nw.js', {}, function(new_win) {
- `new_instance` `{Boolean}` _Optional_ whether to open a new window in a separate render process.
- `inject_js_start` `{String}` _Optional_ the script to be injected before document loaded. See [Manifest format](Manifest Format.md#inject_js_start)
- `inject_js_end` `{String}` _Optional_ the script to be injected before document unloaded. See [Manifest format](Manifest Format.md#inject_js_end)
- `id` `{String}` _Optional_ the ID used to identify the window. This will be used to remember the size and position of the window and restore that geometry when a window with the same id is later opened. [See also the Chrome App documentation](https://developer.chrome.com/apps/app_window#type-CreateWindowOptions)
- `id` `{String}` _Optional_ the `id` used to identify the window. This will be used to remember the size and position of the window and restore that geometry when a window with the same id is later opened. [See also the Chrome App documentation](https://developer.chrome.com/apps/app_window#type-CreateWindowOptions)
* `callback(win)` `{Function}` _Optional_ callback when with the opened native `Window` object

Open a new window and load `url` in it.
Expand Down
26 changes: 26 additions & 0 deletions test/remoting/issue4493-win-open-size/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>issue4493-win-open-size</title>
</head>
<body>
<button id="resize-window" onclick="resizeWindow()">Resize to 777x555</button>
<script>
function out(id, msg) {
var h1 = document.createElement('h1');
h1.setAttribute('id', id);
h1.innerHTML = msg;
document.body.appendChild(h1);
}
function resizeWindow() {
resizeTo(777,555);
}
window.onresize = function() {
out('resize', innerWidth + 'x' + innerHeight);
};
out('size', innerWidth + 'x' + innerHeight);
</script>
</body>
</html>
8 changes: 8 additions & 0 deletions test/remoting/issue4493-win-open-size/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "issue4493-win-open-size",
"main": "index.html",
"window": {
"width": 666,
"height": 333
}
}
37 changes: 37 additions & 0 deletions test/remoting/issue4493-win-open-size/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import time
import os
import platform

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument("nwapp=" + os.path.dirname(os.path.abspath(__file__)))

# open first time
print 'Open first time'
driver = webdriver.Chrome(executable_path=os.environ['CHROMEDRIVER'], chrome_options=chrome_options)
driver.implicitly_wait(10)
time.sleep(1)
try:
print driver.current_url
size = driver.find_element_by_id('size').get_attribute('innerHTML')
print 'open size %s' % size
driver.find_element_by_id('resize-window').click()
size = driver.find_element_by_id('resize').get_attribute('innerHTML')
print 'resize to %s' % size
finally:
driver.quit()

# open second time
print 'Open second time'
driver = webdriver.Chrome(executable_path=os.environ['CHROMEDRIVER'], chrome_options=chrome_options)
driver.implicitly_wait(10)
time.sleep(1)
try:
print driver.current_url
size = driver.find_element_by_id('size').get_attribute('innerHTML')
print 'open size %s' % size
assert(size == '666x333')
finally:
driver.quit()

0 comments on commit d715f34

Please sign in to comment.