Add editorconfig, resolve differences

This includes newlines, tabs, among other things.
This commit is contained in:
impinball 2016-06-18 02:59:42 -04:00
parent 80d0a69dab
commit b4fb21475c
90 changed files with 1707 additions and 1701 deletions

View file

@ -9,4 +9,4 @@ License: MIT
- pushStateMock - mock for `history.pushState` and `location`
- ajaxMock - mock for XMLHttpRequest and JSONP transporters
- parseURL - helper function for URL parsing
- parseURL - helper function for URL parsing

View file

@ -1,3 +1,3 @@
"use strict"
module.exports = typeof setImmediate === "function" ? setImmediate : setTimeout
module.exports = typeof setImmediate === "function" ? setImmediate : setTimeout

View file

@ -8,9 +8,9 @@ module.exports = function() {
var ancestor = this
while (ancestor !== child && ancestor !== null) ancestor = ancestor.parentNode
if (ancestor === child) throw new Error("Node cannot be inserted at the specified point in the hierarchy")
if (child.nodeType == null) throw new Error("Argument is not a DOM element")
var index = this.childNodes.indexOf(child)
if (index > -1) this.childNodes.splice(index, 1)
if (child.nodeType === 11) {
@ -35,9 +35,9 @@ module.exports = function() {
var ancestor = this
while (ancestor !== child && ancestor !== null) ancestor = ancestor.parentNode
if (ancestor === child) throw new Error("Node cannot be inserted at the specified point in the hierarchy")
if (child.nodeType == null) throw new Error("Argument is not a DOM element")
var refIndex = this.childNodes.indexOf(reference)
var index = this.childNodes.indexOf(child)
if (reference !== null && refIndex < 0) throw new TypeError("Invalid argument")
@ -109,7 +109,7 @@ module.exports = function() {
},
set innerHTML(value) {
while (this.firstChild) this.removeChild(this.firstChild)
var stack = [this], depth = 0, voidElements = ["area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"]
value.replace(/<([a-z0-9\-]+?)((?:\s+?[^=]+?=(?:"[^"]*?"|'[^']*?'|[^\s>]*))*?)(\s*\/)?>|<\/([a-z0-9\-]+?)>|([^<]+)/g, function(match, startTag, attrs, selfClosed, endTag, text) {
if (startTag) {
@ -173,7 +173,7 @@ module.exports = function() {
if (this.nodeName === "INPUT" && this.attributes["type"] != null && this.attributes["type"].nodeValue === "checkbox" && e.type === "click") {
this.checked = !this.checked
}
e.target = this
if (events[e.type] != null) {
for (var i = 0; i < events[e.type].length; i++) {
@ -186,7 +186,7 @@ module.exports = function() {
if (typeof this["on" + e.type] === "function" && !isModernEvent(e.type)) this["on" + e.type](e)
},
}
if (element.nodeName === "A") {
var href
Object.defineProperty(element, "href", {
@ -195,7 +195,7 @@ module.exports = function() {
enumerable: true,
})
}
if (element.nodeName === "INPUT") {
var checked
Object.defineProperty(element, "checked", {
@ -203,10 +203,10 @@ module.exports = function() {
set: function(value) {checked = Boolean(value)},
enumerable: true,
})
element.value = ""
}
if (element.nodeName === "TEXTAREA") {
var value
Object.defineProperty(element, "value", {
@ -218,7 +218,7 @@ module.exports = function() {
enumerable: true,
})
}
function getOptions(element) {
var options = []
for (var i = 0; i < element.childNodes.length; i++) {
@ -340,6 +340,6 @@ module.exports = function() {
$window.document.body = $window.document.createElement("body")
$window.document.documentElement.appendChild($window.document.body)
activeElement = $window.document.body
return $window
}

View file

@ -9,9 +9,9 @@ module.exports = function() {
var pathname = "/"
var search = ""
var hash = ""
var past = [], future = []
function getURL() {
if (protocol === "file:") return protocol + "//" + pathname + search + hash
return protocol + "//" + hostname + prefix(":", port) + pathname + search + hash
@ -75,7 +75,7 @@ module.exports = function() {
get href() {
return getURL()
},
set protocol(value) {
throw new Error("Protocol is read-only")
},
@ -112,7 +112,7 @@ module.exports = function() {
hash = prefix("#", value)
if (oldHash != hash) hashchange()
},
set origin(value) {
//origin is writable but ignored
},

View file

@ -17,7 +17,7 @@
<script src="test-pushStateMock.js"></script>
<script src="test-xhrMock.js"></script>
<script src="test-domMock.js"></script>
<script>require("../../ospec/ospec").run()</script>
</body>
</html>
</html>

View file

@ -8,11 +8,11 @@ o.spec("domMock", function() {
o.beforeEach(function() {
$document = domMock().document
})
o.spec("createElement", function() {
o("works", function() {
var node = $document.createElement("div")
o(node.nodeType).equals(1)
o(node.nodeName).equals("DIV")
o(node.namespaceURI).equals("http://www.w3.org/1999/xhtml")
@ -22,11 +22,11 @@ o.spec("domMock", function() {
o(node.nextSibling).equals(null)
})
})
o.spec("createElementNS", function() {
o("works", function() {
var node = $document.createElementNS("http://www.w3.org/2000/svg", "svg")
o(node.nodeType).equals(1)
o(node.nodeName).equals("svg")
o(node.namespaceURI).equals("http://www.w3.org/2000/svg")
@ -36,11 +36,11 @@ o.spec("domMock", function() {
o(node.nextSibling).equals(null)
})
})
o.spec("createTextNode", function() {
o("works", function() {
var node = $document.createTextNode("abc")
o(node.nodeType).equals(3)
o(node.nodeName).equals("#text")
o(node.parentNode).equals(null)
@ -48,41 +48,41 @@ o.spec("domMock", function() {
})
o("works w/ number", function() {
var node = $document.createTextNode(123)
o(node.nodeValue).equals("123")
})
o("works w/ null", function() {
var node = $document.createTextNode(null)
o(node.nodeValue).equals("null")
})
o("works w/ undefined", function() {
var node = $document.createTextNode(undefined)
o(node.nodeValue).equals("undefined")
})
o("works w/ object", function() {
var node = $document.createTextNode({})
o(node.nodeValue).equals("[object Object]")
})
o("does not unescape HTML", function() {
var node = $document.createTextNode("<a>&amp;</a>")
o(node.nodeValue).equals("<a>&amp;</a>")
})
o("nodeValue casts to string", function() {
var node = $document.createTextNode("a")
node.nodeValue = true
o(node.nodeValue).equals("true")
})
})
o.spec("createDocumentFragment", function() {
o("works", function() {
var node = $document.createDocumentFragment()
o(node.nodeType).equals(11)
o(node.nodeName).equals("#document-fragment")
o(node.parentNode).equals(null)
@ -90,13 +90,13 @@ o.spec("domMock", function() {
o(node.firstChild).equals(null)
})
})
o.spec("appendChild", function() {
o("works", function() {
var parent = $document.createElement("div")
var child = $document.createElement("a")
parent.appendChild(child)
o(parent.childNodes.length).equals(1)
o(parent.childNodes[0]).equals(child)
o(parent.firstChild).equals(child)
@ -109,7 +109,7 @@ o.spec("domMock", function() {
parent.appendChild(a)
parent.appendChild(b)
parent.appendChild(a)
o(parent.childNodes.length).equals(2)
o(parent.childNodes[0]).equals(b)
o(parent.childNodes[1]).equals(a)
@ -126,7 +126,7 @@ o.spec("domMock", function() {
parent.appendChild(a)
source.appendChild(b)
parent.appendChild(b)
o(source.childNodes.length).equals(0)
})
o("transfers from fragment", function() {
@ -137,7 +137,7 @@ o.spec("domMock", function() {
a.appendChild(b)
a.appendChild(c)
parent.appendChild(a)
o(parent.childNodes.length).equals(2)
o(parent.childNodes[0]).equals(b)
o(parent.childNodes[1]).equals(c)
@ -168,14 +168,14 @@ o.spec("domMock", function() {
catch (e) {done()}
})
})
o.spec("removeChild", function() {
o("works", function() {
var parent = $document.createElement("div")
var child = $document.createElement("a")
parent.appendChild(child)
parent.removeChild(child)
o(parent.childNodes.length).equals(0)
o(parent.firstChild).equals(null)
o(child.parentNode).equals(null)
@ -187,7 +187,7 @@ o.spec("domMock", function() {
catch (e) {done()}
})
})
o.spec("insertBefore", function() {
o("works", function() {
var parent = $document.createElement("div")
@ -195,7 +195,7 @@ o.spec("domMock", function() {
var b = $document.createElement("b")
parent.appendChild(a)
parent.insertBefore(b, a)
o(parent.childNodes.length).equals(2)
o(parent.childNodes[0]).equals(b)
o(parent.childNodes[1]).equals(a)
@ -211,7 +211,7 @@ o.spec("domMock", function() {
parent.appendChild(a)
parent.appendChild(b)
parent.insertBefore(b, a)
o(parent.childNodes.length).equals(2)
o(parent.childNodes[0]).equals(b)
o(parent.childNodes[1]).equals(a)
@ -228,7 +228,7 @@ o.spec("domMock", function() {
parent.appendChild(a)
source.appendChild(b)
parent.insertBefore(b, a)
o(source.childNodes.length).equals(0)
})
o("transfers from fragment", function() {
@ -241,7 +241,7 @@ o.spec("domMock", function() {
a.appendChild(b)
a.appendChild(c)
parent.insertBefore(a, ref)
o(parent.childNodes.length).equals(3)
o(parent.childNodes[0]).equals(b)
o(parent.childNodes[1]).equals(c)
@ -261,7 +261,7 @@ o.spec("domMock", function() {
var b = $document.createElement("b")
parent.appendChild(a)
parent.insertBefore(b, null)
o(parent.childNodes.length).equals(2)
o(parent.childNodes[0]).equals(a)
o(parent.childNodes[1]).equals(b)
@ -312,81 +312,81 @@ o.spec("domMock", function() {
catch (e) {done()}
})
})
o.spec("setAttribute", function() {
o("works", function() {
var div = $document.createElement("div")
div.setAttribute("id", "aaa")
o(div.attributes["id"].nodeValue).equals("aaa")
o(div.attributes["id"].namespaceURI).equals(null)
})
o("works w/ number", function() {
var div = $document.createElement("div")
div.setAttribute("id", 123)
o(div.attributes["id"].nodeValue).equals("123")
})
o("works w/ null", function() {
var div = $document.createElement("div")
div.setAttribute("id", null)
o(div.attributes["id"].nodeValue).equals("null")
})
o("works w/ undefined", function() {
var div = $document.createElement("div")
div.setAttribute("id", undefined)
o(div.attributes["id"].nodeValue).equals("undefined")
})
o("works w/ object", function() {
var div = $document.createElement("div")
div.setAttribute("id", {})
o(div.attributes["id"].nodeValue).equals("[object Object]")
})
o("setting via attributes map stringifies", function() {
var div = $document.createElement("div")
div.setAttribute("id", "a")
div.attributes["id"].nodeValue = 123
o(div.attributes["id"].nodeValue).equals("123")
})
})
o.spec("setAttributeNS", function() {
o("works", function() {
var div = $document.createElement("div")
div.setAttributeNS("http://www.w3.org/1999/xlink", "href", "aaa")
o(div.attributes["href"].nodeValue).equals("aaa")
o(div.attributes["href"].namespaceURI).equals("http://www.w3.org/1999/xlink")
})
o("works w/ number", function() {
var div = $document.createElement("div")
div.setAttributeNS("http://www.w3.org/1999/xlink", "href", 123)
o(div.attributes["href"].nodeValue).equals("123")
o(div.attributes["href"].namespaceURI).equals("http://www.w3.org/1999/xlink")
})
})
o.spec("removeAttribute", function() {
o("works", function() {
var div = $document.createElement("div")
div.setAttribute("id", "aaa")
div.removeAttribute("id")
o("id" in div.attributes).equals(false)
})
})
o.spec("textContent", function() {
o("works", function() {
var div = $document.createElement("div")
var a = $document.createElement("a")
div.textContent = "aaa"
o(div.childNodes.length).equals(1)
o(div.firstChild.nodeType).equals(3)
o(div.firstChild.nodeValue).equals("aaa")
@ -395,11 +395,11 @@ o.spec("domMock", function() {
var div = $document.createElement("div")
var a = $document.createElement("a")
div.textContent = ""
o(div.childNodes.length).equals(0)
})
})
o.spec("innerHTML", function() {
o("works", function() {
var div = $document.createElement("div")
@ -446,7 +446,7 @@ o.spec("domMock", function() {
var a = $document.createElement("a")
div.appendChild(a)
div.innerHTML = "<b></b>"
o(a.parentNode).equals(null)
})
})
@ -462,22 +462,22 @@ o.spec("domMock", function() {
var input = $document.createElement("input")
$document.body.appendChild(input)
input.focus()
o($document.activeElement).equals(input)
$document.body.removeChild(input)
})
})
o.spec("style", function() {
o("has style property", function() {
var div = $document.createElement("div")
o(typeof div.style).equals("object")
})
o("setting style string works", function() {
var div = $document.createElement("div")
div.style = "background-color: red; border-bottom: 1px solid red;"
o(div.style.backgroundColor).equals("red")
o(div.style.borderBottom).equals("1px solid red")
})
@ -485,7 +485,7 @@ o.spec("domMock", function() {
var div = $document.createElement("div")
div.style = "background: red;"
div.style = ""
o(div.style.background).equals("")
})
})
@ -497,17 +497,17 @@ o.spec("domMock", function() {
div = $document.createElement("div")
e = $document.createEvent("MouseEvents")
e.initEvent("click", true, true)
$document.body.appendChild(div)
})
o.afterEach(function() {
$document.body.removeChild(div)
})
o("addEventListener works", function() {
div.addEventListener("click", spy, false)
div.dispatchEvent(e)
o(spy.callCount).equals(1)
o(spy.this).equals(div)
o(spy.args[0].type).equals("click")
@ -517,14 +517,14 @@ o.spec("domMock", function() {
div.addEventListener("click", spy, false)
div.removeEventListener("click", spy, false)
div.dispatchEvent(e)
o(spy.callCount).equals(0)
done()
})
o("click fires onclick", function() {
div.onclick = spy
div.dispatchEvent(e)
o(spy.callCount).equals(1)
o(spy.this).equals(div)
o(spy.args[0].type).equals("click")
@ -542,17 +542,17 @@ o.spec("domMock", function() {
div = $document.createElement("div")
e = $document.createEvent("HTMLEvents")
e.initEvent("transitionend", true, true)
$document.body.appendChild(div)
})
o.afterEach(function() {
$document.body.removeChild(div)
})
o("ontransitionend does not fire", function(done) {
div.ontransitionend = spy
div.dispatchEvent(e)
o(spy.callCount).equals(0)
done()
})
@ -562,21 +562,21 @@ o.spec("domMock", function() {
o.spec("a[href]", function() {
o("is empty string if no attribute", function() {
var a = $document.createElement("a")
o(a.href).equals("")
o(a.attributes["href"]).equals(undefined)
})
o("is path if attribute is set", function() {
var a = $document.createElement("a")
a.setAttribute("href", "")
o(a.href).notEquals("")
o(a.attributes["href"].nodeValue).equals("")
})
o("is path if property is set", function() {
var a = $document.createElement("a")
a.href = ""
o(a.href).notEquals("")
o(a.attributes["href"].nodeValue).equals("")
})
@ -585,24 +585,24 @@ o.spec("domMock", function() {
o("only exists in input elements", function() {
var input = $document.createElement("input")
var a = $document.createElement("a")
o("checked" in input).equals(true)
o("checked" in a).equals(false)
})
o("tracks attribute value when unset", function() {
var input = $document.createElement("input")
input.setAttribute("type", "checkbox")
o(input.checked).equals(false)
o(input.attributes["checked"]).equals(undefined)
input.setAttribute("checked", "")
o(input.checked).equals(true)
o(input.attributes["checked"].nodeValue).equals("")
input.removeAttribute("checked")
o(input.checked).equals(false)
o(input.attributes["checked"]).equals(undefined)
})
@ -610,27 +610,27 @@ o.spec("domMock", function() {
var input = $document.createElement("input")
input.setAttribute("type", "checkbox")
input.checked = true
o(input.checked).equals(true)
o(input.attributes["checked"]).equals(undefined)
input.checked = false
input.setAttribute("checked", "")
input.checked = true
input.removeAttribute("checked")
o(input.checked).equals(true)
})
o("toggles on click", function() {
var input = $document.createElement("input")
input.setAttribute("type", "checkbox")
input.checked = false
var e = $document.createEvent("MouseEvents")
e.initEvent("click", true, true)
input.dispatchEvent(e)
o(input.checked).equals(true)
})
})
@ -638,7 +638,7 @@ o.spec("domMock", function() {
o("only exists in input elements", function() {
var input = $document.createElement("input")
var a = $document.createElement("a")
o("value" in input).equals(true)
o("value" in a).equals(false)
})
@ -647,14 +647,14 @@ o.spec("domMock", function() {
o("reads from child if no value", function() {
var input = $document.createElement("textarea")
input.appendChild($document.createTextNode("aaa"))
o(input.value).equals("aaa")
})
o("ignores child if value set", function() {
var input = $document.createElement("textarea")
input.value = "aaa"
input.setAttribute("value", "bbb")
o(input.value).equals("aaa")
})
})
@ -662,37 +662,37 @@ o.spec("domMock", function() {
o("only exist in select elements", function() {
var select = $document.createElement("select")
var a = $document.createElement("a")
o("value" in select).equals(true)
o("value" in a).equals(false)
o("selectedIndex" in select).equals(true)
o("selectedIndex" in a).equals(false)
})
o("value defaults to value at first index", function() {
var select = $document.createElement("select")
var option1 = $document.createElement("option")
option1.setAttribute("value", "a")
select.appendChild(option1)
var option2 = $document.createElement("option")
option2.setAttribute("value", "b")
select.appendChild(option2)
o(select.value).equals("a")
o(select.selectedIndex).equals(0)
})
o("value falls back to child nodeValue if no attribute", function() {
var select = $document.createElement("select")
var option1 = $document.createElement("option")
option1.appendChild($document.createTextNode("a"))
var option2 = $document.createElement("option")
option2.appendChild($document.createTextNode("b"))
select.appendChild(option1)
select.appendChild(option2)
o(select.value).equals("a")
o(select.selectedIndex).equals(0)
o(select.childNodes[0].selected).equals(true)
@ -701,159 +701,159 @@ o.spec("domMock", function() {
})
o("value defaults to invalid if no options", function() {
var select = $document.createElement("select")
o(select.value).equals("")
o(select.selectedIndex).equals(-1)
})
o("setting valid value works", function() {
var select = $document.createElement("select")
var option1 = $document.createElement("option")
option1.setAttribute("value", "a")
select.appendChild(option1)
var option2 = $document.createElement("option")
option2.setAttribute("value", "b")
select.appendChild(option2)
select.value = "b"
o(select.value).equals("b")
o(select.selectedIndex).equals(1)
})
o("setting valid value works with optgroup", function() {
var select = $document.createElement("select")
var option1 = $document.createElement("option")
option1.setAttribute("value", "a")
var option2 = $document.createElement("option")
option2.setAttribute("value", "b")
var option3 = $document.createElement("option")
option3.setAttribute("value", "c")
var optgroup = $document.createElement("optgroup")
optgroup.appendChild(option1)
optgroup.appendChild(option2)
select.appendChild(optgroup)
select.appendChild(option3)
select.value = "b"
o(select.value).equals("b")
o(select.selectedIndex).equals(1)
})
o("setting valid selectedIndex works", function() {
var select = $document.createElement("select")
var option1 = $document.createElement("option")
option1.setAttribute("value", "a")
select.appendChild(option1)
var option2 = $document.createElement("option")
option2.setAttribute("value", "b")
select.appendChild(option2)
select.selectedIndex = 1
o(select.value).equals("b")
o(select.selectedIndex).equals(1)
})
o("setting option[selected] works", function() {
var select = $document.createElement("select")
var option1 = $document.createElement("option")
option1.setAttribute("value", "a")
select.appendChild(option1)
var option2 = $document.createElement("option")
option2.setAttribute("value", "b")
select.appendChild(option2)
select.childNodes[1].selected = true
o(select.value).equals("b")
o(select.selectedIndex).equals(1)
})
o("unsetting option[selected] works", function() {
var select = $document.createElement("select")
var option1 = $document.createElement("option")
option1.setAttribute("value", "a")
select.appendChild(option1)
var option2 = $document.createElement("option")
option2.setAttribute("value", "b")
select.appendChild(option2)
select.childNodes[1].selected = true
select.childNodes[1].selected = false
o(select.value).equals("a")
o(select.selectedIndex).equals(0)
})
o("setting invalid value yields a selectedIndex of -1 and value of empty string", function() {
var select = $document.createElement("select")
var option1 = $document.createElement("option")
option1.setAttribute("value", "a")
select.appendChild(option1)
var option2 = $document.createElement("option")
option2.setAttribute("value", "b")
select.appendChild(option2)
select.value = "c"
o(select.value).equals("")
o(select.selectedIndex).equals(-1)
})
o("setting invalid selectedIndex yields a selectedIndex of -1 and value of empty string", function() {
var select = $document.createElement("select")
var option1 = $document.createElement("option")
option1.setAttribute("value", "a")
select.appendChild(option1)
var option2 = $document.createElement("option")
option2.setAttribute("value", "b")
select.appendChild(option2)
select.selectedIndex = -2
o(select.value).equals("")
o(select.selectedIndex).equals(-1)
})
o("setting invalid value yields a selectedIndex of -1 and value of empty string even when there's an option whose value is empty string", function() {
var select = $document.createElement("select")
var option1 = $document.createElement("option")
option1.setAttribute("value", "a")
select.appendChild(option1)
var option2 = $document.createElement("option")
option2.setAttribute("value", "")
select.appendChild(option2)
select.value = "c"
o(select.value).equals("")
o(select.selectedIndex).equals(-1)
})
o("setting invalid selectedIndex yields a selectedIndex of -1 and value of empty string even when there's an option whose value is empty string", function() {
var select = $document.createElement("select")
var option1 = $document.createElement("option")
option1.setAttribute("value", "a")
select.appendChild(option1)
var option2 = $document.createElement("option")
option2.setAttribute("value", "")
select.appendChild(option2)
select.selectedIndex = -2
o(select.value).equals("")
o(select.selectedIndex).equals(-1)
})
@ -863,7 +863,7 @@ o.spec("domMock", function() {
o("works", function() {
var el = $document.createElement("div")
el.className = "a"
o(el.className).equals("a")
o(el.attributes["class"].nodeValue).equals("a")
})

View file

@ -5,7 +5,7 @@ var parseURL = require("../../test-utils/parseURL")
o.spec("parseURL", function() {
var root = {protocol: "http:", hostname: "localhost", port: "", pathname: "/"}
o.spec("full URL", function() {
o("parses full URL", function() {
var data = parseURL("http://www.google.com:80/test?a=b#c")
@ -147,4 +147,4 @@ o.spec("parseURL", function() {
o(data.pathname).equals("/a:b")
})
})
})
})

View file

@ -4,30 +4,30 @@ var o = require("../../ospec/ospec")
var pushStateMock = require("../../test-utils/pushStateMock")
o.spec("pushStateMock", function() {
var $window
o.beforeEach(function() {
$window = pushStateMock()
})
o.spec("initial state", function() {
o("has url on page load", function() {
o($window.location.href).equals("http://localhost/")
})
})
o.spec("set href", function() {
o("changes url on location.href change", function() {
var old = $window.location.href
$window.location.href = "http://localhost/a"
o(old).equals("http://localhost/")
o($window.location.href).equals("http://localhost/a")
})
o("changes url on relative location.href change", function() {
var old = $window.location.href
$window.location.href = "a"
o(old).equals("http://localhost/")
o($window.location.href).equals("http://localhost/a")
o($window.location.pathname).equals("/a")
@ -36,7 +36,7 @@ o.spec("pushStateMock", function() {
$window.location.href = "a"
var old = $window.location.href
$window.location.href = ".."
o(old).equals("http://localhost/a")
o($window.location.href).equals("http://localhost/")
o($window.location.pathname).equals("/")
@ -45,7 +45,7 @@ o.spec("pushStateMock", function() {
$window.location.href = "a/b/c"
var old = $window.location.href
$window.location.href = ".."
o(old).equals("http://localhost/a/b/c")
o($window.location.href).equals("http://localhost/a")
o($window.location.pathname).equals("/a")
@ -53,7 +53,7 @@ o.spec("pushStateMock", function() {
o("does not change url on dotdot location.href change from root", function() {
var old = $window.location.href
$window.location.href = ".."
o(old).equals("http://localhost/")
o($window.location.href).equals("http://localhost/")
o($window.location.pathname).equals("/")
@ -62,7 +62,7 @@ o.spec("pushStateMock", function() {
var old = $window.location.href
$window.location.href = "a"
$window.location.href = "./b"
o(old).equals("http://localhost/")
o($window.location.href).equals("http://localhost/b")
o($window.location.pathname).equals("/b")
@ -71,7 +71,7 @@ o.spec("pushStateMock", function() {
var old = $window.location.href
$window.location.href = "a"
$window.location.href = "."
o(old).equals("http://localhost/")
o($window.location.href).equals("http://localhost/a")
o($window.location.pathname).equals("/a")
@ -79,7 +79,7 @@ o.spec("pushStateMock", function() {
o("changes url on hash-only location.href change", function() {
var old = $window.location.href
$window.location.href = "#a"
o(old).equals("http://localhost/")
o($window.location.href).equals("http://localhost/#a")
o($window.location.hash).equals("#a")
@ -87,7 +87,7 @@ o.spec("pushStateMock", function() {
o("changes url on search-only location.href change", function() {
var old = $window.location.href
$window.location.href = "?a"
o(old).equals("http://localhost/")
o($window.location.href).equals("http://localhost/?a")
o($window.location.search).equals("?a")
@ -95,7 +95,7 @@ o.spec("pushStateMock", function() {
o("changes hash on location.href change", function() {
var old = $window.location.href
$window.location.href = "http://localhost/a#b"
o(old).equals("http://localhost/")
o($window.location.href).equals("http://localhost/a#b")
o($window.location.hash).equals("#b")
@ -103,7 +103,7 @@ o.spec("pushStateMock", function() {
o("changes search on location.href change", function() {
var old = $window.location.href
$window.location.href = "http://localhost/a?b"
o(old).equals("http://localhost/")
o($window.location.href).equals("http://localhost/a?b")
o($window.location.search).equals("?b")
@ -111,7 +111,7 @@ o.spec("pushStateMock", function() {
o("changes search and hash on location.href change", function() {
var old = $window.location.href
$window.location.href = "http://localhost/a?b#c"
o(old).equals("http://localhost/")
o($window.location.href).equals("http://localhost/a?b#c")
o($window.location.search).equals("?b")
@ -120,7 +120,7 @@ o.spec("pushStateMock", function() {
o("handles search with search and hash", function() {
var old = $window.location.href
$window.location.href = "http://localhost/a?b?c#d"
o(old).equals("http://localhost/")
o($window.location.href).equals("http://localhost/a?b?c#d")
o($window.location.search).equals("?b?c")
@ -129,7 +129,7 @@ o.spec("pushStateMock", function() {
o("handles hash with search and hash", function() {
var old = $window.location.href
$window.location.href = "http://localhost/a#b?c#d"
o(old).equals("http://localhost/")
o($window.location.href).equals("http://localhost/a#b?c#d")
o($window.location.search).equals("")
@ -140,7 +140,7 @@ o.spec("pushStateMock", function() {
o("changes url on location.search change", function() {
var old = $window.location.href
$window.location.search = "?b"
o(old).equals("http://localhost/")
o($window.location.href).equals("http://localhost/?b")
o($window.location.search).equals("?b")
@ -150,7 +150,7 @@ o.spec("pushStateMock", function() {
o("changes url on location.hash change", function() {
var old = $window.location.href
$window.location.hash = "#b"
o(old).equals("http://localhost/")
o($window.location.href).equals("http://localhost/#b")
o($window.location.hash).equals("#b")
@ -160,7 +160,7 @@ o.spec("pushStateMock", function() {
o("changes url on location.pathname change", function() {
var old = $window.location.href
$window.location.pathname = "/a"
o(old).equals("http://localhost/")
o($window.location.href).equals("http://localhost/a")
o($window.location.pathname).equals("/a")
@ -181,7 +181,7 @@ o.spec("pushStateMock", function() {
o("setting origin changes href", function() {
var old = $window.location.href
$window.location.port = "81"
o(old).equals("http://localhost/")
o($window.location.port).equals("81")
o($window.location.href).equals("http://localhost:81/")
@ -191,7 +191,7 @@ o.spec("pushStateMock", function() {
o("setting hostname changes href", function() {
var old = $window.location.href
$window.location.hostname = "127.0.0.1"
o(old).equals("http://localhost/")
o($window.location.hostname).equals("127.0.0.1")
o($window.location.href).equals("http://127.0.0.1/")
@ -201,7 +201,7 @@ o.spec("pushStateMock", function() {
o("setting origin is ignored", function() {
var old = $window.location.href
$window.location.origin = "http://127.0.0.1"
o(old).equals("http://localhost/")
o($window.location.origin).equals("http://localhost")
})
@ -210,7 +210,7 @@ o.spec("pushStateMock", function() {
o("setting host is ignored", function() {
var old = $window.location.href
$window.location.host = "http://127.0.0.1"
o(old).equals("http://localhost/")
o($window.location.host).equals("localhost")
})
@ -219,14 +219,14 @@ o.spec("pushStateMock", function() {
o("changes url on pushstate", function() {
var old = $window.location.href
$window.history.pushState(null, null, "http://localhost/a")
o(old).equals("http://localhost/")
o($window.location.href).equals("http://localhost/a")
})
o("changes search on pushstate", function() {
var old = $window.location.href
$window.history.pushState(null, null, "http://localhost/?a")
o(old).equals("http://localhost/")
o($window.location.href).equals("http://localhost/?a")
o($window.location.search).equals("?a")
@ -234,7 +234,7 @@ o.spec("pushStateMock", function() {
o("changes search on relative pushstate", function() {
var old = $window.location.href
$window.history.pushState(null, null, "?a")
o(old).equals("http://localhost/")
o($window.location.href).equals("http://localhost/?a")
o($window.location.search).equals("?a")
@ -242,7 +242,7 @@ o.spec("pushStateMock", function() {
o("changes hash on pushstate", function() {
var old = $window.location.href
$window.history.pushState(null, null, "http://localhost/#a")
o(old).equals("http://localhost/")
o($window.location.href).equals("http://localhost/#a")
o($window.location.hash).equals("#a")
@ -250,7 +250,7 @@ o.spec("pushStateMock", function() {
o("changes hash on relative pushstate", function() {
var old = $window.location.href
$window.history.pushState(null, null, "#a")
o(old).equals("http://localhost/")
o($window.location.href).equals("http://localhost/#a")
o($window.location.hash).equals("#a")
@ -260,14 +260,14 @@ o.spec("pushStateMock", function() {
o("history.back() without history does not trigger onpopstate", function() {
$window.onpopstate = o.spy()
$window.history.back()
o($window.onpopstate.callCount).equals(0)
})
o("history.back() after pushstate triggers onpopstate", function() {
$window.onpopstate = o.spy()
$window.history.pushState(null, null, "http://localhost/a")
$window.history.back()
o($window.onpopstate.callCount).equals(1)
o($window.onpopstate.args[0].type).equals("popstate")
})
@ -275,63 +275,63 @@ o.spec("pushStateMock", function() {
$window.onpopstate = o.spy()
$window.history.pushState(null, null, "a")
$window.history.back()
o($window.onpopstate.callCount).equals(1)
})
o("history.back() after search pushstate triggers onpopstate", function() {
$window.onpopstate = o.spy()
$window.history.pushState(null, null, "http://localhost/?a")
$window.history.back()
o($window.onpopstate.callCount).equals(1)
})
o("history.back() after relative search pushstate triggers onpopstate", function() {
$window.onpopstate = o.spy()
$window.history.pushState(null, null, "?a")
$window.history.back()
o($window.onpopstate.callCount).equals(1)
})
o("history.back() after hash pushstate triggers onpopstate", function() {
$window.onpopstate = o.spy()
$window.history.pushState(null, null, "http://localhost/#a")
$window.history.back()
o($window.onpopstate.callCount).equals(1)
})
o("history.back() after relative hash pushstate triggers onpopstate", function() {
$window.onpopstate = o.spy()
$window.history.pushState(null, null, "#a")
$window.history.back()
o($window.onpopstate.callCount).equals(1)
})
o("history.back() after replacestate does not trigger onpopstate", function() {
$window.onpopstate = o.spy()
$window.history.replaceState(null, null, "http://localhost/a")
$window.history.back()
o($window.onpopstate.callCount).equals(0)
})
o("history.back() after relative replacestate does not trigger onpopstate", function() {
$window.onpopstate = o.spy()
$window.history.replaceState(null, null, "a")
$window.history.back()
o($window.onpopstate.callCount).equals(0)
})
o("history.back() after relative search replacestate does not trigger onpopstate", function() {
$window.onpopstate = o.spy()
$window.history.replaceState(null, null, "?a")
$window.history.back()
o($window.onpopstate.callCount).equals(0)
})
o("history.back() after relative hash replacestate does not trigger onpopstate", function() {
$window.onpopstate = o.spy()
$window.history.replaceState(null, null, "#a")
$window.history.back()
o($window.onpopstate.callCount).equals(0)
})
o("history.forward() after pushstate triggers onpopstate", function() {
@ -339,7 +339,7 @@ o.spec("pushStateMock", function() {
$window.history.pushState(null, null, "http://localhost/a")
$window.history.back()
$window.history.forward()
o($window.onpopstate.callCount).equals(2)
})
o("history.forward() after relative pushstate triggers onpopstate", function() {
@ -347,7 +347,7 @@ o.spec("pushStateMock", function() {
$window.history.pushState(null, null, "a")
$window.history.back()
$window.history.forward()
o($window.onpopstate.callCount).equals(2)
})
o("history.forward() after search pushstate triggers onpopstate", function() {
@ -355,7 +355,7 @@ o.spec("pushStateMock", function() {
$window.history.pushState(null, null, "http://localhost/?a")
$window.history.back()
$window.history.forward()
o($window.onpopstate.callCount).equals(2)
})
o("history.forward() after relative search pushstate triggers onpopstate", function() {
@ -363,7 +363,7 @@ o.spec("pushStateMock", function() {
$window.history.pushState(null, null, "?a")
$window.history.back()
$window.history.forward()
o($window.onpopstate.callCount).equals(2)
})
o("history.forward() after hash pushstate triggers onpopstate", function() {
@ -371,7 +371,7 @@ o.spec("pushStateMock", function() {
$window.history.pushState(null, null, "http://localhost/#a")
$window.history.back()
$window.history.forward()
o($window.onpopstate.callCount).equals(2)
})
o("history.forward() after relative hash pushstate triggers onpopstate", function() {
@ -379,33 +379,33 @@ o.spec("pushStateMock", function() {
$window.history.pushState(null, null, "#a")
$window.history.back()
$window.history.forward()
o($window.onpopstate.callCount).equals(2)
})
o("history.back() without history does not trigger onpopstate", function() {
$window.onpopstate = o.spy()
$window.history.back()
o($window.onpopstate.callCount).equals(0)
})
o("history.forward() without history does not trigger onpopstate", function() {
$window.onpopstate = o.spy()
$window.history.forward()
o($window.onpopstate.callCount).equals(0)
})
o("history navigation without history does not trigger onpopstate", function() {
$window.onpopstate = o.spy()
$window.history.back()
$window.history.forward()
o($window.onpopstate.callCount).equals(0)
})
o("reverse history navigation without history does not trigger onpopstate", function() {
$window.onpopstate = o.spy()
$window.history.forward()
$window.history.back()
o($window.onpopstate.callCount).equals(0)
})
o("onpopstate has correct url during call", function(done) {
@ -422,47 +422,47 @@ o.spec("pushStateMock", function() {
o("onhashchange triggers on location.href change", function() {
$window.onhashchange = o.spy()
$window.location.href = "http://localhost/#a"
o($window.onhashchange.callCount).equals(1)
o($window.onhashchange.args[0].type).equals("hashchange")
})
o("onhashchange triggers on relative location.href change", function() {
$window.onhashchange = o.spy()
$window.location.href = "#a"
o($window.onhashchange.callCount).equals(1)
})
o("onhashchange triggers on location.hash change", function() {
$window.onhashchange = o.spy()
$window.location.hash = "#a"
o($window.onhashchange.callCount).equals(1)
})
o("onhashchange does not trigger on page change", function() {
$window.onhashchange = o.spy()
$window.location.href = "http://localhost/a"
o($window.onhashchange.callCount).equals(0)
})
o("onhashchange does not trigger on page change with different hash", function() {
$window.location.href = "http://localhost/#a"
$window.onhashchange = o.spy()
$window.location.href = "http://localhost/a#b"
o($window.onhashchange.callCount).equals(0)
})
o("onhashchange does not trigger on page change with same hash", function() {
$window.location.href = "http://localhost/#b"
$window.onhashchange = o.spy()
$window.location.href = "http://localhost/a#b"
o($window.onhashchange.callCount).equals(0)
})
o("onhashchange triggers on history.back()", function() {
$window.location.href = "#a"
$window.onhashchange = o.spy()
$window.history.back()
o($window.onhashchange.callCount).equals(1)
})
o("onhashchange triggers on history.forward()", function() {
@ -470,7 +470,7 @@ o.spec("pushStateMock", function() {
$window.onhashchange = o.spy()
$window.history.back()
$window.history.forward()
o($window.onhashchange.callCount).equals(2)
})
o("onhashchange does not trigger on history.back() that causes page change with different hash", function() {
@ -478,7 +478,7 @@ o.spec("pushStateMock", function() {
$window.location.href = "a#b"
$window.onhashchange = o.spy()
$window.history.back()
o($window.onhashchange.callCount).equals(0)
})
o("onhashchange does not trigger on history.back() that causes page change with same hash", function() {
@ -486,7 +486,7 @@ o.spec("pushStateMock", function() {
$window.location.href = "a#a"
$window.onhashchange = o.spy()
$window.history.back()
o($window.onhashchange.callCount).equals(0)
})
o("onhashchange does not trigger on history.forward() that causes page change with different hash", function() {
@ -495,7 +495,7 @@ o.spec("pushStateMock", function() {
$window.onhashchange = o.spy()
$window.history.back()
$window.history.forward()
o($window.onhashchange.callCount).equals(0)
})
o("onhashchange does not trigger on history.forward() that causes page change with same hash", function() {
@ -504,7 +504,7 @@ o.spec("pushStateMock", function() {
$window.onhashchange = o.spy()
$window.history.back()
$window.history.forward()
o($window.onhashchange.callCount).equals(0)
})
})
@ -512,45 +512,45 @@ o.spec("pushStateMock", function() {
o("onunload triggers on location.href change", function() {
$window.onunload = o.spy()
$window.location.href = "http://localhost/a"
o($window.onunload.callCount).equals(1)
o($window.onunload.args[0].type).equals("unload")
})
o("onunload triggers on relative location.href change", function() {
$window.onunload = o.spy()
$window.location.href = "a"
o($window.onunload.callCount).equals(1)
})
o("onunload triggers on search change via location.href", function() {
$window.onunload = o.spy()
$window.location.href = "http://localhost/?a"
o($window.onunload.callCount).equals(1)
})
o("onunload triggers on relative search change via location.href", function() {
$window.onunload = o.spy()
$window.location.href = "?a"
o($window.onunload.callCount).equals(1)
})
o("onunload does not trigger on hash change via location.href", function() {
$window.onunload = o.spy()
$window.location.href = "http://localhost/#a"
o($window.onunload.callCount).equals(0)
})
o("onunload does not trigger on relative hash change via location.href", function() {
$window.onunload = o.spy()
$window.location.href = "#a"
o($window.onunload.callCount).equals(0)
})
o("onunload does not trigger on hash-only history.back()", function() {
$window.location.href = "#a"
$window.onunload = o.spy()
$window.history.back()
o($window.onunload.callCount).equals(0)
})
o("onunload does not trigger on hash-only history.forward()", function() {
@ -558,7 +558,7 @@ o.spec("pushStateMock", function() {
$window.history.back()
$window.onunload = o.spy()
$window.history.forward()
o($window.onunload.callCount).equals(0)
})
o("onunload has correct url during call via location.href change", function(done) {
@ -576,4 +576,4 @@ o.spec("pushStateMock", function() {
$window.location.search = "?a"
})
})
})
})

View file

@ -9,7 +9,7 @@ o.spec("xhrMock", function() {
o.beforeEach(function() {
$window = xhrMock()
})
o.spec("xhr", function() {
o("works", function(done, timeout) {
$window.$defineRoutes({
@ -81,13 +81,13 @@ o.spec("xhrMock", function() {
return {status: 200, responseText: queryData["callback"] + "(" + JSON.stringify({a: 1}) + ")"}
}
})
$window["cb"] = finish
var script = $window.document.createElement("script")
script.src = "/test?callback=cb"
$window.document.documentElement.appendChild(script)
function finish(data) {
o(data).deepEquals({a: 1})
done()
@ -101,13 +101,13 @@ o.spec("xhrMock", function() {
}
})
$window.$defineJSONPCallbackKey("cb")
$window["customcb"] = finish2
var script = $window.document.createElement("script")
script.src = "/test?cb=customcb"
$window.document.documentElement.appendChild(script)
function finish2(data) {
o(data).deepEquals({a: 2})
done()
@ -120,13 +120,13 @@ o.spec("xhrMock", function() {
return {status: 200, responseText: queryData["callback"] + "(" + JSON.stringify({a: 3}) + ")"}
}
})
$window["cbwithinparams"] = finish
var script = $window.document.createElement("script")
script.src = "/test?a=b&callback=cbwithinparams&c=d"
$window.document.documentElement.appendChild(script)
function finish(data) {
o(data).deepEquals({a: 3})
done()
@ -137,11 +137,11 @@ o.spec("xhrMock", function() {
script.onerror = finish
script.src = "/test?cb=nonexistent"
$window.document.documentElement.appendChild(script)
function finish(e) {
o(e.type).equals("error")
done()
}
})
})
})
})

View file

@ -10,7 +10,7 @@ module.exports = function() {
var serverErrorHandler = function() {
return {status: 500, responseText: "server error, most likely the URL was not defined"}
}
var $window = {
XMLHttpRequest: function XMLHttpRequest() {
var args = {}
@ -74,4 +74,4 @@ module.exports = function() {
},
}
return $window
}
}