diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/webkit/PerformanceTests/Speedometer/resources/flightjs-example-app/components/jasmine-flight | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/webkit/PerformanceTests/Speedometer/resources/flightjs-example-app/components/jasmine-flight')
4 files changed, 638 insertions, 0 deletions
diff --git a/third_party/webkit/PerformanceTests/Speedometer/resources/flightjs-example-app/components/jasmine-flight/LICENSE.md b/third_party/webkit/PerformanceTests/Speedometer/resources/flightjs-example-app/components/jasmine-flight/LICENSE.md new file mode 100644 index 0000000000..57ccdff5f7 --- /dev/null +++ b/third_party/webkit/PerformanceTests/Speedometer/resources/flightjs-example-app/components/jasmine-flight/LICENSE.md @@ -0,0 +1,19 @@ +Copyright (c) 2013 Twitter, Inc and others + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE.
\ No newline at end of file diff --git a/third_party/webkit/PerformanceTests/Speedometer/resources/flightjs-example-app/components/jasmine-flight/README.md b/third_party/webkit/PerformanceTests/Speedometer/resources/flightjs-example-app/components/jasmine-flight/README.md new file mode 100644 index 0000000000..aa8b0f84c8 --- /dev/null +++ b/third_party/webkit/PerformanceTests/Speedometer/resources/flightjs-example-app/components/jasmine-flight/README.md @@ -0,0 +1,145 @@ +# jasmine-flight [![Build Status](https://travis-ci.org/flightjs/jasmine-flight.png?branch=master)](http://travis-ci.org/flightjs/jasmine-flight) + +Extensions to the Jasmine test framework for use with [Flight](https://github.com/flightjs/flight) + +# Getting started + +Include [jasmine-flight.js](https://raw.github.com/flightjs/jasmine-flight/master/lib/jasmine-flight.js) +in your app and load it in your test runner. + +Or install it with [Bower](http://bower.io/): + +```bash +bower install --save-dev jasmine-flight +``` + +**N.B.** jasmine-flight depends on +[jasmine](https://github.com/pivotal/jasmine) and +[jasmine-jquery](https://github.com/velesin/jasmine-jquery) + +## Components + +```javascript +describeComponent('path/to/component', function () { + beforeEach(function () { + setupComponent(); + }); + + it('should do x', function () { + // a component instance is now accessible as this.component + // the component root node is attached to the DOM + // the component root node is also available as this.$node + }); +}); +``` + +## Mixins + +```javascript +describeMixin('path/to/mixin', function () { + // initialize the component and attach it to the DOM + beforeEach(function () { + setupComponent(); + }); + + it('should do x', function () { + expect(this.component.doSomething()).toBe(expected); + }); +}); +``` + +## Event spy + +```javascript +describeComponent('data/twitter_profile', function () { + beforeEach(function () { + setupComponent(); + }); + + describe('listens for uiNeedsTwitterUserId', function () { + // was the event triggered? + it('and triggers dataTwitterUserId', function () { + var eventSpy = spyOnEvent(document, 'dataTwitterProfile'); + $(document).trigger('uiNeedsTwitterUserId', { + screen_name: 'tbrd' + }); + expect(eventSpy).toHaveBeenTriggeredOn(document); + }); + + // is the user id correct? + it('and has correct id', function () { + var eventSpy = spyOnEvent(document, 'dataTwitterUserId'); + $(document).trigger('uiNeedsTwitteruserId', { + screen_name: 'tbrd' + }); + expect(eventSpy.mostRecentCall.data).toEqual({ + screen_name: 'tbrd', + id: 4149861 + }); + }); + }); +}); +``` + +## setupComponent + +```javascript +setupComponent(optionalFixture, optionalOptions); +``` + +Calling `setupComponent` twice will create an instance, tear it down and create a new one. + +### HTML Fixtures + +```javascript +describeComponent('ui/twitter_profile', function () { + // is the component attached to the fixture? + it('this.component.$node has class "foo"', function () { + setupComponent('<span class="foo">Test</span>'); + expect(this.component.$node).toHaveClass('foo'); + }); +}); +``` + +### Component Options + +```javascript +describeComponent('data/twitter_profile', function () { + // is the option set correctly? + it('this.component.attr.baseUrl is set', function () { + setupComponent({ + baseUrl: 'http://twitter.com/1.1/' + }); + expect(this.component.attr.baseUrl).toBe('http://twitter.com/1.1/'); + }); +}); +``` + +# Teardown + +Components are automatically torn down after each test. + +## Contributing to this project + +Anyone and everyone is welcome to contribute. Please take a moment to +review the [guidelines for contributing](CONTRIBUTING.md). + +* [Bug reports](CONTRIBUTING.md#bugs) +* [Feature requests](CONTRIBUTING.md#features) +* [Pull requests](CONTRIBUTING.md#pull-requests) + +## Authors + +* [@tbrd](http://github.com/tbrd) + +## Thanks + +* [@esbie](http://github.com/esbie) and + [@skilldrick](http://github.com/skilldrick) for creating the original + `describeComponent` & `describeMixin` methods. + +## License + +Copyright 2013 Twitter, Inc and other contributors. + +Licensed under the MIT License diff --git a/third_party/webkit/PerformanceTests/Speedometer/resources/flightjs-example-app/components/jasmine-flight/bower.json b/third_party/webkit/PerformanceTests/Speedometer/resources/flightjs-example-app/components/jasmine-flight/bower.json new file mode 100644 index 0000000000..dd5f09f08e --- /dev/null +++ b/third_party/webkit/PerformanceTests/Speedometer/resources/flightjs-example-app/components/jasmine-flight/bower.json @@ -0,0 +1,30 @@ +{ + "name": "jasmine-flight", + "version": "1.1.0", + "description": "Extensions to the Jasmine test framework for use with Flight", + "main": "lib/jasmine-flight.js", + "keywords": [ + "flight", + "jasmine", + "test" + ], + "ignore": [ + ".*", + "test", + "package.json", + "karma.conf.js", + "CONTRIBUTING.md", + "CHANGELOG.md" + ], + "devDependencies": { + "flight": "~1.0.9" + }, + "gitHead": "5174302b9a87ebdda99de6a436ec2a64200fc5ff", + "readme": "# jasmine-flight [![Build Status](https://travis-ci.org/flightjs/jasmine-flight.png?branch=master)](http://travis-ci.org/flightjs/jasmine-flight)\n\nExtensions to the Jasmine test framework for use with [Flight](https://github.com/flightjs/flight)\n\n# Getting started\n\nInclude [jasmine-flight.js](https://raw.github.com/flightjs/jasmine-flight/master/lib/jasmine-flight.js)\nin your app and load it in your test runner.\n\nOr install it with [Bower](http://bower.io/):\n\n```bash\nbower install --save-dev jasmine-flight\n```\n\n**N.B.** jasmine-flight depends on\n[jasmine](https://github.com/pivotal/jasmine) and\n[jasmine-jquery](https://github.com/velesin/jasmine-jquery)\n\n## Components\n\n```javascript\ndescribeComponent('path/to/component', function () {\n beforeEach(function () {\n setupComponent();\n });\n\n it('should do x', function () {\n // a component instance is now accessible as this.component\n // the component root node is attached to the DOM\n // the component root node is also available as this.$node\n });\n});\n```\n\n## Mixins\n\n```javascript\ndescribeMixin('path/to/mixin', function () {\n // initialize the component and attach it to the DOM\n beforeEach(function () {\n setupComponent();\n });\n\n it('should do x', function () {\n expect(this.component.doSomething()).toBe(expected);\n });\n});\n```\n\n## Event spy\n\n```javascript\ndescribeComponent('data/twitter_profile', function () {\n beforeEach(function () {\n setupComponent();\n });\n\n describe('listens for uiNeedsTwitterUserId', function () {\n // was the event triggered?\n it('and triggers dataTwitterUserId', function () {\n var eventSpy = spyOnEvent(document, 'dataTwitterProfile');\n $(document).trigger('uiNeedsTwitterUserId', {\n screen_name: 'tbrd'\n });\n expect(eventSpy).toHaveBeenTriggeredOn(document);\n });\n\n // is the user id correct?\n it('and has correct id', function () {\n var eventSpy = spyOnEvent(document, 'dataTwitterUserId');\n $(document).trigger('uiNeedsTwitteruserId', {\n screen_name: 'tbrd'\n });\n expect(eventSpy.mostRecentCall.data).toEqual({\n screen_name: 'tbrd',\n id: 4149861\n });\n });\n });\n});\n```\n\n## setupComponent\n\n```javascript\nsetupComponent(optionalFixture, optionalOptions);\n```\n\nCalling `setupComponent` twice will create an instance, tear it down and create a new one.\n\n### HTML Fixtures\n\n```javascript\ndescribeComponent('ui/twitter_profile', function () {\n // is the component attached to the fixture?\n it('this.component.$node has class \"foo\"', function () {\n setupComponent('<span class=\"foo\">Test</span>');\n expect(this.component.$node).toHaveClass('foo');\n });\n});\n```\n\n### Component Options\n\n```javascript\ndescribeComponent('data/twitter_profile', function () {\n // is the option set correctly?\n it('this.component.attr.baseUrl is set', function () {\n setupComponent({\n baseUrl: 'http://twitter.com/1.1/'\n });\n expect(this.component.attr.baseUrl).toBe('http://twitter.com/1.1/');\n });\n});\n```\n\n# Teardown\n\nComponents are automatically torn down after each test.\n\n## Contributing to this project\n\nAnyone and everyone is welcome to contribute. Please take a moment to\nreview the [guidelines for contributing](CONTRIBUTING.md).\n\n* [Bug reports](CONTRIBUTING.md#bugs)\n* [Feature requests](CONTRIBUTING.md#features)\n* [Pull requests](CONTRIBUTING.md#pull-requests)\n\n## Authors\n\n* [@tbrd](http://github.com/tbrd)\n\n## Thanks\n\n* [@esbie](http://github.com/esbie) and\n [@skilldrick](http://github.com/skilldrick) for creating the original\n `describeComponent` & `describeMixin` methods.\n\n## License\n\nCopyright 2013 Twitter, Inc and other contributors.\n\nLicensed under the MIT License\n", + "readmeFilename": "README.md", + "_id": "jasmine-flight@1.1.0", + "repository": { + "type": "git", + "url": "git://github.com/flightjs/jasmine-flight.git" + } +}
\ No newline at end of file diff --git a/third_party/webkit/PerformanceTests/Speedometer/resources/flightjs-example-app/components/jasmine-flight/lib/jasmine-flight.js b/third_party/webkit/PerformanceTests/Speedometer/resources/flightjs-example-app/components/jasmine-flight/lib/jasmine-flight.js new file mode 100644 index 0000000000..8ec76b4e1d --- /dev/null +++ b/third_party/webkit/PerformanceTests/Speedometer/resources/flightjs-example-app/components/jasmine-flight/lib/jasmine-flight.js @@ -0,0 +1,444 @@ +/** + * Copyright 2013, Twitter Inc. and other contributors + * Licensed under the MIT License + */ + +(function (root) { + 'use strict'; + + jasmine.flight = {}; + + /** + * Wrapper for describe. Load component before each test. + * + * @param componentPath + * @param specDefinitions + */ + + root.describeComponent = function (componentPath, specDefinitions) { + jasmine.getEnv().describeComponent(componentPath, specDefinitions); + }; + + jasmine.Env.prototype.describeComponent = function (componentPath, specDefinitions) { + describe(componentPath, function () { + beforeEach(function () { + this.Component = this.component = this.$node = null; + + var requireCallback = function (registry, Component) { + registry.reset(); + this.Component = Component; + }.bind(this); + + require(['flight/lib/registry', componentPath], requireCallback); + + waitsFor(function () { + return this.Component !== null; + }.bind(this)); + }); + + afterEach(function () { + if (this.$node) { + this.$node.remove(); + this.$node = null; + } + + var requireCallback = function (defineComponent) { + if (this.component) { + this.component = null; + } + + this.Component = null; + defineComponent.teardownAll(); + }.bind(this); + + require(['flight/lib/component'], requireCallback); + + waitsFor(function () { + return this.Component === null; + }.bind(this)); + }); + + specDefinitions.apply(this); + }); + }; + + /** + * Wrapper for describe. Load mixin before each test. + * + * @param mixinPath + * @param specDefinitions + */ + + root.describeMixin = function (mixinPath, specDefinitions) { + jasmine.getEnv().describeMixin(mixinPath, specDefinitions); + }; + + jasmine.Env.prototype.describeMixin = function (mixinPath, specDefinitions) { + describe(mixinPath, function () { + beforeEach(function () { + this.Component = this.component = this.$node = null; + + var requireCallback = function (registry, defineComponent, Mixin) { + registry.reset(); + this.Component = defineComponent(function () {}, Mixin); + }.bind(this); + + require(['flight/lib/registry', 'flight/lib/component', mixinPath], requireCallback); + + waitsFor(function () { + return this.Component !== null; + }); + }); + + afterEach(function () { + if (this.$node) { + this.$node.remove(); + this.$node = null; + } + + var requireCallback = function (defineComponent) { + if (this.component) { + this.component = null; + } + + this.Component = null; + defineComponent.teardownAll(); + }.bind(this); + + require(['flight/lib/component'], requireCallback); + + waitsFor(function () { + return this.Component === null; + }.bind(this)); + }); + + specDefinitions.apply(this); + }); + }; + + /** + * Wrapper for describe. Load module before each test. + * + * @param modulePath + * @param specDefinitions + */ + + root.describeModule = function (modulePath, specDefinitions) { + return jasmine.getEnv().describeModule(modulePath, specDefinitions); + }; + + jasmine.Env.prototype.describeModule = function (modulePath, specDefinitions) { + describe(modulePath, function () { + beforeEach(function () { + this.module = null; + + var requireCallback = function (module) { + this.module = module; + }.bind(this); + + require([modulePath], requireCallback); + + waitsFor(function () { + return this.module !== null; + }); + }); + + specDefinitions.apply(this); + }); + }; + + /** + * Create root node and initialize component. Fixture should be html string + * or jQuery object. + * + * @param fixture {String} (Optional) + * @param options {Options} (Optional) + */ + + root.setupComponent = function (fixture, options) { + jasmine.getEnv().currentSpec.setupComponent(fixture, options); + }; + + jasmine.Spec.prototype.setupComponent = function (fixture, options) { + if (this.component) { + this.component.teardown(); + this.$node.remove(); + } + + this.$node = $('<div class="component-root" />'); + $('body').append(this.$node); + + if (fixture instanceof jQuery || typeof fixture === 'string') { + this.$node.append(fixture); + } else { + options = fixture; + fixture = null; + } + + options = options === undefined ? {} : options; + + this.component = new this.Component(this.$node, options); + }; + + + (function (namespace) { + var eventsData = { + spiedEvents: {}, + handlers: [] + }; + + namespace.formatElement = function ($element) { + var limit = 200; + var output = ''; + + if ($element instanceof jQuery) { + output = jasmine.JQuery.elementToString($element); + if (output.length > limit) { + output = output.slice(0, 200) + '...'; + } + } else { + //$element should always be a jQuery object + output = 'element is not a jQuery object'; + } + + return output; + }; + + namespace.compareColors = function (color1, color2) { + if (color1.charAt(0) === color2.charAt(0)) { + return color1 === color2; + } else { + return namespace.hex2rgb(color1) === namespace.hex2rgb(color2); + } + }; + + namespace.hex2rgb = function (colorString) { + if (colorString.charAt(0) !== '#') return colorString; + // note: hexStr should be #rrggbb + var hex = parseInt(colorString.substring(1), 16); + var r = (hex & 0xff0000) >> 16; + var g = (hex & 0x00ff00) >> 8; + var b = hex & 0x0000ff; + return 'rgb(' + r + ', ' + g + ', ' + b + ')'; + }; + + namespace.events = { + spyOn: function (selector, eventName) { + eventsData.spiedEvents[[selector, eventName]] = { + callCount: 0, + calls: [], + mostRecentCall: {}, + name: eventName + }; + + var handler = function (e, data) { + var call = { + event: e, + args: jasmine.util.argsToArray(arguments), + data: data + }; + eventsData.spiedEvents[[selector, eventName]].callCount++; + eventsData.spiedEvents[[selector, eventName]].calls.push(call); + eventsData.spiedEvents[[selector, eventName]].mostRecentCall = call; + }; + + jQuery(selector).on(eventName, handler); + eventsData.handlers.push(handler); + return eventsData.spiedEvents[[selector, eventName]]; + }, + + eventArgs: function (selector, eventName, expectedArg) { + var actualArgs = eventsData.spiedEvents[[selector, eventName]].mostRecentCall.args; + + if (!actualArgs) { + throw 'No event spy found on ' + eventName + '. Try adding a call to spyOnEvent or make sure that the selector the event is triggered on and the selector being spied on are correct.'; + } + + // remove extra event metadata if it is not tested for + if ((actualArgs.length === 2) && typeof actualArgs[1] === 'object' && + expectedArg && !expectedArg.scribeContext && !expectedArg.sourceEventData && !expectedArg.scribeData) { + actualArgs[1] = $.extend({}, actualArgs[1]); + delete actualArgs[1].sourceEventData; + delete actualArgs[1].scribeContext; + delete actualArgs[1].scribeData; + } + + return actualArgs; + }, + + wasTriggered: function (selector, event) { + var spiedEvent = eventsData.spiedEvents[[selector, event]]; + return spiedEvent && spiedEvent.callCount > 0; + }, + + wasTriggeredWith: function (selector, eventName, expectedArg, env) { + var actualArgs = jasmine.flight.events.eventArgs(selector, eventName, expectedArg); + return actualArgs && env.contains_(actualArgs, expectedArg); + }, + + wasTriggeredWithData: function (selector, eventName, expectedArg, env) { + var actualArgs = jasmine.flight.events.eventArgs(selector, eventName, expectedArg); + var valid; + + if (actualArgs) { + valid = false; + for (var i = 0; i < actualArgs.length; i++) { + if (jasmine.flight.validateHash(expectedArg, actualArgs[i])) { + return true; + } + } + return valid; + } + + return false; + }, + + cleanUp: function () { + eventsData.spiedEvents = {}; + eventsData.handlers = []; + } + }; + + namespace.validateHash = function (a, b, intersection) { + var validHash; + for (var field in a) { + if ((typeof a[field] === 'object') && (typeof b[field] === 'object')) { + validHash = jasmine.flight.validateHash(a[field], b[field]); + } else if (intersection && (typeof a[field] === 'undefined' || typeof b[field] === 'undefined')) { + validHash = true; + } else { + validHash = (a[field] === b[field]); + } + if (!validHash) { + break; + } + } + return validHash; + }; + })(jasmine.flight); + + beforeEach(function () { + this.addMatchers({ + toHaveBeenTriggeredOn: function () { + var selector = arguments[0]; + var eventName = typeof this.actual === 'string' ? this.actual : this.actual.name; + var wasTriggered = jasmine.flight.events.wasTriggered(selector, eventName); + + this.message = function () { + var $pp = function (obj) { + var description; + var attr; + + if (!(obj instanceof jQuery)) { + obj = $(obj); + } + + description = [ + obj.get(0).nodeName + ]; + + attr = obj.get(0).attributes || []; + + for (var x = 0; x < attr.length; x++) { + description.push(attr[x].name + '="' + attr[x].value + '"'); + } + + return '<' + description.join(' ') + '>'; + }; + + if (wasTriggered) { + return [ + '<div class="value-mismatch">Expected event ' + eventName + ' to have been triggered on' + selector, + '<div class="value-mismatch">Expected event ' + eventName + ' not to have been triggered on' + selector + ]; + } else { + return [ + 'Expected event ' + eventName + ' to have been triggered on ' + $pp(selector), + 'Expected event ' + eventName + ' not to have been triggered on ' + $pp(selector) + ]; + } + }; + + return wasTriggered; + }, + + toHaveBeenTriggeredOnAndWith: function () { + var selector = arguments[0]; + var expectedArg = arguments[1]; + var exactMatch = !arguments[2]; + var wasTriggered = jasmine.flight.events.wasTriggered(selector, this.actual); + + this.message = function () { + var $pp = function (obj) { + var description; + var attr; + + if (!(obj instanceof jQuery)) { + obj = $(obj); + } + + description = [ + obj.get(0).nodeName + ]; + + attr = obj.get(0).attributes || []; + + for (var x = 0; x < attr.length; x++) { + description.push(attr[x].name + '="' + attr[x].value + '"'); + } + + return '<' + description.join(' ') + '>'; + }; + + if (wasTriggered) { + var actualArg = jasmine.flight.events.eventArgs(selector, this.actual, expectedArg)[1]; + return [ + '<div class="value-mismatch">Expected event ' + this.actual.name + ' to have been triggered on' + selector, + '<div class="value-mismatch">Expected event ' + this.actual.name + ' not to have been triggered on' + selector + ]; + } else { + return [ + 'Expected event ' + this.actual.name + ' to have been triggered on ' + $pp(selector), + 'Expected event ' + this.actual.name + ' not to have been triggered on ' + $pp(selector) + ]; + } + }; + + if (!wasTriggered) { + return false; + } + + if (exactMatch) { + return jasmine.flight.events.wasTriggeredWith(selector, this.actual, expectedArg, this.env); + } else { + return jasmine.flight.events.wasTriggeredWithData(selector, this.actual, expectedArg, this.env); + } + }, + + toHaveCss: function (prop, val) { + var result; + if (val instanceof RegExp) { + result = val.test(this.actual.css(prop)); + } else if (prop.match(/color/)) { + //IE returns colors as hex strings; other browsers return rgb(r, g, b) strings + result = jasmine.flight.compareColors(this.actual.css(prop), val); + } else { + result = this.actual.css(prop) === val; + //sometimes .css() returns strings when it should return numbers + if (!result && typeof val === 'number') { + result = parseFloat(this.actual.css(prop), 10) === val; + } + } + + this.actual = jasmine.flight.formatElement(this.actual); + return result; + } + }); + }); + + root.spyOnEvent = function (selector, eventName) { + jasmine.JQuery.events.spyOn(selector, eventName); + return jasmine.flight.events.spyOn(selector, eventName); + }; + +}(this)); |