OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 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 static org.chromium.base.test.util.ScalableTimeout.scaleTimeout; | 7 import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout; |
8 | 8 |
| 9 import android.support.test.InstrumentationRegistry; |
9 import android.support.test.filters.LargeTest; | 10 import android.support.test.filters.LargeTest; |
10 | 11 |
11 import junit.framework.Assert; | 12 import junit.framework.Assert; |
12 | 13 |
| 14 import org.junit.Rule; |
| 15 import org.junit.Test; |
| 16 import org.junit.runner.RunWith; |
| 17 |
| 18 import org.chromium.base.test.BaseJUnit4ClassRunner; |
13 import org.chromium.base.test.util.Feature; | 19 import org.chromium.base.test.util.Feature; |
14 import org.chromium.base.test.util.RetryOnFailure; | 20 import org.chromium.base.test.util.RetryOnFailure; |
15 import org.chromium.base.test.util.UrlUtils; | 21 import org.chromium.base.test.util.UrlUtils; |
16 import org.chromium.content.browser.test.util.Criteria; | 22 import org.chromium.content.browser.test.util.Criteria; |
17 import org.chromium.content.browser.test.util.CriteriaHelper; | 23 import org.chromium.content.browser.test.util.CriteriaHelper; |
18 import org.chromium.content.browser.test.util.DOMUtils; | 24 import org.chromium.content.browser.test.util.DOMUtils; |
19 import org.chromium.content.browser.test.util.TestCallbackHelperContainer; | 25 import org.chromium.content.browser.test.util.TestCallbackHelperContainer; |
20 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnPage
FinishedHelper; | 26 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnPage
FinishedHelper; |
21 import org.chromium.content_public.browser.LoadUrlParams; | 27 import org.chromium.content_public.browser.LoadUrlParams; |
22 import org.chromium.content_shell_apk.ContentShellTestBase; | 28 import org.chromium.content_shell_apk.ContentShellActivityTestRule; |
23 | 29 |
24 import java.util.concurrent.TimeUnit; | 30 import java.util.concurrent.TimeUnit; |
25 | 31 |
26 /** | 32 /** |
27 * Provides test environment for Gesture Detector Reset for Content Shell. | 33 * Provides test environment for Gesture Detector Reset for Content Shell. |
28 * This is a helper class for Content Shell tests. | 34 * This is a helper class for Content Shell tests. |
29 */ | 35 */ |
30 public class GestureDetectorResetTest extends ContentShellTestBase { | 36 @RunWith(BaseJUnit4ClassRunner.class) |
| 37 public class GestureDetectorResetTest { |
| 38 @Rule |
| 39 public ContentShellActivityTestRule mActivityTestRule = new ContentShellActi
vityTestRule(); |
| 40 |
31 private static final long WAIT_TIMEOUT_SECONDS = scaleTimeout(2); | 41 private static final long WAIT_TIMEOUT_SECONDS = scaleTimeout(2); |
32 private static final String CLICK_TEST_URL = UrlUtils.encodeHtmlDataUri("<ht
ml><body>" | 42 private static final String CLICK_TEST_URL = UrlUtils.encodeHtmlDataUri("<ht
ml><body>" |
33 + "<button id=\"button\" " | 43 + "<button id=\"button\" " |
34 + " onclick=\"document.getElementById('test').textContent = 'clicke
d';\">" | 44 + " onclick=\"document.getElementById('test').textContent = 'clicke
d';\">" |
35 + "Button" | 45 + "Button" |
36 + "</button><br/>" | 46 + "</button><br/>" |
37 + "<div id=\"test\">not clicked</div><br/>" | 47 + "<div id=\"test\">not clicked</div><br/>" |
38 + "</body></html>"); | 48 + "</body></html>"); |
39 | 49 |
40 private static class NodeContentsIsEqualToCriteria extends Criteria { | 50 private static class NodeContentsIsEqualToCriteria extends Criteria { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 // After the click, the text on the page should say "clicked". | 93 // After the click, the text on the page should say "clicked". |
84 CriteriaHelper.pollInstrumentationThread(new NodeContentsIsEqualToCriter
ia( | 94 CriteriaHelper.pollInstrumentationThread(new NodeContentsIsEqualToCriter
ia( |
85 "The page contents didn't change after a click " + disambiguatio
n, | 95 "The page contents didn't change after a click " + disambiguatio
n, |
86 contentViewCore, "test", "clicked")); | 96 contentViewCore, "test", "clicked")); |
87 } | 97 } |
88 | 98 |
89 /** | 99 /** |
90 * Tests that showing a select popup and having the page reload while the po
pup is showing does | 100 * Tests that showing a select popup and having the page reload while the po
pup is showing does |
91 * not assert. | 101 * not assert. |
92 */ | 102 */ |
| 103 @Test |
93 @LargeTest | 104 @LargeTest |
94 @Feature({"Browser"}) | 105 @Feature({"Browser"}) |
95 @RetryOnFailure | 106 @RetryOnFailure |
96 public void testSeparateClicksAreRegisteredOnReload() | 107 public void testSeparateClicksAreRegisteredOnReload() |
97 throws InterruptedException, Exception, Throwable { | 108 throws InterruptedException, Exception, Throwable { |
98 // Load the test page. | 109 // Load the test page. |
99 launchContentShellWithUrl(CLICK_TEST_URL); | 110 mActivityTestRule.launchContentShellWithUrl(CLICK_TEST_URL); |
100 waitForActiveShellToBeDoneLoading(); | 111 mActivityTestRule.waitForActiveShellToBeDoneLoading(); |
101 | 112 |
102 final ContentViewCore viewCore = getContentViewCore(); | 113 final ContentViewCore viewCore = mActivityTestRule.getContentViewCore(); |
103 final TestCallbackHelperContainer viewClient = | 114 final TestCallbackHelperContainer viewClient = |
104 new TestCallbackHelperContainer(viewCore); | 115 new TestCallbackHelperContainer(viewCore); |
105 final OnPageFinishedHelper onPageFinishedHelper = | 116 final OnPageFinishedHelper onPageFinishedHelper = |
106 viewClient.getOnPageFinishedHelper(); | 117 viewClient.getOnPageFinishedHelper(); |
107 | 118 |
108 // Test that the button click works. | 119 // Test that the button click works. |
109 verifyClicksAreRegistered("on initial load", viewCore); | 120 verifyClicksAreRegistered("on initial load", viewCore); |
110 | 121 |
111 // Reload the test page. | 122 // Reload the test page. |
112 int currentCallCount = onPageFinishedHelper.getCallCount(); | 123 int currentCallCount = onPageFinishedHelper.getCallCount(); |
113 getInstrumentation().runOnMainSync(new Runnable() { | 124 InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable(
) { |
114 @Override | 125 @Override |
115 public void run() { | 126 public void run() { |
116 getActivity().getActiveShell().loadUrl(CLICK_TEST_URL); | 127 mActivityTestRule.getActivity().getActiveShell().loadUrl(CLICK_T
EST_URL); |
117 } | 128 } |
118 }); | 129 }); |
119 onPageFinishedHelper.waitForCallback(currentCallCount, 1, | 130 onPageFinishedHelper.waitForCallback(currentCallCount, 1, |
120 WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS); | 131 WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS); |
121 | 132 |
122 // Test that the button click still works. | 133 // Test that the button click still works. |
123 verifyClicksAreRegistered("after reload", viewCore); | 134 verifyClicksAreRegistered("after reload", viewCore); |
124 | 135 |
125 // Directly navigate to the test page. | 136 // Directly navigate to the test page. |
126 currentCallCount = onPageFinishedHelper.getCallCount(); | 137 currentCallCount = onPageFinishedHelper.getCallCount(); |
127 getInstrumentation().runOnMainSync(new Runnable() { | 138 InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable(
) { |
128 @Override | 139 @Override |
129 public void run() { | 140 public void run() { |
130 getActivity().getActiveShell().getContentViewCore().getWebConten
ts() | 141 mActivityTestRule.getActivity() |
131 .getNavigationController().loadUrl( | 142 .getActiveShell() |
132 new LoadUrlParams(CLICK_TEST_URL)); | 143 .getContentViewCore() |
| 144 .getWebContents() |
| 145 .getNavigationController() |
| 146 .loadUrl(new LoadUrlParams(CLICK_TEST_URL)); |
133 } | 147 } |
134 }); | 148 }); |
135 onPageFinishedHelper.waitForCallback(currentCallCount, 1, | 149 onPageFinishedHelper.waitForCallback(currentCallCount, 1, |
136 WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS); | 150 WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS); |
137 | 151 |
138 // Test that the button click still works. | 152 // Test that the button click still works. |
139 verifyClicksAreRegistered("after direct navigation", viewCore); | 153 verifyClicksAreRegistered("after direct navigation", viewCore); |
140 } | 154 } |
141 } | 155 } |
OLD | NEW |