[Pkg-javascript-commits] [sockjs-client] 28/350: Fix message transmission when the message is sent from an iframe/popup in IE7/8

tonnerre at ancient-solutions.com tonnerre at ancient-solutions.com
Fri Aug 5 01:03:38 UTC 2016


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

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

commit d3c4759066b38ef1695355a469879fd2fb3a902a
Author: Yannick Croissant <yannick.croissant at gmail.com>
Date:   Wed Apr 30 17:23:24 2014 +0200

    Fix message transmission when the message is sent from an iframe/popup in IE7/8
---
 lib/dom.js                       |  8 ++++++--
 tests/html/sockjs-in-parent.html | 19 +++++++++++++++++++
 tests/html/src/tests.coffee      | 41 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 66 insertions(+), 2 deletions(-)

diff --git a/lib/dom.js b/lib/dom.js
index 78a3b49..4a903e2 100644
--- a/lib/dom.js
+++ b/lib/dom.js
@@ -126,7 +126,9 @@ utils.createIframe = function (iframe_url, error_callback) {
             // When the iframe is not loaded, IE raises an exception
             // on 'contentWindow'.
             if (iframe && iframe.contentWindow) {
-                iframe.contentWindow.postMessage(msg, origin);
+                setTimeout(function() {
+                    iframe.contentWindow.postMessage(msg, origin);
+                }, 0);
             }
         } catch (x) {};
     };
@@ -178,7 +180,9 @@ utils.createHtmlfile = function (iframe_url, error_callback) {
             // When the iframe is not loaded, IE raises an exception
             // on 'contentWindow'.
             if (iframe && iframe.contentWindow) {
-                iframe.contentWindow.postMessage(msg, origin);
+                setTimeout(function() {
+                    iframe.contentWindow.postMessage(msg, origin);
+                }, 0);
             }
         } catch (x) {};
     };
diff --git a/tests/html/sockjs-in-parent.html b/tests/html/sockjs-in-parent.html
new file mode 100755
index 0000000..e207a2c
--- /dev/null
+++ b/tests/html/sockjs-in-parent.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+<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;
+  </script>
+  <script>
+    c = parent._sockjs_global;
+    window_id = document.location.hash.slice(1);
+    hook = c(window_id);
+    hook.callback = function(code) {eval(code);};
+    hook.open();
+  </script>
+</head>
+<body>
+  <h2>Don't panic!</h2>
+</body>
diff --git a/tests/html/src/tests.coffee b/tests/html/src/tests.coffee
old mode 100644
new mode 100755
index 90ef2db..3c2cd86
--- a/tests/html/src/tests.coffee
+++ b/tests/html/src/tests.coffee
@@ -55,6 +55,46 @@ factor_echo_rich = (protocol) ->
     messages = [ [1,2,3,'data'], null, false, "data", 1, 12.0, {a:1, b:2} ]
     return echo_factory_factory(protocol, messages)
 
+factor_echo_from_child = (protocol) ->
+  return ->
+    timeout = undefined
+    hookReady = false
+    sockJSReady = false
+    expect 4
+    hook = newIframe("sockjs-in-parent.html")
+    r = newSockJS("/echo", protocol)
+    code = "hook.r.send('a'); hook.onsend();"
+    hook.open = ->
+      hook.iobj.loaded()
+      ok true, "iframe open"
+      hookReady = true
+      hook.r = r
+      sockJSReady and hook.callback(code)
+
+    r.onopen = (e) ->
+      hook.iobj.loaded()
+      ok true, "sockjs open"
+      sockJSReady = true
+      hookReady and hook.callback(code)
+
+    r.onmessage = (e) ->
+      clearTimeout timeout
+      equal e.data, "a"
+      ok true, "onmessage"
+      hook.iobj.cleanup()
+      hook.del()
+      r.close()
+
+    hook.onsend = (e) ->
+      timeout = setTimeout(->
+        ok false
+        r.close()
+        return
+      , 300)
+      return
+
+    r.onclose = ->
+      start()
 
 factor_echo_unicode = (protocol) ->
     messages = [
@@ -292,6 +332,7 @@ test_protocol_messages = (protocol) ->
     else
         asyncTest("echo1", factor_echo_basic(protocol))
         asyncTest("echo2", factor_echo_rich(protocol))
+        asyncTest("echo from child", factor_echo_from_child(protocol))
         asyncTest("unicode", factor_echo_unicode(protocol))
         asyncTest("utf encoding 0x00-0xFF",
             factor_echo_utf_encoding_simple(protocol))

-- 
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