Added unit test for issue #2537 - Add new pageremove event.

The test makes use of a pageremove callback that conditionally calls preventDefault() on the event so that the test can make sure a developer can prevent a specific page from being removed from the DOM.
This commit is contained in:
Kin Blas 2011-09-28 11:38:18 -07:00
parent 34fb7b2dc1
commit 880df5fcf5

View file

@ -96,6 +96,56 @@
]);
});
asyncTest( "preventDefault on pageremove event can prevent external page from being removed from the DOM", function(){
var preventRemoval = true,
removeCallback = function( e ) {
if ( preventRemoval ) {
e.preventDefault();
}
};
$( document ).bind( "pageremove", removeCallback );
$.testHelper.pageSequence([
navigateTestRoot,
function(){
$.mobile.changePage( "external.html" );
},
// page is pulled and displayed in the dom
function(){
same( $( "#external-test" ).length, 1 );
window.history.back();
},
// external-test *IS* cached in the dom after transitioning away
function(){
same( $( "#external-test" ).length, 1 );
// Switch back to the page again!
$.mobile.changePage( "external.html" );
},
// page is still present and displayed in the dom
function(){
same( $( "#external-test" ).length, 1 );
// Now turn off our removal prevention.
preventRemoval = false;
window.history.back();
},
// external-test is *NOT* cached in the dom after transitioning away
function(){
same( $( "#external-test" ).length, 0 );
$( document ).unbind( "pageremove", removeCallback );
start();
}
]);
});
asyncTest( "external page is cached in the DOM after pagehide", function(){
$.testHelper.pageSequence([
navigateTestRoot,