Skip to content

Commit

Permalink
add test cases for type checking in window.open
Browse files Browse the repository at this point in the history
  • Loading branch information
lifesinger committed Sep 26, 2013
1 parent 5460410 commit b6b8230
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lab/2013/check-type/ifr.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!doctype html>
<html>
<head>
<title>Test</title>
</head>
<body>
<script>

window.arr = [0, 1, 2]
window.str = "xxx"
window.fn = function() {}
window.obj = {}

</script>
</body>
</html>
16 changes: 16 additions & 0 deletions lab/2013/check-type/nwn.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!doctype html>
<html>
<head>
<title>Test</title>
</head>
<body>
<script>

window.arr = [0, 1, 2]
window.str = "xxx"
window.fn = function() {}
window.obj = {}

</script>
</body>
</html>
61 changes: 61 additions & 0 deletions lab/2013/check-type/test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<!doctype html>
<html>
<head>
<title>test</title>
</head>
<body>
<iframe id="ifr" src="ifr.html"></iframe>

<div id="o"></div>

<script>

function isType(type) {
return function(obj) {
return {}.toString.call(obj) == "[object " + type + "]"
}
}

var isObject = isType("Object")
var isString = isType("String")
var isArray = isType("Array")
var isFunction = isType("Function")


var ifr = document.getElementById("ifr").contentWindow
var nwn = window.open("nwn.html")
var out = document.getElementById("o")

function print(msg) {
var p = document.createElement('p')
p.innerHTML = msg
out.appendChild(p)
}


setTimeout(done, 1000)

function done() {
print("isObject(ifr.obj) = " + (isObject(ifr.obj)))
print("isObject(nwn.obj) = " + (isObject(nwn.obj)))

print("isString(ifr.str) = " + (isString(ifr.str)))
print("isString(nwn.str) = " + (isString(nwn.str)))

print("isArray(ifr.arr) = " + (isArray(ifr.arr)))
print("isArray(nwn.arr) = " + (isArray(nwn.arr)))

print("isFunction(ifr.fn) = " + (isFunction(ifr.fn)))
print("isFunction(nwn.fn) = " + (isFunction(nwn.fn)))

nwn.close()
}

</script>

<p>
<a href="http://whattheheadsaid.com/2010/10/cross-context-isarray-and-internet-explorer">http://whattheheadsaid.com/2010/10/cross-context-isarray-and-internet-explorer</a>
</p>

</body>
</html>

0 comments on commit b6b8230

Please sign in to comment.