diff options
| author | Guang Zhu <guangzhu@google.com> | 2009-10-29 18:24:54 -0700 |
|---|---|---|
| committer | Guang Zhu <guangzhu@google.com> | 2009-12-02 17:55:18 -0800 |
| commit | 5dc4f21ab6360b45f464c1451f8d403dd4df3c63 (patch) | |
| tree | 5e5e3e45a1d0028d61de6d84c7b4db042a8c6b78 /tests/DumpRenderTree/src/com/android/dumprendertree/TestShellActivity.java | |
| parent | 96dac84be4143d83b13648045b9af31ac0f81004 (diff) | |
| download | frameworks_base-5dc4f21ab6360b45f464c1451f8d403dd4df3c63.zip frameworks_base-5dc4f21ab6360b45f464c1451f8d403dd4df3c63.tar.gz frameworks_base-5dc4f21ab6360b45f464c1451f8d403dd4df3c63.tar.bz2 | |
Add support for extracting render time and image in page cycler
Diffstat (limited to 'tests/DumpRenderTree/src/com/android/dumprendertree/TestShellActivity.java')
| -rw-r--r-- | tests/DumpRenderTree/src/com/android/dumprendertree/TestShellActivity.java | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/DumpRenderTree/src/com/android/dumprendertree/TestShellActivity.java b/tests/DumpRenderTree/src/com/android/dumprendertree/TestShellActivity.java index aeb55b4..b6b1661 100644 --- a/tests/DumpRenderTree/src/com/android/dumprendertree/TestShellActivity.java +++ b/tests/DumpRenderTree/src/com/android/dumprendertree/TestShellActivity.java @@ -25,6 +25,9 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.DialogInterface.OnClickListener; import android.graphics.Bitmap; +import android.graphics.Canvas; +import android.graphics.Bitmap.CompressFormat; +import android.graphics.Bitmap.Config; import android.net.http.SslError; import android.os.Bundle; import android.os.Handler; @@ -163,6 +166,8 @@ public class TestShellActivity extends Activity implements LayoutTestController mResultFile = intent.getStringExtra(RESULT_FILE); mTimeoutInMillis = intent.getIntExtra(TIMEOUT_IN_MILLIS, 0); + mGetDrawtime = intent.getBooleanExtra(GET_DRAW_TIME, false); + mSaveImagePath = intent.getStringExtra(SAVE_IMAGE); Log.v(LOGTAG, " Loading " + mTestUrl); mWebView.loadUrl(mTestUrl); @@ -459,6 +464,18 @@ public class TestShellActivity extends Activity implements LayoutTestController public void onPageFinished(WebView view, String url) { Log.v(LOGTAG, "onPageFinished, url=" + url); mPageFinished = true; + // get page draw time + if (FsUtils.isTestPageUrl(url)) { + if (mGetDrawtime) { + long[] times = new long[DRAW_RUNS]; + times = getDrawWebViewTime(mWebView, DRAW_RUNS); + FsUtils.writeDrawTime(DRAW_TIME_LOG, url, times); + } + if (mSaveImagePath != null) { + String name = FsUtils.getLastSegmentInPath(url); + drawPageToFile(mSaveImagePath + "/" + name + ".png", mWebView); + } + } // Calling finished() will check if we've met all the conditions for completing // this test and move to the next one if we are ready. if (finished()) { @@ -691,6 +708,41 @@ public class TestShellActivity extends Activity implements LayoutTestController mPageFinished = false; mOneHundredPercentComplete = false; mDumpWebKitData = false; + mGetDrawtime = false; + mSaveImagePath = null; + } + + private long[] getDrawWebViewTime(WebView view, int count) { + if (count == 0) + return null; + long[] ret = new long[count]; + long start; + Canvas canvas = new Canvas(); + Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Config.ARGB_8888); + canvas.setBitmap(bitmap); + for (int i = 0; i < count; i++) { + start = System.currentTimeMillis(); + view.draw(canvas); + ret[i] = System.currentTimeMillis() - start; + } + return ret; + } + + private void drawPageToFile(String fileName, WebView view) { + Canvas canvas = new Canvas(); + Bitmap bitmap = Bitmap.createBitmap(view.getContentWidth(), view.getContentHeight(), + Config.ARGB_8888); + canvas.setBitmap(bitmap); + view.drawPage(canvas); + try { + FileOutputStream fos = new FileOutputStream(fileName); + if(!bitmap.compress(CompressFormat.PNG, 90, fos)) { + Log.w(LOGTAG, "Failed to compress and save image."); + } + } catch (IOException ioe) { + Log.e(LOGTAG, "", ioe); + } + bitmap.recycle(); } private boolean canMoveToNextTest() { @@ -730,7 +782,9 @@ public class TestShellActivity extends Activity implements LayoutTestController private String mResultFile; private int mTimeoutInMillis; private String mUiAutoTestPath; + private String mSaveImagePath; private BufferedReader mTestListReader; + private boolean mGetDrawtime; // States private boolean mTimedOut; @@ -766,6 +820,11 @@ public class TestShellActivity extends Activity implements LayoutTestController static final String RESULT_FILE = "ResultFile"; static final String TIMEOUT_IN_MILLIS = "TimeoutInMillis"; static final String UI_AUTO_TEST = "UiAutoTest"; + static final String GET_DRAW_TIME = "GetDrawTime"; + static final String SAVE_IMAGE = "SaveImage"; + + static final int DRAW_RUNS = 5; + static final String DRAW_TIME_LOG = "/sdcard/android/page_draw_time.txt"; private boolean mGeolocationPermissionSet; private boolean mGeolocationPermission; |
