title: Test Javascript method calling in WebView [Robolectric]
body: <p>I'm trying to test whether Javascript method (registered as an interface in WebView) is called or not. Following sample works when executed within standard app flow, but it doesn't work when I try to run it like a Robolectric test.
  Anybody knows why?</p>
  
  <pre><code>@RunWith(RobolectricTestRunner::class)
  @Config(sdk = [Build.VERSION_CODES.O_MR1])
  class ExampleUnitTest {
  
      private lateinit var activityController: ActivityController&lt;Activity&gt;
      private lateinit var activity: Activity
      private lateinit var webView: WebView
  
      val signal = CountDownLatch(1)
      var success = false
  
      @Before
      fun setUp() {
          activityController = Robolectric.buildActivity(Activity::class.java)
          activity = activityController.get()
          webView = WebView(activity)
          webView.settings.javaScriptEnabled = true
          webView.addJavascriptInterface(this, "example")
      }
  
      @Test
      fun getUuid() {
          System.out.println("Ping")
          webView.evaluateJavascript("example.pong();", null);
          signal.await(10, TimeUnit.SECONDS)
          Assert.assertTrue(success)
      }
  
      @JavascriptInterface
      fun pong() {
          System.out.println("Pong")
          success = true
          signal.countDown()
      }
  }
  </code></pre>