Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cfb0048b authored by Jonathan Dixon's avatar Jonathan Dixon Committed by Android Git Automerger
Browse files

am 7ef3bfec: Merge "Remove WebViewClassic specific test code" into klp-dev

* commit '7ef3bfec':
  Remove WebViewClassic specific test code
parents 34515fd7 7ef3bfec
Loading
Loading
Loading
Loading
+0 −1809

File deleted.

Preview size limit exceeded, changes collapsed.

+0 −38
Original line number Diff line number Diff line
/*
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.webkit;

import com.android.frameworks.coretests.R;

import android.app.Activity;
import android.os.Bundle;

public class AccessibilityInjectorTestActivity extends Activity {

    private WebView mWebView;

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.accessibility_injector_test);
        mWebView = (WebView) findViewById(R.id.webview);
    }

    public WebView getWebView() {
        return mWebView;
    }
}
+0 −88
Original line number Diff line number Diff line
/*
 * Copyright (C) 2009 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.webkit;

import android.test.AndroidTestCase;
import android.util.Log;
import android.webkit.CacheManager.CacheResult;
import android.webkit.PluginData;
import android.webkit.UrlInterceptHandler;

import java.util.LinkedList;
import java.util.Map;

public class UrlInterceptRegistryTest extends AndroidTestCase {

    /**
     * To run these tests: $ mmm
     * frameworks/base/tests/CoreTests/android && adb remount && adb
     * sync $ adb shell am instrument -w  -e class \
     * android.webkit.UrlInterceptRegistryTest \
     * android.core/android.test.InstrumentationTestRunner
     */

    private static class MockUrlInterceptHandler implements UrlInterceptHandler {
        private PluginData mData;
        private String mUrl;

        public MockUrlInterceptHandler(PluginData data, String url) {
            mData = data;
            mUrl = url;
        }

        public CacheResult service(String url, Map<String, String> headers) {
            return null;
        }

        public PluginData getPluginData(String url,
                                        Map<String,
                                        String> headers) {
            if (mUrl.equals(url)) {
                return mData;
            }

            return null;
        }
    }

    public void testGetPluginData() {
        PluginData data = new PluginData(null, 0 , null, 200);
        String url = new String("url1");
        MockUrlInterceptHandler handler1 =
                new MockUrlInterceptHandler(data, url);

        data = new PluginData(null, 0 , null, 404);
        url = new String("url2");
        MockUrlInterceptHandler handler2 =
                new MockUrlInterceptHandler(data, url);

        assertTrue(UrlInterceptRegistry.registerHandler(handler1));
        assertTrue(UrlInterceptRegistry.registerHandler(handler2));

        data = UrlInterceptRegistry.getPluginData("url1", null);
        assertTrue(data != null);
        assertTrue(data.getStatusCode() == 200);

        data = UrlInterceptRegistry.getPluginData("url2", null);
        assertTrue(data != null);
        assertTrue(data.getStatusCode() == 404);

        assertTrue(UrlInterceptRegistry.unregisterHandler(handler1));
        assertTrue(UrlInterceptRegistry.unregisterHandler(handler2));

    }
}
+0 −59
Original line number Diff line number Diff line
/*
 * Copyright (C) 2006 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.webkit;

import android.test.AndroidTestCase;
import android.text.format.DateFormat;
import android.test.suitebuilder.annotation.MediumTest;
import android.util.Log;
import android.webkit.DateSorter;

import java.util.Calendar;
import java.util.Date;

public class WebkitTest extends AndroidTestCase {

    private static final String LOGTAG = WebkitTest.class.getName();

    @MediumTest
    public void testDateSorter() throws Exception {
        /**
         * Note: check the logging output manually to test
         * nothing automated yet, besides object creation
         */
        DateSorter dateSorter = new DateSorter(mContext);
        Date date = new Date();

        for (int i = 0; i < DateSorter.DAY_COUNT; i++) {
            Log.i(LOGTAG, "Boundary " + i + " " + dateSorter.getBoundary(i));
            Log.i(LOGTAG, "Label " + i + " " + dateSorter.getLabel(i));
        }

        Calendar c = Calendar.getInstance();
        long time = c.getTimeInMillis();
        int index;
        Log.i(LOGTAG, "now: " + dateSorter.getIndex(time));
        for (int i = 0; i < 20; i++) {
            time -= 8 * 60 * 60 * 1000; // 8 hours
            date.setTime(time);
            c.setTime(date);
            index = dateSorter.getIndex(time);
            Log.i(LOGTAG, "time: " + DateFormat.format("yyyy/MM/dd HH:mm:ss", c).toString() +
                    " " + index + " " + dateSorter.getLabel(index));
        }
    }
}
+0 −128
Original line number Diff line number Diff line
/*
 * Copyright (C) 2010 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package android.webkit;

import android.test.AndroidTestCase;

public class ZoomManagerTest extends AndroidTestCase {

    private ZoomManager zoomManager;

    @Override
    public void setUp() {
        WebView webView = new WebView(this.getContext());
        WebViewClassic webViewClassic = WebViewClassic.fromWebView(webView);
        CallbackProxy callbackProxy = new CallbackProxy(this.getContext(), webViewClassic);
        zoomManager = new ZoomManager(webViewClassic, callbackProxy);

        zoomManager.init(1.00f);
    }

    public void testInit() {
        testInit(0.01f);
        testInit(1.00f);
        testInit(1.25f);
    }

    private void testInit(float density) {
        zoomManager.init(density);
        actualScaleTest(density);
        defaultScaleTest(density);
        assertEquals(zoomManager.getDefaultMaxZoomScale(), zoomManager.getMaxZoomScale());
        assertEquals(zoomManager.getDefaultMinZoomScale(), zoomManager.getMinZoomScale());
        assertEquals(density, zoomManager.getTextWrapScale());
    }

    public void testUpdateDefaultZoomDensity() {
        // test the basic case where the actual values are equal to the defaults
        testUpdateDefaultZoomDensity(0.01f);
        testUpdateDefaultZoomDensity(1.00f);
        testUpdateDefaultZoomDensity(1.25f);
    }

    private void testUpdateDefaultZoomDensity(float density) {
        zoomManager.updateDefaultZoomDensity(density);
        defaultScaleTest(density);
    }

    public void testUpdateDefaultZoomDensityWithSmallMinZoom() {
        // test the case where the minZoomScale has changed to be < the default
        float newDefaultScale = 1.50f;
        float minZoomScale = ZoomManager.DEFAULT_MIN_ZOOM_SCALE_FACTOR * newDefaultScale;
        WebViewCore.ViewState minViewState = new WebViewCore.ViewState();
        minViewState.mMinScale = minZoomScale - 0.1f;
        zoomManager.updateZoomRange(minViewState, 0, 0);
        zoomManager.updateDefaultZoomDensity(newDefaultScale);
        defaultScaleTest(newDefaultScale);
    }

    public void testUpdateDefaultZoomDensityWithLargeMinZoom() {
        // test the case where the minZoomScale has changed to be > the default
        float newDefaultScale = 1.50f;
        float minZoomScale = ZoomManager.DEFAULT_MIN_ZOOM_SCALE_FACTOR * newDefaultScale;
        WebViewCore.ViewState minViewState = new WebViewCore.ViewState();
        minViewState.mMinScale = minZoomScale + 0.1f;
        zoomManager.updateZoomRange(minViewState, 0, 0);
        zoomManager.updateDefaultZoomDensity(newDefaultScale);
        defaultScaleTest(newDefaultScale);
    }

    public void testUpdateDefaultZoomDensityWithSmallMaxZoom() {
        // test the case where the maxZoomScale has changed to be < the default
        float newDefaultScale = 1.50f;
        float maxZoomScale = ZoomManager.DEFAULT_MAX_ZOOM_SCALE_FACTOR * newDefaultScale;
        WebViewCore.ViewState maxViewState = new WebViewCore.ViewState();
        maxViewState.mMaxScale = maxZoomScale - 0.1f;
        zoomManager.updateZoomRange(maxViewState, 0, 0);
        zoomManager.updateDefaultZoomDensity(newDefaultScale);
        defaultScaleTest(newDefaultScale);
    }

    public void testUpdateDefaultZoomDensityWithLargeMaxZoom() {
        // test the case where the maxZoomScale has changed to be > the default
        float newDefaultScale = 1.50f;
        float maxZoomScale = ZoomManager.DEFAULT_MAX_ZOOM_SCALE_FACTOR * newDefaultScale;
        WebViewCore.ViewState maxViewState = new WebViewCore.ViewState();
        maxViewState.mMaxScale = maxZoomScale + 0.1f;
        zoomManager.updateZoomRange(maxViewState, 0, 0);
        zoomManager.updateDefaultZoomDensity(newDefaultScale);
        defaultScaleTest(newDefaultScale);
    }

    public void testComputeScaleWithLimits() {
        final float maxScale = zoomManager.getMaxZoomScale();
        final float minScale = zoomManager.getMinZoomScale();
        assertTrue(maxScale > minScale);
        assertEquals(maxScale, zoomManager.computeScaleWithLimits(maxScale));
        assertEquals(maxScale, zoomManager.computeScaleWithLimits(maxScale + .01f));
        assertEquals(minScale, zoomManager.computeScaleWithLimits(minScale));
        assertEquals(minScale, zoomManager.computeScaleWithLimits(minScale - .01f));
    }

    private void actualScaleTest(float actualScale) {
        assertEquals(actualScale, zoomManager.getScale());
        assertEquals(1 / actualScale, zoomManager.getInvScale());
    }

    private void defaultScaleTest(float defaultScale) {
        final float maxDefault = ZoomManager.DEFAULT_MAX_ZOOM_SCALE_FACTOR * defaultScale;
        final float minDefault = ZoomManager.DEFAULT_MIN_ZOOM_SCALE_FACTOR * defaultScale;
        assertEquals(defaultScale, zoomManager.getDefaultScale());
        assertEquals(1 / defaultScale, zoomManager.getInvDefaultScale());
        assertEquals(maxDefault, zoomManager.getDefaultMaxZoomScale());
        assertEquals(minDefault, zoomManager.getDefaultMinZoomScale());
    }
}
Loading