[Pkg-javascript-commits] [sockjs-client] 229/434: Framework for dom tests.
Tonnerre Lombard
tonnerre-guest at moszumanska.debian.org
Wed Jan 8 00:47:15 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 6ad9e0397c6126a58df3f510c1cf07f7cde0e7a4
Author: Marek Majkowski <majek04 at gmail.com>
Date: Wed Nov 30 13:07:14 2011 +0000
Framework for dom tests.
---
Makefile | 3 ++-
lib/dom.js | 21 +++++++++++++++++++++
tests/html/iframe.html | 20 ++++++++++++++++++++
tests/html/src/domtests.coffee | 36 ++++++++++++++++++++++++++++++++++++
tests/html/unittests.html | 1 +
5 files changed, 80 insertions(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
index 144ea89..5643724 100644
--- a/Makefile
+++ b/Makefile
@@ -24,7 +24,8 @@ tests/html/lib/%.js: tests/html/src/%.coffee
coffee -o tests/html/lib/ -c --bare $<
test: tests
-tests: tests/html/lib/sockjs.js tests/html/lib/tests.js tests/html/lib/unittests.js
+tests: tests/html/lib/sockjs.js tests/html/lib/tests.js \
+ tests/html/lib/domtests.js
node tests/server.js
diff --git a/lib/dom.js b/lib/dom.js
index 8d56596..0b9efc8 100644
--- a/lib/dom.js
+++ b/lib/dom.js
@@ -1,3 +1,24 @@
+// May be used by htmlfile jsonp and transports.
+var MPrefix = '_sockjs_global';
+utils.createHook = function() {
+ var window_id = 'a' + utils.random_string(8);
+ if (!(MPrefix in _window)) {
+ var map = {};
+ _window[MPrefix] = function(window_id) {
+ if (!(window_id in map)) {
+ map[window_id] = {
+ id: window_id,
+ del: function() {delete map[window_id];}
+ };
+ }
+ return map[window_id];
+ }
+ }
+ return _window[MPrefix](window_id);
+};
+
+
+
utils.attachMessage = function(listener) {
utils.attachEvent('message', listener);
};
diff --git a/tests/html/iframe.html b/tests/html/iframe.html
new file mode 100644
index 0000000..d1984da
--- /dev/null
+++ b/tests/html/iframe.html
@@ -0,0 +1,20 @@
+<!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;
+ _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();
+ </script>
+</body>
diff --git a/tests/html/src/domtests.coffee b/tests/html/src/domtests.coffee
new file mode 100644
index 0000000..c8b7c85
--- /dev/null
+++ b/tests/html/src/domtests.coffee
@@ -0,0 +1,36 @@
+module('dom tests')
+
+u = SockJS.getUtils()
+
+newIframe = ->
+ hook = u.createHook()
+ err = ->
+ console.log('iframe error. bad.')
+ hook.iobj = u.createIframe('/iframe.html#' + hook.id, err)
+ return hook
+
+
+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()
+ ok(true)
+ start()
+
+
+
+
+
+# 1. data url
+# 2. wrong uri
+# 3. mass run - to verify mem leaks
+
diff --git a/tests/html/unittests.html b/tests/html/unittests.html
index 6c4d197..1ce9bd0 100644
--- a/tests/html/unittests.html
+++ b/tests/html/unittests.html
@@ -13,6 +13,7 @@
<script type="text/javascript" src="config.js"></script>
<script type="text/javascript" src="lib/unittests.js"></script>
+ <script type="text/javascript" src="lib/domtests.js"></script>
</head>
<body>
<p>
--
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