Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: f5a5b1de88
Fetching contributors…

Cannot retrieve contributors at this time

file 92 lines (71 sloc) 2.153 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width"/>
<title>location.hash change event (hashchange) tests</title>
<script src="tests.common.js"></script>

<!--[if lte IE 7]><script src="../src/core/fixes/trident3.js"></script><![endif]-->
<!--[if IE 8]><script src="../src/core/fixes/trident4.js"></script><![endif]-->
<script src="../src/core/prototype.js"></script>
<script src="../src/core/fixes/onhashchange.js"></script>
</head>
<body>
<script>
Tests.test(function (t)
{
t.parallel(1)

t.test('signs of presence', function (t)
{
t.isin('onhashchange', window, 'window')
})

t.test('dispath on location.hash = …', function (t)
{
function onhashchange (e)
{
window.removeEventListener('hashchange', onhashchange, false)

t.eq(e.type, 'hashchange', 'event.type')

t.done()
}

window.addEventListener('hashchange', onhashchange, false)

setTimeout(function () { window.location.hash = Math.longRandom() }, 0)
t.wait(1000)
})

t.test('dispath on history.back()', function (t)
{
if (/Chrome [123456]\.|MSIE [67]\./.test(Tests.ua))
return t.warn('This browser (' + Tests.ua + ') does not take location.hash changes in history account.')

// window.location.hash = Math.longRandom()

function onhashchange (e)
{
window.removeEventListener('hashchange', onhashchange, false)

t.eq(e.type, 'hashchange', 'event.type')

t.done()
}

function back (e)
{
window.addEventListener('hashchange', onhashchange, false)
history.back()
}

setTimeout(back, 1)
t.wait(1000)
})

t.test('dispath on history.back()', function (t)
{
if (window.location.setHashchangeCheckInterval)
window.location.setHashchangeCheckInterval(1)

var count = 0

function onhashchange () { count++ }
window.addEventListener('hashchange', onhashchange, false)

window.location.hash = Math.longRandom()

function check ()
{
t.eq(count, 1, 'fired once')

if (window.location.setHashchangeCheckInterval)
window.location.setHashchangeCheckInterval()
}

t.async(check, 500)
})
})
</script>
</body>
</html>
Something went wrong with that request. Please try again.