OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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.android_webview.test; | 5 package org.chromium.android_webview.test; |
6 | 6 |
7 import android.app.Activity; | 7 import android.app.Activity; |
8 import android.content.pm.ActivityInfo; | 8 import android.content.pm.ActivityInfo; |
9 import android.test.FlakyTest; | 9 import android.test.FlakyTest; |
10 import android.test.suitebuilder.annotation.SmallTest; | 10 import android.test.suitebuilder.annotation.SmallTest; |
11 import android.view.View; | 11 import android.view.View; |
12 import android.view.ViewConfiguration; | 12 import android.view.ViewConfiguration; |
13 | 13 |
| 14 import org.chromium.android_webview.AwContents; |
14 import org.chromium.base.ThreadUtils; | 15 import org.chromium.base.ThreadUtils; |
15 import org.chromium.base.test.util.DisabledTest; | 16 import org.chromium.base.test.util.DisabledTest; |
16 import org.chromium.base.test.util.Feature; | 17 import org.chromium.base.test.util.Feature; |
17 import org.chromium.content.browser.ContentSettings; | 18 import org.chromium.content.browser.ContentSettings; |
18 import org.chromium.content.browser.ContentViewCore; | 19 import org.chromium.content.browser.ContentViewCore; |
19 import org.chromium.content.browser.test.util.Criteria; | 20 import org.chromium.content.browser.test.util.Criteria; |
20 import org.chromium.content.browser.test.util.CriteriaHelper; | 21 import org.chromium.content.browser.test.util.CriteriaHelper; |
21 | 22 |
22 import java.util.concurrent.Callable; | 23 import java.util.concurrent.Callable; |
23 | 24 |
24 /** | 25 /** |
25 * A test suite for zooming-related methods and settings. | 26 * A test suite for zooming-related methods and settings. |
26 */ | 27 */ |
27 public class ContentViewZoomTest extends AndroidWebViewTestBase { | 28 public class ContentViewZoomTest extends AndroidWebViewTestBase { |
28 private static final long TEST_TIMEOUT_MS = 20000L; | 29 private static final long TEST_TIMEOUT_MS = 20000L; |
29 private static final int CHECK_INTERVAL_MS = 100; | 30 private static final int CHECK_INTERVAL_MS = 100; |
30 | 31 |
31 private TestAwContentsClient mContentsClient; | 32 private TestAwContentsClient mContentsClient; |
| 33 private AwContents mAwContents; |
32 private ContentViewCore mContentViewCore; | 34 private ContentViewCore mContentViewCore; |
33 | 35 |
34 @Override | 36 @Override |
35 public void setUp() throws Exception { | 37 public void setUp() throws Exception { |
36 super.setUp(); | 38 super.setUp(); |
37 mContentsClient = new TestAwContentsClient(); | 39 mContentsClient = new TestAwContentsClient(); |
38 mContentViewCore = | 40 final AwTestContainerView testContainerView = |
39 createAwTestContainerViewOnMainSync(mContentsClient).getContentV
iewCore(); | 41 createAwTestContainerViewOnMainSync(mContentsClient); |
| 42 mAwContents = testContainerView.getAwContents(); |
| 43 mContentViewCore = testContainerView.getContentViewCore(); |
40 } | 44 } |
41 | 45 |
42 private String getZoomableHtml() { | 46 private String getZoomableHtml() { |
43 StringBuilder sb = new StringBuilder(); | 47 StringBuilder sb = new StringBuilder(); |
44 sb.append("<html><head><meta name=\"viewport\" content=\"" | 48 sb.append("<html><head><meta name=\"viewport\" content=\"" |
45 + "width=device-width, minimum-scale=0.5, maximum-scale=2.0, i
nitial-scale=0.5" | 49 + "width=device-width, minimum-scale=0.5, maximum-scale=2.0, i
nitial-scale=0.5" |
46 + "\"/></head><body>"); | 50 + "\"/></head><body>"); |
47 | 51 |
48 for (int i = 0; i < 1000; i++) { | 52 for (int i = 0; i < 1000; i++) { |
49 sb.append("This is body. "); | 53 sb.append("This is body. "); |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 } catch (Throwable t) { | 186 } catch (Throwable t) { |
183 t.printStackTrace(); | 187 t.printStackTrace(); |
184 fail("Failed to query canZoomIn/Out: " + t.toString()); | 188 fail("Failed to query canZoomIn/Out: " + t.toString()); |
185 return false; | 189 return false; |
186 } | 190 } |
187 } | 191 } |
188 }, TEST_TIMEOUT_MS, CHECK_INTERVAL_MS); | 192 }, TEST_TIMEOUT_MS, CHECK_INTERVAL_MS); |
189 } | 193 } |
190 | 194 |
191 private void runMagnificationTest(boolean supportZoom) throws Throwable { | 195 private void runMagnificationTest(boolean supportZoom) throws Throwable { |
192 loadDataSync(mContentViewCore, mContentsClient.getOnPageFinishedHelper()
, | 196 loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), |
193 getZoomableHtml(), "text/html", false); | 197 getZoomableHtml(), "text/html", false); |
194 // It takes some time for scaling to settle down. | 198 // It takes some time for scaling to settle down. |
195 waitUntilCanNotZoomOut(); | 199 waitUntilCanNotZoomOut(); |
196 getContentSettingsOnUiThread(mContentViewCore).setSupportZoom(supportZoo
m); | 200 getContentSettingsOnUiThread(mAwContents).setSupportZoom(supportZoom); |
197 assertTrue("Should be able to zoom in", canZoomInOnUiThread()); | 201 assertTrue("Should be able to zoom in", canZoomInOnUiThread()); |
198 assertFalse("Should not be able to zoom out", canZoomOutOnUiThread()); | 202 assertFalse("Should not be able to zoom out", canZoomOutOnUiThread()); |
199 | 203 |
200 while (canZoomInOnUiThread()) { | 204 while (canZoomInOnUiThread()) { |
201 assertTrue(zoomInOnUiThreadAndWait()); | 205 assertTrue(zoomInOnUiThreadAndWait()); |
202 } | 206 } |
203 assertTrue("Should be able to zoom out", canZoomOutOnUiThread()); | 207 assertTrue("Should be able to zoom out", canZoomOutOnUiThread()); |
204 | 208 |
205 while (canZoomOutOnUiThread()) { | 209 while (canZoomOutOnUiThread()) { |
206 assertTrue(zoomOutOnUiThreadAndWait()); | 210 assertTrue(zoomOutOnUiThreadAndWait()); |
(...skipping 19 matching lines...) Expand all Loading... |
226 * BUG 153522 | 230 * BUG 153522 |
227 */ | 231 */ |
228 @FlakyTest | 232 @FlakyTest |
229 public void testMagnificationWithZoomSupportOff() throws Throwable { | 233 public void testMagnificationWithZoomSupportOff() throws Throwable { |
230 runMagnificationTest(false); | 234 runMagnificationTest(false); |
231 } | 235 } |
232 | 236 |
233 @SmallTest | 237 @SmallTest |
234 @Feature({"Android-WebView"}) | 238 @Feature({"Android-WebView"}) |
235 public void testZoomUsingMultiTouch() throws Throwable { | 239 public void testZoomUsingMultiTouch() throws Throwable { |
236 ContentSettings webSettings = getContentSettingsOnUiThread(mContentViewC
ore); | 240 ContentSettings webSettings = getContentSettingsOnUiThread(mAwContents); |
237 loadDataSync(mContentViewCore, mContentsClient.getOnPageFinishedHelper()
, | 241 loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), |
238 getZoomableHtml(), "text/html", false); | 242 getZoomableHtml(), "text/html", false); |
239 | 243 |
240 assertTrue(webSettings.supportZoom()); | 244 assertTrue(webSettings.supportZoom()); |
241 assertFalse(webSettings.getBuiltInZoomControls()); | 245 assertFalse(webSettings.getBuiltInZoomControls()); |
242 assertFalse(isMultiTouchZoomSupportedOnUiThread()); | 246 assertFalse(isMultiTouchZoomSupportedOnUiThread()); |
243 | 247 |
244 getContentSettingsOnUiThread(mContentViewCore).setBuiltInZoomControls(tr
ue); | 248 getContentSettingsOnUiThread(mAwContents).setBuiltInZoomControls(true); |
245 assertTrue(isMultiTouchZoomSupportedOnUiThread()); | 249 assertTrue(isMultiTouchZoomSupportedOnUiThread()); |
246 | 250 |
247 getContentSettingsOnUiThread(mContentViewCore).setSupportZoom(false); | 251 getContentSettingsOnUiThread(mAwContents).setSupportZoom(false); |
248 assertFalse(isMultiTouchZoomSupportedOnUiThread()); | 252 assertFalse(isMultiTouchZoomSupportedOnUiThread()); |
249 } | 253 } |
250 | 254 |
251 /** | 255 /** |
252 * @SmallTest | 256 * @SmallTest |
253 * @Feature({"Android-WebView"}) | 257 * @Feature({"Android-WebView"}) |
254 * BUG 153522 | 258 * BUG 153522 |
255 */ | 259 */ |
256 @FlakyTest | 260 @FlakyTest |
257 public void testZoomControls() throws Throwable { | 261 public void testZoomControls() throws Throwable { |
258 ContentSettings webSettings = getContentSettingsOnUiThread(mContentViewC
ore); | 262 ContentSettings webSettings = getContentSettingsOnUiThread(mAwContents); |
259 loadDataSync(mContentViewCore, mContentsClient.getOnPageFinishedHelper()
, | 263 loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), |
260 getZoomableHtml(), "text/html", false); | 264 getZoomableHtml(), "text/html", false); |
261 | 265 |
262 assertTrue(webSettings.supportZoom()); | 266 assertTrue(webSettings.supportZoom()); |
263 webSettings.setBuiltInZoomControls(true); | 267 webSettings.setBuiltInZoomControls(true); |
264 webSettings.setDisplayZoomControls(false); | 268 webSettings.setDisplayZoomControls(false); |
265 | 269 |
266 // With DisplayZoomControls set to false, attempts to display zoom | 270 // With DisplayZoomControls set to false, attempts to display zoom |
267 // controls must be ignored. | 271 // controls must be ignored. |
268 assertNull(getZoomControlsOnUiThread()); | 272 assertNull(getZoomControlsOnUiThread()); |
269 invokeZoomPickerOnUiThread(); | 273 invokeZoomPickerOnUiThread(); |
270 assertNull(getZoomControlsOnUiThread()); | 274 assertNull(getZoomControlsOnUiThread()); |
271 | 275 |
272 webSettings.setDisplayZoomControls(true); | 276 webSettings.setDisplayZoomControls(true); |
273 assertNull(getZoomControlsOnUiThread()); | 277 assertNull(getZoomControlsOnUiThread()); |
274 invokeZoomPickerOnUiThread(); | 278 invokeZoomPickerOnUiThread(); |
275 View zoomControls = getZoomControlsOnUiThread(); | 279 View zoomControls = getZoomControlsOnUiThread(); |
276 assertEquals(View.VISIBLE, zoomControls.getVisibility()); | 280 assertEquals(View.VISIBLE, zoomControls.getVisibility()); |
277 } | 281 } |
278 | 282 |
279 @SmallTest | 283 @SmallTest |
280 @Feature({"Android-WebView"}) | 284 @Feature({"Android-WebView"}) |
281 public void testZoomControlsOnNonZoomableContent() throws Throwable { | 285 public void testZoomControlsOnNonZoomableContent() throws Throwable { |
282 ContentSettings webSettings = getContentSettingsOnUiThread(mContentViewC
ore); | 286 ContentSettings webSettings = getContentSettingsOnUiThread(mAwContents); |
283 loadDataSync(mContentViewCore, mContentsClient.getOnPageFinishedHelper()
, | 287 loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), |
284 getNonZoomableHtml(), "text/html", false); | 288 getNonZoomableHtml(), "text/html", false); |
285 | 289 |
286 // ContentView must update itself according to the viewport setup. | 290 // ContentView must update itself according to the viewport setup. |
287 waitUntilCanNotZoom(); | 291 waitUntilCanNotZoom(); |
288 | 292 |
289 assertTrue(webSettings.supportZoom()); | 293 assertTrue(webSettings.supportZoom()); |
290 webSettings.setBuiltInZoomControls(true); | 294 webSettings.setBuiltInZoomControls(true); |
291 webSettings.setDisplayZoomControls(true); | 295 webSettings.setDisplayZoomControls(true); |
292 assertNull(getZoomControlsOnUiThread()); | 296 assertNull(getZoomControlsOnUiThread()); |
293 invokeZoomPickerOnUiThread(); | 297 invokeZoomPickerOnUiThread(); |
294 View zoomControls = getZoomControlsOnUiThread(); | 298 View zoomControls = getZoomControlsOnUiThread(); |
295 assertEquals(View.GONE, zoomControls.getVisibility()); | 299 assertEquals(View.GONE, zoomControls.getVisibility()); |
296 } | 300 } |
297 | 301 |
298 /** | 302 /** |
299 * @SmallTest | 303 * @SmallTest |
300 * @Feature({"Android-WebView"}) | 304 * @Feature({"Android-WebView"}) |
301 * BUG 153523 | 305 * BUG 153523 |
302 */ | 306 */ |
303 @DisabledTest | 307 @DisabledTest |
304 public void testZoomControlsOnOrientationChange() throws Throwable { | 308 public void testZoomControlsOnOrientationChange() throws Throwable { |
305 ContentSettings webSettings = getContentSettingsOnUiThread(mContentViewC
ore); | 309 ContentSettings webSettings = getContentSettingsOnUiThread(mAwContents); |
306 loadDataSync(mContentViewCore, mContentsClient.getOnPageFinishedHelper()
, | 310 loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), |
307 getZoomableHtml(), "text/html", false); | 311 getZoomableHtml(), "text/html", false); |
308 | 312 |
309 assertTrue(webSettings.supportZoom()); | 313 assertTrue(webSettings.supportZoom()); |
310 webSettings.setBuiltInZoomControls(true); | 314 webSettings.setBuiltInZoomControls(true); |
311 webSettings.setDisplayZoomControls(true); | 315 webSettings.setDisplayZoomControls(true); |
312 invokeZoomPickerOnUiThread(); | 316 invokeZoomPickerOnUiThread(); |
313 | 317 |
314 // Now force an orientation change, and try to display the zoom picker | 318 // Now force an orientation change, and try to display the zoom picker |
315 // again. Make sure that we don't crash when the ZoomPicker registers | 319 // again. Make sure that we don't crash when the ZoomPicker registers |
316 // it's receiver. | 320 // it's receiver. |
317 | 321 |
318 Activity activity = getActivity(); | 322 Activity activity = getActivity(); |
319 int orientation = activity.getRequestedOrientation(); | 323 int orientation = activity.getRequestedOrientation(); |
320 activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAI
T); | 324 activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAI
T); |
321 activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCA
PE); | 325 activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCA
PE); |
322 activity.setRequestedOrientation(orientation); | 326 activity.setRequestedOrientation(orientation); |
323 invokeZoomPickerOnUiThread(); | 327 invokeZoomPickerOnUiThread(); |
324 | 328 |
325 // We may crash shortly (as the zoom picker has a short delay in it befo
re | 329 // We may crash shortly (as the zoom picker has a short delay in it befo
re |
326 // it tries to register it's BroadcastReceiver), so sleep to verify we d
on't. | 330 // it tries to register it's BroadcastReceiver), so sleep to verify we d
on't. |
327 // The delay is encoded in ZoomButtonsController#ZOOM_CONTROLS_TIMEOUT, | 331 // The delay is encoded in ZoomButtonsController#ZOOM_CONTROLS_TIMEOUT, |
328 // if that changes we may need to update this test. | 332 // if that changes we may need to update this test. |
329 Thread.sleep(ViewConfiguration.getZoomControlsTimeout()); | 333 Thread.sleep(ViewConfiguration.getZoomControlsTimeout()); |
330 } | 334 } |
331 } | 335 } |
OLD | NEW |