Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/javascript/webdriver/test/logging_test.js
2868 views
1
// Licensed to the Software Freedom Conservancy (SFC) under one
2
// or more contributor license agreements. See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership. The SFC licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License. You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied. See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
goog.require('goog.debug.LogRecord');
19
goog.require('goog.debug.Logger');
20
goog.require('goog.testing.jsunit');
21
goog.require('webdriver.logging');
22
23
function convert(level, msg, name, time) {
24
var recordIn = new webdriver.logging.LogRecord(level, msg, name, time);
25
return webdriver.logging.Entry.fromClosureLogRecord(recordIn);
26
}
27
28
function checkRecord(record, level, msg, time) {
29
assertEquals('wrong level', level.value, record.level.value);
30
assertEquals('wrong message', msg, record.message);
31
assertEquals('wrong time', time, record.timestamp);
32
}
33
34
function testPreferencesToJSON() {
35
var prefs = new webdriver.logging.Preferences();
36
assertObjectEquals({}, prefs.toJSON());
37
38
prefs.setLevel('foo', webdriver.logging.Level.DEBUG);
39
assertObjectEquals({'foo': 'DEBUG'}, prefs.toJSON());
40
41
prefs.setLevel('bar', webdriver.logging.Level.OFF);
42
prefs.setLevel('baz', webdriver.logging.Level.WARNING);
43
assertObjectEquals(
44
{'foo': 'DEBUG', 'bar': 'OFF', 'baz': 'WARNING'},
45
prefs.toJSON());
46
47
// CONFIG should always map to DEBUG.
48
prefs.setLevel('quux', webdriver.logging.Level.CONFIG);
49
assertObjectEquals(
50
{'foo': 'DEBUG', 'bar': 'OFF', 'baz': 'WARNING', 'quux': 'DEBUG'},
51
prefs.toJSON());
52
53
prefs.setLevel('quot', webdriver.logging.Level.ALL);
54
assertObjectEquals(
55
{'foo': 'DEBUG', 'bar': 'OFF', 'baz': 'WARNING', 'quux': 'DEBUG',
56
'quot': 'ALL'},
57
prefs.toJSON());
58
}
59
60
function testConvertingLogRecords() {
61
checkRecord(
62
convert(goog.debug.Logger.Level.SHOUT, 'foo bar', 'the.name', 1234),
63
webdriver.logging.Level.SEVERE, '[the.name] foo bar', 1234);
64
checkRecord(
65
convert(goog.debug.Logger.Level.SEVERE, 'foo bar', 'the.name', 1234),
66
webdriver.logging.Level.SEVERE, '[the.name] foo bar', 1234);
67
checkRecord(
68
convert(goog.debug.Logger.Level.WARNING, 'foo bar', 'the.name', 1234),
69
webdriver.logging.Level.WARNING, '[the.name] foo bar', 1234);
70
checkRecord(
71
convert(goog.debug.Logger.Level.INFO, 'foo bar', 'the.name', 1234),
72
webdriver.logging.Level.INFO, '[the.name] foo bar', 1234);
73
checkRecord(
74
convert(goog.debug.Logger.Level.CONFIG, 'foo bar', 'the.name', 1234),
75
webdriver.logging.Level.DEBUG, '[the.name] foo bar', 1234);
76
checkRecord(
77
convert(goog.debug.Logger.Level.FINE, 'foo bar', 'the.name', 1234),
78
webdriver.logging.Level.DEBUG, '[the.name] foo bar', 1234);
79
checkRecord(
80
convert(goog.debug.Logger.Level.FINER, 'foo bar', 'the.name', 1234),
81
webdriver.logging.Level.DEBUG, '[the.name] foo bar', 1234);
82
checkRecord(
83
convert(goog.debug.Logger.Level.FINEST, 'foo bar', 'the.name', 1234),
84
webdriver.logging.Level.DEBUG, '[the.name] foo bar', 1234);
85
}
86
87