Update web-platform-tests to revision 0d318188757a9c996e20b82db201fd04de5aa255

This commit is contained in:
James Graham 2015-03-27 09:15:38 +00:00
parent b2a5225831
commit 1a81b18b9f
12321 changed files with 544385 additions and 6 deletions

View file

@ -0,0 +1,31 @@
<!doctype html>
<meta charset=utf-8>
<title>Synthetic popstate events</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
test(function () {
assert_throws('NotSupportedError', function() {
document.createEvent('PopStateEvent');
}, 'document.createEvent("PopStateEvent") should not be supported');
}, 'document.createEvent');
test(function () {
assert_false('initPopStateEvent' in PopStateEvent.prototype,
'There should be no PopStateEvent#initPopStateEvent');
}, 'initPopStateEvent');
test(function () {
var state = history.state;
var data;
window.addEventListener('popstate', function (e) {
data = e.state;
});
window.dispatchEvent(new PopStateEvent('popstate', {
'state': {testdata:true}
}));
assert_true(data.testdata,'state data was corrupted');
assert_equals(history.state, state, "history.state was NOT set by dispatching the event");
}, 'Dispatching a synthetic PopStateEvent');
</script>

View file

@ -0,0 +1,6 @@
[
{
"id": "event-definitions-0",
"original_id": "event-definitions-0"
}
]

View file

@ -0,0 +1,30 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Media documents: image</title>
<link rel="author" title="Michael Ventnor" href="mailto:mventnor@mozilla.com">
<link rel="author" title="Ms2ger" href="mailto:ms2ger@gmail.com">
<link rel="help" href="https://html.spec.whatwg.org/multipage/#read-media">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
var t = async_test("The document for a standalone media file should have one child in the body.");
function frameLoaded() {
var testframe = document.getElementById('testframe');
var testframeChildren = testframe.contentDocument.body.childNodes;
assert_equals(testframeChildren.length, 1, "Body of image document has 1 child");
assert_equals(testframeChildren[0].nodeName, "IMG", "Only child of body must be an <img> element");
assert_equals(testframeChildren[0].namespaceURI, "http://www.w3.org/1999/xhtml",
"Only child of body must be an HTML element");
t.done();
}
</script>
</head>
<body>
<div id="log"></div>
<iframe id="testframe" onload="t.step(frameLoaded)"
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAAXNSR0IArs4c6QAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9oMFgQGMyFwHucAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAADElEQVQI12P4//8/AAX+Av7czFnnAAAAAElFTkSuQmCC"></iframe>
</body>
</html>

View file

@ -0,0 +1,30 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Media documents: video</title>
<link rel="author" title="Michael Ventnor" href="mailto:mventnor@mozilla.com">
<link rel="author" title="Ms2ger" href="mailto:ms2ger@gmail.com">
<link rel="help" href="https://html.spec.whatwg.org/multipage/#read-media">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
var t = async_test("The document for a standalone media file should have one child in the body.");
function frameLoaded() {
var testframe = document.getElementById('testframe');
var testframeChildren = testframe.contentDocument.body.childNodes;
assert_equals(testframeChildren.length, 1, "Body of image document has 1 child");
assert_equals(testframeChildren[0].nodeName, "VIDEO", "Only child of body must be an <video> element");
assert_equals(testframeChildren[0].namespaceURI, "http://www.w3.org/1999/xhtml",
"Only child of body must be an HTML element");
t.done();
}
</script>
</head>
<body>
<div id="log"></div>
<iframe id="testframe" onload="t.step(frameLoaded)"
src="data:video/webm,"></iframe>
</body>
</html>

View file

@ -0,0 +1,41 @@
<!DOCTYPE html>
<title>Page load processing model for text files</title>
<link rel="author" title="Ms2ger" href="ms2ger@gmail.com">
<link rel="help" href="https://html.spec.whatwg.org/multipage/#read-text">
<link rel="stylesheet" href="/resources/testharness.css">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
var t = async_test("Checking document metadata for text file");
var tD = async_test("Checking DOM for text file");
var tC = async_test("Checking contents for text file");
var iframe = document.body.appendChild(document.createElement("iframe"));
iframe.onload = function(e) {
var doc = iframe.contentDocument;
t.step(function() {
assert_equals(doc.compatMode, "BackCompat");
assert_equals(doc.contentType, "text/plain");
assert_equals(doc.doctype, null);
t.done();
})
tD.step(function() {
assert_equals(doc.childNodes.length, 1, "Document should have 1 child")
assert_equals(doc.documentElement.tagName, "HTML");
assert_equals(doc.documentElement.childNodes.length, 2,
"Root element should have 2 children")
assert_equals(doc.documentElement.firstChild.tagName, "HEAD");
assert_equals(doc.documentElement.lastChild.tagName, "BODY");
assert_equals(doc.documentElement.lastChild.childNodes.length, 1,
"Body element should have 1 child")
assert_equals(doc.documentElement.lastChild.firstChild.tagName, "PRE");
tD.done();
})
tC.step(function() {
assert_equals(doc.documentElement.lastChild.firstChild.firstChild.data,
"This is a sample text/plain document.\n\nThis is not an HTML document.\n\n");
tC.done();
})
};
iframe.src = "../../../../common/text-plain.txt";
</script>

View file

@ -0,0 +1,23 @@
<!DOCTYPE HTML>
<script>
t = opener.t;
do_test = t.step(function () {
localStorage.test6564729 += '4';
var d = document;
var e = document.open(); // has no effect (ignore-opens-during-unload > 0)
localStorage.test6564729 += (e == d) ? '5' : 'A [' + e + '] ';
document.write('FAIL - document.write executed and blocked navigation!'); // has no effect (ignore-opens-during-unload > 0)
localStorage.test6564729 += document.body.textContent.match('FAIL') ? 'B' : '6';
document.close(); // has no effect (no script-created parser)
localStorage.test6564729 += '7';
})
onload = t.step_func(function() {
localStorage.test6564729 = '0';
setTimeout(t.step_func(function() {document.links[0].click()}));
});
</script>
<body onbeforeunload="localStorage.test6564729 += '1'"
onpagehide="localStorage.test6564729 += '3'"
onunload="do_test()">
<p><a href="001a.html">Follow this link to run the test.</a>
<p><iframe src="001b.html"></iframe>

View file

@ -0,0 +1,15 @@
<!doctype html>
<title>document.open in unload</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
var t = async_test();
var win;
t.step(function() {
win = window.open("001-1.html");
});
add_completion_callback(function() {win.close()});
</script>

View file

@ -0,0 +1,7 @@
<!DOCTYPE HTML>
<script>
opener.t.step(function() {
opener.assert_equals(localStorage.test6564729, '0123456789');
opener.t.done();
});
</script>

View file

@ -0,0 +1,5 @@
<!DOCTYPE HTML>
<body onbeforeunload="localStorage.test6564729 += '2'"
onpagehide="localStorage.test6564729 += '8'"
onunload="localStorage.test6564729 += '9'">
<p>Inner frame

View file

@ -0,0 +1,28 @@
<!DOCTYPE HTML>
<script>
var t = opener.t;
var do_test = t.step_func(function() {
localStorage.test6564729 += '1';
var d = document;
var e = document.open(); // unload triggered here - beforeunload 2, 3 in 002b; pagehide 4, unload 5, pagehide 6 in 002b, unload 7 in 002b
localStorage.test6564729 += (e == d) ? '8' : 'X';
var s = 'FAIL if you see this | ' + localStorage.test6564729;
document.write(s);
localStorage.test6564729 += document.body.textContent == s ? '9' : 'x';
document.close();
localStorage.test6564729 += 'Z';
document.body.textContent += ' // ' + localStorage.test6564729;
location = '002a.html'; // unload triggers again here, but they're not registered event listeners any more
});
onload = t.step_func(function() {
localStorage.test6564729 = '0';
setTimeout(function() {document.getElementsByTagName("input")[0].click()}, 100);
});
</script>
<body onbeforeunload="localStorage.test6564729 += '2'"
onpagehide="localStorage.test6564729 += '4'"
onunload="localStorage.test6564729 += '5'">
<input type=button value="Activate this button to run the test" onclick="do_test()">
<p><iframe src="002b.html"></iframe>

View file

@ -0,0 +1,15 @@
<!doctype html>
<title>document.open in unload</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
var t = async_test();
var win;
t.step(function() {
win = window.open("002-1.html");
});
add_completion_callback(function() {win.close()});
</script>

View file

@ -0,0 +1,7 @@
<!DOCTYPE HTML>
<script>
opener.t.step(function() {
opener.assert_equals(localStorage.test6564729, '0123456789Z');
opener.t.done();
});
</script>

View file

@ -0,0 +1,5 @@
<!DOCTYPE HTML>
<body onbeforeunload="localStorage.test6564729 += '3'"
onpagehide="localStorage.test6564729 += '6'"
onunload="localStorage.test6564729 += '7'">
<p>Inner frame

View file

