/** 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); }
/** 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); }