blob: 55917681507fafb77c79ebaf23855c39fe8d594d (
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
|
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test for count/countReset in console</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="head.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<script type="application/javascript">
SimpleTest.waitForExplicitFinish();
function ConsoleListener() {
addConsoleStorageListener(this);
}
ConsoleListener.prototype = {
observe(aSubject) {
let obj = aSubject.wrappedJSObject;
if (obj.arguments[0] != "test") {
return;
}
if (!this._cb) {
ok(false, "Callback not set!");
return;
}
if (!this._cb(obj)) {
return;
}
this._cb = null;
this._resolve();
},
shutdown() {
removeConsoleStorageListener(this);
},
waitFor(cb) {
return new Promise(resolve => {
this._cb = SpecialPowers.wrapCallback(cb);
this._resolve = resolve;
});
},
};
let listener = new ConsoleListener();
async function runTest() {
// First count.
let cl = listener.waitFor(obj => {
return ("counter" in obj) &&
("label" in obj.counter) &&
obj.counter.label == "test" &&
obj.counter.count == 1;
});
console.count("test");
await cl;
ok(true, "Console.count == 1 received!");
// Second count.
cl = listener.waitFor(obj => {
return ("counter" in obj) &&
("label" in obj.counter) &&
obj.counter.label == "test" &&
obj.counter.count == 2;
});
console.count("test");
await cl;
ok(true, "Console.count == 2 received!");
// Counter reset.
cl = listener.waitFor(obj => {
return ("counter" in obj) &&
("label" in obj.counter) &&
obj.counter.label == "test" &&
obj.counter.count == 0;
});
console.countReset("test");
await cl;
ok(true, "Console.countReset == 0 received!");
// Counter reset with error.
cl = listener.waitFor(obj => {
return ("counter" in obj) &&
("label" in obj.counter) &&
obj.counter.label == "test" &&
obj.counter.error == "counterDoesntExist";
});
console.countReset("test");
await cl;
ok(true, "Console.countReset with error received!");
// First again!
cl = listener.waitFor(obj => {
return ("counter" in obj) &&
("label" in obj.counter) &&
obj.counter.label == "test" &&
obj.counter.count == 1;
});
console.count("test");
await cl;
ok(true, "Console.count == 1 received!");
}
runTest().then(() => {
listener.shutdown();
SimpleTest.finish();
});
</script>
</body>
</html>
|