blob: d7374e2bdebf6ee488f2d3d7605e0b5beec2e4a7 [file] [log] [blame]
<!DOCTYPE html>
<script src="/js-test-resources/testharness.js"></script>
<script src="/js-test-resources/testharnessreport.js"></script>
<script>
var t = async_test('Makes sure that preloaded resources trigger onerror');
</script>
<script>
var scriptFailed = false;
var styleFailed = false;
var imageFailed = false;
var fontFailed = false;
var trackFailed = false;
var gibrishFailed = false;
var fetchFailed = false;
var noTypeFailed = false;
var counter = 0;
function count() {
++window.counter;
};
</script>
<link rel=preload href="../non-existent/dummy.js" as=script onerror="count();scriptFailed = true;" onload="count();">
<link rel=preload href="../non-existent/dummy.css" as=style onerror="count();styleFailed = true;" onload="count();">
<link rel=preload href="../non-existent/square.png" as=image onerror="count();imageFailed = true;" onload="count();">
<link rel=preload href="../non-existent/Ahem.ttf" as=font crossorigin onerror="count();fontFailed = true;" onload="count();">
<link rel=preload href="../non-existent/security/captions.vtt" as=track onerror="count();trackFailed = true;" onload="count();">
<link rel=preload href="../non-existent/dummy.xml" as=foobarxmlthing onerror="count();gibrishFailed = true;" onload="count();">
<link rel=preload href="http://127.0.0.1:9999/non-existent/dummy.xml?fetch" as=fetch onerror="count();fetchFailed = true;" onload="count();">
<link rel=preload href="http://127.0.0.1:9999/non-existent/dummy.xml" onerror="count();noTypeFailed = true;" onload="count();">
<script>
document.write('<script src="../non-existent/dummy.js"></scr' + 'ipt>' +
'<link rel=stylesheet href="../non-existent/dummy.css">' +
'<img src="../non-existent/square.png">' +
'<video><source src="test.mp4">' +
'<track kind=subtitles src="../../non-existent/security/captions.vtt" srclang=en>' +
'</video>' +
'<style>' +
' @font-face { font-family:ahem; src: url(../../non-existent/Ahem.ttf); }' +
' span { font-family: ahem, Arial; }' +
'</style>' +
'<span>This test makes sure that link preload triggers error events for non-existing resources.</span>');
var xhr = new XMLHttpRequest();
xhr.open("GET", "../non-existent/dummy.xml");
xhr.send();
var xhr2 = new XMLHttpRequest();
xhr2.open("GET", "http://127.0.0.1:9999/non-existent/dummy.xml");
xhr2.send();
function test() {
assert_true(styleFailed);
assert_true(scriptFailed);
assert_true(imageFailed);
assert_true(fontFailed);
assert_true(trackFailed);
assert_false(gibrishFailed);
assert_true(fetchFailed);
assert_false(noTypeFailed);
t.done();
};
setInterval(t.step_func(function() {
if (window.counter >= 6)
test();
}, 100));
</script>