harmony 0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/LICENSE +19 -0
- data/Manifest +117 -0
- data/README.md +155 -0
- data/Rakefile +39 -0
- data/docs.watchr +25 -0
- data/harmony.gemspec +18 -0
- data/lib/harmony.rb +5 -0
- data/lib/harmony/page.rb +123 -0
- data/specs.watchr +36 -0
- data/test/harmony_test.rb +8 -0
- data/test/page_test.rb +73 -0
- data/test/test_helper.rb +13 -0
- data/vendor/README +1 -0
- data/vendor/envjs/README +36 -0
- data/vendor/envjs/bin/envjsrb +255 -0
- data/vendor/envjs/bin/jquery-1.2.6-test.js +33 -0
- data/vendor/envjs/bin/jquery-1.3.1-test.js +33 -0
- data/vendor/envjs/bin/jquery-1.3.2-test.js +106 -0
- data/vendor/envjs/bin/prototype-1.6.0.3-test.js +82 -0
- data/vendor/envjs/bin/prototype_1.6.0.3_tmpl.txt +27 -0
- data/vendor/envjs/bin/test-jquery.sh +58 -0
- data/vendor/envjs/bin/test-prototype.sh +54 -0
- data/vendor/envjs/bin/tidy +0 -0
- data/vendor/envjs/lib/envjs.rb +23 -0
- data/vendor/envjs/lib/envjs/env.js +21665 -0
- data/vendor/envjs/lib/envjs/net.rb +3 -0
- data/vendor/envjs/lib/envjs/net/cgi.rb +94 -0
- data/vendor/envjs/lib/envjs/net/file.rb +75 -0
- data/vendor/envjs/lib/envjs/options.rb +11 -0
- data/vendor/envjs/lib/envjs/runtime.rb +351 -0
- data/vendor/envjs/lib/envjs/tempfile.rb +24 -0
- data/vendor/envjs/test/base64.js +80 -0
- data/vendor/envjs/test/call-load-test.js +15 -0
- data/vendor/envjs/test/data.js +45 -0
- data/vendor/envjs/test/debug.js +53 -0
- data/vendor/envjs/test/firebug/errorIcon.png +0 -0
- data/vendor/envjs/test/firebug/firebug.css +209 -0
- data/vendor/envjs/test/firebug/firebug.html +23 -0
- data/vendor/envjs/test/firebug/firebug.js +672 -0
- data/vendor/envjs/test/firebug/firebugx.js +10 -0
- data/vendor/envjs/test/firebug/infoIcon.png +0 -0
- data/vendor/envjs/test/firebug/warningIcon.png +0 -0
- data/vendor/envjs/test/fixtures/html/events.html +171 -0
- data/vendor/envjs/test/fixtures/html/iframe1.html +46 -0
- data/vendor/envjs/test/fixtures/html/iframe1a.html +46 -0
- data/vendor/envjs/test/fixtures/html/iframe2.html +45 -0
- data/vendor/envjs/test/fixtures/html/iframe3.html +28 -0
- data/vendor/envjs/test/fixtures/html/iframeN.html +57 -0
- data/vendor/envjs/test/fixtures/html/malformed.html +181 -0
- data/vendor/envjs/test/fixtures/html/scope.html +81 -0
- data/vendor/envjs/test/fixtures/html/trivial.html +19 -0
- data/vendor/envjs/test/fixtures/html/with_js.html +26 -0
- data/vendor/envjs/test/fixtures/images/icon-blue.png +0 -0
- data/vendor/envjs/test/fixtures/js/external_script.js +1 -0
- data/vendor/envjs/test/fixtures/js/script.js +1 -0
- data/vendor/envjs/test/fixtures/js/script_error.js +2 -0
- data/vendor/envjs/test/html/events.html +171 -0
- data/vendor/envjs/test/html/iframe1.html +46 -0
- data/vendor/envjs/test/html/iframe1a.html +46 -0
- data/vendor/envjs/test/html/iframe2.html +45 -0
- data/vendor/envjs/test/html/iframe3.html +30 -0
- data/vendor/envjs/test/html/iframeN.html +57 -0
- data/vendor/envjs/test/html/malformed.html +181 -0
- data/vendor/envjs/test/html/scope.html +87 -0
- data/vendor/envjs/test/html/script.js +1 -0
- data/vendor/envjs/test/html/trivial.html +19 -0
- data/vendor/envjs/test/html/with_js.html +26 -0
- data/vendor/envjs/test/index.html +328 -0
- data/vendor/envjs/test/java-prototype.js +9 -0
- data/vendor/envjs/test/primary-tests.js +24 -0
- data/vendor/envjs/test/prototype-test.js +13 -0
- data/vendor/envjs/test/qunit.js +61 -0
- data/vendor/envjs/test/qunit/qunit/qunit.css +17 -0
- data/vendor/envjs/test/qunit/qunit/qunit.js +997 -0
- data/vendor/envjs/test/scope.rb +25 -0
- data/vendor/envjs/test/specs/dist/env.spec.js +1534 -0
- data/vendor/envjs/test/specs/envjs.spec.css +46 -0
- data/vendor/envjs/test/specs/parser/html.js +31 -0
- data/vendor/envjs/test/specs/parser/spec.html +40 -0
- data/vendor/envjs/test/specs/parser/xml.js +31 -0
- data/vendor/envjs/test/specs/qunit.bdd.js +210 -0
- data/vendor/envjs/test/specs/qunit.css +17 -0
- data/vendor/envjs/test/specs/qunit.js +997 -0
- data/vendor/envjs/test/specs/template/spec-0.js +31 -0
- data/vendor/envjs/test/specs/template/spec-1.js +31 -0
- data/vendor/envjs/test/specs/template/spec.html +40 -0
- data/vendor/envjs/test/specs/window/css.js +23 -0
- data/vendor/envjs/test/specs/window/dialog.js +25 -0
- data/vendor/envjs/test/specs/window/document.js +23 -0
- data/vendor/envjs/test/specs/window/event.js +25 -0
- data/vendor/envjs/test/specs/window/history.js +34 -0
- data/vendor/envjs/test/specs/window/location.js +34 -0
- data/vendor/envjs/test/specs/window/navigator.js +71 -0
- data/vendor/envjs/test/specs/window/screen.js +42 -0
- data/vendor/envjs/test/specs/window/spec.html +48 -0
- data/vendor/envjs/test/specs/window/timer.js +26 -0
- data/vendor/envjs/test/specs/window/window.js +53 -0
- data/vendor/envjs/test/specs/xhr/spec.html +47 -0
- data/vendor/envjs/test/specs/xhr/xhr.js +31 -0
- data/vendor/envjs/test/test.js +10 -0
- data/vendor/envjs/test/unit/dom.js +44 -0
- data/vendor/envjs/test/unit/elementmembers.js +60 -0
- data/vendor/envjs/test/unit/events.js +195 -0
- data/vendor/envjs/test/unit/fixtures/external_script.js +1 -0
- data/vendor/envjs/test/unit/iframe.js +234 -0
- data/vendor/envjs/test/unit/multi-window.js +212 -0
- data/vendor/envjs/test/unit/nu.validator.js +34 -0
- data/vendor/envjs/test/unit/onload.js +90 -0
- data/vendor/envjs/test/unit/parser.js +121 -0
- data/vendor/envjs/test/unit/prototypecompat.js +22 -0
- data/vendor/envjs/test/unit/proxy.js +6 -0
- data/vendor/envjs/test/unit/scope.js +209 -0
- data/vendor/envjs/test/unit/timer.js +115 -0
- data/vendor/envjs/test/unit/window.js +41 -0
- data/vendor/envjs/test/vendor/jQuery/README +2 -0
- data/vendor/envjs/test/vendor/prototype-1.6.0.3.js +4320 -0
- metadata +200 -0
@@ -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
|
+
|
@@ -0,0 +1,121 @@
|
|
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
|
+
test("Really Ugly HTML Parsing", function() {
|
104
|
+
|
105
|
+
expect(1);
|
106
|
+
|
107
|
+
should('parse the document without error',{
|
108
|
+
be:'safe',
|
109
|
+
test:function(){
|
110
|
+
var doc = document.implementation.createHTMLDocument();
|
111
|
+
doc.load('html/malformed.html');
|
112
|
+
}
|
113
|
+
});
|
114
|
+
|
115
|
+
});
|
116
|
+
|
117
|
+
// Local Variables:
|
118
|
+
// espresso-indent-level:4
|
119
|
+
// c-basic-offset:4
|
120
|
+
// tab-width:4
|
121
|
+
// 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
|
+
});
|
@@ -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
|
+
});
|