Skip to content

Commit 5519798

Browse files
Unified code for run() tests. Tests for IE are using CapturedExceptions.ie_10.
1 parent 3843057 commit 5519798

1 file changed

Lines changed: 92 additions & 91 deletions

File tree

test/TestStacktrace.js

Lines changed: 92 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@
5656
delete window.opera;
5757
delete window.fakeOpera;
5858
}
59+
},
60+
createModeStub: function(mode) {
61+
return function() {
62+
ok(false, 'must not call run() for mode "' + mode + '"');
63+
};
64+
},
65+
createModeStubs: function(p, stub) {
66+
var modes = ['other', 'opera9', 'opera10a', 'opera10b', 'opera11', 'firefox', 'safari', 'ie', 'chrome'];
67+
for (var i = 0, len = modes.length; i < len; i++) {
68+
var mode = modes[i];
69+
p[mode] = stub || this.createModeStub(mode);
70+
}
5971
}
6072
};
6173

@@ -89,20 +101,18 @@
89101
test("run mode", function() {
90102
expect(1);
91103
var p = impl();
92-
p.other = p.firefox = p.chrome = p.ie = p.safari = p.opera9 = p.opera10a = p.opera10b = p.opera11 = function() {
104+
UnitTest.fn.createModeStubs(p, function() {
93105
ok(true, 'called mode() successfully');
94-
};
106+
});
95107
p.run();
96108
});
97109

