Skip to content

Commit 51efa6a

Browse files
author
Gabriel Schulhof
committed
Merge branch 'sequence-tests'
2 parents 00d82c0 + 34ae892 commit 51efa6a

19 files changed

+823
-200
lines changed

tests/functional/hashchange/dialog.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ <h1>A dialog</h1>
1010
</div>
1111
<div data-role="content">
1212
<a href="hashchange.html" data-role="button" data-inline="true">A page</a>
13-
<div id="thePopup" data-role="popup">
13+
<div id="thePopupInsideADialog" data-role="popup">
1414
<p>This is a popup from a dialog</p>
1515
<a href="hashchange1.html">Another page</a>
1616
<a href="hashchange2.html">Yet another page</a>
1717
</div>
18-
<a href="#thePopup" data-role="button" data-rel="popup" data-inline="true">A popup from a dialog</a>
18+
<a href="#thePopupInsideADialog" data-role="button" data-rel="popup" data-inline="true">A popup from a dialog</a>
1919
<a href="dialog1.html" data-role="button" data-rel="dialog" data-inline="true">Another dialog</a>
2020
<a href="dialog2.html" data-role="button" data-rel="dialog" data-inline="true">Yet another dialog</a>
2121
<a href="hashchange1.html" data-role="button" data-inline="true">Another page</a>

tests/functional/hashchange/hashchange.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@
99
<script src="../../../js/jquery.tag.inserter.js"></script>
1010
<script src="../../../js/jquery.js"></script>
1111
<script src="../../../docs/_assets/js/jqm-docs.js"></script>
12+
<!--
13+
<script>
14+
(function( $, undefined ) {
15+
$( document ).bind( "mobileinit", function() {
16+
$.mobile.pushStateEnabled = false;
17+
});
18+
})( jQuery );
19+
</script>
20+
-->
1221
<script src="../../../js/"></script>
1322
</head>
1423
<body>

tests/jquery.testHelper.js

