| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.content.browser; | 5 package org.chromium.content.browser; |
| 6 | 6 |
| 7 import android.support.test.InstrumentationRegistry; |
| 7 import android.support.test.filters.MediumTest; | 8 import android.support.test.filters.MediumTest; |
| 8 import android.view.KeyEvent; | 9 import android.view.KeyEvent; |
| 9 import android.view.View; | 10 import android.view.View; |
| 10 import android.view.ViewGroup; | 11 import android.view.ViewGroup; |
| 11 | 12 |
| 12 import org.chromium.base.test.util.Feature; | 13 import org.chromium.base.test.util.Feature; |
| 13 import org.chromium.base.test.util.RetryOnFailure; | 14 import org.chromium.base.test.util.RetryOnFailure; |
| 14 import org.chromium.base.test.util.UrlUtils; | 15 import org.chromium.base.test.util.UrlUtils; |
| 15 import org.chromium.content.browser.test.util.Criteria; | 16 import org.chromium.content.browser.test.util.Criteria; |
| 16 import org.chromium.content.browser.test.util.CriteriaHelper; | 17 import org.chromium.content.browser.test.util.CriteriaHelper; |
| 17 import org.chromium.content.browser.test.util.DOMUtils; | 18 import org.chromium.content.browser.test.util.DOMUtils; |
| 18 import org.chromium.content_shell_apk.ContentShellTestBase; | |
| 19 | 19 |
| 20 import java.util.concurrent.TimeoutException; | 20 import java.util.concurrent.TimeoutException; |
| 21 | 21 |
| 22 import org.junit.Rule; |
| 23 import org.junit.Test; |
| 24 import org.chromium.base.test.BaseJUnit4ClassRunner; |
| 25 import org.junit.runner.RunWith; |
| 26 import org.chromium.content_shell_apk.ContentShellActivityTestRule; |
| 27 |
| 22 /** | 28 /** |
| 23 * Class which provides test coverage for Popup Zoomer. | 29 * Class which provides test coverage for Popup Zoomer. |
| 24 */ | 30 */ |
| 31 @RunWith(BaseJUnit4ClassRunner.class) |
| 25 @RetryOnFailure | 32 @RetryOnFailure |
| 26 public class ContentViewPopupZoomerTest extends ContentShellTestBase { | 33 public class ContentViewPopupZoomerTest { |
| 34 |
| 35 @Rule |
| 36 public ContentShellActivityTestRule mActivityTestRule = new ContentShellActi
vityTestRule(); |
| 27 private static PopupZoomer findPopupZoomer(ViewGroup view) { | 37 private static PopupZoomer findPopupZoomer(ViewGroup view) { |
| 28 assert view != null; | 38 assert view != null; |
| 29 for (int i = 0; i < view.getChildCount(); i++) { | 39 for (int i = 0; i < view.getChildCount(); i++) { |
| 30 View child = view.getChildAt(i); | 40 View child = view.getChildAt(i); |
| 31 if (child instanceof PopupZoomer) return (PopupZoomer) child; | 41 if (child instanceof PopupZoomer) return (PopupZoomer) child; |
| 32 } | 42 } |
| 33 return null; | 43 return null; |
| 34 } | 44 } |
| 35 | 45 |
| 36 private static class PopupShowingCriteria extends Criteria { | 46 private static class PopupShowingCriteria extends Criteria { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 testUrl.append("</small></div></body></html>"); | 88 testUrl.append("</small></div></body></html>"); |
| 79 return UrlUtils.encodeHtmlDataUri(testUrl.toString()); | 89 return UrlUtils.encodeHtmlDataUri(testUrl.toString()); |
| 80 } | 90 } |
| 81 | 91 |
| 82 public ContentViewPopupZoomerTest() { | 92 public ContentViewPopupZoomerTest() { |
| 83 } | 93 } |
| 84 | 94 |
| 85 /** | 95 /** |
| 86 * Tests that shows a zoomer popup and makes sure it has valid dimensions. | 96 * Tests that shows a zoomer popup and makes sure it has valid dimensions. |
| 87 */ | 97 */ |
| 98 @Test |
| 88 @MediumTest | 99 @MediumTest |
| 89 @Feature({"Browser"}) | 100 @Feature({"Browser"}) |
| 90 public void testPopupZoomerShowsUp() throws InterruptedException, TimeoutExc
eption { | 101 public void testPopupZoomerShowsUp() throws InterruptedException, TimeoutExc
eption { |
| 91 launchContentShellWithUrl(generateTestUrl(100, 15, "clickme")); | 102 mActivityTestRule.launchContentShellWithUrl(generateTestUrl(100, 15, "cl
ickme")); |
| 92 waitForActiveShellToBeDoneLoading(); | 103 mActivityTestRule.waitForActiveShellToBeDoneLoading(); |
| 93 | 104 |
| 94 final ContentViewCore viewCore = getContentViewCore(); | 105 final ContentViewCore viewCore = mActivityTestRule.getContentViewCore(); |
| 95 final ViewGroup view = viewCore.getContainerView(); | 106 final ViewGroup view = viewCore.getContainerView(); |
| 96 | 107 |
| 97 // The popup should be hidden before the click. | 108 // The popup should be hidden before the click. |
| 98 CriteriaHelper.pollInstrumentationThread(new PopupShowingCriteria(view,
false)); | 109 CriteriaHelper.pollInstrumentationThread(new PopupShowingCriteria(view,
false)); |
| 99 | 110 |
| 100 // Once clicked, the popup should show up. | 111 // Once clicked, the popup should show up. |
| 101 DOMUtils.clickNode(viewCore, "clickme"); | 112 DOMUtils.clickNode(viewCore, "clickme"); |
| 102 CriteriaHelper.pollInstrumentationThread(new PopupShowingCriteria(view,
true)); | 113 CriteriaHelper.pollInstrumentationThread(new PopupShowingCriteria(view,
true)); |
| 103 | 114 |
| 104 // The shown popup should have valid dimensions eventually. | 115 // The shown popup should have valid dimensions eventually. |
| 105 CriteriaHelper.pollInstrumentationThread(new PopupHasNonZeroDimensionsCr
iteria(view)); | 116 CriteriaHelper.pollInstrumentationThread(new PopupHasNonZeroDimensionsCr
iteria(view)); |
| 106 } | 117 } |
| 107 | 118 |
| 108 /** | 119 /** |
| 109 * Tests Popup zoomer hides when device back key is pressed. | 120 * Tests Popup zoomer hides when device back key is pressed. |
| 110 */ | 121 */ |
| 122 @Test |
| 111 @MediumTest | 123 @MediumTest |
| 112 @Feature({"Browser"}) | 124 @Feature({"Browser"}) |
| 113 @RetryOnFailure | 125 @RetryOnFailure |
| 114 public void testBackKeyDismissesPopupZoomer() throws InterruptedException, T
imeoutException { | 126 public void testBackKeyDismissesPopupZoomer() throws InterruptedException, T
imeoutException { |
| 115 launchContentShellWithUrl(generateTestUrl(100, 15, "clickme")); | 127 mActivityTestRule.launchContentShellWithUrl(generateTestUrl(100, 15, "cl
ickme")); |
| 116 waitForActiveShellToBeDoneLoading(); | 128 mActivityTestRule.waitForActiveShellToBeDoneLoading(); |
| 117 | 129 |
| 118 final ContentViewCore viewCore = getContentViewCore(); | 130 final ContentViewCore viewCore = mActivityTestRule.getContentViewCore(); |
| 119 final ViewGroup view = viewCore.getContainerView(); | 131 final ViewGroup view = viewCore.getContainerView(); |
| 120 | 132 |
| 121 CriteriaHelper.pollInstrumentationThread(new PopupShowingCriteria(view,
false)); | 133 CriteriaHelper.pollInstrumentationThread(new PopupShowingCriteria(view,
false)); |
| 122 DOMUtils.clickNode(viewCore, "clickme"); | 134 DOMUtils.clickNode(viewCore, "clickme"); |
| 123 CriteriaHelper.pollInstrumentationThread(new PopupShowingCriteria(view,
true)); | 135 CriteriaHelper.pollInstrumentationThread(new PopupShowingCriteria(view,
true)); |
| 124 sendKeys(KeyEvent.KEYCODE_BACK); | 136 InstrumentationRegistry.getInstrumentation().sendKeyDownUpSync(KeyEvent.
KEYCODE_BACK); |
| 125 // When device key is pressed, popup zoomer should hide if already showi
ng. | 137 // When device key is pressed, popup zoomer should hide if already showi
ng. |
| 126 CriteriaHelper.pollInstrumentationThread(new PopupShowingCriteria(view,
false)); | 138 CriteriaHelper.pollInstrumentationThread(new PopupShowingCriteria(view,
false)); |
| 127 } | 139 } |
| 128 } | 140 } |
| OLD | NEW |