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.chrome.browser.input;
7 import android.test.suitebuilder.annotation.LargeTest;
9 import org.chromium.base.test.util.DisabledTest;
10 import org.chromium.base.test.util.Feature;
11 import org.chromium.base.test.util.UrlUtils;
12 import org.chromium.content.browser.ContentView;
13 import org.chromium.content.browser.input.SelectPopupDialog;
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.UiUtils;
19 import org.chromium.chrome.browser.ContentViewUtil;
20 import org.chromium.chrome.testshell.ChromiumTestShellTestBase;
21 import org.chromium.ui.WindowAndroid;
23 import java.util.concurrent.TimeUnit;
25 public class SelectPopupOtherContentViewTest extends ChromiumTestShellTestBase {
26 private static final int WAIT_TIMEOUT_SECONDS = 2;
27 private static final String SELECT_URL = UrlUtils.encodeHtmlDataUri(
29 "Which animal is the strongest:<br/>" +
30 "<select id=\"select\">" +
31 "<option>Black bear</option>" +
32 "<option>Polar bear</option>" +
33 "<option>Grizzly</option>" +
34 "<option>Tiger</option>" +
35 "<option>Lion</option>" +
36 "<option>Gorilla</option>" +
37 "<option>Chipmunk</option>" +
41 private static class PopupShowingCriteria implements Criteria {
43 public boolean isSatisfied() {
44 return SelectPopupDialog.getCurrent() != null;
48 public SelectPopupOtherContentViewTest() {
52 * Tests that the showing select popup does not get closed because an unrelated ContentView
56 * @Feature({"Browser"})
60 public void testPopupNotClosedByOtherContentView()
61 throws InterruptedException, Exception, Throwable {
62 // Load the test page.
63 launchChromiumTestShellWithUrl(SELECT_URL);
64 assertTrue("Page failed to load", waitForActiveShellToBeDoneLoading());
66 final ContentView view = getActivity().getActiveContentView();
67 final TestCallbackHelperContainer viewClient =
68 new TestCallbackHelperContainer(view);
70 // Once clicked, the popup should show up.
71 DOMUtils.clickNode(this, view, viewClient, "select");
72 assertTrue("The select popup did not show up on click.",
73 CriteriaHelper.pollForCriteria(new PopupShowingCriteria()));
75 // Now create and destroy a different ContentView.
76 UiUtils.runOnUiThread(getActivity(), new Runnable() {
79 int nativeWebContents = ContentViewUtil.createNativeWebContents(false);
80 WindowAndroid windowAndroid = new WindowAndroid(getActivity());
81 ContentView contentView = ContentView.newInstance(
82 getActivity(), nativeWebContents, windowAndroid);
83 contentView.destroy();
87 // Process some more events to give a chance to the dialog to hide if it were to.
88 getInstrumentation().waitForIdleSync();
90 // The popup should still be shown.
91 assertNotNull("The select popup got hidden by destroying of unrelated ContentViewCore.",
92 SelectPopupDialog.getCurrent());