Elim cr-checkbox
[chromium-blink-merge.git] / chrome / test / data / third_party / spaceport / js / testDom.js
blobef9234cebbd362a140a67d824d6ca9807f2b5faf
1 define([ 'util/report' ], function (report) {
2 function classes(el) {
3 return el.className.split(/\s+/g);
6 function addClass(el, className) {
7 el.className += ' ' + className;
10 function removeClass(el, className) {
11 // wtb classList (damnit Safari!)
12 el.className = classes(el).filter(function (c) {
13 return c !== className;
14 }).join(' ');
17 function testResultNameAccept(name) {
18 return name !== 'pass';
21 var testDom = {
22 endTest: function (domId, err, results) {
23 var el = document.getElementById(domId);
24 if (!el) {
25 throw new Error('Could not find element #' + domId);
28 function findSlot(name) {
29 var elements = el.querySelectorAll('[data-property]');
30 var i;
31 for (i = 0; i < elements.length; ++i) {
32 var element = elements[i];
33 if (element.getAttribute('data-property') === name) {
34 return element;
38 return null;
41 function fillSlots(name, value) {
42 if (!testResultNameAccept(name)) {
43 return;
46 if (value === null || typeof value === 'undefined') {
47 return;
50 if (typeof value === 'object') {
51 Object.keys(value).forEach(function (subName) {
52 fillSlots(subName, value[subName]);
53 });
54 } else {
55 var slot = findSlot(name);
56 if (slot) {
57 slot.textContent = value;
58 } else {
59 //console.warn('Could not find slot ' + name + ' for ' + domId, value);
64 fillSlots('', results);
66 removeClass(el, 'pass');
67 removeClass(el, 'fail');
68 removeClass(el, 'error');
70 if (err) {
71 addClass(el, 'error');
73 var errorMessageEl = el.querySelector('.error-message');
74 if (errorMessageEl) {
75 errorMessageEl.textContent = err;
77 } else if (results && results.passed) {
78 addClass(el, 'pass');
79 } else {
80 addClass(el, 'fail');
86 return testDom;
87 });