[FIX] tests HttpCase phantomjs conditional injection inject=[(need,file)]
bzr revid: al@openerp.com-20140217000150-wt3pwqrqcd7n2mfd
This commit is contained in:
parent
3c5f3bb04d
commit
75c350976c
|
@ -25,7 +25,7 @@ function waitFor (ready, callback, timeout, timeoutMessageCallback) {
|
||||||
function PhantomTest() {
|
function PhantomTest() {
|
||||||
var self = this;
|
var self = this;
|
||||||
this.options = JSON.parse(phantom.args[phantom.args.length-1]);
|
this.options = JSON.parse(phantom.args[phantom.args.length-1]);
|
||||||
this.inject = [];
|
this.inject = this.options.inject || [];
|
||||||
this.timeout = this.options.timeout ? Math.round(parseFloat(this.options.timeout)*1000 - 5000) : 10000;
|
this.timeout = this.options.timeout ? Math.round(parseFloat(this.options.timeout)*1000 - 5000) : 10000;
|
||||||
this.origin = 'http://localhost';
|
this.origin = 'http://localhost';
|
||||||
this.origin += this.options.port ? ':' + this.options.port : '';
|
this.origin += this.options.port ? ':' + this.options.port : '';
|
||||||
|
@ -60,20 +60,27 @@ function PhantomTest() {
|
||||||
};
|
};
|
||||||
this.page.onLoadFinished = function(status) {
|
this.page.onLoadFinished = function(status) {
|
||||||
if (status === "success") {
|
if (status === "success") {
|
||||||
var src, test;
|
|
||||||
for (var k in self.inject) {
|
for (var k in self.inject) {
|
||||||
if (typeof self.inject[k] !== "string") {
|
var found = false;
|
||||||
test = self.page.evaluate(function (variable) {
|
var v = self.inject[k];
|
||||||
try { return eval("("+variable+")") != null; }
|
var need = v;
|
||||||
catch (e) { return false; }
|
var src = v;
|
||||||
}, self.inject[k][0]);
|
if (v[0]) {
|
||||||
src = self.inject[k][1];
|
need = v[0];
|
||||||
} else {
|
src = v[1];
|
||||||
src = self.inject[k];
|
found = self.page.evaluate(function(code) {
|
||||||
test = true;
|
try {
|
||||||
|
return !!eval(code);
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}, need);
|
||||||
}
|
}
|
||||||
if(test && !page.injectJs(src)) {
|
if(!found) {
|
||||||
self.error("Can't inject " + src);
|
console.log('Injecting', src, 'needed for', need);
|
||||||
|
if(!self.page.injectJs(src)) {
|
||||||
|
self.error("Cannot inject " + src);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -112,8 +119,8 @@ function PhantomTest() {
|
||||||
try {
|
try {
|
||||||
r = !!eval(ready);
|
r = !!eval(ready);
|
||||||
} catch(ex) {
|
} catch(ex) {
|
||||||
console.log("waiting for " + ready)
|
console.log("waiting for " + ready);
|
||||||
};
|
}
|
||||||
return r;
|
return r;
|
||||||
}, ready);
|
}, ready);
|
||||||
// run test
|
// run test
|
||||||
|
|
Loading…
Reference in New Issue