2015-04-04 09:53:59 -07:00
|
|
|
// Licensed to the Software Freedom Conservancy (SFC) under one
|
|
|
|
|
// or more contributor license agreements. See the NOTICE file
|
|
|
|
|
// distributed with this work for additional information
|
|
|
|
|
// regarding copyright ownership. The SFC licenses this file
|
|
|
|
|
// to you under the Apache License, Version 2.0 (the
|
|
|
|
|
// "License"); you may not use this file except in compliance
|
|
|
|
|
// with the License. You may obtain a copy of the License at
|
2014-11-12 19:33:37 +00:00
|
|
|
//
|
2015-04-04 09:53:59 -07:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2014-11-12 19:33:37 +00:00
|
|
|
//
|
2015-04-04 09:53:59 -07:00
|
|
|
// Unless required by applicable law or agreed to in writing,
|
|
|
|
|
// software distributed under the License is distributed on an
|
|
|
|
|
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
|
// KIND, either express or implied. See the License for the
|
|
|
|
|
// specific language governing permissions and limitations
|
|
|
|
|
// under the License.
|
2014-07-05 20:39:52 -04:00
|
|
|
|
|
|
|
|
goog.require('bot.Error');
|
|
|
|
|
goog.require('bot.ErrorCode');
|
|
|
|
|
goog.require('goog.string');
|
|
|
|
|
goog.require('goog.testing.JsUnitException');
|
|
|
|
|
goog.require('goog.testing.PropertyReplacer');
|
|
|
|
|
goog.require('goog.testing.StrictMock');
|
|
|
|
|
goog.require('goog.testing.jsunit');
|
|
|
|
|
goog.require('goog.testing.stacktrace');
|
|
|
|
|
goog.require('webdriver.stacktrace');
|
|
|
|
|
goog.require('webdriver.test.testutil');
|
|
|
|
|
|
2012-10-22 22:58:53 +00:00
|
|
|
var stubs;
|
2012-07-02 19:46:57 +00:00
|
|
|
|
|
|
|
|
function setUpPage() {
|
2012-10-22 22:58:53 +00:00
|
|
|
stubs = new goog.testing.PropertyReplacer();
|
2012-07-02 19:46:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function tearDown() {
|
2012-10-22 22:58:53 +00:00
|
|
|
stubs.reset();
|
2012-07-02 19:46:57 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-22 22:58:53 +00:00
|
|
|
|
|
|
|
|
function assertStackFrame(message, frameOrFrameString, expectedFrame) {
|
|
|
|
|
var frame = frameOrFrameString;
|
|
|
|
|
if (goog.isString(frame)) {
|
|
|
|
|
frame = webdriver.stacktrace.parseStackFrame_(frame);
|
|
|
|
|
assertNotNull(message + '\nunable to parse frame: ' + frameOrFrameString,
|
|
|
|
|
frame);
|
|
|
|
|
}
|
|
|
|
|
var diff = [];
|
|
|
|
|
for (var prop in expectedFrame) {
|
|
|
|
|
if (goog.isString(expectedFrame[prop]) &&
|
|
|
|
|
frame[prop] !== expectedFrame[prop]) {
|
|
|
|
|
diff.push([
|
|
|
|
|
prop, ': <', expectedFrame[prop], '> !== <', frame[prop], '>'
|
|
|
|
|
].join(''));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (diff.length) {
|
|
|
|
|
fail(message +
|
|
|
|
|
'\nfor: <' + frameOrFrameString + '>' +
|
|
|
|
|
'\nexpected: <' + expectedFrame + '>' +
|
|
|
|
|
'\nbut was: <' + frame + '>' +
|
|
|
|
|
'\n ' +
|
|
|
|
|
diff.join('\n '));
|
|
|
|
|
}
|
2012-07-02 19:46:57 +00:00
|
|
|
}
|
|
|
|
|
|
2013-06-14 07:03:52 -07:00
|
|
|
function assertFrame(frame, file, line) {
|
2015-02-21 09:59:24 -08:00
|
|
|
// Normalize path for when run through Node.js on Windows.
|
|
|
|
|
var url = frame.getUrl().replace(/\\/g, '/');
|
|
|
|
|
assertContains('/' + file, url);
|
2013-06-14 07:03:52 -07:00
|
|
|
assertEquals(line, frame.getLine());
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-05 20:39:52 -04:00
|
|
|
function testGetStacktraceFromFile() {
|
2013-06-14 07:03:52 -07:00
|
|
|
if (!webdriver.stacktrace.BROWSER_SUPPORTED) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var stacktrace = webdriver.test.testutil.getStackTrace();
|
2015-06-18 14:22:02 -07:00
|
|
|
assertFrame(stacktrace[0], 'testutil.js', 50);
|
2015-04-04 09:53:59 -07:00
|
|
|
assertFrame(stacktrace[1], 'stacktrace_test.js', 78);
|
2013-06-14 07:03:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function testGetStacktraceWithUrlOnLine() {
|
|
|
|
|
if (!webdriver.stacktrace.BROWSER_SUPPORTED) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The url argument is intentionally ignored here.
|
|
|
|
|
function getStacktraceWithUrlArgument(url) {
|
|
|
|
|
return webdriver.stacktrace.get();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var stacktrace = getStacktraceWithUrlArgument('http://www.google.com');
|
2015-04-04 09:53:59 -07:00
|
|
|
assertFrame(stacktrace[0], 'stacktrace_test.js', 90);
|
2013-06-14 07:03:52 -07:00
|
|
|
|
|
|
|
|
stacktrace = getStacktraceWithUrlArgument('http://www.google.com/search');
|
2015-04-04 09:53:59 -07:00
|
|
|
assertFrame(stacktrace[0], 'stacktrace_test.js', 90);
|
2013-06-14 07:03:52 -07:00
|
|
|
}
|
|
|
|
|
|
2012-07-02 19:46:57 +00:00
|
|
|
function testParseStackFrameInV8() {
|
2012-10-22 22:58:53 +00:00
|
|
|
assertStackFrame('exception name only (node v0.8)',
|
2012-07-02 19:46:57 +00:00
|
|
|
' at Error (unknown source)',
|
2013-06-14 07:03:52 -07:00
|
|
|
new webdriver.stacktrace.Frame('', 'Error', '', 'unknown source'));
|
2012-10-22 22:58:53 +00:00
|
|
|
|
|
|
|
|
assertStackFrame('exception name only (chrome v22)',
|
|
|
|
|
' at Error (<anonymous>)',
|
2013-06-14 07:03:52 -07:00
|
|
|
new webdriver.stacktrace.Frame('', 'Error', '', '<anonymous>'));
|
2012-07-02 19:46:57 +00:00
|
|
|
|
|
|
|
|
assertStackFrame('context object + function name + url',
|
|
|
|
|
' at Object.assert (file:///.../asserts.js:29:10)',
|
2013-06-14 07:03:52 -07:00
|
|
|
new webdriver.stacktrace.Frame('Object', 'assert', '',
|
2012-07-02 19:46:57 +00:00
|
|
|
'file:///.../asserts.js:29:10'));
|
|
|
|
|
|
|
|
|
|
assertStackFrame('context object + function name + file',
|
|
|
|
|
' at Object.assert (asserts.js:29:10)',
|
2013-06-14 07:03:52 -07:00
|
|
|
new webdriver.stacktrace.Frame('Object', 'assert', '',
|
2012-07-02 19:46:57 +00:00
|
|
|
'asserts.js:29:10'));
|
|
|
|
|
|
|
|
|
|
assertStackFrame('context object + anonymous function + file',
|
|
|
|
|
' at Interface.<anonymous> (repl.js:182:12)',
|
2013-06-14 07:03:52 -07:00
|
|
|
new webdriver.stacktrace.Frame('Interface', '<anonymous>', '',
|
2012-07-02 19:46:57 +00:00
|
|
|
'repl.js:182:12'));
|
|
|
|
|
|
|
|
|
|
assertStackFrame('url only',
|
|
|
|
|
' at http://www.example.com/jsunit.js:117:13',
|
2013-06-14 07:03:52 -07:00
|
|
|
new webdriver.stacktrace.Frame('', '', '',
|
2012-07-02 19:46:57 +00:00
|
|
|
'http://www.example.com/jsunit.js:117:13'));
|
|
|
|
|
|
|
|
|
|
assertStackFrame('file only',
|
|
|
|
|
' at repl:1:57',
|
2013-06-14 07:03:52 -07:00
|
|
|
new webdriver.stacktrace.Frame('', '', '', 'repl:1:57'));
|
2012-07-02 19:46:57 +00:00
|
|
|
|
|
|
|
|
assertStackFrame('function alias',
|
|
|
|
|
' at [object Object].exec [as execute] (file:///foo)',
|
2013-06-14 07:03:52 -07:00
|
|
|
new webdriver.stacktrace.Frame('[object Object]', 'exec',
|
2012-10-22 22:58:53 +00:00
|
|
|
'execute', 'file:///foo'));
|
2012-07-02 19:46:57 +00:00
|
|
|
|
|
|
|
|
assertStackFrame('constructor call',
|
|
|
|
|
' at new Class (file:///foo)',
|
2013-06-14 07:03:52 -07:00
|
|
|
new webdriver.stacktrace.Frame('new ', 'Class', '', 'file:///foo'));
|
2012-10-22 22:58:53 +00:00
|
|
|
|
|
|
|
|
assertStackFrame('object property constructor call',
|
|
|
|
|
' at new [object Object].foo (repl:1:2)',
|
2013-06-14 07:03:52 -07:00
|
|
|
new webdriver.stacktrace.Frame('new [object Object]', 'foo', '',
|
2012-10-22 22:58:53 +00:00
|
|
|
'repl:1:2'));
|
|
|
|
|
|
|
|
|
|
assertStackFrame('namespaced constructor call',
|
|
|
|
|
' at new foo.bar.Class (foo:1:2)',
|
2013-06-14 07:03:52 -07:00
|
|
|
new webdriver.stacktrace.Frame('new foo.bar', 'Class', '', 'foo:1:2'));
|
2012-07-02 19:46:57 +00:00
|
|
|
|
|
|
|
|
assertStackFrame('anonymous constructor call',
|
|
|
|
|
' at new <anonymous> (file:///foo)',
|
2013-06-14 07:03:52 -07:00
|
|
|
new webdriver.stacktrace.Frame('new ', '<anonymous>', '',
|
2012-07-02 19:46:57 +00:00
|
|
|
'file:///foo'));
|
|
|
|
|
|
|
|
|
|
assertStackFrame('native function call',
|
|
|
|
|
' at Array.forEach (native)',
|
2013-06-14 07:03:52 -07:00
|
|
|
new webdriver.stacktrace.Frame('Array', 'forEach', '', 'native'));
|
2012-07-02 19:46:57 +00:00
|
|
|
|
|
|
|
|
assertStackFrame('eval',
|
|
|
|
|
' at foo (eval at file://bar)',
|
2013-06-14 07:03:52 -07:00
|
|
|
new webdriver.stacktrace.Frame('', 'foo', '', 'eval at file://bar'));
|
2012-10-22 22:58:53 +00:00
|
|
|
|
|
|
|
|
assertStackFrame('nested anonymous eval',
|
|
|
|
|
' at eval (eval at <anonymous> (unknown source), <anonymous>:2:7)',
|
2013-06-14 07:03:52 -07:00
|
|
|
new webdriver.stacktrace.Frame('', 'eval', '',
|
2012-10-22 22:58:53 +00:00
|
|
|
'eval at <anonymous> (unknown source), <anonymous>:2:7'));
|
2013-06-14 07:03:52 -07:00
|
|
|
|
|
|
|
|
assertStackFrame('Url containing parentheses',
|
|
|
|
|
' at Object.assert (http://bar:4000/bar.js?value=(a):150:3)',
|
|
|
|
|
new webdriver.stacktrace.Frame('Object', 'assert', '',
|
|
|
|
|
'http://bar:4000/bar.js?value=(a):150:3'));
|
2014-10-08 10:57:56 -07:00
|
|
|
|
|
|
|
|
assertStackFrame('Frame with non-standard leading whitespace (issue 7994)',
|
|
|
|
|
' at module.exports.runCucumber (/local/dir/path)',
|
|
|
|
|
new webdriver.stacktrace.Frame('module.exports', 'runCucumber', '',
|
|
|
|
|
'/local/dir/path'));
|
2012-07-02 19:46:57 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-22 22:58:53 +00:00
|
|
|
function testParseClosureCanonicalStackFrame() {
|
|
|
|
|
assertStackFrame('unknown frame', '> (unknown)',
|
|
|
|
|
webdriver.stacktrace.ANONYMOUS_FRAME_);
|
|
|
|
|
assertStackFrame('anonymous frame', '> anonymous',
|
|
|
|
|
webdriver.stacktrace.ANONYMOUS_FRAME_);
|
|
|
|
|
|
|
|
|
|
assertStackFrame('name only', '> foo',
|
2013-06-14 07:03:52 -07:00
|
|
|
new webdriver.stacktrace.Frame('', 'foo', '', ''));
|
2012-10-22 22:58:53 +00:00
|
|
|
|
|
|
|
|
assertStackFrame('name and path', '> foo at http://x:123',
|
2013-06-14 07:03:52 -07:00
|
|
|
new webdriver.stacktrace.Frame('', 'foo', '', 'http://x:123'));
|
2012-10-22 22:58:53 +00:00
|
|
|
|
|
|
|
|
assertStackFrame('anonymous function with path',
|
|
|
|
|
'> anonymous at file:///x/y/z',
|
2013-06-14 07:03:52 -07:00
|
|
|
new webdriver.stacktrace.Frame('', 'anonymous', '', 'file:///x/y/z'));
|
2012-10-22 22:58:53 +00:00
|
|
|
|
|
|
|
|
assertStackFrame('anonymous function with v8 path',
|
|
|
|
|
'> anonymous at /x/y/z:12:34',
|
2013-06-14 07:03:52 -07:00
|
|
|
new webdriver.stacktrace.Frame('', 'anonymous', '', '/x/y/z:12:34'));
|
2012-10-22 22:58:53 +00:00
|
|
|
|
|
|
|
|
assertStackFrame('context and name only',
|
2013-06-14 07:03:52 -07:00
|
|
|
'> foo.bar', new webdriver.stacktrace.Frame('foo', 'bar', '', ''));
|
2012-10-22 22:58:53 +00:00
|
|
|
|
|
|
|
|
assertStackFrame('name and alias',
|
2013-06-14 07:03:52 -07:00
|
|
|
'> foo [as bar]', new webdriver.stacktrace.Frame('', 'foo', 'bar', ''));
|
2012-10-22 22:58:53 +00:00
|
|
|
|
|
|
|
|
assertStackFrame('context, name, and alias',
|
|
|
|
|
'> foo.bar [as baz]',
|
2013-06-14 07:03:52 -07:00
|
|
|
new webdriver.stacktrace.Frame('foo', 'bar', 'baz', ''));
|
2012-10-22 22:58:53 +00:00
|
|
|
|
|
|
|
|
assertStackFrame('path only', '> http://x:123',
|
2013-06-14 07:03:52 -07:00
|
|
|
new webdriver.stacktrace.Frame('', '', '', 'http://x:123'));
|
2012-10-22 22:58:53 +00:00
|
|
|
|
|
|
|
|
assertStackFrame('name and arguments',
|
2013-06-14 07:03:52 -07:00
|
|
|
'> foo(arguments)', new webdriver.stacktrace.Frame('', 'foo', '', ''));
|
2012-10-22 22:58:53 +00:00
|
|
|
|
|
|
|
|
assertStackFrame('full frame',
|
|
|
|
|
'> foo.bar(123, "abc") [as baz] at http://x:123',
|
2013-06-14 07:03:52 -07:00
|
|
|
new webdriver.stacktrace.Frame('foo', 'bar', 'baz', 'http://x:123'));
|
2012-10-22 22:58:53 +00:00
|
|
|
|
|
|
|
|
assertStackFrame('name and url with sub-domain',
|
|
|
|
|
'> foo at http://x.y.z:80/path:1:2',
|
2013-06-14 07:03:52 -07:00
|
|
|
new webdriver.stacktrace.Frame('', 'foo', '',
|
2012-10-22 22:58:53 +00:00
|
|
|
'http://x.y.z:80/path:1:2'));
|
|
|
|
|
|
|
|
|
|
assertStackFrame('name and url with sub-domain',
|
|
|
|
|
'> foo.bar.baz at http://x.y.z:80/path:1:2',
|
2013-06-14 07:03:52 -07:00
|
|
|
new webdriver.stacktrace.Frame('foo.bar', 'baz', '',
|
2012-10-22 22:58:53 +00:00
|
|
|
'http://x.y.z:80/path:1:2'));
|
2012-07-02 19:46:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// All test strings are parsed with the conventional and long
|
|
|
|
|
// frame algorithms.
|
|
|
|
|
function testParseStackFrameInFirefox() {
|
|
|
|
|
var frameString = 'Error("Assertion failed")@:0';
|
|
|
|
|
var frame = webdriver.stacktrace.parseStackFrame_(frameString);
|
2013-06-14 07:03:52 -07:00
|
|
|
var expected = new webdriver.stacktrace.Frame('', 'Error', '', '');
|
2012-07-02 19:46:57 +00:00
|
|
|
assertObjectEquals('function name + arguments', expected, frame);
|
|
|
|
|
|
|
|
|
|
frame = webdriver.stacktrace.parseLongFirefoxFrame_(frameString);
|
|
|
|
|
assertObjectEquals('function name + arguments', expected, frame);
|
|
|
|
|
|
|
|
|
|
frameString = '()@file:///foo:42';
|
|
|
|
|
frame = webdriver.stacktrace.parseStackFrame_(frameString);
|
2013-06-14 07:03:52 -07:00
|
|
|
expected = new webdriver.stacktrace.Frame('', '', '', 'file:///foo:42');
|
2012-07-02 19:46:57 +00:00
|
|
|
assertObjectEquals('anonymous function', expected, frame);
|
|
|
|
|
|
|
|
|
|
frame = webdriver.stacktrace.parseLongFirefoxFrame_(frameString);
|
|
|
|
|
assertObjectEquals('anonymous function', expected, frame);
|
|
|
|
|
|
|
|
|
|
frameString = '@javascript:alert(0)';
|
|
|
|
|
frame = webdriver.stacktrace.parseStackFrame_(frameString);
|
2013-06-14 07:03:52 -07:00
|
|
|
expected = new webdriver.stacktrace.Frame('', '', '', 'javascript:alert(0)');
|
2012-07-02 19:46:57 +00:00
|
|
|
assertObjectEquals('anonymous function', expected, frame);
|
|
|
|
|
|
|
|
|
|
frame = webdriver.stacktrace.parseLongFirefoxFrame_(frameString);
|
2012-10-22 22:58:53 +00:00
|
|
|
assertObjectEquals('anonymous function', expected, frame);
|
|
|
|
|
}
|
2012-07-02 19:46:57 +00:00
|
|
|
|
|
|
|
|
function testStringRepresentation() {
|
2013-06-14 07:03:52 -07:00
|
|
|
var frame = new webdriver.stacktrace.Frame('window', 'foo', 'bar',
|
2012-10-22 22:58:53 +00:00
|
|
|
'http://x?a=1&b=2:1');
|
|
|
|
|
assertEquals(' at window.foo [as bar] (http://x?a=1&b=2:1)',
|
2012-07-02 19:46:57 +00:00
|
|
|
frame.toString());
|
2012-10-22 22:58:53 +00:00
|
|
|
|
2013-06-14 07:03:52 -07:00
|
|
|
frame = new webdriver.stacktrace.Frame('', 'Error', '', '');
|
2012-10-22 22:58:53 +00:00
|
|
|
assertEquals(' at Error (<anonymous>)', frame.toString());
|
|
|
|
|
|
|
|
|
|
assertEquals(' at <anonymous>',
|
|
|
|
|
webdriver.stacktrace.ANONYMOUS_FRAME_.toString());
|
|
|
|
|
|
2013-06-14 07:03:52 -07:00
|
|
|
frame = new webdriver.stacktrace.Frame('', '', '', 'http://x:123');
|
2012-10-22 22:58:53 +00:00
|
|
|
assertEquals(' at http://x:123', frame.toString());
|
|
|
|
|
|
2013-06-14 07:03:52 -07:00
|
|
|
frame = new webdriver.stacktrace.Frame('foo', 'bar', '', 'http://x:123');
|
2012-10-22 22:58:53 +00:00
|
|
|
assertEquals(' at foo.bar (http://x:123)', frame.toString());
|
|
|
|
|
|
2013-06-14 07:03:52 -07:00
|
|
|
frame = new webdriver.stacktrace.Frame('new ', 'Foo', '', 'http://x:123');
|
2012-10-22 22:58:53 +00:00
|
|
|
assertEquals(' at new Foo (http://x:123)', frame.toString());
|
|
|
|
|
|
2013-06-14 07:03:52 -07:00
|
|
|
frame = new webdriver.stacktrace.Frame('new foo', 'Bar', '', '');
|
2012-10-22 22:58:53 +00:00
|
|
|
assertEquals(' at new foo.Bar (<anonymous>)', frame.toString());
|
2012-07-02 19:46:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create a stack trace string with one modest record and one long record,
|
|
|
|
|
// Verify that all frames are parsed. The length of the long arg is set
|
|
|
|
|
// to blow Firefox 3x's stack if put through a RegExp.
|
|
|
|
|
function testParsingLongStackTrace() {
|
|
|
|
|
var longArg = goog.string.buildString(
|
|
|
|
|
'(', goog.string.repeat('x', 1000000), ')');
|
|
|
|
|
var stackTrace = goog.string.buildString(
|
|
|
|
|
'shortFrame()@:0\n',
|
|
|
|
|
'longFrame',
|
|
|
|
|
longArg,
|
|
|
|
|
'@http://google.com/somescript:0\n');
|
2013-06-14 07:03:52 -07:00
|
|
|
var frames = webdriver.stacktrace.parse_(stackTrace);
|
2012-07-02 19:46:57 +00:00
|
|
|
assertEquals('number of returned frames', 2, frames.length);
|
2013-06-14 07:03:52 -07:00
|
|
|
var expected = new webdriver.stacktrace.Frame('', 'shortFrame', '', '');
|
2012-10-22 22:58:53 +00:00
|
|
|
assertStackFrame('short frame', frames[0], expected);
|
|
|
|
|
|
2013-06-14 07:03:52 -07:00
|
|
|
expected = new webdriver.stacktrace.Frame(
|
2012-10-22 22:58:53 +00:00
|
|
|
'', 'longFrame', '', 'http://google.com/somescript:0');
|
|
|
|
|
assertStackFrame('exception name only', frames[1], expected);
|
|
|
|
|
}
|
2012-07-02 19:46:57 +00:00
|
|
|
|
2012-10-22 22:58:53 +00:00
|
|
|
function testRemovesV8MessageHeaderBeforeParsingStack() {
|
2013-06-14 07:03:52 -07:00
|
|
|
var stack =
|
2012-10-22 22:58:53 +00:00
|
|
|
' at Color.red (http://x:1234)\n' +
|
2013-06-14 07:03:52 -07:00
|
|
|
' at Foo.bar (http://y:5678)';
|
2012-10-22 22:58:53 +00:00
|
|
|
|
2013-06-14 07:03:52 -07:00
|
|
|
var frames = webdriver.stacktrace.parse_(stack);
|
2012-10-22 22:58:53 +00:00
|
|
|
assertEquals(2, frames.length);
|
|
|
|
|
assertEquals(' at Color.red (http://x:1234)', frames[0].toString());
|
|
|
|
|
assertEquals(' at Foo.bar (http://y:5678)', frames[1].toString());
|
2012-07-02 19:46:57 +00:00
|
|
|
}
|
2012-10-22 22:58:53 +00:00
|
|
|
|
|
|
|
|
function testCanParseClosureJsUnitExceptions() {
|
|
|
|
|
stubs.set(goog.testing.stacktrace, 'get', function() {
|
|
|
|
|
return '> Color.red at http://x:1234\n' +
|
|
|
|
|
'> Foo.bar at http://y:5678';
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var error = new goog.testing.JsUnitException('stub');
|
|
|
|
|
stubs.reset();
|
|
|
|
|
|
2013-06-14 07:03:52 -07:00
|
|
|
var frames = webdriver.stacktrace.parse_(error.stackTrace);
|
2012-10-22 22:58:53 +00:00
|
|
|
assertEquals(2, frames.length);
|
|
|
|
|
assertEquals(' at Color.red (http://x:1234)', frames[0].toString());
|
|
|
|
|
assertEquals(' at Foo.bar (http://y:5678)', frames[1].toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function testFormattingAV8StyleError() {
|
|
|
|
|
var errorStub = {
|
2013-06-14 07:03:52 -07:00
|
|
|
name: 'Error',
|
|
|
|
|
message: 'foo',
|
2012-10-22 22:58:53 +00:00
|
|
|
toString: function() { return 'Error: foo'; },
|
|
|
|
|
stack:
|
|
|
|
|
'Error: foo\n' +
|
|
|
|
|
' at Color.red (http://x:1234)\n' +
|
|
|
|
|
' at Foo.bar (http://y:5678)'
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var ret = webdriver.stacktrace.format(errorStub);
|
|
|
|
|
assertEquals(errorStub, ret);
|
|
|
|
|
assertEquals([
|
|
|
|
|
'Error: foo',
|
|
|
|
|
' at Color.red (http://x:1234)',
|
|
|
|
|
' at Foo.bar (http://y:5678)'
|
|
|
|
|
].join('\n'), ret.stack);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function testFormattingAFirefoxStyleError() {
|
|
|
|
|
var errorStub = {
|
2013-06-14 07:03:52 -07:00
|
|
|
name: 'Error',
|
|
|
|
|
message: 'boom',
|
2012-10-22 22:58:53 +00:00
|
|
|
toString: function() { return 'Error: boom'; },
|
|
|
|
|
stack:
|
|
|
|
|
'foo@file:///foo/foo.js:1\n' +
|
|
|
|
|
'@file:///bar/bar.js:1'
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var ret = webdriver.stacktrace.format(errorStub);
|
|
|
|
|
assertEquals(errorStub, ret);
|
|
|
|
|
assertEquals([
|
|
|
|
|
'Error: boom',
|
|
|
|
|
' at foo (file:///foo/foo.js:1)',
|
|
|
|
|
' at file:///bar/bar.js:1'
|
|
|
|
|
].join('\n'), ret.stack);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function testInsertsAnAnonymousFrameWhenUnableToParse() {
|
|
|
|
|
var errorStub = {
|
2013-06-14 07:03:52 -07:00
|
|
|
name: 'Error',
|
|
|
|
|
message: 'boom',
|
2012-10-22 22:58:53 +00:00
|
|
|
toString: function() { return 'Error: boom'; },
|
|
|
|
|
stack:
|
|
|
|
|
'foo@file:///foo/foo.js:1\n' +
|
|
|
|
|
'this is unparsable garbage\n' +
|
|
|
|
|
'@file:///bar/bar.js:1'
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var ret = webdriver.stacktrace.format(errorStub);
|
|
|
|
|
assertEquals(errorStub, ret);
|
|
|
|
|
assertEquals([
|
|
|
|
|
'Error: boom',
|
|
|
|
|
' at foo (file:///foo/foo.js:1)',
|
|
|
|
|
' at <anonymous>',
|
|
|
|
|
' at file:///bar/bar.js:1'
|
|
|
|
|
].join('\n'), ret.stack);
|
|
|
|
|
}
|
2012-11-08 16:22:32 +00:00
|
|
|
|
|
|
|
|
function testFormattingBotErrors() {
|
|
|
|
|
var error = new bot.Error(bot.ErrorCode.NO_SUCH_ELEMENT, 'boom');
|
|
|
|
|
var expectedStack = [
|
|
|
|
|
'NoSuchElementError: boom',
|
|
|
|
|
' at Color.red (http://x:1234)',
|
|
|
|
|
' at Foo.bar (http://y:5678)'
|
|
|
|
|
].join('\n');
|
|
|
|
|
error.stack = expectedStack;
|
|
|
|
|
|
|
|
|
|
var ret = webdriver.stacktrace.format(error);
|
|
|
|
|
assertEquals(ret, error);
|
|
|
|
|
assertEquals(expectedStack, error.stack);
|
|
|
|
|
}
|
2012-10-22 22:58:53 +00:00
|
|
|
|
2013-06-14 07:03:52 -07:00
|
|
|
function testFormatsUsingNameAndMessageIfAvailable() {
|
|
|
|
|
var ret = webdriver.stacktrace.format({
|
|
|
|
|
name: 'TypeError',
|
|
|
|
|
message: 'boom'
|
|
|
|
|
});
|
|
|
|
|
assertEquals('TypeError: boom\n', ret.stack);
|
|
|
|
|
|
|
|
|
|
ret = webdriver.stacktrace.format({
|
|
|
|
|
message: 'boom'
|
|
|
|
|
});
|
|
|
|
|
assertEquals('boom\n', ret.stack);
|
|
|
|
|
|
|
|
|
|
ret = webdriver.stacktrace.format({
|
|
|
|
|
toString: function() {
|
|
|
|
|
return 'Hello world'
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
assertEquals('Hello world\n', ret.stack);
|
|
|
|
|
|
|
|
|
|
ret = webdriver.stacktrace.format({
|
|
|
|
|
name: 'TypeError',
|
|
|
|
|
message: 'boom',
|
|
|
|
|
toString: function() {
|
|
|
|
|
return 'Should not use this'
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
assertEquals('TypeError: boom\n', ret.stack);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-08 10:57:56 -07:00
|
|
|
function testDoesNotFormatErrorIfOriginalStacktraceIsInAnUnexpectedFormat() {
|
|
|
|
|
var error = Error('testing');
|
|
|
|
|
var stack = error.stack = [
|
|
|
|
|
'Error: testing',
|
|
|
|
|
'..> at Color.red (http://x:1234)',
|
|
|
|
|
'..> at Foo.bar (http://y:5678)'
|
|
|
|
|
].join('\n');
|
|
|
|
|
|
|
|
|
|
var ret = webdriver.stacktrace.format(error);
|
|
|
|
|
assertEquals(ret, error);
|
|
|
|
|
assertEquals(stack, error.stack);
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-14 07:03:52 -07:00
|
|
|
function testParseStackFrameInIE10() {
|
|
|
|
|
assertStackFrame('name and path',
|
|
|
|
|
' at foo (http://bar:4000/bar.js:150:3)',
|
|
|
|
|
new webdriver.stacktrace.Frame('', 'foo', '',
|
|
|
|
|
'http://bar:4000/bar.js:150:3'));
|
|
|
|
|
|
|
|
|
|
assertStackFrame('Anonymous function',
|
|
|
|
|
' at Anonymous function (http://bar:4000/bar.js:150:3)',
|
|
|
|
|
new webdriver.stacktrace.Frame('', 'Anonymous function', '',
|
|
|
|
|
'http://bar:4000/bar.js:150:3'));
|
|
|
|
|
|
|
|
|
|
assertStackFrame('Global code',
|
|
|
|
|
' at Global code (http://bar:4000/bar.js:150:3)',
|
|
|
|
|
new webdriver.stacktrace.Frame('', 'Global code', '',
|
|
|
|
|
'http://bar:4000/bar.js:150:3'));
|
|
|
|
|
|
|
|
|
|
assertStackFrame('eval code',
|
|
|
|
|
' at foo (eval code:150:3)',
|
|
|
|
|
new webdriver.stacktrace.Frame('', 'foo', '', 'eval code:150:3'));
|
|
|
|
|
|
|
|
|
|
assertStackFrame('nested eval',
|
|
|
|
|
' at eval code (eval code:150:3)',
|
|
|
|
|
new webdriver.stacktrace.Frame('', 'eval code', '', 'eval code:150:3'));
|
|
|
|
|
|
|
|
|
|
assertStackFrame('Url containing parentheses',
|
|
|
|
|
' at foo (http://bar:4000/bar.js?value=(a):150:3)',
|
|
|
|
|
new webdriver.stacktrace.Frame('', 'foo', '',
|
|
|
|
|
'http://bar:4000/bar.js?value=(a):150:3'));
|
|
|
|
|
|
|
|
|
|
assertStackFrame('Url ending with parentheses',
|
|
|
|
|
' at foo (http://bar:4000/bar.js?a=))',
|
|
|
|
|
new webdriver.stacktrace.Frame('', 'foo', '',
|
|
|
|
|
'http://bar:4000/bar.js?a=)'));
|
|
|
|
|
}
|