1/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.dumprendertree2;
18
19import android.net.Uri;
20import android.util.Log;
21import android.webkit.MockGeolocation;
22import android.webkit.WebStorage;
23
24import java.io.File;
25
26/**
27 * A class that is registered as JS interface for webview in LayoutTestExecutor
28 */
29public class LayoutTestController {
30    private static final String LOG_TAG = "LayoutTestController";
31
32    LayoutTestsExecutor mLayoutTestsExecutor;
33
34    public LayoutTestController(LayoutTestsExecutor layoutTestsExecutor) {
35        mLayoutTestsExecutor = layoutTestsExecutor;
36    }
37
38    public void clearAllDatabases() {
39        Log.i(LOG_TAG, "clearAllDatabases() called");
40        WebStorage.getInstance().deleteAllData();
41    }
42
43    public void dumpAsText() {
44        dumpAsText(false);
45    }
46
47    public void dumpAsText(boolean enablePixelTest) {
48        mLayoutTestsExecutor.dumpAsText(enablePixelTest);
49    }
50
51    public void dumpChildFramesAsText() {
52        mLayoutTestsExecutor.dumpChildFramesAsText();
53    }
54
55    public void dumpDatabaseCallbacks() {
56        mLayoutTestsExecutor.dumpDatabaseCallbacks();
57    }
58
59    public void notifyDone() {
60        mLayoutTestsExecutor.notifyDone();
61    }
62
63    public void overridePreference(String key, boolean value) {
64        mLayoutTestsExecutor.overridePreference(key, value);
65    }
66
67    public void setAppCacheMaximumSize(long size) {
68        Log.i(LOG_TAG, "setAppCacheMaximumSize() called with: " + size);
69        android.webkit.WebStorageClassic.getInstance().setAppCacheMaximumSize(size);
70    }
71
72    public void setCanOpenWindows() {
73        mLayoutTestsExecutor.setCanOpenWindows();
74    }
75
76    public void setDatabaseQuota(long quota) {
77        /** TODO: Reset this before every test! */
78        Log.i(LOG_TAG, "setDatabaseQuota() called with: " + quota);
79        WebStorage.getInstance().setQuotaForOrigin(Uri.fromFile(new File("")).toString(),
80                quota);
81    }
82
83    public void setMockGeolocationPosition(double latitude, double longitude, double accuracy) {
84        Log.i(LOG_TAG, "setMockGeolocationPosition(): " + "latitude=" + latitude +
85                " longitude=" + longitude + " accuracy=" + accuracy);
86        mLayoutTestsExecutor.setMockGeolocationPosition(latitude, longitude, accuracy);
87    }
88
89    public void setMockGeolocationError(int code, String message) {
90        Log.i(LOG_TAG, "setMockGeolocationError(): " + "code=" + code + " message=" + message);
91        mLayoutTestsExecutor.setMockGeolocationError(code, message);
92    }
93
94    public void setGeolocationPermission(boolean allow) {
95        mLayoutTestsExecutor.setGeolocationPermission(allow);
96    }
97
98    public void setMockDeviceOrientation(boolean canProvideAlpha, double alpha,
99            boolean canProvideBeta, double beta, boolean canProvideGamma, double gamma) {
100        // Configuration is in WebKit, so stay on WebCore thread, but go via LayoutTestsExecutor
101        // as we need access to the Webview.
102        Log.i(LOG_TAG, "setMockDeviceOrientation(" + canProvideAlpha +
103                ", " + alpha + ", " + canProvideBeta + ", " + beta + ", " + canProvideGamma +
104                ", " + gamma + ")");
105        mLayoutTestsExecutor.setMockDeviceOrientation(
106                canProvideAlpha, alpha, canProvideBeta, beta, canProvideGamma, gamma);
107    }
108
109    public void setXSSAuditorEnabled(boolean flag) {
110        mLayoutTestsExecutor.setXSSAuditorEnabled(flag);
111    }
112
113    public void waitUntilDone() {
114        mLayoutTestsExecutor.waitUntilDone();
115    }
116}
117