aboutsummaryrefslogtreecommitdiff
path: root/src/js
diff options
context:
space:
mode:
authorGravatar Rogan Creswick <creswick@gmail.com>2013-06-13 12:06:09 -0700
committerGravatar Rogan Creswick <creswick@gmail.com>2013-06-13 12:06:09 -0700
commit0dcf39a7de6ddb09011e25ec5a1a6ebcff2f1fc5 (patch)
tree89bbccaba73c35bfec1f4c108d92d66d56a63ef9 /src/js
parent9683b9b075ce96ba0477f7ee746246dba178c25e (diff)
added more semantically rich tests to headless test, and fixed the bugs that those revealed re: the new rule/ruleset formats
Diffstat (limited to 'src/js')
-rw-r--r--src/js/fiveui/injected/compute.js41
-rw-r--r--src/js/selenium/selenium-injected-compute.js16
2 files changed, 43 insertions, 14 deletions
diff --git a/src/js/fiveui/injected/compute.js b/src/js/fiveui/injected/compute.js
index 8efc8f7..4d76335 100644
--- a/src/js/fiveui/injected/compute.js
+++ b/src/js/fiveui/injected/compute.js
@@ -88,9 +88,10 @@
core.port.emit('ReportStats', stats);
};
- core.hash = function(rule, name, node) {
+ core.hash = function(rule, message, node) {
var prob = {
- name: name,
+ name: rule.name,
+ msg: message,
descr: rule.description,
url: window.location.href,
severity: 1,
@@ -195,7 +196,12 @@
/* END of BSD licensed code */
+ /**
+ * @param {!Array.<Rule>} rs A list of Rule objects.
+ */
core.evaluate = function(rs) {
+ console.log("in evaluate");
+ console.log(rs);
var theRule = null;
var date = new Date();
var stats =
@@ -206,8 +212,8 @@
};
fiveui.stats.numElts = 0; // reset stats element counter
- var report = function(name, node) {
- var prob = core.hash(theRule, name, node);
+ var report = function(message, node) {
+ var prob = core.hash(theRule, message, node);
var query = $(node);
if(!query.hasClass(prob.hash)) {
query.addClass(prob.hash);
@@ -225,6 +231,8 @@
report: report
};
+ console.log("theRule.rule");
+ console.log(theRule.rule);
if (theRule.rule) {
try {
// note: fiveui.stats.numElts is updated as a side effect here
@@ -289,25 +297,38 @@
};
var registerBackendListeners = function(port) {
- port.on('SetRules', function(payload) {
+ var assembleRules = function(ruleStrList) {
+ var ruleList = [];
- core.rules = [];
-
- for(var i=0; i<payload.length; ++i) {
+ for(var i=0; i<ruleStrList.length; ++i) {
var moduleStr =
[ '(function(){'
, 'var exports = {};'
- , payload[i]
+ , ruleStrList[i]
, 'return exports;'
, '})()'
].join('\n');
- core.rules.push(eval(moduleStr));
+ console.log("built module string for i="+i);
+ console.log(moduleStr);
+ var evaled = eval(moduleStr);
+ ruleList.push(evaled);
}
+ return ruleList;
+ };
+
+ port.on('SetRules', function(payload) {
+ core.rules = assembleRules(payload);
core.scheduleRules();
registerDomListeners(document);
});
+
+ port.on('ForceEval', function(ruleStrList){
+ var ruleList = assembleRules(ruleStrList);
+ console.log(ruleList);
+ core.evaluate(ruleList);
+ });
};
registerBackendListeners(core.port);
diff --git a/src/js/selenium/selenium-injected-compute.js b/src/js/selenium/selenium-injected-compute.js
index dd208be..e6a8b59 100644
--- a/src/js/selenium/selenium-injected-compute.js
+++ b/src/js/selenium/selenium-injected-compute.js
@@ -19,11 +19,13 @@
* limitations under the License.
*/
+
+
/**
* @return {{on: function(!string, function(*)), emit: function(!string, *)}}
*/
var obtainComputePort = function() {
- fiveui.selPort = new fiveui.SeleniumPort();
+
return fiveui.selPort;
};
@@ -61,7 +63,8 @@ fiveui.SeleniumPort.prototype.emit = function(evt, obj) {
* Send a message to the injected script.
*
* @param {!string} evt The event to fire.
- * @param {?Object} obj The data to associate with the event.
+ * @param {?Array.<string>} obj The data to associate with the event
+ * (an array of strings, each representing a JS module)
*/
fiveui.SeleniumPort.prototype.send = function(evt, obj) {
if (this._events[evt]) {
@@ -81,8 +84,7 @@ fiveui.SeleniumPort.prototype.query = function (type) {
if (!type) {
msgs = this._messages;
- }
- else {
+ } else {
for (i=0; i < this._messages.length; i += 1) {
console.log(this._messages);
if (this._messages[i].type === type) {
@@ -97,3 +99,9 @@ fiveui.SeleniumPort.prototype.query = function (type) {
// return the new messages to the backend:
return msgs;
};
+
+// Define a port at the top level, so multiple contexts can access it.
+fiveui.selPort = new fiveui.SeleniumPort();
+// fiveui.selPort.emit('ReportProblem', {name: 'foo'});
+
+// this._messages = [{type: 'ReportProblem', payload: {name: 'bork'}}];