From a57ccb9e7aa7e6d30c74173705ccf40ef33e3bf5 Mon Sep 17 00:00:00 2001 From: Marco Bonardo Date: Fri, 12 Sep 2014 20:49:02 +0200 Subject: [PATCH] Bug 1065633 - Intermittent test_removeVisitsByTimeframe.js. r=post-facto --- .../unit/test_removeVisitsByTimeframe.js | 693 ++++++++---------- 1 file changed, 318 insertions(+), 375 deletions(-) diff --git a/toolkit/components/places/tests/unit/test_removeVisitsByTimeframe.js b/toolkit/components/places/tests/unit/test_removeVisitsByTimeframe.js index caa02b44a15..ae02d4ab8dc 100644 --- a/toolkit/components/places/tests/unit/test_removeVisitsByTimeframe.js +++ b/toolkit/components/places/tests/unit/test_removeVisitsByTimeframe.js @@ -4,386 +4,329 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -const bmsvc = PlacesUtils.bookmarks; -const histsvc = PlacesUtils.history; - const NOW = Date.now() * 1000; -const TEST_URL = "http://example.com/"; -const TEST_URI = uri(TEST_URL); -const PLACE_URL = "place:queryType=0&sort=8&maxResults=10"; -const PLACE_URI = uri(PLACE_URL); +const TEST_URI = uri("http://example.com/"); +const PLACE_URI = uri("place:queryType=0&sort=8&maxResults=10"); -var tests = [ - { - desc: "Remove some visits outside valid timeframe from an unbookmarked URI", - run: function () { - print("Add 10 visits for the URI from way in the past."); - let visits = []; - for (let i = 0; i < 10; i++) { - visits.push({ uri: TEST_URI, visitDate: NOW - 1000 - i }); - } - promiseAddVisits(visits).then(this.continue_run.bind(this)); - }, - continue_run: function () { - print("Remove visits using timerange outside the URI's visits."); - histsvc.QueryInterface(Ci.nsIBrowserHistory). - removeVisitsByTimeframe(NOW - 10, NOW); +function* cleanup() { + yield promiseClearHistory(); + remove_all_bookmarks(); + // This is needed to remove place: entries. + DBConn().executeSimpleSQL("DELETE FROM moz_places"); +} - print("URI should still exist in moz_places."); - do_check_true(page_in_database(TEST_URL)); - - print("Run a history query and check that all visits still exist."); - var query = histsvc.getNewQuery(); - var opts = histsvc.getNewQueryOptions(); - opts.resultType = opts.RESULTS_AS_VISIT; - opts.sortingMode = opts.SORT_BY_DATE_DESCENDING; - var resultRoot = histsvc.executeQuery(query, opts).root; - resultRoot.containerOpen = true; - do_check_eq(resultRoot.childCount, 10); - for (let i = 0; i < resultRoot.childCount; i++) { - var visitTime = resultRoot.getChild(i).time; - do_check_eq(visitTime, NOW - 1000 - i); - } - resultRoot.containerOpen = false; - - print("asyncHistory.isURIVisited should return true."); - PlacesUtils.asyncHistory.isURIVisited(TEST_URI, function(aURI, aIsVisited) { - do_check_true(aIsVisited); - - promiseAsyncUpdates().then(function () { - print("Frecency should be positive.") - do_check_true(frecencyForUrl(TEST_URI) > 0); - run_next_test(); - }); - }); - } - }, - - { - desc: "Remove some visits outside valid timeframe from a bookmarked URI", - run: function () { - print("Add 10 visits for the URI from way in the past."); - let visits = []; - for (let i = 0; i < 10; i++) { - visits.push({ uri: TEST_URI, visitDate: NOW - 1000 - i }); - } - promiseAddVisits(visits).then(function () { - print("Bookmark the URI."); - bmsvc.insertBookmark(bmsvc.unfiledBookmarksFolder, - TEST_URI, - bmsvc.DEFAULT_INDEX, - "bookmark title"); - - promiseAsyncUpdates().then(this.continue_run.bind(this)); - }.bind(this)); - }, - continue_run: function () { - print("Remove visits using timerange outside the URI's visits."); - histsvc.QueryInterface(Ci.nsIBrowserHistory). - removeVisitsByTimeframe(NOW - 10, NOW); - - print("URI should still exist in moz_places."); - do_check_true(page_in_database(TEST_URL)); - - print("Run a history query and check that all visits still exist."); - var query = histsvc.getNewQuery(); - var opts = histsvc.getNewQueryOptions(); - opts.resultType = opts.RESULTS_AS_VISIT; - opts.sortingMode = opts.SORT_BY_DATE_DESCENDING; - var resultRoot = histsvc.executeQuery(query, opts).root; - resultRoot.containerOpen = true; - do_check_eq(resultRoot.childCount, 10); - for (let i = 0; i < resultRoot.childCount; i++) { - var visitTime = resultRoot.getChild(i).time; - do_check_eq(visitTime, NOW - 1000 - i); - } - resultRoot.containerOpen = false; - - print("asyncHistory.isURIVisited should return true."); - PlacesUtils.asyncHistory.isURIVisited(TEST_URI, function(aURI, aIsVisited) { - do_check_true(aIsVisited); - - promiseAsyncUpdates().then(function () { - print("Frecency should be positive.") - do_check_true(frecencyForUrl(TEST_URI) > 0); - run_next_test(); - }); - }); - } - }, - - { - desc: "Remove some visits from an unbookmarked URI", - run: function () { - print("Add 10 visits for the URI from now to 9 usecs in the past."); - let visits = []; - for (let i = 0; i < 10; i++) { - visits.push({ uri: TEST_URI, visitDate: NOW - i }); - } - promiseAddVisits(visits).then(this.continue_run.bind(this)); - }, - continue_run: function () { - print("Remove the 5 most recent visits."); - histsvc.QueryInterface(Ci.nsIBrowserHistory). - removeVisitsByTimeframe(NOW - 4, NOW); - - print("URI should still exist in moz_places."); - do_check_true(page_in_database(TEST_URL)); - - print("Run a history query and check that only the older 5 visits " + - "still exist."); - var query = histsvc.getNewQuery(); - var opts = histsvc.getNewQueryOptions(); - opts.resultType = opts.RESULTS_AS_VISIT; - opts.sortingMode = opts.SORT_BY_DATE_DESCENDING; - var resultRoot = histsvc.executeQuery(query, opts).root; - resultRoot.containerOpen = true; - do_check_eq(resultRoot.childCount, 5); - for (let i = 0; i < resultRoot.childCount; i++) { - var visitTime = resultRoot.getChild(i).time; - do_check_eq(visitTime, NOW - i - 5); - } - resultRoot.containerOpen = false; - - print("asyncHistory.isURIVisited should return true."); - PlacesUtils.asyncHistory.isURIVisited(TEST_URI, function(aURI, aIsVisited) { - do_check_true(aIsVisited); - - promiseAsyncUpdates().then(function () { - print("Frecency should be positive.") - do_check_true(frecencyForUrl(TEST_URI) > 0); - run_next_test(); - }); - }); - } - }, - - { - desc: "Remove some visits from a bookmarked URI", - run: function () { - print("Add 10 visits for the URI from now to 9 usecs in the past."); - let visits = []; - for (let i = 0; i < 10; i++) { - visits.push({ uri: TEST_URI, visitDate: NOW - i }); - } - promiseAddVisits(visits).then(function () { - print("Bookmark the URI."); - bmsvc.insertBookmark(bmsvc.unfiledBookmarksFolder, - TEST_URI, - bmsvc.DEFAULT_INDEX, - "bookmark title"); - promiseAsyncUpdates().then(this.continue_run.bind(this)); - }.bind(this)); - }, - continue_run: function () { - print("Remove the 5 most recent visits."); - histsvc.QueryInterface(Ci.nsIBrowserHistory). - removeVisitsByTimeframe(NOW - 4, NOW); - - print("URI should still exist in moz_places."); - do_check_true(page_in_database(TEST_URL)); - - print("Run a history query and check that only the older 5 visits " + - "still exist."); - var query = histsvc.getNewQuery(); - var opts = histsvc.getNewQueryOptions(); - opts.resultType = opts.RESULTS_AS_VISIT; - opts.sortingMode = opts.SORT_BY_DATE_DESCENDING; - var resultRoot = histsvc.executeQuery(query, opts).root; - resultRoot.containerOpen = true; - do_check_eq(resultRoot.childCount, 5); - for (let i = 0; i < resultRoot.childCount; i++) { - var visitTime = resultRoot.getChild(i).time; - do_check_eq(visitTime, NOW - i - 5); - } - resultRoot.containerOpen = false; - - print("asyncHistory.isURIVisited should return true."); - PlacesUtils.asyncHistory.isURIVisited(TEST_URI, function(aURI, aIsVisited) { - do_check_true(aIsVisited); - - promiseAsyncUpdates().then(function () { - print("Frecency should be positive.") - do_check_true(frecencyForUrl(TEST_URI) > 0); - run_next_test(); - }); - }); - } - }, - - { - desc: "Remove all visits from an unbookmarked URI", - run: function () { - print("Add some visits for the URI."); - let visits = []; - for (let i = 0; i < 10; i++) { - visits.push({ uri: TEST_URI, visitDate: NOW - i }); - } - promiseAddVisits(visits).then(this.continue_run.bind(this)); - }, - continue_run: function () { - print("Remove all visits."); - histsvc.QueryInterface(Ci.nsIBrowserHistory). - removeVisitsByTimeframe(NOW - 10, NOW); - - print("URI should no longer exist in moz_places."); - do_check_false(page_in_database(TEST_URL)); - - print("Run a history query and check that no visits exist."); - var query = histsvc.getNewQuery(); - var opts = histsvc.getNewQueryOptions(); - opts.resultType = opts.RESULTS_AS_VISIT; - opts.sortingMode = opts.SORT_BY_DATE_DESCENDING; - var resultRoot = histsvc.executeQuery(query, opts).root; - resultRoot.containerOpen = true; - do_check_eq(resultRoot.childCount, 0); - resultRoot.containerOpen = false; - - print("asyncHistory.isURIVisited should return false."); - PlacesUtils.asyncHistory.isURIVisited(TEST_URI, function(aURI, aIsVisited) { - do_check_false(aIsVisited); - run_next_test(); - }); - } - }, - - { - desc: "Remove all visits from an unbookmarked place: URI", - run: function () { - print("Add some visits for the URI."); - let visits = []; - for (let i = 0; i < 10; i++) { - visits.push({ uri: PLACE_URI, visitDate: NOW - i }); - } - promiseAddVisits(visits).then(this.continue_run.bind(this)); - }, - continue_run: function () { - print("Remove all visits."); - histsvc.QueryInterface(Ci.nsIBrowserHistory). - removeVisitsByTimeframe(NOW - 10, NOW); - - print("URI should still exist in moz_places."); - do_check_true(page_in_database(PLACE_URL)); - - print("Run a history query and check that no visits exist."); - var query = histsvc.getNewQuery(); - var opts = histsvc.getNewQueryOptions(); - opts.resultType = opts.RESULTS_AS_VISIT; - opts.sortingMode = opts.SORT_BY_DATE_DESCENDING; - var resultRoot = histsvc.executeQuery(query, opts).root; - resultRoot.containerOpen = true; - do_check_eq(resultRoot.childCount, 0); - resultRoot.containerOpen = false; - - print("asyncHistory.isURIVisited should return false."); - PlacesUtils.asyncHistory.isURIVisited(PLACE_URI, function(aURI, aIsVisited) { - do_check_false(aIsVisited); - - promiseAsyncUpdates().then(function () { - print("Frecency should be zero.") - do_check_eq(frecencyForUrl(PLACE_URL), 0); - run_next_test(); - }); - }); - } - }, - - { - desc: "Remove all visits from a bookmarked URI", - run: function () { - print("Add some visits for the URI."); - let visits = []; - for (let i = 0; i < 10; i++) { - visits.push({ uri: TEST_URI, visitDate: NOW - i }); - } - promiseAddVisits(visits).then(function () { - print("Bookmark the URI."); - bmsvc.insertBookmark(bmsvc.unfiledBookmarksFolder, - TEST_URI, - bmsvc.DEFAULT_INDEX, - "bookmark title"); - promiseAsyncUpdates().then(this.continue_run.bind(this)); - }.bind(this)); - }, - continue_run: function () { - print("Remove all visits."); - histsvc.QueryInterface(Ci.nsIBrowserHistory). - removeVisitsByTimeframe(NOW - 10, NOW); - - print("URI should still exist in moz_places."); - do_check_true(page_in_database(TEST_URL)); - - print("Run a history query and check that no visits exist."); - var query = histsvc.getNewQuery(); - var opts = histsvc.getNewQueryOptions(); - opts.resultType = opts.RESULTS_AS_VISIT; - opts.sortingMode = opts.SORT_BY_DATE_DESCENDING; - var resultRoot = histsvc.executeQuery(query, opts).root; - resultRoot.containerOpen = true; - do_check_eq(resultRoot.childCount, 0); - resultRoot.containerOpen = false; - - print("asyncHistory.isURIVisited should return false."); - PlacesUtils.asyncHistory.isURIVisited(TEST_URI, function(aURI, aIsVisited) { - do_check_false(aIsVisited); - - print("nsINavBookmarksService.isBookmarked should return true."); - do_check_true(bmsvc.isBookmarked(TEST_URI)); - - promiseAsyncUpdates().then(function () { - print("Frecency should be negative.") - do_check_true(frecencyForUrl(TEST_URI) < 0); - run_next_test(); - }); - }); - } - }, - - { - desc: "Remove some visits from a zero frecency URI retains zero frecency", - run: function () { - do_log_info("Add some visits for the URI."); - promiseAddVisits([{ uri: TEST_URI, transition: TRANSITION_FRAMED_LINK, - visitDate: (NOW - 86400000000) }, - { uri: TEST_URI, transition: TRANSITION_FRAMED_LINK, - visitDate: NOW }]).then( - this.continue_run.bind(this)); - }, - continue_run: function () { - do_log_info("Remove newer visit."); - histsvc.QueryInterface(Ci.nsIBrowserHistory). - removeVisitsByTimeframe(NOW - 10, NOW); - - promiseAsyncUpdates().then(function() { - do_log_info("URI should still exist in moz_places."); - do_check_true(page_in_database(TEST_URL)); - do_log_info("Frecency should be zero.") - do_check_eq(frecencyForUrl(TEST_URI), 0); - run_next_test(); - }); - } +add_task(function remove_visits_outside_unbookmarked_uri() { + do_log_info("*** TEST: Remove some visits outside valid timeframe from an unbookmarked URI"); + + do_log_info("Add 10 visits for the URI from way in the past."); + let visits = []; + for (let i = 0; i < 10; i++) { + visits.push({ uri: TEST_URI, visitDate: NOW - 1000 - i }); } -]; + yield promiseAddVisits(visits); -/////////////////////////////////////////////////////////////////////////////// + do_log_info("Remove visits using timerange outside the URI's visits."); + PlacesUtils.history.removeVisitsByTimeframe(NOW - 10, NOW); + yield promiseAsyncUpdates(); -function run_test() -{ - do_test_pending(); + do_log_info("URI should still exist in moz_places."); + do_check_true(page_in_database(TEST_URI.spec)); + + do_log_info("Run a history query and check that all visits still exist."); + let query = PlacesUtils.history.getNewQuery(); + let opts = PlacesUtils.history.getNewQueryOptions(); + opts.resultType = opts.RESULTS_AS_VISIT; + opts.sortingMode = opts.SORT_BY_DATE_DESCENDING; + let root = PlacesUtils.history.executeQuery(query, opts).root; + root.containerOpen = true; + do_check_eq(root.childCount, 10); + for (let i = 0; i < root.childCount; i++) { + let visitTime = root.getChild(i).time; + do_check_eq(visitTime, NOW - 1000 - i); + } + root.containerOpen = false; + + do_log_info("asyncHistory.isURIVisited should return true."); + do_check_true(yield promiseIsURIVisited(TEST_URI)); + + yield promiseAsyncUpdates(); + do_log_info("Frecency should be positive.") + do_check_true(frecencyForUrl(TEST_URI) > 0); + + yield cleanup(); +}); + +add_task(function remove_visits_outside_bookmarked_uri() { + do_log_info("*** TEST: Remove some visits outside valid timeframe from a bookmarked URI"); + + do_log_info("Add 10 visits for the URI from way in the past."); + let visits = []; + for (let i = 0; i < 10; i++) { + visits.push({ uri: TEST_URI, visitDate: NOW - 1000 - i }); + } + yield promiseAddVisits(visits); + do_log_info("Bookmark the URI."); + PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, + TEST_URI, + PlacesUtils.bookmarks.DEFAULT_INDEX, + "bookmark title"); + yield promiseAsyncUpdates(); + + do_log_info("Remove visits using timerange outside the URI's visits."); + PlacesUtils.history.removeVisitsByTimeframe(NOW - 10, NOW); + yield promiseAsyncUpdates(); + + do_log_info("URI should still exist in moz_places."); + do_check_true(page_in_database(TEST_URI.spec)); + + do_log_info("Run a history query and check that all visits still exist."); + let query = PlacesUtils.history.getNewQuery(); + let opts = PlacesUtils.history.getNewQueryOptions(); + opts.resultType = opts.RESULTS_AS_VISIT; + opts.sortingMode = opts.SORT_BY_DATE_DESCENDING; + let root = PlacesUtils.history.executeQuery(query, opts).root; + root.containerOpen = true; + do_check_eq(root.childCount, 10); + for (let i = 0; i < root.childCount; i++) { + let visitTime = root.getChild(i).time; + do_check_eq(visitTime, NOW - 1000 - i); + } + root.containerOpen = false; + + do_log_info("asyncHistory.isURIVisited should return true."); + do_check_true(yield promiseIsURIVisited(TEST_URI)); + yield promiseAsyncUpdates(); + + do_log_info("Frecency should be positive.") + do_check_true(frecencyForUrl(TEST_URI) > 0); + + yield cleanup(); +}); + +add_task(function remove_visits_unbookmarked_uri() { + do_log_info("*** TEST: Remove some visits from an unbookmarked URI"); + + do_log_info("Add 10 visits for the URI from now to 9 usecs in the past."); + let visits = []; + for (let i = 0; i < 10; i++) { + visits.push({ uri: TEST_URI, visitDate: NOW - i }); + } + yield promiseAddVisits(visits); + + do_log_info("Remove the 5 most recent visits."); + PlacesUtils.history.removeVisitsByTimeframe(NOW - 4, NOW); + yield promiseAsyncUpdates(); + + do_log_info("URI should still exist in moz_places."); + do_check_true(page_in_database(TEST_URI.spec)); + + do_log_info("Run a history query and check that only the older 5 visits still exist."); + let query = PlacesUtils.history.getNewQuery(); + let opts = PlacesUtils.history.getNewQueryOptions(); + opts.resultType = opts.RESULTS_AS_VISIT; + opts.sortingMode = opts.SORT_BY_DATE_DESCENDING; + let root = PlacesUtils.history.executeQuery(query, opts).root; + root.containerOpen = true; + do_check_eq(root.childCount, 5); + for (let i = 0; i < root.childCount; i++) { + let visitTime = root.getChild(i).time; + do_check_eq(visitTime, NOW - i - 5); + } + root.containerOpen = false; + + do_log_info("asyncHistory.isURIVisited should return true."); + do_check_true(yield promiseIsURIVisited(TEST_URI)); + yield promiseAsyncUpdates(); + + do_log_info("Frecency should be positive.") + do_check_true(frecencyForUrl(TEST_URI) > 0); + + yield cleanup(); +}); + +add_task(function remove_visits_bookmarked_uri() { + do_log_info("*** TEST: Remove some visits from a bookmarked URI"); + + do_log_info("Add 10 visits for the URI from now to 9 usecs in the past."); + let visits = []; + for (let i = 0; i < 10; i++) { + visits.push({ uri: TEST_URI, visitDate: NOW - i }); + } + yield promiseAddVisits(visits); + do_log_info("Bookmark the URI."); + PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, + TEST_URI, + PlacesUtils.bookmarks.DEFAULT_INDEX, + "bookmark title"); + yield promiseAsyncUpdates(); + + do_log_info("Remove the 5 most recent visits."); + PlacesUtils.history.removeVisitsByTimeframe(NOW - 4, NOW); + yield promiseAsyncUpdates(); + + do_log_info("URI should still exist in moz_places."); + do_check_true(page_in_database(TEST_URI.spec)); + + do_log_info("Run a history query and check that only the older 5 visits still exist."); + let query = PlacesUtils.history.getNewQuery(); + let opts = PlacesUtils.history.getNewQueryOptions(); + opts.resultType = opts.RESULTS_AS_VISIT; + opts.sortingMode = opts.SORT_BY_DATE_DESCENDING; + let root = PlacesUtils.history.executeQuery(query, opts).root; + root.containerOpen = true; + do_check_eq(root.childCount, 5); + for (let i = 0; i < root.childCount; i++) { + let visitTime = root.getChild(i).time; + do_check_eq(visitTime, NOW - i - 5); + } + root.containerOpen = false; + + do_log_info("asyncHistory.isURIVisited should return true."); + do_check_true(yield promiseIsURIVisited(TEST_URI)); + yield promiseAsyncUpdates() + + do_log_info("Frecency should be positive.") + do_check_true(frecencyForUrl(TEST_URI) > 0); + + yield cleanup(); +}); + +add_task(function remove_all_visits_unbookmarked_uri() { + do_log_info("*** TEST: Remove all visits from an unbookmarked URI"); + + do_log_info("Add some visits for the URI."); + let visits = []; + for (let i = 0; i < 10; i++) { + visits.push({ uri: TEST_URI, visitDate: NOW - i }); + } + yield promiseAddVisits(visits); + + do_log_info("Remove all visits."); + PlacesUtils.history.removeVisitsByTimeframe(NOW - 10, NOW); + yield promiseAsyncUpdates(); + + do_log_info("URI should no longer exist in moz_places."); + do_check_false(page_in_database(TEST_URI.spec)); + + do_log_info("Run a history query and check that no visits exist."); + let query = PlacesUtils.history.getNewQuery(); + let opts = PlacesUtils.history.getNewQueryOptions(); + opts.resultType = opts.RESULTS_AS_VISIT; + opts.sortingMode = opts.SORT_BY_DATE_DESCENDING; + let root = PlacesUtils.history.executeQuery(query, opts).root; + root.containerOpen = true; + do_check_eq(root.childCount, 0); + root.containerOpen = false; + + do_log_info("asyncHistory.isURIVisited should return false."); + do_check_false(yield promiseIsURIVisited(TEST_URI)); + + yield cleanup(); +}); + +add_task(function remove_all_visits_unbookmarked_place_uri() { + do_log_info("*** TEST: Remove all visits from an unbookmarked place: URI"); + do_log_info("Add some visits for the URI."); + let visits = []; + for (let i = 0; i < 10; i++) { + visits.push({ uri: PLACE_URI, visitDate: NOW - i }); + } + yield promiseAddVisits(visits); + + do_log_info("Remove all visits."); + PlacesUtils.history.removeVisitsByTimeframe(NOW - 10, NOW); + yield promiseAsyncUpdates(); + + do_log_info("URI should still exist in moz_places."); + do_check_true(page_in_database(PLACE_URI.spec)); + + do_log_info("Run a history query and check that no visits exist."); + let query = PlacesUtils.history.getNewQuery(); + let opts = PlacesUtils.history.getNewQueryOptions(); + opts.resultType = opts.RESULTS_AS_VISIT; + opts.sortingMode = opts.SORT_BY_DATE_DESCENDING; + let root = PlacesUtils.history.executeQuery(query, opts).root; + root.containerOpen = true; + do_check_eq(root.childCount, 0); + root.containerOpen = false; + + do_log_info("asyncHistory.isURIVisited should return false."); + do_check_false(yield promiseIsURIVisited(PLACE_URI)); + yield promiseAsyncUpdates(); + + do_log_info("Frecency should be zero.") + do_check_eq(frecencyForUrl(PLACE_URI.spec), 0); + + yield cleanup(); +}); + +add_task(function remove_all_visits_bookmarked_uri() { + do_log_info("*** TEST: Remove all visits from a bookmarked URI"); + + do_log_info("Add some visits for the URI."); + let visits = []; + for (let i = 0; i < 10; i++) { + visits.push({ uri: TEST_URI, visitDate: NOW - i }); + } + yield promiseAddVisits(visits); + do_log_info("Bookmark the URI."); + PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, + TEST_URI, + PlacesUtils.bookmarks.DEFAULT_INDEX, + "bookmark title"); + yield promiseAsyncUpdates(); + + do_log_info("Remove all visits."); + PlacesUtils.history.removeVisitsByTimeframe(NOW - 10, NOW); + yield promiseAsyncUpdates(); + + do_log_info("URI should still exist in moz_places."); + do_check_true(page_in_database(TEST_URI.spec)); + + do_log_info("Run a history query and check that no visits exist."); + let query = PlacesUtils.history.getNewQuery(); + let opts = PlacesUtils.history.getNewQueryOptions(); + opts.resultType = opts.RESULTS_AS_VISIT; + opts.sortingMode = opts.SORT_BY_DATE_DESCENDING; + let root = PlacesUtils.history.executeQuery(query, opts).root; + root.containerOpen = true; + do_check_eq(root.childCount, 0); + root.containerOpen = false; + + do_log_info("asyncHistory.isURIVisited should return false."); + do_check_false(yield promiseIsURIVisited(TEST_URI)); + + do_log_info("nsINavBookmarksService.isBookmarked should return true."); + do_check_true(PlacesUtils.bookmarks.isBookmarked(TEST_URI)); + yield promiseAsyncUpdates(); + + do_log_info("Frecency should be negative.") + do_check_true(frecencyForUrl(TEST_URI) < 0); + + yield cleanup(); +}); + +add_task(function remove_all_visits_bookmarked_uri() { + do_log_info("*** TEST: Remove some visits from a zero frecency URI retains zero frecency"); + + do_log_info("Add some visits for the URI."); + yield promiseAddVisits([{ uri: TEST_URI, transition: TRANSITION_FRAMED_LINK, + visitDate: (NOW - 86400000000) }, + { uri: TEST_URI, transition: TRANSITION_FRAMED_LINK, + visitDate: NOW }]); + + do_log_info("Remove newer visit."); + PlacesUtils.history.removeVisitsByTimeframe(NOW - 10, NOW); + yield promiseAsyncUpdates(); + + do_log_info("URI should still exist in moz_places."); + do_check_true(page_in_database(TEST_URI.spec)); + do_log_info("Frecency should be zero.") + do_check_eq(frecencyForUrl(TEST_URI), 0); + + yield cleanup(); +}); + +function run_test() { run_next_test(); } - -function run_next_test() { - if (tests.length) { - let test = tests.shift(); - print("\n ***Test: " + test.desc); - promiseClearHistory().then(function() { - remove_all_bookmarks(); - DBConn().executeSimpleSQL("DELETE FROM moz_places"); - test.run.call(test); - }); - } - else { - do_test_finished(); - } -}