Permalink
Browse files

Redesigned code that loads a url in a window's session.

  • Loading branch information...
1 parent 7958375 commit 20a773177a73fc65fef998100330e11223811dbe @detro committed Aug 3, 2012
Showing with 19 additions and 27 deletions.
  1. +17 −26 src/request_handlers/session_request_handler.js
  2. +2 −1 src/session.js
@@ -391,35 +391,26 @@ ghostdriver.SessionReqHand = function(session) {
_postUrlCommand = function(req, res) {
// Load the given URL in the Page
var postObj = JSON.parse(req.post),
- pageOpenTimeout = _session.getTimeout(_session.timeoutNames().PAGE_LOAD),
- pageOpenTimedout = false,
- timer;
+ pageOpenTimeout = _session.getTimeout(_session.timeoutNames().PAGE_LOAD);
if (typeof(postObj) === "object" && postObj.url) {
// Open the given URL and, when done, return "HTTP 200 OK"
- _session.getCurrentWindow().open(postObj.url, function(status) {
- if (!pageOpenTimedout) {
- // Callback received: don't need the timer anymore
- clearTimeout(timer);
-
- if (status === "success") {
- res.success(_session.getId());
- } else {
- _errors.handleInvalidReqInvalidCommandMethodEH(req, res);
- }
- }
- });
- timer = setTimeout(function() {
- // Command Failed (Timed-out)
- pageOpenTimedout = true;
- _errors.handleFailedCommandEH(
- _errors.FAILED_CMD_STATUS.TIMEOUT,
- "URL '"+postObj.url+"' didn't load within "+pageOpenTimeout+"ms",
- req,
- res,
- _session,
- "SessionReqHand");
- }, pageOpenTimeout);
+ _session.getCurrentWindow().evaluateAndWaitForLoad(
+ function(url) {
+ window.location.assign(url);
+ },
+ function() {
+ res.success(_session.getId());
+ },
+ function() {
+ _errors.handleFailedCommandEH(
+ _errors.FAILED_CMD_STATUS.TIMEOUT,
+ "URL '"+postObj.url+"' didn't load within "+pageOpenTimeout+"ms",
+ req,
+ res,
+ _session,
+ "SessionReqHand");
+ }, postObj.url);
} else {
throw _errors.createInvalidReqMissingCommandParameterEH(req);
}
View
@@ -95,7 +95,6 @@ ghostdriver.Session = function(desiredCapabilities) {
// We are ready to Eval
this.evaluateAsync.apply(this, args);
-
},
_setOneShotCallbackDecorator = function(callbackName, handlerFunc) {
@@ -135,6 +134,8 @@ ghostdriver.Session = function(desiredCapabilities) {
// 4. Remove every closing page
page.onClosing = _deleteClosingPage;
+ // page.onConsoleMessage = function(msg) { console.log(msg); };
+
return page;
},

0 comments on commit 20a7731

Please sign in to comment.