Tests for locking / unlocking drawer

Change-Id: I0c95f57b0abe5cdc9cb3107baf0adeaea91b2cd1
diff --git a/v7/appcompat/tests/src/android/support/v7/app/DrawerLayoutTest.java b/v7/appcompat/tests/src/android/support/v7/app/DrawerLayoutTest.java
index 5ab4506..49f3efe 100755
--- a/v7/appcompat/tests/src/android/support/v7/app/DrawerLayoutTest.java
+++ b/v7/appcompat/tests/src/android/support/v7/app/DrawerLayoutTest.java
@@ -369,4 +369,48 @@
 
         mDrawerLayout.removeDrawerListener(mockedListener);
     }
+
+    @Test
+    @SmallTest
+    public void testDrawerLockUnlock() {
+        assertEquals("Drawer is unlocked in initial state",
+                DrawerLayout.LOCK_MODE_UNLOCKED, mDrawerLayout.getDrawerLockMode(mStartDrawer));
+
+        // Lock the drawer open
+        onView(withId(R.id.drawer_layout)).perform(
+                setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN, GravityCompat.START));
+        // Check that it's locked open
+        assertEquals("Drawer is now locked open",
+                DrawerLayout.LOCK_MODE_LOCKED_OPEN, mDrawerLayout.getDrawerLockMode(mStartDrawer));
+        // and also opened
+        assertTrue("Drawer is also opened", mDrawerLayout.isDrawerOpen(mStartDrawer));
+
+        // Unlock the drawer
+        onView(withId(R.id.drawer_layout)).perform(
+                setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, mStartDrawer));
+        // Check that it's still opened
+        assertTrue("Drawer is still opened", mDrawerLayout.isDrawerOpen(mStartDrawer));
+        // Close the drawer
+        onView(withId(R.id.drawer_layout)).perform(closeDrawer(mStartDrawer));
+        // Check that the drawer is unlocked
+        assertEquals("Start drawer is now unlocked",
+                DrawerLayout.LOCK_MODE_UNLOCKED, mDrawerLayout.getDrawerLockMode(mStartDrawer));
+
+        // Open the drawer and then clock it closed
+        onView(withId(R.id.drawer_layout)).perform(openDrawer(mStartDrawer));
+        onView(withId(R.id.drawer_layout)).perform(
+                setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, GravityCompat.START));
+        // Check that the drawer is locked close
+        assertEquals("Drawer is now locked close",
+                DrawerLayout.LOCK_MODE_LOCKED_CLOSED,
+                mDrawerLayout.getDrawerLockMode(mStartDrawer));
+        // and also closed
+        assertFalse("Drawer is also closed", mDrawerLayout.isDrawerOpen(mStartDrawer));
+
+        // Unlock the drawer
+        onView(withId(R.id.drawer_layout)).perform(
+                setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, mStartDrawer));
+        // Check that it's still closed
+        assertFalse("Drawer is still closed", mDrawerLayout.isDrawerOpen(mStartDrawer));
+    }
 }
diff --git a/v7/appcompat/tests/src/android/support/v7/testutils/DrawerLayoutActions.java b/v7/appcompat/tests/src/android/support/v7/testutils/DrawerLayoutActions.java
index ee33a98..4feb013 100755
--- a/v7/appcompat/tests/src/android/support/v7/testutils/DrawerLayoutActions.java
+++ b/v7/appcompat/tests/src/android/support/v7/testutils/DrawerLayoutActions.java
@@ -245,7 +245,7 @@
      * Sets the lock mode for the drawer at the specified edge gravity.
      */
     public static ViewAction setDrawerLockMode(final int lockMode, final int drawerEdgeGravity) {
-        return new ViewAction() {
+        return wrap(new ViewAction() {
             @Override
             public Matcher<View> getConstraints() {
                 return isAssignableFrom(DrawerLayout.class);
@@ -265,14 +265,14 @@
 
                 uiController.loopMainThreadUntilIdle();
             }
-        };
+        });
     }
 
     /**
      * Sets the lock mode for the drawer.
      */
     public static ViewAction setDrawerLockMode(final int lockMode, final View drawerView) {
-        return new ViewAction() {
+        return wrap(new ViewAction() {
             @Override
             public Matcher<View> getConstraints() {
                 return isAssignableFrom(DrawerLayout.class);
@@ -292,6 +292,6 @@
 
                 uiController.loopMainThreadUntilIdle();
             }
-        };
+        });
     }
 }