blob: e3ff1b76a58a7f26873237cea369da57200f1cf3 [file] [log] [blame]
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -07001/*
2 * Copyright (C) 2007 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.dumprendertree;
18
Guang Zhu6bf18ba2009-09-15 23:47:20 -070019import com.android.dumprendertree.forwarder.ForwardService;
20
Guang Zhu1871fe02009-04-29 14:49:03 -070021import android.app.Activity;
Guang Zhuf92bd422009-06-29 10:40:55 -070022import android.app.AlertDialog;
Andrei Popescu4950b2b2009-09-03 13:56:07 +010023import android.content.Context;
Guang Zhuf92bd422009-06-29 10:40:55 -070024import android.content.DialogInterface;
Guang Zhu1871fe02009-04-29 14:49:03 -070025import android.content.Intent;
Guang Zhuf92bd422009-06-29 10:40:55 -070026import android.content.DialogInterface.OnClickListener;
Guang Zhu1871fe02009-04-29 14:49:03 -070027import android.graphics.Bitmap;
Guang Zhu5dc4f212009-10-29 18:24:54 -070028import android.graphics.Canvas;
29import android.graphics.Bitmap.CompressFormat;
30import android.graphics.Bitmap.Config;
Guang Zhu1871fe02009-04-29 14:49:03 -070031import android.net.http.SslError;
32import android.os.Bundle;
Christian Mehlmauer8b85dce2010-07-19 20:11:27 +020033import android.os.Environment;
Guang Zhu1871fe02009-04-29 14:49:03 -070034import android.os.Handler;
35import android.os.Message;
36import android.util.Log;
37import android.view.ViewGroup;
Ben Murdoch9b815d02010-06-01 18:45:10 +010038import android.view.Window;
Kristian Monsen16d041c2010-12-06 13:43:51 +000039import android.webkit.CookieManager;
Guang Zhu6c15f602010-05-03 11:49:04 -070040import android.webkit.ConsoleMessage;
Ben Murdoch7e73ce92011-01-20 11:21:24 +000041import android.webkit.CookieManager;
Steve Blockdad347c2009-08-19 18:46:34 +010042import android.webkit.GeolocationPermissions;
Guang Zhu1871fe02009-04-29 14:49:03 -070043import android.webkit.HttpAuthHandler;
44import android.webkit.JsPromptResult;
45import android.webkit.JsResult;
46import android.webkit.SslErrorHandler;
47import android.webkit.WebChromeClient;
48import android.webkit.WebSettings;
Ben Murdoche6f3e452009-04-22 16:02:31 +010049import android.webkit.WebStorage;
Guang Zhu1871fe02009-04-29 14:49:03 -070050import android.webkit.WebView;
51import android.webkit.WebViewClient;
52import android.widget.LinearLayout;
53
Guang Zhuf92bd422009-06-29 10:40:55 -070054import java.io.BufferedReader;
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -070055import java.io.File;
56import java.io.FileOutputStream;
Guang Zhuf92bd422009-06-29 10:40:55 -070057import java.io.FileReader;
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -070058import java.io.IOException;
Ben Murdoche6f3e452009-04-22 16:02:31 +010059import java.net.MalformedURLException;
60import java.net.URL;
Andrei Popescu4950b2b2009-09-03 13:56:07 +010061import java.util.HashMap;
Steve Blockf0f30c62010-08-18 15:15:42 +010062import java.util.Iterator;
Andrei Popescu4950b2b2009-09-03 13:56:07 +010063import java.util.Map;
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -070064import java.util.Vector;
65
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -070066public class TestShellActivity extends Activity implements LayoutTestController {
Guang Zhuf92bd422009-06-29 10:40:55 -070067
Guang Zhu1871fe02009-04-29 14:49:03 -070068 static enum DumpDataType {DUMP_AS_TEXT, EXT_REPR, NO_OP}
Guang Zhuf92bd422009-06-29 10:40:55 -070069
Steve Blockfb0de342010-03-19 18:48:35 +000070 // String constants for use with layoutTestController.overridePreferences
Steve Block5f37cc432010-10-13 18:44:31 +010071 private final String WEBKIT_OFFLINE_WEB_APPLICATION_CACHE_ENABLED =
72 "WebKitOfflineWebApplicationCacheEnabled";
73 private final String WEBKIT_USES_PAGE_CACHE_PREFERENCE_KEY = "WebKitUsesPageCachePreferenceKey";
Steve Blockfb0de342010-03-19 18:48:35 +000074
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -070075 public class AsyncHandler extends Handler {
76 @Override
77 public void handleMessage(Message msg) {
78 if (msg.what == MSG_TIMEOUT) {
79 mTimedOut = true;
Guang Zhu4ce6e7c2011-01-14 16:17:20 -080080 mWebView.stopLoading();
Guang Zhu56a36932009-09-28 09:53:48 -070081 if (mCallback != null)
Guang Zhuf92bd422009-06-29 10:40:55 -070082 mCallback.timedOut(mWebView.getUrl());
Guang Zhu56a36932009-09-28 09:53:48 -070083 if (!mRequestedWebKitData) {
Guang Zhu72160472009-09-25 17:34:12 -070084 requestWebKitData();
85 } else {
86 // if timed out and webkit data has been dumped before
87 // finish directly
88 finished();
89 }
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -070090 return;
91 } else if (msg.what == MSG_WEBKIT_DATA) {
Guang Zhuf2f7f562010-12-23 16:25:47 -080092 mHandler.removeMessages(MSG_DUMP_TIMEOUT);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -070093 TestShellActivity.this.dump(mTimedOut, (String)msg.obj);
94 return;
Guang Zhuf37a5742010-12-23 14:37:31 -080095 } else if (msg.what == MSG_DUMP_TIMEOUT) {
96 throw new RuntimeException("WebView dump timeout, is it pegged?");
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -070097 }
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -070098 super.handleMessage(msg);
99 }
100 }
101
102 public void requestWebKitData() {
103 Message callback = mHandler.obtainMessage(MSG_WEBKIT_DATA);
Guang Zhuf92bd422009-06-29 10:40:55 -0700104
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700105 if (mRequestedWebKitData)
106 throw new AssertionError("Requested webkit data twice: " + mWebView.getUrl());
Guang Zhuf92bd422009-06-29 10:40:55 -0700107
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700108 mRequestedWebKitData = true;
Guang Zhu72160472009-09-25 17:34:12 -0700109 Log.v(LOGTAG, "message sent to WebView to dump text.");
Guang Zhu1871fe02009-04-29 14:49:03 -0700110 switch (mDumpDataType) {
111 case DUMP_AS_TEXT:
Shimeng (Simon) Wangad456862010-06-16 17:32:24 -0700112 callback.arg1 = mDumpTopFrameAsText ? 1 : 0;
113 callback.arg2 = mDumpChildFramesAsText ? 1 : 0;
Guang Zhuf37a5742010-12-23 14:37:31 -0800114 setDumpTimeout(DUMP_TIMEOUT_MS);
Guang Zhu1871fe02009-04-29 14:49:03 -0700115 mWebView.documentAsText(callback);
116 break;
117 case EXT_REPR:
118 mWebView.externalRepresentation(callback);
Guang Zhuf37a5742010-12-23 14:37:31 -0800119 setDumpTimeout(DUMP_TIMEOUT_MS);
Guang Zhu1871fe02009-04-29 14:49:03 -0700120 break;
121 default:
122 finished();
123 break;
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700124 }
Guang Zhuf92bd422009-06-29 10:40:55 -0700125 }
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700126
Guang Zhuf37a5742010-12-23 14:37:31 -0800127 private void setDumpTimeout(long timeout) {
Guang Zhu49171bc2011-05-10 19:08:08 -0700128 Log.v(LOGTAG, "setting dump timeout at " + timeout);
Guang Zhuf37a5742010-12-23 14:37:31 -0800129 Message msg = mHandler.obtainMessage(MSG_DUMP_TIMEOUT);
130 mHandler.sendMessageDelayed(msg, timeout);
131 }
132
Guang Zhu889181d2009-07-09 12:55:15 -0700133 public void clearCache() {
Guang Zhuf56e1a12009-07-20 11:16:28 -0700134 mWebView.freeMemory();
Guang Zhu889181d2009-07-09 12:55:15 -0700135 }
136
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700137 @Override
138 protected void onCreate(Bundle icicle) {
139 super.onCreate(icicle);
Ben Murdoch9b815d02010-06-01 18:45:10 +0100140 requestWindowFeature(Window.FEATURE_PROGRESS);
Guang Zhuf92bd422009-06-29 10:40:55 -0700141
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700142 LinearLayout contentView = new LinearLayout(this);
143 contentView.setOrientation(LinearLayout.VERTICAL);
144 setContentView(contentView);
145
Kristian Monsen16d041c2010-12-06 13:43:51 +0000146 CookieManager.setAcceptFileSchemeCookies(true);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700147 mWebView = new WebView(this);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700148 mEventSender = new WebViewEventSender(mWebView);
149 mCallbackProxy = new CallbackProxy(mEventSender, this);
150
Andrei Popescu4950b2b2009-09-03 13:56:07 +0100151 mWebView.addJavascriptInterface(mCallbackProxy, "layoutTestController");
152 mWebView.addJavascriptInterface(mCallbackProxy, "eventSender");
Ben Murdoche6f3e452009-04-22 16:02:31 +0100153 setupWebViewForLayoutTests(mWebView, mCallbackProxy);
154
Romain Guy980a9382010-01-08 15:06:28 -0800155 contentView.addView(mWebView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 0.0f));
Guang Zhuf92bd422009-06-29 10:40:55 -0700156
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700157 mWebView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
Guang Zhuf92bd422009-06-29 10:40:55 -0700158
Feng Qian28909202009-08-13 14:54:56 -0700159 // Expose window.gc function to JavaScript. JSC build exposes
160 // this function by default, but V8 requires the flag to turn it on.
161 // WebView::setJsFlags is noop in JSC build.
162 mWebView.setJsFlags("--expose_gc");
163
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700164 mHandler = new AsyncHandler();
Guang Zhuf92bd422009-06-29 10:40:55 -0700165
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700166 Intent intent = getIntent();
167 if (intent != null) {
168 executeIntent(intent);
169 }
Steve Block68dede32010-08-04 10:28:46 +0100170
171 // This is asynchronous, but it gets processed by WebCore before it starts loading pages.
172 mWebView.useMockDeviceOrientation();
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700173 }
Guang Zhuf92bd422009-06-29 10:40:55 -0700174
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700175 @Override
176 protected void onNewIntent(Intent intent) {
177 super.onNewIntent(intent);
178 executeIntent(intent);
179 }
Guang Zhuf92bd422009-06-29 10:40:55 -0700180
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700181 private void executeIntent(Intent intent) {
182 resetTestStatus();
183 if (!Intent.ACTION_VIEW.equals(intent.getAction())) {
184 return;
185 }
Guang Zhuf92bd422009-06-29 10:40:55 -0700186
Ben Murdoch9b815d02010-06-01 18:45:10 +0100187 mTotalTestCount = intent.getIntExtra(TOTAL_TEST_COUNT, mTotalTestCount);
188 mCurrentTestNumber = intent.getIntExtra(CURRENT_TEST_NUMBER, mCurrentTestNumber);
189
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700190 mTestUrl = intent.getStringExtra(TEST_URL);
Guang Zhuf92bd422009-06-29 10:40:55 -0700191 if (mTestUrl == null) {
192 mUiAutoTestPath = intent.getStringExtra(UI_AUTO_TEST);
193 if(mUiAutoTestPath != null) {
194 beginUiAutoTest();
195 }
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700196 return;
Guang Zhuf92bd422009-06-29 10:40:55 -0700197 }
198
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700199 mResultFile = intent.getStringExtra(RESULT_FILE);
200 mTimeoutInMillis = intent.getIntExtra(TIMEOUT_IN_MILLIS, 0);
Guang Zhu5dc4f212009-10-29 18:24:54 -0700201 mGetDrawtime = intent.getBooleanExtra(GET_DRAW_TIME, false);
202 mSaveImagePath = intent.getStringExtra(SAVE_IMAGE);
Guang Zhu5d53c192010-07-14 17:17:54 -0700203 mStopOnRefError = intent.getBooleanExtra(STOP_ON_REF_ERROR, false);
Ben Murdoch9b815d02010-06-01 18:45:10 +0100204 setTitle("Test " + mCurrentTestNumber + " of " + mTotalTestCount);
205 float ratio = (float)mCurrentTestNumber / mTotalTestCount;
206 int progress = (int)(ratio * Window.PROGRESS_END);
207 getWindow().setFeatureInt(Window.FEATURE_PROGRESS, progress);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700208
209 Log.v(LOGTAG, " Loading " + mTestUrl);
210 mWebView.loadUrl(mTestUrl);
Guang Zhuf92bd422009-06-29 10:40:55 -0700211
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700212 if (mTimeoutInMillis > 0) {
213 // Create a timeout timer
214 Message m = mHandler.obtainMessage(MSG_TIMEOUT);
215 mHandler.sendMessageDelayed(m, mTimeoutInMillis);
216 }
217 }
Guang Zhuf92bd422009-06-29 10:40:55 -0700218
219 private void beginUiAutoTest() {
220 try {
221 mTestListReader = new BufferedReader(
222 new FileReader(mUiAutoTestPath));
223 } catch (IOException ioe) {
224 Log.e(LOGTAG, "Failed to open test list for read.", ioe);
225 finishUiAutoTest();
226 return;
227 }
228 moveToNextTest();
229 }
230
231 private void finishUiAutoTest() {
232 try {
233 if(mTestListReader != null)
234 mTestListReader.close();
235 } catch (IOException ioe) {
236 Log.w(LOGTAG, "Failed to close test list file.", ioe);
237 }
Guang Zhu6bf18ba2009-09-15 23:47:20 -0700238 ForwardService.getForwardService().stopForwardService();
Guang Zhuf92bd422009-06-29 10:40:55 -0700239 finished();
240 }
241
242 private void moveToNextTest() {
243 String url = null;
244 try {
245 url = mTestListReader.readLine();
246 } catch (IOException ioe) {
247 Log.e(LOGTAG, "Failed to read next test.", ioe);
248 finishUiAutoTest();
249 return;
250 }
251 if (url == null) {
252 mUiAutoTestPath = null;
253 finishUiAutoTest();
254 AlertDialog.Builder builder = new AlertDialog.Builder(this);
255 builder.setMessage("All tests finished. Exit?")
256 .setCancelable(false)
257 .setPositiveButton("Yes", new OnClickListener(){
258 public void onClick(DialogInterface dialog, int which) {
259 TestShellActivity.this.finish();
260 }
261 })
262 .setNegativeButton("No", new OnClickListener(){
263 public void onClick(DialogInterface dialog, int which) {
264 dialog.cancel();
265 }
266 });
267 builder.create().show();
268 return;
269 }
Guang Zhuf92bd422009-06-29 10:40:55 -0700270 Intent intent = new Intent(Intent.ACTION_VIEW);
271 intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
Guang Zhu6bf18ba2009-09-15 23:47:20 -0700272 intent.putExtra(TestShellActivity.TEST_URL, FsUtils.getTestUrl(url));
Ben Murdoch9b815d02010-06-01 18:45:10 +0100273 intent.putExtra(TestShellActivity.CURRENT_TEST_NUMBER, ++mCurrentTestNumber);
Guang Zhuf92bd422009-06-29 10:40:55 -0700274 intent.putExtra(TIMEOUT_IN_MILLIS, 10000);
275 executeIntent(intent);
276 }
277
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700278 @Override
279 protected void onStop() {
280 super.onStop();
281 mWebView.stopLoading();
282 }
Guang Zhuf92bd422009-06-29 10:40:55 -0700283
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700284 @Override
285 protected void onDestroy() {
286 super.onDestroy();
287 mWebView.destroy();
288 mWebView = null;
289 }
Guang Zhuf92bd422009-06-29 10:40:55 -0700290
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700291 @Override
292 public void onLowMemory() {
293 super.onLowMemory();
Feng Qian0aeed6a2009-07-16 20:53:31 -0700294 Log.e(LOGTAG, "Low memory, clearing caches");
295 mWebView.freeMemory();
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700296 }
297
298 // Dump the page
299 public void dump(boolean timeout, String webkitData) {
Ben Murdoch2eea5f32009-09-23 15:28:57 +0100300 mDumpWebKitData = true;
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700301 if (mResultFile == null || mResultFile.length() == 0) {
302 finished();
303 return;
304 }
Guang Zhuf92bd422009-06-29 10:40:55 -0700305
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700306 try {
307 File parentDir = new File(mResultFile).getParentFile();
308 if (!parentDir.exists()) {
309 parentDir.mkdirs();
310 }
Guang Zhuf92bd422009-06-29 10:40:55 -0700311
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700312 FileOutputStream os = new FileOutputStream(mResultFile);
313 if (timeout) {
314 Log.w("Layout test: Timeout", mResultFile);
315 os.write(TIMEOUT_STR.getBytes());
316 os.write('\n');
317 }
318 if (mDumpTitleChanges)
319 os.write(mTitleChanges.toString().getBytes());
320 if (mDialogStrings != null)
321 os.write(mDialogStrings.toString().getBytes());
322 mDialogStrings = null;
Ben Murdoche6f3e452009-04-22 16:02:31 +0100323 if (mDatabaseCallbackStrings != null)
324 os.write(mDatabaseCallbackStrings.toString().getBytes());
325 mDatabaseCallbackStrings = null;
326 if (mConsoleMessages != null)
327 os.write(mConsoleMessages.toString().getBytes());
328 mConsoleMessages = null;
Feng Qianbe42388b2009-04-16 10:05:38 -0700329 if (webkitData != null)
330 os.write(webkitData.getBytes());
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700331 os.flush();
332 os.close();
333 } catch (IOException ex) {
Guang Zhuf92bd422009-06-29 10:40:55 -0700334 Log.e(LOGTAG, "Cannot write to " + mResultFile + ", " + ex.getMessage());
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700335 }
336
337 finished();
338 }
Guang Zhuf92bd422009-06-29 10:40:55 -0700339
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700340 public void setCallback(TestShellCallback callback) {
341 mCallback = callback;
342 }
Guang Zhuf92bd422009-06-29 10:40:55 -0700343
Ben Murdoch2eea5f32009-09-23 15:28:57 +0100344 public boolean finished() {
345 if (canMoveToNextTest()) {
346 mHandler.removeMessages(MSG_TIMEOUT);
Ben Murdoch977f7692009-09-16 20:13:07 +0100347 if (mUiAutoTestPath != null) {
348 //don't really finish here
349 moveToNextTest();
350 } else {
351 if (mCallback != null) {
352 mCallback.finished();
353 }
Guang Zhuf92bd422009-06-29 10:40:55 -0700354 }
Ben Murdoch2eea5f32009-09-23 15:28:57 +0100355 return true;
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700356 }
Ben Murdoch2eea5f32009-09-23 15:28:57 +0100357 return false;
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700358 }
Guang Zhuf92bd422009-06-29 10:40:55 -0700359
Guang Zhu1871fe02009-04-29 14:49:03 -0700360 public void setDefaultDumpDataType(DumpDataType defaultDumpDataType) {
361 mDefaultDumpDataType = defaultDumpDataType;
362 }
363
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700364 // .......................................
365 // LayoutTestController Functions
Ben Murdoch357d2802010-07-23 16:18:58 +0100366 public void dumpAsText(boolean enablePixelTests) {
367 // Added after webkit update to r63859. See trac.webkit.org/changeset/63730.
368 if (enablePixelTests) {
369 Log.v(LOGTAG, "dumpAsText(enablePixelTests == true) not implemented on Android!");
370 }
371
Guang Zhu1871fe02009-04-29 14:49:03 -0700372 mDumpDataType = DumpDataType.DUMP_AS_TEXT;
Shimeng (Simon) Wangad456862010-06-16 17:32:24 -0700373 mDumpTopFrameAsText = true;
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700374 if (mWebView != null) {
375 String url = mWebView.getUrl();
376 Log.v(LOGTAG, "dumpAsText called: "+url);
377 }
378 }
379
Shimeng (Simon) Wangad456862010-06-16 17:32:24 -0700380 public void dumpChildFramesAsText() {
381 mDumpDataType = DumpDataType.DUMP_AS_TEXT;
382 mDumpChildFramesAsText = true;
383 if (mWebView != null) {
384 String url = mWebView.getUrl();
385 Log.v(LOGTAG, "dumpChildFramesAsText called: "+url);
386 }
387 }
388
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700389 public void waitUntilDone() {
390 mWaitUntilDone = true;
391 String url = mWebView.getUrl();
392 Log.v(LOGTAG, "waitUntilDone called: " + url);
393 }
Guang Zhuf92bd422009-06-29 10:40:55 -0700394
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700395 public void notifyDone() {
396 String url = mWebView.getUrl();
397 Log.v(LOGTAG, "notifyDone called: " + url);
398 if (mWaitUntilDone) {
399 mWaitUntilDone = false;
Ben Murdoch1620bcd2010-06-03 11:51:54 +0100400 if (!mRequestedWebKitData && !mTimedOut && !finished()) {
401 requestWebKitData();
402 }
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700403 }
404 }
Guang Zhuf92bd422009-06-29 10:40:55 -0700405
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700406 public void display() {
407 mWebView.invalidate();
408 }
409
410 public void clearBackForwardList() {
411 mWebView.clearHistory();
412
413 }
414
415 public void dumpBackForwardList() {
416 //printf("\n============== Back Forward List ==============\n");
417 // mWebHistory
418 //printf("===============================================\n");
419
420 }
421
422 public void dumpChildFrameScrollPositions() {
423 // TODO Auto-generated method stub
424
425 }
426
427 public void dumpEditingCallbacks() {
428 // TODO Auto-generated method stub
429
430 }
431
432 public void dumpSelectionRect() {
433 // TODO Auto-generated method stub
434
435 }
436
437 public void dumpTitleChanges() {
438 if (!mDumpTitleChanges) {
439 mTitleChanges = new StringBuffer();
440 }
441 mDumpTitleChanges = true;
442 }
443
444 public void keepWebHistory() {
445 if (!mKeepWebHistory) {
446 mWebHistory = new Vector();
447 }
448 mKeepWebHistory = true;
449 }
450
451 public void queueBackNavigation(int howfar) {
452 // TODO Auto-generated method stub
453
454 }
455
456 public void queueForwardNavigation(int howfar) {
457 // TODO Auto-generated method stub
458
459 }
460
461 public void queueLoad(String Url, String frameTarget) {
462 // TODO Auto-generated method stub
463
464 }
465
466 public void queueReload() {
467 mWebView.reload();
468 }
469
470 public void queueScript(String scriptToRunInCurrentContext) {
Guang Zhuf92bd422009-06-29 10:40:55 -0700471 mWebView.loadUrl("javascript:"+scriptToRunInCurrentContext);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700472 }
473
474 public void repaintSweepHorizontally() {
475 // TODO Auto-generated method stub
476
477 }
478
479 public void setAcceptsEditing(boolean b) {
480 // TODO Auto-generated method stub
481
482 }
483
484 public void setMainFrameIsFirstResponder(boolean b) {
485 // TODO Auto-generated method stub
486
487 }
488
489 public void setWindowIsKey(boolean b) {
490 // This is meant to show/hide the window. The best I can find
491 // is setEnabled()
492 mWebView.setEnabled(b);
493 }
494
495 public void testRepaint() {
496 mWebView.invalidate();
497 }
Ben Murdoche6f3e452009-04-22 16:02:31 +0100498
499 public void dumpDatabaseCallbacks() {
500 Log.v(LOGTAG, "dumpDatabaseCallbacks called.");
501 mDumpDatabaseCallbacks = true;
502 }
503
504 public void setCanOpenWindows() {
505 Log.v(LOGTAG, "setCanOpenWindows called.");
506 mCanOpenWindows = true;
507 }
508
Steve Blockdad347c2009-08-19 18:46:34 +0100509 /**
510 * Sets the Geolocation permission state to be used for all future requests.
511 */
512 public void setGeolocationPermission(boolean allow) {
Steve Blockf0f30c62010-08-18 15:15:42 +0100513 mIsGeolocationPermissionSet = true;
Steve Blockdad347c2009-08-19 18:46:34 +0100514 mGeolocationPermission = allow;
Steve Blockf0f30c62010-08-18 15:15:42 +0100515
516 if (mPendingGeolocationPermissionCallbacks != null) {
517 Iterator iter = mPendingGeolocationPermissionCallbacks.keySet().iterator();
518 while (iter.hasNext()) {
519 GeolocationPermissions.Callback callback =
520 (GeolocationPermissions.Callback) iter.next();
521 String origin = (String) mPendingGeolocationPermissionCallbacks.get(callback);
522 callback.invoke(origin, mGeolocationPermission, false);
523 }
524 mPendingGeolocationPermissionCallbacks = null;
525 }
Steve Blockdad347c2009-08-19 18:46:34 +0100526 }
527
Steve Block68dede32010-08-04 10:28:46 +0100528 public void setMockDeviceOrientation(boolean canProvideAlpha, double alpha,
529 boolean canProvideBeta, double beta, boolean canProvideGamma, double gamma) {
530 mWebView.setMockDeviceOrientation(canProvideAlpha, alpha, canProvideBeta, beta,
531 canProvideGamma, gamma);
532 }
533
Steve Blockfb0de342010-03-19 18:48:35 +0000534 public void overridePreference(String key, boolean value) {
535 // TODO: We should look up the correct WebView for the frame which
536 // called the layoutTestController method. Currently, we just use the
537 // WebView for the main frame. EventSender suffers from the same
538 // problem.
Steve Block5f37cc432010-10-13 18:44:31 +0100539 if (WEBKIT_OFFLINE_WEB_APPLICATION_CACHE_ENABLED.equals(key)) {
Steve Blockfb0de342010-03-19 18:48:35 +0000540 mWebView.getSettings().setAppCacheEnabled(value);
Steve Block5f37cc432010-10-13 18:44:31 +0100541 } else if (WEBKIT_USES_PAGE_CACHE_PREFERENCE_KEY.equals(key)) {
542 // Cache the maximum possible number of pages.
543 mWebView.getSettings().setPageCacheCapacity(Integer.MAX_VALUE);
544 } else {
545 Log.w(LOGTAG, "LayoutTestController.overridePreference(): " +
546 "Unsupported preference '" + key + "'");
Steve Blockfb0de342010-03-19 18:48:35 +0000547 }
548 }
549
Elliott Slaughter5dc0c822010-06-22 11:31:54 -0700550 public void setXSSAuditorEnabled (boolean flag) {
551 mWebView.getSettings().setXSSAuditorEnabled(flag);
552 }
553
Ben Murdoche6f3e452009-04-22 16:02:31 +0100554 private final WebViewClient mViewClient = new WebViewClient(){
555 @Override
556 public void onPageFinished(WebView view, String url) {
557 Log.v(LOGTAG, "onPageFinished, url=" + url);
Ben Murdoch2eea5f32009-09-23 15:28:57 +0100558 mPageFinished = true;
Guang Zhu5dc4f212009-10-29 18:24:54 -0700559 // get page draw time
560 if (FsUtils.isTestPageUrl(url)) {
561 if (mGetDrawtime) {
562 long[] times = new long[DRAW_RUNS];
563 times = getDrawWebViewTime(mWebView, DRAW_RUNS);
564 FsUtils.writeDrawTime(DRAW_TIME_LOG, url, times);
565 }
566 if (mSaveImagePath != null) {
567 String name = FsUtils.getLastSegmentInPath(url);
568 drawPageToFile(mSaveImagePath + "/" + name + ".png", mWebView);
569 }
570 }
Ben Murdoch1620bcd2010-06-03 11:51:54 +0100571
Ben Murdoch2eea5f32009-09-23 15:28:57 +0100572 // Calling finished() will check if we've met all the conditions for completing
Ben Murdoch1620bcd2010-06-03 11:51:54 +0100573 // this test and move to the next one if we are ready. Otherwise we ask WebCore to
574 // dump the page.
Ben Murdoch2eea5f32009-09-23 15:28:57 +0100575 if (finished()) {
576 return;
577 }
Ben Murdoch1620bcd2010-06-03 11:51:54 +0100578
579 if (!mWaitUntilDone && !mRequestedWebKitData && !mTimedOut) {
580 requestWebKitData();
581 } else {
582 if (mWaitUntilDone) {
583 Log.v(LOGTAG, "page finished loading but waiting for notifyDone to be called: " + url);
584 }
585
586 if (mRequestedWebKitData) {
587 Log.v(LOGTAG, "page finished loading but webkit data has already been requested: " + url);
588 }
589
590 if (mTimedOut) {
591 Log.v(LOGTAG, "page finished loading but already timed out: " + url);
592 }
593 }
594
Ben Murdoche6f3e452009-04-22 16:02:31 +0100595 super.onPageFinished(view, url);
596 }
597
598 @Override
599 public void onPageStarted(WebView view, String url, Bitmap favicon) {
600 Log.v(LOGTAG, "onPageStarted, url=" + url);
Ben Murdoch2eea5f32009-09-23 15:28:57 +0100601 mPageFinished = false;
Ben Murdoche6f3e452009-04-22 16:02:31 +0100602 super.onPageStarted(view, url, favicon);
603 }
604
605 @Override
606 public void onReceivedError(WebView view, int errorCode, String description,
607 String failingUrl) {
608 Log.v(LOGTAG, "onReceivedError, errorCode=" + errorCode
609 + ", desc=" + description + ", url=" + failingUrl);
610 super.onReceivedError(view, errorCode, description, failingUrl);
611 }
612
613 @Override
614 public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler,
615 String host, String realm) {
Steve Block2bb25532010-03-25 14:48:13 +0000616 if (handler.useHttpAuthUsernamePassword() && view != null) {
617 String[] credentials = view.getHttpAuthUsernamePassword(host, realm);
618 if (credentials != null && credentials.length == 2) {
619 handler.proceed(credentials[0], credentials[1]);
620 return;
621 }
622 }
Ben Murdoche6f3e452009-04-22 16:02:31 +0100623 handler.cancel();
624 }
625
626 @Override
627 public void onReceivedSslError(WebView view, SslErrorHandler handler,
628 SslError error) {
629 handler.proceed();
630 }
631 };
632
633
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700634 private final WebChromeClient mChromeClient = new WebChromeClient() {
635 @Override
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700636 public void onReceivedTitle(WebView view, String title) {
Ben Murdoch9b815d02010-06-01 18:45:10 +0100637 setTitle("Test " + mCurrentTestNumber + " of " + mTotalTestCount + ": "+ title);
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700638 if (mDumpTitleChanges) {
639 mTitleChanges.append("TITLE CHANGED: ");
640 mTitleChanges.append(title);
641 mTitleChanges.append("\n");
642 }
643 }
644
645 @Override
646 public boolean onJsAlert(WebView view, String url, String message,
647 JsResult result) {
648 if (mDialogStrings == null) {
649 mDialogStrings = new StringBuffer();
650 }
651 mDialogStrings.append("ALERT: ");
652 mDialogStrings.append(message);
653 mDialogStrings.append('\n');
654 result.confirm();
655 return true;
656 }
Guang Zhuf92bd422009-06-29 10:40:55 -0700657
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700658 @Override
659 public boolean onJsConfirm(WebView view, String url, String message,
660 JsResult result) {
661 if (mDialogStrings == null) {
662 mDialogStrings = new StringBuffer();
663 }
664 mDialogStrings.append("CONFIRM: ");
665 mDialogStrings.append(message);
666 mDialogStrings.append('\n');
667 result.confirm();
668 return true;
669 }
Guang Zhuf92bd422009-06-29 10:40:55 -0700670
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700671 @Override
672 public boolean onJsPrompt(WebView view, String url, String message,
673 String defaultValue, JsPromptResult result) {
674 if (mDialogStrings == null) {
675 mDialogStrings = new StringBuffer();
676 }
677 mDialogStrings.append("PROMPT: ");
678 mDialogStrings.append(message);
679 mDialogStrings.append(", default text: ");
680 mDialogStrings.append(defaultValue);
681 mDialogStrings.append('\n');
682 result.confirm();
683 return true;
684 }
Ben Murdoche6f3e452009-04-22 16:02:31 +0100685
686 @Override
Guang Zhuf4bf5522009-07-23 14:19:35 -0700687 public boolean onJsTimeout() {
688 Log.v(LOGTAG, "JavaScript timeout");
689 return false;
690 }
691
692 @Override
Ben Murdoche6f3e452009-04-22 16:02:31 +0100693 public void onExceededDatabaseQuota(String url_str,
Ben Murdochd497d872009-08-25 19:32:54 +0100694 String databaseIdentifier, long currentQuota,
695 long estimatedSize, long totalUsedQuota,
Ben Murdoche6f3e452009-04-22 16:02:31 +0100696 WebStorage.QuotaUpdater callback) {
697 if (mDumpDatabaseCallbacks) {
698 if (mDatabaseCallbackStrings == null) {
699 mDatabaseCallbackStrings = new StringBuffer();
700 }
701
702 String protocol = "";
703 String host = "";
704 int port = 0;
705
706 try {
707 URL url = new URL(url_str);
708 protocol = url.getProtocol();
709 host = url.getHost();
710 if (url.getPort() > -1) {
711 port = url.getPort();
712 }
713 } catch (MalformedURLException e) {}
714
715 String databaseCallbackString =
716 "UI DELEGATE DATABASE CALLBACK: " +
717 "exceededDatabaseQuotaForSecurityOrigin:{" + protocol +
718 ", " + host + ", " + port + "} database:" +
719 databaseIdentifier + "\n";
720 Log.v(LOGTAG, "LOG: "+databaseCallbackString);
721 mDatabaseCallbackStrings.append(databaseCallbackString);
722 }
723 // Give 5MB more quota.
724 callback.updateQuota(currentQuota + 1024 * 1024 * 5);
725 }
726
Steve Blockdad347c2009-08-19 18:46:34 +0100727 /**
728 * Instructs the client to show a prompt to ask the user to set the
729 * Geolocation permission state for the specified origin.
730 */
731 @Override
732 public void onGeolocationPermissionsShowPrompt(String origin,
733 GeolocationPermissions.Callback callback) {
Steve Blockf0f30c62010-08-18 15:15:42 +0100734 if (mIsGeolocationPermissionSet) {
Steve Blockdad347c2009-08-19 18:46:34 +0100735 callback.invoke(origin, mGeolocationPermission, false);
Steve Blockf0f30c62010-08-18 15:15:42 +0100736 return;
Steve Blockdad347c2009-08-19 18:46:34 +0100737 }
Steve Blockf0f30c62010-08-18 15:15:42 +0100738 if (mPendingGeolocationPermissionCallbacks == null) {
739 mPendingGeolocationPermissionCallbacks =
740 new HashMap<GeolocationPermissions.Callback, String>();
741 }
742 mPendingGeolocationPermissionCallbacks.put(callback, origin);
Steve Blockdad347c2009-08-19 18:46:34 +0100743 }
744
Ben Murdoche6f3e452009-04-22 16:02:31 +0100745 @Override
Guang Zhu6c15f602010-05-03 11:49:04 -0700746 public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
747 String msg = "CONSOLE MESSAGE: line " + consoleMessage.lineNumber() + ": "
748 + consoleMessage.message() + "\n";
Ben Murdoche6f3e452009-04-22 16:02:31 +0100749 if (mConsoleMessages == null) {
750 mConsoleMessages = new StringBuffer();
751 }
Guang Zhu6c15f602010-05-03 11:49:04 -0700752 mConsoleMessages.append(msg);
753 Log.v(LOGTAG, "LOG: " + msg);
754 // the rationale here is that if there's an error of either type, and the test was
755 // waiting for "notifyDone" signal to finish, then there's no point in waiting
756 // anymore because the JS execution is already terminated at this point and a
757 // "notifyDone" will never come out so it's just wasting time till timeout kicks in
Guang Zhu5d53c192010-07-14 17:17:54 -0700758 if ((msg.contains("Uncaught ReferenceError:") || msg.contains("Uncaught TypeError:"))
759 && mWaitUntilDone && mStopOnRefError) {
Guang Zhu6c15f602010-05-03 11:49:04 -0700760 Log.w(LOGTAG, "Terminating test case on uncaught ReferenceError or TypeError.");
761 mHandler.postDelayed(new Runnable() {
762 public void run() {
763 notifyDone();
764 }
765 }, 500);
766 }
767 return true;
Ben Murdoche6f3e452009-04-22 16:02:31 +0100768 }
769
770 @Override
771 public boolean onCreateWindow(WebView view, boolean dialog,
772 boolean userGesture, Message resultMsg) {
773 if (!mCanOpenWindows) {
Ben Murdochfc4a69e2010-02-04 16:35:10 +0000774 // We can't open windows, so just send null back.
775 WebView.WebViewTransport transport =
776 (WebView.WebViewTransport) resultMsg.obj;
777 transport.setWebView(null);
778 resultMsg.sendToTarget();
779 return true;
Ben Murdoche6f3e452009-04-22 16:02:31 +0100780 }
781
782 // We never display the new window, just create the view and
783 // allow it's content to execute and be recorded by the test
784 // runner.
785
Andrei Popescu4950b2b2009-09-03 13:56:07 +0100786 HashMap<String, Object> jsIfaces = new HashMap<String, Object>();
787 jsIfaces.put("layoutTestController", mCallbackProxy);
788 jsIfaces.put("eventSender", mCallbackProxy);
789 WebView newWindowView = new NewWindowWebView(TestShellActivity.this, jsIfaces);
Ben Murdoche6f3e452009-04-22 16:02:31 +0100790 setupWebViewForLayoutTests(newWindowView, mCallbackProxy);
791 WebView.WebViewTransport transport =
792 (WebView.WebViewTransport) resultMsg.obj;
793 transport.setWebView(newWindowView);
794 resultMsg.sendToTarget();
795 return true;
796 }
Ben Murdochfc4a69e2010-02-04 16:35:10 +0000797
798 @Override
799 public void onCloseWindow(WebView view) {
800 view.destroy();
801 }
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700802 };
Guang Zhuf92bd422009-06-29 10:40:55 -0700803
Andrei Popescu4950b2b2009-09-03 13:56:07 +0100804 private static class NewWindowWebView extends WebView {
805 public NewWindowWebView(Context context, Map<String, Object> jsIfaces) {
Elliott Slaughterf21d2e32010-07-14 18:08:54 -0700806 super(context, null, 0, jsIfaces, false);
Andrei Popescu4950b2b2009-09-03 13:56:07 +0100807 }
808 }
809
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700810 private void resetTestStatus() {
811 mWaitUntilDone = false;
Guang Zhu1871fe02009-04-29 14:49:03 -0700812 mDumpDataType = mDefaultDumpDataType;
Shimeng (Simon) Wangad456862010-06-16 17:32:24 -0700813 mDumpTopFrameAsText = false;
814 mDumpChildFramesAsText = false;
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700815 mTimedOut = false;
816 mDumpTitleChanges = false;
817 mRequestedWebKitData = false;
Ben Murdoche6f3e452009-04-22 16:02:31 +0100818 mDumpDatabaseCallbacks = false;
819 mCanOpenWindows = false;
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700820 mEventSender.resetMouse();
Ben Murdochecbc65c2010-01-13 10:54:56 +0000821 mEventSender.clearTouchPoints();
Ben Murdoch8a032a32010-02-02 18:20:11 +0000822 mEventSender.clearTouchMetaState();
Ben Murdoch2eea5f32009-09-23 15:28:57 +0100823 mPageFinished = false;
Ben Murdoch2eea5f32009-09-23 15:28:57 +0100824 mDumpWebKitData = false;
Guang Zhu5dc4f212009-10-29 18:24:54 -0700825 mGetDrawtime = false;
826 mSaveImagePath = null;
Ben Murdocha8b97682010-04-15 12:20:48 -0700827 setDefaultWebSettings(mWebView);
Steve Blockf0f30c62010-08-18 15:15:42 +0100828 mIsGeolocationPermissionSet = false;
829 mPendingGeolocationPermissionCallbacks = null;
Ben Murdoch7e73ce92011-01-20 11:21:24 +0000830 CookieManager.getInstance().removeAllCookie();
Guang Zhu5dc4f212009-10-29 18:24:54 -0700831 }
832
833 private long[] getDrawWebViewTime(WebView view, int count) {
834 if (count == 0)
835 return null;
836 long[] ret = new long[count];
837 long start;
838 Canvas canvas = new Canvas();
839 Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Config.ARGB_8888);
840 canvas.setBitmap(bitmap);
841 for (int i = 0; i < count; i++) {
842 start = System.currentTimeMillis();
843 view.draw(canvas);
844 ret[i] = System.currentTimeMillis() - start;
845 }
846 return ret;
847 }
848
849 private void drawPageToFile(String fileName, WebView view) {
850 Canvas canvas = new Canvas();
851 Bitmap bitmap = Bitmap.createBitmap(view.getContentWidth(), view.getContentHeight(),
852 Config.ARGB_8888);
853 canvas.setBitmap(bitmap);
854 view.drawPage(canvas);
855 try {
856 FileOutputStream fos = new FileOutputStream(fileName);
857 if(!bitmap.compress(CompressFormat.PNG, 90, fos)) {
858 Log.w(LOGTAG, "Failed to compress and save image.");
859 }
860 } catch (IOException ioe) {
861 Log.e(LOGTAG, "", ioe);
862 }
863 bitmap.recycle();
Ben Murdoch2eea5f32009-09-23 15:28:57 +0100864 }
865
866 private boolean canMoveToNextTest() {
Ben Murdoch1620bcd2010-06-03 11:51:54 +0100867 return (mDumpWebKitData && mPageFinished && !mWaitUntilDone) || mTimedOut;
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700868 }
Ben Murdoche6f3e452009-04-22 16:02:31 +0100869
870 private void setupWebViewForLayoutTests(WebView webview, CallbackProxy callbackProxy) {
871 if (webview == null) {
872 return;
873 }
874
Ben Murdocha8b97682010-04-15 12:20:48 -0700875 setDefaultWebSettings(webview);
876
877 webview.setWebChromeClient(mChromeClient);
878 webview.setWebViewClient(mViewClient);
879 // Setting a touch interval of -1 effectively disables the optimisation in WebView
880 // that stops repeated touch events flooding WebCore. The Event Sender only sends a
881 // single event rather than a stream of events (like what would generally happen in
882 // a real use of touch events in a WebView) and so if the WebView drops the event,
883 // the test will fail as the test expects one callback for every touch it synthesizes.
884 webview.setTouchInterval(-1);
885 }
886
887 public void setDefaultWebSettings(WebView webview) {
Ben Murdoche6f3e452009-04-22 16:02:31 +0100888 WebSettings settings = webview.getSettings();
Guang Zhuf4bf5522009-07-23 14:19:35 -0700889 settings.setAppCacheEnabled(true);
890 settings.setAppCachePath(getApplicationContext().getCacheDir().getPath());
891 settings.setAppCacheMaxSize(Long.MAX_VALUE);
Ben Murdoche6f3e452009-04-22 16:02:31 +0100892 settings.setJavaScriptEnabled(true);
893 settings.setJavaScriptCanOpenWindowsAutomatically(true);
894 settings.setSupportMultipleWindows(true);
895 settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
896 settings.setDatabaseEnabled(true);
897 settings.setDatabasePath(getDir("databases",0).getAbsolutePath());
898 settings.setDomStorageEnabled(true);
Guang Zhub028f922009-08-11 14:27:32 -0700899 settings.setWorkersEnabled(false);
Elliott Slaughterbe1304f2010-06-23 11:29:02 -0700900 settings.setXSSAuditorEnabled(false);
Steve Block5f37cc432010-10-13 18:44:31 +0100901 settings.setPageCacheCapacity(0);
Ben Murdoche6f3e452009-04-22 16:02:31 +0100902 }
903
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700904 private WebView mWebView;
905 private WebViewEventSender mEventSender;
906 private AsyncHandler mHandler;
907 private TestShellCallback mCallback;
908
909 private CallbackProxy mCallbackProxy;
Guang Zhuf92bd422009-06-29 10:40:55 -0700910
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700911 private String mTestUrl;
912 private String mResultFile;
913 private int mTimeoutInMillis;
Guang Zhuf92bd422009-06-29 10:40:55 -0700914 private String mUiAutoTestPath;
Guang Zhu5dc4f212009-10-29 18:24:54 -0700915 private String mSaveImagePath;
Guang Zhuf92bd422009-06-29 10:40:55 -0700916 private BufferedReader mTestListReader;
Guang Zhu5dc4f212009-10-29 18:24:54 -0700917 private boolean mGetDrawtime;
Ben Murdoch9b815d02010-06-01 18:45:10 +0100918 private int mTotalTestCount;
919 private int mCurrentTestNumber;
Guang Zhu5d53c192010-07-14 17:17:54 -0700920 private boolean mStopOnRefError;
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700921
922 // States
923 private boolean mTimedOut;
924 private boolean mRequestedWebKitData;
925 private boolean mFinishedRunning;
926
927 // Layout test controller variables.
Guang Zhu1871fe02009-04-29 14:49:03 -0700928 private DumpDataType mDumpDataType;
929 private DumpDataType mDefaultDumpDataType = DumpDataType.EXT_REPR;
Shimeng (Simon) Wangad456862010-06-16 17:32:24 -0700930 private boolean mDumpTopFrameAsText;
931 private boolean mDumpChildFramesAsText;
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700932 private boolean mWaitUntilDone;
933 private boolean mDumpTitleChanges;
934 private StringBuffer mTitleChanges;
935 private StringBuffer mDialogStrings;
936 private boolean mKeepWebHistory;
937 private Vector mWebHistory;
Ben Murdoche6f3e452009-04-22 16:02:31 +0100938 private boolean mDumpDatabaseCallbacks;
939 private StringBuffer mDatabaseCallbackStrings;
940 private StringBuffer mConsoleMessages;
941 private boolean mCanOpenWindows;
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700942
Ben Murdoch2eea5f32009-09-23 15:28:57 +0100943 private boolean mPageFinished = false;
944 private boolean mDumpWebKitData = false;
Ben Murdoch977f7692009-09-16 20:13:07 +0100945
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700946 static final String TIMEOUT_STR = "**Test timeout";
Steve Block8e8cf732011-02-10 10:51:45 -0800947 static final long DUMP_TIMEOUT_MS = 100000; // 100s timeout for dumping webview content
Guang Zhuf92bd422009-06-29 10:40:55 -0700948
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700949 static final int MSG_TIMEOUT = 0;
950 static final int MSG_WEBKIT_DATA = 1;
Guang Zhuf37a5742010-12-23 14:37:31 -0800951 static final int MSG_DUMP_TIMEOUT = 2;
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700952
953 static final String LOGTAG="TestShell";
Guang Zhuf92bd422009-06-29 10:40:55 -0700954
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700955 static final String TEST_URL = "TestUrl";
956 static final String RESULT_FILE = "ResultFile";
957 static final String TIMEOUT_IN_MILLIS = "TimeoutInMillis";
Guang Zhuf92bd422009-06-29 10:40:55 -0700958 static final String UI_AUTO_TEST = "UiAutoTest";
Guang Zhu5dc4f212009-10-29 18:24:54 -0700959 static final String GET_DRAW_TIME = "GetDrawTime";
960 static final String SAVE_IMAGE = "SaveImage";
Ben Murdoch9b815d02010-06-01 18:45:10 +0100961 static final String TOTAL_TEST_COUNT = "TestCount";
962 static final String CURRENT_TEST_NUMBER = "TestNumber";
Guang Zhu5d53c192010-07-14 17:17:54 -0700963 static final String STOP_ON_REF_ERROR = "StopOnReferenceError";
Guang Zhu5dc4f212009-10-29 18:24:54 -0700964
965 static final int DRAW_RUNS = 5;
Christian Mehlmauer8b85dce2010-07-19 20:11:27 +0200966 static final String DRAW_TIME_LOG = Environment.getExternalStorageDirectory() +
967 "/android/page_draw_time.txt";
Steve Blockdad347c2009-08-19 18:46:34 +0100968
Steve Blockf0f30c62010-08-18 15:15:42 +0100969 private boolean mIsGeolocationPermissionSet;
Steve Blockdad347c2009-08-19 18:46:34 +0100970 private boolean mGeolocationPermission;
Steve Blockf0f30c62010-08-18 15:15:42 +0100971 private Map mPendingGeolocationPermissionCallbacks;
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -0700972}