summaryrefslogtreecommitdiffstats
path: root/browser/components/uitour/test/browser_trackingProtection.js
blob: 32a9920ecbaaffe162084f35af8f70fd194eb0b2 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
"use strict";

var {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
const PREF_INTRO_COUNT = "privacy.trackingprotection.introCount";
const PREF_TP_ENABLED = "privacy.trackingprotection.enabled";
const BENIGN_PAGE = "http://tracking.example.org/browser/browser/base/content/test/general/benignPage.html";
const TRACKING_PAGE = "http://tracking.example.org/browser/browser/base/content/test/general/trackingPage.html";
const TOOLTIP_PANEL = document.getElementById("UITourTooltip");
const TOOLTIP_ANCHOR = document.getElementById("tracking-protection-icon");

var {UrlClassifierTestUtils} = Cu.import("resource://testing-common/UrlClassifierTestUtils.jsm", {});

registerCleanupFunction(function() {
  UrlClassifierTestUtils.cleanupTestTrackers();
  Services.prefs.clearUserPref(PREF_TP_ENABLED);
  Services.prefs.clearUserPref(PREF_INTRO_COUNT);
});

function allowOneIntro() {
  Services.prefs.setIntPref(PREF_INTRO_COUNT, TrackingProtection.MAX_INTROS - 1);
}

add_task(function* setup_test() {
  Services.prefs.setBoolPref(PREF_TP_ENABLED, true);
  yield UrlClassifierTestUtils.addTestTrackers();
});

add_task(function* test_benignPage() {
  info("Load a test page not containing tracking elements");
  allowOneIntro();
  yield BrowserTestUtils.withNewTab({gBrowser, url: BENIGN_PAGE}, function*() {
    yield waitForConditionPromise(() => {
      return is_visible(TOOLTIP_PANEL);
    }, "Info panel shouldn't appear on a benign page").
      then(() => ok(false, "Info panel shouldn't appear"),
           () => {
             ok(true, "Info panel didn't appear on a benign page");
           });

  });
});

add_task(function* test_trackingPages() {
  info("Load a test page containing tracking elements");
  allowOneIntro();
  yield BrowserTestUtils.withNewTab({gBrowser, url: TRACKING_PAGE}, function*() {
    yield new Promise((resolve, reject) => {
      waitForPopupAtAnchor(TOOLTIP_PANEL, TOOLTIP_ANCHOR, resolve,
                           "Intro panel should appear");
    });

    is(Services.prefs.getIntPref(PREF_INTRO_COUNT), TrackingProtection.MAX_INTROS, "Check intro count increased");

    let step2URL = Services.urlFormatter.formatURLPref("privacy.trackingprotection.introURL") +
                   "?step=2&newtab=true";
    let buttons = document.getElementById("UITourTooltipButtons");

    info("Click the step text and nothing should happen");
    let tabCount = gBrowser.tabs.length;
    yield EventUtils.synthesizeMouseAtCenter(buttons.children[0], {});
    is(gBrowser.tabs.length, tabCount, "Same number of tabs should be open");

    info("Resetting count to test that viewing the tour prevents future panels");
    allowOneIntro();

    let panelHiddenPromise = promisePanelElementHidden(window, TOOLTIP_PANEL);
    let tabPromise = BrowserTestUtils.waitForNewTab(gBrowser, step2URL);
    info("Clicking the main button");
    EventUtils.synthesizeMouseAtCenter(buttons.children[1], {});
    let tab = yield tabPromise;
    is(Services.prefs.getIntPref(PREF_INTRO_COUNT), TrackingProtection.MAX_INTROS,
       "Check intro count is at the max after opening step 2");
    is(gBrowser.tabs.length, tabCount + 1, "Tour step 2 tab opened");
    yield panelHiddenPromise;
    ok(true, "Panel hid when the button was clicked");
    yield BrowserTestUtils.removeTab(tab);
  });

  info("Open another tracking page and make sure we don't show the panel again");
  yield BrowserTestUtils.withNewTab({gBrowser, url: TRACKING_PAGE}, function*() {
    yield waitForConditionPromise(() => {
      return is_visible(TOOLTIP_PANEL);
    }, "Info panel shouldn't appear more than MAX_INTROS").
      then(() => ok(false, "Info panel shouldn't appear again"),
           () => {
             ok(true, "Info panel didn't appear more than MAX_INTROS on tracking pages");
           });

  });
});