FileDocCategorySizeDatePackage
TestShellActivity.javaAPI DocAndroid 1.5 API12853Wed May 06 22:42:02 BST 2009com.android.dumprendertree

TestShellActivity

public class TestShellActivity extends android.app.Activity implements LayoutTestController

Fields Summary
private final android.webkit.WebChromeClient
mChromeClient
private android.webkit.WebView
mWebView
private WebViewEventSender
mEventSender
private AsyncHandler
mHandler
private TestShellCallback
mCallback
private CallbackProxy
mCallbackProxy
private String
mTestUrl
private String
mResultFile
private int
mTimeoutInMillis
private boolean
mTimedOut
private boolean
mRequestedWebKitData
private boolean
mFinishedRunning
private boolean
mDumpAsText
private boolean
mWaitUntilDone
private boolean
mDumpTitleChanges
private StringBuffer
mTitleChanges
private StringBuffer
mDialogStrings
private boolean
mKeepWebHistory
private Vector
mWebHistory
static final String
TIMEOUT_STR
static final int
MSG_TIMEOUT
static final int
MSG_WEBKIT_DATA
static final String
LOGTAG
static final String
TEST_URL
static final String
RESULT_FILE
static final String
TIMEOUT_IN_MILLIS
Constructors Summary
Methods Summary
public voidclearBackForwardList()

        mWebView.clearHistory();

    
public voiddisplay()

        mWebView.invalidate();
    
public voiddump(boolean timeout, java.lang.String webkitData)

        if (mResultFile == null || mResultFile.length() == 0) {
            finished();
            return;
        }
        
        try {
            File parentDir = new File(mResultFile).getParentFile();
            if (!parentDir.exists()) {
                parentDir.mkdirs();
            }
            
            FileOutputStream os = new FileOutputStream(mResultFile);
            if (timeout) {
                Log.w("Layout test: Timeout", mResultFile);
                os.write(TIMEOUT_STR.getBytes());
                os.write('\n");
            }
            if (mDumpTitleChanges)
                os.write(mTitleChanges.toString().getBytes());
            if (mDialogStrings != null)
                os.write(mDialogStrings.toString().getBytes());
            mDialogStrings = null;
            os.write(webkitData.getBytes());
            os.flush();
            os.close();
        } catch (IOException ex) {
            Log.e(LOGTAG, "Cannot write to " + mResultFile + ", " + ex.getMessage());          
        }

        finished();
    
public voiddumpAsText()

        mDumpAsText = true;
        if (mWebView != null) {
            String url = mWebView.getUrl();
            Log.v(LOGTAG, "dumpAsText called: "+url);
        }
    
public voiddumpBackForwardList()

        //printf("\n============== Back Forward List ==============\n");
        // mWebHistory
        //printf("===============================================\n");

    
public voiddumpChildFrameScrollPositions()

        // TODO Auto-generated method stub

    
public voiddumpEditingCallbacks()

        // TODO Auto-generated method stub

    
public voiddumpSelectionRect()

        // TODO Auto-generated method stub

    
public voiddumpTitleChanges()

        if (!mDumpTitleChanges) {
            mTitleChanges = new StringBuffer();
        }
        mDumpTitleChanges = true;
    
private voidexecuteIntent(android.content.Intent intent)

        resetTestStatus();
        if (!Intent.ACTION_VIEW.equals(intent.getAction())) {
            return;
        }
        
        mTestUrl = intent.getStringExtra(TEST_URL);
        if (mTestUrl == null)
            return;
        
        mResultFile = intent.getStringExtra(RESULT_FILE);
        mTimeoutInMillis = intent.getIntExtra(TIMEOUT_IN_MILLIS, 0);

        Log.v(LOGTAG, "  Loading " + mTestUrl);
        mWebView.loadUrl(mTestUrl);
            
        if (mTimeoutInMillis > 0) {
            // Create a timeout timer
            Message m = mHandler.obtainMessage(MSG_TIMEOUT);
            mHandler.sendMessageDelayed(m, mTimeoutInMillis);
        }
    
public voidfinished()

        if (mCallback != null) {
            mCallback.finished();
        }
    
public voidkeepWebHistory()

        if (!mKeepWebHistory) {
            mWebHistory = new Vector();
        }
        mKeepWebHistory = true;
    
public voidnotifyDone()

        String url = mWebView.getUrl();
        Log.v(LOGTAG, "notifyDone called: " + url);
        if (mWaitUntilDone) {
            mWaitUntilDone = false;
            mChromeClient.onProgressChanged(mWebView, 100);
        }
    
protected voidonCreate(Bundle icicle)

        super.onCreate(icicle);
        
        LinearLayout contentView = new LinearLayout(this);
        contentView.setOrientation(LinearLayout.VERTICAL);
        setContentView(contentView);

        mWebView = new WebView(this);
        mWebView.getSettings().setJavaScriptEnabled(true);
        mWebView.setWebChromeClient(mChromeClient);
        mEventSender = new WebViewEventSender(mWebView);
        mCallbackProxy = new CallbackProxy(mEventSender, this);

        mWebView.addJavascriptInterface(mCallbackProxy, "layoutTestController");
        mWebView.addJavascriptInterface(mCallbackProxy, "eventSender");
        contentView.addView(mWebView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT, 0.0f));
 
        mWebView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
            
        mHandler = new AsyncHandler();
        
        Intent intent = getIntent();
        if (intent != null) {
            executeIntent(intent);
        }
    
