From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../mochitest/ajax/prototype/test/browser.html | 229 ++++ .../mochitest/ajax/prototype/test/console.html | 110 ++ .../ajax/prototype/test/functional/event.html | 243 ++++ .../mochitest/ajax/prototype/test/lib/unittest.js | 602 +++++++++ dom/tests/mochitest/ajax/prototype/test/test.css | 50 + .../ajax/prototype/test/unit/ajax_test.js | 286 ++++ .../ajax/prototype/test/unit/array_test.js | 190 +++ .../ajax/prototype/test/unit/base_test.js | 511 +++++++ .../mochitest/ajax/prototype/test/unit/dom_test.js | 1404 ++++++++++++++++++++ .../prototype/test/unit/element_mixins_test.js | 32 + .../ajax/prototype/test/unit/enumerable_test.js | 263 ++++ .../ajax/prototype/test/unit/event_test.js | 286 ++++ .../ajax/prototype/test/unit/fixtures/ajax.html | 2 + .../ajax/prototype/test/unit/fixtures/ajax.js | 42 + .../ajax/prototype/test/unit/fixtures/array.html | 1 + .../ajax/prototype/test/unit/fixtures/base.html | 6 + .../ajax/prototype/test/unit/fixtures/base.js | 106 ++ .../ajax/prototype/test/unit/fixtures/content.html | 1 + .../ajax/prototype/test/unit/fixtures/data.json | 1 + .../ajax/prototype/test/unit/fixtures/dom.css | 85 ++ .../ajax/prototype/test/unit/fixtures/dom.html | 285 ++++ .../ajax/prototype/test/unit/fixtures/dom.js | 17 + .../test/unit/fixtures/element_mixins.html | 4 + .../prototype/test/unit/fixtures/element_mixins.js | 2 + .../ajax/prototype/test/unit/fixtures/empty.html | 0 .../ajax/prototype/test/unit/fixtures/empty.js | 1 + .../prototype/test/unit/fixtures/enumerable.html | 8 + .../prototype/test/unit/fixtures/enumerable.js | 23 + .../ajax/prototype/test/unit/fixtures/event.html | 4 + .../ajax/prototype/test/unit/fixtures/form.html | 112 ++ .../ajax/prototype/test/unit/fixtures/hash.js | 25 + .../ajax/prototype/test/unit/fixtures/hello.js | 1 + .../ajax/prototype/test/unit/fixtures/logo.gif | Bin 0 -> 3502 bytes .../prototype/test/unit/fixtures/position.html | 9 + .../prototype/test/unit/fixtures/selector.html | 69 + .../ajax/prototype/test/unit/fixtures/string.js | 8 + .../prototype/test/unit/fixtures/unittest.html | 18 + .../ajax/prototype/test/unit/form_test.js | 384 ++++++ .../ajax/prototype/test/unit/hash_test.js | 178 +++ .../ajax/prototype/test/unit/number_test.js | 44 + .../ajax/prototype/test/unit/position_test.js | 44 + .../ajax/prototype/test/unit/range_test.js | 58 + .../ajax/prototype/test/unit/selector_test.js | 377 ++++++ .../ajax/prototype/test/unit/string_test.js | 540 ++++++++ .../ajax/prototype/test/unit/tmp/ajax_test.html | 42 + .../ajax/prototype/test/unit/tmp/array_test.html | 39 + .../ajax/prototype/test/unit/tmp/base_test.html | 45 + .../ajax/prototype/test/unit/tmp/dom_test.html | 326 +++++ .../test/unit/tmp/element_mixins_test.html | 43 + .../prototype/test/unit/tmp/enumerable_test.html | 48 + .../ajax/prototype/test/unit/tmp/event_test.html | 42 + .../ajax/prototype/test/unit/tmp/form_test.html | 150 +++ .../ajax/prototype/test/unit/tmp/hash_test.html | 40 + .../ajax/prototype/test/unit/tmp/number_test.html | 38 + .../prototype/test/unit/tmp/position_test.html | 47 + .../ajax/prototype/test/unit/tmp/range_test.html | 38 + .../prototype/test/unit/tmp/selector_test.html | 107 ++ .../ajax/prototype/test/unit/tmp/string_test.html | 40 + .../ajax/prototype/test/unit/tmp/unit_test.html | 56 + .../ajax/prototype/test/unit/unittest_test.js | 143 ++ 60 files changed, 7905 insertions(+) create mode 100644 dom/tests/mochitest/ajax/prototype/test/browser.html create mode 100644 dom/tests/mochitest/ajax/prototype/test/console.html create mode 100644 dom/tests/mochitest/ajax/prototype/test/functional/event.html create mode 100644 dom/tests/mochitest/ajax/prototype/test/lib/unittest.js create mode 100644 dom/tests/mochitest/ajax/prototype/test/test.css create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/ajax_test.js create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/array_test.js create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/base_test.js create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/dom_test.js create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/element_mixins_test.js create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/enumerable_test.js create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/event_test.js create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/fixtures/ajax.html create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/fixtures/ajax.js create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/fixtures/array.html create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/fixtures/base.html create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/fixtures/base.js create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/fixtures/content.html create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/fixtures/data.json create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/fixtures/dom.css create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/fixtures/dom.html create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/fixtures/dom.js create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/fixtures/element_mixins.html create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/fixtures/element_mixins.js create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/fixtures/empty.html create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/fixtures/empty.js create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/fixtures/enumerable.html create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/fixtures/enumerable.js create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/fixtures/event.html create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/fixtures/form.html create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/fixtures/hash.js create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/fixtures/hello.js create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/fixtures/logo.gif create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/fixtures/position.html create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/fixtures/selector.html create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/fixtures/string.js create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/fixtures/unittest.html create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/form_test.js create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/hash_test.js create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/number_test.js create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/position_test.js create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/range_test.js create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/selector_test.js create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/string_test.js create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/tmp/ajax_test.html create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/tmp/array_test.html create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/tmp/base_test.html create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/tmp/dom_test.html create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/tmp/element_mixins_test.html create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/tmp/enumerable_test.html create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/tmp/event_test.html create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/tmp/form_test.html create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/tmp/hash_test.html create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/tmp/number_test.html create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/tmp/position_test.html create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/tmp/range_test.html create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/tmp/selector_test.html create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/tmp/string_test.html create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/tmp/unit_test.html create mode 100644 dom/tests/mochitest/ajax/prototype/test/unit/unittest_test.js (limited to 'dom/tests/mochitest/ajax/prototype/test') diff --git a/dom/tests/mochitest/ajax/prototype/test/browser.html b/dom/tests/mochitest/ajax/prototype/test/browser.html new file mode 100644 index 0000000000..ec699f9d45 --- /dev/null +++ b/dom/tests/mochitest/ajax/prototype/test/browser.html @@ -0,0 +1,229 @@ + + + + + Prototype object browser + + + + + +
+
+
+
+

+
+ + + \ No newline at end of file diff --git a/dom/tests/mochitest/ajax/prototype/test/console.html b/dom/tests/mochitest/ajax/prototype/test/console.html new file mode 100644 index 0000000000..2b586ee426 --- /dev/null +++ b/dom/tests/mochitest/ajax/prototype/test/console.html @@ -0,0 +1,110 @@ + + + + Prototype Console + + + + + + + + +
+
+ + +
+ + + diff --git a/dom/tests/mochitest/ajax/prototype/test/functional/event.html b/dom/tests/mochitest/ajax/prototype/test/functional/event.html new file mode 100644 index 0000000000..526e711f9a --- /dev/null +++ b/dom/tests/mochitest/ajax/prototype/test/functional/event.html @@ -0,0 +1,243 @@ + + + + Prototype functional test file + + + + + + + + +

Prototype functional tests for the Event module

+ +
log empty
+ +

A basic event test - click here

+

click to stop observing the first test

+ +

click to ensure generic Event methods work on inline handlers

+ + + +

Scope test - scope of the handler should be this element

+ + + +

Event object test - should be present as a first argument

+ + + +

Hijack link test (preventDefault)

+ + + +
+ + +

Mouse click: + left middle right

+ + + +

Context menu event (tries to prevent default)

+ + + +

Event.element() test

+ + + +

Event.currentTarget test

+ + + +

Event.findElement() test

+ + + +

Stop propagation test (bubbling)

+ + + +
+

Keyup test - focus on the textarea and type

+ +
+ + + +

bindAsEventListener() test

+ + + +

Object.inspect(event) test

+ + + +

Add unload events

