[Pkg-javascript-commits] [sockjs-client] 243/434: #15 add tests
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 36b73f04e11165d63487a3ecde9d3cc2d875a2ba
Author: Marek Majkowski <majek04 at gmail.com>
Date: Thu Dec 1 17:00:24 2011 +0000
#15 add tests
The tests are quite messy, I'm aware.
---
Makefile | 2 +-
tests/html/sockjs-in-head.html | 21 ++++++++++++++++
tests/html/src/domtests.coffee | 4 +--
tests/html/src/endtoendtests.coffee | 50 +++++++++++++++++++++++++++++++++++++
tests/html/tests-qunit.html | 1 +
tests/server.js | 8 +++++-
6 files changed, 82 insertions(+), 4 deletions(-)
diff --git a/Makefile b/Makefile
index 0d50efa..a2c80b5 100644
--- a/Makefile
+++ b/Makefile
@@ -24,7 +24,7 @@ tests/html/lib/%.js: tests/html/src/%.coffee
coffee -o tests/html/lib/ -c --bare $<
build_tests: tests/html/lib/sockjs.js tests/html/lib/tests.js \
- tests/html/lib/domtests.js
+ tests/html/lib/domtests.js tests/html/lib/endtoendtests.js
test: tests
tests: build_tests
diff --git a/tests/html/sockjs-in-head.html b/tests/html/sockjs-in-head.html
new file mode 100644
index 0000000..c8c851a
--- /dev/null
+++ b/tests/html/sockjs-in-head.html
@@ -0,0 +1,21 @@
+<!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 src="/lib/sockjs.js?no=cache"></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>
+ <script src="slow-script.js?yes=nocache"></script>
+</head>
+<body>
+ <h2>Don't panic!</h2>
+</body>
diff --git a/tests/html/src/domtests.coffee b/tests/html/src/domtests.coffee
index f6f542c..d4d4eff 100644
--- a/tests/html/src/domtests.coffee
+++ b/tests/html/src/domtests.coffee
@@ -2,14 +2,14 @@ module('Dom')
u = SockJS.getUtils()
-newIframe = ->
+newIframe = (path = '/iframe.html') ->
# Requires to put:
# 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)
+ hook.iobj = u.createIframe(path + '?a=' + Math.random() + '#' + hook.id, err)
return hook
onunload_test_factory = (code) ->
diff --git a/tests/html/src/endtoendtests.coffee b/tests/html/src/endtoendtests.coffee
new file mode 100644
index 0000000..f1569eb
--- /dev/null
+++ b/tests/html/src/endtoendtests.coffee
@@ -0,0 +1,50 @@
+module('End to End')
+
+factory_body_check = (protocol) ->
+ if not SockJS[protocol] or not SockJS[protocol].enabled(client_opts.sockjs_opts)
+ n = " " + protocol + "[unsupported by client]"
+ test n, ->
+ log('Unsupported protocol (by client): "' + protocol + '"')
+ else
+ asyncTest protocol, ->
+ expect(5)
+ path = '/echo'
+ url = if /^http/.test(path) then path else client_opts.url + path
+
+ code = """
+ hook.test_body(!!document.body, typeof document.body);
+
+ var sock = new SockJS('""" + url + """', '""" + protocol + """');
+ sock.onopen = function() {
+ var m = hook.onopen();
+ sock.send(m);
+ };
+ sock.onmessage = function(e) {
+ hook.onmessage(e.data);
+ sock.close();
+ };
+ """
+ hook = newIframe('sockjs-in-head.html')
+ hook.open = ->
+ hook.iobj.loaded()
+ ok(true, 'open')
+ hook.callback(code)
+ hook.test_body = (is_body, type) ->
+ equal(is_body, false, 'body not yet loaded ' + type)
+ hook.onopen = ->
+ ok(true, 'onopen')
+ return 'a'
+ hook.onmessage = (m) ->
+ equal(m, 'a')
+ ok(true, 'onmessage')
+ hook.iobj.cleanup()
+ hook.del()
+ start()
+
+module('sockjs in head')
+body_protocols = ['iframe-eventsource',
+ 'iframe-htmlfile',
+ 'iframe-xhr-polling',
+ 'jsonp-polling']
+for protocol in body_protocols
+ factory_body_check(protocol)
\ No newline at end of file
diff --git a/tests/html/tests-qunit.html b/tests/html/tests-qunit.html
index 4df8314..1aa6cc6 100644
--- a/tests/html/tests-qunit.html
+++ b/tests/html/tests-qunit.html
@@ -19,6 +19,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>
+ <script type="text/javascript" src="lib/endtoendtests.js"></script>
<script type="text/javascript" src="lib/tests.js"></script>
</head>
<body>
diff --git a/tests/server.js b/tests/server.js
index 941e72f..b5110c5 100644
--- a/tests/server.js
+++ b/tests/server.js
@@ -10,7 +10,13 @@ var static_directory = new node_static.Server(__dirname + '/html');
var server = http.createServer();
server.addListener('request', function(req, res) {
- if (req.url === '/config.js') {
+ if (/[/]slow-script.js/.test(req.url)) {
+ res.setHeader('content-type', 'application/javascript');
+ res.writeHead(200);
+ setTimeout(function() {
+ res.end('var a = 1;\n');
+ }, 500);
+ } else if (req.url === '/config.js') {
res.setHeader('content-type', 'application/javascript');
res.writeHead(200);
res.end('var client_opts = ' +
--
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