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.
5 package org.chromium.content.browser;
7 import android.view.View;
8 import android.view.ViewGroup;
10 import org.chromium.base.test.util.DisabledTest;
11 import org.chromium.base.test.util.UrlUtils;
12 import org.chromium.content.browser.test.util.Criteria;
13 import org.chromium.content.browser.test.util.CriteriaHelper;
14 import org.chromium.content.browser.test.util.DOMUtils;
15 import org.chromium.content_shell_apk.ContentShellTestBase;
17 import java.util.concurrent.TimeoutException;
19 public class ContentViewPopupZoomerTest extends ContentShellTestBase {
20 private static PopupZoomer findPopupZoomer(ViewGroup view) {
22 for (int i = 0; i < view.getChildCount(); i++) {
23 View child = view.getChildAt(i);
24 if (child instanceof PopupZoomer) return (PopupZoomer) child;
29 private static class PopupShowingCriteria implements Criteria {
30 private final ViewGroup mView;
31 private final boolean mShouldBeShown;
32 public PopupShowingCriteria(ViewGroup view, boolean shouldBeShown) {
34 mShouldBeShown = shouldBeShown;
37 public boolean isSatisfied() {
38 PopupZoomer popup = findPopupZoomer(mView);
39 boolean isVisibilitySet = popup == null ? false : popup.getVisibility() == View.VISIBLE;
40 return isVisibilitySet ? mShouldBeShown : !mShouldBeShown;
44 private static class PopupHasNonZeroDimensionsCriteria implements Criteria {
45 private final ViewGroup mView;
46 public PopupHasNonZeroDimensionsCriteria(ViewGroup view) {
50 public boolean isSatisfied() {
51 PopupZoomer popup = findPopupZoomer(mView);
52 if (popup == null) return false;
53 return popup.getWidth() != 0 && popup.getHeight() != 0;
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 + "\"") : "") + ">" +
66 (isTargeted ? "<b>" : "") + i + (isTargeted ? "</b>" : "") +
67 "</sup></small></a>");
69 testUrl.append("</small></div></body></html>");
70 return UrlUtils.encodeHtmlDataUri(testUrl.toString());
73 public ContentViewPopupZoomerTest() {
77 * Tests that shows a zoomer popup and makes sure it has valid dimensions.
80 //@Feature({"Browser"})
81 //@RerunWithUpdatedContainerView -> this test should pass with this new annotation.
82 @DisabledTest // crbug.com/167045
83 public void testPopupZoomerShowsUp() throws InterruptedException, TimeoutException {
84 launchContentShellWithUrl(generateTestUrl(100, 15, "clickme"));
85 assertTrue("Page failed to load", waitForActiveShellToBeDoneLoading());
87 final ContentViewCore viewCore = getContentViewCore();
88 final ViewGroup view = viewCore.getContainerView();
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)));
94 // Once clicked, the popup should show up.
95 DOMUtils.clickNode(this, viewCore, "clickme");
96 assertTrue("The zoomer popup did not show up on click.",
97 CriteriaHelper.pollForCriteria(new PopupShowingCriteria(view, true)));
99 // The shown popup should have valid dimensions eventually.
100 assertTrue("The zoomer popup has zero dimensions.",
101 CriteriaHelper.pollForCriteria(new PopupHasNonZeroDimensionsCriteria(view)));