+ + + + diff --git a/dom/tests/mochitest/ajax/prototype/test/lib/unittest.js b/dom/tests/mochitest/ajax/prototype/test/lib/unittest.js new file mode 100644 index 0000000000..4f92d13dc0 --- /dev/null +++ b/dom/tests/mochitest/ajax/prototype/test/lib/unittest.js @@ -0,0 +1,602 @@ +// Copyright (c) 2005 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) +// (c) 2005 Jon Tirsen (http://www.tirsen.com) +// (c) 2005 Michael Schuerig (http://www.schuerig.de/michael/) +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + +// experimental, Firefox-only +Event.simulateMouse = function(element, eventName) { + var options = Object.extend({ + pointerX: 0, + pointerY: 0, + buttons: 0 + }, arguments[2] || {}); + var oEvent = document.createEvent("MouseEvents"); + oEvent.initMouseEvent(eventName, true, true, document.defaultView, + options.buttons, options.pointerX, options.pointerY, options.pointerX, options.pointerY, + false, false, false, false, 0, $(element)); + + if (this.mark) Element.remove(this.mark); + + var style = 'position: absolute; width: 5px; height: 5px;' + + 'top: #{pointerY}px; left: #{pointerX}px;'.interpolate(options) + + 'border-top: 1px solid red; border-left: 1px solid red;' + + this.mark = new Element('div', { style: style }); + this.mark.appendChild(document.createTextNode(" ")); + document.body.appendChild(this.mark); + + if (this.step) + alert('['+new Date().getTime().toString()+'] '+eventName+'/'+Test.Unit.inspect(options)); + + $(element).dispatchEvent(oEvent); +}; + +// Note: Due to a fix in Firefox 1.0.5/6 that probably fixed "too much", this doesn't work in 1.0.6 or DP2. +// You need to downgrade to 1.0.4 for now to get this working +// See https://bugzilla.mozilla.org/show_bug.cgi?id=289940 for the fix that fixed too much +Event.simulateKey = function(element, eventName) { + var options = Object.extend({ + ctrlKey: false, + altKey: false, + shiftKey: false, + metaKey: false, + keyCode: 0, + charCode: 0 + }, arguments[2] || {}); + + var oEvent = document.createEvent("KeyboardEvent"); + oEvent.initKeyEvent(eventName, true, true, window, + options.ctrlKey, options.altKey, options.shiftKey, options.metaKey, + options.keyCode, options.charCode ); + $(element).dispatchEvent(oEvent); +}; + +Event.simulateKeys = function(element, command) { + for (var i=0; i' + testName + ''); + }, + + setStatus: function(status) { + this.getLastLogLine().addClassName(status); + $(this.getLastLogLine().getElementsByTagName('td')[1]).update(status); + }, + + finish: function(status, summary) { + if (!this.element) return; + this.setStatus(status); + this.message(summary); + }, + + message: function(message) { + if (!this.element) return; + this.getMessageCell().update(this._toHTML(message)); + }, + + summary: function(summary) { + if (!this.element) return; + var div = $(this.element.getElementsByTagName('div')[0]); + div.update(this._toHTML(summary)); + }, + + getLastLogLine: function() { + //return this.element.descendants('tr').last(); + var trs = this.element.getElementsByTagName('tr'); + return $(trs[trs.length - 1]); + }, + + getMessageCell: function() { + return this.getLastLogLine().down('td', 2); + var tds = this.getLastLogLine().getElementsByTagName('td'); + return $(tds[2]); + }, + + _createLogTable: function() { + var html = '
running...
' + + '' + + '' + + '' + + '
StatusTestMessage
'; + this.element.update(html); + + }, + + appendActionButtons: function(actions) { + actions = $H(actions); + if (!actions.any()) return; + var div = new Element("div", {className: 'action_buttons'}); + actions.inject(div, function(container, action) { + var button = new Element("input").setValue(action.key).observe("click", action.value); + button.type = "button"; + return container.insert(button); + }); + this.getMessageCell().insert(div); + }, + + _toHTML: function(txt) { + return txt.escapeHTML().replace(/\n/g,"
"); + } +}); + +Test.Unit.Runner = Class.create({ + initialize: function(testcases) { + var options = this.options = Object.extend({ + testLog: 'testlog' + }, arguments[1] || {}); + + options.resultsURL = this.queryParams.resultsURL; + + this.tests = this.getTests(testcases); + this.currentTest = 0; + + Event.observe(window, "load", function() { + this.logger = new Test.Unit.Logger($(options.testLog)); + this.runTests.bind(this).delay(0.1); + }.bind(this)); + }, + + queryParams: window.location.search.parseQuery(), + + getTests: function(testcases) { + var tests, options = this.options; + if (this.queryParams.tests) tests = this.queryParams.tests.split(','); + else if (options.tests) tests = options.tests; + else if (options.test) tests = [option.test]; + else tests = Object.keys(testcases).grep(/^test/); + + return tests.map(function(test) { + if (testcases[test]) + return new Test.Unit.Testcase(test, testcases[test], testcases.setup, testcases.teardown); + }).compact(); + }, + + getResult: function() { + var results = { + tests: this.tests.length, + assertions: 0, + failures: 0, + errors: 0 + }; + + return this.tests.inject(results, function(results, test) { + results.assertions += test.assertions; + results.failures += test.failures; + results.errors += test.errors; + return results; + }); + }, + + postResults: function() { + if (this.options.resultsURL) { + new Ajax.Request(this.options.resultsURL, + { method: 'get', parameters: this.getResult(), asynchronous: false }); + } + }, + + runTests: function() { + var test = this.tests[this.currentTest], actions; + + if (!test) return this.finish(); + if (test.timerID > 0) test.timerID = -1; + if (!test.isWaiting) this.logger.start(test.name); + test.run(); + if (test.isWaiting) { + if (test.timeToWait) { + this.logger.message("Waiting for " + test.timeToWait + "ms"); + test.timerID = setTimeout(this.runTests.bind(this), test.timeToWait); + } else { + this.logger.message("Waiting for finish"); + } + test.runner = this; + return; + } + + this.logger.finish(test.status(), test.summary()); + if (actions = test.actions) this.logger.appendActionButtons(actions); + this.currentTest++; + // tail recursive, hopefully the browser will skip the stackframe + this.runTests(); + }, + + finish: function() { + this.postResults(); + this.logger.summary(this.summary()); + }, + + summary: function() { + return '#{tests} tests, #{assertions} assertions, #{failures} failures, #{errors} errors' + .interpolate(this.getResult()); + } +}); + +Test.Unit.MessageTemplate = Class.create({ + initialize: function(string) { + var parts = []; + (string || '').scan(/(?=[^\\])\?|(?:\\\?|[^\?])+/, function(part) { + parts.push(part[0]); + }); + this.parts = parts; + }, + + evaluate: function(params) { + return this.parts.map(function(part) { + return part == '?' ? Test.Unit.inspect(params.shift()) : part.replace(/\\\?/, '?'); + }).join(''); + } +}); + +Test.Unit.Assertions = { + buildMessage: function(message, template) { + var args = $A(arguments).slice(2); + return (message ? message + '\n' : '') + new Test.Unit.MessageTemplate(template).evaluate(args); + }, + + flunk: function(message) { + this.assertBlock(message || 'Flunked', function() { return false }); + }, + + assertBlock: function(message, block) { + try { + block.call(this) ? this.pass() : this.fail(message); + } catch(e) { this.error(e) } + }, + + assert: function(expression, message) { + message = this.buildMessage(message || 'assert', 'got ', expression); + this.assertBlock(message, function() { return expression }); + }, + + assertEqual: function(expected, actual, message) { + message = this.buildMessage(message || 'assertEqual', 'expected , actual: ', expected, actual); + this.assertBlock(message, function() { return expected == actual }); + }, + + assertNotEqual: function(expected, actual, message) { + message = this.buildMessage(message || 'assertNotEqual', 'expected , actual: ', expected, actual); + this.assertBlock(message, function() { return expected != actual }); + }, + + assertEnumEqual: function(expected, actual, message) { + expected = $A(expected); + actual = $A(actual); + message = this.buildMessage(message || 'assertEnumEqual', 'expected , actual: ', expected, actual); + this.assertBlock(message, function() { + return expected.length == actual.length && expected.zip(actual).all(function(pair) { return pair[0] == pair[1] }); + }); + }, + + assertEnumNotEqual: function(expected, actual, message) { + expected = $A(expected); + actual = $A(actual); + message = this.buildMessage(message || 'assertEnumNotEqual', ' was the same as ', expected, actual); + this.assertBlock(message, function() { + return expected.length != actual.length || expected.zip(actual).any(function(pair) { return pair[0] != pair[1] }); + }); + }, + + assertHashEqual: function(expected, actual, message) { + expected = $H(expected); + actual = $H(actual); + var expected_array = expected.toArray().sort(), actual_array = actual.toArray().sort(); + message = this.buildMessage(message || 'assertHashEqual', 'expected , actual: ', expected, actual); + // from now we recursively zip & compare nested arrays + var block = function() { + return expected_array.length == actual_array.length && + expected_array.zip(actual_array).all(function(pair) { + return pair.all(Object.isArray) ? + pair[0].zip(pair[1]).all(arguments.callee) : pair[0] == pair[1]; + }); + }; + this.assertBlock(message, block); + }, + + assertHashNotEqual: function(expected, actual, message) { + expected = $H(expected); + actual = $H(actual); + var expected_array = expected.toArray().sort(), actual_array = actual.toArray().sort(); + message = this.buildMessage(message || 'assertHashNotEqual', ' was the same as ', expected, actual); + // from now we recursively zip & compare nested arrays + var block = function() { + return !(expected_array.length == actual_array.length && + expected_array.zip(actual_array).all(function(pair) { + return pair.all(Object.isArray) ? + pair[0].zip(pair[1]).all(arguments.callee) : pair[0] == pair[1]; + })); + }; + this.assertBlock(message, block); + }, + + assertIdentical: function(expected, actual, message) { + message = this.buildMessage(message || 'assertIdentical', 'expected , actual: ', expected, actual); + this.assertBlock(message, function() { return expected === actual }); + }, + + assertNotIdentical: function(expected, actual, message) { + message = this.buildMessage(message || 'assertNotIdentical', 'expected , actual: ', expected, actual); + this.assertBlock(message, function() { return expected !== actual }); + }, + + assertNull: function(obj, message) { + message = this.buildMessage(message || 'assertNull', 'got ', obj); + this.assertBlock(message, function() { return obj === null }); + }, + + assertNotNull: function(obj, message) { + message = this.buildMessage(message || 'assertNotNull', 'got ', obj); + this.assertBlock(message, function() { return obj !== null }); + }, + + assertUndefined: function(obj, message) { + message = this.buildMessage(message || 'assertUndefined', 'got ', obj); + this.assertBlock(message, function() { return typeof obj == "undefined" }); + }, + + assertNotUndefined: function(obj, message) { + message = this.buildMessage(message || 'assertNotUndefined', 'got ', obj); + this.assertBlock(message, function() { return typeof obj != "undefined" }); + }, + + assertNullOrUndefined: function(obj, message) { + message = this.buildMessage(message || 'assertNullOrUndefined', 'got ', obj); + this.assertBlock(message, function() { return obj == null }); + }, + + assertNotNullOrUndefined: function(obj, message) { + message = this.buildMessage(message || 'assertNotNullOrUndefined', 'got ', obj); + this.assertBlock(message, function() { return obj != null }); + }, + + assertMatch: function(expected, actual, message) { + message = this.buildMessage(message || 'assertMatch', 'regex did not match ', expected, actual); + this.assertBlock(message, function() { return new RegExp(expected).exec(actual) }); + }, + + assertNoMatch: function(expected, actual, message) { + message = this.buildMessage(message || 'assertNoMatch', 'regex matched ', expected, actual); + this.assertBlock(message, function() { return !(new RegExp(expected).exec(actual)) }); + }, + + assertHidden: function(element, message) { + message = this.buildMessage(message || 'assertHidden', '? isn\'t hidden.', element); + this.assertBlock(message, function() { return element.style.display == 'none' }); + }, + + assertInstanceOf: function(expected, actual, message) { + message = this.buildMessage(message || 'assertInstanceOf', ' was not an instance of the expected type', actual); + this.assertBlock(message, function() { return actual instanceof expected }); + }, + + assertNotInstanceOf: function(expected, actual, message) { + message = this.buildMessage(message || 'assertNotInstanceOf', ' was an instance of the expected type', actual); + this.assertBlock(message, function() { return !(actual instanceof expected) }); + }, + + assertRespondsTo: function(method, obj, message) { + message = this.buildMessage(message || 'assertRespondsTo', 'object doesn\'t respond to ', method); + this.assertBlock(message, function() { return (method in obj && typeof obj[method] == 'function') }); + }, + + assertRaise: function(exceptionName, method, message) { + message = this.buildMessage(message || 'assertRaise', ' exception expected but none was raised', exceptionName); + var block = function() { + try { + method(); + return false; + } catch(e) { + if (e.name == exceptionName) return true; + else throw e; + } + }; + this.assertBlock(message, block); + }, + + assertNothingRaised: function(method, message) { + try { + method(); + this.assert(true, "Expected nothing to be thrown"); + } catch(e) { + message = this.buildMessage(message || 'assertNothingRaised', ' was thrown when nothing was expected.', e); + this.flunk(message); + } + }, + + _isVisible: function(element) { + element = $(element); + if (!element.parentNode) return true; + this.assertNotNull(element); + if (element.style && Element.getStyle(element, 'display') == 'none') + return false; + + return arguments.callee.call(this, element.parentNode); + }, + + assertVisible: function(element, message) { + message = this.buildMessage(message, '? was not visible.', element); + this.assertBlock(message, function() { return this._isVisible(element) }); + }, + + assertNotVisible: function(element, message) { + message = this.buildMessage(message, '? was not hidden and didn\'t have a hidden parent either.', element); + this.assertBlock(message, function() { return !this._isVisible(element) }); + }, + + assertElementsMatch: function() { + var pass = true, expressions = $A(arguments), elements = $A(expressions.shift()); + if (elements.length != expressions.length) { + message = this.buildMessage('assertElementsMatch', 'size mismatch: ? elements, ? expressions (?).', elements.length, expressions.length, expressions); + this.flunk(message); + pass = false; + } + elements.zip(expressions).all(function(pair, index) { + var element = $(pair.first()), expression = pair.last(); + if (element.match(expression)) return true; + message = this.buildMessage('assertElementsMatch', 'In index : expected but got ?', index, expression, element); + this.flunk(message); + pass = false; + }.bind(this)) + + if (pass) this.assert(true, "Expected all elements to match."); + }, + + assertElementMatches: function(element, expression, message) { + this.assertElementsMatch([element], expression); + } +}; + +Test.Unit.Testcase = Class.create(Test.Unit.Assertions, { + initialize: function(name, test, setup, teardown) { + this.name = name; + this.test = test || Prototype.emptyFunction; + this.setup = setup || Prototype.emptyFunction; + this.teardown = teardown || Prototype.emptyFunction; + this.messages = []; + this.actions = {}; + }, + + isWaiting: false, + timeToWait: null, + timerID: -1, + runner: null, + assertions: 0, + failures: 0, + errors: 0, + isRunningFromRake: window.location.port == 4711, + + wait: function(time, nextPart) { + this.isWaiting = true; + this.test = nextPart; + this.timeToWait = time; + }, + + waitForFinish: function() { + this.isWaiting = true; + }, + + finish: function() { + if (this.timerID > 0) { + clearTimeout(this.timerID); + this.timerID = -1; + this.timeToWait = null; + } + this.test = function(){}; + // continue test + if (this.runner) + this.runner.runTests(); + }, + + run: function(rethrow) { + try { + try { + if (!this.isWaiting) this.setup(); + this.isWaiting = false; + this.test(); + } finally { + if (!this.isWaiting) { + this.teardown(); + } + } + } + catch(e) { + if (rethrow) throw e; + this.error(e, this); + } + }, + + summary: function() { + var msg = '#{assertions} assertions, #{failures} failures, #{errors} errors\n'; + return msg.interpolate(this) + this.messages.join("\n"); + }, + + pass: function() { + this.assertions++; + }, + + fail: function(message) { + this.failures++; + var line = ""; + try { + throw new Error("stack"); + } catch(e){ + match = /.*\/(.*_test\.js):(\d+)/.exec(e.stack || '') || ['','','']; + file = match[1]; + line = match[2]; + } + this.messages.push("Failure: " + message + (line ? " " + file + ": Line #" + line : "")); + }, + + info: function(message) { + this.messages.push("Info: " + message); + }, + + error: function(error, test) { + this.errors++; + this.actions['retry with throw'] = function() { test.run(true) }; + this.messages.push(error.name + ": "+ error.message + "(" + Test.Unit.inspect(error) + ")"); + }, + + status: function() { + if (this.failures > 0) return 'failed'; + if (this.errors > 0) return 'error'; + return 'passed'; + }, + + benchmark: function(operation, iterations) { + var startAt = new Date(); + (iterations || 1).times(operation); + var timeTaken = ((new Date())-startAt); + this.info((arguments[2] || 'Operation') + ' finished ' + + iterations + ' iterations in ' + (timeTaken/1000)+'s' ); + return timeTaken; + } +}); + +if ( parent.SimpleTest && parent.runAJAXTest ) (function(){ + var finish = Test.Unit.Logger.prototype.finish; + Test.Unit.Logger.prototype.finish = function(status,summary){ + parent.SimpleTest.ok( status == "passed", `${this.testName}: ${summary}` ); + return finish.apply( this, arguments ); + }; + + // Intentionally overwrite (to stop the Ajax request) + Test.Unit.Runner.prototype.postResults = parent.runAJAXTest; +})(); + + diff --git a/dom/tests/mochitest/ajax/prototype/test/test.css b/dom/tests/mochitest/ajax/prototype/test/test.css new file mode 100644 index 0000000000..6fe8f51c9b --- /dev/null +++ b/dom/tests/mochitest/ajax/prototype/test/test.css @@ -0,0 +1,50 @@ +body, div, p, h1, h2, h3, ul, ol, span, a, table, td, form, img, li { + font-family: sans-serif; +} + +body { + font-size:0.8em; +} + +#log { + padding-bottom: 1em; + border-bottom: 2px solid #000; + margin-bottom: 2em; +} + +.logsummary { + margin-top: 1em; + margin-bottom: 1em; + padding: 1ex; + border: 1px solid #000; + font-weight: bold; +} + +.logtable { + width:100%; + border-collapse: collapse; + border: 1px dotted #666; +} + +.logtable td, .logtable th { + text-align: left; + padding: 3px 8px; + border: 1px dotted #666; +} + +.logtable .passed { + background-color: #cfc; +} + +.logtable .failed, .logtable .error { + background-color: #fcc; +} + +.logtable td div.action_buttons { + display: inline; +} + +.logtable td div.action_buttons input { + margin: 0 5px; + font-size: 10px; +} \ No newline at end of file diff --git a/dom/tests/mochitest/ajax/prototype/test/unit/ajax_test.js b/dom/tests/mochitest/ajax/prototype/test/unit/ajax_test.js new file mode 100644 index 0000000000..9ceb985186 --- /dev/null +++ b/dom/tests/mochitest/ajax/prototype/test/unit/ajax_test.js @@ -0,0 +1,286 @@ +var extendDefault = function(options) { + return Object.extend({ + asynchronous: false, + method: 'get', + onException: function(request, e) { throw e } + }, options); +}; + +new Test.Unit.Runner({ + setup: function() { + $('content').update(''); + $('content2').update(''); + }, + + teardown: function() { + // hack to cleanup responders + Ajax.Responders.responders = [Ajax.Responders.responders[0]]; + }, + + testSynchronousRequest: function() { + this.assertEqual("", $("content").innerHTML); + + this.assertEqual(0, Ajax.activeRequestCount); + new Ajax.Request("../fixtures/hello.js", extendDefault({ + asynchronous: false, + method: 'GET', + evalJS: 'force' + })); + this.assertEqual(0, Ajax.activeRequestCount); + + var h2 = $("content").firstChild; + this.assertEqual("Hello world!", h2.innerHTML); + }, + + testUpdaterOptions: function() { + var options = { + method: 'get', + asynchronous: false, + evalJS: 'force', + onComplete: Prototype.emptyFunction + } + var request = new Ajax.Updater("content", "../fixtures/hello.js", options); + request.options.onComplete = function() {}; + this.assertIdentical(Prototype.emptyFunction, options.onComplete); + }, + + testEvalResponseShouldBeCalledBeforeOnComplete: function() { + if (this.isRunningFromRake) { + this.assertEqual("", $("content").innerHTML); + + this.assertEqual(0, Ajax.activeRequestCount); + new Ajax.Request("../fixtures/hello.js", extendDefault({ + onComplete: function(response) { this.assertNotEqual("", $("content").innerHTML) }.bind(this) + })); + this.assertEqual(0, Ajax.activeRequestCount); + + var h2 = $("content").firstChild; + this.assertEqual("Hello world!", h2.innerHTML); + } else { + this.info(message); + } + }, + + testContentTypeSetForSimulatedVerbs: function() { + if (this.isRunningFromRake) { + new Ajax.Request('/inspect', extendDefault({ + method: 'put', + contentType: 'application/bogus', + onComplete: function(response) { + this.assertEqual('application/bogus; charset=UTF-8', response.responseJSON.headers['content-type']); + }.bind(this) + })); + } else { + this.info(message); + } + }, + + testOnCreateCallback: function() { + new Ajax.Request("../fixtures/content.html", extendDefault({ + onCreate: function(transport) { this.assertEqual(0, transport.readyState) }.bind(this), + onComplete: function(transport) { this.assertNotEqual(0, transport.readyState) }.bind(this) + })); + }, + + testEvalJS: function() { + if (this.isRunningFromRake) { + + $('content').update(); + new Ajax.Request("/response", extendDefault({ + parameters: Fixtures.js, + onComplete: function(transport) { + var h2 = $("content").firstChild; + this.assertEqual("Hello world!", h2.innerHTML); + }.bind(this) + })); + + $('content').update(); + new Ajax.Request("/response", extendDefault({ + evalJS: false, + parameters: Fixtures.js, + onComplete: function(transport) { + this.assertEqual("", $("content").innerHTML); + }.bind(this) + })); + } else { + this.info(message); + } + + $('content').update(); + new Ajax.Request("../fixtures/hello.js", extendDefault({ + evalJS: 'force', + onComplete: function(transport) { + var h2 = $("content").firstChild; + this.assertEqual("Hello world!", h2.innerHTML); + }.bind(this) + })); + }, + + testCallbacks: function() { + var options = extendDefault({ + onCreate: function(transport) { this.assertInstanceOf(Ajax.Response, transport) }.bind(this) + }); + + Ajax.Request.Events.each(function(state){ + options['on' + state] = options.onCreate; + }); + + new Ajax.Request("../fixtures/content.html", options); + }, + + testResponseText: function() { + new Ajax.Request("../fixtures/empty.html", extendDefault({ + onComplete: function(transport) { this.assertEqual('', transport.responseText) }.bind(this) + })); + + new Ajax.Request("../fixtures/content.html", extendDefault({ + onComplete: function(transport) { this.assertEqual(sentence, transport.responseText.toLowerCase()) }.bind(this) + })); + }, + + testResponseXML: function() { + if (this.isRunningFromRake) { + new Ajax.Request("/response", extendDefault({ + parameters: Fixtures.xml, + onComplete: function(transport) { + this.assertEqual('foo', transport.responseXML.getElementsByTagName('name')[0].getAttribute('attr')) + }.bind(this) + })); + } else { + this.info(message); + } + }, + + testResponseJSON: function() { + if (this.isRunningFromRake) { + new Ajax.Request("/response", extendDefault({ + parameters: Fixtures.json, + onComplete: function(transport) { this.assertEqual(123, transport.responseJSON.test) }.bind(this) + })); + + new Ajax.Request("/response", extendDefault({ + parameters: { + 'Content-Length': 0, + 'Content-Type': 'application/json' + }, + onComplete: function(transport) { this.assertNull(transport.responseJSON) }.bind(this) + })); + + new Ajax.Request("/response", extendDefault({ + evalJSON: false, + parameters: Fixtures.json, + onComplete: function(transport) { this.assertNull(transport.responseJSON) }.bind(this) + })); + + new Ajax.Request("/response", extendDefault({ + parameters: Fixtures.jsonWithoutContentType, + onComplete: function(transport) { this.assertNull(transport.responseJSON) }.bind(this) + })); + + new Ajax.Request("/response", extendDefault({ + sanitizeJSON: true, + parameters: Fixtures.invalidJson, + onException: function(request, error) { + this.assert(error.message.include('Badly formed JSON string')); + this.assertInstanceOf(Ajax.Request, request); + }.bind(this) + })); + } else { + this.info(message); + } + + new Ajax.Request("../fixtures/data.json", extendDefault({ + evalJSON: 'force', + onComplete: function(transport) { this.assertEqual(123, transport.responseJSON.test) }.bind(this) + })); + }, + + testHeaderJSON: function() { + if (this.isRunningFromRake) { + new Ajax.Request("/response", extendDefault({ + parameters: Fixtures.headerJson, + onComplete: function(transport, json) { + this.assertEqual('hello #éà', transport.headerJSON.test); + this.assertEqual('hello #éà', json.test); + }.bind(this) + })); + + new Ajax.Request("/response", extendDefault({ + onComplete: function(transport, json) { + this.assertNull(transport.headerJSON) + this.assertNull(json) + }.bind(this) + })); + } else { + this.info(message); + } + }, + + testGetHeader: function() { + if (this.isRunningFromRake) { + new Ajax.Request("/response", extendDefault({ + parameters: { 'X-TEST': 'some value' }, + onComplete: function(transport) { + this.assertEqual('some value', transport.getHeader('X-Test')); + this.assertNull(transport.getHeader('X-Inexistant')); + }.bind(this) + })); + } else { + this.info(message); + } + }, + + testParametersCanBeHash: function() { + if (this.isRunningFromRake) { + new Ajax.Request("/response", extendDefault({ + parameters: $H({ "one": "two", "three": "four" }), + onComplete: function(transport) { + this.assertEqual("two", transport.getHeader("one")); + this.assertEqual("four", transport.getHeader("three")); + this.assertNull(transport.getHeader("toObject")); + }.bind(this) + })); + } else { + this.info(message); + } + }, + + testIsSameOriginMethod: function() { + var isSameOrigin = Ajax.Request.prototype.isSameOrigin; + this.assert(isSameOrigin.call({ url: '/foo/bar.html' }), '/foo/bar.html'); + this.assert(isSameOrigin.call({ url: window.location.toString() }), window.location); + this.assert(!isSameOrigin.call({ url: 'http://example.com' }), 'http://example.com'); + + if (this.isRunningFromRake) { + Ajax.Request.prototype.isSameOrigin = function() { + return false + }; + + $("content").update('same origin policy'); + new Ajax.Request("/response", extendDefault({ + parameters: Fixtures.js, + onComplete: function(transport) { + this.assertEqual("same origin policy", $("content").innerHTML); + }.bind(this) + })); + + new Ajax.Request("/response", extendDefault({ + parameters: Fixtures.invalidJson, + onException: function(request, error) { + this.assert(error.message.include('Badly formed JSON string')); + }.bind(this) + })); + + new Ajax.Request("/response", extendDefault({ + parameters: { 'X-JSON': '{});window.attacked = true;({}' }, + onException: function(request, error) { + this.assert(error.message.include('Badly formed JSON string')); + }.bind(this) + })); + + Ajax.Request.prototype.isSameOrigin = isSameOrigin; + } else { + this.info(message); + } + } +}); diff --git a/dom/tests/mochitest/ajax/prototype/test/unit/array_test.js b/dom/tests/mochitest/ajax/prototype/test/unit/array_test.js new file mode 100644 index 0000000000..c3f9d41147 --- /dev/null +++ b/dom/tests/mochitest/ajax/prototype/test/unit/array_test.js @@ -0,0 +1,190 @@ +var globalArgsTest = 'nothing to see here'; + +new Test.Unit.Runner({ + test$A: function(){ + this.assertEnumEqual([], $A({})); + }, + + testToArrayOnArguments: function(){ + function toArrayOnArguments(){ + globalArgsTest = $A(arguments); + } + toArrayOnArguments(); + this.assertEnumEqual([], globalArgsTest); + toArrayOnArguments('foo'); + this.assertEnumEqual(['foo'], globalArgsTest); + toArrayOnArguments('foo','bar'); + this.assertEnumEqual(['foo','bar'], globalArgsTest); + }, + + testToArrayOnNodeList: function(){ + // direct HTML + this.assertEqual(3, $A($('test_node').childNodes).length); + + // DOM + var element = document.createElement('div'); + element.appendChild(document.createTextNode('22')); + (2).times(function(){ element.appendChild(document.createElement('span')) }); + this.assertEqual(3, $A(element.childNodes).length); + + // HTML String + element = document.createElement('div'); + $(element).update('22 3); + }, + + + testBindAsEventListener: function() { + for ( var i = 0; i < 10; ++i ) { + var div = document.createElement('div'); + div.setAttribute('id','test-'+i); + document.body.appendChild(div); + var tobj = new TestObj(); + var eventTest = { test: true }; + var call = tobj.assertingEventHandler.bindAsEventListener(tobj, + this.assertEqual.bind(this, eventTest), + this.assertEqual.bind(this, arg1), + this.assertEqual.bind(this, arg2), + this.assertEqual.bind(this, arg3), arg1, arg2, arg3 ); + call(eventTest); + } + }, + + testDateToJSON: function() { + this.assertEqual('\"1970-01-01T00:00:00Z\"', new Date(Date.UTC(1970, 0, 1)).toJSON()); + }, + + testRegExpEscape: function() { + this.assertEqual('word', RegExp.escape('word')); + this.assertEqual('\\/slashes\\/', RegExp.escape('/slashes/')); + this.assertEqual('\\\\backslashes\\\\', RegExp.escape('\\backslashes\\')); + this.assertEqual('\\\\border of word', RegExp.escape('\\border of word')); + + this.assertEqual('\\(\\?\\:non-capturing\\)', RegExp.escape('(?:non-capturing)')); + this.assertEqual('non-capturing', new RegExp(RegExp.escape('(?:') + '([^)]+)').exec('(?:non-capturing)')[1]); + + this.assertEqual('\\(\\?\\=positive-lookahead\\)', RegExp.escape('(?=positive-lookahead)')); + this.assertEqual('positive-lookahead', new RegExp(RegExp.escape('(?=') + '([^)]+)').exec('(?=positive-lookahead)')[1]); + + this.assertEqual('\\(\\?<\\=positive-lookbehind\\)', RegExp.escape('(?<=positive-lookbehind)')); + this.assertEqual('positive-lookbehind', new RegExp(RegExp.escape('(?<=') + '([^)]+)').exec('(?<=positive-lookbehind)')[1]); + + this.assertEqual('\\(\\?\\!negative-lookahead\\)', RegExp.escape('(?!negative-lookahead)')); + this.assertEqual('negative-lookahead', new RegExp(RegExp.escape('(?!') + '([^)]+)').exec('(?!negative-lookahead)')[1]); + + this.assertEqual('\\(\\?<\\!negative-lookbehind\\)', RegExp.escape('(?', new RegExp(RegExp.escape('
')).exec('
')[0]); + + this.assertEqual('false', RegExp.escape(false)); + this.assertEqual('undefined', RegExp.escape()); + this.assertEqual('null', RegExp.escape(null)); + this.assertEqual('42', RegExp.escape(42)); + + this.assertEqual('\\\\n\\\\r\\\\t', RegExp.escape('\\n\\r\\t')); + this.assertEqual('\n\r\t', RegExp.escape('\n\r\t')); + this.assertEqual('\\{5,2\\}', RegExp.escape('{5,2}')); + + this.assertEqual( + '\\/\\(\\[\\.\\*\\+\\?\\^\\=\\!\\:\\$\\{\\}\\(\\)\\|\\[\\\\\\]\\\\\\\/\\\\\\\\\\]\\)\\/g', + RegExp.escape('/([.*+?^=!:${}()|[\\]\\/\\\\])/g') + ); + }, + + testBrowserDetection: function() { + var results = $H(Prototype.Browser).map(function(engine){ + return engine; + }).partition(function(engine){ + return engine[1] === true + }); + var trues = results[0], falses = results[1]; + + this.info('User agent string is: ' + navigator.userAgent); + + this.assert(trues.size() == 0 || trues.size() == 1, + 'There should be only one or no browser detected.'); + + // we should have definite trues or falses here + trues.each(function(result) { + this.assert(result[1] === true); + }, this); + falses.each(function(result) { + this.assert(result[1] === false); + }, this); + + if (navigator.userAgent.indexOf('AppleWebKit/') > -1) { + this.info('Running on WebKit'); + this.assert(Prototype.Browser.WebKit); + } + + if (!!window.opera) { + this.info('Running on Opera'); + this.assert(Prototype.Browser.Opera); + } + + if (!!(window.attachEvent && !window.opera)) { + this.info('Running on IE'); + this.assert(Prototype.Browser.IE); + } + + if (navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1) { + this.info('Running on Gecko'); + this.assert(Prototype.Browser.Gecko); + } + }, + + testClassCreate: function() { + this.assert(Object.isFunction(Animal), 'Animal is not a constructor'); + this.assertEnumEqual([Cat, Mouse, Dog, Ox], Animal.subclasses); + Animal.subclasses.each(function(subclass) { + this.assertEqual(Animal, subclass.superclass); + }, this); + + var Bird = Class.create(Animal); + this.assertEqual(Bird, Animal.subclasses.last()); + // for..in loop (for some reason) doesn't iterate over the constructor property in top-level classes + this.assertEnumEqual(Object.keys(new Animal).sort(), Object.keys(new Bird).without('constructor').sort()); + }, + + testClassInstantiation: function() { + var pet = new Animal("Nibbles"); + this.assertEqual("Nibbles", pet.name, "property not initialized"); + this.assertEqual('Nibbles: Hi!', pet.say('Hi!')); + this.assertEqual(Animal, pet.constructor, "bad constructor reference"); + this.assertUndefined(pet.superclass); + + var Empty = Class.create(); + this.assert('object', typeof new Empty); + }, + + testInheritance: function() { + var tom = new Cat('Tom'); + this.assertEqual(Cat, tom.constructor, "bad constructor reference"); + this.assertEqual(Animal, tom.constructor.superclass, 'bad superclass reference'); + this.assertEqual('Tom', tom.name); + this.assertEqual('Tom: meow', tom.say('meow')); + this.assertEqual('Tom: Yuk! I only eat mice.', tom.eat(new Animal)); + }, + + testSuperclassMethodCall: function() { + var tom = new Cat('Tom'); + this.assertEqual('Tom: Yum!', tom.eat(new Mouse)); + + // augment the constructor and test + var Dodo = Class.create(Animal, { + initialize: function($super, name) { + $super(name); + this.extinct = true; + }, + + say: function($super, message) { + return $super(message) + " honk honk"; + } + }); + + var gonzo = new Dodo('Gonzo'); + this.assertEqual('Gonzo', gonzo.name); + this.assert(gonzo.extinct, 'Dodo birds should be extinct'); + this.assertEqual("Gonzo: hello honk honk", gonzo.say("hello")); + }, + + testClassAddMethods: function() { + var tom = new Cat('Tom'); + var jerry = new Mouse('Jerry'); + + Animal.addMethods({ + sleep: function() { + return this.say('ZZZ'); + } + }); + + Mouse.addMethods({ + sleep: function($super) { + return $super() + " ... no, can't sleep! Gotta steal cheese!"; + }, + escape: function(cat) { + return this.say('(from a mousehole) Take that, ' + cat.name + '!'); + } + }); + + this.assertEqual('Tom: ZZZ', tom.sleep(), "added instance method not available to subclass"); + this.assertEqual("Jerry: ZZZ ... no, can't sleep! Gotta steal cheese!", jerry.sleep()); + this.assertEqual("Jerry: (from a mousehole) Take that, Tom!", jerry.escape(tom)); + // insure that a method has not propagated *up* the prototype chain: + this.assertUndefined(tom.escape); + this.assertUndefined(new Animal().escape); + + Animal.addMethods({ + sleep: function() { + return this.say('zZzZ'); + } + }); + + this.assertEqual("Jerry: zZzZ ... no, can't sleep! Gotta steal cheese!", jerry.sleep()); + }, + + testBaseClassWithMixin: function() { + var grass = new Plant('grass', 3); + this.assertRespondsTo('getValue', grass); + this.assertEqual('#', grass.inspect()); + }, + + testSubclassWithMixin: function() { + var snoopy = new Dog('Snoopy', 12, 'male'); + this.assertRespondsTo('reproduce', snoopy); + }, + + testSubclassWithMixins: function() { + var cow = new Ox('cow', 400, 'female'); + this.assertEqual('#', cow.inspect()); + this.assertRespondsTo('reproduce', cow); + this.assertRespondsTo('getValue', cow); + }, + + testClassWithToStringAndValueOfMethods: function() { + var Foo = Class.create({ + toString: function() { return "toString" }, + valueOf: function() { return "valueOf" } + }); + + var Parent = Class.create({ + m1: function(){ return 'm1' }, + m2: function(){ return 'm2' } + }); + var Child = Class.create(Parent, { + m1: function($super) { return 'm1 child' }, + m2: function($super) { return 'm2 child' } + }); + + this.assert(new Child().m1.toString().indexOf('m1 child') > -1); + + this.assertEqual("toString", new Foo().toString()); + this.assertEqual("valueOf", new Foo().valueOf()); + } +}); \ No newline at end of file diff --git a/dom/tests/mochitest/ajax/prototype/test/unit/dom_test.js b/dom/tests/mochitest/ajax/prototype/test/unit/dom_test.js new file mode 100644 index 0000000000..ebb3b383ec --- /dev/null +++ b/dom/tests/mochitest/ajax/prototype/test/unit/dom_test.js @@ -0,0 +1,1404 @@ +var getInnerHTML = function(id) { + return $(id).innerHTML.toString().toLowerCase().gsub(/[\r\n\t]/, ''); +}; +var createParagraph = function(text) { + var p = document.createElement('p'); + p.appendChild(document.createTextNode(text)); + return p; +} + +new Test.Unit.Runner({ + setup: function() { + if (documentViewportProperties) return; + // Based on properties check from http://www.quirksmode.org/viewport/compatibility.html + documentViewportProperties = { + properties : [ + 'self.pageXOffset', 'self.pageYOffset', + 'self.screenX', 'self.screenY', + 'self.innerHeight', 'self.innerWidth', + 'self.outerHeight', 'self.outerWidth', + 'self.screen.height', 'self.screen.width', + 'self.screen.availHeight', 'self.screen.availWidth', + 'self.screen.availTop', 'self.screen.availLeft', + 'self.screen.Top', 'self.screen.Left', + 'self.screenTop', 'self.screenLeft', + 'document.body.clientHeight', 'document.body.clientWidth', + 'document.body.scrollHeight', 'document.body.scrollWidth', + 'document.body.scrollLeft', 'document.body.scrollTop', + 'document.body.offsetHeight', 'document.body.offsetWidth', + 'document.body.offsetTop', 'document.body.offsetLeft' + ].inject([], function(properties, prop) { + if (!self.screen && prop.include('self.screen')) return; + if (!document.body && prop.include('document.body')) return; + properties.push(prop); + if (prop.include('.body') && document.documentElement) + properties.push(prop.sub('.body', '.documentElement')); + return properties; + }), + + inspect : function() { + var props = []; + this.properties.each(function(prop) { + if (eval(prop)) props[prop] = eval(prop); + }, this); + return props; + } + }; + }, + + testDollarFunction: function() { + this.assertUndefined($()); + + this.assertNull(document.getElementById('noWayThisIDExists')); + this.assertNull($('noWayThisIDExists')); + + this.assertIdentical(document.getElementById('testdiv'), $('testdiv')); + this.assertEnumEqual([ $('testdiv'), $('container') ], $('testdiv', 'container')); + this.assertEnumEqual([ $('testdiv'), undefined, $('container') ], + $('testdiv', 'noWayThisIDExists', 'container')); + var elt = $('testdiv'); + this.assertIdentical(elt, $(elt)); + this.assertRespondsTo('hide', elt); + this.assertRespondsTo('childOf', elt); + }, + + testGetElementsByClassName: function() { + if (document.getElementsByClassName.toString().include('[native code]')) { + this.info("browser uses native getElementsByClassName; skipping tests"); + return; + } + + + var div = $('class_names'), list = $('class_names_ul'); + + this.assertElementsMatch(document.getElementsByClassName('A'), 'p.A', 'ul#class_names_ul.A', 'li.A.C'); + + if (Prototype.Browser.IE) + this.assertUndefined(document.getElementById('unextended').show); + + this.assertElementsMatch(div.getElementsByClassName('B'), 'ul#class_names_ul.A.B', 'div.B.C.D'); + this.assertElementsMatch(div.getElementsByClassName('D C B'), 'div.B.C.D'); + this.assertElementsMatch(div.getElementsByClassName(' D\nC\tB '), 'div.B.C.D'); + this.assertElementsMatch(div.getElementsByClassName($w('D C B'))); + this.assertElementsMatch(list.getElementsByClassName('A'), 'li.A.C'); + this.assertElementsMatch(list.getElementsByClassName(' A '), 'li.A.C'); + this.assertElementsMatch(list.getElementsByClassName('C A'), 'li.A.C'); + this.assertElementsMatch(list.getElementsByClassName("C\nA "), 'li.A.C'); + this.assertElementsMatch(list.getElementsByClassName('B')); + this.assertElementsMatch(list.getElementsByClassName('1'), 'li.1'); + this.assertElementsMatch(list.getElementsByClassName([1]), 'li.1'); + this.assertElementsMatch(list.getElementsByClassName(['1 junk'])); + this.assertElementsMatch(list.getElementsByClassName('')); + this.assertElementsMatch(list.getElementsByClassName(' ')); + this.assertElementsMatch(list.getElementsByClassName([''])); + this.assertElementsMatch(list.getElementsByClassName([' ', ''])); + this.assertElementsMatch(list.getElementsByClassName({})); + + // those lookups shouldn't have extended all nodes in document + if (Prototype.Browser.IE) this.assertUndefined(document.getElementById('unextended')['show']); + }, + + testElementInsertWithHTML: function() { + Element.insert('insertions-main', {before:'

before text

more testing

'}); + this.assert(getInnerHTML('insertions-container').startsWith('

before text

more testing

')); + Element.insert('insertions-main', {after:'

after text

more testing

'}); + this.assert(getInnerHTML('insertions-container').endsWith('

after text

more testing

')); + Element.insert('insertions-main', {top:'

top text.

more testing

'}); + this.assert(getInnerHTML('insertions-main').startsWith('

top text.

more testing

')); + Element.insert('insertions-main', {bottom:'

bottom text.

more testing

'}); + this.assert(getInnerHTML('insertions-main').endsWith('

bottom text.

more testing

')); + }, + + testElementInsertWithDOMNode: function() { + Element.insert('insertions-node-main', {before: createParagraph('node before')}); + this.assert(getInnerHTML('insertions-node-container').startsWith('

node before

')); + Element.insert('insertions-node-main', {after: createParagraph('node after')}); + this.assert(getInnerHTML('insertions-node-container').endsWith('

node after

')); + Element.insert('insertions-node-main', {top:createParagraph('node top')}); + this.assert(getInnerHTML('insertions-node-main').startsWith('

node top

')); + Element.insert('insertions-node-main', {bottom:createParagraph('node bottom')}); + this.assert(getInnerHTML('insertions-node-main').endsWith('

node bottom

')); + this.assertEqual($('insertions-node-main'), $('insertions-node-main').insert(document.createElement('p'))); + }, + + testElementInsertWithToElementMethod: function() { + Element.insert('insertions-node-main', {toElement: createParagraph.curry('toElement') }); + this.assert(getInnerHTML('insertions-node-main').endsWith('

toelement

')); + Element.insert('insertions-node-main', {bottom: {toElement: createParagraph.curry('bottom toElement') }}); + this.assert(getInnerHTML('insertions-node-main').endsWith('

bottom toelement

')); + }, + + testElementInsertWithToHTMLMethod: function() { + Element.insert('insertions-node-main', {toHTML: function() { return '

toHTML

'} }); + this.assert(getInnerHTML('insertions-node-main').endsWith('

tohtml

')); + Element.insert('insertions-node-main', {bottom: {toHTML: function() { return '

bottom toHTML

'} }}); + this.assert(getInnerHTML('insertions-node-main').endsWith('

bottom tohtml

')); + }, + + testElementInsertWithNonString: function() { + Element.insert('insertions-main', {bottom:3}); + this.assert(getInnerHTML('insertions-main').endsWith('3')); + }, + + testElementInsertInTables: function() { + Element.insert('second_row', {after:'Third Row'}); + this.assert($('second_row').descendantOf('table')); + + $('a_cell').insert({top:'hello world'}); + this.assert($('a_cell').innerHTML.startsWith('hello world')); + $('a_cell').insert({after:'hi planet'}); + this.assertEqual('hi planet', $('a_cell').next().innerHTML); + $('table_for_insertions').insert('a cell!'); + this.assert($('table_for_insertions').innerHTML.gsub('\r\n', '').toLowerCase().include('a cell!')); + $('row_1').insert({after:'last'}); + this.assertEqual('last', $A($('table_for_row_insertions').getElementsByTagName('tr')).last().lastChild.innerHTML); + }, + + testElementInsertInSelect: function() { + var selectTop = $('select_for_insert_top'), selectBottom = $('select_for_insert_bottom'); + selectBottom.insert(''); + this.assertEqual('option 45', selectBottom.getValue()); + selectTop.insert({top:''}); + this.assertEqual(4, selectTop.options.length); + }, + + testElementMethodInsert: function() { + $('element-insertions-main').insert({before:'some text before'}); + this.assert(getInnerHTML('element-insertions-container').startsWith('some text before')); + $('element-insertions-main').insert({after:'some text after'}); + this.assert(getInnerHTML('element-insertions-container').endsWith('some text after')); + $('element-insertions-main').insert({top:'some text top'}); + this.assert(getInnerHTML('element-insertions-main').startsWith('some text top')); + $('element-insertions-main').insert({bottom:'some text bottom'}); + this.assert(getInnerHTML('element-insertions-main').endsWith('some text bottom')); + + $('element-insertions-main').insert('some more text at the bottom'); + this.assert(getInnerHTML('element-insertions-main').endsWith('some more text at the bottom')); + + $('element-insertions-main').insert({TOP:'some text uppercase top'}); + this.assert(getInnerHTML('element-insertions-main').startsWith('some text uppercase top')); + + $('element-insertions-multiple-main').insert({ + top:'1', bottom:2, before: new Element('p').update('3'), after:'4' + }); + this.assert(getInnerHTML('element-insertions-multiple-main').startsWith('1')); + this.assert(getInnerHTML('element-insertions-multiple-main').endsWith('2')); + this.assert(getInnerHTML('element-insertions-multiple-container').startsWith('

3

')); + this.assert(getInnerHTML('element-insertions-multiple-container').endsWith('4')); + + $('element-insertions-main').update('test'); + $('element-insertions-main').insert(null); + $('element-insertions-main').insert({bottom:null}); + this.assertEqual('test', getInnerHTML('element-insertions-main')); + $('element-insertions-main').insert(1337); + this.assertEqual('test1337', getInnerHTML('element-insertions-main')); + }, + + testNewElementInsert: function() { + var container = new Element('div'); + element = new Element('div'); + container.insert(element); + + element.insert({ before: '

a paragraph

' }); + this.assertEqual('

a paragraph

', getInnerHTML(container)); + element.insert({ after: 'some text' }); + this.assertEqual('

a paragraph

some text', getInnerHTML(container)); + + element.insert({ top: '

a paragraph

' }); + this.assertEqual('

a paragraph

', getInnerHTML(element)); + element.insert('some text'); + this.assertEqual('

a paragraph

some text', getInnerHTML(element)); + }, + + testInsertionBackwardsCompatibility: function() { + new Insertion.Before('element-insertions-main', 'some backward-compatibility testing before'); + this.assert(getInnerHTML('element-insertions-container').include('some backward-compatibility testing before')); + new Insertion.After('element-insertions-main', 'some backward-compatibility testing after'); + this.assert(getInnerHTML('element-insertions-container').include('some backward-compatibility testing after')); + new Insertion.Top('element-insertions-main', 'some backward-compatibility testing top'); + this.assert(getInnerHTML('element-insertions-main').startsWith('some backward-compatibility testing top')); + new Insertion.Bottom('element-insertions-main', 'some backward-compatibility testing bottom'); + this.assert(getInnerHTML('element-insertions-main').endsWith('some backward-compatibility testing bottom')); + }, + + testElementWrap: function() { + var element = $('wrap'), parent = document.createElement('div'); + element.wrap(); + this.assert(getInnerHTML('wrap-container').startsWith('
\ntestVar="hello!";\n'); + this.assertEqual('hello from div!',$('testdiv').innerHTML); + this.wait(100,function(){ + this.assertEqual('hello!',testVar); + + Element.update('testdiv','another hello from div!\n + + + + + + + + + + + + + +

Prototype Unit test file

+

Ajax

+ + + + +
+ + + +
+
+ + + + + diff --git a/dom/tests/mochitest/ajax/prototype/test/unit/tmp/array_test.html b/dom/tests/mochitest/ajax/prototype/test/unit/tmp/array_test.html new file mode 100644 index 0000000000..cc3b9ef629 --- /dev/null +++ b/dom/tests/mochitest/ajax/prototype/test/unit/tmp/array_test.html @@ -0,0 +1,39 @@ + + + + Prototype Unit test file | Array + + + + + + + + + + + + + +

Prototype Unit test file

+

Array

+ + + + +
+ + + +
22
+ + + + + diff --git a/dom/tests/mochitest/ajax/prototype/test/unit/tmp/base_test.html b/dom/tests/mochitest/ajax/prototype/test/unit/tmp/base_test.html new file mode 100644 index 0000000000..bcd29f91df --- /dev/null +++ b/dom/tests/mochitest/ajax/prototype/test/unit/tmp/base_test.html @@ -0,0 +1,45 @@ + + + + Prototype Unit test file | Base + + + + + + + + + + + + + + + +

Prototype Unit test file

+

Base

+ + + + +
+ + + +
+
    +
  • +
  • +
  • +
+ + + + diff --git a/dom/tests/mochitest/ajax/prototype/test/unit/tmp/dom_test.html b/dom/tests/mochitest/ajax/prototype/test/unit/tmp/dom_test.html new file mode 100644 index 0000000000..c1ffb7536f --- /dev/null +++ b/dom/tests/mochitest/ajax/prototype/test/unit/tmp/dom_test.html @@ -0,0 +1,326 @@ + + + + Prototype Unit test file | Dom + + + + + + + + + + + + + + + + + +

Prototype Unit test file

+

Dom

+ + + + +
+ + + +
+

Scroll test

+
+ +
visible
+ +
visible
+ +
visible
+ +
visible
+ +
+ +
+ + + + + + + + + + + + +
Data
First Row
Second Row
+
+ +
+ + + + + + + + + + + + +
Data
First Row
Second Row
+
+ +

Test paragraph outside of container

+ +
+

Test paragraph 1 inside of container

+

Test paragraph 2 inside of container

+

Test paragraph 3 inside of container

+

Test paragraph 4 inside of container

+
+ +
to be updated
+
+
+
+
+
+
+
+
+
+
+ +

some text

some text

+ +
V
+
H
+
S
+ +
+ +
+ +
+ + +
+
+ + + + +
+

+
    +
  • +
  • +
  • +
+
+
+
+ + +
+ +
blah
+blah +blah + +
+
+
+
+ +
test_csstext_1
+
test_csstext_2
+
test_csstext_3
+
test_csstext_4
+
test_csstext_5
+ +
+
+
+
+ +
+ + + +
+ + + + + + + + + + + + +
+ + +

+ +
+ + + + + +
+ + + + + +
AB
C
DEF
+ +
+
+ +
+
+ +
NFN
+
NFI
+
NFS
+ +
FI
+
FS
+ +op2 +op2 +op3 +op3 +
+
+
+
+
+
+ + + + + + +
Data
+ +
+ +
+ + +

+

+ + +

+

content

+
+
+
+
+
+
+
+
+ +

some content.

+

some content.

+

some content.

+

some content.

+
+
+
+ + + +
+

+ + +
+
+
+
testtest
+
XYZ
+
+
+ foo + bar +
+
+
+ +
+
+
+
+
+
+
+
+ + +
+ + + + diff --git a/dom/tests/mochitest/ajax/prototype/test/unit/tmp/element_mixins_test.html b/dom/tests/mochitest/ajax/prototype/test/unit/tmp/element_mixins_test.html new file mode 100644 index 0000000000..51a789e79b --- /dev/null +++ b/dom/tests/mochitest/ajax/prototype/test/unit/tmp/element_mixins_test.html @@ -0,0 +1,43 @@ + + + + Prototype Unit test file | Element mixins + + + + + + + + + + + + + + + +

Prototype Unit test file

+

Element mixins

+ + + + +
+ + + +
+ + +
+ + + + diff --git a/dom/tests/mochitest/ajax/prototype/test/unit/tmp/enumerable_test.html b/dom/tests/mochitest/ajax/prototype/test/unit/tmp/enumerable_test.html new file mode 100644 index 0000000000..8f462b6395 --- /dev/null +++ b/dom/tests/mochitest/ajax/prototype/test/unit/tmp/enumerable_test.html @@ -0,0 +1,48 @@ + + + + Prototype Unit test file | Enumerable + + + + + + + + + + + + + + + +

Prototype Unit test file

+

Enumerable

+ + + + +
+ + + + + + + + + + +
+ + + + + diff --git a/dom/tests/mochitest/ajax/prototype/test/unit/tmp/event_test.html b/dom/tests/mochitest/ajax/prototype/test/unit/tmp/event_test.html new file mode 100644 index 0000000000..12accf239f --- /dev/null +++ b/dom/tests/mochitest/ajax/prototype/test/unit/tmp/event_test.html @@ -0,0 +1,42 @@ + + + + Prototype Unit test file | Event + + + + + + + + + + + + + +

Prototype Unit test file

+

Event

+ + + + +
+ + + + +
+ + + + + diff --git a/dom/tests/mochitest/ajax/prototype/test/unit/tmp/form_test.html b/dom/tests/mochitest/ajax/prototype/test/unit/tmp/form_test.html new file mode 100644 index 0000000000..14349eb511 --- /dev/null +++ b/dom/tests/mochitest/ajax/prototype/test/unit/tmp/form_test.html @@ -0,0 +1,150 @@ + + + + Prototype Unit test file | Form + + + + + + + + + + + + + +

Prototype Unit test file

+

Form

+ + + + +
+ + + +
+ +
This is not a form element
+ + + + +
+ +
+
+ + + + + +
+ +
+ +
div> + + +
+ + + + + +
+ + +
+ + + + +
+ + + +
+
+ +
+ + + + + +
This is not a form element
+ + + +
+
+ + + +
+ +
+ + +
+
+

+ + +
+ +
+

+ + + +
+ +
+

+ + + +
+ +
+ + + + + diff --git a/dom/tests/mochitest/ajax/prototype/test/unit/tmp/hash_test.html b/dom/tests/mochitest/ajax/prototype/test/unit/tmp/hash_test.html new file mode 100644 index 0000000000..4e4f0be75d --- /dev/null +++ b/dom/tests/mochitest/ajax/prototype/test/unit/tmp/hash_test.html @@ -0,0 +1,40 @@ + + + + Prototype Unit test file | Hash + + + + + + + + + + + + + + + +

Prototype Unit test file

+

Hash

+ + + + +
+ + + + + + + + diff --git a/dom/tests/mochitest/ajax/prototype/test/unit/tmp/number_test.html b/dom/tests/mochitest/ajax/prototype/test/unit/tmp/number_test.html new file mode 100644 index 0000000000..85eed3191b --- /dev/null +++ b/dom/tests/mochitest/ajax/prototype/test/unit/tmp/number_test.html @@ -0,0 +1,38 @@ + + + + Prototype Unit test file | Number + + + + + + + + + + + + + +

Prototype Unit test file

+

Number

+ + + + +
+ + + + + + + + diff --git a/dom/tests/mochitest/ajax/prototype/test/unit/tmp/position_test.html b/dom/tests/mochitest/ajax/prototype/test/unit/tmp/position_test.html new file mode 100644 index 0000000000..78ed551d0e --- /dev/null +++ b/dom/tests/mochitest/ajax/prototype/test/unit/tmp/position_test.html @@ -0,0 +1,47 @@ + + + + Prototype Unit test file | Position + + + + + + + + + + + + + +

Prototype Unit test file

+

Position

+ + + + +
+ + + +
+ +
+
+
+
testtest
+
+
+
+ + + + + diff --git a/dom/tests/mochitest/ajax/prototype/test/unit/tmp/range_test.html b/dom/tests/mochitest/ajax/prototype/test/unit/tmp/range_test.html new file mode 100644 index 0000000000..cbc6f828b6 --- /dev/null +++ b/dom/tests/mochitest/ajax/prototype/test/unit/tmp/range_test.html @@ -0,0 +1,38 @@ + + + + Prototype Unit test file | Range + + + + + + + + + + + + + +

Prototype Unit test file

+

Range

+ + + + +
+ + + + + + + + diff --git a/dom/tests/mochitest/ajax/prototype/test/unit/tmp/selector_test.html b/dom/tests/mochitest/ajax/prototype/test/unit/tmp/selector_test.html new file mode 100644 index 0000000000..84bde55e50 --- /dev/null +++ b/dom/tests/mochitest/ajax/prototype/test/unit/tmp/selector_test.html @@ -0,0 +1,107 @@ + + + + Prototype Unit test file | Selector + + + + + + + + + + + + + +

Prototype Unit test file

+

Selector

+ + + + +
+ + + + + + + + + diff --git a/dom/tests/mochitest/ajax/prototype/test/unit/tmp/string_test.html b/dom/tests/mochitest/ajax/prototype/test/unit/tmp/string_test.html new file mode 100644 index 0000000000..74564fc0ce --- /dev/null +++ b/dom/tests/mochitest/ajax/prototype/test/unit/tmp/string_test.html @@ -0,0 +1,40 @@ + + + + Prototype Unit test file | String + + + + + + + + + + + + + + + +

Prototype Unit test file

+

String

+ + + + +
+ + + + + + + + diff --git a/dom/tests/mochitest/ajax/prototype/test/unit/tmp/unit_test.html b/dom/tests/mochitest/ajax/prototype/test/unit/tmp/unit_test.html new file mode 100644 index 0000000000..b684225ba5 --- /dev/null +++ b/dom/tests/mochitest/ajax/prototype/test/unit/tmp/unit_test.html @@ -0,0 +1,56 @@ + + + + Prototype Unit test file | Unittest + + + + + + + + + + + + + +

Prototype Unit test file

+

Unittest

+ + + + +
+ + + +
+ + +
+ +
+ + + +
+
+ +
  • x1
  • x2
+
  • x1
  • x2
+ +
XXXX
+ +
testcss1
testcss1
+ + + + + diff --git a/dom/tests/mochitest/ajax/prototype/test/unit/unittest_test.js b/dom/tests/mochitest/ajax/prototype/test/unit/unittest_test.js new file mode 100644 index 0000000000..e7afdd60bf --- /dev/null +++ b/dom/tests/mochitest/ajax/prototype/test/unit/unittest_test.js @@ -0,0 +1,143 @@ +var testObj = { + isNice: function() { + return true; + }, + isBroken: function() { + return false; + } +} + +new Test.Unit.Runner({ + + testBuildMessage: function() { + this.assertEqual("'foo' 'bar'", this.buildMessage('', '? ?', 'foo', 'bar')) + }, + + testAssertEqual: function() { + this.assertEqual(0, 0); + this.assertEqual(0, 0, "test"); + + this.assertEqual(0,'0'); + this.assertEqual(65.0, 65); + + this.assertEqual("a", "a"); + this.assertEqual("a", "a", "test"); + + this.assertNotEqual(0, 1); + this.assertNotEqual("a","b"); + this.assertNotEqual({},{}); + this.assertNotEqual([],[]); + this.assertNotEqual([],{}); + }, + + testAssertEnumEqual: function() { + this.assertEnumEqual([], []); + this.assertEnumEqual(['a', 'b'], ['a', 'b']); + this.assertEnumEqual(['1', '2'], [1, 2]); + this.assertEnumNotEqual(['1', '2'], [1, 2, 3]); + }, + + testAssertHashEqual: function() { + this.assertHashEqual({}, {}); + this.assertHashEqual({a:'b'}, {a:'b'}); + this.assertHashEqual({a:'b', c:'d'}, {c:'d', a:'b'}); + this.assertHashNotEqual({a:'b', c:'d'}, {c:'d', a:'boo!'}); + }, + + testAssertRespondsTo: function() { + this.assertRespondsTo('isNice', testObj); + this.assertRespondsTo('isBroken', testObj); + }, + + testAssertIdentical: function() { + this.assertIdentical(0, 0); + this.assertIdentical(0, 0, "test"); + this.assertIdentical(1, 1); + this.assertIdentical('a', 'a'); + this.assertIdentical('a', 'a', "test"); + this.assertIdentical('', ''); + this.assertIdentical(undefined, undefined); + this.assertIdentical(null, null); + this.assertIdentical(true, true); + this.assertIdentical(false, false); + + var obj = {a:'b'}; + this.assertIdentical(obj, obj); + + this.assertNotIdentical({1:2,3:4},{1:2,3:4}); + + this.assertIdentical(1, 1.0); // both are typeof == 'number' + + this.assertNotIdentical(1, '1'); + this.assertNotIdentical(1, '1.0'); + }, + + testAssertNullAndAssertUndefined: function() { + this.assertNull(null); + this.assertNotNull(undefined); + this.assertNotNull(0); + this.assertNotNull(''); + this.assertNotUndefined(null); + this.assertUndefined(undefined); + this.assertNotUndefined(0); + this.assertNotUndefined(''); + this.assertNullOrUndefined(null); + this.assertNullOrUndefined(undefined); + this.assertNotNullOrUndefined(0); + this.assertNotNullOrUndefined(''); + }, + + testAssertMatch: function() { + this.assertMatch(/knowmad.jpg$/, 'http://script.aculo.us/images/knowmad.jpg'); + this.assertMatch(/Fuc/, 'Thomas Fuchs'); + this.assertMatch(/^\$(\d{1,3}(\,\d{3})*|(\d+))(\.\d{2})?$/, '$19.95'); + this.assertMatch(/(\d{3}\) ?)|(\d{3}[- \.])?\d{3}[- \.]\d{4}(\s(x\d+)?){0,1}$/, '704-343-9330'); + this.assertMatch(/^(?:(?:(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))(\/|-|\.)(?:0?2\1(?:29)))|(?:(?:(?:1[6-9]|[2-9]\d)?\d{2})(\/|-|\.)(?:(?:(?:0?[13578]|1[02])\2(?:31))|(?:(?:0?[1,3-9]|1[0-2])\2(29|30))|(?:(?:0?[1-9])|(?:1[0-2]))\2(?:0?[1-9]|1\d|2[0-8]))))$/, '2001-06-16'); + this.assertMatch(/^((0?[123456789])|(1[012]))\s*:\s*([012345]\d)(\s*:\s*([012345]\d))?\s*[ap]m\s*-\s*((0?[123456789])|(1[012]))\s*:\s*([012345]\d)(\s*:\s*([012345]\d))?\s*[ap]m$/i, '2:00PM-2:15PM'); + this.assertNoMatch(/zubar/, 'foo bar'); + }, + + testAssertInstanceOf: function() { + this.assertInstanceOf(String, new String); + this.assertInstanceOf(RegExp, /foo/); + this.assertNotInstanceOf(String, {}); + }, + + testAssertVisible: function() { + this.assertVisible('testcss1'); + this.assertNotVisible('testcss1_span'); + //this.assertNotVisible('testcss2', "Due to a Safari bug, this test fails in Safari."); + + Element.hide('testcss1'); + this.assertNotVisible('testcss1'); + this.assertNotVisible('testcss1_span'); + Element.show('testcss1'); + this.assertVisible('testcss1'); + this.assertNotVisible('testcss1_span'); + + Element.show('testcss1_span'); + this.assertVisible('testcss1_span'); + Element.hide('testcss1'); + this.assertNotVisible('testcss1_span'); // hidden by parent + }, + + testAssertElementsMatch: function() { + this.assertElementsMatch($$('#tlist'), '#tlist'); + this.assertElementMatches($('tlist'), '#tlist'); + } +}); + +/* This test was disabled in bug 486256, because we don't support having two + * Runners in one file. + */ +/* +new Test.Unit.Runner({ + testDummy: function() { + this.assert(true); + }, + + testMultipleTestRunner: function() { + this.assertEqual('passed', $('testlog_2').down('td', 1).innerHTML); + } +}, {testLog: 'testlog_2'}); +*/ -- cgit v1.2.3