[Pkg-javascript-commits] [sockjs-client] 231/434: Test onunload and onmessage events - using an iframe.

Tonnerre Lombard tonnerre-guest at moszumanska.debian.org
Wed Jan 8 00:47:16 UTC 2014


This is an automated email from the git hooks/post-receive script.

tonnerre-guest pushed a commit to branch master
in repository sockjs-client.

commit 81551ebb78c028ac3cf0f4ec5562816f3e960a8b
Author: Marek Majkowski <majek04 at gmail.com>
Date:   Wed Nov 30 17:44:53 2011 +0000

    Test onunload and onmessage events - using an iframe.
    
    onunload doesn't work in opera and konqueror.
    
    onmessage doens't work in konqueror.
    
    Additionally, opera has interesiting restrictions about iframe security - javascript has to be in 'body', not head.
---
 lib/test-hooks.js              |  4 +++
 tests/html/iframe.html         | 14 ++++-----
 tests/html/src/domtests.coffee | 68 ++++++++++++++++++++++++++++++++----------
 3 files changed, 64 insertions(+), 22 deletions(-)

diff --git a/lib/test-hooks.js b/lib/test-hooks.js
index f5820c6..5c7f6dd 100644
--- a/lib/test-hooks.js
+++ b/lib/test-hooks.js
@@ -2,3 +2,7 @@
 SockJS.getUtils = function(){
     return utils;
 };
+
+SockJS.getIframeTransport = function(){
+    return IframeTransport;
+};
diff --git a/tests/html/iframe.html b/tests/html/iframe.html
index d1984da..6b7b5d1 100644
--- a/tests/html/iframe.html
+++ b/tests/html/iframe.html
@@ -3,18 +3,18 @@
 <head>
   <meta http-equiv="X-UA-Compatible" content="IE=edge" />
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
-  <script>
-    document.domain = document.domain;
-    _sockjs_onload = function(){SockJS.bootstrap_iframe();};
-  </script>
   <script src="/lib/sockjs.js"></script>
 </head>
 <body>
   <h2>Don't panic!</h2>
   <p>This is a SockJS hidden iframe. It's used for cross domain magic.</p>
   <script>
-    var window_id = document.location.hash.slice(1);
-    parent._sockjs_global(window_id).callback = function(code) {eval(code);};
-    parent._sockjs_global(window_id).open();
+    document.domain = document.domain;
+    history.navigationMode = 'compatible';
+    c = parent._sockjs_global;
+    window_id = document.location.hash.slice(1);
+    hook = c(window_id);
+    hook.callback = function(code) {eval(code);};
+    hook.open();
   </script>
 </body>
diff --git a/tests/html/src/domtests.coffee b/tests/html/src/domtests.coffee
index c8b7c85..b1b36ba 100644
--- a/tests/html/src/domtests.coffee
+++ b/tests/html/src/domtests.coffee
@@ -1,30 +1,68 @@
-module('dom tests')
+module('Dom')
 
 u = SockJS.getUtils()
 
 newIframe = ->
+    document.domain = document.domain
     hook = u.createHook()
     err = ->
         console.log('iframe error. bad.')
     hook.iobj = u.createIframe('/iframe.html#' + hook.id, err)
     return hook
 
+if navigator.userAgent.indexOf('Konqueror') isnt -1 or $.browser.opera
+    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()
 
-asyncTest 'onunload', ->
-    document.domain = document.domain;
-    """
-    var u = SockJS.getUtils();
-    u.attachEvent('unload', function(){
-            parent.{{ callback }}.message('unload');
-        });
-    """
-    hook = newIframe()
-    hook.open = ->
-        hook.callback('alert("hhello world");')
-        hook.iobj.cleanup()
-        hook.del()
+if not SockJS.getIframeTransport().enabled()
+    test "onmessage [unsupported by client]", ->
         ok(true)
-        start()
+else
+    asyncTest 'onmessage', ->
+        expect(3)
+        hook = newIframe()
+        hook.open = ->
+            ok(true, 'open hook called by an iframe')
+            hook.callback("""
+                    var u = SockJS.getUtils();
+                    u.attachMessage(function(e) {
+                        var b = e.data;
+                        parent.postMessage(window_id + ' ' + 'e', '*');
+                    });
+                    parent.postMessage(window_id + ' ' + 's', '*');
+                """)
+        u.attachMessage (e) ->
+            [window_id, data] = e.data.split(' ')
+            if window_id is hook.id
+                switch data
+                    when 's'
+                        hook.iobj.loaded()
+                        ok(true, 'start frame send')
+                        origin = u.getOrigin(u.amendUrl('/'))
+                        hook.iobj.iframe.contentWindow.postMessage(hook.id + ' ' + 's' , origin)
+                    when 'e'
+                        ok(true, 'done hook called by an iframe')
+                        hook.iobj.cleanup()
+                        hook.del()
+                        start()
 
 
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/sockjs-client.git



More information about the Pkg-javascript-commits mailing list