LayoutTestsExecutor.java revision 41865f4b0c5670369bf957ad72a867757fc6b356
1/* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.dumprendertree2; 18 19import android.app.Activity; 20import android.content.ComponentName; 21import android.content.Context; 22import android.content.Intent; 23import android.content.ServiceConnection; 24import android.net.Uri; 25import android.net.http.SslError; 26import android.os.Bundle; 27import android.os.Environment; 28import android.os.Handler; 29import android.os.IBinder; 30import android.os.Message; 31import android.os.Messenger; 32import android.os.PowerManager; 33import android.os.Process; 34import android.os.PowerManager.WakeLock; 35import android.os.RemoteException; 36import android.util.Log; 37import android.view.Window; 38import android.webkit.ConsoleMessage; 39import android.webkit.GeolocationPermissions; 40import android.webkit.HttpAuthHandler; 41import android.webkit.JsPromptResult; 42import android.webkit.JsResult; 43import android.webkit.SslErrorHandler; 44import android.webkit.WebChromeClient; 45import android.webkit.WebSettings; 46import android.webkit.WebStorage; 47import android.webkit.WebStorage.QuotaUpdater; 48import android.webkit.WebView; 49import android.webkit.WebViewClient; 50 51import java.io.File; 52import java.lang.Thread.UncaughtExceptionHandler; 53import java.net.MalformedURLException; 54import java.net.URL; 55import java.util.HashMap; 56import java.util.Iterator; 57import java.util.List; 58import java.util.Map; 59 60/** 61 * This activity executes the test. It contains WebView and logic of LayoutTestController 62 * functions. It runs in a separate process and sends the results of running the test 63 * to ManagerService. The reason why is to handle crashing (test that crashes brings down 64 * whole process with it). 65 */ 66public class LayoutTestsExecutor extends Activity { 67 68 private enum CurrentState { 69 IDLE, 70 RENDERING_PAGE, 71 WAITING_FOR_ASYNCHRONOUS_TEST, 72 OBTAINING_RESULT; 73 74 public boolean isRunningState() { 75 return this == CurrentState.RENDERING_PAGE || 76 this == CurrentState.WAITING_FOR_ASYNCHRONOUS_TEST; 77 } 78 } 79 80 private static final String LOG_TAG = "LayoutTestsExecutor"; 81 82 public static final String EXTRA_TESTS_LIST = "TestsList"; 83 public static final String EXTRA_TEST_INDEX = "TestIndex"; 84 85 private static final int MSG_ACTUAL_RESULT_OBTAINED = 0; 86 private static final int MSG_TEST_TIMED_OUT = 1; 87 88 private static final int DEFAULT_TIME_OUT_MS = 15 * 1000; 89 90 /** A list of tests that remain to run since last crash */ 91 private List<String> mTestsList; 92 93 /** 94 * This is a number of currently running test. It is 0-based and doesn't reset after 95 * the crash. Initial index is passed to LayoutTestsExecuter in the intent that starts 96 * it. 97 */ 98 private int mCurrentTestIndex; 99 100 /** The total number of tests to run, doesn't reset after crash */ 101 private int mTotalTestCount; 102 103 private WebView mCurrentWebView; 104 private String mCurrentTestRelativePath; 105 private String mCurrentTestUri; 106 private CurrentState mCurrentState = CurrentState.IDLE; 107 108 private boolean mCurrentTestTimedOut; 109 private AbstractResult mCurrentResult; 110 private AdditionalTextOutput mCurrentAdditionalTextOutput; 111 112 private LayoutTestController mLayoutTestController = new LayoutTestController(this); 113 private boolean mCanOpenWindows; 114 private boolean mDumpDatabaseCallbacks; 115 private boolean mIsGeolocationPermissionSet; 116 private boolean mGeolocationPermission; 117 private Map<GeolocationPermissions.Callback, String> mPendingGeolocationPermissionCallbacks; 118 119 private EventSender mEventSender = new EventSender(); 120 121 private WakeLock mScreenDimLock; 122 123 /** COMMUNICATION WITH ManagerService */ 124 125 private Messenger mManagerServiceMessenger; 126 127 private ServiceConnection mServiceConnection = new ServiceConnection() { 128 129 @Override 130 public void onServiceConnected(ComponentName name, IBinder service) { 131 mManagerServiceMessenger = new Messenger(service); 132 startTests(); 133 } 134 135 @Override 136 public void onServiceDisconnected(ComponentName name) { 137 /** TODO */ 138 } 139 }; 140 141 private final Handler mResultHandler = new Handler() { 142 @Override 143 public void handleMessage(Message msg) { 144 switch (msg.what) { 145 case MSG_ACTUAL_RESULT_OBTAINED: 146 onActualResultsObtained(); 147 break; 148 149 case MSG_TEST_TIMED_OUT: 150 onTestTimedOut(); 151 break; 152 153 default: 154 break; 155 } 156 } 157 }; 158 159 /** WEBVIEW CONFIGURATION */ 160 161 private WebViewClient mWebViewClient = new WebViewClient() { 162 @Override 163 public void onPageFinished(WebView view, String url) { 164 /** Some tests fire up many page loads, we don't want to detect them */ 165 if (!url.equals(mCurrentTestUri)) { 166 return; 167 } 168 169 if (mCurrentState == CurrentState.RENDERING_PAGE) { 170 onTestFinished(); 171 } 172 } 173 174 @Override 175 public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, 176 String host, String realm) { 177 if (handler.useHttpAuthUsernamePassword() && view != null) { 178 String[] credentials = view.getHttpAuthUsernamePassword(host, realm); 179 if (credentials != null && credentials.length == 2) { 180 handler.proceed(credentials[0], credentials[1]); 181 return; 182 } 183 } 184 handler.cancel(); 185 } 186 187 @Override 188 public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { 189 // We ignore SSL errors. In particular, the certificate used by the LayoutTests server 190 // produces an error as it lacks a CN field. 191 handler.proceed(); 192 } 193 }; 194 195 private WebChromeClient mWebChromeClient = new WebChromeClient() { 196 @Override 197 public void onExceededDatabaseQuota(String url, String databaseIdentifier, 198 long currentQuota, long estimatedSize, long totalUsedQuota, 199 QuotaUpdater quotaUpdater) { 200 /** TODO: This should be recorded as part of the text result */ 201 /** TODO: The quota should also probably be reset somehow for every test? */ 202 if (mDumpDatabaseCallbacks) { 203 getCurrentAdditionalTextOutput().appendExceededDbQuotaMessage(url, 204 databaseIdentifier); 205 } 206 quotaUpdater.updateQuota(currentQuota + 5 * 1024 * 1024); 207 } 208 209 @Override 210 public boolean onJsAlert(WebView view, String url, String message, JsResult result) { 211 getCurrentAdditionalTextOutput().appendJsAlert(message); 212 result.confirm(); 213 return true; 214 } 215 216 @Override 217 public boolean onJsConfirm(WebView view, String url, String message, JsResult result) { 218 getCurrentAdditionalTextOutput().appendJsConfirm(message); 219 result.confirm(); 220 return true; 221 } 222 223 @Override 224 public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, 225 JsPromptResult result) { 226 getCurrentAdditionalTextOutput().appendJsPrompt(message, defaultValue); 227 result.confirm(); 228 return true; 229 } 230 231 @Override 232 public boolean onConsoleMessage(ConsoleMessage consoleMessage) { 233 getCurrentAdditionalTextOutput().appendConsoleMessage(consoleMessage); 234 return true; 235 } 236 237 @Override 238 public boolean onCreateWindow(WebView view, boolean dialog, boolean userGesture, 239 Message resultMsg) { 240 WebView.WebViewTransport transport = (WebView.WebViewTransport)resultMsg.obj; 241 /** By default windows cannot be opened, so just send null back. */ 242 WebView newWindowWebView = null; 243 244 if (mCanOpenWindows) { 245 /** 246 * We never display the new window, just create the view and allow it's content to 247 * execute and be recorded by the executor. 248 */ 249 newWindowWebView = createWebViewWithJavascriptInterfaces(); 250 setupWebView(newWindowWebView); 251 } 252 253 transport.setWebView(newWindowWebView); 254 resultMsg.sendToTarget(); 255 return true; 256 } 257 258 @Override 259 public void onGeolocationPermissionsShowPrompt(String origin, 260 GeolocationPermissions.Callback callback) { 261 if (mIsGeolocationPermissionSet) { 262 callback.invoke(origin, mGeolocationPermission, false); 263 return; 264 } 265 if (mPendingGeolocationPermissionCallbacks == null) { 266 mPendingGeolocationPermissionCallbacks = 267 new HashMap<GeolocationPermissions.Callback, String>(); 268 } 269 mPendingGeolocationPermissionCallbacks.put(callback, origin); 270 } 271 }; 272 273 /** IMPLEMENTATION */ 274 275 @Override 276 protected void onCreate(Bundle savedInstanceState) { 277 super.onCreate(savedInstanceState); 278 279 /** 280 * It detects the crash by catching all the uncaught exceptions. However, we 281 * still have to kill the process, because after catching the exception the 282 * activity remains in a strange state, where intents don't revive it. 283 * However, we send the message to the service to speed up the rebooting 284 * (we don't have to wait for time-out to kick in). 285 */ 286 Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { 287 @Override 288 public void uncaughtException(Thread thread, Throwable e) { 289 Log.w(LOG_TAG, 290 "onTestCrashed(): " + mCurrentTestRelativePath + " thread=" + thread, e); 291 292 try { 293 Message serviceMsg = 294 Message.obtain(null, ManagerService.MSG_CURRENT_TEST_CRASHED); 295 296 mManagerServiceMessenger.send(serviceMsg); 297 } catch (RemoteException e2) { 298 Log.e(LOG_TAG, "mCurrentTestRelativePath=" + mCurrentTestRelativePath, e2); 299 } 300 301 Process.killProcess(Process.myPid()); 302 } 303 }); 304 305 requestWindowFeature(Window.FEATURE_PROGRESS); 306 307 Intent intent = getIntent(); 308 mTestsList = intent.getStringArrayListExtra(EXTRA_TESTS_LIST); 309 mCurrentTestIndex = intent.getIntExtra(EXTRA_TEST_INDEX, -1); 310 mTotalTestCount = mCurrentTestIndex + mTestsList.size(); 311 312 PowerManager pm = (PowerManager)getSystemService(Context.POWER_SERVICE); 313 mScreenDimLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK 314 | PowerManager.ON_AFTER_RELEASE, "WakeLock in LayoutTester"); 315 mScreenDimLock.acquire(); 316 317 bindService(new Intent(this, ManagerService.class), mServiceConnection, 318 Context.BIND_AUTO_CREATE); 319 } 320 321 private void reset() { 322 WebView previousWebView = mCurrentWebView; 323 324 resetLayoutTestController(); 325 326 mCurrentTestTimedOut = false; 327 mCurrentResult = null; 328 mCurrentAdditionalTextOutput = null; 329 330 mCurrentWebView = createWebViewWithJavascriptInterfaces(); 331 // When we create the first WebView, we need to pause to wait for the WebView thread to spin 332 // and up and for it to register its message handlers. 333 if (previousWebView == null) { 334 try { 335 Thread.currentThread().sleep(1000); 336 } catch (Exception e) {} 337 } 338 setupWebView(mCurrentWebView); 339 340 mEventSender.reset(mCurrentWebView); 341 342 setContentView(mCurrentWebView); 343 if (previousWebView != null) { 344 Log.d(LOG_TAG + "::reset", "previousWebView != null"); 345 previousWebView.destroy(); 346 } 347 } 348 349 private static class WebViewWithJavascriptInterfaces extends WebView { 350 public WebViewWithJavascriptInterfaces( 351 Context context, Map<String, Object> javascriptInterfaces) { 352 super(context, 353 null, // attribute set 354 0, // default style resource ID 355 javascriptInterfaces, 356 false); // is private browsing 357 } 358 } 359 private WebView createWebViewWithJavascriptInterfaces() { 360 Map<String, Object> javascriptInterfaces = new HashMap<String, Object>(); 361 javascriptInterfaces.put("layoutTestController", mLayoutTestController); 362 javascriptInterfaces.put("eventSender", mEventSender); 363 return new WebViewWithJavascriptInterfaces(this, javascriptInterfaces); 364 } 365 366 private void setupWebView(WebView webView) { 367 webView.setWebViewClient(mWebViewClient); 368 webView.setWebChromeClient(mWebChromeClient); 369 370 /** 371 * Setting a touch interval of -1 effectively disables the optimisation in WebView 372 * that stops repeated touch events flooding WebCore. The Event Sender only sends a 373 * single event rather than a stream of events (like what would generally happen in 374 * a real use of touch events in a WebView) and so if the WebView drops the event, 375 * the test will fail as the test expects one callback for every touch it synthesizes. 376 */ 377 webView.setTouchInterval(-1); 378 379 webView.clearCache(true); 380 webView.setDeferMultiTouch(true); 381 382 WebSettings webViewSettings = webView.getSettings(); 383 webViewSettings.setAppCacheEnabled(true); 384 webViewSettings.setAppCachePath(getApplicationContext().getCacheDir().getPath()); 385 webViewSettings.setAppCacheMaxSize(Long.MAX_VALUE); 386 webViewSettings.setJavaScriptEnabled(true); 387 webViewSettings.setJavaScriptCanOpenWindowsAutomatically(true); 388 webViewSettings.setSupportMultipleWindows(true); 389 webViewSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL); 390 webViewSettings.setDatabaseEnabled(true); 391 webViewSettings.setDatabasePath(getDir("databases", 0).getAbsolutePath()); 392 webViewSettings.setDomStorageEnabled(true); 393 webViewSettings.setWorkersEnabled(false); 394 webViewSettings.setXSSAuditorEnabled(false); 395 396 // This is asynchronous, but it gets processed by WebCore before it starts loading pages. 397 mCurrentWebView.useMockDeviceOrientation(); 398 399 // Must do this after setting the AppCache path. 400 WebStorage.getInstance().deleteAllData(); 401 } 402 403 private void startTests() { 404 try { 405 Message serviceMsg = 406 Message.obtain(null, ManagerService.MSG_FIRST_TEST); 407 408 Bundle bundle = new Bundle(); 409 if (!mTestsList.isEmpty()) { 410 bundle.putString("firstTest", mTestsList.get(0)); 411 bundle.putInt("index", mCurrentTestIndex); 412 } 413 414 serviceMsg.setData(bundle); 415 mManagerServiceMessenger.send(serviceMsg); 416 } catch (RemoteException e) { 417 Log.e(LOG_TAG, "mCurrentTestRelativePath=" + mCurrentTestRelativePath, e); 418 } 419 420 runNextTest(); 421 } 422 423 private void runNextTest() { 424 assert mCurrentState == CurrentState.IDLE : "mCurrentState = " + mCurrentState.name(); 425 426 if (mTestsList.isEmpty()) { 427 onAllTestsFinished(); 428 return; 429 } 430 431 mCurrentTestRelativePath = mTestsList.remove(0); 432 433 Log.i(LOG_TAG, "runNextTest(): Start: " + mCurrentTestRelativePath + 434 " (" + mCurrentTestIndex + ")"); 435 436 mCurrentTestUri = FileFilter.getUrl(mCurrentTestRelativePath).toString(); 437 438 reset(); 439 440 /** Start time-out countdown and the test */ 441 mCurrentState = CurrentState.RENDERING_PAGE; 442 mResultHandler.sendEmptyMessageDelayed(MSG_TEST_TIMED_OUT, DEFAULT_TIME_OUT_MS); 443 mCurrentWebView.loadUrl(mCurrentTestUri); 444 } 445 446 private void onTestTimedOut() { 447 assert mCurrentState.isRunningState() : "mCurrentState = " + mCurrentState.name(); 448 449 Log.w(LOG_TAG, "onTestTimedOut(): " + mCurrentTestRelativePath); 450 mCurrentTestTimedOut = true; 451 452 /** 453 * While it is theoretically possible that the test times out because 454 * of webview becoming unresponsive, it is very unlikely. Therefore it's 455 * assumed that obtaining results (that calls various webview methods) 456 * will not itself hang. 457 */ 458 obtainActualResultsFromWebView(); 459 } 460 461 private void onTestFinished() { 462 assert mCurrentState.isRunningState() : "mCurrentState = " + mCurrentState.name(); 463 464 Log.i(LOG_TAG, "onTestFinished(): " + mCurrentTestRelativePath); 465 mResultHandler.removeMessages(MSG_TEST_TIMED_OUT); 466 obtainActualResultsFromWebView(); 467 } 468 469 private void obtainActualResultsFromWebView() { 470 /** 471 * If the result has not been set by the time the test finishes we create 472 * a default type of result. 473 */ 474 if (mCurrentResult == null) { 475 /** TODO: Default type should be RenderTreeResult. We don't support it now. */ 476 mCurrentResult = new TextResult(mCurrentTestRelativePath); 477 } 478 479 mCurrentState = CurrentState.OBTAINING_RESULT; 480 481 if (mCurrentTestTimedOut) { 482 mCurrentResult.setDidTimeOut(); 483 } 484 mCurrentResult.obtainActualResults(mCurrentWebView, 485 mResultHandler.obtainMessage(MSG_ACTUAL_RESULT_OBTAINED)); 486 } 487 488 private void onActualResultsObtained() { 489 assert mCurrentState == CurrentState.OBTAINING_RESULT 490 : "mCurrentState = " + mCurrentState.name(); 491 492 Log.i(LOG_TAG, "onActualResultsObtained(): " + mCurrentTestRelativePath); 493 mCurrentState = CurrentState.IDLE; 494 495 reportResultToService(); 496 mCurrentTestIndex++; 497 updateProgressBar(); 498 runNextTest(); 499 } 500 501 private void reportResultToService() { 502 if (mCurrentAdditionalTextOutput != null) { 503 mCurrentResult.setAdditionalTextOutputString(mCurrentAdditionalTextOutput.toString()); 504 } 505 506 try { 507 Message serviceMsg = 508 Message.obtain(null, ManagerService.MSG_PROCESS_ACTUAL_RESULTS); 509 510 Bundle bundle = mCurrentResult.getBundle(); 511 bundle.putInt("testIndex", mCurrentTestIndex); 512 if (!mTestsList.isEmpty()) { 513 bundle.putString("nextTest", mTestsList.get(0)); 514 } 515 516 serviceMsg.setData(bundle); 517 mManagerServiceMessenger.send(serviceMsg); 518 } catch (RemoteException e) { 519 Log.e(LOG_TAG, "mCurrentTestRelativePath=" + mCurrentTestRelativePath, e); 520 } 521 } 522 523 private void updateProgressBar() { 524 getWindow().setFeatureInt(Window.FEATURE_PROGRESS, 525 mCurrentTestIndex * Window.PROGRESS_END / mTotalTestCount); 526 setTitle(mCurrentTestIndex * 100 / mTotalTestCount + "% " + 527 "(" + mCurrentTestIndex + "/" + mTotalTestCount + ")"); 528 } 529 530 private void onAllTestsFinished() { 531 mScreenDimLock.release(); 532 533 try { 534 Message serviceMsg = 535 Message.obtain(null, ManagerService.MSG_ALL_TESTS_FINISHED); 536 mManagerServiceMessenger.send(serviceMsg); 537 } catch (RemoteException e) { 538 Log.e(LOG_TAG, "mCurrentTestRelativePath=" + mCurrentTestRelativePath, e); 539 } 540 541 unbindService(mServiceConnection); 542 } 543 544 private AdditionalTextOutput getCurrentAdditionalTextOutput() { 545 if (mCurrentAdditionalTextOutput == null) { 546 mCurrentAdditionalTextOutput = new AdditionalTextOutput(); 547 } 548 return mCurrentAdditionalTextOutput; 549 } 550 551 /** LAYOUT TEST CONTROLLER */ 552 553 private static final int MSG_WAIT_UNTIL_DONE = 0; 554 private static final int MSG_NOTIFY_DONE = 1; 555 private static final int MSG_DUMP_AS_TEXT = 2; 556 private static final int MSG_DUMP_CHILD_FRAMES_AS_TEXT = 3; 557 private static final int MSG_SET_CAN_OPEN_WINDOWS = 4; 558 private static final int MSG_DUMP_DATABASE_CALLBACKS = 5; 559 private static final int MSG_SET_GEOLOCATION_PERMISSION = 6; 560 private static final int MSG_OVERRIDE_PREFERENCE = 7; 561 private static final int MSG_SET_XSS_AUDITOR_ENABLED = 8; 562 563 /** String constants for use with layoutTestController.overridePreference() */ 564 private final String WEBKIT_OFFLINE_WEB_APPLICATION_CACHE_ENABLED = 565 "WebKitOfflineWebApplicationCacheEnabled"; 566 567 Handler mLayoutTestControllerHandler = new Handler() { 568 @Override 569 public void handleMessage(Message msg) { 570 assert mCurrentState.isRunningState() : "mCurrentState = " + mCurrentState.name(); 571 572 switch (msg.what) { 573 case MSG_DUMP_AS_TEXT: 574 if (mCurrentResult == null) { 575 mCurrentResult = new TextResult(mCurrentTestRelativePath); 576 } 577 assert mCurrentResult instanceof TextResult 578 : "mCurrentResult instanceof" + mCurrentResult.getClass().getName(); 579 break; 580 581 case MSG_DUMP_CHILD_FRAMES_AS_TEXT: 582 /** If dumpAsText was not called we assume that the result should be text */ 583 if (mCurrentResult == null) { 584 mCurrentResult = new TextResult(mCurrentTestRelativePath); 585 } 586 587 assert mCurrentResult instanceof TextResult 588 : "mCurrentResult instanceof" + mCurrentResult.getClass().getName(); 589 590 ((TextResult)mCurrentResult).setDumpChildFramesAsText(true); 591 break; 592 593 case MSG_DUMP_DATABASE_CALLBACKS: 594 mDumpDatabaseCallbacks = true; 595 break; 596 597 case MSG_NOTIFY_DONE: 598 if (mCurrentState == CurrentState.WAITING_FOR_ASYNCHRONOUS_TEST) { 599 onTestFinished(); 600 } 601 break; 602 603 case MSG_OVERRIDE_PREFERENCE: 604 /** 605 * TODO: We should look up the correct WebView for the frame which 606 * called the layoutTestController method. Currently, we just use the 607 * WebView for the main frame. EventSender suffers from the same 608 * problem. 609 */ 610 if (msg.getData().getString("key").equals( 611 WEBKIT_OFFLINE_WEB_APPLICATION_CACHE_ENABLED)) { 612 mCurrentWebView.getSettings().setAppCacheEnabled(msg.getData().getBoolean( 613 "value")); 614 } else { 615 Log.w(LOG_TAG, "MSG_OVERRIDE_PREFERENCE: unsupported preference!"); 616 } 617 break; 618 619 case MSG_SET_CAN_OPEN_WINDOWS: 620 mCanOpenWindows = true; 621 break; 622 623 case MSG_SET_GEOLOCATION_PERMISSION: 624 mIsGeolocationPermissionSet = true; 625 mGeolocationPermission = msg.arg1 == 1; 626 627 if (mPendingGeolocationPermissionCallbacks != null) { 628 Iterator<GeolocationPermissions.Callback> iter = 629 mPendingGeolocationPermissionCallbacks.keySet().iterator(); 630 while (iter.hasNext()) { 631 GeolocationPermissions.Callback callback = iter.next(); 632 String origin = mPendingGeolocationPermissionCallbacks.get(callback); 633 callback.invoke(origin, mGeolocationPermission, false); 634 } 635 mPendingGeolocationPermissionCallbacks = null; 636 } 637 break; 638 639 case MSG_SET_XSS_AUDITOR_ENABLED: 640 mCurrentWebView.getSettings().setXSSAuditorEnabled(msg.arg1 == 1); 641 break; 642 643 case MSG_WAIT_UNTIL_DONE: 644 mCurrentState = CurrentState.WAITING_FOR_ASYNCHRONOUS_TEST; 645 break; 646 647 default: 648 assert false : "msg.what=" + msg.what; 649 break; 650 } 651 } 652 }; 653 654 private void resetLayoutTestController() { 655 mCanOpenWindows = false; 656 mDumpDatabaseCallbacks = false; 657 mIsGeolocationPermissionSet = false; 658 mPendingGeolocationPermissionCallbacks = null; 659 } 660 661 public void dumpAsText(boolean enablePixelTest) { 662 Log.i(LOG_TAG, mCurrentTestRelativePath + ": dumpAsText(" + enablePixelTest + ") called"); 663 /** TODO: Implement */ 664 if (enablePixelTest) { 665 Log.w(LOG_TAG, "enablePixelTest not implemented, switching to false"); 666 } 667 mLayoutTestControllerHandler.sendEmptyMessage(MSG_DUMP_AS_TEXT); 668 } 669 670 public void dumpChildFramesAsText() { 671 Log.i(LOG_TAG, mCurrentTestRelativePath + ": dumpChildFramesAsText() called"); 672 mLayoutTestControllerHandler.sendEmptyMessage(MSG_DUMP_CHILD_FRAMES_AS_TEXT); 673 } 674 675 public void dumpDatabaseCallbacks() { 676 Log.i(LOG_TAG, mCurrentTestRelativePath + ": dumpDatabaseCallbacks() called"); 677 mLayoutTestControllerHandler.sendEmptyMessage(MSG_DUMP_DATABASE_CALLBACKS); 678 } 679 680 public void notifyDone() { 681 Log.i(LOG_TAG, mCurrentTestRelativePath + ": notifyDone() called"); 682 mLayoutTestControllerHandler.sendEmptyMessage(MSG_NOTIFY_DONE); 683 } 684 685 public void overridePreference(String key, boolean value) { 686 Log.i(LOG_TAG, mCurrentTestRelativePath + ": overridePreference(" + key + ", " + value + 687 ") called"); 688 Message msg = mLayoutTestControllerHandler.obtainMessage(MSG_OVERRIDE_PREFERENCE); 689 msg.getData().putString("key", key); 690 msg.getData().putBoolean("value", value); 691 msg.sendToTarget(); 692 } 693 694 public void setCanOpenWindows() { 695 Log.i(LOG_TAG, mCurrentTestRelativePath + ": setCanOpenWindows() called"); 696 mLayoutTestControllerHandler.sendEmptyMessage(MSG_SET_CAN_OPEN_WINDOWS); 697 } 698 699 public void setGeolocationPermission(boolean allow) { 700 Log.i(LOG_TAG, mCurrentTestRelativePath + ": setGeolocationPermission(" + allow + 701 ") called"); 702 Message msg = mLayoutTestControllerHandler.obtainMessage(MSG_SET_GEOLOCATION_PERMISSION); 703 msg.arg1 = allow ? 1 : 0; 704 msg.sendToTarget(); 705 } 706 707 public void setMockDeviceOrientation(boolean canProvideAlpha, double alpha, 708 boolean canProvideBeta, double beta, boolean canProvideGamma, double gamma) { 709 Log.i(LOG_TAG, mCurrentTestRelativePath + ": setMockDeviceOrientation(" + canProvideAlpha + 710 ", " + alpha + ", " + canProvideBeta + ", " + beta + ", " + canProvideGamma + 711 ", " + gamma + ")"); 712 mCurrentWebView.setMockDeviceOrientation(canProvideAlpha, alpha, canProvideBeta, beta, 713 canProvideGamma, gamma); 714 } 715 716 public void setXSSAuditorEnabled(boolean flag) { 717 Log.i(LOG_TAG, mCurrentTestRelativePath + ": setXSSAuditorEnabled(" + flag + ") called"); 718 Message msg = mLayoutTestControllerHandler.obtainMessage(MSG_SET_XSS_AUDITOR_ENABLED); 719 msg.arg1 = flag ? 1 : 0; 720 msg.sendToTarget(); 721 } 722 723 public void waitUntilDone() { 724 Log.i(LOG_TAG, mCurrentTestRelativePath + ": waitUntilDone() called"); 725 mLayoutTestControllerHandler.sendEmptyMessage(MSG_WAIT_UNTIL_DONE); 726 } 727} 728