FileDocCategorySizeDatePackage
IdleHandlerTest.javaAPI DocAndroid 5.1 API6030Thu Mar 12 22:22:12 GMT 2015android.os

IdleHandlerTest

public class IdleHandlerTest extends TestCase

Fields Summary
Constructors Summary
Methods Summary
public voidtestOneShotFirst()

        TestHandlerThread tester = new BaseTestHandler() {
            int mCount;

            public void go() {
                super.go();
                mCount = 0;
                mHandler.sendMessageDelayed(mHandler.obtainMessage(0), 100);
                addIdleHandler();
            }

            public void handleMessage(Message msg) {
                if (msg.what == 0) {
                    mHandler.sendMessageDelayed(mHandler.obtainMessage(1), 100);
                } else if (msg.what == 1) {
                    if (mCount == 1) {
                        success();
                    } else {
                        failure(new RuntimeException(
                                "Idle handler called " + mCount + " times"));
                    }
                }
            }

            public boolean queueIdle() {
                mCount++;
                return false;
            }
        };

        tester.doTest(1000);
    
public voidtestOneShotLater()

        TestHandlerThread tester = new BaseTestHandler() {
            int mCount;

            public void go() {
                super.go();
                mCount = 0;
                mHandler.sendMessage(mHandler.obtainMessage(0));
            }

            public void handleMessage(Message msg) {
                if (msg.what == 0) {
                    addIdleHandler();
                    mHandler.sendMessageDelayed(mHandler.obtainMessage(1), 100);
                } else if (msg.what == 1) {
                    mHandler.sendMessageDelayed(mHandler.obtainMessage(2), 100);
                } else if (msg.what == 2) {
                    if (mCount == 1) {
                        success();
                    } else {
                        failure(new RuntimeException(
                                "Idle handler called " + mCount + " times"));
                    }
                }
            }

            public boolean queueIdle() {
                mCount++;
                return false;
            }
        };

        tester.doTest(1000);
    
public voidtestRepeatedFirst()

        TestHandlerThread tester = new BaseTestHandler() {
            int mCount;

            public void go() {
                super.go();
                mCount = 0;
                mHandler.sendMessageDelayed(mHandler.obtainMessage(0), 100);
                addIdleHandler();
            }

            public void handleMessage(Message msg) {
                if (msg.what == 0) {
                    mHandler.sendMessageDelayed(mHandler.obtainMessage(1), 100);
                } else if (msg.what == 1) {
                    if (mCount == 2) {
                        success();
                    } else {
                        failure(new RuntimeException(
                                "Idle handler called " + mCount + " times"));
                    }
                }
            }

            public boolean queueIdle() {
                mCount++;
                return true;
            }
        };

        tester.doTest(1000);
    
public voidtestRepeatedLater()

        TestHandlerThread tester = new BaseTestHandler() {
            int mCount;

            public void go() {
                super.go();
                mCount = 0;
                mHandler.sendMessage(mHandler.obtainMessage(0));
            }

            public void handleMessage(Message msg) {
                if (msg.what == 0) {
                    addIdleHandler();
                    mHandler.sendMessageDelayed(mHandler.obtainMessage(1), 100);
                } else if (msg.what == 1) {
                    mHandler.sendMessageDelayed(mHandler.obtainMessage(2), 100);
                } else if (msg.what == 2) {
                    if (mCount == 2) {
                        success();
                    } else {
                        failure(new RuntimeException(
                                "Idle handler called " + mCount + " times"));
                    }
                }
            }

            public boolean queueIdle() {
                mCount++;
                return true;
            }
        };

        tester.doTest(1000);