@ -0,0 +1,23 @@
<!DOCTYPE HTML>
<script>
var t = opener.t;
var do_test = t.step_func(function() {
localStorage.test6564729 += '1';
var d = document;
var e = document.open(); // has no effect (ignore-opens-during-unload > 0 because we're in beforeunload)
localStorage.test6564729 += (e == d) ? '2' : 'A [' + e + '] ';
document.write('FAIL - document.write executed and blocked navigation!'); // has no effect (ignore-opens-during-unload > 0)
localStorage.test6564729 += document.body.textContent.match('FAIL') ? 'B' : '3';
document.close(); // has no effect (no script-created parser)
localStorage.test6564729 += '4';
})
onload=t.step_func(function() {localStorage.test6564729 = '0'; setTimeout(t.step_func(function() {document.links[0].click()}), 100)})
</script>
<body
onbeforeunload="do_test()"
onpagehide="localStorage.test6564729 += '6'"
onunload="localStorage.test6564729 += '7'">
<p><a href="003a.html">Follow this link to run the test.</a>
<p><iframe src="003b.html"></iframe>

View file

@ -0,0 +1,15 @@
<!doctype html>
<title>document.open in beforeunload with link</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
var t = async_test();
var win;
t.step(function() {
win = window.open("003-1.html");
});
add_completion_callback(function() {win.close()});
</script>

View file

@ -0,0 +1,8 @@
<!DOCTYPE HTML>
<p>FAIL</p>
<script>
opener.t.step(function() {
opener.assert_equals(localStorage.test6564729, '0123456789')
opener.t.done();
})
</script>

View file

@ -0,0 +1,5 @@
<!DOCTYPE HTML>
<body onbeforeunload="localStorage.test6564729 += '5'"
onpagehide="localStorage.test6564729 += '8'"
onunload="localStorage.test6564729 += '9'">
<p>Inner frame

View file

@ -0,0 +1,25 @@
<!DOCTYPE HTML>
<script>
var t = opener.t;
var do_test = t.step_func(function() {
localStorage.test6564729 += 'B';
var d = document;
var e = document.open(); // unload triggered here - beforeunload C, D in 004b; pagehide E, unload F, pagehide G in 004b, unload HIJK in 004b
localStorage.test6564729 += (e == d) ? 'L' : 'Y';
var s = 'FAIL if you see this | ' + localStorage.test6564729;
document.write(s);
localStorage.test6564729 += document.body.textContent == s ? 'M' : 'y';
document.close();
localStorage.test6564729 += 'N';
location = '004a.html'; // unload triggers again here, but they're not registered event listeners any more
})
onload = t.step_func(function() {
localStorage.test6564729 = 'A';
setTimeout(t.step_func(function() {document.getElementsByTagName("input")[0].click()}), 100);
})
</script>
<body onbeforeunload="localStorage.test6564729 += 'C'"
onpagehide="localStorage.test6564729 += 'E'"
onunload="localStorage.test6564729 += 'F'">
<input type=button value="Activate this button to run the test" onclick="do_test()">
<p><iframe src="004b.html"></iframe>

View file

@ -0,0 +1,15 @@
<!doctype html>
<title>document.open in beforeunload with button</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
var t = async_test();
var win;
t.step(function() {
win = window.open("004-1.html");
});
add_completion_callback(function() {win.close()});
</script>

View file

@ -0,0 +1,8 @@
<!DOCTYPE HTML>
<p>FAIL</p>
<script>
opener.t.step(function() {
opener.assert_equals(localStorage.test6564729, 'ABCDEFGHIJKLMN');
opener.t.done();
});
</script>

View file

@ -0,0 +1,18 @@
<!DOCTYPE HTML>
<script>
function testRun() {
localStorage.test6564729 += 'H';
var d = parent.document;
var e = parent.document.open(); // no effect, since that document is already in unload
localStorage.test6564729 += (e == d) ? 'I' : 'X';
var s = 'FAIL';
document.write(s);
localStorage.test6564729 += document.body.textContent == s ? 'x' : 'J';
document.close();
localStorage.test6564729 += 'K';
}
</script>
<body onbeforeunload="localStorage.test6564729 += 'D'"
onpagehide="localStorage.test6564729 += 'G'"
onunload="testRun()">
<p>Inner frame

View file

@ -0,0 +1,13 @@
<!DOCTYPE HTML>
<script>
onload = opener.t.step_func(function() {
localStorage.test6564729 = '0'
setTimeout(opener.t.step_func(function() {document.links[0].click()}), 100);
});
</script>
<body
onbeforeunload="localStorage.test6564729 += '1'"
onpagehide="localStorage.test6564729 += '3'"
onunload="localStorage.test6564729 += '4'">
<p><a href="005a.html">Follow this link to run the test.</a>
<p><iframe src="005b.html"></iframe>

View file

@ -0,0 +1,15 @@
<!doctype html>
<title>document.open in pagehide in iframe</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
<script>
var t = async_test();
var win;
t.step(function() {
win = window.open("005-1.html");
});
add_completion_callback(function() {win.close()});
</script>

View file

@ -0,0 +1,8 @@
<!DOCTYPE HTML>
<p>FAIL</p>
<script>
opener.t.step(function() {
opener.assert_equals(localStorage.test6564729, '012345678')
opener.t.done();
});
</script>

View file

@ -0,0 +1,17 @@
<!DOCTYPE HTML>
<script>
var t = parent.opener.t;
var do_test = t.step_func(function () {
localStorage.test6564729 += '5';
var s = 'FAIL: document.open() has canceled the navigation (' + localStorage.test6564729 + ')';
parent.document.open();
parent.document.write(s);
parent.document.close();
localStorage.test6564729 += parent.document.body.textContent.match('FAIL') == s ? 'X' : '6';
localStorage.test6564729 += '7';
});
</script>
<body onbeforeunload="localStorage.test6564729 += '2'"
onpagehide="do_test()"
onunload="localStorage.test6564729 += '8'">
<p>Inner frame

View file

@ -0,0 +1,6 @@
[
{
"id": "event-definition",
"original_id": "event-definition"
}
]

View file

