envjs 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +113 -0
- data/bin/envjsrb +239 -0
- data/bin/jquery-1.2.6-test.js +33 -0
- data/bin/jquery-1.3.1-test.js +33 -0
- data/bin/jquery-1.3.2-test.js +106 -0
- data/bin/prototype-1.6.0.3-test.js +82 -0
- data/bin/prototype_1.6.0.3_tmpl.txt +27 -0
- data/bin/test-jquery.sh +58 -0
- data/bin/test-prototype.sh +54 -0
- data/bin/tidy +0 -0
- data/lib/envjs/env.js +21549 -0
- data/lib/envjs/net/cgi.rb +94 -0
- data/lib/envjs/net/file.rb +75 -0
- data/lib/envjs/net.rb +3 -0
- data/lib/envjs/options.rb +11 -0
- data/lib/envjs/runtime.rb +280 -0
- data/lib/envjs/tempfile.rb +24 -0
- data/lib/envjs.rb +23 -0
- data/test/call-load-test.js +15 -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/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/primary-tests.js +24 -0
- data/test/prototype-test.js +13 -0
- data/test/qunit/qunit/qunit.css +17 -0
- data/test/qunit/qunit/qunit.js +997 -0
- data/test/qunit.js +61 -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 +60 -0
- data/test/unit/events.js +195 -0
- data/test/unit/fixtures/external_script.js +1 -0
- data/test/unit/iframe.js +234 -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 +121 -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 +41 -0
- data/test/vendor/jQuery/README +2 -0
- data/test/vendor/prototype-1.6.0.3.js +4320 -0
- metadata +164 -0
@@ -0,0 +1,212 @@
|
|
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("multi-window");
|
11
|
+
|
12
|
+
test("2nd window.location= operation flagged as error", function() {
|
13
|
+
expect(1);
|
14
|
+
|
15
|
+
if ( window.Envjs.interpreter === "Johnson" ) {
|
16
|
+
ok(true,"we don't object to setting window.location in Johnson, which will blitz the tests");
|
17
|
+
} else {
|
18
|
+
var gotAnException = false;
|
19
|
+
window.onload = function(){;};
|
20
|
+
try {
|
21
|
+
window.location = "html/trivial.html";
|
22
|
+
} catch (e){ gotAnException = true; }
|
23
|
+
try{ ok(gotAnException, "prohibited window.location setter call fails");
|
24
|
+
}catch(e){print(e);}
|
25
|
+
}
|
26
|
+
});
|
27
|
+
|
28
|
+
test("window.open()-related behavior and members", function() {
|
29
|
+
expect(30);
|
30
|
+
|
31
|
+
var anotherWin;
|
32
|
+
try{ ok(anotherWin = window.open("html/trivial.html"),
|
33
|
+
"'window.open' returns new object");
|
34
|
+
}catch(e){print(e);}
|
35
|
+
|
36
|
+
try{ ok(anotherWin.closed == false,
|
37
|
+
"2nd window knows that it is not-closed");
|
38
|
+
}catch(e){print(e);}
|
39
|
+
|
40
|
+
var mtch = anotherWin.document.getElementById('oneP').innerHTML.
|
41
|
+
match(/Nearly-empty HTML/);
|
42
|
+
try{ ok(mtch && mtch.length > 0,
|
43
|
+
"2nd window has correct contents");
|
44
|
+
}catch(e){print(e);}
|
45
|
+
|
46
|
+
try{ ok(anotherWin.opener == window,
|
47
|
+
"2nd window's .opener is original window");
|
48
|
+
}catch(e){print(e);}
|
49
|
+
|
50
|
+
try{ ok(anotherWin.top == anotherWin,
|
51
|
+
"2nd window's .top is itself");
|
52
|
+
}catch(e){print(e);}
|
53
|
+
|
54
|
+
try{ ok(anotherWin.parent == anotherWin,
|
55
|
+
"2nd window's .parent is itself");
|
56
|
+
}catch(e){print(e);}
|
57
|
+
|
58
|
+
try{ ok(anotherWin.document.referrer == location.href,
|
59
|
+
"2nd window's document.referrer points to this one");
|
60
|
+
}catch(e){print(e);}
|
61
|
+
|
62
|
+
|
63
|
+
try{ ok((anotherWin.location = "html/with_js.html") || true,
|
64
|
+
"1st explicit '.location=' completes without exception");
|
65
|
+
}catch(e){print(e);}
|
66
|
+
|
67
|
+
mtch = anotherWin.document.getElementById('HeaderLevel1').
|
68
|
+
innerHTML.match(/Hello/);
|
69
|
+
try{ ok(mtch && mtch.length > 0,
|
70
|
+
"location setter-loaded content is correct");
|
71
|
+
}catch(e){print(e);}
|
72
|
+
|
73
|
+
|
74
|
+
try{ ok((anotherWin.location = "html/trivial.html") || true,
|
75
|
+
"2nd explicit '.location=' completes without exception");
|
76
|
+
}catch(e){print(e);}
|
77
|
+
|
78
|
+
mtch = anotherWin.document.getElementById('oneP').innerHTML.
|
79
|
+
match(/Nearly-empty HTML/);
|
80
|
+
try{ ok(mtch && mtch.length > 0,
|
81
|
+
"2nd location setter-loaded content is correct");
|
82
|
+
}catch(e){print(e);}
|
83
|
+
|
84
|
+
|
85
|
+
var thirdWin;
|
86
|
+
try{ ok(thirdWin = window.open("html/with_js.html"),
|
87
|
+
"2nd 'window.open' returns 3rd window");
|
88
|
+
}catch(e){print(e);}
|
89
|
+
|
90
|
+
mtch = thirdWin.document.getElementById('HeaderLevel1').
|
91
|
+
innerHTML.match(/Hello/);
|
92
|
+
try{ ok(mtch && mtch.length > 0,
|
93
|
+
"3rd window's content is correct");
|
94
|
+
}catch(e){print(e);}
|
95
|
+
|
96
|
+
mtch = anotherWin.document.getElementById('oneP').innerHTML.
|
97
|
+
match(/Nearly-empty HTML/);
|
98
|
+
try{ ok(mtch && mtch.length > 0,
|
99
|
+
"after 3rd window, 2nd's content still correct");
|
100
|
+
}catch(e){print(e);}
|
101
|
+
|
102
|
+
try{ ok(document.title == "jQuery Test Suite",
|
103
|
+
"after 3rd window, original's content still correct");
|
104
|
+
}catch(e){print(e);}
|
105
|
+
|
106
|
+
|
107
|
+
try{ ok(thirdWin.getTestVariables()[0] == "hello, scope",
|
108
|
+
"function from open()'ed window's scope callable");
|
109
|
+
}catch(e){print(e);}
|
110
|
+
|
111
|
+
try{ ok(thirdWin.getTestVariables()[1] == undefined ||
|
112
|
+
thirdWin.getTestVariables()[1] == null,
|
113
|
+
"dynamically-created test variable in 3rd win doesn't exist yet");
|
114
|
+
}catch(e){print(e);}
|
115
|
+
|
116
|
+
try{ ok(thirdWin.setTestVariable(42) || true,
|
117
|
+
"call to fn to create variable in other window's scope w/o exception");
|
118
|
+
}catch(e){print(e);}
|
119
|
+
|
120
|
+
try{ ok(thirdWin.getTestVariables()[1] == 42,
|
121
|
+
"variable in other window's scope created correctly");
|
122
|
+
}catch(e){print(e);}
|
123
|
+
|
124
|
+
try{ ok(thirdWin.notAlwaysPresentVariable == 42,
|
125
|
+
"variable in other window's scope accessible directly, too");
|
126
|
+
}catch(e){print(e);}
|
127
|
+
|
128
|
+
try{ ok((thirdWin.location = "html/with_js.html") || true,
|
129
|
+
"3rd window's '.location=' worked without exception");
|
130
|
+
}catch(e){print(e);}
|
131
|
+
|
132
|
+
try{ ok(thirdWin.getTestVariables()[1] == undefined ||
|
133
|
+
thirdWin.getTestVariables()[1] == null,
|
134
|
+
"reloaded window has clean variable scope");
|
135
|
+
}catch(e){print(e);}
|
136
|
+
|
137
|
+
try{ ok(thirdWin.notAlwaysPresentVariable = 55,
|
138
|
+
"setting variable in other window's scope executes without exception");
|
139
|
+
}catch(e){print(e);}
|
140
|
+
|
141
|
+
try{ ok(thirdWin.getTestVariables()[1] == 55,
|
142
|
+
"directly-set variable visible to code executing in other scope");
|
143
|
+
}catch(e){print(e);}
|
144
|
+
|
145
|
+
try{ ok(window.notAlwaysPresentVariable == undefined ||
|
146
|
+
window.notAlwaysPresentVariable == null,
|
147
|
+
"creating variable in 3rd window scope doesn't affect original window");
|
148
|
+
}catch(e){print(e);}
|
149
|
+
|
150
|
+
try{ ok(anotherWin.notAlwaysPresentVariable == undefined ||
|
151
|
+
anotherWin.notAlwaysPresentVariable == null,
|
152
|
+
"creating variable in 3rd window scope doesn't affect 2nd window");
|
153
|
+
}catch(e){print(e);}
|
154
|
+
|
155
|
+
|
156
|
+
try{ ok(anotherWin.close() || true,
|
157
|
+
"'.close()' executed without exception");
|
158
|
+
}catch(e){print(e);}
|
159
|
+
|
160
|
+
try{ ok(anotherWin.closed == true,
|
161
|
+
"after closing window, '.closed' is true");
|
162
|
+
}catch(e){print(e);}
|
163
|
+
|
164
|
+
try{ ok(window.closed == false,
|
165
|
+
"closing 2nd window doesn't affect original window");
|
166
|
+
}catch(e){print(e);}
|
167
|
+
|
168
|
+
try{ ok(thirdWin.closed == false,
|
169
|
+
"closing 2nd window doesn't affect 3rd window");
|
170
|
+
}catch(e){print(e);}
|
171
|
+
});
|
172
|
+
|
173
|
+
test("window.reload() behavior", function() {
|
174
|
+
expect(3);
|
175
|
+
|
176
|
+
var testWindow = window.open("html/trivial.html");
|
177
|
+
testWindow.checkingScope = 17;
|
178
|
+
try{ ok(testWindow.location.reload() || true,
|
179
|
+
"'window.location.reload()' completes without exception");
|
180
|
+
}catch(e){print(e);}
|
181
|
+
|
182
|
+
var variableNoLongerDefined = false;
|
183
|
+
try {
|
184
|
+
variableNoLongerDefined = (testWindow.checkingScope == undefined);
|
185
|
+
} catch (e){
|
186
|
+
variableNoLongerDefined = true;
|
187
|
+
}
|
188
|
+
try{ ok(variableNoLongerDefined, "reloaded window has clean scope");
|
189
|
+
}catch(e){print(e);}
|
190
|
+
|
191
|
+
var mtch = testWindow.document.getElementById('oneP').innerHTML.
|
192
|
+
match(/Nearly-empty HTML/);
|
193
|
+
try{ ok(mtch && mtch.length > 0,
|
194
|
+
"reloaded window has correct contents");
|
195
|
+
}catch(e){print(e);}
|
196
|
+
});
|
197
|
+
|
198
|
+
test("window.replace() behavior", function() {
|
199
|
+
expect(2);
|
200
|
+
|
201
|
+
var testWindow = window.open("html/trivial.html");
|
202
|
+
try{ ok(testWindow.location.replace("html/with_js.html") || true,
|
203
|
+
"'window.location.replace()' completes without exception");
|
204
|
+
}catch(e){print(e);}
|
205
|
+
|
206
|
+
var mtch = testWindow.document.getElementById('HeaderLevel1').
|
207
|
+
innerHTML.match(/Hello/);
|
208
|
+
try{ ok(mtch && mtch.length > 0, "replaced window has correct content");
|
209
|
+
}catch(e){print(e);}
|
210
|
+
});
|
211
|
+
|
212
|
+
|
@@ -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,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
|
+
});
|
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
|
+
});
|