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. |
4 | |
5 | package org.chromium.chrome.browser.input; |
6 | |
7 | import android.test.suitebuilder.annotation.LargeTest; |
8 | |
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; |
22 | |
23 | import java.util.concurrent.TimeUnit; |
24 | |
25 | public class SelectPopupOtherContentViewTest extends ChromiumTestShellTestBase { |
26 | private static final int WAIT_TIMEOUT_SECONDS = 2; |
27 | private static final String SELECT_URL = UrlUtils.encodeHtmlDataUri( |
28 | "<html><body>" + |
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>" + |
38 | "</select>" + |
39 | "</body></html>"); |
40 | |
41 | private static class PopupShowingCriteria implements Criteria { |
42 | @Override |
43 | public boolean isSatisfied() { |
44 | return SelectPopupDialog.getCurrent() != null; |
45 | } |
46 | } |
47 | |
48 | public SelectPopupOtherContentViewTest() { |
49 | } |
50 | |
51 | /** |
52 | * Tests that the showing select popup does not get closed because an unrelated ContentView |
53 | * gets destroyed. |
54 | * |
55 | * @LargeTest |
56 | * @Feature({"Browser"}) |
57 | * BUG 172967 |
58 | */ |
59 | @DisabledTest |
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()); |
65 | |
66 | final ContentView view = getActivity().getActiveContentView(); |
67 | final TestCallbackHelperContainer viewClient = |
68 | new TestCallbackHelperContainer(view); |
69 | |
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())); |
74 | |
75 | // Now create and destroy a different ContentView. |
76 | UiUtils.runOnUiThread(getActivity(), new Runnable() { |
77 | @Override |
78 | public void run() { |
79 | int nativeWebContents = ContentViewUtil.createNativeWebContents(false); |
80 | WindowAndroid windowAndroid = new WindowAndroid(getActivity()); |
81 | ContentView contentView = ContentView.newInstance( |
82 | getActivity(), nativeWebContents, windowAndroid); |
83 | contentView.destroy(); |
84 | } |
85 | }); |
86 | |
87 | // Process some more events to give a chance to the dialog to hide if it were to. |
88 | getInstrumentation().waitForIdleSync(); |
89 | |
90 | // The popup should still be shown. |
91 | assertNotNull("The select popup got hidden by destroying of unrelated ContentViewCore.", |
92 | SelectPopupDialog.getCurrent()); |
93 | } |
94 | } |