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.test.suitebuilder.annotation.SmallTest; | 7 import android.test.suitebuilder.annotation.SmallTest; |
8 | 8 |
9 import org.chromium.android_webview.AwContents; | 9 import org.chromium.android_webview.AwContents; |
10 import org.chromium.base.test.util.DisabledTest; | 10 import org.chromium.base.test.util.DisabledTest; |
11 import org.chromium.content.browser.ContentViewCore; | 11 import org.chromium.content.browser.ContentViewCore; |
12 import org.chromium.content.browser.test.util.CallbackHelper; | 12 import org.chromium.content.browser.test.util.CallbackHelper; |
13 import org.chromium.android_webview.test.util.CommonResources; | 13 import org.chromium.android_webview.test.util.CommonResources; |
14 | 14 |
15 import android.util.Log; | 15 import android.util.Log; |
16 | 16 |
17 /** | 17 /** |
18 * Tests for the WebViewClient.onScaleChanged. | 18 * Tests for the WebViewClient.onScaleChanged. |
19 */ | 19 */ |
20 public class AwContentsClientOnScaleChangedTest extends AndroidWebViewTestBase { | 20 public class AwContentsClientOnScaleChangedTest extends AndroidWebViewTestBase { |
21 private static class OnScaleChangedHelper extends CallbackHelper { | |
22 private float mLastScaleRatio; | |
23 | |
24 public void notifyCalled(float ratio) { | |
25 super.notifyCalled(); | |
26 mLastScaleRatio = ratio; | |
27 } | |
28 } | |
29 | |
30 private static class TestAwContentsClient | |
31 extends org.chromium.android_webview.test.TestAwContentsClient { | |
32 private OnScaleChangedHelper mOnScaleChangedHelper = new OnScaleChanged
Helper(); | |
33 @Override | |
34 public void onScaleChanged(float oldScale, float newScale) { | |
35 // We should not be getting any messages from scrolling. | |
36 assertTrue(oldScale != newScale); | |
37 mOnScaleChangedHelper.notifyCalled(newScale / oldScale); | |
38 } | |
39 } | |
40 | |
41 private TestAwContentsClient mContentsClient; | 21 private TestAwContentsClient mContentsClient; |
42 private AwContents mAwContents; | 22 private AwContents mAwContents; |
43 | 23 |
44 @Override | 24 @Override |
45 protected void setUp() throws Exception { | 25 protected void setUp() throws Exception { |
46 super.setUp(); | 26 super.setUp(); |
47 mContentsClient = new TestAwContentsClient(); | 27 mContentsClient = new TestAwContentsClient(); |
48 AwTestContainerView testContainerView = | 28 AwTestContainerView testContainerView = |
49 createAwTestContainerViewOnMainSync(mContentsClient); | 29 createAwTestContainerViewOnMainSync(mContentsClient); |
50 mAwContents = testContainerView.getAwContents(); | 30 mAwContents = testContainerView.getAwContents(); |
51 } | 31 } |
52 | 32 |
53 @Override | 33 @Override |
54 protected void tearDown() throws Exception { | 34 protected void tearDown() throws Exception { |
55 super.tearDown(); | 35 super.tearDown(); |
56 } | 36 } |
57 | 37 |
58 /* | 38 /* |
59 @SmallTest | 39 @SmallTest |
60 This test is timing out on ICS bots including cq. See crbug.com/175854. | 40 This test is timing out on ICS bots including cq. See crbug.com/175854. |
61 */ | 41 */ |
62 @DisabledTest | 42 @DisabledTest |
63 public void testScaleUp() throws Throwable { | 43 public void testScaleUp() throws Throwable { |
64 getContentSettingsOnUiThread(mAwContents).setUseWideViewPort(true); | 44 getContentSettingsOnUiThread(mAwContents).setUseWideViewPort(true); |
65 loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), | 45 loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), |
66 CommonResources.ABOUT_HTML, "text/html", false); | 46 CommonResources.ABOUT_HTML, "text/html", false); |
67 ContentViewCore core = mAwContents.getContentViewCore(); | 47 ContentViewCore core = mAwContents.getContentViewCore(); |
68 int callCount = mContentsClient.mOnScaleChangedHelper.getCallCount(); | 48 int callCount = mContentsClient.getOnScaleChangedHelper().getCallCount()
; |
69 core.onSizeChanged(core.getWidth() / 2, core.getHeight() / 2, | 49 core.onSizeChanged(core.getWidth() / 2, core.getHeight() / 2, |
70 core.getWidth(), core.getHeight()); | 50 core.getWidth(), core.getHeight()); |
71 // TODO: Investigate on using core.zoomIn(); | 51 // TODO: Investigate on using core.zoomIn(); |
72 mContentsClient.mOnScaleChangedHelper.waitForCallback(callCount); | 52 mContentsClient.getOnScaleChangedHelper().waitForCallback(callCount); |
73 assertTrue(mContentsClient.mOnScaleChangedHelper.mLastScaleRatio < 1); | 53 assertTrue("Scale ratio:" + mContentsClient.getOnScaleChangedHelper().ge
tLastScaleRatio(), |
| 54 mContentsClient.getOnScaleChangedHelper().getLastScaleRatio() <
1); |
74 } | 55 } |
75 } | 56 } |
OLD | NEW |