summaryrefslogtreecommitdiffstats
path: root/services/tests
diff options
context:
space:
mode:
authorMatthew Williams <mjwilliams@google.com>2014-03-21 21:59:07 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2014-03-21 21:59:07 +0000
commitcde7086b900fd192a8e389f62ab5007d351d86b8 (patch)
tree8b82f7dd61c65e1c677a3664ddc4deaae53362d9 /services/tests
parent717e0f5db7161ddfff98f21fe1cdb2a3b1a6c8b7 (diff)
parent6428046767ee4195617fb41b5639eefa2ca7a939 (diff)
downloadframeworks_base-cde7086b900fd192a8e389f62ab5007d351d86b8.zip
frameworks_base-cde7086b900fd192a8e389f62ab5007d351d86b8.tar.gz
frameworks_base-cde7086b900fd192a8e389f62ab5007d351d86b8.tar.bz2
Merge "Downgrade expedited to normal on reschedule."
Diffstat (limited to 'services/tests')
-rw-r--r--services/tests/servicestests/src/com/android/server/content/SyncOperationTest.java77
-rw-r--r--services/tests/servicestests/src/com/android/server/content/SyncStorageEngineTest.java8
2 files changed, 65 insertions, 20 deletions
diff --git a/services/tests/servicestests/src/com/android/server/content/SyncOperationTest.java b/services/tests/servicestests/src/com/android/server/content/SyncOperationTest.java
index 37176d6..b0296a0 100644
--- a/services/tests/servicestests/src/com/android/server/content/SyncOperationTest.java
+++ b/services/tests/servicestests/src/com/android/server/content/SyncOperationTest.java
@@ -18,12 +18,13 @@ package com.android.server.content;
import android.accounts.Account;
import android.content.ContentResolver;
+import android.content.Context;
import android.os.Bundle;
+import android.os.SystemClock;
+import android.provider.Settings;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
-import com.android.server.content.SyncOperation;
-
/**
* You can run those tests with:
*
@@ -35,6 +36,21 @@ import com.android.server.content.SyncOperation;
public class SyncOperationTest extends AndroidTestCase {
+ Account mDummy;
+ /** Indicate an unimportant long that we're not testing. */
+ long mUnimportantLong = 0L;
+ /** Empty bundle. */
+ Bundle mEmpty;
+ /** Silly authority. */
+ String mAuthority;
+
+ @Override
+ public void setUp() {
+ mDummy = new Account("account1", "type1");
+ mEmpty = new Bundle();
+ mAuthority = "authority1";
+ }
+
@SmallTest
public void testToKey() {
Account account1 = new Account("account1", "type1");
@@ -111,35 +127,64 @@ public class SyncOperationTest extends AndroidTestCase {
@SmallTest
public void testCompareTo() {
- Account dummy = new Account("account1", "type1");
- Bundle b1 = new Bundle();
- final long unimportant = 0L;
long soon = 1000;
long soonFlex = 50;
long after = 1500;
long afterFlex = 100;
- SyncOperation op1 = new SyncOperation(dummy, 0, 0, SyncOperation.REASON_PERIODIC,
- "authority1", b1, soon, soonFlex, unimportant, unimportant, true);
+ SyncOperation op1 = new SyncOperation(mDummy, 0, 0, SyncOperation.REASON_PERIODIC,
+ "authority1", mEmpty, soon, soonFlex, mUnimportantLong, mUnimportantLong, true);
// Interval disjoint from and after op1.
- SyncOperation op2 = new SyncOperation(dummy, 0, 0, SyncOperation.REASON_PERIODIC,
- "authority1", b1, after, afterFlex, unimportant, unimportant, true);
+ SyncOperation op2 = new SyncOperation(mDummy, 0, 0, SyncOperation.REASON_PERIODIC,
+ "authority1", mEmpty, after, afterFlex, mUnimportantLong, mUnimportantLong, true);
// Interval equivalent to op1, but expedited.
Bundle b2 = new Bundle();
b2.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
- SyncOperation op3 = new SyncOperation(dummy, 0, 0, 0,
- "authority1", b2, soon, soonFlex, unimportant, unimportant, true);
+ SyncOperation op3 = new SyncOperation(mDummy, 0, 0, 0,
+ "authority1", b2, -1, soonFlex, mUnimportantLong, mUnimportantLong, true);
// Interval overlaps but not equivalent to op1.
- SyncOperation op4 = new SyncOperation(dummy, 0, 0, SyncOperation.REASON_PERIODIC,
- "authority1", b1, soon + 100, soonFlex + 100, unimportant, unimportant, true);
+ SyncOperation op4 = new SyncOperation(mDummy, 0, 0, SyncOperation.REASON_PERIODIC,
+ "authority1", mEmpty, soon + 100, soonFlex + 100, mUnimportantLong, mUnimportantLong, true);
assertTrue(op1.compareTo(op2) == -1);
assertTrue("less than not transitive.", op2.compareTo(op1) == 1);
- assertTrue(op1.compareTo(op3) == 1);
+ assertTrue("Expedited sync not smaller than non-expedited.", op1.compareTo(op3) == 1);
assertTrue("greater than not transitive. ", op3.compareTo(op1) == -1);
- assertTrue("overlapping intervals not the same.", op1.compareTo(op4) == 0);
- assertTrue("equality not transitive.", op4.compareTo(op1) == 0);
+ assertTrue("overlapping intervals not correctly compared.", op1.compareTo(op4) == -1);
+ assertTrue("equality not transitive.", op4.compareTo(op1) == 1);
+ }
+
+ @SmallTest
+ public void testCopyConstructor() {
+ long fiveSecondsFromNow = 5 * 1000L;
+ long twoSecondsFlex = 2 * 1000L;
+ long eightSeconds = 8 * 1000L;
+ long fourSeconds = 4 * 1000L;
+
+ Bundle withExpedited = new Bundle();
+ withExpedited.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
+ SyncOperation op = new SyncOperation(mDummy, 0, 0, SyncOperation.REASON_USER_START,
+ mAuthority, withExpedited, fiveSecondsFromNow, twoSecondsFlex,
+ eightSeconds /* backoff */, fourSeconds /* delayUntil */, true);
+ // Create another sync op to be rerun in 5 minutes.
+ long now = SystemClock.elapsedRealtime();
+ SyncOperation copy = new SyncOperation(op, fiveSecondsFromNow * 60);
+ // Copying an expedited sync to be re-run should not keep expedited property.
+ assertFalse("A rescheduled sync based off an expedited should not be expedited!",
+ copy.isExpedited());
+ assertFalse("A rescheduled sync based off an expedited should not have expedited=true in"
+ + "its bundle.",
+ copy.extras.getBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, false));
+ assertTrue("Copied sync is not respecting new provided run-time.",
+ copy.latestRunTime == (now + fiveSecondsFromNow * 60));
+ assertTrue("A rescheduled sync should not have any flex.",
+ copy.flexTime == 0L);
+ assertTrue("A rescheduled op should honour the old op's backoff.",
+ copy.backoff == eightSeconds);
+ assertTrue("A rescheduled op should honour the old op's delayUntil param.",
+ copy.delayUntil == fourSeconds);
+
}
}
diff --git a/services/tests/servicestests/src/com/android/server/content/SyncStorageEngineTest.java b/services/tests/servicestests/src/com/android/server/content/SyncStorageEngineTest.java
index 70fd810..ae1967e 100644
--- a/services/tests/servicestests/src/com/android/server/content/SyncStorageEngineTest.java
+++ b/services/tests/servicestests/src/com/android/server/content/SyncStorageEngineTest.java
@@ -131,7 +131,7 @@ public class SyncStorageEngineTest extends AndroidTestCase {
assertEquals(sop.target.userId, popRetrieved.target.userId);
assertEquals(sop.reason, popRetrieved.reason);
assertEquals(sop.syncSource, popRetrieved.syncSource);
- assertEquals(sop.expedited, popRetrieved.expedited);
+ assertEquals(sop.isExpedited(), popRetrieved.expedited);
assert(android.content.PeriodicSync.syncExtrasEquals(sop.extras, popRetrieved.extras));
}
@@ -169,7 +169,7 @@ public class SyncStorageEngineTest extends AndroidTestCase {
assertEquals(deleted.target.userId, popDeleted.target.userId);
assertEquals(deleted.reason, popDeleted.reason);
assertEquals(deleted.syncSource, popDeleted.syncSource);
- assertEquals(deleted.expedited, popDeleted.expedited);
+ assertEquals(deleted.isExpedited(), popDeleted.expedited);
assert(android.content.PeriodicSync.syncExtrasEquals(deleted.extras, popDeleted.extras));
// Delete one to force write-all
engine.deleteFromPending(popDeleted);
@@ -192,7 +192,7 @@ public class SyncStorageEngineTest extends AndroidTestCase {
assertEquals(sop.target.userId, popRetrieved.target.userId);
assertEquals(sop.reason, popRetrieved.reason);
assertEquals(sop.syncSource, popRetrieved.syncSource);
- assertEquals(sop.expedited, popRetrieved.expedited);
+ assertEquals(sop.isExpedited(), popRetrieved.expedited);
assert(android.content.PeriodicSync.syncExtrasEquals(sop.extras, popRetrieved.extras));
popRetrieved = pops.get(1);
@@ -202,7 +202,7 @@ public class SyncStorageEngineTest extends AndroidTestCase {
assertEquals(sop1.target.userId, popRetrieved.target.userId);
assertEquals(sop1.reason, popRetrieved.reason);
assertEquals(sop1.syncSource, popRetrieved.syncSource);
- assertEquals(sop1.expedited, popRetrieved.expedited);
+ assertEquals(sop1.isExpedited(), popRetrieved.expedited);
assert(android.content.PeriodicSync.syncExtrasEquals(sop1.extras, popRetrieved.extras));
}