Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a7e3b645 authored by Wale Ogunwale's avatar Wale Ogunwale
Browse files

Converted window manager unit tests to use JUnit4

Change-Id: I5248d5fcc9f0f5b44bab1d57f16d1cf2ad4b8209
parent 571771c3
Loading
Loading
Loading
Loading
+14 −6
Original line number Diff line number Diff line
@@ -16,17 +16,23 @@

package com.android.server.wm;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import android.content.Context;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import android.view.IWindow;
import android.view.WindowManager;
import android.view.WindowManagerPolicy;

import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

/**
 * Tests for the {@link WindowState} class.
@@ -36,15 +42,16 @@ import static android.view.WindowManager.LayoutParams.TYPE_BASE_APPLICATION;
 * Run: adb shell am instrument -w -e class com.android.server.wm.AppWindowTokenTests com.android.frameworks.servicestests/android.support.test.runner.AndroidJUnitRunner
 */
@SmallTest
public class AppWindowTokenTests extends AndroidTestCase {
@RunWith(AndroidJUnit4.class)
public class AppWindowTokenTests {

    private static WindowManagerService sWm = null;
    private final WindowManagerPolicy mPolicy = new TestWindowManagerPolicy();
    private final IWindow mIWindow = new TestIWindow();

    @Override
    @Before
    public void setUp() throws Exception {
        final Context context = getContext();
        final Context context = InstrumentationRegistry.getTargetContext();
        if (sWm == null) {
            // We only want to do this once for the test process as we don't want WM to try to
            // register a bunch of local services again.
@@ -52,6 +59,7 @@ public class AppWindowTokenTests extends AndroidTestCase {
        }
    }

    @Test
    public void testFindMainWindow() throws Exception {
        final TestAppWindowToken token = new TestAppWindowToken();

+22 −4
Original line number Diff line number Diff line
@@ -16,12 +16,21 @@

package com.android.server.wm;

import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import org.junit.Test;
import org.junit.runner.RunWith;

import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;

import java.util.Comparator;
import java.util.LinkedList;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

/**
 * Test class for {@link WindowContainer}.
 *
@@ -30,14 +39,17 @@ import java.util.LinkedList;
 * Run: adb shell am instrument -w -e class com.android.server.wm.WindowContainerTests com.android.frameworks.servicestests/android.support.test.runner.AndroidJUnitRunner
 */
@SmallTest
public class WindowContainerTests extends AndroidTestCase {
@RunWith(AndroidJUnit4.class)
public class WindowContainerTests {

    @Test
    public void testCreation() throws Exception {
        final TestWindowContainer w = new TestWindowContainerBuilder().setLayer(0).build();
        assertNull("window must have no parent", w.getParentWindow());
        assertEquals("window must have no children", 0, w.getChildrenCount());
    }

    @Test
    public void testAdd() throws Exception {
        final TestWindowContainerBuilder builder = new TestWindowContainerBuilder();
        final TestWindowContainer root = builder.setLayer(0).build();
@@ -69,6 +81,7 @@ public class WindowContainerTests extends AndroidTestCase {
        assertEquals(layer2, root.getChildAt(6));
    }

    @Test
    public void testHasChild() throws Exception {
        final TestWindowContainerBuilder builder = new TestWindowContainerBuilder();
        final TestWindowContainer root = builder.setLayer(0).build();
@@ -98,6 +111,7 @@ public class WindowContainerTests extends AndroidTestCase {
        assertFalse(child2.hasChild(child12));
    }

    @Test
    public void testRemoveImmediately() throws Exception {
        final TestWindowContainerBuilder builder = new TestWindowContainerBuilder();
        final TestWindowContainer root = builder.setLayer(0).build();
@@ -132,6 +146,7 @@ public class WindowContainerTests extends AndroidTestCase {
        assertEquals(0, root.getChildrenCount());
    }

    @Test
    public void testDetachFromDisplay() throws Exception {
        final TestWindowContainerBuilder builder = new TestWindowContainerBuilder();
        final TestWindowContainer root = builder.setLayer(0).build();
@@ -150,6 +165,7 @@ public class WindowContainerTests extends AndroidTestCase {
        assertFalse(child21.detachFromDisplay());
    }

    @Test
    public void testIsAnimating() throws Exception {
        final TestWindowContainerBuilder builder = new TestWindowContainerBuilder();
        final TestWindowContainer root = builder.setLayer(0).build();
@@ -168,6 +184,7 @@ public class WindowContainerTests extends AndroidTestCase {
        assertFalse(child21.isAnimating());
    }

    @Test
    public void testIsVisible() throws Exception {
        final TestWindowContainerBuilder builder = new TestWindowContainerBuilder();
        final TestWindowContainer root = builder.setLayer(0).build();
@@ -186,6 +203,7 @@ public class WindowContainerTests extends AndroidTestCase {
        assertFalse(child21.isVisible());
    }

    @Test
    public void testDetachChild() throws Exception {
        final TestWindowContainerBuilder builder = new TestWindowContainerBuilder();
        final TestWindowContainer root = builder.setLayer(0).build();
+22 −7
Original line number Diff line number Diff line
@@ -16,9 +16,14 @@

package com.android.server.wm;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import android.content.Context;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import android.view.IWindow;
import android.view.WindowManager;
import android.view.WindowManagerPolicy;
@@ -27,6 +32,10 @@ import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

/**
 * Tests for the {@link WindowState} class.
@@ -36,25 +45,26 @@ import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
 * Run: adb shell am instrument -w -e class com.android.server.wm.WindowStateTests com.android.frameworks.servicestests/android.support.test.runner.AndroidJUnitRunner
 */
@SmallTest
public class WindowStateTests extends AndroidTestCase {
@RunWith(AndroidJUnit4.class)
public class WindowStateTests {

    private static WindowManagerService sWm = null;
    private WindowToken mWindowToken;
    private final WindowManagerPolicy mPolicy = new TestWindowManagerPolicy();
    private final IWindow mIWindow = new TestIWindow();

    @Override
    @Before
    public void setUp() throws Exception {
        final Context context = getContext();
//        final InputManagerService im = new InputManagerService(context);
        final Context context = InstrumentationRegistry.getTargetContext();
        if (sWm == null) {
            // We only want to do this once for the test process as we don't want WM to try to
            // register a bunch of local services again.
            sWm = WindowManagerService.main(context, /*im*/ null, true, false, false, mPolicy);
            sWm = WindowManagerService.main(context, null, true, false, false, mPolicy);
        }
        mWindowToken = new WindowToken(sWm, null, 0, false);
    }

    @Test
    public void testIsParentWindowHidden() throws Exception {
        final WindowState parentWindow = createWindow(null, TYPE_APPLICATION);
        final WindowState child1 = createWindow(parentWindow, FIRST_SUB_WINDOW);
@@ -71,6 +81,7 @@ public class WindowStateTests extends AndroidTestCase {
        assertTrue(child2.isParentWindowHidden());
    }

    @Test
    public void testIsChildWindow() throws Exception {
        final WindowState parentWindow = createWindow(null, TYPE_APPLICATION);
        final WindowState child1 = createWindow(parentWindow, FIRST_SUB_WINDOW);
@@ -83,6 +94,7 @@ public class WindowStateTests extends AndroidTestCase {
        assertFalse(randomWindow.isChildWindow());
    }

    @Test
    public void testHasChild() throws Exception {
        final WindowState win1 = createWindow(null, TYPE_APPLICATION);
        final WindowState win11 = createWindow(win1, FIRST_SUB_WINDOW);
@@ -103,6 +115,7 @@ public class WindowStateTests extends AndroidTestCase {
        assertFalse(win2.hasChild(randomWindow));
    }

    @Test
    public void testGetBottomChild() throws Exception {
        final WindowState parentWindow = createWindow(null, TYPE_APPLICATION);
        assertNull(parentWindow.getBottomChild());
@@ -126,6 +139,7 @@ public class WindowStateTests extends AndroidTestCase {
        assertEquals(child4, parentWindow.getBottomChild());
    }

    @Test
    public void testGetParentWindow() throws Exception {
        final WindowState parentWindow = createWindow(null, TYPE_APPLICATION);
        final WindowState child1 = createWindow(parentWindow, FIRST_SUB_WINDOW);
@@ -136,6 +150,7 @@ public class WindowStateTests extends AndroidTestCase {
        assertEquals(parentWindow, child2.getParentWindow());
    }

    @Test
    public void testGetTopParentWindow() throws Exception {
        final WindowState root = createWindow(null, TYPE_APPLICATION);
        final WindowState child1 = createWindow(root, FIRST_SUB_WINDOW);
+19 −8
Original line number Diff line number Diff line
@@ -16,18 +16,24 @@

package com.android.server.wm;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import android.content.Context;
import android.os.IBinder;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import android.view.IWindow;
import android.view.WindowManager;
import android.view.WindowManagerPolicy;

import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

/**
 * Tests for the {@link WindowState} class.
@@ -37,15 +43,16 @@ import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
 * Run: adb shell am instrument -w -e class com.android.server.wm.WindowTokenTests com.android.frameworks.servicestests/android.support.test.runner.AndroidJUnitRunner
 */
@SmallTest
public class WindowTokenTests extends AndroidTestCase {
@RunWith(AndroidJUnit4.class)
public class WindowTokenTests {

    private static WindowManagerService sWm = null;
    private final WindowManagerPolicy mPolicy = new TestWindowManagerPolicy();
    private final IWindow mIWindow = new TestIWindow();

    @Override
    @Before
    public void setUp() throws Exception {
        final Context context = getContext();
        final Context context = InstrumentationRegistry.getTargetContext();
        if (sWm == null) {
            // We only want to do this once for the test process as we don't want WM to try to
            // register a bunch of local services again.
@@ -53,6 +60,7 @@ public class WindowTokenTests extends AndroidTestCase {
        }
    }

    @Test
    public void testAddWindow() throws Exception {
        final TestWindowToken token = new TestWindowToken();

@@ -81,6 +89,7 @@ public class WindowTokenTests extends AndroidTestCase {
        assertTrue(token.hasWindow(window3));
    }

    @Test
    public void testAdjustAnimLayer() throws Exception {
        final TestWindowToken token = new TestWindowToken();
        final WindowState window1 = createWindow(null, TYPE_APPLICATION, token);
@@ -106,6 +115,7 @@ public class WindowTokenTests extends AndroidTestCase {
        assertEquals(window3StartLayer + adj, highestLayer);
    }

    @Test
    public void testGetTopWindow() throws Exception {
        final TestWindowToken token = new TestWindowToken();

@@ -125,6 +135,7 @@ public class WindowTokenTests extends AndroidTestCase {
        assertEquals(window12, token.getTopWindow());
    }

    @Test
    public void testGetWindowIndex() throws Exception {
        final TestWindowToken token = new TestWindowToken();