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 --- dom/tests/mochitest/ajax/jquery/test/data/cow.jpg | Bin 0 -> 1635 bytes .../mochitest/ajax/jquery/test/data/dashboard.xml | 11 + .../mochitest/ajax/jquery/test/data/iframe.html | 8 + .../ajax/jquery/test/data/json_assigned_obj.js | 1 + .../mochitest/ajax/jquery/test/data/json_obj.js | 1 + .../mochitest/ajax/jquery/test/data/name.html | 1 + .../ajax/jquery/test/data/offset/absolute.html | 39 + .../ajax/jquery/test/data/offset/fixed.html | 33 + .../ajax/jquery/test/data/offset/relative.html | 31 + .../ajax/jquery/test/data/offset/scroll.html | 39 + .../ajax/jquery/test/data/offset/static.html | 31 + .../ajax/jquery/test/data/offset/table.html | 43 + .../mochitest/ajax/jquery/test/data/test.html | 7 + dom/tests/mochitest/ajax/jquery/test/data/test.js | 3 + .../mochitest/ajax/jquery/test/data/test2.html | 5 + .../mochitest/ajax/jquery/test/data/test3.html | 3 + .../mochitest/ajax/jquery/test/data/testrunner.js | 334 ++++ .../mochitest/ajax/jquery/test/data/testsuite.css | 117 ++ .../mochitest/ajax/jquery/test/data/with_fries.xml | 25 + dom/tests/mochitest/ajax/jquery/test/fix.html | 48 + dom/tests/mochitest/ajax/jquery/test/index.html | 187 +++ dom/tests/mochitest/ajax/jquery/test/offset.html | 27 + dom/tests/mochitest/ajax/jquery/test/test.js | 41 + dom/tests/mochitest/ajax/jquery/test/unit/ajax.js | 837 ++++++++++ dom/tests/mochitest/ajax/jquery/test/unit/core.js | 1700 ++++++++++++++++++++ .../mochitest/ajax/jquery/test/unit/dimensions.js | 86 + dom/tests/mochitest/ajax/jquery/test/unit/event.js | 348 ++++ dom/tests/mochitest/ajax/jquery/test/unit/fx.js | 435 +++++ .../mochitest/ajax/jquery/test/unit/offset.js | 164 ++ .../mochitest/ajax/jquery/test/unit/selector.js | 224 +++ 30 files changed, 4829 insertions(+) create mode 100644 dom/tests/mochitest/ajax/jquery/test/data/cow.jpg create mode 100644 dom/tests/mochitest/ajax/jquery/test/data/dashboard.xml create mode 100644 dom/tests/mochitest/ajax/jquery/test/data/iframe.html create mode 100644 dom/tests/mochitest/ajax/jquery/test/data/json_assigned_obj.js create mode 100644 dom/tests/mochitest/ajax/jquery/test/data/json_obj.js create mode 100644 dom/tests/mochitest/ajax/jquery/test/data/name.html create mode 100644 dom/tests/mochitest/ajax/jquery/test/data/offset/absolute.html create mode 100644 dom/tests/mochitest/ajax/jquery/test/data/offset/fixed.html create mode 100644 dom/tests/mochitest/ajax/jquery/test/data/offset/relative.html create mode 100644 dom/tests/mochitest/ajax/jquery/test/data/offset/scroll.html create mode 100644 dom/tests/mochitest/ajax/jquery/test/data/offset/static.html create mode 100644 dom/tests/mochitest/ajax/jquery/test/data/offset/table.html create mode 100644 dom/tests/mochitest/ajax/jquery/test/data/test.html create mode 100644 dom/tests/mochitest/ajax/jquery/test/data/test.js create mode 100644 dom/tests/mochitest/ajax/jquery/test/data/test2.html create mode 100644 dom/tests/mochitest/ajax/jquery/test/data/test3.html create mode 100644 dom/tests/mochitest/ajax/jquery/test/data/testrunner.js create mode 100644 dom/tests/mochitest/ajax/jquery/test/data/testsuite.css create mode 100644 dom/tests/mochitest/ajax/jquery/test/data/with_fries.xml create mode 100644 dom/tests/mochitest/ajax/jquery/test/fix.html create mode 100644 dom/tests/mochitest/ajax/jquery/test/index.html create mode 100644 dom/tests/mochitest/ajax/jquery/test/offset.html create mode 100644 dom/tests/mochitest/ajax/jquery/test/test.js create mode 100644 dom/tests/mochitest/ajax/jquery/test/unit/ajax.js create mode 100644 dom/tests/mochitest/ajax/jquery/test/unit/core.js create mode 100644 dom/tests/mochitest/ajax/jquery/test/unit/dimensions.js create mode 100644 dom/tests/mochitest/ajax/jquery/test/unit/event.js create mode 100644 dom/tests/mochitest/ajax/jquery/test/unit/fx.js create mode 100644 dom/tests/mochitest/ajax/jquery/test/unit/offset.js create mode 100644 dom/tests/mochitest/ajax/jquery/test/unit/selector.js (limited to 'dom/tests/mochitest/ajax/jquery/test') diff --git a/dom/tests/mochitest/ajax/jquery/test/data/cow.jpg b/dom/tests/mochitest/ajax/jquery/test/data/cow.jpg new file mode 100644 index 0000000000..2c5b672259 Binary files /dev/null and b/dom/tests/mochitest/ajax/jquery/test/data/cow.jpg differ diff --git a/dom/tests/mochitest/ajax/jquery/test/data/dashboard.xml b/dom/tests/mochitest/ajax/jquery/test/data/dashboard.xml new file mode 100644 index 0000000000..10f6b33479 --- /dev/null +++ b/dom/tests/mochitest/ajax/jquery/test/data/dashboard.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/dom/tests/mochitest/ajax/jquery/test/data/iframe.html b/dom/tests/mochitest/ajax/jquery/test/data/iframe.html new file mode 100644 index 0000000000..3ff26e1612 --- /dev/null +++ b/dom/tests/mochitest/ajax/jquery/test/data/iframe.html @@ -0,0 +1,8 @@ + + + iframe + + +
span text
+ + diff --git a/dom/tests/mochitest/ajax/jquery/test/data/json_assigned_obj.js b/dom/tests/mochitest/ajax/jquery/test/data/json_assigned_obj.js new file mode 100644 index 0000000000..867251dad1 --- /dev/null +++ b/dom/tests/mochitest/ajax/jquery/test/data/json_assigned_obj.js @@ -0,0 +1 @@ +json_assigned_obj = { "test" : "worked" }; diff --git a/dom/tests/mochitest/ajax/jquery/test/data/json_obj.js b/dom/tests/mochitest/ajax/jquery/test/data/json_obj.js new file mode 100644 index 0000000000..7fa61820f8 --- /dev/null +++ b/dom/tests/mochitest/ajax/jquery/test/data/json_obj.js @@ -0,0 +1 @@ +{ "data": {"lang": "en", "length": 25} } diff --git a/dom/tests/mochitest/ajax/jquery/test/data/name.html b/dom/tests/mochitest/ajax/jquery/test/data/name.html new file mode 100644 index 0000000000..0fa32d1a82 --- /dev/null +++ b/dom/tests/mochitest/ajax/jquery/test/data/name.html @@ -0,0 +1 @@ +ERROR diff --git a/dom/tests/mochitest/ajax/jquery/test/data/offset/absolute.html b/dom/tests/mochitest/ajax/jquery/test/data/offset/absolute.html new file mode 100644 index 0000000000..3bbc8417dc --- /dev/null +++ b/dom/tests/mochitest/ajax/jquery/test/data/offset/absolute.html @@ -0,0 +1,39 @@ + + + + + absolute + + + + + +
absolute-1 +
absolute-1-1 +
absolute-1-1-1
+
+
+
absolute-2
+
+

Click the white box to move the marker to it. Clicking the box also changes the position to absolute (if not already) and sets the position according to the position method.

+ + \ No newline at end of file diff --git a/dom/tests/mochitest/ajax/jquery/test/data/offset/fixed.html b/dom/tests/mochitest/ajax/jquery/test/data/offset/fixed.html new file mode 100644 index 0000000000..8d69aae94d --- /dev/null +++ b/dom/tests/mochitest/ajax/jquery/test/data/offset/fixed.html @@ -0,0 +1,33 @@ + + + + + fixed + + + + + +
+
+
+
+

Click the white box to move the marker to it.

+ + \ No newline at end of file diff --git a/dom/tests/mochitest/ajax/jquery/test/data/offset/relative.html b/dom/tests/mochitest/ajax/jquery/test/data/offset/relative.html new file mode 100644 index 0000000000..89aae83e4a --- /dev/null +++ b/dom/tests/mochitest/ajax/jquery/test/data/offset/relative.html @@ -0,0 +1,31 @@ + + + + + relative + + + + + +
+
+
+

Click the white box to move the marker to it. Clicking the box also changes the position to absolute (if not already) and sets the position according to the position method.

+ + \ No newline at end of file diff --git a/dom/tests/mochitest/ajax/jquery/test/data/offset/scroll.html b/dom/tests/mochitest/ajax/jquery/test/data/offset/scroll.html new file mode 100644 index 0000000000..494f640581 --- /dev/null +++ b/dom/tests/mochitest/ajax/jquery/test/data/offset/scroll.html @@ -0,0 +1,39 @@ + + + + + scroll + + + + + +
+
+
+
+
+
+
+

Click the white box to move the marker to it.

+ + \ No newline at end of file diff --git a/dom/tests/mochitest/ajax/jquery/test/data/offset/static.html b/dom/tests/mochitest/ajax/jquery/test/data/offset/static.html new file mode 100644 index 0000000000..10116af65b --- /dev/null +++ b/dom/tests/mochitest/ajax/jquery/test/data/offset/static.html @@ -0,0 +1,31 @@ + + + + + static + + + + + +
+
+
+

Click the white box to move the marker to it. Clicking the box also changes the position to absolute (if not already) and sets the position according to the position method.

+ + \ No newline at end of file diff --git a/dom/tests/mochitest/ajax/jquery/test/data/offset/table.html b/dom/tests/mochitest/ajax/jquery/test/data/offset/table.html new file mode 100644 index 0000000000..5d15b903b6 --- /dev/null +++ b/dom/tests/mochitest/ajax/jquery/test/data/offset/table.html @@ -0,0 +1,43 @@ + + + + + table + + + + + + + + + + + + + + + + + + + + +
th-1th-2th-3
td-1td-2td-3
+
+

Click the white box to move the marker to it.

