├── .gitignore ├── .jshintrc ├── .travis.yml ├── Gruntfile.js ├── bower.json ├── dist ├── storage.swf └── swfstore.min.js ├── example └── index.html ├── flex-sdk └── instructions.md ├── history.md ├── package.json ├── readme.md ├── src ├── Storage.as ├── storage.fla └── swfstore.js └── tests ├── lib ├── jasmine-2.0.3 │ ├── boot.js │ ├── console.js │ ├── jasmine-html.js │ ├── jasmine.css │ ├── jasmine.js │ └── jasmine_favicon.png └── jasmine-jsreporter.js ├── spec-runner.html └── spec └── flashcookies-spec.js /.gitignore: -------------------------------------------------------------------------------- 1 | sauce_connect.log 2 | sauce_connect.log.* 3 | .idea/ 4 | node_modules/ 5 | flex-sdk/ 6 | *.log -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "strict": true, 3 | "undef": true, 4 | "unused": true, 5 | "newcap": true, 6 | "browser": true, 7 | "devel": true 8 | } -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | sudo: false 3 | node_js: 4 | - 'stable' 5 | env: 6 | matrix: 7 | - SAUCE_USERNAME=jsfc 8 | global: 9 | secure: RXiNhz5ga4fIaXYfs7UfSH6FHdo3yPm1KMvrY82Ra5qhVmPNDTBEVDAHZOKGHW61Fiso5xZhkVMMSJtBhDIspMgvRGrKzbTGaHnDjufEC2Lm4vu67nDt1zgyoNt9zqv3RRzxh+kTZl/FzWvv0JJUnURtx6CqJThXGcjFAs3W3/Y= 10 | -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | /*jshint node: true, browser: false*/ 2 | "use strict"; 3 | 4 | module.exports = function(grunt) { 5 | var _ = require('lodash'); 6 | 7 | function browserVersions(browser, min, max) { 8 | return _.map(_.range(min, max + 1), function(v) { 9 | return { 10 | browserName: browser, 11 | version: v 12 | }; 13 | }); 14 | } 15 | 16 | function browserPlatforms(browsers, platforms) { 17 | return _.flatten(_.map(browsers, function(browser) { 18 | return _.map(platforms, function(p) { 19 | return { 20 | browserName: browser, 21 | platform: p 22 | }; 23 | }); 24 | })); 25 | 26 | } 27 | 28 | var scripts = ["*.js", "src/*.js", "tests/spec/*.js"]; 29 | 30 | grunt.loadNpmTasks('grunt-saucelabs'); 31 | grunt.loadNpmTasks('grunt-contrib-connect'); 32 | grunt.loadNpmTasks('grunt-contrib-uglify'); 33 | grunt.loadNpmTasks('grunt-contrib-jshint'); 34 | grunt.loadNpmTasks('grunt-jsbeautifier'); 35 | grunt.loadNpmTasks('grunt-newer'); 36 | grunt.loadNpmTasks('grunt-swf'); 37 | 38 | // Project configuration. 39 | grunt.initConfig({ 40 | 41 | uglify: { 42 | options: { 43 | mangle: false 44 | }, 45 | swfstore: { 46 | files: { 47 | 'dist/swfstore.min.js': ['src/swfstore.js'] 48 | } 49 | } 50 | }, 51 | 52 | "jsbeautifier": { 53 | "rewrite": { 54 | src: scripts 55 | }, 56 | "verify": { 57 | src: scripts, 58 | options: { 59 | mode: "VERIFY_ONLY" 60 | } 61 | } 62 | }, 63 | 64 | "jshint": { 65 | options: { 66 | jshintrc: true 67 | }, 68 | scripts: scripts 69 | }, 70 | 71 | swf: { 72 | options: { 73 | "flex-sdk-path": './flex-sdk' 74 | }, 75 | 'dist/storage.swf': 'src/Storage.as' 76 | }, 77 | 78 | connect: { 79 | // runs the server for the duration of the test. 80 | uses_defaults: { 81 | options: { 82 | port: 8000, 83 | base: './' 84 | } 85 | }, 86 | test: { 87 | options: {} 88 | }, 89 | serve: { 90 | options: { 91 | keepalive: true 92 | } 93 | } 94 | }, 95 | 96 | 'saucelabs-jasmine': { 97 | all: { 98 | options: { 99 | urls: ['http://127.0.0.1:8000/tests/spec-runner.html'], 100 | build: process.env.TRAVIS_JOB_ID, 101 | concurrency: 3, //'Number of concurrent browsers to test against. Will default to the number of overall browsers specified. Check your plan (free: 2, OSS: 3) and make sure you have got sufficient Sauce Labs concurrency.', 102 | detailedError: true, //'false (default) / true; if true log detailed test results when a test error occurs', 103 | testname: 'SwfStore', 104 | sauceConfig: { 105 | // https://docs.saucelabs.com/reference/test-configuration/ 106 | 'video-upload-on-pass': false 107 | }, 108 | tunnelArgs: ['--verbose'], 109 | // https://saucelabs.com/platforms 110 | browsers: browserVersions('internet explorer', 8, 11) // browser, start version, end version. Library actually works in IE 6 & 7 but the tests do not 111 | .concat(browserVersions('safari', 7, 8)) 112 | .concat({ 113 | browserName: 'safari', 114 | version: 8.1 115 | }) 116 | // there's a bug with running the chrome tests on sauce labs 117 | // for some reason, the test result is requested *immediately*, before the tests have executed 118 | .concat(browserPlatforms(['chrome', 'firefox'], ['OS X 10.10', 'Windows 8.1', 'linux'])) 119 | .concat([{ 120 | browserName: 'opera' 121 | }]) 122 | } 123 | } 124 | } 125 | }); 126 | 127 | 128 | 129 | grunt.registerTask('serve', ['connect:serve']); 130 | grunt.registerTask('quick-test', ['jshint', 'jsbeautifier:verify']); 131 | grunt.registerTask('test', ['jshint', 'jsbeautifier:verify', 'connect:test', 'saucelabs-jasmine']); 132 | grunt.registerTask('build', ['newer:uglify', 'newer:swf']); 133 | grunt.registerTask('force-build', ['uglify', 'swf']); 134 | grunt.registerTask('beautify', ['jsbeautifier:rewrite']); 135 | grunt.registerTask('pre-commit', ['quick-test', 'build']); 136 | 137 | grunt.registerTask('default', ['beautify', 'build', 'test']); 138 | 139 | }; 140 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "flash-cookies", 3 | "homepage": "https://github.com/nfriedly/Javascript-Flash-Cookies", 4 | "authors": [ 5 | "Nathan Friedly" 6 | ], 7 | "description": "JavaScript library and .swf for cross-domain flash cookies. ~4kb total when minified and gzipped.", 8 | "main": [ 9 | "src/swfstore.js" 10 | ], 11 | "moduleType": [ 12 | "amd", 13 | "globals", 14 | "node" 15 | ], 16 | "keywords": [ 17 | "swf", 18 | ".swf", 19 | "flash", 20 | "flashcookie", 21 | "flash-cookie", 22 | "flash", 23 | "cookie", 24 | "cookies", 25 | "store", 26 | "storage", 27 | "cross-domain", 28 | "cross", 29 | "domain", 30 | "localStorage" 31 | ], 32 | "license": "MIT", 33 | "ignore": [ 34 | "bower_components", 35 | "flex-sdk", 36 | "node_modules", 37 | "tests", 38 | ".gitignore", 39 | ".jshintrc", 40 | ".travis.yml", 41 | "Gruntfile.js", 42 | "package.json" 43 | ] 44 | } 45 | -------------------------------------------------------------------------------- /dist/storage.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nfriedly/Javascript-Flash-Cookies/2621f029e765be4a835a6ef0ad789a54a49cbd3c/dist/storage.swf -------------------------------------------------------------------------------- /dist/swfstore.min.js: -------------------------------------------------------------------------------- 1 | !function(){"use strict";function SwfStore(config){function id(){return"SwfStore_"+config.namespace.replace(reId,"_")+"_"+counter++}function div(visible){var d=document.createElement("div");return document.body.appendChild(d),d.id=id(),visible||(d.style.position="absolute",d.style.top="-2000px",d.style.left="-2000px"),d}config=config||{};var key,defaults={swf_url:"storage.swf",namespace:"swfstore",debug:!1,timeout:10,onready:null,onerror:null};for(key in defaults)defaults.hasOwnProperty(key)&&(config.hasOwnProperty(key)||(config[key]=defaults[key]));if(config.namespace=config.namespace.replace(reNamespace,"_"),window.SwfStore[config.namespace])throw"There is already an instance of SwfStore using the '"+config.namespace+"' namespace. Use that instance or specify an alternate namespace in the config.";if(this.config=config,"undefined"==typeof console){var loggerOutput=div(!0);this.console={log:function(msg){var m=div(!0);m.innerHTML=msg,loggerOutput.appendChild(m)}}}else this.console=console;this.log=function(type,source,msg){config.debug&&(source="swfStore"===source?"swf":source,"undefined"!=typeof this.console[type]?this.console[type]("SwfStore - "+config.namespace+" ("+source+"): "+msg):this.console.log("SwfStore - "+config.namespace+": "+type+" ("+source+"): "+msg))},this.log("info","js","Initializing..."),SwfStore[config.namespace]=this;var swfContainer=div(config.debug),swfName=id(),flashvars="namespace="+encodeURIComponent(config.namespace);swfContainer.innerHTML=' ',this.swf=document[swfName]||window[swfName],this._timeout=setTimeout(function(){SwfStore[config.namespace].onerror(new Error(config.swf_url+" failed to load within "+config.timeout+" seconds."),"js")},1e3*config.timeout)}function checkData(data){if("function"==typeof data)throw new Error("SwfStore Error: Functions cannot be used as keys or values.")}var counter=0,reNamespace=/[^a-z0-9_\/]/gi,reId=/[^a-z0-9_]/gi;SwfStore.prototype={ready:!1,set:function(key,value){this._checkReady(),checkData(key),checkData(value),null===value||"undefined"==typeof value?this.swf.clear(key):this.swf.set(key,value)},get:function(key){return this._checkReady(),checkData(key),this.swf.get(key)},getAll:function(){this._checkReady();for(var pair,pairs=this.swf.getAll(),data={},i=0,len=pairs.length;len>i;i++)pair=pairs[i],data[pair.key]=pair.value;return data},clearAll:function(){var all=this.getAll();for(var key in all)all.hasOwnProperty(key)&&this.clear(key)},clear:function(key){this._checkReady(),checkData(key),this.swf.clear(key)},_checkReady:function(){if(!this.ready)throw"SwfStore is not yet finished initializing. Pass a config.onready callback or wait until this.ready is true before trying to use a SwfStore instance."},onload:function(){var that=this;setTimeout(function(){clearTimeout(that._timeout),that.ready=!0,that.config.onready&&that.config.onready()},0)},onerror:function(err,source){clearTimeout(this._timeout),err instanceof Error||(err=new Error(err)),this.log("error",source||"swf",err.message),this.config.onerror&&this.config.onerror(err)}},"function"==typeof define&&define.amd?define([],SwfStore):"object"==typeof module&&module.exports&&(module.exports=SwfStore),window.SwfStore=SwfStore}(); -------------------------------------------------------------------------------- /example/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | SwfStore Example (JS library for Cross-Domain Flash Cookies) 5 | 6 | 7 | 8 |

SwfStore Example

9 | 10 | Fork me on GitHub 12 | 13 |

14 | 15 |

Tips:

16 |

To get the most out of this example, put it on two different domains but edit the swf_url: in the 17 | javascript to point to the same storage.swf file from both coppies of this page. (You may also want 18 | change the url to the swfstore.js file to save bandwidth.)

19 | 20 |

If you run this page locally, you may see "Error logging to js: Error #2060" or something similar 21 | because flashplayer is in a restricted security state. Try uploading it to a web server instead.

22 | 23 |

Depending on your browser and add-ons, debug messages will either be sent to the console, or 24 | appended to the end of the page.

25 | 26 | 27 | 28 | 29 | 30 | 31 | 71 | 72 | 73 | 74 |

SwfStore is a javascript library for Cross-Domain Flash Cookies. Read more at http://github.com/nfriedly/Javascript-Flash-Cookies and http://nfriedly.com/techblog/2010/07/swf-for-javascript-cross-domain-flash-cookies/

75 | 76 |

SwfStore was created by Nathan Friedly, and is released under an MIT License

77 | 78 | 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /flex-sdk/instructions.md: -------------------------------------------------------------------------------- 1 | 1. Download the "SDK Installer" (binary) from https://flex.apache.org/installer.html and install it in the default folder. 2 | 3 | 2. Delete this file. 4 | 5 | 3. Have the installer download and install the SDK in this folder. 6 | 7 | See https://github.com/nfriedly/grunt-swf#installing-the-apache-flex-sdk for more details. -------------------------------------------------------------------------------- /history.md: -------------------------------------------------------------------------------- 1 | SwfStore History / Changelog 2 | ============================ 3 | 4 | ### 2.2.2 - 2015-10-02 5 | * Fixed bug where swf would return prototype properties of storage object instead of correctly returning `null` #35 6 | 7 | ### 2.2.1 - 2015-08-05 8 | * Ensure library is always a global regardless of UMD (required for communication with flash) 9 | 10 | ### 2.2.0 - 2015-08-04 11 | * Fixed bugs when namespace contains multiple slashes 12 | * Ensured onerror callback is always given an Error object with a useful message 13 | * Adding UMD for requireJS/Browserfy/etc. 14 | * Added to npm registry for browserify support 15 | * Removed "javascript" from library name 16 | 17 | ### 2.1.0 - 2014-12-17 18 | * Modified SWF to check for new values at every read - see https://github.com/nfriedly/Javascript-Flash-Cookies/pull/29 & https://github.com/nfriedly/Javascript-Flash-Cookies/issues/24 19 | 20 | ### 2.0.2 - 2014-12-11 21 | * Added support for forward slashes (/) in the namespace - https://github.com/nfriedly/Javascript-Flash-Cookies/pull/28 22 | * Testing improvements in progress, but automated tests are currently broken 23 | 24 | ### 2.0.1 - 2014-11-12 25 | * Updated bower name to conform to url-friendly requirement 26 | 27 | ### 2.0.0 - 2014-11-12 28 | 29 | Breaking changes: 30 | * Removed version number from JS 31 | * Removed LSOPath and LSOName params - they were buggy and unused. Path is fixed to / and LSOName is forced to namespace. fixes https://github.com/nfriedly/Javascript-Flash-Cookies/issues/22 32 | 33 | Other Changes 34 | * Moved compiled files to dist/ 35 | * Automated testing on saucelabs 36 | * Automated .swf compiling with Apache Flex 37 | * Moved compiled files to dist/ 38 | * Added a clearAll() method 39 | * Fixed https://github.com/nfriedly/Javascript-Flash-Cookies/issues/21 40 | * Stopped letting `console` pollyfill leak into global scope 41 | * Fixed bug where `set(key, null)` does nothing 42 | * Listed in bower 43 | 44 | ### 1.9.1 - 2014-04-28 45 | * Fixed a XSS vulnerability 46 | * Small changes to Gruntfile to make testing easier 47 | * Switched to semver 48 | 49 | ### 1.9 - 2013-08-30 50 | * Refactored the ActionScript to call flush after both setValue and clearValue (fixes issue #18/#19) 51 | 52 | ### 1.8 - 2012-03-27 53 | * Added support for setting the LSOPath to allow other .swf files to read & write SwfStore's objects 54 | 55 | ### 1.7 - 2012-02-14 56 | 57 | * Updated JS to use https links to download flashplayer (fixes issue #13) 58 | * Converted readme to markdown 59 | 60 | ### 1.6 - 2011-09-13 61 | 62 | * Added a minified js file 63 | * Clarified readme somewhat 64 | * No code changes 65 | 66 | ### 1.5 - 2011-04-05 67 | 68 | * Added Security.allowInsecureDomain("*") to the flash file to allow it to work between http and https urls 69 | 70 | ### 1.4 - 2011-04-04 71 | 72 | * Added .clear(key) support to js to delete keys from flash 73 | * Removed prototype check from JS, and combined all .ready checks into a single _checkReady() function 74 | * Renamed a few items in the SWF to be more consistent 75 | * Changed the style.display.top to -2000px for the swf container when debug is off because at 0px it was affecting popup windows. 76 | * Fixed several namespace-related bugs in both JS and the swf; previously the swf had *always* been using the "SwfStore" namespace reguardless of the JS 77 | * Added sane defaults & reworked how the config is handled 78 | * Now throws an error if two instances are initialized with the same namespace 79 | * Added "use strict"; 80 | * Tweaked JS to pass http://jslint.org/ 81 | * getAll() function does not include the __FlashBugFix value that was added in 1.2 82 | 83 | ### 1.3 - 2011-04-04 84 | 85 | * Fixed two bugs that were coluding together to hide eachother: 86 | * The JS getAll() function was actually calling the getValue() flash function. 87 | * The Flash getAllValues() function had a typo in it that would have thrown an error if it were called. 88 | 89 | ### 1.2 - 2011-03-08 90 | 91 | * Fixed Isssue 11: JS now immediately stores a dummy value in the flashcookie to work around Flashplayers bug where it sometimes deletes cookies that it thinks are not in use but actually are. 92 | * Updated demo and example to reflect change 93 | * Tweaked the logger to use the given log level if the console supports it 94 | * Added a little bit of explanatory info to the example html file. 95 | 96 | ### 1.1 - 2011-01-01 97 | 98 | * Fixed Issue 9: JS now forces .swf onready callback to wait until JS has finished initializing if it fires first. 99 | * Fixed Issue 10: fallback logger now works properly and appends log to bottom of page if no console is found. 100 | * Added version number to library 101 | * Found issue in FlashPlayer where flash cookies can be deleted if two tabs are open, a flash cookie is created in one, then the other is refreshed. Workaround: open only one tab initially. 102 | 103 | ### 1.0 - 2010-09-01 104 | 105 | * Added getAll() function to read all cookies 106 | * Added more inline documentation 107 | 108 | ### 0.7 - 2010-08-26 109 | 110 | * Added live examples 111 | 112 | ### 0.6 - 2010-07-20 113 | 114 | * Fixed Issue 1: Added JS library 115 | * Fixed Issue 3: Added example to source 116 | 117 | ### 0.5 - 2010-07-13 118 | 119 | * Initial commit: included .swf file, readme, and MIT license 120 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "flash-cookies", 3 | "version": "2.2.3", 4 | "description": "JavaScript library and .swf for cross-domain flash cookies. ~4kb total when minified and gzipped.", 5 | "main": "dist/swfstore.min.js", 6 | "scripts": { 7 | "test": "grunt test" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git://github.com/nfriedly/Javascript-Flash-Cookies.git" 12 | }, 13 | "author": "Nathan Friedly - http://nfriedly.com", 14 | "license": "MIT", 15 | "bugs": { 16 | "url": "https://github.com/nfriedly/Javascript-Flash-Cookies/issues" 17 | }, 18 | "homepage": "https://github.com/nfriedly/Javascript-Flash-Cookies", 19 | "devDependencies": { 20 | "grunt": "^0.4.5", 21 | "grunt-cli": "^0.1.13", 22 | "grunt-contrib-connect": "^0.11.2", 23 | "grunt-contrib-jshint": "^0.11.3", 24 | "grunt-contrib-uglify": "^0.9.2", 25 | "grunt-jsbeautifier": "^0.2.10", 26 | "grunt-newer": "^1.1.1", 27 | "grunt-saucelabs": "^8.6.1", 28 | "grunt-swf": "^1.0.2", 29 | "lodash": "^3.10.1" 30 | }, 31 | "keywords": [ 32 | "javascript", 33 | "flash", 34 | "cookie", 35 | "cookies", 36 | "cross-domain", 37 | "flashcookies", 38 | "swf", 39 | "browserify" 40 | ], 41 | "ignore": [ 42 | "bower_components", 43 | "flex-sdk", 44 | "node_modules", 45 | "src", 46 | "tests", 47 | ".gitignore", 48 | ".jshintrc", 49 | ".travis.yml", 50 | "Gruntfile.js", 51 | "package.json" 52 | ] 53 | } 54 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | SwfStore 2 | ======= 3 | 4 | SwfStore is a JavaScript library for cross-domain flash cookies. It includes a .swf file that handles the 5 | storage and a JavaScript interface for loading and communicating with the flash file. 6 | 7 | Working example: https://nfriedly.github.io/Javascript-Flash-Cookies/ and http://nfriedly.com/stuff/swfstore-example/ 8 | 9 | [![Bower package](http://badge.fury.io/bo/javascript-flash-cookies.svg)](http://bower.io/search/?q=flash%20cookies) 10 | [![Build Status](https://travis-ci.org/nfriedly/Javascript-Flash-Cookies.svg?branch=master)](https://travis-ci.org/nfriedly/Javascript-Flash-Cookies) 11 | 12 | --- 13 | 14 | Security Warning 15 | ---------------- 16 | 17 | The default storage.swf allows any website to read the data in your flash file. You should avoid storing private 18 | information in it. It would be wise to edit and recompile the flash file to limit itself to your domain and http/https settings. (See [src/Storage.as around line 93](https://github.com/nfriedly/Javascript-Flash-Cookies/blob/master/src/Storage.as#L93).) 19 | You can do this yourself with Adobe Flash or the Apache Flex SDK (free) or I can do it for you for $5 - email me for details. 20 | 21 | Also, versions older than 1.9.1 are vulnerable to a XSS attack and should not be used. 22 | 23 | 24 | Compatibility 25 | -------------- 26 | 27 | [![Selenium Test Status (It also should work in older IE and Safari's, but the tests don't.)](https://saucelabs.com/browser-matrix/jsfc.svg)](https://saucelabs.com/u/jsfc) 28 | 29 | Requires Flash Player 9.0.31.0 or newer. Should be compatable with nearly all desktop browsers, assuming the user has Adobe Flash installed (or it's Google Chrome, which has flash player built in). Very few mobile browsers/devices support flash. 30 | 31 | 32 | Installation 33 | ------------- 34 | 35 | Via [Bower](http://bower.io/): 36 | 37 | bower install --save flash-cookies 38 | 39 | Or install via [npm](https://npmjs.com/) (for use with [browserify](https://www.npmjs.com/package/browserify): 40 | 41 | npm install --save flash-cookies 42 | 43 | 44 | 45 | Usage Notes 46 | ----------- 47 | 48 | Ensure that the `storage.swf` file is available, Browserify won't make it public by default. 49 | 50 | Certain built-in keys such as `hasOwnProperty` cannot be overwritten in actionscript. A future version may detect this and throw an error. 51 | 52 | Most mobile devices will not work due to lack of flash support. 53 | 54 | 55 | Basic Usage 56 | ----------- 57 | 58 | ```javascript 59 | // this should run on DOMReady, or at least after the opening tag has been parsed. 60 | var mySwfStore = new SwfStore({ 61 | namespace: "my_cool_app", 62 | swf_url: "//example.com/path/to/storage.swf", 63 | onready: function() { 64 | mySwfStore.set('key', 'value'); 65 | console.log('key is now set to ' + mySwfStore.get('key')); 66 | }, 67 | onerror: function(err) { 68 | console.error(err.message); 69 | } 70 | }); 71 | ``` 72 | 73 | A more thorough example is also available at http://nfriedly.com/techblog/2010/07/swf-for-javascript-cross-domain-flash-cookies/ 74 | 75 | Configuration options 76 | --------------------- 77 | 78 | * **`swf_url`**: URL to included `storage.swf` file. All sites/pages using SwfStore should have the exact same url here for cross-domain usage, and it should be a protocol-relative url (just // instead of http:// or https://) for cross-protocol usage. 79 | * **`namespace`**: Namespace used both internally for the JS object and for the LocalStorage Object (cookie). May contain forward slash (`/`) but all other special characters will be replaced with `_` 80 | * **`debug`**: Set to true to log debug information to the browser console (Automatically creates a logging `
` on the page if no console is available.) 81 | * **`timeout`**: Number of seconds to wait before concluding there was an error. Defaults to `10`. 82 | * **`onready`**: Callback function to fire once SwfStore is loaded and ready. No arguments. 83 | * **`onerror`**: Callback function to fire in the event of an error. Passes an `Error` object as the first argument. 84 | 85 | API 86 | --- 87 | 88 | Instance methods: 89 | 90 | * **`get(key)`**: Returns the value for `key` as a String or `null` if the key is not set. 91 | * **`set(key, value)`**: Sets `key` to `value`. 92 | * Note: setting a `key` to `null` or `undefined` is equivalent to `clear()`ing it. 93 | * **`clear(key)`**: Deletes the value for `key` if it exists. 94 | * **`getAll()`**: Returns a Object in the form of `{key: value}` with all data stored in the .swf. 95 | * **`clearAll()`**: Clears all data from the .swf. 96 | * **`ready`**: Boolean to indicate whether or not the .swf has loaded and is ready for access. 97 | * Note: providing an `onready` callback to the config is recommended over checking the `.ready` property. 98 | 99 | Troubleshooting 100 | --------------- 101 | * Be sure the urls to the .swf file and .js file are both correct. 102 | * If the .swf file is unable to communicate with the JavaScript, it will display log messages on the flash object. If debug is enabled, this should be visible on the page. 103 | * To hide the flash object and disable the log messages appending to the bottom of the page, set `debug: false` in the configuration options. (Log messages are added to a `
` if no browser `console` is available). 104 | * If the user does not have flash installed, the onerror function will be called after a (configurable) 10 second timeout. You may want to use a library such as [Flash Detect](http://www.featureblend.com/javascript-flash-detection-library.html) to check for this more quickly. Flash Player 9.0.31.0 or newer is required. 105 | * If you pass a non-string data as the key or value, things may break. Your best bet is to use strings and/or use JSON to encode objects as strings. 106 | * If you see the error `uncaught exception: Error in Actionscript. Use a try/catch block to find error., try using // in the .swf URL rather than https://. See https://github.com/nfriedly/Javascript-Flash-Cookies/issues/14 for more information. 107 | * Do not set display:none on the swf or any of its parent elements, this will cause the file to not render and the timeout will be fired. Disable debug and it will be rendered off screen. 108 | * The error this.swf.set is not a function has been known to occur when the FlashFirebug plugin is enabled in Firefox / Firebug. 109 | * This library is not sutable for storing large amounts of data because the .swf is normally rendered off screen and thus there is no way for the user to respond to Flash's prompt to increase the storage limit. 110 | 111 | 112 | File Details 113 | ------------ 114 | 115 | storage.swf is the compiled flash file ready to be embedded in your website. Note the security warning above. 116 | 117 | swfstore.min.js - a copy of swfstore.js, minified for your convenience. This and a copy of storage.swf should 118 | be all you need to use this on a production website. 119 | 120 | swfstore.js handles the interaction between javascrpt and flash, it also handles embedding and some basic error 121 | checking. 122 | 123 | Storage.as is where all the magic happens. It maps an External Interface to a Local Storage Object. I'm no expert when it comes to Flash / ActionScript, but it should be reasonably well documented and fairly safe. 124 | 125 | The storage.fla is essentially just an empty shell file that points to Storage.as as it's main class. 126 | 127 | See example/index.html for a working example that you can put on your site. 128 | 129 | Compiling 130 | --------- 131 | 132 | ### .js 133 | This project uses [UglifyJS2](https://github.com/mishoo/UglifyJS2) via the [Grunt](http://gruntjs.com/) plugin. Setup: 134 | 135 | * Install [Node.js](http://nodejs.org/) 136 | * Install Grunt globally: `npm install -g grunt` 137 | * `cd` into the project directory and install the dependencies: `npm install` 138 | * Run `grunt uglify` to "compile" (minify) the JavaScript. 139 | 140 | ### .swf 141 | This .swf can be compiled using Adobe Flash (paid) or the Apache Flex SDK (free). 142 | 143 | With Adobe Flash, open `src/storage.fla` and export it to `dist/storage.swf` 144 | 145 | Grunt is set up to use Apache Flex via the [grunt-swf](https://github.com/nfriedly/grunt-swf) plugin. 146 | The plugin is installed via the standard `npm install` but the SDK must be installed separately. 147 | 148 | See `flex-sdk/instructions.md` or https://github.com/nfriedly/grunt-swf#installing-the-apache-flex-sdk for more details on installing the Flex SDK. 149 | 150 | Then run `grunt swf` to compile the .swf. 151 | 152 | Tip: `grunt build` will compile both the .js and the .swf. 153 | 154 | (Note: on Windows, Git Bash may give better results than the windows command prompt.) 155 | 156 | Contributors 157 | ------------ 158 | * Nathan Friedly - http://nfriedly.com 159 | * Alexandre Mercier - https://twitter.com/alemercier 160 | * Andy Garbutt - https://twitter.com/techsplicer 161 | 162 | 163 | Release process 164 | --------------- 165 | * Update the the changelog in the readme 166 | * Compile anything that's changed (see the Compiling section above) 167 | * Commit everything 168 | * Run `npm version [major | minor | patch ]` with the appropriate flag (Ssee http://semver.org/ for details) 169 | * Push to Github - Travis CI will automatically run tests and publish when appropriate 170 | 171 | 172 | To Do 173 | ----- 174 | * Figure out how to run automated cross-domain & cross-protocol tests 175 | * update demo 176 | * Make automated tests less flakey 177 | * Look into http://karma-runner.github.io/ or http://theintern.io/ or similar to automate local testing. 178 | * Sourcemap 179 | 180 | Changelog 181 | --------- 182 | 183 | See [history.md](./history.md) 184 | 185 | MIT License 186 | ----------- 187 | 188 | Copyright (c) 2010 by Nathan Friedly - http://nfriedly.com 189 | 190 | Permission is hereby granted, free of charge, to any person obtaining a copy 191 | of this software and associated documentation files (the "Software"), to deal 192 | in the Software without restriction, including without limitation the rights 193 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 194 | copies of the Software, and to permit persons to whom the Software is 195 | furnished to do so, subject to the following conditions: 196 | 197 | The above copyright notice and this permission notice shall be included in 198 | all copies or substantial portions of the Software. 199 | 200 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 201 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 202 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 203 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 204 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 205 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 206 | THE SOFTWARE. 207 | -------------------------------------------------------------------------------- /src/Storage.as: -------------------------------------------------------------------------------- 1 | /** 2 | * SwfStore - a JavaScript library for cross-domain flash cookies 3 | * 4 | * http://github.com/nfriedly/Javascript-Flash-Cookies 5 | * 6 | * Copyright (c) 2010 by Nathan Friedly - Http://nfriedly.com 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | package { 28 | 29 | import flash.display.Sprite; 30 | import flash.display.Stage; 31 | import flash.events.*; 32 | import flash.external.ExternalInterface; 33 | import flash.text.TextField; 34 | import flash.system.Security; 35 | import flash.net.SharedObject; 36 | import flash.net.SharedObjectFlushStatus; 37 | 38 | public class Storage extends Sprite { 39 | 40 | /** 41 | * The JS callback functions should all be on a global variable at SwfStore.. 42 | */ 43 | private var jsNamespace:String = "SwfStore.swfstore."; 44 | 45 | /** 46 | * Namespace portion provided by JS is tested against this to avoid XSS 47 | */ 48 | private var namespaceCheck:RegExp = /^[a-z0-9_\/]+$/i; 49 | 50 | /** 51 | * Text field used by local logging 52 | */ 53 | private var logText:TextField; 54 | 55 | /** 56 | * Constructor, sets up everything and logs any errors. 57 | * Call this automatically by setting Publish > Class tp "Storage" in your .fla properties. 58 | * 59 | * If javascript is unable to access this object and not receiving any log messages (at wh 60 | */ 61 | public function Storage() { 62 | // Make sure we can talk to javascript at all 63 | if (!ExternalInterface.available) { 64 | localLog("External Interface is not available! (No communication with JavaScript.) Exiting."); 65 | return; 66 | } 67 | ExternalInterface.marshallExceptions = true; // try to pass errors to JS and capture errors from JS 68 | 69 | if (this.loaderInfo.parameters.namespace && !namespaceCheck.test(this.loaderInfo.parameters.namespace)) { 70 | localLog("Invalid namespace, disabling"); 71 | return; 72 | } 73 | 74 | // since even logging involves communicating with javascript, 75 | // the next thing to do is find the external log function 76 | if (this.loaderInfo.parameters.namespace) { 77 | jsNamespace = "SwfStore['" + this.loaderInfo.parameters.namespace+ "']."; 78 | } 79 | 80 | log('Initializing...'); 81 | 82 | // This is necessary to work cross-domain 83 | // Ideally you should add only the domains that you need, for example 84 | // Security.allowDomain("nfriedly.com", "www.nfriedly.com"); 85 | // and then comment the allowInsecureDomain line. 86 | // More information: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/system/Security.html#allowDomain%28%29 87 | Security.allowDomain("*"); 88 | Security.allowInsecureDomain("*"); 89 | 90 | // try to initialize our lso 91 | try { 92 | var dataStore:SharedObject = SharedObject.getLocal(this.loaderInfo.parameters.namespace); 93 | } catch (error:Error) { 94 | // user probably unchecked their "allow third party data" in their global flash settings 95 | onError('Unable to create a local shared object: ' + error.message); 96 | return; 97 | } 98 | 99 | try { 100 | // expose our external interface 101 | ExternalInterface.addCallback("set", setValue); 102 | ExternalInterface.addCallback("get", getValue); 103 | ExternalInterface.addCallback("getAll", getAllValues); 104 | ExternalInterface.addCallback("clear", clearValue); 105 | 106 | // There is a bug in flash player where if no values have been saved and the page is 107 | // then refreshed, the flashcookie gets deleted - even if another tab *had* saved a 108 | // value to the flashcookie. 109 | // So to fix, we immediately save something 110 | this.setValue('__flashBugFix', '1'); 111 | 112 | log('Ready! Firing onload...'); 113 | 114 | ExternalInterface.call(jsNamespace + "onload"); 115 | 116 | } catch (error:SecurityError) { 117 | onError("A SecurityError occurred: " + error.message); 118 | } catch (error:Error) { 119 | onError("An Error occurred: " + error.message); 120 | } 121 | } 122 | 123 | /** 124 | * Attempts to notify JS when there was an error during initialization 125 | */ 126 | private function onError(errStr:String):void { 127 | try { 128 | localLog(errStr); 129 | if (ExternalInterface.available) { 130 | ExternalInterface.call(jsNamespace + "onerror", errStr); 131 | } 132 | } catch (error:Error) { 133 | localLog('Error attempting to fire JS onerror callback:' + error.message); 134 | } 135 | } 136 | 137 | /** 138 | * Saves the data to the LSO, and then flushes it to the disk 139 | * 140 | * @param {string} key 141 | * @param {string} value - Expects a string. Objects will be converted to strings, functions tend to cause problems. 142 | */ 143 | private function setValue(key:String, val:*):void { 144 | try { 145 | if (typeof val != "string") { 146 | val = val.toString(); 147 | } 148 | var dataStore:SharedObject = SharedObject.getLocal(this.loaderInfo.parameters.namespace); 149 | 150 | log('Setting ' + key + '=' + val); 151 | dataStore.data[key] = val; 152 | flush(dataStore); 153 | } catch (error:Error) { 154 | onError('Unable to save data: ' + error.message); 155 | } 156 | } 157 | 158 | /** 159 | * Reads and returns data from the LSO 160 | */ 161 | private function getValue(key:String):String { 162 | try { 163 | var dataStore:SharedObject = SharedObject.getLocal(this.loaderInfo.parameters.namespace); 164 | 165 | log('Reading ' + key); 166 | 167 | if (dataStore.data.hasOwnProperty(key)) { 168 | 169 | var val:String = dataStore.data[key]; 170 | 171 | return val; 172 | 173 | } else 174 | return null; 175 | 176 | } catch (error:Error) { 177 | onError('Unable to read data: ' + error.message); 178 | } 179 | return null; 180 | } 181 | 182 | /** 183 | * Deletes an item from the LSO 184 | */ 185 | private function clearValue(key:String):void { 186 | try { 187 | log("Deleting " + key); 188 | var dataStore:SharedObject = SharedObject.getLocal(this.loaderInfo.parameters.namespace); 189 | delete dataStore.data[key]; 190 | flush(dataStore); 191 | } catch (error:Error) { 192 | onError("Error deleting key: " + error.message); 193 | } 194 | } 195 | 196 | /** 197 | * This retrieves all stored data 198 | */ 199 | private function getAllValues():Array { 200 | var dataStore:SharedObject = SharedObject.getLocal(this.loaderInfo.parameters.namespace); 201 | 202 | var pairs:Array = new Array(); 203 | for (var key:String in dataStore.data) { 204 | if (key != "__flashBugFix") { 205 | // Flash has (another) bug where string keys that start with numbers are sent to JS without quotes. JS then fails to parse this because it's not valid JSON 206 | // https://github.com/nfriedly/Javascript-Flash-Cookies/issues/21 207 | var pair:Object = { 208 | key: key, 209 | value: dataStore.data[key] 210 | }; 211 | pairs.push(pair); 212 | } 213 | } 214 | return pairs; 215 | } 216 | 217 | /** 218 | * Flushes changes to the dataStore 219 | */ 220 | private function flush(dataStore:SharedObject):void { 221 | var flushStatus:String = null; 222 | try { 223 | flushStatus = dataStore.flush(10000); 224 | } catch (error:Error) { 225 | onError("Unable to write SharedObject to disk: " + error.message); 226 | } 227 | 228 | if (flushStatus != null) { 229 | switch (flushStatus) { 230 | case SharedObjectFlushStatus.PENDING: 231 | log("Requesting permission to save object..."); 232 | dataStore.addEventListener(NetStatusEvent.NET_STATUS, onFlushStatus); 233 | break; 234 | case SharedObjectFlushStatus.FLUSHED: 235 | // don't really need another message when everything works right 236 | //log("Value flushed to disk."); 237 | break; 238 | } 239 | } 240 | } 241 | 242 | /** 243 | * This happens if the user is prompted about saving locally 244 | */ 245 | private function onFlushStatus(event:NetStatusEvent):void { 246 | log("User closed permission dialog..."); 247 | switch (event.info.code) { 248 | case "SharedObject.Flush.Success": 249 | log("User granted permission -- value saved."); 250 | break; 251 | case "SharedObject.Flush.Failed": 252 | log("User denied permission -- value not saved."); 253 | break; 254 | } 255 | 256 | var dataStore:SharedObject = SharedObject.getLocal(this.loaderInfo.parameters.namespace); 257 | dataStore.removeEventListener(NetStatusEvent.NET_STATUS, onFlushStatus); 258 | } 259 | 260 | /** 261 | * Attempts to log messages to the supplied javascript logFn, 262 | * if that fails it passes them to localLog() 263 | */ 264 | private function log(str:String):void { 265 | try { 266 | ExternalInterface.call(jsNamespace + "log", 'debug', 'swfStore', str); 267 | } catch (error:Error) { 268 | localLog("Error logging to js: " + error.toString() + " - Original message was: " + str); 269 | } 270 | } 271 | 272 | /** 273 | * Last-resort logging used when communication with javascript fails or isn't avaliable. 274 | * The messages should appear in the flash object, but they might not be pretty. 275 | */ 276 | private function localLog(str:String):void { 277 | // We can't talk to javascript for some reason. 278 | // Attempt to show this to the user (normally this swf is hidden off screen, so regular users shouldn't see it) 279 | if (!logText) { 280 | // create the text field if it doesn't exist yet 281 | logText = new TextField(); 282 | logText.width = 450; // I suspect there's a way to do "100%"... 283 | addChild(logText); 284 | } 285 | logText.appendText(str + "\n"); 286 | } 287 | } 288 | } 289 | -------------------------------------------------------------------------------- /src/storage.fla: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nfriedly/Javascript-Flash-Cookies/2621f029e765be4a835a6ef0ad789a54a49cbd3c/src/storage.fla -------------------------------------------------------------------------------- /src/swfstore.js: -------------------------------------------------------------------------------- 1 | /** 2 | * SwfStore - a JavaScript library for cross-domain flash cookies 3 | * 4 | * http://github.com/nfriedly/Javascript-Flash-Cookies 5 | * 6 | * Copyright (c) 2010 by Nathan Friedly - http://nfriedly.com 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in 16 | * all copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | * THE SOFTWARE. 25 | */ 26 | 27 | /*jslint browser: true, devel: true, vars: true, white: true, nomen: true, plusplus: true, regexp: true */ 28 | /*globals define:false, module:false */ 29 | 30 | (function() { 31 | 32 | "use strict"; // http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/ 33 | 34 | var counter = 0; // a counter for element id's and whatnot 35 | 36 | var reNamespace = /[^a-z0-9_\/]/ig; //a regex to find anything that's not letters, numbers underscore and forward slash 37 | var reId = /[^a-z0-9_]/ig; // same as above except no forward slashes 38 | /** 39 | * SwfStore constructor - creates a new SwfStore object and embeds the .swf into the web page. 40 | * 41 | * usage: 42 | * var mySwfStore = new SwfStore({ 43 | * namespace: "my_cool_app", 44 | * swf_url: "http://example.com/path/to/storage.swf", 45 | * onready: function() { 46 | * console.log('ready!', mySwfStore.get('my_key')); 47 | * }, 48 | * onerror: function() { 49 | * console.error('swfStore failed to load :('); 50 | * } 51 | * }); 52 | * 53 | * @param {object} config 54 | * @param {string} [config.swf_url=storage.swf] - Url to storage.swf. Must be an absolute url (with http:// and all) to work cross-domain 55 | * @param {functon} [config.onready] Callback function that is fired when the SwfStore is loaded. Recommended. 56 | * @param {function} [config.onerror] Callback function that is fired if the SwfStore fails to load. Recommended. 57 | * @param {string} [config.namespace="swfstore"] The namespace to use in both JS and the SWF. Allows a page to have more than one instance of SwfStore. 58 | * @param {integer} [config.timeout=10] The number of seconds to wait before assuming the user does not have flash. 59 | * @param {boolean} [config.debug=false] Is debug mode enabled? If so, mesages will be logged to the console and the .swf will be rendered on the page (although it will be an empty white box unless it cannot communicate with JS. Then it will log errors to the .swf) 60 | */ 61 | function SwfStore(config) { 62 | // make sure we have something of a configuration 63 | config = config || {}; 64 | var defaults = { 65 | swf_url: 'storage.swf', // this should be a complete protocol-relative url (//example.com/path/to/storage.swf) for cross-domain, cross-protocol usage 66 | namespace: 'swfstore', 67 | debug: false, 68 | timeout: 10, // number of seconds to wait before concluding there was an error 69 | onready: null, 70 | onerror: null 71 | }; 72 | var key; 73 | for (key in defaults) { 74 | if (defaults.hasOwnProperty(key)) { 75 | if (!config.hasOwnProperty(key)) { 76 | config[key] = defaults[key]; 77 | } 78 | } 79 | } 80 | config.namespace = config.namespace.replace(reNamespace, '_'); 81 | 82 | if (window.SwfStore[config.namespace]) { 83 | throw "There is already an instance of SwfStore using the '" + config.namespace + "' namespace. Use that instance or specify an alternate namespace in the config."; 84 | } 85 | 86 | this.config = config; 87 | 88 | // a couple of basic timesaver functions 89 | function id() { 90 | return "SwfStore_" + config.namespace.replace(reId, "_") + "_" + (counter++); 91 | } 92 | 93 | function div(visible) { 94 | var d = document.createElement('div'); 95 | document.body.appendChild(d); 96 | d.id = id(); 97 | if (!visible) { 98 | // setting display:none causes the .swf to not render at all 99 | d.style.position = "absolute"; 100 | d.style.top = "-2000px"; 101 | d.style.left = "-2000px"; 102 | } 103 | return d; 104 | } 105 | 106 | // get a logger ready 107 | // if we're in a browser that doesn't have a console, build one 108 | if (typeof console === "undefined") { 109 | var loggerOutput = div(true); 110 | this.console = { 111 | log: function(msg) { 112 | var m = div(true); 113 | m.innerHTML = msg; 114 | loggerOutput.appendChild(m); 115 | } 116 | }; 117 | } else { 118 | this.console = console; 119 | } 120 | this.log = function(type, source, msg) { 121 | if (config.debug) { 122 | // only output to log if debug is currently enabled 123 | source = (source === 'swfStore') ? 'swf' : source; 124 | if (typeof(this.console[type]) !== "undefined") { 125 | this.console[type]('SwfStore - ' + config.namespace + ' (' + source + '): ' + msg); 126 | } else { 127 | this.console.log('SwfStore - ' + config.namespace + ": " + type + ' (' + source + '): ' + msg); 128 | } 129 | } 130 | }; 131 | 132 | this.log('info', 'js', 'Initializing...'); 133 | 134 | // the callback functions that javascript provides to flash must be globally accessible 135 | SwfStore[config.namespace] = this; 136 | 137 | var swfContainer = div(config.debug); 138 | 139 | var swfName = id(); 140 | 141 | var flashvars = "namespace=" + encodeURIComponent(config.namespace); 142 | 143 | swfContainer.innerHTML = '' + 145 | ' ' + 146 | ' ' + 147 | ' ' + 148 | ' ' + 151 | ''; 152 | 153 | this.swf = document[swfName] || window[swfName]; 154 | 155 | this._timeout = setTimeout(function() { 156 | SwfStore[config.namespace].onerror(new Error(config.swf_url + ' failed to load within ' + config.timeout + ' seconds.'), 'js'); 157 | }, config.timeout * 1000); 158 | } 159 | 160 | // we need to check everything we send to flash because it can't take functions as arguments 161 | function checkData(data) { 162 | if (typeof data === "function") { 163 | throw new Error('SwfStore Error: Functions cannot be used as keys or values.'); 164 | } 165 | } 166 | 167 | SwfStore.prototype = { 168 | 169 | /** 170 | * This is an indicator of whether or not the SwfStore is initialized. 171 | * Use the onready and onerror config options rather than checking this variable. 172 | */ 173 | ready: false, 174 | 175 | /** 176 | * Sets the given key to the given value in the swf 177 | * @param {string} key 178 | * @param {string} value 179 | */ 180 | set: function(key, value) { 181 | this._checkReady(); 182 | checkData(key); 183 | checkData(value); 184 | if (value === null || typeof value == "undefined") { 185 | this.swf.clear(key); 186 | } else { 187 | this.swf.set(key, value); 188 | } 189 | }, 190 | 191 | /** 192 | * Retrieves the specified value from the swf. 193 | * @param {string} key 194 | * @return {string} value 195 | */ 196 | get: function(key) { 197 | this._checkReady(); 198 | checkData(key); 199 | //this.log('debug', 'js', 'Reading ' + key); 200 | return this.swf.get(key); 201 | }, 202 | 203 | /** 204 | * Retrieves all stored values from the swf. 205 | * @return {object} 206 | */ 207 | getAll: function() { 208 | this._checkReady(); 209 | var pairs = this.swf.getAll(); 210 | var data = {}; 211 | for (var i = 0, len = pairs.length, pair; i < len; i++) { 212 | pair = pairs[i]; 213 | data[pair.key] = pair.value; 214 | } 215 | return data; 216 | }, 217 | 218 | clearAll: function() { 219 | var all = this.getAll(); 220 | for (var key in all) { 221 | if (all.hasOwnProperty(key)) { 222 | this.clear(key); 223 | } 224 | } 225 | }, 226 | 227 | /** 228 | * Delete the specified key from the swf 229 | * 230 | * @param {string} key 231 | */ 232 | clear: function(key) { 233 | this._checkReady(); 234 | checkData(key); 235 | this.swf.clear(key); 236 | }, 237 | 238 | /** 239 | * We need to run this check before tying to work with the swf 240 | * 241 | * @private 242 | */ 243 | _checkReady: function() { 244 | if (!this.ready) { 245 | throw 'SwfStore is not yet finished initializing. Pass a config.onready callback or wait until this.ready is true before trying to use a SwfStore instance.'; 246 | } 247 | }, 248 | 249 | /** 250 | * This is the function that the swf calls to announce that it has loaded. 251 | * This function in turn fires the onready function if provided in the config. 252 | * 253 | * @private 254 | */ 255 | onload: function() { 256 | // deal with scope the easy way 257 | var that = this; 258 | // wrapping everything in a timeout so that the JS can finish initializing first 259 | // (If the .swf is cached in IE, it fires the callback *immediately* before JS has 260 | // finished executing. setTimeout(function, 0) fixes that) 261 | setTimeout(function() { 262 | clearTimeout(that._timeout); 263 | that.ready = true; 264 | 265 | //this.log('info', 'js', 'Ready!') 266 | if (that.config.onready) { 267 | that.config.onready(); 268 | } 269 | }, 0); 270 | }, 271 | 272 | 273 | /** 274 | * If the swf had an error but is still able to communicate with JavaScript, it will call this function. 275 | * This function is also called if the time limit is reached and flash has not yet loaded. 276 | * This function is most commonly called when either flash is not installed or local storage has been disabled. 277 | * If an onerror function was provided in the config, this function will fire it. 278 | * 279 | * @private 280 | */ 281 | onerror: function(err, source) { 282 | clearTimeout(this._timeout); 283 | if (!(err instanceof Error)) { 284 | err = new Error(err); 285 | } 286 | this.log('error', source || 'swf', err.message); 287 | if (this.config.onerror) { 288 | this.config.onerror(err); 289 | } 290 | } 291 | }; 292 | 293 | // UMD for working with requirejs / browserify 294 | if (typeof define === 'function' && define.amd) { 295 | // AMD. Register as an anonymous module. 296 | define([], SwfStore); 297 | } else if (typeof module === 'object' && module.exports) { 298 | // Browserify 299 | module.exports = SwfStore; 300 | } 301 | 302 | // reguardless of UMD, SwfStore must be a global for flash to communicate with it 303 | window.SwfStore = SwfStore; 304 | 305 | }()); 306 | -------------------------------------------------------------------------------- /tests/lib/jasmine-2.0.3/boot.js: -------------------------------------------------------------------------------- 1 | /** 2 | Starting with version 2.0, this file "boots" Jasmine, performing all of the necessary initialization before executing the loaded environment and all of a project's specs. This file should be loaded after `jasmine.js`, but before any project source files or spec files are loaded. Thus this file can also be used to customize Jasmine for a project. 3 | 4 | If a project is using Jasmine via the standalone distribution, this file can be customized directly. If a project is using Jasmine via the [Ruby gem][jasmine-gem], this file can be copied into the support directory via `jasmine copy_boot_js`. Other environments (e.g., Python) will have different mechanisms. 5 | 6 | The location of `boot.js` can be specified and/or overridden in `jasmine.yml`. 7 | 8 | [jasmine-gem]: http://github.com/pivotal/jasmine-gem 9 | */ 10 | 11 | (function() { 12 | 13 | /** 14 | * ## Require & Instantiate 15 | * 16 | * Require Jasmine's core files. Specifically, this requires and attaches all of Jasmine's code to the `jasmine` reference. 17 | */ 18 | window.jasmine = jasmineRequire.core(jasmineRequire); 19 | 20 | /** 21 | * Since this is being run in a browser and the results should populate to an HTML page, require the HTML-specific Jasmine code, injecting the same reference. 22 | */ 23 | jasmineRequire.html(jasmine); 24 | 25 | /** 26 | * Create the Jasmine environment. This is used to run all specs in a project. 27 | */ 28 | var env = jasmine.getEnv(); 29 | 30 | /** 31 | * ## The Global Interface 32 | * 33 | * Build up the functions that will be exposed as the Jasmine public interface. A project can customize, rename or alias any of these functions as desired, provided the implementation remains unchanged. 34 | */ 35 | var jasmineInterface = jasmineRequire.interface(jasmine, env); 36 | 37 | /** 38 | * Add all of the Jasmine global/public interface to the proper global, so a project can use the public interface directly. For example, calling `describe` in specs instead of `jasmine.getEnv().describe`. 39 | */ 40 | if (typeof window == "undefined" && typeof exports == "object") { 41 | extend(exports, jasmineInterface); 42 | } else { 43 | extend(window, jasmineInterface); 44 | } 45 | 46 | /** 47 | * ## Runner Parameters 48 | * 49 | * More browser specific code - wrap the query string in an object and to allow for getting/setting parameters from the runner user interface. 50 | */ 51 | 52 | var queryString = new jasmine.QueryString({ 53 | getWindowLocation: function() { return window.location; } 54 | }); 55 | 56 | var catchingExceptions = queryString.getParam("catch"); 57 | env.catchExceptions(typeof catchingExceptions === "undefined" ? true : catchingExceptions); 58 | 59 | /** 60 | * ## Reporters 61 | * The `HtmlReporter` builds all of the HTML UI for the runner page. This reporter paints the dots, stars, and x's for specs, as well as all spec names and all failures (if any). 62 | */ 63 | var htmlReporter = new jasmine.HtmlReporter({ 64 | env: env, 65 | onRaiseExceptionsClick: function() { queryString.setParam("catch", !env.catchingExceptions()); }, 66 | getContainer: function() { return document.body; }, 67 | createElement: function() { return document.createElement.apply(document, arguments); }, 68 | createTextNode: function() { return document.createTextNode.apply(document, arguments); }, 69 | timer: new jasmine.Timer() 70 | }); 71 | 72 | /** 73 | * The `jsApiReporter` also receives spec results, and is used by any environment that needs to extract the results from JavaScript. 74 | */ 75 | env.addReporter(jasmineInterface.jsApiReporter); 76 | env.addReporter(htmlReporter); 77 | 78 | /** 79 | * Filter which specs will be run by matching the start of the full name against the `spec` query param. 80 | */ 81 | var specFilter = new jasmine.HtmlSpecFilter({ 82 | filterString: function() { return queryString.getParam("spec"); } 83 | }); 84 | 85 | env.specFilter = function(spec) { 86 | return specFilter.matches(spec.getFullName()); 87 | }; 88 | 89 | /** 90 | * Setting up timing functions to be able to be overridden. Certain browsers (Safari, IE 8, phantomjs) require this hack. 91 | */ 92 | window.setTimeout = window.setTimeout; 93 | window.setInterval = window.setInterval; 94 | window.clearTimeout = window.clearTimeout; 95 | window.clearInterval = window.clearInterval; 96 | 97 | /** 98 | * ## Execution 99 | * 100 | * Replace the browser window's `onload`, ensure it's called, and then run all of the loaded specs. This includes initializing the `HtmlReporter` instance and then executing the loaded Jasmine environment. All of this will happen after all of the specs are loaded. 101 | */ 102 | var currentWindowOnload = window.onload; 103 | 104 | window.onload = function() { 105 | if (currentWindowOnload) { 106 | currentWindowOnload(); 107 | } 108 | htmlReporter.initialize(); 109 | env.execute(); 110 | }; 111 | 112 | /** 113 | * Helper function for readability above. 114 | */ 115 | function extend(destination, source) { 116 | for (var property in source) destination[property] = source[property]; 117 | return destination; 118 | } 119 | 120 | }()); 121 | -------------------------------------------------------------------------------- /tests/lib/jasmine-2.0.3/console.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2008-2014 Pivotal Labs 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | function getJasmineRequireObj() { 24 | if (typeof module !== 'undefined' && module.exports) { 25 | return exports; 26 | } else { 27 | window.jasmineRequire = window.jasmineRequire || {}; 28 | return window.jasmineRequire; 29 | } 30 | } 31 | 32 | getJasmineRequireObj().console = function(jRequire, j$) { 33 | j$.ConsoleReporter = jRequire.ConsoleReporter(); 34 | }; 35 | 36 | getJasmineRequireObj().ConsoleReporter = function() { 37 | 38 | var noopTimer = { 39 | start: function(){}, 40 | elapsed: function(){ return 0; } 41 | }; 42 | 43 | function ConsoleReporter(options) { 44 | var print = options.print, 45 | showColors = options.showColors || false, 46 | onComplete = options.onComplete || function() {}, 47 | timer = options.timer || noopTimer, 48 | specCount, 49 | failureCount, 50 | failedSpecs = [], 51 | pendingCount, 52 | ansi = { 53 | green: '\x1B[32m', 54 | red: '\x1B[31m', 55 | yellow: '\x1B[33m', 56 | none: '\x1B[0m' 57 | }; 58 | 59 | this.jasmineStarted = function() { 60 | specCount = 0; 61 | failureCount = 0; 62 | pendingCount = 0; 63 | print('Started'); 64 | printNewline(); 65 | timer.start(); 66 | }; 67 | 68 | this.jasmineDone = function() { 69 | printNewline(); 70 | for (var i = 0; i < failedSpecs.length; i++) { 71 | specFailureDetails(failedSpecs[i]); 72 | } 73 | 74 | if(specCount > 0) { 75 | printNewline(); 76 | 77 | var specCounts = specCount + ' ' + plural('spec', specCount) + ', ' + 78 | failureCount + ' ' + plural('failure', failureCount); 79 | 80 | if (pendingCount) { 81 | specCounts += ', ' + pendingCount + ' pending ' + plural('spec', pendingCount); 82 | } 83 | 84 | print(specCounts); 85 | } else { 86 | print('No specs found'); 87 | } 88 | 89 | printNewline(); 90 | var seconds = timer.elapsed() / 1000; 91 | print('Finished in ' + seconds + ' ' + plural('second', seconds)); 92 | 93 | printNewline(); 94 | 95 | onComplete(failureCount === 0); 96 | }; 97 | 98 | this.specDone = function(result) { 99 | specCount++; 100 | 101 | if (result.status == 'pending') { 102 | pendingCount++; 103 | print(colored('yellow', '*')); 104 | return; 105 | } 106 | 107 | if (result.status == 'passed') { 108 | print(colored('green', '.')); 109 | return; 110 | } 111 | 112 | if (result.status == 'failed') { 113 | failureCount++; 114 | failedSpecs.push(result); 115 | print(colored('red', 'F')); 116 | } 117 | }; 118 | 119 | return this; 120 | 121 | function printNewline() { 122 | print('\n'); 123 | } 124 | 125 | function colored(color, str) { 126 | return showColors ? (ansi[color] + str + ansi.none) : str; 127 | } 128 | 129 | function plural(str, count) { 130 | return count == 1 ? str : str + 's'; 131 | } 132 | 133 | function repeat(thing, times) { 134 | var arr = []; 135 | for (var i = 0; i < times; i++) { 136 | arr.push(thing); 137 | } 138 | return arr; 139 | } 140 | 141 | function indent(str, spaces) { 142 | var lines = (str || '').split('\n'); 143 | var newArr = []; 144 | for (var i = 0; i < lines.length; i++) { 145 | newArr.push(repeat(' ', spaces).join('') + lines[i]); 146 | } 147 | return newArr.join('\n'); 148 | } 149 | 150 | function specFailureDetails(result) { 151 | printNewline(); 152 | print(result.fullName); 153 | 154 | for (var i = 0; i < result.failedExpectations.length; i++) { 155 | var failedExpectation = result.failedExpectations[i]; 156 | printNewline(); 157 | print(indent(failedExpectation.message, 2)); 158 | print(indent(failedExpectation.stack, 2)); 159 | } 160 | 161 | printNewline(); 162 | } 163 | } 164 | 165 | return ConsoleReporter; 166 | }; 167 | -------------------------------------------------------------------------------- /tests/lib/jasmine-2.0.3/jasmine-html.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2008-2014 Pivotal Labs 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | jasmineRequire.html = function(j$) { 24 | j$.ResultsNode = jasmineRequire.ResultsNode(); 25 | j$.HtmlReporter = jasmineRequire.HtmlReporter(j$); 26 | j$.QueryString = jasmineRequire.QueryString(); 27 | j$.HtmlSpecFilter = jasmineRequire.HtmlSpecFilter(); 28 | }; 29 | 30 | jasmineRequire.HtmlReporter = function(j$) { 31 | 32 | var noopTimer = { 33 | start: function() {}, 34 | elapsed: function() { return 0; } 35 | }; 36 | 37 | function HtmlReporter(options) { 38 | var env = options.env || {}, 39 | getContainer = options.getContainer, 40 | createElement = options.createElement, 41 | createTextNode = options.createTextNode, 42 | onRaiseExceptionsClick = options.onRaiseExceptionsClick || function() {}, 43 | timer = options.timer || noopTimer, 44 | results = [], 45 | specsExecuted = 0, 46 | failureCount = 0, 47 | pendingSpecCount = 0, 48 | htmlReporterMain, 49 | symbols; 50 | 51 | this.initialize = function() { 52 | clearPrior(); 53 | htmlReporterMain = createDom('div', {className: 'jasmine_html-reporter'}, 54 | createDom('div', {className: 'banner'}, 55 | createDom('a', {className: 'title', href: 'http://jasmine.github.io/', target: '_blank'}), 56 | createDom('span', {className: 'version'}, j$.version) 57 | ), 58 | createDom('ul', {className: 'symbol-summary'}), 59 | createDom('div', {className: 'alert'}), 60 | createDom('div', {className: 'results'}, 61 | createDom('div', {className: 'failures'}) 62 | ) 63 | ); 64 | getContainer().appendChild(htmlReporterMain); 65 | 66 | symbols = find('.symbol-summary'); 67 | }; 68 | 69 | var totalSpecsDefined; 70 | this.jasmineStarted = function(options) { 71 | totalSpecsDefined = options.totalSpecsDefined || 0; 72 | timer.start(); 73 | }; 74 | 75 | var summary = createDom('div', {className: 'summary'}); 76 | 77 | var topResults = new j$.ResultsNode({}, '', null), 78 | currentParent = topResults; 79 | 80 | this.suiteStarted = function(result) { 81 | currentParent.addChild(result, 'suite'); 82 | currentParent = currentParent.last(); 83 | }; 84 | 85 | this.suiteDone = function(result) { 86 | if (currentParent == topResults) { 87 | return; 88 | } 89 | 90 | currentParent = currentParent.parent; 91 | }; 92 | 93 | this.specStarted = function(result) { 94 | currentParent.addChild(result, 'spec'); 95 | }; 96 | 97 | var failures = []; 98 | this.specDone = function(result) { 99 | if(noExpectations(result) && console && console.error) { 100 | console.error('Spec \'' + result.fullName + '\' has no expectations.'); 101 | } 102 | 103 | if (result.status != 'disabled') { 104 | specsExecuted++; 105 | } 106 | 107 | symbols.appendChild(createDom('li', { 108 | className: noExpectations(result) ? 'empty' : result.status, 109 | id: 'spec_' + result.id, 110 | title: result.fullName 111 | } 112 | )); 113 | 114 | if (result.status == 'failed') { 115 | failureCount++; 116 | 117 | var failure = 118 | createDom('div', {className: 'spec-detail failed'}, 119 | createDom('div', {className: 'description'}, 120 | createDom('a', {title: result.fullName, href: specHref(result)}, result.fullName) 121 | ), 122 | createDom('div', {className: 'messages'}) 123 | ); 124 | var messages = failure.childNodes[1]; 125 | 126 | for (var i = 0; i < result.failedExpectations.length; i++) { 127 | var expectation = result.failedExpectations[i]; 128 | messages.appendChild(createDom('div', {className: 'result-message'}, expectation.message)); 129 | messages.appendChild(createDom('div', {className: 'stack-trace'}, expectation.stack)); 130 | } 131 | 132 | failures.push(failure); 133 | } 134 | 135 | if (result.status == 'pending') { 136 | pendingSpecCount++; 137 | } 138 | }; 139 | 140 | this.jasmineDone = function() { 141 | var banner = find('.banner'); 142 | banner.appendChild(createDom('span', {className: 'duration'}, 'finished in ' + timer.elapsed() / 1000 + 's')); 143 | 144 | var alert = find('.alert'); 145 | 146 | alert.appendChild(createDom('span', { className: 'exceptions' }, 147 | createDom('label', { className: 'label', 'for': 'raise-exceptions' }, 'raise exceptions'), 148 | createDom('input', { 149 | className: 'raise', 150 | id: 'raise-exceptions', 151 | type: 'checkbox' 152 | }) 153 | )); 154 | var checkbox = find('#raise-exceptions'); 155 | 156 | checkbox.checked = !env.catchingExceptions(); 157 | checkbox.onclick = onRaiseExceptionsClick; 158 | 159 | if (specsExecuted < totalSpecsDefined) { 160 | var skippedMessage = 'Ran ' + specsExecuted + ' of ' + totalSpecsDefined + ' specs - run all'; 161 | alert.appendChild( 162 | createDom('span', {className: 'bar skipped'}, 163 | createDom('a', {href: '?', title: 'Run all specs'}, skippedMessage) 164 | ) 165 | ); 166 | } 167 | var statusBarMessage = ''; 168 | var statusBarClassName = 'bar '; 169 | 170 | if (totalSpecsDefined > 0) { 171 | statusBarMessage += pluralize('spec', specsExecuted) + ', ' + pluralize('failure', failureCount); 172 | if (pendingSpecCount) { statusBarMessage += ', ' + pluralize('pending spec', pendingSpecCount); } 173 | statusBarClassName += (failureCount > 0) ? 'failed' : 'passed'; 174 | } else { 175 | statusBarClassName += 'skipped'; 176 | statusBarMessage += 'No specs found'; 177 | } 178 | 179 | alert.appendChild(createDom('span', {className: statusBarClassName}, statusBarMessage)); 180 | 181 | var results = find('.results'); 182 | results.appendChild(summary); 183 | 184 | summaryList(topResults, summary); 185 | 186 | function summaryList(resultsTree, domParent) { 187 | var specListNode; 188 | for (var i = 0; i < resultsTree.children.length; i++) { 189 | var resultNode = resultsTree.children[i]; 190 | if (resultNode.type == 'suite') { 191 | var suiteListNode = createDom('ul', {className: 'suite', id: 'suite-' + resultNode.result.id}, 192 | createDom('li', {className: 'suite-detail'}, 193 | createDom('a', {href: specHref(resultNode.result)}, resultNode.result.description) 194 | ) 195 | ); 196 | 197 | summaryList(resultNode, suiteListNode); 198 | domParent.appendChild(suiteListNode); 199 | } 200 | if (resultNode.type == 'spec') { 201 | if (domParent.getAttribute('class') != 'specs') { 202 | specListNode = createDom('ul', {className: 'specs'}); 203 | domParent.appendChild(specListNode); 204 | } 205 | var specDescription = resultNode.result.description; 206 | if(noExpectations(resultNode.result)) { 207 | specDescription = 'SPEC HAS NO EXPECTATIONS ' + specDescription; 208 | } 209 | specListNode.appendChild( 210 | createDom('li', { 211 | className: resultNode.result.status, 212 | id: 'spec-' + resultNode.result.id 213 | }, 214 | createDom('a', {href: specHref(resultNode.result)}, specDescription) 215 | ) 216 | ); 217 | } 218 | } 219 | } 220 | 221 | if (failures.length) { 222 | alert.appendChild( 223 | createDom('span', {className: 'menu bar spec-list'}, 224 | createDom('span', {}, 'Spec List | '), 225 | createDom('a', {className: 'failures-menu', href: '#'}, 'Failures'))); 226 | alert.appendChild( 227 | createDom('span', {className: 'menu bar failure-list'}, 228 | createDom('a', {className: 'spec-list-menu', href: '#'}, 'Spec List'), 229 | createDom('span', {}, ' | Failures '))); 230 | 231 | find('.failures-menu').onclick = function() { 232 | setMenuModeTo('failure-list'); 233 | }; 234 | find('.spec-list-menu').onclick = function() { 235 | setMenuModeTo('spec-list'); 236 | }; 237 | 238 | setMenuModeTo('failure-list'); 239 | 240 | var failureNode = find('.failures'); 241 | for (var i = 0; i < failures.length; i++) { 242 | failureNode.appendChild(failures[i]); 243 | } 244 | } 245 | }; 246 | 247 | return this; 248 | 249 | function find(selector) { 250 | return getContainer().querySelector('.jasmine_html-reporter ' + selector); 251 | } 252 | 253 | function clearPrior() { 254 | // return the reporter 255 | var oldReporter = find(''); 256 | 257 | if(oldReporter) { 258 | getContainer().removeChild(oldReporter); 259 | } 260 | } 261 | 262 | function createDom(type, attrs, childrenVarArgs) { 263 | var el = createElement(type); 264 | 265 | for (var i = 2; i < arguments.length; i++) { 266 | var child = arguments[i]; 267 | 268 | if (typeof child === 'string') { 269 | el.appendChild(createTextNode(child)); 270 | } else { 271 | if (child) { 272 | el.appendChild(child); 273 | } 274 | } 275 | } 276 | 277 | for (var attr in attrs) { 278 | if (attr == 'className') { 279 | el[attr] = attrs[attr]; 280 | } else { 281 | el.setAttribute(attr, attrs[attr]); 282 | } 283 | } 284 | 285 | return el; 286 | } 287 | 288 | function pluralize(singular, count) { 289 | var word = (count == 1 ? singular : singular + 's'); 290 | 291 | return '' + count + ' ' + word; 292 | } 293 | 294 | function specHref(result) { 295 | return '?spec=' + encodeURIComponent(result.fullName); 296 | } 297 | 298 | function setMenuModeTo(mode) { 299 | htmlReporterMain.setAttribute('class', 'jasmine_html-reporter ' + mode); 300 | } 301 | 302 | function noExpectations(result) { 303 | return (result.failedExpectations.length + result.passedExpectations.length) === 0 && 304 | result.status === 'passed'; 305 | } 306 | } 307 | 308 | return HtmlReporter; 309 | }; 310 | 311 | jasmineRequire.HtmlSpecFilter = function() { 312 | function HtmlSpecFilter(options) { 313 | var filterString = options && options.filterString() && options.filterString().replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'); 314 | var filterPattern = new RegExp(filterString); 315 | 316 | this.matches = function(specName) { 317 | return filterPattern.test(specName); 318 | }; 319 | } 320 | 321 | return HtmlSpecFilter; 322 | }; 323 | 324 | jasmineRequire.ResultsNode = function() { 325 | function ResultsNode(result, type, parent) { 326 | this.result = result; 327 | this.type = type; 328 | this.parent = parent; 329 | 330 | this.children = []; 331 | 332 | this.addChild = function(result, type) { 333 | this.children.push(new ResultsNode(result, type, this)); 334 | }; 335 | 336 | this.last = function() { 337 | return this.children[this.children.length - 1]; 338 | }; 339 | } 340 | 341 | return ResultsNode; 342 | }; 343 | 344 | jasmineRequire.QueryString = function() { 345 | function QueryString(options) { 346 | 347 | this.setParam = function(key, value) { 348 | var paramMap = queryStringToParamMap(); 349 | paramMap[key] = value; 350 | options.getWindowLocation().search = toQueryString(paramMap); 351 | }; 352 | 353 | this.getParam = function(key) { 354 | return queryStringToParamMap()[key]; 355 | }; 356 | 357 | return this; 358 | 359 | function toQueryString(paramMap) { 360 | var qStrPairs = []; 361 | for (var prop in paramMap) { 362 | qStrPairs.push(encodeURIComponent(prop) + '=' + encodeURIComponent(paramMap[prop])); 363 | } 364 | return '?' + qStrPairs.join('&'); 365 | } 366 | 367 | function queryStringToParamMap() { 368 | var paramStr = options.getWindowLocation().search.substring(1), 369 | params = [], 370 | paramMap = {}; 371 | 372 | if (paramStr.length > 0) { 373 | params = paramStr.split('&'); 374 | for (var i = 0; i < params.length; i++) { 375 | var p = params[i].split('='); 376 | var value = decodeURIComponent(p[1]); 377 | if (value === 'true' || value === 'false') { 378 | value = JSON.parse(value); 379 | } 380 | paramMap[decodeURIComponent(p[0])] = value; 381 | } 382 | } 383 | 384 | return paramMap; 385 | } 386 | 387 | } 388 | 389 | return QueryString; 390 | }; 391 | -------------------------------------------------------------------------------- /tests/lib/jasmine-2.0.3/jasmine.css: -------------------------------------------------------------------------------- 1 | body { overflow-y: scroll; } 2 | 3 | .jasmine_html-reporter { background-color: #eeeeee; padding: 5px; margin: -8px; font-size: 11px; font-family: Monaco, "Lucida Console", monospace; line-height: 14px; color: #333333; } 4 | .jasmine_html-reporter a { text-decoration: none; } 5 | .jasmine_html-reporter a:hover { text-decoration: underline; } 6 | .jasmine_html-reporter p, .jasmine_html-reporter h1, .jasmine_html-reporter h2, .jasmine_html-reporter h3, .jasmine_html-reporter h4, .jasmine_html-reporter h5, .jasmine_html-reporter h6 { margin: 0; line-height: 14px; } 7 | .jasmine_html-reporter .banner, .jasmine_html-reporter .symbol-summary, .jasmine_html-reporter .summary, .jasmine_html-reporter .result-message, .jasmine_html-reporter .spec .description, .jasmine_html-reporter .spec-detail .description, .jasmine_html-reporter .alert .bar, .jasmine_html-reporter .stack-trace { padding-left: 9px; padding-right: 9px; } 8 | .jasmine_html-reporter .banner { position: relative; } 9 | .jasmine_html-reporter .banner .title { background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFoAAAAZCAMAAACGusnyAAACdlBMVEX/////AP+AgICqVaqAQICZM5mAVYCSSZKAQICOOY6ATYCLRouAQICJO4mSSYCIRIiPQICHPIeOR4CGQ4aMQICGPYaLRoCFQ4WKQICPPYWJRYCOQoSJQICNPoSIRICMQoSHQICHRICKQoOHQICKPoOJO4OJQYOMQICMQ4CIQYKLQICIPoKLQ4CKQICNPoKJQISMQ4KJQoSLQYKJQISLQ4KIQoSKQYKIQICIQISMQoSKQYKLQIOLQoOJQYGLQIOKQIOMQoGKQYOLQYGKQIOLQoGJQYOJQIOKQYGJQIOKQoGKQIGLQIKLQ4KKQoGLQYKJQIGKQYKJQIGKQIKJQoGKQYKLQIGKQYKLQIOJQoKKQoOJQYKKQIOJQoKKQoOKQIOLQoKKQYOLQYKJQIOKQoKKQYKKQoKJQYOK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25lIiAvPjxwYXRoCiAgICAgICAgICAgICBkPSJtIDM4MC42ODgsNjIyLjEyOSAtMTEuNjI2LDM1LjgwMSAxNzUuNzU4LDU3LjA5IDExLjYyMSwtMzUuODAxIC0xNzUuNzUzLC01Ny4wOSIKICAgICAgICAgICAgIGlua3NjYXBlOmNvbm5lY3Rvci1jdXJ2YXR1cmU9IjAiCiAgICAgICAgICAgICBpZD0icGF0aDU0IgogICAgICAgICAgICAgc3R5bGU9ImZpbGw6IzhhNDE4MjtmaWxsLW9wYWNpdHk6MTtmaWxsLXJ1bGU6bm9uemVybztzdHJva2U6bm9uZSIgLz48cGF0aAogICAgICAgICAgICAgZD0ibSA3MTYuMjg5LDM3Ni41OSAzNy42NDA2LDAgMCwxODQuODE2IC0zNy42NDA2LDAgMCwtMTg0LjgxNiB6IgogICAgICAgICAgICAgaW5rc2NhcGU6Y29ubmVjdG9yLWN1cnZhdHVyZT0iMCIKICAgICAgICAgICAgIGlkPSJwYXRoNTYiCiAgICAgICAgICAgICBzdHlsZT0iZmlsbDojOGE0MTgyO2ZpbGwtb3BhY2l0eToxO2ZpbGwtcnVsZTpub256ZXJvO3N0cm9rZTpub25lIiAvPjwvZz48L2c+PC9nPjwvZz48L3N2Zz4=') no-repeat, none; -webkit-background-size: 100%; -moz-background-size: 100%; -o-background-size: 100%; background-size: 100%; display: block; float: left; width: 90px; height: 25px; } 10 | .jasmine_html-reporter .banner .version { margin-left: 14px; position: relative; top: 6px; } 11 | .jasmine_html-reporter .banner .duration { position: absolute; right: 14px; top: 6px; } 12 | .jasmine_html-reporter #jasmine_content { position: fixed; right: 100%; } 13 | .jasmine_html-reporter .version { color: #aaaaaa; } 14 | .jasmine_html-reporter .banner { margin-top: 14px; } 15 | .jasmine_html-reporter .duration { color: #aaaaaa; float: right; } 16 | .jasmine_html-reporter .symbol-summary { overflow: hidden; *zoom: 1; margin: 14px 0; } 17 | .jasmine_html-reporter .symbol-summary li { display: inline-block; height: 8px; width: 14px; font-size: 16px; } 18 | .jasmine_html-reporter .symbol-summary li.passed { font-size: 14px; } 19 | .jasmine_html-reporter .symbol-summary li.passed:before { color: #007069; content: "\02022"; } 20 | .jasmine_html-reporter .symbol-summary li.failed { line-height: 9px; } 21 | .jasmine_html-reporter .symbol-summary li.failed:before { color: #ca3a11; content: "\d7"; font-weight: bold; margin-left: -1px; } 22 | .jasmine_html-reporter .symbol-summary li.disabled { font-size: 14px; } 23 | .jasmine_html-reporter .symbol-summary li.disabled:before { color: #bababa; content: "\02022"; } 24 | .jasmine_html-reporter .symbol-summary li.pending { line-height: 17px; } 25 | .jasmine_html-reporter .symbol-summary li.pending:before { color: #ba9d37; content: "*"; } 26 | .jasmine_html-reporter .symbol-summary li.empty { font-size: 14px; } 27 | .jasmine_html-reporter .symbol-summary li.empty:before { color: #ba9d37; content: "\02022"; } 28 | .jasmine_html-reporter .exceptions { color: #fff; float: right; margin-top: 5px; margin-right: 5px; } 29 | .jasmine_html-reporter .bar { line-height: 28px; font-size: 14px; display: block; color: #eee; } 30 | .jasmine_html-reporter .bar.failed { background-color: #ca3a11; } 31 | .jasmine_html-reporter .bar.passed { background-color: #007069; } 32 | .jasmine_html-reporter .bar.skipped { background-color: #bababa; } 33 | .jasmine_html-reporter .bar.menu { background-color: #fff; color: #aaaaaa; } 34 | .jasmine_html-reporter .bar.menu a { color: #333333; } 35 | .jasmine_html-reporter .bar a { color: white; } 36 | .jasmine_html-reporter.spec-list .bar.menu.failure-list, .jasmine_html-reporter.spec-list .results .failures { display: none; } 37 | .jasmine_html-reporter.failure-list .bar.menu.spec-list, .jasmine_html-reporter.failure-list .summary { display: none; } 38 | .jasmine_html-reporter .running-alert { background-color: #666666; } 39 | .jasmine_html-reporter .results { margin-top: 14px; } 40 | .jasmine_html-reporter.showDetails .summaryMenuItem { font-weight: normal; text-decoration: inherit; } 41 | .jasmine_html-reporter.showDetails .summaryMenuItem:hover { text-decoration: underline; } 42 | .jasmine_html-reporter.showDetails .detailsMenuItem { font-weight: bold; text-decoration: underline; } 43 | .jasmine_html-reporter.showDetails .summary { display: none; } 44 | .jasmine_html-reporter.showDetails #details { display: block; } 45 | .jasmine_html-reporter .summaryMenuItem { font-weight: bold; text-decoration: underline; } 46 | .jasmine_html-reporter .summary { margin-top: 14px; } 47 | .jasmine_html-reporter .summary ul { list-style-type: none; margin-left: 14px; padding-top: 0; padding-left: 0; } 48 | .jasmine_html-reporter .summary ul.suite { margin-top: 7px; margin-bottom: 7px; } 49 | .jasmine_html-reporter .summary li.passed a { color: #007069; } 50 | .jasmine_html-reporter .summary li.failed a { color: #ca3a11; } 51 | .jasmine_html-reporter .summary li.empty a { color: #ba9d37; } 52 | .jasmine_html-reporter .summary li.pending a { color: #ba9d37; } 53 | .jasmine_html-reporter .description + .suite { margin-top: 0; } 54 | .jasmine_html-reporter .suite { margin-top: 14px; } 55 | .jasmine_html-reporter .suite a { color: #333333; } 56 | .jasmine_html-reporter .failures .spec-detail { margin-bottom: 28px; } 57 | .jasmine_html-reporter .failures .spec-detail .description { background-color: #ca3a11; } 58 | .jasmine_html-reporter .failures .spec-detail .description a { color: white; } 59 | .jasmine_html-reporter .result-message { padding-top: 14px; color: #333333; white-space: pre; } 60 | .jasmine_html-reporter .result-message span.result { display: block; } 61 | .jasmine_html-reporter .stack-trace { margin: 5px 0 0 0; max-height: 224px; overflow: auto; line-height: 18px; color: #666666; border: 1px solid #ddd; background: white; white-space: pre; } 62 | -------------------------------------------------------------------------------- /tests/lib/jasmine-2.0.3/jasmine.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2008-2014 Pivotal Labs 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining 5 | a copy of this software and associated documentation files (the 6 | "Software"), to deal in the Software without restriction, including 7 | without limitation the rights to use, copy, modify, merge, publish, 8 | distribute, sublicense, and/or sell copies of the Software, and to 9 | permit persons to whom the Software is furnished to do so, subject to 10 | the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | function getJasmineRequireObj() { 24 | if (typeof module !== 'undefined' && module.exports) { 25 | return exports; 26 | } else { 27 | window.jasmineRequire = window.jasmineRequire || {}; 28 | return window.jasmineRequire; 29 | } 30 | } 31 | 32 | getJasmineRequireObj().core = function(jRequire) { 33 | var j$ = {}; 34 | 35 | jRequire.base(j$); 36 | j$.util = jRequire.util(); 37 | j$.Any = jRequire.Any(); 38 | j$.CallTracker = jRequire.CallTracker(); 39 | j$.MockDate = jRequire.MockDate(); 40 | j$.Clock = jRequire.Clock(); 41 | j$.DelayedFunctionScheduler = jRequire.DelayedFunctionScheduler(); 42 | j$.Env = jRequire.Env(j$); 43 | j$.ExceptionFormatter = jRequire.ExceptionFormatter(); 44 | j$.Expectation = jRequire.Expectation(); 45 | j$.buildExpectationResult = jRequire.buildExpectationResult(); 46 | j$.JsApiReporter = jRequire.JsApiReporter(); 47 | j$.matchersUtil = jRequire.matchersUtil(j$); 48 | j$.ObjectContaining = jRequire.ObjectContaining(j$); 49 | j$.pp = jRequire.pp(j$); 50 | j$.QueueRunner = jRequire.QueueRunner(j$); 51 | j$.ReportDispatcher = jRequire.ReportDispatcher(); 52 | j$.Spec = jRequire.Spec(j$); 53 | j$.SpyStrategy = jRequire.SpyStrategy(); 54 | j$.Suite = jRequire.Suite(); 55 | j$.Timer = jRequire.Timer(); 56 | j$.version = jRequire.version(); 57 | 58 | j$.matchers = jRequire.requireMatchers(jRequire, j$); 59 | 60 | return j$; 61 | }; 62 | 63 | getJasmineRequireObj().requireMatchers = function(jRequire, j$) { 64 | var availableMatchers = [ 65 | 'toBe', 66 | 'toBeCloseTo', 67 | 'toBeDefined', 68 | 'toBeFalsy', 69 | 'toBeGreaterThan', 70 | 'toBeLessThan', 71 | 'toBeNaN', 72 | 'toBeNull', 73 | 'toBeTruthy', 74 | 'toBeUndefined', 75 | 'toContain', 76 | 'toEqual', 77 | 'toHaveBeenCalled', 78 | 'toHaveBeenCalledWith', 79 | 'toMatch', 80 | 'toThrow', 81 | 'toThrowError' 82 | ], 83 | matchers = {}; 84 | 85 | for (var i = 0; i < availableMatchers.length; i++) { 86 | var name = availableMatchers[i]; 87 | matchers[name] = jRequire[name](j$); 88 | } 89 | 90 | return matchers; 91 | }; 92 | 93 | getJasmineRequireObj().base = (function (jasmineGlobal) { 94 | if (typeof module !== 'undefined' && module.exports) { 95 | jasmineGlobal = global; 96 | } 97 | 98 | return function(j$) { 99 | j$.unimplementedMethod_ = function() { 100 | throw new Error('unimplemented method'); 101 | }; 102 | 103 | j$.MAX_PRETTY_PRINT_DEPTH = 40; 104 | j$.MAX_PRETTY_PRINT_ARRAY_LENGTH = 100; 105 | j$.DEFAULT_TIMEOUT_INTERVAL = 5000; 106 | 107 | j$.getGlobal = function() { 108 | return jasmineGlobal; 109 | }; 110 | 111 | j$.getEnv = function(options) { 112 | var env = j$.currentEnv_ = j$.currentEnv_ || new j$.Env(options); 113 | //jasmine. singletons in here (setTimeout blah blah). 114 | return env; 115 | }; 116 | 117 | j$.isArray_ = function(value) { 118 | return j$.isA_('Array', value); 119 | }; 120 | 121 | j$.isString_ = function(value) { 122 | return j$.isA_('String', value); 123 | }; 124 | 125 | j$.isNumber_ = function(value) { 126 | return j$.isA_('Number', value); 127 | }; 128 | 129 | j$.isA_ = function(typeName, value) { 130 | return Object.prototype.toString.apply(value) === '[object ' + typeName + ']'; 131 | }; 132 | 133 | j$.isDomNode = function(obj) { 134 | return obj.nodeType > 0; 135 | }; 136 | 137 | j$.any = function(clazz) { 138 | return new j$.Any(clazz); 139 | }; 140 | 141 | j$.objectContaining = function(sample) { 142 | return new j$.ObjectContaining(sample); 143 | }; 144 | 145 | j$.createSpy = function(name, originalFn) { 146 | 147 | var spyStrategy = new j$.SpyStrategy({ 148 | name: name, 149 | fn: originalFn, 150 | getSpy: function() { return spy; } 151 | }), 152 | callTracker = new j$.CallTracker(), 153 | spy = function() { 154 | callTracker.track({ 155 | object: this, 156 | args: Array.prototype.slice.apply(arguments) 157 | }); 158 | return spyStrategy.exec.apply(this, arguments); 159 | }; 160 | 161 | for (var prop in originalFn) { 162 | if (prop === 'and' || prop === 'calls') { 163 | throw new Error('Jasmine spies would overwrite the \'and\' and \'calls\' properties on the object being spied upon'); 164 | } 165 | 166 | spy[prop] = originalFn[prop]; 167 | } 168 | 169 | spy.and = spyStrategy; 170 | spy.calls = callTracker; 171 | 172 | return spy; 173 | }; 174 | 175 | j$.isSpy = function(putativeSpy) { 176 | if (!putativeSpy) { 177 | return false; 178 | } 179 | return putativeSpy.and instanceof j$.SpyStrategy && 180 | putativeSpy.calls instanceof j$.CallTracker; 181 | }; 182 | 183 | j$.createSpyObj = function(baseName, methodNames) { 184 | if (!j$.isArray_(methodNames) || methodNames.length === 0) { 185 | throw 'createSpyObj requires a non-empty array of method names to create spies for'; 186 | } 187 | var obj = {}; 188 | for (var i = 0; i < methodNames.length; i++) { 189 | obj[methodNames[i]] = j$.createSpy(baseName + '.' + methodNames[i]); 190 | } 191 | return obj; 192 | }; 193 | }; 194 | })(this); 195 | 196 | getJasmineRequireObj().util = function() { 197 | 198 | var util = {}; 199 | 200 | util.inherit = function(childClass, parentClass) { 201 | var Subclass = function() { 202 | }; 203 | Subclass.prototype = parentClass.prototype; 204 | childClass.prototype = new Subclass(); 205 | }; 206 | 207 | util.htmlEscape = function(str) { 208 | if (!str) { 209 | return str; 210 | } 211 | return str.replace(/&/g, '&') 212 | .replace(//g, '>'); 214 | }; 215 | 216 | util.argsToArray = function(args) { 217 | var arrayOfArgs = []; 218 | for (var i = 0; i < args.length; i++) { 219 | arrayOfArgs.push(args[i]); 220 | } 221 | return arrayOfArgs; 222 | }; 223 | 224 | util.isUndefined = function(obj) { 225 | return obj === void 0; 226 | }; 227 | 228 | util.arrayContains = function(array, search) { 229 | var i = array.length; 230 | while (i--) { 231 | if (array[i] == search) { 232 | return true; 233 | } 234 | } 235 | return false; 236 | }; 237 | 238 | return util; 239 | }; 240 | 241 | getJasmineRequireObj().Spec = function(j$) { 242 | function Spec(attrs) { 243 | this.expectationFactory = attrs.expectationFactory; 244 | this.resultCallback = attrs.resultCallback || function() {}; 245 | this.id = attrs.id; 246 | this.description = attrs.description || ''; 247 | this.fn = attrs.fn; 248 | this.beforeFns = attrs.beforeFns || function() { return []; }; 249 | this.afterFns = attrs.afterFns || function() { return []; }; 250 | this.onStart = attrs.onStart || function() {}; 251 | this.exceptionFormatter = attrs.exceptionFormatter || function() {}; 252 | this.getSpecName = attrs.getSpecName || function() { return ''; }; 253 | this.expectationResultFactory = attrs.expectationResultFactory || function() { }; 254 | this.queueRunnerFactory = attrs.queueRunnerFactory || function() {}; 255 | this.catchingExceptions = attrs.catchingExceptions || function() { return true; }; 256 | 257 | if (!this.fn) { 258 | this.pend(); 259 | } 260 | 261 | this.result = { 262 | id: this.id, 263 | description: this.description, 264 | fullName: this.getFullName(), 265 | failedExpectations: [], 266 | passedExpectations: [] 267 | }; 268 | } 269 | 270 | Spec.prototype.addExpectationResult = function(passed, data) { 271 | var expectationResult = this.expectationResultFactory(data); 272 | if (passed) { 273 | this.result.passedExpectations.push(expectationResult); 274 | } else { 275 | this.result.failedExpectations.push(expectationResult); 276 | } 277 | }; 278 | 279 | Spec.prototype.expect = function(actual) { 280 | return this.expectationFactory(actual, this); 281 | }; 282 | 283 | Spec.prototype.execute = function(onComplete) { 284 | var self = this; 285 | 286 | this.onStart(this); 287 | 288 | if (this.markedPending || this.disabled) { 289 | complete(); 290 | return; 291 | } 292 | 293 | var allFns = this.beforeFns().concat(this.fn).concat(this.afterFns()); 294 | 295 | this.queueRunnerFactory({ 296 | fns: allFns, 297 | onException: onException, 298 | onComplete: complete, 299 | enforceTimeout: function() { return true; } 300 | }); 301 | 302 | function onException(e) { 303 | if (Spec.isPendingSpecException(e)) { 304 | self.pend(); 305 | return; 306 | } 307 | 308 | self.addExpectationResult(false, { 309 | matcherName: '', 310 | passed: false, 311 | expected: '', 312 | actual: '', 313 | error: e 314 | }); 315 | } 316 | 317 | function complete() { 318 | self.result.status = self.status(); 319 | self.resultCallback(self.result); 320 | 321 | if (onComplete) { 322 | onComplete(); 323 | } 324 | } 325 | }; 326 | 327 | Spec.prototype.disable = function() { 328 | this.disabled = true; 329 | }; 330 | 331 | Spec.prototype.pend = function() { 332 | this.markedPending = true; 333 | }; 334 | 335 | Spec.prototype.status = function() { 336 | if (this.disabled) { 337 | return 'disabled'; 338 | } 339 | 340 | if (this.markedPending) { 341 | return 'pending'; 342 | } 343 | 344 | if (this.result.failedExpectations.length > 0) { 345 | return 'failed'; 346 | } else { 347 | return 'passed'; 348 | } 349 | }; 350 | 351 | Spec.prototype.getFullName = function() { 352 | return this.getSpecName(this); 353 | }; 354 | 355 | Spec.pendingSpecExceptionMessage = '=> marked Pending'; 356 | 357 | Spec.isPendingSpecException = function(e) { 358 | return !!(e && e.toString && e.toString().indexOf(Spec.pendingSpecExceptionMessage) !== -1); 359 | }; 360 | 361 | return Spec; 362 | }; 363 | 364 | if (typeof window == void 0 && typeof exports == 'object') { 365 | exports.Spec = jasmineRequire.Spec; 366 | } 367 | 368 | getJasmineRequireObj().Env = function(j$) { 369 | function Env(options) { 370 | options = options || {}; 371 | 372 | var self = this; 373 | var global = options.global || j$.getGlobal(); 374 | 375 | var totalSpecsDefined = 0; 376 | 377 | var catchExceptions = true; 378 | 379 | var realSetTimeout = j$.getGlobal().setTimeout; 380 | var realClearTimeout = j$.getGlobal().clearTimeout; 381 | this.clock = new j$.Clock(global, new j$.DelayedFunctionScheduler(), new j$.MockDate(global)); 382 | 383 | var runnableLookupTable = {}; 384 | 385 | var spies = []; 386 | 387 | var currentSpec = null; 388 | var currentSuite = null; 389 | 390 | var reporter = new j$.ReportDispatcher([ 391 | 'jasmineStarted', 392 | 'jasmineDone', 393 | 'suiteStarted', 394 | 'suiteDone', 395 | 'specStarted', 396 | 'specDone' 397 | ]); 398 | 399 | this.specFilter = function() { 400 | return true; 401 | }; 402 | 403 | var equalityTesters = []; 404 | 405 | var customEqualityTesters = []; 406 | this.addCustomEqualityTester = function(tester) { 407 | customEqualityTesters.push(tester); 408 | }; 409 | 410 | j$.Expectation.addCoreMatchers(j$.matchers); 411 | 412 | var nextSpecId = 0; 413 | var getNextSpecId = function() { 414 | return 'spec' + nextSpecId++; 415 | }; 416 | 417 | var nextSuiteId = 0; 418 | var getNextSuiteId = function() { 419 | return 'suite' + nextSuiteId++; 420 | }; 421 | 422 | var expectationFactory = function(actual, spec) { 423 | return j$.Expectation.Factory({ 424 | util: j$.matchersUtil, 425 | customEqualityTesters: customEqualityTesters, 426 | actual: actual, 427 | addExpectationResult: addExpectationResult 428 | }); 429 | 430 | function addExpectationResult(passed, result) { 431 | return spec.addExpectationResult(passed, result); 432 | } 433 | }; 434 | 435 | var specStarted = function(spec) { 436 | currentSpec = spec; 437 | reporter.specStarted(spec.result); 438 | }; 439 | 440 | var beforeFns = function(suite) { 441 | return function() { 442 | var befores = []; 443 | while(suite) { 444 | befores = befores.concat(suite.beforeFns); 445 | suite = suite.parentSuite; 446 | } 447 | return befores.reverse(); 448 | }; 449 | }; 450 | 451 | var afterFns = function(suite) { 452 | return function() { 453 | var afters = []; 454 | while(suite) { 455 | afters = afters.concat(suite.afterFns); 456 | suite = suite.parentSuite; 457 | } 458 | return afters; 459 | }; 460 | }; 461 | 462 | var getSpecName = function(spec, suite) { 463 | return suite.getFullName() + ' ' + spec.description; 464 | }; 465 | 466 | // TODO: we may just be able to pass in the fn instead of wrapping here 467 | var buildExpectationResult = j$.buildExpectationResult, 468 | exceptionFormatter = new j$.ExceptionFormatter(), 469 | expectationResultFactory = function(attrs) { 470 | attrs.messageFormatter = exceptionFormatter.message; 471 | attrs.stackFormatter = exceptionFormatter.stack; 472 | 473 | return buildExpectationResult(attrs); 474 | }; 475 | 476 | // TODO: fix this naming, and here's where the value comes in 477 | this.catchExceptions = function(value) { 478 | catchExceptions = !!value; 479 | return catchExceptions; 480 | }; 481 | 482 | this.catchingExceptions = function() { 483 | return catchExceptions; 484 | }; 485 | 486 | var maximumSpecCallbackDepth = 20; 487 | var currentSpecCallbackDepth = 0; 488 | 489 | function clearStack(fn) { 490 | currentSpecCallbackDepth++; 491 | if (currentSpecCallbackDepth >= maximumSpecCallbackDepth) { 492 | currentSpecCallbackDepth = 0; 493 | realSetTimeout(fn, 0); 494 | } else { 495 | fn(); 496 | } 497 | } 498 | 499 | var catchException = function(e) { 500 | return j$.Spec.isPendingSpecException(e) || catchExceptions; 501 | }; 502 | 503 | var queueRunnerFactory = function(options) { 504 | options.catchException = catchException; 505 | options.clearStack = options.clearStack || clearStack; 506 | options.timer = {setTimeout: realSetTimeout, clearTimeout: realClearTimeout}; 507 | 508 | new j$.QueueRunner(options).execute(); 509 | }; 510 | 511 | var topSuite = new j$.Suite({ 512 | env: this, 513 | id: getNextSuiteId(), 514 | description: 'Jasmine__TopLevel__Suite', 515 | queueRunner: queueRunnerFactory, 516 | resultCallback: function() {} // TODO - hook this up 517 | }); 518 | runnableLookupTable[topSuite.id] = topSuite; 519 | currentSuite = topSuite; 520 | 521 | this.topSuite = function() { 522 | return topSuite; 523 | }; 524 | 525 | this.execute = function(runnablesToRun) { 526 | runnablesToRun = runnablesToRun || [topSuite.id]; 527 | 528 | var allFns = []; 529 | for(var i = 0; i < runnablesToRun.length; i++) { 530 | var runnable = runnableLookupTable[runnablesToRun[i]]; 531 | allFns.push((function(runnable) { return function(done) { runnable.execute(done); }; })(runnable)); 532 | } 533 | 534 | reporter.jasmineStarted({ 535 | totalSpecsDefined: totalSpecsDefined 536 | }); 537 | 538 | queueRunnerFactory({fns: allFns, onComplete: reporter.jasmineDone}); 539 | }; 540 | 541 | this.addReporter = function(reporterToAdd) { 542 | reporter.addReporter(reporterToAdd); 543 | }; 544 | 545 | this.addMatchers = function(matchersToAdd) { 546 | j$.Expectation.addMatchers(matchersToAdd); 547 | }; 548 | 549 | this.spyOn = function(obj, methodName) { 550 | if (j$.util.isUndefined(obj)) { 551 | throw new Error('spyOn could not find an object to spy upon for ' + methodName + '()'); 552 | } 553 | 554 | if (j$.util.isUndefined(obj[methodName])) { 555 | throw new Error(methodName + '() method does not exist'); 556 | } 557 | 558 | if (obj[methodName] && j$.isSpy(obj[methodName])) { 559 | //TODO?: should this return the current spy? Downside: may cause user confusion about spy state 560 | throw new Error(methodName + ' has already been spied upon'); 561 | } 562 | 563 | var spy = j$.createSpy(methodName, obj[methodName]); 564 | 565 | spies.push({ 566 | spy: spy, 567 | baseObj: obj, 568 | methodName: methodName, 569 | originalValue: obj[methodName] 570 | }); 571 | 572 | obj[methodName] = spy; 573 | 574 | return spy; 575 | }; 576 | 577 | var suiteFactory = function(description) { 578 | var suite = new j$.Suite({ 579 | env: self, 580 | id: getNextSuiteId(), 581 | description: description, 582 | parentSuite: currentSuite, 583 | queueRunner: queueRunnerFactory, 584 | onStart: suiteStarted, 585 | resultCallback: function(attrs) { 586 | reporter.suiteDone(attrs); 587 | } 588 | }); 589 | 590 | runnableLookupTable[suite.id] = suite; 591 | return suite; 592 | }; 593 | 594 | this.describe = function(description, specDefinitions) { 595 | var suite = suiteFactory(description); 596 | 597 | var parentSuite = currentSuite; 598 | parentSuite.addChild(suite); 599 | currentSuite = suite; 600 | 601 | var declarationError = null; 602 | try { 603 | specDefinitions.call(suite); 604 | } catch (e) { 605 | declarationError = e; 606 | } 607 | 608 | if (declarationError) { 609 | this.it('encountered a declaration exception', function() { 610 | throw declarationError; 611 | }); 612 | } 613 | 614 | currentSuite = parentSuite; 615 | 616 | return suite; 617 | }; 618 | 619 | this.xdescribe = function(description, specDefinitions) { 620 | var suite = this.describe(description, specDefinitions); 621 | suite.disable(); 622 | return suite; 623 | }; 624 | 625 | var specFactory = function(description, fn, suite) { 626 | totalSpecsDefined++; 627 | 628 | var spec = new j$.Spec({ 629 | id: getNextSpecId(), 630 | beforeFns: beforeFns(suite), 631 | afterFns: afterFns(suite), 632 | expectationFactory: expectationFactory, 633 | exceptionFormatter: exceptionFormatter, 634 | resultCallback: specResultCallback, 635 | getSpecName: function(spec) { 636 | return getSpecName(spec, suite); 637 | }, 638 | onStart: specStarted, 639 | description: description, 640 | expectationResultFactory: expectationResultFactory, 641 | queueRunnerFactory: queueRunnerFactory, 642 | fn: fn 643 | }); 644 | 645 | runnableLookupTable[spec.id] = spec; 646 | 647 | if (!self.specFilter(spec)) { 648 | spec.disable(); 649 | } 650 | 651 | return spec; 652 | 653 | function removeAllSpies() { 654 | for (var i = 0; i < spies.length; i++) { 655 | var spyEntry = spies[i]; 656 | spyEntry.baseObj[spyEntry.methodName] = spyEntry.originalValue; 657 | } 658 | spies = []; 659 | } 660 | 661 | function specResultCallback(result) { 662 | removeAllSpies(); 663 | j$.Expectation.resetMatchers(); 664 | customEqualityTesters = []; 665 | currentSpec = null; 666 | reporter.specDone(result); 667 | } 668 | }; 669 | 670 | var suiteStarted = function(suite) { 671 | reporter.suiteStarted(suite.result); 672 | }; 673 | 674 | this.it = function(description, fn) { 675 | var spec = specFactory(description, fn, currentSuite); 676 | currentSuite.addChild(spec); 677 | return spec; 678 | }; 679 | 680 | this.xit = function(description, fn) { 681 | var spec = this.it(description, fn); 682 | spec.pend(); 683 | return spec; 684 | }; 685 | 686 | this.expect = function(actual) { 687 | if (!currentSpec) { 688 | throw new Error('\'expect\' was used when there was no current spec, this could be because an asynchronous test timed out'); 689 | } 690 | 691 | return currentSpec.expect(actual); 692 | }; 693 | 694 | this.beforeEach = function(beforeEachFunction) { 695 | currentSuite.beforeEach(beforeEachFunction); 696 | }; 697 | 698 | this.afterEach = function(afterEachFunction) { 699 | currentSuite.afterEach(afterEachFunction); 700 | }; 701 | 702 | this.pending = function() { 703 | throw j$.Spec.pendingSpecExceptionMessage; 704 | }; 705 | } 706 | 707 | return Env; 708 | }; 709 | 710 | getJasmineRequireObj().JsApiReporter = function() { 711 | 712 | var noopTimer = { 713 | start: function(){}, 714 | elapsed: function(){ return 0; } 715 | }; 716 | 717 | function JsApiReporter(options) { 718 | var timer = options.timer || noopTimer, 719 | status = 'loaded'; 720 | 721 | this.started = false; 722 | this.finished = false; 723 | 724 | this.jasmineStarted = function() { 725 | this.started = true; 726 | status = 'started'; 727 | timer.start(); 728 | }; 729 | 730 | var executionTime; 731 | 732 | this.jasmineDone = function() { 733 | this.finished = true; 734 | executionTime = timer.elapsed(); 735 | status = 'done'; 736 | }; 737 | 738 | this.status = function() { 739 | return status; 740 | }; 741 | 742 | var suites = {}; 743 | 744 | this.suiteStarted = function(result) { 745 | storeSuite(result); 746 | }; 747 | 748 | this.suiteDone = function(result) { 749 | storeSuite(result); 750 | }; 751 | 752 | function storeSuite(result) { 753 | suites[result.id] = result; 754 | } 755 | 756 | this.suites = function() { 757 | return suites; 758 | }; 759 | 760 | var specs = []; 761 | this.specStarted = function(result) { }; 762 | 763 | this.specDone = function(result) { 764 | specs.push(result); 765 | }; 766 | 767 | this.specResults = function(index, length) { 768 | return specs.slice(index, index + length); 769 | }; 770 | 771 | this.specs = function() { 772 | return specs; 773 | }; 774 | 775 | this.executionTime = function() { 776 | return executionTime; 777 | }; 778 | 779 | } 780 | 781 | return JsApiReporter; 782 | }; 783 | 784 | getJasmineRequireObj().Any = function() { 785 | 786 | function Any(expectedObject) { 787 | this.expectedObject = expectedObject; 788 | } 789 | 790 | Any.prototype.jasmineMatches = function(other) { 791 | if (this.expectedObject == String) { 792 | return typeof other == 'string' || other instanceof String; 793 | } 794 | 795 | if (this.expectedObject == Number) { 796 | return typeof other == 'number' || other instanceof Number; 797 | } 798 | 799 | if (this.expectedObject == Function) { 800 | return typeof other == 'function' || other instanceof Function; 801 | } 802 | 803 | if (this.expectedObject == Object) { 804 | return typeof other == 'object'; 805 | } 806 | 807 | if (this.expectedObject == Boolean) { 808 | return typeof other == 'boolean'; 809 | } 810 | 811 | return other instanceof this.expectedObject; 812 | }; 813 | 814 | Any.prototype.jasmineToString = function() { 815 | return ''; 816 | }; 817 | 818 | return Any; 819 | }; 820 | 821 | getJasmineRequireObj().CallTracker = function() { 822 | 823 | function CallTracker() { 824 | var calls = []; 825 | 826 | this.track = function(context) { 827 | calls.push(context); 828 | }; 829 | 830 | this.any = function() { 831 | return !!calls.length; 832 | }; 833 | 834 | this.count = function() { 835 | return calls.length; 836 | }; 837 | 838 | this.argsFor = function(index) { 839 | var call = calls[index]; 840 | return call ? call.args : []; 841 | }; 842 | 843 | this.all = function() { 844 | return calls; 845 | }; 846 | 847 | this.allArgs = function() { 848 | var callArgs = []; 849 | for(var i = 0; i < calls.length; i++){ 850 | callArgs.push(calls[i].args); 851 | } 852 | 853 | return callArgs; 854 | }; 855 | 856 | this.first = function() { 857 | return calls[0]; 858 | }; 859 | 860 | this.mostRecent = function() { 861 | return calls[calls.length - 1]; 862 | }; 863 | 864 | this.reset = function() { 865 | calls = []; 866 | }; 867 | } 868 | 869 | return CallTracker; 870 | }; 871 | 872 | getJasmineRequireObj().Clock = function() { 873 | function Clock(global, delayedFunctionScheduler, mockDate) { 874 | var self = this, 875 | realTimingFunctions = { 876 | setTimeout: global.setTimeout, 877 | clearTimeout: global.clearTimeout, 878 | setInterval: global.setInterval, 879 | clearInterval: global.clearInterval 880 | }, 881 | fakeTimingFunctions = { 882 | setTimeout: setTimeout, 883 | clearTimeout: clearTimeout, 884 | setInterval: setInterval, 885 | clearInterval: clearInterval 886 | }, 887 | installed = false, 888 | timer; 889 | 890 | 891 | self.install = function() { 892 | replace(global, fakeTimingFunctions); 893 | timer = fakeTimingFunctions; 894 | installed = true; 895 | 896 | return self; 897 | }; 898 | 899 | self.uninstall = function() { 900 | delayedFunctionScheduler.reset(); 901 | mockDate.uninstall(); 902 | replace(global, realTimingFunctions); 903 | 904 | timer = realTimingFunctions; 905 | installed = false; 906 | }; 907 | 908 | self.mockDate = function(initialDate) { 909 | mockDate.install(initialDate); 910 | }; 911 | 912 | self.setTimeout = function(fn, delay, params) { 913 | if (legacyIE()) { 914 | if (arguments.length > 2) { 915 | throw new Error('IE < 9 cannot support extra params to setTimeout without a polyfill'); 916 | } 917 | return timer.setTimeout(fn, delay); 918 | } 919 | return Function.prototype.apply.apply(timer.setTimeout, [global, arguments]); 920 | }; 921 | 922 | self.setInterval = function(fn, delay, params) { 923 | if (legacyIE()) { 924 | if (arguments.length > 2) { 925 | throw new Error('IE < 9 cannot support extra params to setInterval without a polyfill'); 926 | } 927 | return timer.setInterval(fn, delay); 928 | } 929 | return Function.prototype.apply.apply(timer.setInterval, [global, arguments]); 930 | }; 931 | 932 | self.clearTimeout = function(id) { 933 | return Function.prototype.call.apply(timer.clearTimeout, [global, id]); 934 | }; 935 | 936 | self.clearInterval = function(id) { 937 | return Function.prototype.call.apply(timer.clearInterval, [global, id]); 938 | }; 939 | 940 | self.tick = function(millis) { 941 | if (installed) { 942 | mockDate.tick(millis); 943 | delayedFunctionScheduler.tick(millis); 944 | } else { 945 | throw new Error('Mock clock is not installed, use jasmine.clock().install()'); 946 | } 947 | }; 948 | 949 | return self; 950 | 951 | function legacyIE() { 952 | //if these methods are polyfilled, apply will be present 953 | return !(realTimingFunctions.setTimeout || realTimingFunctions.setInterval).apply; 954 | } 955 | 956 | function replace(dest, source) { 957 | for (var prop in source) { 958 | dest[prop] = source[prop]; 959 | } 960 | } 961 | 962 | function setTimeout(fn, delay) { 963 | return delayedFunctionScheduler.scheduleFunction(fn, delay, argSlice(arguments, 2)); 964 | } 965 | 966 | function clearTimeout(id) { 967 | return delayedFunctionScheduler.removeFunctionWithId(id); 968 | } 969 | 970 | function setInterval(fn, interval) { 971 | return delayedFunctionScheduler.scheduleFunction(fn, interval, argSlice(arguments, 2), true); 972 | } 973 | 974 | function clearInterval(id) { 975 | return delayedFunctionScheduler.removeFunctionWithId(id); 976 | } 977 | 978 | function argSlice(argsObj, n) { 979 | return Array.prototype.slice.call(argsObj, n); 980 | } 981 | } 982 | 983 | return Clock; 984 | }; 985 | 986 | getJasmineRequireObj().DelayedFunctionScheduler = function() { 987 | function DelayedFunctionScheduler() { 988 | var self = this; 989 | var scheduledLookup = []; 990 | var scheduledFunctions = {}; 991 | var currentTime = 0; 992 | var delayedFnCount = 0; 993 | 994 | self.tick = function(millis) { 995 | millis = millis || 0; 996 | var endTime = currentTime + millis; 997 | 998 | runScheduledFunctions(endTime); 999 | currentTime = endTime; 1000 | }; 1001 | 1002 | self.scheduleFunction = function(funcToCall, millis, params, recurring, timeoutKey, runAtMillis) { 1003 | var f; 1004 | if (typeof(funcToCall) === 'string') { 1005 | /* jshint evil: true */ 1006 | f = function() { return eval(funcToCall); }; 1007 | /* jshint evil: false */ 1008 | } else { 1009 | f = funcToCall; 1010 | } 1011 | 1012 | millis = millis || 0; 1013 | timeoutKey = timeoutKey || ++delayedFnCount; 1014 | runAtMillis = runAtMillis || (currentTime + millis); 1015 | 1016 | var funcToSchedule = { 1017 | runAtMillis: runAtMillis, 1018 | funcToCall: f, 1019 | recurring: recurring, 1020 | params: params, 1021 | timeoutKey: timeoutKey, 1022 | millis: millis 1023 | }; 1024 | 1025 | if (runAtMillis in scheduledFunctions) { 1026 | scheduledFunctions[runAtMillis].push(funcToSchedule); 1027 | } else { 1028 | scheduledFunctions[runAtMillis] = [funcToSchedule]; 1029 | scheduledLookup.push(runAtMillis); 1030 | scheduledLookup.sort(function (a, b) { 1031 | return a - b; 1032 | }); 1033 | } 1034 | 1035 | return timeoutKey; 1036 | }; 1037 | 1038 | self.removeFunctionWithId = function(timeoutKey) { 1039 | for (var runAtMillis in scheduledFunctions) { 1040 | var funcs = scheduledFunctions[runAtMillis]; 1041 | var i = indexOfFirstToPass(funcs, function (func) { 1042 | return func.timeoutKey === timeoutKey; 1043 | }); 1044 | 1045 | if (i > -1) { 1046 | if (funcs.length === 1) { 1047 | delete scheduledFunctions[runAtMillis]; 1048 | deleteFromLookup(runAtMillis); 1049 | } else { 1050 | funcs.splice(i, 1); 1051 | } 1052 | 1053 | // intervals get rescheduled when executed, so there's never more 1054 | // than a single scheduled function with a given timeoutKey 1055 | break; 1056 | } 1057 | } 1058 | }; 1059 | 1060 | self.reset = function() { 1061 | currentTime = 0; 1062 | scheduledLookup = []; 1063 | scheduledFunctions = {}; 1064 | delayedFnCount = 0; 1065 | }; 1066 | 1067 | return self; 1068 | 1069 | function indexOfFirstToPass(array, testFn) { 1070 | var index = -1; 1071 | 1072 | for (var i = 0; i < array.length; ++i) { 1073 | if (testFn(array[i])) { 1074 | index = i; 1075 | break; 1076 | } 1077 | } 1078 | 1079 | return index; 1080 | } 1081 | 1082 | function deleteFromLookup(key) { 1083 | var value = Number(key); 1084 | var i = indexOfFirstToPass(scheduledLookup, function (millis) { 1085 | return millis === value; 1086 | }); 1087 | 1088 | if (i > -1) { 1089 | scheduledLookup.splice(i, 1); 1090 | } 1091 | } 1092 | 1093 | function reschedule(scheduledFn) { 1094 | self.scheduleFunction(scheduledFn.funcToCall, 1095 | scheduledFn.millis, 1096 | scheduledFn.params, 1097 | true, 1098 | scheduledFn.timeoutKey, 1099 | scheduledFn.runAtMillis + scheduledFn.millis); 1100 | } 1101 | 1102 | function runScheduledFunctions(endTime) { 1103 | if (scheduledLookup.length === 0 || scheduledLookup[0] > endTime) { 1104 | return; 1105 | } 1106 | 1107 | do { 1108 | currentTime = scheduledLookup.shift(); 1109 | 1110 | var funcsToRun = scheduledFunctions[currentTime]; 1111 | delete scheduledFunctions[currentTime]; 1112 | 1113 | for (var i = 0; i < funcsToRun.length; ++i) { 1114 | var funcToRun = funcsToRun[i]; 1115 | funcToRun.funcToCall.apply(null, funcToRun.params || []); 1116 | 1117 | if (funcToRun.recurring) { 1118 | reschedule(funcToRun); 1119 | } 1120 | } 1121 | } while (scheduledLookup.length > 0 && 1122 | // checking first if we're out of time prevents setTimeout(0) 1123 | // scheduled in a funcToRun from forcing an extra iteration 1124 | currentTime !== endTime && 1125 | scheduledLookup[0] <= endTime); 1126 | } 1127 | } 1128 | 1129 | return DelayedFunctionScheduler; 1130 | }; 1131 | 1132 | getJasmineRequireObj().ExceptionFormatter = function() { 1133 | function ExceptionFormatter() { 1134 | this.message = function(error) { 1135 | var message = ''; 1136 | 1137 | if (error.name && error.message) { 1138 | message += error.name + ': ' + error.message; 1139 | } else { 1140 | message += error.toString() + ' thrown'; 1141 | } 1142 | 1143 | if (error.fileName || error.sourceURL) { 1144 | message += ' in ' + (error.fileName || error.sourceURL); 1145 | } 1146 | 1147 | if (error.line || error.lineNumber) { 1148 | message += ' (line ' + (error.line || error.lineNumber) + ')'; 1149 | } 1150 | 1151 | return message; 1152 | }; 1153 | 1154 | this.stack = function(error) { 1155 | return error ? error.stack : null; 1156 | }; 1157 | } 1158 | 1159 | return ExceptionFormatter; 1160 | }; 1161 | 1162 | getJasmineRequireObj().Expectation = function() { 1163 | 1164 | var matchers = {}; 1165 | 1166 | function Expectation(options) { 1167 | this.util = options.util || { buildFailureMessage: function() {} }; 1168 | this.customEqualityTesters = options.customEqualityTesters || []; 1169 | this.actual = options.actual; 1170 | this.addExpectationResult = options.addExpectationResult || function(){}; 1171 | this.isNot = options.isNot; 1172 | 1173 | for (var matcherName in matchers) { 1174 | this[matcherName] = matchers[matcherName]; 1175 | } 1176 | } 1177 | 1178 | Expectation.prototype.wrapCompare = function(name, matcherFactory) { 1179 | return function() { 1180 | var args = Array.prototype.slice.call(arguments, 0), 1181 | expected = args.slice(0), 1182 | message = ''; 1183 | 1184 | args.unshift(this.actual); 1185 | 1186 | var matcher = matcherFactory(this.util, this.customEqualityTesters), 1187 | matcherCompare = matcher.compare; 1188 | 1189 | function defaultNegativeCompare() { 1190 | var result = matcher.compare.apply(null, args); 1191 | result.pass = !result.pass; 1192 | return result; 1193 | } 1194 | 1195 | if (this.isNot) { 1196 | matcherCompare = matcher.negativeCompare || defaultNegativeCompare; 1197 | } 1198 | 1199 | var result = matcherCompare.apply(null, args); 1200 | 1201 | if (!result.pass) { 1202 | if (!result.message) { 1203 | args.unshift(this.isNot); 1204 | args.unshift(name); 1205 | message = this.util.buildFailureMessage.apply(null, args); 1206 | } else { 1207 | if (Object.prototype.toString.apply(result.message) === '[object Function]') { 1208 | message = result.message(); 1209 | } else { 1210 | message = result.message; 1211 | } 1212 | } 1213 | } 1214 | 1215 | if (expected.length == 1) { 1216 | expected = expected[0]; 1217 | } 1218 | 1219 | // TODO: how many of these params are needed? 1220 | this.addExpectationResult( 1221 | result.pass, 1222 | { 1223 | matcherName: name, 1224 | passed: result.pass, 1225 | message: message, 1226 | actual: this.actual, 1227 | expected: expected // TODO: this may need to be arrayified/sliced 1228 | } 1229 | ); 1230 | }; 1231 | }; 1232 | 1233 | Expectation.addCoreMatchers = function(matchers) { 1234 | var prototype = Expectation.prototype; 1235 | for (var matcherName in matchers) { 1236 | var matcher = matchers[matcherName]; 1237 | prototype[matcherName] = prototype.wrapCompare(matcherName, matcher); 1238 | } 1239 | }; 1240 | 1241 | Expectation.addMatchers = function(matchersToAdd) { 1242 | for (var name in matchersToAdd) { 1243 | var matcher = matchersToAdd[name]; 1244 | matchers[name] = Expectation.prototype.wrapCompare(name, matcher); 1245 | } 1246 | }; 1247 | 1248 | Expectation.resetMatchers = function() { 1249 | for (var name in matchers) { 1250 | delete matchers[name]; 1251 | } 1252 | }; 1253 | 1254 | Expectation.Factory = function(options) { 1255 | options = options || {}; 1256 | 1257 | var expect = new Expectation(options); 1258 | 1259 | // TODO: this would be nice as its own Object - NegativeExpectation 1260 | // TODO: copy instead of mutate options 1261 | options.isNot = true; 1262 | expect.not = new Expectation(options); 1263 | 1264 | return expect; 1265 | }; 1266 | 1267 | return Expectation; 1268 | }; 1269 | 1270 | //TODO: expectation result may make more sense as a presentation of an expectation. 1271 | getJasmineRequireObj().buildExpectationResult = function() { 1272 | function buildExpectationResult(options) { 1273 | var messageFormatter = options.messageFormatter || function() {}, 1274 | stackFormatter = options.stackFormatter || function() {}; 1275 | 1276 | return { 1277 | matcherName: options.matcherName, 1278 | expected: options.expected, 1279 | actual: options.actual, 1280 | message: message(), 1281 | stack: stack(), 1282 | passed: options.passed 1283 | }; 1284 | 1285 | function message() { 1286 | if (options.passed) { 1287 | return 'Passed.'; 1288 | } else if (options.message) { 1289 | return options.message; 1290 | } else if (options.error) { 1291 | return messageFormatter(options.error); 1292 | } 1293 | return ''; 1294 | } 1295 | 1296 | function stack() { 1297 | if (options.passed) { 1298 | return ''; 1299 | } 1300 | 1301 | var error = options.error; 1302 | if (!error) { 1303 | try { 1304 | throw new Error(message()); 1305 | } catch (e) { 1306 | error = e; 1307 | } 1308 | } 1309 | return stackFormatter(error); 1310 | } 1311 | } 1312 | 1313 | return buildExpectationResult; 1314 | }; 1315 | 1316 | getJasmineRequireObj().MockDate = function() { 1317 | function MockDate(global) { 1318 | var self = this; 1319 | var currentTime = 0; 1320 | 1321 | if (!global || !global.Date) { 1322 | self.install = function() {}; 1323 | self.tick = function() {}; 1324 | self.uninstall = function() {}; 1325 | return self; 1326 | } 1327 | 1328 | var GlobalDate = global.Date; 1329 | 1330 | self.install = function(mockDate) { 1331 | if (mockDate instanceof GlobalDate) { 1332 | currentTime = mockDate.getTime(); 1333 | } else { 1334 | currentTime = new GlobalDate().getTime(); 1335 | } 1336 | 1337 | global.Date = FakeDate; 1338 | }; 1339 | 1340 | self.tick = function(millis) { 1341 | millis = millis || 0; 1342 | currentTime = currentTime + millis; 1343 | }; 1344 | 1345 | self.uninstall = function() { 1346 | currentTime = 0; 1347 | global.Date = GlobalDate; 1348 | }; 1349 | 1350 | createDateProperties(); 1351 | 1352 | return self; 1353 | 1354 | function FakeDate() { 1355 | switch(arguments.length) { 1356 | case 0: 1357 | return new GlobalDate(currentTime); 1358 | case 1: 1359 | return new GlobalDate(arguments[0]); 1360 | case 2: 1361 | return new GlobalDate(arguments[0], arguments[1]); 1362 | case 3: 1363 | return new GlobalDate(arguments[0], arguments[1], arguments[2]); 1364 | case 4: 1365 | return new GlobalDate(arguments[0], arguments[1], arguments[2], arguments[3]); 1366 | case 5: 1367 | return new GlobalDate(arguments[0], arguments[1], arguments[2], arguments[3], 1368 | arguments[4]); 1369 | case 6: 1370 | return new GlobalDate(arguments[0], arguments[1], arguments[2], arguments[3], 1371 | arguments[4], arguments[5]); 1372 | case 7: 1373 | return new GlobalDate(arguments[0], arguments[1], arguments[2], arguments[3], 1374 | arguments[4], arguments[5], arguments[6]); 1375 | } 1376 | } 1377 | 1378 | function createDateProperties() { 1379 | 1380 | FakeDate.now = function() { 1381 | if (GlobalDate.now) { 1382 | return currentTime; 1383 | } else { 1384 | throw new Error('Browser does not support Date.now()'); 1385 | } 1386 | }; 1387 | 1388 | FakeDate.toSource = GlobalDate.toSource; 1389 | FakeDate.toString = GlobalDate.toString; 1390 | FakeDate.parse = GlobalDate.parse; 1391 | FakeDate.UTC = GlobalDate.UTC; 1392 | } 1393 | } 1394 | 1395 | return MockDate; 1396 | }; 1397 | 1398 | getJasmineRequireObj().ObjectContaining = function(j$) { 1399 | 1400 | function ObjectContaining(sample) { 1401 | this.sample = sample; 1402 | } 1403 | 1404 | ObjectContaining.prototype.jasmineMatches = function(other, mismatchKeys, mismatchValues) { 1405 | if (typeof(this.sample) !== 'object') { throw new Error('You must provide an object to objectContaining, not \''+this.sample+'\'.'); } 1406 | 1407 | mismatchKeys = mismatchKeys || []; 1408 | mismatchValues = mismatchValues || []; 1409 | 1410 | var hasKey = function(obj, keyName) { 1411 | return obj !== null && !j$.util.isUndefined(obj[keyName]); 1412 | }; 1413 | 1414 | for (var property in this.sample) { 1415 | if (!hasKey(other, property) && hasKey(this.sample, property)) { 1416 | mismatchKeys.push('expected has key \'' + property + '\', but missing from actual.'); 1417 | } 1418 | else if (!j$.matchersUtil.equals(other[property], this.sample[property])) { 1419 | mismatchValues.push('\'' + property + '\' was \'' + (other[property] ? j$.util.htmlEscape(other[property].toString()) : other[property]) + '\' in actual, but was \'' + (this.sample[property] ? j$.util.htmlEscape(this.sample[property].toString()) : this.sample[property]) + '\' in expected.'); 1420 | } 1421 | } 1422 | 1423 | return (mismatchKeys.length === 0 && mismatchValues.length === 0); 1424 | }; 1425 | 1426 | ObjectContaining.prototype.jasmineToString = function() { 1427 | return ''; 1428 | }; 1429 | 1430 | return ObjectContaining; 1431 | }; 1432 | 1433 | getJasmineRequireObj().pp = function(j$) { 1434 | 1435 | function PrettyPrinter() { 1436 | this.ppNestLevel_ = 0; 1437 | this.seen = []; 1438 | } 1439 | 1440 | PrettyPrinter.prototype.format = function(value) { 1441 | this.ppNestLevel_++; 1442 | try { 1443 | if (j$.util.isUndefined(value)) { 1444 | this.emitScalar('undefined'); 1445 | } else if (value === null) { 1446 | this.emitScalar('null'); 1447 | } else if (value === 0 && 1/value === -Infinity) { 1448 | this.emitScalar('-0'); 1449 | } else if (value === j$.getGlobal()) { 1450 | this.emitScalar(''); 1451 | } else if (value.jasmineToString) { 1452 | this.emitScalar(value.jasmineToString()); 1453 | } else if (typeof value === 'string') { 1454 | this.emitString(value); 1455 | } else if (j$.isSpy(value)) { 1456 | this.emitScalar('spy on ' + value.and.identity()); 1457 | } else if (value instanceof RegExp) { 1458 | this.emitScalar(value.toString()); 1459 | } else if (typeof value === 'function') { 1460 | this.emitScalar('Function'); 1461 | } else if (typeof value.nodeType === 'number') { 1462 | this.emitScalar('HTMLNode'); 1463 | } else if (value instanceof Date) { 1464 | this.emitScalar('Date(' + value + ')'); 1465 | } else if (j$.util.arrayContains(this.seen, value)) { 1466 | this.emitScalar(''); 1467 | } else if (j$.isArray_(value) || j$.isA_('Object', value)) { 1468 | this.seen.push(value); 1469 | if (j$.isArray_(value)) { 1470 | this.emitArray(value); 1471 | } else { 1472 | this.emitObject(value); 1473 | } 1474 | this.seen.pop(); 1475 | } else { 1476 | this.emitScalar(value.toString()); 1477 | } 1478 | } finally { 1479 | this.ppNestLevel_--; 1480 | } 1481 | }; 1482 | 1483 | PrettyPrinter.prototype.iterateObject = function(obj, fn) { 1484 | for (var property in obj) { 1485 | if (!Object.prototype.hasOwnProperty.call(obj, property)) { continue; } 1486 | fn(property, obj.__lookupGetter__ ? (!j$.util.isUndefined(obj.__lookupGetter__(property)) && 1487 | obj.__lookupGetter__(property) !== null) : false); 1488 | } 1489 | }; 1490 | 1491 | PrettyPrinter.prototype.emitArray = j$.unimplementedMethod_; 1492 | PrettyPrinter.prototype.emitObject = j$.unimplementedMethod_; 1493 | PrettyPrinter.prototype.emitScalar = j$.unimplementedMethod_; 1494 | PrettyPrinter.prototype.emitString = j$.unimplementedMethod_; 1495 | 1496 | function StringPrettyPrinter() { 1497 | PrettyPrinter.call(this); 1498 | 1499 | this.string = ''; 1500 | } 1501 | 1502 | j$.util.inherit(StringPrettyPrinter, PrettyPrinter); 1503 | 1504 | StringPrettyPrinter.prototype.emitScalar = function(value) { 1505 | this.append(value); 1506 | }; 1507 | 1508 | StringPrettyPrinter.prototype.emitString = function(value) { 1509 | this.append('\'' + value + '\''); 1510 | }; 1511 | 1512 | StringPrettyPrinter.prototype.emitArray = function(array) { 1513 | if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) { 1514 | this.append('Array'); 1515 | return; 1516 | } 1517 | var length = Math.min(array.length, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH); 1518 | this.append('[ '); 1519 | for (var i = 0; i < length; i++) { 1520 | if (i > 0) { 1521 | this.append(', '); 1522 | } 1523 | this.format(array[i]); 1524 | } 1525 | if(array.length > length){ 1526 | this.append(', ...'); 1527 | } 1528 | this.append(' ]'); 1529 | }; 1530 | 1531 | StringPrettyPrinter.prototype.emitObject = function(obj) { 1532 | if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) { 1533 | this.append('Object'); 1534 | return; 1535 | } 1536 | 1537 | var self = this; 1538 | this.append('{ '); 1539 | var first = true; 1540 | 1541 | this.iterateObject(obj, function(property, isGetter) { 1542 | if (first) { 1543 | first = false; 1544 | } else { 1545 | self.append(', '); 1546 | } 1547 | 1548 | self.append(property); 1549 | self.append(': '); 1550 | if (isGetter) { 1551 | self.append(''); 1552 | } else { 1553 | self.format(obj[property]); 1554 | } 1555 | }); 1556 | 1557 | this.append(' }'); 1558 | }; 1559 | 1560 | StringPrettyPrinter.prototype.append = function(value) { 1561 | this.string += value; 1562 | }; 1563 | 1564 | return function(value) { 1565 | var stringPrettyPrinter = new StringPrettyPrinter(); 1566 | stringPrettyPrinter.format(value); 1567 | return stringPrettyPrinter.string; 1568 | }; 1569 | }; 1570 | 1571 | getJasmineRequireObj().QueueRunner = function(j$) { 1572 | 1573 | function once(fn) { 1574 | var called = false; 1575 | return function() { 1576 | if (!called) { 1577 | called = true; 1578 | fn(); 1579 | } 1580 | }; 1581 | } 1582 | 1583 | function QueueRunner(attrs) { 1584 | this.fns = attrs.fns || []; 1585 | this.onComplete = attrs.onComplete || function() {}; 1586 | this.clearStack = attrs.clearStack || function(fn) {fn();}; 1587 | this.onException = attrs.onException || function() {}; 1588 | this.catchException = attrs.catchException || function() { return true; }; 1589 | this.enforceTimeout = attrs.enforceTimeout || function() { return false; }; 1590 | this.userContext = {}; 1591 | this.timer = attrs.timeout || {setTimeout: setTimeout, clearTimeout: clearTimeout}; 1592 | } 1593 | 1594 | QueueRunner.prototype.execute = function() { 1595 | this.run(this.fns, 0); 1596 | }; 1597 | 1598 | QueueRunner.prototype.run = function(fns, recursiveIndex) { 1599 | var length = fns.length, 1600 | self = this, 1601 | iterativeIndex; 1602 | 1603 | for(iterativeIndex = recursiveIndex; iterativeIndex < length; iterativeIndex++) { 1604 | var fn = fns[iterativeIndex]; 1605 | if (fn.length > 0) { 1606 | return attemptAsync(fn); 1607 | } else { 1608 | attemptSync(fn); 1609 | } 1610 | } 1611 | 1612 | var runnerDone = iterativeIndex >= length; 1613 | 1614 | if (runnerDone) { 1615 | this.clearStack(this.onComplete); 1616 | } 1617 | 1618 | function attemptSync(fn) { 1619 | try { 1620 | fn.call(self.userContext); 1621 | } catch (e) { 1622 | handleException(e); 1623 | } 1624 | } 1625 | 1626 | function attemptAsync(fn) { 1627 | var clearTimeout = function () { 1628 | Function.prototype.apply.apply(self.timer.clearTimeout, [j$.getGlobal(), [timeoutId]]); 1629 | }, 1630 | next = once(function () { 1631 | clearTimeout(timeoutId); 1632 | self.run(fns, iterativeIndex + 1); 1633 | }), 1634 | timeoutId; 1635 | 1636 | if (self.enforceTimeout()) { 1637 | timeoutId = Function.prototype.apply.apply(self.timer.setTimeout, [j$.getGlobal(), [function() { 1638 | self.onException(new Error('Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.')); 1639 | next(); 1640 | }, j$.DEFAULT_TIMEOUT_INTERVAL]]); 1641 | } 1642 | 1643 | try { 1644 | fn.call(self.userContext, next); 1645 | } catch (e) { 1646 | handleException(e); 1647 | next(); 1648 | } 1649 | } 1650 | 1651 | function handleException(e) { 1652 | self.onException(e); 1653 | if (!self.catchException(e)) { 1654 | //TODO: set a var when we catch an exception and 1655 | //use a finally block to close the loop in a nice way.. 1656 | throw e; 1657 | } 1658 | } 1659 | }; 1660 | 1661 | return QueueRunner; 1662 | }; 1663 | 1664 | getJasmineRequireObj().ReportDispatcher = function() { 1665 | function ReportDispatcher(methods) { 1666 | 1667 | var dispatchedMethods = methods || []; 1668 | 1669 | for (var i = 0; i < dispatchedMethods.length; i++) { 1670 | var method = dispatchedMethods[i]; 1671 | this[method] = (function(m) { 1672 | return function() { 1673 | dispatch(m, arguments); 1674 | }; 1675 | }(method)); 1676 | } 1677 | 1678 | var reporters = []; 1679 | 1680 | this.addReporter = function(reporter) { 1681 | reporters.push(reporter); 1682 | }; 1683 | 1684 | return this; 1685 | 1686 | function dispatch(method, args) { 1687 | for (var i = 0; i < reporters.length; i++) { 1688 | var reporter = reporters[i]; 1689 | if (reporter[method]) { 1690 | reporter[method].apply(reporter, args); 1691 | } 1692 | } 1693 | } 1694 | } 1695 | 1696 | return ReportDispatcher; 1697 | }; 1698 | 1699 | 1700 | getJasmineRequireObj().SpyStrategy = function() { 1701 | 1702 | function SpyStrategy(options) { 1703 | options = options || {}; 1704 | 1705 | var identity = options.name || 'unknown', 1706 | originalFn = options.fn || function() {}, 1707 | getSpy = options.getSpy || function() {}, 1708 | plan = function() {}; 1709 | 1710 | this.identity = function() { 1711 | return identity; 1712 | }; 1713 | 1714 | this.exec = function() { 1715 | return plan.apply(this, arguments); 1716 | }; 1717 | 1718 | this.callThrough = function() { 1719 | plan = originalFn; 1720 | return getSpy(); 1721 | }; 1722 | 1723 | this.returnValue = function(value) { 1724 | plan = function() { 1725 | return value; 1726 | }; 1727 | return getSpy(); 1728 | }; 1729 | 1730 | this.throwError = function(something) { 1731 | var error = (something instanceof Error) ? something : new Error(something); 1732 | plan = function() { 1733 | throw error; 1734 | }; 1735 | return getSpy(); 1736 | }; 1737 | 1738 | this.callFake = function(fn) { 1739 | plan = fn; 1740 | return getSpy(); 1741 | }; 1742 | 1743 | this.stub = function(fn) { 1744 | plan = function() {}; 1745 | return getSpy(); 1746 | }; 1747 | } 1748 | 1749 | return SpyStrategy; 1750 | }; 1751 | 1752 | getJasmineRequireObj().Suite = function() { 1753 | function Suite(attrs) { 1754 | this.env = attrs.env; 1755 | this.id = attrs.id; 1756 | this.parentSuite = attrs.parentSuite; 1757 | this.description = attrs.description; 1758 | this.onStart = attrs.onStart || function() {}; 1759 | this.resultCallback = attrs.resultCallback || function() {}; 1760 | this.clearStack = attrs.clearStack || function(fn) {fn();}; 1761 | 1762 | this.beforeFns = []; 1763 | this.afterFns = []; 1764 | this.queueRunner = attrs.queueRunner || function() {}; 1765 | this.disabled = false; 1766 | 1767 | this.children = []; 1768 | 1769 | this.result = { 1770 | id: this.id, 1771 | status: this.disabled ? 'disabled' : '', 1772 | description: this.description, 1773 | fullName: this.getFullName() 1774 | }; 1775 | } 1776 | 1777 | Suite.prototype.getFullName = function() { 1778 | var fullName = this.description; 1779 | for (var parentSuite = this.parentSuite; parentSuite; parentSuite = parentSuite.parentSuite) { 1780 | if (parentSuite.parentSuite) { 1781 | fullName = parentSuite.description + ' ' + fullName; 1782 | } 1783 | } 1784 | return fullName; 1785 | }; 1786 | 1787 | Suite.prototype.disable = function() { 1788 | this.disabled = true; 1789 | this.result.status = 'disabled'; 1790 | }; 1791 | 1792 | Suite.prototype.beforeEach = function(fn) { 1793 | this.beforeFns.unshift(fn); 1794 | }; 1795 | 1796 | Suite.prototype.afterEach = function(fn) { 1797 | this.afterFns.unshift(fn); 1798 | }; 1799 | 1800 | Suite.prototype.addChild = function(child) { 1801 | this.children.push(child); 1802 | }; 1803 | 1804 | Suite.prototype.execute = function(onComplete) { 1805 | var self = this; 1806 | 1807 | this.onStart(this); 1808 | 1809 | if (this.disabled) { 1810 | complete(); 1811 | return; 1812 | } 1813 | 1814 | var allFns = []; 1815 | 1816 | for (var i = 0; i < this.children.length; i++) { 1817 | allFns.push(wrapChildAsAsync(this.children[i])); 1818 | } 1819 | 1820 | this.queueRunner({ 1821 | fns: allFns, 1822 | onComplete: complete 1823 | }); 1824 | 1825 | function complete() { 1826 | self.resultCallback(self.result); 1827 | 1828 | if (onComplete) { 1829 | onComplete(); 1830 | } 1831 | } 1832 | 1833 | function wrapChildAsAsync(child) { 1834 | return function(done) { child.execute(done); }; 1835 | } 1836 | }; 1837 | 1838 | return Suite; 1839 | }; 1840 | 1841 | if (typeof window == void 0 && typeof exports == 'object') { 1842 | exports.Suite = jasmineRequire.Suite; 1843 | } 1844 | 1845 | getJasmineRequireObj().Timer = function() { 1846 | var defaultNow = (function(Date) { 1847 | return function() { return new Date().getTime(); }; 1848 | })(Date); 1849 | 1850 | function Timer(options) { 1851 | options = options || {}; 1852 | 1853 | var now = options.now || defaultNow, 1854 | startTime; 1855 | 1856 | this.start = function() { 1857 | startTime = now(); 1858 | }; 1859 | 1860 | this.elapsed = function() { 1861 | return now() - startTime; 1862 | }; 1863 | } 1864 | 1865 | return Timer; 1866 | }; 1867 | 1868 | getJasmineRequireObj().matchersUtil = function(j$) { 1869 | // TODO: what to do about jasmine.pp not being inject? move to JSON.stringify? gut PrettyPrinter? 1870 | 1871 | return { 1872 | equals: function(a, b, customTesters) { 1873 | customTesters = customTesters || []; 1874 | 1875 | return eq(a, b, [], [], customTesters); 1876 | }, 1877 | 1878 | contains: function(haystack, needle, customTesters) { 1879 | customTesters = customTesters || []; 1880 | 1881 | if (Object.prototype.toString.apply(haystack) === '[object Array]') { 1882 | for (var i = 0; i < haystack.length; i++) { 1883 | if (eq(haystack[i], needle, [], [], customTesters)) { 1884 | return true; 1885 | } 1886 | } 1887 | return false; 1888 | } 1889 | return !!haystack && haystack.indexOf(needle) >= 0; 1890 | }, 1891 | 1892 | buildFailureMessage: function() { 1893 | var args = Array.prototype.slice.call(arguments, 0), 1894 | matcherName = args[0], 1895 | isNot = args[1], 1896 | actual = args[2], 1897 | expected = args.slice(3), 1898 | englishyPredicate = matcherName.replace(/[A-Z]/g, function(s) { return ' ' + s.toLowerCase(); }); 1899 | 1900 | var message = 'Expected ' + 1901 | j$.pp(actual) + 1902 | (isNot ? ' not ' : ' ') + 1903 | englishyPredicate; 1904 | 1905 | if (expected.length > 0) { 1906 | for (var i = 0; i < expected.length; i++) { 1907 | if (i > 0) { 1908 | message += ','; 1909 | } 1910 | message += ' ' + j$.pp(expected[i]); 1911 | } 1912 | } 1913 | 1914 | return message + '.'; 1915 | } 1916 | }; 1917 | 1918 | // Equality function lovingly adapted from isEqual in 1919 | // [Underscore](http://underscorejs.org) 1920 | function eq(a, b, aStack, bStack, customTesters) { 1921 | var result = true; 1922 | 1923 | for (var i = 0; i < customTesters.length; i++) { 1924 | var customTesterResult = customTesters[i](a, b); 1925 | if (!j$.util.isUndefined(customTesterResult)) { 1926 | return customTesterResult; 1927 | } 1928 | } 1929 | 1930 | if (a instanceof j$.Any) { 1931 | result = a.jasmineMatches(b); 1932 | if (result) { 1933 | return true; 1934 | } 1935 | } 1936 | 1937 | if (b instanceof j$.Any) { 1938 | result = b.jasmineMatches(a); 1939 | if (result) { 1940 | return true; 1941 | } 1942 | } 1943 | 1944 | if (b instanceof j$.ObjectContaining) { 1945 | result = b.jasmineMatches(a); 1946 | if (result) { 1947 | return true; 1948 | } 1949 | } 1950 | 1951 | if (a instanceof Error && b instanceof Error) { 1952 | return a.message == b.message; 1953 | } 1954 | 1955 | // Identical objects are equal. `0 === -0`, but they aren't identical. 1956 | // See the [Harmony `egal` proposal](http://wiki.ecmascript.org/doku.php?id=harmony:egal). 1957 | if (a === b) { return a !== 0 || 1 / a == 1 / b; } 1958 | // A strict comparison is necessary because `null == undefined`. 1959 | if (a === null || b === null) { return a === b; } 1960 | var className = Object.prototype.toString.call(a); 1961 | if (className != Object.prototype.toString.call(b)) { return false; } 1962 | switch (className) { 1963 | // Strings, numbers, dates, and booleans are compared by value. 1964 | case '[object String]': 1965 | // Primitives and their corresponding object wrappers are equivalent; thus, `"5"` is 1966 | // equivalent to `new String("5")`. 1967 | return a == String(b); 1968 | case '[object Number]': 1969 | // `NaN`s are equivalent, but non-reflexive. An `egal` comparison is performed for 1970 | // other numeric values. 1971 | return a != +a ? b != +b : (a === 0 ? 1 / a == 1 / b : a == +b); 1972 | case '[object Date]': 1973 | case '[object Boolean]': 1974 | // Coerce dates and booleans to numeric primitive values. Dates are compared by their 1975 | // millisecond representations. Note that invalid dates with millisecond representations 1976 | // of `NaN` are not equivalent. 1977 | return +a == +b; 1978 | // RegExps are compared by their source patterns and flags. 1979 | case '[object RegExp]': 1980 | return a.source == b.source && 1981 | a.global == b.global && 1982 | a.multiline == b.multiline && 1983 | a.ignoreCase == b.ignoreCase; 1984 | } 1985 | if (typeof a != 'object' || typeof b != 'object') { return false; } 1986 | // Assume equality for cyclic structures. The algorithm for detecting cyclic 1987 | // structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`. 1988 | var length = aStack.length; 1989 | while (length--) { 1990 | // Linear search. Performance is inversely proportional to the number of 1991 | // unique nested structures. 1992 | if (aStack[length] == a) { return bStack[length] == b; } 1993 | } 1994 | // Add the first object to the stack of traversed objects. 1995 | aStack.push(a); 1996 | bStack.push(b); 1997 | var size = 0; 1998 | // Recursively compare objects and arrays. 1999 | if (className == '[object Array]') { 2000 | // Compare array lengths to determine if a deep comparison is necessary. 2001 | size = a.length; 2002 | result = size == b.length; 2003 | if (result) { 2004 | // Deep compare the contents, ignoring non-numeric properties. 2005 | while (size--) { 2006 | if (!(result = eq(a[size], b[size], aStack, bStack, customTesters))) { break; } 2007 | } 2008 | } 2009 | } else { 2010 | // Objects with different constructors are not equivalent, but `Object`s 2011 | // from different frames are. 2012 | var aCtor = a.constructor, bCtor = b.constructor; 2013 | if (aCtor !== bCtor && !(isFunction(aCtor) && (aCtor instanceof aCtor) && 2014 | isFunction(bCtor) && (bCtor instanceof bCtor))) { 2015 | return false; 2016 | } 2017 | // Deep compare objects. 2018 | for (var key in a) { 2019 | if (has(a, key)) { 2020 | // Count the expected number of properties. 2021 | size++; 2022 | // Deep compare each member. 2023 | if (!(result = has(b, key) && eq(a[key], b[key], aStack, bStack, customTesters))) { break; } 2024 | } 2025 | } 2026 | // Ensure that both objects contain the same number of properties. 2027 | if (result) { 2028 | for (key in b) { 2029 | if (has(b, key) && !(size--)) { break; } 2030 | } 2031 | result = !size; 2032 | } 2033 | } 2034 | // Remove the first object from the stack of traversed objects. 2035 | aStack.pop(); 2036 | bStack.pop(); 2037 | 2038 | return result; 2039 | 2040 | function has(obj, key) { 2041 | return obj.hasOwnProperty(key); 2042 | } 2043 | 2044 | function isFunction(obj) { 2045 | return typeof obj === 'function'; 2046 | } 2047 | } 2048 | }; 2049 | 2050 | getJasmineRequireObj().toBe = function() { 2051 | function toBe() { 2052 | return { 2053 | compare: function(actual, expected) { 2054 | return { 2055 | pass: actual === expected 2056 | }; 2057 | } 2058 | }; 2059 | } 2060 | 2061 | return toBe; 2062 | }; 2063 | 2064 | getJasmineRequireObj().toBeCloseTo = function() { 2065 | 2066 | function toBeCloseTo() { 2067 | return { 2068 | compare: function(actual, expected, precision) { 2069 | if (precision !== 0) { 2070 | precision = precision || 2; 2071 | } 2072 | 2073 | return { 2074 | pass: Math.abs(expected - actual) < (Math.pow(10, -precision) / 2) 2075 | }; 2076 | } 2077 | }; 2078 | } 2079 | 2080 | return toBeCloseTo; 2081 | }; 2082 | 2083 | getJasmineRequireObj().toBeDefined = function() { 2084 | function toBeDefined() { 2085 | return { 2086 | compare: function(actual) { 2087 | return { 2088 | pass: (void 0 !== actual) 2089 | }; 2090 | } 2091 | }; 2092 | } 2093 | 2094 | return toBeDefined; 2095 | }; 2096 | 2097 | getJasmineRequireObj().toBeFalsy = function() { 2098 | function toBeFalsy() { 2099 | return { 2100 | compare: function(actual) { 2101 | return { 2102 | pass: !!!actual 2103 | }; 2104 | } 2105 | }; 2106 | } 2107 | 2108 | return toBeFalsy; 2109 | }; 2110 | 2111 | getJasmineRequireObj().toBeGreaterThan = function() { 2112 | 2113 | function toBeGreaterThan() { 2114 | return { 2115 | compare: function(actual, expected) { 2116 | return { 2117 | pass: actual > expected 2118 | }; 2119 | } 2120 | }; 2121 | } 2122 | 2123 | return toBeGreaterThan; 2124 | }; 2125 | 2126 | 2127 | getJasmineRequireObj().toBeLessThan = function() { 2128 | function toBeLessThan() { 2129 | return { 2130 | 2131 | compare: function(actual, expected) { 2132 | return { 2133 | pass: actual < expected 2134 | }; 2135 | } 2136 | }; 2137 | } 2138 | 2139 | return toBeLessThan; 2140 | }; 2141 | getJasmineRequireObj().toBeNaN = function(j$) { 2142 | 2143 | function toBeNaN() { 2144 | return { 2145 | compare: function(actual) { 2146 | var result = { 2147 | pass: (actual !== actual) 2148 | }; 2149 | 2150 | if (result.pass) { 2151 | result.message = 'Expected actual not to be NaN.'; 2152 | } else { 2153 | result.message = function() { return 'Expected ' + j$.pp(actual) + ' to be NaN.'; }; 2154 | } 2155 | 2156 | return result; 2157 | } 2158 | }; 2159 | } 2160 | 2161 | return toBeNaN; 2162 | }; 2163 | 2164 | getJasmineRequireObj().toBeNull = function() { 2165 | 2166 | function toBeNull() { 2167 | return { 2168 | compare: function(actual) { 2169 | return { 2170 | pass: actual === null 2171 | }; 2172 | } 2173 | }; 2174 | } 2175 | 2176 | return toBeNull; 2177 | }; 2178 | 2179 | getJasmineRequireObj().toBeTruthy = function() { 2180 | 2181 | function toBeTruthy() { 2182 | return { 2183 | compare: function(actual) { 2184 | return { 2185 | pass: !!actual 2186 | }; 2187 | } 2188 | }; 2189 | } 2190 | 2191 | return toBeTruthy; 2192 | }; 2193 | 2194 | getJasmineRequireObj().toBeUndefined = function() { 2195 | 2196 | function toBeUndefined() { 2197 | return { 2198 | compare: function(actual) { 2199 | return { 2200 | pass: void 0 === actual 2201 | }; 2202 | } 2203 | }; 2204 | } 2205 | 2206 | return toBeUndefined; 2207 | }; 2208 | 2209 | getJasmineRequireObj().toContain = function() { 2210 | function toContain(util, customEqualityTesters) { 2211 | customEqualityTesters = customEqualityTesters || []; 2212 | 2213 | return { 2214 | compare: function(actual, expected) { 2215 | 2216 | return { 2217 | pass: util.contains(actual, expected, customEqualityTesters) 2218 | }; 2219 | } 2220 | }; 2221 | } 2222 | 2223 | return toContain; 2224 | }; 2225 | 2226 | getJasmineRequireObj().toEqual = function() { 2227 | 2228 | function toEqual(util, customEqualityTesters) { 2229 | customEqualityTesters = customEqualityTesters || []; 2230 | 2231 | return { 2232 | compare: function(actual, expected) { 2233 | var result = { 2234 | pass: false 2235 | }; 2236 | 2237 | result.pass = util.equals(actual, expected, customEqualityTesters); 2238 | 2239 | return result; 2240 | } 2241 | }; 2242 | } 2243 | 2244 | return toEqual; 2245 | }; 2246 | 2247 | getJasmineRequireObj().toHaveBeenCalled = function(j$) { 2248 | 2249 | function toHaveBeenCalled() { 2250 | return { 2251 | compare: function(actual) { 2252 | var result = {}; 2253 | 2254 | if (!j$.isSpy(actual)) { 2255 | throw new Error('Expected a spy, but got ' + j$.pp(actual) + '.'); 2256 | } 2257 | 2258 | if (arguments.length > 1) { 2259 | throw new Error('toHaveBeenCalled does not take arguments, use toHaveBeenCalledWith'); 2260 | } 2261 | 2262 | result.pass = actual.calls.any(); 2263 | 2264 | result.message = result.pass ? 2265 | 'Expected spy ' + actual.and.identity() + ' not to have been called.' : 2266 | 'Expected spy ' + actual.and.identity() + ' to have been called.'; 2267 | 2268 | return result; 2269 | } 2270 | }; 2271 | } 2272 | 2273 | return toHaveBeenCalled; 2274 | }; 2275 | 2276 | getJasmineRequireObj().toHaveBeenCalledWith = function(j$) { 2277 | 2278 | function toHaveBeenCalledWith(util, customEqualityTesters) { 2279 | return { 2280 | compare: function() { 2281 | var args = Array.prototype.slice.call(arguments, 0), 2282 | actual = args[0], 2283 | expectedArgs = args.slice(1), 2284 | result = { pass: false }; 2285 | 2286 | if (!j$.isSpy(actual)) { 2287 | throw new Error('Expected a spy, but got ' + j$.pp(actual) + '.'); 2288 | } 2289 | 2290 | if (!actual.calls.any()) { 2291 | result.message = function() { return 'Expected spy ' + actual.and.identity() + ' to have been called with ' + j$.pp(expectedArgs) + ' but it was never called.'; }; 2292 | return result; 2293 | } 2294 | 2295 | if (util.contains(actual.calls.allArgs(), expectedArgs, customEqualityTesters)) { 2296 | result.pass = true; 2297 | result.message = function() { return 'Expected spy ' + actual.and.identity() + ' not to have been called with ' + j$.pp(expectedArgs) + ' but it was.'; }; 2298 | } else { 2299 | result.message = function() { return 'Expected spy ' + actual.and.identity() + ' to have been called with ' + j$.pp(expectedArgs) + ' but actual calls were ' + j$.pp(actual.calls.allArgs()).replace(/^\[ | \]$/g, '') + '.'; }; 2300 | } 2301 | 2302 | return result; 2303 | } 2304 | }; 2305 | } 2306 | 2307 | return toHaveBeenCalledWith; 2308 | }; 2309 | 2310 | getJasmineRequireObj().toMatch = function() { 2311 | 2312 | function toMatch() { 2313 | return { 2314 | compare: function(actual, expected) { 2315 | var regexp = new RegExp(expected); 2316 | 2317 | return { 2318 | pass: regexp.test(actual) 2319 | }; 2320 | } 2321 | }; 2322 | } 2323 | 2324 | return toMatch; 2325 | }; 2326 | 2327 | getJasmineRequireObj().toThrow = function(j$) { 2328 | 2329 | function toThrow(util) { 2330 | return { 2331 | compare: function(actual, expected) { 2332 | var result = { pass: false }, 2333 | threw = false, 2334 | thrown; 2335 | 2336 | if (typeof actual != 'function') { 2337 | throw new Error('Actual is not a Function'); 2338 | } 2339 | 2340 | try { 2341 | actual(); 2342 | } catch (e) { 2343 | threw = true; 2344 | thrown = e; 2345 | } 2346 | 2347 | if (!threw) { 2348 | result.message = 'Expected function to throw an exception.'; 2349 | return result; 2350 | } 2351 | 2352 | if (arguments.length == 1) { 2353 | result.pass = true; 2354 | result.message = function() { return 'Expected function not to throw, but it threw ' + j$.pp(thrown) + '.'; }; 2355 | 2356 | return result; 2357 | } 2358 | 2359 | if (util.equals(thrown, expected)) { 2360 | result.pass = true; 2361 | result.message = function() { return 'Expected function not to throw ' + j$.pp(expected) + '.'; }; 2362 | } else { 2363 | result.message = function() { return 'Expected function to throw ' + j$.pp(expected) + ', but it threw ' + j$.pp(thrown) + '.'; }; 2364 | } 2365 | 2366 | return result; 2367 | } 2368 | }; 2369 | } 2370 | 2371 | return toThrow; 2372 | }; 2373 | 2374 | getJasmineRequireObj().toThrowError = function(j$) { 2375 | function toThrowError (util) { 2376 | return { 2377 | compare: function(actual) { 2378 | var threw = false, 2379 | pass = {pass: true}, 2380 | fail = {pass: false}, 2381 | thrown, 2382 | errorType, 2383 | message, 2384 | regexp, 2385 | name, 2386 | constructorName; 2387 | 2388 | if (typeof actual != 'function') { 2389 | throw new Error('Actual is not a Function'); 2390 | } 2391 | 2392 | extractExpectedParams.apply(null, arguments); 2393 | 2394 | try { 2395 | actual(); 2396 | } catch (e) { 2397 | threw = true; 2398 | thrown = e; 2399 | } 2400 | 2401 | if (!threw) { 2402 | fail.message = 'Expected function to throw an Error.'; 2403 | return fail; 2404 | } 2405 | 2406 | if (!(thrown instanceof Error)) { 2407 | fail.message = function() { return 'Expected function to throw an Error, but it threw ' + j$.pp(thrown) + '.'; }; 2408 | return fail; 2409 | } 2410 | 2411 | if (arguments.length == 1) { 2412 | pass.message = 'Expected function not to throw an Error, but it threw ' + fnNameFor(thrown) + '.'; 2413 | return pass; 2414 | } 2415 | 2416 | if (errorType) { 2417 | name = fnNameFor(errorType); 2418 | constructorName = fnNameFor(thrown.constructor); 2419 | } 2420 | 2421 | if (errorType && message) { 2422 | if (thrown.constructor == errorType && util.equals(thrown.message, message)) { 2423 | pass.message = function() { return 'Expected function not to throw ' + name + ' with message ' + j$.pp(message) + '.'; }; 2424 | return pass; 2425 | } else { 2426 | fail.message = function() { return 'Expected function to throw ' + name + ' with message ' + j$.pp(message) + 2427 | ', but it threw ' + constructorName + ' with message ' + j$.pp(thrown.message) + '.'; }; 2428 | return fail; 2429 | } 2430 | } 2431 | 2432 | if (errorType && regexp) { 2433 | if (thrown.constructor == errorType && regexp.test(thrown.message)) { 2434 | pass.message = function() { return 'Expected function not to throw ' + name + ' with message matching ' + j$.pp(regexp) + '.'; }; 2435 | return pass; 2436 | } else { 2437 | fail.message = function() { return 'Expected function to throw ' + name + ' with message matching ' + j$.pp(regexp) + 2438 | ', but it threw ' + constructorName + ' with message ' + j$.pp(thrown.message) + '.'; }; 2439 | return fail; 2440 | } 2441 | } 2442 | 2443 | if (errorType) { 2444 | if (thrown.constructor == errorType) { 2445 | pass.message = 'Expected function not to throw ' + name + '.'; 2446 | return pass; 2447 | } else { 2448 | fail.message = 'Expected function to throw ' + name + ', but it threw ' + constructorName + '.'; 2449 | return fail; 2450 | } 2451 | } 2452 | 2453 | if (message) { 2454 | if (thrown.message == message) { 2455 | pass.message = function() { return 'Expected function not to throw an exception with message ' + j$.pp(message) + '.'; }; 2456 | return pass; 2457 | } else { 2458 | fail.message = function() { return 'Expected function to throw an exception with message ' + j$.pp(message) + 2459 | ', but it threw an exception with message ' + j$.pp(thrown.message) + '.'; }; 2460 | return fail; 2461 | } 2462 | } 2463 | 2464 | if (regexp) { 2465 | if (regexp.test(thrown.message)) { 2466 | pass.message = function() { return 'Expected function not to throw an exception with a message matching ' + j$.pp(regexp) + '.'; }; 2467 | return pass; 2468 | } else { 2469 | fail.message = function() { return 'Expected function to throw an exception with a message matching ' + j$.pp(regexp) + 2470 | ', but it threw an exception with message ' + j$.pp(thrown.message) + '.'; }; 2471 | return fail; 2472 | } 2473 | } 2474 | 2475 | function fnNameFor(func) { 2476 | return func.name || func.toString().match(/^\s*function\s*(\w*)\s*\(/)[1]; 2477 | } 2478 | 2479 | function extractExpectedParams() { 2480 | if (arguments.length == 1) { 2481 | return; 2482 | } 2483 | 2484 | if (arguments.length == 2) { 2485 | var expected = arguments[1]; 2486 | 2487 | if (expected instanceof RegExp) { 2488 | regexp = expected; 2489 | } else if (typeof expected == 'string') { 2490 | message = expected; 2491 | } else if (checkForAnErrorType(expected)) { 2492 | errorType = expected; 2493 | } 2494 | 2495 | if (!(errorType || message || regexp)) { 2496 | throw new Error('Expected is not an Error, string, or RegExp.'); 2497 | } 2498 | } else { 2499 | if (checkForAnErrorType(arguments[1])) { 2500 | errorType = arguments[1]; 2501 | } else { 2502 | throw new Error('Expected error type is not an Error.'); 2503 | } 2504 | 2505 | if (arguments[2] instanceof RegExp) { 2506 | regexp = arguments[2]; 2507 | } else if (typeof arguments[2] == 'string') { 2508 | message = arguments[2]; 2509 | } else { 2510 | throw new Error('Expected error message is not a string or RegExp.'); 2511 | } 2512 | } 2513 | } 2514 | 2515 | function checkForAnErrorType(type) { 2516 | if (typeof type !== 'function') { 2517 | return false; 2518 | } 2519 | 2520 | var Surrogate = function() {}; 2521 | Surrogate.prototype = type.prototype; 2522 | return (new Surrogate()) instanceof Error; 2523 | } 2524 | } 2525 | }; 2526 | } 2527 | 2528 | return toThrowError; 2529 | }; 2530 | 2531 | getJasmineRequireObj().interface = function(jasmine, env) { 2532 | var jasmineInterface = { 2533 | describe: function(description, specDefinitions) { 2534 | return env.describe(description, specDefinitions); 2535 | }, 2536 | 2537 | xdescribe: function(description, specDefinitions) { 2538 | return env.xdescribe(description, specDefinitions); 2539 | }, 2540 | 2541 | it: function(desc, func) { 2542 | return env.it(desc, func); 2543 | }, 2544 | 2545 | xit: function(desc, func) { 2546 | return env.xit(desc, func); 2547 | }, 2548 | 2549 | beforeEach: function(beforeEachFunction) { 2550 | return env.beforeEach(beforeEachFunction); 2551 | }, 2552 | 2553 | afterEach: function(afterEachFunction) { 2554 | return env.afterEach(afterEachFunction); 2555 | }, 2556 | 2557 | expect: function(actual) { 2558 | return env.expect(actual); 2559 | }, 2560 | 2561 | pending: function() { 2562 | return env.pending(); 2563 | }, 2564 | 2565 | spyOn: function(obj, methodName) { 2566 | return env.spyOn(obj, methodName); 2567 | }, 2568 | 2569 | jsApiReporter: new jasmine.JsApiReporter({ 2570 | timer: new jasmine.Timer() 2571 | }), 2572 | 2573 | jasmine: jasmine 2574 | }; 2575 | 2576 | jasmine.addCustomEqualityTester = function(tester) { 2577 | env.addCustomEqualityTester(tester); 2578 | }; 2579 | 2580 | jasmine.addMatchers = function(matchers) { 2581 | return env.addMatchers(matchers); 2582 | }; 2583 | 2584 | jasmine.clock = function() { 2585 | return env.clock; 2586 | }; 2587 | 2588 | return jasmineInterface; 2589 | }; 2590 | 2591 | getJasmineRequireObj().version = function() { 2592 | return '2.0.3'; 2593 | }; 2594 | -------------------------------------------------------------------------------- /tests/lib/jasmine-2.0.3/jasmine_favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nfriedly/Javascript-Flash-Cookies/2621f029e765be4a835a6ef0ad789a54a49cbd3c/tests/lib/jasmine-2.0.3/jasmine_favicon.png -------------------------------------------------------------------------------- /tests/lib/jasmine-jsreporter.js: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Jasmine JSReporter project from Ivan De Marino. 3 | 4 | Copyright (C) 2011-2014 Ivan De Marino 5 | Copyright (C) 2014 Alex Treppass 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | * Neither the name of the nor the 16 | names of its contributors may be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | ARE DISCLAIMED. IN NO EVENT SHALL IVAN DE MARINO BE LIABLE FOR ANY 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | (function (jasmine) { 31 | 32 | if (!jasmine) { 33 | throw new Error("[Jasmine JSReporter] 'Jasmine' library not found"); 34 | } 35 | 36 | // ------------------------------------------------------------------------ 37 | // Jasmine JSReporter for Jasmine 1.x 38 | // ------------------------------------------------------------------------ 39 | 40 | /** 41 | * Calculate elapsed time, in Seconds. 42 | * @param startMs Start time in Milliseconds 43 | * @param finishMs Finish time in Milliseconds 44 | * @return Elapsed time in Seconds */ 45 | function elapsedSec (startMs, finishMs) { 46 | return (finishMs - startMs) / 1000; 47 | } 48 | 49 | /** 50 | * Round an amount to the given number of Digits. 51 | * If no number of digits is given, than '2' is assumed. 52 | * @param amount Amount to round 53 | * @param numOfDecDigits Number of Digits to round to. Default value is '2'. 54 | * @return Rounded amount */ 55 | function round (amount, numOfDecDigits) { 56 | numOfDecDigits = numOfDecDigits || 2; 57 | return Math.round(amount * Math.pow(10, numOfDecDigits)) / Math.pow(10, numOfDecDigits); 58 | } 59 | 60 | /** 61 | * Create a new array which contains only the failed items. 62 | * @param items Items which will be filtered 63 | * @returns {Array} of failed items */ 64 | function failures (items) { 65 | var fs = [], i, v; 66 | for (i = 0; i < items.length; i += 1) { 67 | v = items[i]; 68 | if (!v.passed_) { 69 | fs.push(v); 70 | } 71 | } 72 | return fs; 73 | } 74 | 75 | /** 76 | * Collect information about a Suite, recursively, and return a JSON result. 77 | * @param suite The Jasmine Suite to get data from 78 | */ 79 | function getSuiteData (suite) { 80 | var suiteData = { 81 | description : suite.description, 82 | durationSec : 0, 83 | specs: [], 84 | suites: [], 85 | passed: true 86 | }, 87 | specs = suite.specs(), 88 | suites = suite.suites(), 89 | i, ilen; 90 | 91 | // Loop over all the Suite's Specs 92 | for (i = 0, ilen = specs.length; i < ilen; ++i) { 93 | suiteData.specs[i] = { 94 | description : specs[i].description, 95 | durationSec : specs[i].durationSec, 96 | passed : specs[i].results().passedCount === specs[i].results().totalCount, 97 | skipped : specs[i].results().skipped, 98 | passedCount : specs[i].results().passedCount, 99 | failedCount : specs[i].results().failedCount, 100 | totalCount : specs[i].results().totalCount, 101 | failures: failures(specs[i].results().getItems()) 102 | }; 103 | suiteData.passed = !suiteData.specs[i].passed ? false : suiteData.passed; 104 | suiteData.durationSec += suiteData.specs[i].durationSec; 105 | } 106 | 107 | // Loop over all the Suite's sub-Suites 108 | for (i = 0, ilen = suites.length; i < ilen; ++i) { 109 | suiteData.suites[i] = getSuiteData(suites[i]); //< recursive population 110 | suiteData.passed = !suiteData.suites[i].passed ? false : suiteData.passed; 111 | suiteData.durationSec += suiteData.suites[i].durationSec; 112 | } 113 | 114 | // Rounding duration numbers to 3 decimal digits 115 | suiteData.durationSec = round(suiteData.durationSec, 4); 116 | 117 | return suiteData; 118 | } 119 | 120 | var JSReporter = function () { 121 | }; 122 | 123 | JSReporter.prototype = { 124 | reportRunnerStarting: function (runner) { 125 | // Nothing to do 126 | }, 127 | 128 | reportSpecStarting: function (spec) { 129 | // Start timing this spec 130 | spec.startedAt = new Date(); 131 | }, 132 | 133 | reportSpecResults: function (spec) { 134 | // Finish timing this spec and calculate duration/delta (in sec) 135 | spec.finishedAt = new Date(); 136 | // If the spec was skipped, reportSpecStarting is never called and spec.startedAt is undefined 137 | spec.durationSec = spec.startedAt ? elapsedSec(spec.startedAt.getTime(), spec.finishedAt.getTime()) : 0; 138 | }, 139 | 140 | reportSuiteResults: function (suite) { 141 | // Nothing to do 142 | }, 143 | 144 | reportRunnerResults: function (runner) { 145 | var suites = runner.suites(), 146 | i, j, ilen; 147 | 148 | // Attach results to the "jasmine" object to make those results easy to scrap/find 149 | jasmine.runnerResults = { 150 | suites: [], 151 | durationSec : 0, 152 | passed : true 153 | }; 154 | 155 | // Loop over all the Suites 156 | for (i = 0, ilen = suites.length, j = 0; i < ilen; ++i) { 157 | if (suites[i].parentSuite === null) { 158 | jasmine.runnerResults.suites[j] = getSuiteData(suites[i]); 159 | // If 1 suite fails, the whole runner fails 160 | jasmine.runnerResults.passed = !jasmine.runnerResults.suites[j].passed ? false : jasmine.runnerResults.passed; 161 | // Add up all the durations 162 | jasmine.runnerResults.durationSec += jasmine.runnerResults.suites[j].durationSec; 163 | j++; 164 | } 165 | } 166 | 167 | // Decorate the 'jasmine' object with getters 168 | jasmine.getJSReport = function () { 169 | if (jasmine.runnerResults) { 170 | return jasmine.runnerResults; 171 | } 172 | return null; 173 | }; 174 | jasmine.getJSReportAsString = function () { 175 | return JSON.stringify(jasmine.getJSReport()); 176 | }; 177 | } 178 | }; 179 | 180 | // export public 181 | jasmine.JSReporter = JSReporter; 182 | 183 | 184 | // ------------------------------------------------------------------------ 185 | // Jasmine JSReporter for Jasmine 2.0 186 | // ------------------------------------------------------------------------ 187 | 188 | /* 189 | Simple timer implementation 190 | */ 191 | var Timer = function () {}; 192 | 193 | Timer.prototype.start = function () { 194 | this.startTime = new Date().getTime(); 195 | return this; 196 | }; 197 | 198 | Timer.prototype.elapsed = function () { 199 | if (this.startTime == null) { 200 | return -1; 201 | } 202 | return new Date().getTime() - this.startTime; 203 | }; 204 | 205 | /* 206 | Utility methods 207 | */ 208 | var _extend = function (obj1, obj2) { 209 | for (var prop in obj2) { 210 | obj1[prop] = obj2[prop]; 211 | } 212 | return obj1; 213 | }; 214 | var _clone = function (obj) { 215 | if (obj !== Object(obj)) { 216 | return obj; 217 | } 218 | return _extend({}, obj); 219 | }; 220 | 221 | jasmine.JSReporter2 = function () { 222 | this.specs = {}; 223 | this.suites = {}; 224 | this.rootSuites = []; 225 | this.suiteStack = []; 226 | 227 | // export methods under jasmine namespace 228 | jasmine.getJSReport = this.getJSReport; 229 | jasmine.getJSReportAsString = this.getJSReportAsString; 230 | }; 231 | 232 | var JSR = jasmine.JSReporter2.prototype; 233 | 234 | // Reporter API methods 235 | // -------------------- 236 | 237 | JSR.suiteStarted = function (suite) { 238 | suite = this._cacheSuite(suite); 239 | // build up suite tree as we go 240 | suite.specs = []; 241 | suite.suites = []; 242 | suite.passed = true; 243 | suite.parentId = this.suiteStack.slice(this.suiteStack.length -1)[0]; 244 | if (suite.parentId) { 245 | this.suites[suite.parentId].suites.push(suite); 246 | } else { 247 | this.rootSuites.push(suite.id); 248 | } 249 | this.suiteStack.push(suite.id); 250 | suite.timer = new Timer().start(); 251 | }; 252 | 253 | JSR.suiteDone = function (suite) { 254 | suite = this._cacheSuite(suite); 255 | suite.duration = suite.timer.elapsed(); 256 | suite.durationSec = suite.duration / 1000; 257 | this.suiteStack.pop(); 258 | 259 | // maintain parent suite state 260 | var parent = this.suites[suite.parentId]; 261 | if (parent) { 262 | parent.passed = parent.passed && suite.passed; 263 | } 264 | 265 | // keep report representation clean 266 | delete suite.timer; 267 | delete suite.id; 268 | delete suite.parentId; 269 | delete suite.fullName; 270 | }; 271 | 272 | JSR.specStarted = function (spec) { 273 | spec = this._cacheSpec(spec); 274 | spec.timer = new Timer().start(); 275 | // build up suites->spec tree as we go 276 | spec.suiteId = this.suiteStack.slice(this.suiteStack.length -1)[0]; 277 | this.suites[spec.suiteId].specs.push(spec); 278 | }; 279 | 280 | JSR.specDone = function (spec) { 281 | spec = this._cacheSpec(spec); 282 | 283 | spec.duration = spec.timer.elapsed(); 284 | spec.durationSec = spec.duration / 1000; 285 | 286 | spec.skipped = spec.status === 'pending'; 287 | spec.passed = spec.skipped || spec.status === 'passed'; 288 | 289 | spec.totalCount = spec.passedExpectations.length + spec.failedExpectations.length; 290 | spec.passedCount = spec.passedExpectations.length; 291 | spec.failedCount = spec.failedExpectations.length; 292 | spec.failures = []; 293 | 294 | for (var i = 0, j = spec.failedExpectations.length; i < j; i++) { 295 | var fail = spec.failedExpectations[i]; 296 | spec.failures.push({ 297 | type: 'expect', 298 | expected: fail.expected, 299 | passed: false, 300 | message: fail.message, 301 | matcherName: fail.matcherName, 302 | trace: { 303 | stack: fail.stack 304 | } 305 | }); 306 | } 307 | 308 | // maintain parent suite state 309 | var parent = this.suites[spec.suiteId]; 310 | if (spec.failed) { 311 | parent.failingSpecs.push(spec); 312 | } 313 | parent.passed = parent.passed && spec.passed; 314 | 315 | // keep report representation clean 316 | delete spec.timer; 317 | delete spec.totalExpectations; 318 | delete spec.passedExpectations; 319 | delete spec.suiteId; 320 | delete spec.fullName; 321 | delete spec.id; 322 | delete spec.status; 323 | delete spec.failedExpectations; 324 | }; 325 | 326 | JSR.jasmineDone = function () { 327 | this._buildReport(); 328 | }; 329 | 330 | JSR.getJSReport = function () { 331 | if (jasmine.jsReport) { 332 | return jasmine.jsReport; 333 | } 334 | }; 335 | 336 | JSR.getJSReportAsString = function () { 337 | if (jasmine.jsReport) { 338 | return JSON.stringify(jasmine.jsReport); 339 | } 340 | }; 341 | 342 | // Private methods 343 | // --------------- 344 | 345 | JSR._haveSpec = function (spec) { 346 | return this.specs[spec.id] != null; 347 | }; 348 | 349 | JSR._cacheSpec = function (spec) { 350 | var existing = this.specs[spec.id]; 351 | if (existing == null) { 352 | existing = this.specs[spec.id] = _clone(spec); 353 | } else { 354 | _extend(existing, spec); 355 | } 356 | return existing; 357 | }; 358 | 359 | JSR._haveSuite = function (suite) { 360 | return this.suites[suite.id] != null; 361 | }; 362 | 363 | JSR._cacheSuite = function (suite) { 364 | var existing = this.suites[suite.id]; 365 | if (existing == null) { 366 | existing = this.suites[suite.id] = _clone(suite); 367 | } else { 368 | _extend(existing, suite); 369 | } 370 | return existing; 371 | }; 372 | 373 | JSR._buildReport = function () { 374 | var overallDuration = 0; 375 | var overallPassed = true; 376 | var overallSuites = []; 377 | 378 | for (var i = 0, j = this.rootSuites.length; i < j; i++) { 379 | var suite = this.suites[this.rootSuites[i]]; 380 | overallDuration += suite.duration; 381 | overallPassed = overallPassed && suite.passed; 382 | overallSuites.push(suite); 383 | } 384 | 385 | jasmine.jsReport = { 386 | passed: overallPassed, 387 | durationSec: overallDuration / 1000, 388 | suites: overallSuites 389 | }; 390 | }; 391 | 392 | })(jasmine); -------------------------------------------------------------------------------- /tests/spec-runner.html: -------------------------------------------------------------------------------- 1 | 2 | 32 | 33 | 34 | Jasmine Spec Runner 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /tests/spec/flashcookies-spec.js: -------------------------------------------------------------------------------- 1 | /*global SwfStore: false, jasmine: false, describe: false, it: false, expect: false, beforeEach: false, afterEach: false*/ 2 | describe("SwfStore()", function() { 3 | "use strict"; 4 | 5 | var SWF_PATH = "../dist/storage.swf?" + (new Date()).getTime(); 6 | 7 | var onerror; 8 | var config; 9 | var instance; 10 | 11 | beforeEach(function() { 12 | onerror = jasmine.createSpy("onerror").and.throwError('onerror callback fired'); 13 | /** 14 | * @param {string} [config.swf_url=storage.swf] - Url to storage.swf. Must be an absolute url (with http:// and all) to work cross-domain 15 | * @param {functon} [config.onready] Callback function that is fired when the SwfStore is loaded. Recommended. 16 | * @param {function} [config.onerror] Callback function that is fired if the SwfStore fails to load. Recommended. 17 | * @param {string} [config.namespace="swfstore"] The namespace to use in both JS and the SWF. Allows a page to have more than one instance of SwfStore. 18 | * @param {integer} [config.timeout=10] The number of seconds to wait before assuming the user does not have flash. 19 | * @param {boolean} [config.debug=false] Is d 20 | */ 21 | config = { 22 | swf_url: SWF_PATH, 23 | timeout: 4.5, 24 | onerror: onerror, 25 | namespace: "test_" + Math.random().toString().substr(2), 26 | debug: true 27 | }; 28 | }); 29 | 30 | function getInstance(cb) { 31 | config.onready = cb; 32 | instance = new SwfStore(config); 33 | } 34 | 35 | function getInstanceAndFinishTest(done, test) { 36 | getInstance(function() { 37 | test(); 38 | done(); 39 | }); 40 | } 41 | 42 | afterEach(function() { 43 | if (instance) { 44 | instance.clearAll(); 45 | instance = null; 46 | } 47 | }); 48 | 49 | it("should exist", function() { 50 | expect(SwfStore).toBeDefined(); 51 | }); 52 | 53 | it("should be able to create a new instance", function(done) { 54 | config.onready = done; 55 | instance = new SwfStore(config); 56 | expect(instance).toBeDefined(); 57 | }); 58 | 59 | it("should use the given swf_url config", function(done) { 60 | config.onready = done; 61 | instance = new SwfStore(config); 62 | expect(instance.config.swf_url).toBe(SWF_PATH); 63 | }); 64 | 65 | it("should fire the callback after the SWF loads", function(done) { 66 | getInstanceAndFinishTest(done, function() { 67 | expect(onerror).not.toHaveBeenCalled(); 68 | }); 69 | }); 70 | 71 | it("should fire the error callback if the SWF fails to load", function(done) { 72 | var onready = jasmine.createSpy("onready"); 73 | var config = { 74 | swf_url: "example_invalid_swf_url", 75 | onready: onready, 76 | onerror: function() { 77 | expect(onready).not.toHaveBeenCalled(); 78 | instance = null; // so that we don't try to call clearAll() on it in the afterEach() 79 | done(); 80 | }, 81 | timeout: 1, 82 | namespace: "_" + Math.random(), 83 | debug: true 84 | }; 85 | instance = new SwfStore(config); 86 | }); 87 | 88 | it("should allow namespaces to contain forward slashes (/)", function(done) { 89 | config.onready = function() { 90 | expect(onerror).not.toHaveBeenCalled(); 91 | instance.set("myKey", "myValue"); 92 | expect(instance.get("myKey")).toBe("myValue"); 93 | done(); 94 | }; 95 | config.namespace = "foo/bar"; 96 | instance = new SwfStore(config); 97 | }); 98 | 99 | it("should allow namespaces to contain multiple forward slashes (/)", function(done) { 100 | config.onready = function() { 101 | expect(onerror).not.toHaveBeenCalled(); 102 | instance.set("myKey", "myValue"); 103 | expect(instance.get("myKey")).toBe("myValue"); 104 | done(); 105 | }; 106 | config.namespace = "foo/bar/baz"; 107 | instance = new SwfStore(config); 108 | }); 109 | 110 | describe('.set()', function() { 111 | it("should store values", function(done) { 112 | getInstanceAndFinishTest(done, function() { 113 | expect(onerror).not.toHaveBeenCalled(); 114 | instance.set("myKey", "myValue"); 115 | expect(instance.get("myKey")).toBe("myValue"); 116 | }); 117 | }); 118 | 119 | it('should clear a value when called with `null`', function(done) { 120 | getInstanceAndFinishTest(done, function() { 121 | expect(onerror).not.toHaveBeenCalled(); 122 | instance.set("key1", "val1"); 123 | expect(instance.get("key1")).toBe("val1"); 124 | instance.set("key1", null); 125 | expect(instance.get("key1")).toBe(null); 126 | }); 127 | }); 128 | }); 129 | 130 | describe('.get()', function() { 131 | it("should retrieve values", function(done) { 132 | getInstanceAndFinishTest(done, function() { 133 | expect(onerror).not.toHaveBeenCalled(); 134 | instance.set("myKey", "myValue"); 135 | expect(instance.get("myKey")).toBe("myValue"); 136 | }); 137 | }); 138 | }); 139 | 140 | describe('.clear()', function() { 141 | it("should clear previously set values", function(done) { 142 | getInstanceAndFinishTest(done, function() { 143 | expect(onerror).not.toHaveBeenCalled(); 144 | instance.clear("myKey"); 145 | expect(instance.get("myKey")).toBe(null); 146 | }); 147 | }); 148 | }); 149 | 150 | describe('.getAll()', function() { 151 | it("should return multiple keys", function(done) { 152 | getInstanceAndFinishTest(done, function() { 153 | expect(onerror).not.toHaveBeenCalled(); 154 | instance.set("key1", "val1"); 155 | instance.set("key2", "val2"); 156 | expect(instance.getAll()).toEqual({ 157 | key1: "val1", 158 | key2: "val2" 159 | }); 160 | }); 161 | }); 162 | it("should allow for keys that begin with numbers", function(done) { 163 | // https://github.com/nfriedly/Javascript-Flash-Cookies/issues/21 164 | getInstanceAndFinishTest(done, function() { 165 | expect(onerror).not.toHaveBeenCalled(); 166 | instance.set("42532093b13e5cbb0f4e4d2", "val1"); 167 | expect(instance.getAll()).toEqual({ 168 | "42532093b13e5cbb0f4e4d2": "val1" 169 | }); 170 | }); 171 | }); 172 | 173 | it("should allow for keys that contain dots", function(done) { 174 | // https://github.com/nfriedly/Javascript-Flash-Cookies/issues/21 175 | getInstanceAndFinishTest(done, function() { 176 | expect(onerror).not.toHaveBeenCalled(); 177 | instance.set("15BWminori.jpg", "val1"); 178 | expect(instance.getAll()).toEqual({ 179 | "15BWminori.jpg": "val1" 180 | }); 181 | }); 182 | }); 183 | 184 | 185 | it("should allow fot keys that contain quotes", function(done) { 186 | // https://github.com/nfriedly/Javascript-Flash-Cookies/issues/21 187 | getInstanceAndFinishTest(done, function() { 188 | expect(onerror).not.toHaveBeenCalled(); 189 | instance.set("'singlequotes'", "val1"); 190 | instance.set('"doublequotes"', "val2"); 191 | expect(instance.getAll()).toEqual({ 192 | "'singlequotes'": "val1", 193 | '"doublequotes"': "val2" 194 | }); 195 | }); 196 | }); 197 | }); 198 | 199 | describe('.clearAll()', function() { 200 | it('should remove all values', function(done) { 201 | getInstanceAndFinishTest(done, function() { 202 | expect(onerror).not.toHaveBeenCalled(); 203 | instance.set("'singlequotes'", "val1"); 204 | instance.set('"doublequotes"', "val2"); 205 | instance.set("15BWminori.jpg", "val1"); 206 | instance.set("42532093b13e5cbb0f4e4d2", "val1"); 207 | instance.set("myKey", "myVal"); 208 | instance.clearAll(); 209 | expect(instance.get("myKey")).toBe(null); 210 | expect(instance.getAll()).toEqual({}); 211 | }); 212 | }); 213 | }); 214 | 215 | }); 216 | --------------------------------------------------------------------------------