Avi Drissman | 4d56a5d | 2022-09-07 17:54:53 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
acleung@google.com | fe72f00 | 2012-12-05 07:59:40 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | package org.chromium.android_webview.test; |
| 6 | |
Ben Joyce | 22b51d3 | 2020-06-15 20:41:17 | [diff] [blame] | 7 | import androidx.test.filters.SmallTest; |
mkosiba@chromium.org | d4acfb0 | 2014-07-02 16:53:36 | [diff] [blame] | 8 | |
Yoland Yan | 08a7725 | 2017-08-18 03:05:07 | [diff] [blame] | 9 | import org.junit.Assert; |
| 10 | import org.junit.Before; |
| 11 | import org.junit.Rule; |
| 12 | import org.junit.Test; |
| 13 | import org.junit.runner.RunWith; |
Mateusz Zbikowski | fbd46b2 | 2023-11-02 19:23:24 | [diff] [blame] | 14 | import org.junit.runners.Parameterized; |
| 15 | import org.junit.runners.Parameterized.UseParametersRunnerFactory; |
Yoland Yan | 08a7725 | 2017-08-18 03:05:07 | [diff] [blame] | 16 | |
acleung@google.com | fe72f00 | 2012-12-05 07:59:40 | [diff] [blame] | 17 | import org.chromium.android_webview.AwContents; |
aurimas@chromium.org | 6f221ce | 2013-12-10 19:28:13 | [diff] [blame] | 18 | import org.chromium.android_webview.test.util.CommonResources; |
Karolina Soltys | ec6a0386 | 2019-03-06 17:20:59 | [diff] [blame] | 19 | import org.chromium.base.task.PostTask; |
Michael Thiessen | 29db7e20 | 2023-03-22 17:10:58 | [diff] [blame] | 20 | import org.chromium.base.task.TaskTraits; |
Michael Thiessen | 1802564 | 2020-11-06 18:13:59 | [diff] [blame] | 21 | import org.chromium.base.test.util.CriteriaHelper; |
acleung@google.com | fe72f00 | 2012-12-05 07:59:40 | [diff] [blame] | 22 | |
Andrew Grieve | e0260713 | 2023-10-25 21:39:06 | [diff] [blame] | 23 | /** Tests for the WebViewClient.onScaleChanged. */ |
Mateusz Zbikowski | fbd46b2 | 2023-11-02 19:23:24 | [diff] [blame] | 24 | @RunWith(Parameterized.class) |
| 25 | @UseParametersRunnerFactory(AwJUnit4ClassRunnerWithParameters.Factory.class) |
| 26 | public class AwContentsClientOnScaleChangedTest extends AwParameterizedTest { |
Andrew Grieve | feff2176 | 2023-11-23 20:41:00 | [diff] [blame] | 27 | @Rule public AwActivityTestRule mActivityTestRule; |
Yoland Yan | 08a7725 | 2017-08-18 03:05:07 | [diff] [blame] | 28 | |
acleung@google.com | fe72f00 | 2012-12-05 07:59:40 | [diff] [blame] | 29 | private TestAwContentsClient mContentsClient; |
| 30 | private AwContents mAwContents; |
| 31 | |
Mateusz Zbikowski | fbd46b2 | 2023-11-02 19:23:24 | [diff] [blame] | 32 | public AwContentsClientOnScaleChangedTest(AwSettingsMutation param) { |
| 33 | this.mActivityTestRule = new AwActivityTestRule(param.getMutation()); |
| 34 | } |
| 35 | |
Yoland Yan | 08a7725 | 2017-08-18 03:05:07 | [diff] [blame] | 36 | @Before |
Peter Wen | c60ef34a | 2019-09-30 16:55:24 | [diff] [blame] | 37 | public void setUp() { |
acleung@google.com | fe72f00 | 2012-12-05 07:59:40 | [diff] [blame] | 38 | mContentsClient = new TestAwContentsClient(); |
| 39 | AwTestContainerView testContainerView = |
Yoland Yan | 08a7725 | 2017-08-18 03:05:07 | [diff] [blame] | 40 | mActivityTestRule.createAwTestContainerViewOnMainSync(mContentsClient); |
acleung@google.com | fe72f00 | 2012-12-05 07:59:40 | [diff] [blame] | 41 | mAwContents = testContainerView.getAwContents(); |
| 42 | } |
| 43 | |
Yoland Yan | 08a7725 | 2017-08-18 03:05:07 | [diff] [blame] | 44 | @Test |
boliu@chromium.org | 6f4bee9 | 2012-12-20 21:52:14 | [diff] [blame] | 45 | @SmallTest |
acleung@google.com | fe72f00 | 2012-12-05 07:59:40 | [diff] [blame] | 46 | public void testScaleUp() throws Throwable { |
Yoland Yan | 08a7725 | 2017-08-18 03:05:07 | [diff] [blame] | 47 | mActivityTestRule.getAwSettingsOnUiThread(mAwContents).setSupportZoom(true); |
Andrew Grieve | e0260713 | 2023-10-25 21:39:06 | [diff] [blame] | 48 | mActivityTestRule.loadDataSync( |
| 49 | mAwContents, |
| 50 | mContentsClient.getOnPageFinishedHelper(), |
boliu | 8d74d0fa | 2015-10-28 02:07:23 | [diff] [blame] | 51 | CommonResources.makeHtmlPageFrom( |
| 52 | "<meta name=\"viewport\" content=\"initial-scale=1.0, " |
| 53 | + " minimum-scale=0.5, maximum-scale=2, user-scalable=yes\" />", |
| 54 | "testScaleUp test page body"), |
Andrew Grieve | e0260713 | 2023-10-25 21:39:06 | [diff] [blame] | 55 | "text/html", |
| 56 | false); |
Ted Choc | 4b8b82c | 2020-04-20 15:51:55 | [diff] [blame] | 57 | CriteriaHelper.pollUiThread(() -> mAwContents.canZoomIn()); |
mnaganov@chromium.org | f4a3a04 | 2013-02-26 12:31:49 | [diff] [blame] | 58 | int callCount = mContentsClient.getOnScaleChangedHelper().getCallCount(); |
Karolina Soltys | ec6a0386 | 2019-03-06 17:20:59 | [diff] [blame] | 59 | PostTask.runOrPostTask( |
Michael Thiessen | 29db7e20 | 2023-03-22 17:10:58 | [diff] [blame] | 60 | TaskTraits.UI_DEFAULT, () -> Assert.assertTrue(mAwContents.zoomIn())); |
mnaganov@chromium.org | f4a3a04 | 2013-02-26 12:31:49 | [diff] [blame] | 61 | mContentsClient.getOnScaleChangedHelper().waitForCallback(callCount); |
Yoland Yan | 08a7725 | 2017-08-18 03:05:07 | [diff] [blame] | 62 | Assert.assertTrue( |
| 63 | "Scale ratio:" + mContentsClient.getOnScaleChangedHelper().getLastScaleRatio(), |
boliu | 8d74d0fa | 2015-10-28 02:07:23 | [diff] [blame] | 64 | mContentsClient.getOnScaleChangedHelper().getLastScaleRatio() > 1); |
acleung@google.com | fe72f00 | 2012-12-05 07:59:40 | [diff] [blame] | 65 | } |
| 66 | } |