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 ;
57using System . Threading . Tasks ;
68using CefSharp . OffScreen ;
79using 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