var global = this; var ssstests = new function ssstests() { var ssstests = this; this.init = function init() { var iframe = this.iframe = document.createElement('iframe'); iframe.style.position = 'absolute'; iframe.style.left = '-1000px'; iframe.width = '100px'; document.getElementsByTagName('body')[0].appendChild(iframe); iframe.src = 'about:blank'; iframe.contentWindow.onload = function() { ssstests.editor = new SSSEditor(iframe.contentWindow); ssstests.run_tests(); }; }; this.setup = function setup() { var b = ssstests.iframe.contentDocument .getElementsByTagName('body')[0]; b.innerHTML = ''; }; this.teardown = function teardown() { var b = ssstests.iframe.contentDocument .getElementsByTagName('body')[0]; while (b.hasChildNodes()) { b.removeChild(b.firstChild); }; }; this.run_tests = function run_tests() { for (var attr in ssstests) { if (attr.indexOf('test_') == 0) { var value = ssstests[attr]; if (typeof value == 'function') { ssstests.setup(); try { value(); ssstests.report_success(attr); } catch(e) { ssstests.report_failure(attr, e); }; ssstests.teardown(); }; }; }; }; this.report_success = function report_success(funcname) { ssstests.print(funcname + '(): ok'); }; this.report_failure = function report_failure(funcname, error) { ssstests.print(funcname + '(): ERROR\n' + error.toString()); }; this.print = function print(msg) { var pre = document.createElement('pre'); pre.appendChild(document.createTextNode(msg)); var body = document.getElementsByTagName('body')[0]; body.appendChild(pre); }; // actual tests this.test_simple_em = function test_simple_em() { var editor = ssstests.editor; var win = editor.window; win.focus(); var doc = win.document; var body = doc.getElementsByTagName('body')[0]; var text = doc.createTextNode('foo bar baz'); body.appendChild(text); var sel = win.getSelection(); var range = sel.getRangeAt(0); range.setStart(text, 4); range.setEnd(text, 7); editor.addElement('em'); testing.assertEquals(body.innerHTML, 'foo bar baz'); var sel = win.getSelection(); var range = sel.getRangeAt(0); testing.assertEquals(range.toString(), 'bar'); editor.addElement('em'); testing.assertEquals(body.innerHTML, 'foo bar baz'); }; this.test_spanning_em = function test_spanning_em() { var editor = ssstests.editor; var win = editor.window; win.focus(); var doc = win.document; var body = doc.getElementsByTagName('body')[0]; body.innerHTML = 'foo