ContentViewPopupZoomerTest.java revision c5cede9ae108bb15f6b7a8aea21c7e1fefa2834c
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; 6 7import android.view.View; 8 9import org.chromium.base.test.util.DisabledTest; 10import org.chromium.base.test.util.UrlUtils; 11import org.chromium.content.browser.test.util.Criteria; 12import org.chromium.content.browser.test.util.CriteriaHelper; 13import org.chromium.content.browser.test.util.DOMUtils; 14import org.chromium.content.browser.test.util.TestCallbackHelperContainer; 15import org.chromium.content_shell_apk.ContentShellTestBase; 16 17import java.util.concurrent.TimeoutException; 18 19public class ContentViewPopupZoomerTest extends ContentShellTestBase { 20 private static PopupZoomer findPopupZoomer(ContentView view) { 21 assert view != null; 22 for (int i = 0; i < view.getChildCount(); i++) { 23 View child = view.getChildAt(i); 24 if (child instanceof PopupZoomer) return (PopupZoomer) child; 25 } 26 return null; 27 } 28 29 private static class PopupShowingCriteria implements Criteria { 30 private final ContentView mView; 31 private final boolean mShouldBeShown; 32 public PopupShowingCriteria(ContentView view, boolean shouldBeShown) { 33 mView = view; 34 mShouldBeShown = shouldBeShown; 35 } 36 @Override 37 public boolean isSatisfied() { 38 PopupZoomer popup = findPopupZoomer(mView); 39 boolean isVisibilitySet = popup == null ? false : popup.getVisibility() == View.VISIBLE; 40 return isVisibilitySet ? mShouldBeShown : !mShouldBeShown; 41 } 42 } 43 44 private static class PopupHasNonZeroDimensionsCriteria implements Criteria { 45 private final ContentView mView; 46 public PopupHasNonZeroDimensionsCriteria(ContentView view) { 47 mView = view; 48 } 49 @Override 50 public boolean isSatisfied() { 51 PopupZoomer popup = findPopupZoomer(mView); 52 if (popup == null) return false; 53 return popup.getWidth() != 0 && popup.getHeight() != 0; 54 } 55 } 56 57 private String generateTestUrl(int totalUrls, int targetIdAt, String targetId) { 58 StringBuilder testUrl = new StringBuilder(); 59 testUrl.append("<html><body>"); 60 for (int i = 0; i < totalUrls; i++) { 61 boolean isTargeted = i == targetIdAt; 62 testUrl.append("<a href=\"data:text/html;utf-8,<html><head><script>" + 63 "function doesItWork() { return 'yes'; }</script></head></html>\"" + 64 (isTargeted ? (" id=\"" + targetId + "\"") : "") + ">" + 65 "<small><sup>" + 66 (isTargeted ? "<b>" : "") + i + (isTargeted ? "</b>" : "") + 67 "</sup></small></a>"); 68 } 69 testUrl.append("</small></div></body></html>"); 70 return UrlUtils.encodeHtmlDataUri(testUrl.toString()); 71 } 72 73 public ContentViewPopupZoomerTest() { 74 } 75 76 /** 77 * Tests that shows a zoomer popup and makes sure it has valid dimensions. 78 */ 79 //@MediumTest 80 //@Feature({"Browser"}) 81 @DisabledTest // crbug.com/167045 82 public void testPopupZoomerShowsUp() throws InterruptedException, TimeoutException { 83 launchContentShellWithUrl(generateTestUrl(100, 15, "clickme")); 84 assertTrue("Page failed to load", waitForActiveShellToBeDoneLoading()); 85 86 final ContentView view = getActivity().getActiveContentView(); 87 final TestCallbackHelperContainer viewClient = 88 new TestCallbackHelperContainer(view); 89 90 // The popup should be hidden before the click. 91 assertTrue("The zoomer popup is shown after load.", 92 CriteriaHelper.pollForCriteria(new PopupShowingCriteria(view, false))); 93 94 // Once clicked, the popup should show up. 95 DOMUtils.clickNode(this, view, "clickme"); 96 assertTrue("The zoomer popup did not show up on click.", 97 CriteriaHelper.pollForCriteria(new PopupShowingCriteria(view, true))); 98 99 // The shown popup should have valid dimensions eventually. 100 assertTrue("The zoomer popup has zero dimensions.", 101 CriteriaHelper.pollForCriteria(new PopupHasNonZeroDimensionsCriteria(view))); 102 } 103} 104