Debian Codegraph @

closure-library/closure/goog/messaging/loggerclient_test.js

raw
1 // Copyright 2010 The Closure Library Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS-IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 goog.provide('goog.messaging.LoggerClientTest');
16 goog.setTestOnly('goog.messaging.LoggerClientTest');
17
18 goog.require('goog.debug');
19 goog.require('goog.debug.Logger');
20 goog.require('goog.messaging.LoggerClient');
21 goog.require('goog.testing.MockControl');
22 goog.require('goog.testing.jsunit');
23 goog.require('goog.testing.messaging.MockMessageChannel');
24
25 var mockControl;
26 var channel;
27 var client;
28 var logger;
29
30 function setUp() {
31 goog.debug.FORCE_SLOPPY_STACKS = false;
32 mockControl = new goog.testing.MockControl();
33 channel = new goog.testing.messaging.MockMessageChannel(mockControl);
34 client = new goog.messaging.LoggerClient(channel, 'log');
35 logger = goog.debug.Logger.getLogger('test.logging.Object');
36 }
37
38 function tearDown() {
39 channel.dispose();
40 client.dispose();
41 }
42
43 function testCommand() {
44 channel.send('log', {
45 name: 'test.logging.Object',
46 level: goog.debug.Logger.Level.WARNING.value,
47 message: 'foo bar',
48 exception: undefined
49 });
50 mockControl.$replayAll();
51 logger.warning('foo bar');
52 mockControl.$verifyAll();
53 }
54
55 function testCommandWithException() {
56 var ex = Error('oh no');
57 ex.stack = ['one', 'two'];
58 ex.message0 = 'message 0';
59 ex.message1 = 'message 1';
60 ex.ignoredProperty = 'ignored';
61
62 channel.send('log', {
63 name: 'test.logging.Object',
64 level: goog.debug.Logger.Level.WARNING.value,
65 message: 'foo bar',
66 exception: {
67 name: 'Error',
68 message: ex.message,
69 stack: ex.stack,
70 lineNumber: ex.lineNumber || ex.line || 'Not available',
71 fileName: ex.fileName || ex.sourceURL || window.location.href,
72 message0: ex.message0,
73 message1: ex.message1
74 }
75 });
76 mockControl.$replayAll();
77 logger.warning('foo bar', ex);
78 mockControl.$verifyAll();
79 }
80
81 function testCommandWithStringException() {
82 // NOTE: the stack traces won't match with the strict mode compatible
83 // stack traces as they are recorded in different locations.
84 goog.debug.FORCE_SLOPPY_STACKS = true;
85
86 channel.send('log', {
87 name: 'test.logging.Object',
88 level: goog.debug.Logger.Level.WARNING.value,
89 message: 'foo bar',
90 exception: {
91 name: 'Unknown error',
92 message: 'oh no',
93 stack: '[Anonymous](object, foo bar, oh no)\n' +
94 '[Anonymous](foo bar, oh no)\n' + goog.debug.getStacktrace(),
95 lineNumber: 'Not available',
96 fileName: window.location.href
97 }
98 });
99 mockControl.$replayAll();
100 logger.warning('foo bar', 'oh no');
101 mockControl.$verifyAll();
102 }