From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- dom/tests/mochitest/ajax/jquery/ChangeLog.txt | 98 + dom/tests/mochitest/ajax/jquery/GPL-LICENSE.txt | 278 ++ dom/tests/mochitest/ajax/jquery/MIT-LICENSE.txt | 20 + dom/tests/mochitest/ajax/jquery/dist/jquery.js | 3549 ++++++++++++++++++++ dom/tests/mochitest/ajax/jquery/manifest.json | 1 + dom/tests/mochitest/ajax/jquery/mochitest.toml | 38 + 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 ++ dom/tests/mochitest/ajax/jquery/test_jQuery.html | 24 + dom/tests/mochitest/ajax/jquery/version.txt | 1 + 38 files changed, 8838 insertions(+) create mode 100644 dom/tests/mochitest/ajax/jquery/ChangeLog.txt create mode 100644 dom/tests/mochitest/ajax/jquery/GPL-LICENSE.txt create mode 100644 dom/tests/mochitest/ajax/jquery/MIT-LICENSE.txt create mode 100644 dom/tests/mochitest/ajax/jquery/dist/jquery.js create mode 100644 dom/tests/mochitest/ajax/jquery/manifest.json create mode 100644 dom/tests/mochitest/ajax/jquery/mochitest.toml 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 create mode 100644 dom/tests/mochitest/ajax/jquery/test_jQuery.html create mode 100644 dom/tests/mochitest/ajax/jquery/version.txt (limited to 'dom/tests/mochitest/ajax/jquery') diff --git a/dom/tests/mochitest/ajax/jquery/ChangeLog.txt b/dom/tests/mochitest/ajax/jquery/ChangeLog.txt new file mode 100644 index 0000000000..6d834c1967 --- /dev/null +++ b/dom/tests/mochitest/ajax/jquery/ChangeLog.txt @@ -0,0 +1,98 @@ +== jQuery ChangeLog == + +== 1.2.2 == + +* show is now element aware (uses default display type instead of just forcing block) +* New special events api: jQuery.events.special +* ready is now a real event and can be bound, unbound and triggered. +* mouseenter and mouseleave now work on all supported browsers +* The hover helper method now uses the mouseenter and mouseleave events +* New offset test suite test/offset.html (requires your pop-up blocker to be disabled) +* Refactored the width and height methods (fixes lots of bugs) +* Fixed event memory leaks in IE (html, remove, empty also no longer leak memory) +* Fixed window/document width/height values +* Fixed event.pageX and event.pageY in IE + +== 1.2 == + +=== 1.1.3 === +* Always create an ActiveXObject when it is available instead of the XMLHttpRequest, even in IE7 +* Removed XMLHttpRequest shadowing, may break code that relies on existence of that function for browser checking +* ... + +=== 1.1.2 === + +* Event handlers (like element.onclick) are now removed when no more functions are bound to the event. +* Fixed DOM Manipulations for form elements. +* Fixed jQuery.isFunction to return false on nodes. +* Fixed jQuery.className.has, escaping regex characters in className (for metadata) +* Fixed an issue in IE where an event on a cloned element is fired during a .clone() inside of an event handler. +* Fixed IE ID selectors selecting by the name attribute. +* Change: Events are now internally stored in elem.$events rather than elem.events (due to a nasty bug relating to DOM 0 expandos). +* .attr('href') is now consistent in all browsers. +* @href is now consistent in all browsers. +* Fixed the slideDown flickering bug. +* Having a \r endline in $("...") caused a never-ending loop. +* Fixed IE6 AJAX memory leak +* Fixed bug in pushStack, reporting an element at [0] in a jQuery object with length 0 + +=== 1.1.1 === + +* Setting the numerical value of a css property failed, for example: .css("opacity",0.5) (also occurred with zIndex, fontWeight) +* Calling $(..., jqobj) with a context of a jQuery object failed. +* Accessing a property on an element that doesn't exist caused an error, for example: $("#foobar").attr("id") +* Calling .load() without a callback caused an error. +* You couldn't cancel an event that was triggered using .trigger() or .click() (for example). +* .add()ing a single DOM element to a jQuery object was broken. +* Passing in undefined values to a $.post() caused weird errors to occur. +* Accessing child nodes within an xml document didn't work properly. +* jQuery.isFunction() was unable to reliably determine a function, in a cross-browser way. +* Triggering a .click() failed in IE. +* Triggered click handlers were executed twice in most browsers. +* A newline passed into $(...) caused Firefox to go into a never-ending loop. +* Calling $.post() without any data caused an error. +* Calling a descendant selector after a child selector caused strange results, for example: $("ul > li ul") +* Triggered events did not occur if an event handler was not bound for that event. + +== 1.1 == + +* Massive speed-ups (4x-10x) in the selector engine. +* You can now unbind event handlers from within themselves +* Added new .one( "type", fn ) method +* text(String) now escapes HTML +* Added attr(String,Function) to calculate the value +* Performming .click(), .blur(), .focus(), .submit() will actually trigger the browsers default action for those events. +* Added global settings for AJAX (in addition to timeout), use $.ajaxSetup() to modify them +* Implemented a better error handling for ajax requests. Exceptions caused by dropping connections are now handled, too. +* Improved event fixing (Opera provides event.srcElement, must ignore it if target is available; only create pageX if clientX is available) +* Fixed nth-child selectors to start on the right number +* jQuery is no longer destructive. Doing var a = $("a"); a.find("span"); does not change the original "a" variable. +* Fixed synchronous requests +* Fixed ID with context selectors (eg. div #id doesn't ignore "div" anymore) +* Fixed docs for html(): Now mentions that is not available for XML documents +* Improved AJAX docs (eg. more examples for $.ajax) +* Documented filter(Function), a very powerful approach for custom filtering +* Improved docs for FX module, merging method descriptions and marking optional arguments +* Improved docs for append, prepend, before and after, merging the three pairs into one +* Improved show/hide animations to show only hidden and hide only visible elements +* Removed .oneEvent() and .unEvent() helper methods. +* Removed all CSS helper methods. +* Removed most attribute helper methods. +* Removed the (undocumented) .find( "selector", fn ) for all destructive methods. +* $.get, $.getIfModified, $.post, $.getScript and $.getJSON now all pass through the XMLHttpRequest as returned by $.ajax + +== 1.0.4 == + +* Tons of bug fixes +* Extensions to $.ajax: $.ajax accepts additonal options: beforeSend, async and processData; returns XMLHttpRequest to allow manual aborting of requests, see docs for details +* AJAX module: the public $.ajax API is now used internally (for $.get/$.post etc.); loading scripts works now much more reliable on all browers except Safari +* New global ajax handler: ajaxSend - called before an ajax request is sent +* Extensions to global ajax handlers: ajaxSend, ajaxSuccess, ajaxError and ajaxComplete get XMLHttpRequest and settings passed as arguments +* Extensions to event handling: pageX and pageY are available x-browser (IE does not provide native pageX/Y) +* Improved docs: $(String) method has now two seperate descriptions, one for selecting elements, one for creating (html on-the-fly) +* FX module: Most inline stlyes added by animations are now removed when the animation is complete, eg. height style when animating height (exception: display styles) +* Added note to attr(String, Object) about issues with setting the name property on input elements +* Seperated internal stuff from get() into set() +* Merged the two API examples for each() into one more precise example +* Improved docs for $.browser and added docs for $.boxModel +* Docs for the jQuery constructor $() were improved: There is now $(String expression[, Object context]) and $(String html) diff --git a/dom/tests/mochitest/ajax/jquery/GPL-LICENSE.txt b/dom/tests/mochitest/ajax/jquery/GPL-LICENSE.txt new file mode 100644 index 0000000000..11dddd00ef --- /dev/null +++ b/dom/tests/mochitest/ajax/jquery/GPL-LICENSE.txt @@ -0,0 +1,278 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. diff --git a/dom/tests/mochitest/ajax/jquery/MIT-LICENSE.txt b/dom/tests/mochitest/ajax/jquery/MIT-LICENSE.txt new file mode 100644 index 0000000000..d4215f0e42 --- /dev/null +++ b/dom/tests/mochitest/ajax/jquery/MIT-LICENSE.txt @@ -0,0 +1,20 @@ +Copyright (c) 2008 John Resig, http://jquery.com/ + +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. diff --git a/dom/tests/mochitest/ajax/jquery/dist/jquery.js b/dom/tests/mochitest/ajax/jquery/dist/jquery.js new file mode 100644 index 0000000000..a28e7cd65c --- /dev/null +++ b/dom/tests/mochitest/ajax/jquery/dist/jquery.js @@ -0,0 +1,3549 @@ +(function(){ +/* + * jQuery 1.2.6 - New Wave Javascript + * + * Copyright (c) 2008 John Resig (jquery.com) + * Dual licensed under the MIT (MIT-LICENSE.txt) + * and GPL (GPL-LICENSE.txt) licenses. + * + * $Date: 2008-05-24 11:09:21 -0700 (Sat, 24 May 2008) $ + * $Rev: 5683 $ + */ + +// Map over jQuery in case of overwrite +var _jQuery = window.jQuery, +// Map over the $ in case of overwrite + _$ = window.$; + +var jQuery = window.jQuery = window.$ = function( selector, context ) { + // The jQuery object is actually just the init constructor 'enhanced' + return new jQuery.fn.init( selector, context ); +}; + +// A simple way to check for HTML strings or ID strings +// (both of which we optimize for) +var quickExpr = /^[^<]*(<(.|\s)+>)[^>]*$|^#(\w+)$/, + +// Is it a simple selector + isSimple = /^.[^:#\[\.]*$/, + +// Will speed up references to undefined, and allows munging its name. + undefined; + +jQuery.fn = jQuery.prototype = { + init: function( selector, context ) { + // Make sure that a selection was provided + selector = selector || document; + + // Handle $(DOMElement) + if ( selector.nodeType ) { + this[0] = selector; + this.length = 1; + return this; + } + // Handle HTML strings + if ( typeof selector == "string" ) { + // Are we dealing with HTML string or an ID? + var match = quickExpr.exec( selector ); + + // Verify a match, and that no context was specified for #id + if ( match && (match[1] || !context) ) { + + // HANDLE: $(html) -> $(array) + if ( match[1] ) + selector = jQuery.clean( [ match[1] ], context ); + + // HANDLE: $("#id") + else { + var elem = document.getElementById( match[3] ); + + // Make sure an element was located + if ( elem ){ + // Handle the case where IE and Opera return items + // by name instead of ID + if ( elem.id != match[3] ) + return jQuery().find( selector ); + + // Otherwise, we inject the element directly into the jQuery object + return jQuery( elem ); + } + selector = []; + } + + // HANDLE: $(expr, [context]) + // (which is just equivalent to: $(content).find(expr) + } else + return jQuery( context ).find( selector ); + + // HANDLE: $(function) + // Shortcut for document ready + } else if ( jQuery.isFunction( selector ) ) + return jQuery( document )[ jQuery.fn.ready ? "ready" : "load" ]( selector ); + + return this.setArray(jQuery.makeArray(selector)); + }, + + // The current version of jQuery being used + jquery: "1.2.6", + + // The number of elements contained in the matched element set + size: function() { + return this.length; + }, + + // The number of elements contained in the matched element set + length: 0, + + // Get the Nth element in the matched element set OR + // Get the whole matched element set as a clean array + get: function( num ) { + return num == undefined ? + + // Return a 'clean' array + jQuery.makeArray( this ) : + + // Return just the object + this[ num ]; + }, + + // Take an array of elements and push it onto the stack + // (returning the new matched element set) + pushStack: function( elems ) { + // Build a new jQuery matched element set + var ret = jQuery( elems ); + + // Add the old object onto the stack (as a reference) + ret.prevObject = this; + + // Return the newly-formed element set + return ret; + }, + + // Force the current matched set of elements to become + // the specified array of elements (destroying the stack in the process) + // You should use pushStack() in order to do this, but maintain the stack + setArray: function( elems ) { + // Resetting the length to 0, then using the native Array push + // is a super-fast way to populate an object with array-like properties + this.length = 0; + Array.prototype.push.apply( this, elems ); + + return this; + }, + + // Execute a callback for every element in the matched set. + // (You can seed the arguments with an array of args, but this is + // only used internally.) + each: function( callback, args ) { + return jQuery.each( this, callback, args ); + }, + + // Determine the position of an element within + // the matched set of elements + index: function( elem ) { + var ret = -1; + + // Locate the position of the desired element + return jQuery.inArray( + // If it receives a jQuery object, the first element is used + elem && elem.jquery ? elem[0] : elem + , this ); + }, + + attr: function( name, value, type ) { + var options = name; + + // Look for the case where we're accessing a style value + if ( name.constructor == String ) + if ( value === undefined ) + return this[0] && jQuery[ type || "attr" ]( this[0], name ); + + else { + options = {}; + options[ name ] = value; + } + + // Check to see if we're setting style values + return this.each(function(i){ + // Set all the styles + for ( name in options ) + jQuery.attr( + type ? + this.style : + this, + name, jQuery.prop( this, options[ name ], type, i, name ) + ); + }); + }, + + css: function( key, value ) { + // ignore negative width and height values + if ( (key == 'width' || key == 'height') && parseFloat(value) < 0 ) + value = undefined; + return this.attr( key, value, "curCSS" ); + }, + + text: function( text ) { + if ( typeof text != "object" && text != null ) + return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) ); + + var ret = ""; + + jQuery.each( text || this, function(){ + jQuery.each( this.childNodes, function(){ + if ( this.nodeType != 8 ) + ret += this.nodeType != 1 ? + this.nodeValue : + jQuery.fn.text( [ this ] ); + }); + }); + + return ret; + }, + + wrapAll: function( html ) { + if ( this[0] ) + // The elements to wrap the target around + jQuery( html, this[0].ownerDocument ) + .clone() + .insertBefore( this[0] ) + .map(function(){ + var elem = this; + + while ( elem.firstChild ) + elem = elem.firstChild; + + return elem; + }) + .append(this); + + return this; + }, + + wrapInner: function( html ) { + return this.each(function(){ + jQuery( this ).contents().wrapAll( html ); + }); + }, + + wrap: function( html ) { + return this.each(function(){ + jQuery( this ).wrapAll( html ); + }); + }, + + append: function() { + return this.domManip(arguments, true, false, function(elem){ + if (this.nodeType == 1) + this.appendChild( elem ); + }); + }, + + prepend: function() { + return this.domManip(arguments, true, true, function(elem){ + if (this.nodeType == 1) + this.insertBefore( elem, this.firstChild ); + }); + }, + + before: function() { + return this.domManip(arguments, false, false, function(elem){ + this.parentNode.insertBefore( elem, this ); + }); + }, + + after: function() { + return this.domManip(arguments, false, true, function(elem){ + this.parentNode.insertBefore( elem, this.nextSibling ); + }); + }, + + end: function() { + return this.prevObject || jQuery( [] ); + }, + + find: function( selector ) { + var elems = jQuery.map(this, function(elem){ + return jQuery.find( selector, elem ); + }); + + return this.pushStack( /[^+>] [^+>]/.test( selector ) || selector.indexOf("..") > -1 ? + jQuery.unique( elems ) : + elems ); + }, + + clone: function( events ) { + // Do the clone + var ret = this.map(function(){ + if ( jQuery.browser.msie && !jQuery.isXMLDoc(this) ) { + // IE copies events bound via attachEvent when + // using cloneNode. Calling detachEvent on the + // clone will also remove the events from the orignal + // In order to get around this, we use innerHTML. + // Unfortunately, this means some modifications to + // attributes in IE that are actually only stored + // as properties will not be copied (such as the + // the name attribute on an input). + var clone = this.cloneNode(true), + container = document.createElement("div"); + container.appendChild(clone); + return jQuery.clean([container.innerHTML])[0]; + } else + return this.cloneNode(true); + }); + + // Need to set the expando to null on the cloned set if it exists + // removeData doesn't work here, IE removes it from the original as well + // this is primarily for IE but the data expando shouldn't be copied over in any browser + var clone = ret.find("*").andSelf().each(function(){ + if ( this[ expando ] != undefined ) + this[ expando ] = null; + }); + + // Copy the events from the original to the clone + if ( events === true ) + this.find("*").andSelf().each(function(i){ + if (this.nodeType == 3) + return; + var events = jQuery.data( this, "events" ); + + for ( var type in events ) + for ( var handler in events[ type ] ) + jQuery.event.add( clone[ i ], type, events[ type ][ handler ], events[ type ][ handler ].data ); + }); + + // Return the cloned set + return ret; + }, + + filter: function( selector ) { + return this.pushStack( + jQuery.isFunction( selector ) && + jQuery.grep(this, function(elem, i){ + return selector.call( elem, i ); + }) || + + jQuery.multiFilter( selector, this ) ); + }, + + not: function( selector ) { + if ( selector.constructor == String ) + // test special case where just one selector is passed in + if ( isSimple.test( selector ) ) + return this.pushStack( jQuery.multiFilter( selector, this, true ) ); + else + selector = jQuery.multiFilter( selector, this ); + + var isArrayLike = selector.length && selector[selector.length - 1] !== undefined && !selector.nodeType; + return this.filter(function() { + return isArrayLike ? jQuery.inArray( this, selector ) < 0 : this != selector; + }); + }, + + add: function( selector ) { + return this.pushStack( jQuery.unique( jQuery.merge( + this.get(), + typeof selector == 'string' ? + jQuery( selector ) : + jQuery.makeArray( selector ) + ))); + }, + + is: function( selector ) { + return !!selector && jQuery.multiFilter( selector, this ).length > 0; + }, + + hasClass: function( selector ) { + return this.is( "." + selector ); + }, + + val: function( value ) { + if ( value == undefined ) { + + if ( this.length ) { + var elem = this[0]; + + // We need to handle select boxes special + if ( jQuery.nodeName( elem, "select" ) ) { + var index = elem.selectedIndex, + values = [], + options = elem.options, + one = elem.type == "select-one"; + + // Nothing was selected + if ( index < 0 ) + return null; + + // Loop through all the selected options + for ( var i = one ? index : 0, max = one ? index + 1 : options.length; i < max; i++ ) { + var option = options[ i ]; + + if ( option.selected ) { + // Get the specifc value for the option + value = jQuery.browser.msie && !option.attributes.value.specified ? option.text : option.value; + + // We don't need an array for one selects + if ( one ) + return value; + + // Multi-Selects return an array + values.push( value ); + } + } + + return values; + + // Everything else, we just grab the value + } else + return (this[0].value || "").replace(/\r/g, ""); + + } + + return undefined; + } + + if( value.constructor == Number ) + value += ''; + + return this.each(function(){ + if ( this.nodeType != 1 ) + return; + + if ( value.constructor == Array && /radio|checkbox/.test( this.type ) ) + this.checked = (jQuery.inArray(this.value, value) >= 0 || + jQuery.inArray(this.name, value) >= 0); + + else if ( jQuery.nodeName( this, "select" ) ) { + var values = jQuery.makeArray(value); + + jQuery( "option", this ).each(function(){ + this.selected = (jQuery.inArray( this.value, values ) >= 0 || + jQuery.inArray( this.text, values ) >= 0); + }); + + if ( !values.length ) + this.selectedIndex = -1; + + } else + this.value = value; + }); + }, + + html: function( value ) { + return value == undefined ? + (this[0] ? + this[0].innerHTML : + null) : + this.empty().append( value ); + }, + + replaceWith: function( value ) { + return this.after( value ).remove(); + }, + + eq: function( i ) { + return this.slice( i, i + 1 ); + }, + + slice: function() { + return this.pushStack( Array.prototype.slice.apply( this, arguments ) ); + }, + + map: function( callback ) { + return this.pushStack( jQuery.map(this, function(elem, i){ + return callback.call( elem, i, elem ); + })); + }, + + andSelf: function() { + return this.add( this.prevObject ); + }, + + data: function( key, value ){ + var parts = key.split("."); + parts[1] = parts[1] ? "." + parts[1] : ""; + + if ( value === undefined ) { + var data = this.triggerHandler("getData" + parts[1] + "!", [parts[0]]); + + if ( data === undefined && this.length ) + data = jQuery.data( this[0], key ); + + return data === undefined && parts[1] ? + this.data( parts[0] ) : + data; + } else + return this.trigger("setData" + parts[1] + "!", [parts[0], value]).each(function(){ + jQuery.data( this, key, value ); + }); + }, + + removeData: function( key ){ + return this.each(function(){ + jQuery.removeData( this, key ); + }); + }, + + domManip: function( args, table, reverse, callback ) { + var clone = this.length > 1, elems; + + return this.each(function(){ + if ( !elems ) { + elems = jQuery.clean( args, this.ownerDocument ); + + if ( reverse ) + elems.reverse(); + } + + var obj = this; + + if ( table && jQuery.nodeName( this, "table" ) && jQuery.nodeName( elems[0], "tr" ) ) + obj = this.getElementsByTagName("tbody")[0] || this.appendChild( this.ownerDocument.createElement("tbody") ); + + var scripts = jQuery( [] ); + + jQuery.each(elems, function(){ + var elem = clone ? + jQuery( this ).clone( true )[0] : + this; + + // execute all scripts after the elements have been injected + if ( jQuery.nodeName( elem, "script" ) ) + scripts = scripts.add( elem ); + else { + // Remove any inner scripts for later evaluation + if ( elem.nodeType == 1 ) + scripts = scripts.add( jQuery( "script", elem ).remove() ); + + // Inject the elements into the document + callback.call( obj, elem ); + } + }); + + scripts.each( evalScript ); + }); + } +}; + +// Give the init function the jQuery prototype for later instantiation +jQuery.fn.init.prototype = jQuery.fn; + +function evalScript( i, elem ) { + if ( elem.src ) + jQuery.ajax({ + url: elem.src, + async: false, + dataType: "script" + }); + + else + jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" ); + + if ( elem.parentNode ) + elem.parentNode.removeChild( elem ); +} + +function now(){ + return +new Date; +} + +jQuery.extend = jQuery.fn.extend = function() { + // copy reference to target object + var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options; + + // Handle a deep copy situation + if ( target.constructor == Boolean ) { + deep = target; + target = arguments[1] || {}; + // skip the boolean and the target + i = 2; + } + + // Handle case when target is a string or something (possible in deep copy) + if ( typeof target != "object" && typeof target != "function" ) + target = {}; + + // extend jQuery itself if only one argument is passed + if ( length == i ) { + target = this; + --i; + } + + for ( ; i < length; i++ ) + // Only deal with non-null/undefined values + if ( (options = arguments[ i ]) != null ) + // Extend the base object + for ( var name in options ) { + var src = target[ name ], copy = options[ name ]; + + // Prevent never-ending loop + if ( target === copy ) + continue; + + // Recurse if we're merging object values + if ( deep && copy && typeof copy == "object" && !copy.nodeType ) + target[ name ] = jQuery.extend( deep, + // Never move original objects, clone them + src || ( copy.length != null ? [ ] : { } ) + , copy ); + + // Don't bring in undefined values + else if ( copy !== undefined ) + target[ name ] = copy; + + } + + // Return the modified object + return target; +}; + +var expando = "jQuery" + now(), uuid = 0, windowData = {}, + // exclude the following css properties to add px + exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i, + // cache defaultView + defaultView = document.defaultView || {}; + +jQuery.extend({ + noConflict: function( deep ) { + window.$ = _$; + + if ( deep ) + window.jQuery = _jQuery; + + return jQuery; + }, + + // See test/unit/core.js for details concerning this function. + isFunction: function( fn ) { + return !!fn && typeof fn != "string" && !fn.nodeName && + fn.constructor != Array && /^[\s[]?function/.test( fn + "" ); + }, + + // check if an element is in a (or is an) XML document + isXMLDoc: function( elem ) { + return elem.documentElement && !elem.body || + elem.tagName && elem.ownerDocument && !elem.ownerDocument.body; + }, + + // Evalulates a script in a global context + globalEval: function( data ) { + data = jQuery.trim( data ); + + if ( data ) { + // Inspired by code by Andrea Giammarchi + // http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html + var head = document.getElementsByTagName("head")[0] || document.documentElement, + script = document.createElement("script"); + + script.type = "text/javascript"; + if ( jQuery.browser.msie ) + script.text = data; + else + script.appendChild( document.createTextNode( data ) ); + + // Use insertBefore instead of appendChild to circumvent an IE6 bug. + // This arises when a base node is used (#2709). + head.insertBefore( script, head.firstChild ); + head.removeChild( script ); + } + }, + + nodeName: function( elem, name ) { + return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase(); + }, + + cache: {}, + + data: function( elem, name, data ) { + elem = elem == window ? + windowData : + elem; + + var id = elem[ expando ]; + + // Compute a unique ID for the element + if ( !id ) + id = elem[ expando ] = ++uuid; + + // Only generate the data cache if we're + // trying to access or manipulate it + if ( name && !jQuery.cache[ id ] ) + jQuery.cache[ id ] = {}; + + // Prevent overriding the named cache with undefined values + if ( data !== undefined ) + jQuery.cache[ id ][ name ] = data; + + // Return the named cache data, or the ID for the element + return name ? + jQuery.cache[ id ][ name ] : + id; + }, + + removeData: function( elem, name ) { + elem = elem == window ? + windowData : + elem; + + var id = elem[ expando ]; + + // If we want to remove a specific section of the element's data + if ( name ) { + if ( jQuery.cache[ id ] ) { + // Remove the section of cache data + delete jQuery.cache[ id ][ name ]; + + // If we've removed all the data, remove the element's cache + name = ""; + + for ( name in jQuery.cache[ id ] ) + break; + + if ( !name ) + jQuery.removeData( elem ); + } + + // Otherwise, we want to remove all of the element's data + } else { + // Clean up the element expando + try { + delete elem[ expando ]; + } catch(e){ + // IE has trouble directly removing the expando + // but it's ok with using removeAttribute + if ( elem.removeAttribute ) + elem.removeAttribute( expando ); + } + + // Completely remove the data cache + delete jQuery.cache[ id ]; + } + }, + + // args is for internal usage only + each: function( object, callback, args ) { + var name, i = 0, length = object.length; + + if ( args ) { + if ( length == undefined ) { + for ( name in object ) + if ( callback.apply( object[ name ], args ) === false ) + break; + } else + for ( ; i < length; ) + if ( callback.apply( object[ i++ ], args ) === false ) + break; + + // A special, fast, case for the most common use of each + } else { + if ( length == undefined ) { + for ( name in object ) + if ( callback.call( object[ name ], name, object[ name ] ) === false ) + break; + } else + for ( var value = object[0]; + i < length && callback.call( value, i, value ) !== false; value = object[++i] ){} + } + + return object; + }, + + prop: function( elem, value, type, i, name ) { + // Handle executable functions + if ( jQuery.isFunction( value ) ) + value = value.call( elem, i ); + + // Handle passing in a number to a CSS property + return value && value.constructor == Number && type == "curCSS" && !exclude.test( name ) ? + value + "px" : + value; + }, + + className: { + // internal only, use addClass("class") + add: function( elem, classNames ) { + jQuery.each((classNames || "").split(/\s+/), function(i, className){ + if ( elem.nodeType == 1 && !jQuery.className.has( elem.className, className ) ) + elem.className += (elem.className ? " " : "") + className; + }); + }, + + // internal only, use removeClass("class") + remove: function( elem, classNames ) { + if (elem.nodeType == 1) + elem.className = classNames != undefined ? + jQuery.grep(elem.className.split(/\s+/), function(className){ + return !jQuery.className.has( classNames, className ); + }).join(" ") : + ""; + }, + + // internal only, use hasClass("class") + has: function( elem, className ) { + return jQuery.inArray( className, (elem.className || elem).toString().split(/\s+/) ) > -1; + } + }, + + // A method for quickly swapping in/out CSS properties to get correct calculations + swap: function( elem, options, callback ) { + var old = {}; + // Remember the old values, and insert the new ones + for ( var name in options ) { + old[ name ] = elem.style[ name ]; + elem.style[ name ] = options[ name ]; + } + + callback.call( elem ); + + // Revert the old values + for ( var name in options ) + elem.style[ name ] = old[ name ]; + }, + + css: function( elem, name, force ) { + if ( name == "width" || name == "height" ) { + var val, props = { position: "absolute", visibility: "hidden", display:"block" }, which = name == "width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ]; + + function getWH() { + val = name == "width" ? elem.offsetWidth : elem.offsetHeight; + var padding = 0, border = 0; + jQuery.each( which, function() { + padding += parseFloat(jQuery.curCSS( elem, "padding" + this, true)) || 0; + border += parseFloat(jQuery.curCSS( elem, "border" + this + "Width", true)) || 0; + }); + val -= Math.round(padding + border); + } + + if ( jQuery(elem).is(":visible") ) + getWH(); + else + jQuery.swap( elem, props, getWH ); + + return Math.max(0, val); + } + + return jQuery.curCSS( elem, name, force ); + }, + + curCSS: function( elem, name, force ) { + var ret, style = elem.style; + + // A helper method for determining if an element's values are broken + function color( elem ) { + if ( !jQuery.browser.safari ) + return false; + + // defaultView is cached + var ret = defaultView.getComputedStyle( elem, null ); + return !ret || ret.getPropertyValue("color") == ""; + } + + // We need to handle opacity special in IE + if ( name == "opacity" && jQuery.browser.msie ) { + ret = jQuery.attr( style, "opacity" ); + + return ret == "" ? + "1" : + ret; + } + // Opera sometimes will give the wrong display answer, this fixes it, see #2037 + if ( jQuery.browser.opera && name == "display" ) { + var save = style.outline; + style.outline = "0 solid black"; + style.outline = save; + } + + // Make sure we're using the right name for getting the float value + if ( name.match( /float/i ) ) + name = styleFloat; + + if ( !force && style && style[ name ] ) + ret = style[ name ]; + + else if ( defaultView.getComputedStyle ) { + + // Only "float" is needed here + if ( name.match( /float/i ) ) + name = "float"; + + name = name.replace( /([A-Z])/g, "-$1" ).toLowerCase(); + + var computedStyle = defaultView.getComputedStyle( elem, null ); + + if ( computedStyle && !color( elem ) ) + ret = computedStyle.getPropertyValue( name ); + + // If the element isn't reporting its values properly in Safari + // then some display: none elements are involved + else { + var swap = [], stack = [], a = elem, i = 0; + + // Locate all of the parent display: none elements + for ( ; a && color(a); a = a.parentNode ) + stack.unshift(a); + + // Go through and make them visible, but in reverse + // (It would be better if we knew the exact display type that they had) + for ( ; i < stack.length; i++ ) + if ( color( stack[ i ] ) ) { + swap[ i ] = stack[ i ].style.display; + stack[ i ].style.display = "block"; + } + + // Since we flip the display style, we have to handle that + // one special, otherwise get the value + ret = name == "display" && swap[ stack.length - 1 ] != null ? + "none" : + ( computedStyle && computedStyle.getPropertyValue( name ) ) || ""; + + // Finally, revert the display styles back + for ( i = 0; i < swap.length; i++ ) + if ( swap[ i ] != null ) + stack[ i ].style.display = swap[ i ]; + } + + // We should always get a number back from opacity + if ( name == "opacity" && ret == "" ) + ret = "1"; + + } else if ( elem.currentStyle ) { + var camelCase = name.replace(/\-(\w)/g, function(all, letter){ + return letter.toUpperCase(); + }); + + ret = elem.currentStyle[ name ] || elem.currentStyle[ camelCase ]; + + // From the awesome hack by Dean Edwards + // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291 + + // If we're not dealing with a regular pixel number + // but a number that has a weird ending, we need to convert it to pixels + if ( !/^\d+(px)?$/i.test( ret ) && /^\d/.test( ret ) ) { + // Remember the original values + var left = style.left, rsLeft = elem.runtimeStyle.left; + + // Put in the new values to get a computed value out + elem.runtimeStyle.left = elem.currentStyle.left; + style.left = ret || 0; + ret = style.pixelLeft + "px"; + + // Revert the changed values + style.left = left; + elem.runtimeStyle.left = rsLeft; + } + } + + return ret; + }, + + clean: function( elems, context ) { + var ret = []; + context = context || document; + // !context.createElement fails in IE with an error but returns typeof 'object' + if (typeof context.createElement == 'undefined') + context = context.ownerDocument || context[0] && context[0].ownerDocument || document; + + jQuery.each(elems, function(i, elem){ + if ( !elem ) + return; + + if ( elem.constructor == Number ) + elem += ''; + + // Convert html string into DOM nodes + if ( typeof elem == "string" ) { + // Fix "XHTML"-style tags in all browsers + elem = elem.replace(/(<(\w+)[^>]*?)\/>/g, function(all, front, tag){ + return tag.match(/^(abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i) ? + all : + front + ">"; + }); + + // Trim whitespace, otherwise indexOf won't work as expected + var tags = jQuery.trim( elem ).toLowerCase(), div = context.createElement("div"); + + var wrap = + // option or optgroup + !tags.indexOf("", "" ] || + + !tags.indexOf("", "" ] || + + tags.match(/^<(thead|tbody|tfoot|colg|cap)/) && + [ 1, "", "
" ] || + + !tags.indexOf("", "" ] || + + // matched above + (!tags.indexOf("", "" ] || + + !tags.indexOf("", "" ] || + + // IE can't serialize and 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 = [ + "", "", "
      ", "
      ", + "