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