Merge pull request #2743 from atom/fix-backward-compatibility

Fix backward compatibility with old BrowserWindow options
This commit is contained in:
Cheng Zhao 2015-09-09 16:25:03 +08:00
commit e5496d9ac0
3 changed files with 29 additions and 12 deletions

View file

@ -70,14 +70,13 @@ Window::Window(v8::Isolate* isolate, const mate::Dictionary& options) {
options.Get(switches::kWebPreferences, &web_preferences);
// Be compatible with old options which are now in web_preferences.
std::string str;
double d;
if (options.Get(switches::kNodeIntegration, &str))
web_preferences.Set(switches::kNodeIntegration, str);
if (options.Get(switches::kPreloadScript, &str))
web_preferences.Set(switches::kPreloadScript, str);
if (options.Get(switches::kZoomFactor, &d))
web_preferences.Set(switches::kZoomFactor, d);
v8::Local<v8::Value> value;
if (options.Get(switches::kNodeIntegration, &value))
web_preferences.Set(switches::kNodeIntegration, value);
if (options.Get(switches::kPreloadScript, &value))
web_preferences.Set(switches::kPreloadScript, value);
if (options.Get(switches::kZoomFactor, &value))
web_preferences.Set(switches::kZoomFactor, value);
// Creates the WebContents used by BrowserWindow.
auto web_contents = WebContents::Create(isolate, web_preferences);

View file

@ -36,11 +36,20 @@ describe 'chromium feature', ->
describe 'window.open', ->
it 'returns a BrowserWindowProxy object', ->
b = window.open 'about:blank', 'test', 'show=no'
b = window.open 'about:blank', '', 'show=no'
assert.equal b.closed, false
assert.equal b.constructor.name, 'BrowserWindowProxy'
b.close()
it 'accepts "node-integration" as feature', (done) ->
listener = (event) ->
window.removeEventListener 'message', listener
b.close()
assert.equal event.data, 'undefined'
done()
window.addEventListener 'message', listener
b = window.open "file://#{fixtures}/pages/window-opener-node.html", '', 'node-integration=no,show=no'
describe 'window.opener', ->
ipc = remote.require 'ipc'
url = "file://#{fixtures}/pages/window-opener.html"
@ -58,19 +67,21 @@ describe 'chromium feature', ->
w.loadUrl url
it 'is not null for window opened by window.open', (done) ->
b = window.open url, 'test2', 'show=no'
b = window.open url, '', 'show=no'
ipc.on 'opener', (event, opener) ->
b.close()
done(if opener isnt null then undefined else opener)
describe 'window.opener.postMessage', ->
it 'sets source and origin correctly', (done) ->
b = window.open "file://#{fixtures}/pages/window-opener-postMessage.html", 'test', 'show=no'
window.addEventListener 'message', (event) ->
listener = (event) ->
window.removeEventListener 'message', listener
b.close()
assert.equal event.source.guestId, b.guestId
assert.equal event.origin, 'file://'
done()
window.addEventListener 'message', listener
b = window.open "file://#{fixtures}/pages/window-opener-postMessage.html", '', 'show=no'
describe 'creating a Uint8Array under browser side', ->
it 'does not crash', ->

View file

@ -0,0 +1,7 @@
<html>
<body>
<script type="text/javascript" charset="utf-8">
window.opener.postMessage(typeof process, '*')
</script>
</body>
</html>