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; |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 t.printStackTrace(); | 187 t.printStackTrace(); |
188 fail("Failed to query canZoomIn/Out: " + t.toString()); | 188 fail("Failed to query canZoomIn/Out: " + t.toString()); |
189 return false; | 189 return false; |
190 } | 190 } |
191 } | 191 } |
192 }, TEST_TIMEOUT_MS, CHECK_INTERVAL_MS); | 192 }, TEST_TIMEOUT_MS, CHECK_INTERVAL_MS); |
193 } | 193 } |
194 | 194 |
195 private void runMagnificationTest(boolean supportZoom) throws Throwable { | 195 private void runMagnificationTest(boolean supportZoom) throws Throwable { |
196 getContentSettingsOnUiThread(mAwContents).setUseWideViewPort(true); | 196 getContentSettingsOnUiThread(mAwContents).setUseWideViewPort(true); |
197 mAwContents.getSettings().setEnableFixedLayoutMode(true); | |
198 loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), | 197 loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), |
199 getZoomableHtml(), "text/html", false); | 198 getZoomableHtml(), "text/html", false); |
200 // It takes some time for scaling to settle down. | 199 // It takes some time for scaling to settle down. |
201 waitUntilCanNotZoomOut(); | 200 waitUntilCanNotZoomOut(); |
202 getContentSettingsOnUiThread(mAwContents).setSupportZoom(supportZoom); | 201 getContentSettingsOnUiThread(mAwContents).setSupportZoom(supportZoom); |
203 assertTrue("Should be able to zoom in", canZoomInOnUiThread()); | 202 assertTrue("Should be able to zoom in", canZoomInOnUiThread()); |
204 assertFalse("Should not be able to zoom out", canZoomOutOnUiThread()); | 203 assertFalse("Should not be able to zoom out", canZoomOutOnUiThread()); |
205 | 204 |
206 while (canZoomInOnUiThread()) { | 205 while (canZoomInOnUiThread()) { |
207 assertTrue(zoomInOnUiThreadAndWait()); | 206 assertTrue(zoomInOnUiThreadAndWait()); |
(...skipping 26 matching lines...) Expand all Loading... |
234 @FlakyTest | 233 @FlakyTest |
235 public void testMagnificationWithZoomSupportOff() throws Throwable { | 234 public void testMagnificationWithZoomSupportOff() throws Throwable { |
236 runMagnificationTest(false); | 235 runMagnificationTest(false); |
237 } | 236 } |
238 | 237 |
239 @SmallTest | 238 @SmallTest |
240 @Feature({"AndroidWebView"}) | 239 @Feature({"AndroidWebView"}) |
241 public void testZoomUsingMultiTouch() throws Throwable { | 240 public void testZoomUsingMultiTouch() throws Throwable { |
242 ContentSettings webSettings = getContentSettingsOnUiThread(mAwContents); | 241 ContentSettings webSettings = getContentSettingsOnUiThread(mAwContents); |
243 webSettings.setUseWideViewPort(true); | 242 webSettings.setUseWideViewPort(true); |
244 mAwContents.getSettings().setEnableFixedLayoutMode(true); | |
245 loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), | 243 loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), |
246 getZoomableHtml(), "text/html", false); | 244 getZoomableHtml(), "text/html", false); |
247 | 245 |
248 assertTrue(webSettings.supportZoom()); | 246 assertTrue(webSettings.supportZoom()); |
249 assertFalse(webSettings.getBuiltInZoomControls()); | 247 assertFalse(webSettings.getBuiltInZoomControls()); |
250 assertFalse(isMultiTouchZoomSupportedOnUiThread()); | 248 assertFalse(isMultiTouchZoomSupportedOnUiThread()); |
251 | 249 |
252 getContentSettingsOnUiThread(mAwContents).setBuiltInZoomControls(true); | 250 getContentSettingsOnUiThread(mAwContents).setBuiltInZoomControls(true); |
253 assertTrue(isMultiTouchZoomSupportedOnUiThread()); | 251 assertTrue(isMultiTouchZoomSupportedOnUiThread()); |
254 | 252 |
255 getContentSettingsOnUiThread(mAwContents).setSupportZoom(false); | 253 getContentSettingsOnUiThread(mAwContents).setSupportZoom(false); |
256 assertFalse(isMultiTouchZoomSupportedOnUiThread()); | 254 assertFalse(isMultiTouchZoomSupportedOnUiThread()); |
257 } | 255 } |
258 | 256 |
259 /** | 257 /** |
260 * @SmallTest | 258 * @SmallTest |
261 * @Feature({"AndroidWebView"}) | 259 * @Feature({"AndroidWebView"}) |
262 * BUG 153522 | 260 * BUG 153522 |
263 */ | 261 */ |
264 @FlakyTest | 262 @FlakyTest |
265 public void testZoomControls() throws Throwable { | 263 public void testZoomControls() throws Throwable { |
266 ContentSettings webSettings = getContentSettingsOnUiThread(mAwContents); | 264 ContentSettings webSettings = getContentSettingsOnUiThread(mAwContents); |
267 webSettings.setUseWideViewPort(true); | 265 webSettings.setUseWideViewPort(true); |
268 mAwContents.getSettings().setEnableFixedLayoutMode(true); | |
269 loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), | 266 loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), |
270 getZoomableHtml(), "text/html", false); | 267 getZoomableHtml(), "text/html", false); |
271 | 268 |
272 assertTrue(webSettings.supportZoom()); | 269 assertTrue(webSettings.supportZoom()); |
273 webSettings.setBuiltInZoomControls(true); | 270 webSettings.setBuiltInZoomControls(true); |
274 webSettings.setDisplayZoomControls(false); | 271 webSettings.setDisplayZoomControls(false); |
275 | 272 |
276 // With DisplayZoomControls set to false, attempts to display zoom | 273 // With DisplayZoomControls set to false, attempts to display zoom |
277 // controls must be ignored. | 274 // controls must be ignored. |
278 assertNull(getZoomControlsOnUiThread()); | 275 assertNull(getZoomControlsOnUiThread()); |
279 invokeZoomPickerOnUiThread(); | 276 invokeZoomPickerOnUiThread(); |
280 assertNull(getZoomControlsOnUiThread()); | 277 assertNull(getZoomControlsOnUiThread()); |
281 | 278 |
282 webSettings.setDisplayZoomControls(true); | 279 webSettings.setDisplayZoomControls(true); |
283 assertNull(getZoomControlsOnUiThread()); | 280 assertNull(getZoomControlsOnUiThread()); |
284 invokeZoomPickerOnUiThread(); | 281 invokeZoomPickerOnUiThread(); |
285 View zoomControls = getZoomControlsOnUiThread(); | 282 View zoomControls = getZoomControlsOnUiThread(); |
286 assertEquals(View.VISIBLE, zoomControls.getVisibility()); | 283 assertEquals(View.VISIBLE, zoomControls.getVisibility()); |
287 } | 284 } |
288 | 285 |
289 @SmallTest | 286 @SmallTest |
290 @Feature({"AndroidWebView"}) | 287 @Feature({"AndroidWebView"}) |
291 public void testZoomControlsOnNonZoomableContent() throws Throwable { | 288 public void testZoomControlsOnNonZoomableContent() throws Throwable { |
292 ContentSettings webSettings = getContentSettingsOnUiThread(mAwContents); | 289 ContentSettings webSettings = getContentSettingsOnUiThread(mAwContents); |
293 webSettings.setUseWideViewPort(true); | 290 webSettings.setUseWideViewPort(true); |
294 mAwContents.getSettings().setEnableFixedLayoutMode(true); | |
295 loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), | 291 loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), |
296 getNonZoomableHtml(), "text/html", false); | 292 getNonZoomableHtml(), "text/html", false); |
297 | 293 |
298 // ContentView must update itself according to the viewport setup. | 294 // ContentView must update itself according to the viewport setup. |
299 waitUntilCanNotZoom(); | 295 waitUntilCanNotZoom(); |
300 | 296 |
301 assertTrue(webSettings.supportZoom()); | 297 assertTrue(webSettings.supportZoom()); |
302 webSettings.setBuiltInZoomControls(true); | 298 webSettings.setBuiltInZoomControls(true); |
303 webSettings.setDisplayZoomControls(true); | 299 webSettings.setDisplayZoomControls(true); |
304 assertNull(getZoomControlsOnUiThread()); | 300 assertNull(getZoomControlsOnUiThread()); |
305 invokeZoomPickerOnUiThread(); | 301 invokeZoomPickerOnUiThread(); |
306 View zoomControls = getZoomControlsOnUiThread(); | 302 View zoomControls = getZoomControlsOnUiThread(); |
307 assertEquals(View.GONE, zoomControls.getVisibility()); | 303 assertEquals(View.GONE, zoomControls.getVisibility()); |
308 } | 304 } |
309 | 305 |
310 /** | 306 /** |
311 * @SmallTest | 307 * @SmallTest |
312 * @Feature({"AndroidWebView"}) | 308 * @Feature({"AndroidWebView"}) |
313 * BUG 153523 | 309 * BUG 153523 |
314 */ | 310 */ |
315 @DisabledTest | 311 @DisabledTest |
316 public void testZoomControlsOnOrientationChange() throws Throwable { | 312 public void testZoomControlsOnOrientationChange() throws Throwable { |
317 ContentSettings webSettings = getContentSettingsOnUiThread(mAwContents); | 313 ContentSettings webSettings = getContentSettingsOnUiThread(mAwContents); |
318 webSettings.setUseWideViewPort(true); | 314 webSettings.setUseWideViewPort(true); |
319 mAwContents.getSettings().setEnableFixedLayoutMode(true); | |
320 loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), | 315 loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), |
321 getZoomableHtml(), "text/html", false); | 316 getZoomableHtml(), "text/html", false); |
322 | 317 |
323 assertTrue(webSettings.supportZoom()); | 318 assertTrue(webSettings.supportZoom()); |
324 webSettings.setBuiltInZoomControls(true); | 319 webSettings.setBuiltInZoomControls(true); |
325 webSettings.setDisplayZoomControls(true); | 320 webSettings.setDisplayZoomControls(true); |
326 invokeZoomPickerOnUiThread(); | 321 invokeZoomPickerOnUiThread(); |
327 | 322 |
328 // Now force an orientation change, and try to display the zoom picker | 323 // Now force an orientation change, and try to display the zoom picker |
329 // again. Make sure that we don't crash when the ZoomPicker registers | 324 // again. Make sure that we don't crash when the ZoomPicker registers |
330 // it's receiver. | 325 // it's receiver. |
331 | 326 |
332 Activity activity = getActivity(); | 327 Activity activity = getActivity(); |
333 int orientation = activity.getRequestedOrientation(); | 328 int orientation = activity.getRequestedOrientation(); |
334 activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAI
T); | 329 activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAI
T); |
335 activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCA
PE); | 330 activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCA
PE); |
336 activity.setRequestedOrientation(orientation); | 331 activity.setRequestedOrientation(orientation); |
337 invokeZoomPickerOnUiThread(); | 332 invokeZoomPickerOnUiThread(); |
338 | 333 |
339 // We may crash shortly (as the zoom picker has a short delay in it befo
re | 334 // We may crash shortly (as the zoom picker has a short delay in it befo
re |
340 // it tries to register it's BroadcastReceiver), so sleep to verify we d
on't. | 335 // it tries to register it's BroadcastReceiver), so sleep to verify we d
on't. |
341 // The delay is encoded in ZoomButtonsController#ZOOM_CONTROLS_TIMEOUT, | 336 // The delay is encoded in ZoomButtonsController#ZOOM_CONTROLS_TIMEOUT, |
342 // if that changes we may need to update this test. | 337 // if that changes we may need to update this test. |
343 Thread.sleep(ViewConfiguration.getZoomControlsTimeout()); | 338 Thread.sleep(ViewConfiguration.getZoomControlsTimeout()); |
344 } | 339 } |
345 } | 340 } |
OLD | NEW |