Bug 1396798: Test toplevel data: URI navigation to images. r=smaug

This commit is contained in:
Christoph Kerschbaumer 2017-09-06 16:16:18 +02:00
Родитель 1e7caa84a1
Коммит 9db4e41781
2 изменённых файлов: 53 добавлений и 0 удалений

Просмотреть файл

@ -13,3 +13,5 @@ support-files =
[test_block_script_wrong_mime.html]
[test_block_toplevel_data_navigation.html]
skip-if = toolkit == 'android' # intermittent failure
[test_block_toplevel_data_img_navigation.html]
skip-if = toolkit == 'android' # intermittent failure

Просмотреть файл

@ -0,0 +1,51 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Bug 1396798: Do not block toplevel data: navigation to image (except svgs)</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<script class="testbody" type="text/javascript">
SpecialPowers.setBoolPref("security.data_uri.block_toplevel_data_uri_navigations", true);
SimpleTest.registerCleanupFunction(() => {
SpecialPowers.clearUserPref("security.data_uri.block_toplevel_data_uri_navigations");
});
SimpleTest.waitForExplicitFinish();
SimpleTest.requestFlakyTimeout("have to test that top level data:image loading is blocked/allowed");
function test_toplevel_data_image() {
const DATA_PNG =
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==";
let win1 = window.open(DATA_PNG);
let wrappedWin1 = SpecialPowers.wrap(win1);
setTimeout(function () {
let images = wrappedWin1.document.getElementsByTagName('img');
is(images.length, 1, "Loading data:image/png should be allowed");
is(images[0].src, DATA_PNG, "Sanity: img src matches");
wrappedWin1.close();
test_toplevel_data_image_svg();
}, 1000);
}
function test_toplevel_data_image_svg() {
const DATA_SVG =
"data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxNiIgaGVpZ2h0PSIxNiIgdmlld0JveD0iMCAwIDE2IDE2Ij4KICA8cGF0aCBkPSJNOCwxMkwzLDcsNCw2bDQsNCw0LTQsMSwxWiIgZmlsbD0iIzZBNkE2QSIgLz4KPC9zdmc+Cg==";
let win2 = window.open(DATA_SVG);
let wrappedWin2 = SpecialPowers.wrap(win2);
setTimeout(function () {
isnot(wrappedWin2.document.documentElement.localName, "svg",
"Loading data:image/svg+xml should be blocked");
wrappedWin2.close();
SimpleTest.finish();
}, 1000);
}
// fire up the tests
test_toplevel_data_image();
</script>
</body>
</html>