Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Commit

Permalink
Merge branch 'sequence-tests'
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Schulhof committed Oct 2, 2012
2 parents 00d82c0 + 34ae892 commit 51efa6a
Show file tree
Hide file tree
Showing 19 changed files with 823 additions and 200 deletions.
4 changes: 2 additions & 2 deletions tests/functional/hashchange/dialog.html
Expand Up @@ -10,12 +10,12 @@ <h1>A dialog</h1>
</div>
<div data-role="content">
<a href="hashchange.html" data-role="button" data-inline="true">A page</a>
<div id="thePopup" data-role="popup">
<div id="thePopupInsideADialog" data-role="popup">
<p>This is a popup from a dialog</p>
<a href="hashchange1.html">Another page</a>
<a href="hashchange2.html">Yet another page</a>
</div>
<a href="#thePopup" data-role="button" data-rel="popup" data-inline="true">A popup from a dialog</a>
<a href="#thePopupInsideADialog" data-role="button" data-rel="popup" data-inline="true">A popup from a dialog</a>
<a href="dialog1.html" data-role="button" data-rel="dialog" data-inline="true">Another dialog</a>
<a href="dialog2.html" data-role="button" data-rel="dialog" data-inline="true">Yet another dialog</a>
<a href="hashchange1.html" data-role="button" data-inline="true">Another page</a>
Expand Down
9 changes: 9 additions & 0 deletions tests/functional/hashchange/hashchange.html
Expand Up @@ -9,6 +9,15 @@
<script src="../../../js/jquery.tag.inserter.js"></script>
<script src="../../../js/jquery.js"></script>
<script src="../../../docs/_assets/js/jqm-docs.js"></script>
<!--
<script>
(function( $, undefined ) {
$( document ).bind( "mobileinit", function() {
$.mobile.pushStateEnabled = false;
});
})( jQuery );
</script>
-->
<script src="../../../js/"></script>
</head>
<body>
Expand Down
104 changes: 102 additions & 2 deletions tests/jquery.testHelper.js
Expand Up @@ -7,9 +7,9 @@
// This function takes sets of files to load asynchronously. Each set will be loaded after
// the previous set has completed loading. That is, each require and it's dependencies in a
// set will be loaded asynchronously, but each set will be run in serial.
asyncLoad: function( seq ) {
asyncLoad: function( seq, baseUrl ) {
require({
baseUrl: "../../../js"
baseUrl: ( baseUrl || "../../../js" )
});

function loadSeq( seq, i ){
Expand Down Expand Up @@ -211,6 +211,106 @@
fn( timedOut );
},

// detailedEventCascade: call a function and expect a series of events to be triggered (or not to be triggered), and guard
// with a timeout against getting stood up. Record the result (timed out / was triggered) for each event, and the order
// in which the event arrived wrt. any other events expected.
// seq : [
// fn(result),
// { key: {
// src: event source (is jQuery object or function returning jQuery object),
// event: event name (is string),
// NB: It's a good idea to namespace your events, because the handler will be removed
// based on the name you give here if a timeout occurs before the event fires.
// userData1: value,
// ...
// userDatan: value
// },
// ...
// ]
// ...
// ]
// result: {
// key: {
// idx: order in which the event fired
// src: event source (is jQuery object),
// event: event name (is string)
// timedOut: timed out (is boolean)
// userData1: value,
// ...
// userDatan: value
// }
// ...
// }
detailedEventCascade: function( seq, result ) {
// grab one step from the sequence
var fn = seq.shift(),
events = seq.shift(),
self = this,
derefSrc = function( src ) {
return ( $.isFunction( src ) ? src() : src );
};

// we're done
if ( fn === undefined ) {
return;
}

// Attach handlers to the various objects which are to be checked for correct event generation
if ( events ) {
var newResult = {},
nEventsDone = 0,
nEvents = 0,
// set a failsafe timer in case one of the events never happens
warnTimer = setTimeout( function() {
$.each( events, function( key, event ) {
if ( newResult[ key ] === undefined ) {
// clean up the unused handler
derefSrc( event.src ).unbind( event.event );
newResult[ key ] = $.extend( {}, event, { timedOut: true } );
}
});

// Move on to the next step
self.detailedEventCascade( seq, newResult );
}, 20000);

function recordResult( key, event, result ) {
// Record the result
newResult[ key ] = $.extend( {}, event, result );
// Increment the number of received responses
nEventsDone++;
if ( nEventsDone === nEvents ) {
// clear the timeout and move on to the next step when all events have been received
clearTimeout( warnTimer );
setTimeout( function() {
self.detailedEventCascade( seq, newResult );
}, 0);
}
}

$.each( events, function( key, event ) {
// Count the events so that we may know how many responses to expect
nEvents++;
// If it's an event
if ( event.src ) {
// Hook up to the event
derefSrc( event.src ).one( event.event, function() {
recordResult( key, event, { timedOut: false, idx: nEventsDone } );
});
}
// If it's a timeout
else {
setTimeout( function() {
recordResult( key, event, { timedOut: true, idx: -1 } );
}, event.length );
}
});
}

// Call the function with the result of the events
fn( result );
},

deferredSequence: function(fns) {
var fn = fns.shift(),
deferred = $.Deferred(),
Expand Down
15 changes: 0 additions & 15 deletions tests/unit/dialog/basic-dialog-hash-key-tests.html

This file was deleted.

57 changes: 0 additions & 57 deletions tests/unit/dialog/basic-tests.html

This file was deleted.

21 changes: 0 additions & 21 deletions tests/unit/dialog/dialog_basic.js

This file was deleted.

11 changes: 11 additions & 0 deletions tests/unit/navigation/sequence-tests/another-page.html
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Another page</title>
</head>
<body>

<div data-nstest-role="page" id="anotherPage"></div>

</body>
</html>
19 changes: 19 additions & 0 deletions tests/unit/navigation/sequence-tests/basic-dialog.html
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div id="basicDialog" data-nstest-role="dialog">
<div data-nstest-role="header">
<h1>Dialog</h1>
</div>
<div data-nstest-role="content">
<div data-nstest-role="popup" id="popupFromBasicDialog">
<a href="another-page.html" id="fromDialogPopupToAnotherPage">Go</a>
</div>
<a href="#popupFromBasicDialog" id="fromDialogToPopup" data-nstest-rel="popup">Go</a>
<a href="another-page.html" id="fromDialogToAnotherPage">Go</a>
</div>
</div>
</body>
</html>
15 changes: 15 additions & 0 deletions tests/unit/navigation/sequence-tests/basic-dialog1.html
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div id="anotherDialog" data-nstest-role="dialog">
<div data-nstest-role="header">
<h1>Dialog</h1>
</div>
<div data-nstest-role="content">
<a href="another-page.html" id="fromAnotherDialogToAnotherPage">Go</a>
</div>
</div>
</body>
</html>
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<script src="../../../../js/jquery.js"></script>
<script src="../../../../js/"></script>
<script>
(function($) {
var l = $.mobile.path.parseLocation();

// Redirect to sequence-tests.html in the same directory as this file
location.href = l.protocol + "//" + l.host + l.directory + "sequence-tests.html" + l.search + "#&ui-state=dialog";
})( jQuery );
</script>
</head>
</html>
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<script src="../../../../js/jquery.js"></script>
<script src="../../../../js/"></script>
<script>
(function($) {
var l = $.mobile.path.parseLocation();

// Redirect to sequence-tests.html in the same directory as this file
location.href = l.protocol + "//" + l.host + l.directory + "sequence-tests.html" + l.search + "#" + l.directory + "sequence-tests.html" + "&ui-state=dialog";
})( jQuery );
</script>
</head>
</html>
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<script src="../../../../js/jquery.js"></script>
<script src="../../../../js/"></script>
<script>
(function($) {
var l = $.mobile.path.parseLocation();

// Redirect to sequence-tests.html in the same directory as this file
location.href = l.protocol + "//" + l.host + l.directory + "sequence-redirect.html" + l.search + "#" + l.directory + "sequence-tests.html" + "&ui-state=dialog";
})( jQuery );
</script>
</head>
</html>
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<!-- forces the base-tests into a push state disabled run and allows for
the test suite runner to pick it up as a seperate test set. See test/unit/ls.php,
test/unit/runner.js, base-tests.html, and tests/jquery.testHelper.js for more. -->
<script src="../../../../js/jquery.js"></script>
<script src="../../../jquery.testHelper.js"></script>
<script type="text/javascript">
$.testHelper.pushStateRedirect( "./sequence-dialog-hash-key-tests.html" );
</script>
</head>
<body>
</body>
</html>
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<!-- forces the base-tests into a push state disabled run and allows for
the test suite runner to pick it up as a seperate test set. See test/unit/ls.php,
test/unit/runner.js, base-tests.html, and tests/jquery.testHelper.js for more. -->
<script src="../../../../js/jquery.js"></script>
<script src="../../../jquery.testHelper.js"></script>
<script type="text/javascript">
$.testHelper.pushStateRedirect( "./sequence-path1-path2-dialog-hash-key-tests.html" );
</script>
</head>
<body>
</body>
</html>
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<!-- forces the base-tests into a push state disabled run and allows for
the test suite runner to pick it up as a seperate test set. See test/unit/ls.php,
test/unit/runner.js, base-tests.html, and tests/jquery.testHelper.js for more. -->
<script src="../../../../js/jquery.js"></script>
<script src="../../../jquery.testHelper.js"></script>
<script type="text/javascript">
$.testHelper.pushStateRedirect( "./sequence-tests.html" );
</script>
</head>
<body>
</body>
</html>

0 comments on commit 51efa6a

Please sign in to comment.