| // Copyright 2015 The Chromium OS Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| /** |
| * @fileoverview Jasmine test file for netlog_summary.js. |
| */ |
| |
| describe('NetlogSummary', function() { |
| var logSummary; |
| var basicLog; |
| var time1; |
| var time2; |
| var time3; |
| |
| beforeEach(function() { |
| logSummary = new LogSummary(); |
| time1 = '2015-01-06T23:33:03.000000-08:00'; |
| time2 = '2015-01-06T23:33:06.000000-08:00'; |
| time3 = '2015-01-06T23:33:08.000000-08:00'; |
| time4 = '2015-01-06T23:33:09.000000-08:00'; |
| |
| basicLog = [ |
| time1 + ' wpa_supplicant[863]: nl80211: Scan trigger', |
| time2 + ' wpa_supplicant[863]: nl80211: Event message available', |
| time3 + ' wpa_supplicant[863]: nl80211: New scan results available' |
| ]; |
| |
| }); |
| |
| it('should return true for active states and false for others', function() { |
| expect(netlogSummary.isActive('Unknown')).toBe(false); |
| expect(netlogSummary.isActive('Idle')).toBe(false); |
| expect(netlogSummary.isActive('Associating')).toBe(true); |
| expect(netlogSummary.isActive('Configuring')).toBe(true); |
| expect(netlogSummary.isActive('Connected')).toBe(true); |
| expect(netlogSummary.isActive('Portal')).toBe(true); |
| expect(netlogSummary.isActive('Failure')).toBe(true); |
| expect(netlogSummary.isActive('Online')).toBe(true); |
| }); |
| |
| it('should gracefully handle empty files', function() { |
| var empty = []; |
| expect(netlogSummary.processLogLines(empty, logSummary)).toBe(null); |
| }); |
| |
| it('should gracefully handle unrelated files', function() { |
| var text = ['a', 'b']; |
| expect(netlogSummary.processLogLines(text, logSummary)).toBe(null); |
| }); |
| |
| it('should handle net.log files directly', function() { |
| var logText = netlogSummary.processLogLines(basicLog, logSummary); |
| expect(logSummary.logStartTime).toEqual(Date.parse(time1)); |
| expect(logSummary.logEndTime).toEqual(Date.parse(time3)); |
| expect(logSummary.managers.length).toBe(1); |
| }); |
| |
| it('should properly handle an incomplete first log line', function() { |
| var log; |
| var logLines = ['licant[781]: wlan0: skip - SSID mismatch']; |
| log = logLines.concat(basicLog); |
| var logText = netlogSummary.processLogLines(log, logSummary); |
| expect(logSummary.logStartTime).toEqual(Date.parse(time1)); |
| expect(logSummary.logEndTime).toEqual(Date.parse(time3)); |
| expect(logSummary.managers.length).toBe(1); |
| }); |
| |
| it('should add a new manager when seen in the log', function() { |
| var log = [ |
| time1 + ' wpa_supplicant[863]: nl80211: Scan trigger', |
| time2 + ' shill[1066]: [INFO:manager.cc(204)] Manager started.', |
| time3 + ' shill[937]: [INFO:manager.cc(204)] Manager started.' |
| ]; |
| var logText = netlogSummary.processLogLines(log, logSummary); |
| expect(logSummary.logStartTime).toEqual(Date.parse(time1)); |
| expect(logSummary.logEndTime).toEqual(Date.parse(time3)); |
| expect(logSummary.managers.length).toBe(3); |
| }); |
| |
| it('should not add default manager log is a clean start', function() { |
| var log = [ |
| time1 + ' shill[1066]: [INFO:manager.cc(204)] Manager started.', |
| time2 + ' shill[937]: [INFO:manager.cc(204)] Manager started.' |
| ]; |
| var logText = netlogSummary.processLogLines(log, logSummary); |
| expect(logSummary.logStartTime).toEqual(Date.parse(time1)); |
| expect(logSummary.logEndTime).toEqual(Date.parse(time2)); |
| expect(logSummary.managers.length).toBe(2); |
| }); |
| |
| it('should properly set the log end time', function() { |
| var logText = netlogSummary.processLogLines(basicLog, logSummary); |
| expect(logSummary.logStartTime).toEqual(Date.parse(time1)); |
| expect(logSummary.logEndTime).toEqual(Date.parse(time3)); |
| }); |
| |
| it('should properly handle a single line log', function() { |
| var log = [time1 + ' wpa_supplicant[863]: nl80211: Scan trigger']; |
| var logText = netlogSummary.processLogLines(log, logSummary); |
| expect(logSummary.logStartTime).toEqual(Date.parse(time1)); |
| expect(logSummary.logEndTime).toEqual(Date.parse(time1)); |
| }); |
| |
| it('should properly handle DisconnectReason updates', function() { |
| var log = [ |
| time1 + ' INFO shill[2590]: [INFO:wifi.cc(872)] WiFi mlan0 ' + |
| 'supplicant updated DisconnectReason to -3', |
| time1 + ' INFO shill[2590]: [INFO:wifi.cc(872)] WiFi mlan0 ' + |
| 'supplicant updated DisconnectReason to -3 (was 7)', |
| time1 + ' INFO shill[2590]: [INFO:wifi.cc(872)] WiFi mlan0 ' + |
| 'supplicant updated DisconnectReason to 3 (was -7)', |
| time1 + ' INFO shill[2590]: [INFO:wifi.cc(872)] WiFi mlan0 ' + |
| 'supplicant updated DisconnectReason to -3 (was -7)', |
| time1 + ' INFO shill[2590]: [INFO:wifi.cc(872)] WiFi mlan0 ' + |
| 'supplicant updated DisconnectReason to 3' |
| ]; |
| var match = log[0].match(netlogSummary.taggedLines['disconnect_reason'].re); |
| expect(match[2]).toEqual('-3'); |
| match = log[1].match(netlogSummary.taggedLines['disconnect_reason'].re); |
| expect(match[2]).toEqual('-3'); |
| expect(match[4]).toEqual('7'); |
| match = log[2].match(netlogSummary.taggedLines['disconnect_reason'].re); |
| expect(match[2]).toEqual('3'); |
| expect(match[4]).toEqual('-7'); |
| match = log[3].match(netlogSummary.taggedLines['disconnect_reason'].re); |
| expect(match[2]).toEqual('-3'); |
| expect(match[4]).toEqual('-7'); |
| match = log[4].match(netlogSummary.taggedLines['disconnect_reason'].re); |
| expect(match[2]).toEqual('3'); |
| }); |
| |
| it('should properly handle supplicant state change updates', function() { |
| |
| var log = [ |
| time1 + ' wpa_supplicant[408]: mlan0: State: COMPLETED -> DISCONNECTED', |
| time2 + ' wpa_supplicant[408]: mlan0: ' + |
| 'State: DISCONNECTED -> DISCONNECTED', |
| time3 + ' wpa_supplicant[408]: mlan0: State: DISCONNECTED -> SCANNING', |
| time4 + ' wpa_supplicant[408]: mlan0: State: SCANNING -> IDLE' |
| ]; |
| |
| netlogSummary.processLogLines(log, logSummary); |
| expect(logSummary.managers.length).toBe(1); |
| |
| var checkStates = logSummary.managers[0].supplicantStates; |
| expect(checkStates.length).toBe(7); |
| expect(checkStates[0].x).toBe(0); |
| expect(checkStates[0].y).toBe('COMPLETED'); |
| expect(checkStates[1].x).toBe(0); |
| expect(checkStates[1].y).toBe('COMPLETED'); |
| expect(checkStates[2].x).toBe(0); |
| expect(checkStates[2].y).toBe('DISCONNECTED'); |
| expect(checkStates[3].x).toBe(5000); |
| expect(checkStates[3].y).toBe('DISCONNECTED'); |
| expect(checkStates[4].x).toBe(5000); |
| expect(checkStates[4].y).toBe('SCANNING'); |
| expect(checkStates[5].x).toBe(6000); |
| expect(checkStates[5].y).toBe('SCANNING'); |
| expect(checkStates[6].x).toBe(6000); |
| expect(checkStates[6].y).toBe('IDLE'); |
| |
| expect(logSummary.managers[0].notes.length).toBe(4); |
| }); |
| }); |