Code example for BaseInputConnection

Methods: sendKeyEvent, sleep

1
      assertTrue(url.endsWith("sample2.html"));
      testView.loadUrl("file:///android_asset/www/backbuttonmultipage/sample3.html");
      sleep(); 
      url = testView.getUrl();
      assertTrue(url.endsWith("sample3.html"));
      BaseInputConnection viewConnection = new BaseInputConnection(testView, true);
      KeyEvent backDown = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK);
      KeyEvent backUp = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK);
      viewConnection.sendKeyEvent(backDown);
      viewConnection.sendKeyEvent(backUp);
      sleep(); 
      url = testView.getUrl();
      assertTrue(url.endsWith("sample2.html"));
      viewConnection.sendKeyEvent(backDown);
      viewConnection.sendKeyEvent(backUp);
      sleep(); 
      url = testView.getUrl();
      assertTrue(url.endsWith("index.html"));
  } 
   
  public void testViaBackButtonOnLayout() { 
      testView.loadUrl("file:///android_asset/www/backbuttonmultipage/sample2.html");
      sleep(); 
      String url = testView.getUrl();
      assertTrue(url.endsWith("sample2.html"));
      testView.loadUrl("file:///android_asset/www/backbuttonmultipage/sample3.html");
      sleep(); 
      url = testView.getUrl();
      assertTrue(url.endsWith("sample3.html"));
      BaseInputConnection viewConnection = new BaseInputConnection(containerView, true);
      KeyEvent backDown = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK);
      KeyEvent backUp = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK);
      viewConnection.sendKeyEvent(backDown);
      viewConnection.sendKeyEvent(backUp);
      sleep(); 
      url = testView.getUrl();
      assertTrue(url.endsWith("sample2.html"));
      viewConnection.sendKeyEvent(backDown);
      viewConnection.sendKeyEvent(backUp);
      sleep(); 
      url = testView.getUrl();
      assertTrue(url.endsWith("index.html"));
  } 
   
  private void sleep() { 
      try { 
          Thread.sleep(TIMEOUT);
      } catch (InterruptedException e) {
          fail("Unexpected Timeout");
      } 
  }