private <T extends ChromeActivity> void triggerWindowOpenAndWaitForLoad( Class<T> classToWaitFor, String linkHtml, boolean checkContents) throws Exception { final WebappActivity firstActivity = startWebappActivity(WEBAPP_1_ID, WEBAPP_1_URL, WEBAPP_1_TITLE, WEBAPP_ICON); final int firstWebappId = firstActivity.getActivityTab().getId(); // Load up the test page. new TabLoadObserver(firstActivity.getActivityTab()).fullyLoadUrl(linkHtml); // Do a plain click to make the link open in the main browser via a window.open(). // If the window is opened successfully, javascript on the first page triggers and changes // its URL as a signal for this test. Runnable fgTrigger = new Runnable() { @Override public void run() { ThreadUtils.runOnUiThreadBlocking( new Runnable() { @Override public void run() { View view = firstActivity.findViewById(android.R.id.content).getRootView(); TouchCommon.singleClickView(view); } }); } }; ChromeActivity secondActivity = ActivityUtils.waitForActivity(getInstrumentation(), classToWaitFor, fgTrigger); waitForFullLoad(secondActivity, "Page 4"); if (checkContents) { assertEquals( "New WebContents was not created", SUCCESS_URL, firstActivity.getActivityTab().getUrl()); } assertNotSame( "Wrong Activity in foreground", firstActivity, ApplicationStatus.getLastTrackedFocusedActivity()); // Close the child window to kick the user back to the WebappActivity. JavaScriptUtils.executeJavaScript( secondActivity.getActivityTab().getWebContents(), "window.close()"); CriteriaHelper.pollUiThread( new Criteria() { @Override public boolean isSatisfied() { Activity lastActivity = ApplicationStatus.getLastTrackedFocusedActivity(); if (!isWebappActivityReady(lastActivity)) return false; WebappActivity webappActivity = (WebappActivity) lastActivity; return webappActivity.getActivityTab().getId() == firstWebappId; } }); ApplicationTestUtils.waitUntilChromeInForeground(); }
private PassphraseCreationDialogFragment getPassphraseCreationDialogFragment() throws InterruptedException { return ActivityUtils.<PassphraseCreationDialogFragment>waitForFragment( mPreferences, SyncCustomizationFragment.FRAGMENT_CUSTOM_PASSPHRASE); }