2011-01-13 06:57:26 +00:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
|
|
|
|
<script src='../editor/jquery.js'></script>
|
2011-01-16 23:07:35 +00:00
|
|
|
<script type='text/javascript' src='../editor/draw.js'></script>
|
2011-01-13 06:57:26 +00:00
|
|
|
<script type='text/javascript' src='qunit/qunit.js'></script>
|
|
|
|
<script type='text/javascript'>
|
|
|
|
$(function() {
|
|
|
|
// log function
|
|
|
|
QUnit.log = function(result, message) {
|
|
|
|
if (window.console && window.console.log) {
|
|
|
|
window.console.log(result +' :: '+ message);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var SVGNS = 'http://www.w3.org/2000/svg';
|
|
|
|
var SENS = "http://svg-edit.googlecode.com";
|
|
|
|
var XMLNSNS = "http://www.w3.org/2000/xmlns/";
|
|
|
|
var NONCE = 'foo';
|
|
|
|
|
|
|
|
var svg = document.createElementNS(SVGNS, 'svg');
|
|
|
|
|
|
|
|
// Set up <svg> with nonce.
|
|
|
|
var svg_n = document.createElementNS(SVGNS, 'svg');
|
|
|
|
svg_n.setAttributeNS(XMLNSNS, 'xmlns:se', SENS);
|
|
|
|
svg_n.setAttributeNS(SENS, 'se:nonce', NONCE);
|
|
|
|
|
2011-01-16 23:07:35 +00:00
|
|
|
test('Test draw module', function() {
|
2011-01-13 06:57:26 +00:00
|
|
|
expect(4);
|
|
|
|
|
2011-01-16 23:07:35 +00:00
|
|
|
ok(svgedit.draw);
|
|
|
|
equals(typeof svgedit.draw, typeof {});
|
2011-01-13 06:57:26 +00:00
|
|
|
|
2011-01-16 23:07:35 +00:00
|
|
|
ok(svgedit.draw.Drawing);
|
|
|
|
equals(typeof svgedit.draw.Drawing, typeof function(){});
|
2011-01-13 06:57:26 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Test document creation', function() {
|
|
|
|
expect(3);
|
|
|
|
|
|
|
|
try {
|
2011-01-16 23:07:35 +00:00
|
|
|
var doc = new svgedit.draw.Drawing();
|
|
|
|
ok(false, 'Created drawing without a valid <svg> element');
|
2011-01-13 06:57:26 +00:00
|
|
|
} catch(e) {
|
|
|
|
ok(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2011-01-16 23:07:35 +00:00
|
|
|
var doc = new svgedit.draw.Drawing(svg);
|
2011-01-13 06:57:26 +00:00
|
|
|
ok(doc);
|
|
|
|
equals(typeof doc, typeof {});
|
|
|
|
} catch(e) {
|
|
|
|
ok(false, 'Could not create document from valid <svg> element: ' + e)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Test nonce', function() {
|
|
|
|
expect(2);
|
|
|
|
|
2011-01-16 23:07:35 +00:00
|
|
|
var doc = new svgedit.draw.Drawing(svg);
|
2011-01-13 06:57:26 +00:00
|
|
|
equals(doc.getNonce(), "");
|
|
|
|
|
2011-01-16 23:07:35 +00:00
|
|
|
doc = new svgedit.draw.Drawing(svg_n);
|
2011-01-13 06:57:26 +00:00
|
|
|
equals(doc.getNonce(), NONCE);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Test getId() and getNextId() without nonce', function() {
|
|
|
|
expect(7);
|
|
|
|
|
|
|
|
var elem2 = document.createElementNS(SVGNS, 'circle');
|
|
|
|
elem2.id = 'svg_2';
|
|
|
|
svg.appendChild(elem2);
|
|
|
|
|
2011-01-16 23:07:35 +00:00
|
|
|
var doc = new svgedit.draw.Drawing(svg);
|
2011-01-13 06:57:26 +00:00
|
|
|
|
|
|
|
equals(doc.getId(), "svg_0");
|
|
|
|
|
|
|
|
equals(doc.getNextId(), "svg_1");
|
|
|
|
equals(doc.getId(), "svg_1");
|
|
|
|
|
|
|
|
equals(doc.getNextId(), "svg_3");
|
|
|
|
equals(doc.getId(), "svg_3");
|
|
|
|
|
|
|
|
equals(doc.getNextId(), "svg_4");
|
|
|
|
equals(doc.getId(), "svg_4");
|
|
|
|
|
|
|
|
// clean out svg document
|
|
|
|
while(svg.firstChild) {svg.removeChild(svg.firstChild);}
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Test getId() and getNextId() with prefix without nonce', function() {
|
|
|
|
expect(7);
|
|
|
|
|
|
|
|
var prefix = 'Bar-';
|
2011-01-16 23:07:35 +00:00
|
|
|
var doc = new svgedit.draw.Drawing(svg, prefix);
|
2011-01-13 06:57:26 +00:00
|
|
|
|
|
|
|
equals(doc.getId(), prefix+"0");
|
|
|
|
|
|
|
|
equals(doc.getNextId(), prefix+"1");
|
|
|
|
equals(doc.getId(), prefix+"1");
|
|
|
|
|
|
|
|
equals(doc.getNextId(), prefix+"2");
|
|
|
|
equals(doc.getId(), prefix+"2");
|
|
|
|
|
|
|
|
equals(doc.getNextId(), prefix+"3");
|
|
|
|
equals(doc.getId(), prefix+"3");
|
|
|
|
|
|
|
|
while(svg.firstChild) {svg.removeChild(svg.firstChild);}
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Test getId() and getNextId() with nonce', function() {
|
|
|
|
expect(7);
|
|
|
|
|
|
|
|
var prefix = "svg_" + NONCE;
|
|
|
|
|
|
|
|
var elem2 = document.createElementNS(SVGNS, 'circle');
|
|
|
|
elem2.id = prefix+'_2';
|
|
|
|
svg_n.appendChild(elem2);
|
|
|
|
|
2011-01-16 23:07:35 +00:00
|
|
|
var doc = new svgedit.draw.Drawing(svg_n);
|
2011-01-13 06:57:26 +00:00
|
|
|
|
|
|
|
equals(doc.getId(), prefix+"_0");
|
|
|
|
|
|
|
|
equals(doc.getNextId(), prefix+"_1");
|
|
|
|
equals(doc.getId(), prefix+"_1");
|
|
|
|
|
|
|
|
equals(doc.getNextId(), prefix+"_3");
|
|
|
|
equals(doc.getId(), prefix+"_3");
|
|
|
|
|
|
|
|
equals(doc.getNextId(), prefix+"_4");
|
|
|
|
equals(doc.getId(), prefix+"_4");
|
|
|
|
while(svg_n.firstChild) {svg_n.removeChild(svg_n.firstChild);}
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Test getId() and getNextId() with prefix with nonce', function() {
|
|
|
|
expect(7);
|
|
|
|
|
|
|
|
var PREFIX = 'Bar-';
|
2011-01-16 23:07:35 +00:00
|
|
|
var doc = new svgedit.draw.Drawing(svg_n, PREFIX);
|
2011-01-13 06:57:26 +00:00
|
|
|
|
|
|
|
var prefix = PREFIX + NONCE + "_";
|
|
|
|
equals(doc.getId(), prefix+"0");
|
|
|
|
|
|
|
|
equals(doc.getNextId(), prefix+"1");
|
|
|
|
equals(doc.getId(), prefix+"1");
|
|
|
|
|
|
|
|
equals(doc.getNextId(), prefix+"2");
|
|
|
|
equals(doc.getId(), prefix+"2");
|
|
|
|
|
|
|
|
equals(doc.getNextId(), prefix+"3");
|
|
|
|
equals(doc.getId(), prefix+"3");
|
|
|
|
|
|
|
|
while(svg_n.firstChild) {svg_n.removeChild(svg.firstChild);}
|
|
|
|
});
|
2011-01-14 18:18:29 +00:00
|
|
|
|
|
|
|
test('Test releaseId()', function() {
|
|
|
|
expect(6);
|
|
|
|
|
2011-01-16 23:07:35 +00:00
|
|
|
var doc = new svgedit.draw.Drawing(svg);
|
2011-01-14 18:18:29 +00:00
|
|
|
|
|
|
|
var firstId = doc.getNextId();
|
|
|
|
var secondId = doc.getNextId();
|
|
|
|
|
|
|
|
var result = doc.releaseId(firstId);
|
|
|
|
ok(result);
|
|
|
|
equals(doc.getNextId(), firstId);
|
|
|
|
equals(doc.getNextId(), "svg_3");
|
|
|
|
|
|
|
|
ok(!doc.releaseId("bad-id"));
|
|
|
|
ok(doc.releaseId(firstId));
|
|
|
|
ok(!doc.releaseId(firstId));
|
|
|
|
});
|
2011-01-16 23:07:35 +00:00
|
|
|
|
|
|
|
test('Test getNumLayers', function() {
|
|
|
|
expect(2);
|
|
|
|
var doc = new svgedit.draw.Drawing(svg);
|
|
|
|
equals(typeof doc.getNumLayers, typeof function() {});
|
|
|
|
equals(doc.getNumLayers(), 0);
|
2011-01-16 23:18:51 +00:00
|
|
|
// TODO(codedread): More here once identifyLayers works.
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Test hasLayer', function() {
|
|
|
|
expect(2);
|
|
|
|
var doc = new svgedit.draw.Drawing(svg);
|
|
|
|
equals(typeof doc.hasLayer, typeof function() {});
|
|
|
|
ok(!doc.hasLayer('invalid-layer'));
|
|
|
|
// TODO(codedread): More here once identifyLayers works.
|
2011-01-16 23:07:35 +00:00
|
|
|
});
|
2011-01-13 06:57:26 +00:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
</head>
|
|
|
|
<body>
|
2011-01-16 23:07:35 +00:00
|
|
|
<h1 id='qunit-header'>Unit Tests for draw.js</h1>
|
2011-01-13 06:57:26 +00:00
|
|
|
<h2 id='qunit-banner'></h2>
|
|
|
|
<h2 id='qunit-userAgent'></h2>
|
|
|
|
<ol id='qunit-tests'>
|
|
|
|
</ol>
|
|
|
|
<div id='anchor' style='visibility:hidden'>
|
|
|
|
</div>
|
|
|
|
</body>
|
|
|
|
</html>
|