Permalink
Browse files

added an essential event test unit, to be expanded to include delegat…

…ion tests (bgerrissen)
  • Loading branch information...
1 parent 3e0834b commit 97cdf079f3254eba5c2830601923f852cbc4f4b9 Diego Perini committed Mar 20, 2010
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <title>Dispatching tests</title>
+
+ <link href="../css/style.css" rel="stylesheet" type="text/css">
+ <link href="../css/qunit.css" rel="stylesheet" type="text/css">
+
+ </head>
+ <body>
+
+ <h1>Dispatching tests</h1>
+ <p>If tests fail, it could also be that the removal of listeners failed, check 'expected' test number.</p>
+ <p>All tests have a timeout of 1000 miliseconds.</p>
+
+ <div id="parent">
+ <div id="child"></div>
+ </div>
+
+ <iframe src="iframetarget.html" width="0" height="0" frameborder="0" id="iframe" name="iframe"></iframe>
+
+ <h1 id="qunit-header">QUnit</h1>
+ <h2 id="qunit-banner"></h2>
+ <h2 id="qunit-userAgent"></h2>
+ <ol id="qunit-tests">
+ </ol>
+
+ <script src="../lib/qunit.js" type="text/javascript"></script>
+ <script src="../../src/nwevents.js" type="text/javascript"></script>
+ <script src="dispatching.js" type="text/javascript"></script>
+
+ </body>
+</html>
View
@@ -0,0 +1,226 @@
+var debug = false,
+
+ parentNode = document.getElementById('parent'),
+ childNode = document.getElementById('child'),
+
+ // aliases
+ add = NW.Event.listen,
+ rem = NW.Event.unlisten,
+ dis = NW.Event.dispatch;
+
+module("DISPATCHING");
+
+// 1
+test('Dispatching "click" event on document object', function() {
+
+ expect(4);
+
+ add(document, 'click', function(e) {
+ rem(document, 'click', arguments.callee, false);
+ equals(this, document, 'this should be document object');
+ equals(e.target, document, 'target should be document object');
+ equals(e.currentTarget, document, 'current target should be document object');
+ equals(e.eventPhase, 2, 'Should be at-target phase');
+ debug && start();
+ }, false);
+
+ debug && stop(1000);
+
+ dis(document, 'click');
+
+});
+
+// 2
+test('1 listener on bubbling phase, dispatching "click" event', function() {
+
+ expect(5);
+
+ add(parentNode, 'click', function(e) {
+ rem(parentNode, 'click', arguments.callee, false);
+ equals(e.type, 'click', 'e.type should equal "click"');
+ equals(e.eventPhase, 2, 'Should be at-target phase');
+ equals(this, parentNode, 'this should be parentNode element');
+ equals(e.target, parentNode, 'e.target should be parentNode element');
+ equals(e.currentTarget, parentNode, 'current target should be parentNode element');
+ debug && start();
+ }, false);
+
+ debug && stop(1000);
+
+ dis(parentNode, 'click');
+
+});
+
+// 3
+test('1 listener on capture phase, dispatching "click" event', function() {
+
+ expect(5);
+
+ add(parentNode, 'click', function(e) {
+ rem(parentNode, 'click', arguments.callee, true);
+ equals(e.type, 'click', 'e.type should equal "click"');
+ equals(e.eventPhase, 2, 'Should be at-target phase');
+ equals(this, parentNode, 'this should be parentNode element');
+ equals(e.target, parentNode, 'e.target should be parentNode element');
+ equals(e.currentTarget, parentNode, 'current target should be parentNode element');
+ debug && start();
+ }, true);
+
+ debug && stop(1000);
+
+ dis(parentNode, 'click');
+
+});
+
+// 4
+test('Listener on parentNode should capture childNode event @ bubble', function() {
+
+ expect(4);
+
+ add(parentNode, 'click', function(e) {
+ rem(parentNode, 'click', arguments.callee, false);
+ equals(e.eventPhase, 3, 'Should be bubbling phase');
+ equals(this, parentNode, 'this should be parentNode element');
+ equals(e.target, childNode, 'e.target should be childNode element');
+ equals(e.currentTarget, parentNode, 'current target should be parentNode element');
+ debug && start();
+ }, false);
+
+ debug && stop(1000);
+
+ dis(childNode, 'click');
+
+});
+
+// 5
+test('Listener on parentNode should capture childNode event @ capture', function() {
+
+ expect(4);
+
+ add(parentNode, 'click', function(e) {
+ rem(parentNode, 'click', arguments.callee, true);
+ equals(e.eventPhase, 1, 'Should be capturing phase');
+ equals(this, parentNode, 'this should be parentNode element');
+ equals(e.target, childNode, 'e.target should be childNode element');
+ equals(e.currentTarget, parentNode, 'current target should be parentNode element');
+ debug && start();
+ }, true);
+
+ debug && stop(1000);
+
+ dis(childNode, 'click');
+
+});
+
+// 6
+test('Dispatching CUSTOM "hello" event @ at-target phase', function() {
+
+ expect(2);
+
+ add(parentNode, 'hello', function(e) {
+ rem(parentNode, 'hello', arguments.callee, false);
+ equals(e.type, 'hello', 'Event type should match custom event type');
+ equals(e.eventPhase, 2, 'Should be at-target phase');
+ debug && start();
+ }, false);
+
+ debug && stop(1000);
+
+ dis(parentNode, 'hello');
+
+});
+
+// 7
+test('Dispatching CUSTOM "hello" event @ capture phase', function() {
+
+ expect(2);
+
+ add(parentNode, 'hello', function(e) {
+ rem(parentNode, 'hello', arguments.callee, true);
+ equals(e.type, 'hello', 'Event type should match custom event type');
+ equals(e.eventPhase, 1, 'Should be capture phase');
+ debug && start();
+ }, true);
+
+ debug && stop(1000);
+
+ dis(childNode, 'hello');
+
+});
+
+// 8
+test('Dispatching CUSTOM "hello" event @ bubble phase', function() {
+
+ expect(2);
+
+ add(parentNode, 'hello', function(e) {
+ rem(parentNode, 'hello', arguments.callee, false);
+ equals(e.type, 'hello', 'Event type should match custom event type');
+ equals(e.eventPhase, 3, 'Should be bubble phase');
+ debug && start();
+ }, false);
+
+ debug && stop(1000);
+
+ dis(childNode, 'hello');
+
+});
+
+// 9
+test('Omitting useCapture argument, should default to bubble (false)', function() {
+
+ expect(2);
+
+ add(parentNode, 'click', function(e) {
+ rem(parentNode, 'click', arguments.callee);
+ equals(e.target, childNode, 'e.target should be childNode element');
+ equals(e.eventPhase, 3, 'Should be bubbling phase');
+ debug && start();
+ });
+
+ debug && stop(1000);
+
+ dis(childNode, 'click');
+
+});
+
+// 10
+test('Listener on iframe document should capture iframe target element event @ bubble', function() {
+
+ expect(3);
+
+ var iframeDoc = window.frames[0].document,
+ iframeTarget = iframeDoc.getElementById('target');
+
+ add(iframeDoc, 'click', function(e) {
+ rem(iframeDoc, 'click', arguments.callee, false);
+ equals(e.target, iframeTarget, 'e.target should be iframe target element');
+ equals(e.eventPhase, 3, 'Should be bubbling phase');
+ equals(e.target.ownerDocument.title, 'A Iframe', 'Should have correct iframe title');
+ debug && start();
+ }, false);
+
+ debug && stop(1000);
+
+ dis(iframeTarget, 'click');
+
+});
+
+// 11
+test('Listener on iframe document should capture iframe target element event @ capture', function() {
+
+ expect(3);
+
+ var iframeDoc = window.frames[0].document,
+ iframeTarget = iframeDoc.getElementById('target');
+
+ add(iframeDoc, 'click', function(e) {
+ rem(iframeDoc, 'click', arguments.callee, true);
+ equals(e.target, iframeTarget, 'e.target should be iframe target element');
+ equals(e.eventPhase, 1, 'e.eventPhase should be 1');
+ equals(e.target.ownerDocument.title, 'A Iframe', 'Should have correct iframe title');
+ }, true);
+
+ dis(iframeTarget, 'click');
+
+});
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <title>A Iframe</title>
+ </head>
+ <body>
+
+ <div id="target"></div>
+
+ </body>
+</html>
View
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <title>NWEvent Suite</title>
+
+ <link rel="stylesheet" type="text/css" href="css/style.css">
+
+ </head>
+ <body>
+
+ <ul>
+ <li><a href="dispatching.html" target="frame">Dispatching</a></li>
+ <li><a href="propagation.html" target="frame">Propagation</a></li>
+ <li><a href="interaction.html" target="frame">Interaction</a></li>
+ <li><a href="integration.html" target="frame">Integration</a></li>
+ </ul>
+
+ <iframe src="dispatching.html" name="frame" width="800" height="700"></iframe>
+
+ </body>
+</html>
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<html lang="en" dir="ltr">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <title>JS Integration tests</title>
+
+ <link href="../css/style.css" rel="stylesheet" type="text/css">
+ <link href="../css/qunit.css" rel="stylesheet" type="text/css">
+
+ </head>
+ <body>
+
+ <h1>JS Integration tests</h1>
+ <p>If tests fail, it could also be that the removal of listeners failed, check 'expected' test number.</p>
+ <p>All tests have a timeout of 1000 miliseconds.</p>
+
+ <div id="parent">
+ <div id="child"></div>
+ </div>
+
+ <iframe src="iframetarget.html" width="0" height="0" frameborder="0" id="iframe"></iframe>
+
+ <h1 id="qunit-header">QUnit</h1>
+ <h2 id="qunit-banner"></h2>
+ <h2 id="qunit-userAgent"></h2>
+ <ol id="qunit-tests">
+ </ol>
+
+ <script src="../lib/qunit.js" type="text/javascript"></script>
+ <script src="../../src/nwevents.js" type="text/javascript"></script>
+ <script src="integration.js" type="text/javascript"></script>
+
+ </body>
+</html>
Oops, something went wrong.

0 comments on commit 97cdf07

Please sign in to comment.