/* * Copyright 2017 Jacek Caban for CodeWeavers * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ function test_input_selection() { var input = document.createElement("input"); input.type = "text"; input.value = "test"; document.body.appendChild(input); function test_range(start, end) { ok(input.selectionStart === start, "input.selectionStart = " + input.selectionStart + " expected " + start); ok(input.selectionEnd === end, "input.selectionEnd = " + input.selectionEnd + " expected " + end); } test_range(0, 0); input.selectionStart = 2; test_range(2, 2); input.selectionStart = -1; test_range(0, 2); input.selectionStart = 10; test_range(4, 4); input.selectionEnd = 2; test_range(2, 2); input.selectionEnd = -1; test_range(0, 0); input.selectionEnd = 10; test_range(0, 4); input.setSelectionRange(2, 3); test_range(2, 3); input.setSelectionRange(-1, 10); test_range(0, 4); input.setSelectionRange(3, 3); test_range(3, 3); next_test(); } function test_textContent() { var text = document.createTextNode("test"); ok(text.textContent === "test", "text.textContent = " + text.textContent); var div = document.createElement("div"); document.body.appendChild(div); div.innerHTML = "abc
text
"; ok(div.textContent === "abc/* */text", "div.textContent = " + div.textContent); div.textContent = "test"; ok(div.textContent === "test", "div.textContent = " + div.textContent); ok(div.childNodes.length === 1, "div.childNodes.length = " + div.childNodes.length); ok(div.firstChild.textContent === "test", "div.firstChild.textContent = " + div.firstChild.textContent); div.textContent = ""; ok(div.textContent === "", "div.textContent = " + div.textContent); ok(div.childNodes.length === 0, "div.childNodes.length = " + div.childNodes.length); ok(document.textContent === null, "document.textContent = " + document.textContent); next_test(); } function test_ElementTraversal() { var div = document.createElement("div"); div.innerHTML = "abcbold'; elems = document.getElementsByClassName("class1"); ok(elems.length === 3, "elems.length = " + elems.length); ok(elems[0].tagName === "DIV", "elems[0].tagName = " + elems[0].tagName); ok(elems[1].tagName === "DIV", "elems[1].tagName = " + elems[1].tagName); ok(elems[2].tagName === "SCRIPT", "elems[2].tagName = " + elems[2].tagName); elems = document.getElementsByClassName("class2"); ok(elems.length === 1, "elems.length = " + elems.length); ok(elems[0].tagName === "A", "elems[0].tagName = " + elems[0].tagName); elems = document.getElementsByClassName("classnotfound"); ok(elems.length == 0, "elems.length = " + elems.length); next_test(); } function test_query_selector() { document.body.innerHTML = '
' + '
' + '' + '
' + ''; var e = document.querySelector("nomatch"); ok(e === null, "e = " + e); e = document.querySelector(".class1"); ok(e.tagName === "DIV", "e.tagName = " + e.tagName); e = document.querySelector("a"); ok(e.tagName === "A", "e.tagName = " + e.tagName); next_test(); } function test_compare_position() { document.body.innerHTML = '
'; var parent = document.body.firstChild; var child1 = parent.firstChild; var child2 = child1.nextSibling; var elem = document.createElement("div"); function compare_position(node1, node2, expected_result, ignore_mask) { var cmp = node1.compareDocumentPosition(node2); ok((cmp & ~ignore_mask) == expected_result, "compareDocumentPosition returned " + cmp + " expected " + expected_result); } compare_position(child1, child2, 4); compare_position(child2, child1, 2); compare_position(parent, child1, 0x14); compare_position(parent, child2, 0x14); compare_position(parent, elem, 0x21, 6); compare_position(elem, parent, 0x21, 6); next_test(); } function test_document_owner() { var node; ok(document.ownerDocument === null, "ownerDocument = " + document.ownerDocument); ok(document.body.ownerDocument === document, "body.ownerDocument = " + document.body.ownerDocument); ok(document.documentElement.ownerDocument === document, "documentElement.ownerDocument = " + document.documentElement.ownerDocument); node = document.createElement("test"); ok(node.ownerDocument === document, "element.ownerDocument = " + node.ownerDocument); node = document.createDocumentFragment(); ok(node.ownerDocument === document, "fragment.ownerDocument = " + node.ownerDocument); node = document.createTextNode("test"); ok(node.ownerDocument === document, "text.ownerDocument = " + node.ownerDocument); next_test(); } function test_style_properties() { var style = document.body.style; var val; style.cssFloat = "left"; ok(style.cssFloat === "left", "cssFloat = " + style.cssFloat); ok(style.getPropertyValue("float") === "left", 'style.getPropertyValue("float") = ' + style.getPropertyValue("float")); ok(style.getPropertyValue("cssFloat") === "", 'style.getPropertyValue("cssFloat") = ' + style.getPropertyValue("cssFloat")); val = style.removeProperty("float"); ok(val === "left", "removeProperty() returned " + val); ok(style.cssFloat === "", "cssFloat = " + style.cssFloat); style.cssFloat = "left"; val = style.removeProperty("FloaT"); ok(val === "left", "removeProperty() returned " + val); ok(style.cssFloat === "", "cssFloat = " + style.cssFloat); style.cssFloat = "left"; val = style.removeProperty("cssFloat"); ok(val === "", "removeProperty() returned " + val); ok(style.cssFloat === "left", "cssFloat = " + style.cssFloat); ok(style["float"] === "left", "float = " + style["float"]); style.testVal = "test"; val = style.removeProperty("testVal"); ok(val === "", "removeProperty() returned " + val); ok(style.testVal === "test", "testVal = " + style.testVal); style["z-index"] = 1; ok(style.zIndex === 1, "zIndex = " + style.zIndex); ok(style["z-index"] === 1, "z-index = " + style["z-index"]); ok(style.getPropertyValue("z-index") === "1", 'style.getPropertyValue("x-index") = ' + style.getPropertyValue("z-index")); ok(style.getPropertyValue("zIndex") === "", 'style.getPropertyValue("xIndex") = ' + style.getPropertyValue("zIndex")); style.setProperty("border-width", "5px"); ok(style.borderWidth === "5px", "style.borderWidth = " + style.borderWidth); try { style.setProperty("border-width", 6); ok(style.borderWidth === "5px", "style.borderWidth = " + style.borderWidth); }catch(e) { win_skip("skipping setProperty tests on too old IE version"); next_test(); return; } style.setProperty("border-width", "7px", "test"); ok(style.borderWidth === "5px", "style.borderWidth = " + style.borderWidth); style.setProperty("border-width", "6px", ""); ok(style.borderWidth === "6px", "style.borderWidth = " + style.borderWidth); style.setProperty("border-width", "7px", "important"); ok(style.borderWidth === "7px", "style.borderWidth = " + style.borderWidth); style.setProperty("border-width", "8px", undefined); ok(style.borderWidth === "7px", "style.borderWidth = " + style.borderWidth); next_test(); } function test_storage() { ok(typeof(window.sessionStorage) === "object", "typeof(window.sessionStorage) = " + typeof(window.sessionStorage)); ok(typeof(window.localStorage) === "object", "typeof(window.localStorage) = " + typeof(window.localStorage)); next_test(); } var tests = [ test_input_selection, test_textContent, test_ElementTraversal, test_getElementsByClassName, test_head, test_iframe, test_anchor, test_query_selector, test_compare_position, test_document_owner, test_style_properties, test_storage ];