Skip to content

Commit 195e62b

Browse files
committed
OffScreen/OffScreenBrowserBasicFacts- Add CrossSiteNavigationJavascriptBinding Test case
Very basic, little crude, passing though Still having some problems with Xunit and shutting down on the correct thread.
1 parent 523fcf1 commit 195e62b

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

CefSharp.Test/OffScreen/OffScreenBrowserBasicFacts.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
//
33
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
44

5+
using System;
6+
using System.Text;
57
using System.Threading.Tasks;
68
using CefSharp.OffScreen;
79
using Xunit;
@@ -14,6 +16,17 @@ namespace CefSharp.Test.OffScreen
1416
[Collection(CefSharpFixtureCollection.Key)]
1517
public class OffScreenBrowserBasicFacts
1618
{
19+
//TODO: Move into own file/namespace
20+
public class AsyncBoundObject
21+
{
22+
public bool MethodCalled { get; set; }
23+
public string Echo(string arg)
24+
{
25+
MethodCalled = true;
26+
return arg;
27+
}
28+
}
29+
1730
private readonly ITestOutputHelper output;
1831
private readonly CefSharpFixture fixture;
1932

@@ -55,5 +68,35 @@ public async Task CanLoadGoogleAndEvaluateScript()
5568
output.WriteLine("Result of 2 + 2: {0}", javascriptResponse.Result);
5669
}
5770
}
71+
72+
[Fact]
73+
public async Task CrossSiteNavigationJavascriptBinding()
74+
{
75+
const string script = @"
76+
(async function()
77+
{
78+
await CefSharp.BindObjectAsync('bound');
79+
bound.echo('test');
80+
})();";
81+
82+
var boundObj = new AsyncBoundObject();
83+
84+
var browser = new ChromiumWebBrowser("https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/url");
85+
browser.JavascriptObjectRepository.Register("bound", boundObj, true);
86+
87+
await browser.LoadPageAsync();
88+
browser.GetMainFrame().ExecuteJavaScriptAsync(script);
89+
90+
await Task.Delay(2000);
91+
Assert.True(boundObj.MethodCalled);
92+
93+
boundObj.MethodCalled = false;
94+
95+
browser.Load("https://www.google.com");
96+
await browser.LoadPageAsync();
97+
browser.GetMainFrame().ExecuteJavaScriptAsync(script);
98+
await Task.Delay(2000);
99+
Assert.True(boundObj.MethodCalled);
100+
}
58101
}
59102
}

0 commit comments

Comments
 (0)