Loading packages/MtpDocumentsProvider/tests/src/com/android/mtp/MtpManagerTest.java +17 −11 Original line number Diff line number Diff line Loading @@ -24,6 +24,9 @@ import android.os.OperationCanceledException; import android.test.InstrumentationTestCase; import java.io.IOException; import java.util.concurrent.Callable; import java.util.concurrent.FutureTask; import java.util.concurrent.TimeUnit; @RealDeviceTest public class MtpManagerTest extends InstrumentationTestCase { Loading Loading @@ -53,20 +56,23 @@ public class MtpManagerTest extends InstrumentationTestCase { public void testCancelEvent() throws Exception { final CancellationSignal signal = new CancellationSignal(); final Thread thread = new Thread() { final FutureTask<Boolean> future = new FutureTask<Boolean>( new Callable<Boolean>() { @Override public void run() { public Boolean call() throws IOException { try { mManager.readEvent(mUsbDevice.getDeviceId(), signal); } catch (OperationCanceledException | IOException e) { getInstrumentation().show(e.getMessage()); return false; } catch (OperationCanceledException exception) { return true; } } }; }); final Thread thread = new Thread(future); thread.start(); Thread.sleep(TIMEOUT_MS); signal.cancel(); thread.join(TIMEOUT_MS); assertTrue(future.get(TIMEOUT_MS, TimeUnit.MILLISECONDS)); } private Context getContext() { Loading packages/MtpDocumentsProvider/tests/src/com/android/mtp/TestResultInstrumentation.java +4 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,10 @@ import junit.framework.AssertionFailedError; import junit.framework.Test; import junit.framework.TestListener; /** * Instrumentation that can show the test result in the TestResultActivity. * It's useful when it runs testcases with a real USB device and could not use USB port for ADB. */ public class TestResultInstrumentation extends InstrumentationTestRunner implements TestListener { private boolean mHasError = false; Loading packages/MtpDocumentsProvider/tests/src/com/android/mtp/TestUtil.java +3 −4 Original line number Diff line number Diff line Loading @@ -33,7 +33,7 @@ import junit.framework.Assert; /** * Static utility methods for testing. */ class TestUtil { final class TestUtil { private static final String ACTION_USB_PERMISSION = "com.android.mtp.USB_PERMISSION"; Loading @@ -42,12 +42,11 @@ class TestUtil { /** * Requests permission for a MTP device and returns the first MTP device that has at least one * storage. * @throws Exception */ static UsbDevice setupMtpDevice( TestResultInstrumentation instrumentation, UsbManager usbManager, MtpManager manager) throws Exception { MtpManager manager) throws InterruptedException, IOException { for (int i = 0; i < 2; i++) { final UsbDevice device = findMtpDevice(instrumentation, usbManager); manager.openDevice(device.getDeviceId()); Loading Loading @@ -121,7 +120,7 @@ class TestUtil { private static void waitForStorages( TestResultInstrumentation instrumentation, MtpManager manager, int deviceId) throws Exception { int deviceId) throws IOException, InterruptedException { while (true) { if (manager.getRoots(deviceId).length == 0) { instrumentation.show("Wait for storages."); Loading Loading
packages/MtpDocumentsProvider/tests/src/com/android/mtp/MtpManagerTest.java +17 −11 Original line number Diff line number Diff line Loading @@ -24,6 +24,9 @@ import android.os.OperationCanceledException; import android.test.InstrumentationTestCase; import java.io.IOException; import java.util.concurrent.Callable; import java.util.concurrent.FutureTask; import java.util.concurrent.TimeUnit; @RealDeviceTest public class MtpManagerTest extends InstrumentationTestCase { Loading Loading @@ -53,20 +56,23 @@ public class MtpManagerTest extends InstrumentationTestCase { public void testCancelEvent() throws Exception { final CancellationSignal signal = new CancellationSignal(); final Thread thread = new Thread() { final FutureTask<Boolean> future = new FutureTask<Boolean>( new Callable<Boolean>() { @Override public void run() { public Boolean call() throws IOException { try { mManager.readEvent(mUsbDevice.getDeviceId(), signal); } catch (OperationCanceledException | IOException e) { getInstrumentation().show(e.getMessage()); return false; } catch (OperationCanceledException exception) { return true; } } }; }); final Thread thread = new Thread(future); thread.start(); Thread.sleep(TIMEOUT_MS); signal.cancel(); thread.join(TIMEOUT_MS); assertTrue(future.get(TIMEOUT_MS, TimeUnit.MILLISECONDS)); } private Context getContext() { Loading
packages/MtpDocumentsProvider/tests/src/com/android/mtp/TestResultInstrumentation.java +4 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,10 @@ import junit.framework.AssertionFailedError; import junit.framework.Test; import junit.framework.TestListener; /** * Instrumentation that can show the test result in the TestResultActivity. * It's useful when it runs testcases with a real USB device and could not use USB port for ADB. */ public class TestResultInstrumentation extends InstrumentationTestRunner implements TestListener { private boolean mHasError = false; Loading
packages/MtpDocumentsProvider/tests/src/com/android/mtp/TestUtil.java +3 −4 Original line number Diff line number Diff line Loading @@ -33,7 +33,7 @@ import junit.framework.Assert; /** * Static utility methods for testing. */ class TestUtil { final class TestUtil { private static final String ACTION_USB_PERMISSION = "com.android.mtp.USB_PERMISSION"; Loading @@ -42,12 +42,11 @@ class TestUtil { /** * Requests permission for a MTP device and returns the first MTP device that has at least one * storage. * @throws Exception */ static UsbDevice setupMtpDevice( TestResultInstrumentation instrumentation, UsbManager usbManager, MtpManager manager) throws Exception { MtpManager manager) throws InterruptedException, IOException { for (int i = 0; i < 2; i++) { final UsbDevice device = findMtpDevice(instrumentation, usbManager); manager.openDevice(device.getDeviceId()); Loading Loading @@ -121,7 +120,7 @@ class TestUtil { private static void waitForStorages( TestResultInstrumentation instrumentation, MtpManager manager, int deviceId) throws Exception { int deviceId) throws IOException, InterruptedException { while (true) { if (manager.getRoots(deviceId).length == 0) { instrumentation.show("Wait for storages."); Loading