setup({explicit_done:true}); onload = function() { var encoding = '{{GET[encoding]}}'; var input_url = 'resources/resource.py?q=\u00E5&encoding=' + encoding + '&type='; ('html css js worker sharedworker worker_importScripts sharedworker_importScripts worker_worker worker_sharedworker sharedworker_worker '+ 'sharedworker_sharedworker eventstream png svg xmlstylesheet_css video webvtt').split(' ').forEach(function(str) { window['input_url_'+str] = input_url + str; }); var blank = 'resources/blank.py?encoding=' + encoding; var stash_put = 'resources/stash.py?q=\u00E5&action=put&id='; var stash_take = 'resources/stash.py?action=take&id='; var expected_obj = { 'utf-8':'%C3%A5', 'utf-16be':'%C3%A5', 'utf-16le':'%C3%A5', 'windows-1252':'%E5', 'windows-1251':'%3F' }; var expected_current = expected_obj[encoding]; var expected_utf8 = expected_obj['utf-8']; function msg(expected, got) { return 'expected substring '+expected+' got '+got; } function poll_for_stash(test_obj, uuid, expected) { var start = new Date(); var poll = test_obj.step_func(function () { var xhr = new XMLHttpRequest(); xhr.open('GET', stash_take + uuid); xhr.onload = test_obj.step_func(function(e) { if (xhr.response == "") { if (new Date() - start > 10000) { // If we set the status to TIMEOUT here we avoid a race between the // page and the test timing out test_obj.force_timeout(); } setTimeout(poll, 200); } else { assert_equals(xhr.response, expected); test_obj.done(); } }); xhr.send(); }) setTimeout(poll, 200); } // background attribute, check with getComputedStyle function test_background(tag) { var spec_url = 'https://html.spec.whatwg.org/multipage/multipage/rendering.html'; spec_url += tag == 'body' ? '#the-page' : '#tables'; test(function() { var elm = document.createElement(tag); document.body.appendChild(elm); this.add_cleanup(function() { document.body.removeChild(elm); }); elm.setAttribute('background', input_url_png); var got = getComputedStyle(elm).backgroundImage; assert_true(got.indexOf(expected_current) > -1, msg(expected_current, got)); }, 'getComputedStyle <'+tag+' background>', {help:spec_url}); } 'body, table, thead, tbody, tfoot, tr, td, th'.split(', ').forEach(function(str) { test_background(str); }); // get a reflecting IDL attributes whose content attribute takes a URL or a list of space-separated URLs function test_reflecting(tag, attr, idlAttr, multiple) { idlAttr = idlAttr || attr; var input = input_url_html; if (multiple) { input += ' ' + input; } test(function() { var elm = document.createElement(tag); assert_true(idlAttr in elm, idlAttr + ' is not supported'); elm.setAttribute(attr, input); var got = elm[idlAttr]; assert_true(got.indexOf(expected_current) > -1, msg(expected_current, got)); }, 'Getting <'+tag+'>.'+idlAttr + (multiple ? ' (multiple URLs)' : ''), {help:'https://html.spec.whatwg.org/multipage/multipage/common-dom-interfaces.html#reflecting-content-attributes-in-idl-attributes'}); } ('iframe src, a href, base href, link href, img src, embed src, object data, track src, video src, audio src, input src, form action, ' + 'input formaction formAction, button formaction formAction, menuitem icon, script src').split(', ').forEach(function(str) { var arr = str.split(' '); test_reflecting(arr[0], arr[1], arr[2]); }); 'a ping'.split(', ').forEach(function(str) { var arr = str.split(' '); test_reflecting(arr[0], arr[1], arr[2], true); }); function setup_navigation(elm, iframe, id, test_obj) { iframe.name = id; elm.target = id; elm.setAttribute('href', input_url_html); document.body.appendChild(iframe); document.body.appendChild(elm); test_obj.add_cleanup(function() { document.body.removeChild(iframe); document.body.removeChild(elm); }); } // follow hyperlink function test_follow_link(tag) { async_test(function() { var elm = document.createElement(tag); var iframe = document.createElement('iframe'); setup_navigation(elm, iframe, 'test_follow_link_'+tag, this); iframe.onload = this.step_func_done(function() { // when the page navigated to has loaded assert_equals(iframe.contentDocument.body.textContent, expected_current); }); // follow the hyperlink elm.click(); // check that navigation succeeded by ...??? XXX }, 'follow hyperlink <'+tag+' href>', {help:'https://html.spec.whatwg.org/multipage/multipage/links.html#following-hyperlinks'}); } 'a, area, link'.split(', ').forEach(function(str) { test_follow_link(str); }); // follow hyperlink with ping attribute function test_follow_link_ping(tag) { async_test(function() { var uuid = token(); var elm = document.createElement(tag); // check if ping is supported assert_true('ping' in elm, 'ping not supported'); elm.setAttribute('ping', stash_put + uuid); var iframe = document.createElement('iframe'); setup_navigation(elm, iframe, 'test_follow_link_ping_'+tag, this); // follow the hyperlink elm.click(); // check that navigation succeeded by ...??? XXX // check that the right URL was requested for the ping poll_for_stash(this, uuid, expected_current); }, 'hyperlink auditing <'+tag+' ping>', {help:'https://html.spec.whatwg.org/multipage/multipage/links.html#hyperlink-auditing'}); } 'a, area'.split(', ').forEach(function(str) { test_follow_link_ping(str); }); // navigating with meta refresh async_test(function() { var iframe = document.createElement('iframe'); iframe.src = blank; document.body.appendChild(iframe); this.add_cleanup(function() { document.body.removeChild(iframe); }); iframe.onload = this.step_func_done(function() { var doc = iframe.contentDocument; var got = doc.body.textContent; if (got == '') { doc.write('REFRESH'); doc.close(); return; } assert_equals(got, expected_current); }); }, 'meta refresh', {help:'https://html.spec.whatwg.org/multipage/multipage/semantics.html#attr-meta-http-equiv-refresh'}); // loading html (or actually svg to support ) function test_load_nested_browsing_context(tag, attr, spec_url) { async_test(function() { var id = 'test_load_nested_browsing_context_'+tag; var elm = document.createElement(tag); elm.setAttribute(attr, input_url_svg); elm.name = id; document.body.appendChild(elm); this.add_cleanup(function() { document.body.removeChild(elm); }); elm.onload = this.step_func_done(function() { assert_equals(window[id].document.documentElement.textContent, expected_current); }); }, 'load nested browsing context <'+tag+' '+attr+'>', {help:spec_url}); } spec_url_load_nested_browsing_context = { frame:'https://html.spec.whatwg.org/multipage/multipage/obsolete.html#process-the-frame-attributes', iframe:'https://html.spec.whatwg.org/multipage/multipage/the-iframe-element.html#process-the-iframe-attributes', object:'https://html.spec.whatwg.org/multipage/multipage/the-iframe-element.html#the-object-element', embed:'https://html.spec.whatwg.org/multipage/multipage/the-iframe-element.html#the-embed-element-setup-steps' }; 'frame src, iframe src, object data, embed src'.split(', ').forEach(function(str) { var arr = str.split(' '); test_load_nested_browsing_context(arr[0], arr[1], spec_url_load_nested_browsing_context[arr[0]]); }); // loading css with async_test(function() { var elm = document.createElement('link'); elm.href = input_url_css; elm.rel = 'stylesheet'; document.head.appendChild(elm); this.add_cleanup(function() { document.head.removeChild(elm); }); elm.onload = this.step_func_done(function() { var got = elm.sheet.href; assert_true(elm.sheet.href.indexOf(expected_current) > -1, 'sheet.href ' + msg(expected_current, got)); assert_equals(elm.sheet.cssRules[0].style.content, '"'+expected_current+'"', 'sheet.cssRules[0].style.content'); }); }, 'loading css ', {help:['https://html.spec.whatwg.org/multipage/multipage/semantics.html#the-link-element', 'https://html.spec.whatwg.org/multipage/multipage/semantics.html#styling']}); // loading js async_test(function() { var elm = document.createElement('script'); elm.src = input_url_js + '&var=test_load_js_got'; document.head.appendChild(elm); // no cleanup elm.onload = this.step_func_done(function() { assert_equals(window.test_load_js_got, expected_current); }); }, 'loading js