/** Verify Geolocation creates an InfoBar and that it's destroyed when navigating back. */ @MediumTest @Feature({"Browser"}) public void testInfoBarForGeolocationDisappearsOnBack() throws InterruptedException { LocationSettingsTestUtil.setSystemLocationSettingEnabled(true); loadUrl(HELLO_WORLD_URL); loadUrl(mTestServer.getURL(GEOLOCATION_PAGE)); assertTrue("InfoBar not added.", mListener.addInfoBarAnimationFinished()); assertEquals("Wrong infobar count", 1, getInfoBars().size()); // Navigate back and ensure the InfoBar has been removed. getInstrumentation() .runOnMainSync( new Runnable() { @Override public void run() { getActivity().getActivityTab().goBack(); } }); CriteriaHelper.pollForCriteria( new Criteria() { @Override public boolean isSatisfied() { return getInfoBars().isEmpty(); } }, MAX_TIMEOUT, CHECK_INTERVAL); assertTrue("InfoBar not removed.", mListener.removeInfoBarAnimationFinished()); }
@Override public void setUp() throws Exception { super.setUp(); mObserver = new MockOrientationObserver(); OrientationChangeObserverCriteria criteria = new OrientationChangeObserverCriteria(mObserver); final ContentShellActivity activity = launchContentShellWithUrl(DEFAULT_URL); waitForActiveShellToBeDoneLoading(); ThreadUtils.runOnUiThreadBlocking( new Runnable() { @Override public void run() { ScreenOrientationListener.getInstance().addObserver(mObserver, activity); ScreenOrientationProvider.startAccurateListening(); } }); // Make sure we start all the tests with the same orientation. lockOrientationAndWait(ScreenOrientationValues.PORTRAIT_PRIMARY); // Make sure mObserver is updated before we start the tests. CriteriaHelper.pollForCriteria(criteria); }
@SmallTest @Feature({"Webapps"}) @TargetApi(Build.VERSION_CODES.LOLLIPOP) public void testThemeColorNotUsedIfPagesHasOne() throws InterruptedException { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return; ThreadUtils.runOnUiThread( new Runnable() { @Override public void run() { TabTestUtils.simulateChangeThemeColor(getActivity().getActivityTab(), Color.GREEN); } }); // Waits for theme-color to change so the test doesn't rely on system timing. assertTrue( CriteriaHelper.pollForCriteria( new Criteria() { @Override public boolean isSatisfied() { return getActivity().getWindow().getStatusBarColor() == ColorUtils.getDarkenedColorForStatusBar(Color.GREEN); } })); }
private void ensureGeolocationRunning(final boolean running) throws Exception { CriteriaHelper.pollForCriteria( new Criteria() { @Override public boolean isSatisfied() { return mMockLocationProvider.isRunning() == running; } }); }
private void assertWaitForSelectActionBarStatus(final boolean show) throws InterruptedException { assertTrue( CriteriaHelper.pollForCriteria( new Criteria() { @Override public boolean isSatisfied() { return show == mContentViewCore.isSelectActionBarShowing(); } })); }
private void assertWaitForSelectionEditableEquals(final boolean expected) throws Throwable { assertTrue( CriteriaHelper.pollForCriteria( new Criteria() { @Override public boolean isSatisfied() { return getContentViewCore().isSelectionEditable() == expected; } })); }
private void assertWaitForKeyboardStatus(final boolean show) throws InterruptedException { assertTrue( CriteriaHelper.pollForCriteria( new Criteria() { @Override public boolean isSatisfied() { return show == getImeAdapter().mIsShowWithoutHideOutstanding && (!show || getAdapterInputConnection() != null); } })); }
public boolean waitForCallback() throws InterruptedException { return CriteriaHelper.pollForCriteria( new Criteria() { @Override public boolean isSatisfied() { return mGotPopupSelection.get(); } }, CALLBACK_TIMEOUT_MS, CHECK_INTERVAL_MS); }
private void assertWaitForHandleNear(final HandleView handle, final int x, final int y) throws Throwable { assertTrue( CriteriaHelper.pollForCriteria( new Criteria() { @Override public boolean isSatisfied() { return isHandleNear(handle, x, y); } })); }
/** * Waits for the UrlBar to have the expected focus state. * * @param urlBar The UrlBar whose focus is being inspected. * @param active Whether the UrlBar is expected to have focus or not. */ public static void waitForFocusAndKeyboardActive(final UrlBar urlBar, final boolean active) throws InterruptedException { CriteriaHelper.pollForCriteria( new Criteria() { @Override public boolean isSatisfied() { return (doesUrlBarHaveFocus(urlBar) == active) && (isKeyboardActiveForView(urlBar) == active); } }); }
private void waitForAutofillPopopShow(final AutofillPopup popup) throws InterruptedException { assertTrue( "Autofill Popup anchor view was never added.", CriteriaHelper.pollForCriteria( new Criteria() { @Override public boolean isSatisfied() { return popup.isShowing(); } })); }
private void waitForAnchorViewAdd(final ContentView view) throws InterruptedException { assertTrue( "Autofill Popup anchor view was never added.", CriteriaHelper.pollForCriteria( new Criteria() { @Override public boolean isSatisfied() { return view.findViewById(R.id.autofill_popup_window) != null; } })); }
private <T extends ChromeActivity> void triggerWindowOpenAndWaitForLoad( Class<T> classToWaitFor, String linkHtml, boolean checkContents) throws Exception { final WebappActivity webappActivity = startWebappActivity(WEBAPP_1_ID, WEBAPP_1_URL, WEBAPP_1_TITLE, WEBAPP_ICON); assertTrue(isNumberOfRunningActivitiesCorrect(1)); // Load up the test page. assertTrue( CriteriaHelper.pollForCriteria( new TabLoadObserver(webappActivity.getActivityTab(), 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 = webappActivity.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, webappActivity.getActivityTab().getUrl()); } assertNotSame( "Wrong Activity in foreground", webappActivity, ApplicationStatus.getLastTrackedFocusedActivity()); // Close the child window to kick the user back to the WebappActivity. JavaScriptUtils.executeJavaScript( secondActivity.getActivityTab().getWebContents(), "window.close()"); assertTrue( CriteriaHelper.pollForUIThreadCriteria( new Criteria() { @Override public boolean isSatisfied() { return webappActivity == ApplicationStatus.getLastTrackedFocusedActivity(); } })); ApplicationTestUtils.waitUntilChromeInForeground(); }
private void assertWaitForHasSelectionPosition() throws Throwable { assertTrue( CriteriaHelper.pollForCriteria( new Criteria() { @Override public boolean isSatisfied() { int start = getSelectionStart(); int end = getSelectionEnd(); return start > 0 && start == end; } })); }
private void waitForKeyboardShowRequest(final TestInputMethodManagerWrapper immw, final int count) throws InterruptedException { assertTrue( "Keyboard was never requested to be shown.", CriteriaHelper.pollForCriteria( new Criteria() { @Override public boolean isSatisfied() { return immw.getShowSoftInputCounter() == count; } })); }
private void assertWaitForEitherHandleNear(final int x, final int y) throws Throwable { final HandleView startHandle = getStartHandle(); final HandleView endHandle = getEndHandle(); assertTrue( CriteriaHelper.pollForCriteria( new Criteria() { @Override public boolean isSatisfied() { return isHandleNear(startHandle, x, y) || isHandleNear(endHandle, x, y); } })); }
private void assertWaitForHandlesShowingEquals(final boolean shouldBeShowing) throws Throwable { assertTrue( CriteriaHelper.pollForCriteria( new Criteria() { @Override public boolean isSatisfied() { SelectionHandleController shc = getContentViewCore().getSelectionHandleControllerForTest(); boolean isShowing = shc != null && shc.isShowing(); return shouldBeShowing == isShowing; } })); }
/** * Similar to CriteriaHelper.pollForCriteria but runs the callable on the UI thread. Note that * exceptions are treated as failure. */ protected boolean pollOnUiThread(final Callable<Boolean> callable) throws Throwable { return CriteriaHelper.pollForCriteria( new Criteria() { @Override public boolean isSatisfied() { try { return runTestOnUiThreadAndGetResult(callable); } catch (Throwable e) { return false; } } }); }
/** * Test fallback works as intended and that we can go back to the original URL even when * redirected via Java redirection. */ @MediumTest @Feature({"Navigation"}) public void testIntentFallbackRedirection() throws Exception { getInstrumentation().waitForIdleSync(); assertEquals(NEW_TAB_PAGE, getActivity().getActivityTab().getUrl()); final String redirectionUrl = TestHttpServerClient.getUrl("chrome/test/data/android/redirect/about.html"); final String initialUrl = TestHttpServerClient.getUrl( "chrome/test/data/android/redirect/js_redirect.cgi?location=" + URLEncoder.encode( "intent://non_existent/#Intent;scheme=non_existent;" + "S.browser_fallback_url=" + redirectionUrl + ";end", "UTF-8")); final String targetUrl = TestHttpServerClient.getUrl("chrome/test/data/android/redirect/one.html"); typeInOmniboxAndNavigate(initialUrl); // Now intent fallback should be triggered assuming 'non_existent' scheme cannot be handled. CriteriaHelper.pollForCriteria( new Criteria() { @Override public boolean isSatisfied() { return getActivity().getActivityTab().getUrl().equals(targetUrl); } }); // Check if Java redirections were removed from the history. // Note that if we try to go back in the test: NavigateToEntry() is called, but // DidNavigate() does not get called. But in real cases we can go back to initial page // without any problem. // TODO(changwan): figure out why we cannot go back on this test. int index = getActivity() .getActivityTab() .getWebContents() .getNavigationController() .getLastCommittedEntryIndex(); assertEquals(1, index); String previousNavigationUrl = getActivity() .getActivityTab() .getWebContents() .getNavigationController() .getEntryAtIndex(0) .getUrl(); assertEquals(NEW_TAB_PAGE, previousNavigationUrl); }
public static void clickOnLinkUsingJs( final InstrumentationTestCase testCase, final AwContents awContents, final OnEvaluateJavaScriptResultHelper onEvaluateJavaScriptResultHelper, final String linkId) throws Throwable { Assert.assertTrue( CriteriaHelper.pollForCriteria( new Criteria() { @Override public boolean isSatisfied() { try { String linkIsNotNull = executeJavaScriptAndWaitForResult( testCase, awContents, onEvaluateJavaScriptResultHelper, "document.getElementById('" + linkId + "') != null"); return linkIsNotNull.equals("true"); } catch (Throwable t) { t.printStackTrace(); Assert.fail("Failed to check if DOM is loaded: " + t.toString()); return false; } } }, WAIT_TIMEOUT_SECONDS * 1000, CHECK_INTERVAL)); testCase .getInstrumentation() .runOnMainSync( new Runnable() { @Override public void run() { awContents .getContentViewCore() .evaluateJavaScript( "var evObj = document.createEvent('Events'); " + "evObj.initEvent('click', true, false); " + "document.getElementById('" + linkId + "').dispatchEvent(evObj);" + "console.log('element with id [" + linkId + "] clicked');"); } }); }
/** Call |lockOrientation| and wait for an orientation change. */ private boolean lockOrientationAndWait(final int orientations) throws InterruptedException { OrientationChangeObserverCriteria criteria = new OrientationChangeObserverCriteria(mObserver); ThreadUtils.runOnUiThreadBlocking( new Runnable() { @Override public void run() { ScreenOrientationProvider.lockOrientation((byte) orientations); } }); getInstrumentation().waitForIdleSync(); return CriteriaHelper.pollForCriteria(criteria); }
private void assertWaitForHandleViewStopped(final HandleView handle) throws Throwable { assertTrue( CriteriaHelper.pollForCriteria( new Criteria() { private Point position = new Point(-1, -1); @Override public boolean isSatisfied() { Point lastPosition = position; position = getHandlePosition(handle); return !handle.isDragging() && position.equals(lastPosition); } })); }
public void assertWaitForHasInputConnection() { try { assertTrue( CriteriaHelper.pollForCriteria( new Criteria() { @Override public boolean isSatisfied() { return getContentViewCore().getInputConnectionForTest() != null; } })); } catch (InterruptedException e) { fail(); } }
/** Verifies the hung renderer InfoBar can kill the hung renderer. */ @Smoke @MediumTest @Feature({"Browser", "Main"}) public void testInfoBarForHungRendererCanKillRenderer() throws InterruptedException { loadUrl(HELLO_WORLD_URL); // Fake an unresponsive renderer signal. ThreadUtils.runOnUiThread( new Runnable() { @Override public void run() { CommandLine.getInstance().appendSwitch(ChromeSwitches.ENABLE_HUNG_RENDERER_INFOBAR); getActivity() .getActivityTab() .getTabWebContentsDelegateAndroid() .rendererUnresponsive(); } }); assertTrue("InfoBar not added", mListener.addInfoBarAnimationFinished()); // Make sure it has Kill/Wait buttons. final List<InfoBar> infoBars = getInfoBars(); assertEquals("Wrong infobar count", 1, infoBars.size()); assertTrue(InfoBarUtil.hasPrimaryButton(infoBars.get(0))); assertTrue(InfoBarUtil.hasSecondaryButton(infoBars.get(0))); // Activite the Kill button. ThreadUtils.runOnUiThread( new Runnable() { @Override public void run() { InfoBarUtil.clickPrimaryButton(infoBars.get(0)); } }); // The renderer should have been killed and the InfoBar removed. assertTrue("InfoBar not removed.", mListener.removeInfoBarAnimationFinished()); assertTrue("Wrong infobar count", getInfoBars().isEmpty()); CriteriaHelper.pollForCriteria( new Criteria() { @Override public boolean isSatisfied() { return getActivity().getActivityTab().isShowingSadTab(); } }, MAX_TIMEOUT, CHECK_INTERVAL); }
/** * Test re-direct functionality for a web-page. * * @throws Exception */ @MediumTest @Feature({"Navigation"}) public void testNavigateRedirect() throws Exception { final String initialUrl = TestHttpServerClient.getUrl("chrome/test/data/android/redirect/about.html"); final String redirectedUrl = TestHttpServerClient.getUrl("chrome/test/data/android/redirect/one.html"); typeInOmniboxAndNavigate(initialUrl); CriteriaHelper.pollForCriteria( new Criteria() { @Override public boolean isSatisfied() { return getActivity().getActivityTab().getUrl().equals(redirectedUrl); } }); }
private void waitForClientBookmarkCount(final int n) throws InterruptedException { boolean success = CriteriaHelper.pollForCriteria( new Criteria() { @Override public boolean isSatisfied() { try { return SyncTestUtil.getLocalData(mContext, BOOKMARKS_TYPE_STRING).size() == n; } catch (Exception e) { throw new RuntimeException(e); } } }, SyncTestUtil.UI_TIMEOUT_MS, SyncTestUtil.CHECK_INTERVAL_MS); assertTrue("There should be " + n + " local bookmarks.", success); }
/** * Wrapper around CriteriaHelper.pollForCriteria. This uses AwTestBase-specifc timeouts and treats * timeouts and exceptions as test failures automatically. */ public static void poll(final Callable<Boolean> callable) throws Exception { assertTrue( CriteriaHelper.pollForCriteria( new Criteria() { @Override public boolean isSatisfied() { try { return callable.call(); } catch (Throwable e) { Log.e(TAG, "Exception while polling.", e); return false; } } }, WAIT_TIMEOUT_MS, CHECK_INTERVAL)); }
public boolean openAutofillPopupAndWaitUntilReady(final AutofillSuggestion[] suggestions) throws InterruptedException { UiUtils.runOnUiThread( getActivity(), new Runnable() { @Override public void run() { mAutofillPopup.filterAndShow(suggestions, false); } }); return CriteriaHelper.pollForCriteria( new Criteria() { @Override public boolean isSatisfied() { return mAutofillPopup.getListView().getChildCount() > 0; } }); }
@HostDrivenTest public void testAboutSyncPageDisplaysCurrentSyncStatus() throws InterruptedException { setupTestAccountAndSignInToSync(FOREIGN_SESSION_TEST_MACHINE_ID); loadUrlWithSanitization("aviator://sync"); SyncTestUtil.AboutSyncInfoGetter aboutInfoGetter = new SyncTestUtil.AboutSyncInfoGetter(getActivity()); try { runTestOnUiThread(aboutInfoGetter); } catch (Throwable t) { Log.w(TAG, "Exception while trying to fetch about sync info from ProfileSyncService.", t); fail("Unable to fetch sync info from ProfileSyncService."); } assertFalse("About sync info should not be empty.", aboutInfoGetter.getAboutInfo().isEmpty()); assertTrue( "About sync info should have sync summary status.", aboutInfoGetter.getAboutInfo().containsKey(SyncTestUtil.SYNC_SUMMARY_STATUS)); final String expectedSyncSummary = aboutInfoGetter.getAboutInfo().get(SyncTestUtil.SYNC_SUMMARY_STATUS); Criteria checker = new Criteria() { @Override public boolean isSatisfied() { final ContentViewCore contentViewCore = getContentViewCore(getActivity()); String innerHtml = ""; try { innerHtml = JavaScriptUtils.executeJavaScriptAndWaitForResult( contentViewCore, "document.documentElement.innerHTML"); } catch (InterruptedException e) { Log.w(TAG, "Interrupted while polling about:sync page for sync status.", e); } catch (TimeoutException e) { Log.w(TAG, "Interrupted while polling about:sync page for sync status.", e); } return innerHtml.contains(expectedSyncSummary); } }; boolean hadExpectedStatus = CriteriaHelper.pollForCriteria( checker, SyncTestUtil.UI_TIMEOUT_MS, SyncTestUtil.CHECK_INTERVAL_MS); assertTrue( "Sync status not present on about sync page: " + expectedSyncSummary, hadExpectedStatus); }
private void pollForPositionCallback() throws Throwable { mJavascriptHelper.evaluateJavaScriptForTests(getWebContents(), "positionCount = 0"); mJavascriptHelper.waitUntilHasValue(); assertEquals(0, Integer.parseInt(mJavascriptHelper.getJsonResultAndClear())); CriteriaHelper.pollForCriteria( new Criteria() { @Override public boolean isSatisfied() { mJavascriptHelper.evaluateJavaScriptForTests(getWebContents(), "positionCount"); try { mJavascriptHelper.waitUntilHasValue(); } catch (Exception e) { fail(); } return Integer.parseInt(mJavascriptHelper.getJsonResultAndClear()) > 0; } }); }