Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / android / javatests / src / org / chromium / chrome / browser / input / SelectPopupOtherContentViewTest.java
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.
4
5 package org.chromium.chrome.browser.input;
6
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;
19
20 public class SelectPopupOtherContentViewTest extends ChromeShellTestBase {
21     private static final String SELECT_URL = UrlUtils.encodeHtmlDataUri(
22             "<html><body>" +
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>" +
32             "</select>" +
33             "</body></html>");
34
35     private class PopupShowingCriteria implements Criteria {
36         @Override
37         public boolean isSatisfied() {
38             ContentViewCore contentViewCore = getActivity().getActiveContentViewCore();
39             return contentViewCore.getSelectPopupForTest() != null;
40         }
41     }
42
43     public SelectPopupOtherContentViewTest() {
44     }
45
46     /**
47      * Tests that the showing select popup does not get closed because an unrelated ContentView
48      * gets destroyed.
49      *
50      * @LargeTest
51      * @Feature({"Browser"})
52      * BUG 172967
53     */
54     @DisabledTest
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());
60
61         final ContentViewCore viewCore = getActivity().getActiveContentViewCore();
62
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()));
67
68         // Now create and destroy a different ContentView.
69         ThreadUtils.runOnUiThreadBlocking(new Runnable() {
70             @Override
71             public void run() {
72                 long nativeWebContents = ContentViewUtil.createNativeWebContents(false);
73                 WindowAndroid windowAndroid = new ActivityWindowAndroid(getActivity());
74
75                 ContentViewCore contentViewCore = new ContentViewCore(getActivity());
76                 ContentView cv = ContentView.newInstance(getActivity(), contentViewCore);
77                 contentViewCore.initialize(cv, cv, nativeWebContents, windowAndroid);
78                 contentViewCore.destroy();
79             }
80         });
81
82         // Process some more events to give a chance to the dialog to hide if it were to.
83         getInstrumentation().waitForIdleSync();
84
85         // The popup should still be shown.
86         assertNotNull("The select popup got hidden by destroying of unrelated ContentViewCore.",
87                 viewCore.getSelectPopupForTest());
88     }
89 }