Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(746)

Side by Side Diff: android_webview/javatests/src/org/chromium/android_webview/test/AwZoomTest.java

Issue 445553002: Merge 281052 "[android_webview] Add a zoomBy method to AwContents." (Closed) Base URL: svn://svn.chromium.org/chrome/branches/2062/src/
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientOnScaleChangedTest.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.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.suitebuilder.annotation.SmallTest; 9 import android.test.suitebuilder.annotation.SmallTest;
10 import android.view.View; 10 import android.view.View;
11 import android.view.ViewConfiguration; 11 import android.view.ViewConfiguration;
12 12
13 import org.chromium.android_webview.AwContents; 13 import org.chromium.android_webview.AwContents;
14 import org.chromium.android_webview.AwSettings; 14 import org.chromium.android_webview.AwSettings;
15 import org.chromium.base.ThreadUtils; 15 import org.chromium.base.ThreadUtils;
16 import org.chromium.base.test.util.Feature; 16 import org.chromium.base.test.util.Feature;
17 17
18 import java.util.Locale; 18 import java.util.Locale;
19 import java.util.concurrent.Callable; 19 import java.util.concurrent.Callable;
20 20
21 /** 21 /**
22 * A test suite for zooming-related methods and settings. 22 * A test suite for zooming-related methods and settings.
23 */ 23 */
24 public class AwZoomTest extends AwTestBase { 24 public class AwZoomTest extends AwTestBase {
25 private TestAwContentsClient mContentsClient; 25 private TestAwContentsClient mContentsClient;
26 private AwContents mAwContents; 26 private AwContents mAwContents;
27 private float MAXIMUM_SCALE = 2.0f;
27 28
28 @Override 29 @Override
29 public void setUp() throws Exception { 30 public void setUp() throws Exception {
30 super.setUp(); 31 super.setUp();
31 mContentsClient = new TestAwContentsClient(); 32 mContentsClient = new TestAwContentsClient();
32 final AwTestContainerView testContainerView = 33 final AwTestContainerView testContainerView =
33 createAwTestContainerViewOnMainSync(mContentsClient); 34 createAwTestContainerViewOnMainSync(mContentsClient);
34 mAwContents = testContainerView.getAwContents(); 35 mAwContents = testContainerView.getAwContents();
35 } 36 }
36 37
37 private String getZoomableHtml(float scale) { 38 private String getZoomableHtml(float scale) {
38 final int divWidthPercent = (int)(100.0f / scale); 39 final int divWidthPercent = (int)(100.0f / scale);
39 return String.format(Locale.US, "<html><head><meta name=\"viewport\" con tent=\"" + 40 return String.format(Locale.US, "<html><head><meta name=\"viewport\" con tent=\"" +
40 "width=device-width, minimum-scale=%f, maximum-scale=2.0, initia l-scale=%f" + 41 "width=device-width, minimum-scale=%f, maximum-scale=%f, initial -scale=%f" +
41 "\"/></head><body style='margin:0'>" + 42 "\"/></head><body style='margin:0'>" +
42 "<div style='width:%d%%;height:100px;border:1px solid black'>Zoo mable</div>" + 43 "<div style='width:%d%%;height:100px;border:1px solid black'>Zoo mable</div>" +
43 "</body></html>", 44 "</body></html>",
44 scale, scale, divWidthPercent); 45 scale, MAXIMUM_SCALE, scale, divWidthPercent);
45 } 46 }
46 47
47 private String getNonZoomableHtml() { 48 private String getNonZoomableHtml() {
48 // This page can't be zoomed because its viewport fully occupies 49 // This page can't be zoomed because its viewport fully occupies
49 // view area and is explicitly made non user-scalable. 50 // view area and is explicitly made non user-scalable.
50 return "<html><head>" + 51 return "<html><head>" +
51 "<meta name=\"viewport\" " + 52 "<meta name=\"viewport\" " +
52 "content=\"width=device-width,height=device-height," + 53 "content=\"width=device-width,height=device-height," +
53 "initial-scale=1,maximum-scale=1,user-scalable=no\">" + 54 "initial-scale=1,maximum-scale=1,user-scalable=no\">" +
54 "</head><body>Non-zoomable</body></html>"; 55 "</head><body>Non-zoomable</body></html>";
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 assertTrue(runTestOnUiThreadAndGetResult(new Callable<Boolean>() { 108 assertTrue(runTestOnUiThreadAndGetResult(new Callable<Boolean>() {
108 @Override 109 @Override
109 public Boolean call() throws Exception { 110 public Boolean call() throws Exception {
110 return mAwContents.zoomOut(); 111 return mAwContents.zoomOut();
111 } 112 }
112 })); 113 }));
113 // The zoom level is updated asynchronously. 114 // The zoom level is updated asynchronously.
114 waitForScaleChange(previousScale); 115 waitForScaleChange(previousScale);
115 } 116 }
116 117
118 private void zoomByOnUiThreadAndWait(final float delta) throws Throwable {
119 final float previousScale = getPixelScaleOnUiThread(mAwContents);
120 assertTrue(runTestOnUiThreadAndGetResult(new Callable<Boolean>() {
121 @Override
122 public Boolean call() throws Exception {
123 return mAwContents.zoomBy(delta);
124 }
125 }));
126 // The zoom level is updated asynchronously.
127 waitForScaleChange(previousScale);
128 }
129
117 private void waitForScaleChange(final float previousScale) throws Throwable { 130 private void waitForScaleChange(final float previousScale) throws Throwable {
118 poll(new Callable<Boolean>() { 131 poll(new Callable<Boolean>() {
119 @Override 132 @Override
120 public Boolean call() throws Exception { 133 public Boolean call() throws Exception {
121 return previousScale != getPixelScaleOnUiThread(mAwContents); 134 return previousScale != getPixelScaleOnUiThread(mAwContents);
122 } 135 }
123 }); 136 });
124 } 137 }
125 138
126 private void waitForScaleToBecome(final float expectedScale) throws Throwabl e { 139 private void waitForScaleToBecome(final float expectedScale) throws Throwabl e {
(...skipping 27 matching lines...) Expand all
154 167
155 while (canZoomInOnUiThread(mAwContents)) { 168 while (canZoomInOnUiThread(mAwContents)) {
156 zoomInOnUiThreadAndWait(); 169 zoomInOnUiThreadAndWait();
157 } 170 }
158 assertTrue("Should be able to zoom out", canZoomOutOnUiThread(mAwContent s)); 171 assertTrue("Should be able to zoom out", canZoomOutOnUiThread(mAwContent s));
159 172
160 while (canZoomOutOnUiThread(mAwContents)) { 173 while (canZoomOutOnUiThread(mAwContents)) {
161 zoomOutOnUiThreadAndWait(); 174 zoomOutOnUiThreadAndWait();
162 } 175 }
163 assertTrue("Should be able to zoom in", canZoomInOnUiThread(mAwContents) ); 176 assertTrue("Should be able to zoom in", canZoomInOnUiThread(mAwContents) );
177
178 zoomByOnUiThreadAndWait(4.0f);
179 waitForScaleToBecome(MAXIMUM_SCALE);
180
181 zoomByOnUiThreadAndWait(0.5f);
182 waitForScaleToBecome(MAXIMUM_SCALE * 0.5f);
183
184 zoomByOnUiThreadAndWait(0.01f);
185 waitForScaleToBecome(pageMinimumScale);
164 } 186 }
165 187
166 @SmallTest 188 @SmallTest
167 @Feature({"AndroidWebView"}) 189 @Feature({"AndroidWebView"})
168 public void testMagnification() throws Throwable { 190 public void testMagnification() throws Throwable {
169 getAwSettingsOnUiThread(mAwContents).setSupportZoom(true); 191 getAwSettingsOnUiThread(mAwContents).setSupportZoom(true);
170 runMagnificationTest(); 192 runMagnificationTest();
171 } 193 }
172 194
173 // According to Android CTS test, zoomIn/Out must work 195 // According to Android CTS test, zoomIn/Out must work
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 activity.setRequestedOrientation(orientation); 291 activity.setRequestedOrientation(orientation);
270 invokeZoomPickerOnUiThread(); 292 invokeZoomPickerOnUiThread();
271 293
272 // We may crash shortly (as the zoom picker has a short delay in it befo re 294 // We may crash shortly (as the zoom picker has a short delay in it befo re
273 // it tries to register it's BroadcastReceiver), so sleep to verify we d on't. 295 // it tries to register it's BroadcastReceiver), so sleep to verify we d on't.
274 // The delay is encoded in ZoomButtonsController#ZOOM_CONTROLS_TIMEOUT, 296 // The delay is encoded in ZoomButtonsController#ZOOM_CONTROLS_TIMEOUT,
275 // if that changes we may need to update this test. 297 // if that changes we may need to update this test.
276 Thread.sleep(ViewConfiguration.getZoomControlsTimeout()); 298 Thread.sleep(ViewConfiguration.getZoomControlsTimeout());
277 } 299 }
278 } 300 }
OLDNEW
« no previous file with comments | « android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientOnScaleChangedTest.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698