diff options
| author | Kenny Root <kroot@google.com> | 2010-10-13 15:43:35 -0700 |
|---|---|---|
| committer | Kenny Root <kroot@google.com> | 2010-10-13 15:43:51 -0700 |
| commit | 0a9b54e88b9cbb30748b5f0b331aec3f3ef8d639 (patch) | |
| tree | 22ff1466c777067596537ccb085cd64ed0bc3bc5 /core/tests | |
| parent | 0726fd9e835579019f6b23ab50d7b45401e11dbe (diff) | |
| parent | 8bb7a1dfbb43dda49fb3c4f86181bcd7f969a832 (diff) | |
| download | frameworks_base-0a9b54e88b9cbb30748b5f0b331aec3f3ef8d639.zip frameworks_base-0a9b54e88b9cbb30748b5f0b331aec3f3ef8d639.tar.gz frameworks_base-0a9b54e88b9cbb30748b5f0b331aec3f3ef8d639.tar.bz2 | |
resolved conflicts for merge of 8bb7a1df to master
Change-Id: Ieec036f494a54eab74a27b954d1423bf981dd3f9
Diffstat (limited to 'core/tests')
| -rw-r--r-- | core/tests/coretests/src/com/android/server/MountServiceTests.java | 145 |
1 files changed, 110 insertions, 35 deletions
diff --git a/core/tests/coretests/src/com/android/server/MountServiceTests.java b/core/tests/coretests/src/com/android/server/MountServiceTests.java index 83e9d18..1f8c92e 100644 --- a/core/tests/coretests/src/com/android/server/MountServiceTests.java +++ b/core/tests/coretests/src/com/android/server/MountServiceTests.java @@ -21,7 +21,6 @@ import com.android.frameworks.coretests.R; import android.content.Context; import android.content.res.Resources; import android.content.res.Resources.NotFoundException; -import android.os.Environment; import android.os.FileUtils; import android.os.storage.OnObbStateChangeListener; import android.os.storage.StorageManager; @@ -57,17 +56,15 @@ public class MountServiceTests extends AndroidTestCase { } } - private interface CompletableTask { - public boolean isDone(); - } + private static class ObbObserver extends OnObbStateChangeListener { + private String path; - private static class ObbObserver extends OnObbStateChangeListener implements CompletableTask { - public String path; - public String state; + public int state = -1; boolean done = false; @Override - public void onObbStateChange(String path, String state) { + public void onObbStateChange(String path, int state) { + Log.d(TAG, "Received message. path=" + path + ", state=" + state); synchronized (this) { this.path = path; this.state = state; @@ -76,32 +73,43 @@ public class MountServiceTests extends AndroidTestCase { } } + public String getPath() { + assertTrue("Expected ObbObserver to have received a state change.", done); + return path; + } + + public int getState() { + assertTrue("Expected ObbObserver to have received a state change.", done); + return state; + } + public void reset() { this.path = null; - this.state = null; + this.state = -1; done = false; } public boolean isDone() { return done; } - } - private boolean waitForCompletion(CompletableTask task) { - long waitTime = 0; - synchronized (task) { - while (!task.isDone() && waitTime < MAX_WAIT_TIME) { - try { - task.wait(WAIT_TIME_INCR); - waitTime += WAIT_TIME_INCR; - } catch (InterruptedException e) { - Log.i(TAG, "Interrupted during sleep", e); + public boolean waitForCompletion() { + long waitTime = 0; + synchronized (this) { + while (!isDone() && waitTime < MAX_WAIT_TIME) { + try { + wait(WAIT_TIME_INCR); + waitTime += WAIT_TIME_INCR; + } catch (InterruptedException e) { + Log.i(TAG, "Interrupted during sleep", e); + } } } - } - return task.isDone(); + return isDone(); + } } + private File getFilePath(String name) { final File filesDir = mContext.getFilesDir(); final File outFile = new File(filesDir, name); @@ -128,23 +136,52 @@ public class MountServiceTests extends AndroidTestCase { } private void mountObb(StorageManager sm, final int resource, final File file, - String expectedState) { + int expectedState) { copyRawToFile(resource, file); - ObbObserver observer = new ObbObserver(); + final ObbObserver observer = new ObbObserver(); assertTrue("mountObb call on " + file.getPath() + " should succeed", sm.mountObb(file.getPath(), null, observer)); assertTrue("Mount should have completed", - waitForCompletion(observer)); + observer.waitForCompletion()); + + if (expectedState == OnObbStateChangeListener.MOUNTED) { + assertTrue("OBB should be mounted", sm.isObbMounted(file.getPath())); + } assertEquals("Actual file and resolved file should be the same", - file.getPath(), observer.path); + file.getPath(), observer.getPath()); + + assertEquals(expectedState, observer.getState()); + } + + private ObbObserver mountObbWithoutWait(final StorageManager sm, final int resource, + final File file) { + copyRawToFile(resource, file); + + final ObbObserver observer = new ObbObserver(); + assertTrue("mountObb call on " + file.getPath() + " should succeed", sm.mountObb(file + .getPath(), null, observer)); + + return observer; + } - assertEquals(expectedState, observer.state); + private void waitForObbActionCompletion(final StorageManager sm, final File file, + final ObbObserver observer, int expectedState, boolean checkPath) { + assertTrue("Mount should have completed", observer.waitForCompletion()); + + assertTrue("OBB should be mounted", sm.isObbMounted(file.getPath())); + + if (checkPath) { + assertEquals("Actual file and resolved file should be the same", file.getPath(), + observer.getPath()); + } + + assertEquals(expectedState, observer.getState()); } - private String checkMountedPath(StorageManager sm, File file) { + private String checkMountedPath(final StorageManager sm, final File file) { final String mountPath = sm.getMountedObbPath(file.getPath()); assertStartsWith("Path should be in " + OBB_MOUNT_PREFIX, OBB_MOUNT_PREFIX, @@ -152,13 +189,21 @@ public class MountServiceTests extends AndroidTestCase { return mountPath; } - private void unmountObb(StorageManager sm, final File outFile) { - ObbObserver observer = new ObbObserver(); + private void unmountObb(final StorageManager sm, final File file, int expectedState) { + final ObbObserver observer = new ObbObserver(); + assertTrue("unmountObb call on test1.obb should succeed", - sm.unmountObb(outFile.getPath(), false, observer)); + sm.unmountObb(file.getPath(), + false, observer)); assertTrue("Unmount should have completed", - waitForCompletion(observer)); + observer.waitForCompletion()); + + assertEquals(expectedState, observer.getState()); + + if (expectedState == OnObbStateChangeListener.UNMOUNTED) { + assertFalse("OBB should not be mounted", sm.isObbMounted(file.getPath())); + } } @LargeTest @@ -167,7 +212,9 @@ public class MountServiceTests extends AndroidTestCase { final File outFile = getFilePath("test1.obb"); - mountObb(sm, R.raw.test1, outFile, Environment.MEDIA_MOUNTED); + mountObb(sm, R.raw.test1, outFile, OnObbStateChangeListener.MOUNTED); + + mountObb(sm, R.raw.test1, outFile, OnObbStateChangeListener.ERROR_ALREADY_MOUNTED); final String mountPath = checkMountedPath(sm, outFile); final File mountDir = new File(mountPath); @@ -175,7 +222,7 @@ public class MountServiceTests extends AndroidTestCase { assertTrue("OBB mounted path should be a directory", mountDir.isDirectory()); - unmountObb(sm, outFile); + unmountObb(sm, outFile, OnObbStateChangeListener.UNMOUNTED); } @LargeTest @@ -184,7 +231,7 @@ public class MountServiceTests extends AndroidTestCase { final File outFile = getFilePath("test1_nosig.obb"); - mountObb(sm, R.raw.test1_nosig, outFile, Environment.MEDIA_BAD_REMOVAL); + mountObb(sm, R.raw.test1_nosig, outFile, OnObbStateChangeListener.ERROR_INTERNAL); assertFalse("OBB should not be mounted", sm.isObbMounted(outFile.getPath())); @@ -199,7 +246,8 @@ public class MountServiceTests extends AndroidTestCase { final File outFile = getFilePath("test1_wrongpackage.obb"); - mountObb(sm, R.raw.test1_wrongpackage, outFile, Environment.MEDIA_BAD_REMOVAL); + mountObb(sm, R.raw.test1_wrongpackage, outFile, + OnObbStateChangeListener.ERROR_PERMISSION_DENIED); assertFalse("OBB should not be mounted", sm.isObbMounted(outFile.getPath())); @@ -207,4 +255,31 @@ public class MountServiceTests extends AndroidTestCase { assertNull("OBB's mounted path should be null", sm.getMountedObbPath(outFile.getPath())); } + + @LargeTest + public void testMountAndUnmountTwoObbs() { + StorageManager sm = getStorageManager(); + + final File file1 = getFilePath("test1.obb"); + final File file2 = getFilePath("test2.obb"); + + ObbObserver oo1 = mountObbWithoutWait(sm, R.raw.test1, file1); + ObbObserver oo2 = mountObbWithoutWait(sm, R.raw.test1, file2); + + Log.d(TAG, "Waiting for OBB #1 to complete mount"); + waitForObbActionCompletion(sm, file1, oo1, OnObbStateChangeListener.MOUNTED, false); + Log.d(TAG, "Waiting for OBB #2 to complete mount"); + waitForObbActionCompletion(sm, file2, oo2, OnObbStateChangeListener.MOUNTED, false); + + final String mountPath1 = checkMountedPath(sm, file1); + final File mountDir1 = new File(mountPath1); + assertTrue("OBB mounted path should be a directory", mountDir1.isDirectory()); + + final String mountPath2 = checkMountedPath(sm, file2); + final File mountDir2 = new File(mountPath2); + assertTrue("OBB mounted path should be a directory", mountDir2.isDirectory()); + + unmountObb(sm, file1, OnObbStateChangeListener.UNMOUNTED); + unmountObb(sm, file2, OnObbStateChangeListener.UNMOUNTED); + } } |
