SelectPopupTest.java revision 1320f92c476a1ad9d19dba2a48c72b75566198e9
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 23/** 24 * Integration Tests for SelectPopup. 25 */ 26public 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} 109