[Checkins] SVN: zc.selenium/trunk/src/zc/selenium/resources/ update
to Selenium Core 0.7.1
Fred L. Drake, Jr.
fdrake at gmail.com
Tue Aug 29 14:41:09 EDT 2006
Log message for revision 69878:
update to Selenium Core 0.7.1
Changed:
A zc.selenium/trunk/src/zc/selenium/resources/InjectedSeleneseRunner.html
U zc.selenium/trunk/src/zc/selenium/resources/SeleneseRunner.html
U zc.selenium/trunk/src/zc/selenium/resources/TestPrompt.html
U zc.selenium/trunk/src/zc/selenium/resources/TestRunner.hta
U zc.selenium/trunk/src/zc/selenium/resources/TestRunner.html
U zc.selenium/trunk/src/zc/selenium/resources/domviewer/selenium-domviewer.js
A zc.selenium/trunk/src/zc/selenium/resources/iedoc-core.xml
U zc.selenium/trunk/src/zc/selenium/resources/iedoc.xml
A zc.selenium/trunk/src/zc/selenium/resources/lib/
A zc.selenium/trunk/src/zc/selenium/resources/lib/cssQuery-level2.js
A zc.selenium/trunk/src/zc/selenium/resources/lib/cssQuery-level3.js
A zc.selenium/trunk/src/zc/selenium/resources/lib/cssQuery-standard.js
A zc.selenium/trunk/src/zc/selenium/resources/lib/cssQuery.js
A zc.selenium/trunk/src/zc/selenium/resources/scripts/find_matching_child.js
D zc.selenium/trunk/src/zc/selenium/resources/scripts/html-xpath-patched.js
U zc.selenium/trunk/src/zc/selenium/resources/scripts/htmlutils.js
A zc.selenium/trunk/src/zc/selenium/resources/scripts/injection.html
A zc.selenium/trunk/src/zc/selenium/resources/scripts/injection_iframe.html
A zc.selenium/trunk/src/zc/selenium/resources/scripts/js2html.js
A zc.selenium/trunk/src/zc/selenium/resources/scripts/narcissus-defs.js
A zc.selenium/trunk/src/zc/selenium/resources/scripts/narcissus-exec.js
A zc.selenium/trunk/src/zc/selenium/resources/scripts/narcissus-parse.js
A zc.selenium/trunk/src/zc/selenium/resources/scripts/prototype-1.4.0.js
A zc.selenium/trunk/src/zc/selenium/resources/scripts/se2html.js
U zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-api.js
U zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-browserbot.js
U zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-browserdetect.js
U zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-commandhandlers.js
U zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-executionloop.js
U zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-logging.js
U zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-seleneserunner.js
U zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-testrunner.js
U zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-version.js
D zc.selenium/trunk/src/zc/selenium/resources/scripts/xpath.js
U zc.selenium/trunk/src/zc/selenium/resources/selenium.css
A zc.selenium/trunk/src/zc/selenium/resources/xpath/
A zc.selenium/trunk/src/zc/selenium/resources/xpath/dom.js
A zc.selenium/trunk/src/zc/selenium/resources/xpath/misc.js
A zc.selenium/trunk/src/zc/selenium/resources/xpath/xpath.js
-=-
Added: zc.selenium/trunk/src/zc/selenium/resources/InjectedSeleneseRunner.html
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/InjectedSeleneseRunner.html 2006-08-29 18:04:40 UTC (rev 69877)
+++ zc.selenium/trunk/src/zc/selenium/resources/InjectedSeleneseRunner.html 2006-08-29 18:41:08 UTC (rev 69878)
@@ -0,0 +1,8 @@
+<html>
+ <head>
+ <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
+ </head>
+<body>
+ <h3>selenium-rc initial page</h3>
+</body>
+</html>
Modified: zc.selenium/trunk/src/zc/selenium/resources/SeleneseRunner.html
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/SeleneseRunner.html 2006-08-29 18:04:40 UTC (rev 69877)
+++ zc.selenium/trunk/src/zc/selenium/resources/SeleneseRunner.html 2006-08-29 18:41:08 UTC (rev 69878)
@@ -1,106 +1,109 @@
-<!--
-Copyright 2004 ThoughtWorks, Inc
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-<html>
-<head>
-<meta content="text/html; charset=ISO-8859-1"
-http-equiv="content-type">
-<title>Selenium Functional Test Runner</title>
-<link rel="stylesheet" type="text/css" href="selenium.css" />
-<script language="JavaScript" type="text/javascript" src="jsunit/app/jsUnitCore.js"></script>
-<script type="text/javascript" src="scripts/xmlextras.js"></script>
-<script language="JavaScript" type="text/javascript" src="scripts/html-xpath-patched.js"></script>
-<script language="JavaScript" type="text/javascript" src="scripts/selenium-browserdetect.js"></script>
-<script language="JavaScript" type="text/javascript" src="scripts/selenium-browserbot.js"></script>
-<script language="JavaScript" type="text/javascript" src="scripts/selenium-api.js"></script>
-<script language="JavaScript" type="text/javascript" src="scripts/selenium-commandhandlers.js"></script>
-<script language="JavaScript" type="text/javascript" src="scripts/selenium-executionloop.js"></script>
-<script language="JavaScript" type="text/javascript" src="scripts/selenium-seleneserunner.js"></script>
-<script language="JavaScript" type="text/javascript" src="scripts/selenium-logging.js"></script>
-<script language="JavaScript" type="text/javascript" src="scripts/selenium-version.js"></script>
-<script language="JavaScript" type="text/javascript" src="scripts/htmlutils.js"></script>
-<script language="JavaScript" type="text/javascript" src="scripts/xpath.js"></script>
-<script language="JavaScript" type="text/javascript" src="scripts/user-extensions.js"></script>
-<script language="JavaScript" type="text/javascript">
- function openDomViewer() {
- var autFrame = document.getElementById('myiframe');
- var autFrameDocument = getIframeDocument(autFrame);
- var domViewer = window.open('domviewer/domviewer.html');
- domViewer.rootDocument = autFrameDocument;
- return false;
- }
-
- function cleanUp() {
- if (LOG != null) {
- LOG.close();
- }
- }
-
-</script>
-<script>
-</script>
-</head>
-
-<body onLoad="runTest()" onUnload="cleanUp()">
-
-<table border="1" style="height: 100%;">
- <tr>
- <td width="50%" height="30%">
- <table>
- <tr>
- <td>
- <img src="selenium-logo.png">
- </td>
- <td>
- <h1><a href="http://selenium.thoughtworks.com" >Selenium</a> Functional Testing for Web Apps</h1>
- Open Source From <a href="http://www.thoughtworks.com">ThoughtWorks, Inc</a> and Friends
- <form action="">
- <br/>Slow Mode:<INPUT TYPE="CHECKBOX" NAME="FASTMODE" VALUE="YES" onmouseup="slowClicked()">
-
- <fieldset>
- <legend>Tools</legend>
-
- <button type="button" id="domViewer1" onclick="openDomViewer();">
- View DOM
- </button>
- <button type="button" onclick="LOG.show();">
- Show Log
- </button>
- </fieldset>
-
- </form>
-
- </td>
- </tr>
- </table>
- <form action="">
- <label id="context" name="context"></label>
- </form>
- </td>
- <td width="50%" height="30%">
- <b>Last Four Test Commands:</b><br/>
- <div id="commandList"></div>
- </td>
- </tr>
- <tr>
- <td colspan="2" height="70%">
- <iframe name="myiframe" id="myiframe" src="" height="100%" width="100%"></iframe>
- </td>
- </tr>
-</table>
-
-</body>
-</html>
-
+<html>
+
+<!--
+Copyright 2004 ThoughtWorks, Inc
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<HTA:APPLICATION ID="SeleniumHTARunner" APPLICATIONNAME="Selenium" >
+<head>
+<meta content="text/html; charset=ISO-8859-1"
+http-equiv="content-type">
+<title>Selenium Functional Test Runner</title>
+<link rel="stylesheet" type="text/css" href="selenium.css" />
+<script language="JavaScript" type="text/javascript" src="jsunit/app/jsUnitCore.js"></script>
+<script type="text/javascript" src="scripts/xmlextras.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/prototype-1.4.0.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-browserdetect.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-browserbot.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/find_matching_child.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-api.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-commandhandlers.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-executionloop.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-seleneserunner.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-logging.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-version.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/htmlutils.js"></script>
+<script language="JavaScript" type="text/javascript" src="xpath/misc.js"></script>
+<script language="JavaScript" type="text/javascript" src="xpath/dom.js"></script>
+<script language="JavaScript" type="text/javascript" src="xpath/xpath.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/user-extensions.js"></script>
+<script language="JavaScript" type="text/javascript">
+ function openDomViewer() {
+ var autFrame = document.getElementById('myiframe');
+ var autFrameDocument = getIframeDocument(autFrame);
+ var domViewer = window.open(getDocumentBase(document) + 'domviewer/domviewer.html');
+ domViewer.rootDocument = autFrameDocument;
+ return false;
+ }
+
+ function cleanUp() {
+ if (LOG != null) {
+ LOG.close();
+ }
+ }
+
+</script>
+</head>
+
+<body onLoad="runSeleniumTest()" onUnload="cleanUp()">
+
+<table border="1" style="height: 100%;">
+ <tr>
+ <td width="50%" height="30%">
+ <table>
+ <tr>
+ <td>
+ <img src="selenium-logo.png">
+ </td>
+ <td>
+ <h1><a href="http://selenium.thoughtworks.com" >Selenium</a> Functional Testing for Web Apps</h1>
+ Open Source From <a href="http://www.thoughtworks.com">ThoughtWorks, Inc</a> and Friends
+ <form action="">
+ <br/>Slow Mode:<INPUT TYPE="CHECKBOX" NAME="FASTMODE" VALUE="YES" onmouseup="slowClicked()">
+
+ <fieldset>
+ <legend>Tools</legend>
+
+ <button type="button" id="domViewer1" onclick="openDomViewer();">
+ View DOM
+ </button>
+ <button type="button" onclick="LOG.show();">
+ Show Log
+ </button>
+ </fieldset>
+
+ </form>
+
+ </td>
+ </tr>
+ </table>
+ <form action="">
+ <label id="context" name="context"></label>
+ </form>
+ </td>
+ <td width="50%" height="30%">
+ <b>Last Four Test Commands:</b><br/>
+ <div id="commandList"></div>
+ </td>
+ </tr>
+ <tr>
+ <td colspan="2" height="70%">
+ <iframe name="myiframe" id="myiframe" src="" height="100%" width="100%"></iframe>
+ </td>
+ </tr>
+</table>
+
+</body>
+</html>
+
Modified: zc.selenium/trunk/src/zc/selenium/resources/TestPrompt.html
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/TestPrompt.html 2006-08-29 18:04:40 UTC (rev 69877)
+++ zc.selenium/trunk/src/zc/selenium/resources/TestPrompt.html 2006-08-29 18:41:08 UTC (rev 69878)
@@ -51,14 +51,15 @@
}
function go() {
+ if (!browserVersion.isHTA) return true;
var inputs = document.getElementsByTagName("input");
var queryString = "";
for (var i = 0; i < inputs.length; i++) {
var elem = inputs[i];
var name = elem.name;
var value = elem.value;
- if (elem.checked) {
- value = "true";
+ if (elem.type == "checkbox") {
+ value = elem.checked;
}
queryString += escape(name) + "=" + escape(value);
if (i < (inputs.length - 1)) {
@@ -75,7 +76,7 @@
<form id="prompt" target="_top" method="GET" onsubmit="return go();" action="TestRunner.html">
<p>Select an HTML test suite:</p>
<input id="test" name="test" size="30" value="tests/TestSuite.html"/>
-<p><label for="auto">Auto-run </label><input id="auto" type="checkbox" name="auto" value="false" onclick="autoCheck();"/>
+<p><label for="auto">Auto-run </label><input id="auto" type="checkbox" name="auto" onclick="autoCheck();"/>
<div id="auto-div" style="display: none">
<label for="close" >Close afterwards </label><input id="close" type="checkbox" name="close" />
<div id="save-div" style="display: none">
Modified: zc.selenium/trunk/src/zc/selenium/resources/TestRunner.hta
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/TestRunner.hta 2006-08-29 18:04:40 UTC (rev 69877)
+++ zc.selenium/trunk/src/zc/selenium/resources/TestRunner.hta 2006-08-29 18:41:08 UTC (rev 69878)
@@ -1,148 +1,168 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
-<html>
-<head>
-<HTA:APPLICATION ID="SeleniumHTARunner" APPLICATIONNAME="Selenium" >
-<!-- the previous line is only relevant if you rename this
- file to "TestRunner.hta" -->
-
-<!-- The copyright notice and other comments have been moved to after the HTA declaration,
- to work-around a bug in IE on Win2K whereby the HTA application doesn't function correctly -->
-<!--
-Copyright 2004 ThoughtWorks, Inc
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type" />
-
-<title>Selenium Functional Test Runner</title>
-<link rel="stylesheet" type="text/css" href="selenium.css" />
-<script language="JavaScript" type="text/javascript" src="scripts/html-xpath-patched.js"></script>
-<script language="JavaScript" type="text/javascript" src="scripts/selenium-browserdetect.js"></script>
-<script language="JavaScript" type="text/javascript" src="scripts/selenium-browserbot.js"></script>
-<script language="JavaScript" type="text/javascript" src="scripts/selenium-api.js"></script>
-<script language="JavaScript" type="text/javascript" src="scripts/selenium-commandhandlers.js"></script>
-<script language="JavaScript" type="text/javascript" src="scripts/selenium-executionloop.js"></script>
-<script language="JavaScript" type="text/javascript" src="scripts/selenium-testrunner.js"></script>
-<script language="JavaScript" type="text/javascript" src="scripts/selenium-logging.js"></script>
-<script language="JavaScript" type="text/javascript" src="scripts/selenium-version.js"></script>
-<script language="JavaScript" type="text/javascript" src="scripts/htmlutils.js"></script>
-<script language="JavaScript" type="text/javascript" src="scripts/xpath.js"></script>
-<script language="JavaScript" type="text/javascript" src="scripts/user-extensions.js"></script>
-<script language="JavaScript" type="text/javascript">
- function openDomViewer() {
- var autFrame = document.getElementById('myiframe');
- var autFrameDocument = getIframeDocument(autFrame);
- this.rootDocument = autFrameDocument;
- var domViewer = window.open('domviewer/domviewer.html');
- return false;
- }
-</script>
-</head>
-
-<body onload="start();">
-
- <table class="layout">
- <form action="" name="controlPanel">
-
- <!-- Suite, Test, Control Panel -->
-
- <tr class="selenium">
- <td width="25%" height="30%" rowspan="2"><iframe name="testSuiteFrame" id="testSuiteFrame" src="./TestPrompt.html" application="yes"></iframe></td>
- <td width="50%" height="30%" rowspan="2"><iframe name="testFrame" id="testFrame" application="yes"></iframe></td>
- <th width="25%" height="1" class="header">
- <h1><a href="http://selenium.thoughtworks.com" title="The Selenium Project">Selenium</a> TestRunner</h1>
- </th>
- </tr>
-
- <tr class="selenium">
- <td width="25%" height="30%" id="controlPanel">
-
- <fieldset>
- <legend>Execute Tests</legend>
-
- <div>
- <input id="modeRun" type="radio" name="runMode" value="0" checked="checked"/><label for="modeRun">Run</label>
- <input id="modeWalk" type="radio" name="runMode" value="500" /><label for="modeWalk">Walk</label>
- <input id="modeStep" type="radio" name="runMode" value="-1" /><label for="modeStep">Step</label>
- </div>
-
- <div>
- <button type="button" id="runSuite" onclick="startTestSuite();"
- title="Run the entire Test-Suite">
- <strong>All</strong>
- </button>
- <button type="button" id="runTest" onclick="runSingleTest();"
- title="Run the current Test">
- <em>Selected</em>
- </button>
- <button type="button" id="continueTest" disabled="disabled"
- title="Continue the Test">
- Continue
- </button>
- </div>
-
- </fieldset>
-
- <table id="stats" align="center">
- <tr>
- <td colspan="2" align="right">Elapsed:</td>
- <td id="elapsedTime" colspan="2">00.00</td>
- </tr>
- <tr>
- <th colspan="2">Tests</th>
- <th colspan="2">Commands</th>
- </tr>
- <tr>
- <td class="count" id="testRuns">0</td>
- <td>run</td>
- <td class="count" id="commandPasses">0</td>
- <td>passed</td>
- </tr>
- <tr>
- <td class="count" id="testFailures">0</td>
- <td>failed</td>
- <td class="count" id="commandFailures">0</td>
- <td>failed</td>
- </tr>
- <tr>
- <td colspan="2"></td>
- <td class="count" id="commandErrors">0</td>
- <td>incomplete</td>
- </tr>
- </table>
-
- <fieldset>
- <legend>Tools</legend>
-
- <button type="button" id="domViewer1" onclick="openDomViewer();">
- View DOM
- </button>
- <button type="button" onclick="LOG.show();">
- Show Log
- </button>
-
- </fieldset>
-
- </td>
- </tr>
-
- <!-- AUT -->
-
- <tr>
- <td colspan="3" height="70%"><iframe name="myiframe" id="myiframe" src="TestRunner-splash.html"></iframe></td>
- </tr>
- </form>
- </table>
-
-</body>
-</html>
+<html>
+
+<head>
+<HTA:APPLICATION ID="SeleniumHTARunner" APPLICATIONNAME="Selenium" >
+<!-- the previous line is only relevant if you rename this
+ file to "TestRunner.hta" -->
+
+<!-- The copyright notice and other comments have been moved to after the HTA declaration,
+ to work-around a bug in IE on Win2K whereby the HTA application doesn't function correctly -->
+<!--
+Copyright 2004 ThoughtWorks, Inc
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type" />
+
+<title>Selenium Functional Test Runner</title>
+<link rel="stylesheet" type="text/css" href="selenium.css" />
+<script type="text/javascript" src="scripts/narcissus-defs.js"></script>
+<script type="text/javascript" src="scripts/narcissus-parse.js"></script>
+<script type="text/javascript" src="scripts/narcissus-exec.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/prototype-1.4.0.js"></script>
+<script language="JavaScript" type="text/javascript" src="lib/cssQuery.js"></script>
+<script language="JavaScript" type="text/javascript" src="lib/cssQuery-standard.js"></script>
+<script language="JavaScript" type="text/javascript" src="lib/cssQuery-level2.js"></script>
+<script language="JavaScript" type="text/javascript" src="lib/cssQuery-level3.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-browserdetect.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-browserbot.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/find_matching_child.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-api.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-commandhandlers.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-executionloop.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-testrunner.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-logging.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-version.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/htmlutils.js"></script>
+<script language="JavaScript" type="text/javascript" src="xpath/misc.js"></script>
+<script language="JavaScript" type="text/javascript" src="xpath/dom.js"></script>
+<script language="JavaScript" type="text/javascript" src="xpath/xpath.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/user-extensions.js"></script>
+<script language="JavaScript" type="text/javascript">
+ function openDomViewer() {
+ var autFrame = document.getElementById('myiframe');
+ var autFrameDocument = getIframeDocument(autFrame);
+ this.rootDocument = autFrameDocument;
+ var domViewer = window.open(getDocumentBase(document) + 'domviewer/domviewer.html');
+ return false;
+ }
+</script>
+</head>
+
+<body onLoad="start();">
+ <table class="layout">
+ <form action="" name="controlPanel">
+
+ <!-- Suite, Test, Control Panel -->
+
+ <tr class="selenium">
+ <td width="25%" height="30%" ><iframe name="testSuiteFrame" id="testSuiteFrame" src="./TestPrompt.html" application="yes"></iframe></td>
+ <td width="50%" height="30%" ><iframe name="testFrame" id="testFrame" application="yes"></iframe></td>
+
+ <td width="25%">
+ <table class="layout">
+ <tr class="selenium">
+ <th width="25%" height="1" class="header">
+ <h1><a href="http://selenium.thoughtworks.com" title="The Selenium Project">Selenium</a> TestRunner</h1>
+ </th>
+ </tr>
+ <tr>
+ <td width="25%" height="30%" id="controlPanel">
+
+ <fieldset>
+ <legend>Execute Tests</legend>
+
+ <div>
+ <input id="modeRun" type="radio" name="runMode" value="0" checked="checked"/><label for="modeRun">Run</label>
+ <input id="modeWalk" type="radio" name="runMode" value="500" /><label for="modeWalk">Walk</label>
+ <input id="modeStep" type="radio" name="runMode" value="-1" /><label for="modeStep">Step</label>
+ </div>
+
+ <div>
+ <button type="button" id="runSuite" onClick="startTestSuite();"
+ title="Run the entire Test-Suite">
+ <strong>All</strong>
+ </button>
+ <button type="button" id="runSeleniumTest" onClick="runSingleTest();"
+ title="Run the current Test">
+ <em>Selected</em>
+ </button>
+ <button type="button" id="continueTest" disabled="disabled"
+ title="Continue the Test">
+ Continue
+ </button>
+ </div>
+
+ <div>
+ <input id="highlightOption" type="checkbox" name="highlightOption" value="0"/>
+ <label for="highlightOption">Highlight elements</label>
+ </div>
+
+ </fieldset>
+
+ <table id="stats" align="center">
+ <tr>
+ <td colspan="2" align="right">Elapsed:</td>
+ <td id="elapsedTime" colspan="2">00.00</td>
+ </tr>
+ <tr>
+ <th colspan="2">Tests</th>
+ <th colspan="2">Commands</th>
+ </tr>
+ <tr>
+ <td class="count" id="testRuns">0</td>
+ <td>run</td>
+ <td class="count" id="commandPasses">0</td>
+ <td>passed</td>
+ </tr>
+ <tr>
+ <td class="count" id="testFailures">0</td>
+ <td>failed</td>
+ <td class="count" id="commandFailures">0</td>
+ <td>failed</td>
+ </tr>
+ <tr>
+ <td colspan="2"></td>
+ <td class="count" id="commandErrors">0</td>
+ <td>incomplete</td>
+ </tr>
+ </table>
+
+ <fieldset>
+ <legend>Tools</legend>
+
+ <button type="button" id="domViewer1" onClick="openDomViewer();">
+ View DOM
+ </button>
+ <button type="button" onClick="LOG.show();">
+ Show Log
+ </button>
+
+ </fieldset>
+
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+
+ <!-- AUT -->
+
+ <tr>
+ <td colspan="3" height="70%"><iframe name="myiframe" id="myiframe" src="TestRunner-splash.html"></iframe></td>
+ </tr>
+ </form>
+ </table>
+
+</body>
+</html>
Modified: zc.selenium/trunk/src/zc/selenium/resources/TestRunner.html
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/TestRunner.html 2006-08-29 18:04:40 UTC (rev 69877)
+++ zc.selenium/trunk/src/zc/selenium/resources/TestRunner.html 2006-08-29 18:41:08 UTC (rev 69878)
@@ -1,148 +1,168 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
-<html>
-<head>
-<HTA:APPLICATION ID="SeleniumHTARunner" APPLICATIONNAME="Selenium" >
-<!-- the previous line is only relevant if you rename this
- file to "TestRunner.hta" -->
-
-<!-- The copyright notice and other comments have been moved to after the HTA declaration,
- to work-around a bug in IE on Win2K whereby the HTA application doesn't function correctly -->
-<!--
-Copyright 2004 ThoughtWorks, Inc
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type" />
-
-<title>Selenium Functional Test Runner</title>
-<link rel="stylesheet" type="text/css" href="selenium.css" />
-<script language="JavaScript" type="text/javascript" src="scripts/html-xpath-patched.js"></script>
-<script language="JavaScript" type="text/javascript" src="scripts/selenium-browserdetect.js"></script>
-<script language="JavaScript" type="text/javascript" src="scripts/selenium-browserbot.js"></script>
-<script language="JavaScript" type="text/javascript" src="scripts/selenium-api.js"></script>
-<script language="JavaScript" type="text/javascript" src="scripts/selenium-commandhandlers.js"></script>
-<script language="JavaScript" type="text/javascript" src="scripts/selenium-executionloop.js"></script>
-<script language="JavaScript" type="text/javascript" src="scripts/selenium-testrunner.js"></script>
-<script language="JavaScript" type="text/javascript" src="scripts/selenium-logging.js"></script>
-<script language="JavaScript" type="text/javascript" src="scripts/selenium-version.js"></script>
-<script language="JavaScript" type="text/javascript" src="scripts/htmlutils.js"></script>
-<script language="JavaScript" type="text/javascript" src="scripts/xpath.js"></script>
-<script language="JavaScript" type="text/javascript" src="scripts/user-extensions.js"></script>
-<script language="JavaScript" type="text/javascript">
- function openDomViewer() {
- var autFrame = document.getElementById('myiframe');
- var autFrameDocument = getIframeDocument(autFrame);
- this.rootDocument = autFrameDocument;
- var domViewer = window.open('domviewer/domviewer.html');
- return false;
- }
-</script>
-</head>
-
-<body onload="start();">
-
- <table class="layout">
- <form action="" name="controlPanel">
-
- <!-- Suite, Test, Control Panel -->
-
- <tr class="selenium">
- <td width="25%" height="30%" rowspan="2"><iframe name="testSuiteFrame" id="testSuiteFrame" src="./TestPrompt.html" application="yes"></iframe></td>
- <td width="50%" height="30%" rowspan="2"><iframe name="testFrame" id="testFrame" application="yes"></iframe></td>
- <th width="25%" height="1" class="header">
- <h1><a href="http://selenium.thoughtworks.com" title="The Selenium Project">Selenium</a> TestRunner</h1>
- </th>
- </tr>
-
- <tr class="selenium">
- <td width="25%" height="30%" id="controlPanel">
-
- <fieldset>
- <legend>Execute Tests</legend>
-
- <div>
- <input id="modeRun" type="radio" name="runMode" value="0" checked="checked"/><label for="modeRun">Run</label>
- <input id="modeWalk" type="radio" name="runMode" value="500" /><label for="modeWalk">Walk</label>
- <input id="modeStep" type="radio" name="runMode" value="-1" /><label for="modeStep">Step</label>
- </div>
-
- <div>
- <button type="button" id="runSuite" onclick="startTestSuite();"
- title="Run the entire Test-Suite">
- <strong>All</strong>
- </button>
- <button type="button" id="runTest" onclick="runSingleTest();"
- title="Run the current Test">
- <em>Selected</em>
- </button>
- <button type="button" id="continueTest" disabled="disabled"
- title="Continue the Test">
- Continue
- </button>
- </div>
-
- </fieldset>
-
- <table id="stats" align="center">
- <tr>
- <td colspan="2" align="right">Elapsed:</td>
- <td id="elapsedTime" colspan="2">00.00</td>
- </tr>
- <tr>
- <th colspan="2">Tests</th>
- <th colspan="2">Commands</th>
- </tr>
- <tr>
- <td class="count" id="testRuns">0</td>
- <td>run</td>
- <td class="count" id="commandPasses">0</td>
- <td>passed</td>
- </tr>
- <tr>
- <td class="count" id="testFailures">0</td>
- <td>failed</td>
- <td class="count" id="commandFailures">0</td>
- <td>failed</td>
- </tr>
- <tr>
- <td colspan="2"></td>
- <td class="count" id="commandErrors">0</td>
- <td>incomplete</td>
- </tr>
- </table>
-
- <fieldset>
- <legend>Tools</legend>
-
- <button type="button" id="domViewer1" onclick="openDomViewer();">
- View DOM
- </button>
- <button type="button" onclick="LOG.show();">
- Show Log
- </button>
-
- </fieldset>
-
- </td>
- </tr>
-
- <!-- AUT -->
-
- <tr>
- <td colspan="3" height="70%"><iframe name="myiframe" id="myiframe" src="TestRunner-splash.html"></iframe></td>
- </tr>
- </form>
- </table>
-
-</body>
-</html>
+<html>
+
+<head>
+<HTA:APPLICATION ID="SeleniumHTARunner" APPLICATIONNAME="Selenium" >
+<!-- the previous line is only relevant if you rename this
+ file to "TestRunner.hta" -->
+
+<!-- The copyright notice and other comments have been moved to after the HTA declaration,
+ to work-around a bug in IE on Win2K whereby the HTA application doesn't function correctly -->
+<!--
+Copyright 2004 ThoughtWorks, Inc
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type" />
+
+<title>Selenium Functional Test Runner</title>
+<link rel="stylesheet" type="text/css" href="selenium.css" />
+<script type="text/javascript" src="scripts/narcissus-defs.js"></script>
+<script type="text/javascript" src="scripts/narcissus-parse.js"></script>
+<script type="text/javascript" src="scripts/narcissus-exec.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/prototype-1.4.0.js"></script>
+<script language="JavaScript" type="text/javascript" src="lib/cssQuery.js"></script>
+<script language="JavaScript" type="text/javascript" src="lib/cssQuery-standard.js"></script>
+<script language="JavaScript" type="text/javascript" src="lib/cssQuery-level2.js"></script>
+<script language="JavaScript" type="text/javascript" src="lib/cssQuery-level3.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-browserdetect.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-browserbot.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/find_matching_child.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-api.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-commandhandlers.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-executionloop.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-testrunner.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-logging.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/selenium-version.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/htmlutils.js"></script>
+<script language="JavaScript" type="text/javascript" src="xpath/misc.js"></script>
+<script language="JavaScript" type="text/javascript" src="xpath/dom.js"></script>
+<script language="JavaScript" type="text/javascript" src="xpath/xpath.js"></script>
+<script language="JavaScript" type="text/javascript" src="scripts/user-extensions.js"></script>
+<script language="JavaScript" type="text/javascript">
+ function openDomViewer() {
+ var autFrame = document.getElementById('myiframe');
+ var autFrameDocument = getIframeDocument(autFrame);
+ this.rootDocument = autFrameDocument;
+ var domViewer = window.open(getDocumentBase(document) + 'domviewer/domviewer.html');
+ return false;
+ }
+</script>
+</head>
+
+<body onLoad="start();">
+ <table class="layout">
+ <form action="" name="controlPanel">
+
+ <!-- Suite, Test, Control Panel -->
+
+ <tr class="selenium">
+ <td width="25%" height="30%" ><iframe name="testSuiteFrame" id="testSuiteFrame" src="./TestPrompt.html" application="yes"></iframe></td>
+ <td width="50%" height="30%" ><iframe name="testFrame" id="testFrame" application="yes"></iframe></td>
+
+ <td width="25%">
+ <table class="layout">
+ <tr class="selenium">
+ <th width="25%" height="1" class="header">
+ <h1><a href="http://selenium.thoughtworks.com" title="The Selenium Project">Selenium</a> TestRunner</h1>
+ </th>
+ </tr>
+ <tr>
+ <td width="25%" height="30%" id="controlPanel">
+
+ <fieldset>
+ <legend>Execute Tests</legend>
+
+ <div>
+ <input id="modeRun" type="radio" name="runMode" value="0" checked="checked"/><label for="modeRun">Run</label>
+ <input id="modeWalk" type="radio" name="runMode" value="500" /><label for="modeWalk">Walk</label>
+ <input id="modeStep" type="radio" name="runMode" value="-1" /><label for="modeStep">Step</label>
+ </div>
+
+ <div>
+ <button type="button" id="runSuite" onClick="startTestSuite();"
+ title="Run the entire Test-Suite">
+ <strong>All</strong>
+ </button>
+ <button type="button" id="runSeleniumTest" onClick="runSingleTest();"
+ title="Run the current Test">
+ <em>Selected</em>
+ </button>
+ <button type="button" id="continueTest" disabled="disabled"
+ title="Continue the Test">
+ Continue
+ </button>
+ </div>
+
+ <div>
+ <input id="highlightOption" type="checkbox" name="highlightOption" value="0"/>
+ <label for="highlightOption">Highlight elements</label>
+ </div>
+
+ </fieldset>
+
+ <table id="stats" align="center">
+ <tr>
+ <td colspan="2" align="right">Elapsed:</td>
+ <td id="elapsedTime" colspan="2">00.00</td>
+ </tr>
+ <tr>
+ <th colspan="2">Tests</th>
+ <th colspan="2">Commands</th>
+ </tr>
+ <tr>
+ <td class="count" id="testRuns">0</td>
+ <td>run</td>
+ <td class="count" id="commandPasses">0</td>
+ <td>passed</td>
+ </tr>
+ <tr>
+ <td class="count" id="testFailures">0</td>
+ <td>failed</td>
+ <td class="count" id="commandFailures">0</td>
+ <td>failed</td>
+ </tr>
+ <tr>
+ <td colspan="2"></td>
+ <td class="count" id="commandErrors">0</td>
+ <td>incomplete</td>
+ </tr>
+ </table>
+
+ <fieldset>
+ <legend>Tools</legend>
+
+ <button type="button" id="domViewer1" onClick="openDomViewer();">
+ View DOM
+ </button>
+ <button type="button" onClick="LOG.show();">
+ Show Log
+ </button>
+
+ </fieldset>
+
+ </td>
+ </tr>
+ </table>
+ </td>
+ </tr>
+
+ <!-- AUT -->
+
+ <tr>
+ <td colspan="3" height="70%"><iframe name="myiframe" id="myiframe" src="TestRunner-splash.html"></iframe></td>
+ </tr>
+ </form>
+ </table>
+
+</body>
+</html>
Modified: zc.selenium/trunk/src/zc/selenium/resources/domviewer/selenium-domviewer.js
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/domviewer/selenium-domviewer.js 2006-08-29 18:04:40 UTC (rev 69877)
+++ zc.selenium/trunk/src/zc/selenium/resources/domviewer/selenium-domviewer.js 2006-08-29 18:41:08 UTC (rev 69878)
@@ -106,6 +106,7 @@
}
function getNodeContent(element) {
+
str = "";
id ="";
if (element.id != null && element.id != "") {
@@ -123,17 +124,33 @@
if (element.href != null && element.href != "") {
href = " HREF(" + element.href + ")";
}
+ clazz = "";
+ if (element.className != null && element.className != "") {
+ clazz = " CLASS(" + element.className + ")";
+ }
+ src = "";
+ if (element.src != null && element.src != "") {
+ src = " SRC(" + element.src + ")";
+ }
+ alt = "";
+ if (element.alt != null && element.alt != "") {
+ alt = " ALT(" + element.alt + ")";
+ }
+ type = "";
+ if (element.type != null && element.type != "") {
+ type = " TYPE(" + element.type + ")";
+ }
text ="";
if (element.text != null && element.text != "" && element.text != "undefined") {
text = " #TEXT(" + trim(element.text) +")";
}
- str+=" <b>"+ element.nodeName + id + name + value + href + text + "</b>";
+ str+=" <b>"+ element.nodeName + id + alt + type + clazz + name + value + href + src + text + "</b>";
return str;
}
function trim(val) {
- val2 = val.substring(0,20) + " ";
+ val2 = val.substring(0,40) + " ";
var spaceChr = String.fromCharCode(32);
var length = val2.length;
var retVal = "";
@@ -147,7 +164,7 @@
}
ix = ix-1;
}
- if (val.length > 20) {
+ if (val.length > 40) {
retVal += "...";
}
return retVal;
Added: zc.selenium/trunk/src/zc/selenium/resources/iedoc-core.xml
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/iedoc-core.xml 2006-08-29 18:04:40 UTC (rev 69877)
+++ zc.selenium/trunk/src/zc/selenium/resources/iedoc-core.xml 2006-08-29 18:41:08 UTC (rev 69878)
@@ -0,0 +1,1113 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<apidoc>
+
+<top>Defines an object that runs Selenium commands.
+
+<h3><a name="locators"></a>Element Locators</h3>
+<p>
+Element Locators tell Selenium which HTML element a command refers to.
+The format of a locator is:</p>
+<blockquote>
+<em>locatorType</em><strong>=</strong><em>argument</em>
+</blockquote>
+
+<p>
+We support the following strategies for locating elements:
+</p>
+<blockquote>
+<dl>
+<dt><strong>identifier</strong>=<em>id</em></dt>
+<dd>Select the element with the specified @id attribute. If no match is
+found, select the first element whose @name attribute is <em>id</em>.
+(This is normally the default; see below.)</dd>
+<dt><strong>id</strong>=<em>id</em></dt>
+<dd>Select the element with the specified @id attribute.</dd>
+
+<dt><strong>name</strong>=<em>name</em></dt>
+<dd>Select the first element with the specified @name attribute.</dd>
+<dd><ul class="first last simple">
+<li>username</li>
+<li>name=username</li>
+</ul>
+</dd>
+<dd>The name may optionally be followed by one or more <em>element-filters</em>, separated from the name by whitespace. If the <em>filterType</em> is not specified, <strong>value</strong> is assumed.</dd>
+
+<dd><ul class="first last simple">
+<li>name=flavour value=chocolate</li>
+</ul>
+</dd>
+<dt><strong>dom</strong>=<em>javascriptExpression</em></dt>
+
+<dd>
+
+<dd>Find an element using JavaScript traversal of the HTML Document Object
+Model. DOM locators <em>must</em> begin with "document.".
+<ul class="first last simple">
+<li>dom=document.forms['myForm'].myDropdown</li>
+<li>dom=document.images[56]</li>
+</ul>
+</dd>
+
+</dd>
+
+<dt><strong>xpath</strong>=<em>xpathExpression</em></dt>
+<dd>Locate an element using an XPath expression.
+<ul class="first last simple">
+<li>xpath=//img[@alt='The image alt text']</li>
+<li>xpath=//table[@id='table1']//tr[4]/td[2]</li>
+
+</ul>
+</dd>
+<dt><strong>link</strong>=<em>textPattern</em></dt>
+<dd>Select the link (anchor) element which contains text matching the
+specified <em>pattern</em>.
+<ul class="first last simple">
+<li>link=The link text</li>
+</ul>
+
+</dd>
+
+<dt><strong>css</strong>=<em>cssSelectorSyntax</em></dt>
+<dd>Select the element using css selectors. Please refer to <a href="http://www.w3.org/TR/REC-CSS2/selector.html">CSS2 selectors</a>, <a href="http://www.w3.org/TR/2001/CR-css3-selectors-20011113/">CSS3 selectors</a> for more information. You can also check the TestCssLocators test in the selenium test suite for an example of usage, which is included in the downloaded selenium core package.
+<ul class="first last simple">
+<li>css=a[href="#id3"]</li>
+<li>css=span#firstChild + span</li>
+</ul>
+</dd>
+<dd>Currently the css selector locator supports all css1, css2 and css3 selectors except namespace in css3, some pseudo classes(:nth-of-type, :nth-last-of-type, :first-of-type, :last-of-type, :only-of-type, :visited, :hover, :active, :focus, :indeterminate) and pseudo elements(::first-line, ::first-letter, ::selection, ::before, ::after). </dd>
+</dl>
+</blockquote>
+<p>
+Without an explicit locator prefix, Selenium uses the following default
+strategies:
+</p>
+
+<ul class="simple">
+<li><strong>dom</strong>, for locators starting with "document."</li>
+<li><strong>xpath</strong>, for locators starting with "//"</li>
+<li><strong>identifier</strong>, otherwise</li>
+</ul>
+
+<h3><a name="element-filters">Element Filters</a></h3>
+<blockquote>
+<p>Element filters can be used with a locator to refine a list of candidate elements. They are currently used only in the 'name' element-locator.</p>
+<p>Filters look much like locators, ie.</p>
+<blockquote>
+<em>filterType</em><strong>=</strong><em>argument</em></blockquote>
+
+<p>Supported element-filters are:</p>
+<p><strong>value=</strong><em>valuePattern</em></p>
+<blockquote>
+Matches elements based on their values. This is particularly useful for refining a list of similarly-named toggle-buttons.</blockquote>
+<p><strong>index=</strong><em>index</em></p>
+<blockquote>
+Selects a single element based on its position in the list (offset from zero).</blockquote>
+</blockquote>
+
+<h3><a name="patterns"></a>String-match Patterns</h3>
+
+<p>
+Various Pattern syntaxes are available for matching string values:
+</p>
+<blockquote>
+<dl>
+<dt><strong>glob:</strong><em>pattern</em></dt>
+<dd>Match a string against a "glob" (aka "wildmat") pattern. "Glob" is a
+kind of limited regular-expression syntax typically used in command-line
+shells. In a glob pattern, "*" represents any sequence of characters, and "?"
+represents any single character. Glob patterns match against the entire
+string.</dd>
+<dt><strong>regexp:</strong><em>regexp</em></dt>
+<dd>Match a string using a regular-expression. The full power of JavaScript
+regular-expressions is available.</dd>
+<dt><strong>exact:</strong><em>string</em></dt>
+
+<dd>Match a string exactly, verbatim, without any of that fancy wildcard
+stuff.</dd>
+</dl>
+</blockquote>
+<p>
+If no pattern prefix is specified, Selenium assumes that it's a "glob"
+pattern.
+</p></top>
+
+<function name="click">
+
+<param name="locator">an element locator</param>
+
+<comment>Clicks on a link, button, checkbox or radio button. If the click action
+causes a new page to load (like a link usually does), call
+waitForPageToLoad.</comment>
+
+</function>
+
+<function name="clickAt">
+
+<param name="locator">an element locator</param>
+
+<param name="coordString">specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.</param>
+
+<comment>Clicks on a link, button, checkbox or radio button. If the click action
+causes a new page to load (like a link usually does), call
+waitForPageToLoad.
+
+Beware of http://jira.openqa.org/browse/SEL-280, which will lead some event handlers to
+get null event arguments. Read the bug for more details, including a workaround.</comment>
+
+</function>
+
+<function name="fireEvent">
+
+<param name="locator">an <a href="#locators">element locator</a></param>
+
+<param name="eventName">the event name, e.g. "focus" or "blur"</param>
+
+<comment>Explicitly simulate an event, to trigger the corresponding "on<em>event</em>"
+handler.</comment>
+
+</function>
+
+<function name="keyPress">
+
+<param name="locator">an <a href="#locators">element locator</a></param>
+
+<param name="keycode">the numeric keycode of the key to be pressed, normally the ASCII value of that key.</param>
+
+<comment>Simulates a user pressing and releasing a key.</comment>
+
+</function>
+
+<function name="keyDown">
+
+<param name="locator">an <a href="#locators">element locator</a></param>
+
+<param name="keycode">the numeric keycode of the key to be pressed, normally the ASCII value of that key.</param>
+
+<comment>Simulates a user pressing a key (without releasing it yet).</comment>
+
+</function>
+
+<function name="keyUp">
+
+<param name="locator">an <a href="#locators">element locator</a></param>
+
+<param name="keycode">the numeric keycode of the key to be released, normally the ASCII value of that key.</param>
+
+<comment>Simulates a user releasing a key.</comment>
+
+</function>
+
+<function name="mouseOver">
+
+<param name="locator">an <a href="#locators">element locator</a></param>
+
+<comment>Simulates a user hovering a mouse over the specified element.</comment>
+
+</function>
+
+<function name="mouseOut">
+
+<param name="locator">an <a href="#locators">element locator</a></param>
+
+<comment>Simulates a user moving the mouse pointer away from the specified element.</comment>
+
+</function>
+
+<function name="mouseDown">
+
+<param name="locator">an <a href="#locators">element locator</a></param>
+
+<comment>Simulates a user pressing the mouse button (without releasing it yet) on
+the specified element.</comment>
+
+</function>
+
+<function name="mouseDownAt">
+
+<param name="locator">an <a href="#locators">element locator</a></param>
+
+<param name="coordString">specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.</param>
+
+<comment>Simulates a user pressing the mouse button (without releasing it yet) on
+the specified element.
+
+Beware of http://jira.openqa.org/browse/SEL-280, which will lead some event handlers to
+get null event arguments. Read the bug for more details, including a workaround.</comment>
+
+</function>
+
+<function name="mouseUp">
+
+<param name="locator">an <a href="#locators">element locator</a></param>
+
+<comment>Simulates a user pressing the mouse button (without releasing it yet) on
+the specified element.</comment>
+
+</function>
+
+<function name="mouseUpAt">
+
+<param name="locator">an <a href="#locators">element locator</a></param>
+
+<param name="coordString">specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.</param>
+
+<comment>Simulates a user pressing the mouse button (without releasing it yet) on
+the specified element.
+
+Beware of http://jira.openqa.org/browse/SEL-280, which will lead some event handlers to
+get null event arguments. Read the bug for more details, including a workaround.</comment>
+
+</function>
+
+<function name="mouseMove">
+
+<param name="locator">an <a href="#locators">element locator</a></param>
+
+<comment>Simulates a user pressing the mouse button (without releasing it yet) on
+the specified element.</comment>
+
+</function>
+
+<function name="mouseMoveAt">
+
+<param name="locator">an <a href="#locators">element locator</a></param>
+
+<param name="coordString">specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.</param>
+
+<comment>Simulates a user pressing the mouse button (without releasing it yet) on
+the specified element.
+
+Beware of http://jira.openqa.org/browse/SEL-280, which will lead some event handlers to
+get null event arguments. Read the bug for more details, including a workaround.</comment>
+
+</function>
+
+<function name="type">
+
+<param name="locator">an <a href="#locators">element locator</a></param>
+
+<param name="value">the value to type</param>
+
+<comment>Sets the value of an input field, as though you typed it in.
+
+<p>Can also be used to set the value of combo boxes, check boxes, etc. In these cases,
+value should be the value of the option selected, not the visible text.</p></comment>
+
+</function>
+
+<function name="check">
+
+<param name="locator">an <a href="#locators">element locator</a></param>
+
+<comment>Check a toggle-button (checkbox/radio)</comment>
+
+</function>
+
+<function name="uncheck">
+
+<param name="locator">an <a href="#locators">element locator</a></param>
+
+<comment>Uncheck a toggle-button (checkbox/radio)</comment>
+
+</function>
+
+<function name="select">
+
+<param name="selectLocator">an <a href="#locators">element locator</a> identifying a drop-down menu</param>
+
+<param name="optionLocator">an option locator (a label by default)</param>
+
+<comment>Select an option from a drop-down using an option locator.
+
+<p>
+Option locators provide different ways of specifying options of an HTML
+Select element (e.g. for selecting a specific option, or for asserting
+that the selected option satisfies a specification). There are several
+forms of Select Option Locator.
+</p>
+<dl>
+<dt><strong>label</strong>=<em>labelPattern</em></dt>
+<dd>matches options based on their labels, i.e. the visible text. (This
+is the default.)
+<ul class="first last simple">
+<li>label=regexp:^[Oo]ther</li>
+</ul>
+</dd>
+<dt><strong>value</strong>=<em>valuePattern</em></dt>
+<dd>matches options based on their values.
+<ul class="first last simple">
+<li>value=other</li>
+</ul>
+
+
+</dd>
+<dt><strong>id</strong>=<em>id</em></dt>
+
+<dd>matches options based on their ids.
+<ul class="first last simple">
+<li>id=option1</li>
+</ul>
+</dd>
+<dt><strong>index</strong>=<em>index</em></dt>
+<dd>matches an option based on its index (offset from zero).
+<ul class="first last simple">
+
+<li>index=2</li>
+</ul>
+</dd>
+</dl>
+<p>
+If no option locator prefix is provided, the default behaviour is to match on <strong>label</strong>.
+</p></comment>
+
+</function>
+
+<function name="addSelection">
+
+<param name="locator">an <a href="#locators">element locator</a> identifying a multi-select box</param>
+
+<param name="optionLocator">an option locator (a label by default)</param>
+
+<comment>Add a selection to the set of selected options in a multi-select element using an option locator.
+
+ at see #doSelect for details of option locators</comment>
+
+</function>
+
+<function name="removeSelection">
+
+<param name="locator">an <a href="#locators">element locator</a> identifying a multi-select box</param>
+
+<param name="optionLocator">an option locator (a label by default)</param>
+
+<comment>Remove a selection from the set of selected options in a multi-select element using an option locator.
+
+ at see #doSelect for details of option locators</comment>
+
+</function>
+
+<function name="submit">
+
+<param name="formLocator">an <a href="#locators">element locator</a> for the form you want to submit</param>
+
+<comment>Submit the specified form. This is particularly useful for forms without
+submit buttons, e.g. single-input "Search" forms.</comment>
+
+</function>
+
+<function name="open">
+
+<param name="url">the URL to open; may be relative or absolute</param>
+
+<comment>Opens an URL in the test frame. This accepts both relative and absolute
+URLs.
+
+The "open" command waits for the page to load before proceeding,
+ie. the "AndWait" suffix is implicit.
+
+<em>Note</em>: The URL must be on the same domain as the runner HTML
+due to security restrictions in the browser (Same Origin Policy). If you
+need to open an URL on another domain, use the Selenium Server to start a
+new browser session on that domain.</comment>
+
+</function>
+
+<function name="selectWindow">
+
+<param name="windowID">the JavaScript window ID of the window to select</param>
+
+<comment>Selects a popup window; once a popup window has been selected, all
+commands go to that window. To select the main window again, use "null"
+as the target.</comment>
+
+</function>
+
+<function name="selectFrame">
+
+<param name="locator">an <a href="#locators">element locator</a> identifying a frame or iframe</param>
+
+<comment>NOT IMPLEMENTED YET:
+Selects a frame within the current window. (You may invoke this command
+multiple times to select nested frames.) To select the parent frame, use
+"relative=parent" as a locator; to select the top frame, use "relative=top".
+
+<p>You may also use a DOM expression to identify the frame you want directly,
+like this: <code>dom=frames["main"].frames["subframe"]</code></p></comment>
+
+</function>
+
+<function name="getLogMessages">
+
+<return type="string">all log messages seen since the last call to this API</return>
+
+<comment>Return the contents of the log.
+
+<p>This is a placeholder intended to make the code generator make this API
+available to clients. The selenium server will intercept this call, however,
+and return its recordkeeping of log messages since the last call to this API.
+Thus this code in JavaScript will never be called.</p>
+
+<p>The reason I opted for a servercentric solution is to be able to support
+multiple frames served from different domains, which would break a
+centralized JavaScript logging mechanism under some conditions.</p></comment>
+
+</function>
+
+<function name="getWhetherThisFrameMatchFrameExpression">
+
+<return type="boolean">true if the new frame is this code's window</return>
+
+<param name="currentFrameString">starting frame</param>
+
+<param name="target">new frame (which might be relative to the current one)</param>
+
+<comment>Determine whether current/locator identify the frame containing this running code.
+
+<p>This is useful in proxy injection mode, where this code runs in every
+browser frame and window, and sometimes the selenium server needs to identify
+the "current" frame. In this case, when the test calls selectFrame, this
+routine is called for each frame to figure out which one has been selected.
+The selected frame will return true, while all others will return false.</p></comment>
+
+</function>
+
+<function name="waitForPopUp">
+
+<param name="windowID">the JavaScript window ID of the window that will appear</param>
+
+<param name="timeout">a timeout in milliseconds, after which the action will return with an error</param>
+
+<comment>Waits for a popup window to appear and load up.</comment>
+
+</function>
+
+<function name="chooseCancelOnNextConfirmation">
+
+<comment>By default, Selenium's overridden window.confirm() function will
+return true, as if the user had manually clicked OK. After running
+this command, the next call to confirm() will return false, as if
+the user had clicked Cancel.</comment>
+
+</function>
+
+<function name="answerOnNextPrompt">
+
+<param name="answer">the answer to give in response to the prompt pop-up</param>
+
+<comment>Instructs Selenium to return the specified answer string in response to
+the next JavaScript prompt [window.prompt()].</comment>
+
+</function>
+
+<function name="goBack">
+
+<comment>Simulates the user clicking the "back" button on their browser.</comment>
+
+</function>
+
+<function name="refresh">
+
+<comment>Simulates the user clicking the "Refresh" button on their browser.</comment>
+
+</function>
+
+<function name="close">
+
+<comment>Simulates the user clicking the "close" button in the titlebar of a popup
+window or tab.</comment>
+
+</function>
+
+<function name="isAlertPresent">
+
+<return type="boolean">true if there is an alert</return>
+
+<comment>Has an alert occurred?
+
+<p>
+This function never throws an exception
+</p></comment>
+
+</function>
+
+<function name="isPromptPresent">
+
+<return type="boolean">true if there is a pending prompt</return>
+
+<comment>Has a prompt occurred?
+
+<p>
+This function never throws an exception
+</p></comment>
+
+</function>
+
+<function name="isConfirmationPresent">
+
+<return type="boolean">true if there is a pending confirmation</return>
+
+<comment>Has confirm() been called?
+
+<p>
+This function never throws an exception
+</p></comment>
+
+</function>
+
+<function name="getAlert">
+
+<return type="string">The message of the most recent JavaScript alert</return>
+
+<comment>Retrieves the message of a JavaScript alert generated during the previous action, or fail if there were no alerts.
+
+<p>Getting an alert has the same effect as manually clicking OK. If an
+alert is generated but you do not get/verify it, the next Selenium action
+will fail.</p>
+
+<p>NOTE: under Selenium, JavaScript alerts will NOT pop up a visible alert
+dialog.</p>
+
+<p>NOTE: Selenium does NOT support JavaScript alerts that are generated in a
+page's onload() event handler. In this case a visible dialog WILL be
+generated and Selenium will hang until someone manually clicks OK.</p></comment>
+
+</function>
+
+<function name="getConfirmation">
+
+<return type="string">the message of the most recent JavaScript confirmation dialog</return>
+
+<comment>Retrieves the message of a JavaScript confirmation dialog generated during
+the previous action.
+
+<p>
+By default, the confirm function will return true, having the same effect
+as manually clicking OK. This can be changed by prior execution of the
+chooseCancelOnNextConfirmation command. If an confirmation is generated
+but you do not get/verify it, the next Selenium action will fail.
+</p>
+
+<p>
+NOTE: under Selenium, JavaScript confirmations will NOT pop up a visible
+dialog.
+</p>
+
+<p>
+NOTE: Selenium does NOT support JavaScript confirmations that are
+generated in a page's onload() event handler. In this case a visible
+dialog WILL be generated and Selenium will hang until you manually click
+OK.
+</p></comment>
+
+</function>
+
+<function name="getPrompt">
+
+<return type="string">the message of the most recent JavaScript question prompt</return>
+
+<comment>Retrieves the message of a JavaScript question prompt dialog generated during
+the previous action.
+
+<p>Successful handling of the prompt requires prior execution of the
+answerOnNextPrompt command. If a prompt is generated but you
+do not get/verify it, the next Selenium action will fail.</p>
+
+<p>NOTE: under Selenium, JavaScript prompts will NOT pop up a visible
+dialog.</p>
+
+<p>NOTE: Selenium does NOT support JavaScript prompts that are generated in a
+page's onload() event handler. In this case a visible dialog WILL be
+generated and Selenium will hang until someone manually clicks OK.</p></comment>
+
+</function>
+
+<function name="getLocation">
+
+<return type="string">the absolute URL of the current page</return>
+
+<comment>Gets the absolute URL of the current page.</comment>
+
+</function>
+
+<function name="getTitle">
+
+<return type="string">the title of the current page</return>
+
+<comment>Gets the title of the current page.</comment>
+
+</function>
+
+<function name="getBodyText">
+
+<return type="string">the entire text of the page</return>
+
+<comment>Gets the entire text of the page.</comment>
+
+</function>
+
+<function name="getValue">
+
+<return type="string">the element value, or "on/off" for checkbox/radio elements</return>
+
+<param name="locator">an <a href="#locators">element locator</a></param>
+
+<comment>Gets the (whitespace-trimmed) value of an input field (or anything else with a value parameter).
+For checkbox/radio elements, the value will be "on" or "off" depending on
+whether the element is checked or not.</comment>
+
+</function>
+
+<function name="getText">
+
+<return type="string">the text of the element</return>
+
+<param name="locator">an <a href="#locators">element locator</a></param>
+
+<comment>Gets the text of an element. This works for any element that contains
+text. This command uses either the textContent (Mozilla-like browsers) or
+the innerText (IE-like browsers) of the element, which is the rendered
+text shown to the user.</comment>
+
+</function>
+
+<function name="getEval">
+
+<return type="string">the results of evaluating the snippet</return>
+
+<param name="script">the JavaScript snippet to run</param>
+
+<comment>Gets the result of evaluating the specified JavaScript snippet. The snippet may
+have multiple lines, but only the result of the last line will be returned.
+
+<p>Note that, by default, the snippet will run in the context of the "selenium"
+object itself, so <code>this</code> will refer to the Selenium object, and <code>window</code> will
+refer to the top-level runner test window, not the window of your application.</p>
+
+<p>If you need a reference to the window of your application, you can refer
+to <code>this.browserbot.getCurrentWindow()</code> and if you need to use
+a locator to refer to a single element in your application page, you can
+use <code>this.page().findElement("foo")</code> where "foo" is your locator.</p></comment>
+
+</function>
+
+<function name="isChecked">
+
+<return type="boolean">true if the checkbox is checked, false otherwise</return>
+
+<param name="locator">an <a href="#locators">element locator</a> pointing to a checkbox or radio button</param>
+
+<comment>Gets whether a toggle-button (checkbox/radio) is checked. Fails if the specified element doesn't exist or isn't a toggle-button.</comment>
+
+</function>
+
+<function name="getTable">
+
+<return type="string">the text from the specified cell</return>
+
+<param name="tableCellAddress">a cell address, e.g. "foo.1.4"</param>
+
+<comment>Gets the text from a cell of a table. The cellAddress syntax
+tableLocator.row.column, where row and column start at 0.</comment>
+
+</function>
+
+<function name="getSelectedLabels">
+
+<return type="string[]">an array of all selected option labels in the specified select drop-down</return>
+
+<param name="selectLocator">an <a href="#locators">element locator</a> identifying a drop-down menu</param>
+
+<comment>Gets all option labels (visible text) for selected options in the specified select or multi-select element.</comment>
+
+</function>
+
+<function name="getSelectedLabel">
+
+<return type="string">the selected option label in the specified select drop-down</return>
+
+<param name="selectLocator">an <a href="#locators">element locator</a> identifying a drop-down menu</param>
+
+<comment>Gets option label (visible text) for selected option in the specified select element.</comment>
+
+</function>
+
+<function name="getSelectedValues">
+
+<return type="string[]">an array of all selected option values in the specified select drop-down</return>
+
+<param name="selectLocator">an <a href="#locators">element locator</a> identifying a drop-down menu</param>
+
+<comment>Gets all option values (value attributes) for selected options in the specified select or multi-select element.</comment>
+
+</function>
+
+<function name="getSelectedValue">
+
+<return type="string">the selected option value in the specified select drop-down</return>
+
+<param name="selectLocator">an <a href="#locators">element locator</a> identifying a drop-down menu</param>
+
+<comment>Gets option value (value attribute) for selected option in the specified select element.</comment>
+
+</function>
+
+<function name="getSelectedIndexes">
+
+<return type="string[]">an array of all selected option indexes in the specified select drop-down</return>
+
+<param name="selectLocator">an <a href="#locators">element locator</a> identifying a drop-down menu</param>
+
+<comment>Gets all option indexes (option number, starting at 0) for selected options in the specified select or multi-select element.</comment>
+
+</function>
+
+<function name="getSelectedIndex">
+
+<return type="string">the selected option index in the specified select drop-down</return>
+
+<param name="selectLocator">an <a href="#locators">element locator</a> identifying a drop-down menu</param>
+
+<comment>Gets option index (option number, starting at 0) for selected option in the specified select element.</comment>
+
+</function>
+
+<function name="getSelectedIds">
+
+<return type="string[]">an array of all selected option IDs in the specified select drop-down</return>
+
+<param name="selectLocator">an <a href="#locators">element locator</a> identifying a drop-down menu</param>
+
+<comment>Gets all option element IDs for selected options in the specified select or multi-select element.</comment>
+
+</function>
+
+<function name="getSelectedId">
+
+<return type="string">the selected option ID in the specified select drop-down</return>
+
+<param name="selectLocator">an <a href="#locators">element locator</a> identifying a drop-down menu</param>
+
+<comment>Gets option element ID for selected option in the specified select element.</comment>
+
+</function>
+
+<function name="isSomethingSelected">
+
+<return type="boolean">true if some option has been selected, false otherwise</return>
+
+<param name="selectLocator">an <a href="#locators">element locator</a> identifying a drop-down menu</param>
+
+<comment>Determines whether some option in a drop-down menu is selected.</comment>
+
+</function>
+
+<function name="getSelectOptions">
+
+<return type="string[]">an array of all option labels in the specified select drop-down</return>
+
+<param name="selectLocator">an <a href="#locators">element locator</a> identifying a drop-down menu</param>
+
+<comment>Gets all option labels in the specified select drop-down.</comment>
+
+</function>
+
+<function name="getAttribute">
+
+<return type="string">the value of the specified attribute</return>
+
+<param name="attributeLocator">an element locator followed by an</param>
+
+<comment>Gets the value of an element attribute.
+
+Beware of http://jira.openqa.org/browse/SEL-280, which will lead some event handlers to
+get null event arguments. Read the bug for more details, including a workaround.</comment>
+
+</function>
+
+<function name="isTextPresent">
+
+<return type="boolean">true if the pattern matches the text, false otherwise</return>
+
+<param name="pattern">a <a href="#patterns">pattern</a> to match with the text of the page</param>
+
+<comment>Verifies that the specified text pattern appears somewhere on the rendered page shown to the user.</comment>
+
+</function>
+
+<function name="isElementPresent">
+
+<return type="boolean">true if the element is present, false otherwise</return>
+
+<param name="locator">an <a href="#locators">element locator</a></param>
+
+<comment>Verifies that the specified element is somewhere on the page.</comment>
+
+</function>
+
+<function name="isVisible">
+
+<return type="boolean">true if the specified element is visible, false otherwise</return>
+
+<param name="locator">an <a href="#locators">element locator</a></param>
+
+<comment>Determines if the specified element is visible. An
+element can be rendered invisible by setting the CSS "visibility"
+property to "hidden", or the "display" property to "none", either for the
+element itself or one if its ancestors. This method will fail if
+the element is not present.</comment>
+
+</function>
+
+<function name="isEditable">
+
+<return type="boolean">true if the input element is editable, false otherwise</return>
+
+<param name="locator">an <a href="#locators">element locator</a></param>
+
+<comment>Determines whether the specified input element is editable, ie hasn't been disabled.
+This method will fail if the specified element isn't an input element.</comment>
+
+</function>
+
+<function name="getAllButtons">
+
+<return type="string[]">the IDs of all buttons on the page</return>
+
+<comment>Returns the IDs of all buttons on the page.
+
+<p>If a given button has no ID, it will appear as "" in this array.</p></comment>
+
+</function>
+
+<function name="getAllLinks">
+
+<return type="string[]">the IDs of all links on the page</return>
+
+<comment>Returns the IDs of all links on the page.
+
+<p>If a given link has no ID, it will appear as "" in this array.</p></comment>
+
+</function>
+
+<function name="getAllFields">
+
+<return type="string[]">the IDs of all field on the page</return>
+
+<comment>Returns the IDs of all input fields on the page.
+
+<p>If a given field has no ID, it will appear as "" in this array.</p></comment>
+
+</function>
+
+<function name="getAttributeFromAllWindows">
+
+<return type="string[]">the set of values of this attribute from all known windows.</return>
+
+<param name="attributeName">name of an attribute on the windows</param>
+
+<comment>Returns every instance of some attribute from all known windows.</comment>
+
+</function>
+
+<function name="dragdrop">
+
+<param name="locator">an element locator</param>
+
+<param name="movementsString">offset in pixels from the current location to which the element should be moved, e.g., "+70,-300"</param>
+
+<comment>Drags an element a certain distance and then drops it
+Beware of http://jira.openqa.org/browse/SEL-280, which will lead some event handlers to
+get null event arguments. Read the bug for more details, including a workaround.</comment>
+
+</function>
+
+<function name="windowFocus">
+
+<param name="windowName">name of the window to be given focus</param>
+
+<comment>Gives focus to a window</comment>
+
+</function>
+
+<function name="windowMaximize">
+
+<param name="windowName">name of the window to be enlarged</param>
+
+<comment>Resize window to take up the entire screen</comment>
+
+</function>
+
+<function name="getAllWindowIds">
+
+<return type="string[]">the IDs of all windows that the browser knows about.</return>
+
+<comment>Returns the IDs of all windows that the browser knows about.</comment>
+
+</function>
+
+<function name="getAllWindowNames">
+
+<return type="string[]">the names of all windows that the browser knows about.</return>
+
+<comment>Returns the names of all windows that the browser knows about.</comment>
+
+</function>
+
+<function name="getAllWindowTitles">
+
+<return type="string[]">the titles of all windows that the browser knows about.</return>
+
+<comment>Returns the titles of all windows that the browser knows about.</comment>
+
+</function>
+
+<function name="getHtmlSource">
+
+<return type="string">the entire HTML source</return>
+
+<comment>Returns the entire HTML source between the opening and
+closing "html" tags.</comment>
+
+</function>
+
+<function name="setCursorPosition">
+
+<param name="locator">an <a href="#locators">element locator</a> pointing to an input element or textarea</param>
+
+<param name="position">the numerical position of the cursor in the field; position should be 0 to move the position to the beginning of the field. You can also set the cursor to -1 to move it to the end of the field.</param>
+
+<comment>Moves the text cursor to the specified position in the given input element or textarea.
+This method will fail if the specified element isn't an input element or textarea.</comment>
+
+</function>
+
+<function name="getElementPositionLeft">
+
+<return type="number">of pixels from the edge of the frame.</return>
+
+<param name="locator">an <a href="#locators">element locator</a> pointing to an element OR an element itself</param>
+
+<comment>Retrieves the horizontal position of an element</comment>
+
+</function>
+
+<function name="getElementPositionTop">
+
+<return type="number">of pixels from the edge of the frame.</return>
+
+<param name="locator">an <a href="#locators">element locator</a> pointing to an element OR an element itself</param>
+
+<comment>Retrieves the vertical position of an element</comment>
+
+</function>
+
+<function name="getElementWidth">
+
+<return type="number">width of an element in pixels</return>
+
+<param name="locator">an <a href="#locators">element locator</a> pointing to an element</param>
+
+<comment>Retrieves the width of an element</comment>
+
+</function>
+
+<function name="getElementHeight">
+
+<return type="number">height of an element in pixels</return>
+
+<param name="locator">an <a href="#locators">element locator</a> pointing to an element</param>
+
+<comment>Retrieves the height of an element</comment>
+
+</function>
+
+<function name="getCursorPosition">
+
+<return type="number">the numerical position of the cursor in the field</return>
+
+<param name="locator">an <a href="#locators">element locator</a> pointing to an input element or textarea</param>
+
+<comment>Retrieves the text cursor position in the given input element or textarea; beware, this may not work perfectly on all browsers.
+
+<p>Specifically, if the cursor/selection has been cleared by JavaScript, this command will tend to
+return the position of the last location of the cursor, even though the cursor is now gone from the page. This is filed as <a href="http://jira.openqa.org/browse/SEL-243">SEL-243</a>.</p>
+This method will fail if the specified element isn't an input element or textarea, or there is no cursor in the element.</comment>
+
+</function>
+
+<function name="setContext">
+
+<param name="context">the message to be sent to the browser</param>
+
+<param name="logLevelThreshold">one of "debug", "info", "warn", "error", sets the threshold for browser-side logging</param>
+
+<comment>Writes a message to the status bar and adds a note to the browser-side
+log.
+
+<p>If logLevelThreshold is specified, set the threshold for logging
+to that level (debug, info, warn, error).</p>
+
+<p>(Note that the browser-side logs will <i>not</i> be sent back to the
+server, and are invisible to the Client Driver.)</p></comment>
+
+</function>
+
+<function name="getExpression">
+
+<return type="string">the value passed in</return>
+
+<param name="expression">the value to return</param>
+
+<comment>Returns the specified expression.
+
+<p>This is useful because of JavaScript preprocessing.
+It is used to generate commands like assertExpression and waitForExpression.</p></comment>
+
+</function>
+
+<function name="waitForCondition">
+
+<param name="script">the JavaScript snippet to run</param>
+
+<param name="timeout">a timeout in milliseconds, after which this command will return with an error</param>
+
+<comment>Runs the specified JavaScript snippet repeatedly until it evaluates to "true".
+The snippet may have multiple lines, but only the result of the last line
+will be considered.
+
+<p>Note that, by default, the snippet will be run in the runner's test window, not in the window
+of your application. To get the window of your application, you can use
+the JavaScript snippet <code>selenium.browserbot.getCurrentWindow()</code>, and then
+run your JavaScript in there</p></comment>
+
+</function>
+
+<function name="setTimeout">
+
+<param name="timeout">a timeout in milliseconds, after which the action will return with an error</param>
+
+<comment>Specifies the amount of time that Selenium will wait for actions to complete.
+
+<p>Actions that require waiting include "open" and the "waitFor*" actions.</p>
+The default timeout is 30 seconds.</comment>
+
+</function>
+
+<function name="waitForPageToLoad">
+
+<param name="timeout">a timeout in milliseconds, after which this command will return with an error</param>
+
+<comment>Waits for a new page to load.
+
+<p>You can use this command instead of the "AndWait" suffixes, "clickAndWait", "selectAndWait", "typeAndWait" etc.
+(which are only available in the JS API).</p>
+
+<p>Selenium constantly keeps track of new pages loading, and sets a "newPageLoaded"
+flag when it first notices a page load. Running any other Selenium command after
+turns the flag to false. Hence, if you want to wait for a page to load, you must
+wait immediately after a Selenium command that caused a page-load.</p></comment>
+
+</function>
+
+</apidoc>
Modified: zc.selenium/trunk/src/zc/selenium/resources/iedoc.xml
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/iedoc.xml 2006-08-29 18:04:40 UTC (rev 69877)
+++ zc.selenium/trunk/src/zc/selenium/resources/iedoc.xml 2006-08-29 18:41:08 UTC (rev 69878)
@@ -1,545 +1,1113 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<apidoc>
-<top>Defines an object that runs Selenium commands.
+<?xml version="1.0" encoding="UTF-8"?>
-<h3><a name="locators"></a>Element Locators</h3>
-<p>
-Element Locators tell Selenium which HTML element a command refers to.
-The format of a locator is:</p>
-<blockquote>
-<em>locatorType</em><strong>=</strong><em>argument</em>
-</blockquote>
+<apidoc>
-<p>
-We support the following strategies for locating elements:
-</p>
-<blockquote>
-<dl>
-<dt><strong>identifier</strong>=<em>id</em></dt>
-<dd>Select the element with the specified @id attribute. If no match is
-found, select the first element whose @name attribute is <em>id</em>.
-(This is normally the default; see below.)</dd>
-<dt><strong>id</strong>=<em>id</em></dt>
-<dd>Select the element with the specified @id attribute.</dd>
+<top>Defines an object that runs Selenium commands.
+
+<h3><a name="locators"></a>Element Locators</h3>
+<p>
+Element Locators tell Selenium which HTML element a command refers to.
+The format of a locator is:</p>
+<blockquote>
+<em>locatorType</em><strong>=</strong><em>argument</em>
+</blockquote>
+
+<p>
+We support the following strategies for locating elements:
+</p>
+<blockquote>
+<dl>
+<dt><strong>identifier</strong>=<em>id</em></dt>
+<dd>Select the element with the specified @id attribute. If no match is
+found, select the first element whose @name attribute is <em>id</em>.
+(This is normally the default; see below.)</dd>
+<dt><strong>id</strong>=<em>id</em></dt>
+<dd>Select the element with the specified @id attribute.</dd>
+
+<dt><strong>name</strong>=<em>name</em></dt>
+<dd>Select the first element with the specified @name attribute.</dd>
+<dd><ul class="first last simple">
+<li>username</li>
+<li>name=username</li>
+</ul>
+</dd>
+<dd>The name may optionally be followed by one or more <em>element-filters</em>, separated from the name by whitespace. If the <em>filterType</em> is not specified, <strong>value</strong> is assumed.</dd>
+
+<dd><ul class="first last simple">
+<li>name=flavour value=chocolate</li>
+</ul>
+</dd>
+<dt><strong>dom</strong>=<em>javascriptExpression</em></dt>
+
+<dd>
+
+<dd>Find an element using JavaScript traversal of the HTML Document Object
+Model. DOM locators <em>must</em> begin with "document.".
+<ul class="first last simple">
+<li>dom=document.forms['myForm'].myDropdown</li>
+<li>dom=document.images[56]</li>
+</ul>
+</dd>
+
+</dd>
+
+<dt><strong>xpath</strong>=<em>xpathExpression</em></dt>
+<dd>Locate an element using an XPath expression.
+<ul class="first last simple">
+<li>xpath=//img[@alt='The image alt text']</li>
+<li>xpath=//table[@id='table1']//tr[4]/td[2]</li>
+
+</ul>
+</dd>
+<dt><strong>link</strong>=<em>textPattern</em></dt>
+<dd>Select the link (anchor) element which contains text matching the
+specified <em>pattern</em>.
+<ul class="first last simple">
+<li>link=The link text</li>
+</ul>
+
+</dd>
+
+<dt><strong>css</strong>=<em>cssSelectorSyntax</em></dt>
+<dd>Select the element using css selectors. Please refer to <a href="http://www.w3.org/TR/REC-CSS2/selector.html">CSS2 selectors</a>, <a href="http://www.w3.org/TR/2001/CR-css3-selectors-20011113/">CSS3 selectors</a> for more information. You can also check the TestCssLocators test in the selenium test suite for an example of usage, which is included in the downloaded selenium core package.
+<ul class="first last simple">
+<li>css=a[href="#id3"]</li>
+<li>css=span#firstChild + span</li>
+</ul>
+</dd>
+<dd>Currently the css selector locator supports all css1, css2 and css3 selectors except namespace in css3, some pseudo classes(:nth-of-type, :nth-last-of-type, :first-of-type, :last-of-type, :only-of-type, :visited, :hover, :active, :focus, :indeterminate) and pseudo elements(::first-line, ::first-letter, ::selection, ::before, ::after). </dd>
+</dl>
+</blockquote>
+<p>
+Without an explicit locator prefix, Selenium uses the following default
+strategies:
+</p>
+
+<ul class="simple">
+<li><strong>dom</strong>, for locators starting with "document."</li>
+<li><strong>xpath</strong>, for locators starting with "//"</li>
+<li><strong>identifier</strong>, otherwise</li>
+</ul>
+
+<h3><a name="element-filters">Element Filters</a></h3>
+<blockquote>
+<p>Element filters can be used with a locator to refine a list of candidate elements. They are currently used only in the 'name' element-locator.</p>
+<p>Filters look much like locators, ie.</p>
+<blockquote>
+<em>filterType</em><strong>=</strong><em>argument</em></blockquote>
+
+<p>Supported element-filters are:</p>
+<p><strong>value=</strong><em>valuePattern</em></p>
+<blockquote>
+Matches elements based on their values. This is particularly useful for refining a list of similarly-named toggle-buttons.</blockquote>
+<p><strong>index=</strong><em>index</em></p>
+<blockquote>
+Selects a single element based on its position in the list (offset from zero).</blockquote>
+</blockquote>
+
+<h3><a name="patterns"></a>String-match Patterns</h3>
+
+<p>
+Various Pattern syntaxes are available for matching string values:
+</p>
+<blockquote>
+<dl>
+<dt><strong>glob:</strong><em>pattern</em></dt>
+<dd>Match a string against a "glob" (aka "wildmat") pattern. "Glob" is a
+kind of limited regular-expression syntax typically used in command-line
+shells. In a glob pattern, "*" represents any sequence of characters, and "?"
+represents any single character. Glob patterns match against the entire
+string.</dd>
+<dt><strong>regexp:</strong><em>regexp</em></dt>
+<dd>Match a string using a regular-expression. The full power of JavaScript
+regular-expressions is available.</dd>
+<dt><strong>exact:</strong><em>string</em></dt>
+
+<dd>Match a string exactly, verbatim, without any of that fancy wildcard
+stuff.</dd>
+</dl>
+</blockquote>
+<p>
+If no pattern prefix is specified, Selenium assumes that it's a "glob"
+pattern.
+</p></top>
-<dt><strong>name</strong>=<em>name</em></dt>
-<dd>Select the first element with the specified @name attribute.</dd>
-<dd><ul class="first last simple">
-<li>username</li>
-<li>name=username</li>
-</ul>
-</dd>
-<dd>The name may optionally be followed by one or more <em>element-filters</em>, separated from the name by whitespace. If the <em>filterType</em> is not specified, <strong>value</strong> is assumed.</dd>
+<function name="click">
-<dd><ul class="first last simple">
-<li>name=flavour value=chocolate</li>
-</ul>
-</dd>
-<dt><strong>dom</strong>=<em>javascriptExpression</em></dt>
+<param name="locator">an element locator</param>
-<dd>
+<comment>Clicks on a link, button, checkbox or radio button. If the click action
+causes a new page to load (like a link usually does), call
+waitForPageToLoad.</comment>
-<dd>Find an element using JavaScript traversal of the HTML Document Object
-Model. DOM locators <em>must</em> begin with "document.".
-<ul class="first last simple">
-<li>dom=document.forms['myForm'].myDropdown</li>
-<li>dom=document.images[56]</li>
-</ul>
-</dd>
+</function>
-</dd>
+<function name="clickAt">
-<dt><strong>xpath</strong>=<em>xpathExpression</em></dt>
-<dd>Locate an element using an XPath expression.
-<ul class="first last simple">
-<li>xpath=//img[@alt='The image alt text']</li>
-<li>xpath=//table[@id='table1']//tr[4]/td[2]</li>
+<param name="locator">an element locator</param>
-</ul>
-</dd>
-<dt><strong>link</strong>=<em>textPattern</em></dt>
-<dd>Select the link (anchor) element which contains text matching the
-specified <em>pattern</em>.
-<ul class="first last simple">
-<li>link=The link text</li>
-</ul>
+<param name="coordString">specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.</param>
-</dd>
-</dl>
-</blockquote>
-<p>
-Without an explicit locator prefix, Selenium uses the following default
-strategies:
-</p>
+<comment>Clicks on a link, button, checkbox or radio button. If the click action
+causes a new page to load (like a link usually does), call
+waitForPageToLoad.
+
+Beware of http://jira.openqa.org/browse/SEL-280, which will lead some event handlers to
+get null event arguments. Read the bug for more details, including a workaround.</comment>
-<ul class="simple">
-<li><strong>dom</strong>, for locators starting with "document."</li>
-<li><strong>xpath</strong>, for locators starting with "//"</li>
-<li><strong>identifier</strong>, otherwise</li>
-</ul>
+</function>
-<h3><a name="element-filters">Element Filters</a></h3>
-<blockquote>
-<p>Element filters can be used with a locator to refine a list of candidate elements. They are currently used only in the 'name' element-locator.</p>
-<p>Filters look much like locators, ie.</p>
-<blockquote>
-<em>filterType</em><strong>=</strong><em>argument</em></blockquote>
+<function name="fireEvent">
-<p>Supported element-filters are:</p>
-<p><strong>value=</strong><em>valuePattern</em></p>
-<blockquote>
-Matches elements based on their values. This is particularly useful for refining a list of similarly-named toggle-buttons.</blockquote>
-<p><strong>index=</strong><em>index</em></p>
-<blockquote>
-Selects a single element based on its position in the list (offset from zero).</blockquote>
-</blockquote>
+<param name="locator">an <a href="#locators">element locator</a></param>
-<h3><a name="patterns"></a>String-match Patterns</h3>
+<param name="eventName">the event name, e.g. "focus" or "blur"</param>
-<p>
-Various Pattern syntaxes are available for matching string values:
-</p>
-<blockquote>
-<dl>
-<dt><strong>glob:</strong><em>pattern</em></dt>
-<dd>Match a string against a "glob" (aka "wildmat") pattern. "Glob" is a
-kind of limited regular-expression syntax typically used in command-line
-shells. In a glob pattern, "*" represents any sequence of characters, and "?"
-represents any single character. Glob patterns match against the entire
-string.</dd>
-<dt><strong>regexp:</strong><em>regexp</em></dt>
-<dd>Match a string using a regular-expression. The full power of JavaScript
-regular-expressions is available.</dd>
-<dt><strong>exact:</strong><em>string</em></dt>
+<comment>Explicitly simulate an event, to trigger the corresponding "on<em>event</em>"
+handler.</comment>
-<dd>Match a string exactly, verbatim, without any of that fancy wildcard
-stuff.</dd>
-</dl>
-</blockquote>
-<p>
-If no pattern prefix is specified, Selenium assumes that it's a "glob"
-pattern.
-</p></top>
-<function name="click">
-<param name="locator">an element locator</param>
-<comment>Clicks on a link, button, checkbox or radio button. If the click action
-causes a new page to load (like a link usually does), call
-waitForPageToLoad.</comment>
-</function>
-<function name="fireEvent">
-<param name="locator">an <a href="#locators">element locator</a></param>
-<param name="eventName">the event name, e.g. "focus" or "blur"</param>
-<comment>Explicitly simulate an event, to trigger the corresponding "on<em>event</em>"
-handler.</comment>
-</function>
-<function name="keyPress">
-<param name="locator">an <a href="#locators">element locator</a></param>
-<param name="keycode">the numeric keycode of the key to be pressed, normally the
ASCII value of that key.</param>
-<comment>Simulates a user pressing and releasing a key.</comment>
-</function>
-<function name="keyDown">
-<param name="locator">an <a href="#locators">element locator</a></param>
-<param name="keycode">the numeric keycode of the key to be pressed, normally the
ASCII value of that key.</param>
-<comment>Simulates a user pressing a key (without releasing it yet).</comment>
-</function>
-<function name="keyUp">
-<param name="locator">an <a href="#locators">element locator</a></param>
-<param name="keycode">the numeric keycode of the key to be released, normally the
ASCII value of that key.</param>
-<comment>Simulates a user releasing a key.</comment>
-</function>
-<function name="mouseOver">
-<param name="locator">an <a href="#locators">element locator</a></param>
-<comment>Simulates a user hovering a mouse over the specified element.</comment>
-</function>
-<function name="mouseDown">
-<param name="locator">an <a href="#locators">element locator</a></param>
-<comment>Simulates a user pressing the mouse button (without releasing it yet) on
-the specified element.</comment>
-</function>
-<function name="type">
-<param name="locator">an <a href="#locators">element locator</a></param>
-<param name="value">the value to type</param>
-<comment>Sets the value of an input field, as though you typed it in.
+</function>
-<p>Can also be used to set the value of combo boxes, check boxes, etc. In these cases,
-value should be the value of the option selected, not the visible text.</p></comment>
-</function>
-<function name="check">
-<param name="locator">an <a href="#locators">element locator</a></param>
-<comment>Check a toggle-button (checkbox/radio)</comment>
-</function>
-<function name="uncheck">
-<param name="locator">an <a href="#locators">element locator</a></param>
-<comment>Uncheck a toggle-button (checkbox/radio)</comment>
-</function>
-<function name="select">
-<param name="locator">an <a href="#locators">element locator</a> identifying a drop-down menu</param>
-<param name="optionLocator">an option locator (a label by default)</param>
-<comment>Select an option from a drop-down using an option locator.
+<function name="keyPress">
-<p>
-Option locators provide different ways of specifying options of an HTML
-Select element (e.g. for selecting a specific option, or for asserting
-that the selected option satisfies a specification). There are several
-forms of Select Option Locator.
-</p>
-<dl>
-<dt><strong>label</strong>=<em>labelPattern</em></dt>
-<dd>matches options based on their labels, i.e. the visible text. (This
-is the default.)
-<ul class="first last simple">
-<li>label=regexp:^[Oo]ther</li>
-</ul>
-</dd>
-<dt><strong>value</strong>=<em>valuePattern</em></dt>
-<dd>matches options based on their values.
-<ul class="first last simple">
-<li>value=other</li>
-</ul>
+<param name="locator">an <a href="#locators">element locator</a></param>
+<param name="keycode">the numeric keycode of the key to be pressed, normally the ASCII value of that key.</param>
-</dd>
-<dt><strong>id</strong>=<em>id</em></dt>
+<comment>Simulates a user pressing and releasing a key.</comment>
-<dd>matches options based on their ids.
-<ul class="first last simple">
-<li>id=option1</li>
-</ul>
-</dd>
-<dt><strong>index</strong>=<em>index</em></dt>
-<dd>matches an option based on its index (offset from zero).
-<ul class="first last simple">
+</function>
-<li>index=2</li>
-</ul>
-</dd>
-</dl>
-<p>
-If no option locator prefix is provided, the default behaviour is to match on <strong>label</strong>.
-</p></comment>
-</function>
-<function name="addSelection">
-<param name="locator">an <a href="#locators">element locator</a> identifying a multi-select box</param>
-<param name="optionLocator">an option locator (a label by default)</param>
-<comment>Add a selection to the set of selected options in a multi-select element using an option locator.
+<function name="keyDown">
- at see #doSelect for details of option locators</comment>
-</function>
-<function name="removeSelection">
-<param name="locator">an <a href="#locators">element locator</a> identifying a multi-select box</param>
-<param name="optionLocator">an option locator (a label by default)</param>
-<comment>Remove a selection from the set of selected options in a multi-select element using an option locator.
+<param name="locator">an <a href="#locators">element locator</a></param>
- at see #doSelect for details of option locators</comment>
-</function>
-<function name="submit">
-<param name="formLocator">an <a href="#locators">element locator</a> for the form you want to submit</param>
-<comment>Submit the specified form. This is particularly useful for forms without
-submit buttons, e.g. single-input "Search" forms.</comment>
-</function>
-<function name="open">
-<param name="url">the URL to open; may be relative or absolute</param>
-<comment>Opens an URL in the test frame. This accepts both relative and absolute
-URLs.
+<param name="keycode">the numeric keycode of the key to be pressed, normally the ASCII value of that key.</param>
-The "open" command waits for the page to load before proceeding,
-ie. the "AndWait" suffix is implicit.
+<comment>Simulates a user pressing a key (without releasing it yet).</comment>
-<em>Note</em>: The URL must be on the same domain as the runner HTML
-due to security restrictions in the browser (Same Origin Policy). If you
-need to open an URL on another domain, use the Selenium Server to start a
-new browser session on that domain.</comment>
-</function>
-<function name="selectWindow">
-<param name="windowID">the JavaScript window ID of the window to select</param>
-<comment>Selects a popup window; once a popup window has been selected, all
-commands go to that window. To select the main window again, use "null"
-as the target.</comment>
-</function>
-<function name="waitForPopUp">
-<param name="windowID">the JavaScript window ID of the window that will appear</param>
-<param name="timeout">a timeout in milliseconds, after which the action will return with an error</param>
-<comment>Waits for a popup window to appear and load up.</comment>
-</function>
-<function name="chooseCancelOnNextConfirmation">
-<comment>By default, Selenium's overridden window.confirm() function will
-return true, as if the user had manually clicked OK. After running
-this command, the next call to confirm() will return false, as if
-the user had clicked Cancel.</comment>
-</function>
-<function name="answerOnNextPrompt">
-<param name="answer">the answer to give in response to the prompt pop-up</param>
-<comment>Instructs Selenium to return the specified answer string in response to
-the next JavaScript prompt [window.prompt()].</comment>
-</function>
-<function name="goBack">
-<comment>Simulates the user clicking the "back" button on their browser.</comment>
-</function>
-<function name="refresh">
-<comment>Simulates the user clicking the "Refresh" button on their browser.</comment>
-</function>
-<function name="close">
-<comment>Simulates the user clicking the "close" button in the titlebar of a popup
-window or tab.</comment>
-</function>
-<function name="isAlertPresent">
-<return type="boolean">true if there is an alert</return>
-<comment>Has an alert occurred?
+</function>
-<p>
-This function never throws an exception
-</p></comment>
-</function>
-<function name="isPromptPresent">
-<return type="boolean">true if there is a pending prompt</return>
-<comment>Has a prompt occurred?
+<function name="keyUp">
-<p>
-This function never throws an exception
-</p></comment>
-</function>
-<function name="isConfirmationPresent">
-<return type="boolean">true if there is a pending confirmation</return>
-<comment>Has confirm() been called?
+<param name="locator">an <a href="#locators">element locator</a></param>
-<p>
-This function never throws an exception
-</p></comment>
-</function>
-<function name="getAlert">
-<return type="string">The message of the most recent JavaScript alert</return>
-<comment>Retrieves the message of a JavaScript alert generated during the previous action, or fail if there were no alerts.
+<param name="keycode">the numeric keycode of the key to be released, normally the ASCII value of that key.</param>
-<p>Getting an alert has the same effect as manually clicking OK. If an
-alert is generated but you do not get/verify it, the next Selenium action
-will fail.</p>
+<comment>Simulates a user releasing a key.</comment>
-<p>NOTE: under Selenium, JavaScript alerts will NOT pop up a visible alert
-dialog.</p>
+</function>
-<p>NOTE: Selenium does NOT support JavaScript alerts that are generated in a
-page's onload() event handler. In this case a visible dialog WILL be
-generated and Selenium will hang until someone manually clicks OK.</p></comment>
-</function>
-<function name="getConfirmation">
-<return type="string">the message of the most recent JavaScript confirmation dialog</return>
-<comment>Retrieves the message of a JavaScript confirmation dialog generated during
-the previous action.
+<function name="mouseOver">
-<p>
-By default, the confirm function will return true, having the same effect
-as manually clicking OK. This can be changed by prior execution of the
-chooseCancelOnNextConfirmation command. If an confirmation is generated
-but you do not get/verify it, the next Selenium action will fail.
-</p>
+<param name="locator">an <a href="#locators">element locator</a></param>
-<p>
-NOTE: under Selenium, JavaScript confirmations will NOT pop up a visible
-dialog.
-</p>
+<comment>Simulates a user hovering a mouse over the specified element.</comment>
-<p>
-NOTE: Selenium does NOT support JavaScript confirmations that are
-generated in a page's onload() event handler. In this case a visible
-dialog WILL be generated and Selenium will hang until you manually click
-OK.
-</p></comment>
-</function>
-<function name="getPrompt">
-<return type="string">the message of the most recent JavaScript question prompt</return>
-<comment>Retrieves the message of a JavaScript question prompt dialog generated during
-the previous action.
+</function>
-<p>Successful handling of the prompt requires prior execution of the
-answerOnNextPrompt command. If a prompt is generated but you
-do not get/verify it, the next Selenium action will fail.</p>
+<function name="mouseOut">
-<p>NOTE: under Selenium, JavaScript prompts will NOT pop up a visible
-dialog.</p>
+<param name="locator">an <a href="#locators">element locator</a></param>
-<p>NOTE: Selenium does NOT support JavaScript prompts that are generated in a
-page's onload() event handler. In this case a visible dialog WILL be
-generated and Selenium will hang until someone manually clicks OK.</p></comment>
-</function>
-<function name="getAbsoluteLocation">
-<return type="string">the absolute URL of the current page</return>
-<comment>Gets the absolute URL of the current page.</comment>
-</function>
-<function name="isLocation">
-<return type="boolean">true if the location matches, false otherwise</return>
-<param name="expectedLocation">the location to match</param>
-<comment>Verify the location of the current page ends with the expected location.
-If an URL querystring is provided, this is checked as well.</comment>
-</function>
-<function name="getTitle">
-<return type="string">the title of the current page</return>
-<comment>Gets the title of the current page.</comment>
-</function>
-<function name="getBodyText">
-<return type="string">the entire text of the page</return>
-<comment>Gets the entire text of the page.</comment>
-</function>
-<function name="getValue">
-<return type="string">the element value, or "on/off" for checkbox/radio elements</return>
-<param name="locator">an <a href="#locators">element locator</a></param>
-<comment>Gets the (whitespace-trimmed) value of an input field (or anything else with a value parameter).
-For checkbox/radio elements, the value will be "on" or "off" depending on
-whether the element is checked or not.</comment>
-</function>
-<function name="getText">
-<return type="string">the text of the element</return>
-<param name="locator">an <a href="#locators">element locator</a></param>
-<comment>Gets the text of an element. This works for any element that contains
-text. This command uses either the textContent (Mozilla-like browsers) or
-the innerText (IE-like browsers) of the element, which is the rendered
-text shown to the user.</comment>
-</function>
-<function name="getEval">
-<return type="string">the results of evaluating the snippet</return>
-<param name="script">the JavaScript snippet to run</param>
-<comment>Gets the result of evaluating the specified JavaScript snippet. The snippet may
-have multiple lines, but only the result of the last line will be returned.
+<comment>Simulates a user moving the mouse pointer away from the specified element.</comment>
-<p>Note that, by default, the snippet will run in the context of the "selenium"
-object itself, so <code>this</code> will refer to the Selenium object, and <code>window</code> will
-refer to the top-level runner test window, not the window of your application.</p>
+</function>
-<p>If you need a reference to the window of your application, you can refer
-to <code>this.browserbot.getCurrentWindow()</code> and if you need to use
-a locator to refer to a single element in your application page, you can
-use <code>this.page().findElement("foo")</code> where "foo" is your locator.</p></comment>
-</function>
-<function name="getChecked">
-<return type="string">either "true" or "false" depending on whether the checkbox is checked</return>
-<param name="locator">an <a href="#locators">element locator</a> pointing to a checkbox or radio button</param>
-<comment>Gets whether a toggle-button (checkbox/radio) is checked. Fails if the specified element doesn't exist or isn't a toggle-button.</comment>
-</function>
-<function name="getTable">
-<return type="string">the text from the specified cell</return>
-<param name="tableCellAddress">a cell address, e.g. "foo.1.4"</param>
-<comment>Gets the text from a cell of a table. The cellAddress syntax
-tableLocator.row.column, where row and column start at 0.</comment>
-</function>
-<function name="isSelected">
-<return type="boolean">true if the selected option matches the locator, false otherwise</return>
-<param name="locator">an <a href="#locators">element locator</a></param>
-<param name="optionLocator">an option locator, typically just an option label (e.g. "John Smith")</param>
-<comment>Verifies that the selected option of a drop-down satisfies the optionSpecifier.
+<function name="mouseDown">
-<p>See the select command for more information about option locators.</p></comment>
-</function>
-<function name="getSelectedOptions">
-<return type="string[]">an array of all option labels in the specified select drop-down</return>
-<param name="locator">an <a href="#locators">element locator</a></param>
-<comment>Gets all option labels for selected options in the specified select or multi-select element.</comment>
-</function>
-<function name="getSelectOptions">
-<return type="string[]">an array of all option labels in the specified select drop-down</return>
-<param name="locator">an <a href="#locators">element locator</a></param>
-<comment>Gets all option labels in the specified select drop-down.</comment>
-</function>
-<function name="getAttribute">
-<return type="string">the value of the specified attribute</return>
-<param name="attributeLocator">an element locator followed by an</param>
-<comment>Gets the value of an element attribute.</comment>
-</function>
-<function name="isTextPresent">
-<return type="boolean">true if the pattern matches the text, false otherwise</return>
-<param name="pattern">a <a href="#patterns">pattern</a> to match with the text of the page</param>
-<comment>Verifies that the specified text pattern appears somewhere on the rendered page shown to the user.</comment>
-</function>
-<function name="isElementPresent">
-<return type="boolean">true if the element is present, false otherwise</return>
-<param name="locator">an <a href="#locators">element locator</a></param>
-<comment>Verifies that the specified element is somewhere on the page.</comment>
-</function>
-<function name="isVisible">
-<return type="boolean">true if the specified element is visible, false otherwise</return>
-<param name="locator">an <a href="#locators">element locator</a></param>
-<comment>Determines if the specified element is visible. An
-element can be rendered invisible by setting the CSS "visibility"
-property to "hidden", or the "display" property to "none", either for the
-element itself or one if its ancestors. This method will fail if
-the element is not present.</comment>
-</function>
-<function name="isEditable">
-<return type="boolean">true if the input element is editable, false otherwise</return>
-<param name="locator">an <a href="#locators">element locator</a></param>
-<comment>Determines whether the specified input element is editable, ie hasn't been disabled.
-This method will fail if the specified element isn't an input element.</comment>
-</function>
-<function name="getAllButtons">
-<return type="string[]">the IDs of all buttons on the page</return>
-<comment>Returns the IDs of all buttons on the page.
+<param name="locator">an <a href="#locators">element locator</a></param>
-<p>If a given button has no ID, it will appear as "" in this array.</p></comment>
-</function>
-<function name="getAllLinks">
-<return type="string[]">the IDs of all links on the page</return>
-<comment>Returns the IDs of all links on the page.
+<comment>Simulates a user pressing the mouse button (without releasing it yet) on
+the specified element.</comment>
-<p>If a given link has no ID, it will appear as "" in this array.</p></comment>
-</function>
-<function name="getAllFields">
-<return type="string[]">the IDs of all field on the page</return>
-<comment>Returns the IDs of all input fields on the page.
+</function>
-<p>If a given field has no ID, it will appear as "" in this array.</p></comment>
-</function>
-<function name="getHtmlSource">
-<return type="string">the entire HTML source</return>
-<comment>Returns the entire HTML source between the opening and
-closing "html" tags.</comment>
-</function>
-<function name="setContext">
-<param name="context">the message to be sent to the browser</param>
-<param name="logLevelThreshold">one of "debug", "info", "warn", "error", sets the threshold for browser-side logging</param>
-<comment>Writes a message to the status bar and adds a note to the browser-side
-log.
+<function name="mouseDownAt">
-<p>If logLevelThreshold is specified, set the threshold for logging
-to that level (debug, info, warn, error).</p>
+<param name="locator">an <a href="#locators">element locator</a></param>
-<p>(Note that the browser-side logs will <i>not</i> be sent back to the
-server, and are invisible to the Client Driver.)</p></comment>
-</function>
-<function name="getExpression">
-<return type="string">the value passed in</return>
-<param name="expression">the value to return</param>
-<comment>Returns the specified expression.
+<param name="coordString">specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.</param>
-<p>This is useful because of JavaScript preprocessing.
-It is used to generate commands like assertExpression and storeExpression.</p></comment>
-</function>
-<function name="waitForCondition">
-<param name="script">the JavaScript snippet to run</param>
-<param name="timeout">a timeout in milliseconds, after which this command will return with an error</param>
-<comment>Runs the specified JavaScript snippet repeatedly until it evaluates to "true".
-The snippet may have multiple lines, but only the result of the last line
-will be considered.
+<comment>Simulates a user pressing the mouse button (without releasing it yet) on
+the specified element.
+
+Beware of http://jira.openqa.org/browse/SEL-280, which will lead some event handlers to
+get null event arguments. Read the bug for more details, including a workaround.</comment>
-<p>Note that, by default, the snippet will be run in the runner's test window, not in the window
-of your application. To get the window of your application, you can use
-the JavaScript snippet <code>selenium.browserbot.getCurrentWindow()</code>, and then
-run your JavaScript in there</p></comment>
-</function>
-<function name="setTimeout">
-<param name="timeout">a timeout in milliseconds, after which the action will return with an error</param>
-<comment>Specifies the amount of time that Selenium will wait for actions to complete.
+</function>
-<p>Actions that require waiting include "open" and the "waitFor*" actions.</p>
-The default timeout is 30 seconds.</comment>
-</function>
-<function name="waitForPageToLoad">
-<param name="timeout">a timeout in milliseconds, after which this command will return with an error</param>
-<comment>Waits for a new page to load.
+<function name="mouseUp">
-<p>You can use this command instead of the "AndWait" suffixes, "clickAndWait", "selectAndWait", "typeAndWait" etc.
-(which are only available in the JS API).</p>
+<param name="locator">an <a href="#locators">element locator</a></param>
-<p>Selenium constantly keeps track of new pages loading, and sets a "newPageLoaded"
-flag when it first notices a page load. Running any other Selenium command after
-turns the flag to false. Hence, if you want to wait for a page to load, you must
-wait immediately after a Selenium command that caused a page-load.</p></comment>
-</function>
+<comment>Simulates a user pressing the mouse button (without releasing it yet) on
+the specified element.</comment>
+
+</function>
+
+<function name="mouseUpAt">
+
+<param name="locator">an <a href="#locators">element locator</a></param>
+
+<param name="coordString">specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.</param>
+
+<comment>Simulates a user pressing the mouse button (without releasing it yet) on
+the specified element.
+
+Beware of http://jira.openqa.org/browse/SEL-280, which will lead some event handlers to
+get null event arguments. Read the bug for more details, including a workaround.</comment>
+
+</function>
+
+<function name="mouseMove">
+
+<param name="locator">an <a href="#locators">element locator</a></param>
+
+<comment>Simulates a user pressing the mouse button (without releasing it yet) on
+the specified element.</comment>
+
+</function>
+
+<function name="mouseMoveAt">
+
+<param name="locator">an <a href="#locators">element locator</a></param>
+
+<param name="coordString">specifies the x,y position (i.e. - 10,20) of the mouse event relative to the element returned by the locator.</param>
+
+<comment>Simulates a user pressing the mouse button (without releasing it yet) on
+the specified element.
+
+Beware of http://jira.openqa.org/browse/SEL-280, which will lead some event handlers to
+get null event arguments. Read the bug for more details, including a workaround.</comment>
+
+</function>
+
+<function name="type">
+
+<param name="locator">an <a href="#locators">element locator</a></param>
+
+<param name="value">the value to type</param>
+
+<comment>Sets the value of an input field, as though you typed it in.
+
+<p>Can also be used to set the value of combo boxes, check boxes, etc. In these cases,
+value should be the value of the option selected, not the visible text.</p></comment>
+
+</function>
+
+<function name="check">
+
+<param name="locator">an <a href="#locators">element locator</a></param>
+
+<comment>Check a toggle-button (checkbox/radio)</comment>
+
+</function>
+
+<function name="uncheck">
+
+<param name="locator">an <a href="#locators">element locator</a></param>
+
+<comment>Uncheck a toggle-button (checkbox/radio)</comment>
+
+</function>
+
+<function name="select">
+
+<param name="selectLocator">an <a href="#locators">element locator</a> identifying a drop-down menu</param>
+
+<param name="optionLocator">an option locator (a label by default)</param>
+
+<comment>Select an option from a drop-down using an option locator.
+
+<p>
+Option locators provide different ways of specifying options of an HTML
+Select element (e.g. for selecting a specific option, or for asserting
+that the selected option satisfies a specification). There are several
+forms of Select Option Locator.
+</p>
+<dl>
+<dt><strong>label</strong>=<em>labelPattern</em></dt>
+<dd>matches options based on their labels, i.e. the visible text. (This
+is the default.)
+<ul class="first last simple">
+<li>label=regexp:^[Oo]ther</li>
+</ul>
+</dd>
+<dt><strong>value</strong>=<em>valuePattern</em></dt>
+<dd>matches options based on their values.
+<ul class="first last simple">
+<li>value=other</li>
+</ul>
+
+
+</dd>
+<dt><strong>id</strong>=<em>id</em></dt>
+
+<dd>matches options based on their ids.
+<ul class="first last simple">
+<li>id=option1</li>
+</ul>
+</dd>
+<dt><strong>index</strong>=<em>index</em></dt>
+<dd>matches an option based on its index (offset from zero).
+<ul class="first last simple">
+
+<li>index=2</li>
+</ul>
+</dd>
+</dl>
+<p>
+If no option locator prefix is provided, the default behaviour is to match on <strong>label</strong>.
+</p></comment>
+
+</function>
+
+<function name="addSelection">
+
+<param name="locator">an <a href="#locators">element locator</a> identifying a multi-select box</param>
+
+<param name="optionLocator">an option locator (a label by default)</param>
+
+<comment>Add a selection to the set of selected options in a multi-select element using an option locator.
+
+ at see #doSelect for details of option locators</comment>
+
+</function>
+
+<function name="removeSelection">
+
+<param name="locator">an <a href="#locators">element locator</a> identifying a multi-select box</param>
+
+<param name="optionLocator">an option locator (a label by default)</param>
+
+<comment>Remove a selection from the set of selected options in a multi-select element using an option locator.
+
+ at see #doSelect for details of option locators</comment>
+
+</function>
+
+<function name="submit">
+
+<param name="formLocator">an <a href="#locators">element locator</a> for the form you want to submit</param>
+
+<comment>Submit the specified form. This is particularly useful for forms without
+submit buttons, e.g. single-input "Search" forms.</comment>
+
+</function>
+
+<function name="open">
+
+<param name="url">the URL to open; may be relative or absolute</param>
+
+<comment>Opens an URL in the test frame. This accepts both relative and absolute
+URLs.
+
+The "open" command waits for the page to load before proceeding,
+ie. the "AndWait" suffix is implicit.
+
+<em>Note</em>: The URL must be on the same domain as the runner HTML
+due to security restrictions in the browser (Same Origin Policy). If you
+need to open an URL on another domain, use the Selenium Server to start a
+new browser session on that domain.</comment>
+
+</function>
+
+<function name="selectWindow">
+
+<param name="windowID">the JavaScript window ID of the window to select</param>
+
+<comment>Selects a popup window; once a popup window has been selected, all
+commands go to that window. To select the main window again, use "null"
+as the target.</comment>
+
+</function>
+
+<function name="selectFrame">
+
+<param name="locator">an <a href="#locators">element locator</a> identifying a frame or iframe</param>
+
+<comment>NOT IMPLEMENTED YET:
+Selects a frame within the current window. (You may invoke this command
+multiple times to select nested frames.) To select the parent frame, use
+"relative=parent" as a locator; to select the top frame, use "relative=top".
+
+<p>You may also use a DOM expression to identify the frame you want directly,
+like this: <code>dom=frames["main"].frames["subframe"]</code></p></comment>
+
+</function>
+
+<function name="getLogMessages">
+
+<return type="string">all log messages seen since the last call to this API</return>
+
+<comment>Return the contents of the log.
+
+<p>This is a placeholder intended to make the code generator make this API
+available to clients. The selenium server will intercept this call, however,
+and return its recordkeeping of log messages since the last call to this API.
+Thus this code in JavaScript will never be called.</p>
+
+<p>The reason I opted for a servercentric solution is to be able to support
+multiple frames served from different domains, which would break a
+centralized JavaScript logging mechanism under some conditions.</p></comment>
+
+</function>
+
+<function name="getWhetherThisFrameMatchFrameExpression">
+
+<return type="boolean">true if the new frame is this code's window</return>
+
+<param name="currentFrameString">starting frame</param>
+
+<param name="target">new frame (which might be relative to the current one)</param>
+
+<comment>Determine whether current/locator identify the frame containing this running code.
+
+<p>This is useful in proxy injection mode, where this code runs in every
+browser frame and window, and sometimes the selenium server needs to identify
+the "current" frame. In this case, when the test calls selectFrame, this
+routine is called for each frame to figure out which one has been selected.
+The selected frame will return true, while all others will return false.</p></comment>
+
+</function>
+
+<function name="waitForPopUp">
+
+<param name="windowID">the JavaScript window ID of the window that will appear</param>
+
+<param name="timeout">a timeout in milliseconds, after which the action will return with an error</param>
+
+<comment>Waits for a popup window to appear and load up.</comment>
+
+</function>
+
+<function name="chooseCancelOnNextConfirmation">
+
+<comment>By default, Selenium's overridden window.confirm() function will
+return true, as if the user had manually clicked OK. After running
+this command, the next call to confirm() will return false, as if
+the user had clicked Cancel.</comment>
+
+</function>
+
+<function name="answerOnNextPrompt">
+
+<param name="answer">the answer to give in response to the prompt pop-up</param>
+
+<comment>Instructs Selenium to return the specified answer string in response to
+the next JavaScript prompt [window.prompt()].</comment>
+
+</function>
+
+<function name="goBack">
+
+<comment>Simulates the user clicking the "back" button on their browser.</comment>
+
+</function>
+
+<function name="refresh">
+
+<comment>Simulates the user clicking the "Refresh" button on their browser.</comment>
+
+</function>
+
+<function name="close">
+
+<comment>Simulates the user clicking the "close" button in the titlebar of a popup
+window or tab.</comment>
+
+</function>
+
+<function name="isAlertPresent">
+
+<return type="boolean">true if there is an alert</return>
+
+<comment>Has an alert occurred?
+
+<p>
+This function never throws an exception
+</p></comment>
+
+</function>
+
+<function name="isPromptPresent">
+
+<return type="boolean">true if there is a pending prompt</return>
+
+<comment>Has a prompt occurred?
+
+<p>
+This function never throws an exception
+</p></comment>
+
+</function>
+
+<function name="isConfirmationPresent">
+
+<return type="boolean">true if there is a pending confirmation</return>
+
+<comment>Has confirm() been called?
+
+<p>
+This function never throws an exception
+</p></comment>
+
+</function>
+
+<function name="getAlert">
+
+<return type="string">The message of the most recent JavaScript alert</return>
+
+<comment>Retrieves the message of a JavaScript alert generated during the previous action, or fail if there were no alerts.
+
+<p>Getting an alert has the same effect as manually clicking OK. If an
+alert is generated but you do not get/verify it, the next Selenium action
+will fail.</p>
+
+<p>NOTE: under Selenium, JavaScript alerts will NOT pop up a visible alert
+dialog.</p>
+
+<p>NOTE: Selenium does NOT support JavaScript alerts that are generated in a
+page's onload() event handler. In this case a visible dialog WILL be
+generated and Selenium will hang until someone manually clicks OK.</p></comment>
+
+</function>
+
+<function name="getConfirmation">
+
+<return type="string">the message of the most recent JavaScript confirmation dialog</return>
+
+<comment>Retrieves the message of a JavaScript confirmation dialog generated during
+the previous action.
+
+<p>
+By default, the confirm function will return true, having the same effect
+as manually clicking OK. This can be changed by prior execution of the
+chooseCancelOnNextConfirmation command. If an confirmation is generated
+but you do not get/verify it, the next Selenium action will fail.
+</p>
+
+<p>
+NOTE: under Selenium, JavaScript confirmations will NOT pop up a visible
+dialog.
+</p>
+
+<p>
+NOTE: Selenium does NOT support JavaScript confirmations that are
+generated in a page's onload() event handler. In this case a visible
+dialog WILL be generated and Selenium will hang until you manually click
+OK.
+</p></comment>
+
+</function>
+
+<function name="getPrompt">
+
+<return type="string">the message of the most recent JavaScript question prompt</return>
+
+<comment>Retrieves the message of a JavaScript question prompt dialog generated during
+the previous action.
+
+<p>Successful handling of the prompt requires prior execution of the
+answerOnNextPrompt command. If a prompt is generated but you
+do not get/verify it, the next Selenium action will fail.</p>
+
+<p>NOTE: under Selenium, JavaScript prompts will NOT pop up a visible
+dialog.</p>
+
+<p>NOTE: Selenium does NOT support JavaScript prompts that are generated in a
+page's onload() event handler. In this case a visible dialog WILL be
+generated and Selenium will hang until someone manually clicks OK.</p></comment>
+
+</function>
+
+<function name="getLocation">
+
+<return type="string">the absolute URL of the current page</return>
+
+<comment>Gets the absolute URL of the current page.</comment>
+
+</function>
+
+<function name="getTitle">
+
+<return type="string">the title of the current page</return>
+
+<comment>Gets the title of the current page.</comment>
+
+</function>
+
+<function name="getBodyText">
+
+<return type="string">the entire text of the page</return>
+
+<comment>Gets the entire text of the page.</comment>
+
+</function>
+
+<function name="getValue">
+
+<return type="string">the element value, or "on/off" for checkbox/radio elements</return>
+
+<param name="locator">an <a href="#locators">element locator</a></param>
+
+<comment>Gets the (whitespace-trimmed) value of an input field (or anything else with a value parameter).
+For checkbox/radio elements, the value will be "on" or "off" depending on
+whether the element is checked or not.</comment>
+
+</function>
+
+<function name="getText">
+
+<return type="string">the text of the element</return>
+
+<param name="locator">an <a href="#locators">element locator</a></param>
+
+<comment>Gets the text of an element. This works for any element that contains
+text. This command uses either the textContent (Mozilla-like browsers) or
+the innerText (IE-like browsers) of the element, which is the rendered
+text shown to the user.</comment>
+
+</function>
+
+<function name="getEval">
+
+<return type="string">the results of evaluating the snippet</return>
+
+<param name="script">the JavaScript snippet to run</param>
+
+<comment>Gets the result of evaluating the specified JavaScript snippet. The snippet may
+have multiple lines, but only the result of the last line will be returned.
+
+<p>Note that, by default, the snippet will run in the context of the "selenium"
+object itself, so <code>this</code> will refer to the Selenium object, and <code>window</code> will
+refer to the top-level runner test window, not the window of your application.</p>
+
+<p>If you need a reference to the window of your application, you can refer
+to <code>this.browserbot.getCurrentWindow()</code> and if you need to use
+a locator to refer to a single element in your application page, you can
+use <code>this.page().findElement("foo")</code> where "foo" is your locator.</p></comment>
+
+</function>
+
+<function name="isChecked">
+
+<return type="boolean">true if the checkbox is checked, false otherwise</return>
+
+<param name="locator">an <a href="#locators">element locator</a> pointing to a checkbox or radio button</param>
+
+<comment>Gets whether a toggle-button (checkbox/radio) is checked. Fails if the specified element doesn't exist or isn't a toggle-button.</comment>
+
+</function>
+
+<function name="getTable">
+
+<return type="string">the text from the specified cell</return>
+
+<param name="tableCellAddress">a cell address, e.g. "foo.1.4"</param>
+
+<comment>Gets the text from a cell of a table. The cellAddress syntax
+tableLocator.row.column, where row and column start at 0.</comment>
+
+</function>
+
+<function name="getSelectedLabels">
+
+<return type="string[]">an array of all selected option labels in the specified select drop-down</return>
+
+<param name="selectLocator">an <a href="#locators">element locator</a> identifying a drop-down menu</param>
+
+<comment>Gets all option labels (visible text) for selected options in the specified select or multi-select element.</comment>
+
+</function>
+
+<function name="getSelectedLabel">
+
+<return type="string">the selected option label in the specified select drop-down</return>
+
+<param name="selectLocator">an <a href="#locators">element locator</a> identifying a drop-down menu</param>
+
+<comment>Gets option label (visible text) for selected option in the specified select element.</comment>
+
+</function>
+
+<function name="getSelectedValues">
+
+<return type="string[]">an array of all selected option values in the specified select drop-down</return>
+
+<param name="selectLocator">an <a href="#locators">element locator</a> identifying a drop-down menu</param>
+
+<comment>Gets all option values (value attributes) for selected options in the specified select or multi-select element.</comment>
+
+</function>
+
+<function name="getSelectedValue">
+
+<return type="string">the selected option value in the specified select drop-down</return>
+
+<param name="selectLocator">an <a href="#locators">element locator</a> identifying a drop-down menu</param>
+
+<comment>Gets option value (value attribute) for selected option in the specified select element.</comment>
+
+</function>
+
+<function name="getSelectedIndexes">
+
+<return type="string[]">an array of all selected option indexes in the specified select drop-down</return>
+
+<param name="selectLocator">an <a href="#locators">element locator</a> identifying a drop-down menu</param>
+
+<comment>Gets all option indexes (option number, starting at 0) for selected options in the specified select or multi-select element.</comment>
+
+</function>
+
+<function name="getSelectedIndex">
+
+<return type="string">the selected option index in the specified select drop-down</return>
+
+<param name="selectLocator">an <a href="#locators">element locator</a> identifying a drop-down menu</param>
+
+<comment>Gets option index (option number, starting at 0) for selected option in the specified select element.</comment>
+
+</function>
+
+<function name="getSelectedIds">
+
+<return type="string[]">an array of all selected option IDs in the specified select drop-down</return>
+
+<param name="selectLocator">an <a href="#locators">element locator</a> identifying a drop-down menu</param>
+
+<comment>Gets all option element IDs for selected options in the specified select or multi-select element.</comment>
+
+</function>
+
+<function name="getSelectedId">
+
+<return type="string">the selected option ID in the specified select drop-down</return>
+
+<param name="selectLocator">an <a href="#locators">element locator</a> identifying a drop-down menu</param>
+
+<comment>Gets option element ID for selected option in the specified select element.</comment>
+
+</function>
+
+<function name="isSomethingSelected">
+
+<return type="boolean">true if some option has been selected, false otherwise</return>
+
+<param name="selectLocator">an <a href="#locators">element locator</a> identifying a drop-down menu</param>
+
+<comment>Determines whether some option in a drop-down menu is selected.</comment>
+
+</function>
+
+<function name="getSelectOptions">
+
+<return type="string[]">an array of all option labels in the specified select drop-down</return>
+
+<param name="selectLocator">an <a href="#locators">element locator</a> identifying a drop-down menu</param>
+
+<comment>Gets all option labels in the specified select drop-down.</comment>
+
+</function>
+
+<function name="getAttribute">
+
+<return type="string">the value of the specified attribute</return>
+
+<param name="attributeLocator">an element locator followed by an</param>
+
+<comment>Gets the value of an element attribute.
+
+Beware of http://jira.openqa.org/browse/SEL-280, which will lead some event handlers to
+get null event arguments. Read the bug for more details, including a workaround.</comment>
+
+</function>
+
+<function name="isTextPresent">
+
+<return type="boolean">true if the pattern matches the text, false otherwise</return>
+
+<param name="pattern">a <a href="#patterns">pattern</a> to match with the text of the page</param>
+
+<comment>Verifies that the specified text pattern appears somewhere on the rendered page shown to the user.</comment>
+
+</function>
+
+<function name="isElementPresent">
+
+<return type="boolean">true if the element is present, false otherwise</return>
+
+<param name="locator">an <a href="#locators">element locator</a></param>
+
+<comment>Verifies that the specified element is somewhere on the page.</comment>
+
+</function>
+
+<function name="isVisible">
+
+<return type="boolean">true if the specified element is visible, false otherwise</return>
+
+<param name="locator">an <a href="#locators">element locator</a></param>
+
+<comment>Determines if the specified element is visible. An
+element can be rendered invisible by setting the CSS "visibility"
+property to "hidden", or the "display" property to "none", either for the
+element itself or one if its ancestors. This method will fail if
+the element is not present.</comment>
+
+</function>
+
+<function name="isEditable">
+
+<return type="boolean">true if the input element is editable, false otherwise</return>
+
+<param name="locator">an <a href="#locators">element locator</a></param>
+
+<comment>Determines whether the specified input element is editable, ie hasn't been disabled.
+This method will fail if the specified element isn't an input element.</comment>
+
+</function>
+
+<function name="getAllButtons">
+
+<return type="string[]">the IDs of all buttons on the page</return>
+
+<comment>Returns the IDs of all buttons on the page.
+
+<p>If a given button has no ID, it will appear as "" in this array.</p></comment>
+
+</function>
+
+<function name="getAllLinks">
+
+<return type="string[]">the IDs of all links on the page</return>
+
+<comment>Returns the IDs of all links on the page.
+
+<p>If a given link has no ID, it will appear as "" in this array.</p></comment>
+
+</function>
+
+<function name="getAllFields">
+
+<return type="string[]">the IDs of all field on the page</return>
+
+<comment>Returns the IDs of all input fields on the page.
+
+<p>If a given field has no ID, it will appear as "" in this array.</p></comment>
+
+</function>
+
+<function name="getAttributeFromAllWindows">
+
+<return type="string[]">the set of values of this attribute from all known windows.</return>
+
+<param name="attributeName">name of an attribute on the windows</param>
+
+<comment>Returns every instance of some attribute from all known windows.</comment>
+
+</function>
+
+<function name="dragdrop">
+
+<param name="locator">an element locator</param>
+
+<param name="movementsString">offset in pixels from the current location to which the element should be moved, e.g., "+70,-300"</param>
+
+<comment>Drags an element a certain distance and then drops it
+Beware of http://jira.openqa.org/browse/SEL-280, which will lead some event handlers to
+get null event arguments. Read the bug for more details, including a workaround.</comment>
+
+</function>
+
+<function name="windowFocus">
+
+<param name="windowName">name of the window to be given focus</param>
+
+<comment>Gives focus to a window</comment>
+
+</function>
+
+<function name="windowMaximize">
+
+<param name="windowName">name of the window to be enlarged</param>
+
+<comment>Resize window to take up the entire screen</comment>
+
+</function>
+
+<function name="getAllWindowIds">
+
+<return type="string[]">the IDs of all windows that the browser knows about.</return>
+
+<comment>Returns the IDs of all windows that the browser knows about.</comment>
+
+</function>
+
+<function name="getAllWindowNames">
+
+<return type="string[]">the names of all windows that the browser knows about.</return>
+
+<comment>Returns the names of all windows that the browser knows about.</comment>
+
+</function>
+
+<function name="getAllWindowTitles">
+
+<return type="string[]">the titles of all windows that the browser knows about.</return>
+
+<comment>Returns the titles of all windows that the browser knows about.</comment>
+
+</function>
+
+<function name="getHtmlSource">
+
+<return type="string">the entire HTML source</return>
+
+<comment>Returns the entire HTML source between the opening and
+closing "html" tags.</comment>
+
+</function>
+
+<function name="setCursorPosition">
+
+<param name="locator">an <a href="#locators">element locator</a> pointing to an input element or textarea</param>
+
+<param name="position">the numerical position of the cursor in the field; position should be 0 to move the position to the beginning of the field. You can also set the cursor to -1 to move it to the end of the field.</param>
+
+<comment>Moves the text cursor to the specified position in the given input element or textarea.
+This method will fail if the specified element isn't an input element or textarea.</comment>
+
+</function>
+
+<function name="getElementPositionLeft">
+
+<return type="number">of pixels from the edge of the frame.</return>
+
+<param name="locator">an <a href="#locators">element locator</a> pointing to an element OR an element itself</param>
+
+<comment>Retrieves the horizontal position of an element</comment>
+
+</function>
+
+<function name="getElementPositionTop">
+
+<return type="number">of pixels from the edge of the frame.</return>
+
+<param name="locator">an <a href="#locators">element locator</a> pointing to an element OR an element itself</param>
+
+<comment>Retrieves the vertical position of an element</comment>
+
+</function>
+
+<function name="getElementWidth">
+
+<return type="number">width of an element in pixels</return>
+
+<param name="locator">an <a href="#locators">element locator</a> pointing to an element</param>
+
+<comment>Retrieves the width of an element</comment>
+
+</function>
+
+<function name="getElementHeight">
+
+<return type="number">height of an element in pixels</return>
+
+<param name="locator">an <a href="#locators">element locator</a> pointing to an element</param>
+
+<comment>Retrieves the height of an element</comment>
+
+</function>
+
+<function name="getCursorPosition">
+
+<return type="number">the numerical position of the cursor in the field</return>
+
+<param name="locator">an <a href="#locators">element locator</a> pointing to an input element or textarea</param>
+
+<comment>Retrieves the text cursor position in the given input element or textarea; beware, this may not work perfectly on all browsers.
+
+<p>Specifically, if the cursor/selection has been cleared by JavaScript, this command will tend to
+return the position of the last location of the cursor, even though the cursor is now gone from the page. This is filed as <a href="http://jira.openqa.org/browse/SEL-243">SEL-243</a>.</p>
+This method will fail if the specified element isn't an input element or textarea, or there is no cursor in the element.</comment>
+
+</function>
+
+<function name="setContext">
+
+<param name="context">the message to be sent to the browser</param>
+
+<param name="logLevelThreshold">one of "debug", "info", "warn", "error", sets the threshold for browser-side logging</param>
+
+<comment>Writes a message to the status bar and adds a note to the browser-side
+log.
+
+<p>If logLevelThreshold is specified, set the threshold for logging
+to that level (debug, info, warn, error).</p>
+
+<p>(Note that the browser-side logs will <i>not</i> be sent back to the
+server, and are invisible to the Client Driver.)</p></comment>
+
+</function>
+
+<function name="getExpression">
+
+<return type="string">the value passed in</return>
+
+<param name="expression">the value to return</param>
+
+<comment>Returns the specified expression.
+
+<p>This is useful because of JavaScript preprocessing.
+It is used to generate commands like assertExpression and waitForExpression.</p></comment>
+
+</function>
+
+<function name="waitForCondition">
+
+<param name="script">the JavaScript snippet to run</param>
+
+<param name="timeout">a timeout in milliseconds, after which this command will return with an error</param>
+
+<comment>Runs the specified JavaScript snippet repeatedly until it evaluates to "true".
+The snippet may have multiple lines, but only the result of the last line
+will be considered.
+
+<p>Note that, by default, the snippet will be run in the runner's test window, not in the window
+of your application. To get the window of your application, you can use
+the JavaScript snippet <code>selenium.browserbot.getCurrentWindow()</code>, and then
+run your JavaScript in there</p></comment>
+
+</function>
+
+<function name="setTimeout">
+
+<param name="timeout">a timeout in milliseconds, after which the action will return with an error</param>
+
+<comment>Specifies the amount of time that Selenium will wait for actions to complete.
+
+<p>Actions that require waiting include "open" and the "waitFor*" actions.</p>
+The default timeout is 30 seconds.</comment>
+
+</function>
+
+<function name="waitForPageToLoad">
+
+<param name="timeout">a timeout in milliseconds, after which this command will return with an error</param>
+
+<comment>Waits for a new page to load.
+
+<p>You can use this command instead of the "AndWait" suffixes, "clickAndWait", "selectAndWait", "typeAndWait" etc.
+(which are only available in the JS API).</p>
+
+<p>Selenium constantly keeps track of new pages loading, and sets a "newPageLoaded"
+flag when it first notices a page load. Running any other Selenium command after
+turns the flag to false. Hence, if you want to wait for a page to load, you must
+wait immediately after a Selenium command that caused a page-load.</p></comment>
+
+</function>
+
</apidoc>
Added: zc.selenium/trunk/src/zc/selenium/resources/lib/cssQuery-level2.js
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/lib/cssQuery-level2.js 2006-08-29 18:04:40 UTC (rev 69877)
+++ zc.selenium/trunk/src/zc/selenium/resources/lib/cssQuery-level2.js 2006-08-29 18:41:08 UTC (rev 69878)
@@ -0,0 +1,142 @@
+/*
+ cssQuery, version 2.0.2 (2005-08-19)
+ Copyright: 2004-2005, Dean Edwards (http://dean.edwards.name/)
+ License: http://creativecommons.org/licenses/LGPL/2.1/
+*/
+
+cssQuery.addModule("css-level2", function() {
+
+// -----------------------------------------------------------------------
+// selectors
+// -----------------------------------------------------------------------
+
+// child selector
+selectors[">"] = function($results, $from, $tagName, $namespace) {
+ var $element, i, j;
+ for (i = 0; i < $from.length; i++) {
+ var $subset = childElements($from[i]);
+ for (j = 0; ($element = $subset[j]); j++)
+ if (compareTagName($element, $tagName, $namespace))
+ $results.push($element);
+ }
+};
+
+// sibling selector
+selectors["+"] = function($results, $from, $tagName, $namespace) {
+ for (var i = 0; i < $from.length; i++) {
+ var $element = nextElementSibling($from[i]);
+ if ($element && compareTagName($element, $tagName, $namespace))
+ $results.push($element);
+ }
+};
+
+// attribute selector
+selectors["@"] = function($results, $from, $attributeSelectorID) {
+ var $test = attributeSelectors[$attributeSelectorID].test;
+ var $element, i;
+ for (i = 0; ($element = $from[i]); i++)
+ if ($test($element)) $results.push($element);
+};
+
+// -----------------------------------------------------------------------
+// pseudo-classes
+// -----------------------------------------------------------------------
+
+pseudoClasses["first-child"] = function($element) {
+ return !previousElementSibling($element);
+};
+
+pseudoClasses["lang"] = function($element, $code) {
+ $code = new RegExp("^" + $code, "i");
+ while ($element && !$element.getAttribute("lang")) $element = $element.parentNode;
+ return $element && $code.test($element.getAttribute("lang"));
+};
+
+// -----------------------------------------------------------------------
+// attribute selectors
+// -----------------------------------------------------------------------
+
+// constants
+AttributeSelector.NS_IE = /\\:/g;
+AttributeSelector.PREFIX = "@";
+// properties
+AttributeSelector.tests = {};
+// methods
+AttributeSelector.replace = function($match, $attribute, $namespace, $compare, $value) {
+ var $key = this.PREFIX + $match;
+ if (!attributeSelectors[$key]) {
+ $attribute = this.create($attribute, $compare || "", $value || "");
+ // store the selector
+ attributeSelectors[$key] = $attribute;
+ attributeSelectors.push($attribute);
+ }
+ return attributeSelectors[$key].id;
+};
+AttributeSelector.parse = function($selector) {
+ $selector = $selector.replace(this.NS_IE, "|");
+ var $match;
+ while ($match = $selector.match(this.match)) {
+ var $replace = this.replace($match[0], $match[1], $match[2], $match[3], $match[4]);
+ $selector = $selector.replace(this.match, $replace);
+ }
+ return $selector;
+};
+AttributeSelector.create = function($propertyName, $test, $value) {
+ var $attributeSelector = {};
+ $attributeSelector.id = this.PREFIX + attributeSelectors.length;
+ $attributeSelector.name = $propertyName;
+ $test = this.tests[$test];
+ $test = $test ? $test(this.getAttribute($propertyName), getText($value)) : false;
+ $attributeSelector.test = new Function("e", "return " + $test);
+ return $attributeSelector;
+};
+AttributeSelector.getAttribute = function($name) {
+ switch ($name.toLowerCase()) {
+ case "id":
+ return "e.id";
+ case "class":
+ return "e.className";
+ case "for":
+ return "e.htmlFor";
+ case "href":
+ if (isMSIE) {
+ // IE always returns the full path not the fragment in the href attribute
+ // so we RegExp it out of outerHTML. Opera does the same thing but there
+ // is no way to get the original attribute.
+ return "String((e.outerHTML.match(/href=\\x22?([^\\s\\x22]*)\\x22?/)||[])[1]||'')";
+ }
+ }
+ return "e.getAttribute('" + $name.replace($NAMESPACE, ":") + "')";
+};
+
+// -----------------------------------------------------------------------
+// attribute selector tests
+// -----------------------------------------------------------------------
+
+AttributeSelector.tests[""] = function($attribute) {
+ return $attribute;
+};
+
+AttributeSelector.tests["="] = function($attribute, $value) {
+ return $attribute + "==" + Quote.add($value);
+};
+
+AttributeSelector.tests["~="] = function($attribute, $value) {
+ return "/(^| )" + regEscape($value) + "( |$)/.test(" + $attribute + ")";
+};
+
+AttributeSelector.tests["|="] = function($attribute, $value) {
+ return "/^" + regEscape($value) + "(-|$)/.test(" + $attribute + ")";
+};
+
+// -----------------------------------------------------------------------
+// parsing
+// -----------------------------------------------------------------------
+
+// override parseSelector to parse out attribute selectors
+var _parseSelector = parseSelector;
+parseSelector = function($selector) {
+ return _parseSelector(AttributeSelector.parse($selector));
+};
+
+}); // addModule
Added: zc.selenium/trunk/src/zc/selenium/resources/lib/cssQuery-level3.js
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/lib/cssQuery-level3.js 2006-08-29 18:04:40 UTC (rev 69877)
+++ zc.selenium/trunk/src/zc/selenium/resources/lib/cssQuery-level3.js 2006-08-29 18:41:08 UTC (rev 69878)
@@ -0,0 +1,150 @@
+/*
+ cssQuery, version 2.0.2 (2005-08-19)
+ Copyright: 2004-2005, Dean Edwards (http://dean.edwards.name/)
+ License: http://creativecommons.org/licenses/LGPL/2.1/
+*/
+
+/* Thanks to Bill Edney */
+
+cssQuery.addModule("css-level3", function() {
+
+// -----------------------------------------------------------------------
+// selectors
+// -----------------------------------------------------------------------
+
+// indirect sibling selector
+selectors["~"] = function($results, $from, $tagName, $namespace) {
+ var $element, i;
+ for (i = 0; ($element = $from[i]); i++) {
+ while ($element = nextElementSibling($element)) {
+ if (compareTagName($element, $tagName, $namespace))
+ $results.push($element);
+ }
+ }
+};
+
+// -----------------------------------------------------------------------
+// pseudo-classes
+// -----------------------------------------------------------------------
+
+// I'm hoping these pseudo-classes are pretty readable. Let me know if
+// any need explanation.
+
+pseudoClasses["contains"] = function($element, $text) {
+ $text = new RegExp(regEscape(getText($text)));
+ return $text.test(getTextContent($element));
+};
+
+pseudoClasses["root"] = function($element) {
+ return $element == getDocument($element).documentElement;
+};
+
+pseudoClasses["empty"] = function($element) {
+ var $node, i;
+ for (i = 0; ($node = $element.childNodes[i]); i++) {
+ if (thisElement($node) || $node.nodeType == 3) return false;
+ }
+ return true;
+};
+
+pseudoClasses["last-child"] = function($element) {
+ return !nextElementSibling($element);
+};
+
+pseudoClasses["only-child"] = function($element) {
+ $element = $element.parentNode;
+ return firstElementChild($element) == lastElementChild($element);
+};
+
+pseudoClasses["not"] = function($element, $selector) {
+ var $negated = cssQuery($selector, getDocument($element));
+ for (var i = 0; i < $negated.length; i++) {
+ if ($negated[i] == $element) return false;
+ }
+ return true;
+};
+
+pseudoClasses["nth-child"] = function($element, $arguments) {
+ return nthChild($element, $arguments, previousElementSibling);
+};
+
+pseudoClasses["nth-last-child"] = function($element, $arguments) {
+ return nthChild($element, $arguments, nextElementSibling);
+};
+
+pseudoClasses["target"] = function($element) {
+ return $element.id == location.hash.slice(1);
+};
+
+// UI element states
+
+pseudoClasses["checked"] = function($element) {
+ return $element.checked;
+};
+
+pseudoClasses["enabled"] = function($element) {
+ return $element.disabled === false;
+};
+
+pseudoClasses["disabled"] = function($element) {
+ return $element.disabled;
+};
+
+pseudoClasses["indeterminate"] = function($element) {
+ return $element.indeterminate;
+};
+
+// -----------------------------------------------------------------------
+// attribute selector tests
+// -----------------------------------------------------------------------
+
+AttributeSelector.tests["^="] = function($attribute, $value) {
+ return "/^" + regEscape($value) + "/.test(" + $attribute + ")";
+};
+
+AttributeSelector.tests["$="] = function($attribute, $value) {
+ return "/" + regEscape($value) + "$/.test(" + $attribute + ")";
+};
+
+AttributeSelector.tests["*="] = function($attribute, $value) {
+ return "/" + regEscape($value) + "/.test(" + $attribute + ")";
+};
+
+// -----------------------------------------------------------------------
+// nth child support (Bill Edney)
+// -----------------------------------------------------------------------
+
+function nthChild($element, $arguments, $traverse) {
+ switch ($arguments) {
+ case "n": return true;
+ case "even": $arguments = "2n"; break;
+ case "odd": $arguments = "2n+1";
+ }
+
+ var $$children = childElements($element.parentNode);
+ function _checkIndex($index) {
+ var $index = ($traverse == nextElementSibling) ? $$children.length - $index : $index - 1;
+ return $$children[$index] == $element;
+ };
+
+ // it was just a number (no "n")
+ if (!isNaN($arguments)) return _checkIndex($arguments);
+
+ $arguments = $arguments.split("n");
+ var $multiplier = parseInt($arguments[0]);
+ var $step = parseInt($arguments[1]);
+
+ if ((isNaN($multiplier) || $multiplier == 1) && $step == 0) return true;
+ if ($multiplier == 0 && !isNaN($step)) return _checkIndex($step);
+ if (isNaN($step)) $step = 0;
+
+ var $count = 1;
+ while ($element = $traverse($element)) $count++;
+
+ if (isNaN($multiplier) || $multiplier == 1)
+ return ($traverse == nextElementSibling) ? ($count <= $step) : ($step >= $count);
+
+ return ($count % $multiplier) == $step;
+};
+
+}); // addModule
Added: zc.selenium/trunk/src/zc/selenium/resources/lib/cssQuery-standard.js
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/lib/cssQuery-standard.js 2006-08-29 18:04:40 UTC (rev 69877)
+++ zc.selenium/trunk/src/zc/selenium/resources/lib/cssQuery-standard.js 2006-08-29 18:41:08 UTC (rev 69878)
@@ -0,0 +1,53 @@
+/*
+ cssQuery, version 2.0.2 (2005-08-19)
+ Copyright: 2004-2005, Dean Edwards (http://dean.edwards.name/)
+ License: http://creativecommons.org/licenses/LGPL/2.1/
+*/
+
+cssQuery.addModule("css-standard", function() { // override IE optimisation
+
+// cssQuery was originally written as the CSS engine for IE7. It is
+// optimised (in terms of size not speed) for IE so this module is
+// provided separately to provide cross-browser support.
+
+// -----------------------------------------------------------------------
+// browser compatibility
+// -----------------------------------------------------------------------
+
+// sniff for Win32 Explorer
+isMSIE = eval("false;/*@cc_on at if(@\x5fwin32)isMSIE=true at end@*/");
+
+if (!isMSIE) {
+ getElementsByTagName = function($element, $tagName, $namespace) {
+ return $namespace ? $element.getElementsByTagNameNS("*", $tagName) :
+ $element.getElementsByTagName($tagName);
+ };
+
+ compareNamespace = function($element, $namespace) {
+ return !$namespace || ($namespace == "*") || ($element.prefix == $namespace);
+ };
+
+ isXML = document.contentType ? function($element) {
+ return /xml/i.test(getDocument($element).contentType);
+ } : function($element) {
+ return getDocument($element).documentElement.tagName != "HTML";
+ };
+
+ getTextContent = function($element) {
+ // mozilla || opera || other
+ return $element.textContent || $element.innerText || _getTextContent($element);
+ };
+
+ function _getTextContent($element) {
+ var $textContent = "", $node, i;
+ for (i = 0; ($node = $element.childNodes[i]); i++) {
+ switch ($node.nodeType) {
+ case 11: // document fragment
+ case 1: $textContent += _getTextContent($node); break;
+ case 3: $textContent += $node.nodeValue; break;
+ }
+ }
+ return $textContent;
+ };
+}
+}); // addModule
Added: zc.selenium/trunk/src/zc/selenium/resources/lib/cssQuery.js
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/lib/cssQuery.js 2006-08-29 18:04:40 UTC (rev 69877)
+++ zc.selenium/trunk/src/zc/selenium/resources/lib/cssQuery.js 2006-08-29 18:41:08 UTC (rev 69878)
@@ -0,0 +1,356 @@
+/*
+ cssQuery, version 2.0.2 (2005-08-19)
+ Copyright: 2004-2005, Dean Edwards (http://dean.edwards.name/)
+ License: http://creativecommons.org/licenses/LGPL/2.1/
+*/
+
+// the following functions allow querying of the DOM using CSS selectors
+var cssQuery = function() {
+var version = "2.0.2";
+
+// -----------------------------------------------------------------------
+// main query function
+// -----------------------------------------------------------------------
+
+var $COMMA = /\s*,\s*/;
+var cssQuery = function($selector, $$from) {
+try {
+ var $match = [];
+ var $useCache = arguments.callee.caching && !$$from;
+ var $base = ($$from) ? ($$from.constructor == Array) ? $$from : [$$from] : [document];
+ // process comma separated selectors
+ var $$selectors = parseSelector($selector).split($COMMA), i;
+ for (i = 0; i < $$selectors.length; i++) {
+ // convert the selector to a stream
+ $selector = _toStream($$selectors[i]);
+ // faster chop if it starts with id (MSIE only)
+ if (isMSIE && $selector.slice(0, 3).join("") == " *#") {
+ $selector = $selector.slice(2);
+ $$from = _msie_selectById([], $base, $selector[1]);
+ } else $$from = $base;
+ // process the stream
+ var j = 0, $token, $filter, $arguments, $cacheSelector = "";
+ while (j < $selector.length) {
+ $token = $selector[j++];
+ $filter = $selector[j++];
+ $cacheSelector += $token + $filter;
+ // some pseudo-classes allow arguments to be passed
+ // e.g. nth-child(even)
+ $arguments = "";
+ if ($selector[j] == "(") {
+ while ($selector[j++] != ")" && j < $selector.length) {
+ $arguments += $selector[j];
+ }
+ $arguments = $arguments.slice(0, -1);
+ $cacheSelector += "(" + $arguments + ")";
+ }
+ // process a token/filter pair use cached results if possible
+ $$from = ($useCache && cache[$cacheSelector]) ?
+ cache[$cacheSelector] : select($$from, $token, $filter, $arguments);
+ if ($useCache) cache[$cacheSelector] = $$from;
+ }
+ $match = $match.concat($$from);
+ }
+ delete cssQuery.error;
+ return $match;
+} catch ($error) {
+ cssQuery.error = $error;
+ return [];
+}};
+
+// -----------------------------------------------------------------------
+// public interface
+// -----------------------------------------------------------------------
+
+cssQuery.toString = function() {
+ return "function cssQuery() {\n [version " + version + "]\n}";
+};
+
+// caching
+var cache = {};
+cssQuery.caching = false;
+cssQuery.clearCache = function($selector) {
+ if ($selector) {
+ $selector = _toStream($selector).join("");
+ delete cache[$selector];
+ } else cache = {};
+};
+
+// allow extensions
+var modules = {};
+var loaded = false;
+cssQuery.addModule = function($name, $script) {
+ if (loaded) eval("$script=" + String($script));
+ modules[$name] = new $script();;
+};
+
+// hackery
+cssQuery.valueOf = function($code) {
+ return $code ? eval($code) : this;
+};
+
+// -----------------------------------------------------------------------
+// declarations
+// -----------------------------------------------------------------------
+
+var selectors = {};
+var pseudoClasses = {};
+// a safari bug means that these have to be declared here
+var AttributeSelector = {match: /\[([\w-]+(\|[\w-]+)?)\s*(\W?=)?\s*([^\]]*)\]/};
+var attributeSelectors = [];
+
+// -----------------------------------------------------------------------
+// selectors
+// -----------------------------------------------------------------------
+
+// descendant selector
+selectors[" "] = function($results, $from, $tagName, $namespace) {
+ // loop through current selection
+ var $element, i, j;
+ for (i = 0; i < $from.length; i++) {
+ // get descendants
+ var $subset = getElementsByTagName($from[i], $tagName, $namespace);
+ // loop through descendants and add to results selection
+ for (j = 0; ($element = $subset[j]); j++) {
+ if (thisElement($element) && compareNamespace($element, $namespace))
+ $results.push($element);
+ }
+ }
+};
+
+// ID selector
+selectors["#"] = function($results, $from, $id) {
+ // loop through current selection and check ID
+ var $element, j;
+ for (j = 0; ($element = $from[j]); j++) if ($element.id == $id) $results.push($element);
+};
+
+// class selector
+selectors["."] = function($results, $from, $className) {
+ // create a RegExp version of the class
+ $className = new RegExp("(^|\\s)" + $className + "(\\s|$)");
+ // loop through current selection and check class
+ var $element, i;
+ for (i = 0; ($element = $from[i]); i++)
+ if ($className.test($element.className)) $results.push($element);
+};
+
+// pseudo-class selector
+selectors[":"] = function($results, $from, $pseudoClass, $arguments) {
+ // retrieve the cssQuery pseudo-class function
+ var $test = pseudoClasses[$pseudoClass], $element, i;
+ // loop through current selection and apply pseudo-class filter
+ if ($test) for (i = 0; ($element = $from[i]); i++)
+ // if the cssQuery pseudo-class function returns "true" add the element
+ if ($test($element, $arguments)) $results.push($element);
+};
+
+// -----------------------------------------------------------------------
+// pseudo-classes
+// -----------------------------------------------------------------------
+
+pseudoClasses["link"] = function($element) {
+ var $document = getDocument($element);
+ if ($document.links) for (var i = 0; i < $document.links.length; i++) {
+ if ($document.links[i] == $element) return true;
+ }
+};
+
+pseudoClasses["visited"] = function($element) {
+ // can't do this without jiggery-pokery
+};
+
+// -----------------------------------------------------------------------
+// DOM traversal
+// -----------------------------------------------------------------------
+
+// IE5/6 includes comments (LOL) in it's elements collections.
+// so we have to check for this. the test is tagName != "!". LOL (again).
+var thisElement = function($element) {
+ return ($element && $element.nodeType == 1 && $element.tagName != "!") ? $element : null;
+};
+
+// return the previous element to the supplied element
+// previousSibling is not good enough as it might return a text or comment node
+var previousElementSibling = function($element) {
+ while ($element && ($element = $element.previousSibling) && !thisElement($element)) continue;
+ return $element;
+};
+
+// return the next element to the supplied element
+var nextElementSibling = function($element) {
+ while ($element && ($element = $element.nextSibling) && !thisElement($element)) continue;
+ return $element;
+};
+
+// return the first child ELEMENT of an element
+// NOT the first child node (though they may be the same thing)
+var firstElementChild = function($element) {
+ return thisElement($element.firstChild) || nextElementSibling($element.firstChild);
+};
+
+var lastElementChild = function($element) {
+ return thisElement($element.lastChild) || previousElementSibling($element.lastChild);
+};
+
+// return child elements of an element (not child nodes)
+var childElements = function($element) {
+ var $childElements = [];
+ $element = firstElementChild($element);
+ while ($element) {
+ $childElements.push($element);
+ $element = nextElementSibling($element);
+ }
+ return $childElements;
+};
+
+// -----------------------------------------------------------------------
+// browser compatibility
+// -----------------------------------------------------------------------
+
+// all of the functions in this section can be overwritten. the default
+// configuration is for IE. The functions below reflect this. standard
+// methods are included in a separate module. It would probably be better
+// the other way round of course but this makes it easier to keep IE7 trim.
+
+var isMSIE = true;
+
+var isXML = function($element) {
+ var $document = getDocument($element);
+ return (typeof $document.mimeType == "unknown") ?
+ /\.xml$/i.test($document.URL) :
+ Boolean($document.mimeType == "XML Document");
+};
+
+// return the element's containing document
+var getDocument = function($element) {
+ return $element.ownerDocument || $element.document;
+};
+
+var getElementsByTagName = function($element, $tagName) {
+ return ($tagName == "*" && $element.all) ? $element.all : $element.getElementsByTagName($tagName);
+};
+
+var compareTagName = function($element, $tagName, $namespace) {
+ if ($tagName == "*") return thisElement($element);
+ if (!compareNamespace($element, $namespace)) return false;
+ if (!isXML($element)) $tagName = $tagName.toUpperCase();
+ return $element.tagName == $tagName;
+};
+
+var compareNamespace = function($element, $namespace) {
+ return !$namespace || ($namespace == "*") || ($element.scopeName == $namespace);
+};
+
+var getTextContent = function($element) {
+ return $element.innerText;
+};
+
+function _msie_selectById($results, $from, id) {
+ var $match, i, j;
+ for (i = 0; i < $from.length; i++) {
+ if ($match = $from[i].all.item(id)) {
+ if ($match.id == id) $results.push($match);
+ else if ($match.length != null) {
+ for (j = 0; j < $match.length; j++) {
+ if ($match[j].id == id) $results.push($match[j]);
+ }
+ }
+ }
+ }
+ return $results;
+};
+
+// for IE5.0
+if (![].push) Array.prototype.push = function() {
+ for (var i = 0; i < arguments.length; i++) {
+ this[this.length] = arguments[i];
+ }
+ return this.length;
+};
+
+// -----------------------------------------------------------------------
+// query support
+// -----------------------------------------------------------------------
+
+// select a set of matching elements.
+// "from" is an array of elements.
+// "token" is a character representing the type of filter
+// e.g. ">" means child selector
+// "filter" represents the tag name, id or class name that is being selected
+// the function returns an array of matching elements
+var $NAMESPACE = /\|/;
+function select($$from, $token, $filter, $arguments) {
+ if ($NAMESPACE.test($filter)) {
+ $filter = $filter.split($NAMESPACE);
+ $arguments = $filter[0];
+ $filter = $filter[1];
+ }
+ var $results = [];
+ if (selectors[$token]) {
+ selectors[$token]($results, $$from, $filter, $arguments);
+ }
+ return $results;
+};
+
+// -----------------------------------------------------------------------
+// parsing
+// -----------------------------------------------------------------------
+
+// convert css selectors to a stream of tokens and filters
+// it's not a real stream. it's just an array of strings.
+var $STANDARD_SELECT = /^[^\s>+~]/;
+var $$STREAM = /[\s#.:>+~()@]|[^\s#.:>+~()@]+/g;
+function _toStream($selector) {
+ if ($STANDARD_SELECT.test($selector)) $selector = " " + $selector;
+ return $selector.match($$STREAM) || [];
+};
+
+var $WHITESPACE = /\s*([\s>+~(),]|^|$)\s*/g;
+var $IMPLIED_ALL = /([\s>+~,]|[^(]\+|^)([#.:@])/g;
+var parseSelector = function($selector) {
+ return $selector
+ // trim whitespace
+ .replace($WHITESPACE, "$1")
+ // e.g. ".class1" --> "*.class1"
+ .replace($IMPLIED_ALL, "$1*$2");
+};
+
+var Quote = {
+ toString: function() {return "'"},
+ match: /^('[^']*')|("[^"]*")$/,
+ test: function($string) {
+ return this.match.test($string);
+ },
+ add: function($string) {
+ return this.test($string) ? $string : this + $string + this;
+ },
+ remove: function($string) {
+ return this.test($string) ? $string.slice(1, -1) : $string;
+ }
+};
+
+var getText = function($text) {
+ return Quote.remove($text);
+};
+
+var $ESCAPE = /([\/()[\]?{}|*+-])/g;
+function regEscape($string) {
+ return $string.replace($ESCAPE, "\\$1");
+};
+
+// -----------------------------------------------------------------------
+// modules
+// -----------------------------------------------------------------------
+
+// -------- >> insert modules here for packaging << -------- \\
+
+loaded = true;
+
+// -----------------------------------------------------------------------
+// return the query function
+// -----------------------------------------------------------------------
+
+return cssQuery;
+
+}(); // cssQuery
Added: zc.selenium/trunk/src/zc/selenium/resources/scripts/find_matching_child.js
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/scripts/find_matching_child.js 2006-08-29 18:04:40 UTC (rev 69877)
+++ zc.selenium/trunk/src/zc/selenium/resources/scripts/find_matching_child.js 2006-08-29 18:41:08 UTC (rev 69878)
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2004 ThoughtWorks, Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+Element.findMatchingChildren = function(element, selector) {
+ var matches = $A([]);
+
+ var childCount = element.childNodes.length;
+ for (var i=0; i<childCount; i++) {
+ var child = element.childNodes[i];
+ if (selector(child)) {
+ matches.push(child);
+ } else {
+ childMatches = Element.findMatchingChildren(child, selector);
+ matches.push(childMatches);
+ }
+ }
+
+ return matches.flatten();
+}
+
+ELEMENT_NODE_TYPE = 1;
+
+Element.findFirstMatchingChild = function(element, selector) {
+
+ var childCount = element.childNodes.length;
+ for (var i=0; i<childCount; i++) {
+ var child = element.childNodes[i];
+ if (child.nodeType == ELEMENT_NODE_TYPE) {
+ if (selector(child)) {
+ return child;
+ }
+ result = Element.findFirstMatchingChild(child, selector);
+ if (result) {
+ return result;
+ }
+ }
+ }
+ return null;
+}
+
+Element.findFirstMatchingParent = function(element, selector) {
+ var current = element.parentNode;
+ while (current != null) {
+ if (selector(current)) {
+ break;
+ }
+ current = current.parentNode;
+ }
+ return current;
+}
+
+Element.findMatchingChildById = function(element, id) {
+ return Element.findFirstMatchingChild(element, function(element){return element.id==id} );
+}
+
Deleted: zc.selenium/trunk/src/zc/selenium/resources/scripts/html-xpath-patched.js
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/scripts/html-xpath-patched.js 2006-08-29 18:04:40 UTC (rev 69877)
+++ zc.selenium/trunk/src/zc/selenium/resources/scripts/html-xpath-patched.js 2006-08-29 18:41:08 UTC (rev 69878)
@@ -1,660 +0,0 @@
-/*
- html-xpath, an implementation of DOM Level 3 XPath for Internet Explorer 5+
- Copyright (C) 2004 Dimitri Glazkov
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- This library 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
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
-
-*/
-
-/** SELENIUM:PATCH TO ALLOW USE WITH DOCUMENTS FROM OTHER WINDOWS: 2004-11-24
- TODO resubmit this to http://sf.net/projects/html-xpath */
-function addXPathSupport(document) {
-/** END SELENIUM:PATCH */
-
-var isIe = /MSIE [56789]/.test(navigator.userAgent) && (navigator.platform == "Win32");
-
-// Mozilla has support by default, we don't have an implementation for the rest
-if (isIe)
-{
- // release number
- document.DomL3XPathRelease = "0.0.3.0";
-
- // XPathException
- // An Error object will be thrown, this is just a handler to instantiate that object
- var XPathException = new _XPathExceptionHandler();
- function _XPathExceptionHandler()
- {
- this.INVALID_EXPRESSION_ERR = 51;
- this.TYPE_ERR = 52;
- this.NOT_IMPLEMENTED_ERR = -1;
- this.RUNTIME_ERR = -2;
-
- this.ThrowNotImplemented = function(message)
- {
- ThrowError(this.NOT_IMPLEMENTED_ERR, "This functionality is not implemented.", message);
- }
-
- this.ThrowInvalidExpression = function(message)
- {
- ThrowError(this.INVALID_EXPRESSION_ERR, "Invalid expression", message);
- }
-
- this.ThrowType = function(message)
- {
- ThrowError(this.TYPE_ERR, "Type error", message);
- }
-
- this.Throw = function(message)
- {
- ThrowError(this.RUNTIME_ERR, "Run-time error", message);
- }
-
- function ThrowError(code, description, message)
- {
- var error = new Error(code, "DOM-L3-XPath " + document.DomL3XPathRelease + ": " + description + (message ? ", \"" + message + "\"": ""));
- error.code = code;
- error.name = "XPathException";
- throw error;
- }
- }
-
- // DOMException
- // An Error object will be thrown, this is just a handler to instantiate that object
- var DOMException = new _DOMExceptionHandler();
- function _DOMExceptionHandler()
- {
- this.ThrowInvalidState = function(message)
- {
- ThrowError(13, "The state of the object is no longer valid", message);
- }
-
- function ThrowError(code, description, message)
- {
- var error = new Error(code, "DOM : " + description + (message ? ", \"" + message + "\"": ""));
- error.code = code;
- error.name = "DOMException";
- throw error;
- }
- }
-
- // XPathEvaluator
- // implemented as document object methods
-
- // XPathExpression createExpression(String expression, XPathNSResolver resolver)
- document.createExpression = function
- (
- expression, // String
- resolver // XPathNSResolver
- )
- {
- // returns XPathExpression object
- return new XPathExpression(expression, resolver);
- }
-
- // XPathNSResolver createNSResolver(nodeResolver)
- document.createNSResolver = function
- (
- nodeResolver // Node
- )
- {
- // returns XPathNSResolver
- return new XPathNSResolver(nodeResolver);
- }
-
- // XPathResult evaluate(String expresison, Node contextNode, XPathNSResolver resolver, Number type, XPathResult result)
- document.evaluate = function
- (
- expression, // String
- contextNode, // Node
- resolver, // XPathNSResolver
- type, // Number
- result // XPathResult
- )
- // can raise XPathException, DOMException
- {
- // return XPathResult
- return document.createExpression(expression, resolver).evaluate(contextNode, type, result);
- }
-
- // XPathExpression
- function XPathExpression
- (
- expression, // String
- resolver // XPathNSResolver
- )
- {
- this.expressionString = expression;
- this.resolver = resolver;
-
- // XPathResult evaluate(Node contextNode, Number type, XPathResult result)
- this.evaluate = function
- (
- contextNode, // Node
- type, // Number
- result // XPathResult
- )
- // raises XPathException, DOMException
- {
- // return XPathResult
- return (result && result.constructor == XPathResult ? result.initialize(this, contextNode, resolver, type) : new XPathResult(this, contextNode, resolver, type));
- }
-
- this.toString = function()
- {
- return "[XPathExpression]";
- }
- }
-
- // XPathNSResolver
- function XPathNSResolver(node)
- {
- this.node = node;
-
- // String lookupNamespaceURI(String prefix)
- this.lookupNamespaceURI = function
- (
- prefix // String
- )
- {
- XPathException.ThrowNotImplemented();
- // return String
- return null;
- }
-
- this.toString = function()
- {
- return "[XPathNSResolver]";
- }
- }
-
- // XPathResult
- XPathResult.ANY_TYPE = 0;
- XPathResult.NUMBER_TYPE = 1;
- XPathResult.STRING_TYPE = 2;
- XPathResult.BOOLEAN_TYPE = 3;
- XPathResult.UNORDERED_NODE_ITERATOR_TYPE = 4;
- XPathResult.ORDERED_NODE_ITERATOR_TYPE = 5;
- XPathResult.UNORDERED_SNAPSHOT_TYPE = 6;
- XPathResult.ORDERED_SNAPSHOT_TYPE = 7;
- XPathResult.ANY_UNORDERED_NODE_TYPE = 8;
- XPathResult.FIRST_ORDERED_NODE_TYPE = 9;
-
- function XPathResult
- (
- expression, // XPathExpression
- contextNode, // Node
- resolver, // XPathNSResolver
- type // Number
- )
- {
- this.initialize = function(expression, contextNode, resolver, type)
- {
- this._domResult = null;
- this._expression = expression;
- this._contextNode = contextNode;
- this._resolver = resolver;
- if (type)
- {
- this.resultType = type;
- this._isIterator = (type == XPathResult.UNORDERED_NODE_ITERATOR_TYPE ||
- type == XPathResult.ORDERED_NODE_ITERATOR_TYPE ||
- type == XPathResult.ANY_TYPE);
- this._isSnapshot = (type == XPathResult.UNORDERED_SNAPSHOT_TYPE || type == XPathResult.ORDERED_SNAPSHOT_TYPE);
- this._isNodeSet = type > XPathResult.BOOLEAN_TYPE;
- }
- else
- {
- this.resultType = XPathResult.ANY_TYPE;
- this._isIterator = true;
- this._isSnapshot = false;
- this._isNodeSet = true;
- }
- return this;
- }
-
- this.initialize(expression, contextNode, resolver, type);
-
- this.getInvalidIteratorState = function()
- {
- return documentChangeDetected() || !this._isIterator;
- }
-
- this.getSnapshotLength = function()
- // raises XPathException
- {
- if (!this._isSnapshot)
- {
- XPathException.ThrowType("Snapshot is not an expected result type");
- }
- activateResult(this);
- // return Number
- return this._domResult.length;
- }
-
- // Node iterateNext()
- this.iterateNext = function()
- // raises XPathException, DOMException
- {
- if (!this._isIterator)
- {
- XPathException.ThrowType("Iterator is not an expected result type");
- }
- activateResult(this);
- if (documentChangeDetected())
- {
- DOMException.ThrowInvalidState("iterateNext");
- }
- // return Node
- return getNextNode(this);
- }
-
- // Node snapshotItem(Number index)
- this.snapshotItem = function(index)
- // raises XPathException
- {
- if (!this._isSnapshot)
- {
- XPathException.ThrowType("Snapshot is not an expected result type");
- }
- // return Node
- return getItemNode(this, index);
- }
-
- this.toString = function()
- {
- return "[XPathResult]";
- }
-
- // returns string value of the result, if result type is STRING_TYPE
- // otherwise throws an XPathException
- this.getStringValue = function()
- {
- if (this.resultType != XPathResult.STRING_TYPE)
- {
- XPathException.ThrowType("The expression can not be converted to return String");
- }
- return getNodeText(this);
- }
-
- // returns number value of the result, if the result is NUMBER_TYPE
- // otherwise throws an XPathException
- this.getNumberValue = function()
- {
- if (this.resultType != XPathResult.NUMBER_TYPE)
- {
- XPathException.ThrowType("The expression can not be converted to return Number");
- }
- var number = parseInt(getNodeText(this));
- if (isNaN(number))
- {
- XPathException.ThrowType("The result can not be converted to Number");
- }
- return number;
- }
-
- // returns boolean value of the result, if the result is BOOLEAN_TYPE
- // otherwise throws an XPathException
- this.getBooleanValue = function()
- {
- if (this.resultType != XPathResult.BOOLEAN_TYPE)
- {
- XPathException.ThrowType("The expression can not be converted to return Boolean");
- }
-
- var
- text = getNodeText(this);
- bool = (text ? text.toLowerCase() : null);
- if (bool == "false" || bool == "true")
- {
- return bool;
- }
- XPathException.ThrowType("The result can not be converted to Boolean");
- }
-
- // returns single node, if the result is ANY_UNORDERED_NODE_TYPE or FIRST_ORDERED_NODE_TYPE
- // otherwise throws an XPathException
- this.getSingleNodeValue = function()
- {
- if (this.resultType != XPathResult.ANY_UNORDERED_NODE_TYPE &&
- this.resultType != XPathResult.FIRST_ORDERED_NODE_TYPE)
- {
- XPathException.ThrowType("The expression can not be converted to return single Node value");
- }
- return getSingleNode(this);
- }
-
- function documentChangeDetected()
- {
- return document._XPathMsxmlDocumentHelper.documentChangeDetected();
- }
-
- function getNodeText(result)
- {
- activateResult(result);
- return result._textResult;
-// return ((node = getSingleNode(result)) ? (node.nodeType == 1 ? node.innerText : node.nodeValue) : null);
- }
-
- function findNode(result, current)
- {
- switch(current.nodeType)
- {
- case 1: // NODE_ELEMENT
- var id = current.attributes.getNamedItem("id");
- if (id)
- {
- return document.getElementById(id.value);
- }
- XPathException.Throw("unable to locate element in XML tree");
- case 2: // NODE_ATTRIBUTE
- var id = current.selectSingleNode("..").attributes.getNamedItem("id");
- if (id)
- {
- var node = document.getElementById(id.text);
- if (node)
- {
- return node.attributes.getNamedItem(current.nodeName);
- }
- }
- XPathException.Throw("unable to locate attribute in XML tree");
- case 3: // NODE_TEXT
- var id = current.selectSingleNode("..").attributes.getNamedItem("id");
- if (id)
- {
- var node = document.getElementById(id.value);
- if (node)
- {
- for(child in node.childNodes)
- {
- if (child.nodeType == 3 && child.nodeValue == current.nodeValue)
- {
- return child;
- }
- }
- }
- }
- XPathException.Throw("unable to locate text in XML tree");
- }
- XPathException.Throw("unknown node type");
- }
-
- function activateResult(result)
- {
- if (!result._domResult)
- {
- try
- {
- var expression = result._expression.expressionString;
-
- // adjust expression if contextNode is not a document
- if (result._contextNode != document && expression.indexOf("//") != 0)
- {
-
- expression = "//*[@id = '" + result._contextNode.id + "']" +
- (expression.indexOf("/") == 0 ? "" : "/") + expression;
- }
-
- if (result._isNodeSet)
- {
- result._domResult = document._XPathMsxmlDocumentHelper.getDom().selectNodes(expression);
- }
- else
- {
- result._domResult = true;
- result._textResult = document._XPathMsxmlDocumentHelper.getTextResult(expression);
- }
-
- }
- catch(error)
- {
- alert(error.description);
- XPathException.ThrowInvalidExpression(error.description);
- }
- }
- }
-
- function getSingleNode(result)
- {
- var node = getItemNode(result, 0);
- result._domResult = null;
- return node;
- }
-
- function getItemNode(result, index)
- {
- activateResult(result);
- var current = result._domResult.item(index);
- return (current ? findNode(result, current) : null);
- }
-
- function getNextNode(result)
- {
- var current = result._domResult.nextNode;
- if (current)
- {
- return findNode(result, current);
- }
- result._domResult = null;
- return null;
- }
- }
-
- document.reloadDom = function()
- {
- document._XPathMsxmlDocumentHelper.reset();
- }
-
- document._XPathMsxmlDocumentHelper = new _XPathMsxmlDocumentHelper();
- function _XPathMsxmlDocumentHelper()
- {
- this.getDom = function()
- {
- activateDom(this);
- return this.dom;
- }
-
- this.getXml = function()
- {
- activateDom(this);
- return this.dom.xml;
- }
-
- this.getTextResult = function(expression)
- {
- expression = expression.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, "\"");
- var xslText = "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">" +
- "<xsl:output method=\"text\"/><xsl:template match=\"*\"><xsl:value-of select=\"" + expression + "\"/>" +
- "</xsl:template></xsl:stylesheet>";
- var xsl = new ActiveXObject("Msxml2.DOMDocument");
- xsl.loadXML(xslText);
- try
- {
- var result = this.getDom().transformNode(xsl);
- }
- catch(error)
- {
- alert("Error: " + error.description);
- }
- return result;
- }
-
- this.reset = function()
- {
- this.dom = null;
- }
-
- function onPropertyChangeEventHandler()
- {
- document._propertyChangeDetected = true;
- }
-
- this.documentChangeDetected = function()
- {
- return (document.ignoreDocumentChanges ? false : this._currentElementCount != document.all.length || document._propertyChangeDetected);
- }
-
- function activateDom(helper)
- {
- if (!helper.dom)
- {
- var dom = new ActiveXObject("Msxml2.DOMDocument");
-/** SELENIUM:PATCH TO ALLOW PROVIDE FULL XPATH SUPPORT */
- dom.setProperty("SelectionLanguage", "XPath");
-/** END SELENIUM:PATCH */
- dom.async = false;
- dom.resolveExternals = false;
- loadDocument(dom, helper);
- helper.dom = dom;
- helper._currentElementCount = document.all.length;
- document._propertyChangeDetected = false;
- }
- else
- {
- if (helper.documentChangeDetected())
- {
- var dom = helper.dom;
- dom.load("");
- loadDocument(dom, helper);
- helper._currentElementCount = document.all.length;
- document._propertyChangeDetected = false;
- }
- }
- }
-
- function loadDocument(dom, helper)
- {
- return loadNode(dom, dom, document.body, helper);
- }
-
-
-/** SELENIUM:PATCH for loadNode() - see SEL-68 */
- function loadNode(dom, domParentNode, node, helper)
- {
- // Bad node scenarios
- // 1. If the node contains a /, it's broken HTML
- // 2. If the node doesn't have a name (typically from broken HTML), the node can't be loaded
- // 3. Node types we can't deal with
- //
- // In all scenarios, we just skip the node. We won't be able to
- // query on these nodes, but they're broken anyway.
- if (node.nodeName.indexOf("/") > -1
- || node.nodeName == ""
- || node.nodeName == "#document"
- || node.nodeName == "#document-fragment"
- || node.nodeName == "#cdata-section"
- || node.nodeName == "#xml-declaration"
- || node.nodeName == "#whitespace"
- || node.nodeName == "#significat-whitespace"
- )
- {
- return;
- }
-
- // #comment is a <!-- comment -->, which must be created with createComment()
- if (node.nodeName == "#comment")
- {
- try
- {
- domParentNode.appendChild(dom.createComment(node.nodeValue));
- }
- catch (ex)
- {
- // it's just a comment, we don't care
- }
- }
- else if (node.nodeType == 3)
- {
- domParentNode.appendChild(dom.createTextNode(node.nodeValue));
- }
- else
- {
- var domNode = dom.createElement(node.nodeName.toLowerCase());
- if (!node.id)
- {
- node.id = node.uniqueID;
- }
- domParentNode.appendChild(domNode);
- loadAttributes(dom, domNode, node);
- var length = node.childNodes.length;
- for(var i = 0; i < length; i ++ )
- {
- loadNode(dom, domNode, node.childNodes[i], helper);
- }
- node.attachEvent("onpropertychange", onPropertyChangeEventHandler);
- }
- }
-/** END SELENIUM:PATCH */
-
- function loadAttributes(dom, domParentNode, node)
- {
- for (var i = 0; i < node.attributes.length; i ++ )
- {
- var attribute = node.attributes[i];
- var attributeValue = attribute.nodeValue;
-
-/** SELENIUM:PATCH for loadAttributes() - see SEL-176 */
- if (attributeValue && (attribute.specified || attribute.nodeName == 'value'))
-/** END SELENIUM:PATCH */
- {
- var domAttribute = dom.createAttribute(attribute.nodeName);
- domAttribute.value = attributeValue;
- domParentNode.setAttributeNode(domAttribute);
- }
- }
- }
-
- }
-}
-else
-{
- document.reloadDom = function() {}
- XPathResult.prototype.getStringValue = function()
- {
- return this.stringValue;
- }
-
- XPathResult.prototype.getNumberValue = function()
- {
- return this.numberValue;
- }
-
- XPathResult.prototype.getBooleanValue = function()
- {
- return this.booleanValue;
- }
-
- XPathResult.prototype.getSingleNodeValue = function()
- {
- return this.singleNodeValue;
- }
-
- XPathResult.prototype.getInvalidIteratorState = function()
- {
- return this.invalidIteratorState;
- }
-
- XPathResult.prototype.getSnapshotLength = function()
- {
- return this.snapshotLength;
- }
-
- XPathResult.prototype.getResultType = function()
- {
- return this.resultType;
- }
-}
-/** SELENIUM:PATCH TO ALLOW USE WITH CONTAINED DOCUMENTS */
-}
-/** END SELENIUM:PATCH */
-
Modified: zc.selenium/trunk/src/zc/selenium/resources/scripts/htmlutils.js
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/scripts/htmlutils.js 2006-08-29 18:04:40 UTC (rev 69877)
+++ zc.selenium/trunk/src/zc/selenium/resources/scripts/htmlutils.js 2006-08-29 18:41:08 UTC (rev 69878)
@@ -14,9 +14,9 @@
* limitations under the License.
*
*/
-
+
// This script contains some HTML utility functions that
-// make it possible to handle elements in a way that is
+// make it possible to handle elements in a way that is
// compatible with both IE-like and Mozilla-like browsers
String.prototype.trim = function() {
@@ -35,13 +35,18 @@
// Returns the text in this element
function getText(element) {
- text = "";
+ var text = "";
- if(browserVersion.isFirefox)
+ if(browserVersion.isFirefox && browserVersion.firefoxVersion >= "1.5")
{
var dummyElement = element.cloneNode(true);
renderWhitespaceInTextContent(dummyElement);
text = dummyElement.textContent;
+ } else if (browserVersion.isOpera) {
+ var dummyElement = element.cloneNode(true);
+ renderWhitespaceInTextContent(dummyElement);
+ text = dummyElement.innerText;
+ text = xmlDecode(text);
}
else if(element.textContent)
{
@@ -62,10 +67,16 @@
// Remove non-visible newlines in text nodes
if (element.nodeType == Node.TEXT_NODE)
{
- element.data = element.data.replace(/\n|\r/g, " ");
+ element.data = element.data.replace(/\n|\r|\t/g, " ");
return;
}
+ if (element.nodeType == Node.COMMENT_NODE)
+ {
+ element.data = "";
+ return;
+ }
+
// Don't modify PRE elements
if (element.tagName == "PRE")
{
@@ -76,7 +87,7 @@
if (tagIs(element, ["BR", "HR"]))
{
// Replace this element with a newline text element
- element.parentNode.replaceChild(document.createTextNode("\n"), element)
+ element.parentNode.replaceChild(element.ownerDocument.createTextNode("\n"), element)
}
for (var i = 0; i < element.childNodes.length; i++)
@@ -92,8 +103,9 @@
// BLOCKQUOTE | FORM | HR | TABLE | FIELDSET | ADDRESS">
if (tagIs(element, ["P", "DIV"]))
{
- element.appendChild(document.createTextNode("\n"), element)
+ element.appendChild(element.ownerDocument.createTextNode("\n"), element)
}
+
}
function tagIs(element, tags)
@@ -138,6 +150,15 @@
return text.replace(re, " ");
}
+function xmlDecode(text) {
+ text = text.replace(/"/g, '"');
+ text = text.replace(/'/g, "'");
+ text = text.replace(/</g, "<");
+ text = text.replace(/>/g, ">");
+ text = text.replace(/&/g, "&");
+ return text;
+}
+
// Sets the text in this element
function setText(element, text) {
if(element.textContent) {
@@ -149,8 +170,8 @@
// Get the value of an <input> element
function getInputValue(inputElement) {
- if (inputElement.type.toUpperCase() == 'CHECKBOX' ||
- inputElement.type.toUpperCase() == 'RADIO')
+ if (inputElement.type.toUpperCase() == 'CHECKBOX' ||
+ inputElement.type.toUpperCase() == 'RADIO')
{
return (inputElement.checked ? 'on' : 'off');
}
@@ -173,28 +194,80 @@
function triggerKeyEvent(element, eventType, keycode, canBubble) {
canBubble = (typeof(canBubble) == undefined) ? true : canBubble;
if (element.fireEvent) {
- keyEvent = parent.frames['myiframe'].document.createEventObject();
+ var w = parent.frames['myiframe']
+ if (w==null) {
+ w = window;
+ }
+ keyEvent = w.document.createEventObject();
keyEvent.keyCode=keycode;
element.fireEvent('on' + eventType, keyEvent);
}
else {
- var evt = document.createEvent('KeyEvents');
- evt.initKeyEvent(eventType, true, true, window, false, false, false, false, keycode, keycode);
+ var evt;
+ if( window.KeyEvent ) {
+ evt = document.createEvent('KeyEvents');
+ evt.initKeyEvent(eventType, true, true, window, false, false, false, false, keycode, keycode);
+ } else {
+ evt = document.createEvent('UIEvents');
+ evt.initUIEvent( eventType, true, true, window, 1 );
+ evt.keyCode = keycode;
+ }
+
element.dispatchEvent(evt);
}
}
/* Fire a mouse event in a browser-compatible manner */
-function triggerMouseEvent(element, eventType, canBubble) {
+function triggerMouseEvent(element, eventType, canBubble, clientX, clientY) {
+ clientX = clientX ? clientX : 0;
+ clientY = clientY ? clientY : 0;
+
+ // TODO: set these attributes -- they don't seem to be needed by the initial test cases, but that could change...
+ var screenX = 0;
+ var screenY = 0;
+
canBubble = (typeof(canBubble) == undefined) ? true : canBubble;
if (element.fireEvent) {
- element.fireEvent('on' + eventType);
+ if (!screenX && !screenY && !clientX && !clientY) {
+ element.fireEvent('on' + eventType);
+ }
+ else {
+ var ieEvent = document.createEventObject();
+ ieEvent.detail = 0;
+ ieEvent.screenX = screenX;
+ ieEvent.screenY = screenY;
+ ieEvent.clientX = clientX;
+ ieEvent.clientY = clientY;
+ ieEvent.ctrlKey = false;
+ ieEvent.altKey = false;
+ ieEvent.shiftKey = false;
+ ieEvent.metaKey = false;
+ ieEvent.button = 0;
+ ieEvent.relatedTarget = null;
+
+ // when we go this route, window.event is never set to contain the event we have just created.
+ // ideally we could just slide it in as follows in the try-block below, but this normally
+ // doesn't work. This is why I try to avoid this code path, which is only required if we need to
+ // set attributes on the event (e.g., clientX).
+ try {
+ window.event = ieEvent;
+ }
+ catch(e) {
+ // getting an "Object does not support this action or property" error. Save the event away
+ // for future reference.
+ // TODO: is there a way to update window.event?
+
+ // work around for http://jira.openqa.org/browse/SEL-280 -- make the event available somewhere:
+ selenium.browserbot.getCurrentWindow().selenium_event = ieEvent;
+ }
+ element.fireEvent('on' + eventType, ieEvent);
+ }
}
else {
var evt = document.createEvent('MouseEvents');
if (evt.initMouseEvent)
{
- evt.initMouseEvent(eventType, canBubble, true, document.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null)
+ evt.initMouseEvent(eventType, canBubble, true, document.defaultView, 1, screenX, screenY, clientX, clientY, false, false, false, false, 0, null)
}
else
{
@@ -239,6 +312,14 @@
return 'anonymous';
}
+function getDocumentBase(doc) {
+ var bases = document.getElementsByTagName("base");
+ if (bases && bases.length && bases[0].href) {
+ return bases[0].href;
+ }
+ return "";
+}
+
function describe(object, delimiter) {
var props = new Array();
for (var prop in object) {
@@ -247,7 +328,7 @@
return props.join(delimiter || '\n');
}
-PatternMatcher = function(pattern) {
+var PatternMatcher = function(pattern) {
this.selectStrategy(pattern);
};
PatternMatcher.prototype = {
@@ -256,8 +337,12 @@
this.pattern = pattern;
var strategyName = 'glob'; // by default
if (/^([a-z-]+):(.*)/.test(pattern)) {
- strategyName = RegExp.$1;
- pattern = RegExp.$2;
+ var possibleNewStrategyName = RegExp.$1;
+ var possibleNewPattern = RegExp.$2;
+ if (PatternMatcher.strategies[possibleNewStrategyName]) {
+ strategyName = possibleNewStrategyName;
+ pattern = possibleNewPattern;
+ }
}
var matchStrategy = PatternMatcher.strategies[strategyName];
if (!matchStrategy) {
@@ -304,14 +389,14 @@
},
/**
- * "globContains" (aka "wildmat") patterns, e.g. "glob:one,two,*",
+ * "globContains" (aka "wildmat") patterns, e.g. "glob:one,two,*",
* but don't require a perfect match; instead succeed if actual
* contains something that matches globString.
- * Making this distinction is motivated by a bug in IE6 which
- * leads to the browser hanging if we implement *TextPresent tests
- * by just matching against a regular expression beginning and
- * ending with ".*". The globcontains strategy allows us to satisfy
- * the functional needs of the *TextPresent ops more efficiently
+ * Making this distinction is motivated by a bug in IE6 which
+ * leads to the browser hanging if we implement *TextPresent tests
+ * by just matching against a regular expression beginning and
+ * ending with ".*". The globcontains strategy allows us to satisfy
+ * the functional needs of the *TextPresent ops more efficiently
* and so avoid running into this IE6 freeze.
*/
globContains: function(globString) {
@@ -320,8 +405,8 @@
return this.regexp.test(actual);
};
},
-
+
/**
* "glob" (aka "wildmat") patterns, e.g. "glob:one,two,*"
*/
@@ -331,7 +416,7 @@
return this.regexp.test(actual);
};
}
-
+
};
PatternMatcher.convertGlobMetaCharsToRegexpMetaChars = function(glob) {
@@ -364,8 +449,8 @@
if (args.expected === args.actual) {
return;
}
- Assert.fail(args.comment +
- "Expected '" + args.expected +
+ Assert.fail(args.comment +
+ "Expected '" + args.expected +
"' but was '" + args.actual + "'");
},
@@ -377,11 +462,11 @@
if (PatternMatcher.matches(args.expected, args.actual)) {
return;
}
- Assert.fail(args.comment +
- "Actual value '" + args.actual +
+ Assert.fail(args.comment +
+ "Actual value '" + args.actual +
"' did not match '" + args.expected + "'");
},
-
+
/*
* Assert.notMtches(comment?, pattern, actual)
*/
@@ -390,8 +475,8 @@
if (!PatternMatcher.matches(args.expected, args.actual)) {
return;
}
- Assert.fail(args.comment +
- "Actual value '" + args.actual +
+ Assert.fail(args.comment +
+ "Actual value '" + args.actual +
"' did match '" + args.expected + "'");
}
@@ -424,3 +509,29 @@
error.isSeleniumError = true;
return error;
};
+
+
+var Effect = new Object();
+
+Object.extend(Effect, {
+ highlight : function(element) {
+ var highLightColor = "yellow";
+ var originalColor = Element.getStyle(element, "background-color");
+ Element.setStyle(element, {"background-color" : highLightColor});
+ window.setTimeout(function() {
+ Element.setStyle(element, {"background-color" : originalColor});
+ }, 300);
+ }
+});
+
+
+// for use from vs.2003 debugger
+function objToString(obj) {
+ var s = "";
+ for (key in obj) {
+ var line = key + "->" + obj[key];
+ line.replace("\n", " ");
+ s += line + "\n";
+ }
+ return s;
+}
Added: zc.selenium/trunk/src/zc/selenium/resources/scripts/injection.html
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/scripts/injection.html 2006-08-29 18:04:40 UTC (rev 69877)
+++ zc.selenium/trunk/src/zc/selenium/resources/scripts/injection.html 2006-08-29 18:41:08 UTC (rev 69878)
@@ -0,0 +1,72 @@
+<script language="JavaScript">
+ if (window["selenium_has_been_loaded_into_this_window"]==null)
+ {
+__SELENIUM_JS__
+
+// Some background on the code below: broadly speaking, where we are relative to other windows
+// when running in proxy injection mode depends on whether we are in a frame set file or not.
+//
+// In regular HTML files, the selenium JavaScript is injected into an iframe called "selenium"
+// in order to reduce its impact on the JavaScript environment (through namespace pollution,
+// etc.). So in regular HTML files, we need to look at the parent of the current window when we want
+// a handle to, e.g., the application window.
+//
+// In frame set files, we can't use an iframe, so we put the JavaScript in the head element and share
+// the window with the frame set. So in this case, we need to look at the current window, not the
+// parent when looking for, e.g., the application window. (TODO: Perhaps I should have just
+// assigned a regular frame for selenium?)
+//
+BrowserBot.prototype.getContentWindow = function() {
+ if (window["seleniumInSameWindow"] != null) return window;
+ return window.parent;
+};
+
+BrowserBot.prototype.getTargetWindow = function(windowName) {
+ if (window["seleniumInSameWindow"] != null) return window;
+ return window.parent;
+};
+
+BrowserBot.prototype.getCurrentWindow = function() {
+ if (window["seleniumInSameWindow"] != null) return window;
+ return window.parent;
+};
+
+LOG.openLogWindow = function(message, className) {
+ // disable for now
+};
+
+BrowserBot.prototype.relayToRC = function(name) {
+ var object = eval(name);
+ var s = 'state:' + serializeObject(name, object) + "\n";
+ sendToRC(s);
+}
+
+BrowserBot.prototype.relayBotToRC = function(s) {
+ this.relayToRC("selenium." + s);
+}
+
+function selenium_frameRunTest(oldOnLoadRoutine) {
+ if (oldOnLoadRoutine) {
+ eval(oldOnLoadRoutine);
+ }
+ runSeleniumTest();
+}
+
+function seleniumOnLoad() {
+ injectedSessionId = @SESSION_ID@;
+ window["selenium_has_been_loaded_into_this_window"] = true;
+ runSeleniumTest();
+}
+
+if (window.addEventListener) {
+ window.addEventListener("load", seleniumOnLoad, false); // firefox
+} else if (window.attachEvent){
+ window.attachEvent("onload", seleniumOnLoad); // IE
+}
+else {
+ throw "causing a JavaScript error to tell the world that I did not arrange to be run on load";
+}
+
+injectedSessionId = @SESSION_ID@;
+}
+</script>
Added: zc.selenium/trunk/src/zc/selenium/resources/scripts/injection_iframe.html
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/scripts/injection_iframe.html 2006-08-29 18:04:40 UTC (rev 69877)
+++ zc.selenium/trunk/src/zc/selenium/resources/scripts/injection_iframe.html 2006-08-29 18:41:08 UTC (rev 69878)
@@ -0,0 +1,7 @@
+<script language="JavaScript">
+ // Ideally I would avoid polluting the namespace by enclosing this snippet with
+ // curly braces, but I want to make it easy to look at what URL I used for anyone
+ // who is interested in looking into http://jira.openqa.org/browse/SRC-101:
+ var _sel_url_ = "http://" + location.host + "/selenium-server/core/scripts/injection.html";
+ document.write('<iframe name="selenium" width=0 height=0 id="selenium" src="' + _sel_url_ + '"></iframe>');
+</script>
Added: zc.selenium/trunk/src/zc/selenium/resources/scripts/js2html.js
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/scripts/js2html.js 2006-08-29 18:04:40 UTC (rev 69877)
+++ zc.selenium/trunk/src/zc/selenium/resources/scripts/js2html.js 2006-08-29 18:41:08 UTC (rev 69878)
@@ -0,0 +1,70 @@
+/*
+
+This is an experiment in using the Narcissus JavaScript engine
+to allow Selenium scripts to be written in plain JavaScript.
+
+The 'jsparse' function will compile each high level block into a Selenium table script.
+
+
+TODO:
+1) Test! (More browsers, more sample scripts)
+2) Stepping and walking lower levels of the parse tree
+3) Calling Selenium commands directly from JavaScript
+4) Do we want comments to appear in the TestRunner?
+5) Fix context so variables don't have to be global
+ For now, variables defined with "var" won't be found
+ if used later on in a script.
+6) Fix formatting
+*/
+
+
+function jsparse() {
+ var script = document.getElementById('sejs')
+ var fname = 'javascript script';
+ parse_result = parse(script.text, fname, 0);
+
+ var x2 = new ExecutionContext(GLOBAL_CODE);
+ ExecutionContext.current = x2;
+
+
+ var new_test_source = '';
+ var new_line = '';
+
+ for (i=0;i<parse_result.$length;i++){
+ var the_start = parse_result[i].start;
+ var the_end;
+ if ( i == (parse_result.$length-1)) {
+ the_end = parse_result.tokenizer.source.length;
+ } else {
+ the_end = parse_result[i+1].start;
+ }
+
+ var script_fragment = parse_result.tokenizer.source.slice(the_start,the_end)
+
+ new_line = '<tr><td style="display:none;" class="js">getEval</td>' +
+ '<td style="display:none;">currentTest.doNextCommand()</td>' +
+ '<td style="white-space: pre;">' + script_fragment + '</td>' +
+ '<td></td></tr>\n';
+ new_test_source += new_line;
+ //eval(script_fragment);
+
+
+ };
+
+
+
+ execute(parse_result,x2)
+
+ // Create HTML Table
+ body = document.body
+ body.innerHTML += "<table class='selenium' id='se-js-table'>"+
+ "<tbody>" +
+ "<tr><td>// " + document.title + "</td></tr>" +
+ new_test_source +
+ "</tbody" +
+ "</table>";
+
+ //body.innerHTML = "<pre>" + parse_result + "</pre>"
+}
+
+
Added: zc.selenium/trunk/src/zc/selenium/resources/scripts/narcissus-defs.js
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/scripts/narcissus-defs.js 2006-08-29 18:04:40 UTC (rev 69877)
+++ zc.selenium/trunk/src/zc/selenium/resources/scripts/narcissus-defs.js 2006-08-29 18:41:08 UTC (rev 69878)
@@ -0,0 +1,175 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is the Narcissus JavaScript engine.
+ *
+ * The Initial Developer of the Original Code is
+ * Brendan Eich <brendan at mozilla.org>.
+ * Portions created by the Initial Developer are Copyright (C) 2004
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+/*
+ * Narcissus - JS implemented in JS.
+ *
+ * Well-known constants and lookup tables. Many consts are generated from the
+ * tokens table via eval to minimize redundancy, so consumers must be compiled
+ * separately to take advantage of the simple switch-case constant propagation
+ * done by SpiderMonkey.
+ */
+
+// jrh
+//module('JS.Defs');
+
+GLOBAL = this;
+
+var tokens = [
+ // End of source.
+ "END",
+
+ // Operators and punctuators. Some pair-wise order matters, e.g. (+, -)
+ // and (UNARY_PLUS, UNARY_MINUS).
+ "\n", ";",
+ ",",
+ "=",
+ "?", ":", "CONDITIONAL",
+ "||",
+ "&&",
+ "|",
+ "^",
+ "&",
+ "==", "!=", "===", "!==",
+ "<", "<=", ">=", ">",
+ "<<", ">>", ">>>",
+ "+", "-",
+ "*", "/", "%",
+ "!", "~", "UNARY_PLUS", "UNARY_MINUS",
+ "++", "--",
+ ".",
+ "[", "]",
+ "{", "}",
+ "(", ")",
+
+ // Nonterminal tree node type codes.
+ "SCRIPT", "BLOCK", "LABEL", "FOR_IN", "CALL", "NEW_WITH_ARGS", "INDEX",
+ "ARRAY_INIT", "OBJECT_INIT", "PROPERTY_INIT", "GETTER", "SETTER",
+ "GROUP", "LIST",
+
+ // Terminals.
+ "IDENTIFIER", "NUMBER", "STRING", "REGEXP",
+
+ // Keywords.
+ "break",
+ "case", "catch", "const", "continue",
+ "debugger", "default", "delete", "do",
+ "else", "enum",
+ "false", "finally", "for", "function",
+ "if", "in", "instanceof",
+ "new", "null",
+ "return",
+ "switch",
+ "this", "throw", "true", "try", "typeof",
+ "var", "void",
+ "while", "with",
+ // Extensions
+ "require", "bless", "mixin", "import"
+];
+
+// Operator and punctuator mapping from token to tree node type name.
+// NB: superstring tokens (e.g., ++) must come before their substring token
+// counterparts (+ in the example), so that the opRegExp regular expression
+// synthesized from this list makes the longest possible match.
+var opTypeNames = {
+ '\n': "NEWLINE",
+ ';': "SEMICOLON",
+ ',': "COMMA",
+ '?': "HOOK",
+ ':': "COLON",
+ '||': "OR",
+ '&&': "AND",
+ '|': "BITWISE_OR",
+ '^': "BITWISE_XOR",
+ '&': "BITWISE_AND",
+ '===': "STRICT_EQ",
+ '==': "EQ",
+ '=': "ASSIGN",
+ '!==': "STRICT_NE",
+ '!=': "NE",
+ '<<': "LSH",
+ '<=': "LE",
+ '<': "LT",
+ '>>>': "URSH",
+ '>>': "RSH",
+ '>=': "GE",
+ '>': "GT",
+ '++': "INCREMENT",
+ '--': "DECREMENT",
+ '+': "PLUS",
+ '-': "MINUS",
+ '*': "MUL",
+ '/': "DIV",
+ '%': "MOD",
+ '!': "NOT",
+ '~': "BITWISE_NOT",
+ '.': "DOT",
+ '[': "LEFT_BRACKET",
+ ']': "RIGHT_BRACKET",
+ '{': "LEFT_CURLY",
+ '}': "RIGHT_CURLY",
+ '(': "LEFT_PAREN",
+ ')': "RIGHT_PAREN"
+};
+
+// Hash of keyword identifier to tokens index. NB: we must null __proto__ to
+// avoid toString, etc. namespace pollution.
+var keywords = {__proto__: null};
+
+// Define const END, etc., based on the token names. Also map name to index.
+var consts = " ";
+for (var i = 0, j = tokens.length; i < j; i++) {
+ if (i > 0)
+ consts += "; ";
+ var t = tokens[i];
+ if (/^[a-z]/.test(t)) {
+ consts += t.toUpperCase();
+ keywords[t] = i;
+ } else {
+ consts += (/^\W/.test(t) ? opTypeNames[t] : t);
+ }
+ consts += " = " + i;
+ tokens[t] = i;
+}
+eval(consts + ";");
+
+// Map assignment operators to their indexes in the tokens array.
+var assignOps = ['|', '^', '&', '<<', '>>', '>>>', '+', '-', '*', '/', '%'];
+
+for (i = 0, j = assignOps.length; i < j; i++) {
+ t = assignOps[i];
+ assignOps[t] = tokens[t];
+}
Added: zc.selenium/trunk/src/zc/selenium/resources/scripts/narcissus-exec.js
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/scripts/narcissus-exec.js 2006-08-29 18:04:40 UTC (rev 69877)
+++ zc.selenium/trunk/src/zc/selenium/resources/scripts/narcissus-exec.js 2006-08-29 18:41:08 UTC (rev 69878)
@@ -0,0 +1,1054 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * vim: set ts=4 sw=4 et tw=80:
+ *
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is the Narcissus JavaScript engine.
+ *
+ * The Initial Developer of the Original Code is
+ * Brendan Eich <brendan at mozilla.org>.
+ * Portions created by the Initial Developer are Copyright (C) 2004
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+/*
+ * Narcissus - JS implemented in JS.
+ *
+ * Execution of parse trees.
+ *
+ * Standard classes except for eval, Function, Array, and String are borrowed
+ * from the host JS environment. Function is metacircular. Array and String
+ * are reflected via wrapping the corresponding native constructor and adding
+ * an extra level of prototype-based delegation.
+ */
+
+// jrh
+//module('JS.Exec');
+// end jrh
+
+GLOBAL_CODE = 0; EVAL_CODE = 1; FUNCTION_CODE = 2;
+
+function ExecutionContext(type) {
+ this.type = type;
+}
+
+// jrh
+var agenda = new Array();
+var skip_setup = 0;
+// end jrh
+
+var global = {
+ // Value properties.
+ NaN: NaN, Infinity: Infinity, undefined: undefined,
+ alert : function(msg) { alert(msg) },
+ confirm : function(msg) { return confirm(msg) },
+ document : document,
+ window : window,
+ // jrh
+ //debug: window.open('','debugwindow','width=600,height=400,scrollbars=yes,resizable=yes'),
+ // end jrh
+ navigator : navigator,
+ XMLHttpRequest : function() { return new XMLHttpRequest() },
+ // Function properties.
+ eval: function(s) {
+ if (typeof s != "string") {
+ return s;
+ }
+
+ var x = ExecutionContext.current;
+ var x2 = new ExecutionContext(EVAL_CODE);
+ x2.thisObject = x.thisObject;
+ x2.caller = x.caller;
+ x2.callee = x.callee;
+ x2.scope = x.scope;
+ ExecutionContext.current = x2;
+ try {
+ execute(parse(s), x2);
+ } catch (e) {
+ x.result = x2.result;
+ throw e;
+ } finally {
+ ExecutionContext.current = x;
+ }
+ return x2.result;
+ },
+ parseInt: parseInt, parseFloat: parseFloat,
+ isNaN: isNaN, isFinite: isFinite,
+ decodeURI: decodeURI, encodeURI: encodeURI,
+ decodeURIComponent: decodeURIComponent,
+ encodeURIComponent: encodeURIComponent,
+
+ // Class constructors. Where ECMA-262 requires C.length == 1, we declare
+ // a dummy formal parameter.
+ Object: Object,
+ Function: function(dummy) {
+ var p = "", b = "", n = arguments.length;
+ if (n) {
+ var m = n - 1;
+ if (m) {
+ p += arguments[0];
+ for (var k = 1; k < m; k++)
+ p += "," + arguments[k];
+ }
+ b += arguments[m];
+ }
+
+ // XXX We want to pass a good file and line to the tokenizer.
+ // Note the anonymous name to maintain parity with Spidermonkey.
+ var t = new Tokenizer("anonymous(" + p + ") {" + b + "}");
+
+ // NB: Use the STATEMENT_FORM constant since we don't want to push this
+ // function onto the null compilation context.
+ var f = FunctionDefinition(t, null, false, STATEMENT_FORM);
+ var s = {object: global, parent: null};
+ return new FunctionObject(f, s);
+ },
+ Array: function(dummy) {
+ // Array when called as a function acts as a constructor.
+ return GLOBAL.Array.apply(this, arguments);
+ },
+ String: function(s) {
+ // Called as function or constructor: convert argument to string type.
+ s = arguments.length ? "" + s : "";
+ if (this instanceof String) {
+ // Called as constructor: save the argument as the string value
+ // of this String object and return this object.
+ this.value = s;
+ return this;
+ }
+ return s;
+ },
+ Boolean: Boolean, Number: Number, Date: Date, RegExp: RegExp,
+ Error: Error, EvalError: EvalError, RangeError: RangeError,
+ ReferenceError: ReferenceError, SyntaxError: SyntaxError,
+ TypeError: TypeError, URIError: URIError,
+
+ // Other properties.
+ Math: Math,
+
+ // Extensions to ECMA.
+ //snarf: snarf,
+ evaluate: evaluate,
+ load: function(s) {
+ if (typeof s != "string")
+ return s;
+ var req = new XMLHttpRequest();
+ req.open('GET', s, false);
+ req.send(null);
+
+ evaluate(req.responseText, s, 1)
+ },
+ print: print, version: null
+};
+
+// jrh
+//global.debug.document.body.innerHTML = ''
+// end jrh
+
+// Helper to avoid Object.prototype.hasOwnProperty polluting scope objects.
+function hasDirectProperty(o, p) {
+ return Object.prototype.hasOwnProperty.call(o, p);
+}
+
+// Reflect a host class into the target global environment by delegation.
+function reflectClass(name, proto) {
+ var gctor = global[name];
+ gctor.prototype = proto;
+ proto.constructor = gctor;
+ return proto;
+}
+
+// Reflect Array -- note that all Array methods are generic.
+reflectClass('Array', new Array);
+
+// Reflect String, overriding non-generic methods.
+var gSp = reflectClass('String', new String);
+gSp.toSource = function () { return this.value.toSource(); };
+gSp.toString = function () { return this.value; };
+gSp.valueOf = function () { return this.value; };
+global.String.fromCharCode = String.fromCharCode;
+
+var XCp = ExecutionContext.prototype;
+ExecutionContext.current = XCp.caller = XCp.callee = null;
+XCp.scope = {object: global, parent: null};
+XCp.thisObject = global;
+XCp.result = undefined;
+XCp.target = null;
+XCp.ecmaStrictMode = false;
+
+function Reference(base, propertyName, node) {
+ this.base = base;
+ this.propertyName = propertyName;
+ this.node = node;
+}
+
+Reference.prototype.toString = function () { return this.node.getSource(); }
+
+function getValue(v) {
+ if (v instanceof Reference) {
+ if (!v.base) {
+ throw new ReferenceError(v.propertyName + " is not defined",
+ v.node.filename(), v.node.lineno);
+ }
+ return v.base[v.propertyName];
+ }
+ return v;
+}
+
+function putValue(v, w, vn) {
+ if (v instanceof Reference)
+ return (v.base || global)[v.propertyName] = w;
+ throw new ReferenceError("Invalid assignment left-hand side",
+ vn.filename(), vn.lineno);
+}
+
+function isPrimitive(v) {
+ var t = typeof v;
+ return (t == "object") ? v === null : t != "function";
+}
+
+function isObject(v) {
+ var t = typeof v;
+ return (t == "object") ? v !== null : t == "function";
+}
+
+// If r instanceof Reference, v == getValue(r); else v === r. If passed, rn
+// is the node whose execute result was r.
+function toObject(v, r, rn) {
+ switch (typeof v) {
+ case "boolean":
+ return new global.Boolean(v);
+ case "number":
+ return new global.Number(v);
+ case "string":
+ return new global.String(v);
+ case "function":
+ return v;
+ case "object":
+ if (v !== null)
+ return v;
+ }
+ var message = r + " (type " + (typeof v) + ") has no properties";
+ throw rn ? new TypeError(message, rn.filename(), rn.lineno)
+ : new TypeError(message);
+}
+
+function execute(n, x) {
+ if (!this.new_block)
+ new_block = new Array();
+ //alert (n)
+ var a, f, i, j, r, s, t, u, v;
+ switch (n.type) {
+ case FUNCTION:
+ if (n.functionForm != DECLARED_FORM) {
+ if (!n.name || n.functionForm == STATEMENT_FORM) {
+ v = new FunctionObject(n, x.scope);
+ if (n.functionForm == STATEMENT_FORM)
+ x.scope.object[n.name] = v;
+ } else {
+ t = new Object;
+ x.scope = {object: t, parent: x.scope};
+ try {
+ v = new FunctionObject(n, x.scope);
+ t[n.name] = v;
+ } finally {
+ x.scope = x.scope.parent;
+ }
+ }
+ }
+ break;
+
+ case SCRIPT:
+ t = x.scope.object;
+ a = n.funDecls;
+ for (i = 0, j = a.length; i < j; i++) {
+ s = a[i].name;
+ f = new FunctionObject(a[i], x.scope);
+ t[s] = f;
+ }
+ a = n.varDecls;
+ for (i = 0, j = a.length; i < j; i++) {
+ u = a[i];
+ s = u.name;
+ if (u.readOnly && hasDirectProperty(t, s)) {
+ throw new TypeError("Redeclaration of const " + s,
+ u.filename(), u.lineno);
+ }
+ if (u.readOnly || !hasDirectProperty(t, s)) {
+ t[s] = null;
+ }
+ }
+ // FALL THROUGH
+
+ case BLOCK:
+ for (i = 0, j = n.$length; i < j; i++) {
+ //jrh
+ //execute(n[i], x);
+ //new_block.unshift([n[i], x]);
+ new_block.push([n[i], x]);
+ }
+ new_block.reverse();
+ agenda = agenda.concat(new_block);
+ //agenda = new_block.concat(agenda)
+ // end jrh
+ break;
+
+ case IF:
+ if (getValue(execute(n.condition, x)))
+ execute(n.thenPart, x);
+ else if (n.elsePart)
+ execute(n.elsePart, x);
+ break;
+
+ case SWITCH:
+ s = getValue(execute(n.discriminant, x));
+ a = n.cases;
+ var matchDefault = false;
+ switch_loop:
+ for (i = 0, j = a.length; ; i++) {
+ if (i == j) {
+ if (n.defaultIndex >= 0) {
+ i = n.defaultIndex - 1; // no case matched, do default
+ matchDefault = true;
+ continue;
+ }
+ break; // no default, exit switch_loop
+ }
+ t = a[i]; // next case (might be default!)
+ if (t.type == CASE) {
+ u = getValue(execute(t.caseLabel, x));
+ } else {
+ if (!matchDefault) // not defaulting, skip for now
+ continue;
+ u = s; // force match to do default
+ }
+ if (u === s) {
+ for (;;) { // this loop exits switch_loop
+ if (t.statements.length) {
+ try {
+ execute(t.statements, x);
+ } catch (e) {
+ if (!(e == BREAK && x.target == n)) { throw e }
+ break switch_loop;
+ }
+ }
+ if (++i == j)
+ break switch_loop;
+ t = a[i];
+ }
+ // NOT REACHED
+ }
+ }
+ break;
+
+ case FOR:
+ // jrh
+ // added "skip_setup" so initialization doesn't get called
+ // on every call..
+ if (!skip_setup)
+ n.setup && getValue(execute(n.setup, x));
+ // FALL THROUGH
+ case WHILE:
+ // jrh
+ //while (!n.condition || getValue(execute(n.condition, x))) {
+ if (!n.condition || getValue(execute(n.condition, x))) {
+ try {
+ // jrh
+ //execute(n.body, x);
+ new_block.push([n.body, x]);
+ agenda.push([n.body, x])
+ //agenda.unshift([n.body, x])
+ // end jrh
+ } catch (e) {
+ if (e == BREAK && x.target == n) {
+ break;
+ } else if (e == CONTINUE && x.target == n) {
+ // jrh
+ // 'continue' is invalid inside an 'if' clause
+ // I don't know what commenting this out will break!
+ //continue;
+ // end jrh
+
+ } else {
+ throw e;
+ }
+ }
+ n.update && getValue(execute(n.update, x));
+ // jrh
+ new_block.unshift([n, x])
+ agenda.splice(agenda.length-1,0,[n, x])
+ //agenda.splice(1,0,[n, x])
+ skip_setup = 1
+ // end jrh
+ } else {
+ skip_setup = 0
+ }
+
+ break;
+
+ case FOR_IN:
+ u = n.varDecl;
+ if (u)
+ execute(u, x);
+ r = n.iterator;
+ s = execute(n.object, x);
+ v = getValue(s);
+
+ // ECMA deviation to track extant browser JS implementation behavior.
+ t = (v == null && !x.ecmaStrictMode) ? v : toObject(v, s, n.object);
+ a = [];
+ for (i in t)
+ a.push(i);
+ for (i = 0, j = a.length; i < j; i++) {
+ putValue(execute(r, x), a[i], r);
+ try {
+ execute(n.body, x);
+ } catch (e) {
+ if (e == BREAK && x.target == n) {
+ break;
+ } else if (e == CONTINUE && x.target == n) {
+ continue;
+ } else {
+ throw e;
+ }
+ }
+ }
+ break;
+
+ case DO:
+ do {
+ try {
+ execute(n.body, x);
+ } catch (e) {
+ if (e == BREAK && x.target == n) {
+ break;
+ } else if (e == CONTINUE && x.target == n) {
+ continue;
+ } else {
+ throw e;
+ }
+ }
+ } while (getValue(execute(n.condition, x)));
+ break;
+
+ case BREAK:
+ case CONTINUE:
+ x.target = n.target;
+ throw n.type;
+
+ case TRY:
+ try {
+ execute(n.tryBlock, x);
+ } catch (e) {
+ if (!(e == THROW && (j = n.catchClauses.length))) {
+ throw e;
+ }
+ e = x.result;
+ x.result = undefined;
+ for (i = 0; ; i++) {
+ if (i == j) {
+ x.result = e;
+ throw THROW;
+ }
+ t = n.catchClauses[i];
+ x.scope = {object: {}, parent: x.scope};
+ x.scope.object[t.varName] = e;
+ try {
+ if (t.guard && !getValue(execute(t.guard, x)))
+ continue;
+ execute(t.block, x);
+ break;
+ } finally {
+ x.scope = x.scope.parent;
+ }
+ }
+ } finally {
+ if (n.finallyBlock)
+ execute(n.finallyBlock, x);
+ }
+ break;
+
+ case THROW:
+ x.result = getValue(execute(n.exception, x));
+ throw THROW;
+
+ case RETURN:
+ x.result = getValue(execute(n.value, x));
+ throw RETURN;
+
+ case WITH:
+ r = execute(n.object, x);
+ t = toObject(getValue(r), r, n.object);
+ x.scope = {object: t, parent: x.scope};
+ try {
+ execute(n.body, x);
+ } finally {
+ x.scope = x.scope.parent;
+ }
+ break;
+
+ case VAR:
+ case CONST:
+ for (i = 0, j = n.$length; i < j; i++) {
+ u = n[i].initializer;
+ if (!u)
+ continue;
+ t = n[i].name;
+ for (s = x.scope; s; s = s.parent) {
+ if (hasDirectProperty(s.object, t))
+ break;
+ }
+ u = getValue(execute(u, x));
+ if (n.type == CONST)
+ s.object[t] = u;
+ else
+ s.object[t] = u;
+ }
+ break;
+
+ case DEBUGGER:
+ throw "NYI: " + tokens[n.type];
+
+ case REQUIRE:
+ var req = new XMLHttpRequest();
+ req.open('GET', n.filename, 'false');
+
+ case SEMICOLON:
+ if (n.expression)
+ // print debugging statements
+
+ var the_start = n.start
+ var the_end = n.end
+ var the_statement = parse_result.tokenizer.source.slice(the_start,the_end)
+ //global.debug.document.body.innerHTML += ('<pre>>>> <b>' + the_statement + '</b></pre>')
+ LOG.info('>>>' + the_statement)
+ x.result = getValue(execute(n.expression, x));
+ //if (x.result)
+ //global.debug.document.body.innerHTML += ( '<pre>>>> ' + x.result + '</pre>')
+
+ break;
+
+ case LABEL:
+ try {
+ execute(n.statement, x);
+ } catch (e) {
+ if (!(e == BREAK && x.target == n)) { throw e }
+ }
+ break;
+
+ case COMMA:
+ for (i = 0, j = n.$length; i < j; i++)
+ v = getValue(execute(n[i], x));
+ break;
+
+ case ASSIGN:
+ r = execute(n[0], x);
+ t = n[0].assignOp;
+ if (t)
+ u = getValue(r);
+ v = getValue(execute(n[1], x));
+ if (t) {
+ switch (t) {
+ case BITWISE_OR: v = u | v; break;
+ case BITWISE_XOR: v = u ^ v; break;
+ case BITWISE_AND: v = u & v; break;
+ case LSH: v = u << v; break;
+ case RSH: v = u >> v; break;
+ case URSH: v = u >>> v; break;
+ case PLUS: v = u + v; break;
+ case MINUS: v = u - v; break;
+ case MUL: v = u * v; break;
+ case DIV: v = u / v; break;
+ case MOD: v = u % v; break;
+ }
+ }
+ putValue(r, v, n[0]);
+ break;
+
+ case CONDITIONAL:
+ v = getValue(execute(n[0], x)) ? getValue(execute(n[1], x))
+ : getValue(execute(n[2], x));
+ break;
+
+ case OR:
+ v = getValue(execute(n[0], x)) || getValue(execute(n[1], x));
+ break;
+
+ case AND:
+ v = getValue(execute(n[0], x)) && getValue(execute(n[1], x));
+ break;
+
+ case BITWISE_OR:
+ v = getValue(execute(n[0], x)) | getValue(execute(n[1], x));
+ break;
+
+ case BITWISE_XOR:
+ v = getValue(execute(n[0], x)) ^ getValue(execute(n[1], x));
+ break;
+
+ case BITWISE_AND:
+ v = getValue(execute(n[0], x)) & getValue(execute(n[1], x));
+ break;
+
+ case EQ:
+ v = getValue(execute(n[0], x)) == getValue(execute(n[1], x));
+ break;
+
+ case NE:
+ v = getValue(execute(n[0], x)) != getValue(execute(n[1], x));
+ break;
+
+ case STRICT_EQ:
+ v = getValue(execute(n[0], x)) === getValue(execute(n[1], x));
+ break;
+
+ case STRICT_NE:
+ v = getValue(execute(n[0], x)) !== getValue(execute(n[1], x));
+ break;
+
+ case LT:
+ v = getValue(execute(n[0], x)) < getValue(execute(n[1], x));
+ break;
+
+ case LE:
+ v = getValue(execute(n[0], x)) <= getValue(execute(n[1], x));
+ break;
+
+ case GE:
+ v = getValue(execute(n[0], x)) >= getValue(execute(n[1], x));
+ break;
+
+ case GT:
+ v = getValue(execute(n[0], x)) > getValue(execute(n[1], x));
+ break;
+
+ case IN:
+ v = getValue(execute(n[0], x)) in getValue(execute(n[1], x));
+ break;
+
+ case INSTANCEOF:
+ t = getValue(execute(n[0], x));
+ u = getValue(execute(n[1], x));
+ if (isObject(u) && typeof u.__hasInstance__ == "function")
+ v = u.__hasInstance__(t);
+ else
+ v = t instanceof u;
+ break;
+
+ case LSH:
+ v = getValue(execute(n[0], x)) << getValue(execute(n[1], x));
+ break;
+
+ case RSH:
+ v = getValue(execute(n[0], x)) >> getValue(execute(n[1], x));
+ break;
+
+ case URSH:
+ v = getValue(execute(n[0], x)) >>> getValue(execute(n[1], x));
+ break;
+
+ case PLUS:
+ v = getValue(execute(n[0], x)) + getValue(execute(n[1], x));
+ break;
+
+ case MINUS:
+ v = getValue(execute(n[0], x)) - getValue(execute(n[1], x));
+ break;
+
+ case MUL:
+ v = getValue(execute(n[0], x)) * getValue(execute(n[1], x));
+ break;
+
+ case DIV:
+ v = getValue(execute(n[0], x)) / getValue(execute(n[1], x));
+ break;
+
+ case MOD:
+ v = getValue(execute(n[0], x)) % getValue(execute(n[1], x));
+ break;
+
+ case DELETE:
+ t = execute(n[0], x);
+ v = !(t instanceof Reference) || delete t.base[t.propertyName];
+ break;
+
+ case VOID:
+ getValue(execute(n[0], x));
+ break;
+
+ case TYPEOF:
+ t = execute(n[0], x);
+ if (t instanceof Reference)
+ t = t.base ? t.base[t.propertyName] : undefined;
+ v = typeof t;
+ break;
+
+ case NOT:
+ v = !getValue(execute(n[0], x));
+ break;
+
+ case BITWISE_NOT:
+ v = ~getValue(execute(n[0], x));
+ break;
+
+ case UNARY_PLUS:
+ v = +getValue(execute(n[0], x));
+ break;
+
+ case UNARY_MINUS:
+ v = -getValue(execute(n[0], x));
+ break;
+
+ case INCREMENT:
+ case DECREMENT:
+ t = execute(n[0], x);
+ u = Number(getValue(t));
+ if (n.postfix)
+ v = u;
+ putValue(t, (n.type == INCREMENT) ? ++u : --u, n[0]);
+ if (!n.postfix)
+ v = u;
+ break;
+
+ case DOT:
+ r = execute(n[0], x);
+ t = getValue(r);
+ u = n[1].value;
+ v = new Reference(toObject(t, r, n[0]), u, n);
+ break;
+
+ case INDEX:
+ r = execute(n[0], x);
+ t = getValue(r);
+ u = getValue(execute(n[1], x));
+ v = new Reference(toObject(t, r, n[0]), String(u), n);
+ break;
+
+ case LIST:
+ // Curse ECMA for specifying that arguments is not an Array object!
+ v = {};
+ for (i = 0, j = n.$length; i < j; i++) {
+ u = getValue(execute(n[i], x));
+ v[i] = u;
+ }
+ v.length = i;
+ break;
+
+ case CALL:
+ r = execute(n[0], x);
+ a = execute(n[1], x);
+ f = getValue(r);
+ if (isPrimitive(f) || typeof f.__call__ != "function") {
+ throw new TypeError(r + " is not callable",
+ n[0].filename(), n[0].lineno);
+ }
+ t = (r instanceof Reference) ? r.base : null;
+ if (t instanceof Activation)
+ t = null;
+ v = f.__call__(t, a, x);
+ break;
+
+ case NEW:
+ case NEW_WITH_ARGS:
+ r = execute(n[0], x);
+ f = getValue(r);
+ if (n.type == NEW) {
+ a = {};
+ a.length = 0;
+ } else {
+ a = execute(n[1], x);
+ }
+ if (isPrimitive(f) || typeof f.__construct__ != "function") {
+ throw new TypeError(r + " is not a constructor",
+ n[0].filename(), n[0].lineno);
+ }
+ v = f.__construct__(a, x);
+ break;
+
+ case ARRAY_INIT:
+ v = [];
+ for (i = 0, j = n.$length; i < j; i++) {
+ if (n[i])
+ v[i] = getValue(execute(n[i], x));
+ }
+ v.length = j;
+ break;
+
+ case OBJECT_INIT:
+ v = {};
+ for (i = 0, j = n.$length; i < j; i++) {
+ t = n[i];
+ if (t.type == PROPERTY_INIT) {
+ v[t[0].value] = getValue(execute(t[1], x));
+ } else {
+ f = new FunctionObject(t, x.scope);
+ /*
+ u = (t.type == GETTER) ? '__defineGetter__'
+ : '__defineSetter__';
+ v[u](t.name, thunk(f, x));
+ */
+ }
+ }
+ break;
+
+ case NULL:
+ v = null;
+ break;
+
+ case THIS:
+ v = x.thisObject;
+ break;
+
+ case TRUE:
+ v = true;
+ break;
+
+ case FALSE:
+ v = false;
+ break;
+
+ case IDENTIFIER:
+ for (s = x.scope; s; s = s.parent) {
+ if (n.value in s.object)
+ break;
+ }
+ v = new Reference(s && s.object, n.value, n);
+ break;
+
+ case NUMBER:
+ case STRING:
+ case REGEXP:
+ v = n.value;
+ break;
+
+ case GROUP:
+ v = execute(n[0], x);
+ break;
+
+ default:
+ throw "PANIC: unknown operation " + n.type + ": " + uneval(n);
+ }
+ return v;
+}
+
+function Activation(f, a) {
+ for (var i = 0, j = f.params.length; i < j; i++)
+ this[f.params[i]] = a[i];
+ this.arguments = a;
+}
+
+// Null Activation.prototype's proto slot so that Object.prototype.* does not
+// pollute the scope of heavyweight functions. Also delete its 'constructor'
+// property so that it doesn't pollute function scopes.
+
+Activation.prototype.__proto__ = null;
+delete Activation.prototype.constructor;
+
+function FunctionObject(node, scope) {
+ this.node = node;
+ this.scope = scope;
+ this.length = node.params.length;
+ var proto = {};
+ this.prototype = proto;
+ proto.constructor = this;
+}
+
+var FOp = FunctionObject.prototype = {
+ // Internal methods.
+ __call__: function (t, a, x) {
+ var x2 = new ExecutionContext(FUNCTION_CODE);
+ x2.thisObject = t || global;
+ x2.caller = x;
+ x2.callee = this;
+ a.callee = this;
+ var f = this.node;
+ x2.scope = {object: new Activation(f, a), parent: this.scope};
+
+ ExecutionContext.current = x2;
+ try {
+ execute(f.body, x2);
+ } catch (e) {
+ if (!(e == RETURN)) { throw e } else if (e == RETURN) {
+ return x2.result;
+ }
+ if (e != THROW) { throw e }
+ x.result = x2.result;
+ throw THROW;
+ } finally {
+ ExecutionContext.current = x;
+ }
+ return undefined;
+ },
+
+ __construct__: function (a, x) {
+ var o = new Object;
+ var p = this.prototype;
+ if (isObject(p))
+ o.__proto__ = p;
+ // else o.__proto__ defaulted to Object.prototype
+
+ var v = this.__call__(o, a, x);
+ if (isObject(v))
+ return v;
+ return o;
+ },
+
+ __hasInstance__: function (v) {
+ if (isPrimitive(v))
+ return false;
+ var p = this.prototype;
+ if (isPrimitive(p)) {
+ throw new TypeError("'prototype' property is not an object",
+ this.node.filename(), this.node.lineno);
+ }
+ var o;
+ while ((o = v.__proto__)) {
+ if (o == p)
+ return true;
+ v = o;
+ }
+ return false;
+ },
+
+ // Standard methods.
+ toString: function () {
+ return this.node.getSource();
+ },
+
+ apply: function (t, a) {
+ // Curse ECMA again!
+ if (typeof this.__call__ != "function") {
+ throw new TypeError("Function.prototype.apply called on" +
+ " uncallable object");
+ }
+
+ if (t === undefined || t === null)
+ t = global;
+ else if (typeof t != "object")
+ t = toObject(t, t);
+
+ if (a === undefined || a === null) {
+ a = {};
+ a.length = 0;
+ } else if (a instanceof Array) {
+ var v = {};
+ for (var i = 0, j = a.length; i < j; i++)
+ v[i] = a[i];
+ v.length = i;
+ a = v;
+ } else if (!(a instanceof Object)) {
+ // XXX check for a non-arguments object
+ throw new TypeError("Second argument to Function.prototype.apply" +
+ " must be an array or arguments object",
+ this.node.filename(), this.node.lineno);
+ }
+
+ return this.__call__(t, a, ExecutionContext.current);
+ },
+
+ call: function (t) {
+ // Curse ECMA a third time!
+ var a = Array.prototype.splice.call(arguments, 1);
+ return this.apply(t, a);
+ }
+};
+
+// Connect Function.prototype and Function.prototype.constructor in global.
+reflectClass('Function', FOp);
+
+// Help native and host-scripted functions be like FunctionObjects.
+var Fp = Function.prototype;
+var REp = RegExp.prototype;
+
+if (!('__call__' in Fp)) {
+ Fp.__call__ = function (t, a, x) {
+ // Curse ECMA yet again!
+ a = Array.prototype.splice.call(a, 0, a.length);
+ return this.apply(t, a);
+ };
+
+ REp.__call__ = function (t, a, x) {
+ a = Array.prototype.splice.call(a, 0, a.length);
+ return this.exec.apply(this, a);
+ };
+
+ Fp.__construct__ = function (a, x) {
+ switch (a.length) {
+ case 0:
+ return new this();
+ case 1:
+ return new this(a[0]);
+ case 2:
+ return new this(a[0], a[1]);
+ case 3:
+ return new this(a[0], a[1], a[2]);
+ case 4:
+ return new this(a[0], a[1], a[2], a[3]);
+ case 5:
+ return new this(a[0], a[1], a[2], a[3], a[4]);
+ case 6:
+ return new this(a[0], a[1], a[2], a[3], a[4], a[5]);
+ case 7:
+ return new this(a[0], a[1], a[2], a[3], a[4], a[5], a[6]);
+ }
+ throw "PANIC: too many arguments to constructor";
+ }
+
+ // Since we use native functions such as Date along with host ones such
+ // as global.eval, we want both to be considered instances of the native
+ // Function constructor.
+ Fp.__hasInstance__ = function (v) {
+ return v instanceof Function || v instanceof global.Function;
+ };
+}
+
+function thunk(f, x) {
+ return function () { return f.__call__(this, arguments, x); };
+}
+
+function evaluate(s, f, l) {
+ if (typeof s != "string")
+ return s;
+
+ var x = ExecutionContext.current;
+ var x2 = new ExecutionContext(GLOBAL_CODE);
+ ExecutionContext.current = x2;
+ try {
+ execute(parse(s, f, l), x2);
+ } catch (e) {
+ if (e != THROW) { throw e }
+ if (x) {
+ x.result = x2.result;
+ throw(THROW);
+ }
+ throw x2.result;
+ } finally {
+ ExecutionContext.current = x;
+ }
+ return x2.result;
+}
Added: zc.selenium/trunk/src/zc/selenium/resources/scripts/narcissus-parse.js
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/scripts/narcissus-parse.js 2006-08-29 18:04:40 UTC (rev 69877)
+++ zc.selenium/trunk/src/zc/selenium/resources/scripts/narcissus-parse.js 2006-08-29 18:41:08 UTC (rev 69878)
@@ -0,0 +1,1003 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is the Narcissus JavaScript engine.
+ *
+ * The Initial Developer of the Original Code is
+ * Brendan Eich <brendan at mozilla.org>.
+ * Portions created by the Initial Developer are Copyright (C) 2004
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s): Richard Hundt <www.plextk.org>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+/*
+ * Narcissus - JS implemented in JS.
+ *
+ * Lexical scanner and parser.
+ */
+
+// jrh
+//module('JS.Parse');
+
+// Build a regexp that recognizes operators and punctuators (except newline).
+var opRegExp =
+/^;|^,|^\?|^:|^\|\||^\&\&|^\||^\^|^\&|^===|^==|^=|^!==|^!=|^<<|^<=|^<|^>>>|^>>|^>=|^>|^\+\+|^\-\-|^\+|^\-|^\*|^\/|^%|^!|^~|^\.|^\[|^\]|^\{|^\}|^\(|^\)/;
+
+// A regexp to match floating point literals (but not integer literals).
+var fpRegExp = /^\d+\.\d*(?:[eE][-+]?\d+)?|^\d+(?:\.\d*)?[eE][-+]?\d+|^\.\d+(?:[eE][-+]?\d+)?/;
+
+function Tokenizer(s, f, l) {
+ this.cursor = 0;
+ this.source = String(s);
+ this.tokens = [];
+ this.tokenIndex = 0;
+ this.lookahead = 0;
+ this.scanNewlines = false;
+ this.scanOperand = true;
+ this.filename = f || "";
+ this.lineno = l || 1;
+}
+
+Tokenizer.prototype = {
+ input : function() {
+ return this.source.substring(this.cursor);
+ },
+
+ done : function() {
+ return this.peek() == END;
+ },
+
+ token : function() {
+ return this.tokens[this.tokenIndex];
+ },
+
+ match: function (tt) {
+ return this.get() == tt || this.unget();
+ },
+
+ mustMatch: function (tt) {
+ if (!this.match(tt))
+ throw this.newSyntaxError("Missing " + this.tokens[tt].toLowerCase());
+ return this.token();
+ },
+
+ peek: function () {
+ var tt;
+ if (this.lookahead) {
+ tt = this.tokens[(this.tokenIndex + this.lookahead) & 3].type;
+ } else {
+ tt = this.get();
+ this.unget();
+ }
+ return tt;
+ },
+
+ peekOnSameLine: function () {
+ this.scanNewlines = true;
+ var tt = this.peek();
+ this.scanNewlines = false;
+ return tt;
+ },
+
+ get: function () {
+ var token;
+ while (this.lookahead) {
+ --this.lookahead;
+ this.tokenIndex = (this.tokenIndex + 1) & 3;
+ token = this.tokens[this.tokenIndex];
+ if (token.type != NEWLINE || this.scanNewlines)
+ return token.type;
+ }
+
+ for (;;) {
+ var input = this.input();
+ var rx = this.scanNewlines ? /^[ \t]+/ : /^\s+/;
+ var match = input.match(rx);
+ if (match) {
+ var spaces = match[0];
+ this.cursor += spaces.length;
+ var newlines = spaces.match(/\n/g);
+ if (newlines)
+ this.lineno += newlines.length;
+ input = this.input();
+ }
+
+ if (!(match = input.match(/^\/(?:\*(?:.|\n)*?\*\/|\/.*)/)))
+ break;
+ var comment = match[0];
+ this.cursor += comment.length;
+ newlines = comment.match(/\n/g);
+ if (newlines)
+ this.lineno += newlines.length
+ }
+
+ this.tokenIndex = (this.tokenIndex + 1) & 3;
+ token = this.tokens[this.tokenIndex];
+ if (!token)
+ this.tokens[this.tokenIndex] = token = {};
+ if (!input)
+ return token.type = END;
+ if ((match = input.match(fpRegExp))) {
+ token.type = NUMBER;
+ token.value = parseFloat(match[0]);
+ } else if ((match = input.match(/^0[xX][\da-fA-F]+|^0[0-7]*|^\d+/))) {
+ token.type = NUMBER;
+ token.value = parseInt(match[0]);
+ } else if ((match = input.match(/^((\$\w*)|(\w+))/))) {
+ var id = match[0];
+ token.type = keywords[id] || IDENTIFIER;
+ token.value = id;
+ } else if ((match = input.match(/^"(?:\\.|[^"])*"|^'(?:[^']|\\.)*'/))) {
+ token.type = STRING;
+ token.value = eval(match[0]);
+ } else if (this.scanOperand &&
+ (match = input.match(/^\/((?:\\.|[^\/])+)\/([gi]*)/))) {
+ token.type = REGEXP;
+ token.value = new RegExp(match[1], match[2]);
+ } else if ((match = input.match(opRegExp))) {
+ var op = match[0];
+ if (assignOps[op] && input[op.length] == '=') {
+ token.type = ASSIGN;
+ token.assignOp = GLOBAL[opTypeNames[op]];
+ match[0] += '=';
+ } else {
+ token.type = GLOBAL[opTypeNames[op]];
+ if (this.scanOperand &&
+ (token.type == PLUS || token.type == MINUS)) {
+ token.type += UNARY_PLUS - PLUS;
+ }
+ token.assignOp = null;
+ }
+ //debug('token.value => '+op+', token.type => '+token.type);
+ token.value = op;
+ } else {
+ throw this.newSyntaxError("Illegal token");
+ }
+
+ token.start = this.cursor;
+ this.cursor += match[0].length;
+ token.end = this.cursor;
+ token.lineno = this.lineno;
+ return token.type;
+ },
+
+ unget: function () {
+ if (++this.lookahead == 4) throw "PANIC: too much lookahead!";
+ this.tokenIndex = (this.tokenIndex - 1) & 3;
+ },
+
+ newSyntaxError: function (m) {
+ var e = new SyntaxError(m, this.filename, this.lineno);
+ e.source = this.source;
+ e.cursor = this.cursor;
+ return e;
+ }
+};
+
+function CompilerContext(inFunction) {
+ this.inFunction = inFunction;
+ this.stmtStack = [];
+ this.funDecls = [];
+ this.varDecls = [];
+}
+
+var CCp = CompilerContext.prototype;
+CCp.bracketLevel = CCp.curlyLevel = CCp.parenLevel = CCp.hookLevel = 0;
+CCp.ecmaStrictMode = CCp.inForLoopInit = false;
+
+function Script(t, x) {
+ var n = Statements(t, x);
+ n.type = SCRIPT;
+ n.funDecls = x.funDecls;
+ n.varDecls = x.varDecls;
+ return n;
+}
+
+// Node extends Array, which we extend slightly with a top-of-stack method.
+Array.prototype.top = function() {
+ return this.length && this[this.length-1];
+}
+
+function NarcNode(t, type) {
+ var token = t.token();
+ if (token) {
+ this.type = type || token.type;
+ this.value = token.value;
+ this.lineno = token.lineno;
+ this.start = token.start;
+ this.end = token.end;
+ } else {
+ this.type = type;
+ this.lineno = t.lineno;
+ }
+ this.tokenizer = t;
+ for (var i = 2; i < arguments.length; i++)
+ this.push(arguments[i]);
+}
+
+var Np = NarcNode.prototype = new Array();
+Np.constructor = NarcNode;
+Np.$length = 0;
+Np.toSource = Object.prototype.toSource;
+
+// Always use push to add operands to an expression, to update start and end.
+Np.push = function (kid) {
+ if (kid.start < this.start)
+ this.start = kid.start;
+ if (this.end < kid.end)
+ this.end = kid.end;
+ //debug('length before => '+this.$length);
+ this[this.$length] = kid;
+ this.$length++;
+ //debug('length after => '+this.$length);
+}
+
+NarcNode.indentLevel = 0;
+
+function tokenstr(tt) {
+ var t = tokens[tt];
+ return /^\W/.test(t) ? opTypeNames[t] : t.toUpperCase();
+}
+
+Np.toString = function () {
+ var a = [];
+ for (var i in this) {
+ if (this.hasOwnProperty(i) && i != 'type')
+ a.push({id: i, value: this[i]});
+ }
+ a.sort(function (a,b) { return (a.id < b.id) ? -1 : 1; });
+ INDENTATION = " ";
+ var n = ++NarcNode.indentLevel;
+ var s = "{\n" + INDENTATION.repeat(n) + "type: " + tokenstr(this.type);
+ for (i = 0; i < a.length; i++)
+ s += ",\n" + INDENTATION.repeat(n) + a[i].id + ": " + a[i].value;
+ n = --NarcNode.indentLevel;
+ s += "\n" + INDENTATION.repeat(n) + "}";
+ return s;
+}
+
+Np.getSource = function () {
+ return this.tokenizer.source.slice(this.start, this.end);
+};
+
+Np.filename = function () { return this.tokenizer.filename; };
+
+String.prototype.repeat = function (n) {
+ var s = "", t = this + s;
+ while (--n >= 0)
+ s += t;
+ return s;
+}
+
+// Statement stack and nested statement handler.
+function nest(t, x, node, func, end) {
+ x.stmtStack.push(node);
+ var n = func(t, x);
+ x.stmtStack.pop();
+ end && t.mustMatch(end);
+ return n;
+}
+
+function Statements(t, x) {
+ var n = new NarcNode(t, BLOCK);
+ x.stmtStack.push(n);
+ while (!t.done() && t.peek() != RIGHT_CURLY)
+ n.push(Statement(t, x));
+ x.stmtStack.pop();
+ return n;
+}
+
+function Block(t, x) {
+ t.mustMatch(LEFT_CURLY);
+ var n = Statements(t, x);
+ t.mustMatch(RIGHT_CURLY);
+ return n;
+}
+
+DECLARED_FORM = 0; EXPRESSED_FORM = 1; STATEMENT_FORM = 2;
+
+function Statement(t, x) {
+ var i, label, n, n2, ss, tt = t.get();
+
+ // Cases for statements ending in a right curly return early, avoiding the
+ // common semicolon insertion magic after this switch.
+ switch (tt) {
+ case FUNCTION:
+ return FunctionDefinition(t, x, true,
+ (x.stmtStack.length > 1)
+ ? STATEMENT_FORM
+ : DECLARED_FORM);
+
+ case LEFT_CURLY:
+ n = Statements(t, x);
+ t.mustMatch(RIGHT_CURLY);
+ return n;
+
+ case IF:
+ n = new NarcNode(t);
+ n.condition = ParenExpression(t, x);
+ x.stmtStack.push(n);
+ n.thenPart = Statement(t, x);
+ n.elsePart = t.match(ELSE) ? Statement(t, x) : null;
+ x.stmtStack.pop();
+ return n;
+
+ case SWITCH:
+ n = new NarcNode(t);
+ t.mustMatch(LEFT_PAREN);
+ n.discriminant = Expression(t, x);
+ t.mustMatch(RIGHT_PAREN);
+ n.cases = [];
+ n.defaultIndex = -1;
+ x.stmtStack.push(n);
+ t.mustMatch(LEFT_CURLY);
+ while ((tt = t.get()) != RIGHT_CURLY) {
+ switch (tt) {
+ case DEFAULT:
+ if (n.defaultIndex >= 0)
+ throw t.newSyntaxError("More than one switch default");
+ // FALL THROUGH
+ case CASE:
+ n2 = new NarcNode(t);
+ if (tt == DEFAULT)
+ n.defaultIndex = n.cases.length;
+ else
+ n2.caseLabel = Expression(t, x, COLON);
+ break;
+ default:
+ throw t.newSyntaxError("Invalid switch case");
+ }
+ t.mustMatch(COLON);
+ n2.statements = new NarcNode(t, BLOCK);
+ while ((tt=t.peek()) != CASE && tt != DEFAULT && tt != RIGHT_CURLY)
+ n2.statements.push(Statement(t, x));
+ n.cases.push(n2);
+ }
+ x.stmtStack.pop();
+ return n;
+
+ case FOR:
+ n = new NarcNode(t);
+ n.isLoop = true;
+ t.mustMatch(LEFT_PAREN);
+ if ((tt = t.peek()) != SEMICOLON) {
+ x.inForLoopInit = true;
+ if (tt == VAR || tt == CONST) {
+ t.get();
+ n2 = Variables(t, x);
+ } else {
+ n2 = Expression(t, x);
+ }
+ x.inForLoopInit = false;
+ }
+ if (n2 && t.match(IN)) {
+ n.type = FOR_IN;
+ if (n2.type == VAR) {
+ if (n2.$length != 1) {
+ throw new SyntaxError("Invalid for..in left-hand side",
+ t.filename, n2.lineno);
+ }
+
+ // NB: n2[0].type == IDENTIFIER and n2[0].value == n2[0].name.
+ n.iterator = n2[0];
+ n.varDecl = n2;
+ } else {
+ n.iterator = n2;
+ n.varDecl = null;
+ }
+ n.object = Expression(t, x);
+ } else {
+ n.setup = n2 || null;
+ t.mustMatch(SEMICOLON);
+ n.condition = (t.peek() == SEMICOLON) ? null : Expression(t, x);
+ t.mustMatch(SEMICOLON);
+ n.update = (t.peek() == RIGHT_PAREN) ? null : Expression(t, x);
+ }
+ t.mustMatch(RIGHT_PAREN);
+ n.body = nest(t, x, n, Statement);
+ return n;
+
+ case WHILE:
+ n = new NarcNode(t);
+ n.isLoop = true;
+ n.condition = ParenExpression(t, x);
+ n.body = nest(t, x, n, Statement);
+ return n;
+
+ case DO:
+ n = new NarcNode(t);
+ n.isLoop = true;
+ n.body = nest(t, x, n, Statement, WHILE);
+ n.condition = ParenExpression(t, x);
+ if (!x.ecmaStrictMode) {
+ // <script language="JavaScript"> (without version hints) may need
+ // automatic semicolon insertion without a newline after do-while.
+ // See http://bugzilla.mozilla.org/show_bug.cgi?id=238945.
+ t.match(SEMICOLON);
+ return n;
+ }
+ break;
+
+ case BREAK:
+ case CONTINUE:
+ n = new NarcNode(t);
+ if (t.peekOnSameLine() == IDENTIFIER) {
+ t.get();
+ n.label = t.token().value;
+ }
+ ss = x.stmtStack;
+ i = ss.length;
+ label = n.label;
+ if (label) {
+ do {
+ if (--i < 0)
+ throw t.newSyntaxError("Label not found");
+ } while (ss[i].label != label);
+ } else {
+ do {
+ if (--i < 0) {
+ throw t.newSyntaxError("Invalid " + ((tt == BREAK)
+ ? "break"
+ : "continue"));
+ }
+ } while (!ss[i].isLoop && (tt != BREAK || ss[i].type != SWITCH));
+ }
+ n.target = ss[i];
+ break;
+
+ case TRY:
+ n = new NarcNode(t);
+ n.tryBlock = Block(t, x);
+ n.catchClauses = [];
+ while (t.match(CATCH)) {
+ n2 = new NarcNode(t);
+ t.mustMatch(LEFT_PAREN);
+ n2.varName = t.mustMatch(IDENTIFIER).value;
+ if (t.match(IF)) {
+ if (x.ecmaStrictMode)
+ throw t.newSyntaxError("Illegal catch guard");
+ if (n.catchClauses.length && !n.catchClauses.top().guard)
+ throw t.newSyntaxError("Guarded catch after unguarded");
+ n2.guard = Expression(t, x);
+ } else {
+ n2.guard = null;
+ }
+ t.mustMatch(RIGHT_PAREN);
+ n2.block = Block(t, x);
+ n.catchClauses.push(n2);
+ }
+ if (t.match(FINALLY))
+ n.finallyBlock = Block(t, x);
+ if (!n.catchClauses.length && !n.finallyBlock)
+ throw t.newSyntaxError("Invalid try statement");
+ return n;
+
+ case CATCH:
+ case FINALLY:
+ throw t.newSyntaxError(tokens[tt] + " without preceding try");
+
+ case THROW:
+ n = new NarcNode(t);
+ n.exception = Expression(t, x);
+ break;
+
+ case RETURN:
+ if (!x.inFunction)
+ throw t.newSyntaxError("Invalid return");
+ n = new NarcNode(t);
+ tt = t.peekOnSameLine();
+ if (tt != END && tt != NEWLINE && tt != SEMICOLON && tt != RIGHT_CURLY)
+ n.value = Expression(t, x);
+ break;
+
+ case WITH:
+ n = new NarcNode(t);
+ n.object = ParenExpression(t, x);
+ n.body = nest(t, x, n, Statement);
+ return n;
+
+ case VAR:
+ case CONST:
+ n = Variables(t, x);
+ break;
+
+ case DEBUGGER:
+ n = new NarcNode(t);
+ break;
+
+ case REQUIRE:
+ n = new NarcNode(t);
+ n.classPath = ParenExpression(t, x);
+ break;
+
+ case NEWLINE:
+ case SEMICOLON:
+ n = new NarcNode(t, SEMICOLON);
+ n.expression = null;
+ return n;
+
+ default:
+ if (tt == IDENTIFIER && t.peek() == COLON) {
+ label = t.token().value;
+ ss = x.stmtStack;
+ for (i = ss.length-1; i >= 0; --i) {
+ if (ss[i].label == label)
+ throw t.newSyntaxError("Duplicate label");
+ }
+ t.get();
+ n = new NarcNode(t, LABEL);
+ n.label = label;
+ n.statement = nest(t, x, n, Statement);
+ return n;
+ }
+
+ n = new NarcNode(t, SEMICOLON);
+ t.unget();
+ n.expression = Expression(t, x);
+ n.end = n.expression.end;
+ break;
+ }
+
+ if (t.lineno == t.token().lineno) {
+ tt = t.peekOnSameLine();
+ if (tt != END && tt != NEWLINE && tt != SEMICOLON && tt != RIGHT_CURLY)
+ throw t.newSyntaxError("Missing ; before statement");
+ }
+ t.match(SEMICOLON);
+ return n;
+}
+
+function FunctionDefinition(t, x, requireName, functionForm) {
+ var f = new NarcNode(t);
+ if (f.type != FUNCTION)
+ f.type = (f.value == "get") ? GETTER : SETTER;
+ if (t.match(IDENTIFIER)) {
+ f.name = t.token().value;
+ }
+ else if (requireName)
+ throw t.newSyntaxError("Missing function identifier");
+
+ t.mustMatch(LEFT_PAREN);
+ f.params = [];
+ var tt;
+ while ((tt = t.get()) != RIGHT_PAREN) {
+ if (tt != IDENTIFIER)
+ throw t.newSyntaxError("Missing formal parameter");
+ f.params.push(t.token().value);
+ if (t.peek() != RIGHT_PAREN)
+ t.mustMatch(COMMA);
+ }
+
+ t.mustMatch(LEFT_CURLY);
+ var x2 = new CompilerContext(true);
+ f.body = Script(t, x2);
+ t.mustMatch(RIGHT_CURLY);
+ f.end = t.token().end;
+
+ f.functionForm = functionForm;
+ if (functionForm == DECLARED_FORM) {
+ x.funDecls.push(f);
+ }
+
+ return f;
+}
+
+function Variables(t, x) {
+ var n = new NarcNode(t);
+ do {
+ t.mustMatch(IDENTIFIER);
+ var n2 = new NarcNode(t);
+ n2.name = n2.value;
+ if (t.match(ASSIGN)) {
+ if (t.token().assignOp)
+ throw t.newSyntaxError("Invalid variable initialization");
+ n2.initializer = Expression(t, x, COMMA);
+ }
+ n2.readOnly = (n.type == CONST);
+ n.push(n2);
+ x.varDecls.push(n2);
+ } while (t.match(COMMA));
+ return n;
+}
+
+function ParenExpression(t, x) {
+ t.mustMatch(LEFT_PAREN);
+ var n = Expression(t, x);
+ t.mustMatch(RIGHT_PAREN);
+ return n;
+}
+
+var opPrecedence = {
+ SEMICOLON: 0,
+ COMMA: 1,
+ ASSIGN: 2, HOOK: 2, COLON: 2, CONDITIONAL: 2,
+ // The above all have to have the same precedence, see bug 330975.
+ OR: 4,
+ AND: 5,
+ BITWISE_OR: 6,
+ BITWISE_XOR: 7,
+ BITWISE_AND: 8,
+ EQ: 9, NE: 9, STRICT_EQ: 9, STRICT_NE: 9,
+ LT: 10, LE: 10, GE: 10, GT: 10, IN: 10, INSTANCEOF: 10,
+ LSH: 11, RSH: 11, URSH: 11,
+ PLUS: 12, MINUS: 12,
+ MUL: 13, DIV: 13, MOD: 13,
+ DELETE: 14, VOID: 14, TYPEOF: 14, // PRE_INCREMENT: 14, PRE_DECREMENT: 14,
+ NOT: 14, BITWISE_NOT: 14, UNARY_PLUS: 14, UNARY_MINUS: 14,
+ INCREMENT: 15, DECREMENT: 15, // postfix
+ NEW: 16,
+ DOT: 17
+};
+
+// Map operator type code to precedence.
+for (i in opPrecedence)
+ opPrecedence[GLOBAL[i]] = opPrecedence[i];
+
+var opArity = {
+ COMMA: -2,
+ ASSIGN: 2,
+ CONDITIONAL: 3,
+ OR: 2,
+ AND: 2,
+ BITWISE_OR: 2,
+ BITWISE_XOR: 2,
+ BITWISE_AND: 2,
+ EQ: 2, NE: 2, STRICT_EQ: 2, STRICT_NE: 2,
+ LT: 2, LE: 2, GE: 2, GT: 2, IN: 2, INSTANCEOF: 2,
+ LSH: 2, RSH: 2, URSH: 2,
+ PLUS: 2, MINUS: 2,
+ MUL: 2, DIV: 2, MOD: 2,
+ DELETE: 1, VOID: 1, TYPEOF: 1, // PRE_INCREMENT: 1, PRE_DECREMENT: 1,
+ NOT: 1, BITWISE_NOT: 1, UNARY_PLUS: 1, UNARY_MINUS: 1,
+ INCREMENT: 1, DECREMENT: 1, // postfix
+ NEW: 1, NEW_WITH_ARGS: 2, DOT: 2, INDEX: 2, CALL: 2,
+ ARRAY_INIT: 1, OBJECT_INIT: 1, GROUP: 1
+};
+
+// Map operator type code to arity.
+for (i in opArity)
+ opArity[GLOBAL[i]] = opArity[i];
+
+function Expression(t, x, stop) {
+ var n, id, tt, operators = [], operands = [];
+ var bl = x.bracketLevel, cl = x.curlyLevel, pl = x.parenLevel,
+ hl = x.hookLevel;
+
+ function reduce() {
+ //debug('OPERATORS => '+operators);
+ var n = operators.pop();
+ var op = n.type;
+ var arity = opArity[op];
+ if (arity == -2) {
+ // Flatten left-associative trees.
+ var left = operands.length >= 2 && operands[operands.length-2];
+ if (left.type == op) {
+ var right = operands.pop();
+ left.push(right);
+ return left;
+ }
+ arity = 2;
+ }
+
+ // Always use push to add operands to n, to update start and end.
+ var a = operands.splice(operands.length - arity, operands.length);
+ for (var i = 0; i < arity; i++) {
+ n.push(a[i]);
+ }
+
+ // Include closing bracket or postfix operator in [start,end).
+ if (n.end < t.token().end)
+ n.end = t.token().end;
+
+ operands.push(n);
+ return n;
+ }
+
+loop:
+ while ((tt = t.get()) != END) {
+ //debug('TT => '+tokens[tt]);
+ if (tt == stop &&
+ x.bracketLevel == bl && x.curlyLevel == cl && x.parenLevel == pl &&
+ x.hookLevel == hl) {
+ // Stop only if tt matches the optional stop parameter, and that
+ // token is not quoted by some kind of bracket.
+ break;
+ }
+ switch (tt) {
+ case SEMICOLON:
+ // NB: cannot be empty, Statement handled that.
+ break loop;
+
+ case ASSIGN:
+ case HOOK:
+ case COLON:
+ if (t.scanOperand)
+ break loop;
+ // Use >, not >=, for right-associative ASSIGN and HOOK/COLON.
+ while (operators.length && opPrecedence[operators.top().type] > opPrecedence[tt] ||
+ (tt == COLON && operators.top().type == ASSIGN)) {
+ reduce();
+ }
+ if (tt == COLON) {
+ n = operators.top();
+ if (n.type != HOOK)
+ throw t.newSyntaxError("Invalid label");
+ n.type = CONDITIONAL;
+ --x.hookLevel;
+ } else {
+ operators.push(new NarcNode(t));
+ if (tt == ASSIGN)
+ operands.top().assignOp = t.token().assignOp;
+ else
+ ++x.hookLevel; // tt == HOOK
+ }
+ t.scanOperand = true;
+ break;
+
+ case IN:
+ // An in operator should not be parsed if we're parsing the head of
+ // a for (...) loop, unless it is in the then part of a conditional
+ // expression, or parenthesized somehow.
+ if (x.inForLoopInit && !x.hookLevel &&
+ !x.bracketLevel && !x.curlyLevel && !x.parenLevel) {
+ break loop;
+ }
+ // FALL THROUGH
+ case COMMA:
+ // Treat comma as left-associative so reduce can fold left-heavy
+ // COMMA trees into a single array.
+ // FALL THROUGH
+ case OR:
+ case AND:
+ case BITWISE_OR:
+ case BITWISE_XOR:
+ case BITWISE_AND:
+ case EQ: case NE: case STRICT_EQ: case STRICT_NE:
+ case LT: case LE: case GE: case GT:
+ case INSTANCEOF:
+ case LSH: case RSH: case URSH:
+ case PLUS: case MINUS:
+ case MUL: case DIV: case MOD:
+ case DOT:
+ if (t.scanOperand)
+ break loop;
+ while (operators.length && opPrecedence[operators.top().type] >= opPrecedence[tt])
+ reduce();
+ if (tt == DOT) {
+ t.mustMatch(IDENTIFIER);
+ operands.push(new NarcNode(t, DOT, operands.pop(), new NarcNode(t)));
+ } else {
+ operators.push(new NarcNode(t));
+ t.scanOperand = true;
+ }
+ break;
+
+ case DELETE: case VOID: case TYPEOF:
+ case NOT: case BITWISE_NOT: case UNARY_PLUS: case UNARY_MINUS:
+ case NEW:
+ if (!t.scanOperand)
+ break loop;
+ operators.push(new NarcNode(t));
+ break;
+
+ case INCREMENT: case DECREMENT:
+ if (t.scanOperand) {
+ operators.push(new NarcNode(t)); // prefix increment or decrement
+ } else {
+ // Use >, not >=, so postfix has higher precedence than prefix.
+ while (operators.length && opPrecedence[operators.top().type] > opPrecedence[tt])
+ reduce();
+ n = new NarcNode(t, tt, operands.pop());
+ n.postfix = true;
+ operands.push(n);
+ }
+ break;
+
+ case FUNCTION:
+ if (!t.scanOperand)
+ break loop;
+ operands.push(FunctionDefinition(t, x, false, EXPRESSED_FORM));
+ t.scanOperand = false;
+ break;
+
+ case NULL: case THIS: case TRUE: case FALSE:
+ case IDENTIFIER: case NUMBER: case STRING: case REGEXP:
+ if (!t.scanOperand)
+ break loop;
+ operands.push(new NarcNode(t));
+ t.scanOperand = false;
+ break;
+
+ case LEFT_BRACKET:
+ if (t.scanOperand) {
+ // Array initialiser. Parse using recursive descent, as the
+ // sub-grammar here is not an operator grammar.
+ n = new NarcNode(t, ARRAY_INIT);
+ while ((tt = t.peek()) != RIGHT_BRACKET) {
+ if (tt == COMMA) {
+ t.get();
+ n.push(null);
+ continue;
+ }
+ n.push(Expression(t, x, COMMA));
+ if (!t.match(COMMA))
+ break;
+ }
+ t.mustMatch(RIGHT_BRACKET);
+ operands.push(n);
+ t.scanOperand = false;
+ } else {
+ // Property indexing operator.
+ operators.push(new NarcNode(t, INDEX));
+ t.scanOperand = true;
+ ++x.bracketLevel;
+ }
+ break;
+
+ case RIGHT_BRACKET:
+ if (t.scanOperand || x.bracketLevel == bl)
+ break loop;
+ while (reduce().type != INDEX)
+ continue;
+ --x.bracketLevel;
+ break;
+
+ case LEFT_CURLY:
+ if (!t.scanOperand)
+ break loop;
+ // Object initialiser. As for array initialisers (see above),
+ // parse using recursive descent.
+ ++x.curlyLevel;
+ n = new NarcNode(t, OBJECT_INIT);
+ object_init:
+ if (!t.match(RIGHT_CURLY)) {
+ do {
+ tt = t.get();
+ if ((t.token().value == "get" || t.token().value == "set") &&
+ t.peek() == IDENTIFIER) {
+ if (x.ecmaStrictMode)
+ throw t.newSyntaxError("Illegal property accessor");
+ n.push(FunctionDefinition(t, x, true, EXPRESSED_FORM));
+ } else {
+ switch (tt) {
+ case IDENTIFIER:
+ case NUMBER:
+ case STRING:
+ id = new NarcNode(t);
+ break;
+ case RIGHT_CURLY:
+ if (x.ecmaStrictMode)
+ throw t.newSyntaxError("Illegal trailing ,");
+ break object_init;
+ default:
+ throw t.newSyntaxError("Invalid property name");
+ }
+ t.mustMatch(COLON);
+ n.push(new NarcNode(t, PROPERTY_INIT, id,
+ Expression(t, x, COMMA)));
+ }
+ } while (t.match(COMMA));
+ t.mustMatch(RIGHT_CURLY);
+ }
+ operands.push(n);
+ t.scanOperand = false;
+ --x.curlyLevel;
+ break;
+
+ case RIGHT_CURLY:
+ if (!t.scanOperand && x.curlyLevel != cl)
+ throw "PANIC: right curly botch";
+ break loop;
+
+ case LEFT_PAREN:
+ if (t.scanOperand) {
+ operators.push(new NarcNode(t, GROUP));
+ } else {
+ while (operators.length && opPrecedence[operators.top().type] > opPrecedence[NEW])
+ reduce();
+
+ // Handle () now, to regularize the n-ary case for n > 0.
+ // We must set scanOperand in case there are arguments and
+ // the first one is a regexp or unary+/-.
+ n = operators.top();
+ t.scanOperand = true;
+ if (t.match(RIGHT_PAREN)) {
+ if (n.type == NEW) {
+ --operators.length;
+ n.push(operands.pop());
+ } else {
+ n = new NarcNode(t, CALL, operands.pop(),
+ new NarcNode(t, LIST));
+ }
+ operands.push(n);
+ t.scanOperand = false;
+ break;
+ }
+ if (n.type == NEW)
+ n.type = NEW_WITH_ARGS;
+ else
+ operators.push(new NarcNode(t, CALL));
+ }
+ ++x.parenLevel;
+ break;
+
+ case RIGHT_PAREN:
+ if (t.scanOperand || x.parenLevel == pl)
+ break loop;
+ while ((tt = reduce().type) != GROUP && tt != CALL &&
+ tt != NEW_WITH_ARGS) {
+ continue;
+ }
+ if (tt != GROUP) {
+ n = operands.top();
+ if (n[1].type != COMMA)
+ n[1] = new NarcNode(t, LIST, n[1]);
+ else
+ n[1].type = LIST;
+ }
+ --x.parenLevel;
+ break;
+
+ // Automatic semicolon insertion means we may scan across a newline
+ // and into the beginning of another statement. If so, break out of
+ // the while loop and let the t.scanOperand logic handle errors.
+ default:
+ break loop;
+ }
+ }
+ if (x.hookLevel != hl)
+ throw t.newSyntaxError("Missing : after ?");
+ if (x.parenLevel != pl)
+ throw t.newSyntaxError("Missing ) in parenthetical");
+ if (x.bracketLevel != bl)
+ throw t.newSyntaxError("Missing ] in index expression");
+ if (t.scanOperand)
+ throw t.newSyntaxError("Missing operand");
+
+ // Resume default mode, scanning for operands, not operators.
+ t.scanOperand = true;
+ t.unget();
+
+ while (operators.length)
+ reduce();
+ return operands.pop();
+}
+
+function parse(s, f, l) {
+ var t = new Tokenizer(s, f, l);
+ var x = new CompilerContext(false);
+ var n = Script(t, x);
+ if (!t.done())
+ throw t.newSyntaxError("Syntax error");
+ return n;
+}
+
+debug = function(msg) {
+ document.body.appendChild(document.createTextNode(msg));
+ document.body.appendChild(document.createElement('br'));
+}
+
Added: zc.selenium/trunk/src/zc/selenium/resources/scripts/prototype-1.4.0.js
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/scripts/prototype-1.4.0.js 2006-08-29 18:04:40 UTC (rev 69877)
+++ zc.selenium/trunk/src/zc/selenium/resources/scripts/prototype-1.4.0.js 2006-08-29 18:41:08 UTC (rev 69878)
@@ -0,0 +1,1781 @@
+/* Prototype JavaScript framework, version 1.4.0
+ * (c) 2005 Sam Stephenson <sam at conio.net>
+ *
+ * Prototype is freely distributable under the terms of an MIT-style license.
+ * For details, see the Prototype web site: http://prototype.conio.net/
+ *
+/*--------------------------------------------------------------------------*/
+
+var Prototype = {
+ Version: '1.4.0',
+ ScriptFragment: '(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)',
+
+ emptyFunction: function() {},
+ K: function(x) {return x}
+}
+
+var Class = {
+ create: function() {
+ return function() {
+ this.initialize.apply(this, arguments);
+ }
+ }
+}
+
+var Abstract = new Object();
+
+Object.extend = function(destination, source) {
+ for (property in source) {
+ destination[property] = source[property];
+ }
+ return destination;
+}
+
+Object.inspect = function(object) {
+ try {
+ if (object == undefined) return 'undefined';
+ if (object == null) return 'null';
+ return object.inspect ? object.inspect() : object.toString();
+ } catch (e) {
+ if (e instanceof RangeError) return '...';
+ throw e;
+ }
+}
+
+Function.prototype.bind = function() {
+ var __method = this, args = $A(arguments), object = args.shift();
+ return function() {
+ return __method.apply(object, args.concat($A(arguments)));
+ }
+}
+
+Function.prototype.bindAsEventListener = function(object) {
+ var __method = this;
+ return function(event) {
+ return __method.call(object, event || window.event);
+ }
+}
+
+Object.extend(Number.prototype, {
+ toColorPart: function() {
+ var digits = this.toString(16);
+ if (this < 16) return '0' + digits;
+ return digits;
+ },
+
+ succ: function() {
+ return this + 1;
+ },
+
+ times: function(iterator) {
+ $R(0, this, true).each(iterator);
+ return this;
+ }
+});
+
+var Try = {
+ these: function() {
+ var returnValue;
+
+ for (var i = 0; i < arguments.length; i++) {
+ var lambda = arguments[i];
+ try {
+ returnValue = lambda();
+ break;
+ } catch (e) {}
+ }
+
+ return returnValue;
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+
+var PeriodicalExecuter = Class.create();
+PeriodicalExecuter.prototype = {
+ initialize: function(callback, frequency) {
+ this.callback = callback;
+ this.frequency = frequency;
+ this.currentlyExecuting = false;
+
+ this.registerCallback();
+ },
+
+ registerCallback: function() {
+ setInterval(this.onTimerEvent.bind(this), this.frequency * 1000);
+ },
+
+ onTimerEvent: function() {
+ if (!this.currentlyExecuting) {
+ try {
+ this.currentlyExecuting = true;
+ this.callback();
+ } finally {
+ this.currentlyExecuting = false;
+ }
+ }
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+
+function $() {
+ var elements = new Array();
+
+ for (var i = 0; i < arguments.length; i++) {
+ var element = arguments[i];
+ if (typeof element == 'string')
+ element = document.getElementById(element);
+
+ if (arguments.length == 1)
+ return element;
+
+ elements.push(element);
+ }
+
+ return elements;
+}
+Object.extend(String.prototype, {
+ stripTags: function() {
+ return this.replace(/<\/?[^>]+>/gi, '');
+ },
+
+ stripScripts: function() {
+ return this.replace(new RegExp(Prototype.ScriptFragment, 'img'), '');
+ },
+
+ extractScripts: function() {
+ var matchAll = new RegExp(Prototype.ScriptFragment, 'img');
+ var matchOne = new RegExp(Prototype.ScriptFragment, 'im');
+ return (this.match(matchAll) || []).map(function(scriptTag) {
+ return (scriptTag.match(matchOne) || ['', ''])[1];
+ });
+ },
+
+ evalScripts: function() {
+ return this.extractScripts().map(eval);
+ },
+
+ escapeHTML: function() {
+ var div = document.createElement('div');
+ var text = document.createTextNode(this);
+ div.appendChild(text);
+ return div.innerHTML;
+ },
+
+ unescapeHTML: function() {
+ var div = document.createElement('div');
+ div.innerHTML = this.stripTags();
+ return div.childNodes[0] ? div.childNodes[0].nodeValue : '';
+ },
+
+ toQueryParams: function() {
+ var pairs = this.match(/^\??(.*)$/)[1].split('&');
+ return pairs.inject({}, function(params, pairString) {
+ var pair = pairString.split('=');
+ params[pair[0]] = pair[1];
+ return params;
+ });
+ },
+
+ toArray: function() {
+ return this.split('');
+ },
+
+ camelize: function() {
+ var oStringList = this.split('-');
+ if (oStringList.length == 1) return oStringList[0];
+
+ var camelizedString = this.indexOf('-') == 0
+ ? oStringList[0].charAt(0).toUpperCase() + oStringList[0].substring(1)
+ : oStringList[0];
+
+ for (var i = 1, len = oStringList.length; i < len; i++) {
+ var s = oStringList[i];
+ camelizedString += s.charAt(0).toUpperCase() + s.substring(1);
+ }
+
+ return camelizedString;
+ },
+
+ inspect: function() {
+ return "'" + this.replace('\\', '\\\\').replace("'", '\\\'') + "'";
+ }
+});
+
+String.prototype.parseQuery = String.prototype.toQueryParams;
+
+var $break = new Object();
+var $continue = new Object();
+
+var Enumerable = {
+ each: function(iterator) {
+ var index = 0;
+ try {
+ this._each(function(value) {
+ try {
+ iterator(value, index++);
+ } catch (e) {
+ if (e != $continue) throw e;
+ }
+ });
+ } catch (e) {
+ if (e != $break) throw e;
+ }
+ },
+
+ all: function(iterator) {
+ var result = true;
+ this.each(function(value, index) {
+ result = result && !!(iterator || Prototype.K)(value, index);
+ if (!result) throw $break;
+ });
+ return result;
+ },
+
+ any: function(iterator) {
+ var result = true;
+ this.each(function(value, index) {
+ if (result = !!(iterator || Prototype.K)(value, index))
+ throw $break;
+ });
+ return result;
+ },
+
+ collect: function(iterator) {
+ var results = [];
+ this.each(function(value, index) {
+ results.push(iterator(value, index));
+ });
+ return results;
+ },
+
+ detect: function (iterator) {
+ var result;
+ this.each(function(value, index) {
+ if (iterator(value, index)) {
+ result = value;
+ throw $break;
+ }
+ });
+ return result;
+ },
+
+ findAll: function(iterator) {
+ var results = [];
+ this.each(function(value, index) {
+ if (iterator(value, index))
+ results.push(value);
+ });
+ return results;
+ },
+
+ grep: function(pattern, iterator) {
+ var results = [];
+ this.each(function(value, index) {
+ var stringValue = value.toString();
+ if (stringValue.match(pattern))
+ results.push((iterator || Prototype.K)(value, index));
+ })
+ return results;
+ },
+
+ include: function(object) {
+ var found = false;
+ this.each(function(value) {
+ if (value == object) {
+ found = true;
+ throw $break;
+ }
+ });
+ return found;
+ },
+
+ inject: function(memo, iterator) {
+ this.each(function(value, index) {
+ memo = iterator(memo, value, index);
+ });
+ return memo;
+ },
+
+ invoke: function(method) {
+ var args = $A(arguments).slice(1);
+ return this.collect(function(value) {
+ return value[method].apply(value, args);
+ });
+ },
+
+ max: function(iterator) {
+ var result;
+ this.each(function(value, index) {
+ value = (iterator || Prototype.K)(value, index);
+ if (value >= (result || value))
+ result = value;
+ });
+ return result;
+ },
+
+ min: function(iterator) {
+ var result;
+ this.each(function(value, index) {
+ value = (iterator || Prototype.K)(value, index);
+ if (value <= (result || value))
+ result = value;
+ });
+ return result;
+ },
+
+ partition: function(iterator) {
+ var trues = [], falses = [];
+ this.each(function(value, index) {
+ ((iterator || Prototype.K)(value, index) ?
+ trues : falses).push(value);
+ });
+ return [trues, falses];
+ },
+
+ pluck: function(property) {
+ var results = [];
+ this.each(function(value, index) {
+ results.push(value[property]);
+ });
+ return results;
+ },
+
+ reject: function(iterator) {
+ var results = [];
+ this.each(function(value, index) {
+ if (!iterator(value, index))
+ results.push(value);
+ });
+ return results;
+ },
+
+ sortBy: function(iterator) {
+ return this.collect(function(value, index) {
+ return {value: value, criteria: iterator(value, index)};
+ }).sort(function(left, right) {
+ var a = left.criteria, b = right.criteria;
+ return a < b ? -1 : a > b ? 1 : 0;
+ }).pluck('value');
+ },
+
+ toArray: function() {
+ return this.collect(Prototype.K);
+ },
+
+ zip: function() {
+ var iterator = Prototype.K, args = $A(arguments);
+ if (typeof args.last() == 'function')
+ iterator = args.pop();
+
+ var collections = [this].concat(args).map($A);
+ return this.map(function(value, index) {
+ iterator(value = collections.pluck(index));
+ return value;
+ });
+ },
+
+ inspect: function() {
+ return '#<Enumerable:' + this.toArray().inspect() + '>';
+ }
+}
+
+Object.extend(Enumerable, {
+ map: Enumerable.collect,
+ find: Enumerable.detect,
+ select: Enumerable.findAll,
+ member: Enumerable.include,
+ entries: Enumerable.toArray
+});
+var $A = Array.from = function(iterable) {
+ if (!iterable) return [];
+ if (iterable.toArray) {
+ return iterable.toArray();
+ } else {
+ var results = [];
+ for (var i = 0; i < iterable.length; i++)
+ results.push(iterable[i]);
+ return results;
+ }
+}
+
+Object.extend(Array.prototype, Enumerable);
+
+Array.prototype._reverse = Array.prototype.reverse;
+
+Object.extend(Array.prototype, {
+ _each: function(iterator) {
+ for (var i = 0; i < this.length; i++)
+ iterator(this[i]);
+ },
+
+ clear: function() {
+ this.length = 0;
+ return this;
+ },
+
+ first: function() {
+ return this[0];
+ },
+
+ last: function() {
+ return this[this.length - 1];
+ },
+
+ compact: function() {
+ return this.select(function(value) {
+ return value != undefined || value != null;
+ });
+ },
+
+ flatten: function() {
+ return this.inject([], function(array, value) {
+ return array.concat(value.constructor == Array ?
+ value.flatten() : [value]);
+ });
+ },
+
+ without: function() {
+ var values = $A(arguments);
+ return this.select(function(value) {
+ return !values.include(value);
+ });
+ },
+
+ indexOf: function(object) {
+ for (var i = 0; i < this.length; i++)
+ if (this[i] == object) return i;
+ return -1;
+ },
+
+ reverse: function(inline) {
+ return (inline !== false ? this : this.toArray())._reverse();
+ },
+
+ shift: function() {
+ var result = this[0];
+ for (var i = 0; i < this.length - 1; i++)
+ this[i] = this[i + 1];
+ this.length--;
+ return result;
+ },
+
+ inspect: function() {
+ return '[' + this.map(Object.inspect).join(', ') + ']';
+ }
+});
+var Hash = {
+ _each: function(iterator) {
+ for (key in this) {
+ var value = this[key];
+ if (typeof value == 'function') continue;
+
+ var pair = [key, value];
+ pair.key = key;
+ pair.value = value;
+ iterator(pair);
+ }
+ },
+
+ keys: function() {
+ return this.pluck('key');
+ },
+
+ values: function() {
+ return this.pluck('value');
+ },
+
+ merge: function(hash) {
+ return $H(hash).inject($H(this), function(mergedHash, pair) {
+ mergedHash[pair.key] = pair.value;
+ return mergedHash;
+ });
+ },
+
+ toQueryString: function() {
+ return this.map(function(pair) {
+ return pair.map(encodeURIComponent).join('=');
+ }).join('&');
+ },
+
+ inspect: function() {
+ return '#<Hash:{' + this.map(function(pair) {
+ return pair.map(Object.inspect).join(': ');
+ }).join(', ') + '}>';
+ }
+}
+
+function $H(object) {
+ var hash = Object.extend({}, object || {});
+ Object.extend(hash, Enumerable);
+ Object.extend(hash, Hash);
+ return hash;
+}
+ObjectRange = Class.create();
+Object.extend(ObjectRange.prototype, Enumerable);
+Object.extend(ObjectRange.prototype, {
+ initialize: function(start, end, exclusive) {
+ this.start = start;
+ this.end = end;
+ this.exclusive = exclusive;
+ },
+
+ _each: function(iterator) {
+ var value = this.start;
+ do {
+ iterator(value);
+ value = value.succ();
+ } while (this.include(value));
+ },
+
+ include: function(value) {
+ if (value < this.start)
+ return false;
+ if (this.exclusive)
+ return value < this.end;
+ return value <= this.end;
+ }
+});
+
+var $R = function(start, end, exclusive) {
+ return new ObjectRange(start, end, exclusive);
+}
+
+var Ajax = {
+ getTransport: function() {
+ return Try.these(
+ function() {return new ActiveXObject('Msxml2.XMLHTTP')},
+ function() {return new ActiveXObject('Microsoft.XMLHTTP')},
+ function() {return new XMLHttpRequest()}
+ ) || false;
+ },
+
+ activeRequestCount: 0
+}
+
+Ajax.Responders = {
+ responders: [],
+
+ _each: function(iterator) {
+ this.responders._each(iterator);
+ },
+
+ register: function(responderToAdd) {
+ if (!this.include(responderToAdd))
+ this.responders.push(responderToAdd);
+ },
+
+ unregister: function(responderToRemove) {
+ this.responders = this.responders.without(responderToRemove);
+ },
+
+ dispatch: function(callback, request, transport, json) {
+ this.each(function(responder) {
+ if (responder[callback] && typeof responder[callback] == 'function') {
+ try {
+ responder[callback].apply(responder, [request, transport, json]);
+ } catch (e) {}
+ }
+ });
+ }
+};
+
+Object.extend(Ajax.Responders, Enumerable);
+
+Ajax.Responders.register({
+ onCreate: function() {
+ Ajax.activeRequestCount++;
+ },
+
+ onComplete: function() {
+ Ajax.activeRequestCount--;
+ }
+});
+
+Ajax.Base = function() {};
+Ajax.Base.prototype = {
+ setOptions: function(options) {
+ this.options = {
+ method: 'post',
+ asynchronous: true,
+ parameters: ''
+ }
+ Object.extend(this.options, options || {});
+ },
+
+ responseIsSuccess: function() {
+ return this.transport.status == undefined
+ || this.transport.status == 0
+ || (this.transport.status >= 200 && this.transport.status < 300);
+ },
+
+ responseIsFailure: function() {
+ return !this.responseIsSuccess();
+ }
+}
+
+Ajax.Request = Class.create();
+Ajax.Request.Events =
+ ['Uninitialized', 'Loading', 'Loaded', 'Interactive', 'Complete'];
+
+Ajax.Request.prototype = Object.extend(new Ajax.Base(), {
+ initialize: function(url, options) {
+ this.transport = Ajax.getTransport();
+ this.setOptions(options);
+ this.request(url);
+ },
+
+ request: function(url) {
+ var parameters = this.options.parameters || '';
+ if (parameters.length > 0) parameters += '&_=';
+
+ try {
+ this.url = url;
+ if (this.options.method == 'get' && parameters.length > 0)
+ this.url += (this.url.match(/\?/) ? '&' : '?') + parameters;
+
+ Ajax.Responders.dispatch('onCreate', this, this.transport);
+
+ this.transport.open(this.options.method, this.url,
+ this.options.asynchronous);
+
+ if (this.options.asynchronous) {
+ this.transport.onreadystatechange = this.onStateChange.bind(this);
+ setTimeout((function() {this.respondToReadyState(1)}).bind(this), 10);
+ }
+
+ this.setRequestHeaders();
+
+ var body = this.options.postBody ? this.options.postBody : parameters;
+ this.transport.send(this.options.method == 'post' ? body : null);
+
+ } catch (e) {
+ this.dispatchException(e);
+ }
+ },
+
+ setRequestHeaders: function() {
+ var requestHeaders =
+ ['X-Requested-With', 'XMLHttpRequest',
+ 'X-Prototype-Version', Prototype.Version];
+
+ if (this.options.method == 'post') {
+ requestHeaders.push('Content-type',
+ 'application/x-www-form-urlencoded');
+
+ /* Force "Connection: close" for Mozilla browsers to work around
+ * a bug where XMLHttpReqeuest sends an incorrect Content-length
+ * header. See Mozilla Bugzilla #246651.
+ */
+ if (this.transport.overrideMimeType)
+ requestHeaders.push('Connection', 'close');
+ }
+
+ if (this.options.requestHeaders)
+ requestHeaders.push.apply(requestHeaders, this.options.requestHeaders);
+
+ for (var i = 0; i < requestHeaders.length; i += 2)
+ this.transport.setRequestHeader(requestHeaders[i], requestHeaders[i+1]);
+ },
+
+ onStateChange: function() {
+ var readyState = this.transport.readyState;
+ if (readyState != 1)
+ this.respondToReadyState(this.transport.readyState);
+ },
+
+ header: function(name) {
+ try {
+ return this.transport.getResponseHeader(name);
+ } catch (e) {}
+ },
+
+ evalJSON: function() {
+ try {
+ return eval(this.header('X-JSON'));
+ } catch (e) {}
+ },
+
+ evalResponse: function() {
+ try {
+ return eval(this.transport.responseText);
+ } catch (e) {
+ this.dispatchException(e);
+ }
+ },
+
+ respondToReadyState: function(readyState) {
+ var event = Ajax.Request.Events[readyState];
+ var transport = this.transport, json = this.evalJSON();
+
+ if (event == 'Complete') {
+ try {
+ (this.options['on' + this.transport.status]
+ || this.options['on' + (this.responseIsSuccess() ? 'Success' : 'Failure')]
+ || Prototype.emptyFunction)(transport, json);
+ } catch (e) {
+ this.dispatchException(e);
+ }
+
+ if ((this.header('Content-type') || '').match(/^text\/javascript/i))
+ this.evalResponse();
+ }
+
+ try {
+ (this.options['on' + event] || Prototype.emptyFunction)(transport, json);
+ Ajax.Responders.dispatch('on' + event, this, transport, json);
+ } catch (e) {
+ this.dispatchException(e);
+ }
+
+ /* Avoid memory leak in MSIE: clean up the oncomplete event handler */
+ if (event == 'Complete')
+ this.transport.onreadystatechange = Prototype.emptyFunction;
+ },
+
+ dispatchException: function(exception) {
+ (this.options.onException || Prototype.emptyFunction)(this, exception);
+ Ajax.Responders.dispatch('onException', this, exception);
+ }
+});
+
+Ajax.Updater = Class.create();
+
+Object.extend(Object.extend(Ajax.Updater.prototype, Ajax.Request.prototype), {
+ initialize: function(container, url, options) {
+ this.containers = {
+ success: container.success ? $(container.success) : $(container),
+ failure: container.failure ? $(container.failure) :
+ (container.success ? null : $(container))
+ }
+
+ this.transport = Ajax.getTransport();
+ this.setOptions(options);
+
+ var onComplete = this.options.onComplete || Prototype.emptyFunction;
+ this.options.onComplete = (function(transport, object) {
+ this.updateContent();
+ onComplete(transport, object);
+ }).bind(this);
+
+ this.request(url);
+ },
+
+ updateContent: function() {
+ var receiver = this.responseIsSuccess() ?
+ this.containers.success : this.containers.failure;
+ var response = this.transport.responseText;
+
+ if (!this.options.evalScripts)
+ response = response.stripScripts();
+
+ if (receiver) {
+ if (this.options.insertion) {
+ new this.options.insertion(receiver, response);
+ } else {
+ Element.update(receiver, response);
+ }
+ }
+
+ if (this.responseIsSuccess()) {
+ if (this.onComplete)
+ setTimeout(this.onComplete.bind(this), 10);
+ }
+ }
+});
+
+Ajax.PeriodicalUpdater = Class.create();
+Ajax.PeriodicalUpdater.prototype = Object.extend(new Ajax.Base(), {
+ initialize: function(container, url, options) {
+ this.setOptions(options);
+ this.onComplete = this.options.onComplete;
+
+ this.frequency = (this.options.frequency || 2);
+ this.decay = (this.options.decay || 1);
+
+ this.updater = {};
+ this.container = container;
+ this.url = url;
+
+ this.start();
+ },
+
+ start: function() {
+ this.options.onComplete = this.updateComplete.bind(this);
+ this.onTimerEvent();
+ },
+
+ stop: function() {
+ this.updater.onComplete = undefined;
+ clearTimeout(this.timer);
+ (this.onComplete || Prototype.emptyFunction).apply(this, arguments);
+ },
+
+ updateComplete: function(request) {
+ if (this.options.decay) {
+ this.decay = (request.responseText == this.lastText ?
+ this.decay * this.options.decay : 1);
+
+ this.lastText = request.responseText;
+ }
+ this.timer = setTimeout(this.onTimerEvent.bind(this),
+ this.decay * this.frequency * 1000);
+ },
+
+ onTimerEvent: function() {
+ this.updater = new Ajax.Updater(this.container, this.url, this.options);
+ }
+});
+document.getElementsByClassName = function(className, parentElement) {
+ var children = ($(parentElement) || document.body).getElementsByTagName('*');
+ return $A(children).inject([], function(elements, child) {
+ if (child.className.match(new RegExp("(^|\\s)" + className + "(\\s|$)")))
+ elements.push(child);
+ return elements;
+ });
+}
+
+/*--------------------------------------------------------------------------*/
+
+if (!window.Element) {
+ var Element = new Object();
+}
+
+Object.extend(Element, {
+ visible: function(element) {
+ return $(element).style.display != 'none';
+ },
+
+ toggle: function() {
+ for (var i = 0; i < arguments.length; i++) {
+ var element = $(arguments[i]);
+ Element[Element.visible(element) ? 'hide' : 'show'](element);
+ }
+ },
+
+ hide: function() {
+ for (var i = 0; i < arguments.length; i++) {
+ var element = $(arguments[i]);
+ element.style.display = 'none';
+ }
+ },
+
+ show: function() {
+ for (var i = 0; i < arguments.length; i++) {
+ var element = $(arguments[i]);
+ element.style.display = '';
+ }
+ },
+
+ remove: function(element) {
+ element = $(element);
+ element.parentNode.removeChild(element);
+ },
+
+ update: function(element, html) {
+ $(element).innerHTML = html.stripScripts();
+ setTimeout(function() {html.evalScripts()}, 10);
+ },
+
+ getHeight: function(element) {
+ element = $(element);
+ return element.offsetHeight;
+ },
+
+ classNames: function(element) {
+ return new Element.ClassNames(element);
+ },
+
+ hasClassName: function(element, className) {
+ if (!(element = $(element))) return;
+ return Element.classNames(element).include(className);
+ },
+
+ addClassName: function(element, className) {
+ if (!(element = $(element))) return;
+ return Element.classNames(element).add(className);
+ },
+
+ removeClassName: function(element, className) {
+ if (!(element = $(element))) return;
+ return Element.classNames(element).remove(className);
+ },
+
+ // removes whitespace-only text node children
+ cleanWhitespace: function(element) {
+ element = $(element);
+ for (var i = 0; i < element.childNodes.length; i++) {
+ var node = element.childNodes[i];
+ if (node.nodeType == 3 && !/\S/.test(node.nodeValue))
+ Element.remove(node);
+ }
+ },
+
+ empty: function(element) {
+ return $(element).innerHTML.match(/^\s*$/);
+ },
+
+ scrollTo: function(element) {
+ element = $(element);
+ var x = element.x ? element.x : element.offsetLeft,
+ y = element.y ? element.y : element.offsetTop;
+ window.scrollTo(x, y);
+ },
+
+ getStyle: function(element, style) {
+ element = $(element);
+ var value = element.style[style.camelize()];
+ if (!value) {
+ if (document.defaultView && document.defaultView.getComputedStyle) {
+ var css = document.defaultView.getComputedStyle(element, null);
+ value = css ? css.getPropertyValue(style) : null;
+ } else if (element.currentStyle) {
+ value = element.currentStyle[style.camelize()];
+ }
+ }
+
+ if (window.opera && ['left', 'top', 'right', 'bottom'].include(style))
+ if (Element.getStyle(element, 'position') == 'static') value = 'auto';
+
+ return value == 'auto' ? null : value;
+ },
+
+ setStyle: function(element, style) {
+ element = $(element);
+ for (name in style)
+ element.style[name.camelize()] = style[name];
+ },
+
+ getDimensions: function(element) {
+ element = $(element);
+ if (Element.getStyle(element, 'display') != 'none')
+ return {width: element.offsetWidth, height: element.offsetHeight};
+
+ // All *Width and *Height properties give 0 on elements with display none,
+ // so enable the element temporarily
+ var els = element.style;
+ var originalVisibility = els.visibility;
+ var originalPosition = els.position;
+ els.visibility = 'hidden';
+ els.position = 'absolute';
+ els.display = '';
+ var originalWidth = element.clientWidth;
+ var originalHeight = element.clientHeight;
+ els.display = 'none';
+ els.position = originalPosition;
+ els.visibility = originalVisibility;
+ return {width: originalWidth, height: originalHeight};
+ },
+
+ makePositioned: function(element) {
+ element = $(element);
+ var pos = Element.getStyle(element, 'position');
+ if (pos == 'static' || !pos) {
+ element._madePositioned = true;
+ element.style.position = 'relative';
+ // Opera returns the offset relative to the positioning context, when an
+ // element is position relative but top and left have not been defined
+ if (window.opera) {
+ element.style.top = 0;
+ element.style.left = 0;
+ }
+ }
+ },
+
+ undoPositioned: function(element) {
+ element = $(element);
+ if (element._madePositioned) {
+ element._madePositioned = undefined;
+ element.style.position =
+ element.style.top =
+ element.style.left =
+ element.style.bottom =
+ element.style.right = '';
+ }
+ },
+
+ makeClipping: function(element) {
+ element = $(element);
+ if (element._overflow) return;
+ element._overflow = element.style.overflow;
+ if ((Element.getStyle(element, 'overflow') || 'visible') != 'hidden')
+ element.style.overflow = 'hidden';
+ },
+
+ undoClipping: function(element) {
+ element = $(element);
+ if (element._overflow) return;
+ element.style.overflow = element._overflow;
+ element._overflow = undefined;
+ }
+});
+
+var Toggle = new Object();
+Toggle.display = Element.toggle;
+
+/*--------------------------------------------------------------------------*/
+
+Abstract.Insertion = function(adjacency) {
+ this.adjacency = adjacency;
+}
+
+Abstract.Insertion.prototype = {
+ initialize: function(element, content) {
+ this.element = $(element);
+ this.content = content.stripScripts();
+
+ if (this.adjacency && this.element.insertAdjacentHTML) {
+ try {
+ this.element.insertAdjacentHTML(this.adjacency, this.content);
+ } catch (e) {
+ if (this.element.tagName.toLowerCase() == 'tbody') {
+ this.insertContent(this.contentFromAnonymousTable());
+ } else {
+ throw e;
+ }
+ }
+ } else {
+ this.range = this.element.ownerDocument.createRange();
+ if (this.initializeRange) this.initializeRange();
+ this.insertContent([this.range.createContextualFragment(this.content)]);
+ }
+
+ setTimeout(function() {content.evalScripts()}, 10);
+ },
+
+ contentFromAnonymousTable: function() {
+ var div = document.createElement('div');
+ div.innerHTML = '<table><tbody>' + this.content + '</tbody></table>';
+ return $A(div.childNodes[0].childNodes[0].childNodes);
+ }
+}
+
+var Insertion = new Object();
+
+Insertion.Before = Class.create();
+Insertion.Before.prototype = Object.extend(new Abstract.Insertion('beforeBegin'), {
+ initializeRange: function() {
+ this.range.setStartBefore(this.element);
+ },
+
+ insertContent: function(fragments) {
+ fragments.each((function(fragment) {
+ this.element.parentNode.insertBefore(fragment, this.element);
+ }).bind(this));
+ }
+});
+
+Insertion.Top = Class.create();
+Insertion.Top.prototype = Object.extend(new Abstract.Insertion('afterBegin'), {
+ initializeRange: function() {
+ this.range.selectNodeContents(this.element);
+ this.range.collapse(true);
+ },
+
+ insertContent: function(fragments) {
+ fragments.reverse(false).each((function(fragment) {
+ this.element.insertBefore(fragment, this.element.firstChild);
+ }).bind(this));
+ }
+});
+
+Insertion.Bottom = Class.create();
+Insertion.Bottom.prototype = Object.extend(new Abstract.Insertion('beforeEnd'), {
+ initializeRange: function() {
+ this.range.selectNodeContents(this.element);
+ this.range.collapse(this.element);
+ },
+
+ insertContent: function(fragments) {
+ fragments.each((function(fragment) {
+ this.element.appendChild(fragment);
+ }).bind(this));
+ }
+});
+
+Insertion.After = Class.create();
+Insertion.After.prototype = Object.extend(new Abstract.Insertion('afterEnd'), {
+ initializeRange: function() {
+ this.range.setStartAfter(this.element);
+ },
+
+ insertContent: function(fragments) {
+ fragments.each((function(fragment) {
+ this.element.parentNode.insertBefore(fragment,
+ this.element.nextSibling);
+ }).bind(this));
+ }
+});
+
+/*--------------------------------------------------------------------------*/
+
+Element.ClassNames = Class.create();
+Element.ClassNames.prototype = {
+ initialize: function(element) {
+ this.element = $(element);
+ },
+
+ _each: function(iterator) {
+ this.element.className.split(/\s+/).select(function(name) {
+ return name.length > 0;
+ })._each(iterator);
+ },
+
+ set: function(className) {
+ this.element.className = className;
+ },
+
+ add: function(classNameToAdd) {
+ if (this.include(classNameToAdd)) return;
+ this.set(this.toArray().concat(classNameToAdd).join(' '));
+ },
+
+ remove: function(classNameToRemove) {
+ if (!this.include(classNameToRemove)) return;
+ this.set(this.select(function(className) {
+ return className != classNameToRemove;
+ }).join(' '));
+ },
+
+ toString: function() {
+ return this.toArray().join(' ');
+ }
+}
+
+Object.extend(Element.ClassNames.prototype, Enumerable);
+var Field = {
+ clear: function() {
+ for (var i = 0; i < arguments.length; i++)
+ $(arguments[i]).value = '';
+ },
+
+ focus: function(element) {
+ $(element).focus();
+ },
+
+ present: function() {
+ for (var i = 0; i < arguments.length; i++)
+ if ($(arguments[i]).value == '') return false;
+ return true;
+ },
+
+ select: function(element) {
+ $(element).select();
+ },
+
+ activate: function(element) {
+ element = $(element);
+ element.focus();
+ if (element.select)
+ element.select();
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+
+var Form = {
+ serialize: function(form) {
+ var elements = Form.getElements($(form));
+ var queryComponents = new Array();
+
+ for (var i = 0; i < elements.length; i++) {
+ var queryComponent = Form.Element.serialize(elements[i]);
+ if (queryComponent)
+ queryComponents.push(queryComponent);
+ }
+
+ return queryComponents.join('&');
+ },
+
+ getElements: function(form) {
+ form = $(form);
+ var elements = new Array();
+
+ for (tagName in Form.Element.Serializers) {
+ var tagElements = form.getElementsByTagName(tagName);
+ for (var j = 0; j < tagElements.length; j++)
+ elements.push(tagElements[j]);
+ }
+ return elements;
+ },
+
+ getInputs: function(form, typeName, name) {
+ form = $(form);
+ var inputs = form.getElementsByTagName('input');
+
+ if (!typeName && !name)
+ return inputs;
+
+ var matchingInputs = new Array();
+ for (var i = 0; i < inputs.length; i++) {
+ var input = inputs[i];
+ if ((typeName && input.type != typeName) ||
+ (name && input.name != name))
+ continue;
+ matchingInputs.push(input);
+ }
+
+ return matchingInputs;
+ },
+
+ disable: function(form) {
+ var elements = Form.getElements(form);
+ for (var i = 0; i < elements.length; i++) {
+ var element = elements[i];
+ element.blur();
+ element.disabled = 'true';
+ }
+ },
+
+ enable: function(form) {
+ var elements = Form.getElements(form);
+ for (var i = 0; i < elements.length; i++) {
+ var element = elements[i];
+ element.disabled = '';
+ }
+ },
+
+ findFirstElement: function(form) {
+ return Form.getElements(form).find(function(element) {
+ return element.type != 'hidden' && !element.disabled &&
+ ['input', 'select', 'textarea'].include(element.tagName.toLowerCase());
+ });
+ },
+
+ focusFirstElement: function(form) {
+ Field.activate(Form.findFirstElement(form));
+ },
+
+ reset: function(form) {
+ $(form).reset();
+ }
+}
+
+Form.Element = {
+ serialize: function(element) {
+ element = $(element);
+ var method = element.tagName.toLowerCase();
+ var parameter = Form.Element.Serializers[method](element);
+
+ if (parameter) {
+ var key = encodeURIComponent(parameter[0]);
+ if (key.length == 0) return;
+
+ if (parameter[1].constructor != Array)
+ parameter[1] = [parameter[1]];
+
+ return parameter[1].map(function(value) {
+ return key + '=' + encodeURIComponent(value);
+ }).join('&');
+ }
+ },
+
+ getValue: function(element) {
+ element = $(element);
+ var method = element.tagName.toLowerCase();
+ var parameter = Form.Element.Serializers[method](element);
+
+ if (parameter)
+ return parameter[1];
+ }
+}
+
+Form.Element.Serializers = {
+ input: function(element) {
+ switch (element.type.toLowerCase()) {
+ case 'submit':
+ case 'hidden':
+ case 'password':
+ case 'text':
+ return Form.Element.Serializers.textarea(element);
+ case 'checkbox':
+ case 'radio':
+ return Form.Element.Serializers.inputSelector(element);
+ }
+ return false;
+ },
+
+ inputSelector: function(element) {
+ if (element.checked)
+ return [element.name, element.value];
+ },
+
+ textarea: function(element) {
+ return [element.name, element.value];
+ },
+
+ select: function(element) {
+ return Form.Element.Serializers[element.type == 'select-one' ?
+ 'selectOne' : 'selectMany'](element);
+ },
+
+ selectOne: function(element) {
+ var value = '', opt, index = element.selectedIndex;
+ if (index >= 0) {
+ opt = element.options[index];
+ value = opt.value;
+ if (!value && !('value' in opt))
+ value = opt.text;
+ }
+ return [element.name, value];
+ },
+
+ selectMany: function(element) {
+ var value = new Array();
+ for (var i = 0; i < element.length; i++) {
+ var opt = element.options[i];
+ if (opt.selected) {
+ var optValue = opt.value;
+ if (!optValue && !('value' in opt))
+ optValue = opt.text;
+ value.push(optValue);
+ }
+ }
+ return [element.name, value];
+ }
+}
+
+/*--------------------------------------------------------------------------*/
+
+var $F = Form.Element.getValue;
+
+/*--------------------------------------------------------------------------*/
+
+Abstract.TimedObserver = function() {}
+Abstract.TimedObserver.prototype = {
+ initialize: function(element, frequency, callback) {
+ this.frequency = frequency;
+ this.element = $(element);
+ this.callback = callback;
+
+ this.lastValue = this.getValue();
+ this.registerCallback();
+ },
+
+ registerCallback: function() {
+ setInterval(this.onTimerEvent.bind(this), this.frequency * 1000);
+ },
+
+ onTimerEvent: function() {
+ var value = this.getValue();
+ if (this.lastValue != value) {
+ this.callback(this.element, value);
+ this.lastValue = value;
+ }
+ }
+}
+
+Form.Element.Observer = Class.create();
+Form.Element.Observer.prototype = Object.extend(new Abstract.TimedObserver(), {
+ getValue: function() {
+ return Form.Element.getValue(this.element);
+ }
+});
+
+Form.Observer = Class.create();
+Form.Observer.prototype = Object.extend(new Abstract.TimedObserver(), {
+ getValue: function() {
+ return Form.serialize(this.element);
+ }
+});
+
+/*--------------------------------------------------------------------------*/
+
+Abstract.EventObserver = function() {}
+Abstract.EventObserver.prototype = {
+ initialize: function(element, callback) {
+ this.element = $(element);
+ this.callback = callback;
+
+ this.lastValue = this.getValue();
+ if (this.element.tagName.toLowerCase() == 'form')
+ this.registerFormCallbacks();
+ else
+ this.registerCallback(this.element);
+ },
+
+ onElementEvent: function() {
+ var value = this.getValue();
+ if (this.lastValue != value) {
+ this.callback(this.element, value);
+ this.lastValue = value;
+ }
+ },
+
+ registerFormCallbacks: function() {
+ var elements = Form.getElements(this.element);
+ for (var i = 0; i < elements.length; i++)
+ this.registerCallback(elements[i]);
+ },
+
+ registerCallback: function(element) {
+ if (element.type) {
+ switch (element.type.toLowerCase()) {
+ case 'checkbox':
+ case 'radio':
+ Event.observe(element, 'click', this.onElementEvent.bind(this));
+ break;
+ case 'password':
+ case 'text':
+ case 'textarea':
+ case 'select-one':
+ case 'select-multiple':
+ Event.observe(element, 'change', this.onElementEvent.bind(this));
+ break;
+ }
+ }
+ }
+}
+
+Form.Element.EventObserver = Class.create();
+Form.Element.EventObserver.prototype = Object.extend(new Abstract.EventObserver(), {
+ getValue: function() {
+ return Form.Element.getValue(this.element);
+ }
+});
+
+Form.EventObserver = Class.create();
+Form.EventObserver.prototype = Object.extend(new Abstract.EventObserver(), {
+ getValue: function() {
+ return Form.serialize(this.element);
+ }
+});
+if (!window.Event) {
+ var Event = new Object();
+}
+
+Object.extend(Event, {
+ KEY_BACKSPACE: 8,
+ KEY_TAB: 9,
+ KEY_RETURN: 13,
+ KEY_ESC: 27,
+ KEY_LEFT: 37,
+ KEY_UP: 38,
+ KEY_RIGHT: 39,
+ KEY_DOWN: 40,
+ KEY_DELETE: 46,
+
+ element: function(event) {
+ return event.target || event.srcElement;
+ },
+
+ isLeftClick: function(event) {
+ return (((event.which) && (event.which == 1)) ||
+ ((event.button) && (event.button == 1)));
+ },
+
+ pointerX: function(event) {
+ return event.pageX || (event.clientX +
+ (document.documentElement.scrollLeft || document.body.scrollLeft));
+ },
+
+ pointerY: function(event) {
+ return event.pageY || (event.clientY +
+ (document.documentElement.scrollTop || document.body.scrollTop));
+ },
+
+ stop: function(event) {
+ if (event.preventDefault) {
+ event.preventDefault();
+ event.stopPropagation();
+ } else {
+ event.returnValue = false;
+ event.cancelBubble = true;
+ }
+ },
+
+ // find the first node with the given tagName, starting from the
+ // node the event was triggered on; traverses the DOM upwards
+ findElement: function(event, tagName) {
+ var element = Event.element(event);
+ while (element.parentNode && (!element.tagName ||
+ (element.tagName.toUpperCase() != tagName.toUpperCase())))
+ element = element.parentNode;
+ return element;
+ },
+
+ observers: false,
+
+ _observeAndCache: function(element, name, observer, useCapture) {
+ if (!this.observers) this.observers = [];
+ if (element.addEventListener) {
+ this.observers.push([element, name, observer, useCapture]);
+ element.addEventListener(name, observer, useCapture);
+ } else if (element.attachEvent) {
+ this.observers.push([element, name, observer, useCapture]);
+ element.attachEvent('on' + name, observer);
+ }
+ },
+
+ unloadCache: function() {
+ if (!Event.observers) return;
+ for (var i = 0; i < Event.observers.length; i++) {
+ Event.stopObserving.apply(this, Event.observers[i]);
+ Event.observers[i][0] = null;
+ }
+ Event.observers = false;
+ },
+
+ observe: function(element, name, observer, useCapture) {
+ var element = $(element);
+ useCapture = useCapture || false;
+
+ if (name == 'keypress' &&
+ (navigator.appVersion.match(/Konqueror|Safari|KHTML/)
+ || element.attachEvent))
+ name = 'keydown';
+
+ this._observeAndCache(element, name, observer, useCapture);
+ },
+
+ stopObserving: function(element, name, observer, useCapture) {
+ var element = $(element);
+ useCapture = useCapture || false;
+
+ if (name == 'keypress' &&
+ (navigator.appVersion.match(/Konqueror|Safari|KHTML/)
+ || element.detachEvent))
+ name = 'keydown';
+
+ if (element.removeEventListener) {
+ element.removeEventListener(name, observer, useCapture);
+ } else if (element.detachEvent) {
+ element.detachEvent('on' + name, observer);
+ }
+ }
+});
+
+/* prevent memory leaks in IE */
+Event.observe(window, 'unload', Event.unloadCache, false);
+var Position = {
+ // set to true if needed, warning: firefox performance problems
+ // NOT neeeded for page scrolling, only if draggable contained in
+ // scrollable elements
+ includeScrollOffsets: false,
+
+ // must be called before calling withinIncludingScrolloffset, every time the
+ // page is scrolled
+ prepare: function() {
+ this.deltaX = window.pageXOffset
+ || document.documentElement.scrollLeft
+ || document.body.scrollLeft
+ || 0;
+ this.deltaY = window.pageYOffset
+ || document.documentElement.scrollTop
+ || document.body.scrollTop
+ || 0;
+ },
+
+ realOffset: function(element) {
+ var valueT = 0, valueL = 0;
+ do {
+ valueT += element.scrollTop || 0;
+ valueL += element.scrollLeft || 0;
+ element = element.parentNode;
+ } while (element);
+ return [valueL, valueT];
+ },
+
+ cumulativeOffset: function(element) {
+ var valueT = 0, valueL = 0;
+ do {
+ valueT += element.offsetTop || 0;
+ valueL += element.offsetLeft || 0;
+ element = element.offsetParent;
+ } while (element);
+ return [valueL, valueT];
+ },
+
+ positionedOffset: function(element) {
+ var valueT = 0, valueL = 0;
+ do {
+ valueT += element.offsetTop || 0;
+ valueL += element.offsetLeft || 0;
+ element = element.offsetParent;
+ if (element) {
+ p = Element.getStyle(element, 'position');
+ if (p == 'relative' || p == 'absolute') break;
+ }
+ } while (element);
+ return [valueL, valueT];
+ },
+
+ offsetParent: function(element) {
+ if (element.offsetParent) return element.offsetParent;
+ if (element == document.body) return element;
+
+ while ((element = element.parentNode) && element != document.body)
+ if (Element.getStyle(element, 'position') != 'static')
+ return element;
+
+ return document.body;
+ },
+
+ // caches x/y coordinate pair to use with overlap
+ within: function(element, x, y) {
+ if (this.includeScrollOffsets)
+ return this.withinIncludingScrolloffsets(element, x, y);
+ this.xcomp = x;
+ this.ycomp = y;
+ this.offset = this.cumulativeOffset(element);
+
+ return (y >= this.offset[1] &&
+ y < this.offset[1] + element.offsetHeight &&
+ x >= this.offset[0] &&
+ x < this.offset[0] + element.offsetWidth);
+ },
+
+ withinIncludingScrolloffsets: function(element, x, y) {
+ var offsetcache = this.realOffset(element);
+
+ this.xcomp = x + offsetcache[0] - this.deltaX;
+ this.ycomp = y + offsetcache[1] - this.deltaY;
+ this.offset = this.cumulativeOffset(element);
+
+ return (this.ycomp >= this.offset[1] &&
+ this.ycomp < this.offset[1] + element.offsetHeight &&
+ this.xcomp >= this.offset[0] &&
+ this.xcomp < this.offset[0] + element.offsetWidth);
+ },
+
+ // within must be called directly before
+ overlap: function(mode, element) {
+ if (!mode) return 0;
+ if (mode == 'vertical')
+ return ((this.offset[1] + element.offsetHeight) - this.ycomp) /
+ element.offsetHeight;
+ if (mode == 'horizontal')
+ return ((this.offset[0] + element.offsetWidth) - this.xcomp) /
+ element.offsetWidth;
+ },
+
+ clone: function(source, target) {
+ source = $(source);
+ target = $(target);
+ target.style.position = 'absolute';
+ var offsets = this.cumulativeOffset(source);
+ target.style.top = offsets[1] + 'px';
+ target.style.left = offsets[0] + 'px';
+ target.style.width = source.offsetWidth + 'px';
+ target.style.height = source.offsetHeight + 'px';
+ },
+
+ page: function(forElement) {
+ var valueT = 0, valueL = 0;
+
+ var element = forElement;
+ do {
+ valueT += element.offsetTop || 0;
+ valueL += element.offsetLeft || 0;
+
+ // Safari fix
+ if (element.offsetParent==document.body)
+ if (Element.getStyle(element,'position')=='absolute') break;
+
+ } while (element = element.offsetParent);
+
+ element = forElement;
+ do {
+ valueT -= element.scrollTop || 0;
+ valueL -= element.scrollLeft || 0;
+ } while (element = element.parentNode);
+
+ return [valueL, valueT];
+ },
+
+ clone: function(source, target) {
+ var options = Object.extend({
+ setLeft: true,
+ setTop: true,
+ setWidth: true,
+ setHeight: true,
+ offsetTop: 0,
+ offsetLeft: 0
+ }, arguments[2] || {})
+
+ // find page position of source
+ source = $(source);
+ var p = Position.page(source);
+
+ // find coordinate system to use
+ target = $(target);
+ var delta = [0, 0];
+ var parent = null;
+ // delta [0,0] will do fine with position: fixed elements,
+ // position:absolute needs offsetParent deltas
+ if (Element.getStyle(target,'position') == 'absolute') {
+ parent = Position.offsetParent(target);
+ delta = Position.page(parent);
+ }
+
+ // correct by body offsets (fixes Safari)
+ if (parent == document.body) {
+ delta[0] -= document.body.offsetLeft;
+ delta[1] -= document.body.offsetTop;
+ }
+
+ // set position
+ if(options.setLeft) target.style.left = (p[0] - delta[0] + options.offsetLeft) + 'px';
+ if(options.setTop) target.style.top = (p[1] - delta[1] + options.offsetTop) + 'px';
+ if(options.setWidth) target.style.width = source.offsetWidth + 'px';
+ if(options.setHeight) target.style.height = source.offsetHeight + 'px';
+ },
+
+ absolutize: function(element) {
+ element = $(element);
+ if (element.style.position == 'absolute') return;
+ Position.prepare();
+
+ var offsets = Position.positionedOffset(element);
+ var top = offsets[1];
+ var left = offsets[0];
+ var width = element.clientWidth;
+ var height = element.clientHeight;
+
+ element._originalLeft = left - parseFloat(element.style.left || 0);
+ element._originalTop = top - parseFloat(element.style.top || 0);
+ element._originalWidth = element.style.width;
+ element._originalHeight = element.style.height;
+
+ element.style.position = 'absolute';
+ element.style.top = top + 'px';;
+ element.style.left = left + 'px';;
+ element.style.width = width + 'px';;
+ element.style.height = height + 'px';;
+ },
+
+ relativize: function(element) {
+ element = $(element);
+ if (element.style.position == 'relative') return;
+ Position.prepare();
+
+ element.style.position = 'relative';
+ var top = parseFloat(element.style.top || 0) - (element._originalTop || 0);
+ var left = parseFloat(element.style.left || 0) - (element._originalLeft || 0);
+
+ element.style.top = top + 'px';
+ element.style.left = left + 'px';
+ element.style.height = element._originalHeight;
+ element.style.width = element._originalWidth;
+ }
+}
+
+// Safari returns margins on body which is incorrect if the child is absolutely
+// positioned. For performance reasons, redefine Position.cumulativeOffset for
+// KHTML/WebKit only.
+if (/Konqueror|Safari|KHTML/.test(navigator.userAgent)) {
+ Position.cumulativeOffset = function(element) {
+ var valueT = 0, valueL = 0;
+ do {
+ valueT += element.offsetTop || 0;
+ valueL += element.offsetLeft || 0;
+ if (element.offsetParent == document.body)
+ if (Element.getStyle(element, 'position') == 'absolute') break;
+
+ element = element.offsetParent;
+ } while (element);
+
+ return [valueL, valueT];
+ }
+}
\ No newline at end of file
Added: zc.selenium/trunk/src/zc/selenium/resources/scripts/se2html.js
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/scripts/se2html.js 2006-08-29 18:04:40 UTC (rev 69877)
+++ zc.selenium/trunk/src/zc/selenium/resources/scripts/se2html.js 2006-08-29 18:41:08 UTC (rev 69878)
@@ -0,0 +1,63 @@
+/*
+
+This is an experiment in creating a "selenese" parser that drastically
+cuts down on the line noise associated with writing tests in HTML.
+
+The 'parse' function will accept the follow sample commands.
+
+test-cases:
+ //comment
+ command "param"
+ command "param" // comment
+ command "param" "param2"
+ command "param" "param2" // this is a comment
+
+TODO:
+1) Deal with multiline parameters
+2) Escape quotes properly
+3) Determine whether this should/will become the "preferred" syntax
+ for delivered Selenium self-test scripts
+*/
+
+
+function separse(doc) {
+ // Get object
+ script = doc.getElementById('testcase')
+ // Split into lines
+ lines = script.text.split('\n');
+
+
+ var command_pattern = / *(\w+) *"([^"]*)" *(?:"([^"]*)"){0,1}(?: *(\/\/ *.+))*/i;
+ var comment_pattern = /^ *(\/\/ *.+)/
+
+ // Regex each line into selenium command and convert into table row.
+ // eg. "<command> <quote> <quote> <comment>"
+ var new_test_source = '';
+ var new_line = '';
+ for (var x=0; x < lines.length; x++) {
+ result = lines[x].match(command_pattern);
+ if (result != null) {
+ new_line = "<tr><td>" + (result[1] || ' ') + "</td>" +
+ "<td>" + (result[2] || ' ') + "</td>" +
+ "<td>" + (result[3] || ' ') + "</td>" +
+ "<td>" + (result[4] || ' ') + "</td></tr>\n";
+ new_test_source += new_line;
+ }
+ result = lines[x].match(comment_pattern);
+ if (result != null) {
+ new_line = '<tr><td rowspan="1" colspan="4">' +
+ (result[1] || ' ') +
+ '</td></tr>';
+ new_test_source += new_line;
+ }
+ }
+
+ // Create HTML Table
+ body = doc.body
+ body.innerHTML += "<table class='selenium' id='testtable'>"+
+ new_test_source +
+ "</table>";
+
+}
+
+
Modified: zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-api.js
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-api.js 2006-08-29 18:04:40 UTC (rev 69877)
+++ zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-api.js 2006-08-29 18:41:08 UTC (rev 69878)
@@ -15,7 +15,7 @@
*
*/
-storedVars = new Object();
+var storedVars = new Object();
function Selenium(browserbot) {
/**
@@ -84,6 +84,15 @@
* </ul>
*
* </dd>
+ *
+ * <dt><strong>css</strong>=<em>cssSelectorSyntax</em></dt>
+ * <dd>Select the element using css selectors. Please refer to <a href="http://www.w3.org/TR/REC-CSS2/selector.html">CSS2 selectors</a>, <a href="http://www.w3.org/TR/2001/CR-css3-selectors-20011113/">CSS3 selectors</a> for more information. You can also check the TestCssLocators test in the selenium test suite for an example of usage, which is included in the downloaded selenium core package.
+ * <ul class="first last simple">
+ * <li>css=a[href="#id3"]</li>
+ * <li>css=span#firstChild + span</li>
+ * </ul>
+ * </dd>
+ * <dd>Currently the css selector locator supports all css1, css2 and css3 selectors except namespace in css3, some pseudo classes(:nth-of-type, :nth-last-of-type, :first-of-type, :last-of-type, :only-of-type, :visited, :hover, :active, :focus, :indeterminate) and pseudo elements(::first-line, ::first-letter, ::selection, ::before, ::after). </dd>
* </dl>
* </blockquote>
* <p>
@@ -164,12 +173,31 @@
* Clicks on a link, button, checkbox or radio button. If the click action
* causes a new page to load (like a link usually does), call
* waitForPageToLoad.
- *
+ *
* @param locator an element locator
- *
+ *
*/
+ var element = this.page().findElement(locator);
+ this.page().clickElement(element);
+};
+
+Selenium.prototype.doClickAt = function(locator, coordString) {
+ /**
+ * Clicks on a link, button, checkbox or radio button. If the click action
+ * causes a new page to load (like a link usually does), call
+ * waitForPageToLoad.
+ *
+ * Beware of http://jira.openqa.org/browse/SEL-280, which will lead some event handlers to
+ * get null event arguments. Read the bug for more details, including a workaround.
+ *
+ * @param locator an element locator
+ * @param coordString specifies the x,y position (i.e. - 10,20) of the mouse
+ * event relative to the element returned by the locator.
+ *
+ */
var element = this.page().findElement(locator);
- this.page().clickElement(element);
+ var clientXY = getClientXY(element, coordString)
+ this.page().clickElement(element, clientXY[0], clientXY[1]);
};
Selenium.prototype.doFireEvent = function(locator, eventName) {
@@ -220,6 +248,25 @@
triggerKeyEvent(element, 'keyup', keycode, true);
};
+function getClientXY(element, coordString) {
+ // Parse coordString
+ var coords = null;
+ var x;
+ var y;
+ if (coordString) {
+ coords = coordString.split(/,/);
+ x = Number(coords[0]);
+ y = Number(coords[1]);
+ }
+ else {
+ x = y = 0;
+ }
+
+ // Get position of element,
+ // Return 2 item array with clientX and clientY
+ return [Selenium.prototype.getElementPositionLeft(element) + x, Selenium.prototype.getElementPositionTop(element) + y];
+}
+
Selenium.prototype.doMouseOver = function(locator) {
/**
* Simulates a user hovering a mouse over the specified element.
@@ -230,17 +277,104 @@
triggerMouseEvent(element, 'mouseover', true);
};
+Selenium.prototype.doMouseOut = function(locator) {
+ /**
+ * Simulates a user moving the mouse pointer away from the specified element.
+ *
+ * @param locator an <a href="#locators">element locator</a>
+ */
+ var element = this.page().findElement(locator);
+ triggerMouseEvent(element, 'mouseout', true);
+};
+
Selenium.prototype.doMouseDown = function(locator) {
/**
* Simulates a user pressing the mouse button (without releasing it yet) on
* the specified element.
- *
+ *
* @param locator an <a href="#locators">element locator</a>
*/
+ var element = this.page().findElement(locator);
+ triggerMouseEvent(element, 'mousedown', true);
+};
+
+Selenium.prototype.doMouseDownAt = function(locator, coordString) {
+ /**
+ * Simulates a user pressing the mouse button (without releasing it yet) on
+ * the specified element.
+ *
+ * Beware of http://jira.openqa.org/browse/SEL-280, which will lead some event handlers to
+ * get null event arguments. Read the bug for more details, including a workaround.
+ *
+ * @param locator an <a href="#locators">element locator</a>
+ * @param coordString specifies the x,y position (i.e. - 10,20) of the mouse
+ * event relative to the element returned by the locator.
+ */
var element = this.page().findElement(locator);
- triggerMouseEvent(element, 'mousedown', true);
+ var clientXY = getClientXY(element, coordString)
+
+ triggerMouseEvent(element, 'mousedown', true, clientXY[0], clientXY[1]);
};
+Selenium.prototype.doMouseUp = function(locator) {
+ /**
+ * Simulates a user pressing the mouse button (without releasing it yet) on
+ * the specified element.
+ *
+ * @param locator an <a href="#locators">element locator</a>
+ */
+ var element = this.page().findElement(locator);
+ triggerMouseEvent(element, 'mouseup', true);
+};
+
+Selenium.prototype.doMouseUpAt = function(locator, coordString) {
+ /**
+ * Simulates a user pressing the mouse button (without releasing it yet) on
+ * the specified element.
+ *
+ * Beware of http://jira.openqa.org/browse/SEL-280, which will lead some event handlers to
+ * get null event arguments. Read the bug for more details, including a workaround.
+ *
+ * @param locator an <a href="#locators">element locator</a>
+ * @param coordString specifies the x,y position (i.e. - 10,20) of the mouse
+ * event relative to the element returned by the locator.
+ */
+ var element = this.page().findElement(locator);
+ var clientXY = getClientXY(element, coordString)
+
+ triggerMouseEvent(element, 'mouseup', true, clientXY[0], clientXY[1]);
+};
+
+Selenium.prototype.doMouseMove = function(locator) {
+ /**
+ * Simulates a user pressing the mouse button (without releasing it yet) on
+ * the specified element.
+ *
+ * @param locator an <a href="#locators">element locator</a>
+ */
+ var element = this.page().findElement(locator);
+ triggerMouseEvent(element, 'mousemove', true);
+};
+
+Selenium.prototype.doMouseMoveAt = function(locator, coordString) {
+ /**
+ * Simulates a user pressing the mouse button (without releasing it yet) on
+ * the specified element.
+ *
+ * Beware of http://jira.openqa.org/browse/SEL-280, which will lead some event handlers to
+ * get null event arguments. Read the bug for more details, including a workaround.
+ *
+ * @param locator an <a href="#locators">element locator</a>
+ * @param coordString specifies the x,y position (i.e. - 10,20) of the mouse
+ * event relative to the element returned by the locator.
+ */
+
+ var element = this.page().findElement(locator);
+ var clientXY = getClientXY(element, coordString)
+
+ triggerMouseEvent(element, 'mousemove', true, clientXY[0], clientXY[1]);
+};
+
Selenium.prototype.doType = function(locator, value) {
/**
* Sets the value of an input field, as though you typed it in.
@@ -282,7 +416,7 @@
this.findToggleButton(locator).checked = false;
};
-Selenium.prototype.doSelect = function(locator, optionLocator) {
+Selenium.prototype.doSelect = function(selectLocator, optionLocator) {
/**
* Select an option from a drop-down using an option locator.
*
@@ -328,10 +462,10 @@
* </p>
*
*
- * @param locator an <a href="#locators">element locator</a> identifying a drop-down menu
+ * @param selectLocator an <a href="#locators">element locator</a> identifying a drop-down menu
* @param optionLocator an option locator (a label by default)
*/
- var element = this.page().findElement(locator);
+ var element = this.page().findElement(selectLocator);
if (!("options" in element)) {
throw new SeleniumError("Specified element is not a Select (has no options)");
}
@@ -426,6 +560,94 @@
this.browserbot.selectWindow(windowID);
};
+Selenium.prototype.doSelectFrame = function(locator) {
+ /**
+ * NOT IMPLEMENTED YET:
+ * Selects a frame within the current window. (You may invoke this command
+ * multiple times to select nested frames.) To select the parent frame, use
+ * "relative=parent" as a locator; to select the top frame, use "relative=top".
+ *
+ * <p>You may also use a DOM expression to identify the frame you want directly,
+ * like this: <code>dom=frames["main"].frames["subframe"]</code></p>
+ *
+ * @param locator an <a href="#locators">element locator</a> identifying a frame or iframe
+ */
+ throw new SeleniumError("NOT IMPLEMENTED YET");
+};
+
+Selenium.prototype.getLogMessages = function() {
+ /**
+ * Return the contents of the log.
+ *
+ * <p>This is a placeholder intended to make the code generator make this API
+ * available to clients. The selenium server will intercept this call, however,
+ * and return its recordkeeping of log messages since the last call to this API.
+ * Thus this code in JavaScript will never be called.</p>
+ *
+ * <p>The reason I opted for a servercentric solution is to be able to support
+ * multiple frames served from different domains, which would break a
+ * centralized JavaScript logging mechanism under some conditions.</p>
+ *
+ * @return string all log messages seen since the last call to this API
+ */
+ return "getLogMessages should be implemented in the selenium server";
+};
+
+
+Selenium.prototype.getWhetherThisFrameMatchFrameExpression = function(currentFrameString, target) {
+ /**
+ * Determine whether current/locator identify the frame containing this running code.
+ *
+ * <p>This is useful in proxy injection mode, where this code runs in every
+ * browser frame and window, and sometimes the selenium server needs to identify
+ * the "current" frame. In this case, when the test calls selectFrame, this
+ * routine is called for each frame to figure out which one has been selected.
+ * The selected frame will return true, while all others will return false.</p>
+ *
+ * @param currentFrameString starting frame
+ * @param target new frame (which might be relative to the current one)
+ * @return boolean true if the new frame is this code's window
+ */
+ var isDom = false;
+ if (target.indexOf("dom=")==0) {
+ target = target.substr(4);
+ isDom = true;
+ }
+ var t;
+ try {
+ eval("t=" + currentFrameString + "." + target);
+ } catch (e) {
+ }
+ var autWindow = this.browserbot.getCurrentWindow();
+ if (t!=null) {
+ if (t.window==autWindow) {
+ return true;
+ }
+ return false;
+ }
+ if (isDom) {
+ return false;
+ }
+ var currentFrame;
+ eval("currentFrame=" + currentFrameString);
+ if (target == "relative=up") {
+ if (currentFrame.window.parent==autWindow) {
+ return true;
+ }
+ return false;
+ }
+ if (target == "relative=top") {
+ if (currentFrame.window.top==autWindow) {
+ return true;
+ }
+ return false;
+ }
+ if (autWindow.name==target && currentFrame.window==autWindow.parent) {
+ return true;
+ }
+ return false;
+};
+
Selenium.prototype.doWaitForPopUp = function(windowID, timeout) {
/**
* Waits for a popup window to appear and load up.
@@ -437,7 +659,7 @@
throw new SeleniumError("Timeout is not a number: " + timeout);
}
- testLoop.waitForCondition = function () {
+ currentTest.waitForCondition = function () {
var targetWindow = selenium.browserbot.getTargetWindow(windowID);
if (!targetWindow) return false;
if (!targetWindow.location) return false;
@@ -448,11 +670,13 @@
return true;
};
- testLoop.waitForConditionStart = new Date().getTime();
- testLoop.waitForConditionTimeout = timeout;
+ currentTest.waitForConditionStart = new Date().getTime();
+ currentTest.waitForConditionTimeout = timeout;
}
+Selenium.prototype.doWaitForPopUp.dontCheckAlertsAndConfirms = true;
+
Selenium.prototype.doChooseCancelOnNextConfirmation = function() {
/**
* By default, Selenium's overridden window.confirm() function will
@@ -612,7 +836,7 @@
return this.browserbot.getNextPrompt();
};
-Selenium.prototype.getAbsoluteLocation = function() {
+Selenium.prototype.getLocation = function() {
/** Gets the absolute URL of the current page.
*
* @return string the absolute URL of the current page
@@ -620,33 +844,6 @@
return this.page().location;
};
-Selenium.prototype.isLocation = function(expectedLocation) {
- /**
- * Verify the location of the current page ends with the expected location.
- * If an URL querystring is provided, this is checked as well.
- * @param expectedLocation the location to match
- * @return boolean true if the location matches, false otherwise
- */
- var docLocation = this.page().location;
- var actualPath = docLocation.pathname;
- if (docLocation.protocol == "file:") {
- // replace backslashes with forward slashes, so IE can run off the file system
- var actualPath = docLocation.pathname.replace(/\\/g, "/");
- }
- var searchPos = expectedLocation.lastIndexOf('?');
-
- if (searchPos == -1) {
- return PatternMatcher.matches('*' + expectedLocation, actualPath)
- }
- else {
- var expectedPath = expectedLocation.substring(0, searchPos);
- return PatternMatcher.matches('*' + expectedPath, actualPath)
-
- var expectedQueryString = expectedLocation.substring(searchPos);
- return PatternMatcher.matches(expectedQueryString, docLocation.search)
- }
-};
-
Selenium.prototype.getTitle = function() {
/** Gets the title of the current page.
*
@@ -709,17 +906,20 @@
* @return string the results of evaluating the snippet
*/
try {
- return eval(script);
+ var result = eval(script);
+ // Selenium RC doesn't allow returning null
+ if (null == result) return "null";
+ return result;
} catch (e) {
throw new SeleniumError("Threw an exception: " + e.message);
}
};
-Selenium.prototype.getChecked = function(locator) {
+Selenium.prototype.isChecked = function(locator) {
/**
* Gets whether a toggle-button (checkbox/radio) is checked. Fails if the specified element doesn't exist or isn't a toggle-button.
* @param locator an <a href="#locators">element locator</a> pointing to a checkbox or radio button
- * @return string either "true" or "false" depending on whether the checkbox is checked
+ * @return boolean true if the checkbox is checked, false otherwise
*/
var element = this.page().findElement(locator);
if (element.checked == null) {
@@ -761,55 +961,140 @@
actualContent = getText(table.rows[row].cells[col]);
return actualContent.trim();
}
+ return null;
};
-Selenium.prototype.isSelected = function(locator, optionLocator) {
- /**
- * Verifies that the selected option of a drop-down satisfies the optionSpecifier.
- *
- * <p>See the select command for more information about option locators.</p>
- *
- * @param locator an <a href="#locators">element locator</a>
- * @param optionLocator an option locator, typically just an option label (e.g. "John Smith")
- * @return boolean true if the selected option matches the locator, false otherwise
+Selenium.prototype.getSelectedLabels = function(selectLocator) {
+ /** Gets all option labels (visible text) for selected options in the specified select or multi-select element.
+ *
+ * @param selectLocator an <a href="#locators">element locator</a> identifying a drop-down menu
+ * @return string[] an array of all selected option labels in the specified select drop-down
*/
- var element = this.page().findElement(locator);
- var locator = this.optionLocatorFactory.fromLocatorString(optionLocator);
- if (element.selectedIndex == -1)
- {
- return false;
- }
- return locator.isSelected(element);
-};
+ return this.findSelectedOptionProperties(selectLocator, "text").join(",");
+}
-Selenium.prototype.getSelectedOptions = function(locator) {
- /** Gets all option labels for selected options in the specified select or multi-select element.
+Selenium.prototype.getSelectedLabel = function(selectLocator) {
+ /** Gets option label (visible text) for selected option in the specified select element.
*
- * @param locator an <a href="#locators">element locator</a>
- * @return string[] an array of all option labels in the specified select drop-down
+ * @param selectLocator an <a href="#locators">element locator</a> identifying a drop-down menu
+ * @return string the selected option label in the specified select drop-down
*/
+ return this.findSelectedOptionProperty(selectLocator, "text");
+}
+
+Selenium.prototype.getSelectedValues = function(selectLocator) {
+ /** Gets all option values (value attributes) for selected options in the specified select or multi-select element.
+ *
+ * @param selectLocator an <a href="#locators">element locator</a> identifying a drop-down menu
+ * @return string[] an array of all selected option values in the specified select drop-down
+ */
+ return this.findSelectedOptionProperties(selectLocator, "value").join(",");
+}
+
+Selenium.prototype.getSelectedValue = function(selectLocator) {
+ /** Gets option value (value attribute) for selected option in the specified select element.
+ *
+ * @param selectLocator an <a href="#locators">element locator</a> identifying a drop-down menu
+ * @return string the selected option value in the specified select drop-down
+ */
+ return this.findSelectedOptionProperty(selectLocator, "value");
+}
+
+Selenium.prototype.getSelectedIndexes = function(selectLocator) {
+ /** Gets all option indexes (option number, starting at 0) for selected options in the specified select or multi-select element.
+ *
+ * @param selectLocator an <a href="#locators">element locator</a> identifying a drop-down menu
+ * @return string[] an array of all selected option indexes in the specified select drop-down
+ */
+ return this.findSelectedOptionProperties(selectLocator, "index").join(",");
+}
+
+Selenium.prototype.getSelectedIndex = function(selectLocator) {
+ /** Gets option index (option number, starting at 0) for selected option in the specified select element.
+ *
+ * @param selectLocator an <a href="#locators">element locator</a> identifying a drop-down menu
+ * @return string the selected option index in the specified select drop-down
+ */
+ return this.findSelectedOptionProperty(selectLocator, "index");
+}
+
+Selenium.prototype.getSelectedIds = function(selectLocator) {
+ /** Gets all option element IDs for selected options in the specified select or multi-select element.
+ *
+ * @param selectLocator an <a href="#locators">element locator</a> identifying a drop-down menu
+ * @return string[] an array of all selected option IDs in the specified select drop-down
+ */
+ return this.findSelectedOptionProperties(selectLocator, "id").join(",");
+}
+
+Selenium.prototype.getSelectedId = function(selectLocator) {
+ /** Gets option element ID for selected option in the specified select element.
+ *
+ * @param selectLocator an <a href="#locators">element locator</a> identifying a drop-down menu
+ * @return string the selected option ID in the specified select drop-down
+ */
+ return this.findSelectedOptionProperty(selectLocator, "id");
+}
+
+Selenium.prototype.isSomethingSelected = function(selectLocator) {
+ /** Determines whether some option in a drop-down menu is selected.
+ *
+ * @param selectLocator an <a href="#locators">element locator</a> identifying a drop-down menu
+ * @return boolean true if some option has been selected, false otherwise
+ */
+ var element = this.page().findElement(selectLocator);
+ if (!("options" in element)) {
+ throw new SeleniumError("Specified element is not a Select (has no options)");
+ }
+
+ var selectedOptions = [];
+
+ for (var i = 0; i < element.options.length; i++) {
+ if (element.options[i].selected)
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+Selenium.prototype.findSelectedOptionProperties = function(locator, property) {
var element = this.page().findElement(locator);
+ if (!("options" in element)) {
+ throw new SeleniumError("Specified element is not a Select (has no options)");
+ }
var selectedOptions = [];
for (var i = 0; i < element.options.length; i++) {
if (element.options[i].selected)
{
- var option = element.options[i].text.replace(/,/g, "\\,");
- selectedOptions.push(option);
+ var propVal = element.options[i][property];
+ if (propVal.replace) {
+ propVal.replace(/,/g, "\\,");
+ }
+ selectedOptions.push(propVal);
}
}
- return selectedOptions.join(",");
+ if (selectedOptions.length == 0) Assert.fail("No option selected");
+ return selectedOptions;
+}
+Selenium.prototype.findSelectedOptionProperty = function(locator, property) {
+ var selectedOptions = this.findSelectedOptionProperties(locator, property);
+ if (selectedOptions.length > 1) {
+ Assert.fail("More than one selected option!");
+ }
+ return selectedOptions[0];
}
-Selenium.prototype.getSelectOptions = function(locator) {
+Selenium.prototype.getSelectOptions = function(selectLocator) {
/** Gets all option labels in the specified select drop-down.
*
- * @param locator an <a href="#locators">element locator</a>
+ * @param selectLocator an <a href="#locators">element locator</a> identifying a drop-down menu
* @return string[] an array of all option labels in the specified select drop-down
*/
- var element = this.page().findElement(locator);
+ var element = this.page().findElement(selectLocator);
var selectOptions = [];
@@ -825,6 +1110,10 @@
Selenium.prototype.getAttribute = function(attributeLocator) {
/**
* Gets the value of an element attribute.
+ *
+ * Beware of http://jira.openqa.org/browse/SEL-280, which will lead some event handlers to
+ * get null event arguments. Read the bug for more details, including a workaround.
+ *
* @param attributeLocator an element locator followed by an @ sign and then the name of the attribute, e.g. "foo at bar"
* @return string the value of the specified attribute
*/
@@ -844,10 +1133,18 @@
var allText = this.page().bodyText();
if(allText == "") {
- Assert.fail("Page text not found");
+ // used to assert that allText wasn't empty, but in fact it will be empty if we are in a frameset;
+ // so don't throw an error:
+ return false;
} else {
var patternMatcher = new PatternMatcher(pattern);
+ if (patternMatcher.strategy == PatternMatcher.strategies.exact) {
+ pattern = pattern.replace(/^exact:/, "");
+ return new String(allText).indexOf(pattern) != -1;
+ }
+
if (patternMatcher.strategy == PatternMatcher.strategies.glob) {
+ pattern = pattern.replace(/^glob:/, "");
patternMatcher.matcher = new PatternMatcher.strategies.globContains(pattern);
}
return patternMatcher.matches(allText);
@@ -968,6 +1265,151 @@
return this.page().getAllFields();
};
+Selenium.prototype._getTestAppParentOfAllWindows = function() {
+ /** Returns the IDs of all input fields on the page.
+ *
+ * <p>If a given field has no ID, it will appear as "" in this array.</p>
+ *
+ * @return string[] the IDs of all field on the page
+ */
+ var testAppParentOfAllWindows;
+ if (this.browserbot.getCurrentWindow().opener!=null) {
+ return this.browserbot.getCurrentWindow().opener;
+ }
+ return testAppParentOfAllWindows = this.browserbot.getCurrentWindow();
+};
+
+Selenium.prototype.getAttributeFromAllWindows = function(attributeName) {
+ /** Returns every instance of some attribute from all known windows.
+ *
+ * @param attributeName name of an attribute on the windows
+ * @return string[] the set of values of this attribute from all known windows.
+ */
+ var attributes = new Array();
+ var testAppParentOfAllWindows = this._getTestAppParentOfAllWindows();
+ attributes.push(eval("testAppParentOfAllWindows." + attributeName));
+ var selenium = testAppParentOfAllWindows.selenium==null ? testAppParentOfAllWindows.parent.selenium : testAppParentOfAllWindows.selenium;
+ for (windowName in selenium.browserbot.openedWindows)
+ {
+ attributes.push(eval("selenium.browserbot.openedWindows[windowName]." + attributeName));
+ }
+ return attributes;
+};
+
+Selenium.prototype.findWindow = function(soughtAfterWindowPropertyValue) {
+ var testAppParentOfAllWindows = this._getTestAppParentOfAllWindows();
+ var targetPropertyName = "name";
+ if (soughtAfterWindowPropertyValue.match("^title=")) {
+ targetPropertyName = "document.title";
+ soughtAfterWindowPropertyValue = soughtAfterWindowPropertyValue.replace(/^title=/, "");
+ }
+ else {
+ // matching "name":
+ // If we are not in proxy injection mode, then the top-level test window will be named myiframe.
+ // But as far as the interface goes, we are expected to match a blank string to this window, if
+ // we are searching with respect to the widow name.
+ // So make a special case so that this logic will work:
+ if (PatternMatcher.matches(soughtAfterWindowPropertyValue, "")) {
+ return testAppParentOfAllWindows;
+ }
+ }
+
+ if (PatternMatcher.matches(soughtAfterWindowPropertyValue, eval("testAppParentOfAllWindows." + targetPropertyName))) {
+ return testAppParentOfAllWindows;
+ }
+ for (windowName in selenium.browserbot.openedWindows) {
+ var openedWindow = selenium.browserbot.openedWindows[windowName];
+ if (PatternMatcher.matches(soughtAfterWindowPropertyValue, eval("openedWindow." + targetPropertyName))) {
+ return openedWindow;
+ }
+ }
+ throw new SeleniumError("could not find window with property " + targetPropertyName + " matching " + soughtAfterWindowPropertyValue);
+};
+
+Selenium.prototype.doDragdrop = function(locator, movementsString) {
+ /** Drags an element a certain distance and then drops it
+ * Beware of http://jira.openqa.org/browse/SEL-280, which will lead some event handlers to
+ * get null event arguments. Read the bug for more details, including a workaround.
+ *
+ * @param movementsString offset in pixels from the current location to which the element should be moved, e.g., "+70,-300"
+ * @param locator an element locator
+ */
+ var element = this.page().findElement(locator);
+ var clientStartXY = getClientXY(element)
+ var clientStartX = clientStartXY[0];
+ var clientStartY = clientStartXY[1];
+
+ var movements = movementsString.split(/,/);
+ var movementX = Number(movements[0]);
+ var movementY = Number(movements[1]);
+
+ var clientFinishX = ((clientStartX + movementX) < 0) ? 0 : (clientStartX + movementX);
+ var clientFinishY = ((clientStartY + movementY) < 0) ? 0 : (clientStartY + movementY);
+
+ var movementXincrement = (movementX > 0) ? 1 : -1;
+ var movementYincrement = (movementY > 0) ? 1 : -1;
+
+ triggerMouseEvent(element, 'mousedown', true, clientStartX, clientStartY);
+ var clientX = clientStartX;
+ var clientY = clientStartY;
+ while ((clientX != clientFinishX) || (clientY != clientFinishY)) {
+ if (clientX != clientFinishX) {
+ clientX += movementXincrement;
+ }
+ if (clientY != clientFinishY) {
+ clientY += movementYincrement;
+ }
+ triggerMouseEvent(element, 'mousemove', true, clientX, clientY);
+ }
+ triggerMouseEvent(element, 'mouseup', true, clientFinishX, clientFinishY);
+};
+
+Selenium.prototype.doWindowFocus = function(windowName) {
+/** Gives focus to a window
+ *
+ * @param windowName name of the window to be given focus
+ */
+ this.findWindow(windowName).focus();
+};
+
+
+Selenium.prototype.doWindowMaximize = function(windowName) {
+/** Resize window to take up the entire screen
+ *
+ * @param windowName name of the window to be enlarged
+ */
+ var window = this.findWindow(windowName);
+ if (window!=null && window.screen) {
+ window.moveTo(0,0);
+ window.outerHeight = screen.availHeight;
+ window.outerWidth = screen.availWidth;
+ }
+};
+
+Selenium.prototype.getAllWindowIds = function() {
+ /** Returns the IDs of all windows that the browser knows about.
+ *
+ * @return string[] the IDs of all windows that the browser knows about.
+ */
+ return this.getAttributeFromAllWindows("id");
+};
+
+Selenium.prototype.getAllWindowNames = function() {
+ /** Returns the names of all windows that the browser knows about.
+ *
+ * @return string[] the names of all windows that the browser knows about.
+ */
+ return this.getAttributeFromAllWindows("name");
+};
+
+Selenium.prototype.getAllWindowTitles = function() {
+ /** Returns the titles of all windows that the browser knows about.
+ *
+ * @return string[] the titles of all windows that the browser knows about.
+ */
+ return this.getAttributeFromAllWindows("document.title");
+};
+
Selenium.prototype.getHtmlSource = function() {
/** Returns the entire HTML source between the opening and
* closing "html" tags.
@@ -977,7 +1419,214 @@
return this.page().currentDocument.getElementsByTagName("html")[0].innerHTML;
};
+Selenium.prototype.doSetCursorPosition = function(locator, position) {
+ /**
+ * Moves the text cursor to the specified position in the given input element or textarea.
+ * This method will fail if the specified element isn't an input element or textarea.
+ *
+ * @param locator an <a href="#locators">element locator</a> pointing to an input element or textarea
+ * @param position the numerical position of the cursor in the field; position should be 0 to move the position to the beginning of the field. You can also set the cursor to -1 to move it to the end of the field.
+ */
+ var element = this.page().findElement(locator);
+ if (element.value == undefined) {
+ Assert.fail("Element " + locator + " is not an input.");
+ }
+ if (position == -1) {
+ position = element.value.length;
+ }
+
+ if( element.setSelectionRange && !browserVersion.isOpera) {
+ element.focus();
+ element.setSelectionRange(/*start*/position,/*end*/position);
+ }
+ else if( element.createTextRange ) {
+ triggerEvent(element, 'focus', false);
+ var range = element.createTextRange();
+ range.collapse(true);
+ range.moveEnd('character',position);
+ range.moveStart('character',position);
+ range.select();
+ }
+}
+Selenium.prototype.getElementPositionLeft = function(locator) {
+ /**
+ * Retrieves the horizontal position of an element
+ *
+ * @param locator an <a href="#locators">element locator</a> pointing to an element OR an element itself
+ * @return number of pixels from the edge of the frame.
+ */
+ var element;
+ if ("string"==typeof locator) {
+ element = this.page().findElement(locator);
+ }
+ else {
+ element = locator;
+ }
+ var x = element.offsetLeft;
+ var elementParent = element.offsetParent;
+
+ while (elementParent != null)
+ {
+ if(document.all)
+ {
+ if( (elementParent.tagName != "TABLE") && (elementParent.tagName != "BODY") )
+ {
+ x += elementParent.clientLeft;
+ }
+ }
+ else // Netscape/DOM
+ {
+ if(elementParent.tagName == "TABLE")
+ {
+ var parentBorder = parseInt(elementParent.border);
+ if(isNaN(parentBorder))
+ {
+ var parentFrame = elementParent.getAttribute('frame');
+ if(parentFrame != null)
+ {
+ x += 1;
+ }
+ }
+ else if(parentBorder > 0)
+ {
+ x += parentBorder;
+ }
+ }
+ }
+ x += elementParent.offsetLeft;
+ elementParent = elementParent.offsetParent;
+ }
+ return x;
+};
+
+Selenium.prototype.getElementPositionTop = function(locator) {
+ /**
+ * Retrieves the vertical position of an element
+ *
+ * @param locator an <a href="#locators">element locator</a> pointing to an element OR an element itself
+ * @return number of pixels from the edge of the frame.
+ */
+ var element;
+ if ("string"==typeof locator) {
+ element = this.page().findElement(locator);
+ }
+ else {
+ element = locator;
+ }
+
+ var y = 0;
+
+ while (element != null)
+ {
+ if(document.all)
+ {
+ if( (element.tagName != "TABLE") && (element.tagName != "BODY") )
+ {
+ y += element.clientTop;
+ }
+ }
+ else // Netscape/DOM
+ {
+ if(element.tagName == "TABLE")
+ {
+ var parentBorder = parseInt(element.border);
+ if(isNaN(parentBorder))
+ {
+ var parentFrame = element.getAttribute('frame');
+ if(parentFrame != null)
+ {
+ y += 1;
+ }
+ }
+ else if(parentBorder > 0)
+ {
+ y += parentBorder;
+ }
+ }
+ }
+ y += element.offsetTop;
+
+ // Netscape can get confused in some cases, such that the height of the parent is smaller
+ // than that of the element (which it shouldn't really be). If this is the case, we need to
+ // exclude this element, since it will result in too large a 'top' return value.
+ if (element.offsetParent && element.offsetParent.offsetHeight && element.offsetParent.offsetHeight < element.offsetHeight)
+ {
+ // skip the parent that's too small
+ element = element.offsetParent.offsetParent;
+ }
+ else
+ {
+ // Next up...
+ element = element.offsetParent;
+ }
+ }
+ return y;
+};
+
+Selenium.prototype.getElementWidth = function(locator) {
+ /**
+ * Retrieves the width of an element
+ *
+ * @param locator an <a href="#locators">element locator</a> pointing to an element
+ * @return number width of an element in pixels
+ */
+ var element = this.page().findElement(locator);
+ return element.offsetWidth;
+};
+
+Selenium.prototype.getElementHeight = function(locator) {
+ /**
+ * Retrieves the height of an element
+ *
+ * @param locator an <a href="#locators">element locator</a> pointing to an element
+ * @return number height of an element in pixels
+ */
+ var element = this.page().findElement(locator);
+ return element.offsetHeight;
+};
+
+Selenium.prototype.getCursorPosition = function(locator) {
+ /**
+ * Retrieves the text cursor position in the given input element or textarea; beware, this may not work perfectly on all browsers.
+ *
+ * <p>Specifically, if the cursor/selection has been cleared by JavaScript, this command will tend to
+ * return the position of the last location of the cursor, even though the cursor is now gone from the page. This is filed as <a href="http://jira.openqa.org/browse/SEL-243">SEL-243</a>.</p>
+ * This method will fail if the specified element isn't an input element or textarea, or there is no cursor in the element.
+ *
+ * @param locator an <a href="#locators">element locator</a> pointing to an input element or textarea
+ * @return number the numerical position of the cursor in the field
+ */
+ var element = this.page().findElement(locator);
+ var doc = this.page().currentDocument;
+ var win = this.browserbot.getCurrentWindow();
+ if( doc.selection && !browserVersion.isOpera){
+
+ var selectRange = doc.selection.createRange().duplicate();
+ var elementRange = element.createTextRange();
+ selectRange.move("character",0);
+ elementRange.move("character",0);
+ var inRange1 = selectRange.inRange(elementRange);
+ var inRange2 = elementRange.inRange(selectRange);
+ try {
+ elementRange.setEndPoint("EndToEnd", selectRange);
+ } catch (e) {
+ Assert.fail("There is no cursor on this page!");
+ }
+ var answer = String(elementRange.text).replace(/\r/g,"").length;
+ return answer;
+ } else {
+ if (typeof(element.selectionStart) != undefined) {
+ if (win.getSelection && typeof(win.getSelection().rangeCount) != undefined && win.getSelection().rangeCount == 0) {
+ Assert.fail("There is no cursor on this page!");
+ }
+ return element.selectionStart;
+ }
+ }
+ throw new Error("Couldn't detect cursor position on this browser!");
+}
+
+
Selenium.prototype.doSetContext = function(context, logLevelThreshold) {
/**
* Writes a message to the status bar and adds a note to the browser-side
@@ -1004,7 +1653,7 @@
* Returns the specified expression.
*
* <p>This is useful because of JavaScript preprocessing.
- * It is used to generate commands like assertExpression and storeExpression.</p>
+ * It is used to generate commands like assertExpression and waitForExpression.</p>
*
* @param expression the value to return
* @return string the value passed in
@@ -1029,14 +1678,16 @@
throw new SeleniumError("Timeout is not a number: " + timeout);
}
- testLoop.waitForCondition = function () {
+ currentTest.waitForCondition = function () {
return eval(script);
};
- testLoop.waitForConditionStart = new Date().getTime();
- testLoop.waitForConditionTimeout = timeout;
+ currentTest.waitForConditionStart = new Date().getTime();
+ currentTest.waitForConditionTimeout = timeout;
};
+Selenium.prototype.doWaitForCondition.dontCheckAlertsAndConfirms = true;
+
Selenium.prototype.doSetTimeout = function(timeout) {
/**
* Specifies the amount of time that Selenium will wait for actions to complete.
@@ -1045,7 +1696,7 @@
* The default timeout is 30 seconds.
* @param timeout a timeout in milliseconds, after which the action will return with an error
*/
- testLoop.waitForConditionTimeout = timeout;
+ currentTest.waitForConditionTimeout = timeout;
}
Selenium.prototype.doWaitForPageToLoad = function(timeout) {
@@ -1061,9 +1712,14 @@
* wait immediately after a Selenium command that caused a page-load.</p>
* @param timeout a timeout in milliseconds, after which this command will return with an error
*/
- this.doWaitForCondition("selenium.browserbot.isNewPageLoaded()", timeout);
+ // in pi-mode, the test and the harness share the window; thus if we are executing this code, then we have loaded
+ if (window["proxyInjectionMode"] == null || !window["proxyInjectionMode"]) {
+ this.doWaitForCondition("selenium.browserbot.isNewPageLoaded()", timeout);
+ }
};
+Selenium.prototype.doWaitForPageToLoad.dontCheckAlertsAndConfirms = true;
+
/**
* Evaluate a parameter, performing JavaScript evaluation and variable substitution.
* If the string matches the pattern "javascript{ ... }", evaluate the string between the braces.
@@ -1167,9 +1823,9 @@
throw new SeleniumError("Option with label '" + this.label + "' not found");
};
- this.isSelected = function(element) {
+ this.assertSelected = function(element) {
var selectedLabel = element.options[element.selectedIndex].text;
- return PatternMatcher.matches(this.label, selectedLabel)
+ Assert.matches(this.label, selectedLabel)
};
};
@@ -1188,9 +1844,9 @@
throw new SeleniumError("Option with value '" + this.value + "' not found");
};
- this.isSelected = function(element) {
+ this.assertSelected = function(element) {
var selectedValue = element.options[element.selectedIndex].value;
- return PatternMatcher.matches(this.value, selectedValue)
+ Assert.matches(this.value, selectedValue)
};
};
@@ -1210,8 +1866,8 @@
return element.options[this.index];
};
- this.isSelected = function(element) {
- return this.index == element.selectedIndex;
+ this.assertSelected = function(element) {
+ Assert.equals(this.index, element.selectedIndex);
};
};
@@ -1230,10 +1886,8 @@
throw new SeleniumError("Option with id '" + this.id + "' not found");
};
- this.isSelected = function(element) {
+ this.assertSelected = function(element) {
var selectedId = element.options[element.selectedIndex].id;
- return PatternMatcher.matches(this.id, selectedId)
+ Assert.matches(this.id, selectedId)
};
};
-
-
Modified: zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-browserbot.js
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-browserbot.js 2006-08-29 18:04:40 UTC (rev 69877)
+++ zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-browserbot.js 2006-08-29 18:41:08 UTC (rev 69878)
@@ -27,7 +27,7 @@
// The window to which the commands will be sent. For example, to click on a
// popup window, first select that window, and then do a normal click command.
-BrowserBot = function(frame) {
+var BrowserBot = function(frame) {
this.frame = frame;
this.currentPage = null;
this.currentWindowName = null;
@@ -42,21 +42,22 @@
this.newPageLoaded = false;
this.pageLoadError = null;
+
var self = this;
this.recordPageLoad = function() {
LOG.debug("Page load detected");
try {
- LOG.debug("Page load location=" + self.getCurrentWindow().location);
+ LOG.debug("Page load location=" + self.getCurrentWindow().location);
} catch (e) {
- self.pageLoadError = e;
- return;
+ self.pageLoadError = e;
+ return;
}
self.currentPage = null;
self.newPageLoaded = true;
};
this.isNewPageLoaded = function() {
- if (this.pageLoadError) throw this.pageLoadError;
+ if (this.pageLoadError) throw this.pageLoadError;
return self.newPageLoaded;
};
};
@@ -98,31 +99,46 @@
};
BrowserBot.prototype.hasAlerts = function() {
- return (this.recordedAlerts.length > 0) ;
+ return (this.recordedAlerts.length > 0);
};
+BrowserBot.prototype.relayBotToRC = function() {
+};
+// override in injection.html
+
BrowserBot.prototype.getNextAlert = function() {
- return this.recordedAlerts.shift();
+ var t = this.recordedAlerts.shift();
+ this.relayBotToRC("browserbot.recordedAlerts");
+ return t;
};
BrowserBot.prototype.hasConfirmations = function() {
- return (this.recordedConfirmations.length > 0) ;
+ return (this.recordedConfirmations.length > 0);
};
BrowserBot.prototype.getNextConfirmation = function() {
- return this.recordedConfirmations.shift();
+ var t = this.recordedConfirmations.shift();
+ this.relayBotToRC("browserbot.recordedConfirmations");
+ return t;
};
BrowserBot.prototype.hasPrompts = function() {
- return (this.recordedPrompts.length > 0) ;
+ return (this.recordedPrompts.length > 0);
};
BrowserBot.prototype.getNextPrompt = function() {
- return this.recordedPrompts.shift();
+ var t = this.recordedPrompts.shift();
+ this.relayBotToRC("browserbot.recordedPrompts");
+ return t;
};
BrowserBot.prototype.getFrame = function() {
- return this.frame;
+ var f = this.frame;
+ if (f == null) {
+ f = window;
+ // in case we aren't using frames
+ }
+ return f;
};
BrowserBot.prototype.selectWindow = function(target) {
@@ -137,6 +153,31 @@
}
};
+BrowserBot.prototype.selectFrame = function(target) {
+ if (target == "relative=up") {
+ this.currentWindow = this.getCurrentWindow().parent;
+ } else if (target == "relative=top") {
+ this.currentWindow = this.getCurrentWindow().top;
+ } else {
+ var frame = this.getCurrentPage().findElement(target);
+ if (frame == null) {
+ throw new SeleniumError("Not found: " + target);
+ }
+ // now, did they give us a frame or a frame ELEMENT?
+ if (frame.contentWindow) {
+ // this must be a frame element
+ this.currentWindow = frame.contentWindow;
+ } else if (frame.document) {
+ // must be an actual window frame
+ this.currentWindow = frame;
+ } else {
+ // neither
+ throw new SeleniumError("Not a frame: " + target);
+ }
+ }
+ this.currentPage = null;
+};
+
BrowserBot.prototype.openLocation = function(target) {
// We're moving to a new page - clear the current one
this.currentPage = null;
@@ -166,14 +207,17 @@
};
BrowserBot.prototype.modifyWindowToRecordPopUpDialogs = function(windowToModify, browserBot) {
+ var self = this;
windowToModify.alert = function(alert) {
browserBot.recordedAlerts.push(alert);
+ self.relayBotToRC("browserbot.recordedAlerts");
};
windowToModify.confirm = function(message) {
browserBot.recordedConfirmations.push(message);
var result = browserBot.nextConfirmResult;
browserBot.nextConfirmResult = true;
+ self.relayBotToRC("browserbot.recordedConfirmations");
return result;
};
@@ -182,6 +226,7 @@
var result = !browserBot.nextConfirmResult ? null : browserBot.nextPromptResult;
browserBot.nextConfirmResult = true;
browserBot.nextPromptResult = '';
+ self.relayBotToRC("browserbot.recordedPrompts");
return result;
};
@@ -216,7 +261,8 @@
// Since the unload event doesn't fire in Safari 1.3, we start polling immediately
if (windowObject && !windowObject.closed) {
LOG.debug("Starting pollForLoad: " + windowObject.document.location);
- this.pollForLoad(loadFunction, windowObject, windowObject.document.location, windowObject.document.location.href);
+ this.pollingForLoad = true;
+ this.pollForLoad(loadFunction, windowObject, windowObject.location, windowObject.location.href);
}
};
@@ -228,39 +274,46 @@
BrowserBot.prototype.pollForLoad = function(loadFunction, windowObject, originalLocation, originalHref) {
var windowClosed = true;
try {
- windowClosed = windowObject.closed;
+ windowClosed = windowObject.closed;
} catch (e) {
- LOG.debug("exception detecting closed window (I guess it must be closed)");
- LOG.exception(e);
- // swallow exceptions which may occur in HTA mode when the window is closed
+ LOG.debug("exception detecting closed window (I guess it must be closed)");
+ LOG.exception(e);
+ // swallow exceptions which may occur in HTA mode when the window is closed
}
+ if (null == windowClosed) windowClosed = true;
if (windowClosed) {
+ this.pollingForLoad = false;
return;
}
LOG.debug("pollForLoad original: " + originalHref);
try {
- var currentLocation = windowObject.document.location;
- var currentHref = currentLocation.href
+ var currentLocation = windowObject.location;
+ var currentHref = currentLocation.href
- var sameLoc = (originalLocation === currentLocation);
- var sameHref = (originalHref === currentHref);
- var rs = windowObject.document.readyState;
+ var sameLoc = (originalLocation === currentLocation);
+ var sameHref = (originalHref === currentHref);
+ var rs = windowObject.document.readyState;
- if (rs == null) rs = 'complete';
+ if (rs == null) rs = 'complete';
- if (!(sameLoc && sameHref) && rs == 'complete') {
- LOG.debug("pollForLoad complete: " + rs + " (" + currentHref + ")");
- loadFunction();
- return;
- }
- var self = this;
- LOG.debug("pollForLoad continue: " + currentHref);
- window.setTimeout(function() {self.pollForLoad(loadFunction, windowObject, originalLocation, originalHref);}, 500);
- } catch (e) {
- this.pageLoadError = e;
- }
+ if (!(sameLoc && sameHref) && rs == 'complete') {
+ LOG.debug("pollForLoad complete: " + rs + " (" + currentHref + ")");
+ loadFunction();
+ this.pollingForLoad = false;
+ return;
+ }
+ var self = this;
+ LOG.debug("pollForLoad continue: " + currentHref);
+ window.setTimeout(function() {
+ self.pollForLoad(loadFunction, windowObject, originalLocation, originalHref);
+ }, 500);
+ } catch (e) {
+ LOG.error("Exception during pollForLoad; this should get noticed soon!");
+ LOG.exception(e);
+ this.pageLoadError = e;
+ }
};
@@ -375,12 +428,14 @@
};
};
-PageBot = function(pageWindow) {
+var PageBot = function(pageWindow) {
if (pageWindow) {
this.currentWindow = pageWindow;
this.currentDocument = pageWindow.document;
this.location = pageWindow.location;
- this.title = function() {return this.currentDocument.title;};
+ this.title = function() {
+ return this.currentDocument.title;
+ };
}
// Register all locateElementBy* functions
@@ -436,6 +491,9 @@
else if (browserVersion.isSafari) {
return new SafariPageBot(windowObject);
}
+ else if (browserVersion.isOpera) {
+ return new OperaPageBot(windowObject);
+ }
else {
LOG.info("Using MozillaPageBot")
// Use mozilla by default
@@ -443,26 +501,31 @@
}
};
-MozillaPageBot = function(pageWindow) {
+var MozillaPageBot = function(pageWindow) {
PageBot.call(this, pageWindow);
};
MozillaPageBot.prototype = new PageBot();
-KonquerorPageBot = function(pageWindow) {
+var KonquerorPageBot = function(pageWindow) {
PageBot.call(this, pageWindow);
};
KonquerorPageBot.prototype = new PageBot();
-SafariPageBot = function(pageWindow) {
+var SafariPageBot = function(pageWindow) {
PageBot.call(this, pageWindow);
};
SafariPageBot.prototype = new PageBot();
-IEPageBot = function(pageWindow) {
+var IEPageBot = function(pageWindow) {
PageBot.call(this, pageWindow);
};
IEPageBot.prototype = new PageBot();
+var OperaPageBot = function(pageWindow) {
+ PageBot.call(this, pageWindow);
+};
+OperaPageBot.prototype = new PageBot();
+
/*
* Finds an element on the current page, using various lookup protocols
*/
@@ -479,12 +542,12 @@
var element = this.findElementBy(locatorType, locatorString, this.currentDocument);
if (element != null) {
- return element;
+ return this.highlight(element);
}
for (var i = 0; i < this.currentWindow.frames.length; i++) {
element = this.findElementBy(locatorType, locatorString, this.currentWindow.frames[i].document);
if (element != null) {
- return element;
+ return this.highlight(element);
}
}
@@ -492,6 +555,20 @@
throw new SeleniumError("Element " + locator + " not found");
};
+PageBot.prototype.highlight = function (element) {
+ if (shouldHighlightLocatedElement) {
+ Effect.highlight(element);
+ }
+ return element;
+}
+
+// as a static variable.
+var shouldHighlightLocatedElement = false;
+
+PageBot.prototype.setHighlightElement = function (shouldHighlight) {
+ shouldHighlightLocatedElement = shouldHighlight;
+}
+
/**
* In non-IE browsers, getElementById() does not search by name. Instead, we
* we search separately by id and name.
@@ -544,9 +621,9 @@
};
/**
-* Finds an element using by evaluating the "document.*" string against the
-* current document object. Dom expressions must begin with "document."
-*/
+ * Finds an element using by evaluating the "document.*" string against the
+ * current document object. Dom expressions must begin with "document."
+ */
PageBot.prototype.locateElementByDomTraversal = function(domTraversal, inDocument) {
if (domTraversal.indexOf("document.") != 0) {
return null;
@@ -566,9 +643,9 @@
PageBot.prototype.locateElementByDomTraversal.prefix = "dom";
/**
-* Finds an element identified by the xpath expression. Expressions _must_
-* begin with "//".
-*/
+ * Finds an element identified by the xpath expression. Expressions _must_
+ * begin with "//".
+ */
PageBot.prototype.locateElementByXPath = function(xpath, inDocument) {
// Trim any trailing "/": not valid xpath, and remains from attribute
@@ -588,30 +665,30 @@
// Handle //tag[@attr='value']
var match = xpath.match(/^\/\/(\w+|\*)\[@(\w+)=('([^\']+)'|"([^\"]+)")\]$/);
if (match) {
- return this.findElementByTagNameAndAttributeValue(
- inDocument,
- match[1].toUpperCase(),
- match[2].toLowerCase(),
- match[3].slice(1, -1)
- );
+ return this._findElementByTagNameAndAttributeValue(
+ inDocument,
+ match[1].toUpperCase(),
+ match[2].toLowerCase(),
+ match[3].slice(1, -1)
+ );
}
// Handle //tag[text()='value']
var match = xpath.match(/^\/\/(\w+|\*)\[text\(\)=('([^\']+)'|"([^\"]+)")\]$/);
if (match) {
- return this.findElementByTagNameAndText(
- inDocument,
- match[1].toUpperCase(),
- match[2].slice(1, -1)
- );
+ return this._findElementByTagNameAndText(
+ inDocument,
+ match[1].toUpperCase(),
+ match[2].slice(1, -1)
+ );
}
- return this.findElementUsingFullXPath(xpath, inDocument);
+ return this._findElementUsingFullXPath(xpath, inDocument);
};
-PageBot.prototype.findElementByTagNameAndAttributeValue = function(
- inDocument, tagName, attributeName, attributeValue
-) {
+PageBot.prototype._findElementByTagNameAndAttributeValue = function(
+ inDocument, tagName, attributeName, attributeValue
+ ) {
if (browserVersion.isIE && attributeName == "class") {
attributeName = "className";
}
@@ -625,9 +702,9 @@
return null;
};
-PageBot.prototype.findElementByTagNameAndText = function(
- inDocument, tagName, text
-) {
+PageBot.prototype._findElementByTagNameAndText = function(
+ inDocument, tagName, text
+ ) {
var elements = inDocument.getElementsByTagName(tagName);
for (var i = 0; i < elements.length; i++) {
if (getText(elements[i]) == text) {
@@ -637,30 +714,26 @@
return null;
};
-PageBot.prototype.findElementUsingFullXPath = function(xpath, inDocument) {
- if (browserVersion.isIE && !inDocument.evaluate) {
- addXPathSupport(inDocument);
- }
-
+PageBot.prototype._findElementUsingFullXPath = function(xpath, inDocument) {
// Use document.evaluate() if it's available
if (inDocument.evaluate) {
return inDocument.evaluate(xpath, inDocument, null, 0, null).iterateNext();
}
// If not, fall back to slower JavaScript implementation
- var context = new XPathContext();
- context.expressionContextNode = inDocument;
- var xpathResult = new XPathParser().parse(xpath).evaluate(context);
- if (xpathResult && xpathResult.toArray) {
- return xpathResult.toArray()[0];
+ var context = new ExprContext(inDocument);
+ var xpathObj = xpathParse(xpath);
+ var xpathResult = xpathObj.evaluate(context);
+ if (xpathResult && xpathResult.value) {
+ return xpathResult.value[0];
}
return null;
};
/**
-* Finds a link element with text matching the expression supplied. Expressions must
-* begin with "link:".
-*/
+ * Finds a link element with text matching the expression supplied. Expressions must
+ * begin with "link:".
+ */
PageBot.prototype.locateElementByLinkText = function(linkText, inDocument) {
var links = inDocument.getElementsByTagName('a');
for (var i = 0; i < links.length; i++) {
@@ -674,9 +747,9 @@
PageBot.prototype.locateElementByLinkText.prefix = "link";
/**
-* Returns an attribute based on an attribute locator. This is made up of an element locator
-* suffixed with @attribute-name.
-*/
+ * Returns an attribute based on an attribute locator. This is made up of an element locator
+ * suffixed with @attribute-name.
+ */
PageBot.prototype.findAttribute = function(locator) {
// Split into locator + attributeName
var attributePos = locator.lastIndexOf("@");
@@ -758,28 +831,32 @@
PageBot.prototype.replaceText = function(element, stringValue) {
triggerEvent(element, 'focus', false);
triggerEvent(element, 'select', true);
- element.value=stringValue;
- triggerEvent(element, 'change', true);
+ element.value = stringValue;
+ if (!browserVersion.isChrome) {
+ // In chrome URL, The change event is already fired by setting the value.
+ triggerEvent(element, 'change', true);
+ }
triggerEvent(element, 'blur', false);
};
-// TODO Opera uses this too - split out an Opera version so we don't need the isGecko check here
-MozillaPageBot.prototype.clickElement = function(element) {
+MozillaPageBot.prototype.clickElement = function(element, clientX, clientY) {
triggerEvent(element, 'focus', false);
// Add an event listener that detects if the default action has been prevented.
// (This is caused by a javascript onclick handler returning false)
var preventDefault = false;
- if (browserVersion.isGecko) {
- element.addEventListener("click", function(evt) {preventDefault = evt.getPreventDefault();}, false);
- }
+ element.addEventListener("click", function(evt) {
+ preventDefault = evt.getPreventDefault();
+ }, false);
+
// Trigger the click event.
- triggerMouseEvent(element, 'click', true);
+ triggerMouseEvent(element, 'click', true, clientX, clientY);
// Perform the link action if preventDefault was set.
- if (browserVersion.isGecko && !preventDefault) {
+ // In chrome URL, the link action is already executed by triggerMouseEvent.
+ if (!browserVersion.isChrome && !preventDefault) {
// Try the element itself, as well as it's parent - this handles clicking images inside links.
if (element.href) {
this.currentWindow.location.href = element.href;
@@ -796,15 +873,39 @@
triggerEvent(element, 'blur', false);
};
-KonquerorPageBot.prototype.clickElement = function(element) {
+OperaPageBot.prototype.clickElement = function(element, clientX, clientY) {
triggerEvent(element, 'focus', false);
+ // Trigger the click event.
+ triggerMouseEvent(element, 'click', true, clientX, clientY);
+
+ if (isDefined(element.checked)) {
+ // In Opera, clicking won't check/uncheck
+ if (element.type == "checkbox") {
+ element.checked = !element.checked;
+ } else {
+ element.checked = true;
+ }
+ }
+
+ if (this.windowClosed()) {
+ return;
+ }
+
+ triggerEvent(element, 'blur', false);
+};
+
+
+KonquerorPageBot.prototype.clickElement = function(element, clientX, clientY) {
+
+ triggerEvent(element, 'focus', false);
+
if (element.click) {
element.click();
}
else {
- triggerMouseEvent(element, 'click', true);
+ triggerMouseEvent(element, 'click', true, clientX, clientY);
}
if (this.windowClosed()) {
@@ -814,7 +915,7 @@
triggerEvent(element, 'blur', false);
};
-SafariPageBot.prototype.clickElement = function(element) {
+SafariPageBot.prototype.clickElement = function(element, clientX, clientY) {
triggerEvent(element, 'focus', false);
@@ -826,7 +927,7 @@
}
// For links and other elements, event emulation is required.
else {
- triggerMouseEvent(element, 'click', true);
+ triggerMouseEvent(element, 'click', true, clientX, clientY);
// Unfortunately, triggering the event doesn't seem to activate onclick handlers.
// We currently call onclick for the link, but I'm guessing that the onclick for containing
@@ -851,7 +952,7 @@
} else {
// This is true for buttons outside of forms, and maybe others.
LOG.warn("Ignoring 'click' call for button outside form, or link without href."
- + "Using buttons without an enclosing form can cause wierd problems with URL resolution in Safari." );
+ + "Using buttons without an enclosing form can cause wierd problems with URL resolution in Safari.");
// I implemented special handling for window.open, but unfortunately this behaviour is also displayed
// when we have a button without an enclosing form that sets document.location in the onclick handler.
// The solution is to always use an enclosing form for a button.
@@ -866,7 +967,7 @@
triggerEvent(element, 'blur', false);
};
-IEPageBot.prototype.clickElement = function(element) {
+IEPageBot.prototype.clickElement = function(element, clientX, clientY) {
triggerEvent(element, 'focus', false);
@@ -875,7 +976,9 @@
// Set a flag that records if the page will unload - this isn't always accurate, because
// <a href="javascript:alert('foo'):"> triggers the onbeforeunload event, even thought the page won't unload
var pageUnloading = false;
- var pageUnloadDetector = function() {pageUnloading = true;};
+ var pageUnloadDetector = function() {
+ pageUnloading = true;
+ };
this.currentWindow.attachEvent("onbeforeunload", pageUnloadDetector);
element.click();
@@ -900,6 +1003,8 @@
// If the page is unloading, we may get a "Permission denied" or "Unspecified error".
// Just ignore it, because the document may have unloaded.
if (pageUnloading) {
+ LOG.logHook = function() {
+ };
LOG.warn("Caught exception when firing events on unloading page: " + e.message);
return;
}
@@ -960,11 +1065,14 @@
};
PageBot.prototype.setContext = function(strContext, logLevel) {
- //set the current test title
- document.getElementById("context").innerHTML=strContext;
- if (logLevel!=null) {
- LOG.setLogLevelThreshold(logLevel);
+ //set the current test title
+ var ctx = document.getElementById("context");
+ if (ctx != null) {
+ ctx.innerHTML = strContext;
}
+ if (logLevel != null) {
+ LOG.setLogLevelThreshold(logLevel);
+ }
};
function isDefined(value) {
@@ -973,6 +1081,10 @@
PageBot.prototype.goBack = function() {
this.currentWindow.history.back();
+ if (browserVersion.isOpera && !selenium.browserbot.pollingForLoad) {
+ // DGF On Opera, goBack doesn't re-trigger a load event, so we have to poll for it
+ selenium.browserbot.callOnWindowPageTransition(selenium.browserbot.recordPageLoad, this.currentWindow);
+ }
};
PageBot.prototype.goForward = function() {
@@ -980,7 +1092,11 @@
};
PageBot.prototype.close = function() {
- this.currentWindow.eval("window.close();");
+ if (browserVersion.isChrome) {
+ this.currentWindow.close();
+ } else {
+ this.currentWindow.eval("window.close();");
+ }
};
PageBot.prototype.refresh = function() {
@@ -999,7 +1115,7 @@
return filterFunction(filter, elements);
};
-PageBot.filterFunctions = {};
+PageBot.filterFunctions = {};
PageBot.filterFunctions.name = function(name, elements) {
var selectedElements = [];
@@ -1032,10 +1148,10 @@
return [elements[index]];
};
-PageBot.prototype.selectElements = function(filterExpr, elements, defaultFilterType) {
+PageBot.prototype.selectElements = function(filterExpr, elements, defaultFilterType) {
var filterType = (defaultFilterType || 'value');
-
+
// If there is a filter prefix, use the specified strategy
var result = filterExpr.match(/^([A-Za-z]+)=(.+)/);
if (result) {
@@ -1045,3 +1161,35 @@
return this.selectElementsBy(filterType, filterExpr, elements);
};
+
+/**
+ * Find an element by class
+ */
+PageBot.prototype.locateElementByClass = function(locator, document) {
+ return Element.findFirstMatchingChild(document,
+ function(element) {
+ return element.className == locator
+ }
+ );
+}
+
+/**
+ * Find an element by alt
+ */
+PageBot.prototype.locateElementByAlt = function(locator, document) {
+ return Element.findFirstMatchingChild(document,
+ function(element) {
+ return element.alt == locator
+ }
+ );
+}
+
+/**
+ * Find an element by css selector
+ */
+PageBot.prototype.locateElementByCss = function(locator, document) {
+ var elements = cssQuery(locator, document);
+ if (elements.length != 0)
+ return elements[0];
+ return null;
+}
Modified: zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-browserdetect.js
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-browserdetect.js 2006-08-29 18:04:40 UTC (rev 69877)
+++ zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-browserdetect.js 2006-08-29 18:41:08 UTC (rev 69878)
@@ -20,7 +20,7 @@
// work around seem to make it necessary. Maybe as we learn more about what we need,
// we can do this in a more "feature-centric" rather than "browser-centric" way.
-BrowserVersion = function() {
+var BrowserVersion = function() {
this.name = navigator.appName;
if (window.opera != null)
@@ -29,6 +29,24 @@
this.isOpera = true;
return;
}
+
+ var self = this;
+
+ var checkChrome = function() {
+ var loc = window.document.location.href;
+ try {
+ loc = window.top.document.location.href;
+ } catch (e) {
+ // can't see the top (that means we might be chrome, but it's impossible to be sure)
+ self.isChromeDetectable = "no, top location couldn't be read in this window";
+ }
+
+ if (/^chrome:\/\//.test(loc)) {
+ self.isChrome = true;
+ } else {
+ self.isChrome = false;
+ }
+ }
if (this.name == "Microsoft Internet Explorer")
{
@@ -37,6 +55,9 @@
if (window.top.SeleniumHTARunner && window.top.document.location.pathname.match(/.hta$/i)) {
this.isHTA = true;
}
+ if ("0" == navigator.appMinorVersion) {
+ this.preSV1 = true;
+ }
return;
}
@@ -61,6 +82,12 @@
this.browser = BrowserVersion.FIREFOX;
this.isFirefox = true;
this.isGecko = true;
+ var result = /.*Firefox\/([\d\.]+).*/.exec(navigator.userAgent);
+ if (result)
+ {
+ this.firefoxVersion = result[1];
+ }
+ checkChrome();
return;
}
@@ -69,6 +96,7 @@
this.browser = BrowserVersion.MOZILLA;
this.isMozilla = true;
this.isGecko = true;
+ checkChrome();
return;
}
@@ -83,4 +111,5 @@
BrowserVersion.MOZILLA = "Mozilla";
BrowserVersion.UNKNOWN = "Unknown";
-browserVersion = new BrowserVersion();
+var browserVersion = new BrowserVersion();
+
Modified: zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-commandhandlers.js
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-commandhandlers.js 2006-08-29 18:04:40 UTC (rev 69877)
+++ zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-commandhandlers.js 2006-08-29 18:41:08 UTC (rev 69878)
@@ -35,18 +35,40 @@
var handler = new AssertHandler(assertion, haltOnFailure);
this.asserts[name] = handler;
};
-
+
this.getCommandHandler = function(name) {
return this.actions[name] || this.accessors[name] || this.asserts[name] || null;
};
- this.registerAll = function(commandObject) {
- registerAllAccessors(commandObject);
- registerAllActions(commandObject);
- registerAllAsserts(commandObject);
+
+ // Methods of the form getFoo(target) result in commands:
+ // getFoo, assertFoo, verifyFoo, assertNotFoo, verifyNotFoo
+ // storeFoo, waitForFoo, and waitForNotFoo.
+ var _registerAllAccessors = function(commandObject) {
+ for (var functionName in commandObject) {
+ var matchForGetter = /^get([A-Z].+)$/.exec(functionName);
+ if (matchForGetter != null) {
+ var accessor = commandObject[functionName];
+ var baseName = matchForGetter[1];
+ self.registerAccessor(functionName, accessor);
+ self.registerAssertionsBasedOnAccessor(accessor, baseName);
+ self.registerStoreCommandBasedOnAccessor(accessor, baseName);
+ self.registerWaitForCommandsBasedOnAccessor(accessor, baseName);
+ }
+ var matchForIs = /^is([A-Z].+)$/.exec(functionName);
+ if (matchForIs != null) {
+ var accessor = commandObject[functionName];
+ var baseName = matchForIs[1];
+ var predicate = self.createPredicateFromBooleanAccessor(accessor);
+ self.registerAccessor(functionName, accessor);
+ self.registerAssertionsBasedOnAccessor(accessor, baseName, predicate);
+ self.registerStoreCommandBasedOnAccessor(accessor, baseName);
+ self.registerWaitForCommandsBasedOnAccessor(accessor, baseName, predicate);
+ }
+ }
};
- var registerAllActions = function(commandObject) {
+ var _registerAllActions = function(commandObject) {
for (var functionName in commandObject) {
var result = /^do([A-Z].+)$/.exec(functionName);
if (result != null) {
@@ -54,17 +76,17 @@
// Register the action without the wait flag.
var action = commandObject[functionName];
- self.registerAction(actionName, action, false, false);
+ self.registerAction(actionName, action, false, action.dontCheckAlertsAndConfirms);
// Register actionName + "AndWait" with the wait flag;
var waitActionName = actionName + "AndWait";
- self.registerAction(waitActionName, action, true, false);
+ self.registerAction(waitActionName, action, true, action.dontCheckAlertsAndConfirms);
}
}
};
-
- var registerAllAsserts = function(commandObject) {
+
+ var _registerAllAsserts = function(commandObject) {
for (var functionName in commandObject) {
var result = /^assert([A-Z].+)$/.exec(functionName);
if (result != null) {
@@ -81,7 +103,13 @@
}
};
-
+
+ this.registerAll = function(commandObject) {
+ _registerAllAccessors(commandObject);
+ _registerAllActions(commandObject);
+ _registerAllAsserts(commandObject);
+ };
+
// Given an accessor function getBlah(target),
// return a "predicate" equivalient to isBlah(target, value) that
// is true when the value returned by the accessor matches the specified value.
@@ -95,7 +123,7 @@
}
};
};
-
+
// Given a (no-arg) accessor function getBlah(),
// return a "predicate" equivalient to isBlah(value) that
// is true when the value returned by the accessor matches the specified value.
@@ -109,7 +137,7 @@
}
};
};
-
+
// Given a boolean accessor function isBlah(),
// return a "predicate" equivalient to isBlah() that
// returns an appropriate PredicateResult value.
@@ -131,7 +159,7 @@
}
};
};
-
+
// Given an accessor fuction getBlah([target]) (target is optional)
// return a predicate equivalent to isBlah([target,] value) that
// is true when the value returned by the accessor matches the specified value.
@@ -141,7 +169,7 @@
}
return self.createPredicateFromSingleArgAccessor(accessor);
};
-
+
// Given a predicate, return the negation of that predicate.
// Leaves the message unchanged.
// Used to create assertNot, verifyNot, and waitForNot commands.
@@ -152,7 +180,7 @@
return result;
};
};
-
+
// Convert an isBlahBlah(target, value) function into an assertBlahBlah(target, value) function.
this.createAssertionFromPredicate = function(predicate) {
return function(target, value) {
@@ -162,45 +190,37 @@
}
};
};
-
+
+
+ var _negtiveName = function(baseName) {
+ var matchResult = /^(.*)Present$/.exec(baseName);
+ if (matchResult != null) {
+ return matchResult[1] + "NotPresent";
+ }
+ return "Not" + baseName;
+ };
+
// Register an assertion, a verification, a negative assertion,
// and a negative verification based on the specified accessor.
this.registerAssertionsBasedOnAccessor = function(accessor, baseName, predicate) {
- if (predicate==null) {
+ if (predicate == null) {
predicate = self.createPredicateFromAccessor(accessor);
}
var assertion = self.createAssertionFromPredicate(predicate);
- // Register an assert with the "assert" prefix, and halt on failure.
self.registerAssert("assert" + baseName, assertion, true);
- // Register a verify with the "verify" prefix, and do not halt on failure.
self.registerAssert("verify" + baseName, assertion, false);
-
+
var invertedPredicate = self.invertPredicate(predicate);
var negativeAssertion = self.createAssertionFromPredicate(invertedPredicate);
-
- var result = /^(.*)Present$/.exec(baseName);
- if (result==null) {
- // Register an assertNot with the "assertNot" prefix, and halt on failure.
- self.registerAssert("assertNot"+baseName, negativeAssertion, true);
- // Register a verifyNot with the "verifyNot" prefix, and do not halt on failure.
- self.registerAssert("verifyNot"+baseName, negativeAssertion, false);
- }
- else {
- var invertedBaseName = result[1] + "NotPresent";
-
- // Register an assertNot ending w/ "NotPresent", and halt on failure.
- self.registerAssert("assert"+invertedBaseName, negativeAssertion, true);
- // Register an assertNot ending w/ "NotPresent", and do not halt on failure.
- self.registerAssert("verify"+invertedBaseName, negativeAssertion, false);
- }
+ self.registerAssert("assert" + _negtiveName(baseName), negativeAssertion, true);
+ self.registerAssert("verify" + _negtiveName(baseName), negativeAssertion, false);
};
-
-
+
// Convert an isBlahBlah(target, value) function into a waitForBlahBlah(target, value) function.
this.createWaitForActionFromPredicate = function(predicate) {
var action = function(target, value) {
var seleniumApi = this;
- testLoop.waitForCondition = function () {
+ currentTest.waitForCondition = function () {
try {
return predicate.call(seleniumApi, target, value).isTrue;
} catch (e) {
@@ -214,19 +234,22 @@
};
return action;
};
-
+
// Register a waitForBlahBlah and waitForNotBlahBlah based on the specified accessor.
this.registerWaitForCommandsBasedOnAccessor = function(accessor, baseName, predicate) {
if (predicate==null) {
predicate = self.createPredicateFromAccessor(accessor);
}
var waitForAction = self.createWaitForActionFromPredicate(predicate);
- self.registerAction("waitFor"+baseName, waitForAction, false, accessor.dontCheckAlertsAndConfirms);
+ self.registerAction("waitFor"+baseName, waitForAction, false, true);
var invertedPredicate = self.invertPredicate(predicate);
var waitForNotAction = self.createWaitForActionFromPredicate(invertedPredicate);
- self.registerAction("waitForNot"+baseName, waitForNotAction, false, accessor.dontCheckAlertsAndConfirms);
- }
-
+ self.registerAction("waitFor"+_negtiveName(baseName), waitForNotAction, false, true);
+ //TODO decide remove "waitForNot.*Present" action name or not
+ //for the back compatiblity issues we still make waitForNot.*Present availble
+ self.registerAction("waitForNot"+baseName, waitForNotAction, false, true);
+ }
+
// Register a storeBlahBlah based on the specified accessor.
this.registerStoreCommandBasedOnAccessor = function(accessor, baseName) {
var action;
@@ -241,35 +264,7 @@
}
self.registerAction("store"+baseName, action, false, accessor.dontCheckAlertsAndConfirms);
};
-
- // Methods of the form getFoo(target) result in commands:
- // getFoo, assertFoo, verifyFoo, assertNotFoo, verifyNotFoo
- // storeFoo, waitForFoo, and waitForNotFoo.
- var registerAllAccessors = function(commandObject) {
- for (var functionName in commandObject) {
- var match = /^get([A-Z].+)$/.exec(functionName);
- if (match != null) {
- var accessor = commandObject[functionName];
- var baseName = match[1];
- self.registerAccessor(functionName, accessor);
- self.registerAssertionsBasedOnAccessor(accessor, baseName);
- self.registerStoreCommandBasedOnAccessor(accessor, baseName);
- self.registerWaitForCommandsBasedOnAccessor(accessor, baseName);
- }
- var match = /^is([A-Z].+)$/.exec(functionName);
- if (match != null) {
- var accessor = commandObject[functionName];
- var baseName = match[1];
- var predicate = self.createPredicateFromBooleanAccessor(accessor);
- self.registerAccessor(functionName, accessor);
- self.registerAssertionsBasedOnAccessor(accessor, baseName, predicate);
- self.registerStoreCommandBasedOnAccessor(accessor, baseName);
- self.registerWaitForCommandsBasedOnAccessor(accessor, baseName, predicate);
- }
- }
- };
-
-
+
}
function PredicateResult(isTrue, message) {
@@ -364,8 +359,9 @@
this.result = null;
}
-function SeleniumCommand(command, target, value) {
+function SeleniumCommand(command, target, value, stopOnThisCommand) {
this.command = command;
this.target = target;
this.value = value;
+ this.stopOnThisCommand = stopOnThisCommand;
}
Modified: zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-executionloop.js
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-executionloop.js 2006-08-29 18:04:40 UTC (rev 69877)
+++ zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-executionloop.js 2006-08-29 18:41:08 UTC (rev 69878)
@@ -17,173 +17,167 @@
SELENIUM_PROCESS_WAIT = "wait";
function TestLoop(commandFactory) {
-
this.commandFactory = commandFactory;
- this.waitForConditionTimeout = 30 * 1000; // 30 seconds
+}
- this.start = function() {
+TestLoop.prototype = {
+/** The default is not to have any interval between commands. */
+ start : function() {
selenium.reset();
- LOG.debug("testLoop.start()");
+ LOG.debug("currentTest.start()");
this.continueTest();
- };
+ },
- /**
- * Select the next command and continue the test.
- */
- this.continueTest = function() {
- LOG.debug("testLoop.continueTest() - acquire the next command");
+/**
+ * Select the next command and continue the test.
+ */
+ continueTest : function() {
+ LOG.debug("currentTest.continueTest() - acquire the next command");
if (! this.aborted) {
this.currentCommand = this.nextCommand();
}
if (! this.requiresCallBack) {
- this.beginNextTest();
+ this.beginNextTest();
} // otherwise, just finish and let the callback invoke beginNextTest()
- };
-
- this.beginNextTest = function() {
- LOG.debug("testLoop.beginNextTest()");
- if (this.currentCommand) {
+ },
+
+ beginNextTest : function() {
+ LOG.debug("currentTest.beginNextTest()");
+ if (this.currentCommand) {
// TODO: rename commandStarted to commandSelected, OR roll it into nextCommand
this.commandStarted(this.currentCommand);
- this.resumeAfterDelay();
+ this._resumeAfterDelay();
} else {
this.testComplete();
}
- }
-
- /**
- * Pause, then execute the current command.
- */
- this.resumeAfterDelay = function() {
+ },
+/**
+ * Pause, then execute the current command.
+ */
+ _resumeAfterDelay : function() {
+
// Get the command delay. If a pauseInterval is set, use it once
// and reset it. Otherwise, use the defined command-interval.
var delay = this.pauseInterval || this.getCommandInterval();
this.pauseInterval = undefined;
- if (delay < 0) {
+ if (this.currentCommand.stopOnThisCommand || delay < 0) {
// Pause: enable the "next/continue" button
this.pause();
} else {
- window.setTimeout("testLoop.resume()", delay);
+ window.setTimeout(this.resume.bind(this), delay);
}
- };
+ },
- /**
- * Select the next command and continue the test.
- */
- this.resume = function() {
- LOG.debug("testLoop.resume() - actually execute");
+/**
+ * Select the next command and continue the test.
+ */
+ resume : function() {
+ LOG.debug("currentTest.resume() - actually execute");
try {
- this.executeCurrentCommand();
+ this._executeCurrentCommand();
this.waitForConditionStart = new Date().getTime();
this.continueTestWhenConditionIsTrue();
} catch (e) {
- this.handleCommandError(e);
+ this._handleCommandError(e);
this.testComplete();
return;
}
- };
+ },
- /**
- * Execute the current command.
- *
- * The return value, if not null, should be a function which will be
- * used to determine when execution can continue.
- */
- this.executeCurrentCommand = function() {
+/**
+ * Execute the current command.
+ *
+ * The return value, if not null, should be a function which will be
+ * used to determine when execution can continue.
+ */
+ _executeCurrentCommand : function() {
var command = this.currentCommand;
LOG.info("Executing: |" + command.command + " | " + command.target + " | " + command.value + " |");
-
+
var handler = this.commandFactory.getCommandHandler(command.command);
if (handler == null) {
throw new SeleniumError("Unknown command: '" + command.command + "'");
}
-
+
command.target = selenium.preprocessParameter(command.target);
command.value = selenium.preprocessParameter(command.value);
LOG.debug("Command found, going to execute " + command.command);
var result = handler.execute(selenium, command);
- LOG.debug("Command complete");
+ LOG.debug("Command complete");
this.commandComplete(result);
if (result.processState == SELENIUM_PROCESS_WAIT) {
this.waitForCondition = function() {
- LOG.debug("Checking condition: isNewPageLoaded?");
+ LOG.debug("Checking condition: isNewPageLoaded?");
return selenium.browserbot.isNewPageLoaded();
};
}
- };
-
- this.handleCommandError = function(e) {
- if (!e.isSeleniumError) {
+ },
+
+ _handleCommandError : function(e) {
+ if (!e.isSeleniumError) {
LOG.exception(e);
var msg = "Selenium failure. Please report to selenium-dev at openqa.org, with error details from the log window.";
if (e.message) {
- msg += " The error message is: " + e.message;
+ msg += " The error message is: " + e.message;
}
this.commandError(msg);
} else {
LOG.error(e.message);
this.commandError(e.message);
}
- };
+ },
- /**
- * Busy wait for waitForCondition() to become true, and then carry on
- * with test. Fail the current test if there's a timeout or an exception.
- */
- this.continueTestWhenConditionIsTrue = function () {
- LOG.debug("testLoop.continueTestWhenConditionIsTrue()");
+/**
+ * Busy wait for waitForCondition() to become true, and then carry on
+ * with test. Fail the current test if there's a timeout or an exception.
+ */
+ continueTestWhenConditionIsTrue : function () {
+ LOG.debug("currentTest.continueTestWhenConditionIsTrue()");
try {
if (this.waitForCondition == null || this.waitForCondition()) {
- LOG.debug("condition satisfied; let's continueTest()");
- this.waitForCondition = null;
- this.waitForConditionStart = null;
- this.continueTest();
- } else {
- LOG.debug("waitForCondition was false; keep waiting!");
- if (this.waitForConditionTimeout != null) {
- var now = new Date();
- if ((now - this.waitForConditionStart) > this.waitForConditionTimeout) {
- throw new SeleniumError("Timed out after " + this.waitForConditionTimeout + "ms");
- }
- }
- window.setTimeout("testLoop.continueTestWhenConditionIsTrue()", 10);
- }
- } catch (e) {
- var lastResult = new CommandResult();
- lastResult.failed = true;
- lastResult.failureMessage = e.message;
- this.commandComplete(lastResult);
- this.testComplete();
- }
- };
+ LOG.debug("condition satisfied; let's continueTest()");
+ this.waitForCondition = null;
+ this.waitForConditionStart = null;
+ this.continueTest();
+ } else {
+ LOG.debug("waitForCondition was false; keep waiting!");
+ if (this.waitForConditionTimeout != null) {
+ var now = new Date();
+ if ((now - this.waitForConditionStart) > this.waitForConditionTimeout) {
+ throw new SeleniumError("Timed out after " + this.waitForConditionTimeout + "ms");
+ }
+ }
+ window.setTimeout(this.continueTestWhenConditionIsTrue.bind(this), 10);
+ }
+ } catch (e) {
+ var lastResult = new CommandResult();
+ lastResult.failed = true;
+ lastResult.failureMessage = e.message;
+ this.commandComplete(lastResult);
+ this.testComplete();
+ }
+ },
-}
+ pause : function() {
-/** The default is not to have any interval between commands. */
-TestLoop.prototype.getCommandInterval = function() {
- return 0;
-};
+ },
-TestLoop.prototype.nextCommand = noop;
+ nextCommand : function() {},
+ commandStarted : function() {},
+ commandComplete : function() {},
+ commandError : function() {},
+ testComplete : function() {},
-TestLoop.prototype.commandStarted = noop;
+ getCommandInterval : function() {
+ return 0;
+ }
-TestLoop.prototype.commandError = noop;
+}
-TestLoop.prototype.commandComplete = noop;
-
-TestLoop.prototype.testComplete = noop;
-
-TestLoop.prototype.pause = noop;
-
-function noop() {
-
-};
-
/**
* Tell Selenium to expect a failure on the next command execution. This
* command temporarily installs a CommandFactory that generates
@@ -195,9 +189,9 @@
}
var expectFailureCommandFactory =
- new ExpectFailureCommandFactory(testLoop.commandFactory, message, "failure");
+ new ExpectFailureCommandFactory(currentTest.commandFactory, message, "failure");
expectFailureCommandFactory.baseExecutor = executeCommandAndReturnFailureMessage;
- testLoop.commandFactory = expectFailureCommandFactory;
+ currentTest.commandFactory = expectFailureCommandFactory;
};
/**
@@ -211,9 +205,9 @@
}
var expectFailureCommandFactory =
- new ExpectFailureCommandFactory(testLoop.commandFactory, message, "error");
+ new ExpectFailureCommandFactory(currentTest.commandFactory, message, "error");
expectFailureCommandFactory.baseExecutor = executeCommandAndReturnErrorMessage;
- testLoop.commandFactory = expectFailureCommandFactory;
+ currentTest.commandFactory = expectFailureCommandFactory;
};
function ExpectFailureCommandFactory(originalCommandFactory, expectedErrorMessage, errorType) {
@@ -239,7 +233,7 @@
result.result = baseFailureMessage;
}
}
- testLoop.commandFactory = originalCommandFactory;
+ currentTest.commandFactory = originalCommandFactory;
return result;
};
return expectFailureCommand;
Modified: zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-logging.js
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-logging.js 2006-08-29 18:04:40 UTC (rev 69877)
+++ zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-logging.js 2006-08-29 18:41:08 UTC (rev 69878)
@@ -48,7 +48,7 @@
openLogWindow: function() {
this.logWindow = window.open(
- "SeleniumLog.html", "SeleniumLog",
+ getDocumentBase(document) + "SeleniumLog.html", "SeleniumLog",
"width=600,height=250,bottom=0,right=0,status,scrollbars,resizable"
);
return this.logWindow;
@@ -60,22 +60,31 @@
}
},
+ logHook: function(message, className) {
+ },
+
log: function(message, className) {
var logWindow = this.getLogWindow();
+ this.logHook(message, className);
if (logWindow) {
if (logWindow.append) {
if (this.pendingInfoMessage) {
- logWindow.append(this.pendingInfoMessage, "info");
+ logWindow.append("info: " + this.pendingInfoMessage, "info");
this.pendingInfoMessage = null;
}
- logWindow.append(message, className);
+ logWindow.append(className + ": " + message, className);
}
}
},
close: function(message) {
if (this.logWindow != null) {
- this.logWindow.close();
+ try {
+ this.logWindow.close();
+ } catch (e) {
+ // swallow exception
+ // the window is probably closed if we get an exception here
+ }
this.logWindow = null;
}
},
@@ -105,15 +114,3 @@
var LOG = new Logger();
-function noop() {};
-
-var DummyLogger = function() {};
-DummyLogger.prototype = {
- show: noop,
- log: noop,
- debug: noop,
- info: noop,
- warn: noop,
- error: noop
-};
-
Modified: zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-seleneserunner.js
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-seleneserunner.js 2006-08-29 18:04:40 UTC (rev 69877)
+++ zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-seleneserunner.js 2006-08-29 18:41:08 UTC (rev 69878)
@@ -23,47 +23,97 @@
slowMode = false;
+var injectedSessionId;
var cmd1 = document.createElement("div");
var cmd2 = document.createElement("div");
var cmd3 = document.createElement("div");
var cmd4 = document.createElement("div");
var postResult = "START";
+var debugMode = false;
+var relayToRC = null; // override in injection.html
+var queryString = null;
+var proxyInjectionMode = false;
+var uniqueId = 'sel_' + Math.round(100000 * Math.random());
-function runTest() {
+function runSeleniumTest() {
var testAppFrame = document.getElementById('myiframe');
+
+ if (testAppFrame==null) {
+ proxyInjectionMode = true;
+ testAppFrame = window;
+ }
+ else
+ {
+ proxyInjectionMode = false;
+ }
+
selenium = Selenium.createForFrame(testAppFrame);
+ if (!debugMode) {
+ debugMode = getQueryVariable("debugMode");
+ }
+ if (proxyInjectionMode) {
+ LOG.log = logToRc;
+ }
+ else if (debugMode) {
+ LOG.logHook = logToRc;
+ }
+ window.selenium = selenium;
commandFactory = new CommandHandlerFactory();
commandFactory.registerAll(selenium);
- testLoop = new TestLoop(commandFactory);
+ currentTest = new SeleneseRunner(commandFactory);
- testLoop.nextCommand = nextCommand;
- testLoop.commandStarted = commandStarted;
- testLoop.commandComplete = commandComplete;
- testLoop.commandError = commandError;
- testLoop.requiresCallBack = true;
- testLoop.testComplete = function() {
- window.status = "Selenium Tests Complete, for this Test"
- // Continue checking for new results
- testLoop.continueTest();
- postResult = "START";
- };
+ if (document.getElementById("commandList") != null) {
+ document.getElementById("commandList").appendChild(cmd4);
+ document.getElementById("commandList").appendChild(cmd3);
+ document.getElementById("commandList").appendChild(cmd2);
+ document.getElementById("commandList").appendChild(cmd1);
+ }
- document.getElementById("commandList").appendChild(cmd4);
- document.getElementById("commandList").appendChild(cmd3);
- document.getElementById("commandList").appendChild(cmd2);
- document.getElementById("commandList").appendChild(cmd1);
-
var doContinue = getQueryVariable("continue");
if (doContinue != null) postResult = "OK";
- testLoop.start();
+ currentTest.start();
}
+function getQueryString() {
+ if (queryString != null) return queryString;
+ if (browserVersion.isHTA) {
+ var args = extractArgs();
+ if (args.length < 2) return null;
+ queryString = args[1];
+ return queryString;
+ } else if (proxyInjectionMode) {
+ return selenium.browserbot.getCurrentWindow().location.search.substr(1);
+ } else {
+ return top.location.search.substr(1);
+ }
+}
+
+function extractArgs() {
+ var str = SeleniumHTARunner.commandLine;
+ if (str == null || str == "") return new Array();
+ var matches = str.match(/(?:"([^"]+)"|(?!"([^"]+)")(\S+))/g);
+ // We either want non quote stuff ([^"]+) surrounded by quotes
+ // or we want to look-ahead, see that the next character isn't
+ // a quoted argument, and then grab all the non-space stuff
+ // this will return for the line: "foo" bar
+ // the results "\"foo\"" and "bar"
+
+ // So, let's unquote the quoted arguments:
+ var args = new Array;
+ for (var i = 0; i < matches.length; i++) {
+ args[i] = matches[i];
+ args[i] = args[i].replace(/^"(.*)"$/, "$1");
+ }
+ return args;
+}
+
function getQueryVariable(variable) {
- var query = window.location.search.substring(1);
+ var query = getQueryString();
+ if (query == null) return null;
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
@@ -74,191 +124,333 @@
}
function buildBaseUrl() {
- var lastSlash = window.location.href.lastIndexOf('/');
- var baseUrl = window.location.href.substring(0, lastSlash+1);
- return baseUrl;
+ var baseUrl = getQueryVariable("baseUrl");
+ if (baseUrl != null) {
+ return baseUrl;
+ }
+ var s=window.location.href
+ var slashPairOffset=s.indexOf("//") + "//".length
+ var pathSlashOffset=s.substring(slashPairOffset).indexOf("/")
+ return s.substring(0, slashPairOffset + pathSlashOffset) + "/selenium-server/core/";
}
-function buildDriverParams() {
- var params = "";
-
- var host = getQueryVariable("driverhost");
- var port = getQueryVariable("driverport");
- if (host != undefined && port != undefined) {
- params = params + "&driverhost=" + host + "&driverport=" + port;
+function logToRc(message, logLevel) {
+ if (logLevel==null) {
+ logLevel = "debug";
}
+ if (debugMode) {
+ sendToRC("logLevel=" + logLevel + ":" + message.replace(/[\n\r\015]/, " ") + "\n");
+ }
+}
- var sessionId = getQueryVariable("sessionId");
- if (sessionId != undefined) {
- params = params + "&sessionId=" + sessionId;
+function isArray(x) {
+ return ((typeof x)=="object") && (x["length"]!=null);
+}
+
+function serializeString(name, s) {
+ return name + "=unescape(\"" + escape(s) + "\");";
+}
+
+function serializeObject(name, x)
+{
+ var s = '';
+
+ if (isArray(x))
+ {
+ s = name + "=new Array(); ";
+ var len = x["length"];
+ for (var j = 0; j<len; j++)
+ {
+ s += serializeString(name + "[" + j + "]", x[j]);
+ }
}
+ else if (typeof x == "string")
+ {
+ s = serializeString(name, x);
+ }
+ else
+ {
+ throw "unrecognized object not encoded: " + name + "(" + x + ")";
+ }
+ return s;
+}
- return params;
+function relayBotToRC(s) {}
+
+function setSeleniumWindowName(seleniumWindowName) {
+ selenium.browserbot.getCurrentWindow()['seleniumWindowName'] = seleniumWindowName;
}
-function preventBrowserCaching() {
- var t = (new Date()).getTime();
- return "&counterToMakeURsUniqueAndSoStopPageCachingInTheBrowser=" + t;
-}
+function slowClicked() {
+ slowMode = !slowMode;
+}
-function nextCommand() {
- xmlHttp = XmlHttp.create();
- try {
-
- var url = buildBaseUrl();
+function getIframeDocument(iframe) {
+ if (iframe.contentDocument) {
+ return iframe.contentDocument;
+ }
+ else {
+ return iframe.contentWindow.document;
+ }
+}
+
+SeleneseRunner = Class.create();
+Object.extend(SeleneseRunner.prototype, new TestLoop());
+Object.extend(SeleneseRunner.prototype, {
+ initialize : function(commandFactory) {
+ this.commandFactory = commandFactory;
+ this.requiresCallBack = true;
+ this.commandNode = null;
+ this.xmlHttpForCommandsAndResults = null;
+ },
+
+ nextCommand : function() {
+ var urlParms = "";
if (postResult == "START") {
- url = url + "driver/?seleniumStart=true" + buildDriverParams() + preventBrowserCaching();
+ urlParms += "seleniumStart=true";
+ }
+ this.xmlHttpForCommandsAndResults = XmlHttp.create();
+ sendToRC(postResult, urlParms, this._HandleHttpResponse.bind(this), this.xmlHttpForCommandsAndResults);
+ },
+
+ commandStarted : function(command) {
+ this.commandNode = document.createElement("div");
+ var innerHTML = command.command + '(';
+ if (command.target != null && command.target != "") {
+ innerHTML += command.target;
+ if (command.value != null && command.value != "") {
+ innerHTML += ', ' + command.value;
+ }
+ }
+ innerHTML += ")";
+ this.commandNode.innerHTML = innerHTML;
+ this.commandNode.style.backgroundColor = workingColor;
+ if (document.getElementById("commandList") != null) {
+ document.getElementById("commandList").removeChild(cmd1);
+ document.getElementById("commandList").removeChild(cmd2);
+ document.getElementById("commandList").removeChild(cmd3);
+ document.getElementById("commandList").removeChild(cmd4);
+ cmd4 = cmd3;
+ cmd3 = cmd2;
+ cmd2 = cmd1;
+ cmd1 = this.commandNode;
+ document.getElementById("commandList").appendChild(cmd4);
+ document.getElementById("commandList").appendChild(cmd3);
+ document.getElementById("commandList").appendChild(cmd2);
+ document.getElementById("commandList").appendChild(cmd1);
+ }
+ },
+
+ commandComplete : function(result) {
+
+ if (result.failed) {
+ if (postResult == "CONTINUATION") {
+ currentTest.aborted = true;
+ }
+ postResult = result.failureMessage;
+ this.commandNode.title = result.failureMessage;
+ this.commandNode.style.backgroundColor = failColor;
+ } else if (result.passed) {
+ postResult = "OK";
+ this.commandNode.style.backgroundColor = passColor;
} else {
- url = url + "driver/?" + buildDriverParams() + preventBrowserCaching();
+ if (result.result == null) {
+ postResult = "OK";
+ } else {
+ postResult = "OK," + result.result;
+ }
+ this.commandNode.style.backgroundColor = doneColor;
}
- LOG.debug("XMLHTTPRequesting " + url);
- xmlHttp.open("POST", url, true);
- xmlHttp.onreadystatechange=handleHttpResponse;
- xmlHttp.send(postResult);
- } catch(e) {
- var s = 'xmlHttp returned:\n'
- for (key in e) {
- s += "\t" + key + " -> " + e[key] + "\n"
+ },
+
+ commandError : function(message) {
+ postResult = "ERROR: " + message;
+ this.commandNode.style.backgroundColor = errorColor;
+ this.commandNode.title = message;
+ },
+
+ testComplete : function() {
+ window.status = "Selenium Tests Complete, for this Test"
+ // Continue checking for new results
+ this.continueTest();
+ postResult = "START";
+ },
+
+ _HandleHttpResponse : function() {
+ if (this.xmlHttpForCommandsAndResults.readyState == 4) {
+ if (this.xmlHttpForCommandsAndResults.status == 200) {
+ var command = this._extractCommand(this.xmlHttpForCommandsAndResults);
+ this.currentCommand = command;
+ this.beginNextTest();
+ } else {
+ var s = 'xmlHttp returned: ' + this.xmlHttpForCommandsAndResults.status + ": " + this.xmlHttpForCommandsAndResults.statusText;
+ LOG.error(s);
+ this.currentCommand = null;
+ setTimeout(this.beginNextTest.bind(this), 2000);
+ }
+
}
- LOG.error(s);
- return null;
- }
- return null;
-}
+ },
- function handleHttpResponse() {
- if (xmlHttp.readyState == 4) {
- if (xmlHttp.status == 200) {
- var command = extractCommand(xmlHttp);
- testLoop.currentCommand = command;
- testLoop.beginNextTest();
- } else {
- var s = 'xmlHttp returned: ' + xmlHttp.status + ": " + xmlHttp.statusText;
- LOG.error(s);
- testLoop.currentCommand = null;
- setTimeout("testLoop.beginNextTest();", 2000);
- }
-
- }
- }
+ _extractCommand : function(xmlHttp) {
+ if (slowMode) {
+ this._delay(2000);
+ }
+ var command;
+ try {
+ var re = new RegExp("^(.*?)\n((.|[\r\n])*)");
+ if (re.exec(xmlHttp.responseText)) {
+ command = RegExp.$1;
+ var rest = RegExp.$2;
+ rest = rest.trim();
+ if (rest) {
+ eval(rest);
+ }
+ }
+ else {
+ command = xmlHttp.responseText;
+ }
+ } catch (e) {
+ alert('could not get responseText: ' + e.message);
+ }
+ if (command.substr(0, '|testComplete'.length) == '|testComplete') {
+ return null;
+ }
-function extractCommand(xmlHttp) {
- if (slowMode) {
- delay(2000);
+ return this._createCommandFromRequest(command);
+ },
+
+
+ _delay : function(millis) {
+ var startMillis = new Date();
+ while (true) {
+ milli = new Date();
+ if (milli - startMillis > millis) {
+ break;
+ }
+ }
+ },
+
+// Parses a URI query string into a SeleniumCommand object
+ _createCommandFromRequest : function(commandRequest) {
+ //decodeURIComponent doesn't strip plus signs
+ var processed = commandRequest.replace(/\+/g, "%20");
+ // strip trailing spaces
+ var processed = processed.replace(/\s+$/, "");
+ var vars = processed.split("&");
+ var cmdArgs = new Object();
+ for (var i = 0; i < vars.length; i++) {
+ var pair = vars[i].split("=");
+ cmdArgs[pair[0]] = pair[1];
+ }
+ var cmd = cmdArgs['cmd'];
+ var arg1 = cmdArgs['1'];
+ if (null == arg1) arg1 = "";
+ arg1 = decodeURIComponent(arg1);
+ var arg2 = cmdArgs['2'];
+ if (null == arg2) arg2 = "";
+ arg2 = decodeURIComponent(arg2);
+ if (cmd == null) {
+ throw new Error("Bad command request: " + commandRequest);
+ }
+ return new SeleniumCommand(cmd, arg1, arg2);
}
- var command;
- try {
- command = xmlHttp.responseText;
- } catch (e) {
- alert('could not get responseText: ' + e.message);
+})
+
+
+function sendToRC(dataToBePosted, urlParms, callback, xmlHttpObject, async) {
+ if (async==null) {
+ async = true;
}
- if (command.substr(0,'|testComplete'.length)=='|testComplete') {
- return null;
+ if (xmlHttpObject==null) {
+ xmlHttpObject = XmlHttp.create();
}
+ var url = buildBaseUrl() + "driver/?"
+ if (urlParms) {
+ url += urlParms;
+ }
+ url += "&localFrameAddress=" + (proxyInjectionMode ? makeAddressToAUTFrame() : "top");
+ url += "&seleniumWindowName=" + getSeleniumWindowName();
+ url += "&uniqueId=" + uniqueId;
- return createCommandFromRequest(command);
+ if (callback==null) {
+ callback = function(){};
+ }
+ url += buildDriverParams() + preventBrowserCaching();
+ xmlHttpObject.open("POST", url, async);
+ xmlHttpObject.onreadystatechange = callback;
+ xmlHttpObject.send(dataToBePosted);
+ return null;
}
-function commandStarted(command) {
- commandNode = document.createElement("div");
- innerHTML = command.command + '(';
- if (command.target != null && command.target != "") {
- innerHTML += command.target;
- if (command.value != null && command.value != "") {
- innerHTML += ', ' + command.value;
- }
+function buildDriverParams() {
+ var params = "";
+
+ var host = getQueryVariable("driverhost");
+ var port = getQueryVariable("driverport");
+ if (host != undefined && port != undefined) {
+ params = params + "&driverhost=" + host + "&driverport=" + port;
}
- innerHTML += ")";
- commandNode.innerHTML = innerHTML;
- commandNode.style.backgroundColor = workingColor;
- document.getElementById("commandList").removeChild(cmd1);
- document.getElementById("commandList").removeChild(cmd2);
- document.getElementById("commandList").removeChild(cmd3);
- document.getElementById("commandList").removeChild(cmd4);
- cmd4 = cmd3;
- cmd3 = cmd2;
- cmd2 = cmd1;
- cmd1 = commandNode;
- document.getElementById("commandList").appendChild(cmd4);
- document.getElementById("commandList").appendChild(cmd3);
- document.getElementById("commandList").appendChild(cmd2);
- document.getElementById("commandList").appendChild(cmd1);
-}
-function commandComplete(result) {
- if (result.failed) {
- if (postResult == "CONTINUATION") {
- testLoop.aborted = true;
- }
- postResult = result.failureMessage;
- commandNode.title = result.failureMessage;
- commandNode.style.backgroundColor = failColor;
- } else if (result.passed) {
- postResult = "OK";
- commandNode.style.backgroundColor = passColor;
- } else {
- if (result.result == null) {
- postResult = "OK";
- } else {
- postResult = "OK," + result.result;
- }
- commandNode.style.backgroundColor = doneColor;
+ var sessionId = getQueryVariable("sessionId");
+ if (sessionId == undefined) {
+ sessionId = injectedSessionId;
}
+ if (sessionId != undefined) {
+ params = params + "&sessionId=" + sessionId;
+ }
+ return params;
}
-function commandError(message) {
- postResult = "ERROR: " + message;
- commandNode.style.backgroundColor = errorColor;
- commandNode.title = message;
+function preventBrowserCaching() {
+ var t = (new Date()).getTime();
+ return "&counterToMakeURsUniqueAndSoStopPageCachingInTheBrowser=" + t;
}
-function slowClicked() {
- slowMode = !slowMode;
-}
-
-function delay(millis) {
- startMillis = new Date();
- while (true) {
- milli = new Date();
- if (milli-startMillis > millis) {
- break;
+// Return the name of the current window in the selenium recordkeeping.
+//
+// In selenium, the additional widow has no name.
+//
+// Additional pop-ups are associated with names given by the argument to the routine waitForPopUp.
+//
+// I try to arrange for widows which are opened in such manner to track their own names using the top-level property
+// seleniumWindowName, but it is possible that this property will not be available (if the widow has just reloaded
+// itself). In this case, return "?".
+//
+function getSeleniumWindowName() {
+ var w = (proxyInjectionMode ? selenium.browserbot.getCurrentWindow() : window);
+ if (w.opener==null) {
+ return "";
}
- }
+ if (w["seleniumWindowName"]==null) {
+ return "?";
+ }
+ return w["seleniumWindowName"];
}
-function getIframeDocument(iframe) {
- if (iframe.contentDocument) {
- return iframe.contentDocument;
+// construct a JavaScript expression which leads to my frame (i.e., the frame containing the window
+// in which this code is operating)
+function makeAddressToAUTFrame(w, frameNavigationalJSexpression)
+{
+ if (w==null)
+ {
+ w=top;
+ frameNavigationalJSexpression = "top";
}
- else {
- return iframe.contentWindow.document;
- }
-}
-// Parses a URI query string into a SeleniumCommand object
-function createCommandFromRequest(commandRequest) {
- //decodeURIComponent doesn't strip plus signs
- var processed = commandRequest.replace(/\+/g, "%20");
- // strip trailing spaces
- var processed = processed.replace(/\s+$/, "");
- var vars = processed.split("&");
- var cmdArgs = new Object();
- for (var i=0;i<vars.length;i++) {
- var pair = vars[i].split("=");
- cmdArgs[pair[0]] = pair[1];
+ if (w==selenium.browserbot.getCurrentWindow())
+ {
+ return frameNavigationalJSexpression;
}
- var cmd = cmdArgs['cmd'];
- var arg1 = cmdArgs['1'];
- if (null == arg1) arg1 = "";
- arg1 = decodeURIComponent(arg1);
- var arg2 = cmdArgs['2'];
- if (null == arg2) arg2 = "";
- arg2 = decodeURIComponent(arg2);
- if (cmd == null) {
- throw new Error("Bad command request: " + commandRequest);
+ for (var j = 0; j < w.frames.length; j++)
+ {
+ var t = makeAddressToAUTFrame(w.frames[j], frameNavigationalJSexpression + ".frames[" + j + "]");
+ if (t!=null)
+ {
+ return t;
+ }
}
- return new SeleniumCommand(cmd, arg1, arg2);
+ return null;
}
-
Modified: zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-testrunner.js
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-testrunner.js 2006-08-29 18:04:40 UTC (rev 69877)
+++ zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-testrunner.js 2006-08-29 18:41:08 UTC (rev 69878)
@@ -80,19 +80,31 @@
function continueCurrentTest() {
document.getElementById('continueTest').disabled = true;
- testLoop.resume();
+ currentTest.resume();
}
function getApplicationFrame() {
- return document.getElementById('myiframe');
+ var f = document.getElementById('myiframe');
+ if (f==null) {
+ f = top; // proxyInjection mode does not set myiframe
+ }
+ return f;
}
function getSuiteFrame() {
- return document.getElementById('testSuiteFrame');
+ var f = document.getElementById('testSuiteFrame');
+ if (f==null) {
+ f = top; // proxyInjection mode does not set myiframe
+ }
+ return f;
}
function getTestFrame(){
- return document.getElementById('testFrame');
+ var f = document.getElementById('testFrame');
+ if (f==null) {
+ f = top; // proxyInjection mode does not set myiframe
+ }
+ return f;
}
function loadAndRunIfAuto() {
@@ -121,6 +133,9 @@
document.getElementById('modeStep').onclick = setRunInterval;
document.getElementById('continueTest').onclick = continueCurrentTest;
+
+ document.getElementById("highlightOption").checked = getQueryParameter("highlight")
+
var testSuiteName = getQueryParameter("test");
if (testSuiteName) {
@@ -150,7 +165,8 @@
function onloadTestSuite() {
removeLoadListener(getSuiteFrame(), onloadTestSuite);
-
+ addLoadListener(getTestFrame(), addBreakpointSupport);
+
// Add an onclick function to each link in all suite tables
var allTables = getIframeDocument(getSuiteFrame()).getElementsByTagName("table");
for (var tableNum = 0; tableNum < allTables.length; tableNum++)
@@ -213,6 +229,8 @@
while (bodyElement.firstChild != bodyElement.lastChild) {
bodyElement.removeChild(bodyElement.firstChild);
}
+
+ addBreakpointSupport();
}
// Otherwise, just open up the fresh page.
else {
@@ -223,9 +241,38 @@
};
}
+function addBreakpointSupport() {
+ var testDocument = getIframeDocument(getTestFrame());
+ var tables = testDocument.getElementsByTagName("table");
+ for (var i = 0; i < tables.length; i++) {
+ var candidateRows = tables[i].rows;
+ for (var j = 1; j < candidateRows.length; j++) {
+ Element.setStyle(candidateRows[j], {"cursor" : "pointer"});
+ Event.observe(candidateRows[j], 'click', getBreakpointEventHandler(candidateRows[j]), false);
+ }
+ }
+}
+
+function getBreakpointEventHandler(commandRow) {
+ return function() {
+ if (commandRow.stopOnThisCommand == undefined) {
+ commandRow.stopOnThisCommand = true;
+ commandRow.beforeBackgroundColor = Element.getStyle(commandRow, "backgroundColor");
+ Element.setStyle(commandRow, {"background-color" : "#cccccc"});
+ } else {
+ commandRow.stopOnThisCommand = undefined;
+ Element.setStyle(commandRow, {"background-color" : commandRow.beforeBackgroundColor});
+ }
+ }
+}
+
+
function isQueryParameterTrue(name) {
parameterValue = getQueryParameter(name);
- return (parameterValue != null && parameterValue.toLowerCase() == "true");
+ if (parameterValue == null) return false;
+ if (parameterValue.toLowerCase() == "true") return true;
+ if (parameterValue.toLowerCase() == "on") return true;
+ return false;
}
function getQueryString() {
@@ -243,7 +290,7 @@
function extractArgs() {
var str = SeleniumHTARunner.commandLine;
if (str == null || str == "") return new Array();
- var matches = str.match(/(?:"([^"]+)"|(?!"([^"]+)")\b(\S+)\b)/g);
+ var matches = str.match(/(?:"([^"]+)"|(?!"([^"]+)")(\S+))/g);
// We either want non quote stuff ([^"]+) surrounded by quotes
// or we want to look-ahead, see that the next character isn't
// a quoted argument, and then grab all the non-space stuff
@@ -298,6 +345,7 @@
function startTest() {
removeLoadListener(getTestFrame(), startTest);
+ setHighlightOption();
// Scroll to the top of the test frame
if (getTestFrame().contentWindow) {
@@ -307,58 +355,34 @@
frames['testFrame'].scrollTo(0,0);
}
- currentTest = new HtmlTest(getIframeDocument(getTestFrame()));
+ if (getIframeDocument(getTestFrame()).getElementById('se-js-table')) // selenium script in javascript
+ currentTest = new TestRunner(getIframeDocument(getTestFrame()),true,commandFactory);
+ else
+ currentTest = new TestRunner(getIframeDocument(getTestFrame()),false,commandFactory);
+
+
testFailed = false;
storedVars = new Object();
- testLoop = initialiseTestLoop();
- testLoop.start();
+ currentTest.start();
}
-function HtmlTest(testDocument) {
- this.init(testDocument);
-}
+get_new_rows = function() {
+ var row_array = new Array();
+ for (var i = 0; i < new_block.length; i++) {
-HtmlTest.prototype = {
+ var new_source = (new_block[i][0].tokenizer.source.slice(new_block[i][0].start,
+ new_block[i][0].end));
- init: function(testDocument) {
- this.document = testDocument;
- this.document.bgColor = "";
- this.currentRow = null;
- this.commandRows = new Array();
- this.headerRow = null;
- var tables = this.document.getElementsByTagName("table");
- for (var i = 0; i < tables.length; i++) {
- var candidateRows = tables[i].rows;
- for (var j = 0; j < candidateRows.length; j++) {
- if (!this.headerRow) {
- this.headerRow = candidateRows[j];
- }
- if (candidateRows[j].cells.length >= 3) {
- this.addCommandRow(candidateRows[j]);
- }
- }
- }
- },
+ var row = '<td style="display:none;" class="js">getEval</td>' +
+ '<td style="display:none;">currentTest.doNextCommand()</td>' +
+ '<td style="white-space: pre;">' + new_source + '</td>' +
+ '<td></td>'
- addCommandRow: function(row) {
- if (row.cells[2] && row.cells[2].originalHTML) {
- row.cells[2].innerHTML = row.cells[2].originalHTML;
- }
- row.bgColor = "";
- this.commandRows.push(row);
- },
-
- nextCommand: function() {
- if (this.commandRows.length > 0) {
- this.currentRow = this.commandRows.shift();
- } else {
- this.currentRow = null;
- }
- return this.currentRow;
- }
-
+ row_array.push(row);
+ };
+ return row_array
};
function startTestSuite() {
@@ -437,7 +461,7 @@
new_column.appendChild(tableNode);
// Set the column to be invisible
- new_column.style.cssText = "display: none;";
+ new_column.style.display = "none";
// Add the invisible column
suiteTable.rows[row].appendChild(new_column);
@@ -499,7 +523,7 @@
form.createHiddenField("selenium.version", Selenium.version);
form.createHiddenField("selenium.revision", Selenium.revision);
-
+
form.createHiddenField("result", suiteFailed == true ? "failed" : "passed");
form.createHiddenField("totalTime", Math.floor((currentTime - startTime) / 1000));
@@ -517,10 +541,10 @@
var resultCell = suiteTable.rows[rowNum].cells[1];
form.createHiddenField("testTable." + rowNum, resultCell.innerHTML);
// remove the resultCell, so it's not included in the suite HTML
- resultCell.parentNode.removeChild(resultCell);
+ resultCell.parentNode.removeChild(resultCell);
}
}
-
+
form.createHiddenField("numTestTotal", rowNum);
// Add HTML for the suite itself
@@ -595,30 +619,16 @@
}
-function initialiseTestLoop() {
- testLoop = new TestLoop(commandFactory);
-
- testLoop.getCommandInterval = function() { return runInterval; };
- testLoop.nextCommand = nextCommand;
- testLoop.commandStarted = commandStarted;
- testLoop.commandComplete = commandComplete;
- testLoop.commandError = commandError;
- testLoop.testComplete = testComplete;
- testLoop.pause = function() {
- document.getElementById('continueTest').disabled = false;
- };
- return testLoop;
-}
-
function nextCommand() {
var row = currentTest.nextCommand();
if (row == null) {
return null;
}
row.cells[2].originalHTML = row.cells[2].innerHTML;
- return new SeleniumCommand(getText(row.cells[0]),
+ return new SeleniumCommand(getText(row.cells[0]),
getText(row.cells[1]),
- getText(row.cells[2]));
+ getText(row.cells[2]),
+ row.stopOnThisCommand);
}
function removeNbsp(value) {
@@ -634,109 +644,237 @@
// scrollIntoView (like Konqueror)
}
-function commandStarted() {
- currentTest.currentRow.bgColor = workingColor;
- scrollIntoView(currentTest.currentRow.cells[0]);
- printMetrics();
+function setHighlightOption() {
+ var isHighlight = document.getElementById("highlightOption").checked;
+ selenium.browserbot.getCurrentPage().setHighlightElement(isHighlight);
}
-function commandComplete(result) {
- if (result.failed) {
- numCommandFailures += 1;
- recordFailure(result.failureMessage);
- } else if (result.passed) {
- numCommandPasses += 1;
- currentTest.currentRow.bgColor = passColor;
- } else {
- currentTest.currentRow.bgColor = doneColor;
- }
-}
-function commandError(errorMessage) {
- numCommandErrors += 1;
- recordFailure(errorMessage);
-}
+var TestRunner = Class.create();
+Object.extend(TestRunner.prototype, new TestLoop());
+Object.extend(TestRunner.prototype, {
+ initialize : function(testDocument, isJavaScript, commandFactory) {
-function recordFailure(errorMsg) {
- LOG.warn("recordFailure: " + errorMsg);
- // Set cell background to red
- currentTest.currentRow.bgColor = failColor;
+ this.commandFactory = commandFactory;
+ this.waitForConditionTimeout = 30 * 1000;
+ // 30 seconds
- // Set error message
- currentTest.currentRow.cells[2].innerHTML = errorMsg;
- currentTest.currentRow.title = errorMsg;
- testFailed = true;
- suiteFailed = true;
-}
+ this.isJavaScript = isJavaScript;
+ se = selenium;
+ global.se = selenium;
+ this.document = testDocument;
+ this.document.bgColor = "";
+ this.currentRow = null;
+ this.currentRowIndex = 0;
+ this.commandRows = new Array();
+ this.headerRow = null;
-function testComplete() {
- var resultColor = passColor;
- if (testFailed) {
- resultColor = failColor;
- numTestFailures += 1;
- } else {
- numTestPasses += 1;
- }
+ // used for selenium tests in javascript
+ this.currentItem = null;
+ this.commandAgenda = new Array();
- if (currentTest.headerRow) {
- currentTest.headerRow.bgColor = resultColor;
+ var tables = this.document.getElementsByTagName("table");
+ for (var i = 0; i < tables.length; i++) {
+ var candidateRows = tables[i].rows;
+ for (var j = 0; j < candidateRows.length; j++) {
+ if (!this.headerRow) {
+ this.headerRow = candidateRows[j];
+ }
+ if (candidateRows[j].cells.length >= 3) {
+ this._addCommandRow(candidateRows[j]);
+ }
+ }
+ }
+
+ if (isJavaScript) {
+ var script = this.document.getElementById('sejs') // the script source
+ var fname = 'Selenium JavaScript';
+ parse_result = parse(script.innerHTML, fname, 0);
+
+ var x2 = new ExecutionContext(GLOBAL_CODE);
+ ExecutionContext.current = x2;
+
+ execute(parse_result, x2)
+ }
+ },
+
+ _addCommandRow: function(row) {
+ if (row.cells[2] && row.cells[2].originalHTML) {
+ row.cells[2].innerHTML = row.cells[2].originalHTML;
+ }
+ row.bgColor = "";
+ this.commandRows.push(row);
+ },
+
+ _nextCommandRow: function() {
+ if (this.commandRows.length > 0) {
+ this.currentRow = this.commandRows.shift();
+ if (this.isJavaScript) {
+ this.currentItem = agenda.pop();
+ this.currentRowIndex++;
+ }
+ } else {
+ this.currentRow = null;
+ this.currentItem = null;
+ }
+ return this.currentRow;
+ },
+
+ nextCommand : function() {
+ var row = this._nextCommandRow();
+ if (row == null) {
+ return null;
+ }
+ row.cells[2].originalHTML = row.cells[2].innerHTML;
+ return new SeleniumCommand(getText(row.cells[0]),
+ getText(row.cells[1]),
+ getText(row.cells[2]),
+ row.stopOnThisCommand);
+ },
+
+ commandStarted : function() {
+ this.currentRow.bgColor = workingColor;
+ scrollIntoView(this.currentRow.cells[0]);
+ printMetrics();
+ },
+
+ commandComplete : function(result) {
+ if (result.failed) {
+ numCommandFailures += 1;
+ this._recordFailure(result.failureMessage);
+ } else if (result.passed) {
+ numCommandPasses += 1;
+ this.currentRow.bgColor = passColor;
+ } else {
+ this.currentRow.bgColor = doneColor;
+ }
+ },
+
+
+ commandError : function(errorMessage) {
+ numCommandErrors += 1;
+ this._recordFailure(errorMessage);
+ },
+
+ _recordFailure : function(errorMsg) {
+ LOG.warn("currentTest.recordFailure: " + errorMsg);
+ // Set cell background to red
+ this.currentRow.bgColor = failColor;
+
+ // Set error message
+ this.currentRow.cells[2].innerHTML = errorMsg;
+ this.currentRow.title = errorMsg;
+ testFailed = true;
+ suiteFailed = true;
+ },
+
+ testComplete : function() {
+ var resultColor = passColor;
+ if (testFailed) {
+ resultColor = failColor;
+ numTestFailures += 1;
+ } else {
+ numTestPasses += 1;
+ }
+
+ if (this.headerRow) {
+ this.headerRow.bgColor = resultColor;
+ }
+
+ printMetrics();
+
+ window.setTimeout("runNextTest()", 1);
+ },
+
+ getCommandInterval : function() {
+ return runInterval;
+ },
+
+ pause : function() {
+ document.getElementById('continueTest').disabled = false;
+ },
+
+ doNextCommand: function() {
+ var _n = this.currentItem[0];
+ var _x = this.currentItem[1];
+
+ new_block = new Array()
+ execute(_n, _x);
+ if (new_block.length > 0) {
+ var the_table = this.document.getElementById("se-js-table")
+ var loc = this.currentRowIndex
+ var new_rows = get_new_rows()
+
+ // make the new statements visible on screen...
+ for (var i = 0; i < new_rows.length; i++) {
+ the_table.insertRow(loc + 1);
+ the_table.rows[loc + 1].innerHTML = new_rows[i];
+ this.commandRows.unshift(the_table.rows[loc + 1])
+ }
+
+ }
}
-
- printMetrics();
- window.setTimeout("runNextTest()", 1);
-}
+});
+
Selenium.prototype.doPause = function(waitTime) {
- testLoop.pauseInterval = waitTime;
+ /** Wait for the specified amount of time (in milliseconds)
+ * @param waitTime the amount of time to sleep (in milliseconds)
+ */
+ currentTest.pauseInterval = waitTime;
};
+Selenium.prototype.doPause.dontCheckAlertsAndConfirms = true;
+
Selenium.prototype.doBreak = function() {
+ /** Halt the currently running test, and wait for the user to press the Continue button.
+ * This command is useful for debugging, but be careful when using it, because it will
+ * force automated tests to hang until a user intervenes manually.
+ */
document.getElementById('modeStep').checked = true;
runInterval = -1;
};
+Selenium.prototype.doStore = function(expression, variableName) {
+ /** This command is a synonym for storeExpression.
+ * @param expression the value to store
+ * @param variableName the name of a <a href="#storedVars">variable</a> in which the result is to be stored.
+ */
+ storedVars[variableName] = expression;
+}
+
/*
* Click on the located element, and attach a callback to notify
* when the page is reloaded.
*/
-Selenium.prototype.doModalDialogTest = function(returnValue) {
+// DGF TODO this code has been broken for some time... what is it trying to accomplish?
+Selenium.prototype.XXXdoModalDialogTest = function(returnValue) {
this.browserbot.doModalDialogTest(returnValue);
};
-/*
- * Store the value of a form input in a variable
- */
-Selenium.prototype.doStoreValue = function(target, varName) {
- if (!varName) {
- // Backward compatibility mode: read the ENTIRE text of the page
- // and stores it in a variable with the name of the target
- value = this.page().bodyText();
- storedVars[target] = value;
- return;
+Selenium.prototype.doEcho = function(message) {
+ /** Prints the specified message into the third table cell in your Selenese tables.
+ * Useful for debugging.
+ * @param message the message to print
+ */
+ currentTest.currentRow.cells[2].innerHTML = message;
+}
+
+Selenium.prototype.assertSelected = function(selectLocator, optionLocator) {
+ /**
+ * Verifies that the selected option of a drop-down satisfies the optionSpecifier. <i>Note that this command is deprecated; you should use assertSelectedLabel, assertSelectedValue, assertSelectedIndex, or assertSelectedId instead.</i>
+ *
+ * <p>See the select command for more information about option locators.</p>
+ *
+ * @param selectLocator an <a href="#locators">element locator</a> identifying a drop-down menu
+ * @param optionLocator an option locator, typically just an option label (e.g. "John Smith")
+ */
+ var element = this.page().findElement(selectLocator);
+ var locator = this.optionLocatorFactory.fromLocatorString(optionLocator);
+ if (element.selectedIndex == -1)
+ {
+ Assert.fail("No option selected");
}
- var element = this.page().findElement(target);
- storedVars[varName] = getInputValue(element);
-};
-
-/*
- * Store the text of an element in a variable
- */
-Selenium.prototype.doStoreText = function(target, varName) {
- var element = this.page().findElement(target);
- storedVars[varName] = getText(element);
-};
-
-/*
- * Store the value of an element attribute in a variable
- */
-Selenium.prototype.doStoreAttribute = function(target, varName) {
- storedVars[varName] = this.page().findAttribute(target);
-};
-
-/*
- * Store the result of a literal value
- */
-Selenium.prototype.doStore = function(value, varName) {
- storedVars[varName] = value;
-};
+ locator.assertSelected(element);
+};
\ No newline at end of file
Modified: zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-version.js
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-version.js 2006-08-29 18:04:40 UTC (rev 69877)
+++ zc.selenium/trunk/src/zc/selenium/resources/scripts/selenium-version.js 2006-08-29 18:41:08 UTC (rev 69878)
@@ -1,5 +1,5 @@
-Selenium.version = "0.7.0";
-Selenium.revision = "1007M";
+Selenium.version = "0.7.1";
+Selenium.revision = "1253M";
window.top.document.title += " v" + Selenium.version + " [" + Selenium.revision + "]";
Deleted: zc.selenium/trunk/src/zc/selenium/resources/scripts/xpath.js
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/scripts/xpath.js 2006-08-29 18:04:40 UTC (rev 69877)
+++ zc.selenium/trunk/src/zc/selenium/resources/scripts/xpath.js 2006-08-29 18:41:08 UTC (rev 69878)
@@ -1,4169 +0,0 @@
-/*
- * xpath.js
- *
- * An XPath 1.0 library for JavaScript.
- *
- * Cameron McCormack <cam (at) mcc.id.au>
- *
- * This work is licensed under the Creative Commons Attribution-ShareAlike
- * License. To view a copy of this license, visit
- *
- * http://creativecommons.org/licenses/by-sa/2.0/
- *
- * or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford,
- * California 94305, USA.
- *
- * Revision 18: October 27, 2005
- * DOM 3 XPath support. Caveats:
- * - namespace prefixes aren't resolved in XPathEvaluator.createExpression,
- * but in XPathExpression.evaluate.
- * - XPathResult.invalidIteratorState is not implemented.
- *
- * Revision 17: October 25, 2005
- * Some core XPath function fixes and a patch to avoid crashing certain
- * versions of MSXML in PathExpr.prototype.getOwnerElement, thanks to
- * Sébastien Cramatte <contact (at) zeninteractif.com>.
- *
- * Revision 16: September 22, 2005
- * Workarounds for some IE 5.5 deficiencies.
- * Fixed problem with prefix node tests on attribute nodes.
- *
- * Revision 15: May 21, 2005
- * Fixed problem with QName node tests on elements with an xmlns="...".
- *
- * Revision 14: May 19, 2005
- * Fixed QName node tests on attribute node regression.
- *
- * Revision 13: May 3, 2005
- * Node tests are case insensitive now if working in an HTML DOM.
- *
- * Revision 12: April 26, 2005
- * Updated licence. Slight code changes to enable use of Dean
- * Edwards' script compression, http://dean.edwards.name/packer/ .
- *
- * Revision 11: April 23, 2005
- * Fixed bug with 'and' and 'or' operators, fix thanks to
- * Sandy McArthur <sandy (at) mcarthur.org>.
- *
- * Revision 10: April 15, 2005
- * Added support for a virtual root node, supposedly helpful for
- * implementing XForms. Fixed problem with QName node tests and
- * the parent axis.
- *
- * Revision 9: March 17, 2005
- * Namespace resolver tweaked so using the document node as the context
- * for namespace lookups is equivalent to using the document element.
- *
- * Revision 8: February 13, 2005
- * Handle implicit declaration of 'xmlns' namespace prefix.
- * Fixed bug when comparing nodesets.
- * Instance data can now be associated with a FunctionResolver, and
- * workaround for MSXML not supporting 'localName' and 'getElementById',
- * thanks to Grant Gongaware.
- * Fix a few problems when the context node is the root node.
- *
- * Revision 7: February 11, 2005
- * Default namespace resolver fix from Grant Gongaware
- * <grant (at) gongaware.com>.
- *
- * Revision 6: February 10, 2005
- * Fixed bug in 'number' function.
- *
- * Revision 5: February 9, 2005
- * Fixed bug where text nodes not getting converted to string values.
- *
- * Revision 4: January 21, 2005
- * Bug in 'name' function, fix thanks to Bill Edney.
- * Fixed incorrect processing of namespace nodes.
- * Fixed NamespaceResolver to resolve 'xml' namespace.
- * Implemented union '|' operator.
- *
- * Revision 3: January 14, 2005
- * Fixed bug with nodeset comparisons, bug lexing < and >.
- *
- * Revision 2: October 26, 2004
- * QName node test namespace handling fixed. Few other bug fixes.
- *
- * Revision 1: August 13, 2004
- * Bug fixes from William J. Edney <bedney (at) technicalpursuit.com>.
- * Added minimal licence.
- *
- * Initial version: June 14, 2004
- */
-
-// XPathParser ///////////////////////////////////////////////////////////////
-
-XPathParser.prototype = new Object();
-XPathParser.prototype.constructor = XPathParser;
-XPathParser.superclass = Object.prototype;
-
-function XPathParser() {
- this.init();
-}
-
-XPathParser.prototype.init = function() {
- this.reduceActions = [];
-
- this.reduceActions[3] = function(rhs) {
- return new OrOperation(rhs[0], rhs[2]);
- };
- this.reduceActions[5] = function(rhs) {
- return new AndOperation(rhs[0], rhs[2]);
- };
- this.reduceActions[7] = function(rhs) {
- return new EqualsOperation(rhs[0], rhs[2]);
- };
- this.reduceActions[8] = function(rhs) {
- return new NotEqualOperation(rhs[0], rhs[2]);
- };
- this.reduceActions[10] = function(rhs) {
- return new LessThanOperation(rhs[0], rhs[2]);
- };
- this.reduceActions[11] = function(rhs) {
- return new GreaterThanOperation(rhs[0], rhs[2]);
- };
- this.reduceActions[12] = function(rhs) {
- return new LessThanOrEqualOperation(rhs[0], rhs[2]);
- };
- this.reduceActions[13] = function(rhs) {
- return new GreaterThanOrEqualOperation(rhs[0], rhs[2]);
- };
- this.reduceActions[15] = function(rhs) {
- return new PlusOperation(rhs[0], rhs[2]);
- };
- this.reduceActions[16] = function(rhs) {
- return new MinusOperation(rhs[0], rhs[2]);
- };
- this.reduceActions[18] = function(rhs) {
- return new MultiplyOperation(rhs[0], rhs[2]);
- };
- this.reduceActions[19] = function(rhs) {
- return new DivOperation(rhs[0], rhs[2]);
- };
- this.reduceActions[20] = function(rhs) {
- return new ModOperation(rhs[0], rhs[2]);
- };
- this.reduceActions[22] = function(rhs) {
- return new UnaryMinusOperation(rhs[1]);
- };
- this.reduceActions[24] = function(rhs) {
- return new BarOperation(rhs[0], rhs[2]);
- };
- this.reduceActions[25] = function(rhs) {
- return new PathExpr(undefined, undefined, rhs[0]);
- };
- this.reduceActions[27] = function(rhs) {
- rhs[0].locationPath = rhs[2];
- return rhs[0];
- };
- this.reduceActions[28] = function(rhs) {
- rhs[0].locationPath = rhs[2];
- rhs[0].locationPath.steps.unshift(new Step(Step.DESCENDANTORSELF, new NodeTest(NodeTest.NODE, undefined), []));
- return rhs[0];
- };
- this.reduceActions[29] = function(rhs) {
- return new PathExpr(rhs[0], [], undefined);
- };
- this.reduceActions[30] = function(rhs) {
- if (Utilities.instance_of(rhs[0], PathExpr)) {
- if (rhs[0].filterPredicates == undefined) {
- rhs[0].filterPredicates = [];
- }
- rhs[0].filterPredicates.push(rhs[1]);
- return rhs[0];
- } else {
- return new PathExpr(rhs[0], [rhs[1]], undefined);
- }
- };
- this.reduceActions[32] = function(rhs) {
- return rhs[1];
- };
- this.reduceActions[33] = function(rhs) {
- return new XString(rhs[0]);
- };
- this.reduceActions[34] = function(rhs) {
- return new XNumber(rhs[0]);
- };
- this.reduceActions[36] = function(rhs) {
- return new FunctionCall(rhs[0], []);
- };
- this.reduceActions[37] = function(rhs) {
- return new FunctionCall(rhs[0], rhs[2]);
- };
- this.reduceActions[38] = function(rhs) {
- return [ rhs[0] ];
- };
- this.reduceActions[39] = function(rhs) {
- rhs[2].unshift(rhs[0]);
- return rhs[2];
- };
- this.reduceActions[43] = function(rhs) {
- return new LocationPath(true, []);
- };
- this.reduceActions[44] = function(rhs) {
- rhs[1].absolute = true;
- return rhs[1];
- };
- this.reduceActions[46] = function(rhs) {
- return new LocationPath(false, [ rhs[0] ]);
- };
- this.reduceActions[47] = function(rhs) {
- rhs[0].steps.push(rhs[2]);
- return rhs[0];
- };
- this.reduceActions[49] = function(rhs) {
- return new Step(rhs[0], rhs[1], []);
- };
- this.reduceActions[50] = function(rhs) {
- return new Step(Step.CHILD, rhs[0], []);
- };
- this.reduceActions[51] = function(rhs) {
- return new Step(rhs[0], rhs[1], rhs[2]);
- };
- this.reduceActions[52] = function(rhs) {
- return new Step(Step.CHILD, rhs[0], rhs[1]);
- };
- this.reduceActions[54] = function(rhs) {
- return [ rhs[0] ];
- };
- this.reduceActions[55] = function(rhs) {
- rhs[1].unshift(rhs[0]);
- return rhs[1];
- };
- this.reduceActions[56] = function(rhs) {
- if (rhs[0] == "ancestor") {
- return Step.ANCESTOR;
- } else if (rhs[0] == "ancestor-or-self") {
- return Step.ANCESTORORSELF;
- } else if (rhs[0] == "attribute") {
- return Step.ATTRIBUTE;
- } else if (rhs[0] == "child") {
- return Step.CHILD;
- } else if (rhs[0] == "descendant") {
- return Step.DESCENDANT;
- } else if (rhs[0] == "descendant-or-self") {
- return Step.DESCENDANTORSELF;
- } else if (rhs[0] == "following") {
- return Step.FOLLOWING;
- } else if (rhs[0] == "following-sibling") {
- return Step.FOLLOWINGSIBLING;
- } else if (rhs[0] == "namespace") {
- return Step.NAMESPACE;
- } else if (rhs[0] == "parent") {
- return Step.PARENT;
- } else if (rhs[0] == "preceding") {
- return Step.PRECEDING;
- } else if (rhs[0] == "preceding-sibling") {
- return Step.PRECEDINGSIBLING;
- } else if (rhs[0] == "self") {
- return Step.SELF;
- }
- return -1;
- };
- this.reduceActions[57] = function(rhs) {
- return Step.ATTRIBUTE;
- };
- this.reduceActions[59] = function(rhs) {
- if (rhs[0] == "comment") {
- return new NodeTest(NodeTest.COMMENT, undefined);
- } else if (rhs[0] == "text") {
- return new NodeTest(NodeTest.TEXT, undefined);
- } else if (rhs[0] == "processing-instruction") {
- return new NodeTest(NodeTest.PI, undefined);
- } else if (rhs[0] == "node") {
- return new NodeTest(NodeTest.NODE, undefined);
- }
- return new NodeTest(-1, undefined);
- };
- this.reduceActions[60] = function(rhs) {
- return new NodeTest(NodeTest.PI, rhs[2]);
- };
- this.reduceActions[61] = function(rhs) {
- return rhs[1];
- };
- this.reduceActions[63] = function(rhs) {
- rhs[1].absolute = true;
- rhs[1].steps.unshift(new Step(Step.DESCENDANTORSELF, new NodeTest(NodeTest.NODE, undefined), []));
- return rhs[1];
- };
- this.reduceActions[64] = function(rhs) {
- rhs[0].steps.push(new Step(Step.DESCENDANTORSELF, new NodeTest(NodeTest.NODE, undefined), []));
- rhs[0].steps.push(rhs[2]);
- return rhs[0];
- };
- this.reduceActions[65] = function(rhs) {
- return new Step(Step.SELF, new NodeTest(NodeTest.NODE, undefined), []);
- };
- this.reduceActions[66] = function(rhs) {
- return new Step(Step.PARENT, new NodeTest(NodeTest.NODE, undefined), []);
- };
- this.reduceActions[67] = function(rhs) {
- return new VariableReference(rhs[1]);
- };
- this.reduceActions[68] = function(rhs) {
- return new NodeTest(NodeTest.NAMETESTANY, undefined);
- };
- this.reduceActions[69] = function(rhs) {
- var prefix = rhs[0].substring(0, rhs[0].indexOf(":"));
- return new NodeTest(NodeTest.NAMETESTPREFIXANY, prefix);
- };
- this.reduceActions[70] = function(rhs) {
- return new NodeTest(NodeTest.NAMETESTQNAME, rhs[0]);
- };
-};
-
-XPathParser.actionTable = [
- " s s sssssssss s ss s ss",
- " s ",
- "r rrrrrrrrr rrrrrrr rr r ",
- " rrrrr ",
- " s s sssssssss s ss s ss",
- "rs rrrrrrrr s sssssrrrrrr rrs rs ",
- " s s sssssssss s ss s ss",
- " s ",
- " s ",
- "r rrrrrrrrr rrrrrrr rr rr ",
- "r rrrrrrrrr rrrrrrr rr rr ",
- "r rrrrrrrrr rrrrrrr rr rr ",
- "r rrrrrrrrr rrrrrrr rr rr ",
- "r rrrrrrrrr rrrrrrr rr rr ",
- " s ",
- " s ",
- " s s sssss s s ",
- "r rrrrrrrrr rrrrrrr rr r ",
- "a ",
- "r s rr r ",
- "r sr rr r ",
- "r s rr s rr r ",
- "r rssrr rss rr r ",
- "r rrrrr rrrss rr r ",
- "r rrrrrsss rrrrr rr r ",
- "r rrrrrrrr rrrrr rr r ",
- "r rrrrrrrr rrrrrs rr r ",
- "r rrrrrrrr rrrrrr rr r ",
- "r rrrrrrrr rrrrrr rr r ",
- "r srrrrrrrr rrrrrrs rr sr ",
- "r srrrrrrrr rrrrrrs rr r ",
- "r rrrrrrrrr rrrrrrr rr rr ",
- "r rrrrrrrrr rrrrrrr rr rr ",
- "r rrrrrrrrr rrrrrrr rr rr ",
- "r rrrrrrrr rrrrrr rr r ",
- "r rrrrrrrr rrrrrr rr r ",
- "r rrrrrrrrr rrrrrrr rr r ",
- "r rrrrrrrrr rrrrrrr rr r ",
- " sssss ",
- "r rrrrrrrrr rrrrrrr rr sr ",
- "r rrrrrrrrr rrrrrrr rr r ",
- "r rrrrrrrrr rrrrrrr rr rr ",
- "r rrrrrrrrr rrrrrrr rr rr ",
- " s ",
- "r srrrrrrrr rrrrrrs rr r ",
- "r rrrrrrrr rrrrr rr r ",
- " s ",
- " s ",
- " rrrrr ",
- " s s sssssssss s sss s ss",
- "r srrrrrrrr rrrrrrs rr r ",
- " s s sssssssss s ss s ss",
- " s s sssssssss s ss s ss",
- " s s sssssssss s ss s ss",
- " s s sssssssss s ss s ss",
- " s s sssssssss s ss s ss",
- " s s sssssssss s ss s ss",
- " s s sssssssss s ss s ss",
- " s s sssssssss s ss s ss",
- " s s sssssssss s ss s ss",
- " s s sssssssss s ss s ss",
- " s s sssssssss s ss s ss",
- " s s sssssssss s ss s ss",
- " s s sssssssss s ss s ss",
- " s s sssssssss ss s ss",
- " s s sssssssss s ss s ss",
- " s s sssss s s ",
- " s s sssss s s ",
- "r rrrrrrrrr rrrrrrr rr rr ",
- " s s sssss s s ",
- " s s sssss s s ",
- "r rrrrrrrrr rrrrrrr rr sr ",
- "r rrrrrrrrr rrrrrrr rr sr ",
- "r rrrrrrrrr rrrrrrr rr r ",
- "r rrrrrrrrr rrrrrrr rr rr ",
- " s ",
- "r rrrrrrrrr rrrrrrr rr rr ",
- "r rrrrrrrrr rrrrrrr rr rr ",
- " rr ",
- " s ",
- " rs ",
- "r sr rr r ",
- "r s rr s rr r ",
- "r rssrr rss rr r ",
- "r rssrr rss rr r ",
- "r rrrrr rrrss rr r ",
- "r rrrrr rrrss rr r ",
- "r rrrrr rrrss rr r ",
- "r rrrrr rrrss rr r ",
- "r rrrrrsss rrrrr rr r ",
- "r rrrrrsss rrrrr rr r ",
- "r rrrrrrrr rrrrr rr r ",
- "r rrrrrrrr rrrrr rr r ",
- "r rrrrrrrr rrrrr rr r ",
- "r rrrrrrrr rrrrrr rr r ",
- " r ",
- " s ",
- "r srrrrrrrr rrrrrrs rr r ",
- "r srrrrrrrr rrrrrrs rr r ",
- "r rrrrrrrrr rrrrrrr rr r ",
- "r rrrrrrrrr rrrrrrr rr r ",
- "r rrrrrrrrr rrrrrrr rr r ",
- "r rrrrrrrrr rrrrrrr rr r ",
- "r rrrrrrrrr rrrrrrr rr rr ",
- "r rrrrrrrrr rrrrrrr rr rr ",
- " s s sssssssss s ss s ss",
- "r rrrrrrrrr rrrrrrr rr rr ",
- " r "
-];
-
-XPathParser.actionTableNumber = [
- " 1 0 /.-,+*)(' & %$ # \"!",
- " J ",
- "a aaaaaaaaa aaaaaaa aa a ",
- " YYYYY ",
- " 1 0 /.-,+*)(' & %$ # \"!",
- "K1 KKKKKKKK . +*)('KKKKKK KK# K\" ",
- " 1 0 /.-,+*)(' & %$ # \"!",
- " N ",
- " O ",
- "e eeeeeeeee eeeeeee ee ee ",
- "f fffffffff fffffff ff ff ",
- "d ddddddddd ddddddd dd dd ",
- "B BBBBBBBBB BBBBBBB BB BB ",
- "A AAAAAAAAA AAAAAAA AA AA ",
- " P ",
- " Q ",
- " 1 . +*)(' # \" ",
- "b bbbbbbbbb bbbbbbb bb b ",
- " ",
- "! S !! ! ",
- "\" T\" \"\" \" ",
- "$ V $$ U $$ $ ",
- "& &ZY&& &XW && & ",
- ") ))))) )))\\[ )) ) ",
- ". ....._^] ..... .. . ",
- "1 11111111 11111 11 1 ",
- "5 55555555 55555` 55 5 ",
- "7 77777777 777777 77 7 ",
- "9 99999999 999999 99 9 ",
- ": c:::::::: ::::::b :: a: ",
- "I fIIIIIIII IIIIIIe II I ",
- "= ========= ======= == == ",
- "? ????????? ??????? ?? ?? ",
- "C CCCCCCCCC CCCCCCC CC CC ",
- "J JJJJJJJJ JJJJJJ JJ J ",
- "M MMMMMMMM MMMMMM MM M ",
- "N NNNNNNNNN NNNNNNN NN N ",
- "P PPPPPPPPP PPPPPPP PP P ",
- " +*)(' ",
- "R RRRRRRRRR RRRRRRR RR aR ",
- "U UUUUUUUUU UUUUUUU UU U ",
- "Z ZZZZZZZZZ ZZZZZZZ ZZ ZZ ",
- "c ccccccccc ccccccc cc cc ",
- " j ",
- "L fLLLLLLLL LLLLLLe LL L ",
- "6 66666666 66666 66 6 ",
- " k ",
- " l ",
- " XXXXX ",
- " 1 0 /.-,+*)(' & %$m # \"!",
- "_ f________ ______e __ _ ",
- " 1 0 /.-,+*)(' & %$ # \"!",
- " 1 0 /.-,+*)(' & %$ # \"!",
- " 1 0 /.-,+*)(' & %$ # \"!",
- " 1 0 /.-,+*)(' & %$ # \"!",
- " 1 0 /.-,+*)(' & %$ # \"!",
- " 1 0 /.-,+*)(' & %$ # \"!",
- " 1 0 /.-,+*)(' & %$ # \"!",
- " 1 0 /.-,+*)(' & %$ # \"!",
- " 1 0 /.-,+*)(' & %$ # \"!",
- " 1 0 /.-,+*)(' & %$ # \"!",
- " 1 0 /.-,+*)(' & %$ # \"!",
- " 1 0 /.-,+*)(' & %$ # \"!",
- " 1 0 /.-,+*)(' & %$ # \"!",
- " 1 0 /.-,+*)(' %$ # \"!",
- " 1 0 /.-,+*)(' & %$ # \"!",
- " 1 . +*)(' # \" ",
- " 1 . +*)(' # \" ",
- "> >>>>>>>>> >>>>>>> >> >> ",
- " 1 . +*)(' # \" ",
- " 1 . +*)(' # \" ",
- "Q QQQQQQQQQ QQQQQQQ QQ aQ ",
- "V VVVVVVVVV VVVVVVV VV aV ",
- "T TTTTTTTTT TTTTTTT TT T ",
- "@ @@@@@@@@@ @@@@@@@ @@ @@ ",
- " \x87 ",
- "[ [[[[[[[[[ [[[[[[[ [[ [[ ",
- "D DDDDDDDDD DDDDDDD DD DD ",
- " HH ",
- " \x88 ",
- " F\x89 ",
- "# T# ## # ",
- "% V %% U %% % ",
- "' 'ZY'' 'XW '' ' ",
- "( (ZY(( (XW (( ( ",
- "+ +++++ +++\\[ ++ + ",
- "* ***** ***\\[ ** * ",
- "- ----- ---\\[ -- - ",
- ", ,,,,, ,,,\\[ ,, , ",
- "0 00000_^] 00000 00 0 ",
- "/ /////_^] ///// // / ",
- "2 22222222 22222 22 2 ",
- "3 33333333 33333 33 3 ",
- "4 44444444 44444 44 4 ",
- "8 88888888 888888 88 8 ",
- " ^ ",
- " \x8a ",
- "; f;;;;;;;; ;;;;;;e ;; ; ",
- "< f<<<<<<<< <<<<<<e << < ",
- "O OOOOOOOOO OOOOOOO OO O ",
- "` ````````` ``````` `` ` ",
- "S SSSSSSSSS SSSSSSS SS S ",
- "W WWWWWWWWW WWWWWWW WW W ",
- "\\ \\\\\\\\\\\\\\\\\\ \\\\\\\\\\\\\\ \\\\ \\\\ ",
- "E EEEEEEEEE EEEEEEE EE EE ",
- " 1 0 /.-,+*)(' & %$ # \"!",
- "] ]]]]]]]]] ]]]]]]] ]] ]] ",
- " G "
-];
-
-XPathParser.gotoTable = [
- "3456789:;<=>?@ AB CDEFGH IJ ",
- " ",
- " ",
- " ",
- "L456789:;<=>?@ AB CDEFGH IJ ",
- " M EFGH IJ ",
- " N;<=>?@ AB CDEFGH IJ ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " S EFGH IJ ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " e ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " h J ",
- " i j ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- "o456789:;<=>?@ ABpqCDEFGH IJ ",
- " ",
- " r6789:;<=>?@ AB CDEFGH IJ ",
- " s789:;<=>?@ AB CDEFGH IJ ",
- " t89:;<=>?@ AB CDEFGH IJ ",
- " u89:;<=>?@ AB CDEFGH IJ ",
- " v9:;<=>?@ AB CDEFGH IJ ",
- " w9:;<=>?@ AB CDEFGH IJ ",
- " x9:;<=>?@ AB CDEFGH IJ ",
- " y9:;<=>?@ AB CDEFGH IJ ",
- " z:;<=>?@ AB CDEFGH IJ ",
- " {:;<=>?@ AB CDEFGH IJ ",
- " |;<=>?@ AB CDEFGH IJ ",
- " };<=>?@ AB CDEFGH IJ ",
- " ~;<=>?@ AB CDEFGH IJ ",
- " \x7f=>?@ AB CDEFGH IJ ",
- "\x80456789:;<=>?@ AB CDEFGH IJ\x81",
- " \x82 EFGH IJ ",
- " \x83 EFGH IJ ",
- " ",
- " \x84 GH IJ ",
- " \x85 GH IJ ",
- " i \x86 ",
- " i \x87 ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- " ",
- "o456789:;<=>?@ AB\x8cqCDEFGH IJ ",
- " ",
- " "
-];
-
-XPathParser.productions = [
- [1, 1, 2],
- [2, 1, 3],
- [3, 1, 4],
- [3, 3, 3, -9, 4],
- [4, 1, 5],
- [4, 3, 4, -8, 5],
- [5, 1, 6],
- [5, 3, 5, -22, 6],
- [5, 3, 5, -5, 6],
- [6, 1, 7],
- [6, 3, 6, -23, 7],
- [6, 3, 6, -24, 7],
- [6, 3, 6, -6, 7],
- [6, 3, 6, -7, 7],
- [7, 1, 8],
- [7, 3, 7, -25, 8],
- [7, 3, 7, -26, 8],
- [8, 1, 9],
- [8, 3, 8, -12, 9],
- [8, 3, 8, -11, 9],
- [8, 3, 8, -10, 9],
- [9, 1, 10],
- [9, 2, -26, 9],
- [10, 1, 11],
- [10, 3, 10, -27, 11],
- [11, 1, 12],
- [11, 1, 13],
- [11, 3, 13, -28, 14],
- [11, 3, 13, -4, 14],
- [13, 1, 15],
- [13, 2, 13, 16],
- [15, 1, 17],
- [15, 3, -29, 2, -30],
- [15, 1, -15],
- [15, 1, -16],
- [15, 1, 18],
- [18, 3, -13, -29, -30],
- [18, 4, -13, -29, 19, -30],
- [19, 1, 20],
- [19, 3, 20, -31, 19],
- [20, 1, 2],
- [12, 1, 14],
- [12, 1, 21],
- [21, 1, -28],
- [21, 2, -28, 14],
- [21, 1, 22],
- [14, 1, 23],
- [14, 3, 14, -28, 23],
- [14, 1, 24],
- [23, 2, 25, 26],
- [23, 1, 26],
- [23, 3, 25, 26, 27],
- [23, 2, 26, 27],
- [23, 1, 28],
- [27, 1, 16],
- [27, 2, 16, 27],
- [25, 2, -14, -3],
- [25, 1, -32],
- [26, 1, 29],
- [26, 3, -20, -29, -30],
- [26, 4, -21, -29, -15, -30],
- [16, 3, -33, 30, -34],
- [30, 1, 2],
- [22, 2, -4, 14],
- [24, 3, 14, -4, 23],
- [28, 1, -35],
- [28, 1, -2],
- [17, 2, -36, -18],
- [29, 1, -17],
- [29, 1, -19],
- [29, 1, -18]
-];
-
-XPathParser.DOUBLEDOT = 2;
-XPathParser.DOUBLECOLON = 3;
-XPathParser.DOUBLESLASH = 4;
-XPathParser.NOTEQUAL = 5;
-XPathParser.LESSTHANOREQUAL = 6;
-XPathParser.GREATERTHANOREQUAL = 7;
-XPathParser.AND = 8;
-XPathParser.OR = 9;
-XPathParser.MOD = 10;
-XPathParser.DIV = 11;
-XPathParser.MULTIPLYOPERATOR = 12;
-XPathParser.FUNCTIONNAME = 13;
-XPathParser.AXISNAME = 14;
-XPathParser.LITERAL = 15;
-XPathParser.NUMBER = 16;
-XPathParser.ASTERISKNAMETEST = 17;
-XPathParser.QNAME = 18;
-XPathParser.NCNAMECOLONASTERISK = 19;
-XPathParser.NODETYPE = 20;
-XPathParser.PROCESSINGINSTRUCTIONWITHLITERAL = 21;
-XPathParser.EQUALS = 22;
-XPathParser.LESSTHAN = 23;
-XPathParser.GREATERTHAN = 24;
-XPathParser.PLUS = 25;
-XPathParser.MINUS = 26;
-XPathParser.BAR = 27;
-XPathParser.SLASH = 28;
-XPathParser.LEFTPARENTHESIS = 29;
-XPathParser.RIGHTPARENTHESIS = 30;
-XPathParser.COMMA = 31;
-XPathParser.AT = 32;
-XPathParser.LEFTBRACKET = 33;
-XPathParser.RIGHTBRACKET = 34;
-XPathParser.DOT = 35;
-XPathParser.DOLLAR = 36;
-
-XPathParser.prototype.tokenize = function(s1) {
- var types = [];
- var values = [];
- var s = s1 + '\0';
-
- var pos = 0;
- var c = s.charAt(pos++);
- while (1) {
- while (c == ' ' || c == '\t' || c == '\r' || c == '\n') {
- c = s.charAt(pos++);
- }
- if (c == '\0' || pos >= s.length) {
- break;
- }
-
- if (c == '(') {
- types.push(XPathParser.LEFTPARENTHESIS);
- values.push(c);
- c = s.charAt(pos++);
- continue;
- }
- if (c == ')') {
- types.push(XPathParser.RIGHTPARENTHESIS);
- values.push(c);
- c = s.charAt(pos++);
- continue;
- }
- if (c == '[') {
- types.push(XPathParser.LEFTBRACKET);
- values.push(c);
- c = s.charAt(pos++);
- continue;
- }
- if (c == ']') {
- types.push(XPathParser.RIGHTBRACKET);
- values.push(c);
- c = s.charAt(pos++);
- continue;
- }
- if (c == '@') {
- types.push(XPathParser.AT);
- values.push(c);
- c = s.charAt(pos++);
- continue;
- }
- if (c == ',') {
- types.push(XPathParser.COMMA);
- values.push(c);
- c = s.charAt(pos++);
- continue;
- }
- if (c == '|') {
- types.push(XPathParser.BAR);
- values.push(c);
- c = s.charAt(pos++);
- continue;
- }
- if (c == '+') {
- types.push(XPathParser.PLUS);
- values.push(c);
- c = s.charAt(pos++);
- continue;
- }
- if (c == '-') {
- types.push(XPathParser.MINUS);
- values.push(c);
- c = s.charAt(pos++);
- continue;
- }
- if (c == '=') {
- types.push(XPathParser.EQUALS);
- values.push(c);
- c = s.charAt(pos++);
- continue;
- }
- if (c == '$') {
- types.push(XPathParser.DOLLAR);
- values.push(c);
- c = s.charAt(pos++);
- continue;
- }
-
- if (c == '.') {
- c = s.charAt(pos++);
- if (c == '.') {
- types.push(XPathParser.DOUBLEDOT);
- values.push("..");
- c = s.charAt(pos++);
- continue;
- }
- if (c >= '0' && c <= '9') {
- var number = "." + c;
- c = s.charAt(pos++);
- while (c >= '0' && c <= '9') {
- number += c;
- c = s.charAt(pos++);
- }
- types.push(XPathParser.NUMBER);
- values.push(number);
- continue;
- }
- types.push(XPathParser.DOT);
- values.push('.');
- continue;
- }
-
- if (c == '\'' || c == '"') {
- var delimiter = c;
- var literal = "";
- while ((c = s.charAt(pos++)) != delimiter) {
- literal += c;
- }
- types.push(XPathParser.LITERAL);
- values.push(literal);
- c = s.charAt(pos++);
- continue;
- }
-
- if (c >= '0' && c <= '9') {
- var number = c;
- c = s.charAt(pos++);
- while (c >= '0' && c <= '9') {
- number += c;
- c = s.charAt(pos++);
- }
- if (c == '.') {
- if (s.charAt(pos) >= '0' && s.charAt(pos) <= '9') {
- number += c;
- number += s.charAt(pos++);
- c = s.charAt(pos++);
- while (c >= '0' && c <= '9') {
- number += c;
- c = s.charAt(pos++);
- }
- }
- }
- types.push(XPathParser.NUMBER);
- values.push(number);
- continue;
- }
-
- if (c == '*') {
- if (types.length > 0) {
- var last = types[types.length - 1];
- if (last != XPathParser.AT
- && last != XPathParser.DOUBLECOLON
- && last != XPathParser.LEFTPARENTHESIS
- && last != XPathParser.LEFTBRACKET
- && last != XPathParser.AND
- && last != XPathParser.OR
- && last != XPathParser.MOD
- && last != XPathParser.DIV
- && last != XPathParser.MULTIPLYOPERATOR
- && last != XPathParser.SLASH
- && last != XPathParser.DOUBLESLASH
- && last != XPathParser.BAR
- && last != XPathParser.PLUS
- && last != XPathParser.MINUS
- && last != XPathParser.EQUALS
- && last != XPathParser.NOTEQUAL
- && last != XPathParser.LESSTHAN
- && last != XPathParser.LESSTHANOREQUAL
- && last != XPathParser.GREATERTHAN
- && last != XPathParser.GREATERTHANOREQUAL) {
- types.push(XPathParser.MULTIPLYOPERATOR);
- values.push(c);
- c = s.charAt(pos++);
- continue;
- }
- }
- types.push(XPathParser.ASTERISKNAMETEST);
- values.push(c);
- c = s.charAt(pos++);
- continue;
- }
-
- if (c == ':') {
- if (s.charAt(pos) == ':') {
- types.push(XPathParser.DOUBLECOLON);
- values.push("::");
- pos++;
- c = s.charAt(pos++);
- continue;
- }
- }
-
- if (c == '/') {
- c = s.charAt(pos++);
- if (c == '/') {
- types.push(XPathParser.DOUBLESLASH);
- values.push("//");
- c = s.charAt(pos++);
- continue;
- }
- types.push(XPathParser.SLASH);
- values.push('/');
- continue;
- }
-
- if (c == '!') {
- if (s.charAt(pos) == '=') {
- types.push(XPathParser.NOTEQUAL);
- values.push("!=");
- pos++;
- c = s.charAt(pos++);
- continue;
- }
- }
-
- if (c == '<') {
- if (s.charAt(pos) == '=') {
- types.push(XPathParser.LESSTHANOREQUAL);
- values.push("<=");
- pos++;
- c = s.charAt(pos++);
- continue;
- }
- types.push(XPathParser.LESSTHAN);
- values.push('<');
- c = s.charAt(pos++);
- continue;
- }
-
- if (c == '>') {
- if (s.charAt(pos) == '=') {
- types.push(XPathParser.GREATERTHANOREQUAL);
- values.push(">=");
- pos++;
- c = s.charAt(pos++);
- continue;
- }
- types.push(XPathParser.GREATERTHAN);
- values.push('>');
- c = s.charAt(pos++);
- continue;
- }
-
- if (c == '_' || Utilities.isLetter(c.charCodeAt(0))) {
- var name = c;
- c = s.charAt(pos++);
- while (Utilities.isNCNameChar(c.charCodeAt(0))) {
- name += c;
- c = s.charAt(pos++);
- }
- if (types.length > 0) {
- var last = types[types.length - 1];
- if (last != XPathParser.AT
- && last != XPathParser.DOUBLECOLON
- && last != XPathParser.LEFTPARENTHESIS
- && last != XPathParser.LEFTBRACKET
- && last != XPathParser.AND
- && last != XPathParser.OR
- && last != XPathParser.MOD
- && last != XPathParser.DIV
- && last != XPathParser.MULTIPLYOPERATOR
- && last != XPathParser.SLASH
- && last != XPathParser.DOUBLESLASH
- && last != XPathParser.BAR
- && last != XPathParser.PLUS
- && last != XPathParser.MINUS
- && last != XPathParser.EQUALS
- && last != XPathParser.NOTEQUAL
- && last != XPathParser.LESSTHAN
- && last != XPathParser.LESSTHANOREQUAL
- && last != XPathParser.GREATERTHAN
- && last != XPathParser.GREATERTHANOREQUAL) {
- if (name == "and") {
- types.push(XPathParser.AND);
- values.push(name);
- continue;
- }
- if (name == "or") {
- types.push(XPathParser.OR);
- values.push(name);
- continue;
- }
- if (name == "mod") {
- types.push(XPathParser.MOD);
- values.push(name);
- continue;
- }
- if (name == "div") {
- types.push(XPathParser.DIV);
- values.push(name);
- continue;
- }
- }
- }
- if (c == ':') {
- if (s.charAt(pos) == '*') {
- types.push(XPathParser.NCNAMECOLONASTERISK);
- values.push(name + ":*");
- pos++;
- c = s.charAt(pos++);
- continue;
- }
- if (s.charAt(pos) == '_' || Utilities.isLetter(s.charCodeAt(pos))) {
- name += ':';
- c = s.charAt(pos++);
- while (Utilities.isNCNameChar(c.charCodeAt(0))) {
- name += c;
- c = s.charAt(pos++);
- }
- if (c == '(') {
- types.push(XPathParser.FUNCTIONNAME);
- values.push(name);
- continue;
- }
- types.push(XPathParser.QNAME);
- values.push(name);
- continue;
- }
- if (s.charAt(pos) == ':') {
- types.push(XPathParser.AXISNAME);
- values.push(name);
- continue;
- }
- }
- if (c == '(') {
- if (name == "comment" || name == "text" || name == "node") {
- types.push(XPathParser.NODETYPE);
- values.push(name);
- continue;
- }
- if (name == "processing-instruction") {
- if (s.charAt(pos) == ')') {
- types.push(XPathParser.NODETYPE);
- } else {
- types.push(XPathParser.PROCESSINGINSTRUCTIONWITHLITERAL);
- }
- values.push(name);
- continue;
- }
- types.push(XPathParser.FUNCTIONNAME);
- values.push(name);
- continue;
- }
- types.push(XPathParser.QNAME);
- values.push(name);
- continue;
- }
-
- throw new Error("Unexpected character " + c);
- }
- types.push(1);
- values.push("[EOF]");
- return [types, values];
-};
-
-XPathParser.SHIFT = 's';
-XPathParser.REDUCE = 'r';
-XPathParser.ACCEPT = 'a';
-
-XPathParser.prototype.parse = function(s) {
- var types;
- var values;
- var res = this.tokenize(s);
- if (res == undefined) {
- return undefined;
- }
- types = res[0];
- values = res[1];
- var tokenPos = 0;
- var state = [];
- var tokenType = [];
- var tokenValue = [];
- var s;
- var a;
- var t;
-
- state.push(0);
- tokenType.push(1);
- tokenValue.push("_S");
-
- a = types[tokenPos];
- t = values[tokenPos++];
- while (1) {
- s = state[state.length - 1];
- switch (XPathParser.actionTable[s].charAt(a - 1)) {
- case XPathParser.SHIFT:
- tokenType.push(-a);
- tokenValue.push(t);
- state.push(XPathParser.actionTableNumber[s].charCodeAt(a - 1) - 32);
- a = types[tokenPos];
- t = values[tokenPos++];
- break;
- case XPathParser.REDUCE:
- var num = XPathParser.productions[XPathParser.actionTableNumber[s].charCodeAt(a - 1) - 32][1];
- var rhs = [];
- for (var i = 0; i < num; i++) {
- tokenType.pop();
- rhs.unshift(tokenValue.pop());
- state.pop();
- }
- var s_ = state[state.length - 1];
- tokenType.push(XPathParser.productions[XPathParser.actionTableNumber[s].charCodeAt(a - 1) - 32][0]);
- if (this.reduceActions[XPathParser.actionTableNumber[s].charCodeAt(a - 1) - 32] == undefined) {
- tokenValue.push(rhs[0]);
- } else {
- tokenValue.push(this.reduceActions[XPathParser.actionTableNumber[s].charCodeAt(a - 1) - 32](rhs));
- }
- state.push(XPathParser.gotoTable[s_].charCodeAt(XPathParser.productions[XPathParser.actionTableNumber[s].charCodeAt(a - 1) - 32][0] - 2) - 33);
- break;
- case XPathParser.ACCEPT:
- return new XPath(tokenValue.pop());
- default:
- throw new Error("XPath parse error");
- }
- }
-};
-
-// XPath /////////////////////////////////////////////////////////////////////
-
-XPath.prototype = new Object();
-XPath.prototype.constructor = XPath;
-XPath.superclass = Object.prototype;
-
-function XPath(e) {
- this.expression = e;
-}
-
-XPath.prototype.toString = function() {
- return this.expression.toString();
-};
-
-XPath.prototype.evaluate = function(c) {
- c.contextNode = c.expressionContextNode;
- c.contextSize = 1;
- c.contextPosition = 1;
- c.caseInsensitive = false;
- if (c.contextNode != null) {
- var doc = c.contextNode;
- if (doc.nodeType != 9 /*Node.DOCUMENT_NODE*/) {
- doc = doc.ownerDocument;
- }
- try {
- c.caseInsensitive = doc.implementation.hasFeature("HTML", "2.0");
- } catch (e) {
- c.caseInsensitive = true;
- }
- }
- return this.expression.evaluate(c);
-};
-
-XPath.XML_NAMESPACE_URI = "http://www.w3.org/XML/1998/namespace";
-XPath.XMLNS_NAMESPACE_URI = "http://www.w3.org/2000/xmlns/";
-
-// Expression ////////////////////////////////////////////////////////////////
-
-Expression.prototype = new Object();
-Expression.prototype.constructor = Expression;
-Expression.superclass = Object.prototype;
-
-function Expression() {
-}
-
-Expression.prototype.init = function() {
-};
-
-Expression.prototype.toString = function() {
- return "<Expression>";
-};
-
-Expression.prototype.evaluate = function(c) {
- throw new Error("Could not evaluate expression.");
-};
-
-// UnaryOperation ////////////////////////////////////////////////////////////
-
-UnaryOperation.prototype = new Expression();
-UnaryOperation.prototype.constructor = UnaryOperation;
-UnaryOperation.superclass = Expression.prototype;
-
-function UnaryOperation(rhs) {
- if (arguments.length > 0) {
- this.init(rhs);
- }
-}
-
-UnaryOperation.prototype.init = function(rhs) {
- this.rhs = rhs;
-};
-
-// UnaryMinusOperation ///////////////////////////////////////////////////////
-
-UnaryMinusOperation.prototype = new UnaryOperation();
-UnaryMinusOperation.prototype.constructor = UnaryMinusOperation;
-UnaryMinusOperation.superclass = UnaryOperation.prototype;
-
-function UnaryMinusOperation(rhs) {
- if (arguments.length > 0) {
- this.init(rhs);
- }
-}
-
-UnaryMinusOperation.prototype.init = function(rhs) {
- UnaryMinusOperation.superclass.init.call(this, rhs);
-};
-
-UnaryMinusOperation.prototype.evaluate = function(c) {
- return this.rhs.evaluate(c).number().negate();
-};
-
-UnaryMinusOperation.prototype.toString = function() {
- return "-" + this.rhs.toString();
-};
-
-// BinaryOperation ///////////////////////////////////////////////////////////
-
-BinaryOperation.prototype = new Expression();
-BinaryOperation.prototype.constructor = BinaryOperation;
-BinaryOperation.superclass = Expression.prototype;
-
-function BinaryOperation(lhs, rhs) {
- if (arguments.length > 0) {
- this.init(lhs, rhs);
- }
-}
-
-BinaryOperation.prototype.init = function(lhs, rhs) {
- this.lhs = lhs;
- this.rhs = rhs;
-};
-
-// OrOperation ///////////////////////////////////////////////////////////////
-
-OrOperation.prototype = new BinaryOperation();
-OrOperation.prototype.constructor = OrOperation;
-OrOperation.superclass = BinaryOperation.prototype;
-
-function OrOperation(lhs, rhs) {
- if (arguments.length > 0) {
- this.init(lhs, rhs);
- }
-}
-
-OrOperation.prototype.init = function(lhs, rhs) {
- OrOperation.superclass.init.call(this, lhs, rhs);
-};
-
-OrOperation.prototype.toString = function() {
- return "(" + this.lhs.toString() + " or " + this.rhs.toString() + ")";
-};
-
-OrOperation.prototype.evaluate = function(c) {
- var b = this.lhs.evaluate(c).bool();
- if (b.booleanValue()) {
- return b;
- }
- return this.rhs.evaluate(c).bool();
-};
-
-// AndOperation //////////////////////////////////////////////////////////////
-
-AndOperation.prototype = new BinaryOperation();
-AndOperation.prototype.constructor = AndOperation;
-AndOperation.superclass = BinaryOperation.prototype;
-
-function AndOperation(lhs, rhs) {
- if (arguments.length > 0) {
- this.init(lhs, rhs);
- }
-}
-
-AndOperation.prototype.init = function(lhs, rhs) {
- AndOperation.superclass.init.call(this, lhs, rhs);
-};
-
-AndOperation.prototype.toString = function() {
- return "(" + this.lhs.toString() + " and " + this.rhs.toString() + ")";
-};
-
-AndOperation.prototype.evaluate = function(c) {
- var b = this.lhs.evaluate(c).bool();
- if (!b.booleanValue()) {
- return b;
- }
- return this.rhs.evaluate(c).bool();
-};
-
-// EqualsOperation ///////////////////////////////////////////////////////////
-
-EqualsOperation.prototype = new BinaryOperation();
-EqualsOperation.prototype.constructor = EqualsOperation;
-EqualsOperation.superclass = BinaryOperation.prototype;
-
-function EqualsOperation(lhs, rhs) {
- if (arguments.length > 0) {
- this.init(lhs, rhs);
- }
-}
-
-EqualsOperation.prototype.init = function(lhs, rhs) {
- EqualsOperation.superclass.init.call(this, lhs, rhs);
-};
-
-EqualsOperation.prototype.toString = function() {
- return "(" + this.lhs.toString() + " = " + this.rhs.toString() + ")";
-};
-
-EqualsOperation.prototype.evaluate = function(c) {
- return this.lhs.evaluate(c).equals(this.rhs.evaluate(c));
-};
-
-// NotEqualOperation /////////////////////////////////////////////////////////
-
-NotEqualOperation.prototype = new BinaryOperation();
-NotEqualOperation.prototype.constructor = NotEqualOperation;
-NotEqualOperation.superclass = BinaryOperation.prototype;
-
-function NotEqualOperation(lhs, rhs) {
- if (arguments.length > 0) {
- this.init(lhs, rhs);
- }
-}
-
-NotEqualOperation.prototype.init = function(lhs, rhs) {
- NotEqualOperation.superclass.init.call(this, lhs, rhs);
-};
-
-NotEqualOperation.prototype.toString = function() {
- return "(" + this.lhs.toString() + " != " + this.rhs.toString() + ")";
-};
-
-NotEqualOperation.prototype.evaluate = function(c) {
- return this.lhs.evaluate(c).notequal(this.rhs.evaluate(c));
-};
-
-// LessThanOperation /////////////////////////////////////////////////////////
-
-LessThanOperation.prototype = new BinaryOperation();
-LessThanOperation.prototype.constructor = LessThanOperation;
-LessThanOperation.superclass = BinaryOperation.prototype;
-
-function LessThanOperation(lhs, rhs) {
- if (arguments.length > 0) {
- this.init(lhs, rhs);
- }
-}
-
-LessThanOperation.prototype.init = function(lhs, rhs) {
- LessThanOperation.superclass.init.call(this, lhs, rhs);
-};
-
-LessThanOperation.prototype.evaluate = function(c) {
- return this.lhs.evaluate(c).lessthan(this.rhs.evaluate(c));
-};
-
-LessThanOperation.prototype.toString = function() {
- return "(" + this.lhs.toString() + " < " + this.rhs.toString() + ")";
-};
-
-// GreaterThanOperation //////////////////////////////////////////////////////
-
-GreaterThanOperation.prototype = new BinaryOperation();
-GreaterThanOperation.prototype.constructor = GreaterThanOperation;
-GreaterThanOperation.superclass = BinaryOperation.prototype;
-
-function GreaterThanOperation(lhs, rhs) {
- if (arguments.length > 0) {
- this.init(lhs, rhs);
- }
-}
-
-GreaterThanOperation.prototype.init = function(lhs, rhs) {
- GreaterThanOperation.superclass.init.call(this, lhs, rhs);
-};
-
-GreaterThanOperation.prototype.evaluate = function(c) {
- return this.lhs.evaluate(c).greaterthan(this.rhs.evaluate(c));
-};
-
-GreaterThanOperation.prototype.toString = function() {
- return "(" + this.lhs.toString() + " > " + this.rhs.toString() + ")";
-};
-
-// LessThanOrEqualOperation //////////////////////////////////////////////////
-
-LessThanOrEqualOperation.prototype = new BinaryOperation();
-LessThanOrEqualOperation.prototype.constructor = LessThanOrEqualOperation;
-LessThanOrEqualOperation.superclass = BinaryOperation.prototype;
-
-function LessThanOrEqualOperation(lhs, rhs) {
- if (arguments.length > 0) {
- this.init(lhs, rhs);
- }
-}
-
-LessThanOrEqualOperation.prototype.init = function(lhs, rhs) {
- LessThanOrEqualOperation.superclass.init.call(this, lhs, rhs);
-};
-
-LessThanOrEqualOperation.prototype.evaluate = function(c) {
- return this.lhs.evaluate(c).lessthanorequal(this.rhs.evaluate(c));
-};
-
-LessThanOrEqualOperation.prototype.toString = function() {
- return "(" + this.lhs.toString() + " <= " + this.rhs.toString() + ")";
-};
-
-// GreaterThanOrEqualOperation ///////////////////////////////////////////////
-
-GreaterThanOrEqualOperation.prototype = new BinaryOperation();
-GreaterThanOrEqualOperation.prototype.constructor = GreaterThanOrEqualOperation;
-GreaterThanOrEqualOperation.superclass = BinaryOperation.prototype;
-
-function GreaterThanOrEqualOperation(lhs, rhs) {
- if (arguments.length > 0) {
- this.init(lhs, rhs);
- }
-}
-
-GreaterThanOrEqualOperation.prototype.init = function(lhs, rhs) {
- GreaterThanOrEqualOperation.superclass.init.call(this, lhs, rhs);
-};
-
-GreaterThanOrEqualOperation.prototype.evaluate = function(c) {
- return this.lhs.evaluate(c).greaterthanorequal(this.rhs.evaluate(c));
-};
-
-GreaterThanOrEqualOperation.prototype.toString = function() {
- return "(" + this.lhs.toString() + " >= " + this.rhs.toString() + ")";
-};
-
-// PlusOperation /////////////////////////////////////////////////////////////
-
-PlusOperation.prototype = new BinaryOperation();
-PlusOperation.prototype.constructor = PlusOperation;
-PlusOperation.superclass = BinaryOperation.prototype;
-
-function PlusOperation(lhs, rhs) {
- if (arguments.length > 0) {
- this.init(lhs, rhs);
- }
-}
-
-PlusOperation.prototype.init = function(lhs, rhs) {
- PlusOperation.superclass.init.call(this, lhs, rhs);
-};
-
-PlusOperation.prototype.evaluate = function(c) {
- return this.lhs.evaluate(c).number().plus(this.rhs.evaluate(c).number());
-};
-
-PlusOperation.prototype.toString = function() {
- return "(" + this.lhs.toString() + " + " + this.rhs.toString() + ")";
-};
-
-// MinusOperation ////////////////////////////////////////////////////////////
-
-MinusOperation.prototype = new BinaryOperation();
-MinusOperation.prototype.constructor = MinusOperation;
-MinusOperation.superclass = BinaryOperation.prototype;
-
-function MinusOperation(lhs, rhs) {
- if (arguments.length > 0) {
- this.init(lhs, rhs);
- }
-}
-
-MinusOperation.prototype.init = function(lhs, rhs) {
- MinusOperation.superclass.init.call(this, lhs, rhs);
-};
-
-MinusOperation.prototype.evaluate = function(c) {
- return this.lhs.evaluate(c).number().minus(this.rhs.evaluate(c).number());
-};
-
-MinusOperation.prototype.toString = function() {
- return "(" + this.lhs.toString() + " - " + this.rhs.toString() + ")";
-};
-
-// MultiplyOperation /////////////////////////////////////////////////////////
-
-MultiplyOperation.prototype = new BinaryOperation();
-MultiplyOperation.prototype.constructor = MultiplyOperation;
-MultiplyOperation.superclass = BinaryOperation.prototype;
-
-function MultiplyOperation(lhs, rhs) {
- if (arguments.length > 0) {
- this.init(lhs, rhs);
- }
-}
-
-MultiplyOperation.prototype.init = function(lhs, rhs) {
- MultiplyOperation.superclass.init.call(this, lhs, rhs);
-};
-
-MultiplyOperation.prototype.evaluate = function(c) {
- return this.lhs.evaluate(c).number().multiply(this.rhs.evaluate(c).number());
-};
-
-MultiplyOperation.prototype.toString = function() {
- return "(" + this.lhs.toString() + " * " + this.rhs.toString() + ")";
-};
-
-// DivOperation //////////////////////////////////////////////////////////////
-
-DivOperation.prototype = new BinaryOperation();
-DivOperation.prototype.constructor = DivOperation;
-DivOperation.superclass = BinaryOperation.prototype;
-
-function DivOperation(lhs, rhs) {
- if (arguments.length > 0) {
- this.init(lhs, rhs);
- }
-}
-
-DivOperation.prototype.init = function(lhs, rhs) {
- DivOperation.superclass.init.call(this, lhs, rhs);
-};
-
-DivOperation.prototype.evaluate = function(c) {
- return this.lhs.evaluate(c).number().div(this.rhs.evaluate(c).number());
-};
-
-DivOperation.prototype.toString = function() {
- return "(" + this.lhs.toString() + " div " + this.rhs.toString() + ")";
-};
-
-// ModOperation //////////////////////////////////////////////////////////////
-
-ModOperation.prototype = new BinaryOperation();
-ModOperation.prototype.constructor = ModOperation;
-ModOperation.superclass = BinaryOperation.prototype;
-
-function ModOperation(lhs, rhs) {
- if (arguments.length > 0) {
- this.init(lhs, rhs);
- }
-}
-
-ModOperation.prototype.init = function(lhs, rhs) {
- ModOperation.superclass.init.call(this, lhs, rhs);
-};
-
-ModOperation.prototype.evaluate = function(c) {
- return this.lhs.evaluate(c).number().mod(this.rhs.evaluate(c).number());
-};
-
-ModOperation.prototype.toString = function() {
- return "(" + this.lhs.toString() + " mod " + this.rhs.toString() + ")";
-};
-
-// BarOperation //////////////////////////////////////////////////////////////
-
-BarOperation.prototype = new BinaryOperation();
-BarOperation.prototype.constructor = BarOperation;
-BarOperation.superclass = BinaryOperation.prototype;
-
-function BarOperation(lhs, rhs) {
- if (arguments.length > 0) {
- this.init(lhs, rhs);
- }
-}
-
-BarOperation.prototype.init = function(lhs, rhs) {
- BarOperation.superclass.init.call(this, lhs, rhs);
-};
-
-BarOperation.prototype.evaluate = function(c) {
- return this.lhs.evaluate(c).nodeset().union(this.rhs.evaluate(c).nodeset());
-};
-
-BarOperation.prototype.toString = function() {
- return this.lhs.toString() + " | " + this.rhs.toString();
-};
-
-// PathExpr //////////////////////////////////////////////////////////////////
-
-PathExpr.prototype = new Expression();
-PathExpr.prototype.constructor = PathExpr;
-PathExpr.superclass = Expression.prototype;
-
-function PathExpr(filter, filterPreds, locpath) {
- if (arguments.length > 0) {
- this.init(filter, filterPreds, locpath);
- }
-}
-
-PathExpr.prototype.init = function(filter, filterPreds, locpath) {
- PathExpr.superclass.init.call(this);
- this.filter = filter;
- this.filterPredicates = filterPreds;
- this.locationPath = locpath;
-};
-
-PathExpr.prototype.evaluate = function(c) {
- var nodes;
- var xpc = new XPathContext();
- xpc.variableResolver = c.variableResolver;
- xpc.functionResolver = c.functionResolver;
- xpc.namespaceResolver = c.namespaceResolver;
- xpc.expressionContextNode = c.expressionContextNode;
- xpc.virtualRoot = c.virtualRoot;
- xpc.caseInsensitive = c.caseInsensitive;
- if (this.filter == null) {
- nodes = [ c.contextNode ];
- } else {
- var ns = this.filter.evaluate(c);
- if (!Utilities.instance_of(ns, XNodeSet)) {
- if (this.filterPredicates != null && this.filterPredicates.length > 0 || this.locationPath != null) {
- throw new Error("Path expression filter must evaluate to a nodset if predicates or location path are used");
- }
- return ns;
- }
- nodes = ns.toArray();
- if (this.filterPredicates != null) {
- // apply each of the predicates in turn
- for (var j = 0; j < this.filterPredicates.length; j++) {
- var pred = this.filterPredicates[j];
- var newNodes = [];
- xpc.contextSize = nodes.length;
- for (xpc.contextPosition = 1; xpc.contextPosition <= xpc.contextSize; xpc.contextPosition++) {
- xpc.contextNode = nodes[xpc.contextPosition - 1];
- if (this.predicateMatches(pred, xpc)) {
- newNodes.push(xpc.contextNode);
- }
- }
- nodes = newNodes;
- }
- }
- }
- if (this.locationPath != null) {
- if (this.locationPath.absolute) {
- if (nodes[0].nodeType != 9 /*Node.DOCUMENT_NODE*/) {
- if (xpc.virtualRoot != null) {
- nodes = [ xpc.virtualRoot ];
- } else {
- if (nodes[0].ownerDocument == null) {
- // IE 5.5 doesn't have ownerDocument?
- var n = nodes[0];
- while (n.parentNode != null) {
- n = n.parentNode;
- }
- nodes = [ n ];
- } else {
- nodes = [ nodes[0].ownerDocument ];
- }
- }
- } else {
- nodes = [ nodes[0] ];
- }
- }
- for (var i = 0; i < this.locationPath.steps.length; i++) {
- var step = this.locationPath.steps[i];
- var newNodes = [];
- for (var j = 0; j < nodes.length; j++) {
- xpc.contextNode = nodes[j];
- switch (step.axis) {
- case Step.ANCESTOR:
- // look at all the ancestor nodes
- if (xpc.contextNode === xpc.virtualRoot) {
- break;
- }
- var m;
- if (xpc.contextNode.nodeType == 2 /*Node.ATTRIBUTE_NODE*/) {
- m = this.getOwnerElement(xpc.contextNode);
- } else {
- m = xpc.contextNode.parentNode;
- }
- while (m != null) {
- if (step.nodeTest.matches(m, xpc)) {
- newNodes.push(m);
- }
- if (m === xpc.virtualRoot) {
- break;
- }
- m = m.parentNode;
- }
- break;
-
- case Step.ANCESTORORSELF:
- // look at all the ancestor nodes and the current node
- for (var m = xpc.contextNode; m != null; m = m.nodeType == 2 /*Node.ATTRIBUTE_NODE*/ ? this.getOwnerElement(m) : m.parentNode) {
- if (step.nodeTest.matches(m, xpc)) {
- newNodes.push(m);
- }
- if (m === xpc.virtualRoot) {
- break;
- }
- }
- break;
-
- case Step.ATTRIBUTE:
- // look at the attributes
- var nnm = xpc.contextNode.attributes;
- if (nnm != null) {
- for (var k = 0; k < nnm.length; k++) {
- var m = nnm.item(k);
- if (step.nodeTest.matches(m, xpc)) {
- newNodes.push(m);
- }
- }
- }
- break;
-
- case Step.CHILD:
- // look at all child elements
- for (var m = xpc.contextNode.firstChild; m != null; m = m.nextSibling) {
- if (step.nodeTest.matches(m, xpc)) {
- newNodes.push(m);
- }
- }
- break;
-
- case Step.DESCENDANT:
- // look at all descendant nodes
- var st = [ xpc.contextNode.firstChild ];
- while (st.length > 0) {
- for (var m = st.pop(); m != null; ) {
- if (step.nodeTest.matches(m, xpc)) {
- newNodes.push(m);
- }
- if (m.firstChild != null) {
- st.push(m.nextSibling);
- m = m.firstChild;
- } else {
- m = m.nextSibling;
- }
- }
- }
- break;
-
- case Step.DESCENDANTORSELF:
- // look at self
- if (step.nodeTest.matches(xpc.contextNode, xpc)) {
- newNodes.push(xpc.contextNode);
- }
- // look at all descendant nodes
- var st = [ xpc.contextNode.firstChild ];
- while (st.length > 0) {
- for (var m = st.pop(); m != null; ) {
- if (step.nodeTest.matches(m, xpc)) {
- newNodes.push(m);
- }
- if (m.firstChild != null) {
- st.push(m.nextSibling);
- m = m.firstChild;
- } else {
- m = m.nextSibling;
- }
- }
- }
- break;
-
- case Step.FOLLOWING:
- if (xpc.contextNode === xpc.virtualRoot) {
- break;
- }
- var st = [];
- if (xpc.contextNode.firstChild != null) {
- st.unshift(xpc.contextNode.firstChild);
- } else {
- st.unshift(xpc.contextNode.nextSibling);
- }
- for (var m = xpc.contextNode.parentNode; m != null && m.nodeType != 9 /*Node.DOCUMENT_NODE*/ && m !== xpc.virtualRoot; m = m.parentNode) {
- st.unshift(m.nextSibling);
- }
- do {
- for (var m = st.pop(); m != null; ) {
- if (step.nodeTest.matches(m, xpc)) {
- newNodes.push(m);
- }
- if (m.firstChild != null) {
- st.push(m.nextSibling);
- m = m.firstChild;
- } else {
- m = m.nextSibling;
- }
- }
- } while (st.length > 0);
- break;
-
- case Step.FOLLOWINGSIBLING:
- if (xpc.contextNode === xpc.virtualRoot) {
- break;
- }
- for (var m = xpc.contextNode.nextSibling; m != null; m = m.nextSibling) {
- if (step.nodeTest.matches(m, xpc)) {
- newNodes.push(m);
- }
- }
- break;
-
- case Step.NAMESPACE:
- var n = {};
- if (xpc.contextNode.nodeType == 1 /*Node.ELEMENT_NODE*/) {
- n["xml"] = XPath.XML_NAMESPACE_URI;
- n["xmlns"] = XPath.XMLNS_NAMESPACE_URI;
- for (var m = xpc.contextNode; m != null && m.nodeType == 1 /*Node.ELEMENT_NODE*/; m = m.parentNode) {
- for (var k = 0; k < m.attributes.length; k++) {
- var attr = m.attributes.item(k);
- var nm = String(attr.name);
- if (nm == "xmlns") {
- if (n[""] == undefined) {
- n[""] = attr.value;
- }
- } else if (nm.length > 6 && nm.substring(0, 6) == "xmlns:") {
- var pre = nm.substring(6, nm.length);
- if (n[pre] == undefined) {
- n[pre] = attr.value;
- }
- }
- }
- }
- for (var pre in n) {
- var nsn = new NamespaceNode(pre, n[pre], xpc.contextNode);
- if (step.nodeTest.matches(nsn, xpc)) {
- newNodes.push(nsn);
- }
- }
- }
- break;
-
- case Step.PARENT:
- m = null;
- if (xpc.contextNode !== xpc.virtualRoot) {
- if (xpc.contextNode.nodeType == 2 /*Node.ATTRIBUTE_NODE*/) {
- m = this.getOwnerElement(xpc.contextNode);
- } else {
- m = xpc.contextNode.parentNode;
- }
- }
- if (m != null && step.nodeTest.matches(m, xpc)) {
- newNodes.push(m);
- }
- break;
-
- case Step.PRECEDING:
- var st;
- if (xpc.virtualRoot != null) {
- st = [ xpc.virtualRoot ];
- } else {
- st = xpc.contextNode.nodeType == 9 /*Node.DOCUMENT_NODE*/
- ? [ xpc.contextNode ]
- : [ xpc.contextNode.ownerDocument ];
- }
- outer: while (st.length > 0) {
- for (var m = st.pop(); m != null; ) {
- if (m == xpc.contextNode) {
- break outer;
- }
- if (step.nodeTest.matches(m, xpc)) {
- newNodes.unshift(m);
- }
- if (m.firstChild != null) {
- st.push(m.nextSibling);
- m = m.firstChild;
- } else {
- m = m.nextSibling;
- }
- }
- }
- break;
-
- case Step.PRECEDINGSIBLING:
- if (xpc.contextNode === xpc.virtualRoot) {
- break;
- }
- for (var m = xpc.contextNode.previousSibling; m != null; m = m.previousSibling) {
- if (step.nodeTest.matches(m, xpc)) {
- newNodes.push(m);
- }
- }
- break;
-
- case Step.SELF:
- if (step.nodeTest.matches(xpc.contextNode, xpc)) {
- newNodes.push(xpc.contextNode);
- }
- break;
-
- default:
- }
- }
- nodes = newNodes;
- // apply each of the predicates in turn
- for (var j = 0; j < step.predicates.length; j++) {
- var pred = step.predicates[j];
- var newNodes = [];
- xpc.contextSize = nodes.length;
- for (xpc.contextPosition = 1; xpc.contextPosition <= xpc.contextSize; xpc.contextPosition++) {
- xpc.contextNode = nodes[xpc.contextPosition - 1];
- if (this.predicateMatches(pred, xpc)) {
- newNodes.push(xpc.contextNode);
- } else {
- }
- }
- nodes = newNodes;
- }
- }
- }
- var ns = new XNodeSet();
- ns.addArray(nodes);
- return ns;
-};
-
-PathExpr.prototype.predicateMatches = function(pred, c) {
- var res = pred.evaluate(c);
- if (Utilities.instance_of(res, XNumber)) {
- return c.contextPosition == res.numberValue();
- }
- return res.booleanValue();
-};
-
-PathExpr.prototype.toString = function() {
- if (this.filter != undefined) {
- var s = this.filter.toString();
- if (Utilities.instance_of(this.filter, XString)) {
- s = "'" + s + "'";
- }
- if (this.filterPredicates != undefined) {
- for (var i = 0; i < this.filterPredicates.length; i++) {
- s = s + "[" + this.filterPredicates[i].toString() + "]";
- }
- }
- if (this.locationPath != undefined) {
- if (!this.locationPath.absolute) {
- s += "/";
- }
- s += this.locationPath.toString();
- }
- return s;
- }
- return this.locationPath.toString();
-};
-
-PathExpr.prototype.getOwnerElement = function(n) {
- // DOM 2 has ownerElement
- if (n.ownerElement) {
- return n.ownerElement;
- }
- // DOM 1 Internet Explorer can use selectSingleNode (ironically)
- try {
- if (n.selectSingleNode) {
- return n.selectSingleNode("..");
- }
- } catch (e) {
- }
- // Other DOM 1 implementations must use this egregious search
- var doc = n.nodeType == 9 /*Node.DOCUMENT_NODE*/
- ? n
- : n.ownerDocument;
- var elts = doc.getElementsByTagName("*");
- for (var i = 0; i < elts.length; i++) {
- var elt = elts.item(i);
- var nnm = elt.attributes;
- for (var j = 0; j < nnm.length; j++) {
- var an = nnm.item(j);
- if (an === n) {
- return elt;
- }
- }
- }
- return null;
-};
-
-// LocationPath //////////////////////////////////////////////////////////////
-
-LocationPath.prototype = new Object();
-LocationPath.prototype.constructor = LocationPath;
-LocationPath.superclass = Object.prototype;
-
-function LocationPath(abs, steps) {
- if (arguments.length > 0) {
- this.init(abs, steps);
- }
-}
-
-LocationPath.prototype.init = function(abs, steps) {
- this.absolute = abs;
- this.steps = steps;
-};
-
-LocationPath.prototype.toString = function() {
- var s;
- if (this.absolute) {
- s = "/";
- } else {
- s = "";
- }
- for (var i = 0; i < this.steps.length; i++) {
- if (i != 0) {
- s += "/";
- }
- s += this.steps[i].toString();
- }
- return s;
-};
-
-// Step //////////////////////////////////////////////////////////////////////
-
-Step.prototype = new Object();
-Step.prototype.constructor = Step;
-Step.superclass = Object.prototype;
-
-function Step(axis, nodetest, preds) {
- if (arguments.length > 0) {
- this.init(axis, nodetest, preds);
- }
-}
-
-Step.prototype.init = function(axis, nodetest, preds) {
- this.axis = axis;
- this.nodeTest = nodetest;
- this.predicates = preds;
-};
-
-Step.prototype.toString = function() {
- var s;
- switch (this.axis) {
- case Step.ANCESTOR:
- s = "ancestor";
- break;
- case Step.ANCESTORORSELF:
- s = "ancestor-or-self";
- break;
- case Step.ATTRIBUTE:
- s = "attribute";
- break;
- case Step.CHILD:
- s = "child";
- break;
- case Step.DESCENDANT:
- s = "descendant";
- break;
- case Step.DESCENDANTORSELF:
- s = "descendant-or-self";
- break;
- case Step.FOLLOWING:
- s = "following";
- break;
- case Step.FOLLOWINGSIBLING:
- s = "following-sibling";
- break;
- case Step.NAMESPACE:
- s = "namespace";
- break;
- case Step.PARENT:
- s = "parent";
- break;
- case Step.PRECEDING:
- s = "preceding";
- break;
- case Step.PRECEDINGSIBLING:
- s = "preceding-sibling";
- break;
- case Step.SELF:
- s = "self";
- break;
- }
- s += "::";
- s += this.nodeTest.toString();
- for (var i = 0; i < this.predicates.length; i++) {
- s += "[" + this.predicates[i].toString() + "]";
- }
- return s;
-};
-
-Step.ANCESTOR = 0;
-Step.ANCESTORORSELF = 1;
-Step.ATTRIBUTE = 2;
-Step.CHILD = 3;
-Step.DESCENDANT = 4;
-Step.DESCENDANTORSELF = 5;
-Step.FOLLOWING = 6;
-Step.FOLLOWINGSIBLING = 7;
-Step.NAMESPACE = 8;
-Step.PARENT = 9;
-Step.PRECEDING = 10;
-Step.PRECEDINGSIBLING = 11;
-Step.SELF = 12;
-
-// NodeTest //////////////////////////////////////////////////////////////////
-
-NodeTest.prototype = new Object();
-NodeTest.prototype.constructor = NodeTest;
-NodeTest.superclass = Object.prototype;
-
-function NodeTest(type, value) {
- if (arguments.length > 0) {
- this.init(type, value);
- }
-}
-
-NodeTest.prototype.init = function(type, value) {
- this.type = type;
- this.value = value;
-};
-
-NodeTest.prototype.toString = function() {
- switch (this.type) {
- case NodeTest.NAMETESTANY:
- return "*";
- case NodeTest.NAMETESTPREFIXANY:
- return this.value + ":*";
- case NodeTest.NAMETESTRESOLVEDANY:
- return "{" + this.value + "}*";
- case NodeTest.NAMETESTQNAME:
- return this.value;
- case NodeTest.NAMETESTRESOLVEDNAME:
- return "{" + this.namespaceURI + "}" + this.value;
- case NodeTest.COMMENT:
- return "comment()";
- case NodeTest.TEXT:
- return "text()";
- case NodeTest.PI:
- if (this.value != undefined) {
- return "processing-instruction(\"" + this.value + "\")";
- }
- return "processing-instruction()";
- case NodeTest.NODE:
- return "node()";
- }
- return "<unknown nodetest type>";
-};
-
-NodeTest.prototype.matches = function(n, xpc) {
- switch (this.type) {
- case NodeTest.NAMETESTANY:
- if (n.nodeType == 2 /*Node.ATTRIBUTE_NODE*/
- || n.nodeType == 1 /*Node.ELEMENT_NODE*/
- || n.nodeType == XPathNamespace.XPATH_NAMESPACE_NODE) {
- return true;
- }
- return false;
- case NodeTest.NAMETESTPREFIXANY:
- if ((n.nodeType == 2 /*Node.ATTRIBUTE_NODE*/ || n.nodeType == 1 /*Node.ELEMENT_NODE*/)) {
- var ns = xpc.namespaceResolver.getNamespace(this.value, xpc.expressionContextNode)
- if (ns == null) {
- throw new Error("Cannot resolve QName " + this.value);
- }
- return true;
- }
- return false;
- case NodeTest.NAMETESTQNAME:
- if (n.nodeType == 2 /*Node.ATTRIBUTE_NODE*/
- || n.nodeType == 1 /*Node.ELEMENT_NODE*/
- || n.nodeType == XPathNamespace.XPATH_NAMESPACE_NODE) {
- var test = Utilities.resolveQName(this.value, xpc.namespaceResolver, xpc.expressionContextNode, false);
- if (test[0] == null) {
- throw new Error("Cannot resolve QName " + this.value);
- }
- test[0] = String(test[0]);
- test[1] = String(test[1]);
- if (test[0] == "") {
- test[0] = null;
- }
- var node = Utilities.resolveQName(n.nodeName, xpc.namespaceResolver, n, true);
- node[0] = String(node[0]);
- node[1] = String(node[1]);
- if (node[0] == "") {
- node[0] = null;
- }
- if (xpc.caseInsensitive) {
- return test[0] == node[0] && String(test[1]).toLowerCase() == String(node[1]).toLowerCase();
- }
- return test[0] == node[0] && test[1] == node[1];
- }
- return false;
- case NodeTest.COMMENT:
- return n.nodeType == 8 /*Node.COMMENT_NODE*/;
- case NodeTest.TEXT:
- return n.nodeType == 3 /*Node.TEXT_NODE*/ || n.nodeType == 4 /*Node.CDATA_SECTION_NODE*/;
- case NodeTest.PI:
- return n.nodeType == 7 /*Node.PROCESSING_INSTRUCTION_NODE*/
- && (this.value == null || n.nodeName == this.value);
- case NodeTest.NODE:
- return n.nodeType == 9 /*Node.DOCUMENT_NODE*/
- || n.nodeType == 1 /*Node.ELEMENT_NODE*/
- || n.nodeType == 2 /*Node.ATTRIBUTE_NODE*/
- || n.nodeType == 3 /*Node.TEXT_NODE*/
- || n.nodeType == 4 /*Node.CDATA_SECTION_NODE*/
- || n.nodeType == 8 /*Node.COMMENT_NODE*/
- || n.nodeType == 7 /*Node.PROCESSING_INSTRUCTION_NODE*/;
- }
- return false;
-};
-
-NodeTest.NAMETESTANY = 0;
-NodeTest.NAMETESTPREFIXANY = 1;
-NodeTest.NAMETESTQNAME = 2;
-NodeTest.COMMENT = 3;
-NodeTest.TEXT = 4;
-NodeTest.PI = 5;
-NodeTest.NODE = 6;
-
-// VariableReference /////////////////////////////////////////////////////////
-
-VariableReference.prototype = new Expression();
-VariableReference.prototype.constructor = VariableReference;
-VariableReference.superclass = Expression.prototype;
-
-function VariableReference(v) {
- if (arguments.length > 0) {
- this.init(v);
- }
-}
-
-VariableReference.prototype.init = function(v) {
- this.variable = v;
-};
-
-VariableReference.prototype.toString = function() {
- return "$" + this.variable;
-};
-
-VariableReference.prototype.evaluate = function(c) {
- return c.variableResolver.getVariable(this.variable, c);
-};
-
-// FunctionCall //////////////////////////////////////////////////////////////
-
-FunctionCall.prototype = new Expression();
-FunctionCall.prototype.constructor = FunctionCall;
-FunctionCall.superclass = Expression.prototype;
-
-function FunctionCall(fn, args) {
- if (arguments.length > 0) {
- this.init(fn, args);
- }
-}
-
-FunctionCall.prototype.init = function(fn, args) {
- this.functionName = fn;
- this.arguments = args;
-};
-
-FunctionCall.prototype.toString = function() {
- var s = this.functionName + "(";
- for (var i = 0; i < this.arguments.length; i++) {
- if (i > 0) {
- s += ", ";
- }
- s += this.arguments[i].toString();
- }
- return s + ")";
-};
-
-FunctionCall.prototype.evaluate = function(c) {
- var f = c.functionResolver.getFunction(this.functionName, c);
- if (f == undefined) {
- throw new Error("Unknown function " + this.functionName);
- }
- var a = [c].concat(this.arguments);
- return f.apply(c.functionResolver.thisArg, a);
-};
-
-// XString ///////////////////////////////////////////////////////////////////
-
-XString.prototype = new Expression();
-XString.prototype.constructor = XString;
-XString.superclass = Expression.prototype;
-
-function XString(s) {
- if (arguments.length > 0) {
- this.init(s);
- }
-}
-
-XString.prototype.init = function(s) {
- this.str = s;
-};
-
-XString.prototype.toString = function() {
- return this.str;
-};
-
-XString.prototype.evaluate = function(c) {
- return this;
-};
-
-XString.prototype.string = function() {
- return this;
-};
-
-XString.prototype.number = function() {
- return new XNumber(this.str);
-};
-
-XString.prototype.bool = function() {
- return new XBoolean(this.str);
-};
-
-XString.prototype.nodeset = function() {
- throw new Error("Cannot convert string to nodeset");
-};
-
-XString.prototype.stringValue = function() {
- return this.str;
-};
-
-XString.prototype.numberValue = function() {
- return this.number().numberValue();
-};
-
-XString.prototype.booleanValue = function() {
- return this.bool().booleanValue();
-};
-
-XString.prototype.equals = function(r) {
- if (Utilities.instance_of(r, XBoolean)) {
- return this.bool().equals(r);
- }
- if (Utilities.instance_of(r, XNumber)) {
- return this.number().equals(r);
- }
- if (Utilities.instance_of(r, XNodeSet)) {
- return r.compareWithString(this, Operators.equals);
- }
- return new XBoolean(this.str == r.str);
-};
-
-XString.prototype.notequal = function(r) {
- if (Utilities.instance_of(r, XBoolean)) {
- return this.bool().notequal(r);
- }
- if (Utilities.instance_of(r, XNumber)) {
- return this.number().notequal(r);
- }
- if (Utilities.instance_of(r, XNodeSet)) {
- return r.compareWithString(this, Operators.notequal);
- }
- return new XBoolean(this.str != r.str);
-};
-
-XString.prototype.lessthan = function(r) {
- if (Utilities.instance_of(r, XNodeSet)) {
- return r.compareWithNumber(this.number(), Operators.greaterthanorequal);
- }
- return this.number().lessthan(r.number());
-};
-
-XString.prototype.greaterthan = function(r) {
- if (Utilities.instance_of(r, XNodeSet)) {
- return r.compareWithNumber(this.number(), Operators.lessthanorequal);
- }
- return this.number().greaterthan(r.number());
-};
-
-XString.prototype.lessthanorequal = function(r) {
- if (Utilities.instance_of(r, XNodeSet)) {
- return r.compareWithNumber(this.number(), Operators.greaterthan);
- }
- return this.number().lessthanorequal(r.number());
-};
-
-XString.prototype.greaterthanorequal = function(r) {
- if (Utilities.instance_of(r, XNodeSet)) {
- return r.compareWithNumber(this.number(), Operators.lessthan);
- }
- return this.number().greaterthanorequal(r.number());
-};
-
-// XNumber ///////////////////////////////////////////////////////////////////
-
-XNumber.prototype = new Expression();
-XNumber.prototype.constructor = XNumber;
-XNumber.superclass = Expression.prototype;
-
-function XNumber(n) {
- if (arguments.length > 0) {
- this.init(n);
- }
-}
-
-XNumber.prototype.init = function(n) {
- this.num = Number(n);
-};
-
-XNumber.prototype.toString = function() {
- return this.num;
-};
-
-XNumber.prototype.evaluate = function(c) {
- return this;
-};
-
-XNumber.prototype.string = function() {
- return new XString(this.num);
-};
-
-XNumber.prototype.number = function() {
- return this;
-};
-
-XNumber.prototype.bool = function() {
- return new XBoolean(this.num);
-};
-
-XNumber.prototype.nodeset = function() {
- throw new Error("Cannot convert number to nodeset");
-};
-
-XNumber.prototype.stringValue = function() {
- return this.string().stringValue();
-};
-
-XNumber.prototype.numberValue = function() {
- return this.num;
-};
-
-XNumber.prototype.booleanValue = function() {
- return this.bool().booleanValue();
-};
-
-XNumber.prototype.negate = function() {
- return new XNumber(-this.num);
-};
-
-XNumber.prototype.equals = function(r) {
- if (Utilities.instance_of(r, XBoolean)) {
- return this.bool().equals(r);
- }
- if (Utilities.instance_of(r, XString)) {
- return this.equals(r.number());
- }
- if (Utilities.instance_of(r, XNodeSet)) {
- return r.compareWithNumber(this, Operators.equals);
- }
- return new XBoolean(this.num == r.num);
-};
-
-XNumber.prototype.notequal = function(r) {
- if (Utilities.instance_of(r, XBoolean)) {
- return this.bool().notequal(r);
- }
- if (Utilities.instance_of(r, XString)) {
- return this.notequal(r.number());
- }
- if (Utilities.instance_of(r, XNodeSet)) {
- return r.compareWithNumber(this, Operators.notequal);
- }
- return new XBoolean(this.num != r.num);
-};
-
-XNumber.prototype.lessthan = function(r) {
- if (Utilities.instance_of(r, XNodeSet)) {
- return r.compareWithNumber(this, Operators.greaterthanorequal);
- }
- if (Utilities.instance_of(r, XBoolean) || Utilities.instance_of(r, XString)) {
- return this.lessthan(r.number());
- }
- return new XBoolean(this.num < r.num);
-};
-
-XNumber.prototype.greaterthan = function(r) {
- if (Utilities.instance_of(r, XNodeSet)) {
- return r.compareWithNumber(this, Operators.lessthanorequal);
- }
- if (Utilities.instance_of(r, XBoolean) || Utilities.instance_of(r, XString)) {
- return this.greaterthan(r.number());
- }
- return new XBoolean(this.num > r.num);
-};
-
-XNumber.prototype.lessthanorequal = function(r) {
- if (Utilities.instance_of(r, XNodeSet)) {
- return r.compareWithNumber(this, Operators.greaterthan);
- }
- if (Utilities.instance_of(r, XBoolean) || Utilities.instance_of(r, XString)) {
- return this.lessthanorequal(r.number());
- }
- return new XBoolean(this.num <= r.num);
-};
-
-XNumber.prototype.greaterthanorequal = function(r) {
- if (Utilities.instance_of(r, XNodeSet)) {
- return r.compareWithNumber(this, Operators.lessthan);
- }
- if (Utilities.instance_of(r, XBoolean) || Utilities.instance_of(r, XString)) {
- return this.greaterthanorequal(r.number());
- }
- return new XBoolean(this.num >= r.num);
-};
-
-XNumber.prototype.plus = function(r) {
- return new XNumber(this.num + r.num);
-};
-
-XNumber.prototype.minus = function(r) {
- return new XNumber(this.num - r.num);
-};
-
-XNumber.prototype.multiply = function(r) {
- return new XNumber(this.num * r.num);
-};
-
-XNumber.prototype.div = function(r) {
- return new XNumber(this.num / r.num);
-};
-
-XNumber.prototype.mod = function(r) {
- return new XNumber(this.num % r.num);
-};
-
-// XBoolean //////////////////////////////////////////////////////////////////
-
-XBoolean.prototype = new Expression();
-XBoolean.prototype.constructor = XBoolean;
-XBoolean.superclass = Expression.prototype;
-
-function XBoolean(b) {
- if (arguments.length > 0) {
- this.init(b);
- }
-}
-
-XBoolean.prototype.init = function(b) {
- this.b = Boolean(b);
-};
-
-XBoolean.prototype.toString = function() {
- return this.b.toString();
-};
-
-XBoolean.prototype.evaluate = function(c) {
- return this;
-};
-
-XBoolean.prototype.string = function() {
- return new XString(this.b);
-};
-
-XBoolean.prototype.number = function() {
- return new XNumber(this.b);
-};
-
-XBoolean.prototype.bool = function() {
- return this;
-};
-
-XBoolean.prototype.nodeset = function() {
- throw new Error("Cannot convert boolean to nodeset");
-};
-
-XBoolean.prototype.stringValue = function() {
- return this.string().stringValue();
-};
-
-XBoolean.prototype.numberValue = function() {
- return this.num().numberValue();
-};
-
-XBoolean.prototype.booleanValue = function() {
- return this.b;
-};
-
-XBoolean.prototype.not = function() {
- return new XBoolean(!this.b);
-};
-
-XBoolean.prototype.equals = function(r) {
- if (Utilities.instance_of(r, XString) || Utilities.instance_of(r, XNumber)) {
- return this.equals(r.bool());
- }
- if (Utilities.instance_of(r, XNodeSet)) {
- return r.compareWithBoolean(this, Operators.equals);
- }
- return new XBoolean(this.b == r.b);
-};
-
-XBoolean.prototype.notequal = function(r) {
- if (Utilities.instance_of(r, XString) || Utilities.instance_of(r, XNumber)) {
- return this.notequal(r.bool());
- }
- if (Utilities.instance_of(r, XNodeSet)) {
- return r.compareWithBoolean(this, Operators.notequal);
- }
- return new XBoolean(this.b != r.b);
-};
-
-XBoolean.prototype.lessthan = function(r) {
- if (Utilities.instance_of(r, XNodeSet)) {
- return r.compareWithNumber(this.number(), Operators.greaterthanorequal);
- }
- return this.number().lessthan(r.number());
-};
-
-XBoolean.prototype.greaterthan = function(r) {
- if (Utilities.instance_of(r, XNodeSet)) {
- return r.compareWithNumber(this.number(), Operators.lessthanorequal);
- }
- return this.number().greaterthan(r.number());
-};
-
-XBoolean.prototype.lessthanorequal = function(r) {
- if (Utilities.instance_of(r, XNodeSet)) {
- return r.compareWithNumber(this.number(), Operators.greaterthan);
- }
- return this.number().lessthanorequal(r.number());
-};
-
-XBoolean.prototype.greaterthanorequal = function(r) {
- if (Utilities.instance_of(r, XNodeSet)) {
- return r.compareWithNumber(this.number(), Operators.lessthan);
- }
- return this.number().greaterthanorequal(r.number());
-};
-
-// XNodeSet //////////////////////////////////////////////////////////////////
-
-XNodeSet.prototype = new Expression();
-XNodeSet.prototype.constructor = XNodeSet;
-XNodeSet.superclass = Expression.prototype;
-
-function XNodeSet() {
- this.init();
-}
-
-XNodeSet.prototype.init = function() {
- this.tree = null;
- this.size = 0;
-};
-
-XNodeSet.prototype.toString = function() {
- var p = this.first();
- if (p == null) {
- return "";
- }
- return this.stringForNode(p);
-};
-
-XNodeSet.prototype.evaluate = function(c) {
- return this;
-};
-
-XNodeSet.prototype.string = function() {
- return new XString(this.toString());
-};
-
-XNodeSet.prototype.stringValue = function() {
- return this.toString();
-};
-
-XNodeSet.prototype.number = function() {
- return new XNumber(this.string());
-};
-
-XNodeSet.prototype.numberValue = function() {
- return Number(this.string());
-};
-
-XNodeSet.prototype.bool = function() {
- return new XBoolean(this.tree != null);
-};
-
-XNodeSet.prototype.booleanValue = function() {
- return this.tree != null;
-};
-
-XNodeSet.prototype.nodeset = function() {
- return this;
-};
-
-XNodeSet.prototype.stringForNode = function(n) {
- if (n.nodeType == 9 /*Node.DOCUMENT_NODE*/) {
- n = n.documentElement;
- }
- if (n.nodeType == 1 /*Node.ELEMENT_NODE*/) {
- return this.stringForNodeRec(n);
- }
- if (n.isNamespaceNode) {
- return n.namespace;
- }
- return n.nodeValue;
-};
-
-XNodeSet.prototype.stringForNodeRec = function(n) {
- var s = "";
- for (var n2 = n.firstChild; n2 != null; n2 = n2.nextSibling) {
- if (n2.nodeType == 3 /*Node.TEXT_NODE*/) {
- s += n2.nodeValue;
- } else if (n2.nodeType == 1 /*Node.ELEMENT_NODE*/) {
- s += this.stringForNodeRec(n2);
- }
- }
- return s;
-};
-
-XNodeSet.prototype.first = function() {
- var p = this.tree;
- if (p == null) {
- return null;
- }
- while (p.left != null) {
- p = p.left;
- }
- return p.node;
-};
-
-XNodeSet.prototype.add = function(n) {
- if (this.tree == null) {
- this.tree = new Object();
- this.tree.node = n;
- this.tree.left = null;
- this.tree.right = null;
- this.size = 1;
- return;
- }
-
- var p = this.tree;
- while (1) {
- var o = this.order(n, p.node);
- if (o == 0) {
- return;
- }
- if (o > 0) {
- if (p.right == null) {
- p.right = new Object();
- p.right.node = n;
- p.right.left = null;
- p.right.right = null;
- this.size++;
- return;
- }
- p = p.right;
- } else {
- if (p.left == null) {
- p.left = new Object();
- p.left.node = n;
- p.left.left = null;
- p.left.right = null;
- this.size++;
- return;
- }
- p = p.left;
- }
- }
-};
-
-XNodeSet.prototype.addArray = function(ns) {
- for (var i = 0; i < ns.length; i++) {
- this.add(ns[i]);
- }
-};
-
-XNodeSet.prototype.toArray = function() {
- var a = [];
- this.toArrayRec(this.tree, a);
- return a;
-};
-
-XNodeSet.prototype.toArrayRec = function(t, a) {
- if (t != null) {
- this.toArrayRec(t.left, a);
- a.push(t.node);
- this.toArrayRec(t.right, a);
- }
-};
-
-XNodeSet.prototype.order = function(n1, n2) {
- if (n1 == n2) {
- return 0;
- }
- var d1 = 0;
- var d2 = 0;
- for (var m1 = n1; m1 != null; m1 = m1.parentNode) {
- d1++;
- }
- for (var m2 = n2; m2 != null; m2 = m2.parentNode) {
- d2++;
- }
- if (d1 > d2) {
- while (d1 > d2) {
- n1 = n1.parentNode;
- d1--;
- }
- if (n1 == n2) {
- return 1;
- }
- } else if (d2 > d1) {
- while (d2 > d1) {
- n2 = n2.parentNode;
- d2--;
- }
- if (n1 == n2) {
- return -1;
- }
- }
- while (n1.parentNode != n2.parentNode) {
- n1 = n1.parentNode;
- n2 = n2.parentNode;
- }
- while (n1.previousSibling != null && n2.previousSibling != null) {
- n1 = n1.previousSibling;
- n2 = n2.previousSibling;
- }
- if (n1.previousSibling == null) {
- return -1;
- }
- return 1;
-};
-
-XNodeSet.prototype.compareWithString = function(r, o) {
- var a = this.toArray();
- for (var i = 0; i < a.length; i++) {
- var n = a[i];
- var l = new XString(this.stringForNode(n));
- var res = o(l, r);
- if (res.booleanValue()) {
- return res;
- }
- }
- return new XBoolean(false);
-};
-
-XNodeSet.prototype.compareWithNumber = function(r, o) {
- var a = this.toArray();
- for (var i = 0; i < a.length; i++) {
- var n = a[i];
- var l = new XNumber(this.stringForNode(n));
- var res = o(l, r);
- if (res.booleanValue()) {
- return res;
- }
- }
- return new XBoolean(false);
-};
-
-XNodeSet.prototype.compareWithBoolean = function(r, o) {
- return o(this.bool(), r);
-};
-
-XNodeSet.prototype.compareWithNodeSet = function(r, o) {
- var a = this.toArray();
- for (var i = 0; i < a.length; i++) {
- var n = a[i];
- var l = new XString(this.stringForNode(n));
- var b = r.toArray();
- for (var j = 0; j < b.length; j++) {
- var n2 = b[j];
- var r = new XString(this.stringForNode(n2));
- var res = o(l, r);
- if (res.booleanValue()) {
- return res;
- }
- }
- }
- return new XBoolean(false);
-};
-
-XNodeSet.prototype.equals = function(r) {
- if (Utilities.instance_of(r, XString)) {
- return this.compareWithString(r, Operators.equals);
- }
- if (Utilities.instance_of(r, XNumber)) {
- return this.compareWithNumber(r, Operators.equals);
- }
- if (Utilities.instance_of(r, XBoolean)) {
- return this.compareWithBoolean(r, Operators.equals);
- }
- return this.compareWithNodeSet(r, Operators.equals);
-};
-
-XNodeSet.prototype.notequal = function(r) {
- if (Utilities.instance_of(r, XString)) {
- return this.compareWithString(r, Operators.notequal);
- }
- if (Utilities.instance_of(r, XNumber)) {
- return this.compareWithNumber(r, Operators.notequal);
- }
- if (Utilities.instance_of(r, XBoolean)) {
- return this.compareWithBoolean(r, Operators.notequal);
- }
- return this.compareWithNodeSet(r, Operators.notequal);
-};
-
-XNodeSet.prototype.lessthan = function(r) {
- if (Utilities.instance_of(r, XString)) {
- return this.compareWithNumber(r.number(), Operators.lessthan);
- }
- if (Utilities.instance_of(r, XNumber)) {
- return this.compareWithNumber(r, Operators.lessthan);
- }
- if (Utilities.instance_of(r, XBoolean)) {
- return this.compareWithBoolean(r, Operators.lessthan);
- }
- return this.compareWithNodeSet(r, Operators.lessthan);
-};
-
-XNodeSet.prototype.greaterthan = function(r) {
- if (Utilities.instance_of(r, XString)) {
- return this.compareWithNumber(r.number(), Operators.greaterthan);
- }
- if (Utilities.instance_of(r, XNumber)) {
- return this.compareWithNumber(r, Operators.greaterthan);
- }
- if (Utilities.instance_of(r, XBoolean)) {
- return this.compareWithBoolean(r, Operators.greaterthan);
- }
- return this.compareWithNodeSet(r, Operators.greaterthan);
-};
-
-XNodeSet.prototype.lessthanorequal = function(r) {
- if (Utilities.instance_of(r, XString)) {
- return this.compareWithNumber(r.number(), Operators.lessthanorequal);
- }
- if (Utilities.instance_of(r, XNumber)) {
- return this.compareWithNumber(r, Operators.lessthanorequal);
- }
- if (Utilities.instance_of(r, XBoolean)) {
- return this.compareWithBoolean(r, Operators.lessthanorequal);
- }
- return this.compareWithNodeSet(r, Operators.lessthanorequal);
-};
-
-XNodeSet.prototype.greaterthanorequal = function(r) {
- if (Utilities.instance_of(r, XString)) {
- return this.compareWithNumber(r.number(), Operators.greaterthanorequal);
- }
- if (Utilities.instance_of(r, XNumber)) {
- return this.compareWithNumber(r, Operators.greaterthanorequal);
- }
- if (Utilities.instance_of(r, XBoolean)) {
- return this.compareWithBoolean(r, Operators.greaterthanorequal);
- }
- return this.compareWithNodeSet(r, Operators.greaterthanorequal);
-};
-
-XNodeSet.prototype.union = function(r) {
- var ns = new XNodeSet();
- ns.tree = this.tree;
- ns.size = this.size;
- ns.addArray(r.toArray());
- return ns;
-};
-
-// XPathNamespace ////////////////////////////////////////////////////////////
-
-XPathNamespace.prototype = new Object();
-XPathNamespace.prototype.constructor = XPathNamespace;
-XPathNamespace.superclass = Object.prototype;
-
-function XPathNamespace(pre, ns, p) {
- this.isXPathNamespace = true;
- this.ownerDocument = p.ownerDocument;
- this.nodeName = "#namespace";
- this.prefix = pre;
- this.localName = pre;
- this.namespaceURI = ns;
- this.nodeValue = ns;
- this.ownerElement = p;
- this.nodeType = XPathNamespace.XPATH_NAMESPACE_NODE;
-}
-
-XPathNamespace.prototype.toString = function() {
- return "{ \"" + this.prefix + "\", \"" + this.namespaceURI + "\" }";
-};
-
-// Operators /////////////////////////////////////////////////////////////////
-
-var Operators = new Object();
-
-Operators.equals = function(l, r) {
- return l.equals(r);
-};
-
-Operators.notequal = function(l, r) {
- return l.notequal(r);
-};
-
-Operators.lessthan = function(l, r) {
- return l.lessthan(r);
-};
-
-Operators.greaterthan = function(l, r) {
- return l.greaterthan(r);
-};
-
-Operators.lessthanorequal = function(l, r) {
- return l.lessthanorequal(r);
-};
-
-Operators.greaterthanorequal = function(l, r) {
- return l.greaterthanorequal(r);
-};
-
-// XPathContext //////////////////////////////////////////////////////////////
-
-XPathContext.prototype = new Object();
-XPathContext.prototype.constructor = XPathContext;
-XPathContext.superclass = Object.prototype;
-
-function XPathContext(vr, nr, fr) {
- this.variableResolver = vr != null ? vr : new VariableResolver();
- this.namespaceResolver = nr != null ? nr : new NamespaceResolver();
- this.functionResolver = fr != null ? fr : new FunctionResolver();
-}
-
-// VariableResolver //////////////////////////////////////////////////////////
-
-VariableResolver.prototype = new Object();
-VariableResolver.prototype.constructor = VariableResolver;
-VariableResolver.superclass = Object.prototype;
-
-function VariableResolver() {
-}
-
-VariableResolver.prototype.getVariable = function(vn, c) {
- var parts = Utilities.splitQName(vn);
- if (parts[0] != null) {
- parts[0] = c.namespaceResolver.getNamespace(parts[0], c.expressionContextNode);
- if (parts[0] == null) {
- throw new Error("Cannot resolve QName " + fn);
- }
- }
- return this.getVariableWithName(parts[0], parts[1], c.expressionContextNode);
-};
-
-VariableResolver.prototype.getVariableWithName = function(ns, ln, c) {
- return null;
-};
-
-// FunctionResolver //////////////////////////////////////////////////////////
-
-FunctionResolver.prototype = new Object();
-FunctionResolver.prototype.constructor = FunctionResolver;
-FunctionResolver.superclass = Object.prototype;
-
-function FunctionResolver(thisArg) {
- this.thisArg = thisArg != null ? thisArg : Functions;
- this.functions = new Object();
- this.addStandardFunctions();
-}
-
-FunctionResolver.prototype.addStandardFunctions = function() {
- this.functions["{}last"] = Functions.last;
- this.functions["{}position"] = Functions.position;
- this.functions["{}count"] = Functions.count;
- this.functions["{}id"] = Functions.id;
- this.functions["{}local-name"] = Functions.localName;
- this.functions["{}namespace-uri"] = Functions.namespaceURI;
- this.functions["{}name"] = Functions.name;
- this.functions["{}string"] = Functions.string;
- this.functions["{}concat"] = Functions.concat;
- this.functions["{}starts-with"] = Functions.startsWith;
- this.functions["{}contains"] = Functions.contains;
- this.functions["{}substring-before"] = Functions.substringBefore;
- this.functions["{}substring-after"] = Functions.substringAfter;
- this.functions["{}substring"] = Functions.substring;
- this.functions["{}string-length"] = Functions.stringLength;
- this.functions["{}normalize-space"] = Functions.normalizeSpace;
- this.functions["{}translate"] = Functions.translate;
- this.functions["{}boolean"] = Functions.boolean_;
- this.functions["{}not"] = Functions.not;
- this.functions["{}true"] = Functions.true_;
- this.functions["{}false"] = Functions.false_;
- this.functions["{}lang"] = Functions.lang;
- this.functions["{}number"] = Functions.number;
- this.functions["{}sum"] = Functions.sum;
- this.functions["{}floor"] = Functions.floor;
- this.functions["{}ceiling"] = Functions.ceiling;
- this.functions["{}round"] = Functions.round;
-};
-
-FunctionResolver.prototype.addFunction = function(ns, ln, f) {
- this.functions["{" + ns + "}" + ln] = f;
-};
-
-FunctionResolver.prototype.getFunction = function(fn, c) {
- var parts = Utilities.resolveQName(fn, c.namespaceResolver, c.contextNode, false);
- if (parts[0] == null) {
- throw new Error("Cannot resolve QName " + fn);
- }
- return this.getFunctionWithName(parts[0], parts[1], c.contextNode);
-};
-
-FunctionResolver.prototype.getFunctionWithName = function(ns, ln, c) {
- return this.functions["{" + ns + "}" + ln];
-};
-
-// NamespaceResolver /////////////////////////////////////////////////////////
-
-NamespaceResolver.prototype = new Object();
-NamespaceResolver.prototype.constructor = NamespaceResolver;
-NamespaceResolver.superclass = Object.prototype;
-
-function NamespaceResolver() {
-}
-
-NamespaceResolver.prototype.getNamespace = function(prefix, n) {
- if (prefix == "xml") {
- return XPath.XML_NAMESPACE_URI;
- } else if (prefix == "xmlns") {
- return XPath.XMLNS_NAMESPACE_URI;
- }
- if (n.nodeType == 9 /*Node.DOCUMENT_NODE*/) {
- n = n.documentElement;
- } else if (n.nodeType == 2 /*Node.ATTRIBUTE_NODE*/) {
- n = PathExpr.prototype.getOwnerElement(n);
- } else if (n.nodeType != 1 /*Node.ELEMENT_NODE*/) {
- n = n.parentNode;
- }
- while (n != null && n.nodeType == 1 /*Node.ELEMENT_NODE*/) {
- var nnm = n.attributes;
- for (var i = 0; i < nnm.length; i++) {
- var a = nnm.item(i);
- var aname = a.nodeName;
- if (aname == "xmlns" && prefix == ""
- || aname == "xmlns:" + prefix) {
- return String(a.nodeValue);
- }
- }
- n = n.parentNode;
- }
- return null;
-};
-
-// Functions /////////////////////////////////////////////////////////////////
-
-Functions = new Object();
-
-Functions.last = function() {
- var c = arguments[0];
- if (arguments.length != 1) {
- throw new Error("Function last expects ()");
- }
- return new XNumber(c.contextSize);
-};
-
-Functions.position = function() {
- var c = arguments[0];
- if (arguments.length != 1) {
- throw new Error("Function position expects ()");
- }
- return new XNumber(c.contextPosition);
-};
-
-Functions.count = function() {
- var c = arguments[0];
- var ns;
- if (arguments.length != 2 || !Utilities.instance_of(ns = arguments[1].evaluate(c), XNodeSet)) {
- throw new Error("Function count expects (node-set)");
- }
- return new XNumber(ns.size);
-};
-
-Functions.id = function() {
- var c = arguments[0];
- var id;
- if (arguments.length != 2) {
- throw new Error("Function id expects (object)");
- }
- id = arguments[1].evaluate(c);
- if (Utilities.instance_of(id, XNodeSet)) {
- id = id.toArray().join(" ");
- } else {
- id = id.stringValue();
- }
- var ids = id.split(/[\x0d\x0a\x09\x20]+/);
- var count = 0;
- var ns = new XNodeSet();
- var doc = c.contextNode.nodeType == 9 /*Node.DOCUMENT_NODE*/
- ? c.contextNode
- : c.contextNode.ownerDocument;
- for (var i = 0; i < ids.length; i++) {
- var n;
- if (doc.getElementById) {
- n = doc.getElementById(ids[i]);
- } else {
- n = Utilities.getElementById(doc, ids[i]);
- }
- if (n != null) {
- ns.add(n);
- count++;
- }
- }
- return ns;
-};
-
-Functions.localName = function() {
- var c = arguments[0];
- var n;
- if (arguments.length == 1) {
- n = c.contextNode;
- } else if (arguments.length == 2) {
- n = arguments[1].evaluate(c).first();
- } else {
- throw new Error("Function local-name expects (node-set?)");
- }
- if (n == null) {
- return new XString("");
- }
- return new XString(n.localName ? n.localName : n.baseName);
-};
-
-Functions.namespaceURI = function() {
- var c = arguments[0];
- var n;
- if (arguments.length == 1) {
- n = c.contextNode;
- } else if (arguments.length == 2) {
- n = arguments[1].evaluate(c).first();
- } else {
- throw new Error("Function namespace-uri expects (node-set?)");
- }
- if (n == null) {
- return new XString("");
- }
- return new XString(n.namespaceURI);
-};
-
-Functions.name = function() {
- var c = arguments[0];
- var n;
- if (arguments.length == 1) {
- n = c.contextNode;
- } else if (arguments.length == 2) {
- n = arguments[1].evaluate(c).first();
- } else {
- throw new Error("Function name expects (node-set?)");
- }
- if (n == null) {
- return new XString("");
- }
- if (n.nodeType == 1 /*Node.ELEMENT_NODE*/ || n.nodeType == 2 /*Node.ATTRIBUTE_NODE*/) {
- return new XString(n.nodeName);
- } else if (n.localName == null) {
- return new XString("");
- } else {
- return new XString(n.localName);
- }
-};
-
-Functions.string = function() {
- var c = arguments[0];
- if (arguments.length == 1) {
- return XNodeSet.prototype.stringForNode(c.contextNode);
- } else if (arguments.length == 2) {
- return arguments[1].evaluate(c).string();
- }
- throw new Error("Function string expects (object?)");
-};
-
-Functions.concat = function() {
- var c = arguments[0];
- if (arguments.length < 3) {
- throw new Error("Function concat expects (string, string, string*)");
- }
- var s = "";
- for (var i = 1; i < arguments.length; i++) {
- s += arguments[i].evaluate(c).stringValue();
- }
- return new XString(s);
-};
-
-Functions.startsWith = function() {
- var c = arguments[0];
- if (arguments.length != 3) {
- throw new Error("Function startsWith expects (string, string)");
- }
- var s1 = arguments[1].evaluate(c).stringValue();
- var s2 = arguments[2].evaluate(c).stringValue();
- return new XBoolean(s1.substring(0, s2.length) == s2);
-};
-
-Functions.contains = function() {
- var c = arguments[0];
- if (arguments.length != 3) {
- throw new Error("Function contains expects (string, string)");
- }
- var s1 = arguments[1].evaluate(c).stringValue();
- var s2 = arguments[2].evaluate(c).stringValue();
- return new XBoolean(s1.indexOf(s2) != -1);
-};
-
-Functions.substringBefore = function() {
- var c = arguments[0];
- if (arguments.length != 3) {
- throw new Error("Function substring-before expects (string, string)");
- }
- var s1 = arguments[1].evaluate(c).stringValue();
- var s2 = arguments[2].evaluate(c).stringValue();
- return new XString(s1.substring(0, s1.indexOf(s2)));
-};
-
-Functions.substringAfter = function() {
- var c = arguments[0];
- if (arguments.length != 3) {
- throw new Error("Function substring-after expects (string, string)");
- }
- var s1 = arguments[1].evaluate(c).stringValue();
- var s2 = arguments[2].evaluate(c).stringValue();
- if (s2.length == 0) {
- return new XString(s1);
- }
- var i = s1.indexOf(s2);
- if (i == -1) {
- return new XString("");
- }
- return new XString(s1.substring(s1.indexOf(s2) + 1));
-};
-
-Functions.substring = function() {
- var c = arguments[0];
- if (!(arguments.length == 3 || arguments.length == 4)) {
- throw new Error("Function substring expects (string, number, number?)");
- }
- var s = arguments[1].evaluate(c).stringValue();
- var n1 = Math.round(arguments[2].evaluate(c).numberValue()) - 1;
- var n2 = arguments.length == 4 ? n1 + Math.round(arguments[3].evaluate(c).numberValue()) : undefined;
- return new XString(s.substring(n1, n2));
-};
-
-Functions.stringLength = function() {
- var c = arguments[0];
- var s;
- if (arguments.length == 1) {
- s = XNodeSet.prototype.stringForNode(c.contextNode);
- } else if (arguments.length == 2) {
- s = arguments[1].evaluate(c).stringValue();
- } else {
- throw new Error("Function string-length expects (string?)");
- }
- return new XNumber(s.length);
-};
-
-Functions.normalizeSpace = function() {
- var c = arguments[0];
- var s;
- if (arguments.length == 1) {
- s = XNodeSet.prototype.stringForNode(c.contextNode);
- } else if (arguments.length == 2) {
- s = arguments[1].evaluate(c).stringValue();
- } else {
- throw new Error("Function normalize-space expects (string?)");
- }
- var i = 0;
- var j = s.length - 1;
- while (Utilities.isSpace(s.charCodeAt(j))) {
- j--;
- }
- var t = "";
- while (i <= j && Utilities.isSpace(s.charCodeAt(i))) {
- i++;
- }
- while (i <= j) {
- if (Utilities.isSpace(s.charCodeAt(i))) {
- t += " ";
- while (i <= j && Utilities.isSpace(s.charCodeAt(i))) {
- i++;
- }
- } else {
- t += s.charAt(i);
- i++;
- }
- }
- return new XString(t);
-};
-
-Functions.translate = function() {
- var c = arguments[0];
- if (arguments.length != 4) {
- throw new Error("Function translate expects (string, string, string)");
- }
- var s1 = arguments[1].evaluate(c).stringValue();
- var s2 = arguments[2].evaluate(c).stringValue();
- var s3 = arguments[3].evaluate(c).stringValue();
- var map = [];
- for (var i = 0; i < s2.length; i++) {
- var j = s2.charCodeAt(i);
- if (map[j] == undefined) {
- var k = i > s3.length ? "" : s3.charAt(i);
- map[j] = k;
- }
- }
- var t = "";
- for (var i = 0; i < s1.length; i++) {
- var c = s1.charCodeAt(i);
- var r = map[c];
- if (r == undefined) {
- t += s1.charAt(i);
- } else {
- t += r;
- }
- }
- return new XString(t);
-};
-
-Functions.boolean_ = function() {
- var c = arguments[0];
- if (arguments.length != 2) {
- throw new Error("Function boolean expects (object)");
- }
- return arguments[1].evaluate(c).bool();
-};
-
-Functions.not = function() {
- var c = arguments[0];
- if (arguments.length != 2) {
- throw new Error("Function not expects (object)");
- }
- return arguments[1].evaluate(c).bool().not();
-};
-
-Functions.true_ = function() {
- if (arguments.length != 1) {
- throw new Error("Function true expects ()");
- }
- return new XBoolean(true);
-};
-
-Functions.false_ = function() {
- if (arguments.length != 1) {
- throw new Error("Function false expects ()");
- }
- return new XBoolean(false);
-};
-
-Functions.lang = function() {
- var c = arguments[0];
- if (arguments.length != 2) {
- throw new Error("Function lang expects (string)");
- }
- var lang;
- for (var n = c.contextNode; n != null && n.nodeType != 9 /*Node.DOCUMENT_NODE*/; n = n.parentNode) {
- var a = n.getAttributeNS(XPath.XML_NAMESPACE_URI, "lang");
- if (a != null) {
- lang = String(a);
- break;
- }
- }
- if (lang == null) {
- return new XBoolean(false);
- }
- var s = arguments[1].evaluate(c).stringValue();
- return new XBoolean(lang.substring(0, s.length) == s
- && (lang.length == s.length || lang.charAt(s.length) == '-'));
-};
-
-Functions.number = function() {
- var c = arguments[0];
- if (!(arguments.length == 1 || arguments.length == 2)) {
- throw new Error("Function number expects (object?)");
- }
- if (arguments.length == 1) {
- return new XNumber(XNodeSet.prototype.stringForNode(c.contextNode));
- }
- return arguments[1].evaluate(c).number();
-};
-
-Functions.sum = function() {
- var c = arguments[0];
- var ns;
- if (arguments.length != 2 || !Utilities.instance_of((ns = arguments[1].evaluate(c)), XNodeSet)) {
- throw new Error("Function sum expects (node-set)");
- }
- ns = ns.toArray();
- var n = 0;
- for (var i = 0; i < ns.length; i++) {
- n += new XNumber(XNodeSet.prototype.stringForNode(ns[i])).numberValue();
- }
- return new XNumber(n);
-};
-
-Functions.floor = function() {
- var c = arguments[0];
- if (arguments.length != 2) {
- throw new Error("Function floor expects (number)");
- }
- return new XNumber(Math.floor(arguments[1].evaluate(c).numberValue()));
-};
-
-Functions.ceiling = function() {
- var c = arguments[0];
- if (arguments.length != 2) {
- throw new Error("Function ceiling expects (number)");
- }
- return new XNumber(Math.ceil(arguments[1].evaluate(c).numberValue()));
-};
-
-Functions.round = function() {
- var c = arguments[0];
- if (arguments.length != 2) {
- throw new Error("Function round expects (number)");
- }
- return new XNumber(Math.round(arguments[1].evaluate(c).numberValue()));
-};
-
-// Utilities /////////////////////////////////////////////////////////////////
-
-Utilities = new Object();
-
-Utilities.splitQName = function(qn) {
- var i = qn.indexOf(":");
- if (i == -1) {
- return [ null, qn ];
- }
- return [ qn.substring(0, i), qn.substring(i + 1) ];
-};
-
-Utilities.resolveQName = function(qn, nr, n, useDefault) {
- var parts = Utilities.splitQName(qn);
- if (parts[0] != null) {
- parts[0] = nr.getNamespace(parts[0], n);
- } else {
- if (useDefault) {
- parts[0] = nr.getNamespace("", n);
- if (parts[0] == null) {
- parts[0] = "";
- }
- } else {
- parts[0] = "";
- }
- }
- return parts;
-};
-
-Utilities.isSpace = function(c) {
- return c == 0x9 || c == 0xd || c == 0xa || c == 0x20;
-};
-
-Utilities.isLetter = function(c) {
- return c >= 0x0041 && c <= 0x005A ||
- c >= 0x0061 && c <= 0x007A ||
- c >= 0x00C0 && c <= 0x00D6 ||
- c >= 0x00D8 && c <= 0x00F6 ||
- c >= 0x00F8 && c <= 0x00FF ||
- c >= 0x0100 && c <= 0x0131 ||
- c >= 0x0134 && c <= 0x013E ||
- c >= 0x0141 && c <= 0x0148 ||
- c >= 0x014A && c <= 0x017E ||
- c >= 0x0180 && c <= 0x01C3 ||
- c >= 0x01CD && c <= 0x01F0 ||
- c >= 0x01F4 && c <= 0x01F5 ||
- c >= 0x01FA && c <= 0x0217 ||
- c >= 0x0250 && c <= 0x02A8 ||
- c >= 0x02BB && c <= 0x02C1 ||
- c == 0x0386 ||
- c >= 0x0388 && c <= 0x038A ||
- c == 0x038C ||
- c >= 0x038E && c <= 0x03A1 ||
- c >= 0x03A3 && c <= 0x03CE ||
- c >= 0x03D0 && c <= 0x03D6 ||
- c == 0x03DA ||
- c == 0x03DC ||
- c == 0x03DE ||
- c == 0x03E0 ||
- c >= 0x03E2 && c <= 0x03F3 ||
- c >= 0x0401 && c <= 0x040C ||
- c >= 0x040E && c <= 0x044F ||
- c >= 0x0451 && c <= 0x045C ||
- c >= 0x045E && c <= 0x0481 ||
- c >= 0x0490 && c <= 0x04C4 ||
- c >= 0x04C7 && c <= 0x04C8 ||
- c >= 0x04CB && c <= 0x04CC ||
- c >= 0x04D0 && c <= 0x04EB ||
- c >= 0x04EE && c <= 0x04F5 ||
- c >= 0x04F8 && c <= 0x04F9 ||
- c >= 0x0531 && c <= 0x0556 ||
- c == 0x0559 ||
- c >= 0x0561 && c <= 0x0586 ||
- c >= 0x05D0 && c <= 0x05EA ||
- c >= 0x05F0 && c <= 0x05F2 ||
- c >= 0x0621 && c <= 0x063A ||
- c >= 0x0641 && c <= 0x064A ||
- c >= 0x0671 && c <= 0x06B7 ||
- c >= 0x06BA && c <= 0x06BE ||
- c >= 0x06C0 && c <= 0x06CE ||
- c >= 0x06D0 && c <= 0x06D3 ||
- c == 0x06D5 ||
- c >= 0x06E5 && c <= 0x06E6 ||
- c >= 0x0905 && c <= 0x0939 ||
- c == 0x093D ||
- c >= 0x0958 && c <= 0x0961 ||
- c >= 0x0985 && c <= 0x098C ||
- c >= 0x098F && c <= 0x0990 ||
- c >= 0x0993 && c <= 0x09A8 ||
- c >= 0x09AA && c <= 0x09B0 ||
- c == 0x09B2 ||
- c >= 0x09B6 && c <= 0x09B9 ||
- c >= 0x09DC && c <= 0x09DD ||
- c >= 0x09DF && c <= 0x09E1 ||
- c >= 0x09F0 && c <= 0x09F1 ||
- c >= 0x0A05 && c <= 0x0A0A ||
- c >= 0x0A0F && c <= 0x0A10 ||
- c >= 0x0A13 && c <= 0x0A28 ||
- c >= 0x0A2A && c <= 0x0A30 ||
- c >= 0x0A32 && c <= 0x0A33 ||
- c >= 0x0A35 && c <= 0x0A36 ||
- c >= 0x0A38 && c <= 0x0A39 ||
- c >= 0x0A59 && c <= 0x0A5C ||
- c == 0x0A5E ||
- c >= 0x0A72 && c <= 0x0A74 ||
- c >= 0x0A85 && c <= 0x0A8B ||
- c == 0x0A8D ||
- c >= 0x0A8F && c <= 0x0A91 ||
- c >= 0x0A93 && c <= 0x0AA8 ||
- c >= 0x0AAA && c <= 0x0AB0 ||
- c >= 0x0AB2 && c <= 0x0AB3 ||
- c >= 0x0AB5 && c <= 0x0AB9 ||
- c == 0x0ABD ||
- c == 0x0AE0 ||
- c >= 0x0B05 && c <= 0x0B0C ||
- c >= 0x0B0F && c <= 0x0B10 ||
- c >= 0x0B13 && c <= 0x0B28 ||
- c >= 0x0B2A && c <= 0x0B30 ||
- c >= 0x0B32 && c <= 0x0B33 ||
- c >= 0x0B36 && c <= 0x0B39 ||
- c == 0x0B3D ||
- c >= 0x0B5C && c <= 0x0B5D ||
- c >= 0x0B5F && c <= 0x0B61 ||
- c >= 0x0B85 && c <= 0x0B8A ||
- c >= 0x0B8E && c <= 0x0B90 ||
- c >= 0x0B92 && c <= 0x0B95 ||
- c >= 0x0B99 && c <= 0x0B9A ||
- c == 0x0B9C ||
- c >= 0x0B9E && c <= 0x0B9F ||
- c >= 0x0BA3 && c <= 0x0BA4 ||
- c >= 0x0BA8 && c <= 0x0BAA ||
- c >= 0x0BAE && c <= 0x0BB5 ||
- c >= 0x0BB7 && c <= 0x0BB9 ||
- c >= 0x0C05 && c <= 0x0C0C ||
- c >= 0x0C0E && c <= 0x0C10 ||
- c >= 0x0C12 && c <= 0x0C28 ||
- c >= 0x0C2A && c <= 0x0C33 ||
- c >= 0x0C35 && c <= 0x0C39 ||
- c >= 0x0C60 && c <= 0x0C61 ||
- c >= 0x0C85 && c <= 0x0C8C ||
- c >= 0x0C8E && c <= 0x0C90 ||
- c >= 0x0C92 && c <= 0x0CA8 ||
- c >= 0x0CAA && c <= 0x0CB3 ||
- c >= 0x0CB5 && c <= 0x0CB9 ||
- c == 0x0CDE ||
- c >= 0x0CE0 && c <= 0x0CE1 ||
- c >= 0x0D05 && c <= 0x0D0C ||
- c >= 0x0D0E && c <= 0x0D10 ||
- c >= 0x0D12 && c <= 0x0D28 ||
- c >= 0x0D2A && c <= 0x0D39 ||
- c >= 0x0D60 && c <= 0x0D61 ||
- c >= 0x0E01 && c <= 0x0E2E ||
- c == 0x0E30 ||
- c >= 0x0E32 && c <= 0x0E33 ||
- c >= 0x0E40 && c <= 0x0E45 ||
- c >= 0x0E81 && c <= 0x0E82 ||
- c == 0x0E84 ||
- c >= 0x0E87 && c <= 0x0E88 ||
- c == 0x0E8A ||
- c == 0x0E8D ||
- c >= 0x0E94 && c <= 0x0E97 ||
- c >= 0x0E99 && c <= 0x0E9F ||
- c >= 0x0EA1 && c <= 0x0EA3 ||
- c == 0x0EA5 ||
- c == 0x0EA7 ||
- c >= 0x0EAA && c <= 0x0EAB ||
- c >= 0x0EAD && c <= 0x0EAE ||
- c == 0x0EB0 ||
- c >= 0x0EB2 && c <= 0x0EB3 ||
- c == 0x0EBD ||
- c >= 0x0EC0 && c <= 0x0EC4 ||
- c >= 0x0F40 && c <= 0x0F47 ||
- c >= 0x0F49 && c <= 0x0F69 ||
- c >= 0x10A0 && c <= 0x10C5 ||
- c >= 0x10D0 && c <= 0x10F6 ||
- c == 0x1100 ||
- c >= 0x1102 && c <= 0x1103 ||
- c >= 0x1105 && c <= 0x1107 ||
- c == 0x1109 ||
- c >= 0x110B && c <= 0x110C ||
- c >= 0x110E && c <= 0x1112 ||
- c == 0x113C ||
- c == 0x113E ||
- c == 0x1140 ||
- c == 0x114C ||
- c == 0x114E ||
- c == 0x1150 ||
- c >= 0x1154 && c <= 0x1155 ||
- c == 0x1159 ||
- c >= 0x115F && c <= 0x1161 ||
- c == 0x1163 ||
- c == 0x1165 ||
- c == 0x1167 ||
- c == 0x1169 ||
- c >= 0x116D && c <= 0x116E ||
- c >= 0x1172 && c <= 0x1173 ||
- c == 0x1175 ||
- c == 0x119E ||
- c == 0x11A8 ||
- c == 0x11AB ||
- c >= 0x11AE && c <= 0x11AF ||
- c >= 0x11B7 && c <= 0x11B8 ||
- c == 0x11BA ||
- c >= 0x11BC && c <= 0x11C2 ||
- c == 0x11EB ||
- c == 0x11F0 ||
- c == 0x11F9 ||
- c >= 0x1E00 && c <= 0x1E9B ||
- c >= 0x1EA0 && c <= 0x1EF9 ||
- c >= 0x1F00 && c <= 0x1F15 ||
- c >= 0x1F18 && c <= 0x1F1D ||
- c >= 0x1F20 && c <= 0x1F45 ||
- c >= 0x1F48 && c <= 0x1F4D ||
- c >= 0x1F50 && c <= 0x1F57 ||
- c == 0x1F59 ||
- c == 0x1F5B ||
- c == 0x1F5D ||
- c >= 0x1F5F && c <= 0x1F7D ||
- c >= 0x1F80 && c <= 0x1FB4 ||
- c >= 0x1FB6 && c <= 0x1FBC ||
- c == 0x1FBE ||
- c >= 0x1FC2 && c <= 0x1FC4 ||
- c >= 0x1FC6 && c <= 0x1FCC ||
- c >= 0x1FD0 && c <= 0x1FD3 ||
- c >= 0x1FD6 && c <= 0x1FDB ||
- c >= 0x1FE0 && c <= 0x1FEC ||
- c >= 0x1FF2 && c <= 0x1FF4 ||
- c >= 0x1FF6 && c <= 0x1FFC ||
- c == 0x2126 ||
- c >= 0x212A && c <= 0x212B ||
- c == 0x212E ||
- c >= 0x2180 && c <= 0x2182 ||
- c >= 0x3041 && c <= 0x3094 ||
- c >= 0x30A1 && c <= 0x30FA ||
- c >= 0x3105 && c <= 0x312C ||
- c >= 0xAC00 && c <= 0xD7A3 ||
- c >= 0x4E00 && c <= 0x9FA5 ||
- c == 0x3007 ||
- c >= 0x3021 && c <= 0x3029;
-};
-
-Utilities.isNCNameChar = function(c) {
- return c >= 0x0030 && c <= 0x0039
- || c >= 0x0660 && c <= 0x0669
- || c >= 0x06F0 && c <= 0x06F9
- || c >= 0x0966 && c <= 0x096F
- || c >= 0x09E6 && c <= 0x09EF
- || c >= 0x0A66 && c <= 0x0A6F
- || c >= 0x0AE6 && c <= 0x0AEF
- || c >= 0x0B66 && c <= 0x0B6F
- || c >= 0x0BE7 && c <= 0x0BEF
- || c >= 0x0C66 && c <= 0x0C6F
- || c >= 0x0CE6 && c <= 0x0CEF
- || c >= 0x0D66 && c <= 0x0D6F
- || c >= 0x0E50 && c <= 0x0E59
- || c >= 0x0ED0 && c <= 0x0ED9
- || c >= 0x0F20 && c <= 0x0F29
- || c == 0x002E
- || c == 0x002D
- || c == 0x005F
- || Utilities.isLetter(c)
- || c >= 0x0300 && c <= 0x0345
- || c >= 0x0360 && c <= 0x0361
- || c >= 0x0483 && c <= 0x0486
- || c >= 0x0591 && c <= 0x05A1
- || c >= 0x05A3 && c <= 0x05B9
- || c >= 0x05BB && c <= 0x05BD
- || c == 0x05BF
- || c >= 0x05C1 && c <= 0x05C2
- || c == 0x05C4
- || c >= 0x064B && c <= 0x0652
- || c == 0x0670
- || c >= 0x06D6 && c <= 0x06DC
- || c >= 0x06DD && c <= 0x06DF
- || c >= 0x06E0 && c <= 0x06E4
- || c >= 0x06E7 && c <= 0x06E8
- || c >= 0x06EA && c <= 0x06ED
- || c >= 0x0901 && c <= 0x0903
- || c == 0x093C
- || c >= 0x093E && c <= 0x094C
- || c == 0x094D
- || c >= 0x0951 && c <= 0x0954
- || c >= 0x0962 && c <= 0x0963
- || c >= 0x0981 && c <= 0x0983
- || c == 0x09BC
- || c == 0x09BE
- || c == 0x09BF
- || c >= 0x09C0 && c <= 0x09C4
- || c >= 0x09C7 && c <= 0x09C8
- || c >= 0x09CB && c <= 0x09CD
- || c == 0x09D7
- || c >= 0x09E2 && c <= 0x09E3
- || c == 0x0A02
- || c == 0x0A3C
- || c == 0x0A3E
- || c == 0x0A3F
- || c >= 0x0A40 && c <= 0x0A42
- || c >= 0x0A47 && c <= 0x0A48
- || c >= 0x0A4B && c <= 0x0A4D
- || c >= 0x0A70 && c <= 0x0A71
- || c >= 0x0A81 && c <= 0x0A83
- || c == 0x0ABC
- || c >= 0x0ABE && c <= 0x0AC5
- || c >= 0x0AC7 && c <= 0x0AC9
- || c >= 0x0ACB && c <= 0x0ACD
- || c >= 0x0B01 && c <= 0x0B03
- || c == 0x0B3C
- || c >= 0x0B3E && c <= 0x0B43
- || c >= 0x0B47 && c <= 0x0B48
- || c >= 0x0B4B && c <= 0x0B4D
- || c >= 0x0B56 && c <= 0x0B57
- || c >= 0x0B82 && c <= 0x0B83
- || c >= 0x0BBE && c <= 0x0BC2
- || c >= 0x0BC6 && c <= 0x0BC8
- || c >= 0x0BCA && c <= 0x0BCD
- || c == 0x0BD7
- || c >= 0x0C01 && c <= 0x0C03
- || c >= 0x0C3E && c <= 0x0C44
- || c >= 0x0C46 && c <= 0x0C48
- || c >= 0x0C4A && c <= 0x0C4D
- || c >= 0x0C55 && c <= 0x0C56
- || c >= 0x0C82 && c <= 0x0C83
- || c >= 0x0CBE && c <= 0x0CC4
- || c >= 0x0CC6 && c <= 0x0CC8
- || c >= 0x0CCA && c <= 0x0CCD
- || c >= 0x0CD5 && c <= 0x0CD6
- || c >= 0x0D02 && c <= 0x0D03
- || c >= 0x0D3E && c <= 0x0D43
- || c >= 0x0D46 && c <= 0x0D48
- || c >= 0x0D4A && c <= 0x0D4D
- || c == 0x0D57
- || c == 0x0E31
- || c >= 0x0E34 && c <= 0x0E3A
- || c >= 0x0E47 && c <= 0x0E4E
- || c == 0x0EB1
- || c >= 0x0EB4 && c <= 0x0EB9
- || c >= 0x0EBB && c <= 0x0EBC
- || c >= 0x0EC8 && c <= 0x0ECD
- || c >= 0x0F18 && c <= 0x0F19
- || c == 0x0F35
- || c == 0x0F37
- || c == 0x0F39
- || c == 0x0F3E
- || c == 0x0F3F
- || c >= 0x0F71 && c <= 0x0F84
- || c >= 0x0F86 && c <= 0x0F8B
- || c >= 0x0F90 && c <= 0x0F95
- || c == 0x0F97
- || c >= 0x0F99 && c <= 0x0FAD
- || c >= 0x0FB1 && c <= 0x0FB7
- || c == 0x0FB9
- || c >= 0x20D0 && c <= 0x20DC
- || c == 0x20E1
- || c >= 0x302A && c <= 0x302F
- || c == 0x3099
- || c == 0x309A
- || c == 0x00B7
- || c == 0x02D0
- || c == 0x02D1
- || c == 0x0387
- || c == 0x0640
- || c == 0x0E46
- || c == 0x0EC6
- || c == 0x3005
- || c >= 0x3031 && c <= 0x3035
- || c >= 0x309D && c <= 0x309E
- || c >= 0x30FC && c <= 0x30FE;
-};
-
-Utilities.coalesceText = function(n) {
- for (var m = n.firstChild; m != null; m = m.nextSibling) {
- if (m.nodeType == 3 /*Node.TEXT_NODE*/ || m.nodeType == 4 /*Node.CDATA_SECTION_NODE*/) {
- var s = m.nodeValue;
- var first = m;
- m = m.nextSibling;
- while (m != null && (m.nodeType == 3 /*Node.TEXT_NODE*/ || m.nodeType == 4 /*Node.CDATA_SECTION_NODE*/)) {
- s += m.nodeValue;
- var del = m;
- m = m.nextSibling;
- del.parentNode.removeChild(del);
- }
- if (first.nodeType == 4 /*Node.CDATA_SECTION_NODE*/) {
- var p = first.parentNode;
- if (first.nextSibling == null) {
- p.removeChild(first);
- p.appendChild(p.ownerDocument.createTextNode(s));
- } else {
- var next = first.nextSibling;
- p.removeChild(first);
- p.insertBefore(p.ownerDocument.createTextNode(s), next);
- }
- } else {
- first.nodeValue = s;
- }
- if (m == null) {
- break;
- }
- } else if (m.nodeType == 1 /*Node.ELEMENT_NODE*/) {
- Utilities.coalesceText(m);
- }
- }
-};
-
-Utilities.instance_of = function(o, c) {
- while (o != null) {
- if (o.constructor === c) {
- return true;
- }
- if (o === Object) {
- return false;
- }
- o = o.constructor.superclass;
- }
- return false;
-};
-
-Utilities.getElementById = function(n, id) {
- // Note that this does not check the DTD to check for actual
- // attributes of type ID, so this may be a bit wrong.
- if (n.nodeType == 1 /*Node.ELEMENT_NODE*/) {
- if (n.getAttribute("id") == id
- || n.getAttributeNS(null, "id") == id) {
- return n;
- }
- }
- for (var m = n.firstChild; m != null; m = m.nextSibling) {
- var res = Utilities.getElementById(m, id);
- if (res != null) {
- return res;
- }
- }
- return null;
-};
-
-// XPathException ////////////////////////////////////////////////////////////
-
-XPathException.prototype = {};
-XPathException.prototype.constructor = XPathException;
-XPathException.superclass = Object.prototype;
-
-function XPathException(c, e) {
- this.code = c;
- this.exception = e;
-}
-
-XPathException.prototype.toString = function() {
- var msg = this.exception ? ": " + this.exception.toString() : "";
- switch (this.code) {
- case XPathException.INVALID_EXPRESSION_ERR:
- return "Invalid expression" + msg;
- case XPathException.TYPE_ERR:
- return "Type error" + msg;
- }
-};
-
-XPathException.INVALID_EXPRESSION_ERR = 51;
-XPathException.TYPE_ERR = 52;
-
-// XPathExpression ///////////////////////////////////////////////////////////
-
-XPathExpression.prototype = {};
-XPathExpression.prototype.constructor = XPathExpression;
-XPathExpression.superclass = Object.prototype;
-
-function XPathExpression(e, r, p) {
- this.xpath = p.parse(e);
- this.context = new XPathContext();
- this.context.namespaceResolver = new XPathNSResolverWrapper(r);
-}
-
-XPathExpression.prototype.evaluate = function(n, t, res) {
- this.context.expressionContextNode = n;
- var result = this.xpath.evaluate(this.context);
- return new XPathResult(result, t);
-}
-
-// XPathNSResolverWrapper ////////////////////////////////////////////////////
-
-XPathNSResolverWrapper.prototype = {};
-XPathNSResolverWrapper.prototype.constructor = XPathNSResolverWrapper;
-XPathNSResolverWrapper.superclass = Object.prototype;
-
-function XPathNSResolverWrapper(r) {
- this.xpathNSResolver = r;
-}
-
-XPathNSResolverWrapper.prototype.getNamespace = function(prefix, n) {
- if (this.xpathNSResolver == null) {
- return null;
- }
- return this.xpathNSResolver.lookupNamespaceURI(prefix);
-};
-
-// NodeXPathNSResolver ///////////////////////////////////////////////////////
-
-NodeXPathNSResolver.prototype = {};
-NodeXPathNSResolver.prototype.constructor = NodeXPathNSResolver;
-NodeXPathNSResolver.superclass = Object.prototype;
-
-function NodeXPathNSResolver(n) {
- this.node = n;
- this.namespaceResolver = new NamespaceResolver();
-}
-
-NodeXPathNSResolver.prototype.lookupNamespaceURI = function(prefix) {
- return this.namespaceResolver.getNamespace(prefix, this.node);
-};
-
-// XPathResult ///////////////////////////////////////////////////////////////
-
-XPathResult.prototype = {};
-XPathResult.prototype.constructor = XPathResult;
-XPathResult.superclass = Object.prototype;
-
-function XPathResult(v, t) {
- if (t == XPathResult.ANY_TYPE) {
- if (v.constructor === XString) {
- t = XPathResult.STRING_TYPE;
- } else if (v.constructor === XNumber) {
- t = XPathResult.NUMBER_TYPE;
- } else if (v.constructor === XBoolean) {
- t = XPathResult.BOOLEAN_TYPE;
- } else if (v.constructor === XNodeSet) {
- t = XPathResult.UNORDERED_NODE_ITERATOR_TYPE;
- }
- }
- this.resultType = t;
- switch (t) {
- case XPathResult.NUMBER_TYPE:
- this.numberValue = v.numberValue();
- return;
- case XPathResult.STRING_TYPE:
- this.stringValue = v.stringValue();
- return;
- case XPathResult.BOOLEAN_TYPE:
- this.booleanValue = v.booleanValue();
- return;
- case XPathResult.ANY_UNORDERED_NODE_TYPE:
- case XPathResult.FIRST_UNORDERED_NODE_TYPE:
- if (v.constructor === XNodeSet) {
- this.singleNodeValue = v.first();
- return;
- }
- break;
- case XPathResult.UNORDERED_NODE_ITERATOR_TYPE:
- case XPathResult.ORDERED_NODE_ITERATOR_TYPE:
- if (v.constructor === XNodeSet) {
- this.invalidIteratorState = false;
- this.nodes = v.toArray();
- this.iteratorIndex = 0;
- return;
- }
- break;
- case XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE:
- case XPathResult.ORDERED_NODE_SNAPSHOT_TYPE:
- if (v.constructor === XNodeSet) {
- this.nodes = v.toArray();
- this.snapshotLength = this.nodes.length;
- return;
- }
- break;
- }
- throw new XPathException(XPathException.TYPE_ERR);
-};
-
-XPathResult.prototype.iterateNext = function() {
- if (this.resultType != XPathResult.UNORDERED_NODE_ITERATOR_TYPE
- && this.resultType != XPathResult.ORDERED_NODE_ITERATOR_TYPE) {
- throw new XPathException(XPathException.TYPE_ERR);
- }
- return this.nodes[this.iteratorIndex++];
-};
-
-XPathResult.prototype.snapshotItem = function(i) {
- if (this.resultType != XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE
- && this.resultType != XPathResult.ORDERED_NODE_SNAPSHOT_TYPE) {
- throw new XPathException(XPathException.TYPE_ERR);
- }
- return this.nodes[i];
-};
-
-XPathResult.ANY_TYPE = 0;
-XPathResult.NUMBER_TYPE = 1;
-XPathResult.STRING_TYPE = 2;
-XPathResult.BOOLEAN_TYPE = 3;
-XPathResult.UNORDERED_NODE_ITERATOR_TYPE = 4;
-XPathResult.ORDERED_NODE_ITERATOR_TYPE = 5;
-XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE = 6;
-XPathResult.ORDERED_NODE_SNAPSHOT_TYPE = 7;
-XPathResult.ANY_UNORDERED_NODE_TYPE = 8;
-XPathResult.FIRST_ORDERED_NODE_TYPE = 9;
-
-// DOM 3 XPath support ///////////////////////////////////////////////////////
-
-function installDOM3XPathSupport(doc, p) {
- doc.createExpression = function(e, r) {
- try {
- return new XPathExpression(e, r, p);
- } catch (e) {
- throw new XPathException(XPathException.INVALID_EXPRESSION_ERR, e);
- }
- };
- doc.createNSResolver = function(n) {
- return new NodeXPathNSResolver(n);
- };
- doc.evaluate = function(e, cn, r, t, res) {
- if (t < 0 || t > 9) {
- throw { code: 0, toString: function() { return "Request type not supported"; } };
- }
- return doc.createExpression(e, r, p).evaluate(cn, t, res);
- };
-};
-
-// ---------------------------------------------------------------------------
-
-// Install DOM 3 XPath support for the current document.
-try {
- var shouldInstall = true;
- try {
- if (document.implementation
- && document.implementation.hasFeature
- && document.implementation.hasFeature("XPath", null)) {
- shouldInstall = false;
- }
- } catch (e) {
- }
- if (shouldInstall) {
- installDOM3XPathSupport(document, new XPathParser());
- }
-} catch (e) {
-}
Modified: zc.selenium/trunk/src/zc/selenium/resources/selenium.css
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/selenium.css 2006-08-29 18:04:40 UTC (rev 69877)
+++ zc.selenium/trunk/src/zc/selenium/resources/selenium.css 2006-08-29 18:41:08 UTC (rev 69878)
@@ -209,3 +209,29 @@
#logging-console li.debug {
color: green;
}
+
+
+table.selenium {
+ font-family:Verdana, Arial, sans-serif;
+ font-size:12;
+ border-width: 1px 1px 1px 1px;
+ border-spacing: 2px;
+ border-style: solid none solid none;
+ border-color: gray gray gray gray;
+ border-collapse: separate;
+ background-color: white;
+}
+table.selenium th {
+ border-width: 1px 1px 1px 1px;
+ padding: 1px 1px 1px 1px;
+ border-style: none none none none;
+ border-color: gray gray gray gray;
+ -moz-border-radius: 0px 0px 0px 0px;
+}
+table.selenium td {
+ border-width: 1px 1px 1px 1px;
+ padding: 1px 1px 1px 1px;
+ border-style: none none none none;
+ border-color: gray gray gray gray;
+ -moz-border-radius: 0px 0px 0px 0px;
+}
\ No newline at end of file
Added: zc.selenium/trunk/src/zc/selenium/resources/xpath/dom.js
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/xpath/dom.js 2006-08-29 18:04:40 UTC (rev 69877)
+++ zc.selenium/trunk/src/zc/selenium/resources/xpath/dom.js 2006-08-29 18:41:08 UTC (rev 69878)
@@ -0,0 +1,428 @@
+// Copyright 2005 Google Inc.
+// All Rights Reserved
+//
+// An XML parse and a minimal DOM implementation that just supportes
+// the subset of the W3C DOM that is used in the XSLT implementation.
+//
+// References:
+//
+// [DOM] W3C DOM Level 3 Core Specification
+// <http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/>.
+//
+//
+// Author: Steffen Meschkat <mesch at google.com>
+
+// NOTE: The split() method in IE omits empty result strings. This is
+// utterly annoying. So we don't use it here.
+
+// Resolve entities in XML text fragments. According to the DOM
+// specification, the DOM is supposed to resolve entity references at
+// the API level. I.e. no entity references are passed through the
+// API. See "Entities and the DOM core", p.12, DOM 2 Core
+// Spec. However, different browsers actually pass very different
+// values at the API.
+//
+function xmlResolveEntities(s) {
+
+ var parts = stringSplit(s, '&');
+
+ var ret = parts[0];
+ for (var i = 1; i < parts.length; ++i) {
+ var rp = stringSplit(parts[i], ';');
+ if (rp.length == 1) {
+ // no entity reference: just a & but no ;
+ ret += parts[i];
+ continue;
+ }
+
+ var ch;
+ switch (rp[0]) {
+ case 'lt':
+ ch = '<';
+ break;
+ case 'gt':
+ ch = '>';
+ break;
+ case 'amp':
+ ch = '&';
+ break;
+ case 'quot':
+ ch = '"';
+ break;
+ case 'apos':
+ ch = '\'';
+ break;
+ case 'nbsp':
+ ch = String.fromCharCode(160);
+ break;
+ default:
+ // Cool trick: let the DOM do the entity decoding. We assign
+ // the entity text through non-W3C DOM properties and read it
+ // through the W3C DOM. W3C DOM access is specified to resolve
+ // entities.
+ var span = window.document.createElement('span');
+ span.innerHTML = '&' + rp[0] + '; ';
+ ch = span.childNodes[0].nodeValue.charAt(0);
+ }
+ ret += ch + rp[1];
+ }
+
+ return ret;
+}
+
+
+// Parses the given XML string with our custom, JavaScript XML parser. Written
+// by Steffen Meschkat (mesch at google.com).
+function xmlParse(xml) {
+ Timer.start('xmlparse');
+ var regex_empty = /\/$/;
+
+ // See also <http://www.w3.org/TR/REC-xml/#sec-common-syn> for
+ // allowed chars in a tag and attribute name. TODO(mesch): the
+ // following is still not completely correct.
+
+ var regex_tagname = /^([\w:-]*)/;
+ var regex_attribute = /([\w:-]+)\s?=\s?('([^\']*)'|"([^\"]*)")/g;
+
+ var xmldoc = new XDocument();
+ var root = xmldoc;
+
+ // For the record: in Safari, we would create native DOM nodes, but
+ // in Opera that is not possible, because the DOM only allows HTML
+ // element nodes to be created, so we have to do our own DOM nodes.
+
+ // xmldoc = document.implementation.createDocument('','',null);
+ // root = xmldoc; // .createDocumentFragment();
+ // NOTE(mesch): using the DocumentFragment instead of the Document
+ // crashes my Safari 1.2.4 (v125.12).
+ var stack = [];
+
+ var parent = root;
+ stack.push(parent);
+
+ var x = stringSplit(xml, '<');
+ for (var i = 1; i < x.length; ++i) {
+ var xx = stringSplit(x[i], '>');
+ var tag = xx[0];
+ var text = xmlResolveEntities(xx[1] || '');
+
+ if (tag.charAt(0) == '/') {
+ stack.pop();
+ parent = stack[stack.length-1];
+
+ } else if (tag.charAt(0) == '?') {
+ // Ignore XML declaration and processing instructions
+ } else if (tag.charAt(0) == '!') {
+ // Ignore notation and comments
+ } else {
+ var empty = tag.match(regex_empty);
+ var tagname = regex_tagname.exec(tag)[1];
+ var node = xmldoc.createElement(tagname);
+
+ var att;
+ while (att = regex_attribute.exec(tag)) {
+ var val = xmlResolveEntities(att[3] || att[4] || '');
+ node.setAttribute(att[1], val);
+ }
+
+ if (empty) {
+ parent.appendChild(node);
+ } else {
+ parent.appendChild(node);
+ parent = node;
+ stack.push(node);
+ }
+ }
+
+ if (text && parent != root) {
+ parent.appendChild(xmldoc.createTextNode(text));
+ }
+ }
+
+ Timer.end('xmlparse');
+ return root;
+}
+
+
+// Our W3C DOM Node implementation. Note we call it XNode because we
+// can't define the identifier Node. We do this mostly for Opera,
+// where we can't reuse the HTML DOM for parsing our own XML, and for
+// Safari, where it is too expensive to have the template processor
+// operate on native DOM nodes.
+function XNode(type, name, value, owner) {
+ this.attributes = [];
+ this.childNodes = [];
+
+ XNode.init.call(this, type, name, value, owner);
+}
+
+// Don't call as method, use apply() or call().
+XNode.init = function(type, name, value, owner) {
+ this.nodeType = type - 0;
+ this.nodeName = '' + name;
+ this.nodeValue = '' + value;
+ this.ownerDocument = owner;
+
+ this.firstChild = null;
+ this.lastChild = null;
+ this.nextSibling = null;
+ this.previousSibling = null;
+ this.parentNode = null;
+}
+
+XNode.unused_ = [];
+
+XNode.recycle = function(node) {
+ if (!node) {
+ return;
+ }
+
+ if (node.constructor == XDocument) {
+ XNode.recycle(node.documentElement);
+ return;
+ }
+
+ if (node.constructor != this) {
+ return;
+ }
+
+ XNode.unused_.push(node);
+ for (var a = 0; a < node.attributes.length; ++a) {
+ XNode.recycle(node.attributes[a]);
+ }
+ for (var c = 0; c < node.childNodes.length; ++c) {
+ XNode.recycle(node.childNodes[c]);
+ }
+ node.attributes.length = 0;
+ node.childNodes.length = 0;
+ XNode.init.call(node, 0, '', '', null);
+}
+
+XNode.create = function(type, name, value, owner) {
+ if (XNode.unused_.length > 0) {
+ var node = XNode.unused_.pop();
+ XNode.init.call(node, type, name, value, owner);
+ return node;
+ } else {
+ return new XNode(type, name, value, owner);
+ }
+}
+
+XNode.prototype.appendChild = function(node) {
+ // firstChild
+ if (this.childNodes.length == 0) {
+ this.firstChild = node;
+ }
+
+ // previousSibling
+ node.previousSibling = this.lastChild;
+
+ // nextSibling
+ node.nextSibling = null;
+ if (this.lastChild) {
+ this.lastChild.nextSibling = node;
+ }
+
+ // parentNode
+ node.parentNode = this;
+
+ // lastChild
+ this.lastChild = node;
+
+ // childNodes
+ this.childNodes.push(node);
+}
+
+
+XNode.prototype.replaceChild = function(newNode, oldNode) {
+ if (oldNode == newNode) {
+ return;
+ }
+
+ for (var i = 0; i < this.childNodes.length; ++i) {
+ if (this.childNodes[i] == oldNode) {
+ this.childNodes[i] = newNode;
+
+ var p = oldNode.parentNode;
+ oldNode.parentNode = null;
+ newNode.parentNode = p;
+
+ p = oldNode.previousSibling;
+ oldNode.previousSibling = null;
+ newNode.previousSibling = p;
+ if (newNode.previousSibling) {
+ newNode.previousSibling.nextSibling = newNode;
+ }
+
+ p = oldNode.nextSibling;
+ oldNode.nextSibling = null;
+ newNode.nextSibling = p;
+ if (newNode.nextSibling) {
+ newNode.nextSibling.previousSibling = newNode;
+ }
+
+ if (this.firstChild == oldNode) {
+ this.firstChild = newNode;
+ }
+
+ if (this.lastChild == oldNode) {
+ this.lastChild = newNode;
+ }
+
+ break;
+ }
+ }
+}
+
+XNode.prototype.insertBefore = function(newNode, oldNode) {
+ if (oldNode == newNode) {
+ return;
+ }
+
+ if (oldNode.parentNode != this) {
+ return;
+ }
+
+ if (newNode.parentNode) {
+ newNode.parentNode.removeChild(newNode);
+ }
+
+ var newChildren = [];
+ for (var i = 0; i < this.childNodes.length; ++i) {
+ var c = this.childNodes[i];
+ if (c == oldNode) {
+ newChildren.push(newNode);
+
+ newNode.parentNode = this;
+
+ newNode.previousSibling = oldNode.previousSibling;
+ oldNode.previousSibling = newNode;
+ if (newNode.previousSibling) {
+ newNode.previousSibling.nextSibling = newNode;
+ }
+
+ newNode.nextSibling = oldNode;
+
+ if (this.firstChild == oldNode) {
+ this.firstChild = newNode;
+ }
+ }
+ newChildren.push(c);
+ }
+ this.childNodes = newChildren;
+}
+
+XNode.prototype.removeChild = function(node) {
+ var newChildren = [];
+ for (var i = 0; i < this.childNodes.length; ++i) {
+ var c = this.childNodes[i];
+ if (c != node) {
+ newChildren.push(c);
+ } else {
+ if (c.previousSibling) {
+ c.previousSibling.nextSibling = c.nextSibling;
+ }
+ if (c.nextSibling) {
+ c.nextSibling.previousSibling = c.previousSibling;
+ }
+ if (this.firstChild == c) {
+ this.firstChild = c.nextSibling;
+ }
+ if (this.lastChild == c) {
+ this.lastChild = c.previousSibling;
+ }
+ }
+ }
+ this.childNodes = newChildren;
+}
+
+
+XNode.prototype.hasAttributes = function() {
+ return this.attributes.length > 0;
+}
+
+
+XNode.prototype.setAttribute = function(name, value) {
+ for (var i = 0; i < this.attributes.length; ++i) {
+ if (this.attributes[i].nodeName == name) {
+ this.attributes[i].nodeValue = '' + value;
+ return;
+ }
+ }
+ this.attributes.push(new XNode(DOM_ATTRIBUTE_NODE, name, value));
+}
+
+
+XNode.prototype.getAttribute = function(name) {
+ for (var i = 0; i < this.attributes.length; ++i) {
+ if (this.attributes[i].nodeName == name) {
+ return this.attributes[i].nodeValue;
+ }
+ }
+ return null;
+}
+
+XNode.prototype.removeAttribute = function(name) {
+ var a = [];
+ for (var i = 0; i < this.attributes.length; ++i) {
+ if (this.attributes[i].nodeName != name) {
+ a.push(this.attributes[i]);
+ }
+ }
+ this.attributes = a;
+}
+
+
+function XDocument() {
+ XNode.call(this, DOM_DOCUMENT_NODE, '#document', null, this);
+ this.documentElement = null;
+}
+
+XDocument.prototype = new XNode(DOM_DOCUMENT_NODE, '#document');
+
+XDocument.prototype.clear = function() {
+ XNode.recycle(this.documentElement);
+ this.documentElement = null;
+}
+
+XDocument.prototype.appendChild = function(node) {
+ XNode.prototype.appendChild.call(this, node);
+ this.documentElement = this.childNodes[0];
+}
+
+XDocument.prototype.createElement = function(name) {
+ return XNode.create(DOM_ELEMENT_NODE, name, null, this);
+}
+
+XDocument.prototype.createDocumentFragment = function() {
+ return XNode.create(DOM_DOCUMENT_FRAGMENT_NODE, '#document-fragment',
+ null, this);
+}
+
+XDocument.prototype.createTextNode = function(value) {
+ return XNode.create(DOM_TEXT_NODE, '#text', value, this);
+}
+
+XDocument.prototype.createAttribute = function(name) {
+ return XNode.create(DOM_ATTRIBUTE_NODE, name, null, this);
+}
+
+XDocument.prototype.createComment = function(data) {
+ return XNode.create(DOM_COMMENT_NODE, '#comment', data, this);
+}
+
+XNode.prototype.getElementsByTagName = function(name, list) {
+ if (!list) {
+ list = [];
+ }
+
+ if (this.nodeName == name) {
+ list.push(this);
+ }
+
+ for (var i = 0; i < this.childNodes.length; ++i) {
+ this.childNodes[i].getElementsByTagName(name, list);
+ }
+
+ return list;
+}
Added: zc.selenium/trunk/src/zc/selenium/resources/xpath/misc.js
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/xpath/misc.js 2006-08-29 18:04:40 UTC (rev 69877)
+++ zc.selenium/trunk/src/zc/selenium/resources/xpath/misc.js 2006-08-29 18:41:08 UTC (rev 69878)
@@ -0,0 +1,255 @@
+// Copyright 2005 Google Inc.
+// All Rights Reserved
+//
+// Miscellania that support the ajaxslt implementation.
+//
+// Author: Steffen Meschkat <mesch at google.com>
+//
+
+function el(i) {
+ return document.getElementById(i);
+}
+
+function px(x) {
+ return x + 'px';
+}
+
+// Split a string s at all occurrences of character c. This is like
+// the split() method of the string object, but IE omits empty
+// strings, which violates the invariant (s.split(x).join(x) == s).
+function stringSplit(s, c) {
+ var a = s.indexOf(c);
+ if (a == -1) {
+ return [ s ];
+ }
+
+ var parts = [];
+ parts.push(s.substr(0,a));
+ while (a != -1) {
+ var a1 = s.indexOf(c, a + 1);
+ if (a1 != -1) {
+ parts.push(s.substr(a + 1, a1 - a - 1));
+ } else {
+ parts.push(s.substr(a + 1));
+ }
+ a = a1;
+ }
+
+ return parts;
+}
+
+// Returns the text value if a node; for nodes without children this
+// is the nodeValue, for nodes with children this is the concatenation
+// of the value of all children.
+function xmlValue(node) {
+ if (!node) {
+ return '';
+ }
+
+ var ret = '';
+ if (node.nodeType == DOM_TEXT_NODE ||
+ node.nodeType == DOM_CDATA_SECTION_NODE ||
+ node.nodeType == DOM_ATTRIBUTE_NODE) {
+ ret += node.nodeValue;
+
+ } else if (node.nodeType == DOM_ELEMENT_NODE ||
+ node.nodeType == DOM_DOCUMENT_NODE ||
+ node.nodeType == DOM_DOCUMENT_FRAGMENT_NODE) {
+ for (var i = 0; i < node.childNodes.length; ++i) {
+ ret += arguments.callee(node.childNodes[i]);
+ }
+ }
+ return ret;
+}
+
+// Returns the representation of a node as XML text.
+function xmlText(node) {
+ var ret = '';
+ if (node.nodeType == DOM_TEXT_NODE) {
+ ret += xmlEscapeText(node.nodeValue);
+
+ } else if (node.nodeType == DOM_ELEMENT_NODE) {
+ ret += '<' + node.nodeName;
+ for (var i = 0; i < node.attributes.length; ++i) {
+ var a = node.attributes[i];
+ if (a && a.nodeName && a.nodeValue) {
+ ret += ' ' + a.nodeName;
+ ret += '="' + xmlEscapeAttr(a.nodeValue) + '"';
+ }
+ }
+
+ if (node.childNodes.length == 0) {
+ ret += '/>';
+
+ } else {
+ ret += '>';
+ for (var i = 0; i < node.childNodes.length; ++i) {
+ ret += arguments.callee(node.childNodes[i]);
+ }
+ ret += '</' + node.nodeName + '>';
+ }
+
+ } else if (node.nodeType == DOM_DOCUMENT_NODE ||
+ node.nodeType == DOM_DOCUMENT_FRAGMENT_NODE) {
+ for (var i = 0; i < node.childNodes.length; ++i) {
+ ret += arguments.callee(node.childNodes[i]);
+ }
+ }
+
+ return ret;
+}
+
+// Applies the given function to each element of the array.
+function mapExec(array, func) {
+ for (var i = 0; i < array.length; ++i) {
+ func(array[i]);
+ }
+}
+
+// Returns an array that contains the return value of the given
+// function applied to every element of the input array.
+function mapExpr(array, func) {
+ var ret = [];
+ for (var i = 0; i < array.length; ++i) {
+ ret.push(func(array[i]));
+ }
+ return ret;
+};
+
+// Reverses the given array in place.
+function reverseInplace(array) {
+ for (var i = 0; i < array.length / 2; ++i) {
+ var h = array[i];
+ var ii = array.length - i - 1;
+ array[i] = array[ii];
+ array[ii] = h;
+ }
+}
+
+// Shallow-copies an array.
+function copyArray(dst, src) {
+ for (var i = 0; i < src.length; ++i) {
+ dst.push(src[i]);
+ }
+}
+
+function assert(b) {
+ if (!b) {
+ throw 'assertion failed';
+ }
+}
+
+// Based on
+// <http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1950641247>
+var DOM_ELEMENT_NODE = 1;
+var DOM_ATTRIBUTE_NODE = 2;
+var DOM_TEXT_NODE = 3;
+var DOM_CDATA_SECTION_NODE = 4;
+var DOM_ENTITY_REFERENCE_NODE = 5;
+var DOM_ENTITY_NODE = 6;
+var DOM_PROCESSING_INSTRUCTION_NODE = 7;
+var DOM_COMMENT_NODE = 8;
+var DOM_DOCUMENT_NODE = 9;
+var DOM_DOCUMENT_TYPE_NODE = 10;
+var DOM_DOCUMENT_FRAGMENT_NODE = 11;
+var DOM_NOTATION_NODE = 12;
+
+
+var xpathdebug = false; // trace xpath parsing
+var xsltdebug = false; // trace xslt processing
+
+
+// Escape XML special markup chracters: tag delimiter < > and entity
+// reference start delimiter &. The escaped string can be used in XML
+// text portions (i.e. between tags).
+function xmlEscapeText(s) {
+ return s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
+}
+
+// Escape XML special markup characters: tag delimiter < > entity
+// reference start delimiter & and quotes ". The escaped string can be
+// used in double quoted XML attribute value portions (i.e. in
+// attributes within start tags).
+function xmlEscapeAttr(s) {
+ return xmlEscapeText(s).replace(/\"/g, '"');
+}
+
+// Escape markup in XML text, but don't touch entity references. The
+// escaped string can be used as XML text (i.e. between tags).
+function xmlEscapeTags(s) {
+ return s.replace(/</g, '<').replace(/>/g, '>');
+}
+
+// An implementation of the debug log.
+
+var logging__ = false;
+
+function Log() {};
+
+Log.lines = [];
+
+Log.write = function(s) {
+ if (logging__) {
+ this.lines.push(xmlEscapeText(s));
+ this.show();
+ }
+};
+
+// Writes the given XML with every tag on a new line.
+Log.writeXML = function(xml) {
+ if (logging__) {
+ var s0 = xml.replace(/</g, '\n<');
+ var s1 = xmlEscapeText(s0);
+ var s2 = s1.replace(/\s*\n(\s|\n)*/g, '<br/>');
+ this.lines.push(s2);
+ this.show();
+ }
+}
+
+// Writes without any escaping
+Log.writeRaw = function(s) {
+ if (logging__) {
+ this.lines.push(s);
+ this.show();
+ }
+}
+
+Log.clear = function() {
+ if (logging__) {
+ var l = this.div();
+ l.innerHTML = '';
+ this.lines = [];
+ }
+}
+
+Log.show = function() {
+ var l = this.div();
+ l.innerHTML += this.lines.join('<br/>') + '<br/>';
+ this.lines = [];
+ l.scrollTop = l.scrollHeight;
+}
+
+Log.div = function() {
+ var l = document.getElementById('log');
+ if (!l) {
+ l = document.createElement('div');
+ l.id = 'log';
+ l.style.position = 'absolute';
+ l.style.right = '5px';
+ l.style.top = '5px';
+ l.style.width = '250px';
+ l.style.height = '150px';
+ l.style.overflow = 'auto';
+ l.style.backgroundColor = '#f0f0f0';
+ l.style.border = '1px solid gray';
+ l.style.fontSize = '10px';
+ l.style.padding = '5px';
+ document.body.appendChild(l);
+ }
+ return l;
+}
+
+
+function Timer() {}
+Timer.start = function() {}
+Timer.end = function() {}
Added: zc.selenium/trunk/src/zc/selenium/resources/xpath/xpath.js
===================================================================
--- zc.selenium/trunk/src/zc/selenium/resources/xpath/xpath.js 2006-08-29 18:04:40 UTC (rev 69877)
+++ zc.selenium/trunk/src/zc/selenium/resources/xpath/xpath.js 2006-08-29 18:41:08 UTC (rev 69878)
@@ -0,0 +1,2182 @@
+// Copyright 2005 Google Inc.
+// All Rights Reserved
+//
+// An XPath parser and evaluator written in JavaScript. The
+// implementation is complete except for functions handling
+// namespaces.
+//
+// Reference: [XPATH] XPath Specification
+// <http://www.w3.org/TR/1999/REC-xpath-19991116>.
+//
+//
+// The API of the parser has several parts:
+//
+// 1. The parser function xpathParse() that takes a string and returns
+// an expession object.
+//
+// 2. The expression object that has an evaluate() method to evaluate the
+// XPath expression it represents. (It is actually a hierarchy of
+// objects that resembles the parse tree, but an application will call
+// evaluate() only on the top node of this hierarchy.)
+//
+// 3. The context object that is passed as an argument to the evaluate()
+// method, which represents the DOM context in which the expression is
+// evaluated.
+//
+// 4. The value object that is returned from evaluate() and represents
+// values of the different types that are defined by XPath (number,
+// string, boolean, and node-set), and allows to convert between them.
+//
+// These parts are near the top of the file, the functions and data
+// that are used internally follow after them.
+//
+//
+// TODO(mesch): add jsdoc comments. Use more coherent naming.
+//
+//
+// Author: Steffen Meschkat <mesch at google.com>
+
+
+// The entry point for the parser.
+//
+// @param expr a string that contains an XPath expression.
+// @return an expression object that can be evaluated with an
+// expression context.
+
+function xpathParse(expr) {
+ if (xpathdebug) {
+ Log.write('XPath parse ' + expr);
+ }
+ xpathParseInit();
+
+ var cached = xpathCacheLookup(expr);
+ if (cached) {
+ if (xpathdebug) {
+ Log.write(' ... cached');
+ }
+ return cached;
+ }
+
+ // Optimize for a few common cases: simple attribute node tests
+ // (@id), simple element node tests (page), variable references
+ // ($address), numbers (4), multi-step path expressions where each
+ // step is a plain element node test
+ // (page/overlay/locations/location).
+
+ if (expr.match(/^(\$|@)?\w+$/i)) {
+ var ret = makeSimpleExpr(expr);
+ xpathParseCache[expr] = ret;
+ if (xpathdebug) {
+ Log.write(' ... simple');
+ }
+ return ret;
+ }
+
+ if (expr.match(/^\w+(\/\w+)*$/i)) {
+ var ret = makeSimpleExpr2(expr);
+ xpathParseCache[expr] = ret;
+ if (xpathdebug) {
+ Log.write(' ... simple 2');
+ }
+ return ret;
+ }
+
+ var cachekey = expr; // expr is modified during parse
+ if (xpathdebug) {
+ Timer.start('XPath parse', cachekey);
+ }
+
+ var stack = [];
+ var ahead = null;
+ var previous = null;
+ var done = false;
+
+ var parse_count = 0;
+ var lexer_count = 0;
+ var reduce_count = 0;
+
+ while (!done) {
+ parse_count++;
+ expr = expr.replace(/^\s*/, '');
+ previous = ahead;
+ ahead = null;
+
+ var rule = null;
+ var match = '';
+ for (var i = 0; i < xpathTokenRules.length; ++i) {
+ var result = xpathTokenRules[i].re.exec(expr);
+ lexer_count++;
+ if (result && result.length > 0 && result[0].length > match.length) {
+ rule = xpathTokenRules[i];
+ match = result[0];
+ break;
+ }
+ }
+
+ // Special case: allow operator keywords to be element and
+ // variable names.
+
+ // NOTE(mesch): The parser resolves conflicts by looking ahead,
+ // and this is the only case where we look back to
+ // disambiguate. So this is indeed something different, and
+ // looking back is usually done in the lexer (via states in the
+ // general case, called "start conditions" in flex(1)). Also,the
+ // conflict resolution in the parser is not as robust as it could
+ // be, so I'd like to keep as much off the parser as possible (all
+ // these precedence values should be computed from the grammar
+ // rules and possibly associativity declarations, as in bison(1),
+ // and not explicitly set.
+
+ if (rule &&
+ (rule == TOK_DIV ||
+ rule == TOK_MOD ||
+ rule == TOK_AND ||
+ rule == TOK_OR) &&
+ (!previous ||
+ previous.tag == TOK_AT ||
+ previous.tag == TOK_DSLASH ||
+ previous.tag == TOK_SLASH ||
+ previous.tag == TOK_AXIS ||
+ previous.tag == TOK_DOLLAR)) {
+ rule = TOK_QNAME;
+ }
+
+ if (rule) {
+ expr = expr.substr(match.length);
+ if (xpathdebug) {
+ Log.write('token: ' + match + ' -- ' + rule.label);
+ }
+ ahead = {
+ tag: rule,
+ match: match,
+ prec: rule.prec ? rule.prec : 0, // || 0 is removed by the compiler
+ expr: makeTokenExpr(match)
+ };
+
+ } else {
+ if (xpathdebug) {
+ Log.write('DONE');
+ }
+ done = true;
+ }
+
+ while (xpathReduce(stack, ahead)) {
+ reduce_count++;
+ if (xpathdebug) {
+ Log.write('stack: ' + stackToString(stack));
+ }
+ }
+ }
+
+ if (xpathdebug) {
+ Log.write(stackToString(stack));
+ }
+
+ if (stack.length != 1) {
+ throw 'XPath parse error ' + cachekey + ':\n' + stackToString(stack);
+ }
+
+ var result = stack[0].expr;
+ xpathParseCache[cachekey] = result;
+
+ if (xpathdebug) {
+ Timer.end('XPath parse', cachekey);
+ }
+
+ if (xpathdebug) {
+ Log.write('XPath parse: ' + parse_count + ' / ' +
+ lexer_count + ' / ' + reduce_count);
+ }
+
+ return result;
+}
+
+var xpathParseCache = {};
+
+function xpathCacheLookup(expr) {
+ return xpathParseCache[expr];
+}
+
+function xpathReduce(stack, ahead) {
+ var cand = null;
+
+ if (stack.length > 0) {
+ var top = stack[stack.length-1];
+ var ruleset = xpathRules[top.tag.key];
+
+ if (ruleset) {
+ for (var i = 0; i < ruleset.length; ++i) {
+ var rule = ruleset[i];
+ var match = xpathMatchStack(stack, rule[1]);
+ if (match.length) {
+ cand = {
+ tag: rule[0],
+ rule: rule,
+ match: match
+ };
+ cand.prec = xpathGrammarPrecedence(cand);
+ break;
+ }
+ }
+ }
+ }
+
+ var ret;
+ if (cand && (!ahead || cand.prec > ahead.prec ||
+ (ahead.tag.left && cand.prec >= ahead.prec))) {
+ for (var i = 0; i < cand.match.matchlength; ++i) {
+ stack.pop();
+ }
+
+ if (xpathdebug) {
+ Log.write('reduce ' + cand.tag.label + ' ' + cand.prec +
+ ' ahead ' + (ahead ? ahead.tag.label + ' ' + ahead.prec +
+ (ahead.tag.left ? ' left' : '')
+ : ' none '));
+ }
+
+ var matchexpr = mapExpr(cand.match, function(m) { return m.expr; });
+ cand.expr = cand.rule[3].apply(null, matchexpr);
+
+ stack.push(cand);
+ ret = true;
+
+ } else {
+ if (ahead) {
+ if (xpathdebug) {
+ Log.write('shift ' + ahead.tag.label + ' ' + ahead.prec +
+ (ahead.tag.left ? ' left' : '') +
+ ' over ' + (cand ? cand.tag.label + ' ' +
+ cand.prec : ' none'));
+ }
+ stack.push(ahead);
+ }
+ ret = false;
+ }
+ return ret;
+}
+
+function xpathMatchStack(stack, pattern) {
+
+ // NOTE(mesch): The stack matches for variable cardinality are
+ // greedy but don't do backtracking. This would be an issue only
+ // with rules of the form A* A, i.e. with an element with variable
+ // cardinality followed by the same element. Since that doesn't
+ // occur in the grammar at hand, all matches on the stack are
+ // unambiguous.
+
+ var S = stack.length;
+ var P = pattern.length;
+ var p, s;
+ var match = [];
+ match.matchlength = 0;
+ var ds = 0;
+ for (p = P - 1, s = S - 1; p >= 0 && s >= 0; --p, s -= ds) {
+ ds = 0;
+ var qmatch = [];
+ if (pattern[p] == Q_MM) {
+ p -= 1;
+ match.push(qmatch);
+ while (s - ds >= 0 && stack[s - ds].tag == pattern[p]) {
+ qmatch.push(stack[s - ds]);
+ ds += 1;
+ match.matchlength += 1;
+ }
+
+ } else if (pattern[p] == Q_01) {
+ p -= 1;
+ match.push(qmatch);
+ while (s - ds >= 0 && ds < 2 && stack[s - ds].tag == pattern[p]) {
+ qmatch.push(stack[s - ds]);
+ ds += 1;
+ match.matchlength += 1;
+ }
+
+ } else if (pattern[p] == Q_1M) {
+ p -= 1;
+ match.push(qmatch);
+ if (stack[s].tag == pattern[p]) {
+ while (s - ds >= 0 && stack[s - ds].tag == pattern[p]) {
+ qmatch.push(stack[s - ds]);
+ ds += 1;
+ match.matchlength += 1;
+ }
+ } else {
+ return [];
+ }
+
+ } else if (stack[s].tag == pattern[p]) {
+ match.push(stack[s]);
+ ds += 1;
+ match.matchlength += 1;
+
+ } else {
+ return [];
+ }
+
+ reverseInplace(qmatch);
+ qmatch.expr = mapExpr(qmatch, function(m) { return m.expr; });
+ }
+
+ reverseInplace(match);
+
+ if (p == -1) {
+ return match;
+
+ } else {
+ return [];
+ }
+}
+
+function xpathTokenPrecedence(tag) {
+ return tag.prec || 2;
+}
+
+function xpathGrammarPrecedence(frame) {
+ var ret = 0;
+
+ if (frame.rule) { /* normal reduce */
+ if (frame.rule.length >= 3 && frame.rule[2] >= 0) {
+ ret = frame.rule[2];
+
+ } else {
+ for (var i = 0; i < frame.rule[1].length; ++i) {
+ var p = xpathTokenPrecedence(frame.rule[1][i]);
+ ret = Math.max(ret, p);
+ }
+ }
+ } else if (frame.tag) { /* TOKEN match */
+ ret = xpathTokenPrecedence(frame.tag);
+
+ } else if (frame.length) { /* Q_ match */
+ for (var j = 0; j < frame.length; ++j) {
+ var p = xpathGrammarPrecedence(frame[j]);
+ ret = Math.max(ret, p);
+ }
+ }
+
+ return ret;
+}
+
+function stackToString(stack) {
+ var ret = '';
+ for (var i = 0; i < stack.length; ++i) {
+ if (ret) {
+ ret += '\n';
+ }
+ ret += stack[i].tag.label;
+ }
+ return ret;
+}
+
+
+// XPath expression evaluation context. An XPath context consists of a
+// DOM node, a list of DOM nodes that contains this node, a number
+// that represents the position of the single node in the list, and a
+// current set of variable bindings. (See XPath spec.)
+//
+// The interface of the expression context:
+//
+// Constructor -- gets the node, its position, the node set it
+// belongs to, and a parent context as arguments. The parent context
+// is used to implement scoping rules for variables: if a variable
+// is not found in the current context, it is looked for in the
+// parent context, recursively. Except for node, all arguments have
+// default values: default position is 0, default node set is the
+// set that contains only the node, and the default parent is null.
+//
+// Notice that position starts at 0 at the outside interface;
+// inside XPath expressions this shows up as position()=1.
+//
+// clone() -- creates a new context with the current context as
+// parent. If passed as argument to clone(), the new context has a
+// different node, position, or node set. What is not passed is
+// inherited from the cloned context.
+//
+// setVariable(name, expr) -- binds given XPath expression to the
+// name.
+//
+// getVariable(name) -- what the name says.
+//
+// setNode(node, position) -- sets the context to the new node and
+// its corresponding position. Needed to implement scoping rules for
+// variables in XPath. (A variable is visible to all subsequent
+// siblings, not only to its children.)
+
+function ExprContext(node, position, nodelist, parent) {
+ this.node = node;
+ this.position = position || 0;
+ this.nodelist = nodelist || [ node ];
+ this.variables = {};
+ this.parent = parent || null;
+ this.root = parent ? parent.root : node.ownerDocument;
+}
+
+ExprContext.prototype.clone = function(node, position, nodelist) {
+ return new
+ ExprContext(node || this.node,
+ typeof position != 'undefined' ? position : this.position,
+ nodelist || this.nodelist, this);
+};
+
+ExprContext.prototype.setVariable = function(name, value) {
+ this.variables[name] = value;
+};
+
+ExprContext.prototype.getVariable = function(name) {
+ if (typeof this.variables[name] != 'undefined') {
+ return this.variables[name];
+
+ } else if (this.parent) {
+ return this.parent.getVariable(name);
+
+ } else {
+ return null;
+ }
+}
+
+ExprContext.prototype.setNode = function(node, position) {
+ this.node = node;
+ this.position = position;
+}
+
+
+// XPath expression values. They are what XPath expressions evaluate
+// to. Strangely, the different value types are not specified in the
+// XPath syntax, but only in the semantics, so they don't show up as
+// nonterminals in the grammar. Yet, some expressions are required to
+// evaluate to particular types, and not every type can be coerced
+// into every other type. Although the types of XPath values are
+// similar to the types present in JavaScript, the type coercion rules
+// are a bit peculiar, so we explicitly model XPath types instead of
+// mapping them onto JavaScript types. (See XPath spec.)
+//
+// The four types are:
+//
+// StringValue
+//
+// NumberValue
+//
+// BooleanValue
+//
+// NodeSetValue
+//
+// The common interface of the value classes consists of methods that
+// implement the XPath type coercion rules:
+//
+// stringValue() -- returns the value as a JavaScript String,
+//
+// numberValue() -- returns the value as a JavaScript Number,
+//
+// booleanValue() -- returns the value as a JavaScript Boolean,
+//
+// nodeSetValue() -- returns the value as a JavaScript Array of DOM
+// Node objects.
+//
+
+function StringValue(value) {
+ this.value = value;
+ this.type = 'string';
+}
+
+StringValue.prototype.stringValue = function() {
+ return this.value;
+}
+
+StringValue.prototype.booleanValue = function() {
+ return this.value.length > 0;
+}
+
+StringValue.prototype.numberValue = function() {
+ return this.value - 0;
+}
+
+StringValue.prototype.nodeSetValue = function() {
+ throw this + ' ' + Error().stack;
+}
+
+function BooleanValue(value) {
+ this.value = value;
+ this.type = 'boolean';
+}
+
+BooleanValue.prototype.stringValue = function() {
+ return '' + this.value;
+}
+
+BooleanValue.prototype.booleanValue = function() {
+ return this.value;
+}
+
+BooleanValue.prototype.numberValue = function() {
+ return this.value ? 1 : 0;
+}
+
+BooleanValue.prototype.nodeSetValue = function() {
+ throw this + ' ' + Error().stack;
+}
+
+function NumberValue(value) {
+ this.value = value;
+ this.type = 'number';
+}
+
+NumberValue.prototype.stringValue = function() {
+ return '' + this.value;
+}
+
+NumberValue.prototype.booleanValue = function() {
+ return !!this.value;
+}
+
+NumberValue.prototype.numberValue = function() {
+ return this.value - 0;
+}
+
+NumberValue.prototype.nodeSetValue = function() {
+ throw this + ' ' + Error().stack;
+}
+
+function NodeSetValue(value) {
+ this.value = value;
+ this.type = 'node-set';
+}
+
+NodeSetValue.prototype.stringValue = function() {
+ if (this.value.length == 0) {
+ return '';
+ } else {
+ return xmlValue(this.value[0]);
+ }
+}
+
+NodeSetValue.prototype.booleanValue = function() {
+ return this.value.length > 0;
+}
+
+NodeSetValue.prototype.numberValue = function() {
+ return this.stringValue() - 0;
+}
+
+NodeSetValue.prototype.nodeSetValue = function() {
+ return this.value;
+};
+
+// XPath expressions. They are used as nodes in the parse tree and
+// possess an evaluate() method to compute an XPath value given an XPath
+// context. Expressions are returned from the parser. Teh set of
+// expression classes closely mirrors the set of non terminal symbols
+// in the grammar. Every non trivial nonterminal symbol has a
+// corresponding expression class.
+//
+// The common expression interface consists of the following methods:
+//
+// evaluate(context) -- evaluates the expression, returns a value.
+//
+// toString() -- returns the XPath text representation of the
+// expression (defined in xsltdebug.js).
+//
+// parseTree(indent) -- returns a parse tree representation of the
+// expression (defined in xsltdebug.js).
+
+function TokenExpr(m) {
+ this.value = m;
+}
+
+TokenExpr.prototype.evaluate = function() {
+ return new StringValue(this.value);
+};
+
+function LocationExpr() {
+ this.absolute = false;
+ this.steps = [];
+}
+
+LocationExpr.prototype.appendStep = function(s) {
+ this.steps.push(s);
+}
+
+LocationExpr.prototype.prependStep = function(s) {
+ var steps0 = this.steps;
+ this.steps = [ s ];
+ for (var i = 0; i < steps0.length; ++i) {
+ this.steps.push(steps0[i]);
+ }
+};
+
+LocationExpr.prototype.evaluate = function(ctx) {
+ var start;
+ if (this.absolute) {
+ start = ctx.root;
+
+ } else {
+ start = ctx.node;
+ }
+
+ var nodes = [];
+ xPathStep(nodes, this.steps, 0, start, ctx);
+ return new NodeSetValue(nodes);
+};
+
+function xPathStep(nodes, steps, step, input, ctx) {
+ var s = steps[step];
+ var ctx2 = ctx.clone(input);
+ var nodelist = s.evaluate(ctx2).nodeSetValue();
+
+ for (var i = 0; i < nodelist.length; ++i) {
+ if (step == steps.length - 1) {
+ nodes.push(nodelist[i]);
+ } else {
+ xPathStep(nodes, steps, step + 1, nodelist[i], ctx);
+ }
+ }
+}
+
+function StepExpr(axis, nodetest, predicate) {
+ this.axis = axis;
+ this.nodetest = nodetest;
+ this.predicate = predicate || [];
+}
+
+StepExpr.prototype.appendPredicate = function(p) {
+ this.predicate.push(p);
+}
+
+StepExpr.prototype.evaluate = function(ctx) {
+ var input = ctx.node;
+ var nodelist = [];
+
+ // NOTE(mesch): When this was a switch() statement, it didn't work
+ // in Safari/2.0. Not sure why though; it resulted in the JavaScript
+ // console output "undefined" (without any line number or so).
+
+ if (this.axis == xpathAxis.ANCESTOR_OR_SELF) {
+ nodelist.push(input);
+ for (var n = input.parentNode; n; n = input.parentNode) {
+ nodelist.push(n);
+ }
+
+ } else if (this.axis == xpathAxis.ANCESTOR) {
+ for (var n = input.parentNode; n; n = input.parentNode) {
+ nodelist.push(n);
+ }
+
+ } else if (this.axis == xpathAxis.ATTRIBUTE) {
+ copyArray(nodelist, input.attributes);
+
+ } else if (this.axis == xpathAxis.CHILD) {
+ copyArray(nodelist, input.childNodes);
+
+ } else if (this.axis == xpathAxis.DESCENDANT_OR_SELF) {
+ nodelist.push(input);
+ xpathCollectDescendants(nodelist, input);
+
+ } else if (this.axis == xpathAxis.DESCENDANT) {
+ xpathCollectDescendants(nodelist, input);
+
+ } else if (this.axis == xpathAxis.FOLLOWING) {
+ for (var n = input.parentNode; n; n = n.parentNode) {
+ for (var nn = n.nextSibling; nn; nn = nn.nextSibling) {
+ nodelist.push(nn);
+ xpathCollectDescendants(nodelist, nn);
+ }
+ }
+
+ } else if (this.axis == xpathAxis.FOLLOWING_SIBLING) {
+ for (var n = input.nextSibling; n; n = input.nextSibling) {
+ nodelist.push(n);
+ }
+
+ } else if (this.axis == xpathAxis.NAMESPACE) {
+ alert('not implemented: axis namespace');
+
+ } else if (this.axis == xpathAxis.PARENT) {
+ if (input.parentNode) {
+ nodelist.push(input.parentNode);
+ }
+
+ } else if (this.axis == xpathAxis.PRECEDING) {
+ for (var n = input.parentNode; n; n = n.parentNode) {
+ for (var nn = n.previousSibling; nn; nn = nn.previousSibling) {
+ nodelist.push(nn);
+ xpathCollectDescendantsReverse(nodelist, nn);
+ }
+ }
+
+ } else if (this.axis == xpathAxis.PRECEDING_SIBLING) {
+ for (var n = input.previousSibling; n; n = input.previousSibling) {
+ nodelist.push(n);
+ }
+
+ } else if (this.axis == xpathAxis.SELF) {
+ nodelist.push(input);
+
+ } else {
+ throw 'ERROR -- NO SUCH AXIS: ' + this.axis;
+ }
+
+ // process node test
+ var nodelist0 = nodelist;
+ nodelist = [];
+ for (var i = 0; i < nodelist0.length; ++i) {
+ var n = nodelist0[i];
+ if (this.nodetest.evaluate(ctx.clone(n, i, nodelist0)).booleanValue()) {
+ nodelist.push(n);
+ }
+ }
+
+ // process predicates
+ for (var i = 0; i < this.predicate.length; ++i) {
+ var nodelist0 = nodelist;
+ nodelist = [];
+ for (var ii = 0; ii < nodelist0.length; ++ii) {
+ var n = nodelist0[ii];
+ if (this.predicate[i].evaluate(ctx.clone(n, ii, nodelist0)).booleanValue()) {
+ nodelist.push(n);
+ }
+ }
+ }
+
+ return new NodeSetValue(nodelist);
+};
+
+function NodeTestAny() {
+ this.value = new BooleanValue(true);
+}
+
+NodeTestAny.prototype.evaluate = function(ctx) {
+ return this.value;
+};
+
+function NodeTestElement() {}
+
+NodeTestElement.prototype.evaluate = function(ctx) {
+ return new BooleanValue(ctx.node.nodeType == DOM_ELEMENT_NODE);
+}
+
+function NodeTestText() {}
+
+NodeTestText.prototype.evaluate = function(ctx) {
+ return new BooleanValue(ctx.node.nodeType == DOM_TEXT_NODE);
+}
+
+function NodeTestComment() {}
+
+NodeTestComment.prototype.evaluate = function(ctx) {
+ return new BooleanValue(ctx.node.nodeType == DOM_COMMENT_NODE);
+}
+
+function NodeTestPI(target) {
+ this.target = target;
+}
+
+NodeTestPI.prototype.evaluate = function(ctx) {
+ return new
+ BooleanValue(ctx.node.nodeType == DOM_PROCESSING_INSTRUCTION_NODE &&
+ (!this.target || ctx.node.nodeName == this.target));
+}
+
+function NodeTestNC(nsprefix) {
+ this.regex = new RegExp("^" + nsprefix + ":");
+ this.nsprefix = nsprefix;
+}
+
+NodeTestNC.prototype.evaluate = function(ctx) {
+ var n = ctx.node;
+ return new BooleanValue(this.regex.match(n.nodeName));
+}
+
+function NodeTestName(name) {
+ this.name = name;
+}
+
+NodeTestName.prototype.evaluate = function(ctx) {
+ var n = ctx.node;
+ // NOTE (Patrick Lightbody): this change allows node selection to be case-insensitive
+ return new BooleanValue(n.nodeName.toUpperCase() == this.name.toUpperCase());
+}
+
+function PredicateExpr(expr) {
+ this.expr = expr;
+}
+
+PredicateExpr.prototype.evaluate = function(ctx) {
+ var v = this.expr.evaluate(ctx);
+ if (v.type == 'number') {
+ // NOTE(mesch): Internally, position is represented starting with
+ // 0, however in XPath position starts with 1. See functions
+ // position() and last().
+ return new BooleanValue(ctx.position == v.numberValue() - 1);
+ } else {
+ return new BooleanValue(v.booleanValue());
+ }
+};
+
+function FunctionCallExpr(name) {
+ this.name = name;
+ this.args = [];
+}
+
+FunctionCallExpr.prototype.appendArg = function(arg) {
+ this.args.push(arg);
+};
+
+FunctionCallExpr.prototype.evaluate = function(ctx) {
+ var fn = '' + this.name.value;
+ var f = this.xpathfunctions[fn];
+ if (f) {
+ return f.call(this, ctx);
+ } else {
+ Log.write('XPath NO SUCH FUNCTION ' + fn);
+ return new BooleanValue(false);
+ }
+};
+
+FunctionCallExpr.prototype.xpathfunctions = {
+ 'last': function(ctx) {
+ assert(this.args.length == 0);
+ // NOTE(mesch): XPath position starts at 1.
+ return new NumberValue(ctx.nodelist.length);
+ },
+
+ 'position': function(ctx) {
+ assert(this.args.length == 0);
+ // NOTE(mesch): XPath position starts at 1.
+ return new NumberValue(ctx.position + 1);
+ },
+
+ 'count': function(ctx) {
+ assert(this.args.length == 1);
+ var v = this.args[0].evaluate(ctx);
+ return new NumberValue(v.nodeSetValue().length);
+ },
+
+ 'id': function(ctx) {
+ assert(this.args.length == 1);
+ var e = this.args.evaluate(ctx);
+ var ret = [];
+ var ids;
+ if (e.type == 'node-set') {
+ ids = [];
+ for (var i = 0; i < e.length; ++i) {
+ var v = xmlValue(e[i]).split(/\s+/);
+ for (var ii = 0; ii < v.length; ++ii) {
+ ids.push(v[ii]);
+ }
+ }
+ } else {
+ ids = e.split(/\s+/);
+ }
+ var d = ctx.node.ownerDocument;
+ for (var i = 0; i < ids.length; ++i) {
+ var n = d.getElementById(ids[i]);
+ if (n) {
+ ret.push(n);
+ }
+ }
+ return new NodeSetValue(ret);
+ },
+
+ 'local-name': function(ctx) {
+ alert('not implmented yet: XPath function local-name()');
+ },
+
+ 'namespace-uri': function(ctx) {
+ alert('not implmented yet: XPath function namespace-uri()');
+ },
+
+ 'name': function(ctx) {
+ assert(this.args.length == 1 || this.args.length == 0);
+ var n;
+ if (this.args.length == 0) {
+ n = [ ctx.node ];
+ } else {
+ n = this.args[0].evaluate(ctx).nodeSetValue();
+ }
+
+ if (n.length == 0) {
+ return new StringValue('');
+ } else {
+ return new StringValue(n[0].nodeName);
+ }
+ },
+
+ 'string': function(ctx) {
+ assert(this.args.length == 1 || this.args.length == 0);
+ if (this.args.length == 0) {
+ return new StringValue(new NodeSetValue([ ctx.node ]).stringValue());
+ } else {
+ return new StringValue(this.args[0].evaluate(ctx).stringValue());
+ }
+ },
+
+ 'concat': function(ctx) {
+ var ret = '';
+ for (var i = 0; i < this.args.length; ++i) {
+ ret += this.args[i].evaluate(ctx).stringValue();
+ }
+ return new StringValue(ret);
+ },
+
+ 'starts-with': function(ctx) {
+ assert(this.args.length == 2);
+ var s0 = this.args[0].evaluate(ctx).stringValue();
+ var s1 = this.args[1].evaluate(ctx).stringValue();
+ return new BooleanValue(s0.indexOf(s1) == 0);
+ },
+
+ 'contains': function(ctx) {
+ assert(this.args.length == 2);
+ var s0 = this.args[0].evaluate(ctx).stringValue();
+ var s1 = this.args[1].evaluate(ctx).stringValue();
+ return new BooleanValue(s0.indexOf(s1) != -1);
+ },
+
+ 'substring-before': function(ctx) {
+ assert(this.args.length == 2);
+ var s0 = this.args[0].evaluate(ctx).stringValue();
+ var s1 = this.args[1].evaluate(ctx).stringValue();
+ var i = s0.indexOf(s1);
+ var ret;
+ if (i == -1) {
+ ret = '';
+ } else {
+ ret = s0.substr(0,i);
+ }
+ return new StringValue(ret);
+ },
+
+ 'substring-after': function(ctx) {
+ assert(this.args.length == 2);
+ var s0 = this.args[0].evaluate(ctx).stringValue();
+ var s1 = this.args[1].evaluate(ctx).stringValue();
+ var i = s0.indexOf(s1);
+ var ret;
+ if (i == -1) {
+ ret = '';
+ } else {
+ ret = s0.substr(i + s1.length);
+ }
+ return new StringValue(ret);
+ },
+
+ 'substring': function(ctx) {
+ // NOTE: XPath defines the position of the first character in a
+ // string to be 1, in JavaScript this is 0 ([XPATH] Section 4.2).
+ assert(this.args.length == 2 || this.args.length == 3);
+ var s0 = this.args[0].evaluate(ctx).stringValue();
+ var s1 = this.args[1].evaluate(ctx).numberValue();
+ var ret;
+ if (this.args.length == 2) {
+ var i1 = Math.max(0, Math.round(s1) - 1);
+ ret = s0.substr(i1);
+
+ } else {
+ var s2 = this.args[2].evaluate(ctx).numberValue();
+ var i0 = Math.round(s1) - 1;
+ var i1 = Math.max(0, i0);
+ var i2 = Math.round(s2) - Math.max(0, -i0);
+ ret = s0.substr(i1, i2);
+ }
+ return new StringValue(ret);
+ },
+
+ 'string-length': function(ctx) {
+ var s;
+ if (this.args.length > 0) {
+ s = this.args[0].evaluate(ctx).stringValue();
+ } else {
+ s = new NodeSetValue([ ctx.node ]).stringValue();
+ }
+ return new NumberValue(s.length);
+ },
+
+ 'normalize-space': function(ctx) {
+ var s;
+ if (this.args.length > 0) {
+ s = this.args[0].evaluate(ctx).stringValue();
+ } else {
+ s = new NodeSetValue([ ctx.node ]).stringValue();
+ }
+ s = s.replace(/^\s*/,'').replace(/\s*$/,'').replace(/\s+/g, ' ');
+ return new StringValue(s);
+ },
+
+ 'translate': function(ctx) {
+ assert(this.args.length == 3);
+ var s0 = this.args[0].evaluate(ctx).stringValue();
+ var s1 = this.args[1].evaluate(ctx).stringValue();
+ var s2 = this.args[2].evaluate(ctx).stringValue();
+
+ for (var i = 0; i < s1.length; ++i) {
+ s0 = s0.replace(new RegExp(s1.charAt(i), 'g'), s2.charAt(i));
+ }
+ return new StringValue(s0);
+ },
+
+ 'boolean': function(ctx) {
+ assert(this.args.length == 1);
+ return new BooleanValue(this.args[0].evaluate(ctx).booleanValue());
+ },
+
+ 'not': function(ctx) {
+ assert(this.args.length == 1);
+ var ret = !this.args[0].evaluate(ctx).booleanValue();
+ return new BooleanValue(ret);
+ },
+
+ 'true': function(ctx) {
+ assert(this.args.length == 0);
+ return new BooleanValue(true);
+ },
+
+ 'false': function(ctx) {
+ assert(this.args.length == 0);
+ return new BooleanValue(false);
+ },
+
+ 'lang': function(ctx) {
+ assert(this.args.length == 1);
+ var lang = this.args[0].evaluate(ctx).stringValue();
+ var xmllang;
+ var n = ctx.node;
+ while (n && n != n.parentNode /* just in case ... */) {
+ xmllang = n.getAttribute('xml:lang');
+ if (xmllang) {
+ break;
+ }
+ n = n.parentNode;
+ }
+ if (!xmllang) {
+ return new BooleanValue(false);
+ } else {
+ var re = new RegExp('^' + lang + '$', 'i');
+ return new BooleanValue(xmllang.match(re) ||
+ xmllang.replace(/_.*$/,'').match(re));
+ }
+ },
+
+ 'number': function(ctx) {
+ assert(this.args.length == 1 || this.args.length == 0);
+
+ if (this.args.length == 1) {
+ return new NumberValue(this.args[0].evaluate(ctx).numberValue());
+ } else {
+ return new NumberValue(new NodeSetValue([ ctx.node ]).numberValue());
+ }
+ },
+
+ 'sum': function(ctx) {
+ assert(this.args.length == 1);
+ var n = this.args[0].evaluate(ctx).nodeSetValue();
+ var sum = 0;
+ for (var i = 0; i < n.length; ++i) {
+ sum += xmlValue(n[i]) - 0;
+ }
+ return new NumberValue(sum);
+ },
+
+ 'floor': function(ctx) {
+ assert(this.args.length == 1);
+ var num = this.args[0].evaluate(ctx).numberValue();
+ return new NumberValue(Math.floor(num));
+ },
+
+ 'ceiling': function(ctx) {
+ assert(this.args.length == 1);
+ var num = this.args[0].evaluate(ctx).numberValue();
+ return new NumberValue(Math.ceil(num));
+ },
+
+ 'round': function(ctx) {
+ assert(this.args.length == 1);
+ var num = this.args[0].evaluate(ctx).numberValue();
+ return new NumberValue(Math.round(num));
+ },
+
+ // TODO(mesch): The following functions are custom. There is a
+ // standard that defines how to add functions, which should be
+ // applied here.
+
+ 'ext-join': function(ctx) {
+ assert(this.args.length == 2);
+ var nodes = this.args[0].evaluate(ctx).nodeSetValue();
+ var delim = this.args[1].evaluate(ctx).stringValue();
+ var ret = '';
+ for (var i = 0; i < nodes.length; ++i) {
+ if (ret) {
+ ret += delim;
+ }
+ ret += xmlValue(nodes[i]);
+ }
+ return new StringValue(ret);
+ },
+
+ // ext-if() evaluates and returns its second argument, if the
+ // boolean value of its first argument is true, otherwise it
+ // evaluates and returns its third argument.
+
+ 'ext-if': function(ctx) {
+ assert(this.args.length == 3);
+ if (this.args[0].evaluate(ctx).booleanValue()) {
+ return this.args[1].evaluate(ctx);
+ } else {
+ return this.args[2].evaluate(ctx);
+ }
+ },
+
+ 'ext-sprintf': function(ctx) {
+ assert(this.args.length >= 1);
+ var args = [];
+ for (var i = 0; i < this.args.length; ++i) {
+ args.push(this.args[i].evaluate(ctx).stringValue());
+ }
+ return new StringValue(sprintf.apply(null, args));
+ },
+
+ // ext-cardinal() evaluates its single argument as a number, and
+ // returns the current node that many times. It can be used in the
+ // select attribute to iterate over an integer range.
+
+ 'ext-cardinal': function(ctx) {
+ assert(this.args.length >= 1);
+ var c = this.args[0].evaluate(ctx).numberValue();
+ var ret = [];
+ for (var i = 0; i < c; ++i) {
+ ret.push(ctx.node);
+ }
+ return new NodeSetValue(ret);
+ }
+};
+
+function UnionExpr(expr1, expr2) {
+ this.expr1 = expr1;
+ this.expr2 = expr2;
+}
+
+UnionExpr.prototype.evaluate = function(ctx) {
+ var nodes1 = this.expr1.evaluate(ctx).nodeSetValue();
+ var nodes2 = this.expr2.evaluate(ctx).nodeSetValue();
+ var I1 = nodes1.length;
+ for (var i2 = 0; i2 < nodes2.length; ++i2) {
+ for (var i1 = 0; i1 < I1; ++i1) {
+ if (nodes1[i1] == nodes2[i2]) {
+ // break inner loop and continue outer loop, labels confuse
+ // the js compiler, so we don't use them here.
+ i1 = I1;
+ }
+ }
+ nodes1.push(nodes2[i2]);
+ }
+ return new NodeSetValue(nodes2);
+};
+
+function PathExpr(filter, rel) {
+ this.filter = filter;
+ this.rel = rel;
+}
+
+PathExpr.prototype.evaluate = function(ctx) {
+ var nodes = this.filter.evaluate(ctx).nodeSetValue();
+ var nodes1 = [];
+ for (var i = 0; i < nodes.length; ++i) {
+ var nodes0 = this.rel.evaluate(ctx.clone(nodes[i], i, nodes)).nodeSetValue();
+ for (var ii = 0; ii < nodes0.length; ++ii) {
+ nodes1.push(nodes0[ii]);
+ }
+ }
+ return new NodeSetValue(nodes1);
+};
+
+function FilterExpr(expr, predicate) {
+ this.expr = expr;
+ this.predicate = predicate;
+}
+
+FilterExpr.prototype.evaluate = function(ctx) {
+ var nodes = this.expr.evaluate(ctx).nodeSetValue();
+ for (var i = 0; i < this.predicate.length; ++i) {
+ var nodes0 = nodes;
+ nodes = [];
+ for (var j = 0; j < nodes0.length; ++j) {
+ var n = nodes0[j];
+ if (this.predicate[i].evaluate(ctx.clone(n, j, nodes0)).booleanValue()) {
+ nodes.push(n);
+ }
+ }
+ }
+
+ return new NodeSetValue(nodes);
+}
+
+function UnaryMinusExpr(expr) {
+ this.expr = expr;
+}
+
+UnaryMinusExpr.prototype.evaluate = function(ctx) {
+ return new NumberValue(-this.expr.evaluate(ctx).numberValue());
+};
+
+function BinaryExpr(expr1, op, expr2) {
+ this.expr1 = expr1;
+ this.expr2 = expr2;
+ this.op = op;
+}
+
+BinaryExpr.prototype.evaluate = function(ctx) {
+ var ret;
+ switch (this.op.value) {
+ case 'or':
+ ret = new BooleanValue(this.expr1.evaluate(ctx).booleanValue() ||
+ this.expr2.evaluate(ctx).booleanValue());
+ break;
+
+ case 'and':
+ ret = new BooleanValue(this.expr1.evaluate(ctx).booleanValue() &&
+ this.expr2.evaluate(ctx).booleanValue());
+ break;
+
+ case '+':
+ ret = new NumberValue(this.expr1.evaluate(ctx).numberValue() +
+ this.expr2.evaluate(ctx).numberValue());
+ break;
+
+ case '-':
+ ret = new NumberValue(this.expr1.evaluate(ctx).numberValue() -
+ this.expr2.evaluate(ctx).numberValue());
+ break;
+
+ case '*':
+ ret = new NumberValue(this.expr1.evaluate(ctx).numberValue() *
+ this.expr2.evaluate(ctx).numberValue());
+ break;
+
+ case 'mod':
+ ret = new NumberValue(this.expr1.evaluate(ctx).numberValue() %
+ this.expr2.evaluate(ctx).numberValue());
+ break;
+
+ case 'div':
+ ret = new NumberValue(this.expr1.evaluate(ctx).numberValue() /
+ this.expr2.evaluate(ctx).numberValue());
+ break;
+
+ case '=':
+ ret = this.compare(ctx, function(x1, x2) { return x1 == x2; });
+ break;
+
+ case '!=':
+ ret = this.compare(ctx, function(x1, x2) { return x1 != x2; });
+ break;
+
+ case '<':
+ ret = this.compare(ctx, function(x1, x2) { return x1 < x2; });
+ break;
+
+ case '<=':
+ ret = this.compare(ctx, function(x1, x2) { return x1 <= x2; });
+ break;
+
+ case '>':
+ ret = this.compare(ctx, function(x1, x2) { return x1 > x2; });
+ break;
+
+ case '>=':
+ ret = this.compare(ctx, function(x1, x2) { return x1 >= x2; });
+ break;
+
+ default:
+ alert('BinaryExpr.evaluate: ' + this.op.value);
+ }
+ return ret;
+};
+
+BinaryExpr.prototype.compare = function(ctx, cmp) {
+ var v1 = this.expr1.evaluate(ctx);
+ var v2 = this.expr2.evaluate(ctx);
+
+ var ret;
+ if (v1.type == 'node-set' && v2.type == 'node-set') {
+ var n1 = v1.nodeSetValue();
+ var n2 = v2.nodeSetValue();
+ ret = false;
+ for (var i1 = 0; i1 < n1.length; ++i1) {
+ for (var i2 = 0; i2 < n2.length; ++i2) {
+ if (cmp(xmlValue(n1[i1]), xmlValue(n2[i2]))) {
+ ret = true;
+ // Break outer loop. Labels confuse the jscompiler and we
+ // don't use them.
+ i2 = n2.length;
+ i1 = n1.length;
+ }
+ }
+ }
+
+ } else if (v1.type == 'node-set' || v2.type == 'node-set') {
+
+ if (v1.type == 'number') {
+ var s = v1.numberValue();
+ var n = v2.nodeSetValue();
+
+ ret = false;
+ for (var i = 0; i < n.length; ++i) {
+ var nn = xmlValue(n[i]) - 0;
+ if (cmp(s, nn)) {
+ ret = true;
+ break;
+ }
+ }
+
+ } else if (v2.type == 'number') {
+ var n = v1.nodeSetValue();
+ var s = v2.numberValue();
+
+ ret = false;
+ for (var i = 0; i < n.length; ++i) {
+ var nn = xmlValue(n[i]) - 0;
+ if (cmp(nn, s)) {
+ ret = true;
+ break;
+ }
+ }
+
+ } else if (v1.type == 'string') {
+ var s = v1.stringValue();
+ var n = v2.nodeSetValue();
+
+ ret = false;
+ for (var i = 0; i < n.length; ++i) {
+ var nn = xmlValue(n[i]);
+ if (cmp(s, nn)) {
+ ret = true;
+ break;
+ }
+ }
+
+ } else if (v2.type == 'string') {
+ var n = v1.nodeSetValue();
+ var s = v2.stringValue();
+
+ ret = false;
+ for (var i = 0; i < n.length; ++i) {
+ var nn = xmlValue(n[i]);
+ if (cmp(nn, s)) {
+ ret = true;
+ break;
+ }
+ }
+
+ } else {
+ ret = cmp(v1.booleanValue(), v2.booleanValue());
+ }
+
+ } else if (v1.type == 'boolean' || v2.type == 'boolean') {
+ ret = cmp(v1.booleanValue(), v2.booleanValue());
+
+ } else if (v1.type == 'number' || v2.type == 'number') {
+ ret = cmp(v1.numberValue(), v2.numberValue());
+
+ } else {
+ ret = cmp(v1.stringValue(), v2.stringValue());
+ }
+
+ return new BooleanValue(ret);
+}
+
+function LiteralExpr(value) {
+ this.value = value;
+}
+
+LiteralExpr.prototype.evaluate = function(ctx) {
+ return new StringValue(this.value);
+};
+
+function NumberExpr(value) {
+ this.value = value;
+}
+
+NumberExpr.prototype.evaluate = function(ctx) {
+ return new NumberValue(this.value);
+};
+
+function VariableExpr(name) {
+ this.name = name;
+}
+
+VariableExpr.prototype.evaluate = function(ctx) {
+ return ctx.getVariable(this.name);
+}
+
+// Factory functions for semantic values (i.e. Expressions) of the
+// productions in the grammar. When a production is matched to reduce
+// the current parse state stack, the function is called with the
+// semantic values of the matched elements as arguments, and returns
+// another semantic value. The semantic value is a node of the parse
+// tree, an expression object with an evaluate() method that evaluates the
+// expression in an actual context. These factory functions are used
+// in the specification of the grammar rules, below.
+
+function makeTokenExpr(m) {
+ return new TokenExpr(m);
+}
+
+function passExpr(e) {
+ return e;
+}
+
+function makeLocationExpr1(slash, rel) {
+ rel.absolute = true;
+ return rel;
+}
+
+function makeLocationExpr2(dslash, rel) {
+ rel.absolute = true;
+ rel.prependStep(makeAbbrevStep(dslash.value));
+ return rel;
+}
+
+function makeLocationExpr3(slash) {
+ var ret = new LocationExpr();
+ ret.appendStep(makeAbbrevStep('.'));
+ ret.absolute = true;
+ return ret;
+}
+
+function makeLocationExpr4(dslash) {
+ var ret = new LocationExpr();
+ ret.absolute = true;
+ ret.appendStep(makeAbbrevStep(dslash.value));
+ return ret;
+}
+
+function makeLocationExpr5(step) {
+ var ret = new LocationExpr();
+ ret.appendStep(step);
+ return ret;
+}
+
+function makeLocationExpr6(rel, slash, step) {
+ rel.appendStep(step);
+ return rel;
+}
+
+function makeLocationExpr7(rel, dslash, step) {
+ rel.appendStep(makeAbbrevStep(dslash.value));
+ return rel;
+}
+
+function makeStepExpr1(dot) {
+ return makeAbbrevStep(dot.value);
+}
+
+function makeStepExpr2(ddot) {
+ return makeAbbrevStep(ddot.value);
+}
+
+function makeStepExpr3(axisname, axis, nodetest) {
+ return new StepExpr(axisname.value, nodetest);
+}
+
+function makeStepExpr4(at, nodetest) {
+ return new StepExpr('attribute', nodetest);
+}
+
+function makeStepExpr5(nodetest) {
+ return new StepExpr('child', nodetest);
+}
+
+function makeStepExpr6(step, predicate) {
+ step.appendPredicate(predicate);
+ return step;
+}
+
+function makeAbbrevStep(abbrev) {
+ switch (abbrev) {
+ case '//':
+ return new StepExpr('descendant-or-self', new NodeTestAny);
+
+ case '.':
+ return new StepExpr('self', new NodeTestAny);
+
+ case '..':
+ return new StepExpr('parent', new NodeTestAny);
+ }
+}
+
+function makeNodeTestExpr1(asterisk) {
+ return new NodeTestElement;
+}
+
+function makeNodeTestExpr2(ncname, colon, asterisk) {
+ return new NodeTestNC(ncname.value);
+}
+
+function makeNodeTestExpr3(qname) {
+ return new NodeTestName(qname.value);
+}
+
+function makeNodeTestExpr4(typeo, parenc) {
+ var type = typeo.value.replace(/\s*\($/, '');
+ switch(type) {
+ case 'node':
+ return new NodeTestAny;
+
+ case 'text':
+ return new NodeTestText;
+
+ case 'comment':
+ return new NodeTestComment;
+
+ case 'processing-instruction':
+ return new NodeTestPI;
+ }
+}
+
+function makeNodeTestExpr5(typeo, target, parenc) {
+ var type = typeo.replace(/\s*\($/, '');
+ if (type != 'processing-instruction') {
+ throw type + ' ' + Error().stack;
+ }
+ return new NodeTestPI(target.value);
+}
+
+function makePredicateExpr(pareno, expr, parenc) {
+ return new PredicateExpr(expr);
+}
+
+function makePrimaryExpr(pareno, expr, parenc) {
+ return expr;
+}
+
+function makeFunctionCallExpr1(name, pareno, parenc) {
+ return new FunctionCallExpr(name);
+}
+
+function makeFunctionCallExpr2(name, pareno, arg1, args, parenc) {
+ var ret = new FunctionCallExpr(name);
+ ret.appendArg(arg1);
+ for (var i = 0; i < args.length; ++i) {
+ ret.appendArg(args[i]);
+ }
+ return ret;
+}
+
+function makeArgumentExpr(comma, expr) {
+ return expr;
+}
+
+function makeUnionExpr(expr1, pipe, expr2) {
+ return new UnionExpr(expr1, expr2);
+}
+
+function makePathExpr1(filter, slash, rel) {
+ return new PathExpr(filter, rel);
+}
+
+function makePathExpr2(filter, dslash, rel) {
+ rel.prependStep(makeAbbrevStep(dslash.value));
+ return new PathExpr(filter, rel);
+}
+
+function makeFilterExpr(expr, predicates) {
+ if (predicates.length > 0) {
+ return new FilterExpr(expr, predicates);
+ } else {
+ return expr;
+ }
+}
+
+function makeUnaryMinusExpr(minus, expr) {
+ return new UnaryMinusExpr(expr);
+}
+
+function makeBinaryExpr(expr1, op, expr2) {
+ return new BinaryExpr(expr1, op, expr2);
+}
+
+function makeLiteralExpr(token) {
+ // remove quotes from the parsed value:
+ var value = token.value.substring(1, token.value.length - 1);
+ return new LiteralExpr(value);
+}
+
+function makeNumberExpr(token) {
+ return new NumberExpr(token.value);
+}
+
+function makeVariableReference(dollar, name) {
+ return new VariableExpr(name.value);
+}
+
+// Used before parsing for optimization of common simple cases. See
+// the begin of xpathParse() for which they are.
+function makeSimpleExpr(expr) {
+ if (expr.charAt(0) == '$') {
+ return new VariableExpr(expr.substr(1));
+ } else if (expr.charAt(0) == '@') {
+ var a = new NodeTestName(expr.substr(1));
+ var b = new StepExpr('attribute', a);
+ var c = new LocationExpr();
+ c.appendStep(b);
+ return c;
+ } else if (expr.match(/^[0-9]+$/)) {
+ return new NumberExpr(expr);
+ } else {
+ var a = new NodeTestName(expr);
+ var b = new StepExpr('child', a);
+ var c = new LocationExpr();
+ c.appendStep(b);
+ return c;
+ }
+}
+
+function makeSimpleExpr2(expr) {
+ var steps = expr.split('/');
+ var c = new LocationExpr();
+ for (var i in steps) {
+ var a = new NodeTestName(steps[i]);
+ var b = new StepExpr('child', a);
+ c.appendStep(b);
+ }
+ return c;
+}
+
+// The axes of XPath expressions.
+
+var xpathAxis = {
+ ANCESTOR_OR_SELF: 'ancestor-or-self',
+ ANCESTOR: 'ancestor',
+ ATTRIBUTE: 'attribute',
+ CHILD: 'child',
+ DESCENDANT_OR_SELF: 'descendant-or-self',
+ DESCENDANT: 'descendant',
+ FOLLOWING_SIBLING: 'following-sibling',
+ FOLLOWING: 'following',
+ NAMESPACE: 'namespace',
+ PARENT: 'parent',
+ PRECEDING_SIBLING: 'preceding-sibling',
+ PRECEDING: 'preceding',
+ SELF: 'self'
+};
+
+var xpathAxesRe = [
+ xpathAxis.ANCESTOR_OR_SELF,
+ xpathAxis.ANCESTOR,
+ xpathAxis.ATTRIBUTE,
+ xpathAxis.CHILD,
+ xpathAxis.DESCENDANT_OR_SELF,
+ xpathAxis.DESCENDANT,
+ xpathAxis.FOLLOWING_SIBLING,
+ xpathAxis.FOLLOWING,
+ xpathAxis.NAMESPACE,
+ xpathAxis.PARENT,
+ xpathAxis.PRECEDING_SIBLING,
+ xpathAxis.PRECEDING,
+ xpathAxis.SELF
+].join('|');
+
+
+// The tokens of the language. The label property is just used for
+// generating debug output. The prec property is the precedence used
+// for shift/reduce resolution. Default precedence is 0 as a lookahead
+// token and 2 on the stack. TODO(mesch): this is certainly not
+// necessary and too complicated. Simplify this!
+
+// NOTE: tabular formatting is the big exception, but here it should
+// be OK.
+
+var TOK_PIPE = { label: "|", prec: 17, re: new RegExp("^\\|") };
+var TOK_DSLASH = { label: "//", prec: 19, re: new RegExp("^//") };
+var TOK_SLASH = { label: "/", prec: 30, re: new RegExp("^/") };
+var TOK_AXIS = { label: "::", prec: 20, re: new RegExp("^::") };
+var TOK_COLON = { label: ":", prec: 1000, re: new RegExp("^:") };
+var TOK_AXISNAME = { label: "[axis]", re: new RegExp('^(' + xpathAxesRe + ')') };
+var TOK_PARENO = { label: "(", prec: 34, re: new RegExp("^\\(") };
+var TOK_PARENC = { label: ")", re: new RegExp("^\\)") };
+var TOK_DDOT = { label: "..", prec: 34, re: new RegExp("^\\.\\.") };
+var TOK_DOT = { label: ".", prec: 34, re: new RegExp("^\\.") };
+var TOK_AT = { label: "@", prec: 34, re: new RegExp("^@") };
+
+var TOK_COMMA = { label: ",", re: new RegExp("^,") };
+
+var TOK_OR = { label: "or", prec: 10, re: new RegExp("^or\\b") };
+var TOK_AND = { label: "and", prec: 11, re: new RegExp("^and\\b") };
+var TOK_EQ = { label: "=", prec: 12, re: new RegExp("^=") };
+var TOK_NEQ = { label: "!=", prec: 12, re: new RegExp("^!=") };
+var TOK_GE = { label: ">=", prec: 13, re: new RegExp("^>=") };
+var TOK_GT = { label: ">", prec: 13, re: new RegExp("^>") };
+var TOK_LE = { label: "<=", prec: 13, re: new RegExp("^<=") };
+var TOK_LT = { label: "<", prec: 13, re: new RegExp("^<") };
+var TOK_PLUS = { label: "+", prec: 14, re: new RegExp("^\\+"), left: true };
+var TOK_MINUS = { label: "-", prec: 14, re: new RegExp("^\\-"), left: true };
+var TOK_DIV = { label: "div", prec: 15, re: new RegExp("^div\\b"), left: true };
+var TOK_MOD = { label: "mod", prec: 15, re: new RegExp("^mod\\b"), left: true };
+
+var TOK_BRACKO = { label: "[", prec: 32, re: new RegExp("^\\[") };
+var TOK_BRACKC = { label: "]", re: new RegExp("^\\]") };
+var TOK_DOLLAR = { label: "$", re: new RegExp("^\\$") };
+
+var TOK_NCNAME = { label: "[ncname]", re: new RegExp('^[a-z][-\\w]*','i') };
+
+var TOK_ASTERISK = { label: "*", prec: 15, re: new RegExp("^\\*"), left: true };
+var TOK_LITERALQ = { label: "[litq]", prec: 20, re: new RegExp("^'[^\\']*'") };
+var TOK_LITERALQQ = {
+ label: "[litqq]",
+ prec: 20,
+ re: new RegExp('^"[^\\"]*"')
+};
+
+var TOK_NUMBER = {
+ label: "[number]",
+ prec: 35,
+ re: new RegExp('^\\d+(\\.\\d*)?') };
+
+var TOK_QNAME = {
+ label: "[qname]",
+ re: new RegExp('^([a-z][-\\w]*:)?[a-z][-\\w]*','i')
+};
+
+var TOK_NODEO = {
+ label: "[nodetest-start]",
+ re: new RegExp('^(processing-instruction|comment|text|node)\\(')
+};
+
+// The table of the tokens of our grammar, used by the lexer: first
+// column the tag, second column a regexp to recognize it in the
+// input, third column the precedence of the token, fourth column a
+// factory function for the semantic value of the token.
+//
+// NOTE: order of this list is important, because the first match
+// counts. Cf. DDOT and DOT, and AXIS and COLON.
+
+var xpathTokenRules = [
+ TOK_DSLASH,
+ TOK_SLASH,
+ TOK_DDOT,
+ TOK_DOT,
+ TOK_AXIS,
+ TOK_COLON,
+ TOK_AXISNAME,
+ TOK_NODEO,
+ TOK_PARENO,
+ TOK_PARENC,
+ TOK_BRACKO,
+ TOK_BRACKC,
+ TOK_AT,
+ TOK_COMMA,
+ TOK_OR,
+ TOK_AND,
+ TOK_NEQ,
+ TOK_EQ,
+ TOK_GE,
+ TOK_GT,
+ TOK_LE,
+ TOK_LT,
+ TOK_PLUS,
+ TOK_MINUS,
+ TOK_ASTERISK,
+ TOK_PIPE,
+ TOK_MOD,
+ TOK_DIV,
+ TOK_LITERALQ,
+ TOK_LITERALQQ,
+ TOK_NUMBER,
+ TOK_QNAME,
+ TOK_NCNAME,
+ TOK_DOLLAR
+];
+
+// All the nonterminals of the grammar. The nonterminal objects are
+// identified by object identity; the labels are used in the debug
+// output only.
+var XPathLocationPath = { label: "LocationPath" };
+var XPathRelativeLocationPath = { label: "RelativeLocationPath" };
+var XPathAbsoluteLocationPath = { label: "AbsoluteLocationPath" };
+var XPathStep = { label: "Step" };
+var XPathNodeTest = { label: "NodeTest" };
+var XPathPredicate = { label: "Predicate" };
+var XPathLiteral = { label: "Literal" };
+var XPathExpr = { label: "Expr" };
+var XPathPrimaryExpr = { label: "PrimaryExpr" };
+var XPathVariableReference = { label: "Variablereference" };
+var XPathNumber = { label: "Number" };
+var XPathFunctionCall = { label: "FunctionCall" };
+var XPathArgumentRemainder = { label: "ArgumentRemainder" };
+var XPathPathExpr = { label: "PathExpr" };
+var XPathUnionExpr = { label: "UnionExpr" };
+var XPathFilterExpr = { label: "FilterExpr" };
+var XPathDigits = { label: "Digits" };
+
+var xpathNonTerminals = [
+ XPathLocationPath,
+ XPathRelativeLocationPath,
+ XPathAbsoluteLocationPath,
+ XPathStep,
+ XPathNodeTest,
+ XPathPredicate,
+ XPathLiteral,
+ XPathExpr,
+ XPathPrimaryExpr,
+ XPathVariableReference,
+ XPathNumber,
+ XPathFunctionCall,
+ XPathArgumentRemainder,
+ XPathPathExpr,
+ XPathUnionExpr,
+ XPathFilterExpr,
+ XPathDigits
+];
+
+// Quantifiers that are used in the productions of the grammar.
+var Q_01 = { label: "?" };
+var Q_MM = { label: "*" };
+var Q_1M = { label: "+" };
+
+// Tag for left associativity (right assoc is implied by undefined).
+var ASSOC_LEFT = true;
+
+// The productions of the grammar. Columns of the table:
+//
+// - target nonterminal,
+// - pattern,
+// - precedence,
+// - semantic value factory
+//
+// The semantic value factory is a function that receives parse tree
+// nodes from the stack frames of the matched symbols as arguments and
+// returns an a node of the parse tree. The node is stored in the top
+// stack frame along with the target object of the rule. The node in
+// the parse tree is an expression object that has an evaluate() method
+// and thus evaluates XPath expressions.
+//
+// The precedence is used to decide between reducing and shifting by
+// comparing the precendence of the rule that is candidate for
+// reducing with the precedence of the look ahead token. Precedence of
+// -1 means that the precedence of the tokens in the pattern is used
+// instead. TODO: It shouldn't be necessary to explicitly assign
+// precedences to rules.
+
+var xpathGrammarRules =
+ [
+ [ XPathLocationPath, [ XPathRelativeLocationPath ], 18,
+ passExpr ],
+ [ XPathLocationPath, [ XPathAbsoluteLocationPath ], 18,
+ passExpr ],
+
+ [ XPathAbsoluteLocationPath, [ TOK_SLASH, XPathRelativeLocationPath ], 18,
+ makeLocationExpr1 ],
+ [ XPathAbsoluteLocationPath, [ TOK_DSLASH, XPathRelativeLocationPath ], 18,
+ makeLocationExpr2 ],
+
+ [ XPathAbsoluteLocationPath, [ TOK_SLASH ], 0,
+ makeLocationExpr3 ],
+ [ XPathAbsoluteLocationPath, [ TOK_DSLASH ], 0,
+ makeLocationExpr4 ],
+
+ [ XPathRelativeLocationPath, [ XPathStep ], 31,
+ makeLocationExpr5 ],
+ [ XPathRelativeLocationPath,
+ [ XPathRelativeLocationPath, TOK_SLASH, XPathStep ], 31,
+ makeLocationExpr6 ],
+ [ XPathRelativeLocationPath,
+ [ XPathRelativeLocationPath, TOK_DSLASH, XPathStep ], 31,
+ makeLocationExpr7 ],
+
+ [ XPathStep, [ TOK_DOT ], 33,
+ makeStepExpr1 ],
+ [ XPathStep, [ TOK_DDOT ], 33,
+ makeStepExpr2 ],
+ [ XPathStep,
+ [ TOK_AXISNAME, TOK_AXIS, XPathNodeTest ], 33,
+ makeStepExpr3 ],
+ [ XPathStep, [ TOK_AT, XPathNodeTest ], 33,
+ makeStepExpr4 ],
+ [ XPathStep, [ XPathNodeTest ], 33,
+ makeStepExpr5 ],
+ [ XPathStep, [ XPathStep, XPathPredicate ], 33,
+ makeStepExpr6 ],
+
+ [ XPathNodeTest, [ TOK_ASTERISK ], 33,
+ makeNodeTestExpr1 ],
+ [ XPathNodeTest, [ TOK_NCNAME, TOK_COLON, TOK_ASTERISK ], 33,
+ makeNodeTestExpr2 ],
+ [ XPathNodeTest, [ TOK_QNAME ], 33,
+ makeNodeTestExpr3 ],
+ [ XPathNodeTest, [ TOK_NODEO, TOK_PARENC ], 33,
+ makeNodeTestExpr4 ],
+ [ XPathNodeTest, [ TOK_NODEO, XPathLiteral, TOK_PARENC ], 33,
+ makeNodeTestExpr5 ],
+
+ [ XPathPredicate, [ TOK_BRACKO, XPathExpr, TOK_BRACKC ], 33,
+ makePredicateExpr ],
+
+ [ XPathPrimaryExpr, [ XPathVariableReference ], 33,
+ passExpr ],
+ [ XPathPrimaryExpr, [ TOK_PARENO, XPathExpr, TOK_PARENC ], 33,
+ makePrimaryExpr ],
+ [ XPathPrimaryExpr, [ XPathLiteral ], 30,
+ passExpr ],
+ [ XPathPrimaryExpr, [ XPathNumber ], 30,
+ passExpr ],
+ [ XPathPrimaryExpr, [ XPathFunctionCall ], 30,
+ passExpr ],
+
+ [ XPathFunctionCall, [ TOK_QNAME, TOK_PARENO, TOK_PARENC ], -1,
+ makeFunctionCallExpr1 ],
+ [ XPathFunctionCall,
+ [ TOK_QNAME, TOK_PARENO, XPathExpr, XPathArgumentRemainder, Q_MM,
+ TOK_PARENC ], -1,
+ makeFunctionCallExpr2 ],
+ [ XPathArgumentRemainder, [ TOK_COMMA, XPathExpr ], -1,
+ makeArgumentExpr ],
+
+ [ XPathUnionExpr, [ XPathPathExpr ], 20,
+ passExpr ],
+ [ XPathUnionExpr, [ XPathUnionExpr, TOK_PIPE, XPathPathExpr ], 20,
+ makeUnionExpr ],
+
+ [ XPathPathExpr, [ XPathLocationPath ], 20,
+ passExpr ],
+ [ XPathPathExpr, [ XPathFilterExpr ], 19,
+ passExpr ],
+ [ XPathPathExpr,
+ [ XPathFilterExpr, TOK_SLASH, XPathRelativeLocationPath ], 20,
+ makePathExpr1 ],
+ [ XPathPathExpr,
+ [ XPathFilterExpr, TOK_DSLASH, XPathRelativeLocationPath ], 20,
+ makePathExpr2 ],
+
+ [ XPathFilterExpr, [ XPathPrimaryExpr, XPathPredicate, Q_MM ], 20,
+ makeFilterExpr ],
+
+ [ XPathExpr, [ XPathPrimaryExpr ], 16,
+ passExpr ],
+ [ XPathExpr, [ XPathUnionExpr ], 16,
+ passExpr ],
+
+ [ XPathExpr, [ TOK_MINUS, XPathExpr ], -1,
+ makeUnaryMinusExpr ],
+
+ [ XPathExpr, [ XPathExpr, TOK_OR, XPathExpr ], -1,
+ makeBinaryExpr ],
+ [ XPathExpr, [ XPathExpr, TOK_AND, XPathExpr ], -1,
+ makeBinaryExpr ],
+
+ [ XPathExpr, [ XPathExpr, TOK_EQ, XPathExpr ], -1,
+ makeBinaryExpr ],
+ [ XPathExpr, [ XPathExpr, TOK_NEQ, XPathExpr ], -1,
+ makeBinaryExpr ],
+
+ [ XPathExpr, [ XPathExpr, TOK_LT, XPathExpr ], -1,
+ makeBinaryExpr ],
+ [ XPathExpr, [ XPathExpr, TOK_LE, XPathExpr ], -1,
+ makeBinaryExpr ],
+ [ XPathExpr, [ XPathExpr, TOK_GT, XPathExpr ], -1,
+ makeBinaryExpr ],
+ [ XPathExpr, [ XPathExpr, TOK_GE, XPathExpr ], -1,
+ makeBinaryExpr ],
+
+ [ XPathExpr, [ XPathExpr, TOK_PLUS, XPathExpr ], -1,
+ makeBinaryExpr, ASSOC_LEFT ],
+ [ XPathExpr, [ XPathExpr, TOK_MINUS, XPathExpr ], -1,
+ makeBinaryExpr, ASSOC_LEFT ],
+
+ [ XPathExpr, [ XPathExpr, TOK_ASTERISK, XPathExpr ], -1,
+ makeBinaryExpr, ASSOC_LEFT ],
+ [ XPathExpr, [ XPathExpr, TOK_DIV, XPathExpr ], -1,
+ makeBinaryExpr, ASSOC_LEFT ],
+ [ XPathExpr, [ XPathExpr, TOK_MOD, XPathExpr ], -1,
+ makeBinaryExpr, ASSOC_LEFT ],
+
+ [ XPathLiteral, [ TOK_LITERALQ ], -1,
+ makeLiteralExpr ],
+ [ XPathLiteral, [ TOK_LITERALQQ ], -1,
+ makeLiteralExpr ],
+
+ [ XPathNumber, [ TOK_NUMBER ], -1,
+ makeNumberExpr ],
+
+ [ XPathVariableReference, [ TOK_DOLLAR, TOK_QNAME ], 200,
+ makeVariableReference ]
+ ];
+
+// That function computes some optimizations of the above data
+// structures and will be called right here. It merely takes the
+// counter variables out of the global scope.
+
+var xpathRules = [];
+
+function xpathParseInit() {
+ if (xpathRules.length) {
+ return;
+ }
+
+ // Some simple optimizations for the xpath expression parser: sort
+ // grammar rules descending by length, so that the longest match is
+ // first found.
+
+ xpathGrammarRules.sort(function(a,b) {
+ var la = a[1].length;
+ var lb = b[1].length;
+ if (la < lb) {
+ return 1;
+ } else if (la > lb) {
+ return -1;
+ } else {
+ return 0;
+ }
+ });
+
+ var k = 1;
+ for (var i = 0; i < xpathNonTerminals.length; ++i) {
+ xpathNonTerminals[i].key = k++;
+ }
+
+ for (i = 0; i < xpathTokenRules.length; ++i) {
+ xpathTokenRules[i].key = k++;
+ }
+
+ Log.write('XPath parse INIT: ' + k + ' rules');
+
+ // Another slight optimization: sort the rules into bins according
+ // to the last element (observing quantifiers), so we can restrict
+ // the match against the stack to the subest of rules that match the
+ // top of the stack.
+ //
+ // TODO(mesch): What we actually want is to compute states as in
+ // bison, so that we don't have to do any explicit and iterated
+ // match against the stack.
+
+ function push_(array, position, element) {
+ if (!array[position]) {
+ array[position] = [];
+ }
+ array[position].push(element);
+ }
+
+ for (i = 0; i < xpathGrammarRules.length; ++i) {
+ var rule = xpathGrammarRules[i];
+ var pattern = rule[1];
+
+ for (var j = pattern.length - 1; j >= 0; --j) {
+ if (pattern[j] == Q_1M) {
+ push_(xpathRules, pattern[j-1].key, rule);
+ break;
+
+ } else if (pattern[j] == Q_MM || pattern[j] == Q_01) {
+ push_(xpathRules, pattern[j-1].key, rule);
+ --j;
+
+ } else {
+ push_(xpathRules, pattern[j].key, rule);
+ break;
+ }
+ }
+ }
+
+ Log.write('XPath parse INIT: ' + xpathRules.length + ' rule bins');
+
+ var sum = 0;
+ mapExec(xpathRules, function(i) {
+ if (i) {
+ sum += i.length;
+ }
+ });
+
+ Log.write('XPath parse INIT: ' + (sum / xpathRules.length) + ' average bin size');
+}
+
+// Local utility functions that are used by the lexer or parser.
+
+function xpathCollectDescendants(nodelist, node) {
+ for (var n = node.firstChild; n; n = n.nextSibling) {
+ nodelist.push(n);
+ arguments.callee(nodelist, n);
+ }
+}
+
+function xpathCollectDescendantsReverse(nodelist, node) {
+ for (var n = node.lastChild; n; n = n.previousSibling) {
+ nodelist.push(n);
+ arguments.callee(nodelist, n);
+ }
+}
+
+
+// The entry point for the library: match an expression against a DOM
+// node. Returns an XPath value.
+function xpathDomEval(expr, node) {
+ var expr1 = xpathParse(expr);
+ var ret = expr1.evaluate(new ExprContext(node));
+ return ret;
+}
+
+// Utility function to sort a list of nodes. Used by xsltSort() and
+// nxslSelect().
+function xpathSort(input, sort) {
+ if (sort.length == 0) {
+ return;
+ }
+
+ var sortlist = [];
+
+ for (var i = 0; i < input.nodelist.length; ++i) {
+ var node = input.nodelist[i];
+ var sortitem = { node: node, key: [] };
+ var context = input.clone(node, 0, [ node ]);
+
+ for (var j = 0; j < sort.length; ++j) {
+ var s = sort[j];
+ var value = s.expr.evaluate(context);
+
+ var evalue;
+ if (s.type == 'text') {
+ evalue = value.stringValue();
+ } else if (s.type == 'number') {
+ evalue = value.numberValue();
+ }
+ sortitem.key.push({ value: evalue, order: s.order });
+ }
+
+ // Make the sort stable by adding a lowest priority sort by
+ // id. This is very convenient and furthermore required by the
+ // spec ([XSLT] - Section 10 Sorting).
+ sortitem.key.push({ value: i, order: 'ascending' });
+
+ sortlist.push(sortitem);
+ }
+
+ sortlist.sort(xpathSortByKey);
+
+ var nodes = [];
+ for (var i = 0; i < sortlist.length; ++i) {
+ nodes.push(sortlist[i].node);
+ }
+ input.nodelist = nodes;
+ input.setNode(nodes[0], 0);
+}
+
+
+// Sorts by all order criteria defined. According to the JavaScript
+// spec ([ECMA] Section 11.8.5), the compare operators compare strings
+// as strings and numbers as numbers.
+//
+// NOTE: In browsers which do not follow the spec, this breaks only in
+// the case that numbers should be sorted as strings, which is very
+// uncommon.
+
+function xpathSortByKey(v1, v2) {
+ // NOTE: Sort key vectors of different length never occur in
+ // xsltSort.
+
+ for (var i = 0; i < v1.key.length; ++i) {
+ var o = v1.key[i].order == 'descending' ? -1 : 1;
+ if (v1.key[i].value > v2.key[i].value) {
+ return +1 * o;
+ } else if (v1.key[i].value < v2.key[i].value) {
+ return -1 * o;
+ }
+ }
+
+ return 0;
+}
More information about the Checkins
mailing list