Skip to content

Commit ca90515

Browse files
committed
Test - Simplify callback promise tests
Issue #4276
1 parent b8dbb0c commit ca90515

File tree

3 files changed

+8
-111
lines changed

3 files changed

+8
-111
lines changed

CefSharp.Example/JavascriptBinding/AsyncBoundObject.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ public async void VoidReturnAsync()
218218

219219
public async Task<string> JavascriptCallbackEvalPromise(string msg, IJavascriptCallback callback)
220220
{
221-
var response = await callback.ExecuteAsync(callback.Id, msg);
221+
var response = await callback.ExecuteAsync(msg);
222222

223223
//Echo the response
224224
return (string)response.Result;
@@ -273,7 +273,7 @@ public async Task<string> JavascriptOptionalCallbackEvalPromise(bool invokeCallb
273273
{
274274
if (invokeCallback)
275275
{
276-
var response = await callback.ExecuteAsync(callback.Id, msg).ConfigureAwait(false);
276+
var response = await callback.ExecuteAsync(msg).ConfigureAwait(false);
277277
//Echo the response
278278
return (string)response.Result;
279279
}

CefSharp.Example/Resources/BindingTestSingle.html

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -19,41 +19,7 @@
1919

2020
QUnit.test("Pass callback(promise) that is conditionally invoked:", async (assert) =>
2121
{
22-
let convertPromiseToCefSharpCallback = function (p)
23-
{
24-
let f = function (callbackId, ...args)
25-
{
26-
//We immediately return CefSharpDefEvalScriptRes as we will be
27-
//using a promise and will call sendEvalScriptResponse when our
28-
//promise has completed
29-
(async function ()
30-
{
31-
try
32-
{
33-
//Await the promise
34-
let response = await p(...args);
35-
36-
//We're done, let's send our response back to our .Net App
37-
cefSharp.sendEvalScriptResponse(callbackId, true, response, true);
38-
}
39-
catch (err)
40-
{
41-
//An error occurred let's send the response back to our .Net App
42-
cefSharp.sendEvalScriptResponse(callbackId, false, err.message, true);
43-
}
44-
})();
45-
46-
//Let CefSharp know we're going to be defering our response as we have some async/await
47-
//processing to happen before our callback returns it's value
48-
return "CefSharpDefEvalScriptRes";
49-
}
50-
51-
return f;
52-
}
53-
54-
//The function convertPromiseToCefSharpCallback can be used in your own projects
55-
//Pass in a function that wraps your promise, not your promise directly
56-
let callback = convertPromiseToCefSharpCallback(function (msg)
22+
let callback = function (msg)
5723
{
5824
return new Promise((resolve, reject) =>
5925
{
@@ -62,7 +28,7 @@
6228
resolve(msg);
6329
}, 300);
6430
});
65-
});
31+
};
6632

6733
const expectedResult = "Callback has not been invoked";
6834
const actualResult = await boundAsync.javascriptOptionalCallbackEvalPromise(false, expectedResult, callback);

CefSharp.Example/Resources/BindingTestsAsyncTask.html

Lines changed: 4 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -98,42 +98,7 @@
9898

9999
QUnit.test("JavascriptCallback EvalPromise:", async (assert) =>
100100
{
101-
let convertPromiseToCefSharpCallback = function (p)
102-
{
103-
let f = function (callbackId, ...args)
104-
{
105-
//We immediately return CefSharpDefEvalScriptRes as we will be
106-
//using a promise and will call sendEvalScriptResponse when our
107-
//promise has completed
108-
(async function ()
109-
{
110-
try
111-
{
112-
//Await the promise
113-
let response = await p(...args);
114-
115-
//We're done, let's send our response back to our .Net App
116-
cefSharp.sendEvalScriptResponse(callbackId, true, response, true);
117-
}
118-
catch (err)
119-
{
120-
//An error occurred let's send the response back to our .Net App
121-
cefSharp.sendEvalScriptResponse(callbackId, false, err.message, true);
122-
123-
}
124-
})();
125-
126-
//Let CefSharp know we're going to be defering our response as we have some async/await
127-
//processing to happen before our callback returns it's value
128-
return "CefSharpDefEvalScriptRes";
129-
}
130-
131-
return f;
132-
}
133-
134-
//The function convertPromiseToCefSharpCallback can be used in your own projects
135-
//Pass in a function that wraps your promise, not your promise directly
136-
let callback = convertPromiseToCefSharpCallback(function (msg)
101+
let callback = function (msg)
137102
{
138103
return new Promise((resolve, reject) =>
139104
{
@@ -142,7 +107,7 @@
142107
resolve(msg);
143108
}, 300);
144109
});
145-
});
110+
};
146111

147112
const expectedResult = "JavascriptCallback after promise";
148113
const actualResult = await boundAsync.javascriptCallbackEvalPromise(expectedResult, callback);
@@ -153,41 +118,7 @@
153118
// Issue #3979
154119
QUnit.test("JavascriptCallback conditionally EvalPromise:", async (assert) =>
155120
{
156-
let convertPromiseToCefSharpCallback = function (p)
157-
{
158-
let f = function (callbackId, ...args)
159-
{
160-
//We immediately return CefSharpDefEvalScriptRes as we will be
161-
//using a promise and will call sendEvalScriptResponse when our
162-
//promise has completed
163-
(async function ()
164-
{
165-
try
166-
{
167-
//Await the promise
168-
let response = await p(...args);
169-
170-
//We're done, let's send our response back to our .Net App
171-
cefSharp.sendEvalScriptResponse(callbackId, true, response, true);
172-
}
173-
catch (err)
174-
{
175-
//An error occurred let's send the response back to our .Net App
176-
cefSharp.sendEvalScriptResponse(callbackId, false, err.message, true);
177-
}
178-
})();
179-
180-
//Let CefSharp know we're going to be defering our response as we have some async/await
181-
//processing to happen before our callback returns it's value
182-
return "CefSharpDefEvalScriptRes";
183-
}
184-
185-
return f;
186-
}
187-
188-
//The function convertPromiseToCefSharpCallback can be used in your own projects
189-
//Pass in a function that wraps your promise, not your promise directly
190-
let callback = convertPromiseToCefSharpCallback(function (msg)
121+
let callback = function (msg)
191122
{
192123
return new Promise((resolve, reject) =>
193124
{
@@ -196,7 +127,7 @@
196127
resolve(msg);
197128
}, 300);
198129
});
199-
});
130+
};
200131

201132
const expectedResult = "Callback has not been invoked";
202133
const actualResult = await boundAsync.javascriptOptionalCallbackEvalPromise(false, expectedResult, callback);

0 commit comments

Comments
 (0)