summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/newtab/browser_newtab_bug722273.js
blob: 5cbfcd3ff4cb36e87307fc518df36c40875436ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

const NOW = Date.now() * 1000;
const URL = "http://fake-site.com/";

var tmp = {};
Cc["@mozilla.org/moz/jssubscript-loader;1"]
  .getService(Ci.mozIJSSubScriptLoader)
  .loadSubScript("chrome://browser/content/sanitize.js", tmp);

var {Sanitizer} = tmp;

add_task(function* () {
  yield promiseSanitizeHistory();
  yield promiseAddFakeVisits();
  yield* addNewTabPageTab();

  let cellUrl = yield performOnCell(0, cell => { return cell.site.url; });
  is(cellUrl, URL, "first site is our fake site");

  let updatedPromise = whenPagesUpdated();
  yield promiseSanitizeHistory();
  yield updatedPromise;

  let isGone = yield performOnCell(0, cell => { return cell.site == null; });
  ok(isGone, "fake site is gone");
});

function promiseAddFakeVisits() {
  let visits = [];
  for (let i = 59; i > 0; i--) {
    visits.push({
      visitDate: NOW - i * 60 * 1000000,
      transitionType: Ci.nsINavHistoryService.TRANSITION_LINK
    });
  }
  let place = {
    uri: makeURI(URL),
    title: "fake site",
    visits: visits
  };
  return new Promise((resolve, reject) => {
    PlacesUtils.asyncHistory.updatePlaces(place, {
      handleError: () => reject(new Error("Couldn't add visit")),
      handleResult: function () {},
      handleCompletion: function () {
        NewTabUtils.links.populateCache(function () {
          NewTabUtils.allPages.update();
          resolve();
        }, true);
      }
    });
  });
}

function promiseSanitizeHistory() {
  let s = new Sanitizer();
  s.prefDomain = "privacy.cpd.";

  let prefs = gPrefService.getBranch(s.prefDomain);
  prefs.setBoolPref("history", true);
  prefs.setBoolPref("downloads", false);
  prefs.setBoolPref("cache", false);
  prefs.setBoolPref("cookies", false);
  prefs.setBoolPref("formdata", false);
  prefs.setBoolPref("offlineApps", false);
  prefs.setBoolPref("passwords", false);
  prefs.setBoolPref("sessions", false);
  prefs.setBoolPref("siteSettings", false);

  return s.sanitize();
}