/** Test that the progress bar only traverses the page a single time per navigation. */ @Feature({"Android-Toolbar"}) @MediumTest @Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE) public void testToolbarTraversesScreenOnce() throws InterruptedException, TimeoutException { EmbeddedTestServer testServer = EmbeddedTestServer.createAndStartFileServer( getInstrumentation().getContext(), Environment.getExternalStorageDirectory()); final WebContents webContents = getActivity().getActivityTab().getWebContents(); TestWebContentsObserver observer = new TestWebContentsObserver(webContents); // Start and stop load events are carefully tracked; there should be two start-stop pairs // that do not overlap. OnPageStartedHelper startHelper = observer.getOnPageStartedHelper(); OnPageFinishedHelper finishHelper = observer.getOnPageFinishedHelper(); ToolbarProgressBar progressBar = (ToolbarProgressBar) getActivity().findViewById(R.id.progress); // Reset progress bar start count in case anything else triggered it. progressBar.resetStartCountForTesting(); // Ensure no load events have occured yet. assertEquals(0, startHelper.getCallCount()); assertEquals(0, finishHelper.getCallCount()); loadUrl(testServer.getURL(TEST_PAGE)); // Wait for the initial page to be loaded if it hasn't already. if (finishHelper.getCallCount() == 0) { finishHelper.waitForCallback(finishHelper.getCallCount(), 1); } // Exactly one start load and one finish load event should have occured. assertEquals(1, startHelper.getCallCount()); assertEquals(1, finishHelper.getCallCount()); // Load content in the iframe of the test page to trigger another load. JavaScriptUtils.executeJavaScript(webContents, "loadIframeInPage();"); // A load start will be triggered. startHelper.waitForCallback(startHelper.getCallCount(), 1); assertEquals(2, startHelper.getCallCount()); // Wait for the iframe to finish loading. finishHelper.waitForCallback(finishHelper.getCallCount(), 1); assertEquals(2, finishHelper.getCallCount()); // Though the page triggered two load events, the progress bar should have only appeared a // single time. assertEquals(1, progressBar.getStartCountForTesting()); }
/** * 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); }
@Override public void onPageFinished(String url) { mOnPageFinishedHelper.notifyCalled(url); }