Path: blob/trunk/javascript/webdriver/test/logging_test.js
2868 views
// Licensed to the Software Freedom Conservancy (SFC) under one1// or more contributor license agreements. See the NOTICE file2// distributed with this work for additional information3// regarding copyright ownership. The SFC licenses this file4// to you under the Apache License, Version 2.0 (the5// "License"); you may not use this file except in compliance6// with the License. You may obtain a copy of the License at7//8// http://www.apache.org/licenses/LICENSE-2.09//10// Unless required by applicable law or agreed to in writing,11// software distributed under the License is distributed on an12// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13// KIND, either express or implied. See the License for the14// specific language governing permissions and limitations15// under the License.1617goog.require('goog.debug.LogRecord');18goog.require('goog.debug.Logger');19goog.require('goog.testing.jsunit');20goog.require('webdriver.logging');2122function convert(level, msg, name, time) {23var recordIn = new webdriver.logging.LogRecord(level, msg, name, time);24return webdriver.logging.Entry.fromClosureLogRecord(recordIn);25}2627function checkRecord(record, level, msg, time) {28assertEquals('wrong level', level.value, record.level.value);29assertEquals('wrong message', msg, record.message);30assertEquals('wrong time', time, record.timestamp);31}3233function testPreferencesToJSON() {34var prefs = new webdriver.logging.Preferences();35assertObjectEquals({}, prefs.toJSON());3637prefs.setLevel('foo', webdriver.logging.Level.DEBUG);38assertObjectEquals({'foo': 'DEBUG'}, prefs.toJSON());3940prefs.setLevel('bar', webdriver.logging.Level.OFF);41prefs.setLevel('baz', webdriver.logging.Level.WARNING);42assertObjectEquals(43{'foo': 'DEBUG', 'bar': 'OFF', 'baz': 'WARNING'},44prefs.toJSON());4546// CONFIG should always map to DEBUG.47prefs.setLevel('quux', webdriver.logging.Level.CONFIG);48assertObjectEquals(49{'foo': 'DEBUG', 'bar': 'OFF', 'baz': 'WARNING', 'quux': 'DEBUG'},50prefs.toJSON());5152prefs.setLevel('quot', webdriver.logging.Level.ALL);53assertObjectEquals(54{'foo': 'DEBUG', 'bar': 'OFF', 'baz': 'WARNING', 'quux': 'DEBUG',55'quot': 'ALL'},56prefs.toJSON());57}5859function testConvertingLogRecords() {60checkRecord(61convert(goog.debug.Logger.Level.SHOUT, 'foo bar', 'the.name', 1234),62webdriver.logging.Level.SEVERE, '[the.name] foo bar', 1234);63checkRecord(64convert(goog.debug.Logger.Level.SEVERE, 'foo bar', 'the.name', 1234),65webdriver.logging.Level.SEVERE, '[the.name] foo bar', 1234);66checkRecord(67convert(goog.debug.Logger.Level.WARNING, 'foo bar', 'the.name', 1234),68webdriver.logging.Level.WARNING, '[the.name] foo bar', 1234);69checkRecord(70convert(goog.debug.Logger.Level.INFO, 'foo bar', 'the.name', 1234),71webdriver.logging.Level.INFO, '[the.name] foo bar', 1234);72checkRecord(73convert(goog.debug.Logger.Level.CONFIG, 'foo bar', 'the.name', 1234),74webdriver.logging.Level.DEBUG, '[the.name] foo bar', 1234);75checkRecord(76convert(goog.debug.Logger.Level.FINE, 'foo bar', 'the.name', 1234),77webdriver.logging.Level.DEBUG, '[the.name] foo bar', 1234);78checkRecord(79convert(goog.debug.Logger.Level.FINER, 'foo bar', 'the.name', 1234),80webdriver.logging.Level.DEBUG, '[the.name] foo bar', 1234);81checkRecord(82convert(goog.debug.Logger.Level.FINEST, 'foo bar', 'the.name', 1234),83webdriver.logging.Level.DEBUG, '[the.name] foo bar', 1234);84}858687