summaryrefslogtreecommitdiff
path: root/frontend/delta/js/Clipperz/PM/Proxy/Proxy.Test.js
Unidiff
Diffstat (limited to 'frontend/delta/js/Clipperz/PM/Proxy/Proxy.Test.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/delta/js/Clipperz/PM/Proxy/Proxy.Test.js161
1 files changed, 161 insertions, 0 deletions
diff --git a/frontend/delta/js/Clipperz/PM/Proxy/Proxy.Test.js b/frontend/delta/js/Clipperz/PM/Proxy/Proxy.Test.js
new file mode 100644
index 0000000..83d9244
--- a/dev/null
+++ b/frontend/delta/js/Clipperz/PM/Proxy/Proxy.Test.js
@@ -0,0 +1,161 @@
1/*
2
3Copyright 2008-2013 Clipperz Srl
4
5This file is part of Clipperz, the online password manager.
6For further information about its features and functionalities please
7refer to http://www.clipperz.com.
8
9* Clipperz is free software: you can redistribute it and/or modify it
10 under the terms of the GNU Affero General Public License as published
11 by the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14* Clipperz is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 See the GNU Affero General Public License for more details.
18
19* You should have received a copy of the GNU Affero General Public
20 License along with Clipperz. If not, see http://www.gnu.org/licenses/.
21
22*/
23
24if (typeof(Clipperz) == 'undefined') { Clipperz = {}; }
25if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; }
26if (typeof(Clipperz.PM.Proxy) == 'undefined') { Clipperz.PM.Proxy = {}; }
27
28//=============================================================================
29
30Clipperz.PM.Proxy.Test = function(args) {
31 Clipperz.PM.Proxy.Test.superclass.constructor.call(this, args);
32
33 args = args || {};
34
35 this._expectedRequests = (args.shouldCheckExpectedRequests === true) ? [] : null;
36 this._isExpectingRequests = true;
37 this._unexpectedRequests = [];
38
39 this.dataStore().resetData();
40
41 return this;
42}
43
44Clipperz.Base.extend(Clipperz.PM.Proxy.Test, Clipperz.PM.Proxy.Offline, {
45
46 'toString': function() {
47 return "Clipperz.PM.Proxy.Test";
48 },
49
50 //=========================================================================
51
52 'expectedRequests': function () {
53 return this._expectedRequests;
54 },
55
56 //-------------------------------------------------------------------------
57
58 'shouldCheckExpectedRequests': function () {
59 return (this._expectedRequests != null);
60 },
61
62 'setShouldCheckExpectedRequests': function(aValue) {
63 if (aValue) {
64 this._expectedRequests = aValue;
65 } else {
66 this._expectedRequests = null;
67 }
68 },
69
70 //-------------------------------------------------------------------------
71
72 'shouldNotReceiveAnyFurtherRequest': function () {
73 this._isExpectingRequests = false;
74 },
75
76 'mayReceiveMoreRequests': function () {
77 this._isExpectingRequests = true;
78 this.resetUnexpectedRequests();
79 },
80
81 'isExpectingRequests': function () {
82 return this._isExpectingRequests;
83 },
84
85 //-------------------------------------------------------------------------
86
87 'unexpectedRequests': function () {
88 return this._unexpectedRequests;
89 },
90
91 'resetUnexpectedRequests': function () {
92 this._unexpectedRequests = [];
93 },
94
95 //-------------------------------------------------------------------------
96
97 'testExpectedRequestParameters': function (aPath, anActualRequest, anExpectedRequest) {
98 var aKey;
99 for (aKey in anExpectedRequest) {
100 if (typeof(anActualRequest[aKey]) == 'undefined') {
101 throw "the expected paramter [" + aKey + "] is missing from the actual request";
102 }
103 if (typeof(anExpectedRequest[aKey]) == 'object') {
104 this.testExpectedRequestParameters(aPath + "." + aKey, anActualRequest[aKey], anExpectedRequest[aKey])
105 } else {
106 if (! anExpectedRequest[aKey](anActualRequest[aKey])) {
107 throw "wrong value for paramter [" + aKey + "]; got '" + anActualRequest[aKey] + "'";
108 }
109 }
110 }
111 },
112
113 //-------------------------------------------------------------------------
114
115 'checkRequest': function(aFunctionName, someParameters) {
116 if (this.shouldCheckExpectedRequests()) {
117 var expectedRequest;
118
119 expectedRequest = this.expectedRequests().pop();
120 if (expectedRequest == null) {
121 throw "Proxy.Test.sentMessage: no expected result specified. Got request '" + aFunctionName + "': " + someParameters;
122 }
123
124 try {
125 if (aFunctionName != expectedRequest.functionName) {
126 throw "wrong function name. Got '" + aFunctionName + "', expected '" + expectedRequest.request.functionName + "'";
127 }
128
129 this.testExpectedRequestParameters("parameters", someParameters, expectedRequest.parameters);
130 } catch(exception) {
131 throw "Proxy.Test.sentMessage[" + expectedRequest.name + "]: " + exception;
132 }
133 }
134 },
135
136 //=========================================================================
137
138 '_sendMessage': function(aFunctionName, aVersion, someParameters) {
139 var result;
140
141 if (this.isExpectingRequests() == false) {
142 // throw Clipperz.PM.Connection.exception.UnexpectedRequest;
143Clipperz.log("UNEXPECTED REQUEST " + aFunctionName /* + ": " + Clipperz.Base.serializeJSON(someParameters) */);
144 this.unexpectedRequests().push({'functionName':aFunctionName, 'someParameters': someParameters});
145 };
146//if (aFunctionName == 'knock') {
147 //console.log(">>> send message - " + aFunctionName, someParameters);
148//} else {
149 //console.log(">>> SEND MESSAGE - " + aFunctionName + " [" + someParameters['parameters']['message'] + "]", someParameters['parameters']['parameters']);
150//}
151 this.checkRequest(aFunctionName, someParameters);
152 result = Clipperz.PM.Proxy.Test.superclass._sendMessage.call(this, aFunctionName, aVersion, someParameters);
153
154 return result;
155 },
156
157 //=========================================================================
158 __syntaxFix__: "syntax fix"
159
160});
161