@ -0,0 +1,333 @@
<!doctype html>
<html>
<head>
<title>history.pushState tests</title>
<script type="text/javascript" src="/resources/testharness.js"></script>
<script type="text/javascript" src="/resources/testharnessreport.js"></script>
<script type="text/javascript">
//does not test for firing of popstate onload, because this was dropped from the specification on 25 March 2011
//covers history.state after load, in accordance with the specification draft from 25 March 2011
//history.state before load is tested in 006 and 007
//does not test for structured cloning of FileList, File or Blob interfaces, as these require manual file selection
//**This test assumes that assignments to location.hash will be synchronous - this is how all browsers implement it.
//The spec (as of 25 March 2011) disagrees.**//
var histlength, atstep = 0, lasttimer;
setup({explicit_done:true}); //tests should take under 6 seconds + execution time
window.onload = function () {
if( location.protocol == 'file:' ) {
document.getElementsByTagName('p')[0].innerHTML = 'ERROR: This test cannot be run from file: (URL resolving will not work). It must be loaded over HTTP.';
return;
} else if( location.protocol == 'https:' ) {
document.getElementsByTagName('p')[0].innerHTML += '<br>WARNING: Browsers may intentionally fail to update history.length when pages are loaded over HTTPS, as a privacy restriction. If possible, load this page over HTTP.';
}
//use a timeout, because some browsers intentionally do not add history entries for URL changes in the onload thread
setTimeout(testinit,100);
};
function testinit() {
atstep = 1;
histlength = history.length;
iframe = document.getElementsByTagName('iframe')[0].src = 'blank2.html';
//reportload will now be called by the onload handler for the iframe
}
function reportload() {
var iframe = document.getElementsByTagName('iframe')[0], hashchng = false;
var canvassup = false, cloneobj;
function tests1() {
//Firefox may fail when reloading, because it recovers iframe state, and therefore does not see the need to alter history length
test(function () { assert_equals( history.length, histlength + 1, 'make sure that you loaded the test in a new tab/window' ); }, 'history.length should update when loading pages in an iframe');
histlength = history.length;
iframe.contentWindow.location.hash = 'test'; //should be synchronous **SEE COMMENT AT TOP OF FILE
test(function () {
assert_equals( history.length, histlength + 1, 'make sure that you loaded the test in a new tab/window' );
}, 'history.length should update when setting location.hash');
test(function () { assert_true( !!history.pushState, 'critical test; ignore any failures after this' ); }, 'history.pushState must exist'); //assert_exists does not allow prototype inheritance
test(function () { assert_true( !!iframe.contentWindow.history.pushState, 'critical test; ignore any failures after this' ); }, 'history.pushState must exist within iframes');
test(function () {
assert_equals( iframe.contentWindow.history.state, null );
}, 'initial history.state should be null');
test(function () {
histlength = history.length;
iframe.contentWindow.history.pushState('','');
assert_equals( history.length, histlength + 1 );
}, 'history.length should update when pushing a state');
test(function () {
assert_equals( iframe.contentWindow.history.state, '' );
}, 'history.state should update after a state is pushed');
histlength = history.length;
history.back();
setTimeout(tests2,50); //.back is queued to end of thread
}
function tests2() {
test(function () {
assert_equals( history.length, histlength );
}, 'history.length should not decrease after going back');
test(function () {
assert_equals( iframe.contentWindow.location.hash.replace(/^#/,''), 'test' );
}, 'traversing history must traverse pushed states');
history.go(-1);
setTimeout(tests3,50); //.go is queued to end of thread
}
function tests3() {
test(function () {
assert_equals( iframe.contentWindow.location.hash.replace(/^#/,''), '', '(this could cause other failures later on)' );
}, 'traversing history must also traverse hash changes');
//Safari 5.0.3 fails here - it navigates *this* document to the *iframe's* location, instead of just navigating the iframe
history.go(2);
setTimeout(tests4,50); //.go is queued to end of thread
}
function tests4() {
test(function () {
//Firefox 4 beta 11 has a messed up error object, which does not have the right error type or .SECURITY_ERR property
assert_throws('SECURITY_ERR',function () { history.pushState('','','//exa mple'); });
}, 'pushState must not be allowed to create invalid URLs');
test(function () {
assert_throws('SECURITY_ERR',function () { history.pushState('','','http://www.example.com/'); });
}, 'pushState must not be allowed to create cross-origin URLs');
test(function () {
assert_throws('SECURITY_ERR',function () { history.pushState('','','about:blank'); });
}, 'pushState must not be allowed to create cross-origin URLs (about:blank)');
test(function () {
assert_throws('SECURITY_ERR',function () { history.pushState('','','data:text/html,'); });
}, 'pushState must not be allowed to create cross-origin URLs (data:URI)');
test(function () {
assert_throws('SECURITY_ERR',function () { iframe.contentWindow.history.pushState('','','http://www.example.com/'); },iframe.contentWindow);
}, 'security errors are expected to be thrown in the context of the document that owns the history object');
test(function () {
iframe.contentWindow.location.hash = 'test2';
assert_equals( iframe.contentWindow.location.hash.replace(/^#/,''), 'test2', 'location.hash did not change when told to' );
}, 'location.hash must be allowed to change (part 1)');
history.go(-1);
setTimeout(tests5,50); //.go is queued to end of thread
}
function tests5() {
test(function () {
assert_equals( iframe.contentWindow.location.hash.replace(/^#/,''), 'test', 'location.hash did not change when going back' );
}, 'location.hash must be allowed to change (part 2)');
test(function () {
iframe.contentWindow.history.pushState('','');
assert_equals( iframe.contentWindow.location.hash.replace(/^#/,''), 'test', 'location.hash changed when an unrelated state was pushed' );
}, 'pushState must not alter location.hash when no URL is provided');
history.go(1); //should do nothing, since the pushState should have removed the forward history
setTimeout(tests6,50); //.go is queued to end of thread
}
function tests6() {
test(function () {
assert_equals( iframe.contentWindow.location.hash.replace(/^#/,''), 'test' );
}, 'pushState must remove all history after the current state');
test(function () {
iframe.contentWindow.history.pushState('','','#test3');
assert_equals( iframe.contentWindow.location.hash.replace(/^#/,''), 'test3' );
}, 'pushState must be able to set location.hash');
//begin setup for "remove any tasks queued by the history traversal task source"
iframe.contentWindow.location.hash = '#test4';
iframe.contentWindow.history.go(-1); //must be queued
try {
//must remove the queued navigation in the same browsing context
iframe.contentWindow.history.pushState('','');
} catch(unsuperr) {}
//allow the browser to mistakenly run the .go if it is going to
//do not put two .go commands in the same thread, in case the browser mistakenly calculates the history position when
//calling .go instead of when executing the traversal task - that could give a false PASS in the next test otherwise
setTimeout(tests7,50);
}
function tests7() {
iframe.contentWindow.history.go(-1); //must be queued, but should not be removed this time
setTimeout(tests8,50); //.go is queued to end of thread
}
function tests8() {
test(function () {
assert_equals( iframe.contentWindow.location.hash.replace(/^#/,''), 'test4' );
}, 'pushState must remove any tasks queued by the history traversal task source');
//end "remove any tasks queued by the history traversal task source"
window.addEventListener('hashchange',function () { hashchng = true; },false);
try {
//push a state that changes the hash
iframe.contentWindow.history.pushState('','',iframe.contentWindow.location.pathname+'#test5');
} catch(unsuperr) {}
setTimeout(tests9,50); //allow the hashchange event to process, if the browser has mistakenly fired it
}
function tests9() {
test(function () {
assert_false( hashchng );
}, 'pushState must not fire hashchange events');
test(function () {
iframe.contentWindow.history.pushState('','','/testing_ignore_me_404');
assert_equals( iframe.contentWindow.location.pathname, '/testing_ignore_me_404' );
}, 'pushState must be able to set location.pathname');
test(function () {
var newURL = location.href.replace(/\/[^\/]*$/)+'/testing_ignore_me_404/';
iframe.contentWindow.history.pushState('','',newURL);
assert_equals( iframe.contentWindow.location.href, newURL );
}, 'pushState must be able to set absolute URLs to the same host');
test(function () {
assert_throws( 'DATA_CLONE_ERR', function () {
history.pushState({dummy:function () {}},'');
} );
}, 'pushState must not be able to use a function as data');
test(function () {
assert_throws( 'DATA_CLONE_ERR', function () {
history.pushState({dummy:window},'');
} );
}, 'pushState must not be able to use a DOM node as data');
test(function () {
try { a.b = c; } catch(errdata) {
assert_throws( 'DATA_CLONE_ERR', function () {
history.pushState({dummy:errdata},'');
} );
}
}, 'pushState must not be able to use an error object as data');
test(function () {
assert_throws( 'DATA_CLONE_ERR', function () {
iframe.contentWindow.history.pushState(document,'');
}, iframe.contentWindow );
}, 'security errors are expected to be thrown in the context of the document that owns the history object (2)');
cloneobj = {
nulldata: null,
udefdata: window.undefined,
booldata: true,
numdata: 1,
strdata: 'string data',
boolobj: new Boolean(true),
numobj: new Number(1),
strobj: new String('string data'),
datedata: new Date(),
regdata: /a/g,
arrdata: [1]
};
cloneobj.regdata.lastIndex = 1;
cloneobj.looped = cloneobj;
//test the ImageData type, if the browser supports it
var canvas = document.createElement('canvas');
if( canvas.getContext && ( canvas = canvas.getContext('2d') ) && canvas.createImageData ) {
canvassup = true;
cloneobj.imgdata = canvas.createImageData(1,1);
}
test(function () {
try {
iframe.contentWindow.history.pushState(cloneobj,'new title');
} catch(e) {
cloneobj.looped = null;
//try again because this object is needed for future tests
iframe.contentWindow.history.pushState(cloneobj,'new title');
//rethrow so the browser gets a FAIL for not coping with the circular reference; "internal structured cloning algorithm" step 1
throw(e);
}
}, 'pushState must be able to make structured clones of complex objects');
test(function () {
assert_equals( iframe.contentWindow.history.state && iframe.contentWindow.history.state.strdata, 'string data' );
}, 'history.state should also reference a clone of the original object');
test(function () {
assert_false( cloneobj === iframe.contentWindow.history.state );
}, 'history.state should be a clone of the original object, not a reference to it');
/*
behaviour is not defined per spec, and no known implementations do this
test(function () {
assert_equals( iframe.contentDocument.title, 'new title', 'not required for specification conformance' );
}, 'pushState MIGHT set the document title');
*/
history.go(-1);
setTimeout(tests10,50); //.go is queued to end of thread
}
function tests10() {
var eventtime = setTimeout(function () { tests11(false); },500); //should be cleared by the event handler long before it has a chance to fire
iframe.contentWindow.addEventListener('popstate',function (e) { clearTimeout(eventtime); tests11(true,e); },false);
history.forward();
}
function tests11(hasFired,ev) {
test(function () {
assert_true( hasFired );
}, 'popstate event should fire when navigation occurs');
test(function () {
assert_true( !!ev && typeof(ev.state) != 'undefined', 'state information was not passed' );
assert_true( !!ev.state, 'state information does not contain the expected value - browser is probably stuck in the wrong history position' );
assert_equals( ev.state.nulldata, null, 'state null data was not correct' );
assert_equals( ev.state.udefdata, window.undefined, 'state undefined data was not correct' );
assert_true( ev.state.booldata, 'state boolean data was not correct' );
assert_equals( ev.state.numdata, 1, 'state numeric data was not correct' );
assert_equals( ev.state.strdata, 'string data', 'state string data was not correct' );
assert_true( !!ev.state.datedata.getTime, 'state date data was not correct' );
assert_exists( ev.state, 'regdata', 'state regex data was not correct' );
assert_equals( ev.state.regdata.source, 'a', 'state regex pattern data was not correct' );
assert_true( ev.state.regdata.global, 'state regex flag data was not correct' );
assert_equals( ev.state.regdata.lastIndex, 0, 'state regex lastIndex data was not correct' );
assert_equals( ev.state.arrdata.length, 1, 'state array data was not correct' );
assert_true( ev.state.boolobj.valueOf(), 'state boolean data was not correct' );
assert_equals( ev.state.numobj.valueOf(), 1, 'state numeric data was not correct' );
assert_equals( ev.state.strobj.valueOf(), 'string data', 'state string data was not correct' );
if( canvassup ) {
assert_equals( ev.state.imgdata.width, 1, 'state ImageData was not correct' );
}
}, 'popstate event should pass the state data');
test(function () {
assert_equals( ev.state.looped, ev.state );
}, 'state data should cope with circular object references');
test(function () {
assert_false( cloneobj === ev.state );
}, 'state data should be a clone of the original object, not a reference to it');
test(function () {
assert_equals( iframe.contentWindow.history.state && iframe.contentWindow.history.state.strdata, 'string data' );
}, 'history.state should also reference a clone of the original object (2)');
test(function () {
assert_false( cloneobj === iframe.contentWindow.history.state );
}, 'history.state should be a clone of the original object, not a reference to it (2)');
test(function () {
assert_false( iframe.contentWindow.history.state === ev.state );
}, 'history.state should be a separate clone of the object, not a reference to the object passed to the event handler');
try {
iframe.contentWindow.persistval = true;
iframe.contentWindow.history.pushState('','', location.href.replace(/\/[^\/]*$/,'/blank3.html') );
} catch(unsuperr) {}
//it's already cached, so this should be very fast if the browser mistakenly loads it
//it should not need to load at all, since it's just a pushed state
setTimeout(tests12,1000);
}
function tests12() {
test(function () {
assert_true( iframe.contentWindow.persistval && !iframe.contentWindow.forreal );
}, 'pushState should not actually load the new URL');
atstep = 3;
iframe.contentWindow.location.reload(); //load the real URL
lasttimer = setTimeout(function () { tests13(false); },3000); //should be cleared by the onload handler long before it has a chance to fire
}
function tests13(passed) {
test(function () {
assert_true( passed, 'expected a load event to fire when reloading the URL from cache, gave up waiting after 3 seconds' );
}, 'reloading a pushed state should actually load the new URL');
//try to make browsers behave when reloading so that the correct URL is recovered - does not always work
iframe.contentWindow.location.href = location.href.replace(/\/[^\/]*$/,'/blank.html');
done();
}
if( atstep == 1 ) {
//blank2 has loaded
atstep = 2;
//use a timeout, because some browsers intentionally do not add history entries for URL changes in an onload thread
setTimeout(tests1,100);
} else if( atstep == 3 ) {
//blank3 should now have loaded after the .reload() command
atstep = 4;
clearTimeout(lasttimer);
tests13(true);
}
}
</script>
</head>
<body>
<noscript><p>Enable JavaScript and reload</p></noscript>
<p>WARNING: This test should always be loaded in a new tab/window, to avoid browsers attempting to recover the state of frames, and history length. Do not reload the test.</p>
<div id="log">Running test...</div>
<p><iframe onload="reportload();" src="blank.html"></iframe></p>
<p><iframe src="blank.html"></iframe></p>
<p><iframe src="blank2.html"></iframe></p>
<p><iframe src="blank3.html"></iframe></p>
</body>
</html>

View file

@ -0,0 +1,308 @@
<!doctype html>
<html>
<head>
<title>history.replaceState tests</title>
<script type="text/javascript" src="/resources/testharness.js"></script>
<script type="text/javascript" src="/resources/testharnessreport.js"></script>
<script type="text/javascript">
//does not test for firing of popstate onload, because this was dropped from the specification on 25 March 2011
//covers history.state after load, in accordance with the specification draft from 25 March 2011
//history.state before load is tested in 006 and 007
//does not test for structured cloning of FileList, File or Blob interfaces, as these require manual file selection
//**This test assumes that assignments to location.hash will be synchronous - this is how all browsers implement it.
//The spec (as of 25 March 2011) disagrees.
var histlength, atstep = 0, lasttimer;
setup({explicit_done:true}); //tests should take under 6 seconds + execution time
window.onload = function () {
if( location.protocol == 'file:' ) {
document.getElementsByTagName('p')[0].innerHTML = 'ERROR: This test cannot be run from file: (URL resolving will not work). It must be loaded over HTTP.';
return;
} else if( location.protocol == 'https:' ) {
document.getElementsByTagName('p')[0].innerHTML += '<br>WARNING: Browsers may intentionally fail to update history.length when pages are loaded over HTTPS, as a privacy restriction. If possible, load this page over HTTP.';
}
//use a timeout, because some browsers intentionally do not add history entries for URL changes in the onload thread
setTimeout(testinit,100);
};
function testinit() {
atstep = 1;
histlength = history.length;
iframe = document.getElementsByTagName('iframe')[0].src = 'blank2.html';
//reportload will now be called by the onload handler for the iframe
}
function reportload() {
var iframe = document.getElementsByTagName('iframe')[0], hashchng = false;
var canvassup = false, cloneobj;
function tests1() {
test(function () { assert_equals( history.length, histlength + 1, 'make sure that you loaded the test in a new tab/window' ); }, 'history.length should update when loading pages in an iframe');
histlength = history.length;
iframe.contentWindow.location.hash = 'test'; //should be synchronous **SEE COMMENT AT TOP OF FILE
test(function () {
assert_equals( history.length, histlength + 1, 'make sure that you loaded the test in a new tab/window' );
}, 'history.length should update when setting location.hash');
test(function () { assert_true( !!history.replaceState, 'critical test; ignore any failures after this' ); }, 'history.replaceState must exist'); //assert_exists does not allow prototype inheritance
test(function () { assert_true( !!iframe.contentWindow.history.replaceState, 'critical test; ignore any failures after this' ); }, 'history.replaceState must exist within iframes');
test(function () {
assert_equals( iframe.contentWindow.history.state, null );
}, 'initial history.state should be null');
iframe.contentWindow.location.hash = 'test2';
history.back();
setTimeout(tests2,50); //.go is queued to end of thread
}
function tests2() {
test(function () {
histlength = history.length;
iframe.contentWindow.history.replaceState('','');
assert_equals( history.length, histlength );
}, 'history.length should not update when replacing a state with no URL');
test(function () {
assert_equals( iframe.contentWindow.history.state, '' );
}, 'history.state should update after a state is pushed');
test(function () {
assert_equals( iframe.contentWindow.location.hash.replace(/^#/,''), 'test' );
}, 'hash should not change when replaceState is called without a URL');
test(function () {
histlength = history.length;
iframe.contentWindow.history.replaceState('','','#test3');
assert_equals( history.length, histlength );
}, 'history.length should not update when replacing a state with a URL');
test(function () {
assert_equals( iframe.contentWindow.location.hash.replace(/^#/,''), 'test3' );
}, 'hash should change when replaceState is called with a URL');
history.go(-1);
setTimeout(tests3,50); //.go is queued to end of thread
}
function tests3() {
test(function () {
assert_equals( iframe.contentWindow.location.hash.replace(/^#/,''), '' );
}, 'replaceState must replace the existing state and not add an extra one');
history.go(2);
setTimeout(tests4,50); //.go is queued to end of thread
}
function tests4() {
test(function () {
assert_equals( iframe.contentWindow.location.hash.replace(/^#/,''), 'test2' );
}, 'replaceState must replace the existing state without altering the forward history');
test(function () {
assert_throws('SECURITY_ERR',function () { history.replaceState('','','//exa mple'); });
}, 'replaceState must not be allowed to create invalid URLs');
test(function () {
assert_throws('SECURITY_ERR',function () { history.replaceState('','','http://www.example.com/'); });
}, 'replaceState must not be allowed to create cross-origin URLs');
test(function () {
assert_throws('SECURITY_ERR',function () { history.replaceState('','','about:blank'); });
}, 'replaceState must not be allowed to create cross-origin URLs (about:blank)');
test(function () {
assert_throws('SECURITY_ERR',function () { history.replaceState('','','data:text/html,'); });
}, 'replaceState must not be allowed to create cross-origin URLs (data:URI)');
test(function () {
assert_throws('SECURITY_ERR',function () { iframe.contentWindow.history.replaceState('','','http://www.example.com/'); },iframe.contentWindow);
}, 'security errors are expected to be thrown in the context of the document that owns the history object');
test(function () {
//avoids browsers running .go synchronously when only a hash change is involved
iframe.contentWindow.history.replaceState('','','/testing_ignore_me_404#test4');
assert_equals( iframe.contentWindow.location.pathname, '/testing_ignore_me_404' );
}, 'replaceState must be able to set location.pathname');
test(function () {
var newURL = location.href.replace(/\/[^\/]*$/)+'/testing_ignore_me_404/';
iframe.contentWindow.history.replaceState('','',newURL);
assert_equals( iframe.contentWindow.location.href, newURL );
}, 'replaceState must be able to set absolute URLs to the same host');
//begin setup for "[must not] remove any tasks queued by the history traversal task source"
iframe.contentWindow.history.go(-1); //must be queued so the next command takes place *beforehand*
try {
//must not remove the queued navigation in the same browsing context
iframe.contentWindow.history.replaceState('','',iframe.contentWindow.location.pathname+'#test5');
} catch(unsuperr2) {}
//allow the browser to run the .go
setTimeout(tests5,50);
}
function tests5() {
test(function () {
assert_equals( iframe.contentWindow.location.hash.replace(/^#/,''), 'test3' );
}, 'replaceState must not remove any tasks queued by the history traversal task source');
//Safari 5.0.3 fails here - it navigates *this* document to the *iframe's* location, instead of just navigating the iframe
history.go(1);
setTimeout(tests6,50); //.go is queued to end of thread
}
function tests6() {
test(function () {
assert_equals( iframe.contentWindow.location.hash.replace(/^#/,''), 'test5' );
}, '.go must queue a task with the history traversal task source (run asynchronously)');
//end "[must not] remove any tasks queued by the history traversal task source"
window.addEventListener('hashchange',function () { hashchng = true; },false);
try {
//push a state that changes the hash
iframe.contentWindow.history.replaceState('','',iframe.contentWindow.location.pathname+'#test6');
} catch(unsuperr) {}
setTimeout(tests7,50); //allow the hashchange event to process, if the browser has mistakenly fired it
}
function tests7() {
test(function () {
assert_false( hashchng );
}, 'replaceState must not fire hashchange events');
test(function () {
assert_throws( 'DATA_CLONE_ERR', function () {
history.replaceState({dummy:function () {}},'');
} );
}, 'replaceState must not be able to use a function as data');
test(function () {
assert_throws( 'DATA_CLONE_ERR', function () {
history.replaceState({dummy:window},'');
} );
}, 'replaceState must not be able to use a DOM node as data');
test(function () {
try { a.b = c; } catch(errdata) {
assert_throws( 'DATA_CLONE_ERR', function () {
history.replaceState({dummy:errdata},'');
} );
}
}, 'replaceState must not be able to use an error object as data');
test(function () {
assert_throws( 'DATA_CLONE_ERR', function () {
iframe.contentWindow.history.replaceState(document,'');
}, iframe.contentWindow );
}, 'security errors are expected to be thrown in the context of the document that owns the history object (2)');
cloneobj = {
nulldata: null,
udefdata: window.undefined,
booldata: true,
numdata: 1,
strdata: 'string data',
boolobj: new Boolean(true),
numobj: new Number(1),
strobj: new String('string data'),
datedata: new Date(),
regdata: /a/g,
arrdata: [1]
};
cloneobj.regdata.lastIndex = 1;
cloneobj.looped = cloneobj;
//test the ImageData type, if the browser supports it
var canvas = document.createElement('canvas');
if( canvas.getContext && ( canvas = canvas.getContext('2d') ) && canvas.createImageData ) {
canvassup = true;
cloneobj.imgdata = canvas.createImageData(1,1);
}
test(function () {
try {
iframe.contentWindow.history.replaceState(cloneobj,'new title');
} catch(e) {
cloneobj.looped = null;
//try again because this object is needed for future tests
iframe.contentWindow.history.replaceState(cloneobj,'new title');
//rethrow so the browser gets a FAIL for not coping with the circular reference; "internal structured cloning algorithm" step 1
throw(e);
}
}, 'replaceState must be able to make structured clones of complex objects');
test(function () {
assert_equals( iframe.contentWindow.history.state && iframe.contentWindow.history.state.strdata, 'string data' );
}, 'history.state should also reference a clone of the original object');
test(function () {
assert_false( cloneobj === iframe.contentWindow.history.state );
}, 'history.state should be a clone of the original object, not a reference to it');
history.go(-1);
setTimeout(tests8,50); //.go is queued to end of thread
}
function tests8() {
var eventtime = setTimeout(function () { tests9(false); },500); //should be cleared by the event handler long before it has a chance to fire
iframe.contentWindow.addEventListener('popstate',function (e) { clearTimeout(eventtime); tests9(true,e); },false);
history.forward();
}
function tests9(hasFired,ev) {
test(function () {
assert_true( hasFired );
}, 'popstate event should fire when navigation occurs');
test(function () {
assert_true( !!ev && typeof(ev.state) != 'undefined', 'state information was not passed' );
assert_true( !!ev.state, 'state information does not contain the expected value - browser is probably stuck in the wrong history position' );
assert_equals( ev.state.nulldata, null, 'state null data was not correct' );
assert_equals( ev.state.udefdata, window.undefined, 'state undefined data was not correct' );
assert_true( ev.state.booldata, 'state boolean data was not correct' );
assert_equals( ev.state.numdata, 1, 'state numeric data was not correct' );
assert_equals( ev.state.strdata, 'string data', 'state string data was not correct' );
assert_true( !!ev.state.datedata.getTime, 'state date data was not correct' );
assert_exists( ev.state, 'regdata', 'state regex data was not correct' );
assert_equals( ev.state.regdata.source, 'a', 'state regex pattern data was not correct' );
assert_true( ev.state.regdata.global, 'state regex flag data was not correct' );
assert_equals( ev.state.regdata.lastIndex, 0, 'state regex lastIndex data was not correct' );
assert_equals( ev.state.arrdata.length, 1, 'state array data was not correct' );
assert_true( ev.state.boolobj.valueOf(), 'state boolean data was not correct' );
assert_equals( ev.state.numobj.valueOf(), 1, 'state numeric data was not correct' );
assert_equals( ev.state.strobj.valueOf(), 'string data', 'state string data was not correct' );
if( canvassup ) {
assert_equals( ev.state.imgdata.width, 1, 'state ImageData was not correct' );
}
}, 'popstate event should pass the state data');
test(function () {
assert_equals( ev.state.looped, ev.state );
}, 'state data should cope with circular object references');
test(function () {
assert_false( cloneobj === ev.state );
}, 'state data should be a clone of the original object, not a reference to it');
test(function () {
assert_equals( iframe.contentWindow.history.state && iframe.contentWindow.history.state.strdata, 'string data' );
}, 'history.state should also reference a clone of the original object (2)');
test(function () {
assert_false( cloneobj === iframe.contentWindow.history.state );
}, 'history.state should be a clone of the original object, not a reference to it (2)');
test(function () {
assert_false( iframe.contentWindow.history.state === ev.state );
}, 'history.state should be a separate clone of the object, not a reference to the object passed to the event handler');
try {
iframe.contentWindow.persistval = true;
iframe.contentWindow.history.replaceState('','', location.href.replace(/\/[^\/]*$/,'/blank3.html') );
} catch(unsuperr) {}
//it's already cached, so this should be very fast if the browser mistakenly loads it
//it should not need to load at all, since it's just a pushed state
setTimeout(tests10,1000);
}
function tests10() {
test(function () {
assert_true( iframe.contentWindow.persistval && !iframe.contentWindow.forreal );
}, 'replaceState should not actually load the new URL');
atstep = 3;
iframe.contentWindow.location.reload(); //load the real URL
lasttimer = setTimeout(function () { tests11(false); },3000); //should be cleared by the onload handler long before it has a chance to fire
}
function tests11(passed) {
test(function () {
assert_true( passed, 'expected a load event to fire when reloading the URL from cache, gave up waiting after 3 seconds' );
}, 'reloading a replaced state should actually load the new URL');
//try to make browsers behave when reloading so that the correct URL is recovered - does not always work
iframe.contentWindow.location.href = location.href.replace(/\/[^\/]*$/,'/blank.html');
done();
}
if( atstep == 1 ) {
//blank2 has loaded
atstep = 2;
//use a timeout, because some browsers intentionally do not add history entries for URL changes in an onload thread
setTimeout(tests1,100);
} else if( atstep == 3 ) {
//blank3 should now have loaded after the .reload() command
atstep = 4;
clearTimeout(lasttimer);
tests11(true);
}
}
</script>
</head>
<body>
<noscript><p>Enable JavaScript and reload</p></noscript>
<p>WARNING: This test should always be loaded in a new tab/window, to avoid browsers attempting to recover the state of frames, and history length. Do not reload the test.</p>
<div id="log">Running test...</div>
<p><iframe onload="reportload();" src="blank.html"></iframe></p>
<p><iframe src="blank.html"></iframe></p>
<p><iframe src="blank2.html"></iframe></p>
<p><iframe src="blank3.html"></iframe></p>
</body>
</html>

View file

@ -0,0 +1,62 @@
<!doctype html>
<html>
<head>
<title>Final history position for history.go should be calculated when executing the task</title>
<script type="text/javascript" src="/resources/testharness.js"></script>
<script type="text/javascript" src="/resources/testharnessreport.js"></script>
<script type="text/javascript">
setup({explicit_done:true});
window.onload = function () {
var hashcount = 0;
if( location.hash && location.hash != '#' ) {
location.href = location.href.replace(/#.*$/,'');
return;
}
setTimeout(add1,100);
function add1() {
location.hash = '#foo';
setTimeout(add2,100);
}
function add2() {
location.hash = '#bar';
setTimeout(add3,100);
}
function add3() {
location.hash = '#baz';
setTimeout(dojumps,100);
}
function dojumps() {
window.onhashchange = function () {
hashcount++;
};
history.go(-2);
test(function () {
//many browsers special-case jumps that only imply hash changes and will do them synchronously - the spec does allow this
assert_equals( hashcount, 0, 'hashchange fired even though the location should not have changed' );
assert_equals( location.hash.replace(/^#/,''), 'baz', 'the browser navigated synchronously' );
}, '.go commands should be queued until the thread has ended');
history.go(-1);
setTimeout(checkjumps,100);
}
function checkjumps() {
test(function () {
assert_true( !!hashcount, 'this testcase requires haschange support; the test cannot be used in this browser' );
}, 'browser needs to support hashchange events for this testcase');
test(function () {
assert_equals( hashcount, 2, 'the wrong number of queued commands were executed' );
}, 'queued .go commands should all be executed when the queue is processed');
test(function () {
assert_equals( location.hash.replace(/^#/,''), '' );
}, 'history position should be calculated when executing, not when calling the .go command');
done();
}
};
</script>
</head>
<body>
<noscript><p>Enable JavaScript and reload</p></noscript>
<div id="log"></div>
</body>
</html>

View file

@ -0,0 +1,47 @@
<!doctype html>
<html>
<head>
<title>Popstate event listener registration</title>
<script type="text/javascript" src="/resources/testharness.js"></script>
<script type="text/javascript" src="/resources/testharnessreport.js"></script>
<script type="text/javascript">
//this test checks that onpopstate works on the body element
var readyForPop = false, bodypop = false, inlinepop = false;
setup({explicit_done:true});
//use a timeout to avoid "popstate fires onload" from setting the variables too early
setTimeout(step1,1000);
function step1() {
readyForPop = true;
test(function () {
history.pushState('','');
history.pushState('','');
}, 'history.pushState support is needed for this testcase');
history.go(-1);
setTimeout(step2,50); //.go is queued to end of thread
}
function step2() {
test(function () {
assert_true( bodypop );
}, '<body onpopstate="..."> should register a listener for the popstate event');
window.onpopstate = function () { inlinepop = true; };
history.go(-1);
setTimeout(step3,50); //.go is queued to end of thread
}
function step3() {
test(function () {
assert_true( inlinepop );
}, 'window.onpopstate should register a listener for the popstate event');
done();
}
</script>
</head>
<body onpopstate="if( readyForPop ) { bodypop = true; }">
<noscript><p>Enable JavaScript and reload</p></noscript>
<div id="log"></div>
</body>
</html>

View file

@ -0,0 +1,53 @@
<!doctype html>
<html>
<head>
<title>Firing popstate after onload, even if there is no pushed/replaced state</title>
<script type="text/javascript" src="/resources/testharness.js"></script>
<script type="text/javascript" src="/resources/testharnessreport.js"></script>
<script type="text/javascript">
//spec (25 March 2011 draft) states that popstate must not fire after onload unless there is a pushed/replaced state that is navigated
var popfired = false;
setup({explicit_done:true});
window.addEventListener('popstate',function (e) { popfired = true; },false);
test(function () {
assert_equals( history.state, null );
}, 'history.state should initially be null');
window.onload = function () {
test(function () {
assert_false( popfired );
}, 'popstate event should not fire before onload fires');
test(function () {
assert_equals( history.state, null );
}, 'history.state should still be null onload');
popfired = false;
setTimeout(function () {
test(function () {
assert_false( popfired );
}, 'popstate event should not fire after onload fires');
test(function () {
assert_equals( history.state, null );
}, 'history.state should still be null after onload');
test(function () {
var failed = false, realstate = history.state;
try {
history.state = '';
} catch(e) {
failed = e;
}
assert_equals(history.state,realstate,'property was read/write');
assert_false(failed);
}, 'writing to history.state should be silently ignored and not throw an error');
done();
},100);
};
</script>
</head>
<body>
<noscript><p>Enable JavaScript and reload</p></noscript>
<div id="log"></div>
</body>
</html>

View file

@ -0,0 +1,56 @@
<!doctype html>
<html>
<head>
<title>Firing popstate after onload with pushed state</title>
<meta name=timeout content=long>
<script type="text/javascript" src="/resources/testharness.js"></script>
<script type="text/javascript" src="/resources/testharnessreport.js"></script>
</head>
<body>
<noscript><p>Enable JavaScript and reload</p></noscript>
<div id="log">It looks like the browser stopped loading the page when encountering a .go(-1) command pointing to a pushed state. This will break the tests.</div>
<script type="text/javascript">
//spec (25 March 2011 draft) states that popstate must fire before onload if there is a pushed/replaced state that is navigated
var popfired = false;
setup({explicit_done:true});
test(function () {
assert_equals( history.state, null );
}, 'history.state should initially be null');
window.addEventListener('popstate',function (e) { popfired = e.state; },false);
test(function () {
history.pushState('state1','');
history.pushState('state2','');
}, 'history.pushState support is needed for this testcase');
test(function () {
assert_equals( history.state, 'state2' );
}, 'history.state should reflect pushed state');
if( history.pushState ) { history.go(-1); }
window.onload = function () {
test(function () {
assert_true( !!popfired );
}, 'popstate event should fire before onload fires');
test(function () {
assert_equals( popfired, 'state1' );
}, 'the correct state should be restored when navigating during initial load');
test(function () {
assert_equals( history.state, 'state1' );
}, 'history.state should reflect the navigated state onload');
popfired = false;
setTimeout(function () {
test(function () {
assert_false( !!popfired );
}, 'popstate event should not fire after onload fires');
test(function () {
assert_equals( history.state, 'state1' );
}, 'history.state should reflect the navigated state after onload');
done();
if( history.pushState ) { history.go(-1); } //go back to the start to avoid state recovery when reloading
},100);
};
</script>
</body>
</html>

View file

@ -0,0 +1,40 @@
<!doctype html>
<html>
<!-- configure this test below to point to the script -->
<head>
<title>history.pushState/replaceState resolving</title>
<script type="text/javascript" src="/resources/testharness.js"></script>
<script type="text/javascript" src="/resources/testharnessreport.js"></script>
</head>
<body>
<p></p>
<noscript><p>Enable JavaScript and reload</p></noscript>
<div id="log"></div>
<script type="text/javascript">
/*
Location of the script (which must be hosted on a separate domain from this test) containing the test code:
var beforehref = location.href;
test(function () {
history.pushState('','','/testing_ignore_me_404');
assert_equals(location.href,beforehref.replace(/^(\w*:\/\/[^\/]*\/)[\w\W]*$/,'$1testing_ignore_me_404'));
}, 'history.pushState URL resolving should be done relative to the document, not the script');
test(function () {
history.replaceState('','','/testing_ignore_me_404_2');
assert_equals(location.href,beforehref.replace(/^(\w*:\/\/[^\/]*\/)[\w\W]*$/,'$1testing_ignore_me_404_2'));
}, 'history.replaceState URL resolving should be done relative to the document, not the script');
*/
var scriptlocation = 'http://www.' + location.host + location.pathname.split("/").slice(0,-1).join("/") + "/008.js";
if( location.protocol == 'file:' ) {
document.getElementsByTagName('p')[0].innerHTML = 'ERROR: This test cannot be run from file: (URL resolving will not work). It must be loaded over HTTP.';
} else {
document.write('<script type="text\/javascript" src="'+scriptlocation+'"><\/script>');
}
</script>
</body>
</html>

View file

@ -0,0 +1,20 @@
<!doctype html>
<html>
<head>
<title>history.pushState/replaceState and referer headers</title>
</head>
<body>
<noscript><p>Enable JavaScript and reload</p></noscript>
<div id="log"></div>
<script type="text/javascript">
window.onload = function () {
setTimeout(function () {
try { history.pushState('','','009-2.html?1234'); } catch(e) {}
location.href = '009-3.html?pipe=sub';
},10);
};
</script>
</body>
</html>

View file

@ -0,0 +1,28 @@
<!doctype html>
<html>
<head>
<title>history.pushState/replaceState and referer headers</title>
</head>
<body>
<noscript><p>Enable JavaScript and reload</p></noscript>
<div id="log"></div>
<script type="text/javascript">
var httpReferer = "{{headers[referer]}}";
var lastUrl = location.href.replace(/\/[^\/]*$/,'\/009-2.html?1234');
parent.test(function () {
parent.assert_equals( httpReferer, lastUrl );
}, 'HTTP Referer should use the pushed state');
parent.test(function () {
parent.assert_equals( document.referrer, lastUrl );
}, 'document.referrer should use the pushed state');
window.onload = function () {
setTimeout(function () {
try { history.pushState('','','009-4.html?2345'); } catch(e) {}
location.href = '009-5.html?pipe=sub';
},10);
};
</script>
</body>
</html>

View file

@ -0,0 +1,23 @@
<!doctype html>
<html>
<head>
<title>history.pushState/replaceState and referer headers</title>
</head>
<body>
<noscript><p>Enable JavaScript and reload</p></noscript>
<div id="log"></div>
<script type="text/javascript">
var httpReferer = unescape("{{headers[referer]}}");
var lastUrl = location.href.replace(/\/[^\/]*$/,'\/009-4.html?2345');
parent.test(function () {
parent.assert_equals( httpReferer, lastUrl );
}, 'HTTP Referer should use the replaced state');
parent.test(function () {
parent.assert_equals( document.referrer, lastUrl );
}, 'document.referrer should use the replaced state');
parent.done();
</script>
</body>
</html>

View file

@ -0,0 +1,22 @@
<!doctype html>
<html>
<head>
<title>history.pushState/replaceState and referer headers</title>
<script type="text/javascript" src="/resources/testharness.js"></script>
<script type="text/javascript" src="/resources/testharnessreport.js"></script>
</head>
<body>
<noscript><p>Enable JavaScript and reload</p></noscript>
<div id="log"></div>
<script type="text/javascript">
setup({explicit_done:true});
var iframe = document.createElement('iframe');
window.onload = function () {
iframe.setAttribute('src','009-1.html');
document.body.appendChild(iframe)
};
</script>
</body>
</html>

View file

@ -0,0 +1,16 @@
<!doctype html>
<html>
<head>
<title>history.pushState/replaceState and referer headers (before onload)</title>
</head>
<body>
<noscript><p>Enable JavaScript and reload</p></noscript>
<div id="log"></div>
<script type="text/javascript">
try { history.pushState('','','010-2.html?1234'); } catch(e) {}
location.href = '010-3.html?pipe=sub';
</script>
</body>
</html>

View file

@ -0,0 +1,24 @@
<!doctype html>
<html>
<head>
<title>history.pushState/replaceState and referer headers (before onload)</title>
</head>
<body>
<noscript><p>Enable JavaScript and reload</p></noscript>
<div id="log"></div>
<script type="text/javascript">
var httpReferer = "{{headers[referer]}}";
var lastUrl = location.href.replace(/\/[^\/]*$/,'\/010-2.html?1234');
parent.test(function () {
parent.assert_equals( httpReferer, lastUrl );
}, 'HTTP Referer should use the pushed state (before onload)');
parent.test(function () {
parent.assert_equals( document.referrer, lastUrl );
}, 'document.referrer should use the pushed state (before onload)');
try { history.pushState('','','010-4.html?2345'); } catch(e) {}
location.href = '010-5.html?pipe=sub';
</script>
</body>
</html>

View file

@ -0,0 +1,23 @@
<!doctype html>
<html>
<head>
<title>history.pushState/replaceState and referer headers (before onload)</title>
</head>
<body>
<noscript><p>Enable JavaScript and reload</p></noscript>
<div id="log"></div>
<script type="text/javascript">
var httpReferer = "{{headers[referer]}}";
var lastUrl = location.href.replace(/\/[^\/]*$/,'\/010-4.html?2345');
parent.test(function () {
parent.assert_equals( httpReferer, lastUrl );
}, 'HTTP Referer should use the replaced state (before onload)');
parent.test(function () {
parent.assert_equals( document.referrer, lastUrl );
}, 'document.referrer should use the replaced state (before onload)');
parent.done();
</script>
</body>
</html>

View file

@ -0,0 +1,22 @@
<!doctype html>
<html>
<head>
<title>history.pushState/replaceState and referer headers (before onload)</title>
<script type="text/javascript" src="/resources/testharness.js"></script>
<script type="text/javascript" src="/resources/testharnessreport.js"></script>
</head>
<body>
<noscript><p>Enable JavaScript and reload</p></noscript>
<div id="log"></div>
<script type="text/javascript">
setup({explicit_done:true});
var iframe = document.createElement('iframe');
window.onload = function () {
iframe.setAttribute('src','010-1.html');
document.body.appendChild(iframe)
};
</script>
</body>
</html>

View file

@ -0,0 +1,32 @@
<!doctype html>
<html>
<head>
<title>history.pushState before onload</title>
<script type="text/javascript" src="/resources/testharness.js"></script>
<script type="text/javascript" src="/resources/testharnessreport.js"></script>
</head>
<body>
<noscript><p>Enable JavaScript and reload</p></noscript>
<div id="log"></div>
<script type="text/javascript">
var newUrl = location.href.replace(/\/[^\/]*$/,'\/011-1.html');
setup({explicit_done:true});
test(function () {
history.pushState('','','011-1.html');
}, 'pushState should be able to set the location state');
test(function () {
assert_equals( location.href, newUrl );
}, 'pushed location should be reflected immediately');
window.onload = function () {
setTimeout(function () {
test(function () {
assert_equals( location.href, newUrl );
}, 'pushed location should be retained after the page has loaded');
done();
},10);
};
</script>
</body>
</html>

View file

@ -0,0 +1,32 @@
<!doctype html>
<html>
<head>
<title>history.replaceState before onload</title>
<script type="text/javascript" src="/resources/testharness.js"></script>
<script type="text/javascript" src="/resources/testharnessreport.js"></script>
</head>
<body>
<noscript><p>Enable JavaScript and reload</p></noscript>
<div id="log"></div>
<script type="text/javascript">
var newUrl = location.href.replace(/\/[^\/]*$/,'\/011-1.html');
setup({explicit_done:true});
test(function () {
history.replaceState('','','011-1.html');
}, 'replaceState should be able to set the location state');
test(function () {
assert_equals( location.href, newUrl );
}, 'replaced location should be reflected immediately');
window.onload = function () {
setTimeout(function () {
test(function () {
assert_equals( location.href, newUrl );
}, 'replaced location should be retained after the page has loaded');
done();
},10);
};
</script>
</body>
</html>

View file

@ -0,0 +1,8 @@
<!doctype html>
<html>
<head>
<title>Dummy page 1</title>
</head>
<body>
</body>
</html>

View file

@ -0,0 +1,13 @@
<!doctype html>
<html>
<head>
<title>Dummy page 2</title>
</head>
<body>
<script type="text/javascript">
if( self == top || !parent.reportload ) {
document.write("<p>FAIL. Browser got confused when navigating forwards, and navigated the whole window to the iframe's location, instead of just navigating the iframe. It is not possible to run the testsuite.<\/p>");
}
</script>
</body>
</html>

View file

@ -0,0 +1,11 @@
<!doctype html>
<html>
<head>
<title>Dummy page 3</title>
<script type="text/javascript">
var forreal = true;
</script>
</head>
<body>
</body>
</html>

View file

@ -0,0 +1,20 @@
<!DOCTYPE HTML>
<html>
<head>
<title>combination_history_001(Combine pushState and replaceSate methods.)</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="log"></div>
<script>
test(function () {
window.history.pushState(1, document.title, '?x=1');
assert_equals(history.state, 1, "first");
window.history.replaceState(2, document.title, '?x=1');
assert_equals(history.state, 2, "second")
}, "Combine pushState and replaceSate methods");
</script>
</body>
</html>

View file

@ -0,0 +1,22 @@
<!DOCTYPE HTML>
<html>
<head>
<title>combination_history_002(After calling of pushState method, check length.)</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="log"></div>
<script>
test(function () {
var first;
var second;
first = window.history.length;
window.history.pushState(1, document.title, '?x=1');
second = window.history.length;
assert_equals(second - first, 1, "second - first");
}, "After calling of pushState method, check length");
</script>
</body>
</html>

View file

@ -0,0 +1,26 @@
<!DOCTYPE HTML>
<html>
<head>
<title>combination_history_003(After calling of pushState and replaceState methods, check length.)</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="log"></div>
<script>
test(function () {
var first;
var second;
var third;
first = window.history.length;
window.history.pushState(1, document.title, '?x=1');
second = window.history.length;
window.history.replaceState(2, document.title, '?x=2');
third = window.history.length;
assert_equals(second - first, 1, "second - first");
assert_equals(third, second, "third");
}, "After calling of pushState and replaceState methods, check length");
</script>
</body>
</html>

View file

@ -0,0 +1,29 @@
<!DOCTYPE HTML>
<html>
<head>
<title>combination_history_004(After calling of back method, check length.)</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="log"></div>
<script>
var t = async_test("After calling of back method, check length");
var last;
t.step(function () {
window.history.pushState(1, document.title, '?x=1');
window.history.pushState(2, document.title, '?x=2');
last = window.history.length;
window.history.back();
});
window.addEventListener('popstate', t.step_func(function(e) {
assert_equals(e.state, 1, "state");
assert_equals(window.history.length, last, "last");
t.done();
}), false);
</script>
</body>
</html>

View file

@ -0,0 +1,34 @@
<!DOCTYPE HTML>
<html>
<head>
<title>combination_history_005(After calling of forward method, check length.)</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="log"></div>
<script>
var t = async_test("After calling of forward method, check length");
var last;
var fired = false;
t.step(function () {
window.history.pushState(1, document.title, '?x=1');
window.history.pushState(2, document.title, '?x=2');
last = window.history.length;
window.history.back();
});
window.addEventListener('popstate', t.step_func(function(e) {
if(fired) {
assert_equals(e.state, 2, "state");
assert_equals(window.history.length, last, "last");
t.done();
}
fired = true;
window.history.forward();
}), false);
</script>
</body>
</html>

View file

@ -0,0 +1,30 @@
<!DOCTYPE HTML>
<html>
<head>
<title>combination_history_006(After calling of go method, check length.)</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="log"></div>
<script>
var t = async_test("After calling of go method, check length");
var last;
t.step(function () {
window.history.pushState(1, document.title, '?x=1');
window.history.pushState(2, document.title, '?x=2');
last = window.history.length;
window.history.go(-1);
});
window.addEventListener('popstate', t.step_func(function(e) {
assert_equals(e.state, 1, "state");
assert_equals(window.history.length, last, "last");
t.done();
}), false);
</script>
</body>
</html>

View file

@ -0,0 +1,32 @@
<!DOCTYPE HTML>
<html>
<head>
<title>combination_history_007(After calling of back and pushState method, check length.)</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="log"></div>
<script>
var t = async_test("After calling of back and pushState method, check length");
var last;
t.step(function () {
window.history.pushState(1, document.title, '?x=1');
window.history.pushState(2, document.title, '?x=2');
last = window.history.length;
window.history.back();
});
window.addEventListener('popstate', t.step_func(function(e) {
assert_equals(e.state, 1, "state");
assert_equals(window.history.length, last, "last");
window.history.pushState(3, document.title, '?x=3');
assert_equals(window.history.length, last, "last");
t.done();
}), false);
</script>
</body>
</html>

View file

@ -0,0 +1,27 @@
<!DOCTYPE HTML>
<html>
<head>
<title>history_back</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="log"></div>
<script>
var t = async_test("history back");
t.step(function () {
window.history.pushState(1, document.title, '?x=1');
window.history.pushState(2, document.title, '?x=2');
window.history.back();
});
window.addEventListener('popstate', t.step_func(function(e) {
assert_equals(e.state, 1, "history state");
t.done();
}), false);
</script>
</body>
</html>

View file

@ -0,0 +1,32 @@
<!DOCTYPE HTML>
<html>
<head>
<title>history_forward</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="log"></div>
<script>
var t = async_test("history forward");
var fired = false;
t.step(function () {
window.history.pushState(1, document.title, '?x=1');
window.history.pushState(2, document.title, '?x=2');
window.history.back();
});
window.addEventListener('popstate', t.step_func(function(e) {
if(fired) {
assert_equals(e.state, 2, "history state");
t.done();
}
fired = true;
window.history.forward();
}), false);
</script>
</body>
</html>

View file

@ -0,0 +1,27 @@
<!DOCTYPE HTML>
<html>
<head>
<title>history_go_minus</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="log"></div>
<script>
var t = async_test("history go minus");
t.step(function () {
window.history.pushState(1, document.title, '?x=1');
window.history.pushState(2, document.title, '?x=2');
window.history.go(-1);
});
window.addEventListener('popstate', t.step_func(function(e) {
assert_equals(e.state, 1, "history state");
t.done();
}), false);
</script>
</body>
</html>

View file

@ -0,0 +1,33 @@
<!DOCTYPE HTML>
<html>
<head>
<title>history_go_plus</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="log"></div>
<script>
var t = async_test("history go plus");
var fired = false;
t.step(function () {
window.history.pushState(1, document.title, '?x=1');
window.history.pushState(2, document.title, '?x=2');
window.history.back();
});
window.addEventListener('popstate', t.step_func(function(e) {
if(fired) {
assert_equals(e.state, 2, "history state");
t.done();
}
fired = true;
window.history.go(1);
}), false);
</script>
</body>
</html>

View file

@ -0,0 +1,19 @@
<!DOCTYPE HTML>
<html>
<head>
<title>history_pushState</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="log"></div>
<script>
test(function () {
window.history.pushState(1, document.title, '?x=1');
var state;
state = window.history.state;
assert_equals(state, 1, "history state");
}, "history pushState");
</script>
</body>
</html>

View file

@ -0,0 +1,18 @@
<!DOCTYPE HTML>
<html>
<head>
<title>history_pushState SECURITY_ERR</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="log"></div>
<script>
test(function () {
assert_throws("SecurityError", function () {
window.history.pushState(1, document.title, 'http://www.microsoft.com/test.html');
});
}, "history pushState SECURITY_ERR");
</script>
</body>
</html>

View file

@ -0,0 +1,20 @@
<!DOCTYPE HTML>
<html>
<head>
<title>history_pushState_NoOptionalParam</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="log"></div>
<script>
test(function () {
window.history.pushState(1, document.title);
var state;
state = window.history.state;
assert_equals(state, 1, "history state");
}, "history pushState NoOptionalParam");
</script>
</body>
</html>

View file

@ -0,0 +1,20 @@
<!DOCTYPE HTML>
<html>
<head>
<title>history_replaceState</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="log"></div>
<script>
test(function () {
window.history.replaceState(1, document.title, '?x=1');
var second;
second = window.history.state;
assert_equals(second, 1, "history state");
}, "history replaceState");
</script>
</body>
</html>

View file

@ -0,0 +1,18 @@
<!DOCTYPE HTML>
<html>
<head>
<title>history_replaceState SECURITY_ERR</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="log"></div>
<script>
test(function () {
assert_throws("SecurityError", function () {
window.history.replaceState(1, document.title, 'http://www.microsoft.com/test.html');
});
}, "history replaceState SECURITY_ERR");
</script>
</body>
</html>

View file

@ -0,0 +1,20 @@
<!DOCTYPE HTML>
<html>
<head>
<title>history_replaceStateNoOptionalParam</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="log"></div>
<script>
test(function () {
window.history.replaceState(1, document.title);
var second;
second = window.history.state;
assert_equals(second, 1, "history state");
}, "history replaceStateNoOptionalParam");
</script>
</body>
</html>

View file

@ -0,0 +1,24 @@
<!DOCTYPE HTML>
<html>
<head>
<title>history_state</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="log"></div>
<script>
test(function () {
var first;
var second;
first = window.history.state;
window.history.pushState(1, document.title, '?x=1');
second = window.history.state;
assert_equals(first, null, "first");
assert_equals(second, 1, "second");
}, "history state");
</script>
</body>
</html>

View file

@ -0,0 +1,6 @@
[
{
"id": "security-location",
"original_id": "security-location"
}
]

View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<title>Location stringifier</title>
<link rel="author" title="Ms2ger" href="mailto:ms2ger@gmail.com">
<link rel="help" href="https://heycam.github.io/webidl/#es-stringifier">
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=/common/stringifiers.js></script>
<div id=log></div>
<script>
test_stringifier_attribute(location, "href", true);
</script>

View file

@ -0,0 +1,20 @@
<!DOCTYPE HTML>
<html>
<head>
<title>location_assign</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="log"></div>
<script>
test(function () {
var href = location.href;
location.assign('#x');
assert_equals((href + "#x"), location.href, "location href");
}, "location assign");
</script>
</body>
</html>

View file

@ -0,0 +1,20 @@
<!DOCTYPE HTML>
<html>
<head>
<title>location_hash</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="log"></div>
<script>
test(function () {
window.history.pushState(1, document.title, '#x=1');
var hash = location.hash;
assert_equals(hash, "#x=1", "hash");
}, "location hash");
</script>
</body>
</html>

View file

@ -0,0 +1,28 @@
<!DOCTYPE HTML>
<html>
<head>
<title>location_host</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="log"></div>
<script>
test(function () {
var host = location.host;
var url = location.href;
var pos = url.indexOf("//");
if (pos != -1) {
url = url.substr(pos+2, url.length-pos-2);
pos = url.indexOf("/");
if (pos != -1)
url = url.substr(0, pos);
}
assert_equals(host, url, "host");
}, "location host");
</script>
</body>
</html>

View file

@ -0,0 +1,33 @@
<!DOCTYPE HTML>
<html>
<head>
<title>location_hostname</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="log"></div>
<script>
test(function () {
var hostname = location.hostname;
var url = location.href;
var pos = url.indexOf("//");
if (pos != -1) {
url = url.substr(pos+2, url.length-pos-2);
pos = url.indexOf(":");
if (pos != -1) {
url = url.substr(0, pos);
} else {
pos = url.indexOf("/");
if (pos != -1)
url = url.substr(0, pos);
}
}
assert_equals(hostname, url, "hostname");
}, "location hostname");
</script>
</body>
</html>

View file

@ -0,0 +1,19 @@
<!DOCTYPE HTML>
<html>
<head>
<title>location_href</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="log"></div>
<script>
test(function () {
var href = location.href;
assert_equals(href, document.URL, "href");
}, "location href");
</script>
</body>
</html>

View file

@ -0,0 +1,22 @@
<!DOCTYPE HTML>
<html>
<head>
<title>location_pathname</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="log"></div>
<script>
test(function () {
var pathname = location.pathname;
var url = location.href
url = url.replace(location.protocol + "//" + location.host, "");
assert_equals(pathname, url, "pathname");
}, "location pathname");
</script>
</body>
</html>

View file

@ -0,0 +1,31 @@
<!DOCTYPE HTML>
<html>
<head>
<title>location_port</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="log"></div>
<script>
test(function () {
var port = location.port;
var url = location.href;
var pos = url.indexOf("//");
if (pos != -1) {
url = url.substr(pos+2, url.length-pos-2);
pos = url.indexOf("/");
if (pos != -1)
url = url.substr(0, pos);
pos = url.indexOf(":");
if (pos != -1)
url = url.substr(pos+1, url.length-pos-1);
}
assert_equals(port, url, "port");
}, "location port");
</script>
</body>
</html>

View file

@ -0,0 +1,25 @@
<!DOCTYPE HTML>
<html>
<head>
<title>location_protocol</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="log"></div>
<script>
test(function () {
var protocol = location.protocol;
var url = location.href;
var pos = url.indexOf("//");
if (pos != -1) {
url = url.substr(0, pos);
}
assert_equals(protocol, url, "protocol");
}, "location protocol");
</script>
</body>
</html>

View file

@ -0,0 +1,20 @@
<!DOCTYPE HTML>
<html>
<head>
<title>location_replace</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="log"></div>
<script>
test(function () {
var href = location.href;
location.replace('#x');
assert_equals((href + "#x"), location.href, "location href");
}, "location replace");
</script>
</body>
</html>

View file

@ -0,0 +1,20 @@
<!DOCTYPE HTML>
<html>
<head>
<title>location_search</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="log"></div>
<script>
test(function () {
window.history.pushState(1, document.title, '?x=1');
var search = location.search;
assert_equals(search, "?x=1", "search");
}, "location search");
</script>
</body>
</html>

View file

@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<title>Location interface Security</title>
<link rel="author" title="Microsoft" href="http://www.microsoft.com/" />
<link rel="help" href="https://html.spec.whatwg.org/multipage/#security-location" />
<meta name="assert" content="access location object from different origins doesn't raise SECURITY_ERR exception" />
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<p>Access location object from different origins doesn't raise SECURITY_ERR exception</p>
<div id=log></div>
<script>
var runTest = async_test("Accessing location object from different origins doesn't raise SECURITY_ERR exception").step_func_done(function() {
var frame = document.getElementById('testframe');
frame.setAttribute('onload', '');
frame.contentWindow.location = 'http://{{domains[www1]}}:{{ports[http][0]}}/'
});
</script>
<iframe id='testframe' src="http://{{domains[www]}}:{{ports[http][0]}}/" onload="runTest()">Test Frame</iframe>
</body>
</html>

View file

@ -0,0 +1,23 @@
<!DOCTYPE HTML>
<html manifest="../resources/manifest/clock.manifest">
<head>
<title>Offline Application Cache - API_status_CHECKING</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<ol>
<li>Refresh the page.</li>
</ol>
<div id="log"></div>
<script>
var t = async_test("checking status test"),
cache = window.applicationCache;
cache.onchecking = t.step_func_done(function() {
assert_equals(cache.status, cache.CHECKING, "cache.status should equals cache.CHECKING");
});
</script>
</body>
</html>

Some files were not shown because too many files have changed in this diff Show more