smparkes-envjs 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README +101 -0
- data/bin/envjsrb +147 -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 +98 -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 +10423 -0
- data/lib/envjs/net/file.rb +71 -0
- data/lib/envjs/net.rb +3 -0
- data/lib/envjs/runtime.rb +132 -0
- data/lib/envjs/runtime.rb.smp +133 -0
- data/lib/envjs/tempfile.rb +24 -0
- data/lib/envjs.rb +23 -0
- data/test/call-load-test.js +17 -0
- data/test/debug.js +53 -0
- data/test/envjs-call-load-test.js +3 -0
- data/test/envjs-prototype.js +3 -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/scope.html +87 -0
- data/test/html/trivial.html +19 -0
- data/test/html/with_js.html +26 -0
- data/test/index.html +304 -0
- data/test/java-prototype.js +9 -0
- data/test/primaryTests.js +26 -0
- data/test/prototype.js +15 -0
- data/test/qunit/package.json +21 -0
- data/test/qunit/qunit/qunit.css +17 -0
- data/test/qunit/qunit/qunit.js +997 -0
- data/test/qunit/qunit/qunit.js.smp +1002 -0
- data/test/qunit/test/index.html +17 -0
- data/test/qunit/test/same.js +1368 -0
- data/test/qunit/test/test.js +136 -0
- data/test/qunit.js +61 -0
- data/test/qunit.smp/package.json +21 -0
- data/test/qunit.smp/qunit/qunit.css +17 -0
- data/test/qunit.smp/qunit/qunit.js +997 -0
- data/test/qunit.smp/test/index.html +17 -0
- data/test/qunit.smp/test/same.js +1368 -0
- data/test/qunit.smp/test/test.js +136 -0
- data/test/rhino-call-load-test.js +5 -0
- data/test/test-with-envs-jar.js +8 -0
- data/test/test-with-rhino-jar.js +9 -0
- data/test/unit/dom.js +43 -0
- data/test/unit/elementmembers.js +29 -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/onload.js +82 -0
- data/test/unit/parser.js +113 -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 +130 -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
|
+
|
data/test/unit/onload.js
ADDED
@@ -0,0 +1,82 @@
|
|
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(9);
|
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('pCreatedByScriptOnloadA').innerHTML.
|
63
|
+
match(/script-onload event handler/);
|
64
|
+
try{ ok(mtch && mtch.length > 0,
|
65
|
+
"Got confirmation that script-onload handler executed, empty tag");
|
66
|
+
}catch(e){print(e);}
|
67
|
+
|
68
|
+
mtch = document.getElementById('pCreatedByScriptOnloadB').innerHTML.
|
69
|
+
match(/script-onload event handler/);
|
70
|
+
try{ ok(mtch && mtch.length > 0,
|
71
|
+
"Script-onload handler executed, with open/close tag pair");
|
72
|
+
}catch(e){print(e);}
|
73
|
+
|
74
|
+
mtch = document.getElementById('pShouldntBeCreated');
|
75
|
+
try{ ok(!(mtch),
|
76
|
+
"Confirmed that script-onload handler that shouldn't execute actually didn't");
|
77
|
+
}catch(e){print(e);}
|
78
|
+
});
|
79
|
+
|
80
|
+
|
81
|
+
// still to test: onload events for: <frame>, <frameset>, image obj, layer obj
|
82
|
+
|
data/test/unit/parser.js
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
// environment mocking for parser
|
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/parser.js", "src/dom/entities.js");
|
8
|
+
|
9
|
+
module("parser");
|
10
|
+
|
11
|
+
test("Entity replaced", function() {
|
12
|
+
expect(14);
|
13
|
+
var htmlstr = "<html><body>Hello, "World"!</body></html>";
|
14
|
+
var p = new XMLP(htmlstr);
|
15
|
+
equals(XMLP._ELM_B, p.next(), "Opening html tag"); // _ELM_B <html>
|
16
|
+
equals(XMLP._ELM_B, p.next(), "Opening body tag"); // _ELM_B <body>
|
17
|
+
|
18
|
+
equals(XMLP._TEXT, p.next(), "Parser emits text event");
|
19
|
+
var actual = p.getContent().substring(p.getContentBegin(), p.getContentEnd());
|
20
|
+
equals("Hello, ", actual, "Parser content set");
|
21
|
+
equals(XMLP._ENTITY, p.next(), "Parser emits entity event");
|
22
|
+
|
23
|
+
actual = p.getContent().substring(p.getContentBegin(), p.getContentEnd());
|
24
|
+
equals('"', actual, "Parser replaces " entity");
|
25
|
+
|
26
|
+
equals(XMLP._TEXT, p.next(), "Parser emits second text event");
|
27
|
+
actual = p.getContent().substring(p.getContentBegin(), p.getContentEnd());
|
28
|
+
equals("World", actual, "Parser content set");
|
29
|
+
|
30
|
+
equals(XMLP._ENTITY, p.next(), "Parser emits second entity event");
|
31
|
+
actual = p.getContent().substring(p.getContentBegin(), p.getContentEnd());
|
32
|
+
equals('"', actual, "Parser replaces second " entity");
|
33
|
+
|
34
|
+
equals(XMLP._TEXT, p.next(), "Parser emits third text event");
|
35
|
+
actual = p.getContent().substring(p.getContentBegin(), p.getContentEnd());
|
36
|
+
equals('!', actual, "Parser content set");
|
37
|
+
|
38
|
+
equals(XMLP._ELM_E, p.next(), "Closing body tag"); // _ELM_E </body>
|
39
|
+
equals(XMLP._ELM_E, p.next(), "Closing html tag"); // _ELM_E </html>
|
40
|
+
});
|
41
|
+
|
42
|
+
test("HTML standard entities spot-check", function() {
|
43
|
+
// test definition
|
44
|
+
var numentities = 23;
|
45
|
+
var numexpect = 2 + (4*numentities);
|
46
|
+
expect(numexpect)
|
47
|
+
var htmlstr = "<html><body>" & < > "+
|
48
|
+
" © ® ¥ ¶ " +
|
49
|
+
"Ê Õ æ ÷ Κ θ "+
|
50
|
+
"• … ™ ⇒ ∑ ♣ " +
|
51
|
+
"  — </body></html>";
|
52
|
+
var expected = [ '"', '&', '<', '>',
|
53
|
+
'\xA0', '\xA9','\xAE','\xA5','\xB6',
|
54
|
+
'\xCA', '\xD5', '\xE6', '\xF7', '\u039A','\u03B8',
|
55
|
+
'\u2022','\u2026','\u2122','\u21D2','\u2211','\u2663',
|
56
|
+
'\u2002','\u2014' ];
|
57
|
+
|
58
|
+
// get started
|
59
|
+
var p = new XMLP(htmlstr);
|
60
|
+
equals(XMLP._ELM_B, p.next(), "Opening html tag"); // _ELM_B <html>
|
61
|
+
equals(XMLP._ELM_B, p.next(), "Opening body tag"); // _ELM_B <body>
|
62
|
+
|
63
|
+
// check entities
|
64
|
+
for (idx=0; idx < numentities; idx++) {
|
65
|
+
equals(XMLP._ENTITY, p.next(), "Parser emits entity event -- '" +
|
66
|
+
expected[idx] + "'");
|
67
|
+
actual = p.getContent().substring(
|
68
|
+
p.getContentBegin(), p.getContentEnd());
|
69
|
+
equals(expected[idx], actual, "Parser replaces entity -- '" +
|
70
|
+
expected[idx] + "'");
|
71
|
+
|
72
|
+
equals(XMLP._TEXT, p.next(), "Parser emits text event");
|
73
|
+
actual = p.getContent().substring(
|
74
|
+
p.getContentBegin(), p.getContentEnd());
|
75
|
+
equals(" ", actual, "Parser content set");
|
76
|
+
}
|
77
|
+
});
|
78
|
+
|
79
|
+
test("Toggle entity replacement", function() {
|
80
|
+
expect(6);
|
81
|
+
var htmlstr = "<html><body>Hello, "World"!</body></html>";
|
82
|
+
var p = new XMLP(htmlstr);
|
83
|
+
p.replaceEntities = false;
|
84
|
+
equals(XMLP._ELM_B, p.next(), "Opening html tag"); // _ELM_B <html>
|
85
|
+
equals(XMLP._ELM_B, p.next(), "Opening body tag"); // _ELM_B <body>
|
86
|
+
|
87
|
+
equals(XMLP._TEXT, p.next(), "Parser emits text event");
|
88
|
+
var actual = p.getContent().substring(p.getContentBegin(), p.getContentEnd());
|
89
|
+
equals("Hello, "World"!", actual, "Parser content set");
|
90
|
+
|
91
|
+
equals(XMLP._ELM_E, p.next(), "Closing body tag"); // _ELM_E </body>
|
92
|
+
equals(XMLP._ELM_E, p.next(), "Closing html tag"); // _ELM_E </html>
|
93
|
+
});
|
94
|
+
/**
|
95
|
+
test("Clean HTML", function() {
|
96
|
+
expect(3);
|
97
|
+
var domParser = new DOMParser(),
|
98
|
+
htmlstr = "<div><p>this is a pig... 'oink! oink!'</div>";
|
99
|
+
|
100
|
+
Envjs.tidyHTML = true;
|
101
|
+
equals(Envjs.tidy(htmlstr),
|
102
|
+
"<div><p>this is a pig... 'oink! oink!'</p></div>",
|
103
|
+
'got expected xmlstring');
|
104
|
+
|
105
|
+
|
106
|
+
var domnode = domParser.parseFromString(htmlstr);
|
107
|
+
ok(domnode, 'Malformed p was parsed without error');
|
108
|
+
equals(domnode.xml,
|
109
|
+
"<div><p>this is a pig... 'oink! oink!'</p></div>",
|
110
|
+
'got expected value for .xml');
|
111
|
+
Envjs.tidyHTML = false;
|
112
|
+
|
113
|
+
});*/
|
@@ -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
|
+
});
|