toolkit/components/places/tests/expiration/test_debug_expiration.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/places/tests/expiration/test_debug_expiration.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,111 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +/**
     1.8 + * What this is aimed to test:
     1.9 + *
    1.10 + * Expiration can be manually triggered through a debug topic, but that should
    1.11 + * only expire orphan entries, unless -1 is passed as limit.
    1.12 + */
    1.13 +
    1.14 +let gNow = getExpirablePRTime();
    1.15 +
    1.16 +add_task(function test_expire_orphans()
    1.17 +{
    1.18 +  // Add visits to 2 pages and force a orphan expiration. Visits should survive.
    1.19 +  yield promiseAddVisits({ uri: uri("http://page1.mozilla.org/"),
    1.20 +                           visitDate: gNow++ });
    1.21 +  yield promiseAddVisits({ uri: uri("http://page2.mozilla.org/"),
    1.22 +                           visitDate: gNow++ });
    1.23 +  // Create a orphan place.
    1.24 +  let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
    1.25 +                                                NetUtil.newURI("http://page3.mozilla.org/"),
    1.26 +                                                PlacesUtils.bookmarks.DEFAULT_INDEX, "");
    1.27 +  PlacesUtils.bookmarks.removeItem(id);
    1.28 +
    1.29 +  // Expire now.
    1.30 +  yield promiseForceExpirationStep(0);
    1.31 +
    1.32 +  // Check that visits survived.
    1.33 +  do_check_eq(visits_in_database("http://page1.mozilla.org/"), 1);
    1.34 +  do_check_eq(visits_in_database("http://page2.mozilla.org/"), 1);
    1.35 +  do_check_false(page_in_database("http://page3.mozilla.org/"));
    1.36 +
    1.37 +  // Clean up.
    1.38 +  yield promiseClearHistory();
    1.39 +});
    1.40 +
    1.41 +add_task(function test_expire_orphans_optionalarg()
    1.42 +{
    1.43 +  // Add visits to 2 pages and force a orphan expiration. Visits should survive.
    1.44 +  yield promiseAddVisits({ uri: uri("http://page1.mozilla.org/"),
    1.45 +                           visitDate: gNow++ });
    1.46 +  yield promiseAddVisits({ uri: uri("http://page2.mozilla.org/"),
    1.47 +                           visitDate: gNow++ });
    1.48 +  // Create a orphan place.
    1.49 +  let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
    1.50 +                                                NetUtil.newURI("http://page3.mozilla.org/"),
    1.51 +                                                PlacesUtils.bookmarks.DEFAULT_INDEX, "");
    1.52 +  PlacesUtils.bookmarks.removeItem(id);
    1.53 +
    1.54 +  // Expire now.
    1.55 +  yield promiseForceExpirationStep();
    1.56 +
    1.57 +  // Check that visits survived.
    1.58 +  do_check_eq(visits_in_database("http://page1.mozilla.org/"), 1);
    1.59 +  do_check_eq(visits_in_database("http://page2.mozilla.org/"), 1);
    1.60 +  do_check_false(page_in_database("http://page3.mozilla.org/"));
    1.61 +
    1.62 +  // Clean up.
    1.63 +  yield promiseClearHistory();
    1.64 +});
    1.65 +
    1.66 +add_task(function test_expire_limited()
    1.67 +{
    1.68 +  // Add visits to 2 pages and force a single expiration.
    1.69 +  // Only 1 page should survive.
    1.70 +  yield promiseAddVisits({ uri: uri("http://page1.mozilla.org/"),
    1.71 +                           visitDate: gNow++ });
    1.72 +  yield promiseAddVisits({ uri: uri("http://page2.mozilla.org/"),
    1.73 +                           visitDate: gNow++ });
    1.74 +
    1.75 +  // Expire now.
    1.76 +  yield promiseForceExpirationStep(1);
    1.77 +
    1.78 +  // Check that visits to the more recent page survived.
    1.79 +  do_check_false(page_in_database("http://page1.mozilla.org/"));
    1.80 +  do_check_eq(visits_in_database("http://page2.mozilla.org/"), 1);
    1.81 +
    1.82 +  // Clean up.
    1.83 +  yield promiseClearHistory();
    1.84 +});
    1.85 +
    1.86 +add_task(function test_expire_unlimited()
    1.87 +{
    1.88 +  // Add visits to 2 pages and force a single expiration.
    1.89 +  // Only 1 page should survive.
    1.90 +  yield promiseAddVisits({ uri: uri("http://page1.mozilla.org/"),
    1.91 +                           visitDate: gNow++ });
    1.92 +  yield promiseAddVisits({ uri: uri("http://page2.mozilla.org/"),
    1.93 +                           visitDate: gNow++ });
    1.94 +
    1.95 +  // Expire now.
    1.96 +  yield promiseForceExpirationStep(-1);
    1.97 +
    1.98 +  // Check that visits to the more recent page survived.
    1.99 +  do_check_false(page_in_database("http://page1.mozilla.org/"));
   1.100 +  do_check_false(page_in_database("http://page2.mozilla.org/"));
   1.101 +
   1.102 +  // Clean up.
   1.103 +  yield promiseClearHistory();
   1.104 +});
   1.105 +
   1.106 +function run_test()
   1.107 +{
   1.108 +  // Set interval to a large value so we don't expire on it.
   1.109 +  setInterval(3600); // 1h
   1.110 +  // Set maxPages to a low value, so it's easy to go over it.
   1.111 +  setMaxPages(1);
   1.112 +
   1.113 +  run_next_test();
   1.114 +}

mercurial