Skip to content

Commit

Permalink
Extracting a utility method to set WebLoadingListener
Browse files Browse the repository at this point in the history
  • Loading branch information
barancev committed Jan 11, 2014
1 parent f3acfca commit fff83ad
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 29 deletions.
32 changes: 3 additions & 29 deletions javascript/firefox-driver/js/firefoxDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,7 @@ FirefoxDriver.prototype.get = function(respond, parameters) {
}

if (loadEventExpected) {
var browser = respond.session.getBrowser();
var topWindow = browser.contentWindow;
new WebLoadingListener(browser, function(timedOut) {
// Focus on the top window.
respond.session.setWindow(topWindow);
if (timedOut) {
browser.stop();
respond.sendError(new WebDriverError(bot.ErrorCode.TIMEOUT,
'Timed out waiting for page load.'));
} else {
respond.value = '';
respond.send();
}
}, respond.session.getPageLoadTimeout(), respond.session.getWindow());
Utils.initWebLoadingListener(respond, respond.session.getWindow());
}

respond.session.getBrowser().loadURI(url);
Expand Down Expand Up @@ -672,21 +659,8 @@ FirefoxDriver.prototype.goForward = function(respond) {

FirefoxDriver.prototype.refresh = function(respond) {
var browser = respond.session.getBrowser();
var topWindow = browser.contentWindow;
// Wait for the reload to finish before sending the response.
new WebLoadingListener(browser, function(timedOut) {
// Reset to the top window.
respond.session.setWindow(topWindow);
if (timedOut) {
browser.stop();
respond.sendError(new WebDriverError(bot.ErrorCode.TIMEOUT,
'Timed out waiting for page load.'));
} else {
respond.send();
}
}, respond.session.getPageLoadTimeout(), respond.session.getWindow());

topWindow.location.reload(true);
Utils.initWebLoadingListener(respond, browser.contentWindow);
browser.contentWindow.location.reload(true);
};


Expand Down
18 changes: 18 additions & 0 deletions javascript/firefox-driver/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,24 @@ Utils.getPageLoadingStrategy = function() {
prefs.getCharPref('webdriver.load.strategy') : 'normal';
};

Utils.initWebLoadingListener = function(respond, opt_window) {
var browser = respond.session.getBrowser();
var topWindow = browser.contentWindow;
var window = opt_window || topWindow;
// Wait for the reload to finish before sending the response.
new WebLoadingListener(browser, function(timedOut) {
// Reset to the top window.
respond.session.setWindow(topWindow);
if (timedOut) {
browser.stop();
respond.sendError(new WebDriverError(bot.ErrorCode.TIMEOUT,
'Timed out waiting for page load.'));
} else {
respond.send();
}
}, respond.session.getPageLoadTimeout(), window);
};

Utils.type = function(doc, element, text, opt_useNativeEvents, jsTimer, releaseModifiers,
opt_keysState) {

Expand Down

0 comments on commit fff83ad

Please sign in to comment.