-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add "true" to truthy values list for windowFeatures
Prior to this CL, window.open(url, '', 'noopener=true') would treat 'noopener=true' as if noopener is false. This is currently per-spec [1] but there is a desire [2][3] to change that. [1] https://html.spec.whatwg.org/multipage/window-object.html#concept-window-open-features-parse-boolean [2] whatwg/html#7425 [3] whatwg/html#7399 Fixed: 1277613 Change-Id: I5b3a7e985a9bb392c2150846b50369cfcd9b05fa
- Loading branch information
1 parent
206491a
commit 90803a5
Showing
4 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
html/browsers/the-window-object/support/windowFeature-values-target.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<script> | ||
const channelName = location.search.substr(1), | ||
channel = new BroadcastChannel(channelName); | ||
|
||
const haveOpener = window.opener !== null; | ||
const haveReferrer = document.referrer !== null && document.referrer !== ""; | ||
const allBarProps = [ | ||
window.locationbar.visible, | ||
window.menubar.visible, | ||
window.personalbar.visible, | ||
window.scrollbars.visible, | ||
window.statusbar.visible, | ||
window.toolbar.visible | ||
]; | ||
const isPopup = allBarProps.every(x=>!x); | ||
|
||
channel.postMessage({haveOpener, haveReferrer, isPopup}); | ||
|
||
// Because messages are not delivered synchronously and because closing a | ||
// browsing context prompts the eventual clearing of all task sources, this | ||
// document should not be closed until the opener document has confirmed | ||
// receipt. | ||
channel.onmessage = () => window.close(); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
html/browsers/the-window-object/window-open-windowfeatures-values.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<!doctype html> | ||
<meta charset=utf-8> | ||
<meta name="timeout" content="long"> | ||
<title>window.open() windowFeature value parsing</title> | ||
<link rel="author" href="mailto:masonf@chromium.org"> | ||
<link rel="help" href="https://html.spec.whatwg.org/multipage/window-object.html#concept-window-open-features-parse-boolean"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script> | ||
function testValueGeneric(val, expectTrue, property, testFn) { | ||
const windowFeatureStr = val === "" ? property : `${property}=${val}`; | ||
async_test(t => { | ||
const windowName = '' + Math.round(Math.random()*1e12); | ||
const channel = new BroadcastChannel(windowName); | ||
channel.onmessage = t.step_func_done(e => { | ||
// Send message first so if asserts throw the popup is still closed | ||
channel.postMessage(null); | ||
testFn(e.data); | ||
}); | ||
window.open("support/windowFeature-values-target.html?" + windowName, windowName, windowFeatureStr); | ||
},`Test ${windowFeatureStr}, expected interpretation is ${expectTrue ? 'true' : 'false'}`); | ||
} | ||
|
||
function testValueForNoReferrer(val, expectTrue) { | ||
testValueGeneric(val, expectTrue, "noreferrer", (data) => { | ||
if (expectTrue) { | ||
assert_false(data.haveReferrer); | ||
assert_false(data.haveOpener); | ||
} else { | ||
assert_true(data.haveReferrer); | ||
assert_true(data.haveOpener); | ||
} | ||
}); | ||
} | ||
|
||
function testValueForNoOpener(val, expectTrue) { | ||
testValueGeneric(val, expectTrue, "noopener", (data) => { | ||
assert_equals(data.haveOpener, !expectTrue); | ||
}); | ||
} | ||
|
||
function testValueForPopup(val, expectTrue) { | ||
testValueGeneric(val, expectTrue, "popup", (data) => { | ||
assert_equals(data.isPopup, expectTrue); | ||
}); | ||
} | ||
|
||
function testValue(val, expectTrue) { | ||
const quotes = val === "" ? [''] : ['','"',"'"]; | ||
let noQuotes = true; | ||
for (const quote of quotes) { | ||
const thisExpectTrue = expectTrue && noQuotes; | ||
const thisVal = quote + val + quote; | ||
testValueForNoReferrer(thisVal, thisExpectTrue); | ||
testValueForNoOpener(thisVal, thisExpectTrue); | ||
testValueForPopup(thisVal, thisExpectTrue); | ||
noQuotes = false; | ||
} | ||
} | ||
|
||
testValue('',true); // Just the parameter means true | ||
testValue('yes',true); // Yes means true | ||
testValue('true',true); // True means true | ||
testValue('foo',false); // If parsing as an integer is an error, false | ||
testValue('0',false); // 0 is false | ||
testValue('00',false); // 0 is false | ||
testValue('1',true); // Non-zero is true | ||
testValue('99999',true); // Non-zero is true | ||
testValue('-1',true); // Non-zero is true | ||
testValue('1foo',true); // This parses to 1 | ||
testValue('0foo',false); // This parses to 0 | ||
</script> |