ImmersiveMode/Application/tests/src/com/example/android/immersivemode/tests/ImmersiveModeSampleTests.java
public void testDecorHeightExpanded() {
        // Grab the initial height of the DecorWindow.
        int startingHeight = getActivity().getWindow().getDecorView().getHeight();

        // In order to test that this worked:  Need to toggle the immersive mode on the UI thread,
        // wait a suitable amount of time (this test goes with 200 ms), then check to see if the
        // height changed.
        try {
            Runnable testRunnable = (new Runnable() {
                public void run() {
                    // Toggle immersive mode
                    mTestFragment.toggleHideyBar();
                    synchronized(this) {
                        // Notify any thread waiting on this runnable that it can continue
                        this.notify();
                    }
                }
            });
            synchronized(testRunnable) {
                // Since toggling immersive mode makes changes to the view heirarchy, it needs to run
                // on the UI thread, or crashing will occur.
                mTestActivity.runOnUiThread(testRunnable);
                testRunnable.wait();

            }
            synchronized(this) {
                //Wait about 200ms for the change to take place
                wait(200L);
            }
        } catch (Throwable throwable) {
            fail(throwable.getMessage());
        }

        int expandedHeight = getActivity().getWindow().getDecorView().getHeight();
        assertTrue("Bars aren't hidden.", expandedHeight != startingHeight);
    }
/**
     * Verify that the view's height actually changed when the toggle method is called.
     * This should result in a change in height for the DecorView.
     */
Verify that the view's height actually changed when the toggle method is called.
This should result in a change in height for the DecorView.
Verify that the view ' s height actually changed when the toggle method is called . This should result in a change in height for the DecorView .
public void testDecorHeightExpanded() {
        int startingHeight = getActivity().getWindow().getDecorView().getHeight();
        try {
            Runnable testRunnable = (new Runnable() {
                public void run() {
                    mTestFragment.toggleHideyBar();
                    synchronized(this) {
                        this.notify();
                    }
                }
            });
            synchronized(testRunnable) {
                mTestActivity.runOnUiThread(testRunnable);
                testRunnable.wait();
            }
            synchronized(this) {
                wait(200L);
            }
        } catch (Throwable throwable) {
            fail(throwable.getMessage());
        }
        int expandedHeight = getActivity().getWindow().getDecorView().getHeight();
        assertTrue("Bars aren't hidden.", expandedHeight != startingHeight);
    }
public void testDecorHeightExpanded ( ) { int startingHeight = getActivity ( ) . getWindow ( ) . getDecorView ( ) . getHeight ( ) ; try { Runnable testRunnable = ( new Runnable ( ) { public void run ( ) { mTestFragment . toggleHideyBar ( ) ; synchronized ( this ) { this . notify ( ) ; } } } ) ; synchronized ( testRunnable ) { mTestActivity . runOnUiThread ( testRunnable ) ; testRunnable . wait ( ) ; } synchronized ( this ) { wait ( 200L ) ; } } catch ( Throwable throwable ) { fail ( throwable . getMessage ( ) ) ; } int expandedHeight = getActivity ( ) . getWindow ( ) . getDecorView ( ) . getHeight ( ) ; assertTrue ( "Bars aren't hidden." , expandedHeight != startingHeight ) ; }
Verify that the view's height actually changed when the toggle method is called.
Verify that the view ' s height actually changed when the toggle method is called .
// Grab the initial height of the DecorWindow. // In order to test that this worked:  Need to toggle the immersive mode on the UI thread, // wait a suitable amount of time (this test goes with 200 ms), then check to see if the // height changed. // Toggle immersive mode // Notify any thread waiting on this runnable that it can continue // Since toggling immersive mode makes changes to the view heirarchy, it needs to run // on the UI thread, or crashing will occur. //Wait about 200ms for the change to take place