forked from cefsharp/CefSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBindingTestAsync.js
More file actions
289 lines (236 loc) · 10.4 KB
/
BindingTestAsync.js
File metadata and controls
289 lines (236 loc) · 10.4 KB
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
QUnit.module('BindingTestAsync', (hooks) =>
{
hooks.before(async () =>
{
await CefSharp.BindObjectAsync("boundAsync");
});
QUnit.test("BindObjectAsync Second call with boundAsync param", async (assert) =>
{
const res = await CefSharp.BindObjectAsync("boundAsync");
assert.equal(res.Success, false, "Second call to BindObjectAsync with already bound objects as params returned false.");
});
QUnit.test("Async call (Throw .Net Exception)", async (assert) =>
{
assert.rejects(boundAsync.error());
});
QUnit.test("Async call (Divide 16 / 2):", async (assert) =>
{
const actualResult = await boundAsync.div(16, 2);
const expectedResult = 8;
assert.equal(expectedResult, actualResult, "Divide 16 / 2");
});
QUnit.test("Async call (Div with Blocking Task 16 / 2):", async (assert) =>
{
const actualResult = await boundAsync.divWithBlockingTaskCall(16, 2);
const expectedResult = 8;
assert.equal(expectedResult, actualResult, "Divide 16 / 2");
});
QUnit.test("Async call (Divide 16 /0)", async (assert) =>
{
assert.rejects(boundAsync.div(16, 0));
});
QUnit.test("Async call (UIntAddModel 3 + 2):", async (assert) =>
{
const actualResult = await boundAsync.uIntAddModel({ ParamA: 3, ParamB: 2 });
const expectedResult = 5;
assert.equal(expectedResult, actualResult, "Add 3 + 2 resulted in " + expectedResult);
});
QUnit.test("Async call (UIntAdd 3 + 2):", async (assert) =>
{
const actualResult = await boundAsync.uIntAdd(3, 2);
const expectedResult = 5;
assert.equal(expectedResult, actualResult, "Add 3 + 2 resulted in " + expectedResult);
});
QUnit.test("Async call (Hello):", async (assert) =>
{
const res = await boundAsync.hello('CefSharp');
assert.equal(res, "Hello CefSharp")
});
QUnit.test("Async call (Long Running Task):", async (assert) =>
{
const res = await boundAsync.doSomething();
assert.ok(true, "Slept for 1000ms")
});
QUnit.test("Async call (return Struct):", async (assert) =>
{
var res = await boundAsync.returnObject('CefSharp Struct Test');
assert.equal(res.Value, "CefSharp Struct Test", "Struct with a single field");
});
QUnit.test("Async call (return Class):", async (assert) =>
{
//Returns a class
const res = await boundAsync.returnClass('CefSharp Class Test');
const expectedResult = 'CefSharp Class Test';
assert.equal(expectedResult, res.Value, "Class with a single property");
});
QUnit.test("Async call (return Class as JsonString):", async (assert) =>
{
const expectedResult = 'CefSharp Class Test';
//Returns a class
const res = await boundAsync.returnClassAsJsonString(expectedResult);
assert.equal(expectedResult, res.Value, "Class with a single property");
});
QUnit.test("Async call (returnStructArray):", async (assert) =>
{
const res = await boundAsync.returnStructArray('CefSharp');
assert.equal(res[0].Value, "CefSharpItem1", "Expected Result of CefSharpItem1");
assert.equal(res[1].Value, "CefSharpItem2", "Expected Result of CefSharpItem2");
});
QUnit.test("Async call (returnClassesArray):", async (assert) =>
{
var asyncCallback = assert.async();
boundAsync.returnClassesArray('CefSharp').then(function (res)
{
assert.equal(res[0].Value, "CefSharpItem1", "Expected Result of CefSharpItem1");
assert.equal(res[1].Value, "CefSharpItem2", "Expected Result of CefSharpItem2");
asyncCallback();
});
});
QUnit.test("Async call (echoDateTime): now", async (assert) =>
{
const now = new Date();
const res = await boundAsync.echoDateTime(now);
assert.deepEqual(res, now, "Expected echo datetime");
});
QUnit.test("Async call (echoDateTime): unixTimeZero", async (assert) =>
{
const unixTimeZero = new Date(Date.parse('01 Jan 1970 00:00:00 GMT'));
const res = await boundAsync.echoDateTime(unixTimeZero);
assert.deepEqual(res, unixTimeZero, "Expected echo unixTimeZero");
});
QUnit.test("Async call (echoNullableDateTime):", async (assert) =>
{
const now = new Date();
const res = await boundAsync.echoNullableDateTime(now);
assert.deepEqual(res, now, "Expected echo datetime");
});
QUnit.test("Async call (echoNullableDateTime) null param:", async (assert) =>
{
const res = await boundAsync.echoNullableDateTime(null);
assert.equal(res, null, "Expected null");
});
QUnit.test("Async call (echoArray):", async (assert) =>
{
const res = await boundAsync.echoArray(["one", null, "three"]);
assert.equal(res.length, 3, "Expected result to be length 3");
assert.equal(res[0], "one", "Expected Result of 1st item");
assert.equal(res[1], null, "Expected Result of 2nd item");
assert.equal(res[2], "three", "Expected Result of 3rd item");
});
QUnit.test("Async call (Test Empty Array):", async (assert) =>
{
const res = await boundAsync.echoArray([]);
assert.equal(Array.isArray(res), true, "Expected result is an array");
assert.equal(res.length, 0, "Expected result to be length 0 (empty array)");
});
QUnit.test("Async call (echoValueTypeArray):", async (assert) =>
{
const res = await boundAsync.echoValueTypeArray([1, null, 3]);
assert.equal(res.length, 3, "Expected result to be length 3");
assert.equal(res[0], 1, "Expected Result of 1st item");
assert.equal(res[1], 0, "Expected Result of 2nd item");
assert.equal(res[2], 3, "Expected Result of 3rd item");
});
QUnit.test("Async call (echoMultidimensionalArray):", async (assert) =>
{
const res = await boundAsync.echoMultidimensionalArray([[1, 2], null, [3, 4]]);
assert.equal(res.length, 3, "Expected result to be length 3");
assert.equal(res[0][0], 1, "Expected Result of 1st item");
assert.equal(res[0][1], 2, "Expected Result of 1st item");
assert.equal(res[1], null, "Expected Result of 2nd item");
assert.equal(res[2][0], 3, "Expected Result of 3rd item");
assert.equal(res[2][1], 4, "Expected Result of 3rd item");
});
QUnit.test("Async call (methodReturnList):", async (assert) =>
{
const list1 =
[
"Element 0 - First",
"Element 1",
"Element 2 - Last"
];
const list2 =
[
["Element 0, 0", "Element 0, 1"],
["Element 1, 0", "Element 1, 1"],
["Element 2, 0", "Element 2, 1"]
];
const results = await Promise.all([
boundAsync.methodReturnsList(),
boundAsync.methodReturnsListOfLists(),
]);
assert.deepEqual(results[0], list1, "Call to boundAsync.MethodReturnsList() resulted in : " + JSON.stringify(results[0]));
assert.deepEqual(results[1], list2, "Call to boundAsync.MethodReturnsListOfLists() resulted in : " + JSON.stringify(results[1]));
});
QUnit.test("Async call (methodReturnsDictionary):", async (assert) =>
{
const dict1 =
{
"five": 5,
"ten": 10
};
const dict2 =
{
"onepointfive": 1.5,
"five": 5,
"ten": "ten",
"twotwo": [2, 2]
};
const dict3 =
{
"data":
{
"onepointfive": 1.5,
"five": 5,
"ten": "ten",
"twotwo": [2, 2]
}
};
const results = await Promise.all([
boundAsync.methodReturnsDictionary1(),
boundAsync.methodReturnsDictionary2(),
boundAsync.methodReturnsDictionary3()
]);
assert.deepEqual(results[0], dict1, "Call to boundAsync.MethodReturnsDictionary1() resulted in : " + JSON.stringify(results[0]));
assert.deepEqual(results[1], dict2, "Call to boundAsync.MethodReturnsDictionary2() resulted in : " + JSON.stringify(results[1]));
assert.deepEqual(results[2], dict3, "Call to boundAsync.MethodReturnsDictionary3() resulted in : " + JSON.stringify(results[2]));
});
QUnit.test("Async call (PassSimpleClassAsArgument):", async (assert) =>
{
const res = await boundAsync.passSimpleClassAsArgument({
TestString: "Hello",
SubClasses:
[
{ PropertyOne: "Test Property One", Numbers: [1, 2, 3] },
{ PropertyOne: "Test Property Two", Numbers: [4, 5, 6] }
]
});
assert.equal(res.Item1, true)
assert.equal(res.Item2, "TestString:Hello;SubClasses[0].PropertyOne:Test Property One");
});
QUnit.test("Bind boundAsync2 and call (Hello):", async (assert) =>
{
//Can use both cefSharp.bindObjectAsync and CefSharp.BindObjectAsync, both do the same
const result = await cefSharp.bindObjectAsync({ NotifyIfAlreadyBound: true }, "boundAsync2");
const res = await boundAsync2.hello('CefSharp');
assert.equal(res, "Hello CefSharp")
assert.equal(true, CefSharp.DeleteBoundObject("boundAsync2"), "Object was unbound");
assert.ok(window.boundAsync2 === undefined, "boundAsync2 is now undefined");
});
//Repeat of the previous test to make sure binding a deleted object is working
QUnit.test("Bind boundAsync2 and call (Hello) Second Attempt:", async (assert) =>
{
const result = await CefSharp.BindObjectAsync({ NotifyIfAlreadyBound: true, IgnoreCache: true }, "boundAsync2");
const res = await boundAsync2.hello('CefSharp');
assert.equal(res, "Hello CefSharp")
});
//Repeat of the previous test to make sure binding a deleted object is working
QUnit.test("Bind boundAsync2 and call (Hello) Third Attempt:", async (assert) =>
{
const result = await CefSharp.BindObjectAsync({ NotifyIfAlreadyBound: true, IgnoreCache: true }, "boundAsync2");
const res = await boundAsync2.hello('CefSharp');
assert.equal(res, "Hello CefSharp")
assert.equal(true, CefSharp.DeleteBoundObject("boundAsync2"), "Object was unbound");
assert.ok(window.boundAsync2 === undefined, "boundAsync2 is now undefined");
});
});