Adding mapbox-gl branch
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<!--
|
||||
Copyright 2011 The Closure Library Authors. All Rights Reserved.
|
||||
|
||||
Use of this source code is governed by the Apache License, Version 2.0.
|
||||
See the COPYING file for details.
|
||||
|
||||
-->
|
||||
<head>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<title>Closure Unit Tests - goog.graphics.SvgGraphics</title>
|
||||
<script src="../base.js"></script>
|
||||
<script>
|
||||
goog.require('goog.dom');
|
||||
goog.require('goog.graphics.SvgGraphics');
|
||||
goog.require('goog.testing.graphics');
|
||||
goog.require('goog.testing.jsunit');
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"> </div>
|
||||
|
||||
<script>
|
||||
var graphics;
|
||||
|
||||
function setUp() {
|
||||
if (!document.createElementNS) {
|
||||
// Some browsers don't support document.createElementNS and this test
|
||||
// should not be run on those browsers (IE7,8).
|
||||
return;
|
||||
}
|
||||
graphics = new goog.graphics.SvgGraphics('100px', '100px');
|
||||
graphics.createDom();
|
||||
goog.dom.getElement('root').appendChild(graphics.getElement());
|
||||
}
|
||||
|
||||
function testAddDef() {
|
||||
if (!graphics) {
|
||||
// setUp has failed (no browser support), we should not run this test.
|
||||
return;
|
||||
}
|
||||
var defElement1 = document.createElement('div');
|
||||
var defElement2 = document.createElement('div');
|
||||
var defKey1 = 'def1';
|
||||
var defKey2 = 'def2';
|
||||
var id = graphics.addDef(defKey1, defElement1);
|
||||
assertEquals('_svgdef_0', id);
|
||||
id = graphics.addDef(defKey1, defElement2);
|
||||
assertEquals('_svgdef_0', id);
|
||||
id = graphics.addDef(defKey2, defElement2);
|
||||
assertEquals('_svgdef_1', id);
|
||||
}
|
||||
|
||||
function testGetDef() {
|
||||
if (!graphics) {
|
||||
// setUp has failed (no browser support), we should not run this test.
|
||||
return;
|
||||
}
|
||||
var defElement = document.createElement('div');
|
||||
var defKey = 'def';
|
||||
var id = graphics.addDef(defKey, defElement);
|
||||
assertEquals(id, graphics.getDef(defKey));
|
||||
assertNull(graphics.getDef('randomKey'));
|
||||
}
|
||||
|
||||
function testRemoveDef() {
|
||||
if (!graphics) {
|
||||
// setUp has failed (no browser support), we should not run this test.
|
||||
return;
|
||||
}
|
||||
var defElement = document.createElement('div');
|
||||
var defKey = 'def';
|
||||
var addedId = graphics.addDef(defKey, defElement);
|
||||
graphics.removeDef('randomKey');
|
||||
assertEquals(addedId, graphics.getDef(defKey));
|
||||
graphics.removeDef(defKey);
|
||||
assertNull(graphics.getDef(defKey));
|
||||
}
|
||||
|
||||
function testSetElementAffineTransform() {
|
||||
if (!graphics) {
|
||||
// setUp has failed (no browser support), we should not run this test.
|
||||
return;
|
||||
}
|
||||
var fill = new goog.graphics.SolidFill('blue');
|
||||
var stroke = null;
|
||||
var rad = -3.1415926 / 6;
|
||||
var costheta = Math.cos(rad);
|
||||
var sintheta = Math.sin(rad);
|
||||
var dx = 10;
|
||||
var dy = -20;
|
||||
var affine = new goog.graphics.AffineTransform(
|
||||
costheta, -sintheta + 1, sintheta, costheta, dx, dy);
|
||||
var rect = graphics.drawRect(10, 20, 30, 40, stroke, fill);
|
||||
rect.setTransform(affine);
|
||||
graphics.render();
|
||||
var svgMatrix = rect.getElement().getTransformToElement(graphics.getElement());
|
||||
assertRoughlyEquals(svgMatrix.a, costheta, 0.001);
|
||||
assertRoughlyEquals(svgMatrix.b, -sintheta + 1, 0.001);
|
||||
assertRoughlyEquals(svgMatrix.c, sintheta, 0.001);
|
||||
assertRoughlyEquals(svgMatrix.d, costheta, 0.001);
|
||||
assertRoughlyEquals(svgMatrix.e, dx, 0.001);
|
||||
assertRoughlyEquals(svgMatrix.f, dy, 0.001);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user