LayoutTestController.java revision 2e5982a55ac031110ed39515a76f7a5ec9ff2c14
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 waitUntilDone() { 39 mLayoutTestsExecutor.waitUntilDone(); 40 } 41 42 public void notifyDone() { 43 mLayoutTestsExecutor.notifyDone(); 44 } 45 46 public void dumpAsText() { 47 dumpAsText(false); 48 } 49 50 public void dumpAsText(boolean enablePixelTest) { 51 mLayoutTestsExecutor.dumpAsText(enablePixelTest); 52 } 53 54 public void dumpChildFramesAsText() { 55 mLayoutTestsExecutor.dumpChildFramesAsText(); 56 } 57 58 public void clearAllDatabases() { 59 Log.i(LOG_TAG, "clearAllDatabases() called"); 60 WebStorage.getInstance().deleteAllData(); 61 } 62 63 public void setCanOpenWindows() { 64 mLayoutTestsExecutor.setCanOpenWindows(); 65 } 66 67 public void dumpDatabaseCallbacks() { 68 mLayoutTestsExecutor.dumpDatabaseCallbacks(); 69 } 70 71 public void setDatabaseQuota(long quota) { 72 /** TODO: Reset this before every test! */ 73 Log.i(LOG_TAG, "setDatabaseQuota() called with: " + quota); 74 WebStorage.getInstance().setQuotaForOrigin(Uri.fromFile(new File("")).toString(), 75 quota); 76 } 77 78 public void setGeolocationPermission(boolean allow) { 79 mLayoutTestsExecutor.setGeolocationPermission(allow); 80 } 81 82 public void setMockGeolocationPosition(double latitude, double longitude, double accuracy) { 83 Log.i(LOG_TAG, "setMockGeolocationPosition(): " + "latitude=" + latitude + 84 " longitude=" + longitude + " accuracy=" + accuracy); 85 MockGeolocation.getInstance().setPosition(latitude, longitude, accuracy); 86 } 87 88 public void setMockGeolocationError(int code, String message) { 89 Log.i(LOG_TAG, "setMockGeolocationError(): " + "code=" + code + " message=" + message); 90 MockGeolocation.getInstance().setError(code, message); 91 } 92 93 public void setMockDeviceOrientation(boolean canProvideAlpha, double alpha, 94 boolean canProvideBeta, double beta, boolean canProvideGamma, double gamma) { 95 // Configuration is in WebKit, so stay on WebCore thread, but go via LayoutTestsExecutor 96 // as we need access to the Webview. 97 Log.i(LOG_TAG, "setMockDeviceOrientation(" + canProvideAlpha + 98 ", " + alpha + ", " + canProvideBeta + ", " + beta + ", " + canProvideGamma + 99 ", " + gamma + ")"); 100 mLayoutTestsExecutor.setMockDeviceOrientation( 101 canProvideAlpha, alpha, canProvideBeta, beta, canProvideGamma, gamma); 102 } 103}