Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / content / public / android / javatests / src / org / chromium / content / browser / input / SelectPopupTest.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.content.browser.input;
6
7 import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout;
8
9 import android.test.suitebuilder.annotation.LargeTest;
10
11 import org.chromium.base.test.util.Feature;
12 import org.chromium.base.test.util.UrlUtils;
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.content.browser.test.util.TestCallbackHelperContainer;
18 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnPageFinishedHelper;
19 import org.chromium.content_shell_apk.ContentShellTestBase;
20
21 import java.util.concurrent.TimeUnit;
22
23 /**
24  * Integration Tests for SelectPopup.
25  */
26 public class SelectPopupTest extends ContentShellTestBase {
27     private static final long WAIT_TIMEOUT_SECONDS = scaleTimeout(2);
28     private static final String SELECT_URL = UrlUtils.encodeHtmlDataUri(
29             "<html><head><meta name=\"viewport\"" +
30             "content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0\" /></head>" +
31             "<body>Which animal is the strongest:<br/>" +
32             "<select id=\"select\">" +
33             "<option>Black bear</option>" +
34             "<option>Polar bear</option>" +
35             "<option>Grizzly</option>" +
36             "<option>Tiger</option>" +
37             "<option>Lion</option>" +
38             "<option>Gorilla</option>" +
39             "<option>Chipmunk</option>" +
40             "</select>" +
41             "</body></html>");
42
43     private class PopupShowingCriteria implements Criteria {
44         @Override
45         public boolean isSatisfied() {
46            return getContentViewCore().getSelectPopupForTest() != null;
47         }
48     }
49
50     private class PopupHiddenCriteria implements Criteria {
51         @Override
52         public boolean isSatisfied() {
53             return getContentViewCore().getSelectPopupForTest() == null;
54         }
55     }
56
57     @Override
58     public void setUp() throws Exception {
59         super.setUp();
60         launchContentShellWithUrl(SELECT_URL);
61         assertTrue("Page failed to load", waitForActiveShellToBeDoneLoading());
62         // TODO(aurimas) remove this wait once crbug.com/179511 is fixed.
63         assertWaitForPageScaleFactorMatch(1);
64     }
65
66     /**
67      * Tests that showing a select popup and having the page reload while the popup is showing does
68      * not assert.
69      */
70     @LargeTest
71     @Feature({"Browser"})
72     @RerunWithUpdatedContainerView
73     public void testReloadWhilePopupShowing() throws InterruptedException, Exception, Throwable {
74         // The popup should be hidden before the click.
75         assertTrue("The select popup is shown after load.",
76                 CriteriaHelper.pollForCriteria(new PopupHiddenCriteria()));
77
78         final ContentViewCore viewCore = getContentViewCore();
79         final TestCallbackHelperContainer viewClient = new TestCallbackHelperContainer(viewCore);
80         final OnPageFinishedHelper onPageFinishedHelper = viewClient.getOnPageFinishedHelper();
81
82         // Once clicked, the popup should show up.
83         DOMUtils.clickNode(this, viewCore, "select");
84         assertTrue("The select popup did not show up on click.",
85                 CriteriaHelper.pollForCriteria(new PopupShowingCriteria()));
86
87         // Reload the test page.
88         int currentCallCount = onPageFinishedHelper.getCallCount();
89         getInstrumentation().runOnMainSync(new Runnable() {
90             @Override
91             public void run() {
92                 // Now reload the page while the popup is showing, it gets hidden.
93                 getContentViewCore().getWebContents().getNavigationController().reload(true);
94             }
95         });
96         onPageFinishedHelper.waitForCallback(currentCallCount, 1,
97                 WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS);
98
99         // The popup should be hidden after the page reload.
100         assertTrue("The select popup did not hide after reload.",
101                 CriteriaHelper.pollForCriteria(new PopupHiddenCriteria()));
102
103         // Click the select and wait for the popup to show.
104         DOMUtils.clickNode(this, viewCore, "select");
105         assertTrue("The select popup did not show on click after reload.",
106                 CriteriaHelper.pollForCriteria(new PopupShowingCriteria()));
107     }
108 }