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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
/*
Copyright 2008-2011 Clipperz Srl
This file is part of Clipperz Community Edition.
Clipperz Community Edition is an online password manager.
For further information about its features and functionalities please
refer to http://www.clipperz.com.
* Clipperz Community Edition is free software: you can redistribute
it and/or modify it under the terms of the GNU Affero General Public
License as published by the Free Software Foundation, either version
3 of the License, or (at your option) any later version.
* Clipperz Community Edition is distributed in the hope that it will
be useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public
License along with Clipperz Community Edition. If not, see
<http://www.gnu.org/licenses/>.
*/
MochiKit.Base.update(Clipperz.Async.Deferred.prototype, {
/*
'_addTest': function(anExpectedValue, aDescription, isDeep, aResult) {
if (isDeep) {
SimpleTest.isDeeply(aResult, anExpectedValue, aDescription);
} else {
SimpleTest.is(aResult, anExpectedValue, aDescription);
}
return aResult;
},
*/
'addTest': function (anExpectedValue, aDescription, isDeep) {
// this.addMethod(this, '_addTest', anExpectedValue, aDescription, isDeep);
// this.addCallback(Clipperz.Async.test, anExpectedValue, aDescription, isDeep);
if (isDeep) {
// SimpleTest.isDeeply(aResult, anExpectedValue, aDescription);
this.addCallback(Clipperz.Async.Test.isDeeply(anExpectedValue, aDescription));
} else {
// SimpleTest.is(aResult, anExpectedValue, aDescription);
this.addCallback(Clipperz.Async.Test.is(anExpectedValue, aDescription));
}
},
//-------------------------------------------------------------------------
'shouldSucceed': function (aDescription) {
this.addCallbackPass(SimpleTest.ok, true, aDescription);
this.addErrbackPass (SimpleTest.ok, false, aDescription);
this.addBoth(MochiKit.Async.succeed, null);
},
'shouldFail': function (aDescription) {
this.addCallbackPass(SimpleTest.ok, false, aDescription);
this.addErrbackPass (SimpleTest.ok, true, aDescription);
this.addBoth(MochiKit.Async.succeed, null);
},
//-------------------------------------------------------------------------
});
Clipperz.Async.Test = {};
MochiKit.Base.update(Clipperz.Async.Test, {
'is': function (anExpectedResult, aDescription) {
return MochiKit.Base.partial(function (anExpectedResult, aDescription, aResult) {
SimpleTest.is(aResult, anExpectedResult, aDescription);
return aResult;
}, anExpectedResult, aDescription);
},
//-------------------------------------------------------------------------
'ok': function (aDescription) {
return MochiKit.Base.partial(function (aDescription, aResult) {
SimpleTest.ok(aResult, aDescription);
return aResult;
}, aDescription);
},
//-------------------------------------------------------------------------
'fail': function(aDescription) {
return MochiKit.Base.partial(function (aDescription, aResult) {
SimpleTest.ok(!aResult, aDescription);
return aResult;
}, aDescription);
},
//-------------------------------------------------------------------------
'isDeeply': function (anExpectedResult, aDescription) {
return MochiKit.Base.partial(function (anExpectedResult, aDescription, aResult) {
SimpleTest.isDeeply(aResult, anExpectedResult, aDescription);
return aResult;
}, anExpectedResult, aDescription);
},
//-------------------------------------------------------------------------
__syntaxFix__: "syntax fix"
});
SimpleTest.runDeferredTests = function (aName, aTestSet, aTestArguments) {
try {
var deferredTests;
var aTestName;
var title;
deferredTests = new Clipperz.Async.Deferred(aName + " <deferred test set>", aTestArguments);
title = aName;
aTestName = window.location.href.match(/#.*/);
if (aTestName && (aTestName != '#')) {
aTestName = aTestName[0].slice(1);
if (aTestName in aTestSet) {
//Clipperz.log("single test execution, via fragment identifier", aTestName);
title += ' [' + aTestName + ']';
deferredTests.addCallback(aTestSet[aTestName], aTestArguments);
deferredTests.addErrback(SimpleTest.ok, false, aTestName);
} else {
title = 'WRONG TEST NAME'
deferredTests.addBoth(is, aTestName, null, "Wrong test name selected to run");
}
} else {
for (aTestName in aTestSet) {
deferredTests.addCallback(aTestSet[aTestName], aTestArguments);
deferredTests.addErrback(SimpleTest.ok, false, aTestName);
deferredTests.addBoth(MochiKit.Async.wait, 0.5);
}
deferredTests.addBoth(is, true, true, "FINISH: completed the full stack of tests");
}
MochiKit.DOM.currentDocument().title = title;
deferredTests.addBoth(SimpleTest.finish);
deferredTests.callback();
SimpleTest.waitForExplicitFinish();
} catch (err) {
var s = "test suite failure!\n";
var o = {};
var k = null;
for (k in err) {
// ensure unique keys?!
if (!o[k]) {
s += k + ": " + err[k] + "\n";
o[k] = err[k];
}
}
ok ( false, s );
}
}
|