summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/markup/test/browser_markup_events1.js
blob: dbfd4a5c3e3753f4ad0b525b69b0f1db908b71cd (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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/* vim: set ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
 http://creativecommons.org/publicdomain/zero/1.0/ */
/* import-globals-from helper_events_test_runner.js */

"use strict";

// Test that markup view event bubbles show the correct event info for DOM
// events.

const TEST_URL = URL_ROOT + "doc_markup_events1.html";

loadHelperScript("helper_events_test_runner.js");

const TEST_DATA = [ // eslint-disable-line
  {
    selector: "html",
    expected: [
      {
        type: "load",
        filename: TEST_URL,
        attributes: [
          "Bubbling",
          "DOM0"
        ],
        handler: "init();"
      }
    ]
  },
  {
    selector: "#container",
    expected: [
      {
        type: "mouseover",
        filename: TEST_URL + ":45",
        attributes: [
          "Capturing",
          "DOM2"
        ],
        handler: "function mouseoverHandler(event) {\n" +
                 "  if (event.target.id !== \"container\") {\n" +
                 "    let output = document.getElementById(\"output\");\n" +
                 "    output.textContent = event.target.textContent;\n" +
                 "  }\n" +
                 "}"
      }
    ]
  },
  {
    selector: "#multiple",
    expected: [
      {
        type: "click",
        filename: TEST_URL + ":52",
        attributes: [
          "Bubbling",
          "DOM2"
        ],
        handler: "function clickHandler(event) {\n" +
                 "  let output = document.getElementById(\"output\");\n" +
                 "  output.textContent = \"click\";\n" +
                 "}"
      },
      {
        type: "mouseup",
        filename: TEST_URL + ":57",
        attributes: [
          "Bubbling",
          "DOM2"
        ],
        handler: "function mouseupHandler(event) {\n" +
                 "  let output = document.getElementById(\"output\");\n" +
                 "  output.textContent = \"mouseup\";\n" +
                 "}"
      }
    ]
  },
  // #noevents tests check that dynamically added events are properly displayed
  // in the markupview
  {
    selector: "#noevents",
    expected: []
  },
  {
    selector: "#noevents",
    beforeTest: function* (inspector, testActor) {
      let nodeMutated = inspector.once("markupmutation");
      yield testActor.eval("window.wrappedJSObject.addNoeventsClickHandler();");
      yield nodeMutated;
    },
    expected: [
      {
        type: "click",
        filename: TEST_URL + ":72",
        attributes: [
          "Bubbling",
          "DOM2"
        ],
        handler: "function noeventsClickHandler(event) {\n" +
                 "  alert(\"noevents has an event listener\");\n" +
                 "}"
      }
    ]
  },
  {
    selector: "#noevents",
    beforeTest: function* (inspector, testActor) {
      let nodeMutated = inspector.once("markupmutation");
      yield testActor.eval(
        "window.wrappedJSObject.removeNoeventsClickHandler();");
      yield nodeMutated;
    },
    expected: []
  },
  {
    selector: "#DOM0",
    expected: [
      {
        type: "click",
        filename: TEST_URL,
        attributes: [
          "Bubbling",
          "DOM0"
        ],
        handler: "alert('DOM0')"
      }
    ]
  },
  {
    selector: "#handleevent",
    expected: [
      {
        type: "click",
        filename: TEST_URL + ":67",
        attributes: [
          "Bubbling",
          "DOM2"
        ],
        handler: "handleEvent: function(blah) {\n" +
                 "  alert(\"handleEvent\");\n" +
                 "}"
      }
    ]
  }
];

add_task(function* () {
  yield runEventPopupTests(TEST_URL, TEST_DATA);
});