1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 /** @suppress {checkTypes|reportUnknownTypes} */
11 QUnit.module('callstack');
13 QUnit.test('well-formed stack frames are parsed correctly', function(assert) {
15 // Function and URL both present.
18 stack: 'Error\n at function (chrome-extension://id/file.js:1:2)'
22 url: 'chrome-extension://id',
31 stack: 'Error\n at chrome-extension://id/file.js:3:4'
35 url: 'chrome-extension://id',
44 stack: 'Error\n at function (file.js:5:6)'
54 // Missing both function and URL.
56 error: { stack: 'Error\n at <anonymous>:7:8' },
67 for (var test of tests) {
68 var callstack = new base.Callstack(test.error);
69 assert.equal(callstack.callstack.length, 1);
70 assert.equal(callstack.callstack[0].fn, test.result.fn);
71 assert.equal(callstack.callstack[0].url, test.result.url);
72 assert.equal(callstack.callstack[0].file, test.result.file);
73 assert.equal(callstack.callstack[0].line, test.result.line);
74 assert.equal(callstack.callstack[0].column, test.result.column);
79 QUnit.test('line numbers are correct', function(assert) {
80 var callstack1 = new base.Callstack();
81 var callstack2 = new base.Callstack();
82 assert.equal(callstack2.callstack[0].line, callstack1.callstack[0].line + 1);
85 QUnit.test('toString() behaves as expected', function(assert) {
88 ' at fn1 (http://test.com/file1:1:2)\n' +
91 var callstack = new base.Callstack(error);
92 assert.equal(callstack.toString(),
93 'fn1 (http://test.com/file1:1:2)\nfn2 (file2:3:4)');