Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | /** |
michael@0 | 5 | * What this is aimed to test: |
michael@0 | 6 | * |
michael@0 | 7 | * Expiration can be manually triggered through a debug topic, but that should |
michael@0 | 8 | * only expire orphan entries, unless -1 is passed as limit. |
michael@0 | 9 | */ |
michael@0 | 10 | |
michael@0 | 11 | let gNow = getExpirablePRTime(); |
michael@0 | 12 | |
michael@0 | 13 | add_task(function test_expire_orphans() |
michael@0 | 14 | { |
michael@0 | 15 | // Add visits to 2 pages and force a orphan expiration. Visits should survive. |
michael@0 | 16 | yield promiseAddVisits({ uri: uri("http://page1.mozilla.org/"), |
michael@0 | 17 | visitDate: gNow++ }); |
michael@0 | 18 | yield promiseAddVisits({ uri: uri("http://page2.mozilla.org/"), |
michael@0 | 19 | visitDate: gNow++ }); |
michael@0 | 20 | // Create a orphan place. |
michael@0 | 21 | let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, |
michael@0 | 22 | NetUtil.newURI("http://page3.mozilla.org/"), |
michael@0 | 23 | PlacesUtils.bookmarks.DEFAULT_INDEX, ""); |
michael@0 | 24 | PlacesUtils.bookmarks.removeItem(id); |
michael@0 | 25 | |
michael@0 | 26 | // Expire now. |
michael@0 | 27 | yield promiseForceExpirationStep(0); |
michael@0 | 28 | |
michael@0 | 29 | // Check that visits survived. |
michael@0 | 30 | do_check_eq(visits_in_database("http://page1.mozilla.org/"), 1); |
michael@0 | 31 | do_check_eq(visits_in_database("http://page2.mozilla.org/"), 1); |
michael@0 | 32 | do_check_false(page_in_database("http://page3.mozilla.org/")); |
michael@0 | 33 | |
michael@0 | 34 | // Clean up. |
michael@0 | 35 | yield promiseClearHistory(); |
michael@0 | 36 | }); |
michael@0 | 37 | |
michael@0 | 38 | add_task(function test_expire_orphans_optionalarg() |
michael@0 | 39 | { |
michael@0 | 40 | // Add visits to 2 pages and force a orphan expiration. Visits should survive. |
michael@0 | 41 | yield promiseAddVisits({ uri: uri("http://page1.mozilla.org/"), |
michael@0 | 42 | visitDate: gNow++ }); |
michael@0 | 43 | yield promiseAddVisits({ uri: uri("http://page2.mozilla.org/"), |
michael@0 | 44 | visitDate: gNow++ }); |
michael@0 | 45 | // Create a orphan place. |
michael@0 | 46 | let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, |
michael@0 | 47 | NetUtil.newURI("http://page3.mozilla.org/"), |
michael@0 | 48 | PlacesUtils.bookmarks.DEFAULT_INDEX, ""); |
michael@0 | 49 | PlacesUtils.bookmarks.removeItem(id); |
michael@0 | 50 | |
michael@0 | 51 | // Expire now. |
michael@0 | 52 | yield promiseForceExpirationStep(); |
michael@0 | 53 | |
michael@0 | 54 | // Check that visits survived. |
michael@0 | 55 | do_check_eq(visits_in_database("http://page1.mozilla.org/"), 1); |
michael@0 | 56 | do_check_eq(visits_in_database("http://page2.mozilla.org/"), 1); |
michael@0 | 57 | do_check_false(page_in_database("http://page3.mozilla.org/")); |
michael@0 | 58 | |
michael@0 | 59 | // Clean up. |
michael@0 | 60 | yield promiseClearHistory(); |
michael@0 | 61 | }); |
michael@0 | 62 | |
michael@0 | 63 | add_task(function test_expire_limited() |
michael@0 | 64 | { |
michael@0 | 65 | // Add visits to 2 pages and force a single expiration. |
michael@0 | 66 | // Only 1 page should survive. |
michael@0 | 67 | yield promiseAddVisits({ uri: uri("http://page1.mozilla.org/"), |
michael@0 | 68 | visitDate: gNow++ }); |
michael@0 | 69 | yield promiseAddVisits({ uri: uri("http://page2.mozilla.org/"), |
michael@0 | 70 | visitDate: gNow++ }); |
michael@0 | 71 | |
michael@0 | 72 | // Expire now. |
michael@0 | 73 | yield promiseForceExpirationStep(1); |
michael@0 | 74 | |
michael@0 | 75 | // Check that visits to the more recent page survived. |
michael@0 | 76 | do_check_false(page_in_database("http://page1.mozilla.org/")); |
michael@0 | 77 | do_check_eq(visits_in_database("http://page2.mozilla.org/"), 1); |
michael@0 | 78 | |
michael@0 | 79 | // Clean up. |
michael@0 | 80 | yield promiseClearHistory(); |
michael@0 | 81 | }); |
michael@0 | 82 | |
michael@0 | 83 | add_task(function test_expire_unlimited() |
michael@0 | 84 | { |
michael@0 | 85 | // Add visits to 2 pages and force a single expiration. |
michael@0 | 86 | // Only 1 page should survive. |
michael@0 | 87 | yield promiseAddVisits({ uri: uri("http://page1.mozilla.org/"), |
michael@0 | 88 | visitDate: gNow++ }); |
michael@0 | 89 | yield promiseAddVisits({ uri: uri("http://page2.mozilla.org/"), |
michael@0 | 90 | visitDate: gNow++ }); |
michael@0 | 91 | |
michael@0 | 92 | // Expire now. |
michael@0 | 93 | yield promiseForceExpirationStep(-1); |
michael@0 | 94 | |
michael@0 | 95 | // Check that visits to the more recent page survived. |
michael@0 | 96 | do_check_false(page_in_database("http://page1.mozilla.org/")); |
michael@0 | 97 | do_check_false(page_in_database("http://page2.mozilla.org/")); |
michael@0 | 98 | |
michael@0 | 99 | // Clean up. |
michael@0 | 100 | yield promiseClearHistory(); |
michael@0 | 101 | }); |
michael@0 | 102 | |
michael@0 | 103 | function run_test() |
michael@0 | 104 | { |
michael@0 | 105 | // Set interval to a large value so we don't expire on it. |
michael@0 | 106 | setInterval(3600); // 1h |
michael@0 | 107 | // Set maxPages to a low value, so it's easy to go over it. |
michael@0 | 108 | setMaxPages(1); |
michael@0 | 109 | |
michael@0 | 110 | run_next_test(); |
michael@0 | 111 | } |