|
56 | 56 | delete window.opera; |
57 | 57 | delete window.fakeOpera; |
58 | 58 | } |
| 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 | + } |
59 | 71 | } |
60 | 72 | }; |
61 | 73 |
|
|
89 | 101 | test("run mode", function() { |
90 | 102 | expect(1); |
91 | 103 | 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() { |
93 | 105 | ok(true, 'called mode() successfully'); |
94 | | - }; |
| 106 | + }); |
95 | 107 | p.run(); |
96 | 108 | }); |
97 | 109 |
|
98 | 110 | test("run chrome", function() { |
99 | 111 | expect(2); |
100 | 112 | 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); |
104 | 114 | p.chrome = function() { |
105 | | - ok(true, 'called run for "chrome"'); |
| 115 | + ok(true, 'called run() for "chrome"'); |
106 | 116 | }; |
107 | 117 | p.run(CapturedExceptions.chrome_15); |
108 | 118 | p.run(CapturedExceptions.chrome_27); |
|
111 | 121 | test("run safari", function() { |
112 | 122 | expect(1); |
113 | 123 | 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); |
117 | 125 | p.safari = function() { |
118 | | - ok(true, 'called run for "safari"'); |
| 126 | + ok(true, 'called run() for "safari"'); |
119 | 127 | }; |
120 | 128 | p.run(CapturedExceptions.safari_6); |
121 | 129 | }); |
122 | 130 |
|
123 | 131 | test("run ie", function() { |
124 | 132 | expect(1); |
125 | 133 | 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); |
129 | 135 | p.ie = function() { |
130 | | - ok(true, 'called run for "ie"'); |
| 136 | + ok(true, 'called run() for "ie"'); |
131 | 137 | }; |
132 | 138 | p.run(CapturedExceptions.ie_10); |
133 | 139 | }); |
134 | 140 |
|
135 | 141 | test("run firefox", function() { |
136 | 142 | expect(5); |
137 | 143 | 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); |
141 | 145 | p.firefox = function() { |
142 | | - ok(true, 'called run for "firefox"'); |
| 146 | + ok(true, 'called run() for "firefox"'); |
143 | 147 | }; |
144 | 148 | p.run(CapturedExceptions.firefox_3_6); |
145 | 149 | p.run(CapturedExceptions.firefox_3_6_file); |
|
151 | 155 | test("run opera9", function() { |
152 | 156 | expect(5); |
153 | 157 | 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); |
157 | 159 | p.opera9 = function() { |
158 | | - ok(true, 'called run for "opera9"'); |
| 160 | + ok(true, 'called run() for "opera9"'); |
159 | 161 | }; |
160 | 162 | UnitTest.fn.prepareFakeOperaEnvironment(); |
161 | 163 | p.run({ |
|
171 | 173 | test("run opera10a", function() { |
172 | 174 | expect(1); |
173 | 175 | 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); |
177 | 177 | p.opera10a = function() { |
178 | | - ok(true, 'called run for "opera10a"'); |
| 178 | + ok(true, 'called run() for "opera10a"'); |
179 | 179 | }; |
180 | 180 | UnitTest.fn.prepareFakeOperaEnvironment(); |
181 | 181 | p.run(CapturedExceptions.opera_1010); |
|
185 | 185 | test("run opera10b", function() { |
186 | 186 | expect(1); |
187 | 187 | 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); |
191 | 189 | p.opera10b = function() { |
192 | | - ok(true, 'called run for "opera10b"'); |
| 190 | + ok(true, 'called run() for "opera10b"'); |
193 | 191 | }; |
194 | 192 | UnitTest.fn.prepareFakeOperaEnvironment(); |
195 | 193 | p.run(CapturedExceptions.opera_1063); |
|
199 | 197 | test("run opera11", function() { |
200 | 198 | expect(3); |
201 | 199 | 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); |
205 | 201 | p.opera11 = function() { |
206 | | - ok(true, 'called run for "opera11"'); |
| 202 | + ok(true, 'called run() for "opera11"'); |
207 | 203 | }; |
208 | 204 | UnitTest.fn.prepareFakeOperaEnvironment(); |
209 | 205 | p.run(CapturedExceptions.opera_1111); |
|
215 | 211 | test("run other", function() { |
216 | 212 | expect(1); |
217 | 213 | 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); |
221 | 215 | p.other = function() { |
222 | | - ok(true, 'called run for other browser'); |
| 216 | + ok(true, 'called run() for other browser'); |
223 | 217 | }; |
224 | 218 | p.run({}); |
225 | 219 | }); |
|
240 | 234 | this.toInstrument = this.callback = null; |
241 | 235 | }); |
242 | 236 |
|
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 | | - |
270 | 237 | test("firefox", function() { |
271 | 238 | expect(34); |
272 | 239 |
|
|
316 | 283 | equals(message[4], 'onclick@file:///E:/javascript-stacktrace/test/functional/ExceptionLab.html:1'); |
317 | 284 | }); |
318 | 285 |
|
| 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 | + |
319 | 313 | test("chrome", function() { |
320 | 314 | expect(14); |
321 | 315 |
|
|
512 | 506 | } |
513 | 507 | }); |
514 | 508 |
|
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 | + } |
523 | 517 | } |
524 | | - } |
525 | 518 |
|
526 | | - function f1(arg1, arg2) { |
527 | | - f0(); |
528 | | - } |
| 519 | + var f2 = function() { |
| 520 | + return f1(1, "abc"); |
| 521 | + }; |
529 | 522 |
|
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'); |
544 | 545 | }); |
545 | 546 |
|
546 | 547 | test("other", function() { |
|
0 commit comments