Created
July 24, 2012 00:49
-
-
Save zacharyc/3167226 to your computer and use it in GitHub Desktop.
Crazy Loading of Screening.js Problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log('############ running connect.js', a, Screening, Screening.launchApp()); | |
var testWindow = window.open('', 'slave'); | |
driver.switchTo().window('slave'); | |
console.log(Screening); | |
driver.get('http://www.google.com'); | |
driver.findElement(webdriver.By.name('q')).sendKeys('webdriver'); | |
driver.findElement(webdriver.By.name('btnG')).click().then(function() { | |
driver.getTitle().then(function(title) { | |
if (title !== 'webdriver - Google Search') { | |
console.log('attemtping to send out a message'); | |
var event = document.createEvent("CustomEvent"); | |
event.initCustomEvent("serverMessage", true, false); | |
event.screeningType = "error"; | |
event.screeningContent = "Titles did not match"; | |
document.dispatchEvent(event); | |
// throw new Error( | |
// 'Expected "webdriver - Google Search", but was "' + title + '"'); | |
} | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
loading director director.js:1 | |
Uncaught ReferenceError: Screening is not defined director.js:51 | |
Should be empty: [] :8081/node_modules/montage/core/promise.js:693 | |
initializing director | |
Session Id: 1341941981967 | |
Director, script name is: TODOz main.reel/main.js:64 | |
outside eval | |
Function | |
foo main.reel/main.js:67 | |
retreiving server file: connect.js main.reel/main.js:97 | |
right before eval | |
Function | |
function (url) { | |
console.log('trying to launch an app'); | |
} main.reel/main.js:70 | |
############ running connect.js foo | |
Function | |
function (url) { | |
console.log('trying to launch an app'); | |
} | |
Function | |
attemtping to send out a message | |
got a server message | |
__FILE__http______localhost__8081__node_modules__montage__core__event__mutable__event__.exports.MutableEvent.Montage.create.fromEvent.value.constructor | |
error Titles did not match |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* <copyright> | |
This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | |
No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | |
(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | |
</copyright> */ | |
var Montage = require("montage/core/core").Montage, | |
Component = require("montage/ui/component").Component, | |
Screening = require('/director/js/screening.js').Screening; | |
exports.Main = Montage.create(Component, { | |
socket: { | |
value: null | |
}, | |
prepareForDraw: { | |
value: function() { | |
var self = this; | |
// Add Event Listeners | |
window.addEventListener("message", self._receiveMessage, false); | |
window.addEventListener("message", function(event) {console.log('boo');}); | |
document.addEventListener("serverMessage", this, false); | |
} | |
}, | |
templateDidLoad: { | |
value: function() { | |
this.init(); | |
} | |
}, | |
_documentAddress: { | |
value: "http://" + document.domain + ":" + document.location.port | |
}, | |
init: { | |
enumerable: false, | |
value: function() { | |
var self = this; | |
this.socket = io.connect(self._documentAddress, { resource: "socket.io" }); | |
this._initDirector(); | |
this.socket.on("reconnect", function() { | |
self._initDriver(); | |
}); | |
} | |
}, | |
_initDirector: { | |
value: function() { | |
var self = this; | |
// this._getFileFromServer("connect.js", false); | |
this.socket.emit("initDirector", function() { | |
// TODOz: code needs to be here | |
}); | |
window.connectDirector(); | |
// console.log("Director, serverIp is:", serverIp); | |
// console.log("Director, sessionId is:", sessionId); | |
console.log("Director, script name is: TODOz"); | |
window.a = 'foo'; | |
console.log('outside eval', Screening, a); | |
// Get the script | |
this._getFileFromServer("connect.js", false, function(script) { | |
console.log('right before eval', Screening, Screening.launchApp); | |
//var s = 'function('+Screening+', launchAppFunction) {' + script + '}();'; | |
eval(script); | |
//eval(s); | |
}); | |
} | |
}, | |
handlePingAction: { | |
value: function() { | |
console.log('foo'); | |
this.socket.emit("serverPing"); | |
} | |
}, | |
handleServerMessage: { | |
value: function(event) { | |
console.log('got a server message', event, event.screeningType, event.screeningContent); | |
var msg = {}; | |
msg.type = event.screeningType; | |
msg.content = event.screeningContent; | |
this.socket.emit("screeningReport", JSON.stringify(msg)); | |
} | |
}, | |
_getFileFromServer: { | |
value: function(filename, root, callback) { | |
console.log('retreiving server file: ', filename); | |
var req = new XMLHttpRequest(); | |
// serverIp has been previously defined | |
if(root) { | |
req.open("GET", this._documentAddress + filename, true); | |
} else { | |
req.open("GET", this._documentAddress + "/director/js/" + filename, true); | |
} | |
req.setRequestHeader("Content-Type", "application/javascript"); | |
req.onreadystatechange = function(aEvt) { | |
if(req.readyState == 4 && req.status >= 200) { | |
if(callback) { | |
callback(req.response); | |
} else { | |
console.log('no callback'); | |
} | |
req.onreadystatechange = null; | |
} | |
}; | |
req.send(); | |
} | |
}, | |
_receiveMessage: { | |
value: function(event) { | |
console.log('got a message', event); | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.Screening = Object.create(Object, { | |
launchApp: { | |
value: function(url) { | |
console.log('trying to launch an app'); | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_initDirector: { | |
value: function() { | |
var self = this; | |
// this._getFileFromServer("connect.js", false); | |
this.socket.emit("initDirector", function() { | |
// TODOz: code needs to be here | |
}); | |
window.connectDirector(); | |
// console.log("Director, serverIp is:", serverIp); | |
// console.log("Director, sessionId is:", sessionId); | |
console.log("Director, script name is: TODOz"); | |
window.a = 'foo'; | |
console.log('outside eval', Screening, a); | |
// Get the script | |
this._getFileFromServer("connect.js", false, function(script) { | |
var myTest = 'blue'; | |
var sMinor = Screening; | |
var l = Screening.launchApp; | |
console.log('right before eval', Screening, Screening.launchApp); | |
//var s = 'function('+Screening+', launchAppFunction) {' + script + '}();'; | |
//(0,eval)(script); | |
eval(script); | |
//eval(s); | |
}); | |
} | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment