Bug 480437 - test_expiration is working on wrong assumptions, r=dietrich
authorMarco Bonardo <mbonardo@mozilla.com>
Thu, 05 Mar 2009 13:08:43 +0100
changeset 25761 255494d0952143a66d917756a2913477ec6ca360
parent 25760 480d7c7f5c38d68ad3ce27eb22e1a3efb9f1e4fd
child 25762 cf078a985bcd0b002310891df84c0b44dec66289
push id5729
push usermak77@bonardo.net
push dateThu, 05 Mar 2009 12:09:27 +0000
treeherdermozilla-central@255494d09521 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdietrich
bugs480437
milestone1.9.2a1pre
Bug 480437 - test_expiration is working on wrong assumptions, r=dietrich
toolkit/components/places/tests/unit/test_expiration.js
--- a/toolkit/components/places/tests/unit/test_expiration.js
+++ b/toolkit/components/places/tests/unit/test_expiration.js
@@ -471,16 +471,17 @@ function run_test() {
 
   startIncrementalExpirationTests();
 }
 
 // incremental expiration tests
 // run async, chained
 
 function startIncrementalExpirationTests() {
+  do_test_pending();
   startExpireNeither();
 }
 
 /*
 test 1: NO EXPIRATION CRITERIA MET (INSIDE SITES CAP)
 
 1. zero visits > {browser.history_expire_days}
 2. zero visits > {browser.history_expire_days_min}
@@ -497,44 +498,46 @@ steps:
 
 confirmation:
   - check onPageExpired, confirm nothing was expired
   - query for the visit, confirm it's there
 
 */
 function startExpireNeither() {
   dump("startExpireNeither()\n");
-  // setup
+  // Cleanup.
   histsvc.removeAllPages();
   observer.expiredURI = null;
 
-  // add data
+  // Setup data.
   histsvc.addVisit(testURI, Date.now() * 1000, null, histsvc.TRANSITION_TYPED, false, 0);
   annosvc.setPageAnnotation(testURI, testAnnoName, testAnnoVal, 0, annosvc.EXPIRE_NEVER);
+  histsvc.addVisit(triggerURI, Date.now() * 1000, null, histsvc.TRANSITION_TYPED, false, 0);
+  annosvc.setPageAnnotation(triggerURI, testAnnoName, testAnnoVal, 0, annosvc.EXPIRE_NEVER);
 
   // set sites cap to 2
   prefs.setIntPref("browser.history_expire_sites", 2);
   // set date minimum to 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); 
+  // Changing expiration preferences has already triggered expiration, it will
+  // run after the partial expiration timer (3,5s).
 
-  // setup confirmation
-  do_test_pending();
-  do_timeout(3600, "checkExpireNeither();"); // incremental expiration timer is 3500
+  // Check results.
+  do_timeout(3600, "checkExpireNeither();");
 }
 
 function checkExpireNeither() {
   dump("checkExpireNeither()\n");
   try {
     do_check_eq(observer.expiredURI, null);
     do_check_eq(annosvc.getPageAnnotationNames(testURI, {}).length, 1);
+    do_check_eq(annosvc.getPageAnnotationNames(triggerURI, {}).length, 1);
   } catch(ex) {
     do_throw(ex);
   }
   dump("done incremental expiration test 1\n");
   startExpireDaysOnly();
 }
 
 /*
@@ -553,43 +556,42 @@ steps:
   - set browser.history_expire_sites to 20
   - kick off incremental expiration
 
 confirmation:
   - check onPageExpired, confirm that the expirable uri was expired
   - query for the visit, confirm it's there
 */
 function startExpireDaysOnly() {
-  // setup
+  dump("startExpireDaysOnly()\n");
+  // Cleanup.
   histsvc.removeAllPages();
   observer.expiredURI = null;
 
-  dump("startExpireDaysOnly()\n");
-
   // add expirable visit
   histsvc.addVisit(testURI, (Date.now() - (86400 * 4 * 1000)) * 1000, null, histsvc.TRANSITION_TYPED, false, 0);
   annosvc.setPageAnnotation(testURI, testAnnoName, testAnnoVal, 0, annosvc.EXPIRE_NEVER);
 
   // add un-expirable visit
   var unexpirableURI = uri("http://unexpirable.com");
   histsvc.addVisit(unexpirableURI, (Date.now() - (86400 * 1000)) * 1000, null, histsvc.TRANSITION_TYPED, false, 0);
   annosvc.setPageAnnotation(unexpirableURI, testAnnoName, testAnnoVal, 0, annosvc.EXPIRE_NEVER);
 
   // set sites cap to 20 (make sure it's not an expiration criteria)
   prefs.setIntPref("browser.history_expire_sites", 20);
   // set date minimum to 2 (also not an expiration criteria)
   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); 
