aboutsummaryrefslogtreecommitdiffstats
path: root/test/data
diff options
context:
space:
mode:
authorRick Waldron <waldron.rick@gmail.com>2013-02-03 15:27:55 -0500
committerRick Waldron <waldron.rick@gmail.com>2013-02-03 15:27:55 -0500
commit7f94a5cc3a167a710576c008da2c186a98ce2dd4 (patch)
treed4a3e8ec0e4385d305676b74a663de3017c48438 /test/data
parented0e2d1e8a5005a80d0dd127dc4019f696471ad6 (diff)
downloadjquery-7f94a5cc3a167a710576c008da2c186a98ce2dd4.tar.gz
jquery-7f94a5cc3a167a710576c008da2c186a98ce2dd4.zip
2.0: Rewrite data.js (Incl. event, manipulation, tests)
Diffstat (limited to 'test/data')
-rw-r--r--test/data/onbeforeunload.html20
-rw-r--r--test/data/testrunner.js74
2 files changed, 60 insertions, 34 deletions
diff --git a/test/data/onbeforeunload.html b/test/data/onbeforeunload.html
new file mode 100644
index 000000000..62c424e89
--- /dev/null
+++ b/test/data/onbeforeunload.html
@@ -0,0 +1,20 @@
+<!doctype html>
+<html>
+ <script src="/dist/jquery.js"></script>
+ <script>
+ function report( event ) {
+ var payload = {
+ event: event.type
+ };
+ return top.postMessage( JSON.stringify(payload), "*" );
+ }
+
+ jQuery( window ).on( "beforeunload", function( event ) {
+ report( event );
+ }).on( "load", function( event ) {
+ setTimeout(function() {
+ window.location.reload();
+ }, 50);
+ });
+ </script>
+</html>
diff --git a/test/data/testrunner.js b/test/data/testrunner.js
index f7aca724a..aa7c13019 100644
--- a/test/data/testrunner.js
+++ b/test/data/testrunner.js
@@ -200,47 +200,53 @@ var Globals = (function() {
*/
QUnit.expectJqData = function( elems, key ) {
var i, elem, expando;
- QUnit.current_testEnvironment.checkJqData = true;
- if ( elems.jquery && elems.toArray ) {
- elems = elems.toArray();
- }
- if ( !jQuery.isArray( elems ) ) {
- elems = [ elems ];
- }
+ // As of jQuery 2.0, there will be no "cache"-data is
+ // stored and managed completely below the API surface
+ if ( jQuery.cache ) {
+ QUnit.current_testEnvironment.checkJqData = true;
- for ( i = 0; i < elems.length; i++ ) {
- elem = elems[i];
-
- // jQuery.data only stores data for nodes in jQuery.cache,
- // for other data targets the data is stored in the object itself,
- // in that case we can't test that target for memory leaks.
- // But we don't have to since in that case the data will/must will
- // be available as long as the object is not garbage collected by
- // the js engine, and when it is, the data will be removed with it.
- if ( !elem.nodeType ) {
- // Fixes false positives for dataTests(window), dataTests({}).
- continue;
+ if ( elems.jquery && elems.toArray ) {
+ elems = elems.toArray();
+ }
+ if ( !jQuery.isArray( elems ) ) {
+ elems = [ elems ];
}
- expando = elem[ jQuery.expando ];
-
- if ( expando === undefined ) {
- // In this case the element exists fine, but
- // jQuery.data (or internal data) was never (in)directly
- // called.
- // Since this method was called it means some data was
- // expected to be found, but since there is nothing, fail early
- // (instead of in teardown).
- notStrictEqual( expando, undefined, "Target for expectJqData must have an expando, for else there can be no data to expect." );
- } else {
- if ( expectedDataKeys[expando] ) {
- expectedDataKeys[expando].push( key );
+ for ( i = 0; i < elems.length; i++ ) {
+ elem = elems[i];
+
+ // jQuery.data only stores data for nodes in jQuery.cache,
+ // for other data targets the data is stored in the object itself,
+ // in that case we can't test that target for memory leaks.
+ // But we don't have to since in that case the data will/must will
+ // be available as long as the object is not garbage collected by
+ // the js engine, and when it is, the data will be removed with it.
+ if ( !elem.nodeType ) {
+ // Fixes false positives for dataTests(window), dataTests({}).
+ continue;
+ }
+
+ expando = elem[ jQuery.expando ];
+
+ if ( expando === undefined ) {
+ // In this case the element exists fine, but
+ // jQuery.data (or internal data) was never (in)directly
+ // called.
+ // Since this method was called it means some data was
+ // expected to be found, but since there is nothing, fail early
+ // (instead of in teardown).
+ notStrictEqual( expando, undefined, "Target for expectJqData must have an expando, for else there can be no data to expect." );
} else {
- expectedDataKeys[expando] = [ key ];
+ if ( expectedDataKeys[expando] ) {
+ expectedDataKeys[expando].push( key );
+ } else {
+ expectedDataKeys[expando] = [ key ];
+ }
}
}
}
+
};
QUnit.config.urlConfig.push( {
id: "jqdata",
@@ -334,7 +340,7 @@ var Globals = (function() {
} else {
delete jQuery.ajaxSettings;
}
-
+
// Cleanup globals
Globals.cleanup();