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