The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.dumprendertree; |
| 18 | |
Guang Zhu | 6bf18ba | 2009-09-15 23:47:20 -0700 | [diff] [blame] | 19 | import com.android.dumprendertree.forwarder.ForwardService; |
| 20 | |
Guang Zhu | 1871fe0 | 2009-04-29 14:49:03 -0700 | [diff] [blame] | 21 | import android.app.Activity; |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 22 | import android.app.AlertDialog; |
Andrei Popescu | 4950b2b | 2009-09-03 13:56:07 +0100 | [diff] [blame] | 23 | import android.content.Context; |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 24 | import android.content.DialogInterface; |
Guang Zhu | 1871fe0 | 2009-04-29 14:49:03 -0700 | [diff] [blame] | 25 | import android.content.Intent; |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 26 | import android.content.DialogInterface.OnClickListener; |
Guang Zhu | 1871fe0 | 2009-04-29 14:49:03 -0700 | [diff] [blame] | 27 | import android.graphics.Bitmap; |
Guang Zhu | 5dc4f21 | 2009-10-29 18:24:54 -0700 | [diff] [blame] | 28 | import android.graphics.Canvas; |
| 29 | import android.graphics.Bitmap.CompressFormat; |
| 30 | import android.graphics.Bitmap.Config; |
Guang Zhu | 1871fe0 | 2009-04-29 14:49:03 -0700 | [diff] [blame] | 31 | import android.net.http.SslError; |
| 32 | import android.os.Bundle; |
Christian Mehlmauer | 8b85dce | 2010-07-19 20:11:27 +0200 | [diff] [blame] | 33 | import android.os.Environment; |
Guang Zhu | 1871fe0 | 2009-04-29 14:49:03 -0700 | [diff] [blame] | 34 | import android.os.Handler; |
| 35 | import android.os.Message; |
| 36 | import android.util.Log; |
| 37 | import android.view.ViewGroup; |
Ben Murdoch | 9b815d0 | 2010-06-01 18:45:10 +0100 | [diff] [blame] | 38 | import android.view.Window; |
Guang Zhu | 6c15f60 | 2010-05-03 11:49:04 -0700 | [diff] [blame] | 39 | import android.webkit.ConsoleMessage; |
Steve Block | dad347c | 2009-08-19 18:46:34 +0100 | [diff] [blame] | 40 | import android.webkit.GeolocationPermissions; |
Guang Zhu | 1871fe0 | 2009-04-29 14:49:03 -0700 | [diff] [blame] | 41 | import android.webkit.HttpAuthHandler; |
| 42 | import android.webkit.JsPromptResult; |
| 43 | import android.webkit.JsResult; |
| 44 | import android.webkit.SslErrorHandler; |
| 45 | import android.webkit.WebChromeClient; |
| 46 | import android.webkit.WebSettings; |
Ben Murdoch | e6f3e45 | 2009-04-22 16:02:31 +0100 | [diff] [blame] | 47 | import android.webkit.WebStorage; |
Guang Zhu | 1871fe0 | 2009-04-29 14:49:03 -0700 | [diff] [blame] | 48 | import android.webkit.WebView; |
| 49 | import android.webkit.WebViewClient; |
| 50 | import android.widget.LinearLayout; |
| 51 | |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 52 | import java.io.BufferedReader; |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 53 | import java.io.File; |
| 54 | import java.io.FileOutputStream; |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 55 | import java.io.FileReader; |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 56 | import java.io.IOException; |
Ben Murdoch | e6f3e45 | 2009-04-22 16:02:31 +0100 | [diff] [blame] | 57 | import java.net.MalformedURLException; |
| 58 | import java.net.URL; |
Andrei Popescu | 4950b2b | 2009-09-03 13:56:07 +0100 | [diff] [blame] | 59 | import java.util.HashMap; |
Steve Block | f0f30c6 | 2010-08-18 15:15:42 +0100 | [diff] [blame] | 60 | import java.util.Iterator; |
Andrei Popescu | 4950b2b | 2009-09-03 13:56:07 +0100 | [diff] [blame] | 61 | import java.util.Map; |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 62 | import java.util.Vector; |
| 63 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 64 | public class TestShellActivity extends Activity implements LayoutTestController { |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 65 | |
Guang Zhu | 1871fe0 | 2009-04-29 14:49:03 -0700 | [diff] [blame] | 66 | static enum DumpDataType {DUMP_AS_TEXT, EXT_REPR, NO_OP} |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 67 | |
Steve Block | fb0de34 | 2010-03-19 18:48:35 +0000 | [diff] [blame] | 68 | // String constants for use with layoutTestController.overridePreferences |
| 69 | private final String WEBKIT_OFFLINE_WEB_APPLICATION_CACHE_ENABLED = "WebKitOfflineWebApplicationCacheEnabled"; |
| 70 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 71 | public class AsyncHandler extends Handler { |
| 72 | @Override |
| 73 | public void handleMessage(Message msg) { |
| 74 | if (msg.what == MSG_TIMEOUT) { |
| 75 | mTimedOut = true; |
Guang Zhu | 56a3693 | 2009-09-28 09:53:48 -0700 | [diff] [blame] | 76 | if (mCallback != null) |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 77 | mCallback.timedOut(mWebView.getUrl()); |
Guang Zhu | 56a3693 | 2009-09-28 09:53:48 -0700 | [diff] [blame] | 78 | if (!mRequestedWebKitData) { |
Guang Zhu | 7216047 | 2009-09-25 17:34:12 -0700 | [diff] [blame] | 79 | requestWebKitData(); |
| 80 | } else { |
| 81 | // if timed out and webkit data has been dumped before |
| 82 | // finish directly |
| 83 | finished(); |
| 84 | } |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 85 | return; |
| 86 | } else if (msg.what == MSG_WEBKIT_DATA) { |
| 87 | TestShellActivity.this.dump(mTimedOut, (String)msg.obj); |
| 88 | return; |
| 89 | } |
| 90 | |
| 91 | super.handleMessage(msg); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | public void requestWebKitData() { |
| 96 | Message callback = mHandler.obtainMessage(MSG_WEBKIT_DATA); |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 97 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 98 | if (mRequestedWebKitData) |
| 99 | throw new AssertionError("Requested webkit data twice: " + mWebView.getUrl()); |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 100 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 101 | mRequestedWebKitData = true; |
Guang Zhu | 7216047 | 2009-09-25 17:34:12 -0700 | [diff] [blame] | 102 | Log.v(LOGTAG, "message sent to WebView to dump text."); |
Guang Zhu | 1871fe0 | 2009-04-29 14:49:03 -0700 | [diff] [blame] | 103 | switch (mDumpDataType) { |
| 104 | case DUMP_AS_TEXT: |
Shimeng (Simon) Wang | ad45686 | 2010-06-16 17:32:24 -0700 | [diff] [blame] | 105 | callback.arg1 = mDumpTopFrameAsText ? 1 : 0; |
| 106 | callback.arg2 = mDumpChildFramesAsText ? 1 : 0; |
Guang Zhu | 1871fe0 | 2009-04-29 14:49:03 -0700 | [diff] [blame] | 107 | mWebView.documentAsText(callback); |
| 108 | break; |
| 109 | case EXT_REPR: |
| 110 | mWebView.externalRepresentation(callback); |
| 111 | break; |
| 112 | default: |
| 113 | finished(); |
| 114 | break; |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 115 | } |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 116 | } |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 117 | |
Guang Zhu | 889181d | 2009-07-09 12:55:15 -0700 | [diff] [blame] | 118 | public void clearCache() { |
Guang Zhu | f56e1a1 | 2009-07-20 11:16:28 -0700 | [diff] [blame] | 119 | mWebView.freeMemory(); |
Guang Zhu | 889181d | 2009-07-09 12:55:15 -0700 | [diff] [blame] | 120 | } |
| 121 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 122 | @Override |
| 123 | protected void onCreate(Bundle icicle) { |
| 124 | super.onCreate(icicle); |
Ben Murdoch | 9b815d0 | 2010-06-01 18:45:10 +0100 | [diff] [blame] | 125 | requestWindowFeature(Window.FEATURE_PROGRESS); |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 126 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 127 | LinearLayout contentView = new LinearLayout(this); |
| 128 | contentView.setOrientation(LinearLayout.VERTICAL); |
| 129 | setContentView(contentView); |
| 130 | |
| 131 | mWebView = new WebView(this); |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 132 | mEventSender = new WebViewEventSender(mWebView); |
| 133 | mCallbackProxy = new CallbackProxy(mEventSender, this); |
| 134 | |
Andrei Popescu | 4950b2b | 2009-09-03 13:56:07 +0100 | [diff] [blame] | 135 | mWebView.addJavascriptInterface(mCallbackProxy, "layoutTestController"); |
| 136 | mWebView.addJavascriptInterface(mCallbackProxy, "eventSender"); |
Ben Murdoch | e6f3e45 | 2009-04-22 16:02:31 +0100 | [diff] [blame] | 137 | setupWebViewForLayoutTests(mWebView, mCallbackProxy); |
| 138 | |
Romain Guy | 980a938 | 2010-01-08 15:06:28 -0800 | [diff] [blame] | 139 | contentView.addView(mWebView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 0.0f)); |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 140 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 141 | mWebView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL); |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 142 | |
Feng Qian | 2890920 | 2009-08-13 14:54:56 -0700 | [diff] [blame] | 143 | // Expose window.gc function to JavaScript. JSC build exposes |
| 144 | // this function by default, but V8 requires the flag to turn it on. |
| 145 | // WebView::setJsFlags is noop in JSC build. |
| 146 | mWebView.setJsFlags("--expose_gc"); |
| 147 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 148 | mHandler = new AsyncHandler(); |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 149 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 150 | Intent intent = getIntent(); |
| 151 | if (intent != null) { |
| 152 | executeIntent(intent); |
| 153 | } |
Steve Block | 68dede3 | 2010-08-04 10:28:46 +0100 | [diff] [blame] | 154 | |
| 155 | // This is asynchronous, but it gets processed by WebCore before it starts loading pages. |
| 156 | mWebView.useMockDeviceOrientation(); |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 157 | } |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 158 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 159 | @Override |
| 160 | protected void onNewIntent(Intent intent) { |
| 161 | super.onNewIntent(intent); |
| 162 | executeIntent(intent); |
| 163 | } |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 164 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 165 | private void executeIntent(Intent intent) { |
| 166 | resetTestStatus(); |
| 167 | if (!Intent.ACTION_VIEW.equals(intent.getAction())) { |
| 168 | return; |
| 169 | } |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 170 | |
Ben Murdoch | 9b815d0 | 2010-06-01 18:45:10 +0100 | [diff] [blame] | 171 | mTotalTestCount = intent.getIntExtra(TOTAL_TEST_COUNT, mTotalTestCount); |
| 172 | mCurrentTestNumber = intent.getIntExtra(CURRENT_TEST_NUMBER, mCurrentTestNumber); |
| 173 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 174 | mTestUrl = intent.getStringExtra(TEST_URL); |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 175 | if (mTestUrl == null) { |
| 176 | mUiAutoTestPath = intent.getStringExtra(UI_AUTO_TEST); |
| 177 | if(mUiAutoTestPath != null) { |
| 178 | beginUiAutoTest(); |
| 179 | } |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 180 | return; |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 181 | } |
| 182 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 183 | mResultFile = intent.getStringExtra(RESULT_FILE); |
| 184 | mTimeoutInMillis = intent.getIntExtra(TIMEOUT_IN_MILLIS, 0); |
Guang Zhu | 5dc4f21 | 2009-10-29 18:24:54 -0700 | [diff] [blame] | 185 | mGetDrawtime = intent.getBooleanExtra(GET_DRAW_TIME, false); |
| 186 | mSaveImagePath = intent.getStringExtra(SAVE_IMAGE); |
Guang Zhu | 5d53c19 | 2010-07-14 17:17:54 -0700 | [diff] [blame] | 187 | mStopOnRefError = intent.getBooleanExtra(STOP_ON_REF_ERROR, false); |
Ben Murdoch | 9b815d0 | 2010-06-01 18:45:10 +0100 | [diff] [blame] | 188 | setTitle("Test " + mCurrentTestNumber + " of " + mTotalTestCount); |
| 189 | float ratio = (float)mCurrentTestNumber / mTotalTestCount; |
| 190 | int progress = (int)(ratio * Window.PROGRESS_END); |
| 191 | getWindow().setFeatureInt(Window.FEATURE_PROGRESS, progress); |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 192 | |
| 193 | Log.v(LOGTAG, " Loading " + mTestUrl); |
| 194 | mWebView.loadUrl(mTestUrl); |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 195 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 196 | if (mTimeoutInMillis > 0) { |
| 197 | // Create a timeout timer |
| 198 | Message m = mHandler.obtainMessage(MSG_TIMEOUT); |
| 199 | mHandler.sendMessageDelayed(m, mTimeoutInMillis); |
| 200 | } |
| 201 | } |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 202 | |
| 203 | private void beginUiAutoTest() { |
| 204 | try { |
| 205 | mTestListReader = new BufferedReader( |
| 206 | new FileReader(mUiAutoTestPath)); |
| 207 | } catch (IOException ioe) { |
| 208 | Log.e(LOGTAG, "Failed to open test list for read.", ioe); |
| 209 | finishUiAutoTest(); |
| 210 | return; |
| 211 | } |
| 212 | moveToNextTest(); |
| 213 | } |
| 214 | |
| 215 | private void finishUiAutoTest() { |
| 216 | try { |
| 217 | if(mTestListReader != null) |
| 218 | mTestListReader.close(); |
| 219 | } catch (IOException ioe) { |
| 220 | Log.w(LOGTAG, "Failed to close test list file.", ioe); |
| 221 | } |
Guang Zhu | 6bf18ba | 2009-09-15 23:47:20 -0700 | [diff] [blame] | 222 | ForwardService.getForwardService().stopForwardService(); |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 223 | finished(); |
| 224 | } |
| 225 | |
| 226 | private void moveToNextTest() { |
| 227 | String url = null; |
| 228 | try { |
| 229 | url = mTestListReader.readLine(); |
| 230 | } catch (IOException ioe) { |
| 231 | Log.e(LOGTAG, "Failed to read next test.", ioe); |
| 232 | finishUiAutoTest(); |
| 233 | return; |
| 234 | } |
| 235 | if (url == null) { |
| 236 | mUiAutoTestPath = null; |
| 237 | finishUiAutoTest(); |
| 238 | AlertDialog.Builder builder = new AlertDialog.Builder(this); |
| 239 | builder.setMessage("All tests finished. Exit?") |
| 240 | .setCancelable(false) |
| 241 | .setPositiveButton("Yes", new OnClickListener(){ |
| 242 | public void onClick(DialogInterface dialog, int which) { |
| 243 | TestShellActivity.this.finish(); |
| 244 | } |
| 245 | }) |
| 246 | .setNegativeButton("No", new OnClickListener(){ |
| 247 | public void onClick(DialogInterface dialog, int which) { |
| 248 | dialog.cancel(); |
| 249 | } |
| 250 | }); |
| 251 | builder.create().show(); |
| 252 | return; |
| 253 | } |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 254 | Intent intent = new Intent(Intent.ACTION_VIEW); |
| 255 | intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); |
Guang Zhu | 6bf18ba | 2009-09-15 23:47:20 -0700 | [diff] [blame] | 256 | intent.putExtra(TestShellActivity.TEST_URL, FsUtils.getTestUrl(url)); |
Ben Murdoch | 9b815d0 | 2010-06-01 18:45:10 +0100 | [diff] [blame] | 257 | intent.putExtra(TestShellActivity.CURRENT_TEST_NUMBER, ++mCurrentTestNumber); |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 258 | intent.putExtra(TIMEOUT_IN_MILLIS, 10000); |
| 259 | executeIntent(intent); |
| 260 | } |
| 261 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 262 | @Override |
| 263 | protected void onStop() { |
| 264 | super.onStop(); |
| 265 | mWebView.stopLoading(); |
| 266 | } |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 267 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 268 | @Override |
| 269 | protected void onDestroy() { |
| 270 | super.onDestroy(); |
| 271 | mWebView.destroy(); |
| 272 | mWebView = null; |
| 273 | } |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 274 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 275 | @Override |
| 276 | public void onLowMemory() { |
| 277 | super.onLowMemory(); |
Feng Qian | 0aeed6a | 2009-07-16 20:53:31 -0700 | [diff] [blame] | 278 | Log.e(LOGTAG, "Low memory, clearing caches"); |
| 279 | mWebView.freeMemory(); |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | // Dump the page |
| 283 | public void dump(boolean timeout, String webkitData) { |
Ben Murdoch | 2eea5f3 | 2009-09-23 15:28:57 +0100 | [diff] [blame] | 284 | mDumpWebKitData = true; |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 285 | if (mResultFile == null || mResultFile.length() == 0) { |
| 286 | finished(); |
| 287 | return; |
| 288 | } |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 289 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 290 | try { |
| 291 | File parentDir = new File(mResultFile).getParentFile(); |
| 292 | if (!parentDir.exists()) { |
| 293 | parentDir.mkdirs(); |
| 294 | } |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 295 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 296 | FileOutputStream os = new FileOutputStream(mResultFile); |
| 297 | if (timeout) { |
| 298 | Log.w("Layout test: Timeout", mResultFile); |
| 299 | os.write(TIMEOUT_STR.getBytes()); |
| 300 | os.write('\n'); |
| 301 | } |
| 302 | if (mDumpTitleChanges) |
| 303 | os.write(mTitleChanges.toString().getBytes()); |
| 304 | if (mDialogStrings != null) |
| 305 | os.write(mDialogStrings.toString().getBytes()); |
| 306 | mDialogStrings = null; |
Ben Murdoch | e6f3e45 | 2009-04-22 16:02:31 +0100 | [diff] [blame] | 307 | if (mDatabaseCallbackStrings != null) |
| 308 | os.write(mDatabaseCallbackStrings.toString().getBytes()); |
| 309 | mDatabaseCallbackStrings = null; |
| 310 | if (mConsoleMessages != null) |
| 311 | os.write(mConsoleMessages.toString().getBytes()); |
| 312 | mConsoleMessages = null; |
Feng Qian | be42388b | 2009-04-16 10:05:38 -0700 | [diff] [blame] | 313 | if (webkitData != null) |
| 314 | os.write(webkitData.getBytes()); |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 315 | os.flush(); |
| 316 | os.close(); |
| 317 | } catch (IOException ex) { |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 318 | Log.e(LOGTAG, "Cannot write to " + mResultFile + ", " + ex.getMessage()); |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | finished(); |
| 322 | } |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 323 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 324 | public void setCallback(TestShellCallback callback) { |
| 325 | mCallback = callback; |
| 326 | } |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 327 | |
Ben Murdoch | 2eea5f3 | 2009-09-23 15:28:57 +0100 | [diff] [blame] | 328 | public boolean finished() { |
| 329 | if (canMoveToNextTest()) { |
| 330 | mHandler.removeMessages(MSG_TIMEOUT); |
Ben Murdoch | 977f769 | 2009-09-16 20:13:07 +0100 | [diff] [blame] | 331 | if (mUiAutoTestPath != null) { |
| 332 | //don't really finish here |
| 333 | moveToNextTest(); |
| 334 | } else { |
| 335 | if (mCallback != null) { |
| 336 | mCallback.finished(); |
| 337 | } |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 338 | } |
Ben Murdoch | 2eea5f3 | 2009-09-23 15:28:57 +0100 | [diff] [blame] | 339 | return true; |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 340 | } |
Ben Murdoch | 2eea5f3 | 2009-09-23 15:28:57 +0100 | [diff] [blame] | 341 | return false; |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 342 | } |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 343 | |
Guang Zhu | 1871fe0 | 2009-04-29 14:49:03 -0700 | [diff] [blame] | 344 | public void setDefaultDumpDataType(DumpDataType defaultDumpDataType) { |
| 345 | mDefaultDumpDataType = defaultDumpDataType; |
| 346 | } |
| 347 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 348 | // ....................................... |
| 349 | // LayoutTestController Functions |
Ben Murdoch | 357d280 | 2010-07-23 16:18:58 +0100 | [diff] [blame] | 350 | public void dumpAsText(boolean enablePixelTests) { |
| 351 | // Added after webkit update to r63859. See trac.webkit.org/changeset/63730. |
| 352 | if (enablePixelTests) { |
| 353 | Log.v(LOGTAG, "dumpAsText(enablePixelTests == true) not implemented on Android!"); |
| 354 | } |
| 355 | |
Guang Zhu | 1871fe0 | 2009-04-29 14:49:03 -0700 | [diff] [blame] | 356 | mDumpDataType = DumpDataType.DUMP_AS_TEXT; |
Shimeng (Simon) Wang | ad45686 | 2010-06-16 17:32:24 -0700 | [diff] [blame] | 357 | mDumpTopFrameAsText = true; |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 358 | if (mWebView != null) { |
| 359 | String url = mWebView.getUrl(); |
| 360 | Log.v(LOGTAG, "dumpAsText called: "+url); |
| 361 | } |
| 362 | } |
| 363 | |
Shimeng (Simon) Wang | ad45686 | 2010-06-16 17:32:24 -0700 | [diff] [blame] | 364 | public void dumpChildFramesAsText() { |
| 365 | mDumpDataType = DumpDataType.DUMP_AS_TEXT; |
| 366 | mDumpChildFramesAsText = true; |
| 367 | if (mWebView != null) { |
| 368 | String url = mWebView.getUrl(); |
| 369 | Log.v(LOGTAG, "dumpChildFramesAsText called: "+url); |
| 370 | } |
| 371 | } |
| 372 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 373 | public void waitUntilDone() { |
| 374 | mWaitUntilDone = true; |
| 375 | String url = mWebView.getUrl(); |
| 376 | Log.v(LOGTAG, "waitUntilDone called: " + url); |
| 377 | } |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 378 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 379 | public void notifyDone() { |
| 380 | String url = mWebView.getUrl(); |
| 381 | Log.v(LOGTAG, "notifyDone called: " + url); |
| 382 | if (mWaitUntilDone) { |
| 383 | mWaitUntilDone = false; |
Ben Murdoch | 1620bcd | 2010-06-03 11:51:54 +0100 | [diff] [blame] | 384 | if (!mRequestedWebKitData && !mTimedOut && !finished()) { |
| 385 | requestWebKitData(); |
| 386 | } |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 387 | } |
| 388 | } |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 389 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 390 | public void display() { |
| 391 | mWebView.invalidate(); |
| 392 | } |
| 393 | |
| 394 | public void clearBackForwardList() { |
| 395 | mWebView.clearHistory(); |
| 396 | |
| 397 | } |
| 398 | |
| 399 | public void dumpBackForwardList() { |
| 400 | //printf("\n============== Back Forward List ==============\n"); |
| 401 | // mWebHistory |
| 402 | //printf("===============================================\n"); |
| 403 | |
| 404 | } |
| 405 | |
| 406 | public void dumpChildFrameScrollPositions() { |
| 407 | // TODO Auto-generated method stub |
| 408 | |
| 409 | } |
| 410 | |
| 411 | public void dumpEditingCallbacks() { |
| 412 | // TODO Auto-generated method stub |
| 413 | |
| 414 | } |
| 415 | |
| 416 | public void dumpSelectionRect() { |
| 417 | // TODO Auto-generated method stub |
| 418 | |
| 419 | } |
| 420 | |
| 421 | public void dumpTitleChanges() { |
| 422 | if (!mDumpTitleChanges) { |
| 423 | mTitleChanges = new StringBuffer(); |
| 424 | } |
| 425 | mDumpTitleChanges = true; |
| 426 | } |
| 427 | |
| 428 | public void keepWebHistory() { |
| 429 | if (!mKeepWebHistory) { |
| 430 | mWebHistory = new Vector(); |
| 431 | } |
| 432 | mKeepWebHistory = true; |
| 433 | } |
| 434 | |
| 435 | public void queueBackNavigation(int howfar) { |
| 436 | // TODO Auto-generated method stub |
| 437 | |
| 438 | } |
| 439 | |
| 440 | public void queueForwardNavigation(int howfar) { |
| 441 | // TODO Auto-generated method stub |
| 442 | |
| 443 | } |
| 444 | |
| 445 | public void queueLoad(String Url, String frameTarget) { |
| 446 | // TODO Auto-generated method stub |
| 447 | |
| 448 | } |
| 449 | |
| 450 | public void queueReload() { |
| 451 | mWebView.reload(); |
| 452 | } |
| 453 | |
| 454 | public void queueScript(String scriptToRunInCurrentContext) { |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 455 | mWebView.loadUrl("javascript:"+scriptToRunInCurrentContext); |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | public void repaintSweepHorizontally() { |
| 459 | // TODO Auto-generated method stub |
| 460 | |
| 461 | } |
| 462 | |
| 463 | public void setAcceptsEditing(boolean b) { |
| 464 | // TODO Auto-generated method stub |
| 465 | |
| 466 | } |
| 467 | |
| 468 | public void setMainFrameIsFirstResponder(boolean b) { |
| 469 | // TODO Auto-generated method stub |
| 470 | |
| 471 | } |
| 472 | |
| 473 | public void setWindowIsKey(boolean b) { |
| 474 | // This is meant to show/hide the window. The best I can find |
| 475 | // is setEnabled() |
| 476 | mWebView.setEnabled(b); |
| 477 | } |
| 478 | |
| 479 | public void testRepaint() { |
| 480 | mWebView.invalidate(); |
| 481 | } |
Ben Murdoch | e6f3e45 | 2009-04-22 16:02:31 +0100 | [diff] [blame] | 482 | |
| 483 | public void dumpDatabaseCallbacks() { |
| 484 | Log.v(LOGTAG, "dumpDatabaseCallbacks called."); |
| 485 | mDumpDatabaseCallbacks = true; |
| 486 | } |
| 487 | |
| 488 | public void setCanOpenWindows() { |
| 489 | Log.v(LOGTAG, "setCanOpenWindows called."); |
| 490 | mCanOpenWindows = true; |
| 491 | } |
| 492 | |
Steve Block | dad347c | 2009-08-19 18:46:34 +0100 | [diff] [blame] | 493 | /** |
| 494 | * Sets the Geolocation permission state to be used for all future requests. |
| 495 | */ |
| 496 | public void setGeolocationPermission(boolean allow) { |
Steve Block | f0f30c6 | 2010-08-18 15:15:42 +0100 | [diff] [blame] | 497 | mIsGeolocationPermissionSet = true; |
Steve Block | dad347c | 2009-08-19 18:46:34 +0100 | [diff] [blame] | 498 | mGeolocationPermission = allow; |
Steve Block | f0f30c6 | 2010-08-18 15:15:42 +0100 | [diff] [blame] | 499 | |
| 500 | if (mPendingGeolocationPermissionCallbacks != null) { |
| 501 | Iterator iter = mPendingGeolocationPermissionCallbacks.keySet().iterator(); |
| 502 | while (iter.hasNext()) { |
| 503 | GeolocationPermissions.Callback callback = |
| 504 | (GeolocationPermissions.Callback) iter.next(); |
| 505 | String origin = (String) mPendingGeolocationPermissionCallbacks.get(callback); |
| 506 | callback.invoke(origin, mGeolocationPermission, false); |
| 507 | } |
| 508 | mPendingGeolocationPermissionCallbacks = null; |
| 509 | } |
Steve Block | dad347c | 2009-08-19 18:46:34 +0100 | [diff] [blame] | 510 | } |
| 511 | |
Steve Block | 68dede3 | 2010-08-04 10:28:46 +0100 | [diff] [blame] | 512 | public void setMockDeviceOrientation(boolean canProvideAlpha, double alpha, |
| 513 | boolean canProvideBeta, double beta, boolean canProvideGamma, double gamma) { |
| 514 | mWebView.setMockDeviceOrientation(canProvideAlpha, alpha, canProvideBeta, beta, |
| 515 | canProvideGamma, gamma); |
| 516 | } |
| 517 | |
Steve Block | fb0de34 | 2010-03-19 18:48:35 +0000 | [diff] [blame] | 518 | public void overridePreference(String key, boolean value) { |
| 519 | // TODO: We should look up the correct WebView for the frame which |
| 520 | // called the layoutTestController method. Currently, we just use the |
| 521 | // WebView for the main frame. EventSender suffers from the same |
| 522 | // problem. |
| 523 | if (key.equals(WEBKIT_OFFLINE_WEB_APPLICATION_CACHE_ENABLED)) { |
| 524 | mWebView.getSettings().setAppCacheEnabled(value); |
| 525 | } |
| 526 | } |
| 527 | |
Elliott Slaughter | 5dc0c82 | 2010-06-22 11:31:54 -0700 | [diff] [blame] | 528 | public void setXSSAuditorEnabled (boolean flag) { |
| 529 | mWebView.getSettings().setXSSAuditorEnabled(flag); |
| 530 | } |
| 531 | |
Ben Murdoch | e6f3e45 | 2009-04-22 16:02:31 +0100 | [diff] [blame] | 532 | private final WebViewClient mViewClient = new WebViewClient(){ |
| 533 | @Override |
| 534 | public void onPageFinished(WebView view, String url) { |
| 535 | Log.v(LOGTAG, "onPageFinished, url=" + url); |
Ben Murdoch | 2eea5f3 | 2009-09-23 15:28:57 +0100 | [diff] [blame] | 536 | mPageFinished = true; |
Guang Zhu | 5dc4f21 | 2009-10-29 18:24:54 -0700 | [diff] [blame] | 537 | // get page draw time |
| 538 | if (FsUtils.isTestPageUrl(url)) { |
| 539 | if (mGetDrawtime) { |
| 540 | long[] times = new long[DRAW_RUNS]; |
| 541 | times = getDrawWebViewTime(mWebView, DRAW_RUNS); |
| 542 | FsUtils.writeDrawTime(DRAW_TIME_LOG, url, times); |
| 543 | } |
| 544 | if (mSaveImagePath != null) { |
| 545 | String name = FsUtils.getLastSegmentInPath(url); |
| 546 | drawPageToFile(mSaveImagePath + "/" + name + ".png", mWebView); |
| 547 | } |
| 548 | } |
Ben Murdoch | 1620bcd | 2010-06-03 11:51:54 +0100 | [diff] [blame] | 549 | |
Ben Murdoch | 2eea5f3 | 2009-09-23 15:28:57 +0100 | [diff] [blame] | 550 | // Calling finished() will check if we've met all the conditions for completing |
Ben Murdoch | 1620bcd | 2010-06-03 11:51:54 +0100 | [diff] [blame] | 551 | // this test and move to the next one if we are ready. Otherwise we ask WebCore to |
| 552 | // dump the page. |
Ben Murdoch | 2eea5f3 | 2009-09-23 15:28:57 +0100 | [diff] [blame] | 553 | if (finished()) { |
| 554 | return; |
| 555 | } |
Ben Murdoch | 1620bcd | 2010-06-03 11:51:54 +0100 | [diff] [blame] | 556 | |
| 557 | if (!mWaitUntilDone && !mRequestedWebKitData && !mTimedOut) { |
| 558 | requestWebKitData(); |
| 559 | } else { |
| 560 | if (mWaitUntilDone) { |
| 561 | Log.v(LOGTAG, "page finished loading but waiting for notifyDone to be called: " + url); |
| 562 | } |
| 563 | |
| 564 | if (mRequestedWebKitData) { |
| 565 | Log.v(LOGTAG, "page finished loading but webkit data has already been requested: " + url); |
| 566 | } |
| 567 | |
| 568 | if (mTimedOut) { |
| 569 | Log.v(LOGTAG, "page finished loading but already timed out: " + url); |
| 570 | } |
| 571 | } |
| 572 | |
Ben Murdoch | e6f3e45 | 2009-04-22 16:02:31 +0100 | [diff] [blame] | 573 | super.onPageFinished(view, url); |
| 574 | } |
| 575 | |
| 576 | @Override |
| 577 | public void onPageStarted(WebView view, String url, Bitmap favicon) { |
| 578 | Log.v(LOGTAG, "onPageStarted, url=" + url); |
Ben Murdoch | 2eea5f3 | 2009-09-23 15:28:57 +0100 | [diff] [blame] | 579 | mPageFinished = false; |
Ben Murdoch | e6f3e45 | 2009-04-22 16:02:31 +0100 | [diff] [blame] | 580 | super.onPageStarted(view, url, favicon); |
| 581 | } |
| 582 | |
| 583 | @Override |
| 584 | public void onReceivedError(WebView view, int errorCode, String description, |
| 585 | String failingUrl) { |
| 586 | Log.v(LOGTAG, "onReceivedError, errorCode=" + errorCode |
| 587 | + ", desc=" + description + ", url=" + failingUrl); |
| 588 | super.onReceivedError(view, errorCode, description, failingUrl); |
| 589 | } |
| 590 | |
| 591 | @Override |
| 592 | public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, |
| 593 | String host, String realm) { |
Steve Block | 2bb2553 | 2010-03-25 14:48:13 +0000 | [diff] [blame] | 594 | if (handler.useHttpAuthUsernamePassword() && view != null) { |
| 595 | String[] credentials = view.getHttpAuthUsernamePassword(host, realm); |
| 596 | if (credentials != null && credentials.length == 2) { |
| 597 | handler.proceed(credentials[0], credentials[1]); |
| 598 | return; |
| 599 | } |
| 600 | } |
Ben Murdoch | e6f3e45 | 2009-04-22 16:02:31 +0100 | [diff] [blame] | 601 | handler.cancel(); |
| 602 | } |
| 603 | |
| 604 | @Override |
| 605 | public void onReceivedSslError(WebView view, SslErrorHandler handler, |
| 606 | SslError error) { |
| 607 | handler.proceed(); |
| 608 | } |
| 609 | }; |
| 610 | |
| 611 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 612 | private final WebChromeClient mChromeClient = new WebChromeClient() { |
| 613 | @Override |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 614 | public void onReceivedTitle(WebView view, String title) { |
Ben Murdoch | 9b815d0 | 2010-06-01 18:45:10 +0100 | [diff] [blame] | 615 | setTitle("Test " + mCurrentTestNumber + " of " + mTotalTestCount + ": "+ title); |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 616 | if (mDumpTitleChanges) { |
| 617 | mTitleChanges.append("TITLE CHANGED: "); |
| 618 | mTitleChanges.append(title); |
| 619 | mTitleChanges.append("\n"); |
| 620 | } |
| 621 | } |
| 622 | |
| 623 | @Override |
| 624 | public boolean onJsAlert(WebView view, String url, String message, |
| 625 | JsResult result) { |
| 626 | if (mDialogStrings == null) { |
| 627 | mDialogStrings = new StringBuffer(); |
| 628 | } |
| 629 | mDialogStrings.append("ALERT: "); |
| 630 | mDialogStrings.append(message); |
| 631 | mDialogStrings.append('\n'); |
| 632 | result.confirm(); |
| 633 | return true; |
| 634 | } |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 635 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 636 | @Override |
| 637 | public boolean onJsConfirm(WebView view, String url, String message, |
| 638 | JsResult result) { |
| 639 | if (mDialogStrings == null) { |
| 640 | mDialogStrings = new StringBuffer(); |
| 641 | } |
| 642 | mDialogStrings.append("CONFIRM: "); |
| 643 | mDialogStrings.append(message); |
| 644 | mDialogStrings.append('\n'); |
| 645 | result.confirm(); |
| 646 | return true; |
| 647 | } |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 648 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 649 | @Override |
| 650 | public boolean onJsPrompt(WebView view, String url, String message, |
| 651 | String defaultValue, JsPromptResult result) { |
| 652 | if (mDialogStrings == null) { |
| 653 | mDialogStrings = new StringBuffer(); |
| 654 | } |
| 655 | mDialogStrings.append("PROMPT: "); |
| 656 | mDialogStrings.append(message); |
| 657 | mDialogStrings.append(", default text: "); |
| 658 | mDialogStrings.append(defaultValue); |
| 659 | mDialogStrings.append('\n'); |
| 660 | result.confirm(); |
| 661 | return true; |
| 662 | } |
Ben Murdoch | e6f3e45 | 2009-04-22 16:02:31 +0100 | [diff] [blame] | 663 | |
| 664 | @Override |
Guang Zhu | f4bf552 | 2009-07-23 14:19:35 -0700 | [diff] [blame] | 665 | public boolean onJsTimeout() { |
| 666 | Log.v(LOGTAG, "JavaScript timeout"); |
| 667 | return false; |
| 668 | } |
| 669 | |
| 670 | @Override |
Ben Murdoch | e6f3e45 | 2009-04-22 16:02:31 +0100 | [diff] [blame] | 671 | public void onExceededDatabaseQuota(String url_str, |
Ben Murdoch | d497d87 | 2009-08-25 19:32:54 +0100 | [diff] [blame] | 672 | String databaseIdentifier, long currentQuota, |
| 673 | long estimatedSize, long totalUsedQuota, |
Ben Murdoch | e6f3e45 | 2009-04-22 16:02:31 +0100 | [diff] [blame] | 674 | WebStorage.QuotaUpdater callback) { |
| 675 | if (mDumpDatabaseCallbacks) { |
| 676 | if (mDatabaseCallbackStrings == null) { |
| 677 | mDatabaseCallbackStrings = new StringBuffer(); |
| 678 | } |
| 679 | |
| 680 | String protocol = ""; |
| 681 | String host = ""; |
| 682 | int port = 0; |
| 683 | |
| 684 | try { |
| 685 | URL url = new URL(url_str); |
| 686 | protocol = url.getProtocol(); |
| 687 | host = url.getHost(); |
| 688 | if (url.getPort() > -1) { |
| 689 | port = url.getPort(); |
| 690 | } |
| 691 | } catch (MalformedURLException e) {} |
| 692 | |
| 693 | String databaseCallbackString = |
| 694 | "UI DELEGATE DATABASE CALLBACK: " + |
| 695 | "exceededDatabaseQuotaForSecurityOrigin:{" + protocol + |
| 696 | ", " + host + ", " + port + "} database:" + |
| 697 | databaseIdentifier + "\n"; |
| 698 | Log.v(LOGTAG, "LOG: "+databaseCallbackString); |
| 699 | mDatabaseCallbackStrings.append(databaseCallbackString); |
| 700 | } |
| 701 | // Give 5MB more quota. |
| 702 | callback.updateQuota(currentQuota + 1024 * 1024 * 5); |
| 703 | } |
| 704 | |
Steve Block | dad347c | 2009-08-19 18:46:34 +0100 | [diff] [blame] | 705 | /** |
| 706 | * Instructs the client to show a prompt to ask the user to set the |
| 707 | * Geolocation permission state for the specified origin. |
| 708 | */ |
| 709 | @Override |
| 710 | public void onGeolocationPermissionsShowPrompt(String origin, |
| 711 | GeolocationPermissions.Callback callback) { |
Steve Block | f0f30c6 | 2010-08-18 15:15:42 +0100 | [diff] [blame] | 712 | if (mIsGeolocationPermissionSet) { |
Steve Block | dad347c | 2009-08-19 18:46:34 +0100 | [diff] [blame] | 713 | callback.invoke(origin, mGeolocationPermission, false); |
Steve Block | f0f30c6 | 2010-08-18 15:15:42 +0100 | [diff] [blame] | 714 | return; |
Steve Block | dad347c | 2009-08-19 18:46:34 +0100 | [diff] [blame] | 715 | } |
Steve Block | f0f30c6 | 2010-08-18 15:15:42 +0100 | [diff] [blame] | 716 | if (mPendingGeolocationPermissionCallbacks == null) { |
| 717 | mPendingGeolocationPermissionCallbacks = |
| 718 | new HashMap<GeolocationPermissions.Callback, String>(); |
| 719 | } |
| 720 | mPendingGeolocationPermissionCallbacks.put(callback, origin); |
Steve Block | dad347c | 2009-08-19 18:46:34 +0100 | [diff] [blame] | 721 | } |
| 722 | |
Ben Murdoch | e6f3e45 | 2009-04-22 16:02:31 +0100 | [diff] [blame] | 723 | @Override |
Guang Zhu | 6c15f60 | 2010-05-03 11:49:04 -0700 | [diff] [blame] | 724 | public boolean onConsoleMessage(ConsoleMessage consoleMessage) { |
| 725 | String msg = "CONSOLE MESSAGE: line " + consoleMessage.lineNumber() + ": " |
| 726 | + consoleMessage.message() + "\n"; |
Ben Murdoch | e6f3e45 | 2009-04-22 16:02:31 +0100 | [diff] [blame] | 727 | if (mConsoleMessages == null) { |
| 728 | mConsoleMessages = new StringBuffer(); |
| 729 | } |
Guang Zhu | 6c15f60 | 2010-05-03 11:49:04 -0700 | [diff] [blame] | 730 | mConsoleMessages.append(msg); |
| 731 | Log.v(LOGTAG, "LOG: " + msg); |
| 732 | // the rationale here is that if there's an error of either type, and the test was |
| 733 | // waiting for "notifyDone" signal to finish, then there's no point in waiting |
| 734 | // anymore because the JS execution is already terminated at this point and a |
| 735 | // "notifyDone" will never come out so it's just wasting time till timeout kicks in |
Guang Zhu | 5d53c19 | 2010-07-14 17:17:54 -0700 | [diff] [blame] | 736 | if ((msg.contains("Uncaught ReferenceError:") || msg.contains("Uncaught TypeError:")) |
| 737 | && mWaitUntilDone && mStopOnRefError) { |
Guang Zhu | 6c15f60 | 2010-05-03 11:49:04 -0700 | [diff] [blame] | 738 | Log.w(LOGTAG, "Terminating test case on uncaught ReferenceError or TypeError."); |
| 739 | mHandler.postDelayed(new Runnable() { |
| 740 | public void run() { |
| 741 | notifyDone(); |
| 742 | } |
| 743 | }, 500); |
| 744 | } |
| 745 | return true; |
Ben Murdoch | e6f3e45 | 2009-04-22 16:02:31 +0100 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | @Override |
| 749 | public boolean onCreateWindow(WebView view, boolean dialog, |
| 750 | boolean userGesture, Message resultMsg) { |
| 751 | if (!mCanOpenWindows) { |
Ben Murdoch | fc4a69e | 2010-02-04 16:35:10 +0000 | [diff] [blame] | 752 | // We can't open windows, so just send null back. |
| 753 | WebView.WebViewTransport transport = |
| 754 | (WebView.WebViewTransport) resultMsg.obj; |
| 755 | transport.setWebView(null); |
| 756 | resultMsg.sendToTarget(); |
| 757 | return true; |
Ben Murdoch | e6f3e45 | 2009-04-22 16:02:31 +0100 | [diff] [blame] | 758 | } |
| 759 | |
| 760 | // We never display the new window, just create the view and |
| 761 | // allow it's content to execute and be recorded by the test |
| 762 | // runner. |
| 763 | |
Andrei Popescu | 4950b2b | 2009-09-03 13:56:07 +0100 | [diff] [blame] | 764 | HashMap<String, Object> jsIfaces = new HashMap<String, Object>(); |
| 765 | jsIfaces.put("layoutTestController", mCallbackProxy); |
| 766 | jsIfaces.put("eventSender", mCallbackProxy); |
| 767 | WebView newWindowView = new NewWindowWebView(TestShellActivity.this, jsIfaces); |
Ben Murdoch | e6f3e45 | 2009-04-22 16:02:31 +0100 | [diff] [blame] | 768 | setupWebViewForLayoutTests(newWindowView, mCallbackProxy); |
| 769 | WebView.WebViewTransport transport = |
| 770 | (WebView.WebViewTransport) resultMsg.obj; |
| 771 | transport.setWebView(newWindowView); |
| 772 | resultMsg.sendToTarget(); |
| 773 | return true; |
| 774 | } |
Ben Murdoch | fc4a69e | 2010-02-04 16:35:10 +0000 | [diff] [blame] | 775 | |
| 776 | @Override |
| 777 | public void onCloseWindow(WebView view) { |
| 778 | view.destroy(); |
| 779 | } |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 780 | }; |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 781 | |
Andrei Popescu | 4950b2b | 2009-09-03 13:56:07 +0100 | [diff] [blame] | 782 | private static class NewWindowWebView extends WebView { |
| 783 | public NewWindowWebView(Context context, Map<String, Object> jsIfaces) { |
Elliott Slaughter | f21d2e3 | 2010-07-14 18:08:54 -0700 | [diff] [blame] | 784 | super(context, null, 0, jsIfaces, false); |
Andrei Popescu | 4950b2b | 2009-09-03 13:56:07 +0100 | [diff] [blame] | 785 | } |
| 786 | } |
| 787 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 788 | private void resetTestStatus() { |
| 789 | mWaitUntilDone = false; |
Guang Zhu | 1871fe0 | 2009-04-29 14:49:03 -0700 | [diff] [blame] | 790 | mDumpDataType = mDefaultDumpDataType; |
Shimeng (Simon) Wang | ad45686 | 2010-06-16 17:32:24 -0700 | [diff] [blame] | 791 | mDumpTopFrameAsText = false; |
| 792 | mDumpChildFramesAsText = false; |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 793 | mTimedOut = false; |
| 794 | mDumpTitleChanges = false; |
| 795 | mRequestedWebKitData = false; |
Ben Murdoch | e6f3e45 | 2009-04-22 16:02:31 +0100 | [diff] [blame] | 796 | mDumpDatabaseCallbacks = false; |
| 797 | mCanOpenWindows = false; |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 798 | mEventSender.resetMouse(); |
Ben Murdoch | ecbc65c | 2010-01-13 10:54:56 +0000 | [diff] [blame] | 799 | mEventSender.clearTouchPoints(); |
Ben Murdoch | 8a032a3 | 2010-02-02 18:20:11 +0000 | [diff] [blame] | 800 | mEventSender.clearTouchMetaState(); |
Ben Murdoch | 2eea5f3 | 2009-09-23 15:28:57 +0100 | [diff] [blame] | 801 | mPageFinished = false; |
Ben Murdoch | 2eea5f3 | 2009-09-23 15:28:57 +0100 | [diff] [blame] | 802 | mDumpWebKitData = false; |
Guang Zhu | 5dc4f21 | 2009-10-29 18:24:54 -0700 | [diff] [blame] | 803 | mGetDrawtime = false; |
| 804 | mSaveImagePath = null; |
Ben Murdoch | a8b9768 | 2010-04-15 12:20:48 -0700 | [diff] [blame] | 805 | setDefaultWebSettings(mWebView); |
Steve Block | f0f30c6 | 2010-08-18 15:15:42 +0100 | [diff] [blame] | 806 | mIsGeolocationPermissionSet = false; |
| 807 | mPendingGeolocationPermissionCallbacks = null; |
Guang Zhu | 5dc4f21 | 2009-10-29 18:24:54 -0700 | [diff] [blame] | 808 | } |
| 809 | |
| 810 | private long[] getDrawWebViewTime(WebView view, int count) { |
| 811 | if (count == 0) |
| 812 | return null; |
| 813 | long[] ret = new long[count]; |
| 814 | long start; |
| 815 | Canvas canvas = new Canvas(); |
| 816 | Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Config.ARGB_8888); |
| 817 | canvas.setBitmap(bitmap); |
| 818 | for (int i = 0; i < count; i++) { |
| 819 | start = System.currentTimeMillis(); |
| 820 | view.draw(canvas); |
| 821 | ret[i] = System.currentTimeMillis() - start; |
| 822 | } |
| 823 | return ret; |
| 824 | } |
| 825 | |
| 826 | private void drawPageToFile(String fileName, WebView view) { |
| 827 | Canvas canvas = new Canvas(); |
| 828 | Bitmap bitmap = Bitmap.createBitmap(view.getContentWidth(), view.getContentHeight(), |
| 829 | Config.ARGB_8888); |
| 830 | canvas.setBitmap(bitmap); |
| 831 | view.drawPage(canvas); |
| 832 | try { |
| 833 | FileOutputStream fos = new FileOutputStream(fileName); |
| 834 | if(!bitmap.compress(CompressFormat.PNG, 90, fos)) { |
| 835 | Log.w(LOGTAG, "Failed to compress and save image."); |
| 836 | } |
| 837 | } catch (IOException ioe) { |
| 838 | Log.e(LOGTAG, "", ioe); |
| 839 | } |
| 840 | bitmap.recycle(); |
Ben Murdoch | 2eea5f3 | 2009-09-23 15:28:57 +0100 | [diff] [blame] | 841 | } |
| 842 | |
| 843 | private boolean canMoveToNextTest() { |
Ben Murdoch | 1620bcd | 2010-06-03 11:51:54 +0100 | [diff] [blame] | 844 | return (mDumpWebKitData && mPageFinished && !mWaitUntilDone) || mTimedOut; |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 845 | } |
Ben Murdoch | e6f3e45 | 2009-04-22 16:02:31 +0100 | [diff] [blame] | 846 | |
| 847 | private void setupWebViewForLayoutTests(WebView webview, CallbackProxy callbackProxy) { |
| 848 | if (webview == null) { |
| 849 | return; |
| 850 | } |
| 851 | |
Ben Murdoch | a8b9768 | 2010-04-15 12:20:48 -0700 | [diff] [blame] | 852 | setDefaultWebSettings(webview); |
| 853 | |
| 854 | webview.setWebChromeClient(mChromeClient); |
| 855 | webview.setWebViewClient(mViewClient); |
| 856 | // Setting a touch interval of -1 effectively disables the optimisation in WebView |
| 857 | // that stops repeated touch events flooding WebCore. The Event Sender only sends a |
| 858 | // single event rather than a stream of events (like what would generally happen in |
| 859 | // a real use of touch events in a WebView) and so if the WebView drops the event, |
| 860 | // the test will fail as the test expects one callback for every touch it synthesizes. |
| 861 | webview.setTouchInterval(-1); |
| 862 | } |
| 863 | |
| 864 | public void setDefaultWebSettings(WebView webview) { |
Ben Murdoch | e6f3e45 | 2009-04-22 16:02:31 +0100 | [diff] [blame] | 865 | WebSettings settings = webview.getSettings(); |
Guang Zhu | f4bf552 | 2009-07-23 14:19:35 -0700 | [diff] [blame] | 866 | settings.setAppCacheEnabled(true); |
| 867 | settings.setAppCachePath(getApplicationContext().getCacheDir().getPath()); |
| 868 | settings.setAppCacheMaxSize(Long.MAX_VALUE); |
Ben Murdoch | e6f3e45 | 2009-04-22 16:02:31 +0100 | [diff] [blame] | 869 | settings.setJavaScriptEnabled(true); |
| 870 | settings.setJavaScriptCanOpenWindowsAutomatically(true); |
| 871 | settings.setSupportMultipleWindows(true); |
| 872 | settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL); |
| 873 | settings.setDatabaseEnabled(true); |
| 874 | settings.setDatabasePath(getDir("databases",0).getAbsolutePath()); |
| 875 | settings.setDomStorageEnabled(true); |
Guang Zhu | b028f92 | 2009-08-11 14:27:32 -0700 | [diff] [blame] | 876 | settings.setWorkersEnabled(false); |
Elliott Slaughter | be1304f | 2010-06-23 11:29:02 -0700 | [diff] [blame] | 877 | settings.setXSSAuditorEnabled(false); |
Ben Murdoch | e6f3e45 | 2009-04-22 16:02:31 +0100 | [diff] [blame] | 878 | } |
| 879 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 880 | private WebView mWebView; |
| 881 | private WebViewEventSender mEventSender; |
| 882 | private AsyncHandler mHandler; |
| 883 | private TestShellCallback mCallback; |
| 884 | |
| 885 | private CallbackProxy mCallbackProxy; |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 886 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 887 | private String mTestUrl; |
| 888 | private String mResultFile; |
| 889 | private int mTimeoutInMillis; |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 890 | private String mUiAutoTestPath; |
Guang Zhu | 5dc4f21 | 2009-10-29 18:24:54 -0700 | [diff] [blame] | 891 | private String mSaveImagePath; |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 892 | private BufferedReader mTestListReader; |
Guang Zhu | 5dc4f21 | 2009-10-29 18:24:54 -0700 | [diff] [blame] | 893 | private boolean mGetDrawtime; |
Ben Murdoch | 9b815d0 | 2010-06-01 18:45:10 +0100 | [diff] [blame] | 894 | private int mTotalTestCount; |
| 895 | private int mCurrentTestNumber; |
Guang Zhu | 5d53c19 | 2010-07-14 17:17:54 -0700 | [diff] [blame] | 896 | private boolean mStopOnRefError; |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 897 | |
| 898 | // States |
| 899 | private boolean mTimedOut; |
| 900 | private boolean mRequestedWebKitData; |
| 901 | private boolean mFinishedRunning; |
| 902 | |
| 903 | // Layout test controller variables. |
Guang Zhu | 1871fe0 | 2009-04-29 14:49:03 -0700 | [diff] [blame] | 904 | private DumpDataType mDumpDataType; |
| 905 | private DumpDataType mDefaultDumpDataType = DumpDataType.EXT_REPR; |
Shimeng (Simon) Wang | ad45686 | 2010-06-16 17:32:24 -0700 | [diff] [blame] | 906 | private boolean mDumpTopFrameAsText; |
| 907 | private boolean mDumpChildFramesAsText; |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 908 | private boolean mWaitUntilDone; |
| 909 | private boolean mDumpTitleChanges; |
| 910 | private StringBuffer mTitleChanges; |
| 911 | private StringBuffer mDialogStrings; |
| 912 | private boolean mKeepWebHistory; |
| 913 | private Vector mWebHistory; |
Ben Murdoch | e6f3e45 | 2009-04-22 16:02:31 +0100 | [diff] [blame] | 914 | private boolean mDumpDatabaseCallbacks; |
| 915 | private StringBuffer mDatabaseCallbackStrings; |
| 916 | private StringBuffer mConsoleMessages; |
| 917 | private boolean mCanOpenWindows; |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 918 | |
Ben Murdoch | 2eea5f3 | 2009-09-23 15:28:57 +0100 | [diff] [blame] | 919 | private boolean mPageFinished = false; |
| 920 | private boolean mDumpWebKitData = false; |
Ben Murdoch | 977f769 | 2009-09-16 20:13:07 +0100 | [diff] [blame] | 921 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 922 | static final String TIMEOUT_STR = "**Test timeout"; |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 923 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 924 | static final int MSG_TIMEOUT = 0; |
| 925 | static final int MSG_WEBKIT_DATA = 1; |
| 926 | |
| 927 | static final String LOGTAG="TestShell"; |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 928 | |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 929 | static final String TEST_URL = "TestUrl"; |
| 930 | static final String RESULT_FILE = "ResultFile"; |
| 931 | static final String TIMEOUT_IN_MILLIS = "TimeoutInMillis"; |
Guang Zhu | f92bd42 | 2009-06-29 10:40:55 -0700 | [diff] [blame] | 932 | static final String UI_AUTO_TEST = "UiAutoTest"; |
Guang Zhu | 5dc4f21 | 2009-10-29 18:24:54 -0700 | [diff] [blame] | 933 | static final String GET_DRAW_TIME = "GetDrawTime"; |
| 934 | static final String SAVE_IMAGE = "SaveImage"; |
Ben Murdoch | 9b815d0 | 2010-06-01 18:45:10 +0100 | [diff] [blame] | 935 | static final String TOTAL_TEST_COUNT = "TestCount"; |
| 936 | static final String CURRENT_TEST_NUMBER = "TestNumber"; |
Guang Zhu | 5d53c19 | 2010-07-14 17:17:54 -0700 | [diff] [blame] | 937 | static final String STOP_ON_REF_ERROR = "StopOnReferenceError"; |
Guang Zhu | 5dc4f21 | 2009-10-29 18:24:54 -0700 | [diff] [blame] | 938 | |
| 939 | static final int DRAW_RUNS = 5; |
Christian Mehlmauer | 8b85dce | 2010-07-19 20:11:27 +0200 | [diff] [blame] | 940 | static final String DRAW_TIME_LOG = Environment.getExternalStorageDirectory() + |
| 941 | "/android/page_draw_time.txt"; |
Steve Block | dad347c | 2009-08-19 18:46:34 +0100 | [diff] [blame] | 942 | |
Steve Block | f0f30c6 | 2010-08-18 15:15:42 +0100 | [diff] [blame] | 943 | private boolean mIsGeolocationPermissionSet; |
Steve Block | dad347c | 2009-08-19 18:46:34 +0100 | [diff] [blame] | 944 | private boolean mGeolocationPermission; |
Steve Block | f0f30c6 | 2010-08-18 15:15:42 +0100 | [diff] [blame] | 945 | private Map mPendingGeolocationPermissionCallbacks; |
The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 946 | } |