summaryrefslogtreecommitdiff
path: root/frontend/gamma/tests/SimpleTest/SimpleTest.Async.js
Unidiff
Diffstat (limited to 'frontend/gamma/tests/SimpleTest/SimpleTest.Async.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/gamma/tests/SimpleTest/SimpleTest.Async.js22
1 files changed, 10 insertions, 12 deletions
diff --git a/frontend/gamma/tests/SimpleTest/SimpleTest.Async.js b/frontend/gamma/tests/SimpleTest/SimpleTest.Async.js
index 3633182..268a04d 100644
--- a/frontend/gamma/tests/SimpleTest/SimpleTest.Async.js
+++ b/frontend/gamma/tests/SimpleTest/SimpleTest.Async.js
@@ -1,166 +1,164 @@
1/* 1/*
2 2
3Copyright 2008-2011 Clipperz Srl 3Copyright 2008-2013 Clipperz Srl
4 4
5This file is part of Clipperz Community Edition. 5This file is part of Clipperz, the online password manager.
6Clipperz Community Edition is an online password manager.
7For further information about its features and functionalities please 6For further information about its features and functionalities please
8refer to http://www.clipperz.com. 7refer to http://www.clipperz.com.
9 8
10* Clipperz Community Edition is free software: you can redistribute 9* Clipperz is free software: you can redistribute it and/or modify it
11 it and/or modify it under the terms of the GNU Affero General Public 10 under the terms of the GNU Affero General Public License as published
12 License as published by the Free Software Foundation, either version 11 by the Free Software Foundation, either version 3 of the License, or
13 3 of the License, or (at your option) any later version. 12 (at your option) any later version.
14 13
15* Clipperz Community Edition is distributed in the hope that it will 14* Clipperz is distributed in the hope that it will be useful, but
16 be useful, but WITHOUT ANY WARRANTY; without even the implied 15 WITHOUT ANY WARRANTY; without even the implied warranty of
17 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU Affero General Public License for more details. 17 See the GNU Affero General Public License for more details.
19 18
20* You should have received a copy of the GNU Affero General Public 19* You should have received a copy of the GNU Affero General Public
21 License along with Clipperz Community Edition. If not, see 20 License along with Clipperz. If not, see http://www.gnu.org/licenses/.
22 <http://www.gnu.org/licenses/>.
23 21
24*/ 22*/
25 23
26MochiKit.Base.update(Clipperz.Async.Deferred.prototype, { 24MochiKit.Base.update(Clipperz.Async.Deferred.prototype, {
27/* 25/*
28 '_addTest': function(anExpectedValue, aDescription, isDeep, aResult) { 26 '_addTest': function(anExpectedValue, aDescription, isDeep, aResult) {
29 if (isDeep) { 27 if (isDeep) {
30 SimpleTest.isDeeply(aResult, anExpectedValue, aDescription); 28 SimpleTest.isDeeply(aResult, anExpectedValue, aDescription);
31 } else { 29 } else {
32 SimpleTest.is(aResult, anExpectedValue, aDescription); 30 SimpleTest.is(aResult, anExpectedValue, aDescription);
33 } 31 }
34 32
35 return aResult; 33 return aResult;
36 }, 34 },
37*/ 35*/
38 'addTest': function (anExpectedValue, aDescription, isDeep) { 36 'addTest': function (anExpectedValue, aDescription, isDeep) {
39 // this.addMethod(this, '_addTest', anExpectedValue, aDescription, isDeep); 37 // this.addMethod(this, '_addTest', anExpectedValue, aDescription, isDeep);
40 // this.addCallback(Clipperz.Async.test, anExpectedValue, aDescription, isDeep); 38 // this.addCallback(Clipperz.Async.test, anExpectedValue, aDescription, isDeep);
41 39
42 if (isDeep) { 40 if (isDeep) {
43 // SimpleTest.isDeeply(aResult, anExpectedValue, aDescription); 41 // SimpleTest.isDeeply(aResult, anExpectedValue, aDescription);
44 this.addCallback(Clipperz.Async.Test.isDeeply(anExpectedValue, aDescription)); 42 this.addCallback(Clipperz.Async.Test.isDeeply(anExpectedValue, aDescription));
45 } else { 43 } else {
46 // SimpleTest.is(aResult, anExpectedValue, aDescription); 44 // SimpleTest.is(aResult, anExpectedValue, aDescription);
47 this.addCallback(Clipperz.Async.Test.is(anExpectedValue, aDescription)); 45 this.addCallback(Clipperz.Async.Test.is(anExpectedValue, aDescription));
48 } 46 }
49 }, 47 },
50 48
51 //------------------------------------------------------------------------- 49 //-------------------------------------------------------------------------
52 50
53 'shouldSucceed': function (aDescription) { 51 'shouldSucceed': function (aDescription) {
54 this.addCallbackPass(SimpleTest.ok, true, aDescription); 52 this.addCallbackPass(SimpleTest.ok, true, aDescription);
55 this.addErrbackPass (SimpleTest.ok, false, aDescription); 53 this.addErrbackPass (SimpleTest.ok, false, aDescription);
56 this.addBoth(MochiKit.Async.succeed, null); 54 this.addBoth(MochiKit.Async.succeed, null);
57 }, 55 },
58 56
59 'shouldFail': function (aDescription) { 57 'shouldFail': function (aDescription) {
60 this.addCallbackPass(SimpleTest.ok, false, aDescription); 58 this.addCallbackPass(SimpleTest.ok, false, aDescription);
61 this.addErrbackPass (SimpleTest.ok, true, aDescription); 59 this.addErrbackPass (SimpleTest.ok, true, aDescription);
62 this.addBoth(MochiKit.Async.succeed, null); 60 this.addBoth(MochiKit.Async.succeed, null);
63 }, 61 },
64 62
65 //------------------------------------------------------------------------- 63 //-------------------------------------------------------------------------
66 64
67}); 65});
68 66
69 67
70Clipperz.Async.Test = {}; 68Clipperz.Async.Test = {};
71MochiKit.Base.update(Clipperz.Async.Test, { 69MochiKit.Base.update(Clipperz.Async.Test, {
72 70
73 'is': function (anExpectedResult, aDescription) { 71 'is': function (anExpectedResult, aDescription) {
74 return MochiKit.Base.partial(function (anExpectedResult, aDescription, aResult) { 72 return MochiKit.Base.partial(function (anExpectedResult, aDescription, aResult) {
75 SimpleTest.is(aResult, anExpectedResult, aDescription); 73 SimpleTest.is(aResult, anExpectedResult, aDescription);
76 74
77 return aResult; 75 return aResult;
78 }, anExpectedResult, aDescription); 76 }, anExpectedResult, aDescription);
79 }, 77 },
80 78
81 //------------------------------------------------------------------------- 79 //-------------------------------------------------------------------------
82 80
83 'ok': function (aDescription) { 81 'ok': function (aDescription) {
84 return MochiKit.Base.partial(function (aDescription, aResult) { 82 return MochiKit.Base.partial(function (aDescription, aResult) {
85 SimpleTest.ok(aResult, aDescription); 83 SimpleTest.ok(aResult, aDescription);
86 84
87 return aResult; 85 return aResult;
88 }, aDescription); 86 }, aDescription);
89 }, 87 },
90 88
91 //------------------------------------------------------------------------- 89 //-------------------------------------------------------------------------
92 90
93 'fail': function(aDescription) { 91 'fail': function(aDescription) {
94 return MochiKit.Base.partial(function (aDescription, aResult) { 92 return MochiKit.Base.partial(function (aDescription, aResult) {
95 SimpleTest.ok(!aResult, aDescription); 93 SimpleTest.ok(!aResult, aDescription);
96 94
97 return aResult; 95 return aResult;
98 }, aDescription); 96 }, aDescription);
99 }, 97 },
100 98
101 //------------------------------------------------------------------------- 99 //-------------------------------------------------------------------------
102 100
103 'isDeeply': function (anExpectedResult, aDescription) { 101 'isDeeply': function (anExpectedResult, aDescription) {
104 return MochiKit.Base.partial(function (anExpectedResult, aDescription, aResult) { 102 return MochiKit.Base.partial(function (anExpectedResult, aDescription, aResult) {
105 SimpleTest.isDeeply(aResult, anExpectedResult, aDescription); 103 SimpleTest.isDeeply(aResult, anExpectedResult, aDescription);
106 104
107 return aResult; 105 return aResult;
108 }, anExpectedResult, aDescription); 106 }, anExpectedResult, aDescription);
109 }, 107 },
110 108
111 //------------------------------------------------------------------------- 109 //-------------------------------------------------------------------------
112 __syntaxFix__: "syntax fix" 110 __syntaxFix__: "syntax fix"
113}); 111});
114 112
115 113
116SimpleTest.runDeferredTests = function (aName, aTestSet, aTestArguments) { 114SimpleTest.runDeferredTests = function (aName, aTestSet, aTestArguments) {
117 try { 115 try {
118 var deferredTests; 116 var deferredTests;
119 var aTestName; 117 var aTestName;
120 var title; 118 var title;
121 119
122 deferredTests = new Clipperz.Async.Deferred(aName + " <deferred test set>", aTestArguments); 120 deferredTests = new Clipperz.Async.Deferred(aName + " <deferred test set>", aTestArguments);
123 121
124 title = aName; 122 title = aName;
125 123
126 aTestName = window.location.href.match(/#.*/); 124 aTestName = window.location.href.match(/#.*/);
127 if (aTestName && (aTestName != '#')) { 125 if (aTestName && (aTestName != '#')) {
128 aTestName = aTestName[0].slice(1); 126 aTestName = aTestName[0].slice(1);
129 if (aTestName in aTestSet) { 127 if (aTestName in aTestSet) {
130 //Clipperz.log("single test execution, via fragment identifier", aTestName); 128 //Clipperz.log("single test execution, via fragment identifier", aTestName);
131 title += ' [' + aTestName + ']'; 129 title += ' [' + aTestName + ']';
132 deferredTests.addCallback(aTestSet[aTestName], aTestArguments); 130 deferredTests.addCallback(aTestSet[aTestName], aTestArguments);
133 deferredTests.addErrback(SimpleTest.ok, false, aTestName); 131 deferredTests.addErrback(SimpleTest.ok, false, aTestName);
134 } else { 132 } else {
135 title = 'WRONG TEST NAME' 133 title = 'WRONG TEST NAME'
136 deferredTests.addBoth(is, aTestName, null, "Wrong test name selected to run"); 134 deferredTests.addBoth(is, aTestName, null, "Wrong test name selected to run");
137 } 135 }
138 } else { 136 } else {
139 for (aTestName in aTestSet) { 137 for (aTestName in aTestSet) {
140 deferredTests.addCallback(aTestSet[aTestName], aTestArguments); 138 deferredTests.addCallback(aTestSet[aTestName], aTestArguments);
141 deferredTests.addErrback(SimpleTest.ok, false, aTestName); 139 deferredTests.addErrback(SimpleTest.ok, false, aTestName);
142 deferredTests.addBoth(MochiKit.Async.wait, 0.5); 140 deferredTests.addBoth(MochiKit.Async.wait, 0.5);
143 } 141 }
144 deferredTests.addBoth(is, true, true, "FINISH: completed the full stack of tests"); 142 deferredTests.addBoth(is, true, true, "FINISH: completed the full stack of tests");
145 } 143 }
146 144
147 MochiKit.DOM.currentDocument().title = title; 145 MochiKit.DOM.currentDocument().title = title;
148 146
149 deferredTests.addBoth(SimpleTest.finish); 147 deferredTests.addBoth(SimpleTest.finish);
150 deferredTests.callback(); 148 deferredTests.callback();
151 149
152 SimpleTest.waitForExplicitFinish(); 150 SimpleTest.waitForExplicitFinish();
153 } catch (err) { 151 } catch (err) {
154 var s = "test suite failure!\n"; 152 var s = "test suite failure!\n";
155 var o = {}; 153 var o = {};
156 var k = null; 154 var k = null;
157 for (k in err) { 155 for (k in err) {
158 // ensure unique keys?! 156 // ensure unique keys?!
159 if (!o[k]) { 157 if (!o[k]) {
160 s += k + ": " + err[k] + "\n"; 158 s += k + ": " + err[k] + "\n";
161 o[k] = err[k]; 159 o[k] = err[k];
162 } 160 }
163 } 161 }
164 ok ( false, s ); 162 ok ( false, s );
165 } 163 }
166} 164}