Upstream version 11.40.277.0
[platform/framework/web/crosswalk.git] / src / content / public / android / javatests / src / org / chromium / content / browser / ContentViewPopupZoomerTest.java
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
5 package org.chromium.content.browser;
6
7 import android.view.View;
8 import android.view.ViewGroup;
9
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;
16
17 import java.util.concurrent.TimeoutException;
18
19 public class ContentViewPopupZoomerTest extends ContentShellTestBase {
20     private static PopupZoomer findPopupZoomer(ViewGroup 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 ViewGroup mView;
31         private final boolean mShouldBeShown;
32         public PopupShowingCriteria(ViewGroup 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 ViewGroup mView;
46         public PopupHasNonZeroDimensionsCriteria(ViewGroup 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     //@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());
86
87         final ContentViewCore viewCore = getContentViewCore();
88         final ViewGroup view = viewCore.getContainerView();
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, viewCore, "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 }