diff options
Diffstat (limited to 'WebKit/chromium/src/js/Tests.js')
-rw-r--r-- | WebKit/chromium/src/js/Tests.js | 224 |
1 files changed, 0 insertions, 224 deletions
diff --git a/WebKit/chromium/src/js/Tests.js b/WebKit/chromium/src/js/Tests.js index 2233463..5cebb52 100644 --- a/WebKit/chromium/src/js/Tests.js +++ b/WebKit/chromium/src/js/Tests.js @@ -953,230 +953,6 @@ TestSuite.prototype._waitUntilScriptsAreParsed = function(expectedScripts, callb /** - * Gets a XPathResult matching given xpath. - * @param {string} xpath - * @param {number} resultType - * @param {Node} opt_ancestor Context node. If not specified documentElement - * will be used - * @return {XPathResult} Type of returned value is determined by "resultType" parameter - */ - -TestSuite.prototype._evaluateXpath = function(xpath, resultType, opt_ancestor) -{ - if (!opt_ancestor) - opt_ancestor = document.documentElement; - try { - return document.evaluate(xpath, opt_ancestor, null, resultType, null); - } catch(e) { - this.fail('Error in expression: "' + xpath + '".' + e); - } -}; - - -/** - * Gets first Node matching given xpath. - * @param {string} xpath - * @param {Node} opt_ancestor Context node. If not specified documentElement - * will be used - * @return {?Node} - */ -TestSuite.prototype._findNode = function(xpath, opt_ancestor) -{ - var result = this._evaluateXpath(xpath, XPathResult.FIRST_ORDERED_NODE_TYPE, opt_ancestor).singleNodeValue; - this.assertTrue(!!result, "Cannot find node on path: " + xpath); - return result; -}; - - -/** - * Gets a text matching given xpath. - * @param {string} xpath - * @param {Node} opt_ancestor Context node. If not specified documentElement - * will be used - * @return {?string} - */ -TestSuite.prototype._findText = function(xpath, opt_ancestor) -{ - var result = this._evaluateXpath(xpath, XPathResult.STRING_TYPE, opt_ancestor).stringValue; - this.assertTrue(!!result, "Cannot find text on path: " + xpath); - return result; -}; - - -/** - * Gets an iterator over nodes matching given xpath. - * @param {string} xpath - * @param {Node} opt_ancestor Context node. If not specified, documentElement - * will be used - * @return {XPathResult} Iterator over the nodes - */ -TestSuite.prototype._nodeIterator = function(xpath, opt_ancestor) -{ - return this._evaluateXpath(xpath, XPathResult.ORDERED_NODE_ITERATOR_TYPE, opt_ancestor); -}; - - -/** - * Checks the scopeSectionDiv against the expectations. - * @param {Node} scopeSectionDiv The section div - * @param {Object} expectations Expectations dictionary - */ -TestSuite.prototype._checkScopeSectionDiv = function(scopeSectionDiv, expectations) -{ - var scopeTitle = this._findText('./div[@class="header"]/div[@class="title"]/text()', scopeSectionDiv); - this.assertEquals(expectations.title, scopeTitle, "Unexpected scope section title."); - if (!expectations.properties) - return; - this.assertTrue(scopeSectionDiv.hasStyleClass("expanded"), 'Section "' + scopeTitle + '" is collapsed.'); - - var propertyIt = this._nodeIterator("./ol/li", scopeSectionDiv); - var propertyLi; - var foundProps = []; - while (propertyLi = propertyIt.iterateNext()) { - var name = this._findText('./span[@class="name"]/text()', propertyLi); - var value = this._findText('./span[@class="value"]/text()', propertyLi); - this.assertTrue(!!name, 'Invalid variable name: "' + name + '"'); - this.assertTrue(name in expectations.properties, "Unexpected property: " + name); - this.assertEquals(expectations.properties[name], value, 'Unexpected "' + name + '" property value.'); - delete expectations.properties[name]; - foundProps.push(name + " = " + value); - } - - // Check that all expected properties were found. - for (var p in expectations.properties) - this.fail('Property "' + p + '" was not found in scope "' + scopeTitle + '". Found properties: "' + foundProps.join(",") + '"'); -}; - - -/** - * Expands scope sections matching the filter and invokes the callback on - * success. - * @param {function(WebInspector.ObjectPropertiesSection, number):boolean} - * filter - * @param {Function} callback - */ -TestSuite.prototype._expandScopeSections = function(filter, callback) -{ - var sections = WebInspector.currentPanel.sidebarPanes.scopechain.sections; - - var toBeUpdatedCount = 0; - function updateListener() { - --toBeUpdatedCount; - if (toBeUpdatedCount === 0) { - // Report when all scopes are expanded and populated. - callback(); - } - } - - // Global scope is always the last one. - for (var i = 0; i < sections.length - 1; i++) { - var section = sections[i]; - if (!filter(sections, i)) - continue; - ++toBeUpdatedCount; - var populated = section.populated; - - this._hookGetPropertiesCallback(updateListener, - function() { - section.expand(); - if (populated) { - // Make sure "updateProperties" callback will be called at least once - // after it was overridden. - section.update(); - } - }); - } -}; - - -/** - * Tests that scopes can be expanded and contain expected data. - */ -TestSuite.prototype.testExpandScope = function() -{ - this.showPanel("scripts"); - var test = this; - - this._executeCodeWhenScriptsAreParsed("handleClick()", ["debugger_closure.html"]); - - this._waitForScriptPause( - { - functionsOnStack: ["innerFunction", "handleClick", ""], - lineNumber: 8, - lineText: " debugger;" - }, - expandAllSectionsExceptGlobal); - - // Expanding Global scope takes for too long so we skeep it. - function expandAllSectionsExceptGlobal() { - test._expandScopeSections(function(sections, i) { - return i < sections.length - 1; - }, - examineScopes /* When all scopes are expanded and populated check them. */); - } - - // Check scope sections contents. - function examineScopes() { - var scopeVariablesSection = test._findNode('//div[@id="scripts-sidebar"]/div[div[@class="title"]/text()="Scope Variables"]'); - var expectedScopes = [ - { - title: "Local", - properties: { - x:"2009", - innerFunctionLocalVar:"2011", - "this": "DOMWindow", - } - }, - { - title: "Closure", - properties: { - n: '"TextParam"', - makeClosureLocalVar: '"local.TextParam"', - } - }, - { - title: "Global", - }, - ]; - var it = test._nodeIterator('./div[@class="body"]/div', scopeVariablesSection); - var scopeIndex = 0; - var scopeDiv; - while (scopeDiv = it.iterateNext()) { - test.assertTrue(scopeIndex < expectedScopes.length, "Too many scopes."); - test._checkScopeSectionDiv(scopeDiv, expectedScopes[scopeIndex]); - ++scopeIndex; - } - test.assertEquals(expectedScopes.length, scopeIndex, "Unexpected number of scopes."); - - test.releaseControl(); - } - - test.takeControl(); -}; - - -/** - * Returns child tree element for a property with given name. - * @param {TreeElement} parent Parent tree element. - * @param {string} childName - * @param {string} objectPath Path to the object. Will be printed in the case - * of failure. - * @return {TreeElement} - */ -TestSuite.prototype._findChildProperty = function(parent, childName, objectPath) -{ - var children = parent.children; - for (var i = 0; i < children.length; i++) { - var treeElement = children[i]; - var property = treeElement.property; - if (property.name === childName) - return treeElement; - } - this.fail('Cannot find property "' + childName + '" in ' + objectPath); -}; - - -/** * Executes the 'code' with InjectedScriptAccess.getProperties overriden * so that all callbacks passed to InjectedScriptAccess.getProperties are * extended with the "hook". |