1 // Copyright (c) 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 android.test.suitebuilder.annotation.LargeTest;
9 import org.chromium.base.test.util.Feature;
10 import org.chromium.base.test.util.UrlUtils;
11 import org.chromium.content.browser.ContentView;
12 import org.chromium.content.browser.test.util.Criteria;
13 import org.chromium.content.browser.test.util.CriteriaHelper;
14 import org.chromium.content.browser.test.util.DOMUtils;
15 import org.chromium.content.browser.test.util.TestCallbackHelperContainer;
16 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnPageFinishedHelper;
17 import org.chromium.content_shell_apk.ContentShellTestBase;
19 import java.util.concurrent.TimeUnit;
21 public class SelectPopupTest extends ContentShellTestBase {
22 private static final int WAIT_TIMEOUT_SECONDS = 2;
23 private static final String SELECT_URL = UrlUtils.encodeHtmlDataUri(
24 "<html><head><meta name=\"viewport\"" +
25 "content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0\" /></head>" +
26 "<body>Which animal is the strongest:<br/>" +
27 "<select id=\"select\">" +
28 "<option>Black bear</option>" +
29 "<option>Polar bear</option>" +
30 "<option>Grizzly</option>" +
31 "<option>Tiger</option>" +
32 "<option>Lion</option>" +
33 "<option>Gorilla</option>" +
34 "<option>Chipmunk</option>" +
38 private static class PopupShowingCriteria implements Criteria {
40 public boolean isSatisfied() {
41 return SelectPopupDialog.getCurrent() != null;
45 private static class PopupHiddenCriteria implements Criteria {
47 public boolean isSatisfied() {
48 return SelectPopupDialog.getCurrent() == null;
53 public void setUp() throws Exception {
55 launchContentShellWithUrl(SELECT_URL);
56 assertTrue("Page failed to load", waitForActiveShellToBeDoneLoading());
57 // TODO(aurimas) remove this wait once crbug.com/179511 is fixed.
58 assertWaitForPageScaleFactorMatch(1);
62 * Tests that showing a select popup and having the page reload while the popup is showing does
67 public void testReloadWhilePopupShowing() throws InterruptedException, Exception, Throwable {
68 // The popup should be hidden before the click.
69 assertTrue("The select popup is shown after load.",
70 CriteriaHelper.pollForCriteria(new PopupHiddenCriteria()));
72 final ContentView view = getActivity().getActiveContentView();
73 final TestCallbackHelperContainer viewClient =
74 new TestCallbackHelperContainer(view);
75 final OnPageFinishedHelper onPageFinishedHelper =
76 viewClient.getOnPageFinishedHelper();
78 // Once clicked, the popup should show up.
79 DOMUtils.clickNode(this, view, viewClient, "select");
80 assertTrue("The select popup did not show up on click.",
81 CriteriaHelper.pollForCriteria(new PopupShowingCriteria()));
83 // Reload the test page.
84 int currentCallCount = onPageFinishedHelper.getCallCount();
85 getInstrumentation().runOnMainSync(new Runnable() {
88 // Now reload the page while the popup is showing, it gets hidden.
89 getActivity().getActiveShell().loadUrl(SELECT_URL);
92 onPageFinishedHelper.waitForCallback(currentCallCount, 1,
93 WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS);
95 // The popup should be hidden after the page reload.
96 assertTrue("The select popup did not hide after reload.",
97 CriteriaHelper.pollForCriteria(new PopupHiddenCriteria()));
99 // Click the select and wait for the popup to show.
100 DOMUtils.clickNode(this, view, viewClient, "select");
101 assertTrue("The select popup did not show on click after reload.",
102 CriteriaHelper.pollForCriteria(new PopupShowingCriteria()));