window-open-windowfeatures-values.html (2657B)
1 <!doctype html> 2 <meta charset=utf-8> 3 <meta name="timeout" content="long"> 4 <title>window.open() windowFeature value parsing</title> 5 <link rel="author" href="mailto:masonf@chromium.org"> 6 <link rel="help" href="https://html.spec.whatwg.org/multipage/window-object.html#concept-window-open-features-parse-boolean"> 7 <script src="/resources/testharness.js"></script> 8 <script src="/resources/testharnessreport.js"></script> 9 <script> 10 function testValueGeneric(val, expectTrue, property, testFn) { 11 const windowFeatureStr = val === "" ? property : `${property}=${val}`; 12 async_test(t => { 13 const windowName = '' + Math.round(Math.random()*1e12); 14 const channel = new BroadcastChannel(windowName); 15 channel.onmessage = t.step_func_done(e => { 16 // Send message first so if asserts throw the popup is still closed 17 channel.postMessage(null); 18 testFn(e.data); 19 }); 20 window.open("support/windowFeature-values-target.html?" + windowName, windowName, windowFeatureStr); 21 },`Test ${windowFeatureStr}, expected interpretation is ${expectTrue ? 'true' : 'false'}`); 22 } 23 24 function testValueForNoReferrer(val, expectTrue) { 25 testValueGeneric(val, expectTrue, "noreferrer", (data) => { 26 if (expectTrue) { 27 assert_false(data.haveReferrer); 28 assert_false(data.haveOpener); 29 } else { 30 assert_true(data.haveReferrer); 31 assert_true(data.haveOpener); 32 } 33 }); 34 } 35 36 function testValueForNoOpener(val, expectTrue) { 37 testValueGeneric(val, expectTrue, "noopener", (data) => { 38 assert_equals(data.haveOpener, !expectTrue); 39 }); 40 } 41 42 function testValueForPopup(val, expectTrue) { 43 testValueGeneric(val, expectTrue, "popup", (data) => { 44 assert_equals(data.isPopup, expectTrue); 45 }); 46 } 47 48 function testValue(val, expectTrue) { 49 const quotes = val === "" ? [''] : ['','"',"'"]; 50 let noQuotes = true; 51 for (const quote of quotes) { 52 const thisExpectTrue = expectTrue && noQuotes; 53 const thisVal = quote + val + quote; 54 testValueForNoReferrer(thisVal, thisExpectTrue); 55 testValueForNoOpener(thisVal, thisExpectTrue); 56 testValueForPopup(thisVal, thisExpectTrue); 57 noQuotes = false; 58 } 59 } 60 61 testValue('',true); // Just the parameter means true 62 testValue('yes',true); // Yes means true 63 testValue('true',true); // True means true 64 testValue('foo',false); // If parsing as an integer is an error, false 65 testValue('0',false); // 0 is false 66 testValue('00',false); // 0 is false 67 testValue('1',true); // Non-zero is true 68 testValue('99999',true); // Non-zero is true 69 testValue('-1',true); // Non-zero is true 70 testValue('1foo',true); // This parses to 1 71 testValue('0foo',false); // This parses to 0 72 </script>