2019-01-04 18:16:59 +03:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Test for external protocol URLs blocked for iframes</title>
|
2019-04-15 23:56:58 +03:00
|
|
|
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
|
2019-01-04 18:16:59 +03:00
|
|
|
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div id='foo'><a href='#'>Click here to test this issue</a></div>
|
|
|
|
<script>
|
|
|
|
|
2019-01-30 14:19:35 +03:00
|
|
|
function test_initialize() {
|
|
|
|
ChromeUtils.resetLastExternalProtocolIframeAllowed();
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
|
2019-01-24 22:05:03 +03:00
|
|
|
function test_noUserInteraction() {
|
|
|
|
is(ChromeUtils.getPopupControlState(), "openAbused", "No user-interaction means: abuse state");
|
|
|
|
ok(!ChromeUtils.isPopupTokenUnused(), "Popup token has not been used yet");
|
|
|
|
is(ChromeUtils.lastExternalProtocolIframeAllowed(), 0, "No iframe loaded before this test!");
|
|
|
|
|
|
|
|
for (let i = 0; i < 10; ++i) {
|
|
|
|
let ifr = document.createElement('iframe');
|
|
|
|
ifr.src = "foo+bar:all_good";
|
|
|
|
document.body.appendChild(ifr);
|
|
|
|
|
|
|
|
is(ChromeUtils.getPopupControlState(), "openAbused", "No user-interaction means: abuse state");
|
|
|
|
ok(!ChromeUtils.isPopupTokenUnused(), "Popup token has been used!");
|
|
|
|
ok(ChromeUtils.lastExternalProtocolIframeAllowed() != 0, "We have 1 iframe loaded");
|
|
|
|
}
|
|
|
|
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_userInteraction() {
|
2019-01-24 08:31:41 +03:00
|
|
|
let foo = document.getElementById('foo');
|
|
|
|
foo.addEventListener('click', _ => {
|
|
|
|
is(ChromeUtils.getPopupControlState(), "openAllowed", "Click events allow popups");
|
|
|
|
ok(!ChromeUtils.isPopupTokenUnused(), "Popup token has not been used yet");
|
2019-01-04 18:16:59 +03:00
|
|
|
|
2019-01-24 08:31:41 +03:00
|
|
|
for (let i = 0; i < 10; ++i) {
|
|
|
|
let ifr = document.createElement('iframe');
|
|
|
|
ifr.src = "foo+bar:all_good";
|
|
|
|
document.body.appendChild(ifr);
|
2019-01-04 18:16:59 +03:00
|
|
|
|
2019-01-24 08:31:41 +03:00
|
|
|
is(ChromeUtils.getPopupControlState(), "openAllowed", "Click events allow popups");
|
|
|
|
ok(ChromeUtils.isPopupTokenUnused(), "Popup token has been used!");
|
|
|
|
}
|
2019-01-04 18:16:59 +03:00
|
|
|
|
2019-01-24 22:05:03 +03:00
|
|
|
next();
|
2019-01-04 18:16:59 +03:00
|
|
|
|
2019-01-24 08:31:41 +03:00
|
|
|
}, {once: true});
|
2019-01-04 18:16:59 +03:00
|
|
|
|
2019-01-24 08:31:41 +03:00
|
|
|
setTimeout(_ => {
|
|
|
|
sendMouseEvent({type:'click'}, 'foo');
|
|
|
|
}, 0);
|
|
|
|
}
|
2019-01-04 18:16:59 +03:00
|
|
|
|
2019-01-24 22:05:03 +03:00
|
|
|
let tests = [
|
2019-01-30 14:19:35 +03:00
|
|
|
test_initialize,
|
2019-01-24 22:05:03 +03:00
|
|
|
test_noUserInteraction,
|
|
|
|
test_userInteraction,
|
|
|
|
];
|
|
|
|
|
|
|
|
function next() {
|
|
|
|
if (tests.length == 0) {
|
|
|
|
SimpleTest.finish();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let test = tests.shift();
|
|
|
|
SimpleTest.executeSoon(test);
|
|
|
|
}
|
|
|
|
|
2019-01-24 08:31:41 +03:00
|
|
|
SpecialPowers.pushPrefEnv({'set': [
|
|
|
|
['dom.block_external_protocol_in_iframes', true],
|
|
|
|
]}, next);
|
2019-01-04 18:16:59 +03:00
|
|
|
|
2019-01-24 08:31:41 +03:00
|
|
|
SimpleTest.waitForExplicitFinish();
|
2019-01-04 18:16:59 +03:00
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|