smparkes-envjs 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. data/README +101 -0
  2. data/bin/envjsrb +147 -0
  3. data/bin/jquery-1.2.6-test.js +33 -0
  4. data/bin/jquery-1.3.1-test.js +33 -0
  5. data/bin/jquery-1.3.2-test.js +98 -0
  6. data/bin/prototype-1.6.0.3-test.js +82 -0
  7. data/bin/prototype_1.6.0.3_tmpl.txt +27 -0
  8. data/bin/test-jquery.sh +58 -0
  9. data/bin/test-prototype.sh +54 -0
  10. data/bin/tidy +0 -0
  11. data/lib/envjs/env.js +10423 -0
  12. data/lib/envjs/net/file.rb +71 -0
  13. data/lib/envjs/net.rb +3 -0
  14. data/lib/envjs/runtime.rb +132 -0
  15. data/lib/envjs/runtime.rb.smp +133 -0
  16. data/lib/envjs/tempfile.rb +24 -0
  17. data/lib/envjs.rb +23 -0
  18. data/test/call-load-test.js +17 -0
  19. data/test/debug.js +53 -0
  20. data/test/envjs-call-load-test.js +3 -0
  21. data/test/envjs-prototype.js +3 -0
  22. data/test/html/events.html +171 -0
  23. data/test/html/iframe1.html +46 -0
  24. data/test/html/iframe1a.html +46 -0
  25. data/test/html/iframe2.html +45 -0
  26. data/test/html/iframe3.html +30 -0
  27. data/test/html/iframeN.html +57 -0
  28. data/test/html/scope.html +87 -0
  29. data/test/html/trivial.html +19 -0
  30. data/test/html/with_js.html +26 -0
  31. data/test/index.html +304 -0
  32. data/test/java-prototype.js +9 -0
  33. data/test/primaryTests.js +26 -0
  34. data/test/prototype.js +15 -0
  35. data/test/qunit/package.json +21 -0
  36. data/test/qunit/qunit/qunit.css +17 -0
  37. data/test/qunit/qunit/qunit.js +997 -0
  38. data/test/qunit/qunit/qunit.js.smp +1002 -0
  39. data/test/qunit/test/index.html +17 -0
  40. data/test/qunit/test/same.js +1368 -0
  41. data/test/qunit/test/test.js +136 -0
  42. data/test/qunit.js +61 -0
  43. data/test/qunit.smp/package.json +21 -0
  44. data/test/qunit.smp/qunit/qunit.css +17 -0
  45. data/test/qunit.smp/qunit/qunit.js +997 -0
  46. data/test/qunit.smp/test/index.html +17 -0
  47. data/test/qunit.smp/test/same.js +1368 -0
  48. data/test/qunit.smp/test/test.js +136 -0
  49. data/test/rhino-call-load-test.js +5 -0
  50. data/test/test-with-envs-jar.js +8 -0
  51. data/test/test-with-rhino-jar.js +9 -0
  52. data/test/unit/dom.js +43 -0
  53. data/test/unit/elementmembers.js +29 -0
  54. data/test/unit/events.js +195 -0
  55. data/test/unit/fixtures/external_script.js +1 -0
  56. data/test/unit/iframe.js +234 -0
  57. data/test/unit/multi-window.js +212 -0
  58. data/test/unit/onload.js +82 -0
  59. data/test/unit/parser.js +113 -0
  60. data/test/unit/prototypecompat.js +22 -0
  61. data/test/unit/proxy.js +6 -0
  62. data/test/unit/scope.js +209 -0
  63. data/test/unit/timer.js +115 -0
  64. data/test/unit/window.js +41 -0
  65. data/test/vendor/jQuery/README +2 -0
  66. data/test/vendor/prototype-1.6.0.3.js +4320 -0
  67. metadata +130 -0
