예제 #1
0
  /** Loads the main html then triggers the popup window. */
  public void triggerPopup(
      final AwContents parentAwContents,
      TestAwContentsClient parentAwContentsClient,
      TestWebServer testWebServer,
      String mainHtml,
      String popupHtml,
      String popupPath,
      String triggerScript)
      throws Exception {
    enableJavaScriptOnUiThread(parentAwContents);
    getInstrumentation()
        .runOnMainSync(
            new Runnable() {
              @Override
              public void run() {
                parentAwContents.getSettings().setSupportMultipleWindows(true);
                parentAwContents.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
              }
            });

    final String parentUrl = testWebServer.setResponse("/popupParent.html", mainHtml, null);
    if (popupHtml != null) {
      testWebServer.setResponse(popupPath, popupHtml, null);
    } else {
      testWebServer.setResponseWithNoContentStatus(popupPath);
    }

    parentAwContentsClient.getOnCreateWindowHelper().setReturnValue(true);
    loadUrlSync(parentAwContents, parentAwContentsClient.getOnPageFinishedHelper(), parentUrl);

    TestAwContentsClient.OnCreateWindowHelper onCreateWindowHelper =
        parentAwContentsClient.getOnCreateWindowHelper();
    int currentCallCount = onCreateWindowHelper.getCallCount();
    parentAwContents.evaluateJavaScriptForTests(triggerScript, null);
    onCreateWindowHelper.waitForCallback(
        currentCallCount, 1, WAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
  }
예제 #2
0
 /** Loads url on the UI thread and blocks until onPageFinished is called. */
 public void loadUrlSync(
     final AwContents awContents, CallbackHelper onPageFinishedHelper, final String url)
     throws Exception {
   loadUrlSync(awContents, onPageFinishedHelper, url, null);
 }