From 75c350976ce4d325daf3ebd3dedde9e05b2912a4 Mon Sep 17 00:00:00 2001 From: Antony Lesuisse Date: Mon, 17 Feb 2014 01:01:50 +0100 Subject: [PATCH] [FIX] tests HttpCase phantomjs conditional injection inject=[(need,file)] bzr revid: al@openerp.com-20140217000150-wt3pwqrqcd7n2mfd --- openerp/tests/phantomtest.js | 37 +++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/openerp/tests/phantomtest.js b/openerp/tests/phantomtest.js index e1cbbf735de..669bd00ec42 100644 --- a/openerp/tests/phantomtest.js +++ b/openerp/tests/phantomtest.js @@ -25,7 +25,7 @@ function waitFor (ready, callback, timeout, timeoutMessageCallback) { function PhantomTest() { var self = this; 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.origin = 'http://localhost'; this.origin += this.options.port ? ':' + this.options.port : ''; @@ -60,20 +60,27 @@ function PhantomTest() { }; this.page.onLoadFinished = function(status) { if (status === "success") { - var src, test; for (var k in self.inject) { - if (typeof self.inject[k] !== "string") { - test = self.page.evaluate(function (variable) { - try { return eval("("+variable+")") != null; } - catch (e) { return false; } - }, self.inject[k][0]); - src = self.inject[k][1]; - } else { - src = self.inject[k]; - test = true; + var found = false; + var v = self.inject[k]; + var need = v; + var src = v; + if (v[0]) { + need = v[0]; + src = v[1]; + found = self.page.evaluate(function(code) { + try { + return !!eval(code); + } catch (e) { + return false; + } + }, need); } - if(test && !page.injectJs(src)) { - self.error("Can't inject " + src); + if(!found) { + console.log('Injecting', src, 'needed for', need); + if(!self.page.injectJs(src)) { + self.error("Cannot inject " + src); + } } } } @@ -112,8 +119,8 @@ function PhantomTest() { try { r = !!eval(ready); } catch(ex) { - console.log("waiting for " + ready) - }; + console.log("waiting for " + ready); + } return r; }, ready); // run test