summaryrefslogtreecommitdiffstats
path: root/addon-sdk/source/test/test-dom.js
blob: 0b50a76395ad97763b122e6a35d89facb60b3cba (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
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

"use strict";

const events = require("sdk/dom/events");
const { activeBrowserWindow: { document } } = require("sdk/deprecated/window-utils");
const window = document.window;
/*
exports["test on / emit"] = function (assert, done) {
  let element = document.createElement("div");
  events.on(element, "click", function listener(event) {
    assert.equal(event.target, element, "event has correct target");
    events.removeListener(element, "click", listener);
    done();
  });

  events.emit(element, "click", {
    category: "MouseEvents",
    settings: [
      true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null
    ]
  });
};

exports["test remove"] = function (assert, done) {
  let element = document.createElement("span");
  let l1 = 0;
  let l2 = 0;
  let options = {
    category: "MouseEvents",
    settings: [
      true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null
    ]
  };

  events.on(element, "click", function listener1(event) {
    l1 ++;
    assert.equal(event.target, element, "event has correct target");
    events.removeListener(element, "click", listener1);
  });

  events.on(element, "click", function listener2(event) {
    l2 ++;
    if (l1 < l2) {
      assert.equal(l1, 1, "firs listener was called and then romeved");
      events.removeListener(element, "click", listener2);
      done();
    }
    events.emit(element, "click", options);
  });

  events.emit(element, "click", options);
};

exports["test once"] = function (assert, done) {
  let element = document.createElement("h1");
  let l1 = 0;
  let l2 = 0;
  let options = {
    category: "MouseEvents",
    settings: [
      true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null
    ]
  };


  events.once(element, "click", function listener(event) {
    assert.equal(event.target, element, "event target is a correct element");
    l1 ++;
  });

  events.on(element, "click", function listener(event) {
    l2 ++;
    if (l2 > 3) {
      events.removeListener(element, "click", listener);
      assert.equal(event.target, element, "event has correct target");
      assert.equal(l1, 1, "once was called only once");
      done();
    }
    events.emit(element, "click", options);
  });

  events.emit(element, "click", options);
}
*/
require("test").run(exports);