Files
svgedit/test/svgutils_test.html
Philip Rogers 7e3f9e037d Add pathseg.js, a polyfill for the SVGPathSeg API
The SVGPathSeg API is being removed from the spec [1] and is being
removed in Chromium 47 [2]. I implemented a drop-in polyfill[3] so
svg-edit users are not broken as browsers migrate away from the
path seg api.

This patch simply imports the upstream pathseg.js and updates all
dependencies. With this change all tests pass in Chrome 46 (with
the path seg api), Chrome 47 (without the path seg api), and
there are no changes to tests in Safari 9.01 or Firefox 43. I
also manually tested svg-edit while developing the polyfill and
could not find any broken features.

[1] https://lists.w3.org/Archives/Public/www-svg/2015Jun/0044.html
[2] https://groups.google.com/a/chromium.org/d/msg/blink-dev/EDC3cBg9mCU/OvElJgOWCgAJ
[3] https://github.com/progers/pathseg
2015-11-04 19:25:30 -08:00

136 lines
4.3 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Unit Tests for svgutils.js</title>
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
<script src='../editor/jquery.js'></script>
<script src='../editor/svgedit.js'></script>
<!-- svgutils.js depends on these three... mock out? -->
<script src='../editor/pathseg.js'></script>
<script src='../editor/browser.js'></script>
<script src='../editor/svgtransformlist.js'></script>
<script src='../editor/svgutils.js'></script>
<script src='qunit/qunit.js'></script>
<script>
$(function() {
// log function
QUnit.log = function(details) {
if (window.console && window.console.log) {
window.console.log(details.result +' :: '+ details.message);
}
};
var svg = document.createElementNS(svgedit.NS.SVG, 'svg');
module('svgedit.utilities');
test('Test svgedit.utilities package', function() {
expect(3);
ok(svgedit.utilities);
ok(svgedit.utilities.toXml);
equals(typeof svgedit.utilities.toXml, typeof function(){});
});
test('Test svgedit.utilities.toXml() function', function() {
expect(6);
var toXml = svgedit.utilities.toXml;
equals(toXml('a'), 'a');
equals(toXml('ABC_'), 'ABC_');
equals(toXml('PB&J'), 'PB&amp;J');
equals(toXml('2 < 5'), '2 &lt; 5');
equals(toXml('5 > 2'), '5 &gt; 2');
equals(toXml('\'<&>"'), '&#x27;&lt;&amp;&gt;&quot;');
});
test('Test svgedit.utilities.fromXml() function', function() {
expect(6);
var fromXml = svgedit.utilities.fromXml;
equals(fromXml('a'), 'a');
equals(fromXml('ABC_'), 'ABC_');
equals(fromXml('PB&amp;J'), 'PB&J');
equals(fromXml('2 &lt; 5'), '2 < 5');
equals(fromXml('5 &gt; 2'), '5 > 2');
equals(fromXml('&lt;&amp;&gt;'), '<&>');
});
test('Test svgedit.utilities.encode64() function', function() {
expect(4);
var encode64 = svgedit.utilities.encode64;
equals(encode64('abcdef'), 'YWJjZGVm');
equals(encode64('12345'), 'MTIzNDU=');
equals(encode64(' '), 'IA==');
equals(encode64('`~!@#$%^&*()-_=+[{]}\\|;:\'",<.>/?'), 'YH4hQCMkJV4mKigpLV89K1t7XX1cfDs6JyIsPC4+Lz8=');
});
test('Test svgedit.utilities.decode64() function', function() {
expect(4);
var decode64 = svgedit.utilities.decode64;
equals(decode64('YWJjZGVm'), 'abcdef');
equals(decode64('MTIzNDU='), '12345');
equals(decode64('IA=='), ' ');
equals(decode64('YH4hQCMkJV4mKigpLV89K1t7XX1cfDs6JyIsPC4+Lz8='), '`~!@#$%^&*()-_=+[{]}\\|;:\'",<.>/?');
});
test('Test svgedit.utilities.convertToXMLReferences() function', function() {
expect(1);
var convert = svgedit.utilities.convertToXMLReferences;
equals(convert('ABC'), 'ABC');
// equals(convert('ÀBC'), '&#192;BC');
});
test('Test svgedit.utilities.bboxToObj() function', function() {
expect(5);
var bboxToObj = svgedit.utilities.bboxToObj;
var rect = svg.createSVGRect();
rect.x = 1;
rect.y = 2;
rect.width = 3;
rect.height = 4;
var obj = bboxToObj(rect);
equals(typeof obj, typeof {});
equals(obj.x, 1);
equals(obj.y, 2);
equals(obj.width, 3);
equals(obj.height, 4);
});
test("Test getUrlFromAttr", function() {
expect(4);
equal(svgedit.utilities.getUrlFromAttr("url(#foo)"), "#foo");
equal(svgedit.utilities.getUrlFromAttr("url(somefile.svg#foo)"), "somefile.svg#foo");
equal(svgedit.utilities.getUrlFromAttr("url('#foo')"), "#foo");
equal(svgedit.utilities.getUrlFromAttr('url("#foo")'), "#foo");
});
test("Test getPathBBox", function() {
if(svgedit.browser.supportsPathBBox()) return;
var doc = svgedit.utilities.text2xml('<svg></svg>');
var path = doc.createElementNS(svgedit.NS.SVG, 'path');
path.setAttributeNS(null, 'd', 'm0,0l5,0l0,5l-5,0l0,-5z');
var bb = svgedit.utilities.getPathBBox(path);
equals(typeof bb, 'object', 'BBox returned object');
ok(bb.x && !isNaN(bb.x));
ok(bb.y && !isNaN(bb.y));
});
});
</script>
</head>
<body>
<h1 id='qunit-header'>Unit Tests for svgutils.js</h1>
<h2 id='qunit-banner'></h2>
<h2 id='qunit-userAgent'></h2>
<ol id='qunit-tests'></ol>
</body>
</html>