@@ -130,6 +130,117 @@ 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+ 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+ }
214+ [ Theory ]
215+ [ InlineData ( CefExample . BaseUrl + "/" ) ]
216+ [ InlineData ( "someorigin" , CefExample . BaseUrl + "/" ) ]
217+ [ InlineData ( CefExample . BaseUrl + "/" , "someorigin" ) ]
218+ [ InlineData ( "firstorigin" , "secondorigin" , CefExample . BaseUrl + "/" ) ]
219+ [ InlineData ( "firstorigin" , CefExample . BaseUrl + "/" , "secondorigin" ) ]
220+ public async Task ShouldEnableJsBindingApiForOrigin ( params string [ ] origins )
221+ {
222+ using ( var browser = new ChromiumWebBrowser ( CefExample . BindingApiCustomObjectNameTestUrl , automaticallyCreateBrowser : false ) )
223+ {
224+ var settings = browser . JavascriptObjectRepository . Settings ;
225+ settings . JavascriptBindingApiEnabled = true ;
226+ settings . JavascriptBindingApiAllowOrigins = origins ;
227+
228+ //To modify the settings we need to defer browser creation slightly
229+ browser . CreateBrowser ( ) ;
230+
231+ await browser . WaitForInitialLoadAsync ( ) ;
232+
233+ var response1 = await browser . EvaluateScriptAsync ( "typeof window.cefSharp === 'undefined'" ) ;
234+ var response2 = await browser . EvaluateScriptAsync ( "typeof window.CefSharp === 'undefined'" ) ;
235+
236+ Assert . True ( response1 . Success ) ;
237+ Assert . False ( ( bool ) response1 . Result ) ;
238+
239+ Assert . True ( response2 . Success ) ;
240+ Assert . False ( ( bool ) response2 . Result ) ;
241+ }
242+ }
243+
133244 [ Fact ]
134245 public async Task ShouldEnableJsBindingApi ( )
135246 {
0 commit comments