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
3// found in the LICENSE file.
4
5package org.chromium.android_webview.test;
6
7import android.test.suitebuilder.annotation.SmallTest;
8
9import org.chromium.android_webview.AwContents;
10import org.chromium.android_webview.test.util.CommonResources;
11import org.chromium.content.browser.ContentViewCore;
12
13/**
14 * Tests for the WebViewClient.onScaleChanged.
15 */
16public class AwContentsClientOnScaleChangedTest extends AwTestBase {
17    private TestAwContentsClient mContentsClient;
18    private AwContents mAwContents;
19
20    @Override
21    protected void setUp() throws Exception {
22        super.setUp();
23        mContentsClient = new TestAwContentsClient();
24        AwTestContainerView testContainerView =
25                createAwTestContainerViewOnMainSync(mContentsClient);
26        mAwContents = testContainerView.getAwContents();
27    }
28
29    @Override
30    protected void tearDown() throws Exception {
31        super.tearDown();
32    }
33
34    @SmallTest
35    public void testScaleUp() throws Throwable {
36        getAwSettingsOnUiThread(mAwContents).setUseWideViewPort(true);
37        loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(),
38                CommonResources.ABOUT_HTML, "text/html", false);
39        ContentViewCore core = mAwContents.getContentViewCore();
40        int callCount = mContentsClient.getOnScaleChangedHelper().getCallCount();
41        core.onSizeChanged(
42                core.getViewportWidthPix() / 2, core.getViewportHeightPix() / 2,
43                core.getViewportWidthPix(), core.getViewportHeightPix());
44        // TODO: Investigate on using core.zoomIn();
45        mContentsClient.getOnScaleChangedHelper().waitForCallback(callCount);
46        assertTrue("Scale ratio:" + mContentsClient.getOnScaleChangedHelper().getLastScaleRatio(),
47                mContentsClient.getOnScaleChangedHelper().getLastScaleRatio() < 1);
48    }
49}
50