@@ -6,30 +6,96 @@ provides: ~
6
6
...
7
7
*/
8
8
9
- /* todo
10
- document.addListener = function(type, fn){
11
- if (this.addEventListener) this.addEventListener(type, fn, false);
12
- else this.attachEvent('on' + type, fn);
13
- return this;
14
- };
15
-
16
- document.removeListener = function(type, fn){
17
- if (this.removeEventListener) this.removeEventListener(type, fn, false);
18
- else this.detachEvent('on' + type, fn);
19
- return this;
20
- };
21
-
22
-
23
- window.fireEvent =
24
- document.fireEvent = function(type){
25
- if (type == 'domready')
26
- for (var i = 0; i < domreadyCallbacks.length; ++i){
9
+ describe ( "DOMReady" , function ( ) {
10
+
11
+ var win , frame , cb , ready ;
12
+ function checkStatus ( ) {
13
+ ready = win && win . callbackFired ;
14
+ if ( ready ) cb ( ) ;
15
+ return ready ;
27
16
}
28
- domreadyCallbacks[i]();
29
- };
30
17
31
- window.addEvent = function(){};
18
+ function newFrame ( url ) {
19
+ var iframe = new IFrame ( {
20
+ src : 'specsserver/' + url
21
+ } ) ;
22
+ document . getElement ( 'body' ) . adopt ( iframe ) ;
23
+ return iframe ;
24
+ }
25
+
26
+ beforeEach ( function ( ) {
27
+ cb = jasmine . createSpy ( 'DOMReady!' ) ;
28
+ } ) ;
29
+
30
+ afterEach ( function ( ) {
31
+ frame . destroy ( ) ;
32
+ win = cb = frame = ready = null ;
33
+ } ) ;
34
+
35
+ it ( 'should fire DOMReady, after flushing, when the DOM is ready' , function ( ) {
36
+ frame = newFrame ( 'DOMReady.flushA.html~DOMReady.flushB.html' ) ;
37
+ frame . addEvent ( 'load' , function ( ) {
38
+ win = frame . contentWindow ;
39
+ expect ( win . moments [ 0 ] ) . toEqual ( 'loading' ) ;
40
+ expect ( win . moments [ 1 ] ) . toEqual ( 'loading' ) ;
41
+ expect ( win . moments [ 2 ] == 'interactive' || win . moments [ 2 ] == 'complete' ) . toBeTruthy ( ) ;
42
+ } ) ;
43
+
44
+ waitsFor ( function ( ) {
45
+ return checkStatus ( ) ;
46
+ } , "the iframe to load" , 8000 ) ;
47
+ runs ( function ( ) {
48
+ expect ( cb ) . toHaveBeenCalled ( ) ;
49
+ } ) ;
50
+ } ) ;
51
+
52
+ it ( 'should fire DOMReady when the DOM is ready' , function ( ) {
53
+ frame = newFrame ( 'DOMReady.head.html' ) ;
54
+ frame . addEvent ( 'load' , function ( ) {
55
+ win = frame . contentWindow ;
56
+ } ) ;
57
+ waitsFor ( function ( ) {
58
+ return checkStatus ( ) ;
59
+ } , "the iframe to load" , 1500 ) ;
60
+ runs ( function ( ) {
61
+ expect ( cb ) . toHaveBeenCalled ( ) ;
62
+ } ) ;
63
+ } ) ;
64
+
65
+ it ( 'should fire DOMReady when a new `addEvent("domready"` is added' , function ( ) {
66
+ frame = newFrame ( 'DOMReady.onAdd.html' ) ;
67
+ frame . addEvent ( 'load' , function ( ) {
68
+ win = frame . contentWindow ;
69
+ win . addEvent ( 'domready' , win . callback ) ;
70
+ } ) ;
71
+ waitsFor ( function ( ) {
72
+ return checkStatus ( ) ;
73
+ } , "the iframe to load" , 1500 ) ;
74
+ runs ( function ( ) {
75
+ expect ( cb ) . toHaveBeenCalled ( ) ;
76
+ } ) ;
77
+ } ) ;
78
+
79
+ it ( 'should fire when MooTools was loaded into a already-ready page' , function ( ) {
80
+ frame = newFrame ( 'DOMReady.delayed.html' ) ;
81
+ var ready ;
82
+ frame . addEvent ( 'load' , function ( ) {
83
+ win = frame . contentWindow ;
84
+ expect ( win . MooTools ) . toBeFalsy ( ) ; // because MooTools should not be loaded yet
85
+ var i = setInterval ( function ( ) {
86
+ if ( win . addEvent && win . callback ) {
87
+ win . addEvent ( 'domready' , win . callback ) ;
88
+ if ( ready ) clearInterval ( i ) ;
89
+ }
90
+ } , 50 ) ;
91
+ } ) ;
92
+ waitsFor ( function ( ) {
93
+ return checkStatus ( ) ;
94
+ } , "the iframe to load and MooTools to be deployed" , 6000 ) ;
95
+ runs ( function ( ) {
96
+ expect ( cb ) . toHaveBeenCalled ( ) ;
97
+ } ) ;
98
+ } ) ;
99
+
100
+ } ) ;
32
101
33
- var Element = this.Element || {};
34
- Element.Events = {};
35
- */
0 commit comments