gecko-dev/dom/base/test/test_location_searchParams.html

90 lines
2.7 KiB
HTML

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1037715
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 1037715</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1037715">Mozilla Bug 1037715</a>
<iframe id="a"></iframe>
<script type="application/javascript">
var l;
var iframe = document.getElementById('a');
function onload0() {
iframe.removeEventListener('load', onload0);
l = iframe.contentWindow.location;
is(l.searchParams.get('a'), 'test0', 'l.searchParams value is ok');
info('changing location from JS...');
iframe.addEventListener('load', onload1);
iframe.contentWindow.location.href = 'file_empty.html?a=test1';
}
function onload1() {
iframe.removeEventListener('load', onload1);
var ll = iframe.contentWindow.location;
is(ll.searchParams.get('a'), 'test1', 'location.searchParams value is ok');
is(l.searchParams.get('a'), 'test1', 'l.searchParams value is ok');
isnot(ll.searchParams, l.searchParams, '2 different objects.');
info('changing location using l.searchParams...');
iframe.addEventListener('load', onload2);
l.searchParams.set('a', 'test2');
}
function onload2() {
iframe.removeEventListener('load', onload2);
var ll = iframe.contentWindow.location;
is(ll.searchParams.get('a'), 'test2', 'location.searchParams value is ok');
is(l.searchParams.get('a'), 'test2', 'l.searchParams value is ok');
isnot(ll.searchParams, l.searchParams, '2 different objects.');
info('changing iframe.src...');
iframe.addEventListener('load', onload3);
l.search = 'a=test3';
}
function onload3() {
iframe.removeEventListener('load', onload3);
var ll = iframe.contentWindow.location;
is(ll.searchParams.get('a'), 'test3', 'location.searchParams value is ok');
is(l.searchParams.get('a'), 'test3', 'l.searchParams value is ok');
isnot(ll.searchParams, l.searchParams, '2 different objects.');
info('changing iframe.src...');
iframe.addEventListener('load', onload4);
iframe.src = 'file_empty.html?a=test4';
}
function onload4() {
iframe.removeEventListener('load', onload4);
var ll = iframe.contentWindow.location;
is(ll.searchParams.get('a'), 'test4', 'location.searchParams value is ok');
is(l.searchParams.get('a'), 'test4', 'l.searchParams value is ok');
isnot(ll.searchParams, l.searchParams, '2 different objects.');
SimpleTest.finish();
}
iframe.addEventListener('load', onload0);
iframe.src = "file_empty.html?a=test0";
SimpleTest.waitForExplicitFinish();
</script>
</body>
</html>