summaryrefslogtreecommitdiffstats
path: root/tests/src/com/android
diff options
context:
space:
mode:
authorBen Murdoch <benm@google.com>2010-02-09 17:03:07 +0000
committerBen Murdoch <benm@google.com>2010-02-18 19:17:31 +0000
commit34b89ef113c7e5e365f75ec692a98a5484834ca0 (patch)
tree35954444ffed1b7b4cf2610d9e8d5941294e83bd /tests/src/com/android
parent96ab239a56b9efc53794a900128fa449853f5f1e (diff)
downloadpackages_apps_browser-34b89ef113c7e5e365f75ec692a98a5484834ca0.zip
packages_apps_browser-34b89ef113c7e5e365f75ec692a98a5484834ca0.tar.gz
packages_apps_browser-34b89ef113c7e5e365f75ec692a98a5484834ca0.tar.bz2
When a second database is created on an origin, ensure that the quota for that origin is large enough to cover both databases (old and new).
Fix for 2417477 Change-Id: I914b29a5f90a11fe3c3dc9a927a8720197b03560
Diffstat (limited to 'tests/src/com/android')
-rw-r--r--tests/src/com/android/browser/WebStorageSizeManagerUnitTests.java77
1 files changed, 73 insertions, 4 deletions
diff --git a/tests/src/com/android/browser/WebStorageSizeManagerUnitTests.java b/tests/src/com/android/browser/WebStorageSizeManagerUnitTests.java
index b7956d7..354c4da 100644
--- a/tests/src/com/android/browser/WebStorageSizeManagerUnitTests.java
+++ b/tests/src/com/android/browser/WebStorageSizeManagerUnitTests.java
@@ -108,14 +108,14 @@ public class WebStorageSizeManagerUnitTests extends AndroidTestCase {
totalUsedQuota += origin2Quota;
// Origin 1 runs out of space.
- manager.onExceededDatabaseQuota("1", "1", origin1Quota, origin1EstimatedSize, totalUsedQuota, mQuotaUpdater);
+ manager.onExceededDatabaseQuota("1", "1", origin1Quota, 0, totalUsedQuota, mQuotaUpdater);
assertEquals(origin1EstimatedSize + quotaIncrease, mNewQuota);
totalUsedQuota -= origin1Quota;
origin1Quota = mNewQuota;
totalUsedQuota += origin1Quota;
// Origin 2 runs out of space.
- manager.onExceededDatabaseQuota("2", "2", origin2Quota, origin2EstimatedSize, totalUsedQuota, mQuotaUpdater);
+ manager.onExceededDatabaseQuota("2", "2", origin2Quota, 0, totalUsedQuota, mQuotaUpdater);
assertEquals(origin2EstimatedSize + quotaIncrease, mNewQuota);
totalUsedQuota -= origin2Quota;
origin2Quota = mNewQuota;
@@ -131,14 +131,14 @@ public class WebStorageSizeManagerUnitTests extends AndroidTestCase {
totalUsedQuota += origin3Quota;
// Origin 1 runs out of space again. It should increase it's quota to take the last 1MB.
- manager.onExceededDatabaseQuota("1", "1", origin1Quota, origin1EstimatedSize, totalUsedQuota, mQuotaUpdater);
+ manager.onExceededDatabaseQuota("1", "1", origin1Quota, 0, totalUsedQuota, mQuotaUpdater);
assertEquals(origin1Quota + quotaIncrease, mNewQuota);
totalUsedQuota -= origin1Quota;
origin1Quota = mNewQuota;
totalUsedQuota += origin1Quota;
// Origin 1 runs out of space again. It should inow fail to increase in size.
- manager.onExceededDatabaseQuota("1", "1", origin1Quota, origin1EstimatedSize, totalUsedQuota, mQuotaUpdater);
+ manager.onExceededDatabaseQuota("1", "1", origin1Quota, 0, totalUsedQuota, mQuotaUpdater);
assertEquals(origin1Quota, mNewQuota);
// We try adding a new origin. Which will fail.
@@ -228,4 +228,73 @@ public class WebStorageSizeManagerUnitTests extends AndroidTestCase {
maxSize = WebStorageSizeManager.calculateGlobalLimit(fileSystemSize, freeSpaceSize);
assertEquals(0, maxSize);
}
+
+ public void testManyDatabasesOnOneOrigin() {
+ // This test ensures that if an origin creates more than one database, the quota that is
+ // assigned to the origin after the second creation is enough to satisfy all databases
+ // under that origin.
+ // See b/2417477.
+
+ long totalUsedQuota = 0;
+ mDiskInfo.setTotalSizeBytes(bytes(100));
+ mDiskInfo.setFreeSpaceSizeBytes(bytes(100));
+ // This should give us a storage area of 13MB, with 3.25MB for appcache and 9.75MB for
+ // databases.
+ assertEquals(bytes(13), WebStorageSizeManager.calculateGlobalLimit(
+ mDiskInfo.getTotalSizeBytes(), mDiskInfo.getFreeSpaceSizeBytes()));
+
+ // We have an appcache file size of 0 MB.
+ mAppCacheInfo.setAppCacheSizeBytes(0);
+
+ // Create the manager.
+ WebStorageSizeManager manager = new WebStorageSizeManager(null, mDiskInfo, mAppCacheInfo);
+
+ // We add an origin.
+ long originQuota = 0;
+ long database1EstimatedSize = bytes(2);
+ manager.onExceededDatabaseQuota("1", "1", originQuota, database1EstimatedSize,
+ totalUsedQuota, mQuotaUpdater);
+ assertEquals(database1EstimatedSize, mNewQuota);
+ originQuota = mNewQuota;
+ totalUsedQuota = originQuota;
+
+ // Now try to create a new database under the origin, by invoking onExceededDatabaseQuota
+ // again. This time, request more space than the old quota + the quota increase step.
+ long database2EstimatedSize = bytes(3.5);
+ manager.onExceededDatabaseQuota("1", "2", originQuota, database2EstimatedSize,
+ totalUsedQuota, mQuotaUpdater);
+ assertEquals(database1EstimatedSize + database2EstimatedSize, mNewQuota);
+ originQuota = mNewQuota;
+ totalUsedQuota = originQuota;
+
+ // Create another database, but this time use a size that will overflow the space on the
+ // device. It should be denied.
+ long database3EstimatedSize = bytes(50);
+ manager.onExceededDatabaseQuota("1", "3", originQuota, database3EstimatedSize,
+ totalUsedQuota, mQuotaUpdater);
+ assertEquals(originQuota, mNewQuota);
+
+ // Create another database. This time, request less than the old quota.
+ long database4EstimatedSize = bytes(2);
+ manager.onExceededDatabaseQuota("1", "4", originQuota, database4EstimatedSize,
+ totalUsedQuota, mQuotaUpdater);
+ assertEquals(database1EstimatedSize + database2EstimatedSize + database4EstimatedSize,
+ mNewQuota);
+ originQuota = mNewQuota;
+ totalUsedQuota = originQuota;
+
+ // Now have the first database overflow it's quota. We should get 1 more MB.
+ manager.onExceededDatabaseQuota("1", "1", originQuota, 0, totalUsedQuota, mQuotaUpdater);
+ assertEquals(database1EstimatedSize + database2EstimatedSize + database4EstimatedSize +
+ bytes(1), mNewQuota);
+ originQuota = mNewQuota;
+ totalUsedQuota = originQuota;
+
+ // Create a db under the origin that uses a quota less than the usual quota increase step.
+ long database5EstimatedSize = bytes(0.5);
+ manager.onExceededDatabaseQuota("1", "5", originQuota, database5EstimatedSize,
+ totalUsedQuota, mQuotaUpdater);
+ assertEquals(database1EstimatedSize + database2EstimatedSize + database4EstimatedSize +
+ bytes(1) + database5EstimatedSize, mNewQuota);
+ }
}