protected voidonDestroy()

        super.onDestroy();
        mWebView.destroy();
        mWebView = null;
    
public voidonLowMemory()

        super.onLowMemory();
        Log.e(LOGTAG, "Low memory, kill self");
        System.exit(1);
    
protected voidonNewIntent(android.content.Intent intent)

        super.onNewIntent(intent);
        executeIntent(intent);
    
protected voidonStop()

        super.onStop();
        mWebView.stopLoading();
    
public voidqueueBackNavigation(int howfar)

        // TODO Auto-generated method stub

    
public voidqueueForwardNavigation(int howfar)

        // TODO Auto-generated method stub

    
public voidqueueLoad(java.lang.String Url, java.lang.String frameTarget)

        // TODO Auto-generated method stub

    
public voidqueueReload()

        mWebView.reload();
    
public voidqueueScript(java.lang.String scriptToRunInCurrentContext)

        mWebView.loadUrl("javascript:"+scriptToRunInCurrentContext);     
    
public voidrepaintSweepHorizontally()

        // TODO Auto-generated method stub

    
public voidrequestWebKitData()

        Message callback = mHandler.obtainMessage(MSG_WEBKIT_DATA);
        
        if (mRequestedWebKitData)
            throw new AssertionError("Requested webkit data twice: " + mWebView.getUrl());
        
        mRequestedWebKitData = true;
        if (mDumpAsText) { 
            mWebView.documentAsText(callback);
        } else {
            mWebView.externalRepresentation(callback);
        }
    
private voidresetTestStatus()

    
       
        mWaitUntilDone = false;
        mDumpAsText = false;
        mTimedOut = false;
        mDumpTitleChanges = false;
        mRequestedWebKitData = false;
        mEventSender.resetMouse();
    
public voidsetAcceptsEditing(boolean b)

        // TODO Auto-generated method stub

    
public voidsetCallback(TestShellCallback callback)

        mCallback = callback;
    
public voidsetMainFrameIsFirstResponder(boolean b)

        // TODO Auto-generated method stub

    
public voidsetWindowIsKey(boolean b)

        // This is meant to show/hide the window. The best I can find
        // is setEnabled()
        mWebView.setEnabled(b);
    
public voidtestRepaint()

        mWebView.invalidate();
    
public voidwaitUntilDone()

        mWaitUntilDone = true;
        String url = mWebView.getUrl();
        Log.v(LOGTAG, "waitUntilDone called: " + url);