Bug 407018 expiration not using browser.history_expire_days_min (r=sspitzer,a=mconnor)
authordietrich@mozilla.com
Wed, 05 Dec 2007 13:30:37 -0800
changeset 8775 2a852ed00b67a75ae064b7d17f78a471f9f2b036
parent 8774 f7f99c8f89fa18f9bd2b6006fe8653ba0f753792
child 8776 3d0117dce6da499e518e619c2336759a72d5446c
push idunknown
push userunknown
push dateunknown
reviewerssspitzer, mconnor
bugs407018
milestone1.9b2pre
Bug 407018 expiration not using browser.history_expire_days_min (r=sspitzer,a=mconnor)
toolkit/components/places/src/nsNavHistoryExpire.cpp
toolkit/components/places/tests/unit/test_expiration.js
--- a/toolkit/components/places/src/nsNavHistoryExpire.cpp
+++ b/toolkit/components/places/src/nsNavHistoryExpire.cpp
@@ -474,26 +474,28 @@ nsNavHistoryExpire::FindVisits(PRTime aE
     // records above the cap.
     sqlMinAge.AppendLiteral("WHERE v.visit_date < ?1 "
                             "ORDER BY v.visit_date DESC LIMIT ?2 OFFSET ?3");
 
     nsCOMPtr<mozIStorageStatement> selectMinStatement;
     nsresult rv = aConnection->CreateStatement(sqlMinAge, getter_AddRefs(selectMinStatement));
     NS_ENSURE_SUCCESS(rv, rv);
 
-    rv = selectStatement->BindInt64Parameter(0, aExpireThreshold);
+    PRInt64 minDaysAgo = mHistory->mExpireDaysMin * 86400 * PR_USEC_PER_SEC;
+    PRTime minThreshold = PR_Now() - minDaysAgo;
+    rv = selectMinStatement->BindInt64Parameter(0, minThreshold);
     NS_ENSURE_SUCCESS(rv, rv);
-    rv = selectStatement->BindInt64Parameter(1, aNumToExpire);
+    rv = selectMinStatement->BindInt64Parameter(1, aNumToExpire);
     NS_ENSURE_SUCCESS(rv, rv);
-    rv = selectStatement->BindInt32Parameter(2, mHistory->mExpireSites);
+    rv = selectMinStatement->BindInt32Parameter(2, mHistory->mExpireSites);
     NS_ENSURE_SUCCESS(rv, rv);
 
     hasMore = PR_FALSE;
-    while (NS_SUCCEEDED(selectStatement->ExecuteStep(&hasMore)) && hasMore) {
-      nsNavHistoryExpireRecord record(selectStatement);
+    while (NS_SUCCEEDED(selectMinStatement->ExecuteStep(&hasMore)) && hasMore) {
+      nsNavHistoryExpireRecord record(selectMinStatement);
       aRecords.AppendElement(record);
     }
   }
 
   return NS_OK;
 }
 
 
--- a/toolkit/components/places/tests/unit/test_expiration.js
+++ b/toolkit/components/places/tests/unit/test_expiration.js
@@ -528,45 +528,48 @@ steps:
   - set browser.history_expire_sites to 2
   - kick off incremental expiration
 
 confirmation:
   - check onPageExpired, confirm nothing was expired
   - query for the visit, confirm it's there
 */
 function startExpireDaysOnly() {
-  dump("startExpireDaysOnly()\n");
   // setup
   histsvc.removeAllPages();
   observer.expiredURI = null;
 
+  dump("startExpireDaysOnly()\n");
+
   // add expirable visit
   histsvc.addVisit(testURI, (Date.now() - (86400 * 2 * 1000)) * 1000, 0, histsvc.TRANSITION_TYPED, false, 0);
   annosvc.setPageAnnotation(testURI, testAnnoName, testAnnoVal, 0, annosvc.EXPIRE_WITH_HISTORY);
 
   // add un-expirable visit
   histsvc.addVisit(uri("http://unexpirable.com"), (Date.now() - (86400 * 1000)) * 1000, 0, histsvc.TRANSITION_TYPED, false, 0);
 
   // set visit cap to 2
   prefs.setIntPref("browser.history_expire_sites", 2);
   // set date minimum to 2
-  prefs.setIntPref("browser.history_expire_days", 2);
+  prefs.setIntPref("browser.history_expire_days_min", 2);
+  // set date maximum to 3
+  prefs.setIntPref("browser.history_expire_days", 3);
 
   // trigger expiration
   ghist.addURI(triggerURI, false, true, null); 
 
   // setup confirmation
   do_timeout(3600, "checkExpireDaysOnly();"); // incremental expiration timer is 3500
 }
 
 function checkExpireDaysOnly() {
   try {
     // test expired record
-    do_check_eq(observer.expiredURI, testURI.spec);
-    do_check_eq(annosvc.getPageAnnotationNames(testURI, {}).length, 0);
+    do_check_eq(observer.expiredURI, null);
+    do_check_eq(annosvc.getPageAnnotationNames(testURI, {}).length, 1);
     // test unexpired record
     do_check_neq(histsvc.getPageTitle(uri("http://unexpirable.com")), null);
   } catch(ex) {}
   dump("done expiration test 2\n");
   startExpireBoth();
 }
 
 /*
@@ -586,35 +589,35 @@ steps:
   - set browser.history_expire_sites to 1
   - kick off incremental expiration
 
 confirmation:
   - check onPageExpired, confirm our visit was expired
   - query for the visit, confirm it's not there
 */
 function startExpireBoth() {
-  dump("starting expiration test 3: both criteria met\n");
   // setup
   histsvc.removeAllPages();
   observer.expiredURI = null;
+  dump("starting expiration test 3: both criteria met\n");
 
   // add visits
   // 2 days old, in microseconds
   var age = (Date.now() - (86400 * 2 * 1000)) * 1000;
   dump("AGE: " + age + "\n");
   histsvc.addVisit(testURI, age, 0, histsvc.TRANSITION_TYPED, false, 0);
   histsvc.addVisit(testURI, age, 0, histsvc.TRANSITION_TYPED, false, 0);
   annosvc.setPageAnnotation(testURI, testAnnoName, testAnnoVal, 0, annosvc.EXPIRE_WITH_HISTORY);
 
   // set visit cap to 1
   prefs.setIntPref("browser.history_expire_sites", 1);
   // set date max to 3
   prefs.setIntPref("browser.history_expire_days", 3);
   // set date minimum to 1
-  prefs.setIntPref("browser.history_expire_days", 1);
+  prefs.setIntPref("browser.history_expire_days_min", 1);
 
   // trigger expiration
   ghist.addURI(triggerURI, false, true, null);
 
   // setup confirmation
   do_timeout(3600, "checkExpireBoth();"); // incremental expiration timer is 3500
 }