Adding mapbox-gl branch

This commit is contained in:
Andreas Hocevar
2015-03-16 18:50:27 +01:00
parent 7985f030fa
commit 57ee7f52fd
3109 changed files with 943365 additions and 0 deletions
@@ -0,0 +1,58 @@
// Copyright 2009 The Closure Library Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS-IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/**
* @fileoverview Additional asserts for testing ControlRenderers.
*
* @author mkretzschmar@google.com (Martin Kretzschmar)
*/
goog.provide('goog.testing.ui.rendererasserts');
goog.require('goog.testing.asserts');
goog.require('goog.ui.ControlRenderer');
/**
* Assert that a control renderer constructor doesn't call getCssClass.
*
* @param {?function(new:goog.ui.ControlRenderer)} rendererClassUnderTest The
* renderer constructor to test.
*/
goog.testing.ui.rendererasserts.assertNoGetCssClassCallsInConstructor =
function(rendererClassUnderTest) {
var getCssClassCalls = 0;
/**
* @constructor
* @extends {goog.ui.ControlRenderer}
* @final
*/
function TestControlRenderer() {
rendererClassUnderTest.call(this);
}
goog.inherits(TestControlRenderer, rendererClassUnderTest);
/** @override */
TestControlRenderer.prototype.getCssClass = function() {
getCssClassCalls++;
return TestControlRenderer.superClass_.getCssClass.call(this);
};
var testControlRenderer = new TestControlRenderer();
assertEquals('Constructors should not call getCssClass, ' +
'getCustomRenderer must be able to override it post construction.',
0, getCssClassCalls);
};
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html>
<!--
Copyright 2009 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.
-->
<!--
Author: mkretzschmar@google.com (Martin Kretzschmar)
-->
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>
Closure Unit Tests - goog.testing.ui.rendererasserts
</title>
<script src="../../base.js">
</script>
<script>
goog.require('goog.testing.ui.rendererassertsTest');
</script>
</head>
<body>
</body>
</html>
@@ -0,0 +1,46 @@
// Copyright 2009 The Closure Library Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS-IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
goog.provide('goog.testing.ui.rendererassertsTest');
goog.setTestOnly('goog.testing.ui.rendererassertsTest');
goog.require('goog.testing.asserts');
goog.require('goog.testing.jsunit');
goog.require('goog.testing.ui.rendererasserts');
goog.require('goog.ui.ControlRenderer');
function testSuccess() {
function GoodRenderer() {}
goog.testing.ui.rendererasserts.
assertNoGetCssClassCallsInConstructor(GoodRenderer);
}
function testFailure() {
function BadRenderer() {
goog.ui.ControlRenderer.call(this);
this.myClass = this.getCssClass();
}
goog.inherits(BadRenderer, goog.ui.ControlRenderer);
var ex = assertThrows(
'Expected assertNoGetCssClassCallsInConstructor to fail.',
function() {
goog.testing.ui.rendererasserts.
assertNoGetCssClassCallsInConstructor(BadRenderer);
});
assertTrue('Expected assertNoGetCssClassCallsInConstructor to throw a' +
' jsunit exception', ex.isJsUnitException);
assertContains('getCssClass', ex.message);
}
@@ -0,0 +1,177 @@
// Copyright 2009 The Closure Library Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS-IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// All Rights Reserved
/**
* @fileoverview A driver for testing renderers.
*
* @author nicksantos@google.com (Nick Santos)
*/
goog.provide('goog.testing.ui.RendererHarness');
goog.require('goog.Disposable');
goog.require('goog.dom.NodeType');
goog.require('goog.testing.asserts');
goog.require('goog.testing.dom');
/**
* A driver for testing renderers.
*
* @param {goog.ui.ControlRenderer} renderer A renderer to test.
* @param {Element} renderParent The parent of the element where controls will
* be rendered.
* @param {Element} decorateParent The parent of the element where controls will
* be decorated.
* @constructor
* @extends {goog.Disposable}
* @final
*/
goog.testing.ui.RendererHarness = function(renderer, renderParent,
decorateParent) {
goog.Disposable.call(this);
/**
* The renderer under test.
* @type {goog.ui.ControlRenderer}
* @private
*/
this.renderer_ = renderer;
/**
* The parent of the element where controls will be rendered.
* @type {Element}
* @private
*/
this.renderParent_ = renderParent;
/**
* The original HTML of the render element.
* @type {string}
* @private
*/
this.renderHtml_ = renderParent.innerHTML;
/**
* Teh parent of the element where controls will be decorated.
* @type {Element}
* @private
*/
this.decorateParent_ = decorateParent;
/**
* The original HTML of the decorated element.
* @type {string}
* @private
*/
this.decorateHtml_ = decorateParent.innerHTML;
};
goog.inherits(goog.testing.ui.RendererHarness, goog.Disposable);
/**
* A control to create by decoration.
* @type {goog.ui.Control}
* @private
*/
goog.testing.ui.RendererHarness.prototype.decorateControl_;
/**
* A control to create by rendering.
* @type {goog.ui.Control}
* @private
*/
goog.testing.ui.RendererHarness.prototype.renderControl_;
/**
* Whether all the necessary assert methods have been called.
* @type {boolean}
* @private
*/
goog.testing.ui.RendererHarness.prototype.verified_ = false;
/**
* Attach a control and render its DOM.
* @param {goog.ui.Control} control A control.
* @return {Element} The element created.
*/
goog.testing.ui.RendererHarness.prototype.attachControlAndRender =
function(control) {
this.renderControl_ = control;
control.setRenderer(this.renderer_);
control.render(this.renderParent_);
return control.getElement();
};
/**
* Attach a control and decorate the element given in the constructor.
* @param {goog.ui.Control} control A control.
* @return {Element} The element created.
*/
goog.testing.ui.RendererHarness.prototype.attachControlAndDecorate =
function(control) {
this.decorateControl_ = control;
control.setRenderer(this.renderer_);
var child = this.decorateParent_.firstChild;
assertEquals('The decorated node must be an element',
goog.dom.NodeType.ELEMENT, child.nodeType);
control.decorate(/** @type {!Element} */ (child));
return control.getElement();
};
/**
* Assert that the rendered element and the decorated element match.
*/
goog.testing.ui.RendererHarness.prototype.assertDomMatches = function() {
assert('Both elements were not generated',
!!(this.renderControl_ && this.decorateControl_));
goog.testing.dom.assertHtmlMatches(
this.renderControl_.getElement().innerHTML,
this.decorateControl_.getElement().innerHTML);
this.verified_ = true;
};
/**
* Destroy the harness, verifying that all assertions had been checked.
* @override
* @protected
*/
goog.testing.ui.RendererHarness.prototype.disposeInternal = function() {
// If the harness was not verified appropriately, throw an exception.
assert('Expected assertDomMatches to be called',
this.verified_ || !this.renderControl_ || !this.decorateControl_);
if (this.decorateControl_) {
this.decorateControl_.dispose();
}
if (this.renderControl_) {
this.renderControl_.dispose();
}
this.renderParent_.innerHTML = this.renderHtml_;
this.decorateParent_.innerHTML = this.decorateHtml_;
goog.testing.ui.RendererHarness.superClass_.disposeInternal.call(this);
};
@@ -0,0 +1,140 @@
// Copyright 2008 The Closure Library Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS-IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/**
* @fileoverview Tools for testing Closure renderers against static markup
* spec pages.
*
*/
goog.provide('goog.testing.ui.style');
goog.require('goog.array');
goog.require('goog.asserts');
goog.require('goog.dom');
goog.require('goog.dom.classlist');
goog.require('goog.testing.asserts');
/**
* Uses document.write to add an iFrame to the page with the reference path in
* the src attribute. Used for loading an html file containing reference
* structures to test against into the page. Should be called within the body of
* the jsunit test page.
* @param {string} referencePath A path to a reference HTML file.
*/
goog.testing.ui.style.writeReferenceFrame = function(referencePath) {
document.write('<iframe id="reference" name="reference" ' +
'src="' + referencePath + '"></iframe>');
};
/**
* Returns a reference to the first element child of a node with the given id
* from the page loaded into the reference iFrame. Used to retrieve a particular
* reference DOM structure to test against.
* @param {string} referenceId The id of a container element for a reference
* structure in the reference page.
* @return {Node} The root element of the reference structure.
*/
goog.testing.ui.style.getReferenceNode = function(referenceId) {
return goog.dom.getFirstElementChild(
window.frames['reference'].document.getElementById(referenceId));
};
/**
* Returns an array of all element children of a given node.
* @param {Node} element The node to get element children of.
* @return {!Array<!Node>} An array of all the element children.
*/
goog.testing.ui.style.getElementChildren = function(element) {
var first = goog.dom.getFirstElementChild(element);
if (!first) {
return [];
}
var children = [first], next;
while (next = goog.dom.getNextElementSibling(children[children.length - 1])) {
children.push(next);
}
return children;
};
/**
* Tests whether a given node is a "content" node of a reference structure,
* which means it is allowed to have arbitrary children.
* @param {Node} element The node to test.
* @return {boolean} Whether the given node is a content node or not.
*/
goog.testing.ui.style.isContentNode = function(element) {
return element.className.indexOf('content') != -1;
};
/**
* Tests that the structure, node names, and classes of the given element are
* the same as the reference structure with the given id. Throws an error if the
* element doesn't have the same nodes at each level of the DOM with the same
* classes on each. The test ignores all DOM structure within content nodes.
* @param {Node} element The root node of the DOM structure to test.
* @param {string} referenceId The id of the container for the reference
* structure to test against.
*/
goog.testing.ui.style.assertStructureMatchesReference = function(element,
referenceId) {
goog.testing.ui.style.assertStructureMatchesReferenceInner_(element,
goog.testing.ui.style.getReferenceNode(referenceId));
};
/**
* A recursive function for comparing structure, node names, and classes between
* a test and reference DOM structure. Throws an error if one of these things
* doesn't match. Used internally by
* {@link goog.testing.ui.style.assertStructureMatchesReference}.
* @param {Node} element DOM element to test.
* @param {Node} reference DOM element to use as a reference (test against).
* @private
*/
goog.testing.ui.style.assertStructureMatchesReferenceInner_ = function(element,
reference) {
if (!element && !reference) {
return;
}
assertTrue('Expected two elements.', !!element && !!reference);
assertEquals('Expected nodes to have the same nodeName.',
element.nodeName, reference.nodeName);
var testElem = goog.asserts.assertElement(element);
var refElem = goog.asserts.assertElement(reference);
var elementClasses = goog.dom.classlist.get(testElem);
goog.array.forEach(goog.dom.classlist.get(refElem), function(referenceClass) {
assertContains('Expected test node to have all reference classes.',
referenceClass, elementClasses);
});
// Call assertStructureMatchesReferenceInner_ on all element children
// unless this is a content node
var elChildren = goog.testing.ui.style.getElementChildren(element),
refChildren = goog.testing.ui.style.getElementChildren(reference);
if (!goog.testing.ui.style.isContentNode(reference)) {
if (elChildren.length != refChildren.length) {
assertEquals('Expected same number of children for a non-content node.',
elChildren.length, refChildren.length);
}
for (var i = 0; i < elChildren.length; i++) {
goog.testing.ui.style.assertStructureMatchesReferenceInner_(elChildren[i],
refChildren[i]);
}
}
};
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html>
<!--
Copyright 2008 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.testing.ui.style Reference HTML</title>
</head>
<body>
<div id="reference">
<div class="one two three">
<div class="four five"></div>
<div class="six seven content">
Content
</div>
</div>
</div>
</body>
</html>
@@ -0,0 +1,75 @@
<!DOCTYPE html>
<html>
<!--
Copyright 2008 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.testing.ui.style
</title>
<script src="../../base.js">
</script>
<script>
goog.require('goog.testing.ui.styleTest');
</script>
</head>
<body>
<div id="correct">
<div class="one two three">
<div class="four five"></div>
<div class="six seven content">
<div></div>
Blah
</div>
</div>
</div>
<div id="missing-class">
<div class="one two three">
<div class="five"></div>
<div class="six seven content">
<div></div>
Blah
</div>
</div>
</div>
<div id="extra-class">
<div class="one two three">
<div class="four five five-point-five"></div>
<div class="six seven content">
<div></div>
Blah
</div>
</div>
</div>
<div id="missing-child">
<div class="one two three">
<div class="six seven content">
<div></div>
Blah
</div>
</div>
</div>
<div id="extra-child">
<div class="one two three">
<div class="four five">
<div class="five-point-five"></div>
</div>
<div class="six seven content">
<div></div>
Blah
</div>
</div>
</div>
</body>
</html>
@@ -0,0 +1,73 @@
// Copyright 2008 The Closure Library Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS-IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
goog.provide('goog.testing.ui.styleTest');
goog.setTestOnly('goog.testing.ui.styleTest');
goog.require('goog.dom');
goog.require('goog.testing.jsunit');
goog.require('goog.testing.ui.style');
// Write iFrame tag to load reference FastUI markup. Then, our tests will
// compare the generated markup to the reference markup.
var refPath = 'style_reference.html';
goog.testing.ui.style.writeReferenceFrame(refPath);
// assertStructureMatchesReference should succeed if the structure, node
// names, and classes match.
function testCorrect() {
var el = goog.dom.getFirstElementChild(goog.dom.getElement('correct'));
goog.testing.ui.style.assertStructureMatchesReference(el, 'reference');
}
// assertStructureMatchesReference should fail if one of the nodes is
// missing a class.
function testMissingClass() {
var el = goog.dom.getFirstElementChild(
goog.dom.getElement('missing-class'));
var e = assertThrows(function() {
goog.testing.ui.style.assertStructureMatchesReference(el, 'reference');
});
assertContains('all reference classes', e.message);
}
// assertStructureMatchesReference should NOT fail if one of the nodes has
// an additional class.
function testExtraClass() {
var el = goog.dom.getFirstElementChild(
goog.dom.getElement('extra-class'));
goog.testing.ui.style.assertStructureMatchesReference(el, 'reference');
}
// assertStructureMatchesReference should fail if there is a missing child
// node somewhere in the DOM structure.
function testMissingChild() {
var el = goog.dom.getFirstElementChild(
goog.dom.getElement('missing-child'));
var e = assertThrows(function() {
goog.testing.ui.style.assertStructureMatchesReference(el, 'reference');
});
assertContains('same number of children', e.message);
}
// assertStructureMatchesReference should fail if there is an extra child
// node somewhere in the DOM structure.
function testExtraChild() {
var el = goog.dom.getFirstElementChild(
goog.dom.getElement('extra-child'));
var e = assertThrows(function() {
goog.testing.ui.style.assertStructureMatchesReference(el, 'reference');
});
assertContains('same number of children', e.message);
}