+ + \ No newline at end of file diff --git a/dom/tests/mochitest/ajax/jquery/test/data/test.html b/dom/tests/mochitest/ajax/jquery/test/data/test.html new file mode 100644 index 0000000000..fc6dc38607 --- /dev/null +++ b/dom/tests/mochitest/ajax/jquery/test/data/test.html @@ -0,0 +1,7 @@ +html text
+ + +blabla diff --git a/dom/tests/mochitest/ajax/jquery/test/data/test.js b/dom/tests/mochitest/ajax/jquery/test/data/test.js new file mode 100644 index 0000000000..f8bdd091e4 --- /dev/null +++ b/dom/tests/mochitest/ajax/jquery/test/data/test.js @@ -0,0 +1,3 @@ +var foobar = "bar"; +$('#ap').html('bar'); +ok( true, "test.js executed"); diff --git a/dom/tests/mochitest/ajax/jquery/test/data/test2.html b/dom/tests/mochitest/ajax/jquery/test/data/test2.html new file mode 100644 index 0000000000..ebf610e438 --- /dev/null +++ b/dom/tests/mochitest/ajax/jquery/test/data/test2.html @@ -0,0 +1,5 @@ + diff --git a/dom/tests/mochitest/ajax/jquery/test/data/test3.html b/dom/tests/mochitest/ajax/jquery/test/data/test3.html new file mode 100644 index 0000000000..909d41745c --- /dev/null +++ b/dom/tests/mochitest/ajax/jquery/test/data/test3.html @@ -0,0 +1,3 @@ +
This is a user
+
This is a user
+
This is a teacher
diff --git a/dom/tests/mochitest/ajax/jquery/test/data/testrunner.js b/dom/tests/mochitest/ajax/jquery/test/data/testrunner.js new file mode 100644 index 0000000000..24bf0a863a --- /dev/null +++ b/dom/tests/mochitest/ajax/jquery/test/data/testrunner.js @@ -0,0 +1,334 @@ +var _config = { + fixture: null, + Test: [], + stats: { + all: 0, + bad: 0 + }, + queue: [], + blocking: true, + timeout: null, + expected: null, + currentModule: null, + asyncTimeout: 2 // seconds for async timeout +}; + +_config.filters = location.search.length > 1 && //restrict modules/tests by get parameters + $.map( location.search.slice(1).split('&'), decodeURIComponent ); + +var isLocal = !!(window.location.protocol == 'file:'); + +$(function() { + $('#userAgent').html(navigator.userAgent); + runTest(); +}); + +function synchronize(callback) { + _config.queue[_config.queue.length] = callback; + if(!_config.blocking) { + process(); + } +} + +function process() { + while(_config.queue.length && !_config.blocking) { + var call = _config.queue[0]; + _config.queue = _config.queue.slice(1); + call(); + } +} + +function stop(allowFailure) { + _config.blocking = true; + var handler = allowFailure ? start : function() { + ok( false, "Test timed out" ); + start(); + }; + // Disabled, caused too many random errors + //_config.timeout = setTimeout(handler, _config.asyncTimeout * 1000); +} +function start() { + // A slight delay, to avoid any current callbacks + setTimeout(function(){ + if(_config.timeout) + clearTimeout(_config.timeout); + _config.blocking = false; + process(); + }, 13); +} + +function validTest( name ) { + var filters = _config.filters; + if( !filters ) + return true; + + var i = filters.length, + run = false; + while( i-- ){ + var filter = filters[i], + not = filter.charAt(0) == '!'; + if( not ) + filter = filter.slice(1); + if( name.indexOf(filter) != -1 ) + return !not; + if( not ) + run = true; + } + return run; +} + +function runTest() { + _config.blocking = false; + var time = new Date(); + _config.fixture = document.getElementById('main').innerHTML; + _config.ajaxSettings = $.ajaxSettings; + synchronize(function() { + time = new Date() - time; + $("
").html(['

Tests completed in ', + time, ' milliseconds.
', + _config.stats.bad, ' tests of ', _config.stats.all, ' failed.

'] + .join('')) + .appendTo("body"); + $("#banner").addClass(_config.stats.bad ? "fail" : "pass"); + if ( parent.runAJAXTest ) + parent.runAJAXTest(); + + }); +} + +function test(name, callback, nowait) { + if(_config.currentModule) + name = _config.currentModule + " module: " + name; + + if ( !validTest(name) ) + return; + + synchronize(function() { + _config.Test = []; + try { + callback(); + } catch(e) { + if( typeof console != "undefined" && console.error && console.warn ) { + console.error("Test " + name + " died, exception and test follows"); + console.error(e); + console.warn(callback.toString()); + } + _config.Test.push( [ false, "Died on test #" + (_config.Test.length+1) + ": " + e.message ] ); + } + }); + synchronize(function() { + reset(); + + // don't output pause tests + if(nowait) return; + + if(_config.expected && _config.expected != _config.Test.length) { + _config.Test.push( [ false, "Expected " + _config.expected + " assertions, but " + _config.Test.length + " were run" ] ); + } + _config.expected = null; + + var good = 0, bad = 0; + var ol = document.createElement("ol"); + ol.style.display = "none"; + var li = "", state = "pass"; + for ( var i = 0; i < _config.Test.length; i++ ) { + var li = document.createElement("li"); + li.className = _config.Test[i][0] ? "pass" : "fail"; + li.innerHTML = _config.Test[i][1]; + ol.appendChild( li ); + + _config.stats.all++; + if ( !_config.Test[i][0] ) { + state = "fail"; + bad++; + _config.stats.bad++; + } else good++; + + if ( parent.SimpleTest ){ + parent.SimpleTest.ok( _config.Test[i][0], `${name}: ${_config.Test[i][1]}` );} + } + + var li = document.createElement("li"); + li.className = state; + + var b = document.createElement("strong"); + b.innerHTML = name + " (" + bad + ", " + good + ", " + _config.Test.length + ")"; + b.onclick = function(){ + var n = this.nextSibling; + if ( jQuery.css( n, "display" ) == "none" ) + n.style.display = "block"; + else + n.style.display = "none"; + }; + $(b).dblclick(function(event) { + var target = jQuery(event.target).filter("strong").clone(); + if ( target.length ) { + target.children().remove(); + location.href = location.href.match(/^(.+?)(\?.*)?$/)[1] + "?" + encodeURIComponent($.trim(target.text())); + } + }); + li.appendChild( b ); + li.appendChild( ol ); + + document.getElementById("tests").appendChild( li ); + }); +} + +// call on start of module test to prepend name to all tests +function module(moduleName) { + _config.currentModule = moduleName; +} + +/** + * Specify the number of expected assertions to gurantee that failed test (no assertions are run at all) don't slip through. + */ +function expect(asserts) { + _config.expected = asserts; +} + +/** + * Resets the test setup. Useful for tests that modify the DOM. + */ +function reset() { + $("#main").html( _config.fixture ); + $.event.global = {}; + $.ajaxSettings = $.extend({}, _config.ajaxSettings); +} + +/** + * Asserts true. + * @example ok( $("a").size() > 5, "There must be at least 5 anchors" ); + */ +function ok(a, msg) { + _config.Test.push( [ !!a, msg ] ); +} + +/** + * Asserts that two arrays are the same + */ +function isSet(a, b, msg) { + var ret = true; + if ( a && b && a.length != undefined && a.length == b.length ) { + for ( var i = 0; i < a.length; i++ ) + if ( a[i] != b[i] ) + ret = false; + } else + ret = false; + if ( !ret ) + _config.Test.push( [ ret, msg + " expected: " + serialArray(b) + " result: " + serialArray(a) ] ); + else + _config.Test.push( [ ret, msg ] ); +} + +/** + * Asserts that two objects are equivalent + */ +function isObj(a, b, msg) { + var ret = true; + + if ( a && b ) { + for ( var i in a ) + if ( a[i] != b[i] ) + ret = false; + + for ( i in b ) + if ( a[i] != b[i] ) + ret = false; + } else + ret = false; + + _config.Test.push( [ ret, msg ] ); +} + +function serialArray( a ) { + var r = []; + + if ( a && a.length ) + for ( var i = 0; i < a.length; i++ ) { + var str = a[i].nodeName; + if ( str ) { + str = str.toLowerCase(); + if ( a[i].id ) + str += "#" + a[i].id; + } else + str = a[i]; + r.push( str ); + } + + return "[ " + r.join(", ") + " ]"; +} + +/** + * Returns an array of elements with the given IDs, eg. + * @example q("main", "foo", "bar") + * @result [
, , ] + */ +function q() { + var r = []; + for ( var i = 0; i < arguments.length; i++ ) + r.push( document.getElementById( arguments[i] ) ); + return r; +} + +/** + * Asserts that a select matches the given IDs + * @example t("Check for something", "//[a]", ["foo", "baar"]); + * @result returns true if "//[a]" return two elements with the IDs 'foo' and 'baar' + */ +function t(a,b,c) { + var f = jQuery(b); + var s = ""; + for ( var i = 0; i < f.length; i++ ) + s += (s && ",") + '"' + f[i].id + '"'; + isSet(f, q.apply(q,c), a + " (" + b + ")"); +} + +/** + * Add random number to url to stop IE from caching + * + * @example url("data/test.html") + * @result "data/test.html?10538358428943" + * + * @example url("data/test.php?foo=bar") + * @result "data/test.php?foo=bar&10538358345554" + */ +function url(value) { + return value + (/\?/.test(value) ? "&" : "?") + new Date().getTime() + "" + parseInt(Math.random()*100000); +} + +/** + * Checks that the first two arguments are equal, with an optional message. + * Prints out both expected and actual values on failure. + * + * Prefered to ok( expected == actual, message ) + * + * @example equals( "Expected 2 characters.", v.formatMessage("Expected {0} characters.", 2) ); + * + * @param Object actual + * @param Object expected + * @param String message (optional) + */ +function equals(actual, expected, message) { + var result = expected == actual; + message = message || (result ? "okay" : "failed"); + _config.Test.push( [ result, result ? message + ": " + expected : message + " expected: " + expected + " actual: " + actual ] ); +} + +/** + * Trigger an event on an element. + * + * @example triggerEvent( document.body, "click" ); + * + * @param DOMElement elem + * @param String type + */ +function triggerEvent( elem, type, event ) { + if ( jQuery.browser.mozilla || jQuery.browser.opera ) { + event = document.createEvent("MouseEvents"); + event.initMouseEvent(type, true, true, elem.ownerDocument.defaultView, + 0, 0, 0, 0, 0, false, false, false, false, 0, null); + elem.dispatchEvent( event ); + } else if ( jQuery.browser.msie ) { + elem.fireEvent("on"+type); + } +} \ No newline at end of file diff --git a/dom/tests/mochitest/ajax/jquery/test/data/testsuite.css b/dom/tests/mochitest/ajax/jquery/test/data/testsuite.css new file mode 100644 index 0000000000..4801becd65 --- /dev/null +++ b/dom/tests/mochitest/ajax/jquery/test/data/testsuite.css @@ -0,0 +1,117 @@ +body, div, h1 { font-family: 'trebuchet ms', verdana, arial; margin: 0; padding: 0 } +body {font-size: 10pt; } +h1 { padding: 15px; font-size: large; background-color: #06b; color: white; } +h2 { padding: 10px; background-color: #eee; color: black; margin: 0; font-size: small; font-weight: normal } + +.pass { color: green; } +.fail { color: red; } +p.result { margin-left: 1em; } + +#banner { height: 2em; border-bottom: 1px solid white; } +h2.pass { background-color: green; } +h2.fail { background-color: red; } + +ol#tests > li > strong { cursor:pointer; } + +div#fx-tests h4 { + background: red; +} + +div#fx-tests h4.pass { + background: green; +} + +div#fx-tests div.box { + background: red url(data/cow.jpg) no-repeat; + overflow: hidden; + border: 2px solid #000; +} + +div#fx-tests div.overflow { + overflow: visible; +} + +div.inline { + display: inline; +} + +div.autoheight { + height: auto; +} + +div.autowidth { + width: auto; +} + +div.autoopacity { + opacity: auto; +} + +div.largewidth { + width: 100px; +} + +div.largeheight { + height: 100px; +} + +div.largeopacity { + filter: progid:DXImageTransform.Microsoft.Alpha(opacity=100); +} + +div.medwidth { + width: 50px; +} + +div.medheight { + height: 50px; +} + +div.medopacity { + opacity: 0.5; + filter: progid:DXImageTransform.Microsoft.Alpha(opacity=50); +} + +div.nowidth { + width: 0px; +} + +div.noheight { + height: 0px; +} + +div.noopacity { + opacity: 0; + filter: progid:DXImageTransform.Microsoft.Alpha(opacity=0); +} + +div.hidden { + display: none; +} + +div#fx-tests div.widewidth { + background-repeat: repeat-x; +} + +div#fx-tests div.wideheight { + background-repeat: repeat-y; +} + +div#fx-tests div.widewidth.wideheight { + background-repeat: repeat; +} + +div#fx-tests div.noback { + background-image: none; +} + +div.chain, div.chain div { width: 100px; height: 20px; position: relative; float: left; } +div.chain div { position: absolute; top: 0px; left: 0px; } + +div.chain.test { background: red; } +div.chain.test div { background: green; } + +div.chain.out { background: green; } +div.chain.out div { background: red; display: none; } + +div#show-tests * { display: none; } \ No newline at end of file diff --git a/dom/tests/mochitest/ajax/jquery/test/data/with_fries.xml b/dom/tests/mochitest/ajax/jquery/test/data/with_fries.xml new file mode 100644 index 0000000000..88e0e49d57 --- /dev/null +++ b/dom/tests/mochitest/ajax/jquery/test/data/with_fries.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + 1 + + + + + foo + + + + + + + diff --git a/dom/tests/mochitest/ajax/jquery/test/fix.html b/dom/tests/mochitest/ajax/jquery/test/fix.html new file mode 100644 index 0000000000..f4edab7919 --- /dev/null +++ b/dom/tests/mochitest/ajax/jquery/test/fix.html @@ -0,0 +1,48 @@ + + + + + + + Tester + + + + + + + + +
+ Hi +
+ +
+
+ + + diff --git a/dom/tests/mochitest/ajax/jquery/test/index.html b/dom/tests/mochitest/ajax/jquery/test/index.html new file mode 100644 index 0000000000..8608f430b5 --- /dev/null +++ b/dom/tests/mochitest/ajax/jquery/test/index.html @@ -0,0 +1,187 @@ + + + + + jQuery Test Suite + + + + + + + + + + + + + +

jQuery Test Suite

+ +

+ + +
+
+
+ + + + +
    + + diff --git a/dom/tests/mochitest/ajax/jquery/test/offset.html b/dom/tests/mochitest/ajax/jquery/test/offset.html new file mode 100644 index 0000000000..f802dea346 --- /dev/null +++ b/dom/tests/mochitest/ajax/jquery/test/offset.html @@ -0,0 +1,27 @@ + + + + + jQuery Offset Test Suite + + + + + + + +

    jQuery Offset Test Suite

    + +

    + + +
    + + +
      + + diff --git a/dom/tests/mochitest/ajax/jquery/test/test.js b/dom/tests/mochitest/ajax/jquery/test/test.js new file mode 100644 index 0000000000..e76b795a2c --- /dev/null +++ b/dom/tests/mochitest/ajax/jquery/test/test.js @@ -0,0 +1,41 @@ +load( "build/js/writeFile.js", "build/js/parse.js" ); + +function addParams(name, params) { + if(params.length > 0) { + name += "("; + for ( var i = 0; i < params.length; i++) { + name += params[i].type + ", "; + } + return name.substring(0, name.length - 2) + ")"; + } else { + return name + "()"; + } +} +function addTestWrapper(name, test) { + return 'test("' + name + '", function() {\n' + test + '\n});'; +} + +var dir = arguments[1]; +var jq = parse( read(arguments[0]) ); + +var testFile = []; + +String.prototype.decode = function() { + return this.replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&"); +}; + +for ( var i = 0; i < jq.length; i++ ) { + if ( jq[i].tests.length > 0 ) { + var method = jq[i]; + var name = addParams(method.name, method.params); + for(var j = 0; j < method.tests.length; j++) { + if(j > 0) { + name += "x"; + } + testFile[testFile.length] = addTestWrapper(name, method.tests[j].decode()) + "\n"; + } + } +} + +var indexFile = readFile( "build/test/index.html" ); +writeFile( dir + "/index.html", indexFile.replace( /{TESTS}/g, testFile.join("\n") ) ); diff --git a/dom/tests/mochitest/ajax/jquery/test/unit/ajax.js b/dom/tests/mochitest/ajax/jquery/test/unit/ajax.js new file mode 100644 index 0000000000..b60d39e72f --- /dev/null +++ b/dom/tests/mochitest/ajax/jquery/test/unit/ajax.js @@ -0,0 +1,837 @@ +module("ajax"); + +// Safari 3 randomly crashes when running these tests, +// but only in the full suite - you can run just the Ajax +// tests and they'll pass +//if ( !jQuery.browser.safari ) { + +if ( !isLocal ) { + +test("$.ajax() - success callbacks", function() { + expect( 8 ); + + $.ajaxSetup({ timeout: 0 }); + + stop(); + + setTimeout(function(){ + $('#foo').ajaxStart(function(){ + ok( true, "ajaxStart" ); + }).ajaxStop(function(){ + ok( true, "ajaxStop" ); + start(); + }).ajaxSend(function(){ + ok( true, "ajaxSend" ); + }).ajaxComplete(function(){ + ok( true, "ajaxComplete" ); + }).ajaxError(function(){ + ok( false, "ajaxError" ); + }).ajaxSuccess(function(){ + ok( true, "ajaxSuccess" ); + }); + + $.ajax({ + url: url("data/name.html"), + beforeSend: function(){ ok(true, "beforeSend"); }, + success: function(){ ok(true, "success"); }, + error: function(){ ok(false, "error"); }, + complete: function(){ ok(true, "complete"); } + }); + }, 13); +}); + +/* mozilla: the ajaxSuccess part fails intermittently on MacOSX + +test("$.ajax() - error callbacks", function() { + expect( 7 ); + stop(); + + $('#foo').ajaxStart(function(){ + ok( true, "ajaxStart" ); + }).ajaxStop(function(){ + ok( true, "ajaxStop" ); + start(); + }).ajaxSend(function(){ + ok( true, "ajaxSend" ); + }).ajaxComplete(function(){ + ok( true, "ajaxComplete" ); + }).ajaxError(function(){ + ok( true, "ajaxError" ); + }).ajaxSuccess(function(){ + ok( false, "ajaxSuccess" ); + }) + ; + + $.ajaxSetup({ timeout: 500 }); + + $.ajax({ + url: url("data/name.php?wait=5"), + beforeSend: function(){ ok(true, "beforeSend"); }, + success: function(){ ok(false, "success"); }, + error: function(){ ok(true, "error"); }, + complete: function(){ ok(true, "complete"); } + }); +}); + +*/ + +test("$.ajax() - disabled globals", function() { + expect( 3 ); + stop(); + + $('#foo').ajaxStart(function(){ + ok( false, "ajaxStart" ); + }).ajaxStop(function(){ + ok( false, "ajaxStop" ); + }).ajaxSend(function(){ + ok( false, "ajaxSend" ); + }).ajaxComplete(function(){ + ok( false, "ajaxComplete" ); + }).ajaxError(function(){ + ok( false, "ajaxError" ); + }).ajaxSuccess(function(){ + ok( false, "ajaxSuccess" ); + }); + + $.ajax({ + global: false, + url: url("data/name.html"), + beforeSend: function(){ ok(true, "beforeSend"); }, + success: function(){ ok(true, "success"); }, + error: function(){ ok(false, "error"); }, + complete: function(){ + ok(true, "complete"); + setTimeout(function(){ start(); }, 13); + } + }); +}); + +test("$.ajax - xml: non-namespace elements inside namespaced elements", function() { + expect(3); + stop(); + $.ajax({ + url: url("data/with_fries.xml"), + dataType: "xml", + success: function(resp) { + equals( $("properties", resp).length, 1, 'properties in responseXML' ); + equals( $("jsconf", resp).length, 1, 'jsconf in responseXML' ); + equals( $("thing", resp).length, 2, 'things in responseXML' ); + start(); + } + }); +}); + +test("$.ajax - beforeSend", function() { + expect(1); + stop(); + + var check = false; + + $.ajaxSetup({ timeout: 0 }); + + $.ajax({ + url: url("data/name.html"), + beforeSend: function(xml) { + check = true; + }, + success: function(data) { + ok( check, "check beforeSend was executed" ); + start(); + } + }); +}); + +test("$.ajax - beforeSend, cancel request (#2688)", function() { + expect(2); + var request = $.ajax({ + url: url("data/name.html"), + beforeSend: function() { + ok( true, "beforeSend got called, canceling" ); + return false; + }, + success: function() { + ok( false, "request didn't get canceled" ); + }, + complete: function() { + ok( false, "request didn't get canceled" ); + }, + error: function() { + ok( false, "request didn't get canceled" ); + } + }); + ok( request === false, "canceled request must return false instead of XMLHttpRequest instance" ); +}); + +var foobar; + +test("$.ajax - dataType html", function() { + expect(5); + stop(); + + foobar = null; + testFoo = undefined; + + var verifyEvaluation = function() { + equals( testFoo, "foo", 'Check if script was evaluated for datatype html' ); + equals( foobar, "bar", 'Check if script src was evaluated for datatype html' ); + start(); + }; + + $.ajax({ + dataType: "html", + url: url("data/test.html"), + success: function(data) { + $("#ap").html(data); + ok( data.match(/^html text/), 'Check content for datatype html' ); + setTimeout(verifyEvaluation, 600); + } + }); +}); + +test("serialize()", function() { + expect(6); + + equals( $('#form').serialize(), + "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&select1=&select2=3&select3=1&select3=2", + 'Check form serialization as query string'); + + equals( $('#form :input').serialize(), + "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&select1=&select2=3&select3=1&select3=2", + 'Check input serialization as query string'); + + equals( $('#testForm').serialize(), + 'T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=', + 'Check form serialization as query string'); + + equals( $('#testForm :input').serialize(), + 'T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=', + 'Check input serialization as query string'); + + equals( $('#form, #testForm').serialize(), + "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&select1=&select2=3&select3=1&select3=2&T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=", + 'Multiple form serialization as query string'); + + equals( $('#form, #testForm :input').serialize(), + "action=Test&radio2=on&check=on&hidden=&foo%5Bbar%5D=&name=name&select1=&select2=3&select3=1&select3=2&T3=%3F%0AZ&H1=x&H2=&PWD=&T1=&T2=YES&My+Name=me&S1=abc&S3=YES&S4=", + 'Mixed form/input serialization as query string'); +}); + +test("$.param()", function() { + expect(4); + var params = {foo:"bar", baz:42, quux:"All your base are belong to us"}; + equals( $.param(params), "foo=bar&baz=42&quux=All+your+base+are+belong+to+us", "simple" ); + + params = {someName: [1, 2, 3], regularThing: "blah" }; + equals( $.param(params), "someName=1&someName=2&someName=3®ularThing=blah", "with array" ); + + params = {"foo[]":["baz", 42, "All your base are belong to us"]}; + equals( $.param(params), "foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All+your+base+are+belong+to+us", "more array" ); + + params = {"foo[bar]":"baz", "foo[beep]":42, "foo[quux]":"All your base are belong to us"}; + equals( $.param(params), "foo%5Bbar%5D=baz&foo%5Bbeep%5D=42&foo%5Bquux%5D=All+your+base+are+belong+to+us", "even more arrays" ); +}); + +test("synchronous request", function() { + expect(1); + ok( /^{ "data"/.test( $.ajax({url: url("data/json_obj.js"), async: false}).responseText ), "check returned text" ); +}); + +test("synchronous request with callbacks", function() { + expect(2); + var result; + $.ajax({url: url("data/json_obj.js"), async: false, success: function(data) { ok(true, "success callback executed"); result = data; } }); + ok( /^{ "data"/.test( result ), "check returned text" ); +}); + +test("pass-through request object", function() { + expect(8); + stop(true); + + var target = "data/name.html"; + var successCount = 0; + var errorCount = 0; + var errorEx = ""; + var success = function() { + successCount++; + }; + $("#foo").ajaxError(function (e, xml, s, ex) { + errorCount++; + errorEx += ": " + xml.status; + }); + $("#foo").one('ajaxStop', function () { + equals(successCount, 5, "Check all ajax calls successful"); + equals(errorCount, 0, "Check no ajax errors (status" + errorEx + ")"); + $("#foo").unbind('ajaxError'); + start(); + }); + + ok( $.get(url(target), success), "get" ); + ok( $.post(url(target), success), "post" ); + ok( $.getScript(url("data/test.js"), success), "script" ); + ok( $.getJSON(url("data/json_obj.js"), success), "json" ); + ok( $.ajax({url: url(target), success: success}), "generic" ); +}); + +/* mozilla: php not currently supported in mochitest (08/08/2008) +test("ajax cache", function () { + expect(18); + stop(); + + var count = 0; + + $("#firstp").bind("ajaxSuccess", function (e, xml, s) { + var re = /_=(.*?)(&|$)/g; + var oldOne = null; + for (var i = 0; i < 6; i++) { + var ret = re.exec(s.url); + if (!ret) { + break; + } + oldOne = ret[1]; + } + equals(i, 1, "Test to make sure only one 'no-cache' parameter is there"); + ok(oldOne != "tobereplaced555", "Test to be sure parameter (if it was there) was replaced"); + if(++count == 6) + start(); + }); + + ok( $.ajax({url: "data/text.php", cache:false}), "test with no parameters" ); + ok( $.ajax({url: "data/text.php?pizza=true", cache:false}), "test with 1 parameter" ); + ok( $.ajax({url: "data/text.php?_=tobereplaced555", cache:false}), "test with _= parameter" ); + ok( $.ajax({url: "data/text.php?pizza=true&_=tobereplaced555", cache:false}), "test with 1 parameter plus _= one" ); + ok( $.ajax({url: "data/text.php?_=tobereplaced555&tv=false", cache:false}), "test with 1 parameter plus _= one before it" ); + ok( $.ajax({url: "data/text.php?name=David&_=tobereplaced555&washere=true", cache:false}), "test with 2 parameters surrounding _= one" ); +}); +*/ + +test("global ajaxSettings", function() { + expect(2); + + var tmp = jQuery.extend({}, jQuery.ajaxSettings); + var orig = { url: "data/with_fries.xml" }; + var t; + + $.ajaxSetup({ data: {foo: 'bar', bar: 'BAR'} }); + + t = jQuery.extend({}, orig); + t.data = {}; + $.ajax(t); + ok( t.url.indexOf('foo') > -1 && t.url.indexOf('bar') > -1, "Check extending {}" ); + + t = jQuery.extend({}, orig); + t.data = { zoo: 'a', ping: 'b' }; + $.ajax(t); + ok( t.url.indexOf('ping') > -1 && t.url.indexOf('zoo') > -1 && t.url.indexOf('foo') > -1 && t.url.indexOf('bar') > -1, "Check extending { zoo: 'a', ping: 'b' }" ); + + jQuery.ajaxSettings = tmp; +}); + +test("load(String)", function() { + expect(1); + stop(true); // check if load can be called with only url + $('#first').load("data/name.html", start); +}); + +test("load('url selector')", function() { + expect(1); + stop(true); // check if load can be called with only url + $('#first').load("data/test3.html div.user", function(){ + equals( $(this).children("div").length, 2, "Verify that specific elements were injected" ); + start(); + }); +}); + +test("load(String, Function) with ajaxSetup on dataType json, see #2046", function() { + expect(1); + stop(); + $.ajaxSetup({ dataType: "json" }); + $("#first").ajaxComplete(function (e, xml, s) { + equals( s.dataType, "html", "Verify the load() dataType was html" ); + $("#first").unbind("ajaxComplete"); + $.ajaxSetup({ dataType: "" }); + start(); + }); + $('#first').load("data/test3.html"); +}); + +test("load(String, Function) - simple: inject text into DOM", function() { + expect(2); + stop(); + $('#first').load(url("data/name.html"), function() { + ok( /^ERROR/.test($('#first').text()), 'Check if content was injected into the DOM' ); + start(); + }); +}); + +test("load(String, Function) - check scripts", function() { + expect(7); + stop(); + window.testFoo = undefined; + window.foobar = null; + var verifyEvaluation = function() { + equals( foobar, "bar", 'Check if script src was evaluated after load' ); + equals( $('#ap').html(), 'bar', 'Check if script evaluation has modified DOM'); + start(); + }; + $('#first').load(url('data/test.html'), function() { + ok( $('#first').html().match(/^html text/), 'Check content after loading html' ); + equals( $('#foo').html(), 'foo', 'Check if script evaluation has modified DOM'); + equals( testFoo, "foo", 'Check if script was evaluated after load' ); + setTimeout(verifyEvaluation, 600); + }); +}); + +test("load(String, Function) - check file with only a script tag", function() { + expect(3); + stop(); + testFoo = undefined; + $('#first').load(url('data/test2.html'), function() { + equals( $('#foo').html(), 'foo', 'Check if script evaluation has modified DOM'); + equals( testFoo, "foo", 'Check if script was evaluated after load' ); + start(); + }); +}); + +test("$.get(String, Hash, Function) - parse xml and use text() on nodes", function() { + expect(2); + stop(); + $.get(url('data/dashboard.xml'), function(xml) { + var content = []; + $('tab', xml).each(function() { + content.push($(this).text()); + }); + equals( content[0], 'blabla', 'Check first tab'); + equals( content[1], 'blublu', 'Check second tab'); + start(); + }); +}); + +test("$.getScript(String, Function) - with callback", function() { + expect(2); + stop(); + window.foobar = null; + $.getScript(url("data/test.js"), function() { + equals( foobar, "bar", 'Check if script was evaluated' ); + setTimeout(start, 100); + }); +}); + +test("$.getScript(String, Function) - no callback", function() { + expect(1); + stop(true); + $.getScript(url("data/test.js"), start); +}); + +/* mozilla: Tests using php scripts not currently supported (06/26/2008) + +test("$.ajax() - JSONP, Local", function() { + expect(7); + + var count = 0; + function plus(){ if ( ++count == 7 ) start(); } + + stop(); + + $.ajax({ + url: "data/jsonp.php", + dataType: "jsonp", + success: function(data){ + ok( data.data, "JSON results returned (GET, no callback)" ); + plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (GET, no callback)" ); + plus(); + } + }); + + $.ajax({ + url: "data/jsonp.php?callback=?", + dataType: "jsonp", + success: function(data){ + ok( data.data, "JSON results returned (GET, url callback)" ); + plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (GET, url callback)" ); + plus(); + } + }); + + $.ajax({ + url: "data/jsonp.php", + dataType: "jsonp", + data: "callback=?", + success: function(data){ + ok( data.data, "JSON results returned (GET, data callback)" ); + plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (GET, data callback)" ); + plus(); + } + }); + + $.ajax({ + url: "data/jsonp.php", + dataType: "jsonp", + jsonp: "callback", + success: function(data){ + ok( data.data, "JSON results returned (GET, data obj callback)" ); + plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (GET, data obj callback)" ); + plus(); + } + }); + + $.ajax({ + type: "POST", + url: "data/jsonp.php", + dataType: "jsonp", + success: function(data){ + ok( data.data, "JSON results returned (POST, no callback)" ); + plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (GET, data obj callback)" ); + plus(); + } + }); + + $.ajax({ + type: "POST", + url: "data/jsonp.php", + data: "callback=?", + dataType: "jsonp", + success: function(data){ + ok( data.data, "JSON results returned (POST, data callback)" ); + plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (POST, data callback)" ); + plus(); + } + }); + + $.ajax({ + type: "POST", + url: "data/jsonp.php", + jsonp: "callback", + dataType: "jsonp", + success: function(data){ + ok( data.data, "JSON results returned (POST, data obj callback)" ); + plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (POST, data obj callback)" ); + plus(); + } + }); +}); + +test("$.ajax() - JSONP, Remote", function() { + expect(4); + + var count = 0; + function plus(){ if ( ++count == 4 ) start(); } + + var base = window.location.href.replace(/\?.*$/, ""); + + stop(); + + $.ajax({ + url: base + "data/jsonp.php", + dataType: "jsonp", + success: function(data){ + ok( data.data, "JSON results returned (GET, no callback)" ); + plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (GET, no callback)" ); + plus(); + } + }); + + $.ajax({ + url: base + "data/jsonp.php?callback=?", + dataType: "jsonp", + success: function(data){ + ok( data.data, "JSON results returned (GET, url callback)" ); + plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (GET, url callback)" ); + plus(); + } + }); + + $.ajax({ + url: base + "data/jsonp.php", + dataType: "jsonp", + data: "callback=?", + success: function(data){ + ok( data.data, "JSON results returned (GET, data callback)" ); + plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (GET, data callback)" ); + plus(); + } + }); + + $.ajax({ + url: base + "data/jsonp.php", + dataType: "jsonp", + jsonp: "callback", + success: function(data){ + ok( data.data, "JSON results returned (GET, data obj callback)" ); + plus(); + }, + error: function(data){ + ok( false, "Ajax error JSON (GET, data obj callback)" ); + plus(); + } + }); +}); + +test("$.ajax() - script, Remote", function() { + expect(2); + + var base = window.location.href.replace(/\?.*$/, ""); + + stop(); + + window.foobar = null; + $.ajax({ + url: base + "data/test.js", + dataType: "script", + success: function(data){ + ok( foobar, "Script results returned (GET, no callback)" ); + start(); + } + }); +}); + +test("$.ajax() - script, Remote with POST", function() { + expect(3); + + var base = window.location.href.replace(/\?.*$/, ""); + + stop(); + + window.foobar = null; + $.ajax({ + url: base + "data/test.js", + type: "POST", + dataType: "script", + success: function(data, status){ + ok( foobar, "Script results returned (GET, no callback)" ); + equals( status, "success", "Script results returned (GET, no callback)" ); + start(); + } + }); +}); + +test("$.ajax() - script, Remote with scheme-less URL", function() { + expect(2); + + var base = window.location.href.replace(/\?.*$/, ""); + base = base.replace(/^.*?\/\//, "//"); + + stop(); + + window.foobar = null; + $.ajax({ + url: base + "data/test.js", + dataType: "script", + success: function(data){ + ok( foobar, "Script results returned (GET, no callback)" ); + start(); + } + }); +}); + +test("$.getJSON(String, Hash, Function) - JSON array", function() { + expect(4); + stop(); + $.getJSON(url("data/json.php"), {json: "array"}, function(json) { + equals( json[0].name, 'John', 'Check JSON: first, name' ); + equals( json[0].age, 21, 'Check JSON: first, age' ); + equals( json[1].name, 'Peter', 'Check JSON: second, name' ); + equals( json[1].age, 25, 'Check JSON: second, age' ); + start(); + }); +}); + +test("$.getJSON(String, Function) - JSON object", function() { + expect(2); + stop(); + $.getJSON(url("data/json.php"), function(json) { + equals( json.data.lang, 'en', 'Check JSON: lang' ); + equals( json.data.length, 25, 'Check JSON: length' ); + start(); + }); +}); + +test("$.getJSON(String, Function) - JSON object with absolute url to local content", function() { + expect(2); + + var base = window.location.href.replace(/\?.*$/, ""); + + stop(); + $.getJSON(url(base + "data/json.php"), function(json) { + equals( json.data.lang, 'en', 'Check JSON: lang' ); + equals( json.data.length, 25, 'Check JSON: length' ); + start(); + }); +}); + +test("$.post(String, Hash, Function) - simple with xml", function() { + expect(4); + stop(); + $.post(url("data/name.php"), {xml: "5-2"}, function(xml){ + $('math', xml).each(function() { + equals( $('calculation', this).text(), '5-2', 'Check for XML' ); + equals( $('result', this).text(), '3', 'Check for XML' ); + }); + }); + + $.post(url("data/name.php?xml=5-2"), {}, function(xml){ + $('math', xml).each(function() { + equals( $('calculation', this).text(), '5-2', 'Check for XML' ); + equals( $('result', this).text(), '3', 'Check for XML' ); + }); + start(); + }); +}); + +test("$.ajaxSetup({timeout: Number}) - with global timeout", function() { + stop(); + + var passed = 0; + + $.ajaxSetup({timeout: 1000}); + + var pass = function() { + passed++; + if ( passed == 2 ) { + ok( true, 'Check local and global callbacks after timeout' ); + $('#main').unbind("ajaxError"); + start(); + } + }; + + var fail = function(a,b,c) { + ok( false, 'Check for timeout failed ' + a + ' ' + b ); + start(); + }; + + $('#main').ajaxError(pass); + + $.ajax({ + type: "GET", + url: url("data/name.php?wait=5"), + error: pass, + success: fail + }); + + // reset timeout + $.ajaxSetup({timeout: 0}); +}); + +test("$.ajaxSetup({timeout: Number}) with localtimeout", function() { + stop(); + $.ajaxSetup({timeout: 50}); + + $.ajax({ + type: "GET", + timeout: 5000, + url: url("data/name.php?wait=1"), + error: function() { + ok( false, 'Check for local timeout failed' ); + start(); + }, + success: function() { + ok( true, 'Check for local timeout' ); + start(); + } + }); + + // reset timeout + $.ajaxSetup({timeout: 0}); +}); + +test("$.ajax - simple get", function() { + expect(1); + stop(); + $.ajax({ + type: "GET", + url: url("data/name.php?name=foo"), + success: function(msg){ + equals( msg, 'bar', 'Check for GET' ); + start(); + } + }); +}); + +test("$.ajax - simple post", function() { + expect(1); + stop(); + $.ajax({ + type: "POST", + url: url("data/name.php"), + data: "name=peter", + success: function(msg){ + equals( msg, 'pan', 'Check for POST' ); + start(); + } + }); +}); + +test("ajaxSetup()", function() { + expect(1); + stop(); + $.ajaxSetup({ + url: url("data/name.php?name=foo"), + success: function(msg){ + equals( msg, 'bar', 'Check for GET' ); + start(); + } + }); + $.ajax(); +}); + +test("custom timeout does not set error message when timeout occurs, see #970", function() { + stop(); + $.ajax({ + url: "data/name.php?wait=10", + timeout: 500, + error: function(request, status) { + ok( status != null, "status shouldn't be null in error handler" ); + equals( "timeout", status ); + start(); + } + }); +}); + +test("data option: evaluate function values (#2806)", function() { + stop(); + $.ajax({ + url: "data/echoQuery.php", + data: { + key: function() { + return "value"; + } + }, + success: function(result) { + equals( result, "key=value" ); + start(); + } + }) +}); +*/ +} + +//} diff --git a/dom/tests/mochitest/ajax/jquery/test/unit/core.js b/dom/tests/mochitest/ajax/jquery/test/unit/core.js new file mode 100644 index 0000000000..74a03192c0 --- /dev/null +++ b/dom/tests/mochitest/ajax/jquery/test/unit/core.js @@ -0,0 +1,1700 @@ +module("core"); + +test("Basic requirements", function() { + expect(7); + ok( Array.prototype.push, "Array.push()" ); + ok( Function.prototype.apply, "Function.apply()" ); + ok( document.getElementById, "getElementById" ); + ok( document.getElementsByTagName, "getElementsByTagName" ); + ok( RegExp, "RegExp" ); + ok( jQuery, "jQuery" ); + ok( $, "$()" ); +}); + +test("$()", function() { + expect(8); + + var main = $("#main"); + isSet( $("div p", main).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" ); + +/* + // disabled since this test was doing nothing. i tried to fix it but i'm not sure + // what the expected behavior should even be. FF returns "\n" for the text node + // make sure this is handled + var crlfContainer = $('

      \r\n

      '); + var x = crlfContainer.contents().get(0).nodeValue; + equals( x, what???, "Check for \\r and \\n in jQuery()" ); +*/ + + /* // Disabled until we add this functionality in + var pass = true; + try { + $("
      Testing
      ").appendTo(document.getElementById("iframe").contentDocument.body); + } catch(e){ + pass = false; + } + ok( pass, "$('<tag>') needs optional document parameter to ease cross-frame DOM wrangling, see #968" );*/ + + var code = $(""); + equals( code.length, 1, "Correct number of elements generated for code" ); + var img = $(""); + equals( img.length, 1, "Correct number of elements generated for img" ); + var div = $("

      "); + equals( div.length, 4, "Correct number of elements generated for div hr code b" ); + + // can actually yield more than one, when iframes are included, the window is an array as well + equals( $(window).length, 1, "Correct number of elements generated for window" ); + + equals( $(document).length, 1, "Correct number of elements generated for document" ); + + equals( $([1,2,3]).get(1), 2, "Test passing an array to the factory" ); + + equals( $(document.body).get(0), $('body').get(0), "Test passing an html node to the factory" ); +}); + +test("browser", function() { + expect(13); + var browsers = { + //Internet Explorer + "Mozilla/5.0 (Windows; U; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)": "6.0", + "Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.1; .NET CLR 1.1.4322; InfoPath.1; .NET CLR 2.0.50727)": "7.0", + /** Failing #1876 + * "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 2.0.50727; .NET CLR 1.1.4322; .NET CLR 3.0.04506.30)": "7.0", + */ + //Browsers with Gecko engine + //Mozilla + "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.12) Gecko/20050915" : "1.7.12", + //Firefox + "Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3": "1.8.1.3", + //Netscape + "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20070321 Netscape/8.1.3" : "1.7.5", + //Flock + "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.11) Gecko/20070321 Firefox/1.5.0.11 Flock/0.7.12" : "1.8.0.11", + //Opera browser + "Opera/9.20 (X11; Linux x86_64; U; en)": "9.20", + "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 9.20" : "9.20", + "Mozilla/5.0 (Windows NT 5.1; U; pl; rv:1.8.0) Gecko/20060728 Firefox/1.5.0 Opera 9.20": "9.20", + //WebKit engine + "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; sv-se) AppleWebKit/418.9 (KHTML, like Gecko) Safari/419.3": "418.9", + "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/418.8 (KHTML, like Gecko) Safari/419.3" : "418.8", + "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; sv-se) AppleWebKit/312.8 (KHTML, like Gecko) Safari/312.5": "312.8", + //Other user agent string + "Other browser's user agent 1.0":null + }; + for (var i in browsers) { + var v = i.toLowerCase().match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ); // RegEx from Core jQuery.browser.version check + version = v ? v[1] : null; + equals( version, browsers[i], "Checking UA string" ); + } +}); + +test("noConflict", function() { + expect(6); + + var old = jQuery; + var newjQuery = jQuery.noConflict(); + + equals( newjQuery, old, "noConflict returned the jQuery object" ); + equals( jQuery, old, "Make sure jQuery wasn't touched." ); + equals( $, "$", "Make sure $ was reverted." ); + + jQuery = $ = old; + + newjQuery = jQuery.noConflict(true); + + equals( newjQuery, old, "noConflict returned the jQuery object" ); + equals( jQuery, "jQuery", "Make sure jQuery was reverted." ); + equals( $, "$", "Make sure $ was reverted." ); + + jQuery = $ = old; +}); + +test("isFunction", function() { + expect(21); + + // Make sure that false values return false + ok( !jQuery.isFunction(), "No Value" ); + ok( !jQuery.isFunction( null ), "null Value" ); + ok( !jQuery.isFunction( undefined ), "undefined Value" ); + ok( !jQuery.isFunction( "" ), "Empty String Value" ); + ok( !jQuery.isFunction( 0 ), "0 Value" ); + + // Check built-ins + // Safari uses "(Internal Function)" + ok( jQuery.isFunction(String), "String Function("+String+")" ); + ok( jQuery.isFunction(Array), "Array Function("+Array+")" ); + ok( jQuery.isFunction(Object), "Object Function("+Object+")" ); + ok( jQuery.isFunction(Function), "Function Function("+Function+")" ); + + // When stringified, this could be misinterpreted + var mystr = "function"; + ok( !jQuery.isFunction(mystr), "Function String" ); + + // When stringified, this could be misinterpreted + var myarr = [ "function" ]; + ok( !jQuery.isFunction(myarr), "Function Array" ); + + // When stringified, this could be misinterpreted + var myfunction = { "function": "test" }; + ok( !jQuery.isFunction(myfunction), "Function Object" ); + + // Make sure normal functions still work + var fn = function(){}; + ok( jQuery.isFunction(fn), "Normal Function" ); + + var obj = document.createElement("object"); + + // Firefox says this is a function + ok( !jQuery.isFunction(obj), "Object Element" ); + + // IE says this is an object + ok( jQuery.isFunction(obj.getAttribute), "getAttribute Function" ); + + var nodes = document.body.childNodes; + + // Safari says this is a function + ok( !jQuery.isFunction(nodes), "childNodes Property" ); + + var first = document.body.firstChild; + + // Normal elements are reported ok everywhere + ok( !jQuery.isFunction(first), "A normal DOM Element" ); + + var input = document.createElement("input"); + input.type = "text"; + document.body.appendChild( input ); + + // IE says this is an object + ok( jQuery.isFunction(input.focus), "A default function property" ); + + document.body.removeChild( input ); + + var a = document.createElement("a"); + a.href = "some-function"; + document.body.appendChild( a ); + + // This serializes with the word 'function' in it + ok( !jQuery.isFunction(a), "Anchor Element" ); + + document.body.removeChild( a ); + + // Recursive function calls have lengths and array-like properties + function callme(callback){ + function fn(response){ + callback(response); + } + + ok( jQuery.isFunction(fn), "Recursive Function Call" ); + + fn({ some: "data" }); + }; + + callme(function(){ + callme(function(){}); + }); +}); + +var foo = false; + +test("$('html')", function() { + expect(6); + + reset(); + foo = false; + var s = $("")[0]; + ok( s, "Creating a script" ); + ok( !foo, "Make sure the script wasn't executed prematurely" ); + $("body").append(s); + ok( foo, "Executing a scripts contents in the right context" ); + + reset(); + ok( $("")[0], "Creating a link" ); + + reset(); + + var j = $("hi there "); + ok( j.length >= 2, "Check node,textnode,comment creation (some browsers delete comments)" ); + + ok( !$("")[0].selected, "Make sure that options are auto-selected #2050" ); +}); + +test("$('html', context)", function() { + expect(1); + + var $div = $("
      "); + var $span = $("", $div); + equals($span.length, 1, "Verify a span created with a div context works, #1763"); +}); + +if ( !isLocal ) { +test("$(selector, xml).text(str) - Loaded via XML document", function() { + expect(2); + stop(); + $.get('data/dashboard.xml', function(xml) { + // tests for #1419 where IE was a problem + equals( $("tab:first", xml).text(), "blabla", "Verify initial text correct" ); + $("tab:first", xml).text("newtext"); + equals( $("tab:first", xml).text(), "newtext", "Verify new text correct" ); + start(); + }); +}); +} + +test("length", function() { + expect(1); + equals( $("p").length, 6, "Get Number of Elements Found" ); +}); + +test("size()", function() { + expect(1); + equals( $("p").size(), 6, "Get Number of Elements Found" ); +}); + +test("get()", function() { + expect(1); + isSet( $("p").get(), q("firstp","ap","sndp","en","sap","first"), "Get All Elements" ); +}); + +test("get(Number)", function() { + expect(1); + equals( $("p").get(0), document.getElementById("firstp"), "Get A Single Element" ); +}); + +test("add(String|Element|Array|undefined)", function() { + expect(12); + isSet( $("#sndp").add("#en").add("#sap").get(), q("sndp", "en", "sap"), "Check elements from document" ); + isSet( $("#sndp").add( $("#en")[0] ).add( $("#sap") ).get(), q("sndp", "en", "sap"), "Check elements from document" ); + ok( $([]).add($("#form")[0].elements).length >= 13, "Check elements from array" ); + + // For the time being, we're discontinuing support for $(form.elements) since it's ambiguous in IE + // use $([]).add(form.elements) instead. + //equals( $([]).add($("#form")[0].elements).length, $($("#form")[0].elements).length, "Array in constructor must equals array in add()" ); + + var x = $([]).add($("

      xxx

      ")).add($("

      xxx

      ")); + equals( x[0].id, "x1", "Check on-the-fly element1" ); + equals( x[1].id, "x2", "Check on-the-fly element2" ); + + var x = $([]).add("

      xxx

      ").add("

      xxx

      "); + equals( x[0].id, "x1", "Check on-the-fly element1" ); + equals( x[1].id, "x2", "Check on-the-fly element2" ); + + var notDefined; + equals( $([]).add(notDefined).length, 0, "Check that undefined adds nothing" ); + + // Added after #2811 + equals( $([]).add([window,document,document.body,document]).length, 3, "Pass an array" ); + equals( $(document).add(document).length, 1, "Check duplicated elements" ); + equals( $(window).add(window).length, 1, "Check duplicated elements using the window" ); + ok( $([]).add( document.getElementById('form') ).length >= 13, "Add a form (adds the elements)" ); +}); + +test("each(Function)", function() { + expect(1); + var div = $("div"); + div.each(function(){this.foo = 'zoo';}); + var pass = true; + for ( var i = 0; i < div.size(); i++ ) { + if ( div.get(i).foo != "zoo" ) pass = false; + } + ok( pass, "Execute a function, Relative" ); +}); + +test("index(Object)", function() { + expect(10); + + var elements = $([window, document]), + inputElements = $('#radio1,#radio2,#check1,#check2'); + + equals( elements.index(window), 0, "Check for index of elements" ); + equals( elements.index(document), 1, "Check for index of elements" ); + equals( inputElements.index(document.getElementById('radio1')), 0, "Check for index of elements" ); + equals( inputElements.index(document.getElementById('radio2')), 1, "Check for index of elements" ); + equals( inputElements.index(document.getElementById('check1')), 2, "Check for index of elements" ); + equals( inputElements.index(document.getElementById('check2')), 3, "Check for index of elements" ); + equals( inputElements.index(window), -1, "Check for not found index" ); + equals( inputElements.index(document), -1, "Check for not found index" ); + + // enabled since [5500] + equals( elements.index( elements ), 0, "Pass in a jQuery object" ); + equals( elements.index( elements.eq(1) ), 1, "Pass in a jQuery object" ); +}); + +test("attr(String)", function() { + expect(29); + equals( $('#text1').attr('value'), "Test", 'Check for value attribute' ); + equals( $('#text1').attr('value', "Test2").attr('defaultValue'), "Test", 'Check for defaultValue attribute' ); + equals( $('#text1').attr('type'), "text", 'Check for type attribute' ); + equals( $('#radio1').attr('type'), "radio", 'Check for type attribute' ); + equals( $('#check1').attr('type'), "checkbox", 'Check for type attribute' ); + equals( $('#simon1').attr('rel'), "bookmark", 'Check for rel attribute' ); + equals( $('#google').attr('title'), "Google!", 'Check for title attribute' ); + equals( $('#mark').attr('hreflang'), "en", 'Check for hreflang attribute' ); + equals( $('#en').attr('lang'), "en", 'Check for lang attribute' ); + equals( $('#simon').attr('class'), "blog link", 'Check for class attribute' ); + equals( $('#name').attr('name'), "name", 'Check for name attribute' ); + equals( $('#text1').attr('name'), "action", 'Check for name attribute' ); + ok( $('#form').attr('action').indexOf("formaction") >= 0, 'Check for action attribute' ); + equals( $('#text1').attr('minlength'), '20', 'Check for minlength attribute' ); + equals( $('#text1').attr('minLength'), '20', 'Check for minLength attribute' ); + equals( $('#area1').attr('minLength'), '20', 'Check for minLength attribute' ); + equals( $('#text1').attr('maxlength'), '30', 'Check for maxlength attribute' ); + equals( $('#text1').attr('maxLength'), '30', 'Check for maxLength attribute' ); + equals( $('#area1').attr('maxLength'), '30', 'Check for maxLength attribute' ); + equals( $('#select2').attr('selectedIndex'), 3, 'Check for selectedIndex attribute' ); + equals( $('#foo').attr('nodeName'), 'DIV', 'Check for nodeName attribute' ); + equals( $('#foo').attr('tagName'), 'DIV', 'Check for tagName attribute' ); + + $('').attr('href', '#5').appendTo('#main'); // using innerHTML in IE causes href attribute to be serialized to the full path + equals( $('#tAnchor5').attr('href'), "#5", 'Check for non-absolute href (an anchor)' ); + + + // Related to [5574] and [5683] + var body = document.body, $body = $(body); + + ok( $body.attr('foo') === undefined, 'Make sure that a non existent attribute returns undefined' ); + ok( $body.attr('nextSibling') === null, 'Make sure a null expando returns null' ); + + body.setAttribute('foo', 'baz'); + equals( $body.attr('foo'), 'baz', 'Make sure the dom attribute is retrieved when no expando is found' ); + + body.foo = 'bar'; + equals( $body.attr('foo'), 'bar', 'Make sure the expando is preferred over the dom attribute' ); + + $body.attr('foo','cool'); + equals( $body.attr('foo'), 'cool', 'Make sure that setting works well when both expando and dom attribute are available' ); + + body.foo = undefined; + ok( $body.attr('foo') === undefined, 'Make sure the expando is preferred over the dom attribute, even if undefined' ); + + body.removeAttribute('foo'); // Cleanup +}); + +if ( !isLocal ) { + test("attr(String) in XML Files", function() { + expect(2); + stop(); + $.get("data/dashboard.xml", function(xml) { + equals( $("locations", xml).attr("class"), "foo", "Check class attribute in XML document" ); + equals( $("location", xml).attr("for"), "bar", "Check for attribute in XML document" ); + start(); + }); + }); +} + +test("attr(String, Function)", function() { + expect(2); + equals( $('#text1').attr('value', function() { return this.id })[0].value, "text1", "Set value from id" ); + equals( $('#text1').attr('title', function(i) { return i }).attr('title'), "0", "Set value with an index"); +}); + +test("attr(Hash)", function() { + expect(1); + var pass = true; + $("div").attr({foo: 'baz', zoo: 'ping'}).each(function(){ + if ( this.getAttribute('foo') != "baz" && this.getAttribute('zoo') != "ping" ) pass = false; + }); + ok( pass, "Set Multiple Attributes" ); +}); + +test("attr(String, Object)", function() { + expect(19); + var div = $("div").attr("foo", "bar"); + fail = false; + for ( var i = 0; i < div.size(); i++ ) { + if ( div.get(i).getAttribute('foo') != "bar" ){ + fail = i; + break; + } + } + equals( fail, false, "Set Attribute, the #"+fail+" element didn't get the attribute 'foo'" ); + + ok( $("#foo").attr({"width": null}), "Try to set an attribute to nothing" ); + + $("#name").attr('name', 'something'); + equals( $("#name").attr('name'), 'something', 'Set name attribute' ); + $("#check2").attr('checked', true); + equals( document.getElementById('check2').checked, true, 'Set checked attribute' ); + $("#check2").attr('checked', false); + equals( document.getElementById('check2').checked, false, 'Set checked attribute' ); + $("#text1").attr('readonly', true); + equals( document.getElementById('text1').readOnly, true, 'Set readonly attribute' ); + $("#text1").attr('readonly', false); + equals( document.getElementById('text1').readOnly, false, 'Set readonly attribute' ); + $("#name").attr('maxlength', '5'); + equals( document.getElementById('name').maxLength, '5', 'Set maxlength attribute' ); + $("#name").attr('maxLength', '10'); + equals( document.getElementById('name').maxLength, '10', 'Set maxlength attribute' ); + $("#name").attr('minlength', '5'); + equals( document.getElementById('name').minLength, '5', 'Set minlength attribute' ); + $("#name").attr('minLength', '10'); + equals( document.getElementById('name').minLength, '10', 'Set minlength attribute' ); + + // for #1070 + $("#name").attr('someAttr', '0'); + equals( $("#name").attr('someAttr'), '0', 'Set attribute to a string of "0"' ); + $("#name").attr('someAttr', 0); + equals( $("#name").attr('someAttr'), 0, 'Set attribute to the number 0' ); + $("#name").attr('someAttr', 1); + equals( $("#name").attr('someAttr'), 1, 'Set attribute to the number 1' ); + + // using contents will get comments regular, text, and comment nodes + var j = $("#nonnodes").contents(); + + j.attr("name", "attrvalue"); + equals( j.attr("name"), "attrvalue", "Check node,textnode,comment for attr" ); + j.removeAttr("name"); + + reset(); + + var type = $("#check2").attr('type'); + var thrown = false; + try { + $("#check2").attr('type','hidden'); + } catch(e) { + thrown = true; + } + ok( thrown, "Exception thrown when trying to change type property" ); + equals( type, $("#check2").attr('type'), "Verify that you can't change the type of an input element" ); + + var check = document.createElement("input"); + var thrown = true; + try { + $(check).attr('type','checkbox'); + } catch(e) { + thrown = false; + } + ok( thrown, "Exception thrown when trying to change type property" ); + equals( "checkbox", $(check).attr('type'), "Verify that you can change the type of an input element that isn't in the DOM" ); +}); + +if ( !isLocal ) { + test("attr(String, Object) - Loaded via XML document", function() { + expect(2); + stop(); + $.get('data/dashboard.xml', function(xml) { + var titles = []; + $('tab', xml).each(function() { + titles.push($(this).attr('title')); + }); + equals( titles[0], 'Location', 'attr() in XML context: Check first title' ); + equals( titles[1], 'Users', 'attr() in XML context: Check second title' ); + start(); + }); + }); +} + +test("css(String|Hash)", function() { + expect(19); + + equals( $('#main').css("display"), 'none', 'Check for css property "display"'); + + ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible'); + $('#foo').css({display: 'none'}); + ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden'); + $('#foo').css({display: 'block'}); + ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible'); + + $('#floatTest').css({styleFloat: 'right'}); + equals( $('#floatTest').css('styleFloat'), 'right', 'Modified CSS float using "styleFloat": Assert float is right'); + $('#floatTest').css({cssFloat: 'left'}); + equals( $('#floatTest').css('cssFloat'), 'left', 'Modified CSS float using "cssFloat": Assert float is left'); + $('#floatTest').css({'float': 'right'}); + equals( $('#floatTest').css('float'), 'right', 'Modified CSS float using "float": Assert float is right'); + $('#floatTest').css({'font-size': '30px'}); + equals( $('#floatTest').css('font-size'), '30px', 'Modified CSS font-size: Assert font-size is 30px'); + + $.each("0,0.25,0.5,0.75,1".split(','), function(i, n) { + $('#foo').css({opacity: n}); + equals( $('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" ); + $('#foo').css({opacity: parseFloat(n)}); + equals( $('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" ); + }); + $('#foo').css({opacity: ''}); + equals( $('#foo').css('opacity'), '1', "Assert opacity is 1 when set to an empty String" ); +}); + +test("css(String, Object)", function() { + expect(21); + ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible'); + $('#foo').css('display', 'none'); + ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden'); + $('#foo').css('display', 'block'); + ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible'); + + $('#floatTest').css('styleFloat', 'left'); + equals( $('#floatTest').css('styleFloat'), 'left', 'Modified CSS float using "styleFloat": Assert float is left'); + $('#floatTest').css('cssFloat', 'right'); + equals( $('#floatTest').css('cssFloat'), 'right', 'Modified CSS float using "cssFloat": Assert float is right'); + $('#floatTest').css('float', 'left'); + equals( $('#floatTest').css('float'), 'left', 'Modified CSS float using "float": Assert float is left'); + $('#floatTest').css('font-size', '20px'); + equals( $('#floatTest').css('font-size'), '20px', 'Modified CSS font-size: Assert font-size is 20px'); + + $.each("0,0.25,0.5,0.75,1".split(','), function(i, n) { + $('#foo').css('opacity', n); + equals( $('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" ); + $('#foo').css('opacity', parseFloat(n)); + equals( $('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" ); + }); + $('#foo').css('opacity', ''); + equals( $('#foo').css('opacity'), '1', "Assert opacity is 1 when set to an empty String" ); + // for #1438, IE throws JS error when filter exists but doesn't have opacity in it + if (jQuery.browser.msie) { + $('#foo').css("filter", "progid:DXImageTransform.Microsoft.Chroma(color='red');"); + } + equals( $('#foo').css('opacity'), '1', "Assert opacity is 1 when a different filter is set in IE, #1438" ); + + // using contents will get comments regular, text, and comment nodes + var j = $("#nonnodes").contents(); + j.css("padding-left", "1px"); + equals( j.css("padding-left"), "1px", "Check node,textnode,comment css works" ); + + // opera sometimes doesn't update 'display' correctly, see #2037 + $("#t2037")[0].innerHTML = $("#t2037")[0].innerHTML + equals( $("#t2037 .hidden").css("display"), "none", "Make sure browser thinks it is hidden" ); +}); + +test("jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", function () { + expect(4); + + var $checkedtest = $("#checkedtest"); + // IE6 was clearing "checked" in jQuery.css(elem, "height"); + jQuery.css($checkedtest[0], "height"); + ok( !! $(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." ); + ok( ! $(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." ); + ok( !! $(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." ); + ok( ! $(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." ); +}); + +test("width()", function() { + expect(9); + + var $div = $("#nothiddendiv"); + $div.width(30); + equals($div.width(), 30, "Test set to 30 correctly"); + $div.width(-1); // handle negative numbers by ignoring #1599 + equals($div.width(), 30, "Test negative width ignored"); + $div.css("padding", "20px"); + equals($div.width(), 30, "Test padding specified with pixels"); + $div.css("border", "2px solid #fff"); + equals($div.width(), 30, "Test border specified with pixels"); + $div.css("padding", "2em"); + equals($div.width(), 30, "Test padding specified with ems"); + $div.css("border", "1em solid #fff"); + equals($div.width(), 30, "Test border specified with ems"); + $div.css("padding", "2%"); + equals($div.width(), 30, "Test padding specified with percent"); + $div.hide(); + equals($div.width(), 30, "Test hidden div"); + + $div.css({ display: "", border: "", padding: "" }); + + $("#nothiddendivchild").css({ padding: "3px", border: "2px solid #fff" }); + equals($("#nothiddendivchild").width(), 20, "Test child width with border and padding"); + $("#nothiddendiv, #nothiddendivchild").css({ border: "", padding: "", width: "" }); +}); + +test("height()", function() { + expect(8); + + var $div = $("#nothiddendiv"); + $div.height(30); + equals($div.height(), 30, "Test set to 30 correctly"); + $div.height(-1); // handle negative numbers by ignoring #1599 + equals($div.height(), 30, "Test negative height ignored"); + $div.css("padding", "20px"); + equals($div.height(), 30, "Test padding specified with pixels"); + $div.css("border", "2px solid #fff"); + equals($div.height(), 30, "Test border specified with pixels"); + $div.css("padding", "2em"); + equals($div.height(), 30, "Test padding specified with ems"); + $div.css("border", "1em solid #fff"); + equals($div.height(), 30, "Test border specified with ems"); + $div.css("padding", "2%"); + equals($div.height(), 30, "Test padding specified with percent"); + $div.hide(); + equals($div.height(), 30, "Test hidden div"); + + $div.css({ display: "", border: "", padding: "", height: "1px" }); +}); + +test("text()", function() { + expect(1); + var expected = "This link has class=\"blog\": Simon Willison's Weblog"; + equals( $('#sap').text(), expected, 'Check for merged text of more then one element.' ); +}); + +test("wrap(String|Element)", function() { + expect(8); + var defaultText = 'Try them out:' + var result = $('#first').wrap('
      ').text(); + equals( defaultText, result, 'Check for wrapping of on-the-fly html' ); + ok( $('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' ); + + reset(); + var defaultText = 'Try them out:' + var result = $('#first').wrap(document.getElementById('empty')).parent(); + ok( result.is('ol'), 'Check for element wrapping' ); + equals( result.text(), defaultText, 'Check for element wrapping' ); + + reset(); + $('#check1').click(function() { + var checkbox = this; + ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" ); + $(checkbox).wrap( '' ); + ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" ); + }).click(); + + // using contents will get comments regular, text, and comment nodes + var j = $("#nonnodes").contents(); + j.wrap(""); + equals( $("#nonnodes > i").length, 3, "Check node,textnode,comment wraps ok" ); + equals( $("#nonnodes > i").text(), j.text() + j[1].nodeValue, "Check node,textnode,comment wraps doesn't hurt text" ); +}); + +test("wrapAll(String|Element)", function() { + expect(8); + var prev = $("#first")[0].previousSibling; + var p = $("#first")[0].parentNode; + var result = $('#first,#firstp').wrapAll('
      '); + equals( result.parent().length, 1, 'Check for wrapping of on-the-fly html' ); + ok( $('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' ); + ok( $('#firstp').parent().parent().is('.red'), 'Check if wrapper has class "red"' ); + equals( $("#first").parent().parent()[0].previousSibling, prev, "Correct Previous Sibling" ); + equals( $("#first").parent().parent()[0].parentNode, p, "Correct Parent" ); + + reset(); + var prev = $("#first")[0].previousSibling; + var p = $("#first")[0].parentNode; + var result = $('#first,#firstp').wrapAll(document.getElementById('empty')); + equals( $("#first").parent()[0], $("#firstp").parent()[0], "Same Parent" ); + equals( $("#first").parent()[0].previousSibling, prev, "Correct Previous Sibling" ); + equals( $("#first").parent()[0].parentNode, p, "Correct Parent" ); +}); + +test("wrapInner(String|Element)", function() { + expect(6); + var num = $("#first").children().length; + var result = $('#first').wrapInner('
      '); + equals( $("#first").children().length, 1, "Only one child" ); + ok( $("#first").children().is(".red"), "Verify Right Element" ); + equals( $("#first").children().children().children().length, num, "Verify Elements Intact" ); + + reset(); + var num = $("#first").children().length; + var result = $('#first').wrapInner(document.getElementById('empty')); + equals( $("#first").children().length, 1, "Only one child" ); + ok( $("#first").children().is("#empty"), "Verify Right Element" ); + equals( $("#first").children().children().length, num, "Verify Elements Intact" ); +}); + +test("append(String|Element|Array<Element>|jQuery)", function() { + expect(21); + var defaultText = 'Try them out:' + var result = $('#first').append('buga'); + equals( result.text(), defaultText + 'buga', 'Check if text appending works' ); + equals( $('#select3').append('').find('option:last-child').attr('value'), 'appendTest', 'Appending html options to select element'); + + reset(); + var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:"; + $('#sap').append(document.getElementById('first')); + equals( expected, $('#sap').text(), "Check for appending of element" ); + + reset(); + expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo"; + $('#sap').append([document.getElementById('first'), document.getElementById('yahoo')]); + equals( expected, $('#sap').text(), "Check for appending of array of elements" ); + + reset(); + expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo"; + $('#sap').append($("#first, #yahoo")); + equals( expected, $('#sap').text(), "Check for appending of jQuery object" ); + + reset(); + $("#sap").append( 5 ); + ok( $("#sap")[0].innerHTML.match( /5$/ ), "Check for appending a number" ); + + reset(); + $("#sap").append( " text with spaces " ); + ok( $("#sap")[0].innerHTML.match(/ text with spaces $/), "Check for appending text with spaces" ); + + reset(); + ok( $("#sap").append([]), "Check for appending an empty array." ); + ok( $("#sap").append(""), "Check for appending an empty string." ); + ok( $("#sap").append(document.getElementsByTagName("foo")), "Check for appending an empty nodelist." ); + + reset(); + $("#sap").append(document.getElementById('form')); + equals( $("#sap>form").size(), 1, "Check for appending a form" ); // Bug #910 + + reset(); + var pass = true; + try { + $( $("#iframe")[0].contentWindow.document.body ).append("
      test
      "); + } catch(e) { + pass = false; + } + + ok( pass, "Test for appending a DOM node to the contents of an IFrame" ); + + reset(); + $('
      ').appendTo('#form').append('test'); + t( 'Append legend', '#legend', ['legend'] ); + + reset(); + $('#select1').append(''); + equals( $('#select1 option:last').text(), "Test", "Appending <OPTION> (all caps)" ); + + $('#table').append(''); + ok( $('#table colgroup').length, "Append colgroup" ); + + $('#table colgroup').append(''); + ok( $('#table colgroup col').length, "Append col" ); + + reset(); + $('#table').append(''); + ok( $('#table caption').length, "Append caption" ); + + reset(); + $('form:last') + .append('') + .append(''); + + t( "Append Select", "#appendSelect1, #appendSelect2", ["appendSelect1", "appendSelect2"] ); + + // using contents will get comments regular, text, and comment nodes + var j = $("#nonnodes").contents(); + var d = $("
      ").appendTo("#nonnodes").append(j); + equals( $("#nonnodes").length, 1, "Check node,textnode,comment append moved leaving just the div" ); + ok( d.contents().length >= 2, "Check node,textnode,comment append works" ); + d.contents().appendTo("#nonnodes"); + d.remove(); + ok( $("#nonnodes").contents().length >= 2, "Check node,textnode,comment append cleanup worked" ); +}); + +test("appendTo(String|Element|Array<Element>|jQuery)", function() { + expect(6); + var defaultText = 'Try them out:' + $('buga').appendTo('#first'); + equals( $("#first").text(), defaultText + 'buga', 'Check if text appending works' ); + equals( $('').appendTo('#select3').parent().find('option:last-child').attr('value'), 'appendTest', 'Appending html options to select element'); + + reset(); + var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:"; + $(document.getElementById('first')).appendTo('#sap'); + equals( expected, $('#sap').text(), "Check for appending of element" ); + + reset(); + expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo"; + $([document.getElementById('first'), document.getElementById('yahoo')]).appendTo('#sap'); + equals( expected, $('#sap').text(), "Check for appending of array of elements" ); + + reset(); + expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo"; + $("#first, #yahoo").appendTo('#sap'); + equals( expected, $('#sap').text(), "Check for appending of jQuery object" ); + + reset(); + $('#select1').appendTo('#foo'); + t( 'Append select', '#foo select', ['select1'] ); +}); + +test("prepend(String|Element|Array<Element>|jQuery)", function() { + expect(5); + var defaultText = 'Try them out:' + var result = $('#first').prepend('buga'); + equals( result.text(), 'buga' + defaultText, 'Check if text prepending works' ); + equals( $('#select3').prepend('').find('option:first-child').attr('value'), 'prependTest', 'Prepending html options to select element'); + + reset(); + var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog"; + $('#sap').prepend(document.getElementById('first')); + equals( expected, $('#sap').text(), "Check for prepending of element" ); + + reset(); + expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog"; + $('#sap').prepend([document.getElementById('first'), document.getElementById('yahoo')]); + equals( expected, $('#sap').text(), "Check for prepending of array of elements" ); + + reset(); + expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog"; + $('#sap').prepend($("#first, #yahoo")); + equals( expected, $('#sap').text(), "Check for prepending of jQuery object" ); +}); + +test("prependTo(String|Element|Array<Element>|jQuery)", function() { + expect(6); + var defaultText = 'Try them out:' + $('buga').prependTo('#first'); + equals( $('#first').text(), 'buga' + defaultText, 'Check if text prepending works' ); + equals( $('').prependTo('#select3').parent().find('option:first-child').attr('value'), 'prependTest', 'Prepending html options to select element'); + + reset(); + var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog"; + $(document.getElementById('first')).prependTo('#sap'); + equals( expected, $('#sap').text(), "Check for prepending of element" ); + + reset(); + expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog"; + $([document.getElementById('yahoo'), document.getElementById('first')]).prependTo('#sap'); + equals( expected, $('#sap').text(), "Check for prepending of array of elements" ); + + reset(); + expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog"; + $("#yahoo, #first").prependTo('#sap'); + equals( expected, $('#sap').text(), "Check for prepending of jQuery object" ); + + reset(); + $('').prependTo('form:last'); + $('').prependTo('form:last'); + + t( "Prepend Select", "#prependSelect1, #prependSelect2", ["prependSelect1", "prependSelect2"] ); +}); + +test("before(String|Element|Array<Element>|jQuery)", function() { + expect(4); + var expected = 'This is a normal link: bugaYahoo'; + $('#yahoo').before('buga'); + equals( expected, $('#en').text(), 'Insert String before' ); + + reset(); + expected = "This is a normal link: Try them out:Yahoo"; + $('#yahoo').before(document.getElementById('first')); + equals( expected, $('#en').text(), "Insert element before" ); + + reset(); + expected = "This is a normal link: Try them out:diveintomarkYahoo"; + $('#yahoo').before([document.getElementById('first'), document.getElementById('mark')]); + equals( expected, $('#en').text(), "Insert array of elements before" ); + + reset(); + expected = "This is a normal link: Try them out:diveintomarkYahoo"; + $('#yahoo').before($("#first, #mark")); + equals( expected, $('#en').text(), "Insert jQuery before" ); +}); + +test("insertBefore(String|Element|Array<Element>|jQuery)", function() { + expect(4); + var expected = 'This is a normal link: bugaYahoo'; + $('buga').insertBefore('#yahoo'); + equals( expected, $('#en').text(), 'Insert String before' ); + + reset(); + expected = "This is a normal link: Try them out:Yahoo"; + $(document.getElementById('first')).insertBefore('#yahoo'); + equals( expected, $('#en').text(), "Insert element before" ); + + reset(); + expected = "This is a normal link: Try them out:diveintomarkYahoo"; + $([document.getElementById('first'), document.getElementById('mark')]).insertBefore('#yahoo'); + equals( expected, $('#en').text(), "Insert array of elements before" ); + + reset(); + expected = "This is a normal link: Try them out:diveintomarkYahoo"; + $("#first, #mark").insertBefore('#yahoo'); + equals( expected, $('#en').text(), "Insert jQuery before" ); +}); + +test("after(String|Element|Array<Element>|jQuery)", function() { + expect(4); + var expected = 'This is a normal link: Yahoobuga'; + $('#yahoo').after('buga'); + equals( expected, $('#en').text(), 'Insert String after' ); + + reset(); + expected = "This is a normal link: YahooTry them out:"; + $('#yahoo').after(document.getElementById('first')); + equals( expected, $('#en').text(), "Insert element after" ); + + reset(); + expected = "This is a normal link: YahooTry them out:diveintomark"; + $('#yahoo').after([document.getElementById('first'), document.getElementById('mark')]); + equals( expected, $('#en').text(), "Insert array of elements after" ); + + reset(); + expected = "This is a normal link: YahooTry them out:diveintomark"; + $('#yahoo').after($("#first, #mark")); + equals( expected, $('#en').text(), "Insert jQuery after" ); +}); + +test("insertAfter(String|Element|Array<Element>|jQuery)", function() { + expect(4); + var expected = 'This is a normal link: Yahoobuga'; + $('buga').insertAfter('#yahoo'); + equals( expected, $('#en').text(), 'Insert String after' ); + + reset(); + expected = "This is a normal link: YahooTry them out:"; + $(document.getElementById('first')).insertAfter('#yahoo'); + equals( expected, $('#en').text(), "Insert element after" ); + + reset(); + expected = "This is a normal link: YahooTry them out:diveintomark"; + $([document.getElementById('mark'), document.getElementById('first')]).insertAfter('#yahoo'); + equals( expected, $('#en').text(), "Insert array of elements after" ); + + reset(); + expected = "This is a normal link: YahooTry them out:diveintomark"; + $("#mark, #first").insertAfter('#yahoo'); + equals( expected, $('#en').text(), "Insert jQuery after" ); +}); + +test("replaceWith(String|Element|Array<Element>|jQuery)", function() { + expect(10); + $('#yahoo').replaceWith('buga'); + ok( $("#replace")[0], 'Replace element with string' ); + ok( !$("#yahoo")[0], 'Verify that original element is gone, after string' ); + + reset(); + $('#yahoo').replaceWith(document.getElementById('first')); + ok( $("#first")[0], 'Replace element with element' ); + ok( !$("#yahoo")[0], 'Verify that original element is gone, after element' ); + + reset(); + $('#yahoo').replaceWith([document.getElementById('first'), document.getElementById('mark')]); + ok( $("#first")[0], 'Replace element with array of elements' ); + ok( $("#mark")[0], 'Replace element with array of elements' ); + ok( !$("#yahoo")[0], 'Verify that original element is gone, after array of elements' ); + + reset(); + $('#yahoo').replaceWith($("#first, #mark")); + ok( $("#first")[0], 'Replace element with set of elements' ); + ok( $("#mark")[0], 'Replace element with set of elements' ); + ok( !$("#yahoo")[0], 'Verify that original element is gone, after set of elements' ); +}); + +test("replaceAll(String|Element|Array<Element>|jQuery)", function() { + expect(10); + $('buga').replaceAll("#yahoo"); + ok( $("#replace")[0], 'Replace element with string' ); + ok( !$("#yahoo")[0], 'Verify that original element is gone, after string' ); + + reset(); + $(document.getElementById('first')).replaceAll("#yahoo"); + ok( $("#first")[0], 'Replace element with element' ); + ok( !$("#yahoo")[0], 'Verify that original element is gone, after element' ); + + reset(); + $([document.getElementById('first'), document.getElementById('mark')]).replaceAll("#yahoo"); + ok( $("#first")[0], 'Replace element with array of elements' ); + ok( $("#mark")[0], 'Replace element with array of elements' ); + ok( !$("#yahoo")[0], 'Verify that original element is gone, after array of elements' ); + + reset(); + $("#first, #mark").replaceAll("#yahoo"); + ok( $("#first")[0], 'Replace element with set of elements' ); + ok( $("#mark")[0], 'Replace element with set of elements' ); + ok( !$("#yahoo")[0], 'Verify that original element is gone, after set of elements' ); +}); + +test("end()", function() { + expect(3); + equals( 'Yahoo', $('#yahoo').parent().end().text(), 'Check for end' ); + ok( $('#yahoo').end(), 'Check for end with nothing to end' ); + + var x = $('#yahoo'); + x.parent(); + equals( 'Yahoo', $('#yahoo').text(), 'Check for non-destructive behaviour' ); +}); + +test("find(String)", function() { + expect(2); + equals( 'Yahoo', $('#foo').find('.blogTest').text(), 'Check for find' ); + + // using contents will get comments regular, text, and comment nodes + var j = $("#nonnodes").contents(); + equals( j.find("div").length, 0, "Check node,textnode,comment to find zero divs" ); +}); + +test("clone()", function() { + expect(20); + equals( 'This is a normal link: Yahoo', $('#en').text(), 'Assert text for #en' ); + var clone = $('#yahoo').clone(); + equals( 'Try them out:Yahoo', $('#first').append(clone).text(), 'Check for clone' ); + equals( 'This is a normal link: Yahoo', $('#en').text(), 'Reassert text for #en' ); + + var cloneTags = [ + "", "", "
      ", "
      ", + "