Diffstat (limited to 'frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Test.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Test.js | 28 |
1 files changed, 10 insertions, 18 deletions
diff --git a/frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Test.js b/frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Test.js index d554c6a..d459726 100644 --- a/frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Test.js +++ b/frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Test.js | |||
@@ -1,164 +1,156 @@ | |||
1 | /* | 1 | /* |
2 | 2 | ||
3 | Copyright 2008-2011 Clipperz Srl | 3 | Copyright 2008-2013 Clipperz Srl |
4 | 4 | ||
5 | This file is part of Clipperz Community Edition. | 5 | This file is part of Clipperz, the online password manager. |
6 | Clipperz Community Edition is an online password manager. | ||
7 | For further information about its features and functionalities please | 6 | For further information about its features and functionalities please |
8 | refer to http://www.clipperz.com. | 7 | refer 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 | ||
26 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | 24 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } |
27 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } | 25 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } |
28 | if (typeof(Clipperz.PM.Proxy) == 'undefined') { Clipperz.PM.Proxy = {}; } | 26 | if (typeof(Clipperz.PM.Proxy) == 'undefined') { Clipperz.PM.Proxy = {}; } |
29 | 27 | ||
30 | //============================================================================= | 28 | //============================================================================= |
31 | 29 | ||
32 | Clipperz.PM.Proxy.Test = function(args) { | 30 | Clipperz.PM.Proxy.Test = function(args) { |
33 | Clipperz.PM.Proxy.Test.superclass.constructor.call(this, args); | 31 | Clipperz.PM.Proxy.Test.superclass.constructor.call(this, args); |
34 | 32 | ||
35 | args = args || {}; | 33 | args = args || {}; |
36 | 34 | ||
37 | this._expectedRequests = (args.shouldCheckExpectedRequests === true) ? [] : null; | 35 | this._expectedRequests = (args.shouldCheckExpectedRequests === true) ? [] : null; |
38 | this._isExpectingRequests = true; | 36 | this._isExpectingRequests = true; |
39 | this._unexpectedRequests = []; | 37 | this._unexpectedRequests = []; |
40 | 38 | ||
41 | this.dataStore().resetData(); | 39 | this.dataStore().resetData(); |
42 | 40 | ||
43 | return this; | 41 | return this; |
44 | } | 42 | } |
45 | 43 | ||
46 | Clipperz.Base.extend(Clipperz.PM.Proxy.Test, Clipperz.PM.Proxy.Offline, { | 44 | Clipperz.Base.extend(Clipperz.PM.Proxy.Test, Clipperz.PM.Proxy.Offline, { |
47 | 45 | ||
48 | 'toString': function() { | 46 | 'toString': function() { |
49 | return "Clipperz.PM.Proxy.Test"; | 47 | return "Clipperz.PM.Proxy.Test"; |
50 | }, | 48 | }, |
51 | 49 | ||
52 | //========================================================================= | 50 | //========================================================================= |
53 | 51 | ||
54 | 'expectedRequests': function () { | 52 | 'expectedRequests': function () { |
55 | return this._expectedRequests; | 53 | return this._expectedRequests; |
56 | }, | 54 | }, |
57 | 55 | ||
58 | //------------------------------------------------------------------------- | 56 | //------------------------------------------------------------------------- |
59 | 57 | ||
60 | 'shouldCheckExpectedRequests': function () { | 58 | 'shouldCheckExpectedRequests': function () { |
61 | return (this._expectedRequests != null); | 59 | return (this._expectedRequests != null); |
62 | }, | 60 | }, |
63 | 61 | ||
64 | 'setShouldCheckExpectedRequests': function(aValue) { | 62 | 'setShouldCheckExpectedRequests': function(aValue) { |
65 | if (aValue) { | 63 | if (aValue) { |
66 | this._expectedRequests = aValue; | 64 | this._expectedRequests = aValue; |
67 | } else { | 65 | } else { |
68 | this._expectedRequests = null; | 66 | this._expectedRequests = null; |
69 | } | 67 | } |
70 | }, | 68 | }, |
71 | 69 | ||
72 | //------------------------------------------------------------------------- | 70 | //------------------------------------------------------------------------- |
73 | 71 | ||
74 | 'shouldNotReceiveAnyFurtherRequest': function () { | 72 | 'shouldNotReceiveAnyFurtherRequest': function () { |
75 | this._isExpectingRequests = false; | 73 | this._isExpectingRequests = false; |
76 | }, | 74 | }, |
77 | 75 | ||
78 | 'mayReceiveMoreRequests': function () { | 76 | 'mayReceiveMoreRequests': function () { |
79 | this._isExpectingRequests = true; | 77 | this._isExpectingRequests = true; |
80 | this.resetUnexpectedRequests(); | 78 | this.resetUnexpectedRequests(); |
81 | }, | 79 | }, |
82 | 80 | ||
83 | 'isExpectingRequests': function () { | 81 | 'isExpectingRequests': function () { |
84 | return this._isExpectingRequests; | 82 | return this._isExpectingRequests; |
85 | }, | 83 | }, |
86 | 84 | ||
87 | //------------------------------------------------------------------------- | 85 | //------------------------------------------------------------------------- |
88 | 86 | ||
89 | 'unexpectedRequests': function () { | 87 | 'unexpectedRequests': function () { |
90 | return this._unexpectedRequests; | 88 | return this._unexpectedRequests; |
91 | }, | 89 | }, |
92 | 90 | ||
93 | 'resetUnexpectedRequests': function () { | 91 | 'resetUnexpectedRequests': function () { |
94 | this._unexpectedRequests = []; | 92 | this._unexpectedRequests = []; |
95 | }, | 93 | }, |
96 | 94 | ||
97 | //------------------------------------------------------------------------- | 95 | //------------------------------------------------------------------------- |
98 | 96 | ||
99 | 'testExpectedRequestParameters': function (aPath, anActualRequest, anExpectedRequest) { | 97 | 'testExpectedRequestParameters': function (aPath, anActualRequest, anExpectedRequest) { |
100 | var aKey; | 98 | var aKey; |
101 | //console.log(">>> Proxy.testExpectedRequestParameters [" + aPath + "]", anActualRequest, anExpectedRequest); | ||
102 | for (aKey in anExpectedRequest) { | 99 | for (aKey in anExpectedRequest) { |
103 | if (typeof(anActualRequest[aKey]) == 'undefined') { | 100 | if (typeof(anActualRequest[aKey]) == 'undefined') { |
104 | throw "the expected paramter [" + aKey + "] is missing from the actual request"; | 101 | throw "the expected paramter [" + aKey + "] is missing from the actual request"; |
105 | } | 102 | } |
106 | if (typeof(anExpectedRequest[aKey]) == 'object') { | 103 | if (typeof(anExpectedRequest[aKey]) == 'object') { |
107 | this.testExpectedRequestParameters(aPath + "." + aKey, anActualRequest[aKey], anExpectedRequest[aKey]) | 104 | this.testExpectedRequestParameters(aPath + "." + aKey, anActualRequest[aKey], anExpectedRequest[aKey]) |
108 | } else { | 105 | } else { |
109 | if (! anExpectedRequest[aKey](anActualRequest[aKey])) { | 106 | if (! anExpectedRequest[aKey](anActualRequest[aKey])) { |
110 | throw "wrong value for paramter [" + aKey + "]; got '" + anActualRequest[aKey] + "'"; | 107 | throw "wrong value for paramter [" + aKey + "]; got '" + anActualRequest[aKey] + "'"; |
111 | } | 108 | } |
112 | } | 109 | } |
113 | } | 110 | } |
114 | //console.log("<<< Proxy.testExpectedRequestParameters"); | ||
115 | }, | 111 | }, |
116 | 112 | ||
117 | //------------------------------------------------------------------------- | 113 | //------------------------------------------------------------------------- |
118 | 114 | ||
119 | 'checkRequest': function(aFunctionName, someParameters) { | 115 | 'checkRequest': function(aFunctionName, someParameters) { |
120 | if (this.shouldCheckExpectedRequests()) { | 116 | if (this.shouldCheckExpectedRequests()) { |
121 | var expectedRequest; | 117 | var expectedRequest; |
122 | 118 | ||
123 | //console.log(">>> Proxy.Test.checkRequest - " + aFunctionName, someParameters); | ||
124 | expectedRequest = this.expectedRequests().pop(); | 119 | expectedRequest = this.expectedRequests().pop(); |
125 | //console.log("--- Proxy.Test.checkRequest - expectedRequest", expectedRequest); | ||
126 | if (expectedRequest == null) { | 120 | if (expectedRequest == null) { |
127 | throw "Proxy.Test.sentMessage: no expected result specified. Got request '" + aFunctionName + "': " + someParameters; | 121 | throw "Proxy.Test.sentMessage: no expected result specified. Got request '" + aFunctionName + "': " + someParameters; |
128 | } | 122 | } |
129 | 123 | ||
130 | try { | 124 | try { |
131 | if (aFunctionName != expectedRequest.functionName) { | 125 | if (aFunctionName != expectedRequest.functionName) { |
132 | throw "wrong function name. Got '" + aFunctionName + "', expected '" + expectedRequest.request.functionName + "'"; | 126 | throw "wrong function name. Got '" + aFunctionName + "', expected '" + expectedRequest.request.functionName + "'"; |
133 | } | 127 | } |
134 | 128 | ||
135 | this.testExpectedRequestParameters("parameters", someParameters, expectedRequest.parameters); | 129 | this.testExpectedRequestParameters("parameters", someParameters, expectedRequest.parameters); |
136 | } catch(exception) { | 130 | } catch(exception) { |
137 | //console.log("EXCEPTION: Proxy.Test.sentMessage[" + expectedRequest.name + "]", exception) | ||
138 | throw "Proxy.Test.sentMessage[" + expectedRequest.name + "]: " + exception; | 131 | throw "Proxy.Test.sentMessage[" + expectedRequest.name + "]: " + exception; |
139 | } | 132 | } |
140 | } | 133 | } |
141 | //console.log("<<< Proxy.Test.checkRequest"); | ||
142 | }, | 134 | }, |
143 | 135 | ||
144 | //========================================================================= | 136 | //========================================================================= |
145 | 137 | ||
146 | 'sendMessage': function(aFunctionName, someParameters) { | 138 | 'sendMessage': function(aFunctionName, someParameters) { |
147 | var result; | 139 | var result; |
148 | 140 | ||
149 | if (this.isExpectingRequests() == false) { | 141 | if (this.isExpectingRequests() == false) { |
150 | // throw Clipperz.PM.Connection.exception.UnexpectedRequest; | 142 | // throw Clipperz.PM.Connection.exception.UnexpectedRequest; |
151 | Clipperz.log("UNEXPECTED REQUEST " + aFunctionName /* + ": " + Clipperz.Base.serializeJSON(someParameters) */); | 143 | Clipperz.log("UNEXPECTED REQUEST " + aFunctionName /* + ": " + Clipperz.Base.serializeJSON(someParameters) */); |
152 | this.unexpectedRequests().push({'functionName':aFunctionName, 'someParameters': someParameters}); | 144 | this.unexpectedRequests().push({'functionName':aFunctionName, 'someParameters': someParameters}); |
153 | }; | 145 | }; |
154 | this.checkRequest(aFunctionName, someParameters); | 146 | this.checkRequest(aFunctionName, someParameters); |
155 | result = Clipperz.PM.Proxy.Test.superclass.sendMessage.call(this, aFunctionName, someParameters); | 147 | result = Clipperz.PM.Proxy.Test.superclass.sendMessage.call(this, aFunctionName, someParameters); |
156 | 148 | ||
157 | return result; | 149 | return result; |
158 | }, | 150 | }, |
159 | 151 | ||
160 | //========================================================================= | 152 | //========================================================================= |
161 | __syntaxFix__: "syntax fix" | 153 | __syntaxFix__: "syntax fix" |
162 | 154 | ||
163 | }); | 155 | }); |
164 | 156 | ||