@@ -130,14 +130,17 @@ public async Task ShouldDisableJsBindingApi()
130130 }
131131 }
132132
133- [ Fact ]
134- public async Task ShouldDisableJsBindingApiForOrigin ( )
133+ [ Theory ]
134+ [ InlineData ( "notallowed" ) ]
135+ [ InlineData ( "notallowed" , "alsonotallowed" ) ]
136+ [ InlineData ( "notallowed" , "alsonotallowed" , "stillnotallowed" ) ]
137+ public async Task ShouldDisableJsBindingApiForOrigin ( params string [ ] origins )
135138 {
136139 using ( var browser = new ChromiumWebBrowser ( CefExample . BindingApiCustomObjectNameTestUrl , automaticallyCreateBrowser : false ) )
137140 {
138141 var settings = browser . JavascriptObjectRepository . Settings ;
139142 settings . JavascriptBindingApiEnabled = true ;
140- settings . JavascriptBindingApiAllowOrigins = new string [ ] { "notallowed" } ;
143+ settings . JavascriptBindingApiAllowOrigins = origins ;
141144
142145 //To modify the settings we need to defer browser creation slightly
143146 browser . CreateBrowser ( ) ;
@@ -157,9 +160,63 @@ public async Task ShouldDisableJsBindingApiForOrigin()
157160 }
158161 }
159162
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+ await browser . WaitForInitialLoadAsync ( ) ;
176+
177+ var response1 = await browser . EvaluateScriptAsync ( "typeof window.cefSharp === 'undefined'" ) ;
178+ var response2 = await browser . EvaluateScriptAsync ( "typeof window.CefSharp === 'undefined'" ) ;
179+
180+ Assert . True ( response1 . Success ) ;
181+ Assert . False ( ( bool ) response1 . Result ) ;
182+
183+ Assert . True ( response2 . Success ) ;
184+ Assert . False ( ( bool ) response2 . Result ) ;
185+ }
186+ }
187+
188+ [ Theory ]
189+ [ InlineData ( CefExample . BaseUrl ) ]
190+ [ InlineData ( CefExample . BaseUrl + "/" ) ]
191+ public async Task ShouldEnableJsBindingApiForOriginWithOrWithoutTrailingSlash ( string configuredOrigin )
192+ {
193+ using ( var browser = new ChromiumWebBrowser ( CefExample . BindingApiCustomObjectNameTestUrl , automaticallyCreateBrowser : false ) )
194+ {
195+ var settings = browser . JavascriptObjectRepository . Settings ;
196+ settings . JavascriptBindingApiEnabled = true ;
197+ settings . JavascriptBindingApiAllowOrigins = new string [ ] { configuredOrigin } ;
198+
199+ //To modify the settings we need to defer browser creation slightly
200+ browser . CreateBrowser ( ) ;
201+
202+ await browser . WaitForInitialLoadAsync ( ) ;
203+
204+ var response1 = await browser . EvaluateScriptAsync ( "typeof window.cefSharp === 'undefined'" ) ;
205+ var response2 = await browser . EvaluateScriptAsync ( "typeof window.CefSharp === 'undefined'" ) ;
206+
207+ Assert . True ( response1 . Success ) ;
208+ Assert . False ( ( bool ) response1 . Result ) ;
209+
210+ Assert . True ( response2 . Success ) ;
211+ Assert . False ( ( bool ) response2 . Result ) ;
212+ }
213+ }
160214 [ Theory ]
161215 [ InlineData ( CefExample . BaseUrl + "/" ) ]
162216 [ InlineData ( "someorigin" , CefExample . BaseUrl + "/" ) ]
217+ [ InlineData ( CefExample . BaseUrl + "/" , "someorigin" ) ]
218+ [ InlineData ( "firstorigin" , "secondorigin" , CefExample . BaseUrl + "/" ) ]
219+ [ InlineData ( "firstorigin" , CefExample . BaseUrl + "/" , "secondorigin" ) ]
163220 public async Task ShouldEnableJsBindingApiForOrigin ( params string [ ] origins )
164221 {
165222 using ( var browser = new ChromiumWebBrowser ( CefExample . BindingApiCustomObjectNameTestUrl , automaticallyCreateBrowser : false ) )
0 commit comments