[go: nahoru, domu]

blob: ce8bcbaf534aba180e5a9610c6a1ffc21d5ee41e [file] [log] [blame]
Avi Drissman4d56a5d2022-09-07 17:54:531// Copyright 2012 The Chromium Authors
acleung@google.comfe72f002012-12-05 07:59:402// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5package org.chromium.android_webview.test;
6
Ben Joyce22b51d32020-06-15 20:41:177import androidx.test.filters.SmallTest;
mkosiba@chromium.orgd4acfb02014-07-02 16:53:368
Yoland Yan08a77252017-08-18 03:05:079import org.junit.Assert;
10import org.junit.Before;
11import org.junit.Rule;
12import org.junit.Test;
13import org.junit.runner.RunWith;
Mateusz Zbikowskifbd46b22023-11-02 19:23:2414import org.junit.runners.Parameterized;
15import org.junit.runners.Parameterized.UseParametersRunnerFactory;
Yoland Yan08a77252017-08-18 03:05:0716
acleung@google.comfe72f002012-12-05 07:59:4017import org.chromium.android_webview.AwContents;
aurimas@chromium.org6f221ce2013-12-10 19:28:1318import org.chromium.android_webview.test.util.CommonResources;
Karolina Soltysec6a03862019-03-06 17:20:5919import org.chromium.base.task.PostTask;
Michael Thiessen29db7e202023-03-22 17:10:5820import org.chromium.base.task.TaskTraits;
Michael Thiessen18025642020-11-06 18:13:5921import org.chromium.base.test.util.CriteriaHelper;
acleung@google.comfe72f002012-12-05 07:59:4022
Andrew Grievee02607132023-10-25 21:39:0623/** Tests for the WebViewClient.onScaleChanged. */
Mateusz Zbikowskifbd46b22023-11-02 19:23:2424@RunWith(Parameterized.class)
25@UseParametersRunnerFactory(AwJUnit4ClassRunnerWithParameters.Factory.class)
26public class AwContentsClientOnScaleChangedTest extends AwParameterizedTest {
Andrew Grievefeff21762023-11-23 20:41:0027 @Rule public AwActivityTestRule mActivityTestRule;
Yoland Yan08a77252017-08-18 03:05:0728
acleung@google.comfe72f002012-12-05 07:59:4029 private TestAwContentsClient mContentsClient;
30 private AwContents mAwContents;
31
Mateusz Zbikowskifbd46b22023-11-02 19:23:2432 public AwContentsClientOnScaleChangedTest(AwSettingsMutation param) {
33 this.mActivityTestRule = new AwActivityTestRule(param.getMutation());
34 }
35
Yoland Yan08a77252017-08-18 03:05:0736 @Before
Peter Wenc60ef34a2019-09-30 16:55:2437 public void setUp() {
acleung@google.comfe72f002012-12-05 07:59:4038 mContentsClient = new TestAwContentsClient();
39 AwTestContainerView testContainerView =
Yoland Yan08a77252017-08-18 03:05:0740 mActivityTestRule.createAwTestContainerViewOnMainSync(mContentsClient);
acleung@google.comfe72f002012-12-05 07:59:4041 mAwContents = testContainerView.getAwContents();
42 }
43
Yoland Yan08a77252017-08-18 03:05:0744 @Test
boliu@chromium.org6f4bee92012-12-20 21:52:1445 @SmallTest
acleung@google.comfe72f002012-12-05 07:59:4046 public void testScaleUp() throws Throwable {
Yoland Yan08a77252017-08-18 03:05:0747 mActivityTestRule.getAwSettingsOnUiThread(mAwContents).setSupportZoom(true);
Andrew Grievee02607132023-10-25 21:39:0648 mActivityTestRule.loadDataSync(
49 mAwContents,
50 mContentsClient.getOnPageFinishedHelper(),
boliu8d74d0fa2015-10-28 02:07:2351 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 Grievee02607132023-10-25 21:39:0655 "text/html",
56 false);
Ted Choc4b8b82c2020-04-20 15:51:5557 CriteriaHelper.pollUiThread(() -> mAwContents.canZoomIn());
mnaganov@chromium.orgf4a3a042013-02-26 12:31:4958 int callCount = mContentsClient.getOnScaleChangedHelper().getCallCount();
Karolina Soltysec6a03862019-03-06 17:20:5959 PostTask.runOrPostTask(
Michael Thiessen29db7e202023-03-22 17:10:5860 TaskTraits.UI_DEFAULT, () -> Assert.assertTrue(mAwContents.zoomIn()));
mnaganov@chromium.orgf4a3a042013-02-26 12:31:4961 mContentsClient.getOnScaleChangedHelper().waitForCallback(callCount);
Yoland Yan08a77252017-08-18 03:05:0762 Assert.assertTrue(
63 "Scale ratio:" + mContentsClient.getOnScaleChangedHelper().getLastScaleRatio(),
boliu8d74d0fa2015-10-28 02:07:2364 mContentsClient.getOnScaleChangedHelper().getLastScaleRatio() > 1);
acleung@google.comfe72f002012-12-05 07:59:4065 }
66}