@@ -130,6 +130,123 @@ public async Task ShouldDisableJsBindingApi()
130130 }
131131 }
132132
133+ [ Theory ]
134+ [ InlineData ( "notallowed" ) ]
135+ [ InlineData ( "notallowed" , "alsonotallowed" ) ]
136+ [ InlineData ( "notallowed" , "alsonotallowed" , "stillnotallowed" ) ]
137+ public async Task ShouldDisableJsBindingApiForOrigin ( params string [ ] origins )
138+ {
139+ using ( var browser = new ChromiumWebBrowser ( CefExample . BindingApiCustomObjectNameTestUrl , automaticallyCreateBrowser : false ) )
140+ {
141+ var settings = browser . JavascriptObjectRepository . Settings ;
142+ settings . JavascriptBindingApiEnabled = true ;
143+ settings . JavascriptBindingApiAllowOrigins = origins ;
144+
145+ //To modify the settings we need to defer browser creation slightly
146+ browser . CreateBrowser ( ) ;
147+
148+ var loadResponse = await browser . WaitForInitialLoadAsync ( ) ;
149+
150+ Assert . True ( loadResponse . Success ) ;
151+
152+ var response1 = await browser . EvaluateScriptAsync ( "typeof window.cefSharp === 'undefined'" ) ;
153+ var response2 = await browser . EvaluateScriptAsync ( "typeof window.CefSharp === 'undefined'" ) ;
154+
155+ Assert . True ( response1 . Success ) ;
156+ Assert . True ( ( bool ) response1 . Result ) ;
157+
158+ Assert . True ( response2 . Success ) ;
159+ Assert . True ( ( bool ) response2 . Result ) ;
160+ }
161+ }
162+
163+ [ Fact ]
164+ public async Task ShouldEnableJsBindingApiWhenOriginsListIsEmpty ( )
165+ {
166+ using ( var browser = new ChromiumWebBrowser ( CefExample . BindingApiCustomObjectNameTestUrl , automaticallyCreateBrowser : false ) )
167+ {
168+ var settings = browser . JavascriptObjectRepository . Settings ;
169+ settings . JavascriptBindingApiEnabled = true ;
170+ settings . JavascriptBindingApiAllowOrigins = new string [ 0 ] ;
171+
172+ //To modify the settings we need to defer browser creation slightly
173+ browser . CreateBrowser ( ) ;
174+
175+ var loadResponse = await browser . WaitForInitialLoadAsync ( ) ;
176+
177+ Assert . True ( loadResponse . Success ) ;
178+
179+ var response1 = await browser . EvaluateScriptAsync ( "typeof window.cefSharp === 'undefined'" ) ;
180+ var response2 = await browser . EvaluateScriptAsync ( "typeof window.CefSharp === 'undefined'" ) ;
181+
182+ Assert . True ( response1 . Success ) ;
183+ Assert . False ( ( bool ) response1 . Result ) ;
184+
185+ Assert . True ( response2 . Success ) ;
186+ Assert . False ( ( bool ) response2 . Result ) ;
187+ }
188+ }
189+
190+ [ Theory ]
191+ [ InlineData ( CefExample . BaseUrl ) ]
192+ [ InlineData ( CefExample . BaseUrl + "/" ) ]
193+ public async Task ShouldEnableJsBindingApiForOriginWithOrWithoutTrailingSlash ( string configuredOrigin )
194+ {
195+ using ( var browser = new ChromiumWebBrowser ( CefExample . BindingApiCustomObjectNameTestUrl , automaticallyCreateBrowser : false ) )
196+ {
197+ var settings = browser . JavascriptObjectRepository . Settings ;
198+ settings . JavascriptBindingApiEnabled = true ;
199+ settings . JavascriptBindingApiAllowOrigins = new string [ ] { configuredOrigin } ;
200+
201+ //To modify the settings we need to defer browser creation slightly
202+ browser . CreateBrowser ( ) ;
203+
204+ var loadResponse = await browser . WaitForInitialLoadAsync ( ) ;
205+
206+ Assert . True ( loadResponse . Success ) ;
207+
208+ var response1 = await browser . EvaluateScriptAsync ( "typeof window.cefSharp === 'undefined'" ) ;
209+ var response2 = await browser . EvaluateScriptAsync ( "typeof window.CefSharp === 'undefined'" ) ;
210+
211+ Assert . True ( response1 . Success ) ;
212+ Assert . False ( ( bool ) response1 . Result ) ;
213+
214+ Assert . True ( response2 . Success ) ;
215+ Assert . False ( ( bool ) response2 . Result ) ;
216+ }
217+ }
218+ [ Theory ]
219+ [ InlineData ( CefExample . BaseUrl + "/" ) ]
220+ [ InlineData ( "someorigin" , CefExample . BaseUrl + "/" ) ]
221+ [ InlineData ( CefExample . BaseUrl + "/" , "someorigin" ) ]
222+ [ InlineData ( "firstorigin" , "secondorigin" , CefExample . BaseUrl + "/" ) ]
223+ [ InlineData ( "firstorigin" , CefExample . BaseUrl + "/" , "secondorigin" ) ]
224+ public async Task ShouldEnableJsBindingApiForOrigin ( params string [ ] origins )
225+ {
226+ using ( var browser = new ChromiumWebBrowser ( CefExample . BindingApiCustomObjectNameTestUrl , automaticallyCreateBrowser : false ) )
227+ {
228+ var settings = browser . JavascriptObjectRepository . Settings ;
229+ settings . JavascriptBindingApiEnabled = true ;
230+ settings . JavascriptBindingApiAllowOrigins = origins ;
231+
232+ //To modify the settings we need to defer browser creation slightly
233+ browser . CreateBrowser ( ) ;
234+
235+ var loadResponse = await browser . WaitForInitialLoadAsync ( ) ;
236+
237+ Assert . True ( loadResponse . Success ) ;
238+
239+ var response1 = await browser . EvaluateScriptAsync ( "typeof window.cefSharp === 'undefined'" ) ;
240+ var response2 = await browser . EvaluateScriptAsync ( "typeof window.CefSharp === 'undefined'" ) ;
241+
242+ Assert . True ( response1 . Success ) ;
243+ Assert . False ( ( bool ) response1 . Result ) ;
244+
245+ Assert . True ( response2 . Success ) ;
246+ Assert . False ( ( bool ) response2 . Result ) ;
247+ }
248+ }
249+
133250 [ Fact ]
134251 public async Task ShouldEnableJsBindingApi ( )
135252 {
@@ -141,7 +258,9 @@ public async Task ShouldEnableJsBindingApi()
141258 //To modify the settings we need to defer browser creation slightly
142259 browser . CreateBrowser ( ) ;
143260
144- await browser . WaitForInitialLoadAsync ( ) ;
261+ var loadResponse = await browser . WaitForInitialLoadAsync ( ) ;
262+
263+ Assert . True ( loadResponse . Success ) ;
145264
146265 var response1 = await browser . EvaluateScriptAsync ( "typeof window.cefSharp === 'undefined'" ) ;
147266 var response2 = await browser . EvaluateScriptAsync ( "typeof window.CefSharp === 'undefined'" ) ;
0 commit comments