forked from jeresig/env-js
/
spec.js
129 lines (98 loc) · 3.32 KB
/
spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/**
* @todo: document
*/
var _load,
_start,
_count = 1,
_starttime = new Date().getTime(),
_endtime;
try{
_load = load;
_load('test/specs/qunit.js');
_start = QUnit.start;
}catch(e){
_load = _start = function(){};
}
QUnit.log = function(result, message){
if(console)console.log('(' + (_count++) + ')[' +
((!!result) ? 'PASS' : 'FAIL') + '] ' + message);
};
QUnit.done = function( fail, pass){
if(console){
_endtime = new Date().getTime();
console.log('\n\tRESULTS: ( of '+(pass+fail)+' total tests )');
console.log('\t\tPASSED: ' +pass);
console.log('\t\tFAILED: ' +fail);
console.log('\tCompleted in '+(_endtime-_starttime)+' milliseconds.\n');
}
};
QUnit.init();
_load('dist/platform/core.js');
_load('dist/platform/rhino.js');
_load('dist/console.js');
_load('src/common/__extend__.js');
_load('settings.js');
module('rhino');
test('Envjs Platform Interfaces Available', function(){
ok(Envjs, 'Envjs defined');
ok(Envjs.log.toString() !== 'function(){};', 'Envjs.log defined');
ok(Envjs.proxy.toString() !== 'function(){};', 'Envjs.proxy defined');
});
var document = null,
path = 'specs/env/spec.html';
test('Envjs.location', function(){
location = Envjs.location('specs/env/spec.html', 'http://envjs.com/abc123/');
ok(location, 'Able to create Location');
equals(location, 'http://envjs.com/abc123/'+path, 'location');
equals(location.toString(), 'http://envjs.com/abc123/'+path, 'location');
document = {baseURI:'http://envjs.com/'};
location = Envjs.location('specs/env/spec.html');
ok(location, 'Able to create Location');
equals(location, document.baseURI+path, 'location');
equals(location.toString(), document.baseURI+path, 'location');
document = null;
location = Envjs.location('http://envjs.com/specs/env/spec.html');
ok(location, 'Able to create Location');
equals(location, 'http://envjs.com/specs/env/spec.html', 'location');
equals(location.toString(), 'http://envjs.com/specs/env/spec.html', 'location');
});
//Foo is a minimal window implementation
var Foo = function(scope, parent){
var $proxy = new Envjs.proxy(scope, parent),
$parent = parent;
scope.__proxy__ = $proxy;
return __extend__(scope,{
get parent(){
return parent;
},
get top(){
var _parent = $parent;
while(scope && _parent && scope !== _parent){
if(_parent === _parent.parent)break;
_parent = _parent.parent;
}
return _parent || null;
},
get abcdefghi(){
return $proxy;
}
});
};
var _this = this;
test('Envjs.proxy', function(){
var frame = {},
subframe = {};
new Foo(_this, _this);
equals(abcdefghi.parent, abcdefghi, '.parent');
equals(abcdefghi.top, abcdefghi, '.top');
new Foo(frame, abcdefghi);
equals(frame.parent, abcdefghi, '.parent');
new Foo(subframe, frame);
equals(subframe.parent, frame, '.parent');
equals(subframe.parent.parent, abcdefghi, '.parent.parent');
equals(subframe.top, abcdefghi, '.top');
});
Envjs.onExit(function(){
console.log('onExit!');
});
_start();