@@ -6,30 +6,79 @@ 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
+
13
+ function checkStatus ( ) {
14
+ ready = win && win . callbackFired ;
15
+ if ( ready ) cb ( ) ;
16
+ return ready ;
17
+ }
18
+
19
+ function newFrame ( url ) {
20
+ var iframe = new IFrame ( {
21
+ src : 'base/Tests/DOMReady/' + url
22
+ } ) ;
23
+ document . getElement ( 'body' ) . adopt ( iframe ) ;
24
+ return iframe ;
27
25
}
28
- domreadyCallbacks[i]();
29
- };
30
26
31
- window.addEvent = function(){};
27
+ beforeEach ( function ( ) {
28
+ cb = jasmine . createSpy ( 'DOMReady!' ) ;
29
+ } ) ;
32
30
33
- var Element = this.Element || {};
34
- Element.Events = {};
35
- */
31
+ afterEach ( function ( ) {
32
+ frame . destroy ( ) ;
33
+ win = cb = frame = ready = null ;
34
+ } ) ;
35
+
36
+ it ( 'should fire DOMReady when the DOM is ready' , function ( ) {
37
+ frame = newFrame ( 'DOMReady.head.html' ) ;
38
+ frame . addEvent ( 'load' , function ( ) {
39
+ win = frame . contentWindow ;
40
+ } ) ;
41
+ waitsFor ( function ( ) {
42
+ return checkStatus ( ) ;
43
+ } , "the iframe to load" , 1500 ) ;
44
+ runs ( function ( ) {
45
+ expect ( cb ) . toHaveBeenCalled ( ) ;
46
+ } ) ;
47
+ } ) ;
48
+
49
+ it ( 'should fire DOMReady when a new `addEvent("domready"` is added' , function ( ) {
50
+ frame = newFrame ( 'DOMReady.onAdd.html' ) ;
51
+ frame . addEvent ( 'load' , function ( ) {
52
+ win = frame . contentWindow ;
53
+ win . addEvent ( 'domready' , win . callback ) ;
54
+ } ) ;
55
+ waitsFor ( function ( ) {
56
+ return checkStatus ( ) ;
57
+ } , "the iframe to load" , 1500 ) ;
58
+ runs ( function ( ) {
59
+ expect ( cb ) . toHaveBeenCalled ( ) ;
60
+ } ) ;
61
+ } ) ;
62
+
63
+ it ( 'should fire when MooTools was loaded into a already-ready page' , function ( ) {
64
+ frame = newFrame ( 'DOMReady.delayed.html' ) ;
65
+ var ready ;
66
+ frame . addEvent ( 'load' , function ( ) {
67
+ win = frame . contentWindow ;
68
+ expect ( win . MooTools ) . toBeFalsy ( ) ; // because MooTools should not be loaded yet
69
+ var i = setInterval ( function ( ) {
70
+ if ( win . addEvent && win . callback ) {
71
+ win . addEvent ( 'domready' , win . callback ) ;
72
+ if ( ready ) clearInterval ( i ) ;
73
+ }
74
+ } , 50 ) ;
75
+ } ) ;
76
+ waitsFor ( function ( ) {
77
+ return checkStatus ( ) ;
78
+ } , "the iframe to load and MooTools to be deployed" , 6000 ) ;
79
+ runs ( function ( ) {
80
+ expect ( cb ) . toHaveBeenCalled ( ) ;
81
+ } ) ;
82
+ } ) ;
83
+
84
+ } ) ;
0 commit comments