From 7c65b2f40ea9242260eac5a746863f5925423861 Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Sun, 22 Sep 2013 22:39:41 +0200 Subject: Phing: added target for phpunit+selenium Functional tests were using an old selenium RC version. Ported them to use phpunit + selenium; next: opensauce --- .../selenium/core/scripts/find_matching_child.js | 69 - .../test_tools/selenium/core/scripts/htmlutils.js | 842 ------- .../selenium/core/scripts/injection.html | 79 - .../selenium/core/scripts/injection_iframe.html | 7 - tests/test_tools/selenium/core/scripts/js2html.js | 70 - .../selenium/core/scripts/narcissus-defs.js | 175 -- .../selenium/core/scripts/narcissus-exec.js | 1054 --------- .../selenium/core/scripts/narcissus-parse.js | 1003 --------- .../selenium/core/scripts/prototype-1.4.0.js | 1781 --------------- tests/test_tools/selenium/core/scripts/se2html.js | 63 - .../selenium/core/scripts/selenium-api.js | 2329 -------------------- .../selenium/core/scripts/selenium-browserbot.js | 1946 ---------------- .../core/scripts/selenium-browserdetect.js | 142 -- .../core/scripts/selenium-commandhandlers.js | 375 ---- .../core/scripts/selenium-executionloop.js | 177 -- .../selenium/core/scripts/selenium-logging.js | 139 -- .../core/scripts/selenium-seleneserunner.js | 451 ---- .../selenium/core/scripts/selenium-testrunner.js | 1281 ----------- .../selenium/core/scripts/selenium-version.js | 5 - .../core/scripts/user-extensions.js.sample | 75 - .../test_tools/selenium/core/scripts/xmlextras.js | 153 -- 21 files changed, 12216 deletions(-) delete mode 100644 tests/test_tools/selenium/core/scripts/find_matching_child.js delete mode 100644 tests/test_tools/selenium/core/scripts/htmlutils.js delete mode 100644 tests/test_tools/selenium/core/scripts/injection.html delete mode 100644 tests/test_tools/selenium/core/scripts/injection_iframe.html delete mode 100644 tests/test_tools/selenium/core/scripts/js2html.js delete mode 100644 tests/test_tools/selenium/core/scripts/narcissus-defs.js delete mode 100644 tests/test_tools/selenium/core/scripts/narcissus-exec.js delete mode 100644 tests/test_tools/selenium/core/scripts/narcissus-parse.js delete mode 100644 tests/test_tools/selenium/core/scripts/prototype-1.4.0.js delete mode 100644 tests/test_tools/selenium/core/scripts/se2html.js delete mode 100644 tests/test_tools/selenium/core/scripts/selenium-api.js delete mode 100644 tests/test_tools/selenium/core/scripts/selenium-browserbot.js delete mode 100644 tests/test_tools/selenium/core/scripts/selenium-browserdetect.js delete mode 100644 tests/test_tools/selenium/core/scripts/selenium-commandhandlers.js delete mode 100644 tests/test_tools/selenium/core/scripts/selenium-executionloop.js delete mode 100644 tests/test_tools/selenium/core/scripts/selenium-logging.js delete mode 100644 tests/test_tools/selenium/core/scripts/selenium-seleneserunner.js delete mode 100644 tests/test_tools/selenium/core/scripts/selenium-testrunner.js delete mode 100644 tests/test_tools/selenium/core/scripts/selenium-version.js delete mode 100644 tests/test_tools/selenium/core/scripts/user-extensions.js.sample delete mode 100644 tests/test_tools/selenium/core/scripts/xmlextras.js (limited to 'tests/test_tools/selenium/core/scripts') diff --git a/tests/test_tools/selenium/core/scripts/find_matching_child.js b/tests/test_tools/selenium/core/scripts/find_matching_child.js deleted file mode 100644 index fbf35b75..00000000 --- a/tests/test_tools/selenium/core/scripts/find_matching_child.js +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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. - * - */ - -elementFindMatchingChildren = function(element, selector) { - var matches = []; - - var childCount = element.childNodes.length; - for (var i=0; i= "1.5"); - if (isRecentFirefox || browserVersion.isKonqueror || browserVersion.isSafari || browserVersion.isOpera) { - text = getTextContent(element); - } else if (element.textContent) { - text = element.textContent; - } else if (element.innerText) { - text = element.innerText; - } - - text = normalizeNewlines(text); - text = normalizeSpaces(text); - - return text.trim(); -} - -function getTextContent(element, preformatted) { - if (element.nodeType == 3 /*Node.TEXT_NODE*/) { - var text = element.data; - if (!preformatted) { - text = text.replace(/\n|\r|\t/g, " "); - } - return text; - } - if (element.nodeType == 1 /*Node.ELEMENT_NODE*/) { - var childrenPreformatted = preformatted || (element.tagName == "PRE"); - var text = ""; - for (var i = 0; i < element.childNodes.length; i++) { - var child = element.childNodes.item(i); - text += getTextContent(child, childrenPreformatted); - } - // Handle block elements that introduce newlines - // -- From HTML spec: - // - // - // TODO: should potentially introduce multiple newlines to separate blocks - if (element.tagName == "P" || element.tagName == "BR" || element.tagName == "HR" || element.tagName == "DIV") { - text += "\n"; - } - return text; - } - return ''; -} - -/** - * Convert all newlines to \m - */ -function normalizeNewlines(text) -{ - return text.replace(/\r\n|\r/g, "\n"); -} - -/** - * Replace multiple sequential spaces with a single space, and then convert   to space. - */ -function normalizeSpaces(text) -{ - // IE has already done this conversion, so doing it again will remove multiple nbsp - if (browserVersion.isIE) - { - return text; - } - - // Replace multiple spaces with a single space - // TODO - this shouldn't occur inside PRE elements - text = text.replace(/\ +/g, " "); - - // Replace   with a space - var nbspPattern = new RegExp(String.fromCharCode(160), "g"); - if (browserVersion.isSafari) { - return replaceAll(text, String.fromCharCode(160), " "); - } else { - return text.replace(nbspPattern, " "); - } -} - -function replaceAll(text, oldText, newText) { - while (text.indexOf(oldText) != -1) { - text = text.replace(oldText, newText); - } - return text; -} - - -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 != null) { - element.textContent = text; - } else if (element.innerText != null) { - element.innerText = text; - } -} - -// Get the value of an element -function getInputValue(inputElement) { - if (inputElement.type) { - if (inputElement.type.toUpperCase() == 'CHECKBOX' || - inputElement.type.toUpperCase() == 'RADIO') - { - return (inputElement.checked ? 'on' : 'off'); - } - } - if (inputElement.value == null) { - throw new SeleniumError("This element has no value; is it really a form field?"); - } - return inputElement.value; -} - -/* Fire an event in a browser-compatible manner */ -function triggerEvent(element, eventType, canBubble, controlKeyDown, altKeyDown, shiftKeyDown, metaKeyDown) { - canBubble = (typeof(canBubble) == undefined) ? true : canBubble; - if (element.fireEvent) { - var evt = createEventObject(element, controlKeyDown, altKeyDown, shiftKeyDown, metaKeyDown); - element.fireEvent('on' + eventType, evt); - } - else { - var evt = document.createEvent('HTMLEvents'); - - try { - evt.shiftKey = shiftKeyDown; - evt.metaKey = metaKeyDown; - evt.altKey = altKeyDown; - evt.ctrlKey = controlKeyDown; - } catch (e) { - // On Firefox 1.0, you can only set these during initMouseEvent or initKeyEvent - // we'll have to ignore them here - LOG.exception(e); - } - - evt.initEvent(eventType, canBubble, true); - element.dispatchEvent(evt); - } -} - -function getKeyCodeFromKeySequence(keySequence) { - var match = /^\\(\d{1,3})$/.exec(keySequence); - if (match != null) { - return match[1]; - } - match = /^.$/.exec(keySequence); - if (match != null) { - return match[0].charCodeAt(0); - } - // this is for backward compatibility with existing tests - // 1 digit ascii codes will break however because they are used for the digit chars - match = /^\d{2,3}$/.exec(keySequence); - if (match != null) { - return match[0]; - } - throw new SeleniumError("invalid keySequence"); -} - -function createEventObject(element, controlKeyDown, altKeyDown, shiftKeyDown, metaKeyDown) { - var evt = element.ownerDocument.createEventObject(); - evt.shiftKey = shiftKeyDown; - evt.metaKey = metaKeyDown; - evt.altKey = altKeyDown; - evt.ctrlKey = controlKeyDown; - return evt; -} - -function triggerKeyEvent(element, eventType, keySequence, canBubble, controlKeyDown, altKeyDown, shiftKeyDown, metaKeyDown) { - var keycode = getKeyCodeFromKeySequence(keySequence); - canBubble = (typeof(canBubble) == undefined) ? true : canBubble; - if (element.fireEvent) { - var keyEvent = createEventObject(element, controlKeyDown, altKeyDown, shiftKeyDown, metaKeyDown); - keyEvent.keyCode = keycode; - element.fireEvent('on' + eventType, keyEvent); - } - else { - var evt; - if (window.KeyEvent) { - evt = document.createEvent('KeyEvents'); - evt.initKeyEvent(eventType, true, true, window, controlKeyDown, altKeyDown, shiftKeyDown, metaKeyDown, keycode, keycode); - } else { - evt = document.createEvent('UIEvents'); - - evt.shiftKey = shiftKeyDown; - evt.metaKey = metaKeyDown; - evt.altKey = altKeyDown; - evt.ctrlKey = controlKeyDown; - - evt.initUIEvent(eventType, true, true, window, 1); - evt.keyCode = keycode; - evt.which = keycode; - } - - element.dispatchEvent(evt); - } -} - -function removeLoadListener(element, command) { - LOG.info('Removing loadListenter for ' + element + ', ' + command); - if (window.removeEventListener) - element.removeEventListener("load", command, true); - else if (window.detachEvent) - element.detachEvent("onload", command); -} - -function addLoadListener(element, command) { - LOG.info('Adding loadListenter for ' + element + ', ' + command); - var augmentedCommand = function() { - command.call(this, element); - } - if (window.addEventListener && !browserVersion.isOpera) - element.addEventListener("load", augmentedCommand, true); - else if (window.attachEvent) - element.attachEvent("onload", augmentedCommand); -} - -/** - * Override the broken getFunctionName() method from JsUnit - * This file must be loaded _after_ the jsunitCore.js - */ -function getFunctionName(aFunction) { - var regexpResult = aFunction.toString().match(/function (\w*)/); - if (regexpResult && regexpResult[1]) { - return regexpResult[1]; - } - return 'anonymous'; -} - -function getDocumentBase(doc) { - var bases = document.getElementsByTagName("base"); - if (bases && bases.length && bases[0].href) { - return bases[0].href; - } - return ""; -} - -function getTagName(element) { - var tagName; - if (element && element.tagName && element.tagName.toLowerCase) { - tagName = element.tagName.toLowerCase(); - } - return tagName; -} - -function absolutify(url, baseUrl) { - /** returns a relative url in its absolute form, given by baseUrl. - * - * This function is a little odd, because it can take baseUrls that - * aren't necessarily directories. It uses the same rules as the HTML - * <base> tag; if the baseUrl doesn't end with "/", we'll assume - * that it points to a file, and strip the filename off to find its - * base directory. - * - * So absolutify("foo", "http://x/bar") will return "http://x/foo" (stripping off bar), - * whereas absolutify("foo", "http://x/bar/") will return "http://x/bar/foo" (preserving bar). - * Naturally absolutify("foo", "http://x") will return "http://x/foo", appropriately. - * - * @param url the url to make absolute; if this url is already absolute, we'll just return that, unchanged - * @param baseUrl the baseUrl from which we'll absolutify, following the rules above. - * @return 'url' if it was already absolute, or the absolutized version of url if it was not absolute. - */ - - // DGF isn't there some library we could use for this? - - if (/^\w+:/.test(url)) { - // it's already absolute - return url; - } - - var loc; - try { - loc = parseUrl(baseUrl); - } catch (e) { - // is it an absolute windows file path? let's play the hero in that case - if (/^\w:\\/.test(baseUrl)) { - baseUrl = "file:///" + baseUrl.replace(/\\/g, "/"); - loc = parseUrl(baseUrl); - } else { - throw new SeleniumError("baseUrl wasn't absolute: " + baseUrl); - } - } - loc.search = null; - loc.hash = null; - - // if url begins with /, then that's the whole pathname - if (/^\//.test(url)) { - loc.pathname = url; - var result = reassembleLocation(loc); - return result; - } - - // if pathname is null, then we'll just append "/" + the url - if (!loc.pathname) { - loc.pathname = "/" + url; - var result = reassembleLocation(loc); - return result; - } - - // if pathname ends with /, just append url - if (/\/$/.test(loc.pathname)) { - loc.pathname += url; - var result = reassembleLocation(loc); - return result; - } - - // if we're here, then the baseUrl has a pathname, but it doesn't end with / - // in that case, we replace everything after the final / with the relative url - loc.pathname = loc.pathname.replace(/[^\/\\]+$/, url); - var result = reassembleLocation(loc); - return result; - -} - -var URL_REGEX = /^((\w+):\/\/)(([^:]+):?([^@]+)?@)?([^\/\?:]*):?(\d+)?(\/?[^\?#]+)?\??([^#]+)?#?(.+)?/; - -function parseUrl(url) { - var fields = ['url', null, 'protocol', null, 'username', 'password', 'host', 'port', 'pathname', 'search', 'hash']; - var result = URL_REGEX.exec(url); - if (!result) { - throw new SeleniumError("Invalid URL: " + url); - } - var loc = new Object(); - for (var i = 0; i < fields.length; i++) { - var field = fields[i]; - if (field == null) { - continue; - } - loc[field] = result[i]; - } - return loc; -} - -function reassembleLocation(loc) { - if (!loc.protocol) { - throw new Error("Not a valid location object: " + o2s(loc)); - } - var protocol = loc.protocol; - protocol = protocol.replace(/:$/, ""); - var url = protocol + "://"; - if (loc.username) { - url += loc.username; - if (loc.password) { - url += ":" + loc.password; - } - url += "@"; - } - if (loc.host) { - url += loc.host; - } - - if (loc.port) { - url += ":" + loc.port; - } - - if (loc.pathname) { - url += loc.pathname; - } - - if (loc.search) { - url += "?" + loc.search; - } - if (loc.hash) { - var hash = loc.hash; - hash = loc.hash.replace(/^#/, ""); - url += "#" + hash; - } - return url; -} - -function canonicalize(url) { - var tempLink = window.document.createElement("link"); - tempLink.href = url; // this will canonicalize the href - return tempLink.href; -} - -function extractExceptionMessage(ex) { - if (ex == null) return "null exception"; - if (ex.message != null) return ex.message; - if (ex.toString && ex.toString() != null) return ex.toString(); -} - - -function describe(object, delimiter) { - var props = new Array(); - for (var prop in object) { - try { - props.push(prop + " -> " + object[prop]); - } catch (e) { - props.push(prop + " -> [htmlutils: ack! couldn't read this property! (Permission Denied?)]"); - } - } - return props.join(delimiter || '\n'); -} - -var PatternMatcher = function(pattern) { - this.selectStrategy(pattern); -}; -PatternMatcher.prototype = { - - selectStrategy: function(pattern) { - this.pattern = pattern; - var strategyName = 'glob'; - // by default - if (/^([a-z-]+):(.*)/.test(pattern)) { - var possibleNewStrategyName = RegExp.$1; - var possibleNewPattern = RegExp.$2; - if (PatternMatcher.strategies[possibleNewStrategyName]) { - strategyName = possibleNewStrategyName; - pattern = possibleNewPattern; - } - } - var matchStrategy = PatternMatcher.strategies[strategyName]; - if (!matchStrategy) { - throw new SeleniumError("cannot find PatternMatcher.strategies." + strategyName); - } - this.strategy = matchStrategy; - this.matcher = new matchStrategy(pattern); - }, - - matches: function(actual) { - return this.matcher.matches(actual + ''); - // Note: appending an empty string avoids a Konqueror bug - } - -}; - -/** - * A "static" convenience method for easy matching - */ -PatternMatcher.matches = function(pattern, actual) { - return new PatternMatcher(pattern).matches(actual); -}; - -PatternMatcher.strategies = { - -/** - * Exact matching, e.g. "exact:***" - */ - exact: function(expected) { - this.expected = expected; - this.matches = function(actual) { - return actual == this.expected; - }; - }, - -/** - * Match by regular expression, e.g. "regexp:^[0-9]+$" - */ - regexp: function(regexpString) { - this.regexp = new RegExp(regexpString); - this.matches = function(actual) { - return this.regexp.test(actual); - }; - }, - - regex: function(regexpString) { - this.regexp = new RegExp(regexpString); - this.matches = function(actual) { - return this.regexp.test(actual); - }; - }, - -/** - * "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 - * and so avoid running into this IE6 freeze. - */ - globContains: function(globString) { - this.regexp = new RegExp(PatternMatcher.regexpFromGlobContains(globString)); - this.matches = function(actual) { - return this.regexp.test(actual); - }; - }, - - -/** - * "glob" (aka "wildmat") patterns, e.g. "glob:one,two,*" - */ - glob: function(globString) { - this.regexp = new RegExp(PatternMatcher.regexpFromGlob(globString)); - this.matches = function(actual) { - return this.regexp.test(actual); - }; - } - -}; - -PatternMatcher.convertGlobMetaCharsToRegexpMetaChars = function(glob) { - var re = glob; - re = re.replace(/([.^$+(){}\[\]\\|])/g, "\\$1"); - re = re.replace(/\?/g, "(.|[\r\n])"); - re = re.replace(/\*/g, "(.|[\r\n])*"); - return re; -}; - -PatternMatcher.regexpFromGlobContains = function(globContains) { - return PatternMatcher.convertGlobMetaCharsToRegexpMetaChars(globContains); -}; - -PatternMatcher.regexpFromGlob = function(glob) { - return "^" + PatternMatcher.convertGlobMetaCharsToRegexpMetaChars(glob) + "$"; -}; - -var Assert = { - - fail: function(message) { - throw new AssertionFailedError(message); - }, - -/* -* Assert.equals(comment?, expected, actual) -*/ - equals: function() { - var args = new AssertionArguments(arguments); - if (args.expected === args.actual) { - return; - } - Assert.fail(args.comment + - "Expected '" + args.expected + - "' but was '" + args.actual + "'"); - }, - -/* -* Assert.matches(comment?, pattern, actual) -*/ - matches: function() { - var args = new AssertionArguments(arguments); - if (PatternMatcher.matches(args.expected, args.actual)) { - return; - } - Assert.fail(args.comment + - "Actual value '" + args.actual + - "' did not match '" + args.expected + "'"); - }, - -/* -* Assert.notMtches(comment?, pattern, actual) -*/ - notMatches: function() { - var args = new AssertionArguments(arguments); - if (!PatternMatcher.matches(args.expected, args.actual)) { - return; - } - Assert.fail(args.comment + - "Actual value '" + args.actual + - "' did match '" + args.expected + "'"); - } - -}; - -// Preprocess the arguments to allow for an optional comment. -function AssertionArguments(args) { - if (args.length == 2) { - this.comment = ""; - this.expected = args[0]; - this.actual = args[1]; - } else { - this.comment = args[0] + "; "; - this.expected = args[1]; - this.actual = args[2]; - } -} - -function AssertionFailedError(message) { - this.isAssertionFailedError = true; - this.isSeleniumError = true; - this.message = message; - this.failureMessage = message; -} - -function SeleniumError(message) { - var error = new Error(message); - error.isSeleniumError = true; - return error; -} - -function highlight(element) { - var highLightColor = "yellow"; - if (element.originalColor == undefined) { // avoid picking up highlight - element.originalColor = elementGetStyle(element, "background-color"); - } - elementSetStyle(element, {"backgroundColor" : highLightColor}); - window.setTimeout(function() { - try { - //if element is orphan, probably page of it has already gone, so ignore - if (!element.parentNode) { - return; - } - elementSetStyle(element, {"backgroundColor" : element.originalColor}); - } catch (e) {} // DGF unhighlighting is very dangerous and low priority - }, 200); -} - - - -// for use from vs.2003 debugger -function o2s(obj) { - var s = ""; - for (key in obj) { - var line = key + "->" + obj[key]; - line.replace("\n", " "); - s += line + "\n"; - } - return s; -} - -var seenReadyStateWarning = false; - -function openSeparateApplicationWindow(url, suppressMozillaWarning) { - // resize the Selenium window itself - window.resizeTo(1200, 500); - window.moveTo(window.screenX, 0); - - var appWindow = window.open(url + '?start=true', 'main'); - try { - var windowHeight = 500; - if (window.outerHeight) { - windowHeight = window.outerHeight; - } else if (document.documentElement && document.documentElement.offsetHeight) { - windowHeight = document.documentElement.offsetHeight; - } - - if (window.screenLeft && !window.screenX) window.screenX = window.screenLeft; - if (window.screenTop && !window.screenY) window.screenY = window.screenTop; - - appWindow.resizeTo(1200, screen.availHeight - windowHeight - 60); - appWindow.moveTo(window.screenX, window.screenY + windowHeight + 25); - } catch (e) { - LOG.error("Couldn't resize app window"); - LOG.exception(e); - } - - - if (!suppressMozillaWarning && window.document.readyState == null && !seenReadyStateWarning) { - alert("Beware! Mozilla bug 300992 means that we can't always reliably detect when a new page has loaded. Install the Selenium IDE extension or the readyState extension available from selenium.openqa.org to make page load detection more reliable."); - seenReadyStateWarning = true; - } - - return appWindow; -} - -var URLConfiguration = classCreate(); -objectExtend(URLConfiguration.prototype, { - initialize: function() { - }, - _isQueryParameterTrue: function (name) { - var parameterValue = this._getQueryParameter(name); - if (parameterValue == null) return false; - if (parameterValue.toLowerCase() == "true") return true; - if (parameterValue.toLowerCase() == "on") return true; - return false; - }, - - _getQueryParameter: function(searchKey) { - var str = this.queryString - if (str == null) return null; - var clauses = str.split('&'); - for (var i = 0; i < clauses.length; i++) { - var keyValuePair = clauses[i].split('=', 2); - var key = unescape(keyValuePair[0]); - if (key == searchKey) { - return unescape(keyValuePair[1]); - } - } - return null; - }, - - _extractArgs: function() { - 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; - }, - - isMultiWindowMode:function() { - return this._isQueryParameterTrue('multiWindow'); - }, - - getBaseUrl:function() { - return this._getQueryParameter('baseUrl'); - - } -}); - - -function safeScrollIntoView(element) { - if (element.scrollIntoView) { - element.scrollIntoView(false); - return; - } - // TODO: work out how to scroll browsers that don't support - // scrollIntoView (like Konqueror) -} diff --git a/tests/test_tools/selenium/core/scripts/injection.html b/tests/test_tools/selenium/core/scripts/injection.html deleted file mode 100644 index a75c7211..00000000 --- a/tests/test_tools/selenium/core/scripts/injection.html +++ /dev/null @@ -1,79 +0,0 @@ - diff --git a/tests/test_tools/selenium/core/scripts/injection_iframe.html b/tests/test_tools/selenium/core/scripts/injection_iframe.html deleted file mode 100644 index bc26e859..00000000 --- a/tests/test_tools/selenium/core/scripts/injection_iframe.html +++ /dev/null @@ -1,7 +0,0 @@ - diff --git a/tests/test_tools/selenium/core/scripts/js2html.js b/tests/test_tools/selenium/core/scripts/js2html.js deleted file mode 100644 index 407709df..00000000 --- a/tests/test_tools/selenium/core/scripts/js2html.js +++ /dev/null @@ -1,70 +0,0 @@ -/* - -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;icurrentTest.doNextCommand()' + - '' + script_fragment + '' + - '\n'; - new_test_source += new_line; - //eval(script_fragment); - - - }; - - - - execute(parse_result,x2) - - // Create HTML Table - body = document.body - body.innerHTML += ""+ - "" + - "" + - new_test_source + - ""; - - //body.innerHTML = "
" + parse_result + "
" -} - - diff --git a/tests/test_tools/selenium/core/scripts/narcissus-defs.js b/tests/test_tools/selenium/core/scripts/narcissus-defs.js deleted file mode 100644 index 5869397d..00000000 --- a/tests/test_tools/selenium/core/scripts/narcissus-defs.js +++ /dev/null @@ -1,175 +0,0 @@ -/* ***** 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 . - * 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]; -} diff --git a/tests/test_tools/selenium/core/scripts/narcissus-exec.js b/tests/test_tools/selenium/core/scripts/narcissus-exec.js deleted file mode 100644 index e2c88f81..00000000 --- a/tests/test_tools/selenium/core/scripts/narcissus-exec.js +++ /dev/null @@ -1,1054 +0,0 @@ -/* ***** 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 . - * 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 += ('
>>> ' + the_statement + '
') - LOG.info('>>>' + the_statement) - x.result = getValue(execute(n.expression, x)); - //if (x.result) - //global.debug.document.body.innerHTML += ( '
>>> ' + x.result + '
') - - 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; -} diff --git a/tests/test_tools/selenium/core/scripts/narcissus-parse.js b/tests/test_tools/selenium/core/scripts/narcissus-parse.js deleted file mode 100644 index d6acb836..00000000 --- a/tests/test_tools/selenium/core/scripts/narcissus-parse.js +++ /dev/null @@ -1,1003 +0,0 @@ -/* ***** 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 . - * Portions created by the Initial Developer are Copyright (C) 2004 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): Richard Hundt - * - * 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) { - //
// " + document.title + "