summaryrefslogtreecommitdiffstats
path: root/browser/components/uitour/test/browser_UITour_observe.js
blob: d9ecf6fc7d63a52563272a1342f6f0c0a91a148d (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
91
92
93
94
95
96
97
98
99
"use strict";

var gTestTab;
var gContentAPI;

function test() {
  requestLongerTimeout(2);
  UITourTest();
}

var tests = [
  function test_no_params(done) {
    function listener(event, params) {
      is(event, "test-event-1", "Correct event name");
      ok(!params, "No param object");
      gContentAPI.observe(null);
      done();
    }

    gContentAPI.observe(listener, () => {
      UITour.notify("test-event-1");
    });
  },
  function test_param_string(done) {
    function listener(event, params) {
      is(event, "test-event-2", "Correct event name");
      is(params, "a param", "Correct param string");
      gContentAPI.observe(null);
      done();
    }

    gContentAPI.observe(listener, () => {
      UITour.notify("test-event-2", "a param");
    });
  },
  function test_param_object(done) {
    function listener(event, params) {
      is(event, "test-event-3", "Correct event name");
      is(
        JSON.stringify(params),
        JSON.stringify({ key: "something" }),
        "Correct param object"
      );
      gContentAPI.observe(null);
      done();
    }

    gContentAPI.observe(listener, () => {
      UITour.notify("test-event-3", { key: "something" });
    });
  },
  function test_background_tab(done) {
    function listener(event, params) {
      is(event, "test-event-background-1", "Correct event name");
      ok(!params, "No param object");
      gContentAPI.observe(null);
      gBrowser.removeCurrentTab();
      done();
    }

    gContentAPI.observe(listener, () => {
      gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, "about:blank");
      isnot(
        gBrowser.selectedTab,
        gTestTab,
        "Make sure the selected tab changed"
      );

      UITour.notify("test-event-background-1");
    });
  },
  // Make sure the tab isn't torn down when switching back to the tour one.
  function test_background_then_foreground_tab(done) {
    let blankTab = null;
    function listener(event, params) {
      is(event, "test-event-4", "Correct event name");
      ok(!params, "No param object");
      gContentAPI.observe(null);
      gBrowser.removeTab(blankTab);
      done();
    }

    gContentAPI.observe(listener, () => {
      blankTab = gBrowser.selectedTab = BrowserTestUtils.addTab(
        gBrowser,
        "about:blank"
      );
      isnot(
        gBrowser.selectedTab,
        gTestTab,
        "Make sure the selected tab changed"
      );
      gBrowser.selectedTab = gTestTab;
      is(gBrowser.selectedTab, gTestTab, "Switch back to the test tab");

      UITour.notify("test-event-4");
    });
  },
];