Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / remoting / webapp / base / js / callstack_unittest.js
bloba8a44f6fc2fc04ef07e34feb06608bd3553cf463
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} */
7 (function() {
9 'use strict';
11 QUnit.module('callstack');
13 QUnit.test('well-formed stack frames are parsed correctly', function(assert) {
14 var tests = [
15 // Function and URL both present.
17 error: {
18 stack: 'Error\n at function (chrome-extension://id/file.js:1:2)'
20 result: {
21 fn: 'function',
22 url: 'chrome-extension://id',
23 file: 'file.js',
24 line: 1,
25 column: 2
28 // Missing function.
30 error: {
31 stack: 'Error\n at chrome-extension://id/file.js:3:4'
33 result: {
34 fn: '',
35 url: 'chrome-extension://id',
36 file: 'file.js',
37 line: 3,
38 column: 4
41 // Missing URL.
43 error: {
44 stack: 'Error\n at function (file.js:5:6)'
46 result: {
47 fn: 'function',
48 url: '',
49 file: 'file.js',
50 line: 5,
51 column: 6
54 // Missing both function and URL.
56 error: { stack: 'Error\n at <anonymous>:7:8' },
57 result: {
58 fn: '',
59 url: '',
60 file: '<anonymous>',
61 line: 7,
62 column: 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);
77 });
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);
83 });
85 QUnit.test('toString() behaves as expected', function(assert) {
86 var error = {
87 stack: 'Error\n' +
88 ' at fn1 (http://test.com/file1:1:2)\n' +
89 ' at fn2 (file2:3:4)'
91 var callstack = new base.Callstack(error);
92 assert.equal(callstack.toString(),
93 'fn1 (http://test.com/file1:1:2)\nfn2 (file2:3:4)');
94 });
96 })();