This source file includes following definitions.
- isSatisfied
- isSatisfied
- setUp
- Feature
- testReloadWhilePopupShowing
package org.chromium.content.browser.input;
import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout;
import android.test.suitebuilder.annotation.LargeTest;
import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.UrlUtils;
import org.chromium.content.browser.ContentView;
import org.chromium.content.browser.ContentViewCore;
import org.chromium.content.browser.test.util.Criteria;
import org.chromium.content.browser.test.util.CriteriaHelper;
import org.chromium.content.browser.test.util.DOMUtils;
import org.chromium.content.browser.test.util.TestCallbackHelperContainer;
import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnPageFinishedHelper;
import org.chromium.content_shell_apk.ContentShellTestBase;
import java.util.concurrent.TimeUnit;
public class SelectPopupTest extends ContentShellTestBase {
private static final long WAIT_TIMEOUT_SECONDS = scaleTimeout(2);
private static final String SELECT_URL = UrlUtils.encodeHtmlDataUri(
"<html><head><meta name=\"viewport\"" +
"content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0\" /></head>" +
"<body>Which animal is the strongest:<br/>" +
"<select id=\"select\">" +
"<option>Black bear</option>" +
"<option>Polar bear</option>" +
"<option>Grizzly</option>" +
"<option>Tiger</option>" +
"<option>Lion</option>" +
"<option>Gorilla</option>" +
"<option>Chipmunk</option>" +
"</select>" +
"</body></html>");
private class PopupShowingCriteria implements Criteria {
@Override
public boolean isSatisfied() {
ContentViewCore contentViewCore
= getActivity().getActiveContentView().getContentViewCore();
return contentViewCore.getSelectPopupForTest() != null;
}
}
private class PopupHiddenCriteria implements Criteria {
@Override
public boolean isSatisfied() {
ContentViewCore contentViewCore
= getActivity().getActiveContentView().getContentViewCore();
return contentViewCore.getSelectPopupForTest() == null;
}
}
@Override
public void setUp() throws Exception {
super.setUp();
launchContentShellWithUrl(SELECT_URL);
assertTrue("Page failed to load", waitForActiveShellToBeDoneLoading());
assertWaitForPageScaleFactorMatch(1);
}
@LargeTest
@Feature({"Browser"})
public void testReloadWhilePopupShowing() throws InterruptedException, Exception, Throwable {
assertTrue("The select popup is shown after load.",
CriteriaHelper.pollForCriteria(new PopupHiddenCriteria()));
final ContentView view = getActivity().getActiveContentView();
final TestCallbackHelperContainer viewClient =
new TestCallbackHelperContainer(view);
final OnPageFinishedHelper onPageFinishedHelper =
viewClient.getOnPageFinishedHelper();
DOMUtils.clickNode(this, view, viewClient, "select");
assertTrue("The select popup did not show up on click.",
CriteriaHelper.pollForCriteria(new PopupShowingCriteria()));
int currentCallCount = onPageFinishedHelper.getCallCount();
getInstrumentation().runOnMainSync(new Runnable() {
@Override
public void run() {
getActivity().getActiveShell().loadUrl(SELECT_URL);
}
});
onPageFinishedHelper.waitForCallback(currentCallCount, 1,
WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS);
assertTrue("The select popup did not hide after reload.",
CriteriaHelper.pollForCriteria(new PopupHiddenCriteria()));
DOMUtils.clickNode(this, view, viewClient, "select");
assertTrue("The select popup did not show on click after reload.",
CriteriaHelper.pollForCriteria(new PopupShowingCriteria()));
}
}