123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- goog.setTestOnly('goog.testing.ui.style');
- 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');
- goog.testing.ui.style.writeReferenceFrame = function(referencePath) {
- document.write(
- '<iframe id="reference" name="reference" ' +
- 'src="' + referencePath + '"></iframe>');
- };
- goog.testing.ui.style.getReferenceNode = function(referenceId) {
- return goog.dom.getFirstElementChild(
- window.frames['reference'].document.getElementById(referenceId));
- };
- 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;
- };
- goog.testing.ui.style.isContentNode = function(element) {
- return element.className.indexOf('content') != -1;
- };
- goog.testing.ui.style.assertStructureMatchesReference = function(
- element, referenceId) {
- goog.testing.ui.style.assertStructureMatchesReferenceInner_(
- element, goog.testing.ui.style.getReferenceNode(referenceId));
- };
- 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);
- });
-
-
- 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]);
- }
- }
- };
|