Index: /quintagroup.plonetabs/trunk/README.txt
===================================================================
--- /quintagroup.plonetabs/trunk/README.txt (revision 883)
+++ /quintagroup.plonetabs/trunk/README.txt (revision 884)
@@ -41,4 +41,6 @@
after that install quintagroup.plonetabs package.
+* 'How to run js/kss/selenium tests' instruction will be here...
+
Authors
Index: /quintagroup.plonetabs/trunk/quintagroup/plonetabs/configure.zcml
===================================================================
--- /quintagroup.plonetabs/trunk/quintagroup/plonetabs/configure.zcml (revision 883)
+++ /quintagroup.plonetabs/trunk/quintagroup/plonetabs/configure.zcml (revision 884)
@@ -19,6 +19,8 @@
+
+
Index: /quintagroup.plonetabs/trunk/quintagroup/plonetabs/overrides.zcml
===================================================================
--- /quintagroup.plonetabs/trunk/quintagroup/plonetabs/overrides.zcml (revision 884)
+++ /quintagroup.plonetabs/trunk/quintagroup/plonetabs/overrides.zcml (revision 884)
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
Index: /quintagroup.plonetabs/trunk/quintagroup/plonetabs/tests/ecmaunits/__init__.py
===================================================================
--- /quintagroup.plonetabs/trunk/quintagroup/plonetabs/tests/ecmaunits/__init__.py (revision 884)
+++ /quintagroup.plonetabs/trunk/quintagroup/plonetabs/tests/ecmaunits/__init__.py (revision 884)
@@ -0,0 +1,1 @@
+#
Index: /quintagroup.plonetabs/trunk/quintagroup/plonetabs/tests/ecmaunits/configure-online.zcml
===================================================================
--- /quintagroup.plonetabs/trunk/quintagroup/plonetabs/tests/ecmaunits/configure-online.zcml (revision 884)
+++ /quintagroup.plonetabs/trunk/quintagroup/plonetabs/tests/ecmaunits/configure-online.zcml (revision 884)
@@ -0,0 +1,14 @@
+
+
+
+
+
+
Index: /quintagroup.plonetabs/trunk/quintagroup/plonetabs/tests/ecmaunits/ecmaview.py
===================================================================
--- /quintagroup.plonetabs/trunk/quintagroup/plonetabs/tests/ecmaunits/ecmaview.py (revision 884)
+++ /quintagroup.plonetabs/trunk/quintagroup/plonetabs/tests/ecmaunits/ecmaview.py (revision 884)
@@ -0,0 +1,21 @@
+import os
+from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
+from kss.core.tests.ecmaview import EcmaView as base
+
+def absolute_dir(path):
+ here = os.path.split(globals()['__file__'])[0]
+ return os.path.abspath(os.path.join(here, path))
+
+class EcmaView(base):
+ '''quintagroup.plonetabs js test view
+
+ This allows the runner.html to be used on this view.
+
+ This provides the tests run with the compiled kukit.js
+ resource, in the same way as they would be run
+ in production with kss.
+ '''
+
+ _testdir = absolute_dir('js')
+
+ _runner = ViewPageTemplateFile('js/runner.html')
Index: /quintagroup.plonetabs/trunk/quintagroup/plonetabs/tests/ecmaunits/js/ecmaunit-license.txt
===================================================================
--- /quintagroup.plonetabs/trunk/quintagroup/plonetabs/tests/ecmaunits/js/ecmaunit-license.txt (revision 884)
+++ /quintagroup.plonetabs/trunk/quintagroup/plonetabs/tests/ecmaunits/js/ecmaunit-license.txt (revision 884)
@@ -0,0 +1,31 @@
+Copyright (c) 2003-2004, EcmaUnit Contributors
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of EcmaUnit nor the names of its contributors may
+ be used to endorse or promote products derived from this
+ software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Index: /quintagroup.plonetabs/trunk/quintagroup/plonetabs/tests/ecmaunits/js/ecmaunit.js
===================================================================
--- /quintagroup.plonetabs/trunk/quintagroup/plonetabs/tests/ecmaunits/js/ecmaunit.js (revision 884)
+++ /quintagroup.plonetabs/trunk/quintagroup/plonetabs/tests/ecmaunits/js/ecmaunit.js (revision 884)
@@ -0,0 +1,491 @@
+/*****************************************************************************
+ *
+ * Copyright (c) 2003-2004 EcmaUnit Contributors. All rights reserved.
+ *
+ * This software is distributed under the terms of the EcmaUnit
+ * License. See LICENSE.txt for license text. For a list of EcmaUnit
+ * Contributors see CREDITS.txt.
+ *
+ *****************************************************************************/
+
+// $Id: ecmaunit.js 23620 2006-02-23 16:16:28Z guido $
+
+/*
+ Object-oriented prototype-based unit test suite
+*/
+
+function TestCase() {
+ /* a single test case */
+ this.name = 'TestCase';
+};
+
+TestCase.prototype.initialize = function(reporter) {
+ // this array's contents will be displayed when done (if it
+ // contains anything)
+ this._exceptions = new Array();
+ this._reporter = reporter;
+};
+
+TestCase.prototype.setUp = function() {
+ /* this will be called on before each test method that is ran */
+};
+
+TestCase.prototype.tearDown = function() {
+ /* this will be called after each test method that has been ran */
+};
+
+TestCase.prototype.assertEquals = function(var1, var2, message) {
+ /* assert whether 2 vars have the same value */
+ if (!message) {
+ message = '';
+ } else {
+ message = "'" + message + "' ";
+ }
+ if (var1 != var2 &&
+ (!(var1 instanceof Array && var2 instanceof Array) ||
+ !this._arrayDeepCompare(var1, var2))) {
+ this._throwException('Assertion ' + message + 'failed: ' +
+ var1 + ' != ' + var2);
+ };
+};
+
+TestCase.prototype.assertNotEquals = function(var1, var2, message) {
+ /* assert whether 2 vars have different values */
+ if (!message) {
+ message = '';
+ } else {
+ message = "'" + message + "' ";
+ }
+ if (var1 && var1.toSource && var2 && var2.toSource) {
+ if (var1.toSource() == var2.toSource()) {
+ this._throwException('Assertion ' + message + 'failed: ' +
+ var1 + ' == ' + var2);
+ };
+ } else {
+ if (var1 == var2) {
+ this._throwException('Assertion ' + message + 'failed: ' +
+ var1 + ' == ' + var2);
+ };
+ };
+};
+
+TestCase.prototype.debug = function(msg) {
+ this._reporter.debug(msg);
+}
+TestCase.prototype.assert = function(statement, message) {
+ /* assert whether a variable resolves to true */
+ if (!statement) {
+ if (!message) message = (statement && statement.toString) ?
+ statement.toString() : statement;
+ this._throwException('Assertion \'' + message + '\' failed');
+ };
+};
+
+TestCase.prototype.assertTrue = TestCase.prototype.assert;
+
+TestCase.prototype.assertFalse = function(statement, message) {
+ /* assert whether a variable resolves to false */
+ if (statement) {
+ if (!message) message = statement.toString ?
+ statement.toString() : statement;
+ this._throwException('AssertFalse \'' + message + '\' failed');
+ };
+};
+
+TestCase.prototype.assertThrows = function(func, exception, context) {
+ /* assert whether a certain exception is raised */
+ if (!context) {
+ context = null;
+ };
+ var exception_thrown = false;
+ // remove the first three args, they're the function's normal args
+ var args = [];
+ for (var i=3; i < arguments.length; i++) {
+ args.push(arguments[i]);
+ };
+ try {
+ func.apply(context, args);
+ } catch(e) {
+ // allow catching undefined exceptions too
+ if (exception === undefined) {
+ } else if (exception) {
+ var isinstance = false;
+ try {
+ if (e instanceof exception) {
+ isinstance = true;
+ };
+ } catch(f) {
+ };
+ if (!isinstance) {
+ if (exception.toSource && e.toSource) {
+ exception = exception.toSource();
+ e = e.toSource();
+ };
+ if (exception.toString && e.toString) {
+ exception = exception.toString();
+ e = e.toString();
+ };
+ if (e != exception) {
+ this._throwException('Function threw the wrong ' +
+ 'exception ' + e.toString() +
+ ', while expecting ' + exception.toString());
+ };
+ };
+ };
+ exception_thrown = true;
+ };
+ if (!exception_thrown) {
+ if (exception) {
+ this._throwException("function didn\'t raise exception \'" +
+ exception.toString() + "'");
+ } else {
+ this._throwException('function didn\'t raise exception');
+ };
+ };
+};
+
+TestCase.prototype.runTests = function() {
+ /* find all methods of which the name starts with 'test'
+ and call them */
+ var ret = this._runHelper();
+ this._reporter.summarize(ret[0], ret[1], this._exceptions);
+};
+
+TestCase.prototype._runHelper = function() {
+ /* this actually runs the tests
+ return value is an array [total tests ran, total time spent (ms)]
+ */
+ var now = new Date();
+ var starttime = now.getTime();
+ var numtests = 0;
+ for (var attr in this) {
+ if (attr.substr(0, 4) == 'test') {
+ this.setUp();
+ try {
+ this[attr]();
+ this._reporter.reportSuccess(this.name, attr);
+ } catch(e) {
+ var raw = e;
+ if (e && e.name && e.message) { // Microsoft
+ e = e.name + ': ' + e.message;
+ }
+ this._reporter.reportError(this.name, attr, e, raw);
+ this._exceptions.push(new Array(this.name, attr, e, raw));
+ };
+ this.tearDown();
+ numtests++;
+ };
+ };
+ var now = new Date();
+ var totaltime = now.getTime() - starttime;
+ return new Array(numtests, totaltime);
+};
+
+TestCase.prototype._throwException = function(message) {
+ var lineno = this._getLineNo();
+ if (lineno) {
+ message = 'line ' + lineno + ' - ' + message;
+ };
+ throw(message);
+};
+
+TestCase.prototype._getLineNo = function() {
+ /* tries to get the line no in Moz */
+ var stack = undefined;
+ try {notdefined()} catch(e) {stack = e.stack};
+ if (stack) {
+ stack = stack.toString().split('\n');
+ for (var i=0; i < stack.length; i++) {
+ var line = stack[i].split('@')[1];
+ if (line.indexOf('ecmaunit') == -1) {
+ // return the first line after we get out of ecmaunit
+ var chunks = line.split(':');
+ var lineno = chunks[chunks.length - 1];
+ if (lineno != '0') {
+ return lineno;
+ };
+ };
+ };
+ } else {
+ return false;
+ };
+};
+
+TestCase.prototype._arrayDeepCompare = function(a1, a2) {
+ if (!(a1 instanceof Array && a2 instanceof Array)) {
+ return false;
+ };
+ if (a1.length != a2.length) {
+ return false;
+ };
+ for (var i=0; i < a1.length; i++) {
+ if (a1[i] instanceof Array) {
+ if (!this._arrayDeepCompare(a1[i], a2[i])) {
+ return false;
+ };
+ } else if (a1[i] != a2[i]) {
+ return false;
+ };
+ };
+ return true;
+};
+
+function TestSuite(reporter) {
+ /* run a suite of tests */
+ if (reporter) {
+ this._reporter = reporter;
+ this._tests = new Array();
+ this._exceptions = new Array();
+ };
+};
+
+TestSuite.prototype.registerTest = function(test) {
+ /* register a test */
+ if (!test) {
+ throw('TestSuite.registerTest() requires a testcase as argument');
+ };
+ this._tests.push(test);
+};
+
+TestSuite.prototype.runSuite = function() {
+ /* run the suite */
+ var now = new Date();
+ var starttime = now.getTime();
+ var testsran = 0;
+ for (var i=0; i < this._tests.length; i++) {
+ var test = new this._tests[i]();
+ test.initialize(this._reporter);
+ testsran += test._runHelper()[0];
+ // the TestCase class handles output of dots and Fs, but we
+ // should take care of the exceptions
+ if (test._exceptions.length) {
+ for (var j=0; j < test._exceptions.length; j++) {
+ // attr, exc in the org array, so here it becomes
+ // name, attr, exc
+ var excinfo = test._exceptions[j];
+ this._exceptions.push(excinfo);
+ };
+ };
+ };
+ var now = new Date();
+ var totaltime = now.getTime() - starttime;
+ this._reporter.summarize(testsran, totaltime, this._exceptions);
+};
+
+function StdoutReporter(verbose) {
+ if (verbose) {
+ this.verbose = verbose;
+ };
+};
+
+StdoutReporter.prototype.debug = function(text) {
+ print(text+"\n");
+}
+
+StdoutReporter.prototype.reportSuccess = function(testcase, attr) {
+ /* report a test success */
+ if (this.verbose) {
+ print(testcase + '.' + attr + '(): OK');
+ } else {
+ print('.');
+ };
+};
+
+StdoutReporter.prototype.reportError = function(testcase, attr,
+ exception, raw) {
+ /* report a test failure */
+ if (this.verbose) {
+ print(testcase + '.' + attr + '(): FAILED!');
+ } else {
+ print('F');
+ };
+};
+
+StdoutReporter.prototype.summarize = function(numtests, time, exceptions) {
+ print('\n' + numtests + ' tests ran in ' + time / 1000.0 +
+ ' seconds\n');
+ if (exceptions.length) {
+ for (var i=0; i < exceptions.length; i++) {
+ var testcase = exceptions[i][0];
+ var attr = exceptions[i][1];
+ var exception = exceptions[i][2];
+ var raw = exceptions[i][3];
+ print(testcase + '.' + attr + ', exception: ' + exception);
+ if (this.verbose) {
+ this._printStackTrace(raw);
+ };
+ };
+ print('NOT OK!');
+ } else {
+ print('OK!');
+ };
+};
+
+StdoutReporter.prototype._printStackTrace = function(exc) {
+ if (!exc.stack) {
+ print('no stacktrace available');
+ return;
+ };
+ var lines = exc.stack.toString().split('\n');
+ var toprint = [];
+ for (var i=0; i < lines.length; i++) {
+ var line = lines[i];
+ if (line.indexOf('ecmaunit.js') > -1) {
+ // remove useless bit of traceback
+ break;
+ };
+ if (line.charAt(0) == '(') {
+ line = 'function' + line;
+ };
+ var chunks = line.split('@');
+ toprint.push(chunks);
+ };
+ toprint.reverse();
+ for (var i=0; i < toprint.length; i++) {
+ print(' ' + toprint[i][1]);
+ print(' ' + toprint[i][0]);
+ };
+ print();
+};
+
+function HTMLReporter(outputelement, verbose) {
+ if (outputelement) {
+ this.outputelement = outputelement;
+ this.document = outputelement.ownerDocument;
+ this.verbose = verbose;
+ };
+};
+
+HTMLReporter.prototype.debug = function(text) {
+ var msg = this.document.createTextNode(text);
+ var div = this.document.createElement('div');
+ div.appendChild(msg);
+ this.outputelement.appendChild(div);
+};
+
+HTMLReporter.prototype.reportSuccess = function(testcase, attr) {
+ /* report a test success */
+ // a single dot looks rather small
+ var dot = this.document.createTextNode('+');
+ this.outputelement.appendChild(dot);
+};
+
+HTMLReporter.prototype.reportError = function(testcase, attr, exception, raw) {
+ /* report a test failure */
+ var f = this.document.createTextNode('F');
+ this.outputelement.appendChild(f);
+};
+
+HTMLReporter.prototype.summarize = function(numtests, time, exceptions) {
+ /* write the result output to the html node */
+ var p = this.document.createElement('p');
+ var text = this.document.createTextNode(numtests + ' tests ran in ' +
+ time / 1000.0 + ' seconds');
+ p.appendChild(text);
+ this.outputelement.appendChild(p);
+ if (exceptions.length) {
+ for (var i=0; i < exceptions.length; i++) {
+ var testcase = exceptions[i][0];
+ var attr = exceptions[i][1];
+ var exception = exceptions[i][2].toString();
+ var raw = exceptions[i][3];
+ var div = this.document.createElement('div');
+ var lines = exception.toString().split('\n');
+ var text = this.document.createTextNode(
+ testcase + '.' + attr + ', exception ');
+ div.appendChild(text);
+ // add some formatting for Opera: this browser displays nice
+ // tracebacks...
+ for (var j=0; j < lines.length; j++) {
+ var text = lines[j];
+ if (j > 0) {
+ text = '\xa0\xa0\xa0\xa0' + text;
+ };
+ div.appendChild(this.document.createTextNode(text));
+ div.appendChild(this.document.createElement('br'));
+ };
+ div.style.color = 'red';
+ this.outputelement.appendChild(div);
+ if (this.verbose) {
+ // display stack trace on Moz
+ this._displayStackTrace(raw);
+ };
+ };
+ var div = this.document.createElement('div');
+ var text = this.document.createTextNode('NOT OK!');
+ div.appendChild(text);
+ div.style.backgroundColor = 'red';
+ div.style.color = 'black';
+ div.style.fontWeight = 'bold';
+ div.style.textAlign = 'center';
+ div.style.marginTop = '1em';
+ this.outputelement.appendChild(div);
+ } else {
+ var div = this.document.createElement('div');
+ var text = this.document.createTextNode('OK!');
+ div.appendChild(text);
+ div.style.backgroundColor = 'lightgreen';
+ div.style.color = 'black';
+ div.style.fontWeight = 'bold';
+ div.style.textAlign = 'center';
+ div.style.marginTop = '1em';
+ this.outputelement.appendChild(div);
+ };
+};
+
+HTMLReporter.prototype._displayStackTrace = function(exc) {
+ /*
+ if (arguments.caller) {
+ // IE
+ var caller = arguments;
+ toprint = [];
+ while (caller) {
+ var callee = caller.callee.toString();
+ callee = callee.replace('\n', '').replace(/\s+/g, ' ');
+ var funcsig = /(.*?)\s*\{/.exec(callee)[1];
+ var args = caller.callee.arguments;
+ var displayargs = [];
+ for (var i=0; i < args.length; i++) {
+ displayargs.push(args[i].toString());
+ };
+ toprint.push((funcsig + ' - (' + displayargs + ')'));
+ caller = caller.caller;
+ };
+ toprint.reverse();
+ var pre = this.document.createElement('pre');
+ for (var i=0; i < toprint.length; i++) {
+ pre.appendChild(document.createTextNode(toprint[i]));
+ pre.appendChild(document.createElement('br'));
+ };
+ this.outputelement.appendChild(pre);
+ };
+ */
+ if (exc.stack) {
+ // Moz (sometimes)
+ var lines = exc.stack.toString().split('\n');
+ var toprint = []; // need to reverse this before outputting
+ for (var i=0; i < lines.length; i++) {
+ var line = lines[i];
+ if (line.indexOf('ecmaunit.js') > -1) {
+ // remove useless bit of traceback
+ break;
+ };
+ if (line[0] == '(') {
+ line = 'function' + line;
+ };
+ line = line.split('@');
+ toprint.push(line);
+ };
+ toprint.reverse();
+ var pre = this.document.createElement('pre');
+ for (var i=0; i < toprint.length; i++) {
+ pre.appendChild(
+ this.document.createTextNode(
+ ' ' + toprint[i][1] + '\n ' + toprint[i][0] + '\n'
+ )
+ );
+ };
+ pre.appendChild(document.createTextNode('\n'));
+ this.outputelement.appendChild(pre);
+ };
+};
Index: /quintagroup.plonetabs/trunk/quintagroup/plonetabs/tests/ecmaunits/js/runner.html
===================================================================
--- /quintagroup.plonetabs/trunk/quintagroup/plonetabs/tests/ecmaunits/js/runner.html (revision 884)
+++ /quintagroup.plonetabs/trunk/quintagroup/plonetabs/tests/ecmaunits/js/runner.html (revision 884)
@@ -0,0 +1,126 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ KSS ECMAScript Unit Tests: quintagroup.plonetabs
+
+
+ header
+
+
+ This page is the entry to the quintagroup.plonetabs ECMAScript Unit Tests.
+
+
+
+ Tests are running from the filesystem.
+ KSS is running in development (uncooked) mode.
+
+
+
+
+ Suite filter:
+ Test filter:
+
+
+
+
+
Index: /quintagroup.plonetabs/trunk/quintagroup/plonetabs/tests/ecmaunits/js/test_kssparser.js
===================================================================
--- /quintagroup.plonetabs/trunk/quintagroup/plonetabs/tests/ecmaunits/js/test_kssparser.js (revision 884)
+++ /quintagroup.plonetabs/trunk/quintagroup/plonetabs/tests/ecmaunits/js/test_kssparser.js (revision 884)
@@ -0,0 +1,2116 @@
+/*
+* Copyright (c) 2005-2007
+* Authors: KSS Project Contributors (see docs/CREDITS.txt)
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License version 2 as published
+* by the Free Software Foundation.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+* 02111-1307, USA.
+*/
+
+if (typeof(kukit) == "undefined") {
+ var kukit = {};
+}
+
+kukit.KssParserTestCaseBase = function() {
+
+ this.setUp = function() {
+ kukit.eventsGlobalRegistry.register('dnd', 'drag',
+ kukit.pl.NativeEventBinder, '__bind__nodeordocument', null);
+ };
+
+ this.tearDown = function() {
+ kukit.eventsGlobalRegistry.unregister('dnd', 'drag');
+ };
+
+ this.assertKssParmValueEquals = function(a, b, reason) {
+ if (typeof(reason) == 'undefined') {
+ reason = '';
+ } else {
+ reason += ', ';
+ }
+ this.assertEquals(a.isMethod, b.isMethod, reason + 'different types');
+ if (! a.isMethod) {
+ this.assertEquals(a.txt, b.txt, reason + 'text mismatch' );
+ } else {
+ this.assertEquals(a.methodName, b.methodName, reason + 'methodName mismatch');
+ this.assertListEquals(a.args, b.args, reason + 'args mismatch');
+ }
+ };
+
+ this.assertKssParmEquals = function(a, b, reason) {
+ if (typeof(reason) == 'undefined') {
+ reason = '';
+ } else {
+ reason += ', ';
+ }
+ for (var key in a) {
+ this.assertNotEquals(typeof(b[key]), 'undefined', reason + 'key ' + key + ' missing from parms 2');
+ this.assertKssParmValueEquals(a[key], b[key], 'mismatch at parm key ' + key);
+ }
+ for (var key in b) {
+ this.assertNotEquals(typeof(a[key]), 'undefined', reason + 'key ' + key + ' missing from parms 1');
+ this.assertKssParmValueEquals(a[key], b[key], reason + 'mismatch at parm key ' + key);
+ }
+ };
+};
+
+kukit.KssParserTestCaseBase.prototype = new kukit.TokenizerTestCaseBase;
+
+kukit.KssParserTestCase = function() {
+ this.name = 'kukit.KssParserTestCase';
+
+ this.testPropValue = function() {
+ // Parsing property values
+
+ var txt= "b";
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.PropValue(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.value.isMethod, false);
+ this.assertEquals(parser.value.txt, 'b');
+
+ // XXX multiword in PropValue was supported by the token
+ // previously, but it really was never used.
+
+ // multiword is not allowed.
+ txt= "b c";
+ cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.PropValue, cursor, null, true,
+ 'Wrong value : unallowed characters [c] after the argument.')
+
+ // multiword is not allowed.
+ txt= " apples and oranges ;";
+ cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.PropValue, cursor, null, true,
+ 'Wrong value : unallowed characters [and] after the argument.')
+
+ // multiword is not allowed.
+ txt= " /* comments; */ apples and /* more comments and*/ oranges ;";
+ cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.PropValue, cursor, null, true,
+ 'Wrong value : unallowed characters [and] after the argument.')
+
+ // params ok
+ txt= "formVar(x, y) ";
+ cursor = new kukit.tk.Cursor(txt);
+ parser = new kukit.kssp.PropValue(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.value.isMethod, true);
+ this.assertEquals(parser.value.methodName, 'formVar');
+ this.assertListEquals(parser.value.args, ['x', 'y']);
+
+ // params ok
+ txt= "formVar(x, y)";
+ cursor = new kukit.tk.Cursor(txt);
+ parser = new kukit.kssp.PropValue(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.value.isMethod, true);
+ this.assertEquals(parser.value.methodName, 'formVar');
+ this.assertListEquals(parser.value.args, ['x', 'y']);
+
+ //ok
+ txt= " formVar (x, y)";
+ cursor = new kukit.tk.Cursor(txt);
+ parser = new kukit.kssp.PropValue(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.value.isMethod, true);
+ this.assertEquals(parser.value.methodName, 'formVar');
+ this.assertListEquals(parser.value.args, ['x', 'y']);
+
+ txt= " a formVar(x, y)";
+ cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.PropValue, cursor, null, true,
+ 'Wrong value : unallowed characters [formVar] after the argument.')
+
+ txt= " 'formVar'(x, y)";
+ cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.PropValue, cursor, null, true,
+ 'Wrong value : unallowed characters [(] after the argument.')
+
+ txt= "formVar(x, y) xxx";
+ cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.PropValue, cursor, null, true,
+ 'Wrong value : unallowed characters [xxx] after the argument.')
+ };
+
+ this.testPropValueNoParam = function() {
+ // no parameters ok in a provider.
+ var txt= "formVar()";
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.PropValue(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.value.isMethod, true);
+ this.assertEquals(parser.value.methodName, 'formVar');
+ this.assertListEquals(parser.value.args, []);
+ };
+
+ this.testPropValueNoMethodName = function() {
+ var txt= " (x, y)";
+ var cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.PropValue, cursor, null, true,
+ 'Wrong value : empty method name.');
+ };
+
+ this.testMultiPropValueSingleWord = function() {
+ // Multi prop value with single word
+ var txt= "b";
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.MultiPropValue(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.values.length, 1);
+ this.assertEquals(parser.values[0].isMethod, false);
+ this.assertEquals(parser.values[0].txt, 'b');
+ };
+
+ this.testMultiPropValueMultiWord = function() {
+ // Multi prop value with multi word.
+ var txt= "b c";
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.MultiPropValue(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.values.length, 2);
+ this.assertEquals(parser.values[0].isMethod, false);
+ this.assertEquals(parser.values[0].txt, 'b');
+ this.assertEquals(parser.values[1].isMethod, false);
+ this.assertEquals(parser.values[1].txt, 'c');
+ };
+
+ this.testMultiPropValueMultiWord2 = function() {
+ // Multi prop value with multi word.
+ var txt= " apples and oranges ;";
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.MultiPropValue(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.values.length, 3);
+ this.assertEquals(parser.values[0].isMethod, false);
+ this.assertEquals(parser.values[0].txt, 'apples');
+ this.assertEquals(parser.values[1].isMethod, false);
+ this.assertEquals(parser.values[1].txt, 'and');
+ this.assertEquals(parser.values[2].isMethod, false);
+ this.assertEquals(parser.values[2].txt, 'oranges');
+ };
+
+ this.testMultiPropValueMultiWord2 = function() {
+ // Multi prop value with multi word and comments.
+ var txt= " /* comments; */ apples and /* more comments and*/ oranges ;";
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.MultiPropValue(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.values.length, 3);
+ this.assertEquals(parser.values[0].isMethod, false);
+ this.assertEquals(parser.values[0].txt, 'apples');
+ this.assertEquals(parser.values[1].isMethod, false);
+ this.assertEquals(parser.values[1].txt, 'and');
+ this.assertEquals(parser.values[2].isMethod, false);
+ this.assertEquals(parser.values[2].txt, 'oranges');
+ };
+
+
+ this.testMultiPropValueStringAndWord = function() {
+ // Multi prop value with string and word.
+ var txt= "'apples' and oranges;";
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.MultiPropValue(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.values.length, 3);
+ this.assertEquals(parser.values[0].isMethod, false);
+ this.assertEquals(parser.values[0].txt, 'apples');
+ this.assertEquals(parser.values[1].isMethod, false);
+ this.assertEquals(parser.values[1].txt, 'and');
+ this.assertEquals(parser.values[2].isMethod, false);
+ this.assertEquals(parser.values[2].txt, 'oranges');
+ };
+
+ this.testMultiPropValueWordAndString = function() {
+ // Multi prop value with string and word.
+ var txt= "'apples' and oranges;";
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.MultiPropValue(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.values.length, 3);
+ this.assertEquals(parser.values[0].isMethod, false);
+ this.assertEquals(parser.values[0].txt, 'apples');
+ this.assertEquals(parser.values[1].isMethod, false);
+ this.assertEquals(parser.values[1].txt, 'and');
+ this.assertEquals(parser.values[2].isMethod, false);
+ this.assertEquals(parser.values[2].txt, 'oranges');
+ };
+
+ this.testMultiPropValueWordAndProvider = function() {
+ // Multi prop value with word and provider and word.
+ var txt= "apples formVar(x, y) oranges;";
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.MultiPropValue(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.values.length, 3);
+ this.assertEquals(parser.values[0].isMethod, false);
+ this.assertEquals(parser.values[0].txt, 'apples');
+ this.assertEquals(parser.values[1].isMethod, true);
+ this.assertEquals(parser.values[1].methodName, 'formVar');
+ this.assertListEquals(parser.values[1].args, ['x', 'y']);
+ this.assertEquals(parser.values[2].isMethod, false);
+ this.assertEquals(parser.values[2].txt, 'oranges');
+ };
+
+ this.testMultiPropValueProviderAndWord = function() {
+ // Multi prop value with provider and word.
+ var txt= "formVar(x, y) and oranges;";
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.MultiPropValue(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.values.length, 3);
+ this.assertEquals(parser.values[0].isMethod, true);
+ this.assertEquals(parser.values[0].methodName, 'formVar');
+ this.assertListEquals(parser.values[0].args, ['x', 'y']);
+ this.assertEquals(parser.values[1].isMethod, false);
+ this.assertEquals(parser.values[1].txt, 'and');
+ this.assertEquals(parser.values[2].isMethod, false);
+ this.assertEquals(parser.values[2].txt, 'oranges');
+ };
+
+ this.testMultiPropValueMethodArgsWithSpace = function() {
+ // Multi prop value with space after the provider name.
+ var txt= "formVar (x, y) and oranges;";
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.MultiPropValue(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.values.length, 3);
+ this.assertEquals(parser.values[0].isMethod, true);
+ this.assertEquals(parser.values[0].methodName, 'formVar');
+ this.assertListEquals(parser.values[0].args, ['x', 'y']);
+ this.assertEquals(parser.values[1].isMethod, false);
+ this.assertEquals(parser.values[1].txt, 'and');
+ this.assertEquals(parser.values[2].isMethod, false);
+ this.assertEquals(parser.values[2].txt, 'oranges');
+ };
+
+ this.testMultiPropValueManyProviders = function() {
+ // Multi prop value with many providers
+ var txt= "formVar(x, y) kssAttr(foo, true) formVar(a, b);";
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.MultiPropValue(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.values.length, 3);
+ this.assertEquals(parser.values[0].isMethod, true);
+ this.assertEquals(parser.values[0].methodName, 'formVar');
+ this.assertListEquals(parser.values[0].args, ['x', 'y']);
+ this.assertEquals(parser.values[1].isMethod, true);
+ this.assertEquals(parser.values[1].methodName, 'kssAttr');
+ this.assertListEquals(parser.values[1].args, ['foo', 'true']);
+ this.assertEquals(parser.values[2].isMethod, true);
+ this.assertEquals(parser.values[2].methodName, 'formVar');
+ this.assertListEquals(parser.values[2].args, ['a', 'b']);
+ };
+
+ this.testMultiPropValueStringAndManyProviders = function() {
+ // Multi prop value with a string and many providers
+ var txt= "blah kssAttr(foo, true) formVar(a, b);";
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.MultiPropValue(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.values.length, 3);
+ this.assertEquals(parser.values[0].isMethod, false);
+ this.assertEquals(parser.values[0].txt, 'blah');
+ this.assertEquals(parser.values[1].isMethod, true);
+ this.assertEquals(parser.values[1].methodName, 'kssAttr');
+ this.assertListEquals(parser.values[1].args, ['foo', 'true']);
+ this.assertEquals(parser.values[2].isMethod, true);
+ this.assertEquals(parser.values[2].methodName, 'formVar');
+ this.assertListEquals(parser.values[2].args, ['a', 'b']);
+ };
+
+ this.testEventValueSimple = function() {
+ // Parsing event value
+ var txt= "b";
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.EventValue(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.value.methodName, 'b');
+ };
+
+ this.testEventValueMultiword = function() {
+ // multiword ok but does not finish
+ var txt= "b c";
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.EventValue(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(cursor.pos, 1);
+ this.assertEquals(parser.value.methodName, 'b');
+ };
+
+ this.testEventValueStartsWithSpace = function() {
+ // space ok but does not finish
+ var txt= " b";
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.EventValue(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(cursor.pos, 0);
+ this.assertEquals(parser.value.methodName, '');
+ };
+
+ this.testEventValueWithComment = function() {
+ // ok, does not finish
+ var txt= "apples/* more comments and*/";
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.EventValue(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(cursor.pos, 6);
+ this.assertEquals(parser.value.methodName, 'apples');
+ };
+
+ this.testEventValueWithBinderId = function() {
+ // params ok
+ var txt= "click(x)";
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.EventValue(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.value.methodName, 'click');
+ this.assertEquals(parser.value.arg.isMethod, false);
+ this.assertEquals(parser.value.arg.txt, 'x');
+
+ // more then 1 args not ok (but we check it only from kss selector)
+ //txt= "drag(x, y)";
+ //cursor = new kukit.tk.Cursor(txt);
+
+ // not ok but we don't parse an error
+ //txt= "'drag'(x)";
+ //cursor = new kukit.tk.Cursor(txt);
+ //this.assertParsingError(kukit.kssp.EventValue, cursor, null, true,
+ // 'Excess characters after the property value', 16);
+ };
+
+ this.testEventValueWithValueProvider = function() {
+ // methods ok
+ var txt= "click(kssAttr(x))";
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.EventValue(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.value.methodName, 'click');
+ this.assertEquals(parser.value.arg.isMethod, true);
+ this.assertEquals(parser.value.arg.methodName, 'kssAttr');
+ this.assertListEquals(parser.value.arg.args, ['x']);
+ };
+
+ this.testEventValueWithValueProviderRejectsAccessValues = function() {
+ // no more values in the method
+ var txt= "click(kssAttr(x), aaa)";
+ var cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.EventValue, cursor, null, true,
+ 'Wrong event selector : [,] is not expected before the closing parenthesis. :() can have only one parameter.', 000);
+
+ // XXX add more failing cases, maybe?
+ };
+
+ this.testMethodArgs = function() {
+ // Parsing method args
+ var txt= "(a, b)";
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.MethodArgs(cursor, kukit.kssp.openParent, true);
+ this.assertEquals(parser.finished, true);
+ this.assertListEquals(parser.args, ['a', 'b']);
+
+ txt= "('a', /* to annoy you */ \"b\")";
+ cursor = new kukit.tk.Cursor(txt);
+ parser = new kukit.kssp.MethodArgs(cursor, kukit.kssp.openParent, true);
+ this.assertEquals(parser.finished, true);
+ this.assertListEquals(parser.args, ['a', 'b']);
+
+ txt= "(' a multi', /* to annoy you */ \"b multi \")";
+ cursor = new kukit.tk.Cursor(txt);
+ parser = new kukit.kssp.MethodArgs(cursor, kukit.kssp.openParent, true);
+ this.assertEquals(parser.finished, true);
+ this.assertListEquals(parser.args, [' a multi','b multi ']);
+
+ txt= "('a', /*comment*/ /* to annoy you */ \"b\")";
+ cursor = new kukit.tk.Cursor(txt);
+ parser = new kukit.kssp.MethodArgs(cursor, kukit.kssp.openParent, true);
+ this.assertEquals(parser.finished, true);
+ this.assertListEquals(parser.args, ['a', 'b']);
+
+ txt= "(a, b, )";
+ cursor = new kukit.tk.Cursor(txt);
+ parser = new kukit.kssp.MethodArgs(cursor, kukit.kssp.openParent, true);
+ this.assertEquals(parser.finished, true);
+ this.assertListEquals(parser.args, ['a', 'b']);
+
+ txt= "(a, b c )";
+ cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.MethodArgs, cursor, kukit.kssp.openParent, true,
+ 'Wrong method argument [b c] : value cannot have spaces', 9);
+
+ txt= "(a, b 'x' )";
+ cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.MethodArgs, cursor, kukit.kssp.openParent, true,
+ 'Unexpected token : [string] found, [comma] was expected.', 11);
+
+ };
+
+ this.testMethodArgsNoParam = function() {
+ // Parsing method args with no parameters
+ txt= "()";
+ cursor = new kukit.tk.Cursor(txt);
+ parser = new kukit.kssp.MethodArgs(cursor, kukit.kssp.openParent, true);
+ this.assertEquals(parser.finished, true);
+ this.assertListEquals(parser.args, []);
+ };
+
+ this.testMethodArgsRecursive = function() {
+ var txt= "(a, b(c, d))";
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.MethodArgs(cursor, kukit.kssp.openParent, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.args.length, 2);
+ this.assertEquals(parser.args[0], 'a');
+ this.assertEquals(parser.args[1].isMethod, true);
+ this.assertEquals(parser.args[1].methodName, 'b');
+ this.assertListEquals(parser.args[1].args, ['c', 'd']);
+ };
+
+ this.testEmptyDoc = function() {
+ // unexpected eof handling
+
+ var txt= "";
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.Document(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.eventRules.length, 0);
+
+ // In particular, this should not raise unexpected eof.
+ var txt= "/*xxx*/";
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.Document(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.eventRules.length, 0);
+ };
+
+ this.testFull = function() {
+ // Basic parsing test
+ var txt= ""
+ +"/* a long\n"
+ +"** comment\n"
+ +"*/\n"
+ +"\n"
+ +"#calendar-previous a:click {\n"
+ +" action-server : kukitresponse/kukitGetPreviousMonth;\n"
+ +"}\n"
+ +"div#update-area:timeout {\n"
+ +" evt-timeout-delay: 2000; \n"
+ +" action-server: getCurrentTime;\n"
+ +" getCurrentTime-effect: fade; \n"
+ +"}\n"
+ +"#calendar-previous a:click {\n"
+ +" action-server: 'kukitresponse/kukitGetPreviousMonth' /* place comment here*/;\n"
+ +"}\n"
+ +"#calendar-previous a:click {\n"
+ +" action-server : kukitGetPreviousMonth /* place comment here*/;\n"
+ +" kukitGetPreviousMonth-member: formVar(edit, 'f_member');\n"
+ +"}\n"
+ +"#calendar-previous a:dnd-drag(shelve) {\n"
+ +" action-server : whatever\n"
+ +"}\n"
+ +"#button-one:dnd-drag(annoy-me) {\n"
+ +" action-server: clickedButton;\n"
+ +" clickedButton-id: nodeAttr(id);\n"
+ +"}\n"
+ +"document:dnd-drag(annoyMe) {\n"
+ +" action-client: alert;\n"
+ +' alert-message: "You are an idiot! Ha ha ha. (But just keep on trying...)";\n'
+ +"}\n"
+ +"document:dnd-drag(annoyMe) {\n"
+ +" action-client: alert;\n"
+ +' alert-message: "You are an idiot! Ha ha ha. (But just keep on trying...)";\n'
+ +"}\n"
+ +"div#update-area:timeout {\n"
+ +" evt-timeout-delay: 2000; \n"
+ +" action-server: getCurrentTime;\n"
+ +" getCurrentTime-effect: fade; \n"
+ +" action-client: log;\n"
+ +' log-message: "Logging";\n'
+ +"}\n"
+ +"document:dnd-drag(annoyMe) {\n"
+ +" evt-dnd-drag-preventdefault: true;\n"
+ +" action-client: namespaced-alert;\n"
+ +' namespaced-alert-message: "You are an idiot! Ha ha ha. (But just keep on trying...)";\n'
+ +'}\n'
+ +'#button_1:click {\n'
+ +'action-client: setStyle;\n'
+ +'setStyle-kssSelector: htmlid(button_2);\n'
+ +'setStyle-name: backgroundColor;\n'
+ +'setStyle-value: #FFa0a0;\n'
+ +'}\n'
+ +'#button_3:click {\n'
+ +'action-client: setStyle;\n'
+ +'setStyle-kssSelector: "#button_4";\n'
+ +'setStyle-name: /* comment blabla */ backgroundColor;\n'
+ +'setStyle-value: #FFa0a0;\n'
+ +'}\n'
+ +"#calendar-previous a:click {\n"
+ +" action-server : kukitGetPreviousMonth /* place comment here*/;\n"
+ +" kukitGetPreviousMonth-member: formVar(edit, kssAttr(foo));\n"
+ +'}\n'
+ +"#button-one:click(kssAttr(widannoy)) {\n"
+ +" action-client: alert;\n"
+ +"}\n";
+
+ var cursor = new kukit.tk.Cursor(txt);
+
+ // XXX TODO change comments
+
+ var parser = new kukit.kssp.Document(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.eventRules.length, 14);
+ var rule;
+ var action;
+
+ // rule 0
+ // #calendar-previous a:click {
+ // action-server : kukitresponse/kukitGetPreviousMonth;
+ // }
+ rule = parser.eventRules[0];
+ this.assertDictEquals(rule.parms, {});
+ this.assertEquals(rule.kssSelector.isEventSelector, true);
+ this.assertEquals(rule.kssSelector.css, '#calendar-previous a');
+ this.assertEquals(rule.kssSelector.name, 'click');
+ this.assertEquals(rule.kssSelector.namespace, null);
+ action = rule.actions.content['kukitresponse/kukitGetPreviousMonth'];
+ this.assertEquals(action.type, 'S');
+ this.assertEquals(action.name, 'kukitresponse/kukitGetPreviousMonth');
+ this.assertEquals(action.error, null);
+ this.assertKssParmEquals(action.parms, {});
+
+ // rule 1
+ // div#update-area:timeout {
+ // evt-timeout-delay: 2000;
+ // effect: fade;
+ // action-server: getCurrentTime;
+ // }
+ rule = parser.eventRules[1];
+ this.assertDictEquals(rule.parms, {'delay': '2000'});
+ this.assertEquals(rule.kssSelector.isEventSelector, true);
+ this.assertEquals(rule.kssSelector.css, 'div#update-area');
+ this.assertEquals(rule.kssSelector.name, 'timeout');
+ this.assertEquals(rule.kssSelector.namespace, null);
+ action = rule.actions.content['getCurrentTime'];
+ this.assertEquals(action.type, 'S');
+ this.assertEquals(action.name, 'getCurrentTime');
+ this.assertEquals(action.error, null);
+ this.assertKssParmEquals(action.parms, {
+ 'effect': new kukit.rd.KssTextValue('fade')
+ });
+
+ // rule 2
+ // #calendar-previous a:click {
+ // action-server : 'kukitresponse/kukitGetPreviousMonth' /* place comment here*/;
+ // }
+ rule = parser.eventRules[2];
+ this.assertDictEquals(rule.parms, {});
+ this.assertEquals(rule.kssSelector.css, '#calendar-previous a');
+ this.assertEquals(rule.kssSelector.isEventSelector, true);
+ this.assertEquals(rule.kssSelector.name, 'click');
+ this.assertEquals(rule.kssSelector.namespace, null);
+ action = rule.actions.content['kukitresponse/kukitGetPreviousMonth'];
+ this.assertEquals(action.type, 'S');
+ this.assertEquals(action.name, 'kukitresponse/kukitGetPreviousMonth');
+ this.assertEquals(action.error, null);
+ this.assertKssParmEquals(action.parms, {});
+
+ // rule 3
+ // #calendar-previous a:click {
+ // action-server : 'kukitresponse/kukitGetPreviousMonth' /* place comment here*/;
+ // member: formVar(edit, 'f_member');
+ // }
+ rule = parser.eventRules[3];
+ this.assertDictEquals(rule.parms, {});
+ this.assertEquals(rule.kssSelector.css, '#calendar-previous a');
+ this.assertEquals(rule.kssSelector.isEventSelector, true);
+ this.assertEquals(rule.kssSelector.name, 'click');
+ this.assertEquals(rule.kssSelector.namespace, null);
+ action = rule.actions.content['kukitGetPreviousMonth'];
+ this.assertEquals(action.type, 'S');
+ this.assertEquals(action.name, 'kukitGetPreviousMonth');
+ this.assertEquals(action.error, null);
+ this.assertKssParmEquals(action.parms, {
+ 'member': new kukit.rd.KssMethodValue('formVar', ['edit', 'f_member'])
+ });
+
+ // rule 4
+ // #calendar-previous a:dnd-drag(shelve) {
+ // action-server : whatever
+ // }
+ rule = parser.eventRules[4];
+ this.assertDictEquals(rule.parms, {});
+ this.assertEquals(rule.kssSelector.css, '#calendar-previous a');
+ this.assertEquals(rule.kssSelector.isEventSelector, true);
+ this.assertEquals(rule.kssSelector.name, 'drag');
+ this.assertEquals(rule.kssSelector.namespace, 'dnd');
+ this.assertEquals(rule.kssSelector.id, 'shelve');
+ action = rule.actions.content['whatever'];
+ this.assertEquals(action.type, 'S');
+ this.assertEquals(action.name, 'whatever');
+ this.assertEquals(action.error, null);
+ this.assertKssParmEquals(action.parms, {
+ });
+
+ // rule 5
+ //#button-one:dnd-drag(annoyMe) {
+ // action-server: clickedButton;
+ // id: nodeAttr(id);
+ //}
+ rule = parser.eventRules[5];
+ this.assertDictEquals(rule.parms, {});
+ this.assertEquals(rule.kssSelector.css, '#button-one');
+ this.assertEquals(rule.kssSelector.isEventSelector, true);
+ this.assertEquals(rule.kssSelector.name, 'drag');
+ this.assertEquals(rule.kssSelector.namespace, 'dnd');
+ this.assertEquals(rule.kssSelector.id, 'annoy-me');
+ action = rule.actions.content['clickedButton'];
+ this.assertEquals(action.type, 'S');
+ this.assertEquals(action.name, 'clickedButton');
+ this.assertEquals(action.error, null);
+ this.assertKssParmEquals(action.parms, {
+ 'id': new kukit.rd.KssMethodValue('nodeAttr', ['id'])
+ });
+
+ // rule 6
+ // document:dnd-drag(annoyMe) {
+ // action-client: alert;
+ // message: "You are an idiot! Ha ha ha. (But just keep on trying...)";
+ //}
+ rule = parser.eventRules[6];
+ this.assertDictEquals(rule.parms, {});
+ this.assertEquals(rule.kssSelector.css, 'document');
+ this.assertEquals(rule.kssSelector.isMethodSelector, true);
+ this.assertEquals(rule.kssSelector.name, 'drag');
+ this.assertEquals(rule.kssSelector.namespace, 'dnd');
+ this.assertEquals(rule.kssSelector.id, 'annoyMe');
+ action = rule.actions.content['alert'];
+ this.assertEquals(action.type, 'C');
+ this.assertEquals(action.name, 'alert');
+ this.assertEquals(action.error, null);
+ this.assertKssParmEquals(action.parms, {
+ 'message': new kukit.rd.KssTextValue( "You are an idiot! Ha ha ha. (But just keep on trying...)")
+ });
+
+ // rule 7
+ // document:dnd-drag(annoyMe) {
+ // action-client: alert;
+ // message: "You are an idiot! Ha ha ha. (But just keep on trying...)";
+ //}
+ rule = parser.eventRules[7];
+ this.assertDictEquals(rule.parms, {});
+ this.assertEquals(rule.kssSelector.css, 'document');
+ this.assertEquals(rule.kssSelector.isMethodSelector, true);
+ this.assertEquals(rule.kssSelector.name, 'drag');
+ this.assertEquals(rule.kssSelector.namespace, 'dnd');
+ this.assertEquals(rule.kssSelector.id, 'annoyMe');
+ action = rule.actions.content['alert'];
+ this.assertEquals(action.type, 'C');
+ this.assertEquals(action.name, 'alert');
+ this.assertEquals(action.error, null);
+ this.assertKssParmEquals(action.parms, {
+ 'message': new kukit.rd.KssTextValue( "You are an idiot! Ha ha ha. (But just keep on trying...)")
+ });
+
+ // rule 8
+ rule = parser.eventRules[8];
+ this.assertDictEquals(rule.parms, {'delay': '2000'});
+ this.assertEquals(rule.kssSelector.isEventSelector, true);
+ this.assertEquals(rule.kssSelector.css, 'div#update-area');
+ this.assertEquals(rule.kssSelector.name, 'timeout');
+ this.assertEquals(rule.kssSelector.namespace, null);
+ action = rule.actions.content['getCurrentTime'];
+ this.assertEquals(action.type, 'S');
+ this.assertEquals(action.name, 'getCurrentTime');
+ this.assertEquals(action.error, null);
+ this.assertKssParmEquals(action.parms, {
+ 'effect': new kukit.rd.KssTextValue('fade')
+ });
+ action = rule.actions.content['log'];
+ this.assertEquals(action.type, 'C');
+ this.assertEquals(action.name, 'log');
+ this.assertEquals(action.error, null);
+ this.assertKssParmEquals(action.parms, {
+ 'message': new kukit.rd.KssTextValue('Logging')
+ });
+
+ // rule 9
+ //document:dnd-drag(annoyMe) {\n"
+ // evt-dnd-drag-preventdefault: true;\n"
+ // action-client: namespaced-alert;\n"
+ // namespaced-alert-message: "You are an idiot! Ha ha ha. (But just keep on trying...)";\n'
+ //}
+ rule = parser.eventRules[9];
+ this.assertDictEquals(rule.parms, {'preventdefault': 'true'});
+ this.assertEquals(rule.kssSelector.css, 'document');
+ this.assertEquals(rule.kssSelector.isMethodSelector, true);
+ this.assertEquals(rule.kssSelector.name, 'drag');
+ this.assertEquals(rule.kssSelector.namespace, 'dnd');
+ this.assertEquals(rule.kssSelector.id, 'annoyMe');
+ action = rule.actions.content['namespaced-alert'];
+ this.assertEquals(action.type, 'C');
+ this.assertEquals(action.name, 'namespaced-alert');
+ this.assertEquals(action.error, null);
+ this.assertKssParmEquals(action.parms, {
+ 'message': new kukit.rd.KssTextValue( "You are an idiot! Ha ha ha. (But just keep on trying...)")
+ });
+
+ // rule 10
+ //#button_1:click {
+ // action-client: setStyle;
+ // setStyle-kssSelector: htmlid(button_2);
+ // setStyle-name: backgroundColor;
+ // setStyle-value: #FFa0a0;
+ //}
+ rule = parser.eventRules[10];
+ this.assertDictEquals(rule.parms, {});
+ this.assertEquals(rule.kssSelector.isEventSelector, true);
+ this.assertEquals(rule.kssSelector.css, '#button_1');
+ this.assertEquals(rule.kssSelector.name, 'click');
+ this.assertEquals(rule.kssSelector.namespace, null);
+ action = rule.actions.content['setStyle'];
+ this.assertEquals(action.type, 'C');
+ this.assertEquals(action.name, 'setStyle');
+ this.assertEquals(action.error, null);
+ // At this point the parms are before separation yet
+ this.assertKssParmEquals(action.parms, {
+ 'name': new kukit.rd.KssTextValue('backgroundColor'),
+ 'value': new kukit.rd.KssTextValue('#FFa0a0'),
+ 'kssSelector': new kukit.rd.KssMethodValue('htmlid', ['button_2'])
+ });
+
+ // rule 11
+ //#button_3:click {
+ // action-client: setStyle;
+ // setStyle-kssSelector: "#button_4";
+ // setStyle-name: backgroundColor;
+ // setStyle-value: #FFa0a0;
+ //}\n";
+ rule = parser.eventRules[11];
+ this.assertDictEquals(rule.parms, {});
+ this.assertEquals(rule.kssSelector.isEventSelector, true);
+ this.assertEquals(rule.kssSelector.css, '#button_3');
+ this.assertEquals(rule.kssSelector.name, 'click');
+ this.assertEquals(rule.kssSelector.namespace, null);
+ action = rule.actions.content['setStyle'];
+ this.assertEquals(action.type, 'C');
+ this.assertEquals(action.name, 'setStyle');
+ this.assertEquals(action.error, null);
+ // At this point the parms are before separation yet
+ this.assertKssParmEquals(action.parms, {
+ 'name': new kukit.rd.KssTextValue('backgroundColor'),
+ 'value': new kukit.rd.KssTextValue('#FFa0a0'),
+ 'kssSelector': new kukit.rd.KssTextValue('#button_4')
+ });
+
+ // rule 12
+ // #calendar-previous a:click {
+ // kss-action : 'kukitresponse/kukitGetPreviousMonth' /* place comment here*/;
+ // member: formVar(edit, kssAttr(foo));
+ // }
+ rule = parser.eventRules[12];
+ this.assertDictEquals(rule.parms, {});
+ this.assertEquals(rule.kssSelector.css, '#calendar-previous a');
+ this.assertEquals(rule.kssSelector.isEventSelector, true);
+ this.assertEquals(rule.kssSelector.name, 'click');
+ this.assertEquals(rule.kssSelector.namespace, null);
+ action = rule.actions.content['kukitGetPreviousMonth'];
+ this.assertEquals(action.type, 'S');
+ this.assertEquals(action.name, 'kukitGetPreviousMonth');
+ this.assertEquals(action.error, null);
+ var formVar = action.parms.member;
+ this.assertEquals(formVar.methodName, 'formVar');
+ this.assertEquals(formVar.args[0], 'edit');
+ var kssAttr = formVar.args[1];
+ this.assertEquals(kssAttr.methodName, 'kssAttr');
+ this.assertListEquals(kssAttr.args, ['foo']);
+
+ // rule 13
+ // #button-one:click(kssAttr(widannoy)) {\n"
+ // action-client: alert;
+ //}
+ rule = parser.eventRules[13];
+ this.assertDictEquals(rule.parms, {});
+ this.assertEquals(rule.kssSelector.css, '#button-one');
+ this.assertEquals(rule.kssSelector.isEventSelector, true);
+ this.assertEquals(rule.kssSelector.name, 'click');
+ this.assertEquals(rule.kssSelector.namespace, null);
+ this.assertEquals(rule.kssSelector.id, null);
+ this.assertEquals(rule.kssSelector.ppid.methodName, 'kssAttr');
+ this.assertListEquals(rule.kssSelector.ppid.args, ['widannoy']);
+ action = rule.actions.content['alert'];
+ this.assertEquals(action.type, 'C');
+ this.assertEquals(action.name, 'alert');
+ this.assertEquals(action.error, null);
+ this.assertKssParmEquals(action.parms, {
+ });
+
+ };
+
+ this.testActionErrorParameters = function() {
+
+ var txt= ""
+ +"/* a long\n"
+ +"** comment\n"
+ +"*/\n"
+ +"\n"
+ +".inlineEditable:blur{ \n"
+ +" action-server : kukitresponse;\n"
+ +" kukitresponse-error : errors;\n"
+ +"}\n"
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.Document(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.eventRules.length, 1);
+ var rule;
+ var action;
+
+ rule = parser.eventRules[0];
+ this.assertDictEquals(rule.parms, {});
+ this.assertEquals(rule.kssSelector.isEventSelector, true);
+ this.assertEquals(rule.kssSelector.css, '.inlineEditable');
+ this.assertEquals(rule.kssSelector.name, 'blur');
+ this.assertEquals(rule.kssSelector.namespace, null);
+ action = rule.actions.content['kukitresponse'];
+ this.assertEquals((typeof(action) != 'undefined'), true);
+ this.assertEquals(action.type, 'S');
+ this.assertEquals(action.name, 'kukitresponse');
+ this.assertEquals(action.error, 'errors');
+ this.assertKssParmEquals(action.parms, {});
+ };
+
+ this.testDefaultActionErrorParameters = function() {
+
+ return;
+
+ // XXX
+ // default actions can be tested from plugins only currently
+ var txt= ""
+ +"/* a long\n"
+ +"** comment\n"
+ +"*/\n"
+ +"\n"
+ +".inlineEditable:blur{ \n"
+ +" default-error : errors;\n"
+ +"}\n"
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.Document(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.eventRules.length, 1);
+ var rule;
+ var action;
+
+ rule = parser.eventRules[0];
+ this.assertDictEquals(rule.parms, {});
+ this.assertEquals(rule.kssSelector.isEventSelector, true);
+ this.assertEquals(rule.kssSelector.css, '.inlineEditable');
+ this.assertEquals(rule.kssSelector.name, 'blur');
+ this.assertEquals(rule.kssSelector.namespace, null);
+ action = rule.actions.content['default'];
+ this.assertEquals((typeof(action) != 'undefined'), true);
+ this.assertEquals(action.error, 'errors');
+ this.assertKssParmEquals(action.parms, {});
+ };
+};
+
+kukit.KssParserTestCase.prototype = new kukit.KssParserTestCaseBase;
+
+kukit.KssParserValueProvidersCheckTestCase = function() {
+ this.name = 'kukit.KssParserValueProvidersCheckTestCase';
+ // Different tests to see if the syntax type check of
+ // the value providers is working correctly.
+ // At the moment we have the following return value types:
+ //
+ // string: almost all normal providers return string
+ // selection: a selector provider returns a list of nodes
+ // formquery: a form provider returns an ordered list
+ // of key-value pairs to be marshalled
+ // url: the return type of the url() provider
+ //
+ // We do not check the actual evaluation here, as we
+ // have no DOM at hand.
+ //
+ // We also check how these providers can be combined
+ // on one line.
+ //
+ // This testcase can run in DEVELOPMENT MODE ONLY,
+ // (because the checks are ignored in production mode)
+ // and all tests will be skipped
+ // and pass GREEN in production mode.
+
+ this.testNormalProviderAcceptsString = function() {
+ // normal providers does accept string
+ //
+ // This test can only run in development mode, pass otherwise.
+ if (! kukit.isDevelMode) {return;}
+ //
+ var txt= "nodeAttr('id')";
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.PropValue(cursor, null, true);
+ var value = parser.value;
+ value.check();
+ };
+
+ this.testNormalProviderRejectsSelectionAsParameter = function() {
+ // normal providers does not accept selection
+ //
+ // This test can only run in development mode, pass otherwise.
+ if (! kukit.isDevelMode) {return;}
+ //
+ var txt= "nodeAttr(htmlid('id'))";
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.PropValue(cursor, null, true);
+ var value = parser.value;
+ this.assertThrows(function() {
+ value.check();
+ },
+ Error);
+ };
+
+ this.testNormalProviderRejectsSelectionFullRule = function() {
+ // normal providers do not accept selection
+ // full rule
+ //
+ // This test can only run in development mode, pass otherwise.
+ if (! kukit.isDevelMode) {return;}
+ //
+ var txt= "#id:click {\n"
+ + " action-client: log;\n"
+ + " log-message: nodeAttr(htmlid('id'));\n"
+ + "}\n"
+ var cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.Document, cursor, null, true,
+ // XXX This error message will be fixed in service-layer branch
+ // XXX This will also fix running from IE, currently broken at error assert.
+ 'Error in value for action parameter [message] : Error: Expected string value and got [selection] in argument #[1] of provider [nodeAttr].., at row 1, column 11');
+ };
+
+ this.testNormalProviderRejectsFormData = function() {
+ // normal providers do not accept form query
+ //
+ // This test can only run in development mode, pass otherwise.
+ if (! kukit.isDevelMode) {return;}
+ //
+ var txt= "nodeAttr(form('name'))";
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.PropValue(cursor, null, true);
+ var value = parser.value;
+ this.assertThrows(function() {
+ value.check();
+ },
+ Error);
+ };
+
+ this.testNormalProviderRejectsFormDataFullRule = function() {
+ // normal providers do not accept form query
+ // full rule
+ //
+ // This test can only run in development mode, pass otherwise.
+ if (! kukit.isDevelMode) {return;}
+ //
+ var txt= "#id:click {\n"
+ + " action-client: log;\n"
+ + " log-message: nodeAttr(form('name'));\n"
+ + "}\n"
+ var cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.Document, cursor, null, true,
+ // XXX This error message will be fixed in service-layer branch
+ // XXX This will also fix running from IE, currently broken at error assert.
+ 'Error in value for action parameter [message] : Error: Expected string value and got [formquery] in argument #[1] of provider [nodeAttr].., at row 1, column 11');
+ };
+
+ this.testNormalParameterRejectsSelectorInItself = function() {
+ // normal parameters do not accept selector (in itself)
+ //
+ // This test can only run in development mode, pass otherwise.
+ if (! kukit.isDevelMode) {return;}
+ //
+ var txt= "#id:click {\n"
+ + " action-client: log;\n"
+ + " log-message: htmlid('id');\n"
+ + "}\n"
+ var cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.Document, cursor, null, true,
+ // XXX This error message will be fixed in service-layer branch
+ // XXX This will also fix running from IE, currently broken at error assert.
+ 'Provider result type [selection] not allowed in the action parameter [message]., at row 1, column 11');
+ };
+
+ this.testNormalParameterRejectsFormData = function() {
+ // normal parameters do not accept form query
+ //
+ // This test can only run in development mode, pass otherwise.
+ if (! kukit.isDevelMode) {return;}
+ //
+ var txt= "#id:click {\n"
+ + " action-client: log;\n"
+ + " log-message: form('name');\n"
+ + "}\n"
+ var cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.Document, cursor, null, true,
+ // XXX This error message will be fixed in service-layer branch
+ // XXX This will also fix running from IE, currently broken at error assert.
+ 'Provider result type [formquery] not allowed in the action parameter [message]., at row 1, column 1');
+ };
+
+ this.testKssSelectorAcceptsSelector = function() {
+ // kssSelector accepts selector
+ //
+ // This test can only run in development mode, pass otherwise.
+ if (! kukit.isDevelMode) {return;}
+ //
+ var txt= "#id:click {\n"
+ + " action-client: setAttribute;\n"
+ + " setAttribute-kssSelector: htmlid('id');\n"
+ + " setAttribute-name: name;\n"
+ + " setAttribute-value: value;\n"
+ + "}\n"
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.Document(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ };
+
+ this.testKssSelectorAcceptsString = function() {
+ // kssSelector accepts string
+ // (it will evaluate as css(xxx), but we can't check that without a dom)
+ //
+ // This test can only run in development mode, pass otherwise.
+ if (! kukit.isDevelMode) {return;}
+ //
+ var txt= "#id:click {\n"
+ + " action-client: setAttribute;\n"
+ + " setAttribute-kssSelector: htmlid('id');\n"
+ + " setAttribute-name: name;\n"
+ + " setAttribute-value: value;\n"
+ + "}\n"
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.Document(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ };
+
+ this.testKssSelectorRejectsFormData = function() {
+ // kssSelector rejects form query
+ //
+ // This test can only run in development mode, pass otherwise.
+ if (! kukit.isDevelMode) {return;}
+ //
+ var txt= "#id:click {\n"
+ + " action-client: setAttribute;\n"
+ + " setAttribute-kssSelector: form('name');\n"
+ + " setAttribute-name: name;\n"
+ + " setAttribute-value: value;\n"
+ + "}\n"
+ var cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.Document, cursor, null, true,
+ // XXX This error message will be fixed in service-layer branch
+ // XXX This will also fix running from IE, currently broken at error assert.
+ 'Provider result type [formquery] not allowed in the kss action parameter [kssSelector]., at row 1, column 11');
+ };
+
+ this.testKssSubmitFormAcceptsFormData = function() {
+ // kssSubmitForm accepts form query
+ //
+ // This test can only run in development mode, pass otherwise.
+ if (! kukit.isDevelMode) {return;}
+ //
+ var txt= "#id:click {\n"
+ + " action-server: doIt;\n"
+ + " doIt-kssSubmitForm: form('name');\n"
+ + "}\n"
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.Document(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ };
+
+ this.testKssSubmitFormAcceptsString = function() {
+ // kssSubmitForm accepts string
+ // (it will evaluate as form(xxx), but we can't check that without a dom)
+ //
+ // This test can only run in development mode, pass otherwise.
+ if (! kukit.isDevelMode) {return;}
+ //
+ var txt= "#id:click {\n"
+ + " action-server: doIt;\n"
+ + " doIt-kssSubmitForm: 'name';\n"
+ + "}\n"
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.Document(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ };
+
+ this.testKssSubmitFormRejectsSelection = function() {
+ // kssSubmitForm rejects selection
+ //
+ // This test can only run in development mode, pass otherwise.
+ if (! kukit.isDevelMode) {return;}
+ //
+ var txt= "#id:click {\n"
+ + " action-server: doIt;\n"
+ + " doIt-kssSubmitForm: htmlid('id');\n"
+ + "}\n"
+ var cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.Document, cursor, null, true,
+ // XXX This error message will be fixed in service-layer branch
+ // XXX This will also fix running from IE, currently broken at error assert.
+ 'Provider result type [selection] not allowed in the kss action parameter [kssSubmitForm]., at row 1, column 11');
+ };
+
+ this.testCombinedClientAction = function() {
+ // Client action accepts a list of combined providers.
+ //
+ // This test can only run in development mode, pass otherwise.
+ if (! kukit.isDevelMode) {return;}
+ //
+ var txt= "#id:click {\n"
+ + " action-client: htmlid(id) doIt;\n"
+ + "}\n"
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.Document(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ };
+
+ this.testCombinedClientActionRejectsFormData = function() {
+ // Client action rejects form query.
+ //
+ // This test can only run in development mode, pass otherwise.
+ if (! kukit.isDevelMode) {return;}
+ //
+ var txt= "#id:click {\n"
+ + " action-client: htmlid(id) doIt form();\n"
+ + "}\n"
+ var cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.Document, cursor, null, true,
+ // XXX This error message will be fixed in service-layer branch
+ // XXX This will also fix running from IE, currently broken at error assert.
+ 'Error in value for action definition [action-client] : Error: form method needs 1 arguments (formname)., at row 1, column 11');
+ };
+
+ this.testCombinedServerAction = function() {
+ // Server action accepts a list of combined providers.
+ //
+ // This test can only run in development mode, pass otherwise.
+ if (! kukit.isDevelMode) {return;}
+ //
+ var txt= "#id:click {\n"
+ + " action-server: doIt currentForm();\n"
+ + "}\n"
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.Document(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ };
+
+ this.testCombinedServerActionRejectsSelector = function() {
+ // Server action rejects a selection provider.
+ //
+ // This test can only run in development mode, pass otherwise.
+ if (! kukit.isDevelMode) {return;}
+ //
+ var txt= "#id:click {\n"
+ + " action-server: doIt currentForm() htmlid(id);\n"
+ + "}\n"
+ var cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.Document, cursor, null, true,
+ // XXX This error message will be fixed in service-layer branch
+ // XXX This will also fix running from IE, currently broken at error assert.
+ 'Provider result type [selection] not allowed in the action definition [action-server]., at row 1, column 11');
+ };
+
+ this.testCombinedServerActionAcceptsStringAndUrl = function() {
+ // Server action accepts a string and an url.
+ //
+ // This test can only run in development mode, pass otherwise.
+ if (! kukit.isDevelMode) {return;}
+ //
+ var txt= "#id:click {\n"
+ + " action-server: doIt url('http://foo.bar');\n"
+ + "}\n"
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.Document(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ };
+
+ this.testCombinedServerActionAcceptsUrlAndString = function() {
+ // Server action accepts a string and an url.
+ //
+ // This test can only run in development mode, pass otherwise.
+ if (! kukit.isDevelMode) {return;}
+ //
+ var txt= "#id:click {\n"
+ + " action-server: doIt url('http://foo.bar');\n"
+ + "}\n"
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.Document(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ };
+
+ this.testCombinedServerActionAcceptsStringAndFormAndUrl = function() {
+ // Server action accepts string, form, and url providers together.
+ //
+ // This test can only run in development mode, pass otherwise.
+ if (! kukit.isDevelMode) {return;}
+ //
+ var txt= "#id:click {\n"
+ + " action-server: doIt currentForm() url('http://foo.bar');\n"
+ + "}\n"
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.Document(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ };
+
+ this.testCombinedServerActionRejectsUrlInItself = function() {
+ // Server action rejects url() in itself.
+ // It should have a string in any case.
+ //
+ // This test can only run in development mode, pass otherwise.
+ if (! kukit.isDevelMode) {return;}
+ //
+ var txt= "#id:click {\n"
+ + " action-server: url('http://foo.bar');\n"
+ + "}\n"
+ var cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.Document, cursor, null, true,
+ // XXX This error message will be fixed in service-layer branch
+ // XXX This will also fix running from IE, currently broken at error assert.
+ 'Missing [string] value in the action definition [action-server]., at row 1, column 11');
+ };
+
+ this.testCombinedServerActionRejectsTwoStrings = function() {
+ // Server action rejects two strings.
+ //
+ // This test can only run in development mode, pass otherwise.
+ if (! kukit.isDevelMode) {return;}
+ //
+ var txt= "#id:click {\n"
+ + " action-server: foo 'bar';\n"
+ + "}\n"
+ var cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.Document, cursor, null, true,
+ // XXX This error message will be fixed in service-layer branch
+ // XXX This will also fix running from IE, currently broken at error assert.
+ 'Only one [string] value is allowed in the action definition [action-server]., at row 1, column 11');
+ };
+
+
+ this.testCombinedServerActionRejectsUrlWithoutParms = function() {
+ // Server action rejects url() if url has no parameter.
+ // It should have a string in any case.
+ //
+ // This test can only run in development mode, pass otherwise.
+ if (! kukit.isDevelMode) {return;}
+ //
+ var txt= "#id:click {\n"
+ + " action-server: doIt url();\n"
+ + "}\n"
+ var cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.Document, cursor, null, true,
+ // XXX This error message will be fixed in service-layer branch
+ // XXX This will also fix running from IE, currently broken at error assert.
+ 'Error in value for action definition [action-server] : Error: url() needs 1 argument., at row 1, column 11');
+ };
+
+ this.testServerActionRejectsValueProviderForString = function() {
+ // Server action must have a string, no value provider is allowed here.
+ //
+ // This test can only run in development mode, pass otherwise.
+ if (! kukit.isDevelMode) {return;}
+ //
+ var txt= "#id:click {\n"
+ + " action-server: kssAttr(blah);\n"
+ + "}\n"
+ var cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.Document, cursor, null, true,
+ // XXX This error message will be fixed in service-layer branch
+ // XXX This will also fix running from IE, currently broken at error assert.
+ 'Wrong value for key [action-server] : value providers are not allowed for action- keys., at row 1, column 11');
+ };
+
+ this.testNormalProviderRejectsValueAndSelector = function() {
+ // normal parameters rejects value and selector
+ //
+ // This test can only run in development mode, pass otherwise.
+ if (! kukit.isDevelMode) {return;}
+ //
+ var txt= "#id:click {\n"
+ + " action-client: log;\n"
+ + " log-message: kssAttr(blah) htmlid('id');\n"
+ + "}\n"
+ var cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.Document, cursor, null, true,
+ // XXX This error message will be fixed in service-layer branch
+ // XXX This will also fix running from IE, currently broken at error assert.
+ 'Provider result type [selection] not allowed in the action parameter [message]., at row 1, column 11');
+ };
+
+
+ this.testNormalProviderRejectsSelectorAndString = function() {
+ // normal parameters accepts selector and string
+ // although this does not make much sense... but it's allowed.
+ //
+ // This test can only run in development mode, pass otherwise.
+ if (! kukit.isDevelMode) {return;}
+ //
+ var txt= "#id:click {\n"
+ + " action-client: log;\n"
+ + " log-message: htmlid('id') 'message';\n"
+ + "}\n"
+ var cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.Document, cursor, null, true,
+ // XXX This error message will be fixed in service-layer branch
+ // XXX This will also fix running from IE, currently broken at error assert.
+ 'Provider result type [selection] not allowed in the action parameter [message]., at row 1, column 11')
+ };
+
+ this.testNormalProviderRejectsSelector = function() {
+ // normal parameters accepts value and selector
+ //
+ // This test can only run in development mode, pass otherwise.
+ if (! kukit.isDevelMode) {return;}
+ //
+ var txt= "#id:click {\n"
+ + " action-client: log;\n"
+ + " log-message: htmlid('id');\n"
+ + "}\n"
+ var cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.Document, cursor, null, true,
+ // XXX This error message will be fixed in service-layer branch
+ // XXX This will also fix running from IE, currently broken at error assert.
+ 'Provider result type [selection] not allowed in the action parameter [message]., at row 1, column 11')
+ };
+
+ this.testAliasedClientAction = function() {
+ // Client action can be aliased.
+ //
+ // This test can only run in development mode, pass otherwise.
+ // Note that merging the rules is not really tested from here,
+ // as we don't have DOM. So we can't really see if the alias
+ // is working, only that it is parsed well.
+ if (! kukit.isDevelMode) {return;}
+ //
+ var txt= "#id:click {\n"
+ + " action-client: doIt alias(doAlias);\n"
+ + " doAlias-foo: bar;\n"
+ + "}\n"
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.Document(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ };
+
+ this.testServerActionRejectsAlias = function() {
+ // Server action rejects alias().
+ //
+ // This test can only run in development mode, pass otherwise.
+ if (! kukit.isDevelMode) {return;}
+ //
+ var txt= "#id:click {\n"
+ + " action-server: doIt alias(doAlias);\n"
+ + " doAlias-foo: bar;\n"
+ + "}\n"
+ var cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.Document, cursor, null, true,
+ // XXX This error message will be fixed in service-layer branch
+ // XXX This will also fix running from IE, currently broken at error assert.
+ 'Provider result type [alias] not allowed in the action definition [action-server]., at row 1, column 11');
+ };
+
+ this.testNormalParameterRejectsAlias = function() {
+ // normal parameters do not accept alias.
+ //
+ // This test can only run in development mode, pass otherwise.
+ if (! kukit.isDevelMode) {return;}
+ //
+ var txt= "#id:click {\n"
+ + " action-client: log;\n"
+ + " log-message: whatever alias('name');\n"
+ + "}\n"
+ var cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.Document, cursor, null, true,
+ // XXX This error message will be fixed in service-layer branch
+ // XXX This will also fix running from IE, currently broken at error assert.
+ 'Provider result type [alias] not allowed in the action parameter [message]., at row 1, column 11');
+ };
+
+};
+
+kukit.KssParserValueProvidersCheckTestCase.prototype = new kukit.KssParserTestCaseBase;
+
+
+kukit.KssParserSelectorTestCase = function() {
+ this.name = 'kukit.KssParserSelectorTestCase';
+
+ this.testSelectorWithBinderId = function() {
+ // Parsing event selector params
+ var txt= "a:dnd-drag(hello)";
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.KssSelector(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.kssSelector.isEventSelector, true);
+ this.assertEquals(parser.kssSelector.css, 'a');
+ this.assertEquals(parser.kssSelector.name, 'drag');
+ this.assertEquals(parser.kssSelector.namespace, 'dnd');
+ this.assertEquals(parser.kssSelector.id, 'hello');
+ };
+
+ this.testKssSelector = function() {
+ var txt= "a:dnd-drag(hello)";
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.KssSelector(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.kssSelector.isEventSelector, true);
+ this.assertEquals(parser.kssSelector.css, 'a');
+ this.assertEquals(parser.kssSelector.name, 'drag');
+ this.assertEquals(parser.kssSelector.namespace, 'dnd');
+ this.assertEquals(parser.kssSelector.id, 'hello');
+
+ var txt= "a:dnd-drag-toomuch(hello)";
+ var cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.KssSelector, cursor, null, true,
+ 'Wrong event selector [dnd-drag-toomuch] : qualifier should be : or :'
+ , 25);
+
+ // maybe in std css space is not allowed in the parents,
+ // but we tolerate it
+ txt= " a div#id:dnd-drag( hello)";
+ cursor = new kukit.tk.Cursor(txt);
+ parser = new kukit.kssp.KssSelector(cursor, null, true);
+ this.assertEquals(parser.kssSelector.isEventSelector, true);
+ this.assertEquals(parser.kssSelector.css, ' a div#id');
+ this.assertEquals(parser.kssSelector.name, 'drag');
+ this.assertEquals(parser.kssSelector.namespace, 'dnd');
+ this.assertEquals(parser.kssSelector.id, 'hello');
+
+ // We do not allow space here
+ txt= " a div#id:dnd-drag (hello)";
+ cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.KssSelector, cursor, null, true,
+ 'Wrong event selector : missing event qualifier : or :().', 25);
+
+ // We do not allow space here
+ txt= " a div#id: dnd-drag(hello)";
+ cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.KssSelector, cursor, null, true,
+ 'Wrong event selector : missing event qualifier : or :().', 23);
+
+ txt= "a div#id:click ";
+ cursor = new kukit.tk.Cursor(txt);
+ parser = new kukit.kssp.KssSelector(cursor, null, true);
+ this.assertEquals(parser.kssSelector.isEventSelector, true);
+ this.assertEquals(parser.kssSelector.css, 'a div#id');
+ this.assertEquals(parser.kssSelector.name, 'click');
+ this.assertEquals(parser.kssSelector.namespace, null);
+
+ txt= "a div.class:click ";
+ cursor = new kukit.tk.Cursor(txt);
+ parser = new kukit.kssp.KssSelector(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.kssSelector.isEventSelector, true);
+ this.assertEquals(parser.kssSelector.css, 'a div.class');
+ this.assertEquals(parser.kssSelector.name, 'click');
+ this.assertEquals(parser.kssSelector.namespace, null);
+
+ txt= "a:click ";
+ cursor = new kukit.tk.Cursor(txt);
+ parser = new kukit.kssp.KssSelector(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.kssSelector.isEventSelector, true);
+ this.assertEquals(parser.kssSelector.css, 'a');
+ this.assertEquals(parser.kssSelector.name, 'click');
+ this.assertEquals(parser.kssSelector.namespace, null);
+
+ // two params: not allowed
+ txt= "a:click('hello', bello)";
+ cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.KssSelector, cursor, null, true,
+ 'Wrong event selector : [,] is not expected before the closing parenthesis. :() can have only one parameter.', 22);
+
+ // zero params: not std css but tolerated
+ txt= "a:click()";
+ cursor = new kukit.tk.Cursor(txt);
+ parser = new kukit.kssp.KssSelector(cursor, null, true);
+ this.assertParsingError(kukit.kssp.KssSelector, cursor, null, true,
+ 'Wrong event selector : missing event qualifier : or :().', 8);
+
+ txt= " (hello)";
+ cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.KssSelector, cursor, null, true,
+ 'Wrong event selector : missing event qualifier : or :().', 10);
+
+ txt= "hello ('bello')";
+ cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.KssSelector, cursor, null, true,
+ 'Wrong event selector : missing event qualifier : or :().', 16);
+
+ txt= "a:lang(hu) (hello)";
+ cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.KssSelector, cursor, null, true,
+ 'Wrong event selector : missing event qualifier : or :().', 19);
+
+ txt= "a:lang(hu) b (hello)";
+ cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.KssSelector, cursor, null, true,
+ 'Wrong event selector : missing event qualifier : or :().', 20);
+
+ // A valid attr selector in the css selector part.
+ txt= "a[href=hello].class:lang(hu) div#id:click ";
+ cursor = new kukit.tk.Cursor(txt);
+ parser = new kukit.kssp.KssSelector(cursor, null, true);
+ this.assertEquals(parser.kssSelector.isEventSelector, true);
+ this.assertEquals(parser.kssSelector.css, "a[href=hello].class:lang(hu) div#id");
+ this.assertEquals(parser.kssSelector.name, 'click');
+ this.assertEquals(parser.kssSelector.namespace, null);
+
+ txt= "a[href=hello].class:lang(hu) div#id:click(hello) ";
+ cursor = new kukit.tk.Cursor(txt);
+ parser = new kukit.kssp.KssSelector(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.kssSelector.isEventSelector, true);
+ this.assertEquals(parser.kssSelector.css, "a[href=hello].class:lang(hu) div#id");
+ this.assertEquals(parser.kssSelector.name, 'click');
+ this.assertEquals(parser.kssSelector.namespace, null);
+ this.assertEquals(parser.kssSelector.id, 'hello');
+
+ txt= " a:lang(hu) click ";
+ cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.KssSelector, cursor, null, true,
+ 'Wrong event selector : missing event qualifier : or :().', 20);
+
+ // Spaces in the end
+ // txt= " a:lang(hu, uh) b:click "; // XXX not supported
+ txt= " a:lang(hu-uh) b:click ";
+ cursor = new kukit.tk.Cursor(txt);
+ parser = new kukit.kssp.KssSelector(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.kssSelector.isEventSelector, true);
+ this.assertEquals(parser.kssSelector.css, " a:lang(hu-uh) b");
+ this.assertEquals(parser.kssSelector.name, 'click');
+ this.assertEquals(parser.kssSelector.namespace, null);
+
+ // Comment in the end
+ txt= " a:lang(hu-uh) b:click/*comment here*/";
+ cursor = new kukit.tk.Cursor(txt);
+ parser = new kukit.kssp.KssSelector(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.kssSelector.isEventSelector, true);
+ this.assertEquals(parser.kssSelector.css, " a:lang(hu-uh) b");
+ this.assertEquals(parser.kssSelector.name, 'click');
+ this.assertEquals(parser.kssSelector.namespace, null);
+
+ // Should be ok.
+ txt= "a:lang(hu)/*comment here*/b:click ";
+ cursor = new kukit.tk.Cursor(txt);
+ parser = new kukit.kssp.KssSelector(cursor, null, true);
+ this.assertEquals(parser.kssSelector.isEventSelector, true);
+ this.assertEquals(parser.kssSelector.css, "a:lang(hu)/*comment here*/b");
+ this.assertEquals(parser.kssSelector.name, 'click');
+ this.assertEquals(parser.kssSelector.namespace, null);
+
+ // Should be ok.
+ txt= "a:lang(hu) click/*comment here*/b:load ";
+ cursor = new kukit.tk.Cursor(txt);
+ parser = new kukit.kssp.KssSelector(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.kssSelector.isEventSelector, true);
+ this.assertEquals(parser.kssSelector.css, "a:lang(hu) click/*comment here*/b");
+ this.assertEquals(parser.kssSelector.name, 'load');
+ this.assertEquals(parser.kssSelector.namespace, null);
+
+ txt= "a:click:clack ";
+ cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.KssSelector, cursor, null, true,
+ 'Wrong event selector : missing event qualifier : or :().', 14);
+
+ txt= "a:click :clack ";
+ cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.KssSelector, cursor, null, true,
+ 'Wrong event selector : space before the colon.', 18);
+
+ txt= "a:click/*comment */:clack ";
+ cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.KssSelector, cursor, null, true,
+ 'Wrong event selector : missing event qualifier : or :().', 26);
+
+ txt= "click/*comment here*/:clack ";
+ cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.KssSelector, cursor, null, true,
+ 'Wrong event selector : missing event qualifier : or :().', 28);
+
+ txt= "/*comment here*/div:click ";
+ cursor = new kukit.tk.Cursor(txt);
+ parser = new kukit.kssp.KssSelector(cursor, null, true);
+
+ txt= " no-document:click(hello)";
+ cursor = new kukit.tk.Cursor(txt);
+ parser = new kukit.kssp.KssSelector(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.kssSelector.isEventSelector, true);
+ this.assertEquals(parser.kssSelector.css, " no-document");
+ this.assertEquals(parser.kssSelector.name, 'click');
+ this.assertEquals(parser.kssSelector.namespace, null);
+ this.assertEquals(parser.kssSelector.id, "hello");
+
+
+ // Event method selectors
+
+ txt= " document:click(hello) ";
+ cursor = new kukit.tk.Cursor(txt);
+ parser = new kukit.kssp.KssSelector(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.kssSelector.isMethodSelector, true);
+ this.assertEquals(parser.kssSelector.css, 'document');
+ this.assertEquals(parser.kssSelector.name, 'click');
+ this.assertEquals(parser.kssSelector.namespace, null);
+ this.assertEquals(parser.kssSelector.id, 'hello');
+
+ txt= " document:dnd-drag(hello) ";
+ cursor = new kukit.tk.Cursor(txt);
+ parser = new kukit.kssp.KssSelector(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.kssSelector.isMethodSelector, true);
+ this.assertEquals(parser.kssSelector.css, 'document');
+ this.assertEquals(parser.kssSelector.name, 'drag');
+ this.assertEquals(parser.kssSelector.namespace, 'dnd');
+ this.assertEquals(parser.kssSelector.id, 'hello');
+
+ txt= "document";
+ cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.KssSelector, cursor, null, true,
+ 'Wrong event selector : missing event qualifier : or :().', 8);
+
+ txt= "document: ";
+ cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.KssSelector, cursor, null, true,
+ 'Wrong event selector : event name cannot have spaces.', 10);
+
+ // also, "behaviour:" works
+ txt= " behaviour:click(hello) ";
+ cursor = new kukit.tk.Cursor(txt);
+ parser = new kukit.kssp.KssSelector(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.kssSelector.isMethodSelector, true);
+ this.assertEquals(parser.kssSelector.css, 'behaviour');
+ this.assertEquals(parser.kssSelector.name, 'click');
+ this.assertEquals(parser.kssSelector.namespace, null);
+ this.assertEquals(parser.kssSelector.id, 'hello');
+
+ }
+
+ this.testKssSelectorWithWrongEventWithoutNamespace = function() {
+ txt= " document:clack ";
+ cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.KssSelector, cursor, null, true,
+ 'Error : undefined global event [clack] (or maybe namespace is missing ?).');
+ txt= " document:clack(hello) ";
+ cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.KssSelector, cursor, null, true,
+ 'Error : undefined global event [clack] (or maybe namespace is missing ?).');
+ }
+
+ this.testKssSelectorWithRightEventAndMissingNamespace = function() {
+ txt= " document:drag ";
+ cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.KssSelector, cursor, null, true,
+ 'Error : undefined global event [drag] (or maybe namespace is missing ?).');
+ txt= " document:drag(hello) ";
+ cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.KssSelector, cursor, null, true,
+ 'Error : undefined global event [drag] (or maybe namespace is missing ?).');
+ }
+
+ this.testKssSelectorWithUndefinedNamespaceWhenNamespace = function() {
+ txt= " document:dad-drag ";
+ cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.KssSelector, cursor, null, true,
+ 'Error : undefined namespace or event in [dad-drag].');
+ txt= " document:dad-drag(hello) ";
+ cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.KssSelector, cursor, null, true,
+ 'Error : undefined namespace or event in [dad-drag].');
+ }
+
+ this.testKssSelectorWithUndefinedEventNameWhenNameSpace = function() {
+ txt= " document:dnd-drog ";
+ cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.KssSelector, cursor, null, true,
+ 'Error : undefined namespace or event in [dnd-drog].');
+ txt= " document:dnd-drog(hello) ";
+ cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.KssSelector, cursor, null, true,
+ 'Error : undefined namespace or event in [dnd-drog].');
+ }
+
+};
+
+kukit.KssParserSelectorTestCase.prototype = new kukit.KssParserTestCaseBase;
+
+kukit.KssParserSelectorsTestCase = function() {
+ this.name = 'kukit.KssParserSelectorsTestCase';
+
+ this.testSingleSelector = function() {
+ var txt= "a:dnd-drag(hello)";
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.KssSelectors(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.selectors.length, 1);
+ var kssSelector = parser.selectors[0];
+ this.assertEquals(kssSelector.isEventSelector, true);
+ this.assertEquals(kssSelector.css, 'a');
+ this.assertEquals(kssSelector.name, 'drag');
+ this.assertEquals(kssSelector.namespace, 'dnd');
+ this.assertEquals(kssSelector.id, 'hello');
+ };
+
+ this.testMultipleSelectors = function() {
+ var txt= "a:dnd-drag(hello), div a:click";
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.KssSelectors(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.selectors.length, 2);
+ var kssSelector = parser.selectors[0];
+ this.assertEquals(kssSelector.isEventSelector, true);
+ this.assertEquals(kssSelector.css, 'a');
+ this.assertEquals(kssSelector.name, 'drag');
+ this.assertEquals(kssSelector.namespace, 'dnd');
+ this.assertEquals(kssSelector.id, 'hello');
+ var kssSelector = parser.selectors[1];
+ this.assertEquals(kssSelector.isEventSelector, true);
+ this.assertEquals(kssSelector.css, 'div a');
+ this.assertEquals(kssSelector.name, 'click');
+ this.assertEquals(kssSelector.namespace, null);
+
+ };
+
+ this.testMultipleSelectorsWithComment = function() {
+ var txt= "a:dnd-drag(hello), /* a comment */ div a:click";
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.KssSelectors(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.selectors.length, 2);
+ var kssSelector = parser.selectors[0];
+ this.assertEquals(kssSelector.isEventSelector, true);
+ this.assertEquals(kssSelector.css, 'a');
+ this.assertEquals(kssSelector.name, 'drag');
+ this.assertEquals(kssSelector.namespace, 'dnd');
+ this.assertEquals(kssSelector.id, 'hello');
+ var kssSelector = parser.selectors[1];
+ this.assertEquals(kssSelector.isEventSelector, true);
+ this.assertEquals(kssSelector.css, 'div a');
+ this.assertEquals(kssSelector.name, 'click');
+ this.assertEquals(kssSelector.namespace, null);
+ };
+
+ this.testSingleSelectorWithCommaInDoubleQuoteStringInSelector = function() {
+ var txt = 'a[value="Hi, I am a comma"]:dnd-drag(hello)';
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.KssSelectors(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.selectors.length, 1);
+ var kssSelector = parser.selectors[0];
+ this.assertEquals(kssSelector.isEventSelector, true);
+ this.assertEquals(kssSelector.css, 'a[value="Hi, I am a comma"]');
+ this.assertEquals(kssSelector.name, 'drag');
+ this.assertEquals(kssSelector.namespace, 'dnd');
+ this.assertEquals(kssSelector.id, 'hello');
+ };
+
+ this.testSingleSelectorWithCommaInSingleQuoteStringInSelector = function() {
+ var txt = "a[value='Hi, I am a comma']:dnd-drag(hello)";
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.KssSelectors(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.selectors.length, 1);
+ var kssSelector = parser.selectors[0];
+ this.assertEquals(kssSelector.isEventSelector, true);
+ this.assertEquals(kssSelector.css, "a[value='Hi, I am a comma']");
+ this.assertEquals(kssSelector.name, 'drag');
+ this.assertEquals(kssSelector.namespace, 'dnd');
+ this.assertEquals(kssSelector.id, 'hello');
+ };
+
+ this.testMultipleSelectorsWithCommaInDoubleQuoteStringInSelector = function() {
+ var txt = 'a[value="Hi, I am a comma"]:dnd-drag(hello), div a:click';
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.KssSelectors(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.selectors.length, 2);
+ var kssSelector = parser.selectors[0];
+ this.assertEquals(kssSelector.isEventSelector, true);
+ this.assertEquals(kssSelector.css, 'a[value="Hi, I am a comma"]');
+ this.assertEquals(kssSelector.name, 'drag');
+ this.assertEquals(kssSelector.namespace, 'dnd');
+ this.assertEquals(kssSelector.id, 'hello');
+ var kssSelector = parser.selectors[1];
+ this.assertEquals(kssSelector.isEventSelector, true);
+ this.assertEquals(kssSelector.css, 'div a');
+ this.assertEquals(kssSelector.name, 'click');
+ this.assertEquals(kssSelector.namespace, null);
+ };
+
+ this.testMultipleSelectorsWithCommaInSingleQuoteStringInSelector = function() {
+ var txt = "a[value='Hi, I am a comma']:dnd-drag(hello), div a:click";
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.KssSelectors(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.selectors.length, 2);
+ var kssSelector = parser.selectors[0];
+ this.assertEquals(kssSelector.isEventSelector, true);
+ this.assertEquals(kssSelector.css, "a[value='Hi, I am a comma']");
+ this.assertEquals(kssSelector.name, 'drag');
+ this.assertEquals(kssSelector.namespace, 'dnd');
+ this.assertEquals(kssSelector.id, 'hello');
+ var kssSelector = parser.selectors[1];
+ this.assertEquals(kssSelector.isEventSelector, true);
+ this.assertEquals(kssSelector.css, 'div a');
+ this.assertEquals(kssSelector.name, 'click');
+ this.assertEquals(kssSelector.namespace, null);
+ };
+
+ this.testMultipleSelectorsWithCommentAndNewline = function() {
+ var txt= "a:dnd-drag(hello), /* a comment */ \n div a:click";
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.KssSelectors(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.selectors.length, 2);
+ var kssSelector = parser.selectors[0];
+ this.assertEquals(kssSelector.isEventSelector, true);
+ this.assertEquals(kssSelector.css, 'a');
+ this.assertEquals(kssSelector.name, 'drag');
+ this.assertEquals(kssSelector.namespace, 'dnd');
+ this.assertEquals(kssSelector.id, 'hello');
+ var kssSelector = parser.selectors[1];
+ this.assertEquals(kssSelector.isEventSelector, true);
+ this.assertEquals(kssSelector.css, 'div a');
+ this.assertEquals(kssSelector.name, 'click');
+ this.assertEquals(kssSelector.namespace, null);
+ };
+
+ this.testMultipleSelectorsWithNewline = function() {
+ var txt= "a:dnd-drag(hello), \n div a:click";
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.KssSelectors(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.selectors.length, 2);
+ var kssSelector = parser.selectors[0];
+ this.assertEquals(kssSelector.isEventSelector, true);
+ this.assertEquals(kssSelector.css, 'a');
+ this.assertEquals(kssSelector.name, 'drag');
+ this.assertEquals(kssSelector.namespace, 'dnd');
+ this.assertEquals(kssSelector.id, 'hello');
+ var kssSelector = parser.selectors[1];
+ this.assertEquals(kssSelector.isEventSelector, true);
+ this.assertEquals(kssSelector.css, 'div a');
+ this.assertEquals(kssSelector.name, 'click');
+ this.assertEquals(kssSelector.namespace, null);
+ };
+
+ this.testSingleSelectorWithFirstComma = function() {
+ var txt= ",a:dnd-drag(hello),";
+ var cursor = new kukit.tk.Cursor(txt);
+ var msg = 'Wrong event selector : missing event';
+ this.assertParsingError(kukit.kssp.KssSelectors, cursor, null, true,
+ msg, 1);
+ }
+
+ this.testSingleSelectorWithMiddleComma = function() {
+ var txt= "a:dnd-drag(hello),,p:click";
+ var cursor = new kukit.tk.Cursor(txt);
+ var msg = 'Wrong event selector : missing event';
+ this.assertParsingError(kukit.kssp.KssSelectors, cursor, null, true,
+ msg, 1);
+ }
+
+ this.testSingleSelectorWithAdditionalComma = function() {
+ var txt= "a:dnd-drag(hello),";
+ var cursor = new kukit.tk.Cursor(txt);
+ var msg = 'Wrong event selector : trailing comma';
+ this.assertParsingError(kukit.kssp.KssSelectors, cursor, null, true,
+ msg, 1);
+ }
+
+ this.testSingleSelectorWithAdditionalCommas = function() {
+ var txt= "a:dnd-drag(hello),,";
+ var cursor = new kukit.tk.Cursor(txt);
+ var msg = 'Wrong event selector : missing event';
+ this.assertParsingError(kukit.kssp.KssSelectors, cursor, null, true,
+ msg, 1);
+ }
+
+ this.testEventRulesWithMultipleSelectors = function() {
+ var txt= ""
+ +"/* a long\n"
+ +"** comment\n"
+ +"*/\n"
+ +"\n"
+ +"#calendar-previous a:click,\n"
+ +".inlineEditable:blur{ \n"
+ +" action-server : kukitresponse/kukitGetPreviousMonth;\n"
+ +"}\n"
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.Document(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.eventRules.length, 2);
+ var rule;
+ var action;
+
+ rule = parser.eventRules[0];
+ this.assertDictEquals(rule.parms, {});
+ this.assertEquals(rule.kssSelector.isEventSelector, true);
+ this.assertEquals(rule.kssSelector.css, '#calendar-previous a');
+ this.assertEquals(rule.kssSelector.name, 'click');
+ this.assertEquals(rule.kssSelector.namespace, null);
+ action = rule.actions.content['kukitresponse/kukitGetPreviousMonth'];
+ this.assertEquals(action.type, 'S');
+ this.assertEquals(action.name, 'kukitresponse/kukitGetPreviousMonth');
+ this.assertEquals(action.error, null);
+ this.assertKssParmEquals(action.parms, {});
+
+ rule = parser.eventRules[1];
+ this.assertDictEquals(rule.parms, {});
+ this.assertEquals(rule.kssSelector.isEventSelector, true);
+ this.assertEquals(rule.kssSelector.css, '.inlineEditable');
+ this.assertEquals(rule.kssSelector.name, 'blur');
+ this.assertEquals(rule.kssSelector.namespace, null);
+ action = rule.actions.content['kukitresponse/kukitGetPreviousMonth'];
+ this.assertEquals(action.type, 'S');
+ this.assertEquals(action.name, 'kukitresponse/kukitGetPreviousMonth');
+ this.assertEquals(action.error, null);
+ this.assertKssParmEquals(action.parms, {});
+ }
+
+ this.testEventParameters = function() {
+ var txt= ""
+ +"/* a long\n"
+ +"** comment\n"
+ +"*/\n"
+ +"\n"
+ +"#calendar-previous a:click,\n"
+ +".inlineEditable:keydown{ \n"
+ +" evt-click-allowbubbling: true;\n"
+ +" evt-keydown-keycode: 1;\n"
+ +" action-server : kukitresponse/kukitGetPreviousMonth;\n"
+ +"}\n"
+ var cursor = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.Document(cursor, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.eventRules.length, 2);
+ var rule;
+ var action;
+
+ rule = parser.eventRules[0];
+ this.assertDictEquals(rule.parms, {'allowbubbling': 'true'});
+ this.assertEquals(rule.kssSelector.isEventSelector, true);
+ this.assertEquals(rule.kssSelector.css, '#calendar-previous a');
+ this.assertEquals(rule.kssSelector.name, 'click');
+ this.assertEquals(rule.kssSelector.namespace, null);
+ action = rule.actions.content['kukitresponse/kukitGetPreviousMonth'];
+ this.assertEquals(action.type, 'S');
+ this.assertEquals(action.name, 'kukitresponse/kukitGetPreviousMonth');
+ this.assertEquals(action.error, null);
+ this.assertKssParmEquals(action.parms, {});
+
+ rule = parser.eventRules[1];
+ this.assertDictEquals(rule.parms, {'keycode':'1'});
+ this.assertEquals(rule.kssSelector.isEventSelector, true);
+ this.assertEquals(rule.kssSelector.css, '.inlineEditable');
+ this.assertEquals(rule.kssSelector.name, 'keydown');
+ this.assertEquals(rule.kssSelector.namespace, null);
+
+ action = rule.actions.content['kukitresponse/kukitGetPreviousMonth'];
+ this.assertEquals(action.type, 'S');
+ this.assertEquals(action.name, 'kukitresponse/kukitGetPreviousMonth');
+ this.assertEquals(action.error, null);
+ this.assertKssParmEquals(action.parms, {});
+ }
+
+ this.testEventParametersErrorWithoutNamespace = function() {
+ var txt= ""
+ +"/* a long\n"
+ +"** comment\n"
+ +"*/\n"
+ +"\n"
+ +"#calendar-previous a:click,\n"
+ +".inlineEditable:keydown{ \n"
+ +" evt-click-allowbubbling: true;\n"
+ +" evt-blur-allowbubling: true;\n"
+ +" action-server : kukitresponse/kukitGetPreviousMonth;\n"
+ +"}\n"
+ var cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.Document, cursor, null, true,
+ 'Wrong value for evt-[-] [blur] : - should exist in the event of the selectors.', 6);
+ }
+
+ this.testEventParametersErrorWithNamespace = function() {
+ var txt= ""
+ +"/* a long\n"
+ +"** comment\n"
+ +"*/\n"
+ +"\n"
+ +"#calendar-previous a:click,\n"
+ +".inlineEditable:keydown{ \n"
+ +" evt-click-allowbubbling: true;\n"
+ +" evt-dnd-drag-preventdefault: true;\n"
+ +" action-server : kukitresponse/kukitGetPreviousMonth;\n"
+ +"}\n"
+ var cursor = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.Document, cursor, null, true,
+ 'Wrong value for evt-[-] [dnd-drag] : - should exist in the event of the selectors.', 6);
+ }
+
+ this.testValueProvidersInEventIdentification = function() {
+ // Param providers within the event identification
+
+ var txt= "a:click(kssAttr(hello))";
+ var src = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.KssSelector(src, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.kssSelector.isEventSelector, true);
+ this.assertEquals(parser.kssSelector.css, 'a');
+ this.assertEquals(parser.kssSelector.name, 'click');
+ this.assertEquals(parser.kssSelector.namespace, null);
+ this.assertEquals(parser.kssSelector.id, null);
+ this.assertEquals(parser.kssSelector.ppid.methodName, 'kssAttr');
+ this.assertListEquals(parser.kssSelector.ppid.args, ['hello']);
+ };
+
+ this.testValueProvidersInEventIdentification2 = function() {
+ var txt= "a:click(kssAttr(hello, true ))";
+ var src = new kukit.tk.Cursor(txt);
+ var parser = new kukit.kssp.KssSelector(src, null, true);
+ this.assertEquals(parser.finished, true);
+ this.assertEquals(parser.kssSelector.isEventSelector, true);
+ this.assertEquals(parser.kssSelector.css, 'a');
+ this.assertEquals(parser.kssSelector.name, 'click');
+ this.assertEquals(parser.kssSelector.namespace, null);
+ this.assertEquals(parser.kssSelector.id, null);
+ this.assertEquals(parser.kssSelector.ppid.methodName, 'kssAttr');
+ this.assertListEquals(parser.kssSelector.ppid.args, ['hello', 'true']);
+ };
+
+ this.testValueProvidersInEventIdentificationRejectsMoreParameters = function() {
+ var txt= "a:drag(kssAttr(hello), xxx)";
+ var src = new kukit.tk.Cursor(txt);
+ this.assertParsingError(kukit.kssp.KssSelector, src, null, true,
+ 'Wrong event selector : [,] is not expected before the closing parenthesis. :() can have only one parameter.', 000);
+ };
+
+};
+
+kukit.KssParserSelectorsTestCase.prototype = new kukit.KssParserTestCaseBase;
+
+if (typeof(testcase_registry) != 'undefined') {
+ testcase_registry.registerTestCase(kukit.KssParserTestCase,
+ 'kukit.KssParserTestCase');
+ testcase_registry.registerTestCase(kukit.KssParserValueProvidersCheckTestCase,
+ 'kukit.KssParserValueProvidersCheckTestCase');
+ testcase_registry.registerTestCase(kukit.KssParserSelectorTestCase,
+ 'kukit.KssParserSelectorTestCase');
+ testcase_registry.registerTestCase(kukit.KssParserSelectorsTestCase,
+ 'kukit.KssParserSelectorsTestCase');
+}
Index: /quintagroup.plonetabs/trunk/quintagroup/plonetabs/tests/ecmaunits/js/test_requestmanager.js
===================================================================
--- /quintagroup.plonetabs/trunk/quintagroup/plonetabs/tests/ecmaunits/js/test_requestmanager.js (revision 884)
+++ /quintagroup.plonetabs/trunk/quintagroup/plonetabs/tests/ecmaunits/js/test_requestmanager.js (revision 884)
@@ -0,0 +1,341 @@
+/*
+* Copyright (c) 2005-2006
+* Authors:
+* Balázs Reé
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License version 2 as published
+* by the Free Software Foundation.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+* 02111-1307, USA.
+*/
+
+if (typeof(kukit) == "undefined") {
+ var kukit = {};
+}
+
+/* Dummy scheduler for testing */
+
+kukit.DummyScheduler = function(func) {
+};
+
+kukit.DummyScheduler.prototype.setNextWakeAtLeast = function(ts) {
+};
+
+kukit.RequestManagerTestCase = function() {
+ this.name = 'kukit.RequestManagerTestCase';
+
+ this.setUp = function() {
+ };
+
+ this.testSendQueue = function() {
+ // Test the send queue
+ var q;
+
+ var expired = [];
+ var cbe = function(item) {
+ expired.push(item);
+ };
+ // Push items at different timepoints, with same timeout
+ q = new kukit.rm.TestTimerQueue(cbe);
+ var i1 = new kukit.rm.TestRequestItem(null, 1, null, 10000, 1000);
+ q.push(i1);
+ var i2 = new kukit.rm.TestRequestItem(null, 2, null, 10000, 2000);
+ q.push(i2);
+ var i3 = new kukit.rm.TestRequestItem(null, 3, null, 10000, 3000);
+ q.push(i3);
+ var i4 = new kukit.rm.TestRequestItem(null, 4, null, 10000, 4000);
+ q.push(i4);
+ this.assertEquals(q.count, 4);
+ // pop 2, 4
+ this.assertEquals(q.pop(i2), true);
+ this.assertEquals(q.pop(i4), true);
+ this.assertEquals(q.count, 2);
+ this.assertEquals(expired.length, 0);
+ // expire 1, 2
+ q.handleExpiration(12010);
+ this.assertEquals(q.count, 1);
+ this.assertEquals(expired.length, 1);
+ this.assertEquals(expired[0].url, 1);
+ // pop 1, 3
+ this.assertEquals(q.pop(i1), false);
+ this.assertEquals(q.pop(i3), true);
+ this.assertEquals(q.count, 0);
+ this.assertEquals(expired.length, 1);
+ };
+
+ this.assertRmQueues = function(rm, out, wai) {
+ this.assertEquals(rm.sentNr, out, 'OUT does not match');
+ this.assertEquals(rm.waitingQueue.size(), wai, 'WAI does not match');
+ };
+
+ this.testNormalSend = function() {
+ // Test a simple send situation
+ var rm = new kukit.rm.RequestManager(null, 2, kukit.DummyScheduler);
+ this.assertRmQueues(rm, 0, 0);
+ // queues
+ var sent = [];
+ var cbs = function(item) {
+ sent.push(item);
+ };
+
+ // send some elements
+ rm.notifyServer(cbs, 1, null, 10000, 1000);
+ this.assertRmQueues(rm, 1, 0);
+ this.assertEquals(sent.length, 1);
+ this.assertEquals(sent[0].url, 1);
+ rm.notifyServer(cbs, 2, null, 10000, 2000);
+ this.assertRmQueues(rm, 2, 0);
+ this.assertEquals(sent.length, 2);
+ this.assertEquals(sent[1].url, 2);
+ rm.notifyServer(cbs, 3, null, 10000, 3000);
+ this.assertRmQueues(rm, 2, 1);
+ this.assertEquals(sent.length, 2);
+
+ // receive the elements
+ this.assertEquals(sent[0].receivedResult(4000), true);
+ this.assertRmQueues(rm, 2, 0);
+ this.assertEquals(sent.length, 3);
+ this.assertEquals(sent[2].url, 3);
+ this.assertEquals(sent[1].receivedResult(5000), true);
+ this.assertRmQueues(rm, 1, 0);
+ this.assertEquals(sent.length, 3);
+ this.assertEquals(sent[2].receivedResult(6000), true);
+ this.assertRmQueues(rm, 0, 0);
+ this.assertEquals(sent.length, 3);
+
+ };
+
+ this.testSendWithTimeouts = function() {
+ // Test a simple timeout situation
+ var rm = new kukit.rm.RequestManager(null, 2, kukit.DummyScheduler);
+ this.assertRmQueues(rm, 0, 0);
+ // queues
+ var sent = [];
+ var cbs = function(item) {
+ sent.push(item);
+ };
+ var timeout = [];
+ var thook = function(item) {
+ timeout.push(item);
+ };
+
+ // send some elements
+ rm.notifyServer(cbs, 1, thook, 10000, 1000);
+ this.assertRmQueues(rm, 1, 0);
+ this.assertEquals(sent.length, 1);
+ this.assertEquals(sent[0].url, 1);
+ this.assertEquals(timeout.length, 0);
+ rm.notifyServer(cbs, 2, thook, 10000, 2000);
+ this.assertRmQueues(rm, 2, 0);
+ this.assertEquals(sent.length, 2);
+ this.assertEquals(sent[1].url, 2);
+ this.assertEquals(timeout.length, 0);
+
+ // time out 1
+ rm.checkTimeout(11070);
+ this.assertRmQueues(rm, 2, 0);
+ this.assertEquals(sent.length, 2);
+ this.assertEquals(timeout.length, 1);
+ this.assertEquals(timeout[0].url, 1);
+
+ // receive the elements
+ this.assertEquals(sent[0].receivedResult(11060), false);
+ this.assertRmQueues(rm, 1, 0);
+ this.assertEquals(sent.length, 2);
+ this.assertEquals(timeout.length, 1);
+ this.assertEquals(sent[1].receivedResult(11070), true);
+ this.assertRmQueues(rm, 0, 0);
+ this.assertEquals(sent.length, 2);
+ this.assertEquals(timeout.length, 1);
+
+ };
+
+ this.testSendWithQueuedTimeout = function() {
+ // Test timeout with queues not sent out
+ var rm = new kukit.rm.RequestManager(null, 2, kukit.DummyScheduler);
+ this.assertRmQueues(rm, 0, 0);
+ // queues
+ var sent = [];
+ var cbs = function(item) {
+ sent.push(item);
+ };
+
+ // send some elements
+ rm.notifyServer(cbs, 1, null, 10000, 1000);
+ this.assertRmQueues(rm, 1, 0);
+ this.assertEquals(sent.length, 1);
+ this.assertEquals(sent[0].url, 1);
+ rm.notifyServer(cbs, 2, null, 10000, 2000);
+ this.assertRmQueues(rm, 2, 0);
+ this.assertEquals(sent.length, 2);
+ this.assertEquals(sent[1].url, 2);
+ rm.notifyServer(cbs, 3, null, 10000, 3000);
+ this.assertRmQueues(rm, 2, 1);
+ this.assertEquals(sent.length, 2);
+
+ // time out 1
+ rm.checkTimeout(11050);
+ this.assertRmQueues(rm, 2, 1);
+ this.assertEquals(sent.length, 2);
+
+ // receive the elements
+ this.assertEquals(sent[0].receivedResult(11060), false);
+ this.assertRmQueues(rm, 2, 0);
+ this.assertEquals(sent.length, 3);
+ this.assertEquals(sent[2].url, 3);
+ this.assertEquals(sent[1].receivedResult(11070), true);
+ this.assertRmQueues(rm, 1, 0);
+ this.assertEquals(sent.length, 3);
+ this.assertEquals(sent[2].receivedResult(11080), true);
+ this.assertRmQueues(rm, 0, 0);
+ this.assertEquals(sent.length, 3);
+
+ };
+
+ this.testSendWithQueuedSwallowed = function() {
+ // If the queued element is timed out, it it not sent out
+ var rm = new kukit.rm.RequestManager(null, 2, kukit.DummyScheduler);
+ this.assertRmQueues(rm, 0, 0);
+ // queues
+ var sent = [];
+ var cbs = function(item) {
+ sent.push(item);
+ };
+
+ // send some elements
+ rm.notifyServer(cbs, 1, null, 10000, 1000);
+ this.assertRmQueues(rm, 1, 0);
+ this.assertEquals(sent.length, 1);
+ this.assertEquals(sent[0].url, 1);
+ rm.notifyServer(cbs, 2, null, 10000, 2000);
+ this.assertRmQueues(rm, 2, 0);
+ this.assertEquals(sent.length, 2);
+ this.assertEquals(sent[1].url, 2);
+ rm.notifyServer(cbs, 3, null, 8500, 3000);
+ this.assertRmQueues(rm, 2, 1);
+ this.assertEquals(sent.length, 2);
+
+ // time out 1
+ rm.checkTimeout(11050);
+ this.assertRmQueues(rm, 2, 1);
+ this.assertEquals(sent.length, 2);
+
+ // time out 3
+ rm.checkTimeout(11550);
+ this.assertRmQueues(rm, 2, 1);
+ this.assertEquals(sent.length, 2);
+
+ // receive the elements (will swallow the queued one)
+ this.assertEquals(sent[0].receivedResult(11560), false);
+ this.assertRmQueues(rm, 1, 0);
+ this.assertEquals(sent.length, 2);
+ this.assertEquals(sent[1].receivedResult(11570), true);
+ this.assertRmQueues(rm, 0, 0);
+ this.assertEquals(sent.length, 2);
+
+ };
+
+ this.testAllTimedOut = function() {
+ // If all elements are timed out
+ var rm = new kukit.rm.RequestManager(null, 2, kukit.DummyScheduler);
+ this.assertRmQueues(rm, 0, 0);
+ // queues
+ var sent = [];
+ var cbs = function(item) {
+ sent.push(item);
+ };
+
+ // send some elements
+ rm.notifyServer(cbs, 1, null, 10000, 1000);
+ this.assertRmQueues(rm, 1, 0);
+ this.assertEquals(sent.length, 1);
+ this.assertEquals(sent[0].url, 1);
+ rm.notifyServer(cbs, 2, null, 10000, 2000);
+ this.assertRmQueues(rm, 2, 0);
+ this.assertEquals(sent.length, 2);
+ this.assertEquals(sent[1].url, 2);
+ rm.notifyServer(cbs, 3, null, 10000, 3000);
+ this.assertRmQueues(rm, 2, 1);
+ this.assertEquals(sent.length, 2);
+
+ // time out 1, 2, 3
+ rm.checkTimeout(20000);
+ this.assertRmQueues(rm, 2, 1);
+ this.assertEquals(sent.length, 2);
+
+ // receive the elements (will swallow the queued one)
+ this.assertEquals(sent[0].receivedResult(20010), false);
+ this.assertRmQueues(rm, 1, 0);
+ this.assertEquals(sent.length, 2);
+ this.assertEquals(sent[1].receivedResult(20020), false);
+ this.assertRmQueues(rm, 0, 0);
+ this.assertEquals(sent.length, 2);
+
+ };
+
+ this.testTimeoutHooks = function() {
+ // Test if timeout hook(s) are called
+ var rm = new kukit.rm.RequestManager(null, 2, kukit.DummyScheduler);
+ this.assertRmQueues(rm, 0, 0);
+ // queues
+ var sent = [];
+ var cbs = function(item) {
+ sent.push(item);
+ };
+ var timeout1 = [];
+ var thook1 = function(item) {
+ timeout1.push(item);
+ };
+ var timeout2 = [];
+ var thook2 = function(item) {
+ timeout2.push(item);
+ };
+ var timeout3 = [];
+ var thook3 = function(item) {
+ timeout3.push(item);
+ };
+
+ // send some elements
+ rm.notifyServer(cbs, 1, thook1, 10000, 1000);
+ this.assertRmQueues(rm, 1, 0);
+ this.assertEquals(sent.length, 1);
+ this.assertEquals(sent[0].url, 1);
+ rm.notifyServer(cbs, 2, thook2, 10000, 2000);
+ this.assertRmQueues(rm, 2, 0);
+ this.assertEquals(sent.length, 2);
+ this.assertEquals(sent[1].url, 2);
+ rm.notifyServer(cbs, 3, thook3, 10000, 3000);
+ this.assertRmQueues(rm, 2, 1);
+ this.assertEquals(sent.length, 2);
+
+ // time out 1, 2, 3
+ rm.checkTimeout(20000);
+ this.assertRmQueues(rm, 2, 1);
+ this.assertEquals(sent.length, 2);
+
+ // Check the timeout queues
+ this.assertEquals(timeout1.length, 1);
+ this.assertEquals(timeout1[0].url, 1);
+ this.assertEquals(timeout2.length, 1);
+ this.assertEquals(timeout2[0].url, 2);
+ this.assertEquals(timeout3.length, 1);
+ this.assertEquals(timeout3[0].url, 3);
+
+ };
+
+};
+
+kukit.RequestManagerTestCase.prototype = new kukit.UtilsTestCaseBase;
+
+if (typeof(testcase_registry) != 'undefined') {
+ testcase_registry.registerTestCase(kukit.RequestManagerTestCase, 'kukit.RequestManagerTestCase');
+}
Index: /quintagroup.plonetabs/trunk/quintagroup/plonetabs/tests/ecmaunits/js/test_tokenizer.js
===================================================================
--- /quintagroup.plonetabs/trunk/quintagroup/plonetabs/tests/ecmaunits/js/test_tokenizer.js (revision 884)
+++ /quintagroup.plonetabs/trunk/quintagroup/plonetabs/tests/ecmaunits/js/test_tokenizer.js (revision 884)
@@ -0,0 +1,488 @@
+/*
+* Copyright (c) 2005-2006
+* Authors:
+* Martin Heidegger
+* Balazs Ree
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License version 2 as published
+* by the Free Software Foundation.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+* 02111-1307, USA.
+*/
+
+if (typeof(kukit) == "undefined") {
+ var kukit = {};
+}
+
+kukit.TokenizerTestCaseBase = function() {
+
+ this.printDebug = function(parser, prefix) {
+ if (typeof(prefix) == "undefined") {
+ prefix = '';
+ print('########################');
+ }
+ for (var i=0; i b) return -1;
+ else return 0;
+ };
+ q = new kukit.ut.SortedQueue(comparefunc);
+ this.assertEquals(q.empty(), true);
+ this.assertEquals(q.size(), 0);
+ q.push(1);
+ q.push(3);
+ q.push(2);
+ q.push(4);
+ this.assertEquals(q.empty(), false);
+ this.assertEquals(q.size(), 4);
+ this.assertEquals(q.front(), 4);
+ this.assertListEquals(q.elements, [4, 3, 2, 1]);
+ this.assertEquals(q.pop(), 4);
+ this.assertEquals(q.pop(), 3);
+ this.assertEquals(q.pop(), 2);
+ this.assertEquals(q.pop(), 1);
+ this.assertEquals(q.empty(), true);
+ this.assertEquals(q.size(), 0);
+
+ };
+
+ this.testEvalList = function() {
+ var value = kukit.ut.evalList('');
+ this.assertListEquals(value, []);
+ var value = kukit.ut.evalList(' ');
+ this.assertListEquals(value, []);
+ value = kukit.ut.evalList('1');
+ this.assertListEquals(value, ['1']);
+ value = kukit.ut.evalList('1,2');
+ this.assertListEquals(value, ['1', '2']);
+ value = kukit.ut.evalList('1, 2');
+ this.assertListEquals(value, ['1', '2']);
+ value = kukit.ut.evalList('1, 2 ');
+ this.assertListEquals(value, ['1', '2']);
+ value = kukit.ut.evalList(' 1, 2');
+ this.assertListEquals(value, ['1', '2']);
+ value = kukit.ut.evalList(' 1 , 2 ');
+ this.assertListEquals(value, ['1', '2']);
+ }
+
+};
+
+kukit.UtilsTestCase.prototype = new kukit.UtilsTestCaseBase;
+
+kukit.BaseURLTestCase = function() {
+ this.name = 'kukit.BaseURLTestCase';
+
+ this.setUp = function() {
+ this.dom = new global.dommer.DOM();
+ this.doc = this.dom.createDocument();
+ this.html = this.doc.createElement('html');
+ this.doc.appendChild(this.html);
+ this.baseTag = this.doc.createElement('base');
+ this.kssBaseTag = this.doc.createElement('link');
+ this.kssBaseTag.rel = 'kss-base-url';
+ this.pageLocation = "http://kssproject.org/tests";
+ this.baseLocation = "http://kssproject.org/base";
+ this.kssBaseLocation = "http://kssproject.org/kssbase";
+ this.pageRoot = "http://kssproject.org";
+ };
+
+ this.testLocation = function() {
+ var base = kukit.ut.calculateBase(this.doc, this.pageLocation);
+ this.assertEquals(base, this.pageRoot + '/');
+ };
+
+ this.testLocationWithTrailingSlash = function() {
+ var base = kukit.ut.calculateBase(this.doc, this.pageLocation + '/');
+ this.assertEquals(base, this.pageLocation + '/');
+ };
+
+ this.testBaseTagWithTrailingSlash = function() {
+ this.baseTag.href = this.baseLocation + '/';
+ this.html.appendChild(this.baseTag);
+ var base = kukit.ut.calculateBase(this.doc, this.pageLocation);
+ this.assertEquals(base, this.baseLocation + '/');
+ };
+
+ this.testBaseTag = function() {
+ this.baseTag.href = this.baseLocation;
+ this.html.appendChild(this.baseTag);
+ var base = kukit.ut.calculateBase(this.doc, this.pageLocation);
+ this.assertEquals(base, this.pageRoot + '/');
+ };
+
+ this.testKssBaseTagWithTrailingSlash = function() {
+ this.kssBaseTag.href = this.kssBaseLocation + '/';
+ this.html.appendChild(this.kssBaseTag);
+ var base = kukit.ut.calculateBase(this.doc, this.pageLocation);
+ this.assertEquals(base, this.kssBaseLocation + '/');
+ };
+
+ // XXX This test is currently wrong, because Plone does _not_
+ // XXX put the trailing slash to the end, so kss-base-url without
+ // XXX the trailing slash is currently interpreted as if it were there.
+ this.testKssBaseTag = function() {
+ this.kssBaseTag.href = this.kssBaseLocation;
+ this.html.appendChild(this.kssBaseTag);
+ var base = kukit.ut.calculateBase(this.doc, this.pageLocation);
+ // XXX this.assertEquals(base, this.pageRoot + '/');
+ this.assertEquals(base, this.kssBaseLocation + '/');
+ };
+
+ this.testBothKssAndBaseTagWithTrailingSlash = function() {
+ this.kssBaseTag.href = this.kssBaseLocation + '/';
+ this.html.appendChild(this.kssBaseTag);
+ this.baseTag.href = this.baseLocation;
+ this.html.appendChild(this.baseTag);
+ var base = kukit.ut.calculateBase(this.doc, this.pageLocation);
+ this.assertEquals(base, this.kssBaseLocation + '/');
+ };
+
+ // XXX This test is currently wrong, because Plone does _not_
+ // XXX put the trailing slash to the end, so kss-base-url without
+ // XXX the trailing slash is currently interpreted as if it were there.
+ this.testBothKssAndBaseTag = function() {
+ this.kssBaseTag.href = this.kssBaseLocation;
+ this.html.appendChild(this.kssBaseTag);
+ this.baseTag.href = this.baseLocation;
+ this.html.appendChild(this.baseTag);
+ var base = kukit.ut.calculateBase(this.doc, this.pageLocation);
+ // XXX this.assertEquals(base, this.pageRoot + '/');
+ this.assertEquals(base, this.kssBaseLocation + '/');
+ };
+};
+
+kukit.BaseURLTestCase.prototype = new kukit.UtilsTestCaseBase;
+
+if (typeof(testcase_registry) != 'undefined') {
+ testcase_registry.registerTestCase(kukit.UtilsTestCase, 'kukit.UtilsTestCase');
+ testcase_registry.registerTestCase(kukit.BaseURLTestCase, 'kukit.BaseURLTestCase');
+}
Index: /quintagroup.plonetabs/trunk/quintagroup/plonetabs/tests/ecmaunits/js/unittestUtilities.js
===================================================================
--- /quintagroup.plonetabs/trunk/quintagroup/plonetabs/tests/ecmaunits/js/unittestUtilities.js (revision 884)
+++ /quintagroup.plonetabs/trunk/quintagroup/plonetabs/tests/ecmaunits/js/unittestUtilities.js (revision 884)
@@ -0,0 +1,161 @@
+
+function TestCaseRegistry() {
+ this._testcases = new Object();
+
+ this.registerTestCase = function(testcase, suite_name) {
+ if (!testcase) {
+ throw('TestCaseRegistry.registerTestCase() requires a testcase as argument');
+ }
+ testcase = new testcase();
+ if (!suite_name) {
+ suite_name = 'default';
+ }
+ if (!this._testcases[suite_name]) {
+ this._testcases[suite_name] = new Array();
+ }
+ this._testcases[suite_name].push(testcase);
+ }
+
+ this.setTestSuiteFilter = function(filter) {
+ if (filter) {
+ this.suite_filter = new RegExp(filter, "i");
+ } else {
+ this.suite_filter = null;
+ }
+ }
+
+ this.setTestFilter = function(filter) {
+ if (filter) {
+ this.test_filter = new RegExp(filter, "i");
+ } else {
+ this.test_filter = null;
+ }
+ }
+
+ this.getFilteredTestCases = function() {
+ var testcases = new Array();
+
+ var suites = this.getFilteredTestSuitNames();
+ for (suite_index in suites) {
+ var suite = this._testcases[suites[suite_index]];
+ for (var test_index in suite) {
+ var testcase = suite[test_index];
+ if (this.test_filter) {
+ if (!this.test_filter.test(testcase.name)) {
+ continue;
+ }
+ }
+ testcases.push(testcase);
+ }
+ }
+
+ return testcases;
+ }
+
+ this.getFilteredTestSuitNames = function() {
+ var names = new Array();
+
+ for (var suite_name in this._testcases) {
+ if (this.suite_filter) {
+ if (!this.suite_filter.test(suite_name)) {
+ continue;
+ }
+ }
+ names.push(suite_name);
+ }
+
+ return names;
+ }
+
+ this.getFilteredTestNames = function() {
+ var names = new Array();
+
+ var testcases = this.getFilteredTestCases();
+ for (var testcase_index in testcases) {
+ names.push(testcases[testcase_index].name);
+ }
+
+ return names;
+ }
+}
+testcase_registry = new TestCaseRegistry();
+
+function runTestCase(testCase) {
+ // append TOC entry
+ var name = testCase.name;
+ var toc = document.getElementById("testResultsToc");
+ var results_box = document.getElementById("testResultsPlaceHolder");
+
+ // create toc element
+ var toc_item = document.createElement("li");
+ toc_item.appendChild(createLink("./runner.html#"+name, name+" Results", false));
+ toc.appendChild(toc_item);
+
+ // append testcase section
+ var placeHolder = document.createElement("div");
+ placeHolder.className = "placeholder";
+ placeHolder.id = name;
+ var link = createLink(name, name+" Results", true);
+ var header = document.createElement("h3");
+ header.appendChild(link);
+ placeHolder.appendChild(header);
+ results_box.appendChild(placeHolder);
+ testCase.initialize(new HTMLReporter(placeHolder));
+ testCase.runTests();
+};
+
+function runTestCases() {
+ var suite_filter = document.getElementById('suite-filter').value;
+ var test_filter = document.getElementById('test-filter').value;
+ testcase_registry.setTestSuiteFilter(suite_filter);
+ testcase_registry.setTestFilter(test_filter);
+ var testcases = testcase_registry.getFilteredTestCases();
+ for (var testcase_index in testcases) {
+ runTestCase(testcases[testcase_index]);
+ }
+}
+
+function clearOutput() {
+ clearChildNodes(document.getElementById("testResultsToc"));
+ clearChildNodes(document.getElementById("testResultsPlaceHolder"));
+ clearChildNodes(document.getElementById("testSandbox"));
+}
+
+function showFilteredTests() {
+ var suite_filter = document.getElementById('suite-filter').value;
+ var test_filter = document.getElementById('test-filter').value;
+ testcase_registry.setTestSuiteFilter(suite_filter);
+ testcase_registry.setTestFilter(test_filter);
+ putTextInPlaceHolder('Suits: [' + testcase_registry.getFilteredTestSuitNames().join(', ') +
+ '], Tests: [' + testcase_registry.getFilteredTestNames().join(', ') + ']');
+}
+
+function showMarkup() {
+ var text = document.getElementById('testResultsPlaceHolder').innerHTML
+ var msg = this.document.createTextNode(text);
+ var sandbox = document.getElementById("testSandbox");
+ clearChildNodes(sandbox);
+ sandbox.appendChild(msg);
+}
+
+function putTextInPlaceHolder(text) {
+ var msg = this.document.createTextNode(text);
+ var placeholder = document.getElementById("testResultsPlaceHolder");
+ clearChildNodes(placeholder);
+ placeholder.appendChild(msg);
+}
+
+clearChildNodes = function(oNode) {
+ while(oNode.hasChildNodes()) {
+ oNode.removeChild(oNode.firstChild);
+ }
+}
+
+function createLink(link, desc, bName) {
+ var a = document.createElement("a");
+
+ a.setAttribute((bName?"name":"href"), link);
+ if(desc)
+ a.appendChild(document.createTextNode(desc));
+ return a;
+}
Index: /quintagroup.plonetabs/trunk/quintagroup/plonetabs/tests/ecmaunits/kss_demo_index.pt
===================================================================
--- /quintagroup.plonetabs/trunk/quintagroup/plonetabs/tests/ecmaunits/kss_demo_index.pt (revision 884)
+++ /quintagroup.plonetabs/trunk/quintagroup/plonetabs/tests/ecmaunits/kss_demo_index.pt (revision 884)
@@ -0,0 +1,58 @@
+
+
+
+
+
+ KSS demos
+ Kss mode
+ Tests
+
+
+ Credentials are used for site creation. They do not actually log you
+ in or used for anything else in tests.
+
+
+
+ Core plugin
+
+
+ Plugin namespace: core
+
+
+ Category
+
+
+
+
+
+
Index: /quintagroup.plonetabs/trunk/quintagroup/plonetabs/tests/ecmaunits/overrides.zcml
===================================================================
--- /quintagroup.plonetabs/trunk/quintagroup/plonetabs/tests/ecmaunits/overrides.zcml (revision 884)
+++ /quintagroup.plonetabs/trunk/quintagroup/plonetabs/tests/ecmaunits/overrides.zcml (revision 884)
@@ -0,0 +1,13 @@
+
+
+
+
+