<commit_before>module('Dom')

u = SockJS.getUtils()

newIframe = ->
    # Must do:
    #     document.domain = document.domain
    # in HEAD, for IE7
    hook = u.createHook()
    err = ->
        log('iframe error. bad.')
    hook.iobj = u.createIframe('/iframe.html?a=' + Math.random() + '#' + hook.id, err)
    return hook

if navigator.userAgent.indexOf('Konqueror') isnt -1
    test "onunload [unsupported by client]", ->
        ok(true)
else
    asyncTest 'onunload', ->
        expect(2)
        hook = newIframe()
        hook.open = ->
            ok(true, 'open hook called by an iframe')
            hook.callback("""
                    var u = SockJS.getUtils();
                    u.attachEvent('unload', function(){
                        hook.done();
                    });
                """)
            f = -> hook.iobj.cleanup()
            setTimeout(f, 1)
        hook.done = ->
            ok(true, 'done hook called by an iframe')
            hook.del()
            start()

if navigator.userAgent.indexOf('Konqueror') isnt -1 or $.browser.opera
    test "onbeforeunload [unsupported by client]", ->
        ok(true)
else
    asyncTest 'onbeforeunload', ->
        expect(2)
        hook = newIframe()
        hook.open = ->
            ok(true, 'open hook called by an iframe')
            hook.callback("""
                    var u = SockJS.getUtils();
                    u.attachEvent('beforeunload', function(){
                        hook.done();
                  return ;
                    });
                """)
            f = -> hook.iobj.cleanup()
            setTimeout(f, 1)
        hook.done = ->
            ok(true, 'done hook called by an iframe')
            hook.del()
            start()

if not SockJS.getIframeTransport().enabled()
    test "onmessage [unsupported by client]", ->
        ok(true)
else
    asyncTest 'onmessage', ->
        expect(3)<commit_msg>Abstract similar onunload and onbeforeunload tests<commit_after>module('Dom')

u = SockJS.getUtils()

newIframe = ->
    # Must do:
    #     document.domain = document.domain
    # in HEAD, for IE7
    hook = u.createHook()
    err = ->
        log('iframe error. bad.')
    hook.iobj = u.createIframe('/iframe.html?a=' + Math.random() + '#' + hook.id, err)
    return hook

onunload_test_factory = (code) ->
    return ->
        expect(2)
        hook = newIframe()
        hook.open = ->
            ok(true, 'open hook called by an iframe')
            hook.callback(code)
            f = -> hook.iobj.cleanup()
            setTimeout(f, 1)
        hook.done = ->
            ok(true, 'done hook called by an iframe')
            hook.del()
            start()

if navigator.userAgent.indexOf('Konqueror') isnt -1
    test "onunload [unsupported by client]", ->
        ok(true)
else
    asyncTest('onunload', onunload_test_factory("""
                    var u = SockJS.getUtils();
                    u.attachEvent('unload', function(){
                        hook.done();
                    });
                """))

if navigator.userAgent.indexOf('Konqueror') isnt -1 or $.browser.opera
    test "onbeforeunload [unsupported by client]", ->
        ok(true)
else
    asyncTest('onbeforeunload', onunload_test_factory("""
                    var u = SockJS.getUtils();
                    u.attachEvent('beforeunload', function(){
                        hook.done();
                    });
                """))

if not SockJS.getIframeTransport().enabled()
    test "onmessage [unsupported by client]", ->
        ok(true)
else
    asyncTest 'onmessage', ->
        expect(3)
{'fraction_non_alphanumeric': 0.1349404267110003, 'fraction_numerical': 0.0038791909116098642, 'mean_word_length': 1.595255212077642, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5300657', 'n_tokens_mistral': 1083, 'n_tokens_neox': 1048, 'n_words': 242}