• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package com.android.dumprendertree2;
18 
19 import android.net.Uri;
20 import android.util.Log;
21 import android.webkit.MockGeolocation;
22 import android.webkit.WebStorage;
23 
24 import java.io.File;
25 
26 /**
27  * A class that is registered as JS interface for webview in LayoutTestExecutor
28  */
29 public class LayoutTestController {
30     private static final String LOG_TAG = "LayoutTestController";
31 
32     LayoutTestsExecutor mLayoutTestsExecutor;
33 
LayoutTestController(LayoutTestsExecutor layoutTestsExecutor)34     public LayoutTestController(LayoutTestsExecutor layoutTestsExecutor) {
35         mLayoutTestsExecutor = layoutTestsExecutor;
36     }
37 
clearAllDatabases()38     public void clearAllDatabases() {
39         Log.i(LOG_TAG, "clearAllDatabases() called");
40         WebStorage.getInstance().deleteAllData();
41     }
42 
dumpAsText()43     public void dumpAsText() {
44         dumpAsText(false);
45     }
46 
dumpAsText(boolean enablePixelTest)47     public void dumpAsText(boolean enablePixelTest) {
48         mLayoutTestsExecutor.dumpAsText(enablePixelTest);
49     }
50 
dumpChildFramesAsText()51     public void dumpChildFramesAsText() {
52         mLayoutTestsExecutor.dumpChildFramesAsText();
53     }
54 
dumpDatabaseCallbacks()55     public void dumpDatabaseCallbacks() {
56         mLayoutTestsExecutor.dumpDatabaseCallbacks();
57     }
58 
notifyDone()59     public void notifyDone() {
60         mLayoutTestsExecutor.notifyDone();
61     }
62 
overridePreference(String key, boolean value)63     public void overridePreference(String key, boolean value) {
64         mLayoutTestsExecutor.overridePreference(key, value);
65     }
66 
setAppCacheMaximumSize(long size)67     public void setAppCacheMaximumSize(long size) {
68         Log.i(LOG_TAG, "setAppCacheMaximumSize() called with: " + size);
69         android.webkit.WebStorageClassic.getInstance().setAppCacheMaximumSize(size);
70     }
71 
setCanOpenWindows()72     public void setCanOpenWindows() {
73         mLayoutTestsExecutor.setCanOpenWindows();
74     }
75 
setDatabaseQuota(long quota)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 
setMockGeolocationPosition(double latitude, double longitude, double accuracy)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 
setMockGeolocationError(int code, String message)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 
setGeolocationPermission(boolean allow)94     public void setGeolocationPermission(boolean allow) {
95         mLayoutTestsExecutor.setGeolocationPermission(allow);
96     }
97 
setMockDeviceOrientation(boolean canProvideAlpha, double alpha, boolean canProvideBeta, double beta, boolean canProvideGamma, double gamma)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 
setXSSAuditorEnabled(boolean flag)109     public void setXSSAuditorEnabled(boolean flag) {
110         mLayoutTestsExecutor.setXSSAuditorEnabled(flag);
111     }
112 
waitUntilDone()113     public void waitUntilDone() {
114         mLayoutTestsExecutor.waitUntilDone();
115     }
116 }
117