diff options
author | Maksymilian Osowski <maxosowski@google.com> | 2010-07-28 17:22:46 +0100 |
---|---|---|
committer | Maksymilian Osowski <maxosowski@google.com> | 2010-08-02 16:22:28 +0100 |
commit | 42bee9cf7684623124470535d663537f70a4a441 (patch) | |
tree | 56fb9bf6cdd319b3d580f14a18f2d3a07f519505 /tests | |
parent | 6d0dae6a6534a01ee4c58d4f4ee1bf115c82319c (diff) | |
download | frameworks_base-42bee9cf7684623124470535d663537f70a4a441.zip frameworks_base-42bee9cf7684623124470535d663537f70a4a441.tar.gz frameworks_base-42bee9cf7684623124470535d663537f70a4a441.tar.bz2 |
Time-out mechanism and state machine.
Change-Id: I47c4342c02ea152b1503b9d5268900df3b40683c
Diffstat (limited to 'tests')
-rw-r--r-- | tests/DumpRenderTree2/src/com/android/dumprendertree2/LayoutTestsExecutor.java | 90 |
1 files changed, 77 insertions, 13 deletions
diff --git a/tests/DumpRenderTree2/src/com/android/dumprendertree2/LayoutTestsExecutor.java b/tests/DumpRenderTree2/src/com/android/dumprendertree2/LayoutTestsExecutor.java index 608b14e..e0d3e37 100644 --- a/tests/DumpRenderTree2/src/com/android/dumprendertree2/LayoutTestsExecutor.java +++ b/tests/DumpRenderTree2/src/com/android/dumprendertree2/LayoutTestsExecutor.java @@ -50,6 +50,18 @@ import java.util.List; */ public class LayoutTestsExecutor extends Activity { + private enum CurrentState { + IDLE, + RENDERING_PAGE, + WAITING_FOR_ASYNCHRONOUS_TEST, + OBTAINING_RESULT; + + public boolean isRunningState() { + return this == CurrentState.RENDERING_PAGE || + this == CurrentState.WAITING_FOR_ASYNCHRONOUS_TEST; + } + } + /** TODO: make it a setting */ static final String TESTS_ROOT_DIR_PATH = Environment.getExternalStorageDirectory() + @@ -62,6 +74,9 @@ public class LayoutTestsExecutor extends Activity { public static final String EXTRA_TEST_INDEX = "TestIndex"; private static final int MSG_ACTUAL_RESULT_OBTAINED = 0; + private static final int MSG_TEST_TIMED_OUT = 1; + + private static final int DEFAULT_TIME_OUT_MS = 15 * 1000; private List<String> mTestsList; @@ -77,8 +92,9 @@ public class LayoutTestsExecutor extends Activity { private WebView mCurrentWebView; private String mCurrentTestRelativePath; private String mCurrentTestUri; + private CurrentState mCurrentState = CurrentState.IDLE; - private boolean mOnTestFinishedCalled; + private boolean mCurrentTestTimedOut; private AbstractResult mCurrentResult; /** COMMUNICATION WITH ManagerService */ @@ -102,11 +118,17 @@ public class LayoutTestsExecutor extends Activity { private final Handler mResultHandler = new Handler() { @Override public void handleMessage(Message msg) { - if (msg.what == MSG_ACTUAL_RESULT_OBTAINED) { - reportResultToService(); - mCurrentTestIndex++; - updateProgressBar(); - runNextTest(); + switch (msg.what) { + case MSG_ACTUAL_RESULT_OBTAINED: + onActualResultsObtained(); + break; + + case MSG_TEST_TIMED_OUT: + onTestTimedOut(); + break; + + default: + break; } } }; @@ -177,7 +199,9 @@ public class LayoutTestsExecutor extends Activity { } private void reset() { - mOnTestFinishedCalled = false; + WebView previousWebView = mCurrentWebView; + + mCurrentTestTimedOut = false; mCurrentResult = null; mCurrentWebView = new WebView(this); @@ -199,9 +223,14 @@ public class LayoutTestsExecutor extends Activity { webViewSettings.setXSSAuditorEnabled(false); setContentView(mCurrentWebView); + if (previousWebView != null) { + previousWebView.destroy(); + } } private void runNextTest() { + assert mCurrentState == CurrentState.IDLE : "mCurrentState = " + mCurrentState.name(); + if (mTestsList.isEmpty()) { onAllTestsFinished(); return; @@ -212,17 +241,34 @@ public class LayoutTestsExecutor extends Activity { Uri.fromFile(new File(TESTS_ROOT_DIR_PATH, mCurrentTestRelativePath)).toString(); reset(); - /** TODO: Implement timeout */ + + /** Start time-out countdown and the test */ + mCurrentState = CurrentState.RENDERING_PAGE; + mResultHandler.sendEmptyMessageDelayed(MSG_TEST_TIMED_OUT, DEFAULT_TIME_OUT_MS); mCurrentWebView.loadUrl(mCurrentTestUri); } + private void onTestTimedOut() { + assert mCurrentState.isRunningState() : "mCurrentState = " + mCurrentState.name(); + + mCurrentTestTimedOut = true; + + /** + * While it is theoretically possible that the test times out because + * of webview becoming unresponsive, it is very unlikely. Therefore it's + * assumed that obtaining results (that calls various webview methods) + * will not itself hang. + */ + obtainActualResultsFromWebView(); + } + private void onTestFinished() { - if (mOnTestFinishedCalled) { - return; - } + assert mCurrentState.isRunningState() : "mCurrentState = " + mCurrentState.name(); - mOnTestFinishedCalled = true; + obtainActualResultsFromWebView(); + } + private void obtainActualResultsFromWebView() { /** * If the result has not been set by the time the test finishes we create * a default type of result. @@ -232,17 +278,35 @@ public class LayoutTestsExecutor extends Activity { mCurrentResult = new TextResult(mCurrentTestRelativePath); } + mCurrentState = CurrentState.OBTAINING_RESULT; mCurrentResult.obtainActualResults(mCurrentWebView, mResultHandler.obtainMessage(MSG_ACTUAL_RESULT_OBTAINED)); } + private void onActualResultsObtained() { + assert mCurrentState == CurrentState.OBTAINING_RESULT + : "mCurrentState = " + mCurrentState.name(); + + mCurrentState = CurrentState.IDLE; + + mResultHandler.removeMessages(MSG_TEST_TIMED_OUT); + reportResultToService(); + mCurrentTestIndex++; + updateProgressBar(); + runNextTest(); + } + private void reportResultToService() { try { Message serviceMsg = Message.obtain(null, ManagerService.MSG_PROCESS_ACTUAL_RESULTS); + Bundle bundle = mCurrentResult.getBundle(); bundle.putInt("testIndex", mCurrentTestIndex); - /** TODO: Add timeout info to bundle */ + if (mCurrentTestTimedOut) { + bundle.putString("resultCode", AbstractResult.ResultCode.FAIL_TIMED_OUT.name()); + } + serviceMsg.setData(bundle); mManagerServiceMessenger.send(serviceMsg); } catch (RemoteException e) { |