envjs19 0.3.8.20101029121421
Sign up to get free protection for your applications and to get access to all the features.
- data/.jslintrbrc +30 -0
- data/.project +17 -0
- data/CHANGELOG.rdoc +57 -0
- data/DTD/xhtml-lat1.ent +196 -0
- data/DTD/xhtml-special.ent +80 -0
- data/DTD/xhtml-symbol.ent +237 -0
- data/DTD/xhtml.soc +14 -0
- data/DTD/xhtml1-frameset.dtd +1235 -0
- data/DTD/xhtml1-strict.dtd +978 -0
- data/DTD/xhtml1-transitional.dtd +1201 -0
- data/DTD/xhtml1.dcl +192 -0
- data/Makefile +7 -0
- data/Manifest.txt +280 -0
- data/README.rdoc +65 -0
- data/Rakefile +196 -0
- data/Wakefile +11 -0
- data/bin/envjsrb +257 -0
- data/build.properties +9 -0
- data/build.xml +247 -0
- data/gm/jquery.js +6002 -0
- data/gm/mainx.js +2648 -0
- data/gm/sensx.js +135 -0
- data/gm/t.js +6 -0
- data/gm/x.html +76 -0
- data/htmlparser/BrowserTreeBuilder.java +456 -0
- data/htmlparser/README +34 -0
- data/htmlparser/build.sh +38 -0
- data/jsl/jsl +0 -0
- data/jsl/jsl.default.conf +129 -0
- data/jsl/jsl.exe +0 -0
- data/lib/envjs.rb +35 -0
- data/lib/envjs/event_loop.js +206 -0
- data/lib/envjs/net.rb +3 -0
- data/lib/envjs/net/cgi.rb +94 -0
- data/lib/envjs/net/file.rb +69 -0
- data/lib/envjs/options.rb +11 -0
- data/lib/envjs/runtime.rb +346 -0
- data/lib/envjs/tempfile.rb +24 -0
- data/licenses/GPL-LICENSE.txt +278 -0
- data/licenses/MIT-LICENSE.txt +20 -0
- data/src/base64.js +80 -0
- data/src/build.js +6 -0
- data/src/cruft/bad.html +24 -0
- data/src/cruft/dom.js +606 -0
- data/src/cruft/element.js +297 -0
- data/src/cruft/good.html +30 -0
- data/src/cruft/good.js +32 -0
- data/src/cruft/internal.js +81 -0
- data/src/cruft/parser.js +458 -0
- data/src/css/properties.js +293 -0
- data/src/css/rule.js +22 -0
- data/src/css/sizzle.js +717 -0
- data/src/css/stylesheet.js +52 -0
- data/src/dom/attr.js +55 -0
- data/src/dom/cdatasection.js +31 -0
- data/src/dom/characterdata.js +119 -0
- data/src/dom/comment.js +30 -0
- data/src/dom/doctype.js +9 -0
- data/src/dom/document.js +1023 -0
- data/src/dom/dom.js +134 -0
- data/src/dom/element.js +217 -0
- data/src/dom/entities.js +273 -0
- data/src/dom/exception.js +28 -0
- data/src/dom/fragment.js +37 -0
- data/src/dom/implementation.js +140 -0
- data/src/dom/instruction.js +51 -0
- data/src/dom/namednodemap.js +374 -0
- data/src/dom/namespace.js +50 -0
- data/src/dom/node.js +618 -0
- data/src/dom/nodelist.js +195 -0
- data/src/dom/parser.js +1207 -0
- data/src/dom/text.js +73 -0
- data/src/event/event.js +47 -0
- data/src/event/mouseevent.js +4 -0
- data/src/event/uievent.js +8 -0
- data/src/html/a.js +110 -0
- data/src/html/anchor.js +80 -0
- data/src/html/area.js +57 -0
- data/src/html/base.js +26 -0
- data/src/html/blockquote-q.js +19 -0
- data/src/html/body.js +19 -0
- data/src/html/button.js +21 -0
- data/src/html/canvas.js +14 -0
- data/src/html/col-colgroup.js +49 -0
- data/src/html/collection.js +72 -0
- data/src/html/cookie.js +153 -0
- data/src/html/del-ins.js +25 -0
- data/src/html/div.js +28 -0
- data/src/html/document.js +364 -0
- data/src/html/element.js +382 -0
- data/src/html/fieldset.js +19 -0
- data/src/html/form.js +484 -0
- data/src/html/frame.js +89 -0
- data/src/html/frameset.js +25 -0
- data/src/html/head.js +44 -0
- data/src/html/html.js +0 -0
- data/src/html/htmlparser.js +340 -0
- data/src/html/iframe.js +26 -0
- data/src/html/image.js +0 -0
- data/src/html/img.js +62 -0
- data/src/html/input-elements.js +307 -0
- data/src/html/input.js +65 -0
- data/src/html/label.js +26 -0
- data/src/html/legend.js +19 -0
- data/src/html/link.js +82 -0
- data/src/html/map.js +22 -0
- data/src/html/meta.js +37 -0
- data/src/html/object.js +89 -0
- data/src/html/optgroup.js +25 -0
- data/src/html/option.js +103 -0
- data/src/html/param.js +38 -0
- data/src/html/script.js +122 -0
- data/src/html/select.js +132 -0
- data/src/html/style.js +31 -0
- data/src/html/table.js +199 -0
- data/src/html/tbody-thead-tfoot.js +92 -0
- data/src/html/td-th.js +18 -0
- data/src/html/textarea.js +31 -0
- data/src/html/title.js +20 -0
- data/src/html/tr.js +114 -0
- data/src/intro.js +141 -0
- data/src/outro.js +70 -0
- data/src/parser/html5.detailed.js +10762 -0
- data/src/parser/html5.min.js +503 -0
- data/src/parser/html5.pretty.js +10815 -0
- data/src/parser/intro.js +42 -0
- data/src/parser/outro.js +9 -0
- data/src/platform/core.js +323 -0
- data/src/platform/johnson.js +484 -0
- data/src/platform/rhino.js +327 -0
- data/src/platform/static/intro.js +41 -0
- data/src/platform/static/outro.js +30 -0
- data/src/profile/aop.js +238 -0
- data/src/profile/profile.js +402 -0
- data/src/serializer/xml.js +21 -0
- data/src/svg/animatedstring.js +25 -0
- data/src/svg/document.js +25 -0
- data/src/svg/element.js +22 -0
- data/src/svg/locatable.js +17 -0
- data/src/svg/rect.js +18 -0
- data/src/svg/rectelement.js +24 -0
- data/src/svg/stylable.js +49 -0
- data/src/svg/svgelement.js +22 -0
- data/src/svg/transformable.js +15 -0
- data/src/window/css.js +15 -0
- data/src/window/dialog.js +16 -0
- data/src/window/document.js +28 -0
- data/src/window/event.js +265 -0
- data/src/window/history.js +62 -0
- data/src/window/location.js +156 -0
- data/src/window/navigator.js +48 -0
- data/src/window/screen.js +53 -0
- data/src/window/timer.js +21 -0
- data/src/window/window.js +284 -0
- data/src/window/xhr.js +135 -0
- data/src/xpath/expression.js +49 -0
- data/src/xpath/implementation.js +2505 -0
- data/src/xpath/result.js +67 -0
- data/src/xpath/util.js +551 -0
- data/src/xpath/xmltoken.js +149 -0
- data/src/xslt/COPYING +34 -0
- data/src/xslt/ajaxslt-0.8.1/AUTHORS +1 -0
- data/src/xslt/ajaxslt-0.8.1/ChangeLog +136 -0
- data/src/xslt/ajaxslt-0.8.1/Makefile +49 -0
- data/src/xslt/ajaxslt-0.8.1/README +102 -0
- data/src/xslt/ajaxslt-0.8.1/TODO +15 -0
- data/src/xslt/ajaxslt-0.8.1/dom.js +566 -0
- data/src/xslt/ajaxslt-0.8.1/dom_unittest.html +24 -0
- data/src/xslt/ajaxslt-0.8.1/dom_unittest.js +131 -0
- data/src/xslt/ajaxslt-0.8.1/simplelog.js +79 -0
- data/src/xslt/ajaxslt-0.8.1/test/xpath.html +18 -0
- data/src/xslt/ajaxslt-0.8.1/test/xpath_script.js +45 -0
- data/src/xslt/ajaxslt-0.8.1/test/xslt.html +58 -0
- data/src/xslt/ajaxslt-0.8.1/test/xslt_script.js +33 -0
- data/src/xslt/ajaxslt-0.8.1/unittestsuite.html +26 -0
- data/src/xslt/ajaxslt-0.8.1/xmltoken.js +149 -0
- data/src/xslt/ajaxslt-0.8.1/xmltoken_unittest.html +18 -0
- data/src/xslt/ajaxslt-0.8.1/xmltoken_unittest.js +811 -0
- data/src/xslt/ajaxslt-0.8.1/xpath_unittest.html +39 -0
- data/src/xslt/ajaxslt-0.8.1/xpath_unittest.js +557 -0
- data/src/xslt/ajaxslt-0.8.1/xpathdebug.js +234 -0
- data/src/xslt/ajaxslt-0.8.1/xslt_unittest.html +138 -0
- data/src/xslt/ajaxslt-0.8.1/xslt_unittest.js +68 -0
- data/src/xslt/implementation.js +625 -0
- data/src/xslt/processor.js +37 -0
- data/src/xslt/util.js +449 -0
- data/test/base64.js +80 -0
- data/test/call-load-test.js +15 -0
- data/test/data.js +45 -0
- data/test/debug.js +53 -0
- data/test/firebug/errorIcon.png +0 -0
- data/test/firebug/firebug.css +209 -0
- data/test/firebug/firebug.html +23 -0
- data/test/firebug/firebug.js +672 -0
- data/test/firebug/firebugx.js +10 -0
- data/test/firebug/infoIcon.png +0 -0
- data/test/firebug/warningIcon.png +0 -0
- data/test/fixtures/html/events.html +171 -0
- data/test/fixtures/html/iframe1.html +46 -0
- data/test/fixtures/html/iframe1a.html +46 -0
- data/test/fixtures/html/iframe2.html +45 -0
- data/test/fixtures/html/iframe3.html +28 -0
- data/test/fixtures/html/iframeN.html +57 -0
- data/test/fixtures/html/malformed.html +181 -0
- data/test/fixtures/html/scope.html +81 -0
- data/test/fixtures/html/trivial.html +19 -0
- data/test/fixtures/html/with_js.html +26 -0
- data/test/fixtures/images/icon-blue.png +0 -0
- data/test/fixtures/js/external_script.js +1 -0
- data/test/fixtures/js/script.js +1 -0
- data/test/fixtures/js/script_error.js +2 -0
- data/test/foo.html +8 -0
- data/test/foo.js +40 -0
- data/test/html/events.html +171 -0
- data/test/html/iframe1.html +46 -0
- data/test/html/iframe1a.html +46 -0
- data/test/html/iframe2.html +45 -0
- data/test/html/iframe3.html +30 -0
- data/test/html/iframeN.html +57 -0
- data/test/html/malformed.html +181 -0
- data/test/html/scope.html +87 -0
- data/test/html/script.js +1 -0
- data/test/html/trivial.html +19 -0
- data/test/html/with_js.html +26 -0
- data/test/index.html +328 -0
- data/test/java-prototype.js +9 -0
- data/test/jquery.js +6002 -0
- data/test/primary-tests.js +26 -0
- data/test/prototype-test.js +13 -0
- data/test/qunit.js +61 -0
- data/test/qunit/qunit/qunit.css +17 -0
- data/test/qunit/qunit/qunit.js +997 -0
- data/test/scope.html +19 -0
- data/test/scope.rb +24 -0
- data/test/smp/dmathieu/index.html +8 -0
- data/test/specs/dist/env.spec.js +1534 -0
- data/test/specs/envjs.spec.css +46 -0
- data/test/specs/parser/html.js +31 -0
- data/test/specs/parser/spec.html +40 -0
- data/test/specs/parser/xml.js +31 -0
- data/test/specs/qunit.bdd.js +210 -0
- data/test/specs/qunit.css +17 -0
- data/test/specs/qunit.js +997 -0
- data/test/specs/template/spec-0.js +31 -0
- data/test/specs/template/spec-1.js +31 -0
- data/test/specs/template/spec.html +40 -0
- data/test/specs/window/css.js +23 -0
- data/test/specs/window/dialog.js +25 -0
- data/test/specs/window/document.js +23 -0
- data/test/specs/window/event.js +25 -0
- data/test/specs/window/history.js +34 -0
- data/test/specs/window/location.js +34 -0
- data/test/specs/window/navigator.js +71 -0
- data/test/specs/window/screen.js +42 -0
- data/test/specs/window/spec.html +48 -0
- data/test/specs/window/timer.js +26 -0
- data/test/specs/window/window.js +53 -0
- data/test/specs/xhr/spec.html +47 -0
- data/test/specs/xhr/xhr.js +31 -0
- data/test/test.js +10 -0
- data/test/unit/dom.js +44 -0
- data/test/unit/elementmembers.js +92 -0
- data/test/unit/events.js +195 -0
- data/test/unit/fixtures/external_script.js +1 -0
- data/test/unit/form.js +40 -0
- data/test/unit/iframe.js +234 -0
- data/test/unit/insertion.js +23 -0
- data/test/unit/multi-window.js +212 -0
- data/test/unit/nu.validator.js +34 -0
- data/test/unit/onload.js +90 -0
- data/test/unit/parser.js +122 -0
- data/test/unit/prototypecompat.js +22 -0
- data/test/unit/proxy.js +6 -0
- data/test/unit/scope.js +209 -0
- data/test/unit/timer.js +115 -0
- data/test/unit/window.js +57 -0
- data/test/x.js +1 -0
- data/test/y.js +1 -0
- metadata +367 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
/**
|
2
|
+
* @author thatcher
|
3
|
+
*/
|
4
|
+
|
5
|
+
load('dist/env.rhino.js');
|
6
|
+
|
7
|
+
window.location = 'test/html/malformed.html';
|
8
|
+
|
9
|
+
|
10
|
+
var fixture = document.xml,
|
11
|
+
testhtml = '<!DOCTYPE html><html><head/><body><script>document.write("<a>efg");</script><p>abc</body></html>',
|
12
|
+
testfragment = '<div>this is a<strong>pig<div>oink oink!',
|
13
|
+
success = function(){
|
14
|
+
print(doc.xml);
|
15
|
+
};
|
16
|
+
|
17
|
+
var doc;
|
18
|
+
//Envjs.logLevel = Envjs.DEBUG;
|
19
|
+
doc = new DOMParser().parseFromString(testhtml);
|
20
|
+
print(doc.xml);
|
21
|
+
|
22
|
+
|
23
|
+
doc.body.innerHTML = testfragment;
|
24
|
+
print(doc.xml);
|
25
|
+
|
26
|
+
|
27
|
+
/*
|
28
|
+
var start = new Date().getTime();
|
29
|
+
for(var i=0;i<1000;i++){
|
30
|
+
parseHtmlDocument(trivial, document, null, null);
|
31
|
+
}
|
32
|
+
var stop = new Date().getTime();
|
33
|
+
print("1000 parses "+(stop-start));
|
34
|
+
*/
|
data/test/unit/onload.js
ADDED
@@ -0,0 +1,90 @@
|
|
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("onload-events");
|
11
|
+
|
12
|
+
// depends on <script> blocks and elements in test/index.html
|
13
|
+
test("Execution of onload events in top-level document",
|
14
|
+
function() {
|
15
|
+
|
16
|
+
// top-level window-onload works, or test framework wouldn't run.....
|
17
|
+
expect(11);
|
18
|
+
|
19
|
+
var mtch = document.getElementById('pCreatedByBodyOnload').innerHTML.
|
20
|
+
match(/dynamically-generated paragraph/);
|
21
|
+
try{ ok(mtch && mtch.length > 0,
|
22
|
+
"Got confirmation that body-onload handler executed");
|
23
|
+
}catch(e){print(e);}
|
24
|
+
|
25
|
+
mtch = document.getElementById('pCreatedByIframeOnload').innerHTML.
|
26
|
+
match(/iframe-onload event handler/);
|
27
|
+
try{ ok(mtch && mtch.length > 0,
|
28
|
+
"Got confirmation that iframe-onload handler executed");
|
29
|
+
}catch(e){print(e);}
|
30
|
+
|
31
|
+
var iframe = document.getElementById('loadediframe');
|
32
|
+
var aCounter = 0;
|
33
|
+
iframe.onload = function(){
|
34
|
+
aCounter++;
|
35
|
+
};
|
36
|
+
iframe.src = "html/iframe1.html";
|
37
|
+
try{ ok(aCounter == 1,
|
38
|
+
"iframe-onload handler executes when iframe.src assigned");
|
39
|
+
}catch(e){print(e);}
|
40
|
+
|
41
|
+
mtch = document.getElementById('sCreatedByLinkOnload').innerHTML.
|
42
|
+
match(/CreatedByLinkOnloadEvent/);
|
43
|
+
try{ ok(mtch && mtch.length > 0, "link-onload handler executed");
|
44
|
+
}catch(e){print(e);}
|
45
|
+
|
46
|
+
mtch = document.getElementById('pCreatedByImgOnload').innerHTML.
|
47
|
+
match(/img-onload event handler/);
|
48
|
+
try{ ok(mtch && mtch.length > 0,
|
49
|
+
"Got confirmation that img-onload handler executed");
|
50
|
+
}catch(e){print(e);}
|
51
|
+
|
52
|
+
var img = document.getElementById('anImg');
|
53
|
+
aCounter = 10;
|
54
|
+
img.onload = function(){
|
55
|
+
aCounter++;
|
56
|
+
};
|
57
|
+
img.src = "html/img2.png";
|
58
|
+
try{ ok(aCounter == 11,
|
59
|
+
"img-onload handler executes when img.src assigned");
|
60
|
+
}catch(e){print(e);}
|
61
|
+
|
62
|
+
mtch = document.getElementById('pCreatedByScriptA').innerHTML.
|
63
|
+
match(/script event handler/);
|
64
|
+
try{ ok(mtch && mtch.length > 0,
|
65
|
+
"Got confirmation that script-onerror handler executed");
|
66
|
+
}catch(e){print(e);}
|
67
|
+
|
68
|
+
try{ ok(!document.getElementById('pCreatedByScriptB'),
|
69
|
+
"Got confirmation that script-onload handler did not execute");
|
70
|
+
}catch(e){print(e);}
|
71
|
+
|
72
|
+
mtch = document.getElementById('pCreatedByScriptD').innerHTML.
|
73
|
+
match(/script event handler/);
|
74
|
+
try{ ok(mtch && mtch.length > 0,
|
75
|
+
"Got confirmation that script-onload handler executed");
|
76
|
+
}catch(e){print(e);}
|
77
|
+
|
78
|
+
try{ ok(!document.getElementById('pCreatedByScriptC'),
|
79
|
+
"Got confirmation that script-onerror handler did not execute");
|
80
|
+
}catch(e){print(e);}
|
81
|
+
|
82
|
+
mtch = document.getElementById('pShouldntBeCreated');
|
83
|
+
try{ ok(!(mtch),
|
84
|
+
"Confirmed that script-onload handler that shouldn't execute actually didn't");
|
85
|
+
}catch(e){print(e);}
|
86
|
+
});
|
87
|
+
|
88
|
+
|
89
|
+
// still to test: onload events for: <frame>, <frameset>, image obj, layer obj
|
90
|
+
|
data/test/unit/parser.js
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
module("Html5Parser");
|
2
|
+
|
3
|
+
var should = function(msg, options){
|
4
|
+
try{
|
5
|
+
if(options.be&&options.be=='equal'){
|
6
|
+
equals(
|
7
|
+
options.expected,
|
8
|
+
options.actual,
|
9
|
+
msg
|
10
|
+
);
|
11
|
+
}else if(options.be&&options.be==='safe'){
|
12
|
+
options.test();
|
13
|
+
ok(true, msg);
|
14
|
+
}else{
|
15
|
+
ok(false, 'unknown test '+options.be);
|
16
|
+
}
|
17
|
+
}catch(e){
|
18
|
+
//no nothing
|
19
|
+
equals(true, false, options.msg||'This test failed.');
|
20
|
+
}finally{
|
21
|
+
//TODO: might as well keep score here
|
22
|
+
return this;
|
23
|
+
}
|
24
|
+
};
|
25
|
+
|
26
|
+
|
27
|
+
test("XML Standard Entities: Spot Check", function() {
|
28
|
+
|
29
|
+
expect(2);
|
30
|
+
var htmlstr =
|
31
|
+
"<div id='xmlentity' \
|
32
|
+
style='<Hello>, "W'rld"!'\
|
33
|
+
><Hello>, "W'rld"!</div>";
|
34
|
+
|
35
|
+
var doc = document.implementation.createHTMLDocument();
|
36
|
+
doc.body.innerHTML = htmlstr;
|
37
|
+
|
38
|
+
should("Replace entities at nodeValue",{
|
39
|
+
be:'equal',
|
40
|
+
actual : doc.
|
41
|
+
getElementById('xmlentity').
|
42
|
+
childNodes[0].
|
43
|
+
nodeValue,
|
44
|
+
expected : '<Hello>, "W\'rld"!'
|
45
|
+
}).
|
46
|
+
should("serialize only &, < and > for TextNode with innerHTML",{
|
47
|
+
be: 'equal',
|
48
|
+
actual : doc.
|
49
|
+
getElementById('xmlentity').
|
50
|
+
innerHTML,
|
51
|
+
expected : '<Hello>, "W\'rld"!'
|
52
|
+
});
|
53
|
+
|
54
|
+
});
|
55
|
+
|
56
|
+
test("HTML Standard Entities: Spot Check", function() {
|
57
|
+
|
58
|
+
expect(1);
|
59
|
+
var htmlstr = "<div id='htmlentity'>" & < > "+
|
60
|
+
" © ® ¥ ¶ " +
|
61
|
+
"Ê Õ æ ÷ Κ θ "+
|
62
|
+
"• … ™ ⇒ ∑ ♣ " +
|
63
|
+
"  —</div>";
|
64
|
+
|
65
|
+
var doc = document.implementation.createHTMLDocument();
|
66
|
+
doc.body.innerHTML = htmlstr;
|
67
|
+
|
68
|
+
should("serialize only &, < and > for TextNode with innerHTML",{
|
69
|
+
be:'equal',
|
70
|
+
actual:doc.
|
71
|
+
getElementById('htmlentity').
|
72
|
+
innerHTML,
|
73
|
+
expected : '" & < > '+
|
74
|
+
'\xA0 \xA9 \xAE \xA5 \xB6 '+
|
75
|
+
'\xCA \xD5 \xE6 \xF7 \u039A \u03B8 '+
|
76
|
+
'\u2022 \u2026 \u2122 \u21D2 \u2211 \u2663 '+
|
77
|
+
'\u2002 \u2014'
|
78
|
+
});
|
79
|
+
|
80
|
+
});
|
81
|
+
|
82
|
+
test("Serialization Conventions", function(){
|
83
|
+
|
84
|
+
});
|
85
|
+
|
86
|
+
test("Ugly HTML Parsing", function() {
|
87
|
+
|
88
|
+
expect(1);
|
89
|
+
|
90
|
+
var doc = document.implementation.createHTMLDocument();
|
91
|
+
doc.body.innerHTML = '<div id="pig"><p>this is a pig... 'oink! oink!'</div>';
|
92
|
+
|
93
|
+
should('correct the unclosed p tag',{
|
94
|
+
be:'equal',
|
95
|
+
actual:doc.
|
96
|
+
getElementById('pig').
|
97
|
+
xml,
|
98
|
+
expected:'<div id="pig"><p>this is a pig... \'oink! oink!\'</p></div>'
|
99
|
+
});
|
100
|
+
|
101
|
+
});
|
102
|
+
|
103
|
+
// This test is not running under Rhino so can't check if it's known failure
|
104
|
+
false && test("Really Ugly HTML Parsing", function() {
|
105
|
+
|
106
|
+
expect(1);
|
107
|
+
|
108
|
+
should('parse the document without error',{
|
109
|
+
be:'safe',
|
110
|
+
test:function(){
|
111
|
+
var doc = document.implementation.createHTMLDocument();
|
112
|
+
doc.load('html/malformed.html');
|
113
|
+
}
|
114
|
+
});
|
115
|
+
|
116
|
+
});
|
117
|
+
|
118
|
+
// Local Variables:
|
119
|
+
// espresso-indent-level:4
|
120
|
+
// c-basic-offset:4
|
121
|
+
// tab-width:4
|
122
|
+
// End:
|
@@ -0,0 +1,22 @@
|
|
1
|
+
//FYI: shipped with Rails 2.2.2
|
2
|
+
load("test/vendor/prototype-1.6.0.3.js");
|
3
|
+
|
4
|
+
module("prototypecompat");
|
5
|
+
|
6
|
+
test("$ method", function(){
|
7
|
+
expect(1);
|
8
|
+
equals($("header"), document.getElementById("header"));
|
9
|
+
});
|
10
|
+
|
11
|
+
test("$$ method", function(){
|
12
|
+
expect(1);
|
13
|
+
ok($$(".chain").length == 10, "$$ found correct number of elements");
|
14
|
+
});
|
15
|
+
|
16
|
+
// When this failing test passes, ticket #69 can be closed.
|
17
|
+
// (http://envjs.lighthouseapp.com/projects/21590-envjs/tickets/69-prototypes-down-method-is-unavailable)
|
18
|
+
//
|
19
|
+
test("down method", function(){
|
20
|
+
expect(1);
|
21
|
+
ok($('main').down('#foo') != undefined, "$('main').down('#foo') successfully found an element");
|
22
|
+
});
|
data/test/unit/proxy.js
ADDED
data/test/unit/scope.js
ADDED
@@ -0,0 +1,209 @@
|
|
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("scope");
|
11
|
+
|
12
|
+
|
13
|
+
// 'window.js' is responsible for verifying that the JS interpreter's scope
|
14
|
+
// behaves correctly for code in top-level (first to load) document. Most
|
15
|
+
// of the tests in 'frame.js' will fail if the global/window object and
|
16
|
+
// scoping in (i)frames isn't distinct from that of the main document.
|
17
|
+
// The tests here check the scoping of variables and code loaded in
|
18
|
+
// event handlers (page-global and attribute-assigned), as well as
|
19
|
+
// confirming the independence of scoping in frames.
|
20
|
+
|
21
|
+
var __click__ = function(element){
|
22
|
+
var event = new Event({
|
23
|
+
target:element,
|
24
|
+
currentTarget:element
|
25
|
+
});
|
26
|
+
event.initEvent("click");
|
27
|
+
element.dispatchEvent(event);
|
28
|
+
};
|
29
|
+
|
30
|
+
// this test depends on 'iframe1.html' having been loaded into 'index.html's
|
31
|
+
// 'loadediframe' element (and not modified prior to this test's execution)
|
32
|
+
test("Global scope for JS code in an iframe refers to that iframe's window/document", function() {
|
33
|
+
expect(3);
|
34
|
+
|
35
|
+
var idoc = document.getElementById('loadediframe').contentDocument;
|
36
|
+
var mtch = idoc.getElementById('js_generated_p').innerHTML.match(/Dynamic/);
|
37
|
+
try{ ok(mtch && mtch.length > 0,
|
38
|
+
"Can get content from dynamically-generate p element");
|
39
|
+
}catch(e){print(e);}
|
40
|
+
|
41
|
+
mtch = idoc.getElementById('internalDocRefResult').innerHTML.
|
42
|
+
match(/exists-found/);
|
43
|
+
try{ ok(mtch && mtch.length > 0,
|
44
|
+
"Got confirmation of access to 'document' object in iframe");
|
45
|
+
}catch(e){print(e);}
|
46
|
+
|
47
|
+
mtch = idoc.getElementById('appended').innerHTML.match(/appended para/);
|
48
|
+
try{ ok(mtch && mtch.length > 0,
|
49
|
+
"Got confirmation of body-onload execution in iframe");
|
50
|
+
}catch(e){print(e);}
|
51
|
+
});
|
52
|
+
|
53
|
+
|
54
|
+
// the following tests depend on '../html/scope.html' being loaded into
|
55
|
+
// the iframe 'scopeFrame' in the page /index.html'. Each test must only
|
56
|
+
// execute once. Otherwise, there are no test order dependencies
|
57
|
+
// except those noted on individual tests.
|
58
|
+
test("Event handler attribute has access to (correct) 'document'", function() {
|
59
|
+
expect(2);
|
60
|
+
// test: img1.onclick creates p1
|
61
|
+
|
62
|
+
var idoc = document.getElementById('scopeFrame').contentDocument;
|
63
|
+
var mtch = idoc.getElementById('p1');
|
64
|
+
try{ ok(mtch == undefined || mtch == null,
|
65
|
+
"img1 event handler didn't execute early");
|
66
|
+
}catch(e){print(e);}
|
67
|
+
|
68
|
+
var img1 = idoc.getElementById('img1');
|
69
|
+
__click__(img1);
|
70
|
+
mtch = idoc.getElementById('p1').innerHTML.match(/img1 click/);
|
71
|
+
try{ ok(mtch && mtch.length > 0,
|
72
|
+
"img1 event handler executed correctly");
|
73
|
+
}catch(e){print(e);}
|
74
|
+
});
|
75
|
+
|
76
|
+
|
77
|
+
test("Event handler attribute has access to (correct) 'this'", function() {
|
78
|
+
expect(2);
|
79
|
+
// test: div1.onclick creates p2
|
80
|
+
|
81
|
+
var idoc = document.getElementById('scopeFrame').contentDocument;
|
82
|
+
var mtch = idoc.getElementById('p2');
|
83
|
+
try{ ok(mtch == undefined || mtch == null,
|
84
|
+
"div1 event handler didn't execute early");
|
85
|
+
}catch(e){print(e);}
|
86
|
+
|
87
|
+
var div1 = idoc.getElementById('div1');
|
88
|
+
__click__(div1);
|
89
|
+
mtch = idoc.getElementById('p2').innerHTML.match(/div1 click/);
|
90
|
+
try{ ok(mtch && mtch.length > 0,
|
91
|
+
"div1 event handler executed correctly");
|
92
|
+
}catch(e){print(e);}
|
93
|
+
});
|
94
|
+
|
95
|
+
|
96
|
+
test("Event handler attribute has access to (correct) 'this'", function() {
|
97
|
+
expect(2);
|
98
|
+
// test: div1a.onclick creates p2a
|
99
|
+
|
100
|
+
var idoc = document.getElementById('scopeFrame').contentDocument;
|
101
|
+
var mtch = idoc.getElementById('p2a');
|
102
|
+
try{ ok(mtch == undefined || mtch == null,
|
103
|
+
"div1a event handler didn't execute early");
|
104
|
+
}catch(e){print(e);}
|
105
|
+
|
106
|
+
var div1a = idoc.getElementById('div1a');
|
107
|
+
__click__(div1a);
|
108
|
+
mtch = idoc.getElementById('p2a').innerHTML.match(/div1a click/);
|
109
|
+
try{ ok(mtch && mtch.length > 0,
|
110
|
+
"div1a event handler executed correctly");
|
111
|
+
}catch(e){print(e);}
|
112
|
+
});
|
113
|
+
|
114
|
+
|
115
|
+
test("Event handler attribute has enclosing HTML elements in scope chain",
|
116
|
+
function() {
|
117
|
+
expect(2);
|
118
|
+
// test: text1.onchange creates p3 containing values from several elements
|
119
|
+
|
120
|
+
var idoc = document.getElementById('scopeFrame').contentDocument;
|
121
|
+
var mtch = idoc.getElementById('p3');
|
122
|
+
try{ ok(mtch == undefined || mtch == null,
|
123
|
+
"text1 event handler didn't execute early");
|
124
|
+
}catch(e){print(e);}
|
125
|
+
|
126
|
+
text1 = idoc.getElementById('text1');
|
127
|
+
text1.focus();
|
128
|
+
text1.value = "a New Input Value";
|
129
|
+
text1.blur(); // "Dynamic HTML: TDR" 2nd says onchange fires@loss focus
|
130
|
+
|
131
|
+
var goodRE = /components: --a New Input Value-- --text-- --42-- --post-url-- --center--/;
|
132
|
+
mtch = idoc.getElementById('p3').innerHTML.match(goodRE);
|
133
|
+
try{ ok(mtch && mtch.length > 0,
|
134
|
+
"text1 event handler executed correctly");
|
135
|
+
}catch(e){print(e);}
|
136
|
+
});
|
137
|
+
|
138
|
+
|
139
|
+
test("Handler defined in frame lexically scopes to frame", function() {
|
140
|
+
expect(3);
|
141
|
+
|
142
|
+
aVar = "very bad"; // handler must not pick up this version of 'aVar'
|
143
|
+
// test: div2.onclick creates paragraph 'lex' at end of div2
|
144
|
+
|
145
|
+
var idoc = document.getElementById('scopeFrame').contentDocument;
|
146
|
+
var lex = idoc.getElementById('lex');
|
147
|
+
try{ ok(lex == undefined || lex == null,
|
148
|
+
"div2 click handler didn't execute early");
|
149
|
+
}catch(e){print(e);}
|
150
|
+
|
151
|
+
var div2 = idoc.getElementById('div2');
|
152
|
+
__click__(div2);
|
153
|
+
lex = idoc.getElementById('lex');
|
154
|
+
mtch = lex.innerHTML.match(/Lexical scoping is Overridden/);
|
155
|
+
try{ ok(mtch && mtch.length > 0,
|
156
|
+
"div2 click handler generated correct content");
|
157
|
+
}catch(e){print(e);}
|
158
|
+
|
159
|
+
try{ ok(div2 == lex.parentNode,
|
160
|
+
"div2 click handler generated p in correct location");
|
161
|
+
}catch(e){print(e);}
|
162
|
+
});
|
163
|
+
|
164
|
+
|
165
|
+
test("In-frame object-assigned handler scopes to frame", function() {
|
166
|
+
expect(2);
|
167
|
+
// test: div3.onclick creates a p with values from iframe's global scope
|
168
|
+
|
169
|
+
var idoc = document.getElementById('scopeFrame').contentDocument;
|
170
|
+
var p4 = idoc.getElementById('p4');
|
171
|
+
var mtch = p4.innerHTML.match(/Third sentence/);
|
172
|
+
try{ ok(mtch == undefined || mtch == null || mtch.length == 0,
|
173
|
+
"div3 event handler didn't execute early");
|
174
|
+
}catch(e){print(e);}
|
175
|
+
|
176
|
+
bVar = 13; // handler shouldn't pick up this version of 'bVar';
|
177
|
+
__click__(p4); // should bubble to div3 and handler
|
178
|
+
mtch = p4.innerHTML.match(/number 42/);
|
179
|
+
try{ ok(mtch && mtch.length > 0,
|
180
|
+
"div3 event handler executed correctly");
|
181
|
+
}catch(e){print(e);}
|
182
|
+
});
|
183
|
+
|
184
|
+
|
185
|
+
// this test reassigns div3.onclick, so must follow all other div3 tests
|
186
|
+
test("Handler defined in root lexically scopes to root", function() {
|
187
|
+
expect(2);
|
188
|
+
// test: create an onclick fn in this scope, attach/execute in iframe
|
189
|
+
|
190
|
+
var idoc = document.getElementById('scopeFrame').contentDocument;
|
191
|
+
var p4 = idoc.getElementById('p4');
|
192
|
+
var checkValue = "contains good text";
|
193
|
+
idoc.getElementById('div3').onclick = function(){
|
194
|
+
p4.appendChild(idoc.createTextNode(
|
195
|
+
" Fourth sentence " + checkValue + "."));
|
196
|
+
}
|
197
|
+
|
198
|
+
var mtch = p4.innerHTML.match(/Fourth sentence/);
|
199
|
+
try{ ok(mtch == undefined || mtch == null || mtch.length == 0,
|
200
|
+
"new div3 event handler didn't execute early");
|
201
|
+
}catch(e){print(e);}
|
202
|
+
|
203
|
+
var div3 = idoc.getElementById('div3');
|
204
|
+
__click__(div3);
|
205
|
+
mtch = p4.innerHTML.match(/contains good text/);
|
206
|
+
try{ ok(mtch && mtch.length > 0,
|
207
|
+
"new div3 event handler executed correctly");
|
208
|
+
}catch(e){print(e);}
|
209
|
+
});
|