michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: function run_test() { michael@0: run_next_test(); michael@0: } michael@0: michael@0: // Each of these tests a path that triggers a frecency update. Together they michael@0: // hit all sites that update a frecency. michael@0: michael@0: // InsertVisitedURIs::UpdateFrecency and History::InsertPlace michael@0: add_task(function test_InsertVisitedURIs_UpdateFrecency_and_History_InsertPlace() { michael@0: // InsertPlace is at the end of a path that UpdateFrecency is also on, so kill michael@0: // two birds with one stone and expect two notifications. Trigger the path by michael@0: // adding a download. michael@0: let uri = NetUtil.newURI("http://example.com/a"); michael@0: Cc["@mozilla.org/browser/download-history;1"]. michael@0: getService(Ci.nsIDownloadHistory). michael@0: addDownload(uri); michael@0: yield Promise.all([onFrecencyChanged(uri), onFrecencyChanged(uri)]); michael@0: }); michael@0: michael@0: // nsNavHistory::UpdateFrecency michael@0: add_task(function test_nsNavHistory_UpdateFrecency() { michael@0: let bm = PlacesUtils.bookmarks; michael@0: let uri = NetUtil.newURI("http://example.com/b"); michael@0: bm.insertBookmark(bm.unfiledBookmarksFolder, uri, michael@0: Ci.nsINavBookmarksService.DEFAULT_INDEX, "test"); michael@0: yield onFrecencyChanged(uri); michael@0: }); michael@0: michael@0: // nsNavHistory::invalidateFrecencies for particular pages michael@0: add_task(function test_nsNavHistory_invalidateFrecencies_somePages() { michael@0: let uri = NetUtil.newURI("http://test-nsNavHistory-invalidateFrecencies-somePages.com/"); michael@0: // Bookmarking the URI is enough to add it to moz_places, and importantly, it michael@0: // means that removePagesFromHost doesn't remove it from moz_places, so its michael@0: // frecency is able to be changed. michael@0: let bm = PlacesUtils.bookmarks; michael@0: bm.insertBookmark(bm.unfiledBookmarksFolder, uri, michael@0: Ci.nsINavBookmarksService.DEFAULT_INDEX, "test"); michael@0: PlacesUtils.history.removePagesFromHost(uri.host, false); michael@0: yield onFrecencyChanged(uri); michael@0: }); michael@0: michael@0: // nsNavHistory::invalidateFrecencies for all pages michael@0: add_task(function test_nsNavHistory_invalidateFrecencies_allPages() { michael@0: PlacesUtils.history.removeAllPages(); michael@0: yield onManyFrecenciesChanged(); michael@0: }); michael@0: michael@0: // nsNavHistory::DecayFrecency and nsNavHistory::FixInvalidFrecencies michael@0: add_task(function test_nsNavHistory_DecayFrecency_and_nsNavHistory_FixInvalidFrecencies() { michael@0: // FixInvalidFrecencies is at the end of a path that DecayFrecency is also on, michael@0: // so expect two notifications. Trigger the path by making nsNavHistory michael@0: // observe the idle-daily notification. michael@0: PlacesUtils.history.QueryInterface(Ci.nsIObserver). michael@0: observe(null, "idle-daily", ""); michael@0: yield Promise.all([onManyFrecenciesChanged(), onManyFrecenciesChanged()]); michael@0: }); michael@0: michael@0: function onFrecencyChanged(expectedURI) { michael@0: let deferred = Promise.defer(); michael@0: let obs = new NavHistoryObserver(); michael@0: obs.onFrecencyChanged = michael@0: (uri, newFrecency, guid, hidden, visitDate) => { michael@0: PlacesUtils.history.removeObserver(obs); michael@0: do_check_true(!!uri); michael@0: do_check_true(uri.equals(expectedURI)); michael@0: deferred.resolve(); michael@0: }; michael@0: PlacesUtils.history.addObserver(obs, false); michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function onManyFrecenciesChanged() { michael@0: let deferred = Promise.defer(); michael@0: let obs = new NavHistoryObserver(); michael@0: obs.onManyFrecenciesChanged = () => { michael@0: PlacesUtils.history.removeObserver(obs); michael@0: do_check_true(true); michael@0: deferred.resolve(); michael@0: }; michael@0: PlacesUtils.history.addObserver(obs, false); michael@0: return deferred.promise; michael@0: }