1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 package org.chromium.content.browser.input;
7 import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout;
9 import android.test.suitebuilder.annotation.LargeTest;
11 import org.chromium.base.test.util.Feature;
12 import org.chromium.base.test.util.UrlUtils;
13 import org.chromium.content.browser.ContentViewCore;
14 import org.chromium.content.browser.test.util.Criteria;
15 import org.chromium.content.browser.test.util.CriteriaHelper;
16 import org.chromium.content.browser.test.util.DOMUtils;
17 import org.chromium.content.browser.test.util.TestCallbackHelperContainer;
18 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnPageFinishedHelper;
19 import org.chromium.content_shell_apk.ContentShellTestBase;
21 import java.util.concurrent.TimeUnit;
24 * Integration Tests for SelectPopup.
26 public class SelectPopupTest extends ContentShellTestBase {
27 private static final long WAIT_TIMEOUT_SECONDS = scaleTimeout(2);
28 private static final String SELECT_URL = UrlUtils.encodeHtmlDataUri(
29 "<html><head><meta name=\"viewport\"" +
30 "content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0\" /></head>" +
31 "<body>Which animal is the strongest:<br/>" +
32 "<select id=\"select\">" +
33 "<option>Black bear</option>" +
34 "<option>Polar bear</option>" +
35 "<option>Grizzly</option>" +
36 "<option>Tiger</option>" +
37 "<option>Lion</option>" +
38 "<option>Gorilla</option>" +
39 "<option>Chipmunk</option>" +
43 private class PopupShowingCriteria implements Criteria {
45 public boolean isSatisfied() {
46 return getContentViewCore().getSelectPopupForTest() != null;
50 private class PopupHiddenCriteria implements Criteria {
52 public boolean isSatisfied() {
53 return getContentViewCore().getSelectPopupForTest() == null;
58 public void setUp() throws Exception {
60 launchContentShellWithUrl(SELECT_URL);
61 assertTrue("Page failed to load", waitForActiveShellToBeDoneLoading());
62 // TODO(aurimas) remove this wait once crbug.com/179511 is fixed.
63 assertWaitForPageScaleFactorMatch(1);
67 * Tests that showing a select popup and having the page reload while the popup is showing does
72 @RerunWithUpdatedContainerView
73 public void testReloadWhilePopupShowing() throws InterruptedException, Exception, Throwable {
74 // The popup should be hidden before the click.
75 assertTrue("The select popup is shown after load.",
76 CriteriaHelper.pollForCriteria(new PopupHiddenCriteria()));
78 final ContentViewCore viewCore = getContentViewCore();
79 final TestCallbackHelperContainer viewClient = new TestCallbackHelperContainer(viewCore);
80 final OnPageFinishedHelper onPageFinishedHelper = viewClient.getOnPageFinishedHelper();
82 // Once clicked, the popup should show up.
83 DOMUtils.clickNode(this, viewCore, "select");
84 assertTrue("The select popup did not show up on click.",
85 CriteriaHelper.pollForCriteria(new PopupShowingCriteria()));
87 // Reload the test page.
88 int currentCallCount = onPageFinishedHelper.getCallCount();
89 getInstrumentation().runOnMainSync(new Runnable() {
92 // Now reload the page while the popup is showing, it gets hidden.
93 getContentViewCore().getWebContents().getNavigationController().reload(true);
96 onPageFinishedHelper.waitForCallback(currentCallCount, 1,
97 WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS);
99 // The popup should be hidden after the page reload.
100 assertTrue("The select popup did not hide after reload.",
101 CriteriaHelper.pollForCriteria(new PopupHiddenCriteria()));
103 // Click the select and wait for the popup to show.
104 DOMUtils.clickNode(this, viewCore, "select");
105 assertTrue("The select popup did not show on click after reload.",
106 CriteriaHelper.pollForCriteria(new PopupShowingCriteria()));