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.chrome.browser.input;
7 import org.chromium.base.ThreadUtils;
8 import org.chromium.base.test.util.DisabledTest;
9 import org.chromium.base.test.util.UrlUtils;
10 import org.chromium.chrome.browser.ContentViewUtil;
11 import org.chromium.chrome.shell.ChromeShellTestBase;
12 import org.chromium.content.browser.ContentView;
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.ui.base.ActivityWindowAndroid;
18 import org.chromium.ui.base.WindowAndroid;
20 public class SelectPopupOtherContentViewTest extends ChromeShellTestBase {
21 private static final String SELECT_URL = UrlUtils.encodeHtmlDataUri(
23 "Which animal is the strongest:<br/>" +
24 "<select id=\"select\">" +
25 "<option>Black bear</option>" +
26 "<option>Polar bear</option>" +
27 "<option>Grizzly</option>" +
28 "<option>Tiger</option>" +
29 "<option>Lion</option>" +
30 "<option>Gorilla</option>" +
31 "<option>Chipmunk</option>" +
35 private class PopupShowingCriteria implements Criteria {
37 public boolean isSatisfied() {
38 ContentViewCore contentViewCore = getActivity().getActiveContentViewCore();
39 return contentViewCore.getSelectPopupForTest() != null;
43 public SelectPopupOtherContentViewTest() {
47 * Tests that the showing select popup does not get closed because an unrelated ContentView
51 * @Feature({"Browser"})
55 public void testPopupNotClosedByOtherContentView()
56 throws InterruptedException, Exception, Throwable {
57 // Load the test page.
58 launchChromeShellWithUrl(SELECT_URL);
59 assertTrue("Page failed to load", waitForActiveShellToBeDoneLoading());
61 final ContentViewCore viewCore = getActivity().getActiveContentViewCore();
63 // Once clicked, the popup should show up.
64 DOMUtils.clickNode(this, viewCore, "select");
65 assertTrue("The select popup did not show up on click.",
66 CriteriaHelper.pollForCriteria(new PopupShowingCriteria()));
68 // Now create and destroy a different ContentView.
69 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
72 long nativeWebContents = ContentViewUtil.createNativeWebContents(false);
73 WindowAndroid windowAndroid = new ActivityWindowAndroid(getActivity());
75 ContentViewCore contentViewCore = new ContentViewCore(getActivity());
76 ContentView cv = ContentView.newInstance(getActivity(), contentViewCore);
77 contentViewCore.initialize(cv, cv, nativeWebContents, windowAndroid);
78 contentViewCore.destroy();
82 // Process some more events to give a chance to the dialog to hide if it were to.
83 getInstrumentation().waitForIdleSync();
85 // The popup should still be shown.
86 assertNotNull("The select popup got hidden by destroying of unrelated ContentViewCore.",
87 viewCore.getSelectPopupForTest());