Lines changed: 102 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
// This function takes sets of files to load asynchronously. Each set will be loaded after
88
// the previous set has completed loading. That is, each require and it's dependencies in a
99
// set will be loaded asynchronously, but each set will be run in serial.
10-
asyncLoad: function( seq ) {
10+
asyncLoad: function( seq, baseUrl ) {
1111
require({
12-
baseUrl: "../../../js"
12+
baseUrl: ( baseUrl || "../../../js" )
1313
});
1414

1515
function loadSeq( seq, i ){
@@ -211,6 +211,106 @@
211211
fn( timedOut );
212212
},
213213

214+
// detailedEventCascade: call a function and expect a series of events to be triggered (or not to be triggered), and guard
215+
// with a timeout against getting stood up. Record the result (timed out / was triggered) for each event, and the order
216+
// in which the event arrived wrt. any other events expected.
217+
// seq : [
218+
// fn(result),
219+
// { key: {
220+
// src: event source (is jQuery object or function returning jQuery object),
221+
// event: event name (is string),
222+
// NB: It's a good idea to namespace your events, because the handler will be removed
223+
// based on the name you give here if a timeout occurs before the event fires.
224+
// userData1: value,
225+
// ...
226+
// userDatan: value
227+
// },
228+
// ...
229+
// ]
230+
// ...
231+
// ]
232+
// result: {
233+
// key: {
234+
// idx: order in which the event fired
235+
// src: event source (is jQuery object),
236+
// event: event name (is string)
237+
// timedOut: timed out (is boolean)
238+
// userData1: value,
239+
// ...
240+
// userDatan: value
241+
// }
242+
// ...
243+
// }
244+
detailedEventCascade: function( seq, result ) {
245+
// grab one step from the sequence
246+
var fn = seq.shift(),
247+
events = seq.shift(),
248+
self = this,
249+
derefSrc = function( src ) {
250+
return ( $.isFunction( src ) ? src() : src );
251+
};
252+
253+
// we're done
254+
if ( fn === undefined ) {
255+
return;
256+
}
257+
258+
// Attach handlers to the various objects which are to be checked for correct event generation
259+
if ( events ) {
260+
var newResult = {},
261+
nEventsDone = 0,
262+
nEvents = 0,
263+
// set a failsafe timer in case one of the events never happens
264+
warnTimer = setTimeout( function() {
265+
$.each( events, function( key, event ) {
266+
if ( newResult[ key ] === undefined ) {
267+
// clean up the unused handler
268+
derefSrc( event.src ).unbind( event.event );
269+
newResult[ key ] = $.extend( {}, event, { timedOut: true } );
270+
}
271+
});
272+
273+
// Move on to the next step
274+
self.detailedEventCascade( seq, newResult );
275+
}, 20000);
276+
277+
function recordResult( key, event, result ) {
278+
// Record the result
279+
newResult[ key ] = $.extend( {}, event, result );
280+
// Increment the number of received responses
281+
nEventsDone++;
282+
if ( nEventsDone === nEvents ) {
283+
// clear the timeout and move on to the next step when all events have been received
284+
clearTimeout( warnTimer );
285+
setTimeout( function() {
286+
self.detailedEventCascade( seq, newResult );
287+
}, 0);
288+
}
289+
}
290+
291+
$.each( events, function( key, event ) {
292+
// Count the events so that we may know how many responses to expect
293+
nEvents++;
294+
// If it's an event
295+
if ( event.src ) {
296+
// Hook up to the event
297+
derefSrc( event.src ).one( event.event, function() {
298+
recordResult( key, event, { timedOut: false, idx: nEventsDone } );
299+
});
300+
}
301+
// If it's a timeout
302+
else {
303+
setTimeout( function() {
304+
recordResult( key, event, { timedOut: true, idx: -1 } );
305+
}, event.length );
306+
}
307+
});
308+
}
309+
310+
// Call the function with the result of the events
311+
fn( result );
312+
},
313+
214314
deferredSequence: function(fns) {
215315
var fn = fns.shift(),
216316
deferred = $.Deferred(),

tests/unit/dialog/basic-dialog-hash-key-tests.html

Lines changed: 0 additions & 15 deletions
This file was deleted.

tests/unit/dialog/basic-tests.html

Lines changed: 0 additions & 57 deletions
This file was deleted.

tests/unit/dialog/dialog_basic.js

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>Another page</title>
5+
</head>
6+
<body>
7+
8+
<div data-nstest-role="page" id="anotherPage"></div>
9+
10+
</body>
11+
</html>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
</head>
5+
<body>
6+
<div id="basicDialog" data-nstest-role="dialog">
7+
<div data-nstest-role="header">
8+
<h1>Dialog</h1>
9+
</div>
10+
<div data-nstest-role="content">
11+
<div data-nstest-role="popup" id="popupFromBasicDialog">
12+
<a href="another-page.html" id="fromDialogPopupToAnotherPage">Go</a>
13+
</div>
14+
<a href="#popupFromBasicDialog" id="fromDialogToPopup" data-nstest-rel="popup">Go</a>
15+
<a href="another-page.html" id="fromDialogToAnotherPage">Go</a>
16+
</div>
17+
</div>
18+
</body>
19+
</html>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
</head>
5+
<body>
6+
<div id="anotherDialog" data-nstest-role="dialog">
7+
<div data-nstest-role="header">
8+
<h1>Dialog</h1>
9+
</div>
10+
<div data-nstest-role="content">
11+
<a href="another-page.html" id="fromAnotherDialogToAnotherPage">Go</a>
12+
</div>
13+
</div>
14+
</body>
15+
</html>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<script src="../../../../js/jquery.js"></script>
5+
<script src="../../../../js/"></script>
6+
<script>
7+
(function($) {
8+
var l = $.mobile.path.parseLocation();
9+
10+
// Redirect to sequence-tests.html in the same directory as this file
11+
location.href = l.protocol + "//" + l.host + l.directory + "sequence-tests.html" + l.search + "#&ui-state=dialog";
12+
})( jQuery );
13+
</script>
14+
</head>
15+
</html>

0 commit comments

Comments
 (0)