Large diffs are not rendered by default.

119 js/job.js
@@ -1,53 +1,54 @@
/**
* JavaScript file for the "job" page in the browser.
*
* @author John Resig, 2008-2011
* @author John Resig
* @author Timo Tijhof
* @since 0.1.0
* @package TestSwarm
*/
jQuery(function ( $ ) {
jQuery(function( $ ) {
var updateInterval = SWARM.conf.web.ajaxUpdateInterval * 1000,
$wipejobErr = $( '.swarm-wipejob-error' ),
$targetTable = $( 'table.swarm-results' ),
$wipejobErr = $( ".swarm-wipejob-error" ),
$targetTable = $( "table.swarm-results" ),
refreshTableTimout, indicatorText, $indicator;

indicatorText = document.createTextNode( 'updating' );
$indicator = $( '<span class="btn pull-right disabled"> <i class="icon-refresh"></i></span>' )
indicatorText = document.createTextNode( "updating" );
$indicator = $( "<span class='btn pull-right disabled'> <i class='icon-refresh'></i></span>" )
.prepend( indicatorText )
.css( 'opacity', 0 );
.css( "opacity", 0 );

function indicateAction( label ) {
// Make sure any scheduled action is dequeued, we're doing something now.
// Make sure any scheduled action is dequeued, we"re doing something now.
if ( refreshTableTimout ) {
clearTimeout( refreshTableTimout );
}
// $.text() is a getter
// $.fn.text() does empty/append, which means the reference is no meaningless
indicatorText.nodeValue = label;
$indicator.stop( true, true ).css( 'opacity', 1 );
$indicator.stop( true, true ).css( "opacity", 1 );
}

function actionComplete() {
setTimeout( function () {
setTimeout( function() {
$indicator.stop(true, true).animate({
opacity: 0
});
}, 10 );
}

function refreshTable() {
indicateAction( 'updating' );
indicateAction( "updating" );

$.get( window.location.href )
.done( function ( html ) {
.done( function( html ) {
var tableHtml;

tableHtml = $( html ).find( 'table.swarm-results' ).html();
tableHtml = $( html ).find( "table.swarm-results" ).html();
if ( tableHtml !== $targetTable.html() ) {
$targetTable.html( tableHtml );
}
})
.complete( function () {
.complete( function() {
// Wether done or failed: Clean up and schedule next update
actionComplete();
refreshTableTimout = setTimeout( refreshTable, updateInterval );
@@ -58,119 +59,119 @@ jQuery(function ( $ ) {
refreshTableTimout = setTimeout( refreshTable, updateInterval );

function wipejobFail( data ) {
$wipejobErr.hide().text( data.error && data.error.info || 'Action failed.' ).slideDown();
$wipejobErr.hide().text( data.error && data.error.info || "Action failed." ).slideDown();
}

function resetRun( $el ) {
if ( $el.data( 'runStatus' ) !== 'new' ) {
if ( $el.data( "runStatus" ) !== "new" ) {
$.ajax({
url: SWARM.conf.web.contextpath + 'api.php',
type: 'POST',
url: SWARM.conf.web.contextpath + "api.php",
type: "POST",
data: {
action: 'wiperun',
job_id: $el.data( 'jobId' ),
run_id: $el.data( 'runId' ),
client_id: $el.data( 'clientId' ),
useragent_id: $el.data( 'useragentId' ),
action: "wiperun",
job_id: $el.data( "jobId" ),
run_id: $el.data( "runId" ),
client_id: $el.data( "clientId" ),
useragent_id: $el.data( "useragentId" ),
authID: SWARM.auth.project.id,
authToken: SWARM.auth.sessionToken
},
dataType: 'json',
success: function ( data ) {
if ( data.wiperun && data.wiperun.result === 'ok' ) {
$el.empty().attr( 'class', 'swarm-status swarm-status-new' );
dataType: "json",
success: function( data ) {
if ( data.wiperun && data.wiperun.result === "ok" ) {
$el.empty().attr( "class", "swarm-status swarm-status-new" );
refreshTable();
}
}
});
}
}

$( 'table.swarm-results' ).prev().before( $indicator );
$( "table.swarm-results" ).prev().before( $indicator );

if ( SWARM.auth ) {

// This needs to bound as a delegate, because the table auto-refreshes.
$targetTable.on( 'click', '.swarm-reset-run-single', function () {
resetRun( $( this ).closest( 'td' ) );
$targetTable.on( "click", ".swarm-reset-run-single", function() {
resetRun( $( this ).closest( "td" ) );
});

$( '.swarm-reset-runs-failed' ).on( 'click', function () {
var $els = $( 'td[data-run-status="failed"], td[data-run-status="error"], td[data-run-status="timedout"]' );
if ( !$els.length || !window.confirm( 'Are you sure you want to reset all failed runs?' ) ) {
$( ".swarm-reset-runs-failed" ).on( "click", function() {
var $els = $( "td[data-run-status='failed'], td[data-run-status='error'], td[data-run-status='timedout']" );
if ( !$els.length || !window.confirm( "Are you sure you want to reset all failed runs?" ) ) {
return;
}
$els.each( function () {
$els.each( function() {
resetRun( $( this ) );
});
});
$( '.swarm-delete-job' ).click( function () {
if ( !window.confirm( 'Are you sure you want to delete this job?' ) ) {
$( ".swarm-delete-job" ).click( function() {
if ( !window.confirm( "Are you sure you want to delete this job?" ) ) {
return;
}
$wipejobErr.hide();
indicateAction( 'deleting' );
indicateAction( "deleting" );

$.ajax({
url: SWARM.conf.web.contextpath + 'api.php',
type: 'POST',
url: SWARM.conf.web.contextpath + "api.php",
type: "POST",
data: {
action: 'wipejob',
action: "wipejob",
job_id: SWARM.jobInfo.id,
type: 'delete',
type: "delete",
authID: SWARM.auth.project.id,
authToken: SWARM.auth.sessionToken
},
dataType: 'json',
success: function ( data ) {
if ( data.wipejob && data.wipejob.result === 'ok' ) {
dataType: "json",
success: function( data ) {
if ( data.wipejob && data.wipejob.result === "ok" ) {
// Right now the only user authorized to delete a job is the creator,
// the below code makes that assumption.
window.location.href = SWARM.conf.web.contextpath + 'project/' + SWARM.auth.project.id;
window.location.href = SWARM.conf.web.contextpath + "project/" + SWARM.auth.project.id;
return;
}
actionComplete();
wipejobFail( data );
},
error: function ( error ) {
error: function( error ) {
actionComplete();
wipejobFail( error );
}
});
} );
});

$( '.swarm-reset-runs' ).click( function () {
if ( !window.confirm( 'Are you sure you want to reset this job?' ) ) {
$( ".swarm-reset-runs" ).click( function() {
if ( !window.confirm( "Are you sure you want to reset this job?" ) ) {
return;
}
$wipejobErr.hide();
indicateAction( 'resetting' );
indicateAction( "resetting" );

$.ajax({
url: SWARM.conf.web.contextpath + 'api.php',
type: 'POST',
url: SWARM.conf.web.contextpath + "api.php",
type: "POST",
data: {
action: 'wipejob',
action: "wipejob",
job_id: SWARM.jobInfo.id,
type: 'reset',
type: "reset",
authID: SWARM.auth.project.id,
authToken: SWARM.auth.sessionToken
},
dataType: 'json',
success: function ( data ) {
dataType: "json",
success: function( data ) {
actionComplete();
if ( data.wipejob && data.wipejob.result === 'ok' ) {
if ( data.wipejob && data.wipejob.result === "ok" ) {
refreshTable();
return;
}
wipejobFail( data );
},
error: function ( error ) {
error: function( error ) {
actionComplete();
wipejobFail( error );
}
});
} );
});

}

@@ -29,26 +29,26 @@ function prettyDate( time ) {
}

return day_diff === 0 && (
diff < 3 && 'just now' ||
diff < 60 && Math.floor( diff ) + ' seconds ago' ||
diff < 120 && '1 minute ago' ||
diff < 3600 && Math.floor( diff / 60 ) + ' minutes ago' ||
diff < 7200 && '1 hour ago' ||
diff < 86400 && Math.floor( diff / 3600 ) + ' hours ago'
diff < 3 && "just now" ||
diff < 60 && Math.floor( diff ) + " seconds ago" ||
diff < 120 && "1 minute ago" ||
diff < 3600 && Math.floor( diff / 60 ) + " minutes ago" ||
diff < 7200 && "1 hour ago" ||
diff < 86400 && Math.floor( diff / 3600 ) + " hours ago"
) ||
day_diff === 1 && 'Yesterday' ||
day_diff < 7 && day_diff + ' days ago' ||
day_diff < 31 && Math.ceil( day_diff / 7 ) + ' weeks ago';
day_diff === 1 && "Yesterday" ||
day_diff < 7 && day_diff + " days ago" ||
day_diff < 31 && Math.ceil( day_diff / 7 ) + " weeks ago";
}

// If jQuery is included in the page, adds a jQuery plugin to handle it as well
if ( typeof jQuery !== 'undefined' ) {
jQuery.fn.prettyDate = function () {
return this.each( function () {
if ( typeof jQuery !== "undefined" ) {
jQuery.fn.prettyDate = function() {
return this.each(function() {
var date = prettyDate( this.title );
if ( date ) {
jQuery( this ).text( date );
}
} );
});
};
}
@@ -1,32 +1,32 @@
/**
* JavaScript file for the "result" page in the browser.
*
* @author Timo Tijhof, 2012
* @author Timo Tijhof
* @since 1.0
* @package TestSwarm
*/
jQuery(function ( $ ) {
jQuery(function( $ ) {

// Even-out scrollbars
$( '.swarm-result-frame' ).on( 'load', function () {
$( ".swarm-result-frame" ).on( "load", function() {
var frame = this, frameDoc = frame.contentWindow.document;
setTimeout( function () {
setTimeout( function() {
frame.height = frameDoc.height;
}, 50);
});

// Popup links
$( '.swarm-popuplink' ).on( 'click', function ( e ) {
window.open( this.href, '_blank', [
'menubar=no',
'toolbar=no',
'location=yes',
'personalbar=no',
'status=yes',
'resizable=yes',
'scrollbars=yes',
'minimizable=yes'
].join(',') );
$( ".swarm-popuplink" ).on( "click", function( e ) {
window.open( this.href, "_blank", [
"menubar=no",
"toolbar=no",
"location=yes",
"personalbar=no",
"status=yes",
"resizable=yes",
"scrollbars=yes",
"minimizable=yes"
].join( "," ) );
e.preventDefault();
});

104 js/run.js
@@ -1,22 +1,22 @@
/**
* JavaScript file for the "run" page in the browser.
*
* @author John Resig, 2008-2011
* @author Timo Tijhof, 2012
* @author John Resig
* @author Timo Tijhof
* @since 0.1.0
* @package TestSwarm
*/
(function ( $, SWARM, undefined ) {
(function( $, SWARM, undefined ) {
var currRunId, currRunUrl, testTimeout, pauseTimer, cmds, errorOut;

function msg( htmlMsg ) {
$( '#msg' ).html( htmlMsg );
$( "#msg" ).html( htmlMsg );
}

function log( htmlMsg ) {
$( '#history' ).prepend( '<li><strong>' +
new Date().toString().replace( /^\w+ /, '' ).replace( /:[^:]+$/, '' ) +
':</strong> ' + htmlMsg + '</li>'
$( "#history" ).prepend( "<li><strong>" +
new Date().toString().replace( /^\w+ /, "" ).replace( /:[^:]+$/, "" ) +
":</strong> " + htmlMsg + "</li>"
);

msg( htmlMsg );
@@ -26,15 +26,15 @@
* Softly validate the SWARM object
*/
if ( !SWARM.client_id || !SWARM.conf ) {
$( function () {
msg( 'Error: No client id configured! Aborting.' );
$( function() {
msg( "Error: No client id configured! Aborting." );
});
return;
}

errorOut = 0;
cmds = {
reload: function () {
reload: function() {
window.location.reload();
}
};
@@ -50,44 +50,44 @@
cmds.reload();
} else {
errorOut += 1;
errMsg = errMsg ? (' (' + errMsg + ')') : '';
msg( 'Error connecting to server' + errMsg + ', retrying...' );
errMsg = errMsg ? (" (" + errMsg + ")") : "";
msg( "Error connecting to server" + errMsg + ", retrying..." );
setTimeout( retry, SWARM.conf.client.saveRetrySleep * 1000 );
}
}

$.ajax({
type: 'POST',
url: SWARM.conf.web.contextpath + 'api.php',
type: "POST",
url: SWARM.conf.web.contextpath + "api.php",
timeout: SWARM.conf.client.saveReqTimeout * 1000,
cache: false,
data: query,
dataType: 'json',
success: function ( data ) {
dataType: "json",
success: function( data ) {
if ( !data || data.error ) {
error( data.error.info );
} else {
errorOut = 0;
ok.apply( this, arguments );
}
},
error: function () {
error: function() {
error();
}
});
}

function getTests() {
if ( currRunId === undefined ) {
log( 'Connected to the swarm.' );
log( "Connected to the swarm." );
}

currRunId = 0;
currRunUrl = false;

msg( 'Querying for tests to run...' );
msg( "Querying for tests to run..." );
retrySend( {
action: 'getrun',
action: "getrun",
client_id: SWARM.client_id,
run_token: SWARM.run_token
}, getTests, runTests );
@@ -99,30 +99,30 @@
testTimeout = 0;
}

$( 'iframe' ).remove();
$( "iframe" ).remove();
}

function testTimedout( runInfo ) {
cancelTest();
retrySend(
{
action: 'saverun',
action: "saverun",
fail: 0,
error: 0,
total: 0,
status: 3, // ResultAction::STATE_ABORTED
report_html: 'Test Timed Out.',
report_html: "Test Timed Out.",
run_id: currRunId,
client_id: SWARM.client_id,
run_token: SWARM.run_token,
results_id: runInfo.resultsId,
results_store_token: runInfo.resultsStoreToken
},
function () {
function() {
testTimedout( runInfo );
},
function ( data ) {
if ( data.saverun === 'ok' ) {
function( data ) {
if ( data.saverun === "ok" ) {
SWARM.runDone();
} else {
getTests();
@@ -135,14 +135,14 @@
* @param data Object: Reponse from api.php?action=getrun
*/
function runTests( data ) {
var norun_msg, timeLeft, runInfo, params, iframe;
var norun_msg, timeLeft, runInfo, iframe;

if ( !$.isPlainObject( data ) || data.error ) {
// Handle session timeout, where server sends back "Username required."
// Handle TestSwarm reset, where server sends back "Client doesn't exist."
if ( data.error ) {
$(function () {
msg( 'action=getrun failed. ' + $( '<div>' ).text( data.error.info ).html() );
$(function() {
msg( "action=getrun failed. " + $( "<div>" ).text( data.error.info ).html() );
});
return;
}
@@ -156,18 +156,18 @@
currRunId = runInfo.id;
currRunUrl = runInfo.url;

log( 'Running ' + ( runInfo.desc || '' ) + ' tests...' );
log( "Running " + ( runInfo.desc || "" ) + " tests..." );

iframe = document.createElement( 'iframe' );
iframe = document.createElement( "iframe" );
iframe.width = 1000;
iframe.height = 600;
iframe.className = 'test-runner-frame';
iframe.src = currRunUrl + (currRunUrl.indexOf( '?' ) > -1 ? '&' : '?') + $.param({
iframe.className = "test-runner-frame";
iframe.src = currRunUrl + (currRunUrl.indexOf( "?" ) > -1 ? "&" : "?") + $.param({
// Cache buster
'_' : new Date().getTime(),
"_" : new Date().getTime(),
// Homing signal for inject.js so that it can find its target for action=saverun
'swarmURL' : window.location.protocol + '//' + window.location.host + SWARM.conf.web.contextpath +
'index.php?' +
"swarmURL" : window.location.protocol + "//" + window.location.host + SWARM.conf.web.contextpath +
"index.php?" +
$.param({
status: 2, // ResultAction::STATE_FINISHED
run_id: currRunId,
@@ -178,10 +178,10 @@
})
});

$( '#iframes' ).append( iframe );
$( "#iframes" ).append( iframe );

// Timeout after a period of time
testTimeout = setTimeout( function () {
testTimeout = setTimeout( function() {
testTimedout( runInfo );
}, SWARM.conf.client.runTimeout * 1000 );

@@ -195,7 +195,7 @@
// optionally replacing the message by data.timeoutMsg
clearTimeout( pauseTimer );

norun_msg = data.timeoutMsg || 'No new tests to run.';
norun_msg = data.timeoutMsg || "No new tests to run.";

msg( norun_msg );

@@ -204,7 +204,7 @@
timeLeft = currRunUrl ? SWARM.conf.client.cooldownSleep : SWARM.conf.client.nonewrunsSleep;

pauseTimer = setTimeout(function leftTimer() {
msg(norun_msg + ' Getting more in ' + timeLeft + ' seconds.' );
msg(norun_msg + " Getting more in " + timeLeft + " seconds." );
if ( timeLeft >= 1 ) {
timeLeft -= 1;
pauseTimer = setTimeout( leftTimer, 1000 );
@@ -220,31 +220,31 @@
// so that when inject.js does a <form> submission,
// it can call this from within the frame
// as window.parent.SWARM.runDone();
SWARM.runDone = function () {
SWARM.runDone = function() {
cancelTest();
runTests({ timeoutMsg: 'Cooling down.' });
runTests({ timeoutMsg: "Cooling down." });
};

function handleMessage(e) {
e = e || window.event;
retrySend( e.data, function () {
retrySend( e.data, function() {
handleMessage(e);
}, SWARM.runDone );
}

function confUpdate() {
$.ajax({
type: 'POST',
url: SWARM.conf.web.contextpath + 'api.php',
type: "POST",
url: SWARM.conf.web.contextpath + "api.php",
timeout: SWARM.conf.client.saveReqTimeout * 1000,
cache: false,
data: {
action: 'ping',
action: "ping",
client_id: SWARM.client_id,
run_token: SWARM.run_token
},
dataType: 'json'
}).done( function ( data ) {
dataType: "json"
}).done( function( data ) {
// Handle configuration update
if ( data.ping && data.ping.confUpdate ) {
// Refresh control
@@ -255,7 +255,7 @@

$.extend( SWARM.conf, data.ping.confUpdate );
}
}).always( function () {
}).always( function() {
setTimeout( confUpdate, SWARM.conf.client.pingTime * 1000 );
});
}
@@ -265,12 +265,12 @@
* Bind
*/
if ( window.addEventListener ) {
window.addEventListener( 'message', handleMessage, false );
window.addEventListener( "message", handleMessage, false );
} else if ( window.attachEvent ) {
window.attachEvent( 'onmessage', handleMessage );
window.attachEvent( "onmessage", handleMessage );
}

$( function () {
$( function() {
getTests();
confUpdate();
});
@@ -1,78 +1,78 @@
/**
* JavaScript file for all Pages.
* JavaScript file for all pages.
*
* @author John Resig, 2008-2011
* @author Timo Tijhof, 2012
* @author John Resig
* @author Timo Tijhof
* @since 0.1.0
* @package TestSwarm
*/
jQuery(function ( $ ) {
jQuery(function( $ ) {
var query = {},
search = window.location.search;

// Skip leading '?'
// Skip leading "?""
if ( search.length > 1 ) {
$.each( search.slice( 1 ).split( '&' ), function ( i, parts ) {
parts = parts.replace( /^([^=]+)=(.*)$/, function ( p0, p1, p2 ) {
$.each( search.slice( 1 ).split( "&" ), function( i, parts ) {
parts = parts.replace( /^([^=]+)=(.*)$/, function( p0, p1, p2 ) {
query[ decodeURIComponent( p1 ) ] = decodeURIComponent( p2 );
} );
});
});
}

if ( $.fn.prettyDate ) {
$( '.pretty' ).prettyDate();
$( ".pretty" ).prettyDate();
}

if ( SWARM.auth ) {
$( '.swarm-logout-link' ).on( 'click', function ( e ) {
$( '<form>', {
$( ".swarm-logout-link" ).on( "click", function( e ) {
$( "<form>", {
action: SWARM.conf.web.contextpath,
method: 'POST',
css: { display: 'none' }
method: "POST",
css: { display: "none" }
})
.append(
$( '<input type="hidden"/>' ).prop({ name: 'action', value: 'logout' }),
$( '<input type="hidden"/>' ).prop({ name: 'authID', value: SWARM.auth.project.id }),
$( '<input type="hidden"/>' ).prop({ name: 'authToken', value: SWARM.auth.sessionToken })
$( "<input type='hidden'/>" ).prop({ name: "action", value: "logout" }),
$( "<input type='hidden'/>" ).prop({ name: "authID", value: SWARM.auth.project.id }),
$( "<input type='hidden'/>" ).prop({ name: "authToken", value: SWARM.auth.sessionToken })
)
.appendTo( 'body' )
.appendTo( "body" )
.submit();

e.preventDefault();
});
}

$( '.swarm-form-join [name="item"]' ).each( function () {
$( ".swarm-form-join [name='item']" ).each( function() {
var el = this;
$( el ).on( 'input change', function () {
$( el ).on( "input change", function() {
if ( el.value && el.checkValidity && !el.checkValidity() && el.setCustomValidity ) {
// Override the error message that is displayed when the field is non-empty
// and didn't pass validation, defaults to "Did not match pattern" which is not
// useful as the user doesn't know the pattern.
el.setCustomValidity(
'Names should be no longer than 128 characters.'
"Names should be no longer than 128 characters."
);
} else {
el.setCustomValidity( '' );
el.setCustomValidity( "" );
}
});
$([ el, el.form ]).on( 'blur submit', function () {
$([ el, el.form ]).on( "blur submit", function() {
if ( !el.value ) {
el.value = 'anonymous';
el.value = "anonymous";
}
});
} );
});

$( document ).on( 'click', '.swarm-toggle', function () {
$( document ).on( "click", ".swarm-toggle", function() {
var key,
toggleQuery = $( this ).data( 'toggle-query' );
toggleQuery = $( this ).data( "toggle-query" );
for ( key in toggleQuery ) {
if ( query[key] !== undefined && ( toggleQuery[key] === null || toggleQuery[key] === null ) ) {
delete query[key];
} else {
query[key] = toggleQuery[key];
}
}
window.location.search = '?' + $.param( query );
window.location.search = "?" + $.param( query );
});
});