+  // Changing expiration preferences has already triggered expiration, it will
+  // run after the partial expiration timer (3,5s).
 
-  // setup confirmation
-  do_timeout(3600, "checkExpireDaysOnly();"); // incremental expiration timer is 3500
+  // Check results.
+  do_timeout(3600, "checkExpireDaysOnly();");
 }
 
 function checkExpireDaysOnly() {
   try {
     // test expired record
     do_check_eq(observer.expiredURI, testURI.spec);
     do_check_eq(annosvc.getPageAnnotationNames(testURI, {}).length, 0);
 
@@ -618,47 +620,48 @@ steps:
   - set browser.history_expire_sites to 1
   - kick off incremental expiration
 
 confirmation:
   - check onPageExpired, confirm our oldest visit was expired
   - query for the oldest visit, confirm it's not there
 */
 function startExpireBoth() {
-  // setup
+  dump("starting expiration test 3: both criteria met\n");
+  // Cleanup.
   histsvc.removeAllPages();
   observer.expiredURI = null;
-  dump("starting expiration test 3: both criteria met\n");
-  // force a sync, this will ensure that later we will have the same place in
-  // both temp and disk table, and that the expire site cap count is correct.
-  // adw: Commented out per bug 412132.  The patch to that bug made it illegal
-  // to pass bad item IDs into changeBookmarkURI; |bookmark| was removed up in
-  // run_test, and it's never added or used again.  The only thing this call
-  // ended up doing was updating testURI's frecency and notifying bookmark
-  // observers that testURI had changed.  Neither appears relevant to this test.
-  //bmsvc.changeBookmarkURI(bookmark, testURI);
+
+  // Inserting a bookmark will force a sync, this will ensure that later we will
+  // have the same place in both temp and disk table, and that the expire site
+  // cap count is correct.
+  var bmId = bmsvc.insertBookmark(bmsvc.toolbarFolder, testURI, bmsvc.DEFAULT_INDEX, "foo");
+  bmsvc.removeItem(bmId);
+
   // add visits
   // 2 days old, in microseconds
   var age = (Date.now() - (86400 * 2 * 1000)) * 1000;
   dump("AGE: " + age + "\n");
   histsvc.addVisit(testURI, age, null, histsvc.TRANSITION_TYPED, false, 0);
   annosvc.setPageAnnotation(testURI, testAnnoName, testAnnoVal, 0, annosvc.EXPIRE_NEVER);
 
+  histsvc.addVisit(triggerURI, Date.now() * 1000, null, histsvc.TRANSITION_TYPED, false, 0);
+  annosvc.setPageAnnotation(triggerURI, testAnnoName, testAnnoVal, 0, annosvc.EXPIRE_NEVER);
+
   // set sites 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_min", 1);
 
-  // trigger expiration
-  histsvc.addVisit(triggerURI, Date.now() * 1000, null, histsvc.TRANSITION_TYPED, false, 0);
-  annosvc.setPageAnnotation(triggerURI, testAnnoName, testAnnoVal, 0, annosvc.EXPIRE_NEVER);
+  // Changing expiration preferences has already triggered expiration, it will
+  // run after the partial expiration timer (3,5s).
 
-  // setup confirmation
+  // Check results.
   do_timeout(3600, "checkExpireBoth();"); // incremental expiration timer is 3500
 }
 
 function checkExpireBoth() {
   try {
     do_check_eq(observer.expiredURI, testURI.spec);
     do_check_eq(annosvc.getPageAnnotationNames(testURI, {}).length, 0);
     do_check_eq(annosvc.getPageAnnotationNames(triggerURI, {}).length, 1);
@@ -686,37 +689,39 @@ steps:
 
 confirmation:
   - check onPageExpired, confirm nothing was expired
   - query for the visit, confirm it's there
 
 */
 function startExpireNeitherOver() {
   dump("startExpireNeitherOver()\n");
-  // setup
+  // Cleanup.
   histsvc.removeAllPages();
   observer.expiredURI = null;
 
   // add data
   histsvc.addVisit(testURI, Date.now() * 1000, null, histsvc.TRANSITION_TYPED, false, 0);
   annosvc.setPageAnnotation(testURI, testAnnoName, testAnnoVal, 0, annosvc.EXPIRE_NEVER);
 
+  histsvc.addVisit(triggerURI, Date.now() * 1000, null, histsvc.TRANSITION_TYPED, false, 0);
+  annosvc.setPageAnnotation(triggerURI, testAnnoName, testAnnoVal, 0, annosvc.EXPIRE_NEVER);
+
   // set sites cap to 1
   prefs.setIntPref("browser.history_expire_sites", 1);
   // set date minimum to 2
   prefs.setIntPref("browser.history_expire_days_min", 2);
   // set date maximum to 3
   prefs.setIntPref("browser.history_expire_days", 3);
 
-  // trigger expiration
-  histsvc.addVisit(triggerURI, Date.now() * 1000, null, histsvc.TRANSITION_TYPED, false, 0);
-  annosvc.setPageAnnotation(triggerURI, testAnnoName, testAnnoVal, 0, annosvc.EXPIRE_NEVER);
+  // Changing expiration preferences has already triggered expiration, it will
+  // run after the partial expiration timer (3,5s).
 
-  // setup confirmation
-  do_timeout(3600, "checkExpireNeitherOver();"); // incremental expiration timer is 3500
+  // Check results.
+  do_timeout(3600, "checkExpireNeitherOver();");
 }
 
 function checkExpireNeitherOver() {
   dump("checkExpireNeitherOver()\n");
   try {
     do_check_eq(observer.expiredURI, null);
     do_check_eq(annosvc.getPageAnnotationNames(testURI, {}).length, 1);
     do_check_eq(annosvc.getPageAnnotationNames(triggerURI, {}).length, 1);
@@ -741,29 +746,32 @@ steps:
 
 confirmation:
   - check onPageExpired, confirm visit was expired
   - query for the visit, confirm it's not there
 
 */
 function startExpireHistoryDisabled() {
   dump("startExpireHistoryDisabled()\n");
-  // setup
+  // Cleanup.
   histsvc.removeAllPages();
   observer.expiredURI = null;
 
   // add data
   histsvc.addVisit(testURI, Date.now() * 1000, null, histsvc.TRANSITION_TYPED, false, 0);
   annosvc.setPageAnnotation(testURI, testAnnoName, testAnnoVal, 0, annosvc.EXPIRE_NEVER);
 
   // set date maximum to 0
   prefs.setIntPref("browser.history_expire_days", 0);
 
-  // setup confirmation
-  do_timeout(3600, "checkExpireHistoryDisabled();"); // incremental expiration timer is 3500
+  // Changing expiration preferences has already triggered expiration, it will
+  // run after the partial expiration timer (3,5s).
+
+  // Check results.
+  do_timeout(3600, "checkExpireHistoryDisabled();");
 }
 
 function checkExpireHistoryDisabled() {
   dump("checkExpireHistoryDisabled()\n");
   try {
     do_check_eq(observer.expiredURI, testURI.spec);
     do_check_eq(annosvc.getPageAnnotationNames(testURI, {}).length, 0);
   } catch(ex) {
@@ -788,32 +796,35 @@ steps:
 
 confirmation:
   - check onPageExpired, confirm nothing was expired
   - query for the visit, confirm it's there
 
 */
 function startExpireBadPrefs() {
   dump("startExpireBadPrefs()\n");
-  // setup
+  // Cleanup.
   histsvc.removeAllPages();
   observer.expiredURI = null;
 
   // add data
   var age = (Date.now() - (86400 * 10 * 1000)) * 1000;
   histsvc.addVisit(testURI, age, null, histsvc.TRANSITION_TYPED, false, 0);
   annosvc.setPageAnnotation(testURI, testAnnoName, testAnnoVal, 0, annosvc.EXPIRE_NEVER);
 
   // set date minimum to 20
   prefs.setIntPref("browser.history_expire_days_min", 20);
   // set date maximum to 1
   prefs.setIntPref("browser.history_expire_days", 1);
 
-  // setup confirmation
-  do_timeout(3600, "checkExpireBadPrefs();"); // incremental expiration timer is 3500
+  // Changing expiration preferences has already triggered expiration, it will
+  // run after the partial expiration timer (3,5s).
+
+  // Check results.
+  do_timeout(3600, "checkExpireBadPrefs();");
 }
 
 function checkExpireBadPrefs() {
   dump("checkExpireBadPrefs()\n");
   try {
     do_check_eq(observer.expiredURI, null);
     do_check_eq(annosvc.getPageAnnotationNames(testURI, {}).length, 1);
   } catch(ex) {