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