envjs19 0.3.8.20101029121421

Sign up to get free protection for your applications and to get access to all the features.
Files changed (279) hide show
  1. data/.jslintrbrc +30 -0
  2. data/.project +17 -0
  3. data/CHANGELOG.rdoc +57 -0
  4. data/DTD/xhtml-lat1.ent +196 -0
  5. data/DTD/xhtml-special.ent +80 -0
  6. data/DTD/xhtml-symbol.ent +237 -0
  7. data/DTD/xhtml.soc +14 -0
  8. data/DTD/xhtml1-frameset.dtd +1235 -0
  9. data/DTD/xhtml1-strict.dtd +978 -0
  10. data/DTD/xhtml1-transitional.dtd +1201 -0
  11. data/DTD/xhtml1.dcl +192 -0
  12. data/Makefile +7 -0
  13. data/Manifest.txt +280 -0
  14. data/README.rdoc +65 -0
  15. data/Rakefile +196 -0
  16. data/Wakefile +11 -0
  17. data/bin/envjsrb +257 -0
  18. data/build.properties +9 -0
  19. data/build.xml +247 -0
  20. data/gm/jquery.js +6002 -0
  21. data/gm/mainx.js +2648 -0
  22. data/gm/sensx.js +135 -0
  23. data/gm/t.js +6 -0
  24. data/gm/x.html +76 -0
  25. data/htmlparser/BrowserTreeBuilder.java +456 -0
  26. data/htmlparser/README +34 -0
  27. data/htmlparser/build.sh +38 -0
  28. data/jsl/jsl +0 -0
  29. data/jsl/jsl.default.conf +129 -0
  30. data/jsl/jsl.exe +0 -0
  31. data/lib/envjs.rb +35 -0
  32. data/lib/envjs/event_loop.js +206 -0
  33. data/lib/envjs/net.rb +3 -0
  34. data/lib/envjs/net/cgi.rb +94 -0
  35. data/lib/envjs/net/file.rb +69 -0
  36. data/lib/envjs/options.rb +11 -0
  37. data/lib/envjs/runtime.rb +346 -0
  38. data/lib/envjs/tempfile.rb +24 -0
  39. data/licenses/GPL-LICENSE.txt +278 -0
  40. data/licenses/MIT-LICENSE.txt +20 -0
  41. data/src/base64.js +80 -0
  42. data/src/build.js +6 -0
  43. data/src/cruft/bad.html +24 -0
  44. data/src/cruft/dom.js +606 -0
  45. data/src/cruft/element.js +297 -0
  46. data/src/cruft/good.html +30 -0
  47. data/src/cruft/good.js +32 -0
  48. data/src/cruft/internal.js +81 -0
  49. data/src/cruft/parser.js +458 -0
  50. data/src/css/properties.js +293 -0
  51. data/src/css/rule.js +22 -0
  52. data/src/css/sizzle.js +717 -0
  53. data/src/css/stylesheet.js +52 -0
  54. data/src/dom/attr.js +55 -0
  55. data/src/dom/cdatasection.js +31 -0
  56. data/src/dom/characterdata.js +119 -0
  57. data/src/dom/comment.js +30 -0
  58. data/src/dom/doctype.js +9 -0
  59. data/src/dom/document.js +1023 -0
  60. data/src/dom/dom.js +134 -0
  61. data/src/dom/element.js +217 -0
  62. data/src/dom/entities.js +273 -0
  63. data/src/dom/exception.js +28 -0
  64. data/src/dom/fragment.js +37 -0
  65. data/src/dom/implementation.js +140 -0
  66. data/src/dom/instruction.js +51 -0
  67. data/src/dom/namednodemap.js +374 -0
  68. data/src/dom/namespace.js +50 -0
  69. data/src/dom/node.js +618 -0
  70. data/src/dom/nodelist.js +195 -0
  71. data/src/dom/parser.js +1207 -0
  72. data/src/dom/text.js +73 -0
  73. data/src/event/event.js +47 -0
  74. data/src/event/mouseevent.js +4 -0
  75. data/src/event/uievent.js +8 -0
  76. data/src/html/a.js +110 -0
  77. data/src/html/anchor.js +80 -0
  78. data/src/html/area.js +57 -0
  79. data/src/html/base.js +26 -0
  80. data/src/html/blockquote-q.js +19 -0
  81. data/src/html/body.js +19 -0
  82. data/src/html/button.js +21 -0
  83. data/src/html/canvas.js +14 -0
  84. data/src/html/col-colgroup.js +49 -0
  85. data/src/html/collection.js +72 -0
  86. data/src/html/cookie.js +153 -0
  87. data/src/html/del-ins.js +25 -0
  88. data/src/html/div.js +28 -0
  89. data/src/html/document.js +364 -0
  90. data/src/html/element.js +382 -0
  91. data/src/html/fieldset.js +19 -0
  92. data/src/html/form.js +484 -0
  93. data/src/html/frame.js +89 -0
  94. data/src/html/frameset.js +25 -0
  95. data/src/html/head.js +44 -0
  96. data/src/html/html.js +0 -0
  97. data/src/html/htmlparser.js +340 -0
  98. data/src/html/iframe.js +26 -0
  99. data/src/html/image.js +0 -0
  100. data/src/html/img.js +62 -0
  101. data/src/html/input-elements.js +307 -0
  102. data/src/html/input.js +65 -0
  103. data/src/html/label.js +26 -0
  104. data/src/html/legend.js +19 -0
  105. data/src/html/link.js +82 -0
  106. data/src/html/map.js +22 -0
  107. data/src/html/meta.js +37 -0
  108. data/src/html/object.js +89 -0
  109. data/src/html/optgroup.js +25 -0
  110. data/src/html/option.js +103 -0
  111. data/src/html/param.js +38 -0
  112. data/src/html/script.js +122 -0
  113. data/src/html/select.js +132 -0
  114. data/src/html/style.js +31 -0
  115. data/src/html/table.js +199 -0
  116. data/src/html/tbody-thead-tfoot.js +92 -0
  117. data/src/html/td-th.js +18 -0
  118. data/src/html/textarea.js +31 -0
  119. data/src/html/title.js +20 -0
  120. data/src/html/tr.js +114 -0
  121. data/src/intro.js +141 -0
  122. data/src/outro.js +70 -0
  123. data/src/parser/html5.detailed.js +10762 -0
  124. data/src/parser/html5.min.js +503 -0
  125. data/src/parser/html5.pretty.js +10815 -0
  126. data/src/parser/intro.js +42 -0
  127. data/src/parser/outro.js +9 -0
  128. data/src/platform/core.js +323 -0
  129. data/src/platform/johnson.js +484 -0
  130. data/src/platform/rhino.js +327 -0
  131. data/src/platform/static/intro.js +41 -0
  132. data/src/platform/static/outro.js +30 -0
  133. data/src/profile/aop.js +238 -0
  134. data/src/profile/profile.js +402 -0
  135. data/src/serializer/xml.js +21 -0
  136. data/src/svg/animatedstring.js +25 -0
  137. data/src/svg/document.js +25 -0
  138. data/src/svg/element.js +22 -0
  139. data/src/svg/locatable.js +17 -0
  140. data/src/svg/rect.js +18 -0
  141. data/src/svg/rectelement.js +24 -0
  142. data/src/svg/stylable.js +49 -0
  143. data/src/svg/svgelement.js +22 -0
  144. data/src/svg/transformable.js +15 -0
  145. data/src/window/css.js +15 -0
  146. data/src/window/dialog.js +16 -0
  147. data/src/window/document.js +28 -0
  148. data/src/window/event.js +265 -0
  149. data/src/window/history.js +62 -0
  150. data/src/window/location.js +156 -0
  151. data/src/window/navigator.js +48 -0
  152. data/src/window/screen.js +53 -0
  153. data/src/window/timer.js +21 -0
  154. data/src/window/window.js +284 -0
  155. data/src/window/xhr.js +135 -0
  156. data/src/xpath/expression.js +49 -0
  157. data/src/xpath/implementation.js +2505 -0
  158. data/src/xpath/result.js +67 -0
  159. data/src/xpath/util.js +551 -0
  160. data/src/xpath/xmltoken.js +149 -0
  161. data/src/xslt/COPYING +34 -0
  162. data/src/xslt/ajaxslt-0.8.1/AUTHORS +1 -0
  163. data/src/xslt/ajaxslt-0.8.1/ChangeLog +136 -0
  164. data/src/xslt/ajaxslt-0.8.1/Makefile +49 -0
  165. data/src/xslt/ajaxslt-0.8.1/README +102 -0
  166. data/src/xslt/ajaxslt-0.8.1/TODO +15 -0
  167. data/src/xslt/ajaxslt-0.8.1/dom.js +566 -0
  168. data/src/xslt/ajaxslt-0.8.1/dom_unittest.html +24 -0
  169. data/src/xslt/ajaxslt-0.8.1/dom_unittest.js +131 -0
  170. data/src/xslt/ajaxslt-0.8.1/simplelog.js +79 -0
  171. data/src/xslt/ajaxslt-0.8.1/test/xpath.html +18 -0
  172. data/src/xslt/ajaxslt-0.8.1/test/xpath_script.js +45 -0
  173. data/src/xslt/ajaxslt-0.8.1/test/xslt.html +58 -0
  174. data/src/xslt/ajaxslt-0.8.1/test/xslt_script.js +33 -0
  175. data/src/xslt/ajaxslt-0.8.1/unittestsuite.html +26 -0
  176. data/src/xslt/ajaxslt-0.8.1/xmltoken.js +149 -0
  177. data/src/xslt/ajaxslt-0.8.1/xmltoken_unittest.html +18 -0
  178. data/src/xslt/ajaxslt-0.8.1/xmltoken_unittest.js +811 -0
  179. data/src/xslt/ajaxslt-0.8.1/xpath_unittest.html +39 -0
  180. data/src/xslt/ajaxslt-0.8.1/xpath_unittest.js +557 -0
  181. data/src/xslt/ajaxslt-0.8.1/xpathdebug.js +234 -0
  182. data/src/xslt/ajaxslt-0.8.1/xslt_unittest.html +138 -0
  183. data/src/xslt/ajaxslt-0.8.1/xslt_unittest.js +68 -0
  184. data/src/xslt/implementation.js +625 -0
  185. data/src/xslt/processor.js +37 -0
  186. data/src/xslt/util.js +449 -0
  187. data/test/base64.js +80 -0
  188. data/test/call-load-test.js +15 -0
  189. data/test/data.js +45 -0
  190. data/test/debug.js +53 -0
  191. data/test/firebug/errorIcon.png +0 -0
  192. data/test/firebug/firebug.css +209 -0
  193. data/test/firebug/firebug.html +23 -0
  194. data/test/firebug/firebug.js +672 -0
  195. data/test/firebug/firebugx.js +10 -0
  196. data/test/firebug/infoIcon.png +0 -0
  197. data/test/firebug/warningIcon.png +0 -0
  198. data/test/fixtures/html/events.html +171 -0
  199. data/test/fixtures/html/iframe1.html +46 -0
  200. data/test/fixtures/html/iframe1a.html +46 -0
  201. data/test/fixtures/html/iframe2.html +45 -0
  202. data/test/fixtures/html/iframe3.html +28 -0
  203. data/test/fixtures/html/iframeN.html +57 -0
  204. data/test/fixtures/html/malformed.html +181 -0
  205. data/test/fixtures/html/scope.html +81 -0
  206. data/test/fixtures/html/trivial.html +19 -0
  207. data/test/fixtures/html/with_js.html +26 -0
  208. data/test/fixtures/images/icon-blue.png +0 -0
  209. data/test/fixtures/js/external_script.js +1 -0
  210. data/test/fixtures/js/script.js +1 -0
  211. data/test/fixtures/js/script_error.js +2 -0
  212. data/test/foo.html +8 -0
  213. data/test/foo.js +40 -0
  214. data/test/html/events.html +171 -0
  215. data/test/html/iframe1.html +46 -0
  216. data/test/html/iframe1a.html +46 -0
  217. data/test/html/iframe2.html +45 -0
  218. data/test/html/iframe3.html +30 -0
  219. data/test/html/iframeN.html +57 -0
  220. data/test/html/malformed.html +181 -0
  221. data/test/html/scope.html +87 -0
  222. data/test/html/script.js +1 -0
  223. data/test/html/trivial.html +19 -0
  224. data/test/html/with_js.html +26 -0
  225. data/test/index.html +328 -0
  226. data/test/java-prototype.js +9 -0
  227. data/test/jquery.js +6002 -0
  228. data/test/primary-tests.js +26 -0
  229. data/test/prototype-test.js +13 -0
  230. data/test/qunit.js +61 -0
  231. data/test/qunit/qunit/qunit.css +17 -0
  232. data/test/qunit/qunit/qunit.js +997 -0
  233. data/test/scope.html +19 -0
  234. data/test/scope.rb +24 -0
  235. data/test/smp/dmathieu/index.html +8 -0
  236. data/test/specs/dist/env.spec.js +1534 -0
  237. data/test/specs/envjs.spec.css +46 -0
  238. data/test/specs/parser/html.js +31 -0
  239. data/test/specs/parser/spec.html +40 -0
  240. data/test/specs/parser/xml.js +31 -0
  241. data/test/specs/qunit.bdd.js +210 -0
  242. data/test/specs/qunit.css +17 -0
  243. data/test/specs/qunit.js +997 -0
  244. data/test/specs/template/spec-0.js +31 -0
  245. data/test/specs/template/spec-1.js +31 -0
  246. data/test/specs/template/spec.html +40 -0
  247. data/test/specs/window/css.js +23 -0
  248. data/test/specs/window/dialog.js +25 -0
  249. data/test/specs/window/document.js +23 -0
  250. data/test/specs/window/event.js +25 -0
  251. data/test/specs/window/history.js +34 -0
  252. data/test/specs/window/location.js +34 -0
  253. data/test/specs/window/navigator.js +71 -0
  254. data/test/specs/window/screen.js +42 -0
  255. data/test/specs/window/spec.html +48 -0
  256. data/test/specs/window/timer.js +26 -0
  257. data/test/specs/window/window.js +53 -0
  258. data/test/specs/xhr/spec.html +47 -0
  259. data/test/specs/xhr/xhr.js +31 -0
  260. data/test/test.js +10 -0
  261. data/test/unit/dom.js +44 -0
  262. data/test/unit/elementmembers.js +92 -0
  263. data/test/unit/events.js +195 -0
  264. data/test/unit/fixtures/external_script.js +1 -0
  265. data/test/unit/form.js +40 -0
  266. data/test/unit/iframe.js +234 -0
  267. data/test/unit/insertion.js +23 -0
  268. data/test/unit/multi-window.js +212 -0
  269. data/test/unit/nu.validator.js +34 -0
  270. data/test/unit/onload.js +90 -0
  271. data/test/unit/parser.js +122 -0
  272. data/test/unit/prototypecompat.js +22 -0
  273. data/test/unit/proxy.js +6 -0
  274. data/test/unit/scope.js +209 -0
  275. data/test/unit/timer.js +115 -0
  276. data/test/unit/window.js +57 -0
  277. data/test/x.js +1 -0
  278. data/test/y.js +1 -0
  279. metadata +367 -0
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @author thatcher
3
+ */
4
+
5
+ (function(Q){
6
+
7
+ Q.describe('Window Timer',{
8
+
9
+ before:function(){
10
+ //setup
11
+ },
12
+ after:function(){
13
+ //tear down
14
+ }
15
+
16
+ }).should('provide the required w3c interfaces', function(){
17
+
18
+ expect(4);
19
+ ok(setTimeout, 'setTimeout');
20
+ ok(setInterval, 'setInterval');
21
+ ok(clearTimeout, 'clearTimeout');
22
+ ok(clearInterval, 'clearInterval');
23
+
24
+ });
25
+
26
+ })(QUnit);
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @author thatcher
3
+ */
4
+ var global_scope=this;
5
+
6
+ (function(Q){
7
+
8
+ Q.describe('Window Basic Properties',{
9
+
10
+ before:function(){
11
+ //setup
12
+ },
13
+ after:function(){
14
+ //tear down
15
+ }
16
+
17
+ }).should('provide the required w3c interfaces', function(){
18
+
19
+ expect(19);
20
+ ok(window, 'window');
21
+ ok(self, 'self');
22
+ ok(top, 'top');
23
+ ok(parent, 'parent');
24
+ ok(window.toString(), '[object Window]');
25
+
26
+ //these values are usually the empty string ''
27
+ //so we just verify the property is available
28
+ ok('name' in window, 'name');
29
+ ok('status' in window, 'status');
30
+ ok('closed' in window, 'closed');
31
+ ok('defaultStatus' in window, 'defaultStatus');
32
+ ok('length' in window, 'length');
33
+ ok('opener' in window, 'opener');
34
+
35
+ ok(frames, 'frames');
36
+ ok(open, 'open');
37
+ ok(close, 'close');
38
+ ok(innerHeight, 'innerHeight');
39
+ ok(outerHeight, 'outerHeight');
40
+ ok(outerWidth, 'outerWidth');
41
+ ok(screenX, 'screenX');
42
+ ok(screenY, 'screenY');
43
+
44
+
45
+ }).should('have the expected values', function(){
46
+
47
+ equals( window, global_scope, 'window is the global scope "this"');
48
+ equals( window, self, 'self is an alias for window');
49
+ equals( window, top, 'top is an alias for window when the window is not in a frame');
50
+
51
+ });
52
+
53
+ })(QUnit);
@@ -0,0 +1,47 @@
1
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
5
+ <title>Envjs Window Spec</title>
6
+ <link rel="stylesheet" media="screen" href="../qunit.css"/>
7
+ <link rel="stylesheet" media="screen" href="../envjs.spec.css"/>
8
+ <link rel="stylesheet" media="screen" href="http://www.envjs.com/css/blueprint/screen.css"/>
9
+ <link rel="stylesheet" media="screen" href="http://www.envjs.com/css/site.css"/>
10
+ <script type='text/javascript' src='../qunit.js'></script>
11
+ <script type='text/javascript' src='../qunit.bdd.js'></script>
12
+
13
+ <!-- specs for this general api 'module' -->
14
+ <script type='text/javascript' src='css.js'></script>
15
+ <script type='text/javascript' src='dialog.js'></script>
16
+ <script type='text/javascript' src='document.js'></script>
17
+ <script type='text/javascript' src='event.js'></script>
18
+ <script type='text/javascript' src='history.js'></script>
19
+ <script type='text/javascript' src='location.js'></script>
20
+ <script type='text/javascript' src='navigator.js'></script>
21
+ <script type='text/javascript' src='window.js'></script>
22
+ <script type='text/javascript' src='timer.js'></script>
23
+ </head>
24
+ <body class='container'>
25
+ <h2 id="qunit-banner">
26
+ <img id="envjs-icon"
27
+ src="../../fixtures/images/icon-blue.png"
28
+ height='40'/>
29
+ <span id="spec-title">Envjs Window Spec</span>
30
+ </h2>
31
+ <h2 id="qunit-userAgent"></h2>
32
+ <div id='qunit-testrunner-toolbar'></div>
33
+ <div id='qunit-test-summary'>
34
+ <ol id='qunit-tests'></ol>
35
+ </div>
36
+ <div id="qunit-main" style="display:none;">
37
+ <!--
38
+ Test HTML here:
39
+
40
+ not required to be in here but it makes it convenient
41
+ by convention to avoid having to look at the html
42
+ artifacts the test may require or have generated as
43
+ a side effect.
44
+ -->
45
+ </div>
46
+ </body>
47
+ </html>
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @author thatcher
3
+ */
4
+
5
+ (function(Q){
6
+
7
+ Q.describe('Another TEMPLATE Spec',{
8
+ before:function(){
9
+ //setup
10
+ },
11
+ after:function(){
12
+ //tear down
13
+ }
14
+
15
+ }).should('do something', function(){
16
+
17
+ expect(1);
18
+ ok(true, 'good job');
19
+
20
+ }).should('do something else', function(){
21
+
22
+ expect(1);
23
+ ok(true, 'good job');
24
+
25
+ }).pending('should do something new soon', function(){
26
+
27
+ expect(1);
28
+ ok(false, 'todo');
29
+ });
30
+
31
+ })(QUnit);
data/test/test.js ADDED
@@ -0,0 +1,10 @@
1
+ whichJarFile = arguments[0];
2
+ whichTestFile = arguments[1];
3
+
4
+ multiwindow = !(whichJarFile == "rhino");
5
+ whichInterpreter = whichJarFile + " interpreter jar";
6
+
7
+ load("dist/env.rhino.js");
8
+ load("test/" + whichTestFile + ".js");
9
+
10
+ Envjs.wait();
data/test/unit/dom.js ADDED
@@ -0,0 +1,44 @@
1
+ // dependencies for the tests
2
+ $w = { }
3
+ $env = { debug: function() {} }
4
+ $openingWindow = $parentWindow = $initTop = null;
5
+ this.options = this.options || {}
6
+
7
+ load("src/window/window.js", "src/dom/node.js");
8
+
9
+ debugger;
10
+ module("dom");
11
+
12
+ test("Basic requirements", function() {
13
+ expect(5);
14
+ ok( Array.prototype.push, "Array.push()" );
15
+ ok( Function.prototype.apply, "Function.apply()" );
16
+ ok( document.getElementById, "getElementById" );
17
+ ok( document.getElementsByTagName, "getElementsByTagName" );
18
+ ok( RegExp, "RegExp" );
19
+ });
20
+
21
+
22
+ test("document.getElementById", function() {
23
+ expect(14);
24
+ try{ok (document.getElementById('body').id == "body", "Can get Element by id, expected id='body'");}catch(e){print(e);}
25
+ try{ok (document.getElementById('header').id == "header", "Can get Element by id, expected id='header'");}catch(e){print(e);}
26
+ try{ok (document.getElementById('banner').id == "banner", "Can get Element by id, expected id='banner'");}catch(e){print(e);}
27
+ try{ok (document.getElementById('userAgent').id == "userAgent", "Can get Element by id, expected id='userAgent'");}catch(e){print(e);}
28
+ try{ok (document.getElementById('nothiddendiv').id == "nothiddendiv", "Can get Element by id, expected id='nothiddendiv'");}catch(e){print(e);}
29
+ try{ok (document.getElementById('nothiddendivchild').id == "nothiddendivchild", "Can get Element by id, expected id='nothiddendivchild'");}catch(e){print(e);}
30
+ try{ok (document.getElementById('dl').id == "dl", "Can get Element by id, expected id='dl'");}catch(e){print(e);}
31
+ try{ok (document.getElementById('main').id == "main", "Can get Element by id, expected id='main'");}catch(e){print(e);}
32
+ try{ok (document.getElementById('firstp').id == "firstp", "Can get Element by id, expected id='firstp");}catch(e){print(e);}
33
+ try{ok (document.getElementById('simon1').id == "simon1", "Can get Element by id, expected id='simon1'");}catch(e){print(e);}
34
+ try{ok (document.getElementById('ap').id == "ap", "Can get Element by id, expected id='ap'");}catch(e){print(e);}
35
+ try{ok (document.getElementById('google').id == "google", "Can get Element by id, expected id='google'");}catch(e){print(e);}
36
+ try{ok (document.getElementById('groups').id == "groups", "Can get Element by id, expected id='groups'");}catch(e){print(e);}
37
+ try{ok (document.getElementById('台北Táiběi').id == "台北Táiběi", "Can get Element by UTF-8 id, expected id='台北Táiběi'");}catch(e){print(e);}
38
+ });
39
+
40
+ test("element.getElementsByTagName", function() {
41
+ expect(1);
42
+ var body = document.getElementById('body');
43
+ try{ok (body.getElementsByTagName('h1').length == 1, "Can get NodeList length : Expected 1 , Got " + body.getElementsByTagName('h1').length);}catch(e){print(e);}
44
+ });
@@ -0,0 +1,92 @@
1
+ module("elementmembers");
2
+
3
+ // We ought to have test coverage for all members of all DOM objects, but
4
+ // until then, add test cases here for members as they are created
5
+
6
+ test("setting textarea content", function() {
7
+ expect(2);
8
+
9
+ var textarea = document.createElement('textarea');
10
+
11
+ try { textarea.value = 'textarea-value';
12
+ ok(textarea.value == 'textarea-value',
13
+ "textarea.value= sets the value correctly");
14
+ }catch(e){print(e);}
15
+
16
+ try { textarea.innerText = 'textarea-innerText';
17
+ ok(textarea.innerText == 'textarea-innerText',
18
+ "textarea.innerText= sets the value correctly");
19
+ }catch(e){print(e);}
20
+ });
21
+
22
+ test("getting textarea content", function() {
23
+ expect(2);
24
+
25
+ var textarea = document.createElement('textarea');
26
+ var text = document.createTextNode('text-area-content');
27
+ textarea.appendChild(text);
28
+
29
+ try { ok(textarea.value == 'text-area-content',
30
+ "textarea.value returns the correct content, as per http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-24874179");
31
+ }catch(e){print(e);}
32
+
33
+ try { ok(textarea.innerText == 'text-area-content',
34
+ "textarea.innerText returns the correct content");
35
+ }catch(e){print(e);}
36
+ });
37
+
38
+ test("attributes common to all HTML elements", function() {
39
+ expect(4);
40
+
41
+ // tests for .innerText
42
+ var mtch = document.getElementById('dl').innerText.match(
43
+ /^\s+See this blog entry for more information.\s+Here are/);
44
+ try{ ok(mtch && mtch.length > 0,
45
+ "dl.innerText returns the correct content");
46
+ }catch(e){print(e);}
47
+
48
+ mtch = document.getElementById('sndp').innerText.match(/^Everything insid/);
49
+ try{ ok(mtch && mtch.length > 0,
50
+ "p.innerText returns the correct content");
51
+ }catch(e){print(e);}
52
+
53
+ try{ ok(document.getElementById('sndp').innerText = "test text" || true,
54
+ "p.innerText= operates without exception");
55
+ }catch(e){print(e);}
56
+
57
+ try{ ok(document.getElementById('sndp').innerText == "test text",
58
+ "p.innerText= changes content of element");
59
+ }catch(e){print(e);}
60
+ });
61
+
62
+ test("select element", function() {
63
+ expect(14);
64
+
65
+ var select = document.getElementById('select1');
66
+ equals("select-one", select.type, "Select field's type is select-one by default");
67
+
68
+ select = document.getElementById('test_value');
69
+ equals("optionvalue", select.value, "Select field returns its selected option's value as its value");
70
+
71
+ // if option2 is selected, unselect option1 (and update select.value)
72
+ select = document.getElementById('test_selecting');
73
+ select.options[2].selected = true;
74
+ ok(select.options[2].selected, "Select's option should be selected");
75
+ ok(!select.options[1].selected, "Previously selected option should be automatically unselected");
76
+ equals("2", select.value, "Select's value should be updated");
77
+
78
+ // if option2 is unselected, then select first option on the list (and update select.value)
79
+ select.options[2].selected = false;
80
+ ok(!select.options[2].selected, "Select's option should be unselected");
81
+ ok(!select.options[1].selected, "Previously selected option should stay unselected");
82
+ ok(select.options[0].selected, "First option in the select should be selected");
83
+ equals("0", select.value, "Select's value should be updated");
84
+
85
+ // update select's value and options when selectedIndex is changed
86
+ equals(0, select.selectedIndex, "Select's selectedIndex should return the index of selected option");
87
+ select.selectedIndex = 2;
88
+ equals(2, select.selectedIndex, "Select's selectedIndex should be updated");
89
+ equals("2", select.value, "Changing selectedIndex should update select's value");
90
+ ok(!select.options[0].selected, "Changing selectedIndex should unselect currently selected option");
91
+ ok(select.options[2].selected, "Changing selectedIndex should select option at given index");
92
+ });
@@ -0,0 +1,195 @@
1
+ /*
2
+ * This file is a component of env.js,
3
+ * http://github.com/gleneivey/env-js/commits/master/README
4
+ * a Pure JavaScript Browser Environment
5
+ * Copyright 2009 John Resig, licensed under the MIT License
6
+ * http://www.opensource.org/licenses/mit-license.php
7
+ */
8
+
9
+
10
+ module("events");
11
+
12
+ // This file is for tests of general event dispatching, propagation, and
13
+ // handling functionality. In keeping with the general non-exhaustive
14
+ // approach of env.js's unit tests, each behavior is checked for one
15
+ // relevant type of event in one relevant context (page structure, etc.).
16
+
17
+ // These tests rely on the content of ../html/events.html and of the
18
+ // <iframe id='eventsFrame'> tag in ../index.html.
19
+
20
+ // These tests are order-dependent. If you alter the order or add new tests
21
+ // in the middle, the expected values of eventFrameLoaded and
22
+ // eventFrameClicked may well change (perhaps requiring extra parameters
23
+ // to the *Checks convenience functions).
24
+
25
+
26
+ var __click__ = function(element){
27
+ var event = new Event({
28
+ target:element,
29
+ currentTarget:element
30
+ });
31
+ event.initEvent("click");
32
+ element.dispatchEvent(event);
33
+ }
34
+
35
+ function loadChecks(tag, loadCount, imgCount, unloadCount){
36
+ expect(5);
37
+
38
+ var eCounters = window.top.eCounters;
39
+ try{ ok( eCounters["window onload"] == loadCount &&
40
+ eCounters["body onload"] == loadCount,
41
+ tag + ": Onload Events recorded");
42
+ }catch(e){print(e);}
43
+
44
+ try{ ok( eCounters["img onload"] == imgCount,
45
+ tag + ": Img-tag onload event(s) recorded separately");
46
+ }catch(e){print(e);}
47
+
48
+ try{ ok( eCounters["window onunload"] == unloadCount &&
49
+ eCounters["body onunload"] == unloadCount,
50
+ tag + ": Onunload events recorded");
51
+ }catch(e){print(e);}
52
+
53
+ try{ ok( eCounters["body onclick"] == 0 &&
54
+ eCounters["h1 onclick"] == 0 &&
55
+ eCounters["h2 onclick"] == 0 &&
56
+ eCounters["div onclick"] == 0 &&
57
+ eCounters["table onclick"] == 0 &&
58
+ eCounters["tbody onclick"] == 0 &&
59
+ eCounters["tr onclick"] == 0 &&
60
+ eCounters["td onclick"] == 0 &&
61
+ eCounters["ul onclick"] == 0 &&
62
+ eCounters["li onclick"] == 0 &&
63
+ eCounters["p onclick"] == 0 &&
64
+ eCounters["b onclick"] == 0 &&
65
+ eCounters["i onclick"] == 0 &&
66
+ eCounters["a onclick"] == 0 &&
67
+ eCounters["img onclick"] == 0,
68
+ tag + ": Onload events recorded once.");
69
+ }catch(e){print(e);}
70
+
71
+ try{ ok( eventFrameLoaded == loadCount && eventFrameClicked == 0,
72
+ tag + ": " + loadCount + " iframe events recorded on page load.");
73
+ }catch(e){print(e);}
74
+ }
75
+
76
+
77
+ test("Check that events do/don't occur on document load", function() {
78
+ // eCounters already initialized by code in ../html/events.html
79
+ loadChecks("Load", 1, 1, 0);
80
+ });
81
+
82
+ test("Check that events do/don't occur on manual iframe reload", function() {
83
+ document.getElementById('eventsFrame').src = "html/events.html";
84
+ loadChecks("Reload", 2, 2, 1);
85
+ });
86
+
87
+ test("Check that an event which should NOT bubble actually does not",
88
+ function() {
89
+ var img = document.getElementById('eventsFrame').contentDocument.
90
+ getElementById('theIMG').src = "missing.png";
91
+ loadChecks("Img Load", 2, 3, 1);
92
+
93
+ // note: if img-onload had bubbled up, previous tests probably would
94
+ // have failed (too large body-onload counts), too. So this test
95
+ // just ensures that operation is correct even when only part of
96
+ // page is reloading.
97
+ });
98
+
99
+
100
+
101
+ function clickChecks(tag, upperCount, lowerCount){
102
+ expect(5);
103
+
104
+ var eCounters = window.top.eCounters;
105
+ try{ ok( eCounters["window onload"] == 0 &&
106
+ eCounters["window onunload"] == 0 &&
107
+ eCounters["body onload"] == 0 &&
108
+ eCounters["body onunload"] == 0 &&
109
+ eCounters["img onload"] == 0,
110
+ tag + ": Onload events not triggered by click");
111
+ }catch(e){print(e);}
112
+
113
+ var special = (upperCount == lowerCount) ? "" : " not";
114
+ try{ ok( eCounters["ul onclick"] == lowerCount &&
115
+ eCounters["li onclick"] == lowerCount &&
116
+ eCounters["p onclick"] == lowerCount &&
117
+ eCounters["b onclick"] == lowerCount &&
118
+ eCounters["i onclick"] == lowerCount &&
119
+ eCounters["a onclick"] == lowerCount &&
120
+ eCounters["img onclick"] == lowerCount,
121
+ tag + ": Click event did" + special + " bubble through inner elements");
122
+ }catch(e){print(e);}
123
+
124
+ try{ ok( eCounters["body onclick"] == upperCount &&
125
+ eCounters["div onclick"] == upperCount &&
126
+ eCounters["table onclick"] == upperCount &&
127
+ eCounters["tbody onclick"] == upperCount &&
128
+ eCounters["tr onclick"] == upperCount &&
129
+ eCounters["td onclick"] == upperCount,
130
+ tag + ": Click event bubbled through outer elements");
131
+ }catch(e){print(e);}
132
+
133
+ try{ ok( eCounters["h1 onclick"] == 0 &&
134
+ eCounters["h2 onclick"] == 0,
135
+ tag + ": No click events for Hx elements");
136
+ }catch(e){print(e);}
137
+
138
+
139
+ try{ ok( eventFrameLoaded == 2 && eventFrameClicked == 0,
140
+ tag + ": Iframe event counts unchanged");
141
+ }catch(e){print(e);}
142
+ }
143
+
144
+ test("Check that an event which should bubble actually does", function() {
145
+ // clear in-iframe event counters to zero
146
+ window.top.eCounters = {};
147
+ fWin = document.getElementById('eventsFrame').contentWindow;
148
+ fWin.initECounters(window.top.eCounters);
149
+
150
+ // simulate a "click" user action
151
+ var img = document.getElementById('eventsFrame').contentDocument.
152
+ getElementById('theIMG');
153
+ __click__(img);
154
+
155
+ clickChecks("Click img", 1, 1);
156
+ });
157
+
158
+ test("Bubbling event ONLY bubbles 'up'", function() {
159
+ // simulate a "click" user action
160
+ var td = document.getElementById('eventsFrame').contentDocument.
161
+ getElementById('theTD');
162
+ __click__(td);
163
+
164
+ clickChecks("Click td", 2, 1);
165
+ });
166
+
167
+
168
+ test("Check that events can be set with addEventListener(), and bubble",
169
+ function() {
170
+ expect(4);
171
+
172
+ var img = document.getElementById('eventsFrame').contentDocument.
173
+ getElementById('theIMG');
174
+
175
+ // add handlers
176
+ addHdlr = function(id) {
177
+ var elem = document.getElementById('eventsFrame').contentDocument.
178
+ getElementById(id).addEventListener('click', function(event){
179
+ try{
180
+ ok( event.target === img && ( ( this === window ) || ( this.window === window ) ),
181
+ "Scope: 'this' refers to the window '" + window + "'");
182
+ }catch(e){print(e);}
183
+ });
184
+ };
185
+
186
+ // a few objects that the <img 'theImG'>.click event will bubble up through
187
+ addHdlr("theIMG");
188
+ addHdlr("theA");
189
+ addHdlr("theP");
190
+ addHdlr("theLI");
191
+
192
+ // simulate user action
193
+ __click__(img);
194
+ });
195
+