Skip to content

Commit

Permalink
- Fix a typo in nsCommandProcessor
Browse files Browse the repository at this point in the history
- Clean-up/add comments to webLoadingListener so it is easier to follow
  • Loading branch information
jleyba committed Jan 8, 2014
1 parent d5ef371 commit 1eaebcd
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
2 changes: 1 addition & 1 deletion javascript/firefox-driver/js/nsCommandProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ DelayedCommand.prototype.execute = function(ms) {
*/
DelayedCommand.prototype.shouldDelayExecutionForPendingRequest_ = function() {
var loadStrategy = Utils.getPageLoadingStrategy();
if ('unstable' == loadStrategy || 'eager' == loadStrategy && 'none' == loadStrategy) {
if ('unstable' == loadStrategy || 'eager' == loadStrategy || 'none' == loadStrategy) {
return false;
}

Expand Down
43 changes: 35 additions & 8 deletions javascript/firefox-driver/js/webLoadingListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,18 @@ ImpatientListener.prototype.onProgressChange = function(webProgress) {
};


var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces['nsIPrefBranch']);
var prefs = Components.classes['@mozilla.org/preferences-service;1']
.getService(Components.interfaces['nsIPrefBranch']);

/**
* Builds a nsIWebProgressListener for the given browser.
* @param {!nsIWebProgress} browser The browser window to listen to for load
* events.
* @param {function(boolean)} toCall The function to call when listener detects
* that the browser has finished loading.
* @param {Window=} opt_window The DOM window being watched.
* @return {!nsIWebProgressListener} The new listener.
*/
function buildHandler(browser, toCall, opt_window) {
var strategy = Utils.getPageLoadingStrategy();
if ('normal' == strategy) {
Expand All @@ -173,13 +183,22 @@ function buildHandler(browser, toCall, opt_window) {
return new ImpatientListener(browser, toCall, opt_window);
}

fxdriver.logging.warn('Unsupported page loading strategy: ' + strategy);
fxdriver.logging.warning('Unsupported page loading strategy: ' + strategy);
// Fall back to 'normal' strategy
return new PatientListener(browser, toCall, opt_window);
}

var loadingListenerTimer;

/**
* @param {!nsIWebProgress} browser The browser window to listen to for load
* events.
* @param {function(boolean)} toCall The function to call when either the
* timeout expires or the browser finishes loading.
* @param {number} timeout The timeout to use, in milliseconds.
* @param {Window=} opt_window The DOM window being watched.
* @constructor
*/
WebLoadingListener = function(browser, toCall, timeout, opt_window) {
var strategy = Utils.getPageLoadingStrategy();
if ('none' == strategy) {
Expand All @@ -188,23 +207,31 @@ WebLoadingListener = function(browser, toCall, timeout, opt_window) {
}

loadingListenerTimer = new fxdriver.Timer();
var func = function(timedOut) { loadingListenerTimer.cancel(); toCall(timedOut); };
var func = function(timedOut) {
loadingListenerTimer.cancel();
toCall(timedOut);
};

/** @type {!nsIWebProgressListener} */
this.handler = buildHandler(browser, func, opt_window);
browser.addProgressListener(this.handler);
var handler = this.handler;

browser.addProgressListener(this.handler);
if (timeout == -1) {
timeout = 1000 * 60 * 30; // 30 minutes is a loooong time.
}

var handler = this.handler;
loadingListenerTimer.setTimeout(function() {
WebLoadingListener.removeListener(browser, handler);
browser.removeProgressListener(handler);
func(true);
}, timeout);
};


/**
* Removes a progress listener from the given browser.
* @param {!nsIWebProgress} browser The browser to remove a listener from.
* @param {!WebLoadingListener} listener The listener to remove.
*/
WebLoadingListener.removeListener = function(browser, listener) {
browser.removeProgressListener(listener);
browser.removeProgressListener(listener.handler);
};

0 comments on commit 1eaebcd

Please sign in to comment.