@@ -149,6 +149,7 @@ class ExampleSwiftApp_iOSTests: XCTestCase {
149149 loadEchoSample ( webView) ;
150150 let callbackInvoked = expectation ( description: " Callback invoked " )
151151 bridge. registerHandler ( " objcEchoToJs " ) { ( data, responseCallback) in
152+ XCTAssertEqual ( data as! NSDictionary , [ " foo " : " bar " ] ) ;
152153 responseCallback!( data)
153154 }
154155 bridge. callHandler ( " jsRcvResponseTest " , data: nil ) { ( responseData) in
@@ -168,6 +169,7 @@ class ExampleSwiftApp_iOSTests: XCTestCase {
168169 loadEchoSample ( webView) ;
169170 let callbackInvoked = expectation ( description: " Callback invoked " )
170171 bridge. registerHandler ( " objcEchoToJs " ) { ( data, responseCallback) in
172+ XCTAssertEqual ( data as! NSDictionary , [ " foo " : " bar " ] ) ;
171173 responseCallback!( data) ;
172174 }
173175 bridge. callHandler ( " jsRcvResponseTest " , data: nil ) { ( responseData) in
@@ -176,4 +178,34 @@ class ExampleSwiftApp_iOSTests: XCTestCase {
176178 }
177179 }
178180
181+ func testRemoveHandler( ) {
182+ _testRemoveHandler ( uiWebView)
183+ _testRemoveHandler ( wkWebView)
184+ waitForExpectations ( timeout: timeout, handler: nil )
185+ }
186+ func _testRemoveHandler( _ webView: Any ) {
187+ loadEchoSample ( webView) ;
188+ let bridge = bridgeForWebView ( webView)
189+ let callbackNotInvoked = expectation ( description: " Callback invoked " )
190+ var count = 0
191+ bridge. registerHandler ( " objcEchoToJs " ) { ( data, callback) in
192+ count += 1
193+ callback!( data)
194+ }
195+ bridge. callHandler ( " jsRcvResponseTest " , data: nil ) { ( responseData) in
196+ XCTAssertEqual ( responseData as! String , " Response from JS " ) ;
197+ bridge. removeHandler ( " objcEchoToJs " )
198+ bridge. callHandler ( " jsRcvResponseTest " , data: nil ) { ( responseData) in
199+ // Since we have removed the "objcEchoToJs" handler, and since the
200+ // echo.html javascript won't call the response callback until it has
201+ // received a response from "objcEchoToJs", we should never get here
202+ XCTAssert ( false )
203+ }
204+ bridge. callHandler ( " echoHandler " , data: nil ) { ( responseData) in
205+ XCTAssertEqual ( count, 1 )
206+ callbackNotInvoked. fulfill ( )
207+ }
208+ }
209+ }
210+
179211}
0 commit comments