98110
test("run chrome", function() {
99111
expect(2);
100112
var p = impl();
101-
p.other = p.opera9 = p.opera10a = p.opera10b = p.opera11 = p.firefox = p.safari = p.ie = function() {
102-
equals(1, 0, 'must not call run for any mode other than "chrome"');
103-
};
113+
UnitTest.fn.createModeStubs(p);
104114
p.chrome = function() {
105-
ok(true, 'called run for "chrome"');
115+
ok(true, 'called run() for "chrome"');
106116
};
107117
p.run(CapturedExceptions.chrome_15);
108118
p.run(CapturedExceptions.chrome_27);
@@ -111,35 +121,29 @@
111121
test("run safari", function() {
112122
expect(1);
113123
var p = impl();
114-
p.other = p.opera9 = p.opera10a = p.opera10b = p.opera11 = p.firefox = p.chrome = p.ie = function() {
115-
equals(1, 0, 'must not call run for any mode other than "safari"');
116-
};
124+
UnitTest.fn.createModeStubs(p);
117125
p.safari = function() {
118-
ok(true, 'called run for "safari"');
126+
ok(true, 'called run() for "safari"');
119127
};
120128
p.run(CapturedExceptions.safari_6);
121129
});
122130

123131
test("run ie", function() {
124132
expect(1);
125133
var p = impl();
126-
p.other = p.opera9 = p.opera10a = p.opera10b = p.opera11 = p.firefox = p.chrome = p.safari = function() {
127-
equals(1, 0, 'must not call run for any mode other than "ie"');
128-
};
134+
UnitTest.fn.createModeStubs(p);
129135
p.ie = function() {
130-
ok(true, 'called run for "ie"');
136+
ok(true, 'called run() for "ie"');
131137
};
132138
p.run(CapturedExceptions.ie_10);
133139
});
134140

135141
test("run firefox", function() {
136142
expect(5);
137143
var p = impl();
138-
p.other = p.opera9 = p.opera10a = p.opera10b = p.opera11 = p.chrome = p.safari = p.ie = function() {
139-
equals(1, 0, 'must not call run for any mode other than "firefox"');
140-
};
144+
UnitTest.fn.createModeStubs(p);
141145
p.firefox = function() {
142-
ok(true, 'called run for "firefox"');
146+
ok(true, 'called run() for "firefox"');
143147
};
144148
p.run(CapturedExceptions.firefox_3_6);
145149
p.run(CapturedExceptions.firefox_3_6_file);
@@ -151,11 +155,9 @@
151155
test("run opera9", function() {
152156
expect(5);
153157
var p = impl();
154-
p.opera10a = p.opera10b = p.opera11 = p.other = p.firefox = p.chrome = p.safari = p.ie = function() {
155-
equals(1, 0, 'must not call run for any mode other than "opera9"');
156-
};
158+
UnitTest.fn.createModeStubs(p);
157159
p.opera9 = function() {
158-
ok(true, 'called run for "opera9"');
160+
ok(true, 'called run() for "opera9"');
159161
};
160162
UnitTest.fn.prepareFakeOperaEnvironment();
161163
p.run({
@@ -171,11 +173,9 @@
171173
test("run opera10a", function() {
172174
expect(1);
173175
var p = impl();
174-
p.opera9 = p.opera10b = p.opera11 = p.other = p.firefox = p.chrome = p.safari = p.ie = function() {
175-
equals(1, 0, 'must not call run for any mode other than "opera10a"');
176-
};
176+
UnitTest.fn.createModeStubs(p);
177177
p.opera10a = function() {
178-
ok(true, 'called run for "opera10a"');
178+
ok(true, 'called run() for "opera10a"');
179179
};
180180
UnitTest.fn.prepareFakeOperaEnvironment();
181181
p.run(CapturedExceptions.opera_1010);
@@ -185,11 +185,9 @@
185185
test("run opera10b", function() {
186186
expect(1);
187187
var p = impl();
188-
p.opera9 = p.opera10a = p.opera11 = p.other = p.firefox = p.chrome = p.safari = p.ie = function() {
189-
equals(1, 0, 'must not call run for any mode other than "opera10b"');
190-
};
188+
UnitTest.fn.createModeStubs(p);
191189
p.opera10b = function() {
192-
ok(true, 'called run for "opera10b"');
190+
ok(true, 'called run() for "opera10b"');
193191
};
194192
UnitTest.fn.prepareFakeOperaEnvironment();
195193
p.run(CapturedExceptions.opera_1063);
@@ -199,11 +197,9 @@
199197
test("run opera11", function() {
200198
expect(3);
201199
var p = impl();
202-
p.opera9 = p.opera10a = p.opera10b = p.other = p.firefox = p.chrome = p.safari = p.ie = function() {
203-
equals(1, 0, 'must not be called');
204-
};
200+
UnitTest.fn.createModeStubs(p);
205201
p.opera11 = function() {
206-
ok(true, 'called run for "opera11"');
202+
ok(true, 'called run() for "opera11"');
207203
};
208204
UnitTest.fn.prepareFakeOperaEnvironment();
209205
p.run(CapturedExceptions.opera_1111);
@@ -215,11 +211,9 @@
215211
test("run other", function() {
216212
expect(1);
217213
var p = impl();
218-
p.opera9 = p.opera10a = p.opera10b = p.opera11 = p.firefox = p.chrome = p.safari = p.ie = function() {
219-
equals(1, 0, 'must not be called');
220-
};
214+
UnitTest.fn.createModeStubs(p);
221215
p.other = function() {
222-
ok(true, 'called run for other browser');
216+
ok(true, 'called run() for other browser');
223217
};
224218
p.run({});
225219
});
@@ -240,33 +234,6 @@
240234
this.toInstrument = this.callback = null;
241235
});
242236

243-
if (pst.mode(ex) == 'firefox') {
244-
test("firefox live", function() {
245-
function f1(arg1, arg2) {
246-
try {
247-
return this.undef();
248-
} catch (exception) {
249-
return exception;
250-
}
251-
}
252-
253-
var f2 = function() {
254-
return f1(1, "abc");
255-
};
256-
257-
var e = (function() {
258-
return f2();
259-
})();
260-
261-
expect(2);
262-
var message = pst.firefox(e);
263-
// equals(message.join('\n'), '', 'processed stack trace');
264-
equals(message[0].indexOf('f1@'), 0, message[0] + ' should start with f1@');
265-
equals(message[1].indexOf('f2@'), 0, message[1] + ' should start with f2@');
266-
//equals(message[2].indexOf('{anonymous}()@'), 0, message[2] + ' should start with {anonymous}()@');
267-
});
268-
}
269-
270237
test("firefox", function() {
271238
expect(34);
272239

@@ -316,6 +283,33 @@
316283
equals(message[4], 'onclick@file:///E:/javascript-stacktrace/test/functional/ExceptionLab.html:1');
317284
});
318285

286+
if (pst.mode(ex) == 'firefox') {
287+
test("firefox live", function() {
288+
function f1(arg1, arg2) {
289+
try {
290+
return this.undef();
291+
} catch (exception) {
292+
return exception;
293+
}
294+
}
295+
296+
var f2 = function() {
297+
return f1(1, "abc");
298+
};
299+
300+
var e = (function() {
301+
return f2();
302+
})();
303+
304+
expect(2);
305+
var message = pst.firefox(e);
306+
// equals(message.join('\n'), '', 'processed stack trace');
307+
equals(message[0].indexOf('f1@'), 0, message[0] + ' should start with f1@');
308+
equals(message[1].indexOf('f2@'), 0, message[1] + ' should start with f2@');
309+
//equals(message[2].indexOf('{anonymous}()@'), 0, message[2] + ' should start with {anonymous}()@');
310+
});
311+
}
312+
319313
test("chrome", function() {
320314
expect(14);
321315

@@ -512,35 +506,42 @@
512506
}
513507
});
514508

515-
test("ie", function() {
516-
var e = [], ex;
517-
518-
function f0() {
519-
try {
520-
this.undef();
521-
} catch (exception) {
522-
ex = exception;
509+
if (pst.mode(ex) == 'ie') {
510+
test("ie10 live", function() {
511+
function f1(arg1, arg2) {
512+
try {
513+
return this.undef();
514+
} catch (exception) {
515+
return exception;
516+
}
523517
}
524-
}
525518

526-
function f1(arg1, arg2) {
527-
f0();
528-
}
519+
var f2 = function() {
520+
return f1(1, "abc");
521+
};
529522

530-
var f2 = function() {
531-
f1(1, "abc");
532-
};
533-
f2();
534-
if (pst.mode(ex) == 'ie') {
535-
e.push(ex);
536-
}
537-
expect(3 * e.length);
538-
for (var i = 0; i < e.length; i++) {
539-
var stack = pst.ie(e[i]);
540-
equals(stack[0].indexOf('f0'), 0, 'matched f0');
541-
equals(stack[1].indexOf('f1'), 0, 'f1 function name: ' + stack[1]);
542-
equals(stack[2].indexOf('{anonymous}'), 0, 'f2 anonymous');
543-
}
523+
var e = (function() {
524+
return f2();
525+
})();
526+
527+
expect(3);
528+
var message = pst.ie(e);
529+
//equals(e.stack, '', 'original stack trace');
530+
//equals(message.join('\n'), '', 'processed stack trace');
531+
equals(message[0].indexOf('f1@'), 0, message[0] + ' should start with f1@');
532+
equals(message[1].indexOf('f2@'), 0, message[1] + ' should start with f2@');
533+
equals(message[2].indexOf('{anonymous}()@'), 0, message[2] + ' should start with {anonymous}()@');
534+
});
535+
}
536+
537+
test("ie10", function() {
538+
expect(4);
539+
540+
var message = pst.ie(CapturedExceptions.ie_10);
541+
equals(message.length, 3, '3 stack entries');
542+
equals(message[0], '{anonymous}()@http://jenkins.eriwen.com/job/stacktrace.js/ws/test/functional/ExceptionLab.html:48:13');
543+
equals(message[1], 'dumpException3@http://jenkins.eriwen.com/job/stacktrace.js/ws/test/functional/ExceptionLab.html:46:9');
544+
equals(message[2], 'onclick@http://jenkins.eriwen.com/job/stacktrace.js/ws/test/functional/ExceptionLab.html:82:1');
544545
});
545546

546547
test("other", function() {

0 commit comments

Comments
 (0)