@@ -0,0 +1,136 @@
1
+ test("module without setup/teardown (default)", function() {
2
+ expect(1);
3
+ ok(true);
4
+ });
5
+
6
+ test("expect in test", 3, function() {
7
+ ok(true);
8
+ ok(true);
9
+ ok(true);
10
+ });
11
+
12
+ test("expect in test", 1, function() {
13
+ ok(true);
14
+ });
15
+
16
+ module("setup test", {
17
+ setup: function() {
18
+ ok(true);
19
+ }
20
+ });
21
+
22
+ test("module with setup", function() {
23
+ expect(2);
24
+ ok(true);
25
+ });
26
+
27
+ var state;
28
+
29
+ module("setup/teardown test", {
30
+ setup: function() {
31
+ state = true;
32
+ ok(true);
33
+ },
34
+ teardown: function() {
35
+ ok(true);
36
+ }
37
+ });
38
+
39
+ test("module with setup/teardown", function() {
40
+ expect(3);
41
+ ok(true);
42
+ });
43
+
44
+ module("setup/teardown test 2");
45
+
46
+ test("module without setup/teardown", function() {
47
+ expect(1);
48
+ ok(true);
49
+ });
50
+
51
+ if (typeof setTimeout !== 'undefined') {
52
+ state = 'fail';
53
+
54
+ module("teardown and stop", {
55
+ teardown: function() {
56
+ equals(state, "done", "Test teardown.");
57
+ }
58
+ });
59
+
60
+ test("teardown must be called after test ended", function() {
61
+ expect(1);
62
+ stop();
63
+ setTimeout(function() {
64
+ state = "done";
65
+ start();
66
+ }, 13);
67
+ });
68
+ } // end setTimeout tests
69
+
70
+ if (typeof asyncTest !== 'undefined') {
71
+ module("asyncTest");
72
+
73
+ asyncTest("asyncTest", function() {
74
+ expect(2);
75
+ ok(true);
76
+ setTimeout(function() {
77
+ state = "done";
78
+ ok(true);
79
+ start();
80
+ }, 13);
81
+ });
82
+
83
+ asyncTest("asyncTest", 2, function() {
84
+ ok(true);
85
+ setTimeout(function() {
86
+ state = "done";
87
+ ok(true);
88
+ start();
89
+ }, 13);
90
+ });
91
+ } // end asyncTest tests
92
+
93
+ module("save scope", {
94
+ setup: function() {
95
+ this.foo = "bar";
96
+ },
97
+ teardown: function() {
98
+ same(this.foo, "bar");
99
+ }
100
+ });
101
+ test("scope check", function() {
102
+ expect(2);
103
+ same(this.foo, "bar");
104
+ });
105
+
106
+ module("simple testEnvironment setup", {
107
+ foo: "bar",
108
+ bugid: "#5311" // example of meta-data
109
+ });
110
+ test("scope check", function() {
111
+ same(this.foo, "bar");
112
+ });
113
+ test("modify testEnvironment",function() {
114
+ this.foo="hamster";
115
+ });
116
+ test("testEnvironment reset for next test",function() {
117
+ same(this.foo, "bar");
118
+ });
119
+
120
+ module("testEnvironment with object", {
121
+ options:{
122
+ recipe:"soup",
123
+ ingredients:["hamster","onions"]
124
+ }
125
+ });
126
+ test("scope check", function() {
127
+ same(this.options, {recipe:"soup",ingredients:["hamster","onions"]}) ;
128
+ });
129
+ test("modify testEnvironment",function() {
130
+ // since we do a shallow copy, the testEnvironment can be modified
131
+ this.options.ingredients.push("carrots");
132
+ });
133
+ test("testEnvironment reset for next test",function() {
134
+ same(this.options, {recipe:"soup",ingredients:["hamster","onions","carrots"]}, "Is this a bug or a feature? Could do a deep copy") ;
135
+ });
136
+
@@ -0,0 +1,5 @@
1
+ whichJarFile = "rhino"
2
+ multiwindow = false;
3
+ whichInterpreter = whichJarFile + " interpreter jar";
4
+ load("dist/env.rhino.js");
5
+ load("test/call-load-test.js");
@@ -0,0 +1,8 @@
1
+ // Run 'test.js', letting it know that we're running with our customized
2
+ // version of the JS interpreter: env-js.jar
3
+
4
+ whichJarFile = "envjs";
5
+ whichInterpreter = whichJarFile + " interpreter jar";
6
+ multiwindow = true;
7
+ load("dist/env.rhino.js");
8
+ load("test/primaryTests.js");
@@ -0,0 +1,9 @@
1
+ // Run 'test.js', letting it know that we're running with the vanilla
2
+ // unmodified version of the Rhino JS interpreter: rhino.jar
3
+
4
+ whichJarFile = "rhino"
5
+ whichInterpreter = whichJarFile + " interpreter jar";
6
+ multiwindow = false;
7
+ load("dist/env.rhino.js");
8
+ load("test/primaryTests.js");
9
+
data/test/unit/dom.js ADDED
@@ -0,0 +1,43 @@
1
+ // dependencies for the tests
2
+ $w = { }
3
+ $env = { debug: function() {} }
4
+ $openingWindow = $parentWindow = $initTop = null;
5
+ this.options = this.options || {}
6
+
7
+ load("src/window/window.js", "src/dom/node.js");
8
+
9
+
10
+ module("dom");
11
+
12
+ test("Basic requirements", function() {
13
+ expect(5);
14
+ ok( Array.prototype.push, "Array.push()" );
15
+ ok( Function.prototype.apply, "Function.apply()" );
16
+ ok( document.getElementById, "getElementById" );
17
+ ok( document.getElementsByTagName, "getElementsByTagName" );
18
+ ok( RegExp, "RegExp" );
19
+ });
20
+
21
+ test("document.getElementById", function() {
22
+ expect(14);
23
+ try{ok (document.getElementById('body').id == "body", "Can get Element by id, expected id='body'");}catch(e){print(e);}
24
+ try{ok (document.getElementById('header').id == "header", "Can get Element by id, expected id='header'");}catch(e){print(e);}
25
+ try{ok (document.getElementById('banner').id == "banner", "Can get Element by id, expected id='banner'");}catch(e){print(e);}
26
+ try{ok (document.getElementById('userAgent').id == "userAgent", "Can get Element by id, expected id='userAgent'");}catch(e){print(e);}
27
+ try{ok (document.getElementById('nothiddendiv').id == "nothiddendiv", "Can get Element by id, expected id='nothiddendiv'");}catch(e){print(e);}
28
+ try{ok (document.getElementById('nothiddendivchild').id == "nothiddendivchild", "Can get Element by id, expected id='nothiddendivchild'");}catch(e){print(e);}
29
+ try{ok (document.getElementById('dl').id == "dl", "Can get Element by id, expected id='dl'");}catch(e){print(e);}
30
+ try{ok (document.getElementById('main').id == "main", "Can get Element by id, expected id='main'");}catch(e){print(e);}
31
+ try{ok (document.getElementById('firstp').id == "firstp", "Can get Element by id, expected id='firstp");}catch(e){print(e);}
32
+ try{ok (document.getElementById('simon1').id == "simon1", "Can get Element by id, expected id='simon1'");}catch(e){print(e);}
33
+ try{ok (document.getElementById('ap').id == "ap", "Can get Element by id, expected id='ap'");}catch(e){print(e);}
34
+ try{ok (document.getElementById('google').id == "google", "Can get Element by id, expected id='google'");}catch(e){print(e);}
35
+ try{ok (document.getElementById('groups').id == "groups", "Can get Element by id, expected id='groups'");}catch(e){print(e);}
36
+ try{ok (document.getElementById('台北Táiběi').id == "台北Táiběi", "Can get Element by UTF-8 id, expected id='台北Táiběi'");}catch(e){print(e);}
37
+ });
38
+
39
+ test("element.getElementsByTagName", function() {
40
+ expect(1);
41
+ var body = document.getElementById('body');
42
+ try{ok (body.getElementsByTagName('h1').length == 1, "Can get NodeList length : Expected 1 , Got " + body.getElementsByTagName('h1').length);}catch(e){print(e);}
43
+ });
@@ -0,0 +1,29 @@
1
+ module("elementmembers");
2
+
3
+ // We ought to have test coverage for all members of all DOM objects, but
4
+ // until then, add test cases here for members as they are created
5
+
6
+ test("attributes common to all HTML elements", function() {
7
+ expect(4);
8
+
9
+ // tests for .innerText
10
+ var mtch = document.getElementById('dl').innerText.match(
11
+ /^See this blog entry for more information.\s+Here are/);
12
+ try{ ok(mtch && mtch.length > 0,
13
+ "dl.innerText returns the correct content");
14
+ }catch(e){print(e);}
15
+
16
+ mtch = document.getElementById('sndp').innerText.match(/^Everything insid/);
17
+ try{ ok(mtch && mtch.length > 0,
18
+ "p.innerText returns the correct content");
19
+ }catch(e){print(e);}
20
+
21
+ try{ ok(document.getElementById('sndp').innerText = "test text" || true,
22
+ "p.innerText= operates without exception");
23
+ }catch(e){print(e);}
24
+
25
+ try{ ok(document.getElementById('sndp').innerText == "test text",
26
+ "p.innerText= changes content of element");
27
+ }catch(e){print(e);}
28
+ });
29
+
@@ -0,0 +1,195 @@
1
+ /*
2
+ * This file is a component of env.js,
3
+ * http://github.com/gleneivey/env-js/commits/master/README
4
+ * a Pure JavaScript Browser Environment
5
+ * Copyright 2009 John Resig, licensed under the MIT License
6
+ * http://www.opensource.org/licenses/mit-license.php
7
+ */
8
+
9
+
10
+ module("events");
11
+
12
+ // This file is for tests of general event dispatching, propagation, and
13
+ // handling functionality. In keeping with the general non-exhaustive
14
+ // approach of env.js's unit tests, each behavior is checked for one
15
+ // relevant type of event in one relevant context (page structure, etc.).
16
+
17
+ // These tests rely on the content of ../html/events.html and of the
18
+ // <iframe id='eventsFrame'> tag in ../index.html.
19
+
20
+ // These tests are order-dependent. If you alter the order or add new tests
21
+ // in the middle, the expected values of eventFrameLoaded and
22
+ // eventFrameClicked may well change (perhaps requiring extra parameters
23
+ // to the *Checks convenience functions).
24
+
25
+
26
+ var __click__ = function(element){
27
+ var event = new Event({
28
+ target:element,
29
+ currentTarget:element
30
+ });
31
+ event.initEvent("click");
32
+ element.dispatchEvent(event);
33
+ }
34
+
35
+ function loadChecks(tag, loadCount, imgCount, unloadCount){
36
+ expect(5);
37
+
38
+ var eCounters = window.top.eCounters;
39
+ try{ ok( eCounters["window onload"] == loadCount &&
40
+ eCounters["body onload"] == loadCount,
41
+ tag + ": Onload Events recorded");
42
+ }catch(e){print(e);}
43
+
44
+ try{ ok( eCounters["img onload"] == imgCount,
45
+ tag + ": Img-tag onload event(s) recorded separately");
46
+ }catch(e){print(e);}
47
+
48
+ try{ ok( eCounters["window onunload"] == unloadCount &&
49
+ eCounters["body onunload"] == unloadCount,
50
+ tag + ": Onunload events recorded");
51
+ }catch(e){print(e);}
52
+
53
+ try{ ok( eCounters["body onclick"] == 0 &&
54
+ eCounters["h1 onclick"] == 0 &&
55
+ eCounters["h2 onclick"] == 0 &&
56
+ eCounters["div onclick"] == 0 &&
57
+ eCounters["table onclick"] == 0 &&
58
+ eCounters["tbody onclick"] == 0 &&
59
+ eCounters["tr onclick"] == 0 &&
60
+ eCounters["td onclick"] == 0 &&
61
+ eCounters["ul onclick"] == 0 &&
62
+ eCounters["li onclick"] == 0 &&
63
+ eCounters["p onclick"] == 0 &&
64
+ eCounters["b onclick"] == 0 &&
65
+ eCounters["i onclick"] == 0 &&
66
+ eCounters["a onclick"] == 0 &&
67
+ eCounters["img onclick"] == 0,
68
+ tag + ": Onload events recorded once.");
69
+ }catch(e){print(e);}
70
+
71
+ try{ ok( eventFrameLoaded == loadCount && eventFrameClicked == 0,
72
+ tag + ": " + loadCount + " iframe events recorded on page load.");
73
+ }catch(e){print(e);}
74
+ }
75
+
76
+
77
+ test("Check that events do/don't occur on document load", function() {
78
+ // eCounters already initialized by code in ../html/events.html
79
+ loadChecks("Load", 1, 1, 0);
80
+ });
81
+
82
+ test("Check that events do/don't occur on manual iframe reload", function() {
83
+ document.getElementById('eventsFrame').src = "html/events.html";
84
+ loadChecks("Reload", 2, 2, 1);
85
+ });
86
+
87
+ test("Check that an event which should NOT bubble actually does not",
88
+ function() {
89
+ var img = document.getElementById('eventsFrame').contentDocument.
90
+ getElementById('theIMG').src = "missing.png";
91
+ loadChecks("Img Load", 2, 3, 1);
92
+
93
+ // note: if img-onload had bubbled up, previous tests probably would
94
+ // have failed (too large body-onload counts), too. So this test
95
+ // just ensures that operation is correct even when only part of
96
+ // page is reloading.
97
+ });
98
+
99
+
100
+
101
+ function clickChecks(tag, upperCount, lowerCount){
102
+ expect(5);
103
+
104
+ var eCounters = window.top.eCounters;
105
+ try{ ok( eCounters["window onload"] == 0 &&
106
+ eCounters["window onunload"] == 0 &&
107
+ eCounters["body onload"] == 0 &&
108
+ eCounters["body onunload"] == 0 &&
109
+ eCounters["img onload"] == 0,
110
+ tag + ": Onload events not triggered by click");
111
+ }catch(e){print(e);}
112
+
113
+ var special = (upperCount == lowerCount) ? "" : " not";
114
+ try{ ok( eCounters["ul onclick"] == lowerCount &&
115
+ eCounters["li onclick"] == lowerCount &&
116
+ eCounters["p onclick"] == lowerCount &&
117
+ eCounters["b onclick"] == lowerCount &&
118
+ eCounters["i onclick"] == lowerCount &&
119
+ eCounters["a onclick"] == lowerCount &&
120
+ eCounters["img onclick"] == lowerCount,
121
+ tag + ": Click event did" + special + " bubble through inner elements");
122
+ }catch(e){print(e);}
123
+
124
+ try{ ok( eCounters["body onclick"] == upperCount &&
125
+ eCounters["div onclick"] == upperCount &&
126
+ eCounters["table onclick"] == upperCount &&
127
+ eCounters["tbody onclick"] == upperCount &&
128
+ eCounters["tr onclick"] == upperCount &&
129
+ eCounters["td onclick"] == upperCount,
130
+ tag + ": Click event bubbled through outer elements");
131
+ }catch(e){print(e);}
132
+
133
+ try{ ok( eCounters["h1 onclick"] == 0 &&
134
+ eCounters["h2 onclick"] == 0,
135
+ tag + ": No click events for Hx elements");
136
+ }catch(e){print(e);}
137
+
138
+
139
+ try{ ok( eventFrameLoaded == 2 && eventFrameClicked == 0,
140
+ tag + ": Iframe event counts unchanged");
141
+ }catch(e){print(e);}
142
+ }
143
+
144
+ test("Check that an event which should bubble actually does", function() {
145
+ // clear in-iframe event counters to zero
146
+ window.top.eCounters = {};
147
+ fWin = document.getElementById('eventsFrame').contentWindow;
148
+ fWin.initECounters(window.top.eCounters);
149
+
150
+ // simulate a "click" user action
151
+ var img = document.getElementById('eventsFrame').contentDocument.
152
+ getElementById('theIMG');
153
+ __click__(img);
154
+
155
+ clickChecks("Click img", 1, 1);
156
+ });
157
+
158
+ test("Bubbling event ONLY bubbles 'up'", function() {
159
+ // simulate a "click" user action
160
+ var td = document.getElementById('eventsFrame').contentDocument.
161
+ getElementById('theTD');
162
+ __click__(td);
163
+
164
+ clickChecks("Click td", 2, 1);
165
+ });
166
+
167
+
168
+ test("Check that events can be set with addEventListener(), and bubble",
169
+ function() {
170
+ expect(4);
171
+
172
+ var img = document.getElementById('eventsFrame').contentDocument.
173
+ getElementById('theIMG');
174
+
175
+ // add handlers
176
+ addHdlr = function(id) {
177
+ var elem = document.getElementById('eventsFrame').contentDocument.
178
+ getElementById(id).addEventListener('click', function(event){
179
+ try{
180
+ ok( event.target === img && this === window,
181
+ "Scope: 'this' refers to the window '" + window + "'");
182
+ }catch(e){print(e);}
183
+ });
184
+ };
185
+
186
+ // a few objects that the <img 'theImG'>.click event will bubble up through
187
+ addHdlr("theIMG");
188
+ addHdlr("theA");
189
+ addHdlr("theP");
190
+ addHdlr("theLI");
191
+
192
+ // simulate user action
193
+ __click__(img);
194
+ });
195
+
@@ -0,0 +1 @@
1
+ var $$$$$ = "12345";
@@ -0,0 +1,234 @@
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("iframe");
11
+
12
+
13
+ // In general, the tests here use the files ../html/iframe*.html
14
+ // I've tried to keep all of the id attributes and text fragments in these
15
+ // files unique from each other and from the content of index.html
16
+ // to ensure that we can correctly identify which file has loaded into
17
+ // which frame/window. When making modifications/additions, paying
18
+ // attention to uniqueness is recommended.
19
+
20
+
21
+ // all tests to next comment rely on content of ../html/iframe1.html and
22
+ // ../html/iframe1a.html
23
+
24
+ // iframe1 and iframe1a are identical in structure (so we can use the
25
+ // same assertions against both), but different in content text (so
26
+ // that we can tell which one is currently loaded). So, create an
27
+ // object (associative array) that is specific to the content of each.
28
+ contentOfIframe1 = {
29
+ url : "html/iframe1.html",
30
+ titleRE : /IFRAME/,
31
+ elementId : 'anElementWithText',
32
+ elementRE : /content of a paragraph/
33
+ };
34
+ contentOfIframe1a = {
35
+ url : "html/iframe1a.html",
36
+ titleRE : /iframe1a.html/,
37
+ elementId : 'anotherElementWithText',
38
+ elementRE : /block-quote element/
39
+ };
40
+
41
+ var accessChecksForIframe1 = function(flag, iframe, contentOf) {
42
+ expect(6);
43
+
44
+ try{ok (iframe.src == contentOf.url,
45
+ flag + ": Initial iframe src matches test page source");
46
+ }catch(e){print(e);}
47
+
48
+ var idoc = iframe.contentDocument;
49
+ var mtch = idoc.title.match(contentOf.titleRE);
50
+ try{ok (mtch && mtch.length > 0,
51
+ flag + ": Can get 'document' object from test iframe");
52
+ }catch(e){print(e);}
53
+
54
+ var para = idoc.getElementById(contentOf.elementId);
55
+ mtch = para.innerHTML.match(contentOf.elementRE);
56
+ try{ok (mtch && mtch.length > 0,
57
+ flag + ": Can get text from element in an iframe");
58
+ }catch(e){print(e);}
59
+
60
+ try{ok (idoc.parentWindow == iframe.contentWindow,
61
+ flag + ": doc's .parentWindow points to iframe's .contentWindow");
62
+ }catch(e){print(e);}
63
+
64
+ try{ok (idoc.parentWindow.parent == window,
65
+ flag + ": Can follow chain from iframe's doc to containing window");
66
+ }catch(e){print(e);}
67
+
68
+ try{ok (iframe.contentWindow.top == window,
69
+ flag + ": '.top' from iframe does point to top window");
70
+ }catch(e){print(e);}
71
+ };
72
+
73
+ test("IFRAMEs load with accessible content", function() {
74
+ var iframe = document.getElementById('loadediframe');
75
+ // iframe1.html loaded via src= attribute when index.html was parsed
76
+ accessChecksForIframe1("1", iframe, contentOfIframe1);
77
+ });
78
+
79
+
80
+ test("IFRAMEs still load when .src is set after the page is parsed",function() {
81
+ var iframe = document.getElementById('emptyiframe');
82
+ iframe.src = "html/iframe1.html";
83
+ accessChecksForIframe1("2", iframe, contentOfIframe1);
84
+ });
85
+
86
+ test("IFRAMEs reload with accessible content", function() {
87
+ var iframe = document.getElementById('loadediframe');
88
+ iframe.src = "html/iframe1a.html";
89
+ accessChecksForIframe1("3", iframe, contentOfIframe1a);
90
+ });
91
+
92
+
93
+ // this test relies on iframe3.html, iframe2.html, and iframeN.html
94
+ test("IFRAMEs can be nested, created dynamically", function() {
95
+ var startingDepth = 3;
96
+ var endingDepth = 7
97
+ expect(5 + (10*((endingDepth - startingDepth)+1)));
98
+
99
+ // manually load iframe3.html
100
+ var firstIframe = document.getElementById('emptyiframe');
101
+ firstIframe.src = "html/iframe3.html";
102
+
103
+ // iframe3.html contains a static <iframe> element that loads iframe2.html,
104
+ // so at this point, we should have both loaded, with the structure that
105
+ // index.html --contains--> iframe3.html --contains--> iframe2.html
106
+ // w/ id's = emptyiframe nested1Level
107
+
108
+
109
+
110
+ ////////////////////////////////////////
111
+ // first, verify that we've got the structure we expect:
112
+ var mtch = firstIframe.contentDocument.title.match(/nested-IFRAME/);
113
+ try{ok (mtch && mtch.length > 0,
114
+ "top-level IFRAME reloaded from correct source");
115
+ }catch(e){print(e);}
116
+
117
+ var secondIframe = firstIframe.contentDocument.
118
+ getElementById('nested1Level');
119
+ mtch = secondIframe.contentDocument.title.match(/IFRAME loading/);
120
+ try{ok (mtch && mtch.length > 0,
121
+ "can access content of an IFRAME nested in another");
122
+ }catch(e){print(e);}
123
+
124
+ try{ok (secondIframe.contentDocument.parentWindow.parent.parent == window,
125
+ "can follow path from nested IFRAME to root window");
126
+ }catch(e){print(e);}
127
+
128
+ try{ok (secondIframe.contentWindow.parent.parent == window,
129
+ "also path through .contentWindow to root window");
130
+ }catch(e){print(e);}
131
+
132
+ try{ok (secondIframe.contentWindow.top == window,
133
+ "nested IFRAME has correct .top");
134
+ }catch(e){print(e);}
135
+
136
+
137
+ ////////////////////////////////////////
138
+ // OK, now we'll programatically extend the nesting depth from 2 to many
139
+ window.numberNestedIframeLoads = 0;
140
+ window.winLoadCount = 0;
141
+ window.bodyLoadCount = 0;
142
+ window.frameLoadCount = 0;
143
+ for (var c = startingDepth, bottomIframe = secondIframe; c <= endingDepth;
144
+ c++){
145
+
146
+ // add a new iframe within the current leaf iframe
147
+ var newIframe = bottomIframe.contentDocument.createElement("iframe");
148
+ newIframe.setAttribute("id", "iframe_of_depth_" + c);
149
+ newIframe.setAttribute("onload", "iframeOnloadHandler();");
150
+ var bottomBody = bottomIframe.contentDocument.
151
+ getElementsByTagName('body')[0];
152
+
153
+ bottomBody.appendChild(newIframe);
154
+ newIframe.src = "html/iframeN.html";
155
+ bottomIframe = newIframe;
156
+
157
+
158
+
159
+ ////////////////////////////////////////
160
+ // verify contents of just-loaded iframe
161
+ mtch = bottomIframe.contentDocument.getElementById('nestingLevel').
162
+ innerHTML.match(/[0-9]+/);
163
+ try{ok (mtch && mtch.length > 0 && parseInt(mtch[0]) == c,
164
+ "nested " + c + " levels: can access content");
165
+ }catch(e){print(e);}
166
+
167
+ for (var aWindow = bottomIframe.contentWindow, cn = c; cn > 0; cn--)
168
+ aWindow = aWindow.parent;
169
+ try{ok (aWindow == window,
170
+ "nested " + c + " levels: can follow path to root window");
171
+ }catch(e){print(e);}
172
+
173
+ try{ok (bottomIframe.contentWindow.top == window,
174
+ "nested " + c + " levels: IFRAME has correct .top");
175
+ }catch(e){print(e);}
176
+
177
+
178
+
179
+ ////////////////////////////////////////
180
+ // verify events related to iframe load:
181
+ // iframe.onload (container); window.onload and body.onload (contained)
182
+ var num = (c - startingDepth) + 1;
183
+ try{ok (num == window.numberNestedIframeLoads,
184
+ "nested " + c + " levels: event <script> executed");
185
+ }catch(e){print(e);}
186
+
187
+ try{ok (num == window.winLoadCount,
188
+ "nested " + c + " levels: window-onload handler executed");
189
+ }catch(e){print(e);}
190
+ try{ok (num == window.bodyLoadCount,
191
+ "nested " + c + " levels: body-onload handler executed");
192
+ }catch(e){print(e);}
193
+ try{ok (num == window.frameLoadCount,
194
+ "nested " + c + " levels: iframe-onload handler executed");
195
+ }catch(e){print(e);}
196
+
197
+ mtch = bottomIframe.contentWindow.parent.document.
198
+ getElementById("pCreatedIframeOnload" + num).innerHTML.
199
+ match(/para iframe onload ([0-9]+)/);
200
+ try{ok (mtch && mtch.length > 0 && parseInt(mtch[1]) == num,
201
+ "nested " + c + " levels: confirmed iframe-onload");
202
+ }catch(e){print(e);}
203
+ mtch = bottomIframe.contentDocument.
204
+ getElementById("pCreatedWindowOnload" + num).innerHTML.
205
+ match(/para window onload ([0-9]+)/);
206
+ try{ok (mtch && mtch.length > 0 && parseInt(mtch[1]) == num,
207
+ "nested " + c + " levels: confirmed window-onload");
208
+ }catch(e){print(e);}
209
+ mtch = bottomIframe.contentDocument.
210
+ getElementById("pCreatedBodyOnload" + num).innerHTML.
211
+ match(/para body onload ([0-9]+)/);
212
+ try{ok (mtch && mtch.length > 0 && parseInt(mtch[1]) == num,
213
+ "nested " + c + " levels: confirmed body-onload");
214
+ }catch(e){print(e);}
215
+ }
216
+ });
217
+
218
+
219
+ // all tests to next comment rely on content of ../html/iframe2.html
220
+ test("IFRAMEs reload on assignment to 'src'", function() {
221
+ expect(2);
222
+
223
+ var iframe = document.getElementById('loadediframe');
224
+ iframe.src = "html/iframe2.html";
225
+ try{ok (iframe.src == "html/iframe2.html",
226
+ "iframe.src matches value assigned");
227
+ }catch(e){print(e);}
228
+
229
+ var para = iframe.contentDocument.getElementById('aParaInAnIframe');
230
+ var mtch = para.innerHTML.match(/short paragraph/);
231
+ try{ok (mtch && mtch.length > 0,
232
+ "IFRAME reloaded from correct source");
233
+ }catch(e){print(e);}
234
+ });