Beispiel #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);
  }
Beispiel #2
0
  /**
   * Supplies the popup window with AwContents then waits for the popup window to finish loading.
   */
  public PopupInfo connectPendingPopup(final AwContents parentAwContents) throws Exception {
    TestAwContentsClient popupContentsClient;
    AwTestContainerView popupContainerView;
    final AwContents popupContents;
    popupContentsClient = new TestAwContentsClient();
    popupContainerView = createAwTestContainerViewOnMainSync(popupContentsClient);
    popupContents = popupContainerView.getAwContents();
    enableJavaScriptOnUiThread(popupContents);

    getInstrumentation()
        .runOnMainSync(
            new Runnable() {
              @Override
              public void run() {
                parentAwContents.supplyContentsForPopup(popupContents);
              }
            });

    OnPageFinishedHelper onPageFinishedHelper = popupContentsClient.getOnPageFinishedHelper();
    int callCount = onPageFinishedHelper.getCallCount();
    onPageFinishedHelper.waitForCallback(callCount, 1, WAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS);

    return new PopupInfo(popupContentsClient, popupContainerView, popupContents);
  }