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 | function run_test() { |
michael@0 | 5 | run_next_test(); |
michael@0 | 6 | } |
michael@0 | 7 | |
michael@0 | 8 | // Each of these tests a path that triggers a frecency update. Together they |
michael@0 | 9 | // hit all sites that update a frecency. |
michael@0 | 10 | |
michael@0 | 11 | // InsertVisitedURIs::UpdateFrecency and History::InsertPlace |
michael@0 | 12 | add_task(function test_InsertVisitedURIs_UpdateFrecency_and_History_InsertPlace() { |
michael@0 | 13 | // InsertPlace is at the end of a path that UpdateFrecency is also on, so kill |
michael@0 | 14 | // two birds with one stone and expect two notifications. Trigger the path by |
michael@0 | 15 | // adding a download. |
michael@0 | 16 | let uri = NetUtil.newURI("http://example.com/a"); |
michael@0 | 17 | Cc["@mozilla.org/browser/download-history;1"]. |
michael@0 | 18 | getService(Ci.nsIDownloadHistory). |
michael@0 | 19 | addDownload(uri); |
michael@0 | 20 | yield Promise.all([onFrecencyChanged(uri), onFrecencyChanged(uri)]); |
michael@0 | 21 | }); |
michael@0 | 22 | |
michael@0 | 23 | // nsNavHistory::UpdateFrecency |
michael@0 | 24 | add_task(function test_nsNavHistory_UpdateFrecency() { |
michael@0 | 25 | let bm = PlacesUtils.bookmarks; |
michael@0 | 26 | let uri = NetUtil.newURI("http://example.com/b"); |
michael@0 | 27 | bm.insertBookmark(bm.unfiledBookmarksFolder, uri, |
michael@0 | 28 | Ci.nsINavBookmarksService.DEFAULT_INDEX, "test"); |
michael@0 | 29 | yield onFrecencyChanged(uri); |
michael@0 | 30 | }); |
michael@0 | 31 | |
michael@0 | 32 | // nsNavHistory::invalidateFrecencies for particular pages |
michael@0 | 33 | add_task(function test_nsNavHistory_invalidateFrecencies_somePages() { |
michael@0 | 34 | let uri = NetUtil.newURI("http://test-nsNavHistory-invalidateFrecencies-somePages.com/"); |
michael@0 | 35 | // Bookmarking the URI is enough to add it to moz_places, and importantly, it |
michael@0 | 36 | // means that removePagesFromHost doesn't remove it from moz_places, so its |
michael@0 | 37 | // frecency is able to be changed. |
michael@0 | 38 | let bm = PlacesUtils.bookmarks; |
michael@0 | 39 | bm.insertBookmark(bm.unfiledBookmarksFolder, uri, |
michael@0 | 40 | Ci.nsINavBookmarksService.DEFAULT_INDEX, "test"); |
michael@0 | 41 | PlacesUtils.history.removePagesFromHost(uri.host, false); |
michael@0 | 42 | yield onFrecencyChanged(uri); |
michael@0 | 43 | }); |
michael@0 | 44 | |
michael@0 | 45 | // nsNavHistory::invalidateFrecencies for all pages |
michael@0 | 46 | add_task(function test_nsNavHistory_invalidateFrecencies_allPages() { |
michael@0 | 47 | PlacesUtils.history.removeAllPages(); |
michael@0 | 48 | yield onManyFrecenciesChanged(); |
michael@0 | 49 | }); |
michael@0 | 50 | |
michael@0 | 51 | // nsNavHistory::DecayFrecency and nsNavHistory::FixInvalidFrecencies |
michael@0 | 52 | add_task(function test_nsNavHistory_DecayFrecency_and_nsNavHistory_FixInvalidFrecencies() { |
michael@0 | 53 | // FixInvalidFrecencies is at the end of a path that DecayFrecency is also on, |
michael@0 | 54 | // so expect two notifications. Trigger the path by making nsNavHistory |
michael@0 | 55 | // observe the idle-daily notification. |
michael@0 | 56 | PlacesUtils.history.QueryInterface(Ci.nsIObserver). |
michael@0 | 57 | observe(null, "idle-daily", ""); |
michael@0 | 58 | yield Promise.all([onManyFrecenciesChanged(), onManyFrecenciesChanged()]); |
michael@0 | 59 | }); |
michael@0 | 60 | |
michael@0 | 61 | function onFrecencyChanged(expectedURI) { |
michael@0 | 62 | let deferred = Promise.defer(); |
michael@0 | 63 | let obs = new NavHistoryObserver(); |
michael@0 | 64 | obs.onFrecencyChanged = |
michael@0 | 65 | (uri, newFrecency, guid, hidden, visitDate) => { |
michael@0 | 66 | PlacesUtils.history.removeObserver(obs); |
michael@0 | 67 | do_check_true(!!uri); |
michael@0 | 68 | do_check_true(uri.equals(expectedURI)); |
michael@0 | 69 | deferred.resolve(); |
michael@0 | 70 | }; |
michael@0 | 71 | PlacesUtils.history.addObserver(obs, false); |
michael@0 | 72 | return deferred.promise; |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | function onManyFrecenciesChanged() { |
michael@0 | 76 | let deferred = Promise.defer(); |
michael@0 | 77 | let obs = new NavHistoryObserver(); |
michael@0 | 78 | obs.onManyFrecenciesChanged = () => { |
michael@0 | 79 | PlacesUtils.history.removeObserver(obs); |
michael@0 | 80 | do_check_true(true); |
michael@0 | 81 | deferred.resolve(); |
michael@0 | 82 | }; |
michael@0 | 83 | PlacesUtils.history.addObserver(obs, false); |
michael@0 | 84 | return deferred.promise; |
michael@0 | 85 | } |