summaryrefslogtreecommitdiffstats
path: root/docshell/test/browser/browser_timelineMarkers-frame-03.js
blob: cf5f150ad85dff0dd30272ea26ccefa8d2548427 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Test that the docShell profile timeline API returns the right
// markers for DOM events.

var TESTS = [{
  desc: "Event dispatch with single handler",
  searchFor: 'DOMEvent',
  setup: function(docShell) {
    content.document.body.addEventListener("dog",
                                           function(e) { console.log("hi"); },
                                           true);
    content.document.body.dispatchEvent(new content.Event("dog"));
  },
  check: function(markers) {
    markers = markers.filter(m => m.name == 'DOMEvent');
    is(markers.length, 1, "Got 1 marker");
    is(markers[0].type, "dog", "Got dog event name");
    is(markers[0].eventPhase, 2, "Got phase 2");
  }
}, {
  desc: "Event dispatch with a second handler",
  searchFor: function(markers) {
    return markers.filter(m => m.name == 'DOMEvent').length >= 2;
  },
  setup: function(docShell) {
    content.document.body.addEventListener("dog",
                                           function(e) { console.log("hi"); },
                                           false);
    content.document.body.dispatchEvent(new content.Event("dog"));
  },
  check: function(markers) {
    markers = markers.filter(m => m.name == 'DOMEvent');
    is(markers.length, 2, "Got 2 markers");
  }
}, {
  desc: "Event targeted at child",
  searchFor: function(markers) {
    return markers.filter(m => m.name == 'DOMEvent').length >= 2;
  },
  setup: function(docShell) {
    let child = content.document.body.firstElementChild;
    child.addEventListener("dog", function(e) { });
    child.dispatchEvent(new content.Event("dog"));
  },
  check: function(markers) {
    markers = markers.filter(m => m.name == 'DOMEvent');
    is(markers.length, 2, "Got 2 markers");
    is(markers[0].eventPhase, 1, "Got phase 1 marker");
    is(markers[1].eventPhase, 2, "Got phase 2 marker");
  }
}, {
  desc: "Event dispatch on a new document",
  searchFor: function(markers) {
    return markers.filter(m => m.name == 'DOMEvent').length >= 2;
  },
  setup: function(docShell) {
    let doc = content.document.implementation.createHTMLDocument("doc");
    let p = doc.createElement("p");
    p.innerHTML = "inside";
    doc.body.appendChild(p);

    p.addEventListener("zebra", function(e) {console.log("hi");});
    p.dispatchEvent(new content.Event("zebra"));
  },
  check: function(markers) {
    markers = markers.filter(m => m.name == 'DOMEvent');
    is(markers.length, 1, "Got 1 marker");
  }
}, {
  desc: "Event dispatch on window",
  searchFor: function(markers) {
    return markers.filter(m => m.name == 'DOMEvent').length >= 2;
  },
  setup: function(docShell) {
    let doc = content.window.addEventListener("aardvark", function(e) {
      console.log("I like ants!");
    });

    content.window.dispatchEvent(new content.Event("aardvark"));
  },
  check: function(markers) {
    markers = markers.filter(m => m.name == 'DOMEvent');
    is(markers.length, 1, "Got 1 marker");
  }
}];

timelineContentTest(TESTS);