blob: 916be623b003d1108ebf21d468359421879c61c7 [file] [log] [blame]
// 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 psml_document.js.
*/
describe('PsmlDocument', function() {
it('should gracefully handle empty input', function() {
var psmlDocument = new pcap.PsmlDocument();
expect(psmlDocument.read()).toBe(false);
});
it('should extend from pcap.XmlDocument', function() {
var psmlDocument = new pcap.PsmlDocument();
expect(psmlDocument instanceof pcap.PsmlDocument).toBe(true);
expect(psmlDocument instanceof pcap.XmlDocument).toBe(true);
});
it('should return false for invalid XML', function() {
var xmlString = '>this<is><invalid><';
var parser = new DOMParser();
var xml = parser.parseFromString(xmlString, 'application/xml');
var psmlDocument = new pcap.PsmlDocument();
expect(psmlDocument.read(xml)).toBe(false);
});
it('should fail for PSML missing structure tag', function() {
var xmlString = '<?xml version="1.0"?>';
xmlString += '<psml version="0" creator="wireshark/1.99.0">';
xmlString += '<missingstructure><section>No.</section></missingstructure>';
xmlString += '<packet><section>1</section></packet>';
xmlString += '</psml>';
var parser = new DOMParser();
var xml = parser.parseFromString(xmlString, 'application/xml');
var psmlDocument = new pcap.PsmlDocument();
expect(psmlDocument.read(xml)).toBe(false);
expect(psmlDocument.structure_).toBe(null);
expect(psmlDocument.packets_.length).toBe(0);
});
it('should fail for PSML missing packet tag', function() {
var xmlString = '<?xml version="1.0"?>';
xmlString += '<psml version="0" creator="wireshark/1.99.0">';
xmlString += '<structure><section>No.</section></structure>';
xmlString += '<missingpacket><section>1</section></missingpacket>';
xmlString += '</psml>';
var parser = new DOMParser();
var xml = parser.parseFromString(xmlString, 'application/xml');
var psmlDocument = new pcap.PsmlDocument();
expect(psmlDocument.read(xml)).toBe(false);
expect(psmlDocument.structure_).toBe(null);
expect(psmlDocument.packets_.length).toBe(0);
});
it('should succed for valid PSML', function() {
var xmlString = '<?xml version="1.0"?>';
xmlString += '<psml version="0" creator="wireshark/1.99.0">';
xmlString += '<structure><section>foo</section></structure>';
xmlString += '<packet><section>bar</section></packet>';
xmlString += '</psml>';
var parser = new DOMParser();
var xml = parser.parseFromString(xmlString, 'application/xml');
var psmlDocument = new pcap.PsmlDocument();
expect(psmlDocument.read(xml)).toBe(true);
expect(psmlDocument.structure_).toBeDefined();
expect(psmlDocument.structure_.sections_.length).toBe(1);
expect(psmlDocument.structure_.sections_[0]).toBe('foo');
expect(psmlDocument.packets_.length).toBe(1);
expect(psmlDocument.packets_[0].sections_).toBeDefined();
expect(psmlDocument.packets_[0].sections_.length).toBe(1);
expect(psmlDocument.packets_[0].sections_[0]).toBe('bar');
});
});