Browse Source

bringing in usertiming node module so that it is easier to start gathering some performance metrics

Shaddock Heath 10 years ago
parent
commit
2f94448adf

+ 20 - 0
Build/node_modules/usertiming/LICENSE.txt

@@ -0,0 +1,20 @@
+Copyright (c) 2015 Nic Jansma, http://nicj.net
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

+ 136 - 0
Build/node_modules/usertiming/README.md

@@ -0,0 +1,136 @@
+# UserTiming.js
+
+v0.1.7
+
+Copyright 2014 Nic Jansma
+
+http://nicj.net
+
+Licensed under the MIT license
+
+## Introduction
+
+UserTiming.js is a polyfill that adds [UserTiming](http://www.w3.org/TR/user-timing/) support to browsers
+that do not natively support it.
+
+UserTiming is accessed via the [PerformanceTimeline](http://www.w3.org/TR/performance-timeline/), and requires
+[``window.performance.now()``](http://www.w3.org/TR/hr-time/) support, so UserTiming.js
+adds a limited version of these interfaces if the browser does not support them (which is likely the case if the browser
+does not natively support UserTiming).
+
+As of 2013-04-15, UserTiming is natively supported by the following browsers:
+
+* IE 10+
+* Chrome 25+ (prefixed)
+
+UserTiming.js has been verified to add UserTiming support to the following browsers:
+
+* IE 6-9
+* Firefox 3.6+ (previous versions not tested)
+* Safari 4.0.5+ (previous versions not tested)
+* Opera 10.50+ (previous versions not tested)
+
+UserTiming.js will detect native implementations of UserTiming, ``window.performance.now()`` and
+the PerformanceTimeline and will not make any changes if those interfaces already exist.  When a prefixed version
+is found, it is copied over to the unprefixed name.
+
+## Download
+
+Releases are available for download from [GitHub](https://github.com/nicjansma/usertiming.js).
+
+__Development:__ [usertiming.js](https://github.com/nicjansma/usertiming.js/raw/master/src/usertiming.js)
+    - 18.1kb
+
+__Production:__ [usertiming.min.js](https://github.com/nicjansma/usertiming.js/raw/master/dist/usertiming.min.js)
+    - 1,187b (minified / gzipped)
+
+usertiming.js is also available as the [npm usertiming module](https://npmjs.org/package/usertiming). You can install
+using  Node Package Manager (npm):
+
+    npm install usertiming
+
+usertiming.js is also available via [bower](http://bower.io/). You can install using:
+
+    bower install usertiming
+
+## Usage
+
+Please see the [W3C UserTiming API Reference](http://www.w3.org/TR/user-timing/) for details on how to use the
+UserTiming API.
+
+To include the UserTiming.js polyfill, simply include it via a script tag:
+
+```html
+<script type="text/javascript" src="usertiming.min.js"></script>
+```
+
+## Disadvantages of UserTiming.js over native implementations
+
+UserTiming.js provides a 100% functional JavaScript implementation of UserTiming. However, implementing the API in
+JavaScript has some disadvantages over native (built into the browser) implementations.
+
+1. If the browser does not natively support
+    [DOMHighResolutionTimestamps / ``window.performance.now()``](http://www.w3.org/TR/hr-time/), UserTiming.js adds a
+    small shim (via the `Date` object) to mock this interface. However, DOMHighResolutionTimestamp provides higher
+    precision (0.1 milliseconds or better) than the native `Date` object can (1.0 millisecond -- or worse in older
+    browsers).  So if `window.performance.now()` has to be mocked, it will not be as precise as native implementations.
+
+2. UserTiming marks and measures are queried via the [PerformanceTimeline](http://www.w3.org/TR/performance-timeline/),
+    for example by using `getEntries()`, `getEntriesByType()` or `getEntriesByName()`.  UserTiming.js adds these
+    interfaces so you can query for marks and measures, but they obviously will not support any other PerformanceEntrys
+    such as [ResourceTiming](http://www.w3.org/TR/resource-timing/).
+
+3. UserTiming.js is implemented in JavaScript, so it will be less performant than a native implementation.  If you
+    are calling `mark()` or `measure()` at a high-rate, you might incur a performance cost from the UserTiming.js
+    JavaScript implementation versus a native implementation.
+
+## Tests
+
+### UserTiming.js tests
+
+UserTiming.js tests are provided in the ``test/`` directory, and can be run via ``nodeunit``:
+
+    nodeunit test/test.js
+
+Or via ``grunt``:
+
+    grunt test
+
+The tests can also be run in a web browser:
+
+    test/test.html
+
+### W3C tests
+
+The latest [W3C UserTiming tests](http://w3c-test.org/webperf/tests/#ut) (as of 2013-04-15) were copied into the
+``test-w3c/`` directory and can be run in any browser to validate UserTiming.js.  In browsers that natively support
+UserTiming, UserTiming.js does not change anything so the tests will be running against the native browser interface.
+
+The following changes were made to the W3C test suite to work with UserTiming.js:
+
+* The relative test harness JS/CSS urls were changed to point to the local ``test-w3c/`` directory
+    (such as ``testharness.js``, ``webperftestharness.js``, etc)
+
+* All tests were updated to add a reference to ``../src/usertiming.js`` so usertiming.js is actually used
+
+* ``test_user_timing_measure.htm`` and ``test_user_timing_mark.htm``: The threshold was increased from 20ms to 50ms
+    (due to inefficiencies in the test suite)
+
+Additional notes:
+
+* ``usertiming.js`` does **not pass** the IDL tests (``idlharness.html``), nor will it ever.
+
+* The W3C test harness itself does not appear to work in several older browsers (IE <= 8, Firefox 3.6, etc).  The
+    UserTiming.js [test cases](#Tests) should cover most of what the W3C tests are doing, and the nodeunit test harness
+    works in these older browsers.
+
+## Version History
+
+* v0.1.0 - 2013-04-15: Initial version
+* v0.1.1 - 2014-02-19: Updated dependencies, grunt lint task, bower package name
+* v0.1.2 - 2014-02-19: Small bower.json fix
+* v0.1.3 - 2014-08-07: Include dist/ dir in bower and npm packages
+* v0.1.4 - 2014-10-28: Fix for Safari iOS 8
+* v0.1.5 - 2015-01-12: Fix for FF 35
+* v0.1.6 - 2015-02-01: Better FF 35 support (or any browser that has RT but not UT)
+* v0.1.7 - 2015-09-14: Dev-only changes: Lint, switched from NodeUnit to Mocha

+ 1 - 0
Build/node_modules/usertiming/eslint.xml

@@ -0,0 +1 @@
+<?xml version="1.0" encoding="utf-8"?><jslint><file name="Gruntfile.js"></file><file name="src/usertiming.js"></file><file name="test/test-mark.js"></file><file name="test/test-measure.js"></file><file name="test/test-now.js"></file><file name="test/test-performancetimeline.js"></file></jslint>

+ 96 - 0
Build/node_modules/usertiming/package.json

@@ -0,0 +1,96 @@
+{
+  "_args": [
+    [
+      "usertiming",
+      "/Users/shaddockh/Development/AtomicProjects/AtomicGameEngineFork/AtomicGameEngine/Build"
+    ]
+  ],
+  "_from": "usertiming@*",
+  "_id": "[email protected]",
+  "_inCache": true,
+  "_installable": true,
+  "_location": "/usertiming",
+  "_nodeVersion": "0.12.5",
+  "_npmUser": {
+    "email": "[email protected]",
+    "name": "nicjansma"
+  },
+  "_npmVersion": "2.11.2",
+  "_phantomChildren": {},
+  "_requested": {
+    "name": "usertiming",
+    "raw": "usertiming",
+    "rawSpec": "",
+    "scope": null,
+    "spec": "*",
+    "type": "range"
+  },
+  "_requiredBy": [
+    "/"
+  ],
+  "_resolved": "https://registry.npmjs.org/usertiming/-/usertiming-0.1.7.tgz",
+  "_shasum": "25e5522c5d1805836b1c0a1d545f4d29889bb37a",
+  "_shrinkwrap": null,
+  "_spec": "usertiming",
+  "_where": "/Users/shaddockh/Development/AtomicProjects/AtomicGameEngineFork/AtomicGameEngine/Build",
+  "author": {
+    "name": "Nic Jansma"
+  },
+  "bugs": {
+    "url": "http://github.com/nicjansma/usertiming.js/issues"
+  },
+  "dependencies": {},
+  "description": "W3C UserTiming polyfill",
+  "devDependencies": {
+    "expect.js": "^0.3.1",
+    "grunt": ">= 0.4.0",
+    "grunt-contrib-clean": "^0.6.0",
+    "grunt-contrib-uglify": ">0.0.0",
+    "grunt-karma": "^0.10.1",
+    "grunt-mocha-test": "^0.12.7",
+    "gruntify-eslint": ">0.0.0",
+    "karma": "^0.12.31",
+    "karma-chrome-launcher": "^0.1.5",
+    "karma-coverage": "^0.2.6",
+    "karma-expect": "^1.1.0",
+    "karma-firefox-launcher": "^0.1.4",
+    "karma-ie-launcher": "^0.1.5",
+    "karma-mocha": "^0.1.9",
+    "karma-opera-launcher": "^0.1.0",
+    "karma-phantomjs-launcher": "^0.1.4",
+    "karma-safari-launcher": "^0.1.1",
+    "karma-tap-reporter": "0.0.3",
+    "mocha": "^2.1.0"
+  },
+  "directories": {},
+  "dist": {
+    "shasum": "25e5522c5d1805836b1c0a1d545f4d29889bb37a",
+    "tarball": "http://registry.npmjs.org/usertiming/-/usertiming-0.1.7.tgz"
+  },
+  "gitHead": "4d8368299fac268b1ed905eb24378791e157c67f",
+  "homepage": "https://github.com/nicjansma/usertiming.js#readme",
+  "licenses": [
+    {
+      "type": "MIT",
+      "url": "http://github.com/nicjansma/usertiming.js/raw/master/LICENSE.txt"
+    }
+  ],
+  "main": "./src/usertiming",
+  "maintainers": [
+    {
+      "name": "nicjansma",
+      "email": "[email protected]"
+    }
+  ],
+  "name": "usertiming",
+  "optionalDependencies": {},
+  "readme": "ERROR: No README data found!",
+  "repository": {
+    "type": "git",
+    "url": "git+ssh://[email protected]/nicjansma/usertiming.js.git"
+  },
+  "scripts": {
+    "test": "grunt travis --verbose"
+  },
+  "version": "0.1.7"
+}

+ 562 - 0
Build/node_modules/usertiming/src/usertiming.js

@@ -0,0 +1,562 @@
+/*eslint-env browser,amd,node*/
+//
+// usertiming.js
+//
+// A polyfill for UserTiming (http://www.w3.org/TR/user-timing/)
+//
+// Copyright 2013 Nic Jansma
+// http://nicj.net
+//
+// https://github.com/nicjansma/usertiming.js
+//
+// Licensed under the MIT license
+//
+(function(window) {
+    "use strict";
+
+    // allow running in Node.js environment
+    if (typeof window === "undefined") {
+        window = {};
+    }
+
+    // prepare base perf object
+    if (typeof window.performance === "undefined") {
+        window.performance = {};
+    }
+
+    // We need to keep a global reference to the window.performance object to
+    // prevent any added properties from being garbage-collected in Safari 8.
+    // https://bugs.webkit.org/show_bug.cgi?id=137407
+    window._perfRefForUserTimingPolyfill = window.performance;
+
+    //
+    // Note what we shimmed
+    //
+    window.performance.userTimingJsNow = false;
+    window.performance.userTimingJsNowPrefixed = false;
+    window.performance.userTimingJsUserTiming = false;
+    window.performance.userTimingJsUserTimingPrefixed = false;
+    window.performance.userTimingJsPerformanceTimeline = false;
+    window.performance.userTimingJsPerformanceTimelinePrefixed = false;
+
+    // for prefixed support
+    var prefixes = [];
+    var methods = [];
+    var methodTest = null;
+    var i, j;
+
+    //
+    // window.performance.now() shim
+    //  http://www.w3.org/TR/hr-time/
+    //
+    if (typeof window.performance.now !== "function") {
+        window.performance.userTimingJsNow = true;
+
+        // copy prefixed version over if it exists
+        methods = ["webkitNow", "msNow", "mozNow"];
+
+        for (i = 0; i < methods.length; i++) {
+            if (typeof window.performance[methods[i]] === "function") {
+                window.performance.now = window.performance[methods[i]];
+
+                window.performance.userTimingJsNowPrefixed = true;
+
+                break;
+            }
+        }
+
+        //
+        // now() should be a DOMHighResTimeStamp, which is defined as being a time relative
+        // to navigationStart of the PerformanceTiming (PT) interface.  If this browser supports
+        // PT, use that as our relative start.  Otherwise, use "now" as the start and all other
+        // now() calls will be relative to our initialization.
+        //
+
+        var nowOffset = +(new Date());
+        if (window.performance.timing && window.performance.timing.navigationStart) {
+            nowOffset = window.performance.timing.navigationStart;
+        }
+
+        if (typeof window.performance.now !== "function") {
+            // No browser support, fall back to Date.now
+            if (Date.now) {
+                window.performance.now = function() {
+                    return Date.now() - nowOffset;
+                };
+            } else {
+                // no Date.now support, get the time from new Date()
+                window.performance.now = function() {
+                    return +(new Date()) - nowOffset;
+                };
+            }
+        }
+    }
+
+    //
+    // PerformanceTimeline (PT) shims
+    //  http://www.w3.org/TR/performance-timeline/
+    //
+
+    /**
+     * Adds an object to our internal Performance Timeline array.
+     *
+     * Will be blank if the environment supports PT.
+     */
+    var addToPerformanceTimeline = function() {
+    };
+
+    /**
+     * Clears the specified entry types from our timeline array.
+     *
+     * Will be blank if the environment supports PT.
+     */
+    var clearEntriesFromPerformanceTimeline = function() {
+    };
+
+    // performance timeline array
+    var performanceTimeline = [];
+
+    // whether or not the timeline will require sort on getEntries()
+    var performanceTimelineRequiresSort = false;
+
+    // whether or not ResourceTiming is natively supported but UserTiming is
+    // not (eg Firefox 35)
+    var hasNativeGetEntriesButNotUserTiming = false;
+
+    //
+    // If getEntries() and mark() aren't defined, we'll assume
+    // we have to shim at least some PT functions.
+    //
+    if (typeof window.performance.getEntries !== "function" ||
+        typeof window.performance.mark !== "function") {
+
+        if (typeof window.performance.getEntries === "function" &&
+            typeof window.performance.mark !== "function") {
+            hasNativeGetEntriesButNotUserTiming = true;
+        }
+
+        window.performance.userTimingJsPerformanceTimeline = true;
+
+        // copy prefixed version over if it exists
+        prefixes = ["webkit", "moz"];
+        methods = ["getEntries", "getEntriesByName", "getEntriesByType"];
+
+        for (i = 0; i < methods.length; i++) {
+            for (j = 0; j < prefixes.length; j++) {
+                // prefixed method will likely have an upper-case first letter
+                methodTest = prefixes[j] + methods[i].substr(0, 1).toUpperCase() + methods[i].substr(1);
+
+                if (typeof window.performance[methodTest] === "function") {
+                    window.performance[methods[i]] = window.performance[methodTest];
+
+                    window.performance.userTimingJsPerformanceTimelinePrefixed = true;
+                }
+            }
+        }
+
+        /**
+         * Adds an object to our internal Performance Timeline array.
+         *
+         * @param {Object} obj PerformanceEntry
+         */
+        addToPerformanceTimeline = function(obj) {
+            performanceTimeline.push(obj);
+
+            //
+            // If we insert a measure, its startTime may be out of order
+            // from the rest of the entries because the use can use any
+            // mark as the start time.  If so, note we have to sort it before
+            // returning getEntries();
+            //
+            if (obj.entryType === "measure") {
+                performanceTimelineRequiresSort = true;
+            }
+        };
+
+        /**
+         * Ensures our PT array is in the correct sorted order (by startTime)
+         */
+        var ensurePerformanceTimelineOrder = function() {
+            if (!performanceTimelineRequiresSort) {
+                return;
+            }
+
+            //
+            // Measures, which may be in this list, may enter the list in
+            // an unsorted order. For example:
+            //
+            //  1. measure("a")
+            //  2. mark("start_mark")
+            //  3. measure("b", "start_mark")
+            //  4. measure("c")
+            //  5. getEntries()
+            //
+            // When calling #5, we should return [a,c,b] because technically the start time
+            // of c is "0" (navigationStart), which will occur before b's start time due to the mark.
+            //
+            performanceTimeline.sort(function(a, b) {
+                return a.startTime - b.startTime;
+            });
+
+            performanceTimelineRequiresSort = false;
+        };
+
+        /**
+         * Clears the specified entry types from our timeline array.
+         *
+         * @param {string} entryType Entry type (eg "mark" or "measure")
+         * @param {string} [name] Entry name (optional)
+         */
+        clearEntriesFromPerformanceTimeline = function(entryType, name) {
+            // clear all entries from the perf timeline
+            i = 0;
+            while (i < performanceTimeline.length) {
+                if (performanceTimeline[i].entryType !== entryType) {
+                    // unmatched entry type
+                    i++;
+                    continue;
+                }
+
+                if (typeof name !== "undefined" && performanceTimeline[i].name !== name) {
+                    // unmatched name
+                    i++;
+                    continue;
+                }
+
+                // this entry matches our criteria, remove just it
+                performanceTimeline.splice(i, 1);
+            }
+        };
+
+        if (typeof window.performance.getEntries !== "function" || hasNativeGetEntriesButNotUserTiming) {
+            var origGetEntries = window.performance.getEntries;
+
+            /**
+             * Gets all entries from the Performance Timeline.
+             * http://www.w3.org/TR/performance-timeline/#dom-performance-getentries
+             *
+             * NOTE: This will only ever return marks and measures.
+             *
+             * @returns {PerformanceEntry[]} Array of PerformanceEntrys
+             */
+            window.performance.getEntries = function() {
+                ensurePerformanceTimelineOrder();
+
+                // get a copy of all of our entries
+                var entries = performanceTimeline.slice(0);
+
+                // if there was a native version of getEntries, add that
+                if (hasNativeGetEntriesButNotUserTiming && origGetEntries) {
+                    // merge in native
+                    Array.prototype.push.apply(entries, origGetEntries.call(window.performance));
+
+                    // sort by startTime
+                    entries.sort(function(a, b) {
+                        return a.startTime - b.startTime;
+                    });
+                }
+
+                return entries;
+            };
+        }
+
+        if (typeof window.performance.getEntriesByType !== "function" || hasNativeGetEntriesButNotUserTiming) {
+            var origGetEntriesByType = window.performance.getEntriesByType;
+
+            /**
+             * Gets all entries from the Performance Timeline of the specified type.
+             * http://www.w3.org/TR/performance-timeline/#dom-performance-getentriesbytype
+             *
+             * NOTE: This will only work for marks and measures.
+             *
+             * @param {string} entryType Entry type (eg "mark" or "measure")
+             *
+             * @returns {PerformanceEntry[]} Array of PerformanceEntrys
+             */
+            window.performance.getEntriesByType = function(entryType) {
+                // we only support marks/measures
+                if (typeof entryType === "undefined" ||
+                    (entryType !== "mark" && entryType !== "measure")) {
+
+                    if (hasNativeGetEntriesButNotUserTiming && origGetEntriesByType) {
+                        // native version exists, forward
+                        return origGetEntriesByType.call(window.performance, entryType);
+                    }
+
+                    return [];
+                }
+
+                // see note in ensurePerformanceTimelineOrder() on why this is required
+                if (entryType === "measure") {
+                    ensurePerformanceTimelineOrder();
+                }
+
+                // find all entries of entryType
+                var entries = [];
+                for (i = 0; i < performanceTimeline.length; i++) {
+                    if (performanceTimeline[i].entryType === entryType) {
+                        entries.push(performanceTimeline[i]);
+                    }
+                }
+
+                return entries;
+            };
+        }
+
+        if (typeof window.performance.getEntriesByName !== "function" || hasNativeGetEntriesButNotUserTiming) {
+            var origGetEntriesByName = window.performance.getEntriesByName;
+
+            /**
+             * Gets all entries from the Performance Timeline of the specified
+             * name, and optionally, type.
+             * http://www.w3.org/TR/performance-timeline/#dom-performance-getentriesbyname
+             *
+             * NOTE: This will only work for marks and measures.
+             *
+             * @param {string} name Entry name
+             * @param {string} [entryType] Entry type (eg "mark" or "measure")
+             *
+             * @returns {PerformanceEntry[]} Array of PerformanceEntrys
+             */
+            window.performance.getEntriesByName = function(name, entryType) {
+                if (entryType && entryType !== "mark" && entryType !== "measure") {
+                    if (hasNativeGetEntriesButNotUserTiming && origGetEntriesByName) {
+                        // native version exists, forward
+                        return origGetEntriesByName.call(window.performance, name, entryType);
+                    }
+
+                    return [];
+                }
+
+                // see note in ensurePerformanceTimelineOrder() on why this is required
+                if (typeof entryType !== "undefined" && entryType === "measure") {
+                    ensurePerformanceTimelineOrder();
+                }
+
+                // find all entries of the name and (optionally) type
+                var entries = [];
+                for (i = 0; i < performanceTimeline.length; i++) {
+                    if (typeof entryType !== "undefined" &&
+                        performanceTimeline[i].entryType !== entryType) {
+                        continue;
+                    }
+
+                    if (performanceTimeline[i].name === name) {
+                        entries.push(performanceTimeline[i]);
+                    }
+                }
+
+                if (hasNativeGetEntriesButNotUserTiming && origGetEntriesByName) {
+                    // merge in native
+                    Array.prototype.push.apply(entries, origGetEntriesByName.call(window.performance, name, entryType));
+
+                    // sort by startTime
+                    entries.sort(function(a, b) {
+                        return a.startTime - b.startTime;
+                    });
+                }
+
+                return entries;
+            };
+        }
+    }
+
+    //
+    // UserTiming support
+    //
+    if (typeof window.performance.mark !== "function") {
+        window.performance.userTimingJsUserTiming = true;
+
+        // copy prefixed version over if it exists
+        prefixes = ["webkit", "moz", "ms"];
+        methods = ["mark", "measure", "clearMarks", "clearMeasures"];
+
+        for (i = 0; i < methods.length; i++) {
+            for (j = 0; j < prefixes.length; j++) {
+                // prefixed method will likely have an upper-case first letter
+                methodTest = prefixes[j] + methods[i].substr(0, 1).toUpperCase() + methods[i].substr(1);
+
+                if (typeof window.performance[methodTest] === "function") {
+                    window.performance[methods[i]] = window.performance[methodTest];
+
+                    window.performance.userTimingJsUserTimingPrefixed = true;
+                }
+            }
+        }
+
+        // only used for measure(), to quickly see the latest timestamp of a mark
+        var marks = {};
+
+        if (typeof window.performance.mark !== "function") {
+            /**
+             * UserTiming mark
+             * http://www.w3.org/TR/user-timing/#dom-performance-mark
+             *
+             * @param {string} markName Mark name
+             */
+            window.performance.mark = function (markName) {
+                var now = window.performance.now();
+
+                // mark name is required
+                if (typeof markName === "undefined") {
+                    throw new SyntaxError("Mark name must be specified");
+                }
+
+                // mark name can't be a NT timestamp
+                if (window.performance.timing && markName in window.performance.timing) {
+                    throw new SyntaxError("Mark name is not allowed");
+                }
+
+                if (!marks[markName]) {
+                    marks[markName] = [];
+                }
+
+                marks[markName].push(now);
+
+                // add to perf timeline as well
+                addToPerformanceTimeline({
+                    entryType: "mark",
+                    name: markName,
+                    startTime: now,
+                    duration: 0
+                });
+            };
+        }
+
+        if (typeof window.performance.clearMarks !== "function") {
+            /**
+             * UserTiming clear marks
+             * http://www.w3.org/TR/user-timing/#dom-performance-clearmarks
+             *
+             * @param {string} markName Mark name
+             */
+            window.performance.clearMarks = function (markName) {
+                if (!markName) {
+                    // clear all marks
+                    marks = {};
+                } else {
+                    marks[markName] = [];
+                }
+
+                clearEntriesFromPerformanceTimeline("mark", markName);
+            };
+        }
+
+        if (typeof window.performance.measure !== "function") {
+            /**
+             * UserTiming measure
+             * http://www.w3.org/TR/user-timing/#dom-performance-measure
+             *
+             * @param {string} measureName Measure name
+             * @param {string} [startMark] Start mark name
+             * @param {string} [endMark] End mark name
+             */
+            window.performance.measure = function (measureName, startMark, endMark) {
+                var now = window.performance.now();
+
+                if (typeof measureName === "undefined") {
+                    throw new SyntaxError("Measure must be specified");
+                }
+
+                // if there isn't a startMark, we measure from navigationStart to now
+                if (!startMark) {
+                    // add to perf timeline as well
+                    addToPerformanceTimeline({
+                        entryType: "measure",
+                        name: measureName,
+                        startTime: 0,
+                        duration: now
+                    });
+
+                    return;
+                }
+
+                //
+                // If there is a startMark, check for it first in the NavigationTiming interface,
+                // then check our own marks.
+                //
+                var startMarkTime = 0;
+                if (window.performance.timing && startMark in window.performance.timing) {
+                    // mark cannot have a timing of 0
+                    if (startMark !== "navigationStart" && window.performance.timing[startMark] === 0) {
+                        throw new Error(startMark + " has a timing of 0");
+                    }
+
+                    // time is the offset of this mark to navigationStart's time
+                    startMarkTime = window.performance.timing[startMark] - window.performance.timing.navigationStart;
+                } else if (startMark in marks) {
+                    startMarkTime = marks[startMark][marks[startMark].length - 1];
+                } else {
+                    throw new Error(startMark + " mark not found");
+                }
+
+                //
+                // If there is a endMark, check for it first in the NavigationTiming interface,
+                // then check our own marks.
+                //
+                var endMarkTime = now;
+
+                if (endMark) {
+                    endMarkTime = 0;
+
+                    if (window.performance.timing && endMark in window.performance.timing) {
+                        // mark cannot have a timing of 0
+                        if (endMark !== "navigationStart" && window.performance.timing[endMark] === 0) {
+                            throw new Error(endMark + " has a timing of 0");
+                        }
+
+                        // time is the offset of this mark to navigationStart's time
+                        endMarkTime = window.performance.timing[endMark] - window.performance.timing.navigationStart;
+                    } else if (endMark in marks) {
+                        endMarkTime = marks[endMark][marks[endMark].length - 1];
+                    } else {
+                        throw new Error(endMark + " mark not found");
+                    }
+                }
+
+                // add to our measure array
+                var duration = endMarkTime - startMarkTime;
+
+                // add to perf timeline as well
+                addToPerformanceTimeline({
+                    entryType: "measure",
+                    name: measureName,
+                    startTime: startMarkTime,
+                    duration: duration
+                });
+            };
+        }
+
+        if (typeof window.performance.clearMeasures !== "function") {
+            /**
+             * UserTiming clear measures
+             * http://www.w3.org/TR/user-timing/#dom-performance-clearmeasures
+             *
+             * @param {string} measureName Measure name
+             */
+            window.performance.clearMeasures = function (measureName) {
+                clearEntriesFromPerformanceTimeline("measure", measureName);
+            };
+        }
+    }
+
+    //
+    // Export UserTiming to the appropriate location.
+    //
+    // When included directly via a script tag in the browser, we're good as we've been
+    // updating the window.performance object.
+    //
+    if (typeof define !== "undefined" && define.amd) {
+        //
+        // AMD / RequireJS
+        //
+        define([], function () {
+            return window.performance;
+        });
+    } else if (typeof module !== "undefined" && typeof module.exports !== "undefined") {
+        //
+        // Node.js
+        //
+        module.exports = window.performance;
+    }
+}(typeof window !== "undefined" ? window : undefined));

+ 841 - 0
Build/node_modules/usertiming/test-w3c/WebIDLParser.js

@@ -0,0 +1,841 @@
+
+
+(function () {
+    var tokenise = function (str) {
+        var tokens = []
+        ,   re = {
+                "float":        /^-?(([0-9]+\.[0-9]*|[0-9]*\.[0-9]+)([Ee][-+]?[0-9]+)?|[0-9]+[Ee][-+]?[0-9]+)/
+            ,   "integer":      /^-?(0([Xx][0-9A-Fa-f]+|[0-7]*)|[1-9][0-9]*)/
+            ,   "identifier":   /^[A-Z_a-z][0-9A-Z_a-z]*/
+            ,   "string":       /^"[^"]*"/
+            ,   "whitespace":   /^(?:[\t\n\r ]+|[\t\n\r ]*((\/\/.*|\/\*(.|\n|\r)*?\*\/)[\t\n\r ]*))+/
+            ,   "other":        /^[^\t\n\r 0-9A-Z_a-z]/
+            }
+        ,   types = []
+        ;
+        for (var k in re) types.push(k);
+        while (str.length > 0) {
+            var matched = false;
+            for (var i = 0, n = types.length; i < n; i++) {
+                var type = types[i];
+                str = str.replace(re[type], function (tok) {
+                    tokens.push({ type: type, value: tok });
+                    matched = true;
+                    return "";
+                });
+                if (matched) break;
+            }
+            if (matched) continue;
+            throw new Error("Token stream not progressing");
+        }
+        return tokens;
+    };
+    
+    var parse = function (tokens) {
+        var line = 1;
+        tokens = tokens.slice();
+        
+        var FLOAT = "float"
+        ,   INT = "integer"
+        ,   ID = "identifier"
+        ,   STR = "string"
+        ,   OTHER = "other"
+        ;
+        
+        var WebIDLParseError = function (str, line, input, tokens) {
+            this.message = str;
+            this.line = line;
+            this.input = input;
+            this.tokens = tokens;
+        };
+        WebIDLParseError.prototype.toString = function () {
+            return this.message + ", line " + this.line + " (tokens: '" + this.input + "')\n" +
+                   JSON.stringify(this.tokens, null, 4);
+        };
+        
+        var error = function (str) {
+            var tok = "", numTokens = 0, maxTokens = 5;
+            while (numTokens < maxTokens && tokens.length > numTokens) {
+                tok += tokens[numTokens].value;
+                numTokens++;
+            }
+            throw new WebIDLParseError(str, line, tok, tokens.slice(0, 5));
+        };
+        
+        var last_token = null;
+        
+        var consume = function (type, value) {
+            if (!tokens.length || tokens[0].type !== type) return;
+            if (typeof value === "undefined" || tokens[0].value === value) {
+                 last_token = tokens.shift();
+                 if (type === ID) last_token.value = last_token.value.replace(/^_/, "");
+                 return last_token;
+             }
+        };
+        
+        var ws = function () {
+            if (!tokens.length) return;
+            if (tokens[0].type === "whitespace") {
+                var t = tokens.shift();
+                t.value.replace(/\n/g, function (m) { line++; return m; });
+                return t;
+            }
+        };
+        
+        var all_ws = function () {
+            var t = { type: "whitespace", value: "" };
+            while (true) {
+                var w = ws();
+                if (!w) break;
+                t.value += w.value;
+            }
+            if (t.value.length > 0) return t;
+        };
+        
+        var integer_type = function () {
+            var ret = "";
+            all_ws();
+            if (consume(ID, "unsigned")) ret = "unsigned ";
+            all_ws();
+            if (consume(ID, "short")) return ret + "short";
+            if (consume(ID, "long")) {
+                ret += "long";
+                all_ws();
+                if (consume(ID, "long")) return ret + " long";
+                return ret;
+            }
+            if (ret) error("Failed to parse integer type");
+        };
+        
+        var float_type = function () {
+            var ret = "";
+            all_ws();
+            if (consume(ID, "unrestricted")) ret = "unrestricted ";
+            all_ws();
+            if (consume(ID, "float")) return ret + "float";
+            if (consume(ID, "double")) return ret + "double";
+            if (ret) error("Failed to parse float type");
+        };
+        
+        var primitive_type = function () {
+            var num_type = integer_type() || float_type();
+            if (num_type) return num_type;
+            all_ws();
+            if (consume(ID, "boolean")) return "boolean";
+            if (consume(ID, "byte")) return "byte";
+            if (consume(ID, "octet")) return "octet";
+        };
+        
+        var const_value = function () {
+            if (consume(ID, "true")) return { type: "boolean", value: true };
+            if (consume(ID, "false")) return { type: "boolean", value: false };
+            if (consume(ID, "null")) return { type: "null" };
+            if (consume(ID, "Infinity")) return { type: "Infinity", negative: false };
+            if (consume(ID, "NaN")) return { type: "NaN" };
+            var ret = consume(FLOAT) || consume(INT);
+            if (ret) return { type: "number", value: 1 * ret.value };
+            var tok = consume(OTHER, "-");
+            if (tok) {
+                if (consume(ID, "Infinity")) return { type: "Infinity", negative: true };
+                else tokens.unshift(tok);
+            }
+        };
+        
+        var type_suffix = function (obj) {
+            while (true) {
+                all_ws();
+                if (consume(OTHER, "?")) {
+                    if (obj.nullable) error("Can't nullable more than once");
+                    obj.nullable = true;
+                }
+                else if (consume(OTHER, "[")) {
+                    all_ws();
+                    consume(OTHER, "]") || error("Unterminated array type");
+                    if (!obj.array) obj.array = 1;
+                    else obj.array++;
+                }
+                else return;
+            }
+        };
+        
+        var single_type = function () {
+            var prim = primitive_type()
+            ,   ret = { sequence: false, nullable: false, array: false, union: false }
+            ;
+            if (prim) {
+                ret.idlType = prim;
+            }
+            else if (consume(ID, "sequence")) {
+                all_ws();
+                if (!consume(OTHER, "<")) {
+                    ret.idlType = "sequence";
+                }
+                else {
+                    ret.sequence = true;
+                    ret.idlType = type() || error("Error parsing sequence type");
+                    all_ws();
+                    if (!consume(OTHER, ">")) error("Unterminated sequence");
+                    all_ws();
+                    if (consume(OTHER, "?")) ret.nullable = true;
+                    return ret;
+                }
+            }
+            else {
+                var name = consume(ID);
+                if (!name) return;
+                ret.idlType = name.value;
+            }
+            type_suffix(ret);
+            if (ret.nullable && ret.idlType === "any") error("Type any cannot be made nullable");
+            return ret;
+        };
+        
+        var union_type = function () {
+            all_ws();
+            if (!consume(OTHER, "(")) return;
+            var ret = { sequence: false, nullable: false, array: false, union: true, idlType: [] };
+            var fst = type() || error("Union type with no content");
+            ret.idlType.push(fst);
+            while (true) {
+                all_ws();
+                if (!consume(ID, "or")) break;
+                var typ = type() || error("No type after 'or' in union type");
+                ret.idlType.push(typ);
+            }
+            if (!consume(OTHER, ")")) error("Unterminated union type");
+            type_suffix(ret);
+            return ret;
+        };
+        
+        var type = function () {
+            return single_type() || union_type();
+        };
+        
+        var argument = function () {
+            var ret = { optional: false, variadic: false };
+            ret.extAttrs = extended_attrs();
+            all_ws();
+            if (consume(ID, "optional")) {
+                ret.optional = true;
+                all_ws();
+            }
+            ret.idlType = type();
+            if (!ret.idlType) return;
+            if (!ret.optional) {
+                all_ws();
+                if (tokens.length >= 3 &&
+                    tokens[0].type === "other" && tokens[0].value === "." &&
+                    tokens[1].type === "other" && tokens[1].value === "." &&
+                    tokens[2].type === "other" && tokens[2].value === "."
+                    ) {
+                    tokens.shift();
+                    tokens.shift();
+                    tokens.shift();
+                    ret.variadic = true;
+                }
+            }
+            all_ws();
+            var name = consume(ID) || error("No name in argument");
+            ret.name = name.value;
+            if (ret.optional) {
+                all_ws();
+                ret["default"] = default_();
+            }
+            return ret;
+        };
+        
+        var argument_list = function () {
+            var arg = argument(), ret = [];
+            if (!arg) return ret;
+            ret.push(arg);
+            while (true) {
+                all_ws();
+                if (!consume(OTHER, ",")) return ret;
+                all_ws();
+                var nxt = argument() || error("Trailing comma in arguments list");
+                ret.push(nxt);
+            }
+        };
+        
+        var simple_extended_attr = function () {
+            all_ws();
+            var name = consume(ID);
+            if (!name) return;
+            var ret = {
+                name: name.value
+            ,   "arguments": null
+            };
+            all_ws();
+            var eq = consume(OTHER, "=");
+            if (eq) {
+                all_ws();
+                ret.rhs = consume(ID);
+                if (!ret.rhs) return error("No right hand side to extended attribute assignment");
+            }
+            all_ws();
+            if (consume(OTHER, "(")) {
+                ret["arguments"] = argument_list();
+                all_ws();
+                consume(OTHER, ")") || error("Unclosed argument in extended attribute");
+            }
+            return ret;
+        };
+        
+        // Note: we parse something simpler than the official syntax. It's all that ever
+        // seems to be used
+        var extended_attrs = function () {
+            var eas = [];
+            all_ws();
+            if (!consume(OTHER, "[")) return eas;
+            eas[0] = simple_extended_attr() || error("Extended attribute with not content");
+            all_ws();
+            while (consume(OTHER, ",")) {
+                all_ws();
+                eas.push(simple_extended_attr() || error("Trailing comma in extended attribute"));
+                all_ws();
+            }
+            consume(OTHER, "]") || error("No end of extended attribute");
+            return eas;
+        };
+        
+        var default_ = function () {
+            all_ws();
+            if (consume(OTHER, "=")) {
+                all_ws();
+                var def = const_value();
+                if (def) {
+                    return def;
+                }
+                else {
+                    var str = consume(STR) || error("No value for default");
+                    str.value = str.value.replace(/^"/, "").replace(/"$/, "");
+                    return str;
+                }
+            }
+        };
+        
+        var const_ = function () {
+            all_ws();
+            if (!consume(ID, "const")) return;
+            var ret = { type: "const", nullable: false };
+            all_ws();
+            var typ = primitive_type();
+            if (!typ) {
+                typ = consume(ID) || error("No type for const");
+                typ = typ.value;
+            }
+            ret.idlType = typ;
+            all_ws();
+            if (consume(OTHER, "?")) {
+                ret.nullable = true;
+                all_ws();
+            }
+            var name = consume(ID) || error("No name for const");
+            ret.name = name.value;
+            all_ws();
+            consume(OTHER, "=") || error("No value assignment for const");
+            all_ws();
+            var cnt = const_value();
+            if (cnt) ret.value = cnt;
+            else error("No value for const");
+            all_ws();
+            consume(OTHER, ";") || error("Unterminated const");
+            return ret;
+        };
+        
+        var inheritance = function () {
+            all_ws();
+            if (consume(OTHER, ":")) {
+                all_ws();
+                var inh = consume(ID) || error ("No type in inheritance");
+                return inh.value;
+            }
+        };
+        
+        var operation_rest = function (ret) {
+            all_ws();
+            if (!ret) ret = {};
+            var name = consume(ID);
+            ret.name = name ? name.value : null;
+            all_ws();
+            consume(OTHER, "(") || error("Invalid operation");
+            ret["arguments"] = argument_list();
+            all_ws();
+            consume(OTHER, ")") || error("Unterminated operation");
+            all_ws();
+            consume(OTHER, ";") || error("Unterminated operation");
+            return ret;
+        };
+        
+        var callback = function () {
+            all_ws();
+            var ret;
+            if (!consume(ID, "callback")) return;
+            all_ws();
+            var tok = consume(ID, "interface");
+            if (tok) {
+                tokens.unshift(tok);
+                ret = interface_();
+                ret.type = "callback interface";
+                return ret;
+            }
+            var name = consume(ID) || error("No name for callback");
+            ret = { type: "callback", name: name.value };
+            all_ws();
+            consume(OTHER, "=") || error("No assignment in callback");
+            all_ws();
+            ret.idlType = return_type();
+            all_ws();
+            consume(OTHER, "(") || error("No arguments in callback");
+            ret["arguments"] = argument_list();
+            all_ws();
+            consume(OTHER, ")") || error("Unterminated callback");
+            all_ws();
+            consume(OTHER, ";") || error("Unterminated callback");
+            return ret;
+        };
+
+        var attribute = function () {
+            all_ws();
+            var grabbed = []
+            ,   ret = {
+                type:           "attribute"
+            ,   "static":       false
+            ,   stringifier:    false
+            ,   inherit:        false
+            ,   readonly:       false
+            };
+            if (consume(ID, "static")) {
+                ret["static"] = true;
+                grabbed.push(last_token);
+            }
+            else if (consume(ID, "stringifier")) {
+                ret.stringifier = true;
+                grabbed.push(last_token);
+            }
+            var w = all_ws();
+            if (w) grabbed.push(w);
+            if (consume(ID, "inherit")) {
+                if (ret["static"] || ret.stringifier) error("Cannot have a static or stringifier inherit");
+                ret.inherit = true;
+                grabbed.push(last_token);
+                var w = all_ws();
+                if (w) grabbed.push(w);
+            }
+            if (consume(ID, "readonly")) {
+                ret.readonly = true;
+                grabbed.push(last_token);
+                var w = all_ws();
+                if (w) grabbed.push(w);
+            }
+            if (!consume(ID, "attribute")) {
+                tokens = grabbed.concat(tokens);
+                return;
+            }
+            all_ws();
+            ret.idlType = type() || error("No type in attribute");
+            if (ret.idlType.sequence) error("Attributes cannot accept sequence types");
+            all_ws();
+            var name = consume(ID) || error("No name in attribute");
+            ret.name = name.value;
+            all_ws();
+            consume(OTHER, ";") || error("Unterminated attribute");
+            return ret;
+        };
+        
+        var return_type = function () {
+            var typ = type();
+            if (!typ) {
+                if (consume(ID, "void")) {
+                    return "void";
+                }
+                else error("No return type");
+            }
+            return typ;
+        };
+        
+        var operation = function () {
+            all_ws();
+            var ret = {
+                type:           "operation"
+            ,   getter:         false
+            ,   setter:         false
+            ,   creator:        false
+            ,   deleter:        false
+            ,   legacycaller:   false
+            ,   "static":       false
+            ,   stringifier:    false
+            };
+            while (true) {
+                all_ws();
+                if (consume(ID, "getter")) ret.getter = true;
+                else if (consume(ID, "setter")) ret.setter = true;
+                else if (consume(ID, "creator")) ret.creator = true;
+                else if (consume(ID, "deleter")) ret.deleter = true;
+                else if (consume(ID, "legacycaller")) ret.legacycaller = true;
+                else break;
+            }
+            if (ret.getter || ret.setter || ret.creator || ret.deleter || ret.legacycaller) {
+                all_ws();
+                ret.idlType = return_type();
+                operation_rest(ret);
+                return ret;
+            }
+            if (consume(ID, "static")) {
+                ret["static"] = true;
+                ret.idlType = return_type();
+                operation_rest(ret);
+                return ret;
+            }
+            else if (consume(ID, "stringifier")) {
+                ret.stringifier = true;
+                all_ws();
+                if (consume(OTHER, ";")) return ret;
+                ret.idlType = return_type();
+                operation_rest(ret);
+                return ret;
+            }
+            ret.idlType = return_type();
+            all_ws();
+            if (consume(ID, "iterator")) {
+                all_ws();
+                ret.type = "iterator";
+                if (consume(ID, "object")) {
+                    ret.iteratorObject = "object";
+                }
+                else if (consume(OTHER, "=")) {
+                    all_ws();
+                    var name = consume(ID) || error("No right hand side in iterator");
+                    ret.iteratorObject = name.value;
+                }
+                all_ws();
+                consume(OTHER, ";") || error("Unterminated iterator");
+                return ret;
+            }
+            else {
+                operation_rest(ret);
+                return ret;
+            }
+        };
+        
+        var identifiers = function (arr) {
+            while (true) {
+                all_ws();
+                if (consume(OTHER, ",")) {
+                    all_ws();
+                    var name = consume(ID) || error("Trailing comma in identifiers list");
+                    arr.push(name.value);
+                }
+                else break;
+            }
+        };
+        
+        var serialiser = function () {
+            all_ws();
+            if (!consume(ID, "serializer")) return;
+            var ret = { type: "serializer" };
+            all_ws();
+            if (consume(OTHER, "=")) {
+                all_ws();
+                if (consume(OTHER, "{")) {
+                    ret.patternMap = true;
+                    all_ws();
+                    var id = consume(ID);
+                    if (id && id.value === "getter") {
+                        ret.names = ["getter"];
+                    }
+                    else if (id && id.value === "inherit") {
+                        ret.names = ["inherit"];
+                        identifiers(ret.names);
+                    }
+                    else if (id) {
+                        ret.names = [id.value];
+                        identifiers(ret.names);
+                    }
+                    else {
+                        ret.names = [];
+                    }
+                    all_ws();
+                    consume(OTHER, "}") || error("Unterminated serializer pattern map");
+                }
+                else if (consume(OTHER, "[")) {
+                    ret.patternList = true;
+                    all_ws();
+                    var id = consume(ID);
+                    if (id && id.value === "getter") {
+                        ret.names = ["getter"];
+                    }
+                    else if (id) {
+                        ret.names = [id.value];
+                        identifiers(ret.names);
+                    }
+                    else {
+                        ret.names = [];
+                    }
+                    all_ws();
+                    consume(OTHER, "]") || error("Unterminated serializer pattern list");
+                }
+                else {
+                    var name = consume(ID) || error("Invalid serializer");
+                    ret.name = name.value;
+                }
+                all_ws();
+                consume(OTHER, ";") || error("Unterminated serializer");
+                return ret;
+            }
+            else if (consume(OTHER, ";")) {
+                // noop, just parsing
+            }
+            else {
+                ret.idlType = return_type();
+                all_ws();
+                ret.operation = operation_rest();
+            }
+            return ret;
+        };
+        
+        var interface_ = function (isPartial) {
+            all_ws();
+            if (!consume(ID, "interface")) return;
+            all_ws();
+            var name = consume(ID) || error("No name for interface");
+            var ret = {
+                type:   "interface"
+            ,   name:   name.value
+            ,   partial:    false
+            ,   members:    []
+            };
+            if (!isPartial) ret.inheritance = inheritance() || null;
+            all_ws();
+            consume(OTHER, "{") || error("Bodyless interface");
+            while (true) {
+                all_ws();
+                if (consume(OTHER, "}")) {
+                    all_ws();
+                    consume(OTHER, ";") || error("Missing semicolon after interface");
+                    return ret;
+                }
+                var ea = extended_attrs();
+                all_ws();
+                var cnt = const_();
+                if (cnt) {
+                    cnt.extAttrs = ea;
+                    ret.members.push(cnt);
+                    continue;
+                }
+                var mem = serialiser() || attribute() || operation() || error("Unknown member");
+                mem.extAttrs = ea;
+                ret.members.push(mem);
+            }
+        };
+        
+        var partial = function () {
+            all_ws();
+            if (!consume(ID, "partial")) return;
+            var thing = dictionary(true) || interface_(true) || error("Partial doesn't apply to anything");
+            thing.partial = true;
+            return thing;
+        };
+        
+        var dictionary = function (isPartial) {
+            all_ws();
+            if (!consume(ID, "dictionary")) return;
+            all_ws();
+            var name = consume(ID) || error("No name for dictionary");
+            var ret = {
+                type:   "dictionary"
+            ,   name:   name.value
+            ,   partial:    false
+            ,   members:    []
+            };
+            if (!isPartial) ret.inheritance = inheritance() || null;
+            all_ws();
+            consume(OTHER, "{") || error("Bodyless dictionary");
+            while (true) {
+                all_ws();
+                if (consume(OTHER, "}")) {
+                    all_ws();
+                    consume(OTHER, ";") || error("Missing semicolon after dictionary");
+                    return ret;
+                }
+                var ea = extended_attrs();
+                all_ws();
+                var typ = type() || error("No type for dictionary member");
+                all_ws();
+                var name = consume(ID) || error("No name for dictionary member");
+                ret.members.push({
+                    type:       "field"
+                ,   name:       name.value
+                ,   idlType:    typ
+                ,   extAttrs:   ea
+                ,   "default":  default_()
+                });
+                all_ws();
+                consume(OTHER, ";") || error("Unterminated dictionary member");
+            }
+        };
+        
+        var exception = function () {
+            all_ws();
+            if (!consume(ID, "exception")) return;
+            all_ws();
+            var name = consume(ID) || error("No name for exception");
+            var ret = {
+                type:   "exception"
+            ,   name:   name.value
+            ,   members:    []
+            };
+            ret.inheritance = inheritance() || null;
+            all_ws();
+            consume(OTHER, "{") || error("Bodyless exception");
+            while (true) {
+                all_ws();
+                if (consume(OTHER, "}")) {
+                    all_ws();
+                    consume(OTHER, ";") || error("Missing semicolon after exception");
+                    return ret;
+                }
+                var ea = extended_attrs();
+                all_ws();
+                var cnt = const_();
+                if (cnt) {
+                    cnt.extAttrs = ea;
+                    ret.members.push(cnt);
+                }
+                else {
+                    var typ = type();
+                    all_ws();
+                    var name = consume(ID);
+                    all_ws();
+                    if (!typ || !name || !consume(OTHER, ";")) error("Unknown member in exception body");
+                    ret.members.push({
+                        type:       "field"
+                    ,   name:       name.value
+                    ,   idlType:    typ
+                    ,   extAttrs:   ea
+                    });
+                }
+            }
+        };
+        
+        var enum_ = function () {
+            all_ws();
+            if (!consume(ID, "enum")) return;
+            all_ws();
+            var name = consume(ID) || error("No name for enum");
+            var ret = {
+                type:   "enum"
+            ,   name:   name.value
+            ,   values: []
+            };
+            all_ws();
+            consume(OTHER, "{") || error("No curly for enum");
+            var saw_comma = false;
+            while (true) {
+                all_ws();
+                if (consume(OTHER, "}")) {
+                    all_ws();
+                    if (saw_comma) error("Trailing comma in enum");
+                    consume(OTHER, ";") || error("No semicolon after enum");
+                    return ret;
+                }
+                var val = consume(STR) || error("Unexpected value in enum");
+                ret.values.push(val.value.replace(/"/g, ""));
+                all_ws();
+                if (consume(OTHER, ",")) {
+                    all_ws();
+                    saw_comma = true;
+                }
+                else {
+                    saw_comma = false;
+                }
+            }
+        };
+        
+        var typedef = function () {
+            all_ws();
+            if (!consume(ID, "typedef")) return;
+            var ret = {
+                type:   "typedef"
+            };
+            all_ws();
+            ret.typeExtAttrs = extended_attrs();
+            all_ws();
+            ret.idlType = type() || error("No type in typedef");
+            all_ws();
+            var name = consume(ID) || error("No name in typedef");
+            ret.name = name.value;
+            all_ws();
+            consume(OTHER, ";") || error("Unterminated typedef");
+            return ret;
+        };
+        
+        var implements_ = function () {
+            all_ws();
+            var target = consume(ID);
+            if (!target) return;
+            var w = all_ws();
+            if (consume(ID, "implements")) {
+                var ret = {
+                    type:   "implements"
+                ,   target: target.value
+                };
+                all_ws();
+                var imp = consume(ID) || error("Incomplete implements statement");
+                ret["implements"] = imp.value;
+                all_ws();
+                consume(OTHER, ";") || error("No terminating ; for implements statement");
+                return ret;
+            }
+            else {
+                // rollback
+                tokens.unshift(w);
+                tokens.unshift(target);
+            }
+        };
+        
+        var definition = function () {
+            return  callback()      ||
+                    interface_()    ||
+                    partial()       ||
+                    dictionary()    ||
+                    exception()     ||
+                    enum_()         ||
+                    typedef()       ||
+                    implements_()
+                    ;
+        };
+        
+        var definitions = function () {
+            if (!tokens.length) return [];
+            var defs = [];
+            while (true) {
+                var ea = extended_attrs()
+                ,   def = definition();
+                if (!def) {
+                    if (ea.length) error("Stray extended attributes");
+                    break;
+                }
+                def.extAttrs = ea;
+                defs.push(def);
+            }
+            return defs;
+        };
+        var res = definitions();
+        if (tokens.length) error("Unrecognised tokens");
+        return res;
+    };
+
+    var obj = {
+        parse:  function (str) {
+            var tokens = tokenise(str);
+            return parse(tokens);
+        }
+    };
+    if (typeof module !== "undefined" && module.exports) {
+        module.exports = obj;
+    }
+    else {
+        window.WebIDL2 = obj;
+    }
+}());

+ 65 - 0
Build/node_modules/usertiming/test-w3c/idlharness.html

@@ -0,0 +1,65 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8" />
+<title>idlharness test</title>
+<link rel="author" title="W3C" href="http://www.w3.org/" />
+<link rel="help" href="http://www.w3.org/TR/user-timing/#extensions-performance-interface"/>
+<link rel="help" href="http://www.w3.org/TR/user-timing/#performancemark"/>
+<link rel="help" href="http://www.w3.org/TR/user-timing/#performancemeasure"/>
+<script src="testharness.js"></script>
+<script src="testharnessreport.js"></script>
+<script src="WebIDLParser.js"></script>
+<script src="idlharness.js"></script>
+
+<script src="../src/usertiming.js"></script>
+
+</head>
+<body>
+<h1>idlharness test</h1>
+<p>This test validates the WebIDL included in the user Timing specification.</p>
+
+<pre id='untested_idl' style='display:none'>
+interface Performance {
+};
+
+interface PerformanceEntry {
+};
+</pre>
+
+<pre id='idl'>
+partial interface Performance {
+    void mark(DOMString markName);
+    void clearMarks(optional  DOMString markName);
+
+    void measure(DOMString measureName, optional DOMString startMark, optional DOMString endMark);
+    void clearMeasures(optional DOMString measureName);
+};
+
+interface PerformanceMark : PerformanceEntry {
+};
+
+interface PerformanceMeasure : PerformanceEntry {
+};
+       
+</pre>
+
+<script>
+
+(function() {
+  var idl_array = new IdlArray();
+
+  idl_array.add_untested_idls(document.getElementById("untested_idl").textContent);
+  idl_array.add_idls(document.getElementById("idl").textContent);
+
+  idl_array.add_objects({Performance: ["window.performance"]});
+
+  idl_array.test();
+})();
+
+</script>
+
+<div id="log"></div>
+
+</body>
+</html>

+ 1837 - 0
Build/node_modules/usertiming/test-w3c/idlharness.js

@@ -0,0 +1,1837 @@
+/*
+Distributed under both the W3C Test Suite License [1] and the W3C
+3-clause BSD License [2]. To contribute to a W3C Test Suite, see the
+policies and contribution forms [3].
+
+[1] http://www.w3.org/Consortium/Legal/2008/04-testsuite-license
+[2] http://www.w3.org/Consortium/Legal/2008/03-bsd-license
+[3] http://www.w3.org/2004/10/27-testcases
+*/
+
+/*
+ * This file automatically generates browser tests for WebIDL interfaces, using
+ * the testharness.js framework.  To use, first include the following:
+ *
+ *   <script src=/resources/testharness.js></script>
+ *   <script src=/resources/testharnessreport.js></script>
+ *   <script src=/resources/webidl2.js></script>
+ *   <script src=/resources/idlharness.js></script>
+ *
+ * Then you'll need some type of IDLs.  Here's some script that can be run on a
+ * spec written in HTML, which will grab all the elements with class="idl",
+ * concatenate them, and replace the body so you can copy-paste:
+ *
+     var s = "";
+     [].forEach.call(document.getElementsByClassName("idl"), function(idl) {
+       //https://www.w3.org/Bugs/Public/show_bug.cgi?id=14914
+       if (!idl.classList.contains("extract"))
+       {
+         s += idl.textContent + "\n\n";
+       }
+     });
+     document.body.innerHTML = '<pre></pre>';
+     document.body.firstChild.textContent = s;
+ *
+ * (TODO: write this in Python or something so that it can be done from the
+ * command line instead.)
+ *
+ * Once you have that, put it in your script somehow.  The easiest way is to
+ * embed it literally in an HTML file with <script type=text/plain> or similar,
+ * so that you don't have to do any escaping.  Another possibility is to put it
+ * in a separate .idl file that's fetched via XHR or similar.  Sample usage:
+ *
+ *   var idl_array = new IdlArray();
+ *   idl_array.add_untested_idls("interface Node { readonly attribute DOMString nodeName; };");
+ *   idl_array.add_idls("interface Document : Node { readonly attribute DOMString URL; };");
+ *   idl_array.add_objects({Document: ["document"]});
+ *   idl_array.test();
+ *
+ * This tests that window.Document exists and meets all the requirements of
+ * WebIDL.  It also tests that window.document (the result of evaluating the
+ * string "document") has URL and nodeName properties that behave as they
+ * should, and otherwise meets WebIDL's requirements for an object whose
+ * primary interface is Document.  It does not test that window.Node exists,
+ * which is what you want if the Node interface is already tested in some other
+ * specification's suite and your specification only extends or refers to it.
+ * Of course, each IDL string can define many different things, and calls to
+ * add_objects() can register many different objects for different interfaces:
+ * this is a very simple example.
+ *
+ * TODO: Write assert_writable, assert_enumerable, assert_configurable and
+ * their inverses, and use those instead of just checking
+ * getOwnPropertyDescriptor.
+ *
+ * == Public methods of IdlArray ==
+ *
+ * IdlArray objects can be obtained with new IdlArray().  Anything not
+ * documented in this section should be considered an implementation detail,
+ * and outside callers should not use it.
+ *
+ * add_idls(idl_string):
+ *   Parses idl_string (throwing on parse error) and adds the results to the
+ *   IdlArray.  All the definitions will be tested when you run test().  If
+ *   some of the definitions refer to other definitions, those must be present
+ *   too.  For instance, if idl_string says that Document inherits from Node,
+ *   the Node interface must also have been provided in some call to add_idls()
+ *   or add_untested_idls().
+ *
+ * add_untested_idls(idl_string):
+ *   Like add_idls(), but the definitions will not be tested.  If an untested
+ *   interface is added and then extended with a tested partial interface, the
+ *   members of the partial interface will still be tested.  Also, all the
+ *   members will still be tested for objects added with add_objects(), because
+ *   you probably want to test that (for instance) window.document has all the
+ *   properties from Node, not just Document, even if the Node interface itself
+ *   is tested in a different test suite.
+ *
+ * add_objects(dict):
+ *   dict should be an object whose keys are the names of interfaces or
+ *   exceptions, and whose values are arrays of strings.  When an interface or
+ *   exception is tested, every string registered for it with add_objects()
+ *   will be evaluated, and tests will be run on the result to verify that it
+ *   correctly implements that interface or exception.  This is the only way to
+ *   test anything about [NoInterfaceObject] interfaces, and there are many
+ *   tests that can't be run on any interface without an object to fiddle with.
+ *
+ *   The interface has to be the *primary* interface of all the objects
+ *   provided.  For example, don't pass {Node: ["document"]}, but rather
+ *   {Document: ["document"]}.  Assuming the Document interface was declared to
+ *   inherit from Node, this will automatically test that document implements
+ *   the Node interface too.
+ *
+ *   Warning: methods will be called on any provided objects, in a manner that
+ *   WebIDL requires be safe.  For instance, if a method has mandatory
+ *   arguments, the test suite will try calling it with too few arguments to
+ *   see if it throws an exception.  If an implementation incorrectly runs the
+ *   function instead of throwing, this might have side effects, possibly even
+ *   preventing the test suite from running correctly.
+ *
+ * prevent_multiple_testing(name):
+ *   This is a niche method for use in case you're testing many objects that
+ *   implement the same interfaces, and don't want to retest the same
+ *   interfaces every single time.  For instance, HTML defines many interfaces
+ *   that all inherit from HTMLElement, so the HTML test suite has something
+ *   like
+ *     .add_objects({
+ *         HTMLHtmlElement: ['document.documentElement'],
+ *         HTMLHeadElement: ['document.head'],
+ *         HTMLBodyElement: ['document.body'],
+ *         ...
+ *     })
+ *   and so on for dozens of element types.  This would mean that it would
+ *   retest that each and every one of those elements implements HTMLElement,
+ *   Element, and Node, which would be thousands of basically redundant tests.
+ *   The test suite therefore calls prevent_multiple_testing("HTMLElement").
+ *   This means that once one object has been tested to implement HTMLElement
+ *   and its ancestors, no other object will be.  Thus in the example code
+ *   above, the harness would test that document.documentElement correctly
+ *   implements HTMLHtmlElement, HTMLElement, Element, and Node; but
+ *   document.head would only be tested for HTMLHeadElement, and so on for
+ *   further objects.
+ *
+ * test():
+ *   Run all tests.  This should be called after you've called all other
+ *   methods to add IDLs and objects.
+ */
+
+/**
+ * Notes for people who want to edit this file (not just use it as a library):
+ *
+ * Most of the interesting stuff happens in the derived classes of IdlObject,
+ * especially IdlInterface.  The entry point for all IdlObjects is .test(),
+ * which is called by IdlArray.test().  An IdlObject is conceptually just
+ * "thing we want to run tests on", and an IdlArray is an array of IdlObjects
+ * with some additional data thrown in.
+ *
+ * The object model is based on what WebIDLParser.js produces, which is in turn
+ * based on its pegjs grammar.  If you want to figure out what properties an
+ * object will have from WebIDLParser.js, the best way is to look at the
+ * grammar:
+ *
+ *   https://github.com/darobin/webidl.js/blob/master/lib/grammar.peg
+ *
+ * So for instance:
+ *
+ *   // interface definition
+ *   interface
+ *       =   extAttrs:extendedAttributeList? S? "interface" S name:identifier w herit:ifInheritance? w "{" w mem:ifMember* w "}" w ";" w
+ *           { return { type: "interface", name: name, inheritance: herit, members: mem, extAttrs: extAttrs }; }
+ *
+ * This means that an "interface" object will have a .type property equal to
+ * the string "interface", a .name property equal to the identifier that the
+ * parser found, an .inheritance property equal to either null or the result of
+ * the "ifInheritance" production found elsewhere in the grammar, and so on.
+ * After each grammatical production is a JavaScript function in curly braces
+ * that gets called with suitable arguments and returns some JavaScript value.
+ *
+ * (Note that the version of WebIDLParser.js we use might sometimes be
+ * out-of-date or forked.)
+ *
+ * The members and methods of the classes defined by this file are all at least
+ * briefly documented, hopefully.
+ */
+(function(){
+"use strict";
+/// Helpers ///
+function constValue (cnt) {
+    if (cnt.type === "null") return null;
+    if (cnt.type === "NaN") return NaN;
+    if (cnt.type === "Infinity") return cnt.negative ? -Infinity : Infinity;
+    return cnt.value;
+}
+
+/// IdlArray ///
+// Entry point
+window.IdlArray = function()
+//@{
+{
+    /**
+     * A map from strings to the corresponding named IdlObject, such as
+     * IdlInterface or IdlException.  These are the things that test() will run
+     * tests on.
+     */
+    this.members = {};
+
+    /**
+     * A map from strings to arrays of strings.  The keys are interface or
+     * exception names, and are expected to also exist as keys in this.members
+     * (otherwise they'll be ignored).  This is populated by add_objects() --
+     * see documentation at the start of the file.  The actual tests will be
+     * run by calling this.members[name].test_object(obj) for each obj in
+     * this.objects[name].  obj is a string that will be eval'd to produce a
+     * JavaScript value, which is supposed to be an object implementing the
+     * given IdlObject (interface, exception, etc.).
+     */
+    this.objects = {};
+
+    /**
+     * When adding multiple collections of IDLs one at a time, an earlier one
+     * might contain a partial interface or implements statement that depends
+     * on a later one.  Save these up and handle them right before we run
+     * tests.
+     *
+     * .partials is simply an array of objects from WebIDLParser.js'
+     * "partialinterface" production.  .implements maps strings to arrays of
+     * strings, such that
+     *
+     *   A implements B;
+     *   A implements C;
+     *   D implements E;
+     *
+     * results in { A: ["B", "C"], D: ["E"] }.
+     */
+    this.partials = [];
+    this["implements"] = {};
+};
+
+//@}
+IdlArray.prototype.add_idls = function(raw_idls)
+//@{
+{
+    /** Entry point.  See documentation at beginning of file. */
+    this.internal_add_idls(WebIDL2.parse(raw_idls));
+};
+
+//@}
+IdlArray.prototype.add_untested_idls = function(raw_idls)
+//@{
+{
+    /** Entry point.  See documentation at beginning of file. */
+    var parsed_idls = WebIDL2.parse(raw_idls);
+    for (var i = 0; i < parsed_idls.length; i++)
+    {
+        parsed_idls[i].untested = true;
+        if ("members" in parsed_idls[i])
+        {
+            for (var j = 0; j < parsed_idls[i].members.length; j++)
+            {
+                parsed_idls[i].members[j].untested = true;
+            }
+        }
+    }
+    this.internal_add_idls(parsed_idls);
+};
+
+//@}
+IdlArray.prototype.internal_add_idls = function(parsed_idls)
+//@{
+{
+    /**
+     * Internal helper called by add_idls() and add_untested_idls().
+     * parsed_idls is an array of objects that come from WebIDLParser.js's
+     * "definitions" production.  The add_untested_idls() entry point
+     * additionally sets an .untested property on each object (and its
+     * .members) so that they'll be skipped by test() -- they'll only be
+     * used for base interfaces of tested interfaces, return types, etc.
+     */
+    parsed_idls.forEach(function(parsed_idl)
+    {
+        if (parsed_idl.type == "interface" && parsed_idl.partial)
+        {
+            this.partials.push(parsed_idl);
+            return;
+        }
+
+        if (parsed_idl.type == "implements")
+        {
+            if (!(parsed_idl.target in this["implements"]))
+            {
+                this["implements"][parsed_idl.target] = [];
+            }
+            this["implements"][parsed_idl.target].push(parsed_idl["implements"]);
+            return;
+        }
+
+        parsed_idl.array = this;
+        if (parsed_idl.name in this.members)
+        {
+            throw "Duplicate identifier " + parsed_idl.name;
+        }
+        switch(parsed_idl.type)
+        {
+        case "interface":
+            this.members[parsed_idl.name] = new IdlInterface(parsed_idl);
+            break;
+
+        case "exception":
+            this.members[parsed_idl.name] = new IdlException(parsed_idl);
+            break;
+
+        case "dictionary":
+            // Nothing to test, but we need the dictionary info around for type
+            // checks
+            this.members[parsed_idl.name] = new IdlDictionary(parsed_idl);
+            break;
+
+        case "typedef":
+            // TODO
+            console.log("typedef not yet supported");
+            break;
+
+        case "callback":
+            // TODO
+            console.log("callback not yet supported");
+            break;
+
+        case "enum":
+            this.members[parsed_idl.name] = new IdlEnum(parsed_idl);
+            break;
+
+        case "callback":
+            // TODO
+            break;
+
+        default:
+            throw parsed_idl.name + ": " + parsed_idl.type + " not yet supported";
+        }
+    }.bind(this));
+};
+
+//@}
+IdlArray.prototype.add_objects = function(dict)
+//@{
+{
+    /** Entry point.  See documentation at beginning of file. */
+    for (var k in dict)
+    {
+        if (k in this.objects)
+        {
+            this.objects[k] = this.objects[k].concat(dict[k]);
+        }
+        else
+        {
+            this.objects[k] = dict[k];
+        }
+    }
+};
+
+//@}
+IdlArray.prototype.prevent_multiple_testing = function(name)
+//@{
+{
+    /** Entry point.  See documentation at beginning of file. */
+    this.members[name].prevent_multiple_testing = true;
+};
+
+//@}
+IdlArray.prototype.recursively_get_implements = function(interface_name)
+//@{
+{
+    /**
+     * Helper function for test().  Returns an array of things that implement
+     * interface_name, so if the IDL contains
+     *
+     *   A implements B;
+     *   B implements C;
+     *   B implements D;
+     *
+     * then recursively_get_implements("A") should return ["B", "C", "D"].
+     */
+    var ret = this["implements"][interface_name];
+    if (ret === undefined)
+    {
+        return [];
+    }
+    for (var i = 0; i < this["implements"][interface_name].length; i++)
+    {
+        ret = ret.concat(this.recursively_get_implements(ret[i]));
+        if (ret.indexOf(ret[i]) != ret.lastIndexOf(ret[i]))
+        {
+            throw "Circular implements statements involving " + ret[i];
+        }
+    }
+    return ret;
+};
+
+//@}
+IdlArray.prototype.test = function()
+//@{
+{
+    /** Entry point.  See documentation at beginning of file. */
+
+    // First merge in all the partial interfaces and implements statements we
+    // encountered.
+    this.partials.forEach(function(parsed_idl)
+    {
+        if (!(parsed_idl.name in this.members)
+        || !(this.members[parsed_idl.name] instanceof IdlInterface))
+        {
+            throw "Partial interface " + parsed_idl.name + " with no original interface";
+        }
+        if (parsed_idl.extAttrs)
+        {
+            parsed_idl.extAttrs.forEach(function(extAttr)
+            {
+                this.members[parsed_idl.name].extAttrs.push(extAttr);
+            }.bind(this));
+        }
+        parsed_idl.members.forEach(function(member)
+        {
+            this.members[parsed_idl.name].members.push(new IdlInterfaceMember(member));
+        }.bind(this));
+    }.bind(this));
+    this.partials = [];
+
+    for (var lhs in this["implements"])
+    {
+        this.recursively_get_implements(lhs).forEach(function(rhs)
+        {
+            var errStr = lhs + " implements " + rhs + ", but ";
+            if (!(lhs in this.members)) throw errStr + lhs + " is undefined.";
+            if (!(this.members[lhs] instanceof IdlInterface)) throw errStr + lhs + " is not an interface.";
+            if (!(rhs in this.members)) throw errStr + rhs + " is undefined.";
+            if (!(this.members[rhs] instanceof IdlInterface)) throw errStr + rhs + " is not an interface.";
+            this.members[rhs].members.forEach(function(member)
+            {
+                this.members[lhs].members.push(new IdlInterfaceMember(member));
+            }.bind(this));
+        }.bind(this));
+    }
+    this["implements"] = {};
+
+    // Now run test() on every member, and test_object() for every object.
+    for (var name in this.members)
+    {
+        this.members[name].test();
+        if (name in this.objects)
+        {
+            this.objects[name].forEach(function(str)
+            {
+                this.members[name].test_object(str);
+            }.bind(this));
+        }
+    }
+};
+
+//@}
+IdlArray.prototype.assert_type_is = function(value, type)
+//@{
+{
+    /**
+     * Helper function that tests that value is an instance of type according
+     * to the rules of WebIDL.  value is any JavaScript value, and type is an
+     * object produced by WebIDLParser.js' "type" production.  That production
+     * is fairly elaborate due to the complexity of WebIDL's types, so it's
+     * best to look at the grammar to figure out what properties it might have.
+     */
+    if (type.idlType == "any")
+    {
+        // No assertions to make
+        return;
+    }
+
+    if (type.nullable && value === null)
+    {
+        // This is fine
+        return;
+    }
+
+    if (type.array)
+    {
+        // TODO: not supported yet
+        return;
+    }
+
+    if (type.sequence)
+    {
+        assert_true(Array.isArray(value), "is not array");
+        if (!value.length)
+        {
+            // Nothing we can do.
+            return;
+        }
+        this.assert_type_is(value[0], type.idlType.idlType);
+        return;
+    }
+
+    type = type.idlType;
+
+    switch(type)
+    {
+        case "void":
+            assert_equals(value, undefined);
+            return;
+
+        case "boolean":
+            assert_equals(typeof value, "boolean");
+            return;
+
+        case "byte":
+            assert_equals(typeof value, "number");
+            assert_equals(value, Math.floor(value), "not an integer");
+            assert_true(-128 <= value && value <= 127, "byte " + value + " not in range [-128, 127]");
+            return;
+
+        case "octet":
+            assert_equals(typeof value, "number");
+            assert_equals(value, Math.floor(value), "not an integer");
+            assert_true(0 <= value && value <= 255, "octet " + value + " not in range [0, 255]");
+            return;
+
+        case "short":
+            assert_equals(typeof value, "number");
+            assert_equals(value, Math.floor(value), "not an integer");
+            assert_true(-32768 <= value && value <= 32767, "short " + value + " not in range [-32768, 32767]");
+            return;
+
+        case "unsigned short":
+            assert_equals(typeof value, "number");
+            assert_equals(value, Math.floor(value), "not an integer");
+            assert_true(0 <= value && value <= 65535, "unsigned short " + value + " not in range [0, 65535]");
+            return;
+
+        case "long":
+            assert_equals(typeof value, "number");
+            assert_equals(value, Math.floor(value), "not an integer");
+            assert_true(-2147483648 <= value && value <= 2147483647, "long " + value + " not in range [-2147483648, 2147483647]");
+            return;
+
+        case "unsigned long":
+            assert_equals(typeof value, "number");
+            assert_equals(value, Math.floor(value), "not an integer");
+            assert_true(0 <= value && value <= 4294967295, "unsigned long " + value + " not in range [0, 4294967295]");
+            return;
+
+        case "long long":
+            assert_equals(typeof value, "number");
+            return;
+
+        case "unsigned long long":
+            assert_equals(typeof value, "number");
+            assert_true(0 <= value, "unsigned long long is negative");
+            return;
+
+        case "float":
+        case "double":
+            // TODO: distinguish these cases
+            assert_equals(typeof value, "number");
+            return;
+
+        case "DOMString":
+            assert_equals(typeof value, "string");
+            return;
+
+        case "object":
+            assert_true(typeof value == "object" || typeof value == "function", "wrong type: not object or function");
+            return;
+    }
+
+    if (!(type in this.members))
+    {
+        throw "Unrecognized type " + type;
+    }
+
+    if (this.members[type] instanceof IdlInterface)
+    {
+        // We don't want to run the full
+        // IdlInterface.prototype.test_instance_of, because that could result
+        // in an infinite loop.  TODO: This means we don't have tests for
+        // NoInterfaceObject interfaces, and we also can't test objects that
+        // come from another window.
+        assert_true(typeof value == "object" || typeof value == "function", "wrong type: not object or function");
+        if (value instanceof Object
+        && !this.members[type].has_extended_attribute("NoInterfaceObject")
+        && type in window)
+        {
+            assert_true(value instanceof window[type], "not instanceof " + type);
+        }
+    }
+    else if (this.members[type] instanceof IdlEnum)
+    {
+        assert_equals(typeof value, "string");
+    }
+    else if (this.members[type] instanceof IdlDictionary)
+    {
+        // TODO: Test when we actually have something to test this on
+    }
+    else
+    {
+        throw "Type " + type + " isn't an interface or dictionary";
+    }
+};
+//@}
+
+/// IdlObject ///
+function IdlObject() {}
+IdlObject.prototype.test = function()
+//@{
+{
+    /**
+     * By default, this does nothing, so no actual tests are run for IdlObjects
+     * that don't define any (e.g., IdlDictionary at the time of this writing).
+     */
+};
+
+//@}
+IdlObject.prototype.has_extended_attribute = function(name)
+//@{
+{
+    /**
+     * This is only meaningful for things that support extended attributes,
+     * such as interfaces, exceptions, and members.
+     */
+    return this.extAttrs.some(function(o)
+    {
+        return o.name == name;
+    });
+};
+
+//@}
+
+/// IdlDictionary ///
+// Used for IdlArray.prototype.assert_type_is
+function IdlDictionary(obj)
+//@{
+{
+    /**
+     * obj is an object produced by the WebIDLParser.js "dictionary"
+     * production.
+     */
+
+    /** Self-explanatory. */
+    this.name = obj.name;
+
+    /** An array of objects produced by the "dictionaryMember" production. */
+    this.members = obj.members;
+
+    /**
+     * The name (as a string) of the dictionary type we inherit from, or null
+     * if there is none.
+     */
+    this.base = obj.inheritance;
+}
+
+//@}
+IdlDictionary.prototype = Object.create(IdlObject.prototype);
+
+/// IdlExceptionOrInterface ///
+// Code sharing!
+function IdlExceptionOrInterface(obj)
+//@{
+{
+    /**
+     * obj is an object produced by the WebIDLParser.js "exception" or
+     * "interface" production, as appropriate.
+     */
+
+    /** Self-explanatory. */
+    this.name = obj.name;
+
+    /** A back-reference to our IdlArray. */
+    this.array = obj.array;
+
+    /**
+     * An indicator of whether we should run tests on the (exception) interface
+     * object and (exception) interface prototype object.  Tests on members are
+     * controlled by .untested on each member, not this.
+     */
+    this.untested = obj.untested;
+
+    /** An array of objects produced by the "ExtAttr" production. */
+    this.extAttrs = obj.extAttrs;
+
+    /** An array of IdlInterfaceMembers. */
+    this.members = obj.members.map(function(m){return new IdlInterfaceMember(m); });
+
+    /**
+     * The name (as a string) of the type we inherit from, or null if there is
+     * none.
+     */
+    this.base = obj.inheritance;
+}
+ 
+//@}
+IdlExceptionOrInterface.prototype = Object.create(IdlObject.prototype);
+IdlExceptionOrInterface.prototype.test = function()
+//@{
+{
+    if (this.has_extended_attribute("NoInterfaceObject"))
+    {
+        // No tests to do without an instance.  TODO: We should still be able
+        // to run tests on the prototype object, if we obtain one through some
+        // other means.
+        return;
+    }
+
+    if (!this.untested)
+    {
+        // First test things to do with the exception/interface object and
+        // exception/interface prototype object.
+        this.test_self();
+    }
+    // Then test things to do with its members (constants, fields, attributes,
+    // operations, . . .).  These are run even if .untested is true, because
+    // members might themselves be marked as .untested.  This might happen to
+    // interfaces if the interface itself is untested but a partial interface
+    // that extends it is tested -- then the interface itself and its initial
+    // members will be marked as untested, but the members added by the partial
+    // interface are still tested.
+    this.test_members();
+};
+
+//@}
+
+/// IdlException ///
+function IdlException(obj) { IdlExceptionOrInterface.call(this, obj); }
+IdlException.prototype = Object.create(IdlExceptionOrInterface.prototype);
+IdlException.prototype.test_self = function()
+//@{
+{
+    test(function()
+    {
+        // "For every exception that is not declared with the
+        // [NoInterfaceObject] extended attribute, a corresponding property
+        // must exist on the exception’s relevant namespace object. The name of
+        // the property is the identifier of the exception, and its value is an
+        // object called the exception interface object, which provides access
+        // to any constants that have been associated with the exception. The
+        // property has the attributes { [[Writable]]: true, [[Enumerable]]:
+        // false, [[Configurable]]: true }."
+        assert_own_property(window, this.name,
+                            "window does not have own property " + format_value(this.name));
+        var desc = Object.getOwnPropertyDescriptor(window, this.name);
+        assert_false("get" in desc, "window's property " + format_value(this.name) + " has getter");
+        assert_false("set" in desc, "window's property " + format_value(this.name) + " has setter");
+        assert_true(desc.writable, "window's property " + format_value(this.name) + " is not writable");
+        assert_false(desc.enumerable, "window's property " + format_value(this.name) + " is enumerable");
+        assert_true(desc.configurable, "window's property " + format_value(this.name) + " is not configurable");
+
+        // "The exception interface object for a given exception must be a
+        // function object."
+        // "If an object is defined to be a function object, then it has
+        // characteristics as follows:"
+        // "Its [[Prototype]] internal property is the Function prototype
+        // object."
+        // Note: This doesn't match browsers as of December 2011, see
+        // http://www.w3.org/Bugs/Public/show_bug.cgi?id=14813
+        assert_equals(Object.getPrototypeOf(window[this.name]), Function.prototype,
+                      "prototype of window's property " + format_value(this.name) + " is not Function.prototype");
+        // "Its [[Get]] internal property is set as described in ECMA-262
+        // section 15.3.5.4."
+        // Not much to test for this.
+        // "Its [[Construct]] internal property is set as described in ECMA-262
+        // section 13.2.2."
+        // Tested below.
+        // "Its [[HasInstance]] internal property is set as described in
+        // ECMA-262 section 15.3.5.3, unless otherwise specified."
+        // TODO
+        // "Its [[Class]] internal property is “Function”."
+        // String() returns something implementation-dependent, because it
+        // calls Function#toString.
+        assert_class_string(window[this.name], "Function",
+                            "class string of " + this.name);
+
+        // TODO: Test 4.9.1.1. Exception interface object [[Call]] method
+        // (which does not match browsers:
+        // http://www.w3.org/Bugs/Public/show_bug.cgi?id=14885)
+    }.bind(this), this.name + " exception: existence and properties of exception interface object");
+
+    test(function()
+    {
+        assert_own_property(window, this.name,
+                            "window does not have own property " + format_value(this.name));
+
+        // "The exception interface object must also have a property named
+        // “prototype” with attributes { [[Writable]]: false, [[Enumerable]]:
+        // false, [[Configurable]]: false } whose value is an object called the
+        // exception interface prototype object. This object also provides
+        // access to the constants that are declared on the exception."
+        assert_own_property(window[this.name], "prototype",
+                            'exception "' + this.name + '" does not have own property "prototype"');
+        var desc = Object.getOwnPropertyDescriptor(window[this.name], "prototype");
+        assert_false("get" in desc, this.name + ".prototype has getter");
+        assert_false("set" in desc, this.name + ".prototype has setter");
+        assert_false(desc.writable, this.name + ".prototype is writable");
+        assert_false(desc.enumerable, this.name + ".prototype is enumerable");
+        assert_false(desc.configurable, this.name + ".prototype is configurable");
+
+        // "The exception interface prototype object for a given exception must
+        // have an internal [[Prototype]] property whose value is as follows:
+        //
+        // "If the exception is declared to inherit from another exception,
+        // then the value of the internal [[Prototype]] property is the
+        // exception interface prototype object for the inherited exception.
+        // "Otherwise, the exception is not declared to inherit from another
+        // exception. The value of the internal [[Prototype]] property is the
+        // Error prototype object ([ECMA-262], section 15.11.3.1)."
+        //
+        // Note: This doesn't match browsers as of December 2011, see
+        // https://www.w3.org/Bugs/Public/show_bug.cgi?id=14887.
+        var inherit_exception = this.base ? this.base : "Error";
+        assert_own_property(window, inherit_exception,
+                            'should inherit from ' + inherit_exception + ', but window has no such property');
+        assert_own_property(window[inherit_exception], "prototype",
+                            'should inherit from ' + inherit_exception + ', but that object has no "prototype" property');
+        assert_equals(Object.getPrototypeOf(window[this.name].prototype),
+                      window[inherit_exception].prototype,
+                      'prototype of ' + this.name + '.prototype is not ' + inherit_exception + '.prototype');
+
+        // "The class string of an exception interface prototype object is the
+        // concatenation of the exception’s identifier and the string
+        // “Prototype”."
+        assert_class_string(window[this.name].prototype, this.name + "Prototype",
+                            "class string of " + this.name + ".prototype");
+        // TODO: Test String(), based on ES definition of
+        // Error.prototype.toString?
+    }.bind(this), this.name + " exception: existence and properties of exception interface prototype object");
+
+    test(function()
+    {
+        assert_own_property(window, this.name,
+                            "window does not have own property " + format_value(this.name));
+        assert_own_property(window[this.name], "prototype",
+                            'interface "' + this.name + '" does not have own property "prototype"');
+
+        // "There must be a property named “name” on the exception interface
+        // prototype object with attributes { [[Writable]]: true,
+        // [[Enumerable]]: false, [[Configurable]]: true } and whose value is
+        // the identifier of the exception."
+        assert_own_property(window[this.name].prototype, "name",
+                'prototype object does not have own property "name"');
+        var desc = Object.getOwnPropertyDescriptor(window[this.name].prototype, "name");
+        assert_false("get" in desc, this.name + ".prototype.name has getter");
+        assert_false("set" in desc, this.name + ".prototype.name has setter");
+        assert_true(desc.writable, this.name + ".prototype.name is not writable");
+        assert_false(desc.enumerable, this.name + ".prototype.name is enumerable");
+        assert_true(desc.configurable, this.name + ".prototype.name is not configurable");
+        assert_equals(desc.value, this.name, this.name + ".prototype.name has incorrect value");
+    }.bind(this), this.name + " exception: existence and properties of exception interface prototype object's \"name\" property");
+
+    test(function()
+    {
+        assert_own_property(window, this.name,
+                            "window does not have own property " + format_value(this.name));
+        assert_own_property(window[this.name], "prototype",
+                            'interface "' + this.name + '" does not have own property "prototype"');
+
+        // "If the [NoInterfaceObject] extended attribute was not specified on
+        // the exception, then there must also be a property named
+        // “constructor” on the exception interface prototype object with
+        // attributes { [[Writable]]: true, [[Enumerable]]: false,
+        // [[Configurable]]: true } and whose value is a reference to the
+        // exception interface object for the exception."
+        assert_own_property(window[this.name].prototype, "constructor",
+                            this.name + '.prototype does not have own property "constructor"');
+        var desc = Object.getOwnPropertyDescriptor(window[this.name].prototype, "constructor");
+        assert_false("get" in desc, this.name + ".prototype.constructor has getter");
+        assert_false("set" in desc, this.name + ".prototype.constructor has setter");
+        assert_true(desc.writable, this.name + ".prototype.constructor is not writable");
+        assert_false(desc.enumerable, this.name + ".prototype.constructor is enumerable");
+        assert_true(desc.configurable, this.name + ".prototype.constructor in not configurable");
+        assert_equals(window[this.name].prototype.constructor, window[this.name],
+                      this.name + '.prototype.constructor is not the same object as ' + this.name);
+    }.bind(this), this.name + " exception: existence and properties of exception interface prototype object's \"constructor\" property");
+};
+
+//@}
+IdlException.prototype.test_members = function()
+//@{
+{
+    for (var i = 0; i < this.members.length; i++)
+    {
+        var member = this.members[i];
+        if (member.untested)
+        {
+            continue;
+        }
+        if (member.type == "const" && member.name != "prototype")
+        {
+            test(function()
+            {
+                assert_own_property(window, this.name,
+                                    "window does not have own property " + format_value(this.name));
+
+                // "For each constant defined on the exception, there must be a
+                // corresponding property on the exception interface object, if
+                // it exists, if the identifier of the constant is not
+                // “prototype”."
+                assert_own_property(window[this.name], member.name);
+                // "The value of the property is the ECMAScript value that is
+                // equivalent to the constant’s IDL value, according to the
+                // rules in section 4.2 above."
+                assert_equals(window[this.name][member.name], constValue(member.value),
+                              "property has wrong value");
+                // "The property has attributes { [[Writable]]: false,
+                // [[Enumerable]]: true, [[Configurable]]: false }."
+                var desc = Object.getOwnPropertyDescriptor(window[this.name], member.name);
+                assert_false("get" in desc, "property has getter");
+                assert_false("set" in desc, "property has setter");
+                assert_false(desc.writable, "property is writable");
+                assert_true(desc.enumerable, "property is not enumerable");
+                assert_false(desc.configurable, "property is configurable");
+            }.bind(this), this.name + " exception: constant " + member.name + " on exception interface object");
+            // "In addition, a property with the same characteristics must
+            // exist on the exception interface prototype object."
+            test(function()
+            {
+                assert_own_property(window, this.name,
+                                    "window does not have own property " + format_value(this.name));
+                assert_own_property(window[this.name], "prototype",
+                                    'exception "' + this.name + '" does not have own property "prototype"');
+
+                assert_own_property(window[this.name].prototype, member.name);
+                assert_equals(window[this.name].prototype[member.name], constValue(member.value),
+                              "property has wrong value");
+                var desc = Object.getOwnPropertyDescriptor(window[this.name].prototype, member.name);
+                assert_false("get" in desc, "property has getter");
+                assert_false("set" in desc, "property has setter");
+                assert_false(desc.writable, "property is writable");
+                assert_true(desc.enumerable, "property is not enumerable");
+                assert_false(desc.configurable, "property is configurable");
+            }.bind(this), this.name + " exception: constant " + member.name + " on exception interface prototype object");
+        }
+        else if (member.type == "field")
+        {
+            test(function()
+            {
+                assert_own_property(window, this.name,
+                                    "window does not have own property " + format_value(this.name));
+                assert_own_property(window[this.name], "prototype",
+                                    'exception "' + this.name + '" does not have own property "prototype"');
+
+                // "For each exception field, there must be a corresponding
+                // property on the exception interface prototype object, whose
+                // characteristics are as follows:
+                // "The name of the property is the identifier of the exception
+                // field."
+                assert_own_property(window[this.name].prototype, member.name);
+                // "The property has attributes { [[Get]]: G, [[Enumerable]]:
+                // true, [[Configurable]]: true }, where G is the exception
+                // field getter, defined below."
+                var desc = Object.getOwnPropertyDescriptor(window[this.name].prototype, member.name);
+                assert_false("value" in desc, "property descriptor has value but is supposed to be accessor");
+                assert_false("writable" in desc, 'property descriptor has "writable" field but is supposed to be accessor');
+                // TODO: ES5 doesn't seem to say whether desc should have a
+                // .set property.
+                assert_true(desc.enumerable, "property is not enumerable");
+                assert_true(desc.configurable, "property is not configurable");
+                // "The exception field getter is a Function object whose
+                // behavior when invoked is as follows:"
+                assert_equals(typeof desc.get, "function", "typeof getter");
+                // "The value of the Function object’s “length” property is the
+                // Number value 0."
+                // This test is before the TypeError tests so that it's easiest
+                // to see that Firefox 11a1 only fails one assert in this test.
+                assert_equals(desc.get.length, 0, "getter length");
+                // "Let O be the result of calling ToObject on the this value.
+                // "If O is not a platform object representing an exception for
+                // the exception on which the exception field was declared,
+                // then throw a TypeError."
+                // TODO: Test on a platform object representing an exception.
+                assert_throws(new TypeError(), function()
+                {
+                    window[this.name].prototype[member.name];
+                }.bind(this), "getting property on prototype object must throw TypeError");
+                assert_throws(new TypeError(), function()
+                {
+                    desc.get.call({});
+                }.bind(this), "calling getter on wrong object type must throw TypeError");
+            }.bind(this), this.name + " exception: field " + member.name + " on exception interface prototype object");
+        }
+    }
+};
+
+//@}
+IdlException.prototype.test_object = function(desc)
+//@{
+{
+    var obj, exception = null;
+    try
+    {
+        obj = eval(desc);
+    }
+    catch(e)
+    {
+        exception = e;
+    }
+
+    test(function()
+    {
+        assert_equals(exception, null, "Unexpected exception when evaluating object");
+        assert_equals(typeof obj, "object", "wrong typeof object");
+
+        // We can't easily test that its prototype is correct if there's no
+        // interface object, or the object is from a different global
+        // environment (not instanceof Object).  TODO: test in this case that
+        // its prototype at least looks correct, even if we can't test that
+        // it's actually correct.
+        if (!this.has_extended_attribute("NoInterfaceObject")
+        && (typeof obj != "object" || obj instanceof Object))
+        {
+            assert_own_property(window, this.name,
+                                "window does not have own property " + format_value(this.name));
+            assert_own_property(window[this.name], "prototype",
+                                'exception "' + this.name + '" does not have own property "prototype"');
+
+            // "The value of the internal [[Prototype]] property of the
+            // exception object must be the exception interface prototype
+            // object from the global environment the exception object is
+            // associated with."
+            assert_equals(Object.getPrototypeOf(obj),
+                          window[this.name].prototype,
+                          desc + "'s prototype is not " + this.name + ".prototype");
+        }
+
+        // "The class string of the exception object must be the identifier of
+        // the exception."
+        assert_class_string(obj, this.name, "class string of " + desc);
+        // Stringifier is not defined for DOMExceptions, because message isn't
+        // defined.
+    }.bind(this), this.name + " must be represented by " + desc);
+
+    for (var i = 0; i < this.members.length; i++)
+    {
+        var member = this.members[i];
+        test(function()
+        {
+            assert_equals(exception, null, "Unexpected exception when evaluating object");
+            assert_equals(typeof obj, "object", "wrong typeof object");
+            assert_inherits(obj, member.name);
+            if (member.type == "const")
+            {
+                assert_equals(obj[member.name], constValue(member.value));
+            }
+            if (member.type == "field")
+            {
+                this.array.assert_type_is(obj[member.name], member.idlType);
+            }
+        }.bind(this), this.name + " exception: " + desc + ' must inherit property "' + member.name + '" with the proper type');
+    }
+};
+//@}
+
+/// IdlInterface ///
+function IdlInterface(obj) { IdlExceptionOrInterface.call(this, obj); }
+IdlInterface.prototype = Object.create(IdlExceptionOrInterface.prototype);
+IdlInterface.prototype.is_callback = function()
+//@{
+{
+    return this.has_extended_attribute("Callback");
+};
+//@}
+
+IdlInterface.prototype.has_constants = function()
+//@{
+{
+    return this.members.any(function(member) {
+        return member.type === "const";
+    });
+};
+//@}
+
+IdlInterface.prototype.test_self = function()
+//@{
+{
+    test(function()
+    {
+        // This function tests WebIDL as of 2012-11-28.
+
+        // "For every interface that:
+        // * is a callback interface that has constants declared on it, or
+        // * is a non-callback interface that is not declared with the
+        //   [NoInterfaceObject] extended attribute,
+        // a corresponding property MUST exist on the ECMAScript global object.
+        // The name of the property is the identifier of the interface, and its
+        // value is an object called the interface object.
+        // The property has the attributes { [[Writable]]: true,
+        // [[Enumerable]]: false, [[Configurable]]: true }."
+        if (this.is_callback() && !this.has_constants()) {
+            return;
+        }
+
+        // TODO: Should we test here that the property is actually writable
+        // etc., or trust getOwnPropertyDescriptor?
+        assert_own_property(window, this.name,
+                            "window does not have own property " + format_value(this.name));
+        var desc = Object.getOwnPropertyDescriptor(window, this.name);
+        assert_false("get" in desc, "window's property " + format_value(this.name) + " has getter");
+        assert_false("set" in desc, "window's property " + format_value(this.name) + " has setter");
+        assert_true(desc.writable, "window's property " + format_value(this.name) + " is not writable");
+        assert_false(desc.enumerable, "window's property " + format_value(this.name) + " is enumerable");
+        assert_true(desc.configurable, "window's property " + format_value(this.name) + " is not configurable");
+
+        if (this.is_callback()) {
+            // "The internal [[Prototype]] property of an interface object for
+            // a callback interface MUST be the Object.prototype object."
+            assert_equals(Object.getPrototypeOf(window[this.name]), Object.prototype,
+                          "prototype of window's property " + format_value(this.name) + " is not Object.prototype");
+
+            return;
+        }
+
+        // "The interface object for a given non-callback interface is a
+        // function object."
+        // "If an object is defined to be a function object, then it has
+        // characteristics as follows:"
+
+        // "* Its [[Prototype]] internal property is the Function prototype
+        //    object."
+        assert_equals(Object.getPrototypeOf(window[this.name]), Function.prototype,
+                      "prototype of window's property " + format_value(this.name) + " is not Function.prototype");
+
+        // "* Its [[Get]] internal property is set as described in ECMA-262
+        //    section 15.3.5.4."
+        // Not much to test for this.
+
+        // "* Its [[Construct]] internal property is set as described in
+        //    ECMA-262 section 13.2.2."
+        // Tested below if no constructor is defined.  TODO: test constructors
+        // if defined.
+
+        // "* Its [[HasInstance]] internal property is set as described in
+        //    ECMA-262 section 15.3.5.3, unless otherwise specified."
+        // TODO
+
+        // "* Its [[NativeBrand]] internal property is “Function”."
+        // String() returns something implementation-dependent, because it calls
+        // Function#toString.
+        assert_class_string(window[this.name], "Function", "class string of " + this.name);
+
+        if (!this.has_extended_attribute("Constructor")) {
+            // "The internal [[Call]] method of the interface object behaves as
+            // follows . . .
+            //
+            // "If I was not declared with a [Constructor] extended attribute,
+            // then throw a TypeError."
+            assert_throws(new TypeError(), function() {
+                window[this.name]();
+            }.bind(this), "interface object didn't throw TypeError when called as a function");
+            assert_throws(new TypeError(), function() {
+                new window[this.name]();
+            }.bind(this), "interface object didn't throw TypeError when called as a constructor");
+        }
+    }.bind(this), this.name + " interface: existence and properties of interface object");
+
+    if (this.has_extended_attribute("Constructor"))
+    {
+        test(function()
+        {
+            assert_own_property(window, this.name,
+                                "window does not have own property " + format_value(this.name));
+
+            // "Interface objects for interfaces declared with a [Constructor]
+            // extended attribute must have a property named “length” with
+            // attributes { [[Writable]]: false, [[Enumerable]]: false,
+            // [[Configurable]]: false } whose value is a Number determined as
+            // follows: . . .
+            // "Return the length of the shortest argument list of the entries
+            // in S."
+            // TODO: Variadic constructors.  Should generalize this so that it
+            // works for testing operation length too (currently we just don't
+            // support multiple operations with the same identifier).
+            var expected_length = this.extAttrs
+                .filter(function(attr) { return attr.name == "Constructor"; })
+                .map(function(attr) {
+                    return attr.arguments ? attr.arguments.filter(
+                        function(arg) {
+                            return !arg.optional;
+                        }).length : 0;
+                })
+                .reduce(function(m, n) { return Math.min(m, n); });
+            assert_own_property(window[this.name], "length");
+            assert_equals(window[this.name].length, expected_length, "wrong value for " + this.name + ".length");
+            var desc = Object.getOwnPropertyDescriptor(window[this.name], "length");
+            assert_false("get" in desc, this.name + ".length has getter");
+            assert_false("set" in desc, this.name + ".length has setter");
+            assert_false(desc.writable, this.name + ".length is writable");
+            assert_false(desc.enumerable, this.name + ".length is enumerable");
+            assert_false(desc.configurable, this.name + ".length is configurable");
+        }.bind(this), this.name + " interface constructor");
+    }
+
+    // TODO: Test named constructors if I find any interfaces that have them.
+
+    test(function()
+    {
+        assert_own_property(window, this.name,
+                            "window does not have own property " + format_value(this.name));
+
+        if (this.has_extended_attribute("Callback")) {
+            assert_false("prototype" in window[this.name],
+                         this.name + ' should not have a "prototype" property');
+            return;
+        }
+
+        // "The interface object must also have a property named “prototype”
+        // with attributes { [[Writable]]: false, [[Enumerable]]: false,
+        // [[Configurable]]: false } whose value is an object called the
+        // interface prototype object. This object has properties that
+        // correspond to the attributes and operations defined on the
+        // interface, and is described in more detail in section 4.5.3 below."
+        assert_own_property(window[this.name], "prototype",
+                            'interface "' + this.name + '" does not have own property "prototype"');
+        var desc = Object.getOwnPropertyDescriptor(window[this.name], "prototype");
+        assert_false("get" in desc, this.name + ".prototype has getter");
+        assert_false("set" in desc, this.name + ".prototype has setter");
+        assert_false(desc.writable, this.name + ".prototype is writable");
+        assert_false(desc.enumerable, this.name + ".prototype is enumerable");
+        assert_false(desc.configurable, this.name + ".prototype is configurable");
+
+        // Next, test that the [[Prototype]] of the interface prototype object
+        // is correct. (This is made somewhat difficult by the existence of
+        // [NoInterfaceObject].)
+        // TODO: Aryeh thinks there's at least other place in this file where
+        //       we try to figure out if an interface prototype object is
+        //       correct. Consolidate that code.
+
+        // "The interface prototype object for a given interface A must have an
+        // internal [[Prototype]] property whose value is as follows:
+        // "If A is not declared to inherit from another interface, then the
+        // value of the internal [[Prototype]] property of A is the Array
+        // prototype object ([ECMA-262], section 15.4.4) if the interface was
+        // declared with ArrayClass, or the Object prototype object otherwise
+        // ([ECMA-262], section 15.2.4).
+        // "Otherwise, A does inherit from another interface. The value of the
+        // internal [[Prototype]] property of A is the interface prototype
+        // object for the inherited interface."
+        var inherit_interface, inherit_interface_has_interface_object;
+        if (this.base) {
+            inherit_interface = this.base;
+            inherit_interface_has_interface_object =
+                !this.array
+                     .members[inherit_interface]
+                     .has_extended_attribute("NoInterfaceObject");
+        } else if (this.has_extended_attribute('ArrayClass')) {
+            inherit_interface = 'Array';
+            inherit_interface_has_interface_object = true;
+        } else {
+            inherit_interface = 'Object';
+            inherit_interface_has_interface_object = true;
+        }
+        if (inherit_interface_has_interface_object) {
+            assert_own_property(window, inherit_interface,
+                                'should inherit from ' + inherit_interface + ', but window has no such property');
+            assert_own_property(window[inherit_interface], 'prototype',
+                                'should inherit from ' + inherit_interface + ', but that object has no "prototype" property');
+            assert_equals(Object.getPrototypeOf(window[this.name].prototype),
+                          window[inherit_interface].prototype,
+                          'prototype of ' + this.name + '.prototype is not ' + inherit_interface + '.prototype');
+        } else {
+            // We can't test that we get the correct object, because this is the
+            // only way to get our hands on it. We only test that its class
+            // string, at least, is correct.
+            assert_class_string(Object.getPrototypeOf(window[this.name].prototype),
+                                inherit_interface + 'Prototype',
+                                'Class name for prototype of ' + this.name +
+                                '.prototype is not "' + inherit_interface + 'Prototype"');
+        }
+
+        // "The class string of an interface prototype object is the
+        // concatenation of the interface’s identifier and the string
+        // “Prototype”."
+        assert_class_string(window[this.name].prototype, this.name + "Prototype",
+                            "class string of " + this.name + ".prototype");
+        // String() should end up calling {}.toString if nothing defines a
+        // stringifier.
+        if (!this.has_stringifier()) {
+            assert_equals(String(window[this.name].prototype), "[object " + this.name + "Prototype]",
+                    "String(" + this.name + ".prototype)");
+        }
+    }.bind(this), this.name + " interface: existence and properties of interface prototype object");
+
+    test(function()
+    {
+        assert_own_property(window, this.name,
+                            "window does not have own property " + format_value(this.name));
+
+        if (this.has_extended_attribute("Callback")) {
+            assert_false("prototype" in window[this.name],
+                         this.name + ' should not have a "prototype" property');
+            return;
+        }
+
+        assert_own_property(window[this.name], "prototype",
+                            'interface "' + this.name + '" does not have own property "prototype"');
+
+        // "If the [NoInterfaceObject] extended attribute was not specified on
+        // the interface, then the interface prototype object must also have a
+        // property named “constructor” with attributes { [[Writable]]: true,
+        // [[Enumerable]]: false, [[Configurable]]: true } whose value is a
+        // reference to the interface object for the interface."
+        assert_own_property(window[this.name].prototype, "constructor",
+                            this.name + '.prototype does not have own property "constructor"');
+        var desc = Object.getOwnPropertyDescriptor(window[this.name].prototype, "constructor");
+        assert_false("get" in desc, this.name + ".prototype.constructor has getter");
+        assert_false("set" in desc, this.name + ".prototype.constructor has setter");
+        assert_true(desc.writable, this.name + ".prototype.constructor is not writable");
+        assert_false(desc.enumerable, this.name + ".prototype.constructor is enumerable");
+        assert_true(desc.configurable, this.name + ".prototype.constructor in not configurable");
+        assert_equals(window[this.name].prototype.constructor, window[this.name],
+                      this.name + '.prototype.constructor is not the same object as ' + this.name);
+    }.bind(this), this.name + ' interface: existence and properties of interface prototype object\'s "constructor" property');
+};
+
+//@}
+IdlInterface.prototype.test_members = function()
+//@{
+{
+    for (var i = 0; i < this.members.length; i++)
+    {
+        var member = this.members[i];
+        if (member.untested)
+        {
+            continue;
+        }
+        if (member.type == "const")
+        {
+            test(function()
+            {
+                assert_own_property(window, this.name,
+                                    "window does not have own property " + format_value(this.name));
+
+                // "For each constant defined on an interface A, there must be
+                // a corresponding property on the interface object, if it
+                // exists."
+                assert_own_property(window[this.name], member.name);
+                // "The value of the property is that which is obtained by
+                // converting the constant’s IDL value to an ECMAScript
+                // value."
+                assert_equals(window[this.name][member.name], constValue(member.value),
+                              "property has wrong value");
+                // "The property has attributes { [[Writable]]: false,
+                // [[Enumerable]]: true, [[Configurable]]: false }."
+                var desc = Object.getOwnPropertyDescriptor(window[this.name], member.name);
+                assert_false("get" in desc, "property has getter");
+                assert_false("set" in desc, "property has setter");
+                assert_false(desc.writable, "property is writable");
+                assert_true(desc.enumerable, "property is not enumerable");
+                assert_false(desc.configurable, "property is configurable");
+            }.bind(this), this.name + " interface: constant " + member.name + " on interface object");
+            // "In addition, a property with the same characteristics must
+            // exist on the interface prototype object."
+            test(function()
+            {
+                assert_own_property(window, this.name,
+                                    "window does not have own property " + format_value(this.name));
+
+                if (this.has_extended_attribute("Callback")) {
+                    assert_false("prototype" in window[this.name],
+                                 this.name + ' should not have a "prototype" property');
+                    return;
+                }
+
+                assert_own_property(window[this.name], "prototype",
+                                    'interface "' + this.name + '" does not have own property "prototype"');
+
+                assert_own_property(window[this.name].prototype, member.name);
+                assert_equals(window[this.name].prototype[member.name], constValue(member.value),
+                              "property has wrong value");
+                var desc = Object.getOwnPropertyDescriptor(window[this.name], member.name);
+                assert_false("get" in desc, "property has getter");
+                assert_false("set" in desc, "property has setter");
+                assert_false(desc.writable, "property is writable");
+                assert_true(desc.enumerable, "property is not enumerable");
+                assert_false(desc.configurable, "property is configurable");
+            }.bind(this), this.name + " interface: constant " + member.name + " on interface prototype object");
+        }
+        else if (member.type == "attribute")
+        {
+            if (member.has_extended_attribute("Unforgeable"))
+            {
+                // We do the checks in test_interface_of instead
+                continue;
+            }
+            test(function()
+            {
+                assert_own_property(window, this.name,
+                                    "window does not have own property " + format_value(this.name));
+                assert_own_property(window[this.name], "prototype",
+                                    'interface "' + this.name + '" does not have own property "prototype"');
+                assert_true(member.name in window[this.name].prototype,
+                            "The prototype object must have a property " +
+                            format_value(member.name));
+
+                // TODO: Needs to test for LenientThis.
+                assert_throws(new TypeError(), function() {
+                    window[this.name].prototype[member.name];
+                }.bind(this), "getting property on prototype object must throw TypeError");
+
+                do_interface_attribute_asserts(window[this.name].prototype, member);
+            }.bind(this), this.name + " interface: attribute " + member.name);
+        }
+        else if (member.type == "operation")
+        {
+            // TODO: Need to correctly handle multiple operations with the same
+            // identifier.
+            if (!member.name)
+            {
+                // Unnamed getter or such
+                continue;
+            }
+            test(function()
+            {
+                assert_own_property(window, this.name,
+                                    "window does not have own property " + format_value(this.name));
+
+                if (this.has_extended_attribute("Callback")) {
+                    assert_false("prototype" in window[this.name],
+                                 this.name + ' should not have a "prototype" property');
+                    return;
+                }
+
+                assert_own_property(window[this.name], "prototype",
+                                    'interface "' + this.name + '" does not have own property "prototype"');
+
+                // "For each unique identifier of an operation defined on the
+                // interface, there must be a corresponding property on the
+                // interface prototype object (if it is a regular operation) or
+                // the interface object (if it is a static operation), unless
+                // the effective overload set for that identifier and operation
+                // and with an argument count of 0 (for the ECMAScript language
+                // binding) has no entries."
+                //
+                // TODO: The library doesn't seem to support static operations.
+                assert_own_property(window[this.name].prototype, member.name,
+                    "interface prototype object missing non-static operation");
+
+                var desc = Object.getOwnPropertyDescriptor(window[this.name].prototype, member.name);
+                // "The property has attributes { [[Writable]]: true,
+                // [[Enumerable]]: true, [[Configurable]]: true }."
+                assert_false("get" in desc, "property has getter");
+                assert_false("set" in desc, "property has setter");
+                assert_true(desc.writable, "property is not writable");
+                assert_true(desc.enumerable, "property is not enumerable");
+                assert_true(desc.configurable, "property is not configurable");
+                // "The value of the property is a Function object whose
+                // behavior is as follows . . ."
+                assert_equals(typeof window[this.name].prototype[member.name], "function",
+                              "property must be a function");
+                // "The value of the Function object’s “length” property is
+                // a Number determined as follows:
+                // ". . .
+                // "Return the length of the shortest argument list of the
+                // entries in S."
+                //
+                // TODO: Doesn't handle overloading or variadic arguments.
+                assert_equals(window[this.name].prototype[member.name].length,
+                    member.arguments.filter(function(arg) {
+                        return !arg.optional;
+                    }).length,
+                    "property has wrong .length");
+
+                // Make some suitable arguments
+                var args = member.arguments.map(function(arg) {
+                    return create_suitable_object(arg.idlType);
+                });
+
+                // "Let O be a value determined as follows:
+                // ". . .
+                // "Otherwise, throw a TypeError."
+                // This should be hit if the operation is not static, there is
+                // no [ImplicitThis] attribute, and the this value is null.
+                //
+                // TODO: We currently ignore the static and [ImplicitThis]
+                // cases.
+                assert_throws(new TypeError(), function() {
+                    window[this.name].prototype[member.name].apply(null, args);
+                }, "calling operation with this = null didn't throw TypeError");
+
+                // ". . . If O is not null and is also not a platform object
+                // that implements interface I, throw a TypeError."
+                //
+                // TODO: Test a platform object that implements some other
+                // interface.  (Have to be sure to get inheritance right.)
+                assert_throws(new TypeError(), function() {
+                    window[this.name].prototype[member.name].apply({}, args);
+                }, "calling operation with this = {} didn't throw TypeError");
+            }.bind(this), this.name + " interface: operation " + member.name +
+            "(" + member.arguments.map(function(m) { return m.idlType.idlType; }) +
+            ")");
+        }
+        // TODO: check more member types, like stringifier
+    }
+};
+
+//@}
+IdlInterface.prototype.test_object = function(desc)
+//@{
+{
+    var obj, exception = null;
+    try
+    {
+        obj = eval(desc);
+    }
+    catch(e)
+    {
+        exception = e;
+    }
+
+    // TODO: WebIDLParser doesn't currently support named legacycallers, so I'm
+    // not sure what those would look like in the AST
+    var expected_typeof = this.members.some(function(member)
+    {
+        return member.legacycaller
+            || ("idlType" in member && member.idlType.legacycaller)
+            || ("idlType" in member && typeof member.idlType == "object"
+            && "idlType" in member.idlType && member.idlType.idlType == "legacycaller");
+    }) ? "function" : "object";
+
+    this.test_primary_interface_of(desc, obj, exception, expected_typeof);
+    var current_interface = this;
+    while (current_interface)
+    {
+        if (!(current_interface.name in this.array.members))
+        {
+            throw "Interface " + current_interface.name + " not found (inherited by " + this.name + ")";
+        }
+        if (current_interface.prevent_multiple_testing && current_interface.already_tested)
+        {
+            return;
+        }
+        current_interface.test_interface_of(desc, obj, exception, expected_typeof);
+        current_interface = this.array.members[current_interface.base];
+    }
+};
+
+//@}
+IdlInterface.prototype.test_primary_interface_of = function(desc, obj, exception, expected_typeof)
+//@{
+{
+    // We can't easily test that its prototype is correct if there's no
+    // interface object, or the object is from a different global environment
+    // (not instanceof Object).  TODO: test in this case that its prototype at
+    // least looks correct, even if we can't test that it's actually correct.
+    if (!this.has_extended_attribute("NoInterfaceObject")
+    && (typeof obj != expected_typeof || obj instanceof Object))
+    {
+        test(function()
+        {
+            assert_equals(exception, null, "Unexpected exception when evaluating object");
+            assert_equals(typeof obj, expected_typeof, "wrong typeof object");
+            assert_own_property(window, this.name,
+                                "window does not have own property " + format_value(this.name));
+            assert_own_property(window[this.name], "prototype",
+                                'interface "' + this.name + '" does not have own property "prototype"');
+
+            // "The value of the internal [[Prototype]] property of the
+            // platform object is the interface prototype object of the primary
+            // interface from the platform object’s associated global
+            // environment."
+            assert_equals(Object.getPrototypeOf(obj),
+                          window[this.name].prototype,
+                          desc + "'s prototype is not " + this.name + ".prototype");
+        }.bind(this), this.name + " must be primary interface of " + desc);
+    }
+
+    // "The class string of a platform object that implements one or more
+    // interfaces must be the identifier of the primary interface of the
+    // platform object."
+    test(function()
+    {
+        assert_equals(exception, null, "Unexpected exception when evaluating object");
+        assert_equals(typeof obj, expected_typeof, "wrong typeof object");
+        assert_class_string(obj, this.name, "class string of " + desc);
+        if (!this.has_stringifier())
+        {
+            assert_equals(String(obj), "[object " + this.name + "]", "String(" + desc + ")");
+        }
+    }.bind(this), "Stringification of " + desc);
+};
+
+//@}
+IdlInterface.prototype.test_interface_of = function(desc, obj, exception, expected_typeof)
+//@{
+{
+    // TODO: Indexed and named properties, more checks on interface members
+    this.already_tested = true;
+
+    for (var i = 0; i < this.members.length; i++)
+    {
+        var member = this.members[i];
+        if (member.has_extended_attribute("Unforgeable"))
+        {
+            test(function()
+            {
+                assert_equals(exception, null, "Unexpected exception when evaluating object");
+                assert_equals(typeof obj, expected_typeof, "wrong typeof object");
+                do_interface_attribute_asserts(obj, member);
+            }.bind(this), this.name + " interface: " + desc + ' must have own property "' + member.name + '"');
+        }
+        else if ((member.type == "const"
+        || member.type == "attribute"
+        || member.type == "operation")
+        && member.name)
+        {
+            test(function()
+            {
+                assert_equals(exception, null, "Unexpected exception when evaluating object");
+                assert_equals(typeof obj, expected_typeof, "wrong typeof object");
+                assert_inherits(obj, member.name);
+                if (member.type == "const")
+                {
+                    assert_equals(obj[member.name], constValue(member.value));
+                }
+                if (member.type == "attribute")
+                {
+                    // Attributes are accessor properties, so they might
+                    // legitimately throw an exception rather than returning
+                    // anything.
+                    var property, thrown = false;
+                    try
+                    {
+                        property = obj[member.name];
+                    }
+                    catch (e)
+                    {
+                        thrown = true;
+                    }
+                    if (!thrown)
+                    {
+                        this.array.assert_type_is(property, member.idlType);
+                    }
+                }
+                if (member.type == "operation")
+                {
+                    assert_equals(typeof obj[member.name], "function");
+                }
+            }.bind(this), this.name + " interface: " + desc + ' must inherit property "' + member.name + '" with the proper type (' + i + ')');
+        }
+        // TODO: This is wrong if there are multiple operations with the same
+        // identifier.
+        // TODO: Test passing arguments of the wrong type.
+        if (member.type == "operation" && member.name && member.arguments.length)
+        {
+            test(function()
+            {
+                assert_equals(exception, null, "Unexpected exception when evaluating object");
+                assert_equals(typeof obj, expected_typeof, "wrong typeof object");
+                assert_inherits(obj, member.name);
+                var args = [];
+                for (var i = 0; i < member.arguments.length; i++)
+                {
+                    if (member.arguments[i].optional)
+                    {
+                        break;
+                    }
+                    assert_throws(new TypeError(), function()
+                    {
+                        obj[member.name].apply(obj, args);
+                    }.bind(this), "Called with " + i + " arguments");
+
+                    args.push(create_suitable_object(member.arguments[i].idlType));
+                }
+            }.bind(this), this.name + " interface: calling " + member.name +
+            "(" + member.arguments.map(function(m) { return m.idlType.idlType; }) +
+            ") on " + desc + " with too few arguments must throw TypeError");
+        }
+    }
+};
+
+//@}
+IdlInterface.prototype.has_stringifier = function()
+//@{
+{
+    if (this.members.some(function(member) { return member.stringifier; })) {
+        return true;
+    }
+    if (this.base &&
+        this.array.members[this.base].has_stringifier()) {
+        return true;
+    }
+    return false;
+};
+
+//@}
+function do_interface_attribute_asserts(obj, member)
+//@{
+{
+    // "For each attribute defined on the interface, there must exist a
+    // corresponding property. If the attribute was declared with the
+    // [Unforgeable] extended attribute, then the property exists on every
+    // object that implements the interface.  Otherwise, it exists on the
+    // interface’s interface prototype object."
+    //
+    // This is called by test_self() with the prototype as obj, and by
+    // test_interface_of() with the object as obj.
+    assert_own_property(obj, member.name);
+
+    // "The property has attributes { [[Get]]: G, [[Set]]: S, [[Enumerable]]:
+    // true, [[Configurable]]: configurable }, where:
+    // "configurable is false if the attribute was declared with the
+    // [Unforgeable] extended attribute and true otherwise;
+    // "G is the attribute getter, defined below; and
+    // "S is the attribute setter, also defined below."
+    var desc = Object.getOwnPropertyDescriptor(obj, member.name);
+    assert_false("value" in desc, 'property descriptor has value but is supposed to be accessor');
+    assert_false("writable" in desc, 'property descriptor has "writable" field but is supposed to be accessor');
+    assert_true(desc.enumerable, "property is not enumerable");
+    if (member.has_extended_attribute("Unforgeable"))
+    {
+        assert_false(desc.configurable, "[Unforgeable] property must not be configurable");
+    }
+    else
+    {
+        assert_true(desc.configurable, "property must be configurable");
+    }
+
+    // "The attribute getter is a Function object whose behavior when invoked
+    // is as follows:
+    // "...
+    // "The value of the Function object’s “length” property is the Number
+    // value 0."
+    assert_equals(typeof desc.get, "function", "getter must be Function");
+    assert_equals(desc.get.length, 0, "getter length must be 0");
+    // TODO: Account for LenientThis
+    assert_throws(new TypeError(), function()
+    {
+        desc.get.call({});
+    }.bind(this), "calling getter on wrong object type must throw TypeError");
+
+    // TODO: Test calling setter on the interface prototype (should throw
+    // TypeError in most cases).
+    //
+    // "The attribute setter is undefined if the attribute is declared readonly
+    // and has neither a [PutForwards] nor a [Replaceable] extended attribute
+    // declared on it.  Otherwise, it is a Function object whose behavior when
+    // invoked is as follows:
+    // "...
+    // "The value of the Function object’s “length” property is the Number
+    // value 1."
+    if (member.readonly
+    && !member.has_extended_attribute("PutForwards")
+    && !member.has_extended_attribute("Replaceable"))
+    {
+        assert_equals(desc.set, undefined, "setter must be undefined for readonly attributes");
+    }
+    else
+    {
+        assert_equals(typeof desc.set, "function", "setter must be function for PutForwards, Replaceable, or non-readonly attributes");
+        assert_equals(desc.set.length, 1, "setter length must be 1");
+    }
+}
+//@}
+
+/// IdlInterfaceMember ///
+function IdlInterfaceMember(obj)
+//@{
+{
+    /**
+     * obj is an object produced by the WebIDLParser.js "ifMember" production.
+     * We just forward all properties to this object without modification,
+     * except for special extAttrs handling.
+     */
+    for (var k in obj)
+    {
+        this[k] = obj[k];
+    }
+    if (!("extAttrs" in this))
+    {
+        this.extAttrs = [];
+    }
+}
+
+//@}
+IdlInterfaceMember.prototype = Object.create(IdlObject.prototype);
+
+/// Internal helper functions ///
+function create_suitable_object(type)
+//@{
+{
+    /**
+     * type is an object produced by the WebIDLParser.js "type" production.  We
+     * return a JavaScript value that matches the type, if we can figure out
+     * how.
+     */
+    if (type.nullable)
+    {
+        return null;
+    }
+    switch (type.idlType)
+    {
+        case "any":
+        case "boolean":
+            return true;
+
+        case "byte": case "octet": case "short": case "unsigned short":
+        case "long": case "unsigned long": case "long long":
+        case "unsigned long long": case "float": case "double":
+            return 7;
+
+        case "DOMString":
+            return "foo";
+
+        case "object":
+            return {a: "b"};
+
+        case "Node":
+            return document.createTextNode("abc");
+    }
+    return null;
+}
+//@}
+
+/// IdlEnum ///
+// Used for IdlArray.prototype.assert_type_is
+function IdlEnum(obj)
+//@{
+{
+    /**
+     * obj is an object produced by the WebIDLParser.js "dictionary"
+     * production.
+     */
+
+    /** Self-explanatory. */
+    this.name = obj.name;
+
+    console.log("Name is " + this.name);
+
+    /** An array of values produced by the "enum" production. */
+    this.values = obj.values;
+
+}
+//@}
+
+IdlEnum.prototype = Object.create(IdlObject.prototype);
+
+IdlEnum.prototype.test = function()
+//@{
+{
+            test(function()
+            {
+		// NOTHING to test
+		return;
+	    });
+}
+//@}
+}());
+// vim: set expandtab shiftwidth=4 tabstop=4 foldmarker=@{,@} foldmethod=marker:

+ 136 - 0
Build/node_modules/usertiming/test-w3c/test_user_timing_clear_marks.htm

@@ -0,0 +1,136 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <meta charset="UTF-8" />
+        <title>window.performance User Timing clearMarks() method is working properly</title>
+        <link rel="author" title="Microsoft" href="http://www.microsoft.com/" />
+        <link rel="help" href="http://w3c-test.org/webperf/specs/UserTiming/#dom-performance-clearmarks"/>
+        <script src="testharness.js"></script>
+        <script src="testharnessreport.js"></script>
+        <script src="webperftestharness.js"></script>
+        
+        <script src="../src/usertiming.js"></script>
+
+    <script type="text/javascript">
+        // test marks
+        var markName1 = "mark1";
+        var markName2 = "mark2";
+        var markName3 = "markUndefined";
+        var markTestDelay = 200;
+        var entries;
+        var pass;
+        
+        setup({timeout:1000, explicit_done: true});
+        
+        test_namespace();
+    
+        function onload_test()
+        {
+            // test for existance of User Timing and Performance Timeline interface
+            if (window.performance.mark == undefined ||
+                window.performance.clearMarks == undefined ||
+                window.performance.measure == undefined ||
+                window.performance.clearMeasures == undefined ||
+                window.performance.getEntriesByName == undefined ||
+                window.performance.getEntriesByType == undefined ||
+                window.performance.getEntries == undefined)
+            {
+                test_true(false, 
+                          "The User Timing and Performance Timeline interfaces, which are required for this test, " + 
+                          "are defined.");
+                          
+                done();
+            }
+            else
+            {
+                // create a mark using the test delay; the mark's value should be equivalent to the loadEventStart 
+                // navigation timing attribute plus the test delay
+                setTimeout(mark_test_cb, markTestDelay);
+            }
+        }
+        
+        function mark_test_cb()
+        {
+            // create the test marks; only create "mark1" and "mark2", "markUndefined" is a non-existent mark
+            window.performance.mark(markName1);
+            window.performance.mark(markName2);
+            
+            // test that two marks have been created
+            entries = window.performance.getEntriesByType("mark");
+            test_equals(entries.length, 2, "Two marks have been created for this test.");
+
+            // clear non-existent mark
+            window.performance.clearMarks(markName3);
+                      
+            // test that "mark1" still exists
+            entries = window.performance.getEntriesByName(markName1);
+            test_true(entries[0].name == markName1, 
+                      "After a call to window.performance.clearMarks(\"" + markName3 + "\"), where \"" + markName3 +
+                      "\" is a non-existent mark, window.performance.getEntriesByName(\"" + markName1 + "\") " + 
+                      "returns an object containing the \"" + markName1 + "\" mark.");
+                      
+            // test that "mark2" still exists
+            entries = window.performance.getEntriesByName(markName2);
+            test_true(entries[0].name == markName2, 
+                      "After a call to window.performance.clearMarks(\"" + markName3 + "\"), where \"" + markName3 +
+                      "\" is a non-existent mark, window.performance.getEntriesByName(\"" + markName2 + "\") " + 
+                      "returns an object containing the \"" + markName2 + "\" mark.");
+            
+            // clear existent mark
+            window.performance.clearMarks(markName1);
+                      
+            // test that "mark1" was cleared
+            entries = window.performance.getEntriesByName(markName1);
+            pass = true;
+            for (var i in entries)
+            {
+                pass = false;
+            }
+            test_true(pass, 
+                      "After a call to window.performance.clearMarks(\"" + markName1 + "\"), " + 
+                      "window.performance.getEntriesByName(\"" + markName1 + "\") returns an empty object.");
+                      
+            // test that "mark2" still exists
+            entries = window.performance.getEntriesByName(markName2);
+            test_true(entries[0].name == markName2, 
+                      "After a call to window.performance.clearMarks(\"" + markName1 + "\"), " + 
+                      "window.performance.getEntriesByName(\"" + markName2 + "\") returns an object containing the " + 
+                      "\"" + markName2 + "\" mark.");
+                      
+            // clear all marks
+            window.performance.clearMarks();
+                      
+            // test that all marks were cleared
+            entries = window.performance.getEntriesByType("mark");
+            pass = true;
+            for (var i in entries)
+            {
+                pass = false;
+            }
+            test_true(pass, 
+                      "After a call to window.performance.clearMarks(), " + 
+                      "window.performance.getEntriesByType(\"mark\") returns an empty object.");
+            
+            done();
+        }
+    </script>
+    </head>
+    <body onload="onload_test();">
+        <h1>Description</h1>
+        <p>This test validates that the performance.clearMarks() method is working properly. This test creates the 
+           following marks to test this method:
+            <ul>
+                <li>"mark1"</li>
+                <li>"mark2"</li>
+            </ul>
+           After creating each mark, performance.clearMarks() is called three times. First, it is provided with a name
+           of "markUndefined", a non-existent mark, which shouldn't change the state of the Performance Timeline. Next, 
+           it is provided with a name of "mark2", after which, this mark should no longer be present in the Performance 
+           Timeline. Finally, performance.clearMarks() is called without any name provided. After this call, no marks 
+           should be present in the Performance Timeline. The state of the Performance Timeline is tested with the
+           performance.getEntriesByType() and performance.getEntries() methods.
+        </p>
+
+        <div id="log"></div>
+    </body>
+</html>

+ 138 - 0
Build/node_modules/usertiming/test-w3c/test_user_timing_clear_measures.htm

@@ -0,0 +1,138 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <meta charset="UTF-8" />
+        <title>window.performance User Timing clearMeasures() method is working properly</title>
+        <link rel="author" title="Microsoft" href="http://www.microsoft.com/" />
+        <link rel="help" href="http://w3c-test.org/webperf/specs/UserTiming/#dom-performance-clearmeasures"/>
+        <script src="testharness.js"></script>
+        <script src="testharnessreport.js"></script>
+        <script src="webperftestharness.js"></script>
+        
+        <script src="../src/usertiming.js"></script>
+
+    <script type="text/javascript">
+        // test measures
+        var measureName1 = "measure1";
+        var measureName2 = "measure2";
+        var measureName3 = "measureUndefined";
+        var measureTestDelay = 200;
+        var measureEntryNames;
+        var entries;
+        
+        setup({timeout:1000, explicit_done: true});
+        
+        test_namespace();
+    
+        function onload_test()
+        {
+            // test for existance of User Timing and Performance Timeline interface
+            if (window.performance.mark == undefined ||
+                window.performance.clearMarks == undefined ||
+                window.performance.measure == undefined ||
+                window.performance.clearMeasures == undefined ||
+                window.performance.getEntriesByName == undefined ||
+                window.performance.getEntriesByType == undefined ||
+                window.performance.getEntries == undefined)
+            {
+                test_true(false, 
+                          "The User Timing and Performance Timeline interfaces, which are required for this test, " + 
+                          "are defined.");
+                          
+                done();
+            }
+            else
+            {
+                // create measures using the test delay
+                setTimeout(measure_test_cb, measureTestDelay);
+            }
+        }
+        
+        function measure_test_cb()
+        {
+            // create the test measures; only create "measure1" and "measure2", "measureUndefined" is a non-existent
+            // measure; give "measure1" a startMark of "navigationStart" and "measure2" a startMark of 
+            // "responseEnd", this way, "measure1" always come first in a PerformanceEntryList returned from a 
+            // Performance Timeline accessor
+            window.performance.measure(measureName1, "navigationStart");
+            window.performance.measure(measureName2, "responseEnd");
+            
+            // test that two measures have been created
+            entries = window.performance.getEntriesByType("measure");
+            test_equals(entries.length, 2, "Two measures have been created for this test.");
+                      
+            // clear non-existent measure
+            window.performance.clearMeasures(measureName3);
+                      
+            // test that "measure1" still exists
+            entries = window.performance.getEntriesByName(measureName1);
+            test_true(entries[0].name == measureName1, 
+                      "After a call to window.performance.clearMeasures(\"" + measureName3 + "\"), where \"" + measureName3 +
+                      "\" is a non-existent measure, window.performance.getEntriesByName(\"" + measureName1 + "\") " + 
+                      "returns an object containing the \"" + measureName1 + "\" measure.");
+                      
+            // test that "measure2" still exists
+            entries = window.performance.getEntriesByName(measureName2);
+            test_true(entries[0].name == measureName2, 
+                      "After a call to window.performance.clearMeasures(\"" + measureName3 + "\"), where \"" + measureName3 +
+                      "\" is a non-existent measure, window.performance.getEntriesByName(\"" + measureName2 + "\") " + 
+                      "returns an object containing the \"" + measureName2 + "\" measure.");
+            
+            // clear existent measure
+            window.performance.clearMeasures(measureName1);
+                      
+            // test that "measure1" was cleared
+            entries = window.performance.getEntriesByName(measureName1);
+            pass = true;
+            for (var i in entries)
+            {
+                pass = false;
+            }
+            test_true(pass, 
+                      "After a call to window.performance.clearMeasures(\"" + measureName1 + "\"), " + 
+                      "window.performance.getEntriesByName(\"" + measureName1 + "\") returns an empty object.");
+                      
+            // test that "measure2" still exists
+            entries = window.performance.getEntriesByName(measureName2);
+            test_true(entries[0].name == measureName2, 
+                      "After a call to window.performance.clearMeasures(\"" + measureName1 + "\"), " + 
+                      "window.performance.getEntriesByName(\"" + measureName2 + "\") returns an object containing the " + 
+                      "\"" + measureName2 + "\" measure.");
+                      
+            // clear all measures
+            window.performance.clearMeasures();
+                      
+            // test that all measures were cleared
+            entries = window.performance.getEntriesByType("measure");
+            pass = true;
+            for (var i in entries)
+            {
+                pass = false;
+            }
+            test_true(pass, 
+                      "After a call to window.performance.clearMeasures(), " + 
+                      "window.performance.getEntriesByType(\"measure\") returns an empty object.");
+            
+            done();
+        }
+    </script>
+    </head>
+    <body onload="onload_test();">
+        <h1>Description</h1>
+        <p>This test validates that the performance.clearMeasures() method is working properly. This test creates the 
+           following measures to test this method:
+            <ul>
+                <li>"measure1"</li>
+                <li>"measure2"</li>
+            </ul>
+           After creating each measure, performance.clearMeasures() is called three times. First, it is provided with a 
+           name of "measureUndefined", a non-existent measure, which shouldn't change the state of the Performance 
+           Timeline. Next, it is provided with a name of "measure2", after which, this measure should no longer be 
+           present in the Performance Timeline. Finally, performance.clearMeasures() is called without any name 
+           provided. After this call, no measures should be present in the Performance Timeline. The state of the 
+           Performance Timeline is tested with the performance.getEntriesByType() and performance.getEntries() methods.
+        </p>
+
+        <div id="log"></div>
+    </body>
+</html>

+ 30 - 0
Build/node_modules/usertiming/test-w3c/test_user_timing_exists.htm

@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <meta charset="UTF-8" />
+        <title>window.performance User Timing exists</title>
+        <link rel="author" title="Microsoft" href="http://www.microsoft.com/" />
+        <link rel="help" href="http://w3c-test.org/webperf/specs/UserTiming/"/>
+        <script src="testharness.js"></script>
+        <script src="testharnessreport.js"></script>
+        <script src="webperftestharness.js"></script>
+        
+        <script src="../src/usertiming.js"></script>
+
+    </head>
+    <body>
+        <h1>Description</h1>
+        <p>This test validates that all of the methods used to interact with the User Timing API are defined.</p>
+
+        <div id="log"></div>
+
+        <script>
+        test_namespace();
+        
+        test_true(window.performance.mark !== undefined, "window.performance.mark is defined.");
+        test_true(window.performance.clearMarks !== undefined, "window.performance.clearMarks is defined.");
+        test_true(window.performance.measure !== undefined, "window.performance.measure is defined.");
+        test_true(window.performance.clearMeasures !== undefined, "window.performance.clearMeasures is defined.");
+        </script>
+    </body>
+</html>

+ 234 - 0
Build/node_modules/usertiming/test-w3c/test_user_timing_mark.htm

@@ -0,0 +1,234 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <meta charset="UTF-8" />
+        <title>window.performance User Timing mark() method is working properly</title>
+        <link rel="author" title="Microsoft" href="http://www.microsoft.com/" />
+        <link rel="help" href="http://w3c-test.org/webperf/specs/UserTiming/#dom-performance-mark"/>
+        <script src="testharness.js"></script>
+        <script src="testharnessreport.js"></script>
+        <script src="webperftestharness.js"></script>
+        
+        <script src="../src/usertiming.js"></script>
+
+    <script type="text/javascript">
+        // test data
+        var markTestDelay = 200;
+        var testThreshold = 50;
+        var marks;
+        
+        var TEST_MARKS =
+        [
+            {
+                name:                   "mark1",
+                expectedStartTime:      undefined,
+                entryMatch:             undefined
+            },
+            {
+                name:                   "mark1",
+                expectedStartTime:      undefined,
+                entryMatch:             undefined
+            }
+        ];
+        
+        setup({timeout:1000, explicit_done: true});
+        
+        test_namespace();
+    
+        function onload_test()
+        {
+            // test for existance of User Timing and Performance Timeline interface
+            if (window.performance.mark == undefined ||
+                window.performance.clearMarks == undefined ||
+                window.performance.measure == undefined ||
+                window.performance.clearMeasures == undefined ||
+                window.performance.getEntriesByName == undefined ||
+                window.performance.getEntriesByType == undefined ||
+                window.performance.getEntries == undefined)
+            {
+                test_true(false, 
+                          "The User Timing and Performance Timeline interfaces, which are required for this test, " + 
+                          "are defined.");
+                          
+                done();
+            }
+            else
+            {
+                // create first mark
+                window.performance.mark(TEST_MARKS[0].name);
+                
+                // record the time that this mark is created; this should correspond to the mark's startTime
+                TEST_MARKS[0].expectedStartTime = (new Date()) - window.performance.timing.navigationStart;
+            
+                // create the duplicate mark using the test delay; the duplicate mark's value should be equivalent to 
+                // the loadEventStart navigation timing attribute plus the test delay
+                setTimeout(mark_test_cb, markTestDelay);
+            }
+        }
+        
+        function mark_test_cb()
+        {
+            var getByNameScenarios = new Array();
+            
+            // create second, duplicate mark
+            window.performance.mark(TEST_MARKS[1].name);
+            
+            // record the time that this mark is created; this should correspond to the mark's startTime
+            TEST_MARKS[1].expectedStartTime = (new Date()) - window.performance.timing.navigationStart;
+        
+            // test the test marks are returned by getEntriesByName
+            entries = window.performance.getEntriesByName(TEST_MARKS[0].name);
+            test_mark(entries[0], 
+                      "window.performance.getEntriesByName(\"" + TEST_MARKS[0].name + "\")[0]",
+                      TEST_MARKS[0].name,
+                      TEST_MARKS[0].expectedStartTime);
+            TEST_MARKS[0].entryMatch = entries[0];
+            
+            test_mark(entries[1], 
+                      "window.performance.getEntriesByName(\"" + TEST_MARKS[1].name + "\")[1]",
+                      TEST_MARKS[1].name,
+                      TEST_MARKS[1].expectedStartTime);
+            TEST_MARKS[1].entryMatch = entries[1];
+                      
+            // test the test marks are returned by getEntriesByName with the entryType parameter provided
+            entries = window.performance.getEntriesByName(TEST_MARKS[0].name, "mark");
+            test_equals(entries[0].name, TEST_MARKS[0].name, 
+                        "window.performance.getEntriesByName(\"" + TEST_MARKS[0].name + "\", \"mark\") returns an " + 
+                        "object containing the \"" + TEST_MARKS[0].name + "\" mark in the correct order");
+                        
+            test_equals(entries[1].name, TEST_MARKS[1].name, 
+                        "window.performance.getEntriesByName(\"" + TEST_MARKS[1].name + "\", \"mark\") returns an " + 
+                        "object containing the duplicate \"" + TEST_MARKS[1].name + "\" mark in the correct order");
+                        
+            test_true(match_entries(entries[0], TEST_MARKS[0].entryMatch), 
+                      "The \"" + TEST_MARKS[0].name + "\" mark returned by " + 
+                      "window.performance.getEntriesByName(\"" + TEST_MARKS[0].name + "\", \"mark\") matches the " + 
+                      "the \"" + TEST_MARKS[0].name + "\" mark returned by " + 
+                      "window.performance.getEntriesByName(\"" + TEST_MARKS[0].name + "\")");
+                        
+            test_true(match_entries(entries[1], TEST_MARKS[1].entryMatch), 
+                      "The duplicate \"" + TEST_MARKS[1].name + "\" mark returned by " + 
+                      "window.performance.getEntriesByName(\"" + TEST_MARKS[1].name + "\", \"mark\") matches the " + 
+                      "the duplicate \"" + TEST_MARKS[1].name + "\" mark returned by " + 
+                      "window.performance.getEntriesByName(\"" + TEST_MARKS[1].name + "\")");
+            
+            // test the test marks are returned by getEntries
+            entries = get_test_entries(window.performance.getEntries(), "mark");
+            
+            test_equals(entries[0].name, TEST_MARKS[0].name, 
+                        "window.performance.getEntries() returns an object containing the original \"" + 
+                        TEST_MARKS[0].name + "\" mark in the correct order");
+                        
+            test_equals(entries[1].name, TEST_MARKS[1].name, 
+                        "window.performance.getEntries() returns an object containing the duplicate \"" + 
+                        TEST_MARKS[1].name + "\" mark in the correct order");
+                        
+            test_true(match_entries(entries[0], TEST_MARKS[0].entryMatch), 
+                      "The \"" + TEST_MARKS[0].name + "\" mark returned by " + 
+                      "window.performance.getEntries() matches the the \"" + TEST_MARKS[0].name + "\" mark returned " + 
+                      "by window.performance.getEntriesByName(\"" + TEST_MARKS[0].name + "\")");
+                      
+            test_true(match_entries(entries[1], TEST_MARKS[1].entryMatch), 
+                      "The \"" + TEST_MARKS[1].name + "\" mark returned by " + 
+                      "window.performance.getEntries() matches the the duplicate \"" + TEST_MARKS[1].name + "\" mark " +
+                      "returned by window.performance.getEntriesByName(\"" + TEST_MARKS[1].name + "\")");
+                      
+            // test the test marks are returned by getEntriesByType
+            entries = window.performance.getEntriesByType("mark");
+            
+            test_equals(entries[0].name, TEST_MARKS[0].name, 
+                        "window.performance.getEntriesByType(\"mark\") returns an object containing the original \"" + 
+                        TEST_MARKS[0].name + "\" mark in the correct order");
+                        
+            test_equals(entries[1].name, TEST_MARKS[1].name, 
+                        "window.performance.getEntriesByType(\"mark\") returns an object containing the duplicate \"" + 
+                        TEST_MARKS[1].name + "\" mark in the correct order");
+                        
+            test_true(match_entries(entries[0], TEST_MARKS[0].entryMatch), 
+                      "The \"" + TEST_MARKS[0].name + "\" mark returned by " + 
+                      "window.performance.getEntriesByType(\"mark\") matches the the \"" + TEST_MARKS[0].name + 
+                      "\" mark returned by window.performance.getEntriesByName(\"" + TEST_MARKS[0].name + "\")");
+                      
+            test_true(match_entries(entries[1], TEST_MARKS[1].entryMatch), 
+                      "The \"" + TEST_MARKS[1].name + "\" mark returned by " + 
+                      "window.performance.getEntriesByType(\"mark\") matches the the duplicate \"" + 
+                      TEST_MARKS[1].name + "\" mark returned by window.performance.getEntriesByName(\"" + 
+                      TEST_MARKS[1].name + "\")");
+            
+            done();
+        }
+        
+        function match_entries(entry1, entry2)
+        {
+            var pass = true;
+            
+            // match name
+            pass = pass && (entry1.name == entry2.name);
+            
+            // match startTime
+            pass = pass && (entry1.startTime == entry2.startTime);
+            
+            // match entryType
+            pass = pass && (entry1.entryType == entry2.entryType);
+            
+            // match duration
+            pass = pass && (entry1.duration == entry2.duration);
+            
+            return pass;
+        }
+        
+        function test_mark(markEntry, markEntryCommand, expectedName, expectedStartTime)
+        {
+            // test name
+            test_equals(markEntry.name, expectedName, markEntryCommand + ".name == \"" + expectedName + "\"");
+            
+            // test startTime, allow for an acceptable threshold in the difference between the startTime and the 
+            // expected value for the startTime (loadEventStart + markTestDelay)
+            test_true(Math.abs(markEntry.startTime - expectedStartTime) <= testThreshold, 
+                      markEntryCommand + ".startTime ~== " + expectedStartTime + " (up to " + testThreshold + 
+                      "ms difference allowed)");
+            
+            console.log("mes: " + markEntry.startTime);
+            console.log("es: " + expectedStartTime);
+            console.log("d: " + (markEntry.startTime - expectedStartTime));
+            
+            // verify entryType
+            test_equals(markEntry.entryType, "mark", markEntryCommand + ".entryType == \"mark\"");
+            
+            // verify duration
+            test_equals(markEntry.duration, 0, markEntryCommand + ".duration == 0");
+        }
+        
+        function get_test_entries(entryList, entryType)
+        {
+            var testEntries = new Array();
+        
+            // filter entryList
+            for (var i in entryList)
+            {
+                if (entryList[i].entryType == entryType)
+                {
+                    testEntries.push(entryList[i]);
+                }
+            }
+            
+            return testEntries;
+        }
+    </script>
+    </head>
+    <body onload="onload_test();">
+        <h1>Description</h1>
+        <p>This test validates that the performance.mark() method is working properly. This test creates the 
+           following marks to test this method:
+            <ul>
+                <li>"mark1": created using a normal mark() call</li>
+                <li>"mark1": duplicate of the first mark, used to confirm names can be re-used</li>
+            </ul>
+           After creating each mark, the existence of these marks is validated by calling 
+           performance.getEntriesByName() (both with and without the entryType parameter provided), 
+           performance.getEntriesByType(), and performance.getEntries()
+        </p>
+
+        <div id="log"></div>
+    </body>
+</html>

+ 107 - 0
Build/node_modules/usertiming/test-w3c/test_user_timing_mark_exceptions.htm

@@ -0,0 +1,107 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <meta charset="UTF-8" />
+        <title>window.performance User Timing mark() method is throwing the proper exceptions</title>
+        <link rel="author" title="Microsoft" href="http://www.microsoft.com/" />
+        <link rel="help" href="http://w3c-test.org/webperf/specs/UserTiming/#dom-performance-mark"/>
+        <script src="testharness.js"></script>
+        <script src="testharnessreport.js"></script>
+        <script src="webperftestharness.js"></script>
+        
+        <script src="../src/usertiming.js"></script>
+
+    <script type="text/javascript">
+        // navigation timing attributes
+        var timingAttributes = [
+            'connectEnd',
+            'connectStart',
+            'domComplete',
+            'domContentLoadedEventEnd',
+            'domContentLoadedEventStart',
+            'domInteractive',
+            'domLoading',
+            'domainLookupEnd',
+            'domainLookupStart',
+            'fetchStart',
+            'loadEventEnd',
+            'loadEventStart',
+            'navigationStart',
+            'redirectEnd',
+            'redirectStart',
+            'requestStart',
+            'responseEnd',
+            'responseStart',
+            'unloadEventEnd',
+            'unloadEventStart'
+        ];
+    
+        // test data
+        var markExceptionThrown = false;
+        
+        setup({timeout:1000, explicit_done: true});
+        
+        test_namespace();
+    
+        function onload_test()
+        {
+            // test for existance of User Timing and Performance Timeline interface
+            if (window.performance.mark == undefined ||
+                window.performance.clearMarks == undefined ||
+                window.performance.measure == undefined ||
+                window.performance.clearMeasures == undefined ||
+                window.performance.getEntriesByName == undefined ||
+                window.performance.getEntriesByType == undefined ||
+                window.performance.getEntries == undefined)
+            {
+                test_true(false, 
+                          "The User Timing and Performance Timeline interfaces, which are required for this test, " + 
+                          "are defined.");
+                          
+                done();
+            }
+            else
+            {
+                test_mark_exceptions();
+            }
+        }
+        
+        function test_mark_exceptions()
+        {
+            // loop through mark scenarios
+            for (var i in timingAttributes)
+            {
+                try
+                {
+                    // create the mark
+                    window.performance.mark(timingAttributes[i]);
+                    
+                    test_true(false, 
+                              "window.performance.mark(\"" + timingAttributes[i] + "\") threw an exception.");
+                }
+                catch(e)
+                {
+                    test_true(true, 
+                              "window.performance.mark(\"" + timingAttributes[i] + "\") threw an exception.");
+                
+                    // confirm that a SYNTAX_ERR exception is thrown and not any other exception
+                    test_equals(e.code, 
+                                e.SYNTAX_ERR,
+                                "window.performance.mark(\"" + timingAttributes[i] + "\") threw a SYNTAX_ERR " + 
+                                "exception.");
+                }
+            }
+            
+            done();
+        }
+    </script>
+    </head>
+    <body onload="onload_test();">
+        <h1>Description</h1>
+        <p>This test validates that the performance.mark() method throws a SYNTAX_ERR exception whenever a navigation
+           timing attribute is provided for the name parameter.
+        </p>
+
+        <div id="log"></div>
+    </body>
+</html>

+ 336 - 0
Build/node_modules/usertiming/test-w3c/test_user_timing_measure.htm

@@ -0,0 +1,336 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <meta charset="UTF-8" />
+        <title>window.performance User Timing measure() method is working properly</title>
+        <link rel="author" title="Microsoft" href="http://www.microsoft.com/" />
+        <link rel="help" href="http://w3c-test.org/webperf/specs/UserTiming/#dom-performance-measure"/>
+        <script src="testharness.js"></script>
+        <script src="testharnessreport.js"></script>
+        <script src="webperftestharness.js"></script>
+        
+        <script src="../src/usertiming.js"></script>
+
+    <script type="text/javascript">
+        // test data
+        var startMarkName = "mark_start";
+        var startMarkValue;
+        var endMarkName = "mark_end";
+        var endMarkValue;
+        var measures;
+        var testThreshold = 50;
+        
+        // test measures
+        var measureTestDelay = 200;
+        var TEST_MEASURES =
+        [
+            {
+                name:                   "measure_no_start_no_end",
+                startMark:              undefined,
+                endMark:                undefined,
+                startTime:              undefined,
+                duration:               undefined,
+                entryType:              "measure",
+                entryMatch:             undefined,
+                order:                  undefined,
+                found:                  false
+            },
+            {
+                name:                   "measure_start_no_end",
+                startMark:              "mark_start",
+                endMark:                undefined,
+                startTime:              undefined,
+                duration:               undefined,
+                entryType:              "measure",
+                entryMatch:             undefined,
+                order:                  undefined,
+                found:                  false
+            },
+            {
+                name:                   "measure_start_end",
+                startMark:              "mark_start",
+                endMark:                "mark_end",
+                startTime:              undefined,
+                duration:               undefined,
+                entryType:              "measure",
+                entryMatch:             undefined,
+                order:                  undefined,
+                found:                  false
+            },
+            {
+                name:                   "measure_no_start_no_end",
+                startMark:              undefined,
+                endMark:                undefined,
+                startTime:              undefined,
+                duration:               undefined,
+                entryType:              "measure",
+                entryMatch:             undefined,
+                order:                  undefined,
+                found:                  false
+            }
+        ];
+        
+        setup({timeout:1000, explicit_done: true});
+        
+        test_namespace();
+    
+        function onload_test()
+        {
+            // test for existance of User Timing and Performance Timeline interface
+            if (window.performance.mark == undefined ||
+                window.performance.clearMarks == undefined ||
+                window.performance.measure == undefined ||
+                window.performance.clearMeasures == undefined ||
+                window.performance.getEntriesByName == undefined ||
+                window.performance.getEntriesByType == undefined ||
+                window.performance.getEntries == undefined)
+            {
+                test_true(false, 
+                          "The User Timing and Performance Timeline interfaces, which are required for this test, " + 
+                          "are defined.");
+                          
+                done();
+            }
+            else
+            {
+                // create the start mark for the test measures
+                window.performance.mark(startMarkName);
+                
+                // get the start mark's value
+                startMarkValue = window.performance.getEntriesByName(startMarkName)[0].startTime;
+                
+                // create the test end mark using the test delay; this will allow for a significant difference between 
+                // the mark values that should be represented in the duration of measures using these marks
+                setTimeout(measure_test_cb, measureTestDelay);
+            }
+        }
+        
+        function measure_test_cb()
+        {
+            // create the end mark for the test measures
+            window.performance.mark(endMarkName);
+            
+            // get the end mark's value
+            endMarkValue = window.performance.getEntriesByName(endMarkName)[0].startTime;
+                      
+            // loop through all measure scenarios and create the corresponding measures
+            for (var i in TEST_MEASURES)
+            {
+                var scenario = TEST_MEASURES[i];
+                
+                if (scenario.startMark == undefined && scenario.endMark == undefined)
+                {
+                    // both startMark and endMark are undefined, don't provide either parameters
+                    window.performance.measure(scenario.name);
+                    
+                    // when startMark isn't provided to the measure() call, a DOMHighResTimeStamp corresponding 
+                    // to the navigationStart attribute with a timebase of the same attribute is used; this is 
+                    // equivalent to 0
+                    scenario.startTime = 0;
+                    
+                    // when endMark isn't provided to the measure() call, a DOMHighResTimeStamp corresponding to
+                    // the current time with a timebase of the navigationStart attribute is used
+                    scenario.duration = (new Date()) - window.performance.timing.navigationStart;
+                }
+                else if (scenario.startMark != undefined && scenario.endMark == undefined)
+                {
+                    // only startMark is defined, provide startMark and don't provide endMark
+                    window.performance.measure(scenario.name, scenario.startMark);
+                    
+                    // when startMark is provided to the measure() call, the value of the mark whose name is 
+                    // provided is used for the startMark
+                    scenario.startTime = startMarkValue;
+                    
+                    // when endMark isn't provided to the measure() call, a DOMHighResTimeStamp corresponding to
+                    // the current time with a timebase of the navigationStart attribute is used
+                    scenario.duration = ((new Date()) - window.performance.timing.navigationStart) - 
+                                                startMarkValue;
+                }
+                else if (scenario.startMark != undefined && scenario.endMark != undefined)
+                {
+                    // both startMark and endMark are defined, provide both parameters
+                    window.performance.measure(scenario.name, scenario.startMark, scenario.endMark);
+                    
+                    // when startMark is provided to the measure() call, the value of the mark whose name is 
+                    // provided is used for the startMark
+                    scenario.startTime = startMarkValue;
+                    
+                    // when endMark is provided to the measure() call, the value of the mark whose name is 
+                    // provided is used for the startMark
+                    scenario.duration = endMarkValue - startMarkValue;
+                }
+            }
+            
+            // test that expected measures are returned by getEntriesByName
+            for (var i in TEST_MEASURES)
+            {
+                entries = window.performance.getEntriesByName(TEST_MEASURES[i].name);
+                // for all test measures, the test will be validate the test measure against the first entry returned 
+                // by getEntriesByName(), except for the last measure, where since it is a duplicate measure, the test
+                // will validate it against the second entry returned by getEntriesByName()
+                test_measure(entries[(i == 3 ? 1 : 0)], 
+                            "window.performance.getEntriesByName(\"" + TEST_MEASURES[i].name + "\")[" + 
+                            (i == 3 ? 1 : 0) + "]",
+                            TEST_MEASURES[i].name,
+                            TEST_MEASURES[i].startTime,
+                            TEST_MEASURES[i].duration);
+                TEST_MEASURES[i].entryMatch = entries[(i == 3 ? 1 : 0)];
+            }
+            
+            // test that expected measures are returned by getEntriesByName with the entryType parameter provided
+            for (var i in TEST_MEASURES)
+            {
+                entries = window.performance.getEntriesByName(TEST_MEASURES[i].name, "measure");
+                
+                test_true(match_entries(entries[(i == 3 ? 1 : 0)], TEST_MEASURES[i].entryMatch), 
+                          "window.performance.getEntriesByName(\"" + TEST_MEASURES[i].name + "\", \"measure\")[" + 
+                          (i == 3 ? 1 : 0) + "] returns an object containing the \"" + TEST_MEASURES[i].name + 
+                          "\" measure in the correct order, and its value matches the \"" + TEST_MEASURES[i].name + 
+                          "\" measure returned by window.performance.getEntriesByName(\"" + TEST_MEASURES[i].name + 
+                          "\")");
+            }
+            
+            // test that expected measures are returned by getEntries
+            entries = get_test_entries(window.performance.getEntries(), "measure");
+            
+            test_measure_list(entries, "window.performance.getEntries()", TEST_MEASURES);
+            
+            // test that expected measures are returned by getEntriesByType
+            entries = window.performance.getEntriesByType("measure");
+            
+            test_measure_list(entries, "window.performance.getEntriesByType(\"measure\")", TEST_MEASURES);
+            
+            done();
+        }
+        
+        function match_entries(entry1, entry2, threshold)
+        {
+            if (threshold == undefined)
+            {
+                threshold = 0;
+            }
+            
+            var pass = true;
+            
+            // match name
+            pass = pass && (entry1.name == entry2.name);
+            
+            // match startTime
+            pass = pass && (Math.abs(entry1.startTime - entry2.startTime) <= testThreshold);
+            
+            // match entryType
+            pass = pass && (entry1.entryType == entry2.entryType);
+            
+            // match duration
+            pass = pass && (Math.abs(entry1.duration - entry2.duration) <= testThreshold);
+            
+            return pass;
+        }
+        
+        function test_measure(measureEntry, measureEntryCommand, expectedName, expectedStartTime, expectedDuration)
+        {
+            // test name
+            test_true(measureEntry.name == expectedName, measureEntryCommand + ".name == \"" + expectedName + "\"");
+            
+            // test startTime; since for a mark, the startTime is always equal to a mark's value or the value of a
+            // navigation timing attribute, the actual startTime should match the expected value exactly
+            test_true(Math.abs(measureEntry.startTime - expectedStartTime) == 0, 
+                      measureEntryCommand + ".startTime == " + expectedStartTime);
+            
+            // test entryType
+            test_true(measureEntry.entryType == "measure", measureEntryCommand + ".entryType == \"measure\"");
+            
+            // test duration, allow for an acceptable threshold in the difference between the actual duration and the 
+            // expected value for the duration
+            test_true(Math.abs(measureEntry.duration - expectedDuration) <= testThreshold, measureEntryCommand + 
+                      ".duration ~== " + expectedDuration + " (up to " + testThreshold + "ms difference allowed)");
+        }
+        
+        function test_measure_list(measureEntryList, measureEntryListCommand, measureScenarios)
+        {
+            // give all entries a "found" property that can be set to ensure it isn't tested twice
+            for (var i in measureEntryList)
+            {
+                measureEntryList[i].found = false;
+            }
+            
+            for (var i in measureScenarios)
+            {
+                measureScenarios[i].found = false;
+                
+                for (var j in measureEntryList)
+                {
+                    if (match_entries(measureEntryList[j], measureScenarios[i]) && !measureEntryList[j].found)
+                    {
+                        test_true(match_entries(measureEntryList[j], measureScenarios[i].entryMatch), 
+                                  measureEntryListCommand + " returns an object containing the \"" + 
+                                  measureScenarios[i].name + "\" measure, and it's value matches the measure " + 
+                                  "returned by window.performance.getEntriesByName(\"" + measureScenarios[i].name + 
+                                  "\")[" + (i == 3 ? 1 : 0) + "].");
+                                  
+                        measureEntryList[j].found = true;
+                        measureScenarios[i].found = true;
+                        break;
+                    }
+                }
+                
+                if (!measureScenarios[i].found)
+                {
+                    test_true(false, 
+                              measureEntryListCommand + " returns an object containing the \"" + 
+                              measureScenarios[i].name + "\" measure.");
+                }
+            }
+            
+            // verify order of output of getEntriesByType
+            var startTimeCurr = 0;
+            var pass = true;
+            for (var i in measureEntryList)
+            {
+                if (measureEntryList[i].startTime < startTimeCurr)
+                {
+                    pass = false;
+                }
+                startTimeCurr = measureEntryList[i].startTime;
+            }
+            test_true(pass, 
+                      measureEntryListCommand + " returns an object containing all test " + 
+                      "measures in order.");
+        }
+        
+        function get_test_entries(entryList, entryType)
+        {
+            var testEntries = new Array();
+        
+            // filter entryList
+            for (var i in entryList)
+            {
+                if (entryList[i].entryType == entryType)
+                {
+                    testEntries.push(entryList[i]);
+                }
+            }
+            
+            return testEntries;
+        }
+    </script>
+    </head>
+    <body onload="onload_test();">
+        <h1>Description</h1>
+        <p>This test validates that the performance.measure() method is working properly. This test creates the 
+           following measures to test this method:
+            <ul>
+                <li>"measure_no_start_no_end": created using a measure() call without a startMark or endMark 
+                    provided</li>
+                <li>"measure_start_no_end": created using a measure() call with only the startMark provided</li>
+                <li>"measure_start_end": created using a measure() call with both a startMark or endMark provided</li>
+                <li>"measure_no_start_no_end": duplicate of the first measure, used to confirm names can be re-used</li>
+            </ul>
+           After creating each measure, the existence of these measures is validated by calling 
+           performance.getEntriesByName() (both with and without the entryType parameter provided), 
+           performance.getEntriesByType(), and performance.getEntries()
+        </p>
+
+        <div id="log"></div>
+    </body>
+</html>

+ 284 - 0
Build/node_modules/usertiming/test-w3c/test_user_timing_measure_exceptions.htm

@@ -0,0 +1,284 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <meta charset="UTF-8" />
+        <title>window.performance User Timing measure() method is throwing the proper exceptions</title>
+        <link rel="author" title="Microsoft" href="http://www.microsoft.com/" />
+        <link rel="help" href="http://w3c-test.org/webperf/specs/UserTiming/#dom-performance-measure"/>
+        <script src="testharness.js"></script>
+        <script src="testharnessreport.js"></script>
+        <script src="webperftestharness.js"></script>
+        
+        <script src="../src/usertiming.js"></script>
+
+    <script type="text/javascript">
+        // navigation timing attributes
+        var timingAttributes = [
+            'connectEnd',
+            'connectStart',
+            'domComplete',
+            'domContentLoadedEventEnd',
+            'domContentLoadedEventStart',
+            'domInteractive',
+            'domLoading',
+            'domainLookupEnd',
+            'domainLookupStart',
+            'fetchStart',
+            'loadEventEnd',
+            'loadEventStart',
+            'navigationStart',
+            'redirectEnd',
+            'redirectStart',
+            'requestStart',
+            'responseEnd',
+            'responseStart',
+            'unloadEventEnd',
+            'unloadEventStart'
+        ];
+
+        // test data
+        var zeroedNavTimingAtt = undefined;
+        
+        setup({timeout:1000, explicit_done: true});
+        
+        test_namespace();
+    
+        function onload_test()
+        {
+            // test for existance of User Timing and Performance Timeline interface
+            if (window.performance.mark == undefined ||
+                window.performance.clearMarks == undefined ||
+                window.performance.measure == undefined ||
+                window.performance.clearMeasures == undefined ||
+                window.performance.getEntriesByName == undefined ||
+                window.performance.getEntriesByType == undefined ||
+                window.performance.getEntries == undefined)
+            {
+                test_true(false, 
+                          "The User Timing and Performance Timeline interfaces, which are required for this test, " + 
+                          "are defined.");
+                          
+                done();
+            }
+            else
+            {
+                test_measure_exceptions();
+            }
+        }
+        
+        function test_measure_exceptions()
+        {
+            // test scenarios for the SYNTAX_ERR exception
+            try
+            {
+                // create the measure
+                window.performance.measure("measure", "mark");
+                
+                test_true(false, 
+                          "window.performance.measure(\"measure\", \"mark\"), where \"mark\" is a non-existent mark, " +
+                          "threw an exception.");
+            }
+            catch(e)
+            {
+                test_true(true, 
+                          "window.performance.measure(\"measure\", \"mark\"), where \"mark\" is a non-existent mark, " +
+                          " threw an exception.");
+                
+                test_equals(e.code, 
+                            e.SYNTAX_ERR, 
+                            "window.performance.measure(\"measure\", \"mark\"), where \"mark\" is a non-existent " + 
+                            "mark, threw a SYNTAX_ERR exception.");
+            }
+            
+            try
+            {
+                // create the measure
+                window.performance.measure("measure", "mark", "responseEnd");
+                
+                test_true(false, 
+                          "window.performance.measure(\"measure\", \"mark\", \"responseEnd\"), where \"mark\" is a " + 
+                          "non-existent mark, threw an exception.");
+            }
+            catch(e)
+            {
+                test_true(true, 
+                          "window.performance.measure(\"measure\", \"mark\", \"responseEnd\"), where \"mark\" is a " + 
+                          "non-existent mark, threw an exception.");
+                
+                test_equals(e.code, 
+                            e.SYNTAX_ERR, 
+                            "window.performance.measure(\"measure\", \"mark\", \"responseEnd\"), where \"mark\" is a " +
+                            "non-existent mark, threw a SYNTAX_ERR exception.");
+            }
+            
+            try
+            {
+                // create the measure
+                window.performance.measure("measure", "navigationStart", "mark");
+                
+                test_true(false, 
+                          "window.performance.measure(\"measure\", \"navigationStart\", \"mark\"), where \"mark\" is " +
+                          "a non-existent mark, threw an exception.");
+            }
+            catch(e)
+            {
+                test_true(true, 
+                          "window.performance.measure(\"measure\", \"navigationStart\", \"mark\"), where \"mark\" is " +
+                          "a non-existent mark, threw an exception.");
+                
+                test_equals(e.code, 
+                            e.SYNTAX_ERR, 
+                            "window.performance.measure(\"measure\", \"navigationStart\", \"mark\"), where \"mark\" " +
+                            "is a non-existent mark, threw a SYNTAX_ERR exception.");
+            }
+            
+            try
+            {
+                // create the measure
+                window.performance.measure("measure", "mark", "mark");
+                
+                test_true(false, 
+                          "window.performance.measure(\"measure\", \"mark\", \"mark\"), where \"mark\" is a " + 
+                          "non-existent mark, threw an exception.");
+            }
+            catch(e)
+            {
+                test_true(true, 
+                          "window.performance.measure(\"measure\", \"mark\", \"mark\"), where \"mark\" is a " + 
+                          "non-existent mark, threw an exception.");
+                
+                test_equals(e.code, 
+                            e.SYNTAX_ERR, 
+                            "window.performance.measure(\"measure\", \"mark\", \"mark\"), where \"mark\" is a " + 
+                            "non-existent mark, threw a SYNTAX_ERR exception.");
+            }
+            
+            
+            // for testing the INVALID_ACCESS_ERR exception, find a navigation timing attribute with a value of zero
+            for (var i in timingAttributes)
+            {
+                if (window.performance.timing[timingAttributes[i]] == 0)
+                {
+                    zeroedNavTimingAtt = timingAttributes[i];
+                }
+            }
+            
+            if (zeroedNavTimingAtt == undefined)
+            {
+                test_true(false, 
+                          "A navigation timing attribute with a value of 0 was not found to test for the " + 
+                          "INVALID_ACCESS_ERR exception thrown by window.performance.measure().");
+            }
+            else
+            {
+                try
+                {
+                    // create the measure
+                    window.performance.measure("measure", zeroedNavTimingAtt);
+                    
+                    test_true(false, 
+                              "window.performance.measure(\"measure\", \"" + zeroedNavTimingAtt + "\"), where \"" + 
+                              zeroedNavTimingAtt + "\" is a navigation timing attribute with a value of 0, threw an " + 
+                              "exception.");
+                }
+                catch(e)
+                {
+                    test_true(true, 
+                              "window.performance.measure(\"measure\", \"" + zeroedNavTimingAtt + "\"), where \"" + 
+                              zeroedNavTimingAtt + "\" is a navigation timing attribute with a value of 0, threw an " + 
+                              "exception.");
+                    
+                    test_equals(e.code, 
+                                e.INVALID_ACCESS_ERR, 
+                                "window.performance.measure(\"measure\", \"" + zeroedNavTimingAtt + "\"), where \"" + 
+                                zeroedNavTimingAtt + "\" is a navigation timing attribute with a value of 0, threw " + 
+                                "an INVALID_ACCESS_ERR exception.");
+                }
+                
+                try
+                {
+                    // create the measure
+                    window.performance.measure("measure", zeroedNavTimingAtt, "responseEnd");
+                    
+                    test_true(false, 
+                              "window.performance.measure(\"measure\", \"" + zeroedNavTimingAtt + "\", " + 
+                              "\"responseEnd\"), where \"" + zeroedNavTimingAtt + "\" is a navigation timing " + 
+                              "attribute with a value of 0, threw an exception.");
+                }
+                catch(e)
+                {
+                    test_true(true, 
+                              "window.performance.measure(\"measure\", \"" + zeroedNavTimingAtt + "\", " + 
+                              "\"responseEnd\"), where \"" + zeroedNavTimingAtt + "\" is a navigation timing " + 
+                              "attribute with a value of 0, threw an exception.");
+                    
+                    test_equals(e.code, 
+                                e.INVALID_ACCESS_ERR, 
+                                "window.performance.measure(\"measure\", \"" + zeroedNavTimingAtt + "\", " + 
+                                "\"responseEnd\"), where \"" + zeroedNavTimingAtt + "\" is a navigation timing " + 
+                                "attribute with a value of 0, threw an INVALID_ACCESS_ERR exception.");
+                }
+                
+                try
+                {
+                    // create the measure
+                    window.performance.measure("measure", "navigationStart", zeroedNavTimingAtt);
+                    
+                    test_true(false, 
+                              "window.performance.measure(\"measure\", \"navigationStart\", \"" + zeroedNavTimingAtt + 
+                              "\"), where \"" + zeroedNavTimingAtt + "\" is a navigation timing attribute with a " + 
+                              "value of 0, threw an exception.");
+                }
+                catch(e)
+                {
+                    test_true(true, 
+                              "window.performance.measure(\"measure\", \"navigationStart\", \"" + zeroedNavTimingAtt + 
+                              "\"), where \"" + zeroedNavTimingAtt + "\" is a navigation timing attribute with a " + 
+                              "value of 0, threw an exception.");
+                    
+                    test_equals(e.code, 
+                                e.INVALID_ACCESS_ERR, 
+                                "window.performance.measure(\"measure\", \"navigationStart\", \"" + zeroedNavTimingAtt + 
+                                "\"), where \"" + zeroedNavTimingAtt + "\" is a navigation timing attribute with a " + 
+                                "value of 0, threw an INVALID_ACCESS_ERR exception.");
+                }
+                
+                try
+                {
+                    // create the measure
+                    window.performance.measure("measure", zeroedNavTimingAtt, zeroedNavTimingAtt);
+                    
+                    test_true(false, 
+                              "window.performance.measure(\"measure\", \"" + zeroedNavTimingAtt + "\", \"" + 
+                              zeroedNavTimingAtt + "\"), where \"" + zeroedNavTimingAtt + "\" is a navigation timing " +
+                              "attribute with a value of 0, threw an exception.");
+                }
+                catch(e)
+                {
+                    test_true(true, 
+                              "window.performance.measure(\"measure\", \"" + zeroedNavTimingAtt + "\", \"" + 
+                              zeroedNavTimingAtt + "\"), where \"" + zeroedNavTimingAtt + "\" is a navigation timing " +
+                              "attribute with a value of 0, threw an exception.");
+                    
+                    test_equals(e.code, 
+                                e.INVALID_ACCESS_ERR, 
+                                "window.performance.measure(\"measure\", \"" + zeroedNavTimingAtt + "\", \"" + 
+                                zeroedNavTimingAtt + "\"), where \"" + zeroedNavTimingAtt + "\" is a navigation " + 
+                                "timing attribute with a value of 0, threw an INVALID_ACCESS_ERR exception.");
+                }
+            }
+            
+            done();
+        }
+    </script>
+    </head>
+    <body onload="onload_test();">
+        <h1>Description</h1>
+        <p>This test validates that the performance.measure() method throws a SYNTAX_ERR exception whenever a 
+           non-existent mark is provided as the startMark or endMark, and the method also throws a INVALID_ACCESS_ERR
+           whenever a navigation timing attribute with a value of zero is provided as the startMark or endMark.
+        </p>
+
+        <div id="log"></div>
+    </body>
+</html>

+ 237 - 0
Build/node_modules/usertiming/test-w3c/test_user_timing_measure_navigation_timing.htm

@@ -0,0 +1,237 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <meta charset="UTF-8" />
+        <title>window.performance User Timing clearMeasures() method is working properly with navigation timing 
+               attributes</title>
+        <link rel="author" title="Microsoft" href="http://www.microsoft.com/" />
+        <link rel="help" href="http://w3c-test.org/webperf/specs/UserTiming/#dom-performance-measure"/>
+        <script src="testharness.js"></script>
+        <script src="testharnessreport.js"></script>
+        <script src="webperftestharness.js"></script>
+        
+        <script src="../src/usertiming.js"></script>
+
+    <script type="text/javascript">
+        // navigation timing attributes
+        var timingAttributes = [
+            'connectEnd',
+            'connectStart',
+            'domComplete',
+            'domContentLoadedEventEnd',
+            'domContentLoadedEventStart',
+            'domInteractive',
+            'domLoading',
+            'domainLookupEnd',
+            'domainLookupStart',
+            'fetchStart',
+            'loadEventEnd',
+            'loadEventStart',
+            'navigationStart',
+            'redirectEnd',
+            'redirectStart',
+            'requestStart',
+            'responseEnd',
+            'responseStart',
+            'unloadEventEnd',
+            'unloadEventStart'
+        ];
+    
+        // test data
+        var startMarkName = "mark_start";
+        var startMarkValue;
+        var endMarkName = "mark_end";
+        var endMarkValue;
+        var measures;
+        var testThreshold = 50;
+        
+        // test measures
+        measureTestDelay = 200;
+        var TEST_MEASURES =
+        [
+            {
+                name:                   "measure_nav_start_no_end",
+                startMark:              "navigationStart",
+                endMark:                undefined,
+                exceptionTestMessage:   "window.performance.measure(\"measure_nav_start_no_end\", " +
+                                        "\"navigationStart\") ran without throwing any exceptions.",
+                expectedStartTime:      undefined,
+                expectedDuration:       undefined,
+                entryMatch:             undefined
+            },
+            {
+                name:                   "measure_nav_start_mark_end",
+                startMark:              "navigationStart",
+                endMark:                "mark_end",
+                exceptionTestMessage:   "window.performance.measure(\"measure_nav_start_end\", \"navigationStart\", " + 
+                                        "\"mark_end\") ran without throwing any exceptions.",
+                expectedStartTime:      undefined,
+                expectedDuration:       undefined,
+                entryMatch:             undefined
+            },
+            {
+                name:                   "measure_mark_start_nav_end",
+                startMark:              "mark_start",
+                endMark:                "responseEnd",
+                exceptionTestMessage:   "window.performance.measure(\"measure_start_nav_end\", \"mark_start\", " +
+                                        "\"responseEnd\") ran without throwing any exceptions.",
+                expectedStartTime:      undefined,
+                expectedDuration:       undefined,
+                entryMatch:             undefined
+            },
+            {
+                name:                   "measure_nav_start_nav_end",
+                startMark:              "navigationStart",
+                endMark:                "responseEnd",
+                exceptionTestMessage:   "window.performance.measure(\"measure_nav_start_nav_end\", " + 
+                                        "\"navigationStart\", \"responseEnd\") ran without throwing any exceptions.",
+                expectedStartTime:      undefined,
+                expectedDuration:       undefined,
+                entryMatch:             undefined
+            }
+        ];
+        
+        setup({timeout:1000, explicit_done: true});
+        
+        test_namespace();
+    
+        function onload_test()
+        {
+            // test for existance of User Timing and Performance Timeline interface
+            if (window.performance.mark == undefined ||
+                window.performance.clearMarks == undefined ||
+                window.performance.measure == undefined ||
+                window.performance.clearMeasures == undefined ||
+                window.performance.getEntriesByName == undefined ||
+                window.performance.getEntriesByType == undefined ||
+                window.performance.getEntries == undefined)
+            {
+                test_true(false, 
+                          "The User Timing and Performance Timeline interfaces, which are required for this test, " + 
+                          "are defined.");
+                          
+                done();
+            }
+            else
+            {
+                // create the start mark for the test measures
+                window.performance.mark(startMarkName);
+                
+                // get the start mark's value
+                startMarkValue = window.performance.getEntriesByName(startMarkName)[0].startTime;
+                
+                // create the test end mark using the test delay; this will allow for a significant difference between 
+                // the mark values that should be represented in the duration of measures using these marks
+                setTimeout(measure_test_cb, measureTestDelay);
+            }
+        }
+        
+        function measure_test_cb()
+        {
+            // create the end mark for the test measures
+            window.performance.mark(endMarkName);
+            
+            // get the end mark's value
+            endMarkValue = window.performance.getEntriesByName(endMarkName)[0].startTime;
+            
+            // loop through measure scenarios
+            for (var i in TEST_MEASURES)
+            {
+                var scenario = TEST_MEASURES[i];
+                
+                if (scenario.startMark != undefined && scenario.endMark == undefined)
+                {
+                    // only startMark is defined, provide startMark and don't provide endMark
+                    window.performance.measure(scenario.name, scenario.startMark);
+                    
+                    // when startMark is provided to the measure() call, the value of the mark or navigation 
+                    // timing attribute whose name is provided is used for the startMark
+                    scenario.expectedStartTime = (timingAttributes.indexOf(scenario.startMark) != -1 ?
+                                                  window.performance.timing[scenario.startMark] - 
+                                                  window.performance.timing.navigationStart :
+                                                  startMarkValue);
+                    
+                    // when endMark isn't provided to the measure() call, a DOMHighResTimeStamp corresponding to
+                    // the current time with a timebase of the navigationStart attribute is used
+                    scenario.expectedDuration = ((new Date()) - window.performance.timing.navigationStart) - 
+                                                scenario.expectedStartTime;
+                }
+                else if (scenario.startMark != undefined && scenario.endMark != undefined)
+                {
+                    // both startMark and endMark are defined, provide both parameters
+                    window.performance.measure(scenario.name, scenario.startMark, scenario.endMark);
+                    
+                    // when startMark is provided to the measure() call, the value of the mark or navigation 
+                    // timing attribute whose name is provided is used for the startMark
+                    scenario.expectedStartTime = (timingAttributes.indexOf(scenario.startMark) != -1 ?
+                                                  window.performance.timing[scenario.startMark] - 
+                                                  window.performance.timing.navigationStart :
+                                                  startMarkValue);
+                    
+                    // when endMark is provided to the measure() call, the value of the mark whose name is 
+                    // provided is used for the startMark
+                    scenario.expectedDuration = (timingAttributes.indexOf(scenario.endMark) != -1 ?
+                                                 window.performance.timing[scenario.endMark] - 
+                                                 window.performance.timing.navigationStart :
+                                                 endMarkValue) - scenario.expectedStartTime;
+                }
+            }
+            
+            // test the test measures are returned by getEntriesByName
+            for (var i in TEST_MEASURES)
+            {
+                entries = window.performance.getEntriesByName(TEST_MEASURES[i].name);
+                test_measure(entries[0], 
+                            "window.performance.getEntriesByName(\"" + TEST_MEASURES[i].name + "\")[0]",
+                            TEST_MEASURES[i].name,
+                            TEST_MEASURES[i].expectedStartTime,
+                            TEST_MEASURES[i].expectedDuration);
+                TEST_MEASURES[i].entryMatch = entries[0];
+            }
+            
+            done();
+        }
+        
+        function test_measure(measureEntry, measureEntryCommand, expectedName, expectedStartTime, expectedDuration)
+        {
+            // test name
+            test_true(measureEntry.name == expectedName, measureEntryCommand + ".name == \"" + expectedName + "\"");
+            
+            // test startTime; since for a mark, the startTime is always equal to a mark's value or the value of a
+            // navigation timing attribute, the actual startTime should match the expected value exactly
+            test_true(Math.abs(measureEntry.startTime - expectedStartTime) == 0, 
+                      measureEntryCommand + ".startTime == " + expectedStartTime);
+            
+            // test entryType
+            test_true(measureEntry.entryType == "measure", measureEntryCommand + ".entryType == \"measure\"");
+            
+            console.log(measureEntry.duration, expectedDuration)
+            
+            // test duration, allow for an acceptable threshold in the difference between the actual duration and the 
+            // expected value for the duration
+            test_true(Math.abs(measureEntry.duration - expectedDuration) <= testThreshold, measureEntryCommand + 
+                      ".duration ~== " + expectedDuration + " (up to " + testThreshold + "ms difference allowed)");
+        }
+    </script>
+    </head>
+    <body onload="onload_test();">
+        <h1>Description</h1>
+        <p>This test validates that the performance.measure() method is working properly when navigation timing 
+           attributes are used in place of mark names. This test creates the following measures to test this method:
+            <ul>
+                <li>"measure_nav_start_no_end": created using a measure() call with a navigation timing attribute 
+                    provided as the startMark and nothing provided as the endMark</li>
+                <li>"measure_nav_start_mark_end": created using a measure() call with a navigation timing attribute 
+                    provided as the startMark and a mark name provided as the endMark</li>
+                <li>"measure_mark_start_nav_end": created using a measure() call with a mark name provided as the 
+                    startMark and a navigation timing attribute provided as the endMark</li>
+                <li>"measure_nav_start_nav_end":created using a measure() call with a navigation timing attribute 
+                    provided as both the startMark and endMark</li>
+            </ul>
+           After creating each measure, the existence of these measures is validated by calling 
+           performance.getEntriesByName() with each measure name
+        </p>
+
+        <div id="log"></div>
+    </body>
+</html>

+ 92 - 0
Build/node_modules/usertiming/test-w3c/testharness.css

@@ -0,0 +1,92 @@
+html {
+    font-family:DejaVu Sans, Bitstream Vera Sans, Arial, Sans;
+}
+
+#log .warning,
+#log .warning a {
+  color: black;
+  background: yellow;
+}
+
+#log .error,
+#log .error a {
+  color: white;
+  background: red;
+}
+
+#log pre {
+  border: 1px solid black;
+  padding: 1em;
+}
+
+section#summary {
+    margin-bottom:1em;
+}
+
+table#results {
+    border-collapse:collapse;
+    table-layout:fixed;
+    width:100%;
+}
+
+table#results th:first-child,
+table#results td:first-child {
+    width:4em;
+}
+
+table#results th:last-child,
+table#results td:last-child {
+    width:50%;
+}
+
+table#results.assertions th:last-child,
+table#results.assertions td:last-child {
+    width:35%;
+}
+
+table#results th {
+    padding:0;
+    padding-bottom:0.5em;
+    border-bottom:medium solid black;
+}
+
+table#results td {
+    padding:1em;
+    padding-bottom:0.5em;
+    border-bottom:thin solid black;
+}
+
+tr.pass > td:first-child {
+    color:green;
+}
+
+tr.fail > td:first-child {
+    color:red;
+}
+
+tr.timeout > td:first-child {
+    color:red;
+}
+
+tr.notrun > td:first-child {
+    color:blue;
+}
+
+.pass > td:first-child, .fail > td:first-child, .timeout > td:first-child, .notrun > td:first-child {
+    font-variant:small-caps;
+}
+
+table#results span {
+    display:block;
+}
+
+table#results span.expected {
+    font-family:DejaVu Sans Mono, Bitstream Vera Sans Mono, Monospace;
+    white-space:pre;
+}
+
+table#results span.actual {
+    font-family:DejaVu Sans Mono, Bitstream Vera Sans Mono, Monospace;
+    white-space:pre;
+}
+

+ 2233 - 0
Build/node_modules/usertiming/test-w3c/testharness.js

@@ -0,0 +1,2233 @@
+/*
+Distributed under both the W3C Test Suite License [1] and the W3C
+3-clause BSD License [2]. To contribute to a W3C Test Suite, see the
+policies and contribution forms [3].
+
+[1] http://www.w3.org/Consortium/Legal/2008/04-testsuite-license
+[2] http://www.w3.org/Consortium/Legal/2008/03-bsd-license
+[3] http://www.w3.org/2004/10/27-testcases
+*/
+
+/*
+ * == Introduction ==
+ *
+ * This file provides a framework for writing testcases. It is intended to
+ * provide a convenient API for making common assertions, and to work both
+ * for testing synchronous and asynchronous DOM features in a way that
+ * promotes clear, robust, tests.
+ *
+ * == Basic Usage ==
+ *
+ * To use this file, import the script and the testharnessreport script into
+ * the test document:
+ * <script src="/resources/testharness.js"></script>
+ * <script src="/resources/testharnessreport.js"></script>
+ *
+ * Within each file one may define one or more tests. Each test is atomic
+ * in the sense that a single test has a single result (pass/fail/timeout).
+ * Within each test one may have a number of asserts. The test fails at the
+ * first failing assert, and the remainder of the test is (typically) not run.
+ *
+ * If the file containing the tests is a HTML file with an element of id "log"
+ * this will be populated with a table containing the test results after all
+ * the tests have run.
+ *
+ * NOTE: By default tests must be created before the load event fires. For ways
+ *       to create tests after the load event, see "Determining when all tests
+ *       are complete", below
+ *
+ * == Synchronous Tests ==
+ *
+ * To create a synchronous test use the test() function:
+ *
+ * test(test_function, name, properties)
+ *
+ * test_function is a function that contains the code to test. For example a
+ * trivial passing test would be:
+ *
+ * test(function() {assert_true(true)}, "assert_true with true")
+ *
+ * The function passed in is run in the test() call.
+ *
+ * properties is an object that overrides default test properties. The
+ * recognised properties are:
+ *    timeout - the test timeout in ms
+ *
+ * e.g.
+ * test(test_function, "Sample test", {timeout:1000})
+ *
+ * would run test_function with a timeout of 1s.
+ *
+ * Additionally, test-specific metadata can be passed in the properties. These
+ * are used when the individual test has different metadata from that stored 
+ * in the <head>.
+ * The recognized metadata properties are:
+ *
+ *    help - The url of the part of the specification being tested
+ *
+ *    assert - A human readable description of what the test is attempting 
+ *             to prove
+ *
+ *    author - Name and contact information for the author of the test in the
+ *             format: "Name <email_addr>" or "Name http://contact/url"
+ *
+ * == Asynchronous Tests ==
+ *
+ * Testing asynchronous features is somewhat more complex since the result of
+ * a test may depend on one or more events or other callbacks. The API provided
+ * for testing these features is indended to be rather low-level but hopefully
+ * applicable to many situations.
+ *
+ * To create a test, one starts by getting a Test object using async_test:
+ *
+ * async_test(name, properties)
+ *
+ * e.g.
+ * var t = async_test("Simple async test")
+ *
+ * Assertions can be added to the test by calling the step method of the test
+ * object with a function containing the test assertions:
+ *
+ * t.step(function() {assert_true(true)});
+ *
+ * When all the steps are complete, the done() method must be called:
+ *
+ * t.done();
+ *
+ * As a convenience, async_test can also takes a function as first argument.
+ * This function is called with the test object as both its `this` object and
+ * first argument. The above example can be rewritten as:
+ *
+ * async_test(function(t) {
+ *     object.some_event = function() {
+ *         t.step(function (){assert_true(true); t.done();});
+ *     };
+ * }, "Simple async test");
+ *
+ * which avoids cluttering the global scope with references to async
+ * tests instances.
+ *
+ * The properties argument is identical to that for test().
+ *
+ * In many cases it is convenient to run a step in response to an event or a
+ * callback. A convenient method of doing this is through the step_func method
+ * which returns a function that, when called runs a test step. For example
+ *
+ * object.some_event = t.step_func(function(e) {assert_true(e.a)});
+ *
+ * == Making assertions ==
+ *
+ * Functions for making assertions start assert_
+ * The best way to get a list is to look in this file for functions names
+ * matching that pattern. The general signature is
+ *
+ * assert_something(actual, expected, description)
+ *
+ * although not all assertions precisely match this pattern e.g. assert_true
+ * only takes actual and description as arguments.
+ *
+ * The description parameter is used to present more useful error messages when
+ * a test fails
+ *
+ * NOTE: All asserts must be located in a test() or a step of an async_test().
+ *       asserts outside these places won't be detected correctly by the harness
+ *       and may cause a file to stop testing.
+ *
+ * == Setup ==
+ *
+ * Sometimes tests require non-trivial setup that may fail. For this purpose
+ * there is a setup() function, that may be called with one or two arguments.
+ * The two argument version is:
+ *
+ * setup(func, properties)
+ *
+ * The one argument versions may omit either argument.
+ * func is a function to be run synchronously. setup() becomes a no-op once
+ * any tests have returned results. Properties are global properties of the test
+ * harness. Currently recognised properties are:
+ *
+ * timeout - The time in ms after which the harness should stop waiting for
+ *           tests to complete (this is different to the per-test timeout
+ *           because async tests do not start their timer until .step is called)
+ *
+ * explicit_done - Wait for an explicit call to done() before declaring all
+ *                 tests complete (see below)
+ *
+ * output_document - The document to which results should be logged. By default
+ *                   this is the current document but could be an ancestor
+ *                   document in some cases e.g. a SVG test loaded in an HTML
+ *                   wrapper
+ *
+ * explicit_timeout - disable file timeout; only stop waiting for results
+ *                    when the timeout() function is called (typically for
+ *                    use when integrating with some existing test framework
+ *                    that has its own timeout mechanism).
+ *
+ * == Determining when all tests are complete ==
+ *
+ * By default the test harness will assume there are no more results to come
+ * when:
+ * 1) There are no Test objects that have been created but not completed
+ * 2) The load event on the document has fired
+ *
+ * This behaviour can be overridden by setting the explicit_done property to
+ * true in a call to setup(). If explicit_done is true, the test harness will
+ * not assume it is done until the global done() function is called. Once done()
+ * is called, the two conditions above apply like normal.
+ *
+ * == Generating tests ==
+ *
+ * NOTE: this functionality may be removed
+ *
+ * There are scenarios in which is is desirable to create a large number of
+ * (synchronous) tests that are internally similar but vary in the parameters
+ * used. To make this easier, the generate_tests function allows a single
+ * function to be called with each set of parameters in a list:
+ *
+ * generate_tests(test_function, parameter_lists, properties)
+ *
+ * For example:
+ *
+ * generate_tests(assert_equals, [
+ *     ["Sum one and one", 1+1, 2],
+ *     ["Sum one and zero", 1+0, 1]
+ *     ])
+ *
+ * Is equivalent to:
+ *
+ * test(function() {assert_equals(1+1, 2)}, "Sum one and one")
+ * test(function() {assert_equals(1+0, 1)}, "Sum one and zero")
+ *
+ * Note that the first item in each parameter list corresponds to the name of
+ * the test.
+ *
+ * The properties argument is identical to that for test(). This may be a 
+ * single object (used for all generated tests) or an array.
+ *
+ * == Callback API ==
+ *
+ * The framework provides callbacks corresponding to 3 events:
+ *
+ * start - happens when the first Test is created
+ * result - happens when a test result is recieved
+ * complete - happens when all results are recieved
+ *
+ * The page defining the tests may add callbacks for these events by calling
+ * the following methods:
+ *
+ *   add_start_callback(callback) - callback called with no arguments
+ *   add_result_callback(callback) - callback called with a test argument
+ *   add_completion_callback(callback) - callback called with an array of tests
+ *                                       and an status object
+ *
+ * tests have the following properties:
+ *   status: A status code. This can be compared to the PASS, FAIL, TIMEOUT and
+ *           NOTRUN properties on the test object
+ *   message: A message indicating the reason for failure. In the future this
+ *            will always be a string
+ *
+ *  The status object gives the overall status of the harness. It has the
+ *  following properties:
+ *    status: Can be compared to the OK, ERROR and TIMEOUT properties
+ *    message: An error message set when the status is ERROR
+ *
+ * == External API ==
+ *
+ * In order to collect the results of multiple pages containing tests, the test
+ * harness will, when loaded in a nested browsing context, attempt to call
+ * certain functions in each ancestor and opener browsing context:
+ *
+ * start - start_callback
+ * result - result_callback
+ * complete - completion_callback
+ *
+ * These are given the same arguments as the corresponding internal callbacks
+ * described above.
+ *
+ * == External API through cross-document messaging ==
+ *
+ * Where supported, the test harness will also send messages using
+ * cross-document messaging to each ancestor and opener browsing context. Since
+ * it uses the wildcard keyword (*), cross-origin communication is enabled and
+ * script on different origins can collect the results.
+ *
+ * This API follows similar conventions as those described above only slightly
+ * modified to accommodate message event API. Each message is sent by the harness
+ * is passed a single vanilla object, available as the `data` property of the
+ * event object. These objects are structures as follows:
+ *
+ * start - { type: "start" }
+ * result - { type: "result", test: Test }
+ * complete - { type: "complete", tests: [Test, ...], status: TestsStatus }
+ *
+ * == List of assertions ==
+ *
+ * assert_true(actual, description)
+ *   asserts that /actual/ is strictly true
+ *
+ * assert_false(actual, description)
+ *   asserts that /actual/ is strictly false
+ *
+ * assert_equals(actual, expected, description)
+ *   asserts that /actual/ is the same value as /expected/
+ *
+ * assert_not_equals(actual, expected, description)
+ *   asserts that /actual/ is a different value to /expected/. Yes, this means
+ *   that "expected" is a misnomer
+ *
+ * assert_in_array(actual, expected, description)
+ *   asserts that /expected/ is an Array, and /actual/ is equal to one of the
+ *   members -- expected.indexOf(actual) != -1
+ *
+ * assert_array_equals(actual, expected, description)
+ *   asserts that /actual/ and /expected/ have the same length and the value of
+ *   each indexed property in /actual/ is the strictly equal to the corresponding
+ *   property value in /expected/
+ *
+ * assert_approx_equals(actual, expected, epsilon, description)
+ *   asserts that /actual/ is a number within +/- /epsilon/ of /expected/
+ *
+ * assert_less_than(actual, expected, description)
+ *   asserts that /actual/ is a number less than /expected/
+ *
+ * assert_greater_than(actual, expected, description)
+ *   asserts that /actual/ is a number greater than /expected/
+ *
+ * assert_less_than_equal(actual, expected, description)
+ *   asserts that /actual/ is a number less than or equal to /expected/
+ *
+ * assert_greater_than_equal(actual, expected, description)
+ *   asserts that /actual/ is a number greater than or equal to /expected/
+ *
+ * assert_regexp_match(actual, expected, description)
+ *   asserts that /actual/ matches the regexp /expected/
+ *
+ * assert_class_string(object, class_name, description)
+ *   asserts that the class string of /object/ as returned in
+ *   Object.prototype.toString is equal to /class_name/.
+ *
+ * assert_own_property(object, property_name, description)
+ *   assert that object has own property property_name
+ *
+ * assert_inherits(object, property_name, description)
+ *   assert that object does not have an own property named property_name
+ *   but that property_name is present in the prototype chain for object
+ *
+ * assert_idl_attribute(object, attribute_name, description)
+ *   assert that an object that is an instance of some interface has the
+ *   attribute attribute_name following the conditions specified by WebIDL
+ *
+ * assert_readonly(object, property_name, description)
+ *   assert that property property_name on object is readonly
+ *
+ * assert_throws(code, func, description)
+ *   code - the expected exception:
+ *     o string: the thrown exception must be a DOMException with the given
+ *               name, e.g., "TimeoutError" (for compatibility with existing
+ *               tests, a constant is also supported, e.g., "TIMEOUT_ERR")
+ *     o object: the thrown exception must have a property called "name" that
+ *               matches code.name
+ *     o null:   allow any exception (in general, one of the options above
+ *               should be used)
+ *   func - a function that should throw
+ *
+ * assert_unreached(description)
+ *   asserts if called. Used to ensure that some codepath is *not* taken e.g.
+ *   an event does not fire.
+ *
+ * assert_any(assert_func, actual, expected_array, extra_arg_1, ... extra_arg_N)
+ *   asserts that one assert_func(actual, expected_array_N, extra_arg1, ..., extra_arg_N)
+ *   is true for some expected_array_N in expected_array. This only works for assert_func
+ *   with signature assert_func(actual, expected, args_1, ..., args_N). Note that tests
+ *   with multiple allowed pass conditions are bad practice unless the spec specifically
+ *   allows multiple behaviours. Test authors should not use this method simply to hide 
+ *   UA bugs.
+ *
+ * assert_exists(object, property_name, description)
+ *   *** deprecated ***
+ *   asserts that object has an own property property_name
+ *
+ * assert_not_exists(object, property_name, description)
+ *   *** deprecated ***
+ *   assert that object does not have own property property_name
+ */
+
+(function ()
+{
+    var debug = false;
+    // default timeout is 5 seconds, test can override if needed
+    var settings = {
+      output:true,
+      timeout:5000,
+      test_timeout:2000
+    };
+
+    var xhtml_ns = "http://www.w3.org/1999/xhtml";
+
+    // script_prefix is used by Output.prototype.show_results() to figure out
+    // where to get testharness.css from.  It's enclosed in an extra closure to
+    // not pollute the library's namespace with variables like "src".
+    var script_prefix = null;
+    (function ()
+    {
+        var scripts = document.getElementsByTagName("script");
+        for (var i = 0; i < scripts.length; i++)
+        {
+            if (scripts[i].src)
+            {
+                var src = scripts[i].src;
+            }
+            else if (scripts[i].href)
+            {
+                //SVG case
+                var src = scripts[i].href.baseVal;
+            }
+            if (src && src.slice(src.length - "testharness.js".length) === "testharness.js")
+            {
+                script_prefix = src.slice(0, src.length - "testharness.js".length);
+                break;
+            }
+        }
+    })();
+
+    /*
+     * API functions
+     */
+
+    var name_counter = 0;
+    function next_default_name()
+    {
+        //Don't use document.title to work around an Opera bug in XHTML documents
+        var prefix = document.getElementsByTagName("title").length > 0 ?
+                         document.getElementsByTagName("title")[0].firstChild.data :
+                         "Untitled";
+        var suffix = name_counter > 0 ? " " + name_counter : "";
+        name_counter++;
+        return prefix + suffix;
+    }
+
+    function test(func, name, properties)
+    {
+        var test_name = name ? name : next_default_name();
+        properties = properties ? properties : {};
+        var test_obj = new Test(test_name, properties);
+        test_obj.step(func);
+        if (test_obj.status === test_obj.NOTRUN) {
+            test_obj.done();
+        }
+    }
+
+    function async_test(func, name, properties)
+    {
+        if (typeof func !== "function") {
+            properties = name;
+            name = func;
+            func = null;
+        }
+        var test_name = name ? name : next_default_name();
+        properties = properties ? properties : {};
+        var test_obj = new Test(test_name, properties);
+        if (func) {
+            test_obj.step(func, test_obj, test_obj);
+        }
+        return test_obj;
+    }
+
+    function setup(func_or_properties, maybe_properties)
+    {
+        var func = null;
+        var properties = {};
+        if (arguments.length === 2) {
+            func = func_or_properties;
+            properties = maybe_properties;
+        } else if (func_or_properties instanceof Function){
+            func = func_or_properties;
+        } else {
+            properties = func_or_properties;
+        }
+        tests.setup(func, properties);
+        output.setup(properties);
+    }
+
+    function done() {
+        tests.end_wait();
+    }
+
+    function generate_tests(func, args, properties) {
+        forEach(args, function(x, i)
+                {
+                    var name = x[0];
+                    test(function()
+                         {
+                             func.apply(this, x.slice(1));
+                         }, 
+                         name, 
+                         Array.isArray(properties) ? properties[i] : properties);
+                });
+    }
+
+    function on_event(object, event, callback)
+    {
+      object.addEventListener(event, callback, false);
+    }
+
+    expose(test, 'test');
+    expose(async_test, 'async_test');
+    expose(generate_tests, 'generate_tests');
+    expose(setup, 'setup');
+    expose(done, 'done');
+    expose(on_event, 'on_event');
+
+    /*
+     * Return a string truncated to the given length, with ... added at the end
+     * if it was longer.
+     */
+    function truncate(s, len)
+    {
+        if (s.length > len) {
+            return s.substring(0, len - 3) + "...";
+        }
+        return s;
+    }
+
+    /*
+     * Convert a value to a nice, human-readable string
+     */
+    function format_value(val, seen)
+    {
+	if (!seen) {
+	    seen = [];
+        }
+        if (typeof val === "object" && val !== null)
+        {
+            if (seen.indexOf(val) >= 0)
+            {
+                return "[...]";
+            }
+	    seen.push(val);
+        }
+        if (Array.isArray(val))
+        {
+            return "[" + val.map(function(x) {return format_value(x, seen)}).join(", ") + "]";
+        }
+
+        switch (typeof val)
+        {
+        case "string":
+            val = val.replace("\\", "\\\\");
+            for (var i = 0; i < 32; i++)
+            {
+                var replace = "\\";
+                switch (i) {
+                case 0: replace += "0"; break;
+                case 1: replace += "x01"; break;
+                case 2: replace += "x02"; break;
+                case 3: replace += "x03"; break;
+                case 4: replace += "x04"; break;
+                case 5: replace += "x05"; break;
+                case 6: replace += "x06"; break;
+                case 7: replace += "x07"; break;
+                case 8: replace += "b"; break;
+                case 9: replace += "t"; break;
+                case 10: replace += "n"; break;
+                case 11: replace += "v"; break;
+                case 12: replace += "f"; break;
+                case 13: replace += "r"; break;
+                case 14: replace += "x0e"; break;
+                case 15: replace += "x0f"; break;
+                case 16: replace += "x10"; break;
+                case 17: replace += "x11"; break;
+                case 18: replace += "x12"; break;
+                case 19: replace += "x13"; break;
+                case 20: replace += "x14"; break;
+                case 21: replace += "x15"; break;
+                case 22: replace += "x16"; break;
+                case 23: replace += "x17"; break;
+                case 24: replace += "x18"; break;
+                case 25: replace += "x19"; break;
+                case 26: replace += "x1a"; break;
+                case 27: replace += "x1b"; break;
+                case 28: replace += "x1c"; break;
+                case 29: replace += "x1d"; break;
+                case 30: replace += "x1e"; break;
+                case 31: replace += "x1f"; break;
+                }
+                val = val.replace(RegExp(String.fromCharCode(i), "g"), replace);
+            }
+            return '"' + val.replace(/"/g, '\\"') + '"';
+        case "boolean":
+        case "undefined":
+            return String(val);
+        case "number":
+            // In JavaScript, -0 === 0 and String(-0) == "0", so we have to
+            // special-case.
+            if (val === -0 && 1/val === -Infinity)
+            {
+                return "-0";
+            }
+            return String(val);
+        case "object":
+            if (val === null)
+            {
+                return "null";
+            }
+
+            // Special-case Node objects, since those come up a lot in my tests.  I
+            // ignore namespaces.  I use duck-typing instead of instanceof, because
+            // instanceof doesn't work if the node is from another window (like an
+            // iframe's contentWindow):
+            // http://www.w3.org/Bugs/Public/show_bug.cgi?id=12295
+            if ("nodeType" in val
+            && "nodeName" in val
+            && "nodeValue" in val
+            && "childNodes" in val)
+            {
+                switch (val.nodeType)
+                {
+                case Node.ELEMENT_NODE:
+                    var ret = "<" + val.tagName.toLowerCase();
+                    for (var i = 0; i < val.attributes.length; i++)
+                    {
+                        ret += " " + val.attributes[i].name + '="' + val.attributes[i].value + '"';
+                    }
+                    ret += ">" + val.innerHTML + "</" + val.tagName.toLowerCase() + ">";
+                    return "Element node " + truncate(ret, 60);
+                case Node.TEXT_NODE:
+                    return 'Text node "' + truncate(val.data, 60) + '"';
+                case Node.PROCESSING_INSTRUCTION_NODE:
+                    return "ProcessingInstruction node with target " + format_value(truncate(val.target, 60)) + " and data " + format_value(truncate(val.data, 60));
+                case Node.COMMENT_NODE:
+                    return "Comment node <!--" + truncate(val.data, 60) + "-->";
+                case Node.DOCUMENT_NODE:
+                    return "Document node with " + val.childNodes.length + (val.childNodes.length == 1 ? " child" : " children");
+                case Node.DOCUMENT_TYPE_NODE:
+                    return "DocumentType node";
+                case Node.DOCUMENT_FRAGMENT_NODE:
+                    return "DocumentFragment node with " + val.childNodes.length + (val.childNodes.length == 1 ? " child" : " children");
+                default:
+                    return "Node object of unknown type";
+                }
+            }
+
+            // Fall through to default
+        default:
+            return typeof val + ' "' + truncate(String(val), 60) + '"';
+        }
+    }
+    expose(format_value, "format_value");
+
+    /*
+     * Assertions
+     */
+
+    function assert_true(actual, description)
+    {
+        assert(actual === true, "assert_true", description,
+                                "expected true got ${actual}", {actual:actual});
+    };
+    expose(assert_true, "assert_true");
+
+    function assert_false(actual, description)
+    {
+        assert(actual === false, "assert_false", description,
+                                 "expected false got ${actual}", {actual:actual});
+    };
+    expose(assert_false, "assert_false");
+
+    function same_value(x, y) {
+        if (y !== y)
+        {
+            //NaN case
+            return x !== x;
+        }
+        else if (x === 0 && y === 0) {
+            //Distinguish +0 and -0
+            return 1/x === 1/y;
+        }
+        else
+        {
+            //typical case
+            return x === y;
+        }
+    }
+
+    function assert_equals(actual, expected, description)
+    {
+         /*
+          * Test if two primitives are equal or two objects
+          * are the same object
+          */
+        if (typeof actual != typeof expected)
+        {
+            assert(false, "assert_equals", description,
+                          "expected (" + typeof expected + ") ${expected} but got (" + typeof actual + ") ${actual}",
+                          {expected:expected, actual:actual});
+            return;
+        }
+        assert(same_value(actual, expected), "assert_equals", description,
+                                             "expected ${expected} but got ${actual}",
+                                             {expected:expected, actual:actual});
+    };
+    expose(assert_equals, "assert_equals");
+
+    function assert_not_equals(actual, expected, description)
+    {
+         /*
+          * Test if two primitives are unequal or two objects
+          * are different objects
+          */
+        assert(!same_value(actual, expected), "assert_not_equals", description,
+                                              "got disallowed value ${actual}",
+                                              {actual:actual});
+    };
+    expose(assert_not_equals, "assert_not_equals");
+
+    function assert_in_array(actual, expected, description)
+    {
+        assert(expected.indexOf(actual) != -1, "assert_in_array", description,
+                                               "value ${actual} not in array ${expected}",
+                                               {actual:actual, expected:expected});
+    }
+    expose(assert_in_array, "assert_in_array");
+
+    function assert_object_equals(actual, expected, description)
+    {
+         //This needs to be improved a great deal
+         function check_equal(actual, expected, stack)
+         {
+             stack.push(actual);
+
+             var p;
+             for (p in actual)
+             {
+                 assert(expected.hasOwnProperty(p), "assert_object_equals", description,
+                                                    "unexpected property ${p}", {p:p});
+
+                 if (typeof actual[p] === "object" && actual[p] !== null)
+                 {
+                     if (stack.indexOf(actual[p]) === -1)
+                     {
+                         check_equal(actual[p], expected[p], stack);
+                     }
+                 }
+                 else
+                 {
+                     assert(same_value(actual[p], expected[p]), "assert_object_equals", description,
+                                                       "property ${p} expected ${expected} got ${actual}",
+                                                       {p:p, expected:expected, actual:actual});
+                 }
+             }
+             for (p in expected)
+             {
+                 assert(actual.hasOwnProperty(p),
+                        "assert_object_equals", description,
+                        "expected property ${p} missing", {p:p});
+             }
+             stack.pop();
+         }
+         check_equal(actual, expected, []);
+    };
+    expose(assert_object_equals, "assert_object_equals");
+
+    function assert_array_equals(actual, expected, description)
+    {
+        assert(actual.length === expected.length,
+               "assert_array_equals", description,
+               "lengths differ, expected ${expected} got ${actual}",
+               {expected:expected.length, actual:actual.length});
+
+        for (var i=0; i < actual.length; i++)
+        {
+            assert(actual.hasOwnProperty(i) === expected.hasOwnProperty(i),
+                   "assert_array_equals", description,
+                   "property ${i}, property expected to be $expected but was $actual",
+                   {i:i, expected:expected.hasOwnProperty(i) ? "present" : "missing",
+                   actual:actual.hasOwnProperty(i) ? "present" : "missing"});
+            assert(same_value(expected[i], actual[i]),
+                   "assert_array_equals", description,
+                   "property ${i}, expected ${expected} but got ${actual}",
+                   {i:i, expected:expected[i], actual:actual[i]});
+        }
+    }
+    expose(assert_array_equals, "assert_array_equals");
+
+    function assert_approx_equals(actual, expected, epsilon, description)
+    {
+        /*
+         * Test if two primitive numbers are equal withing +/- epsilon
+         */
+        assert(typeof actual === "number",
+               "assert_approx_equals", description,
+               "expected a number but got a ${type_actual}",
+               {type_actual:typeof actual});
+
+        assert(Math.abs(actual - expected) <= epsilon,
+               "assert_approx_equals", description,
+               "expected ${expected} +/- ${epsilon} but got ${actual}",
+               {expected:expected, actual:actual, epsilon:epsilon});
+    };
+    expose(assert_approx_equals, "assert_approx_equals");
+
+    function assert_less_than(actual, expected, description)
+    {
+        /*
+         * Test if a primitive number is less than another
+         */
+        assert(typeof actual === "number",
+               "assert_less_than", description,
+               "expected a number but got a ${type_actual}",
+               {type_actual:typeof actual});
+
+        assert(actual < expected,
+               "assert_less_than", description,
+               "expected a number less than ${expected} but got ${actual}",
+               {expected:expected, actual:actual});
+    };
+    expose(assert_less_than, "assert_less_than");
+
+    function assert_greater_than(actual, expected, description)
+    {
+        /*
+         * Test if a primitive number is greater than another
+         */
+        assert(typeof actual === "number",
+               "assert_greater_than", description,
+               "expected a number but got a ${type_actual}",
+               {type_actual:typeof actual});
+
+        assert(actual > expected,
+               "assert_greater_than", description,
+               "expected a number greater than ${expected} but got ${actual}",
+               {expected:expected, actual:actual});
+    };
+    expose(assert_greater_than, "assert_greater_than");
+
+    function assert_less_than_equal(actual, expected, description)
+    {
+        /*
+         * Test if a primitive number is less than or equal to another
+         */
+        assert(typeof actual === "number",
+               "assert_less_than_equal", description,
+               "expected a number but got a ${type_actual}",
+               {type_actual:typeof actual});
+
+        assert(actual <= expected,
+               "assert_less_than", description,
+               "expected a number less than or equal to ${expected} but got ${actual}",
+               {expected:expected, actual:actual});
+    };
+    expose(assert_less_than_equal, "assert_less_than_equal");
+
+    function assert_greater_than_equal(actual, expected, description)
+    {
+        /*
+         * Test if a primitive number is greater than or equal to another
+         */
+        assert(typeof actual === "number",
+               "assert_greater_than_equal", description,
+               "expected a number but got a ${type_actual}",
+               {type_actual:typeof actual});
+
+        assert(actual >= expected,
+               "assert_greater_than_equal", description,
+               "expected a number greater than or equal to ${expected} but got ${actual}",
+               {expected:expected, actual:actual});
+    };
+    expose(assert_greater_than_equal, "assert_greater_than_equal");
+
+    function assert_regexp_match(actual, expected, description) {
+        /*
+         * Test if a string (actual) matches a regexp (expected)
+         */
+        assert(expected.test(actual),
+               "assert_regexp_match", description,
+               "expected ${expected} but got ${actual}",
+               {expected:expected, actual:actual});
+    }
+    expose(assert_regexp_match, "assert_regexp_match");
+
+    function assert_class_string(object, class_string, description) {
+        assert_equals({}.toString.call(object), "[object " + class_string + "]",
+                      description);
+    }
+    expose(assert_class_string, "assert_class_string");
+
+
+    function _assert_own_property(name) {
+        return function(object, property_name, description)
+        {
+            assert(object.hasOwnProperty(property_name),
+                   name, description,
+                   "expected property ${p} missing", {p:property_name});
+        };
+    }
+    expose(_assert_own_property("assert_exists"), "assert_exists");
+    expose(_assert_own_property("assert_own_property"), "assert_own_property");
+
+    function assert_not_exists(object, property_name, description)
+    {
+        assert(!object.hasOwnProperty(property_name),
+               "assert_not_exists", description,
+               "unexpected property ${p} found", {p:property_name});
+    };
+    expose(assert_not_exists, "assert_not_exists");
+
+    function _assert_inherits(name) {
+        return function (object, property_name, description)
+        {
+            assert(typeof object === "object",
+                   name, description,
+                   "provided value is not an object");
+
+            assert("hasOwnProperty" in object,
+                   name, description,
+                   "provided value is an object but has no hasOwnProperty method");
+
+            assert(!object.hasOwnProperty(property_name),
+                   name, description,
+                   "property ${p} found on object expected in prototype chain",
+                   {p:property_name});
+
+            assert(property_name in object,
+                   name, description,
+                   "property ${p} not found in prototype chain",
+                   {p:property_name});
+        };
+    }
+    expose(_assert_inherits("assert_inherits"), "assert_inherits");
+    expose(_assert_inherits("assert_idl_attribute"), "assert_idl_attribute");
+
+    function assert_readonly(object, property_name, description)
+    {
+         var initial_value = object[property_name];
+         try {
+             //Note that this can have side effects in the case where
+             //the property has PutForwards
+             object[property_name] = initial_value + "a"; //XXX use some other value here?
+             assert(same_value(object[property_name], initial_value),
+                    "assert_readonly", description,
+                    "changing property ${p} succeeded",
+                    {p:property_name});
+         }
+         finally
+         {
+             object[property_name] = initial_value;
+         }
+    };
+    expose(assert_readonly, "assert_readonly");
+
+    function assert_throws(code, func, description)
+    {
+        try
+        {
+            func.call(this);
+            assert(false, "assert_throws", description,
+                   "${func} did not throw", {func:func});
+        }
+        catch(e)
+        {
+            if (e instanceof AssertionError) {
+                throw(e);
+            }
+            if (code === null)
+            {
+                return;
+            }
+            if (typeof code === "object")
+            {
+                assert(typeof e == "object" && "name" in e && e.name == code.name,
+                       "assert_throws", description,
+                       "${func} threw ${actual} (${actual_name}) expected ${expected} (${expected_name})",
+                                    {func:func, actual:e, actual_name:e.name,
+                                     expected:code,
+                                     expected_name:code.name});
+                return;
+            }
+
+            var code_name_map = {
+                INDEX_SIZE_ERR: 'IndexSizeError',
+                HIERARCHY_REQUEST_ERR: 'HierarchyRequestError',
+                WRONG_DOCUMENT_ERR: 'WrongDocumentError',
+                INVALID_CHARACTER_ERR: 'InvalidCharacterError',
+                NO_MODIFICATION_ALLOWED_ERR: 'NoModificationAllowedError',
+                NOT_FOUND_ERR: 'NotFoundError',
+                NOT_SUPPORTED_ERR: 'NotSupportedError',
+                INVALID_STATE_ERR: 'InvalidStateError',
+                SYNTAX_ERR: 'SyntaxError',
+                INVALID_MODIFICATION_ERR: 'InvalidModificationError',
+                NAMESPACE_ERR: 'NamespaceError',
+                INVALID_ACCESS_ERR: 'InvalidAccessError',
+                TYPE_MISMATCH_ERR: 'TypeMismatchError',
+                SECURITY_ERR: 'SecurityError',
+                NETWORK_ERR: 'NetworkError',
+                ABORT_ERR: 'AbortError',
+                URL_MISMATCH_ERR: 'URLMismatchError',
+                QUOTA_EXCEEDED_ERR: 'QuotaExceededError',
+                TIMEOUT_ERR: 'TimeoutError',
+                INVALID_NODE_TYPE_ERR: 'InvalidNodeTypeError',
+                DATA_CLONE_ERR: 'DataCloneError'
+            };
+
+            var name = code in code_name_map ? code_name_map[code] : code;
+
+            var name_code_map = {
+                IndexSizeError: 1,
+                HierarchyRequestError: 3,
+                WrongDocumentError: 4,
+                InvalidCharacterError: 5,
+                NoModificationAllowedError: 7,
+                NotFoundError: 8,
+                NotSupportedError: 9,
+                InvalidStateError: 11,
+                SyntaxError: 12,
+                InvalidModificationError: 13,
+                NamespaceError: 14,
+                InvalidAccessError: 15,
+                TypeMismatchError: 17,
+                SecurityError: 18,
+                NetworkError: 19,
+                AbortError: 20,
+                URLMismatchError: 21,
+                QuotaExceededError: 22,
+                TimeoutError: 23,
+                InvalidNodeTypeError: 24,
+                DataCloneError: 25,
+
+                UnknownError: 0,
+                ConstraintError: 0,
+                DataError: 0,
+                TransactionInactiveError: 0,
+                ReadOnlyError: 0,
+                VersionError: 0
+            };
+
+            if (!(name in name_code_map))
+            {
+                throw new AssertionError('Test bug: unrecognized DOMException code "' + code + '" passed to assert_throws()');
+            }
+
+            var required_props = { code: name_code_map[name] };
+
+            if (required_props.code === 0
+            || ("name" in e && e.name !== e.name.toUpperCase() && e.name !== "DOMException"))
+            {
+                // New style exception: also test the name property.
+                required_props.name = name;
+            }
+
+            //We'd like to test that e instanceof the appropriate interface,
+            //but we can't, because we don't know what window it was created
+            //in.  It might be an instanceof the appropriate interface on some
+            //unknown other window.  TODO: Work around this somehow?
+
+            assert(typeof e == "object",
+                   "assert_throws", description,
+                   "${func} threw ${e} with type ${type}, not an object",
+                   {func:func, e:e, type:typeof e});
+
+            for (var prop in required_props)
+            {
+                assert(typeof e == "object" && prop in e && e[prop] == required_props[prop],
+                       "assert_throws", description,
+                       "${func} threw ${e} that is not a DOMException " + code + ": property ${prop} is equal to ${actual}, expected ${expected}",
+                       {func:func, e:e, prop:prop, actual:e[prop], expected:required_props[prop]});
+            }
+        }
+    }
+    expose(assert_throws, "assert_throws");
+
+    function assert_unreached(description) {
+         assert(false, "assert_unreached", description,
+                "Reached unreachable code");
+    }
+    expose(assert_unreached, "assert_unreached");
+
+    function assert_any(assert_func, actual, expected_array) 
+    {
+        var args = [].slice.call(arguments, 3)
+        var errors = []
+        var passed = false;
+        forEach(expected_array, 
+                function(expected)
+                {
+                    try {
+                        assert_func.apply(this, [actual, expected].concat(args))
+                        passed = true;
+                    } catch(e) {
+                        errors.push(e.message);
+                    }
+                });
+        if (!passed) {
+            throw new AssertionError(errors.join("\n\n"));
+        }
+    }
+    expose(assert_any, "assert_any");
+
+    function Test(name, properties)
+    {
+        this.name = name;
+        this.status = this.NOTRUN;
+        this.timeout_id = null;
+        this.is_done = false;
+
+        this.properties = properties;
+        this.timeout_length = properties.timeout ? properties.timeout : settings.test_timeout;
+
+        this.message = null;
+
+        var this_obj = this;
+        this.steps = [];
+
+        tests.push(this);
+    }
+
+    Test.statuses = {
+        PASS:0,
+        FAIL:1,
+        TIMEOUT:2,
+        NOTRUN:3
+    };
+
+    Test.prototype = merge({}, Test.statuses);
+
+    Test.prototype.structured_clone = function()
+    {
+        if(!this._structured_clone)
+        {
+            var msg = this.message;
+            msg = msg ? String(msg) : msg;
+            this._structured_clone = merge({
+                name:String(this.name),
+                status:this.status,
+                message:msg
+            }, Test.statuses);
+        }
+        return this._structured_clone;
+    };
+
+    Test.prototype.step = function(func, this_obj)
+    {
+        //In case the test has already failed
+        if (this.status !== this.NOTRUN)
+        {
+          return;
+        }
+
+        tests.started = true;
+
+        if (this.timeout_id === null) {
+            this.set_timeout();
+        }
+
+        this.steps.push(func);
+
+        if (arguments.length === 1)
+        {
+            this_obj = this;
+        }
+
+        try
+        {
+            return func.apply(this_obj, Array.prototype.slice.call(arguments, 2));
+        }
+        catch(e)
+        {
+            //This can happen if something called synchronously invoked another
+            //step
+            if (this.status !== this.NOTRUN)
+            {
+                return;
+            }
+            this.status = this.FAIL;
+            this.message = (typeof e === "object" && e !== null) ? e.message : e;
+            if (typeof e.stack != "undefined" && typeof e.message == "string") {
+                //Try to make it more informative for some exceptions, at least
+                //in Gecko and WebKit.  This results in a stack dump instead of
+                //just errors like "Cannot read property 'parentNode' of null"
+                //or "root is null".  Makes it a lot longer, of course.
+                this.message += "(stack: " + e.stack + ")";
+            }
+            this.done();
+            if (debug && e.constructor !== AssertionError) {
+                throw e;
+            }
+        }
+    };
+
+    Test.prototype.step_func = function(func, this_obj)
+    {
+        var test_this = this;
+
+        if (arguments.length === 1)
+        {
+            this_obj = test_this;
+        }
+
+        return function()
+        {
+            test_this.step.apply(test_this, [func, this_obj].concat(
+                Array.prototype.slice.call(arguments)));
+        };
+    };
+
+    Test.prototype.step_func_done = function(func, this_obj)
+    {
+        var test_this = this;
+
+        if (arguments.length === 1)
+        {
+            this_obj = test_this;
+        }
+
+        return function()
+        {
+            test_this.step.apply(test_this, [func, this_obj].concat(
+                Array.prototype.slice.call(arguments)));
+            test_this.done();
+        };
+    };
+
+    Test.prototype.set_timeout = function()
+    {
+        var this_obj = this;
+        this.timeout_id = setTimeout(function()
+                                     {
+                                         this_obj.timeout();
+                                     }, this.timeout_length);
+    };
+
+    Test.prototype.timeout = function()
+    {
+        this.status = this.TIMEOUT;
+        this.timeout_id = null;
+        this.message = "Test timed out";
+        this.done();
+    };
+
+    Test.prototype.done = function()
+    {
+        if (this.is_done) {
+            return;
+        }
+        clearTimeout(this.timeout_id);
+        if (this.status === this.NOTRUN)
+        {
+            this.status = this.PASS;
+        }
+        this.is_done = true;
+        tests.result(this);
+    };
+
+
+    /*
+     * Harness
+     */
+
+    function TestsStatus()
+    {
+        this.status = null;
+        this.message = null;
+    }
+
+    TestsStatus.statuses = {
+        OK:0,
+        ERROR:1,
+        TIMEOUT:2
+    };
+
+    TestsStatus.prototype = merge({}, TestsStatus.statuses);
+
+    TestsStatus.prototype.structured_clone = function()
+    {
+        if(!this._structured_clone)
+        {
+            var msg = this.message;
+            msg = msg ? String(msg) : msg;
+            this._structured_clone = merge({
+                status:this.status,
+                message:msg
+            }, TestsStatus.statuses);
+        }
+        return this._structured_clone;
+    };
+
+    function Tests()
+    {
+        this.tests = [];
+        this.num_pending = 0;
+
+        this.phases = {
+            INITIAL:0,
+            SETUP:1,
+            HAVE_TESTS:2,
+            HAVE_RESULTS:3,
+            COMPLETE:4
+        };
+        this.phase = this.phases.INITIAL;
+
+        this.properties = {};
+
+        //All tests can't be done until the load event fires
+        this.all_loaded = false;
+        this.wait_for_finish = false;
+        this.processing_callbacks = false;
+
+        this.timeout_length = settings.timeout;
+        this.timeout_id = null;
+
+        this.start_callbacks = [];
+        this.test_done_callbacks = [];
+        this.all_done_callbacks = [];
+
+        this.status = new TestsStatus();
+
+        var this_obj = this;
+
+        on_event(window, "load",
+                 function()
+                 {
+                     this_obj.all_loaded = true;
+                     if (this_obj.all_done())
+                     {
+                         this_obj.complete();
+                     }
+                 });
+
+        this.set_timeout();
+    }
+
+    Tests.prototype.setup = function(func, properties)
+    {
+        if (this.phase >= this.phases.HAVE_RESULTS)
+        {
+            return;
+        }
+        if (this.phase < this.phases.SETUP)
+        {
+            this.phase = this.phases.SETUP;
+        }
+
+        for (var p in properties)
+        {
+            if (properties.hasOwnProperty(p))
+            {
+                this.properties[p] = properties[p];
+            }
+        }
+
+        if (properties.timeout)
+        {
+            this.timeout_length = properties.timeout;
+        }
+        if (properties.explicit_done)
+        {
+            this.wait_for_finish = true;
+        }
+        if (properties.explicit_timeout) {
+            this.timeout_length = null;
+        }
+
+        if (func)
+        {
+            try
+            {
+                func();
+            } catch(e)
+            {
+                this.status.status = this.status.ERROR;
+                this.status.message = e;
+            };
+        }
+        this.set_timeout();
+    };
+
+    Tests.prototype.set_timeout = function()
+    {
+        var this_obj = this;
+        clearTimeout(this.timeout_id);
+        if (this.timeout_length !== null)
+        {
+            this.timeout_id = setTimeout(function() {
+                                             this_obj.timeout();
+                                         }, this.timeout_length);
+        }
+    };
+
+    Tests.prototype.timeout = function() {
+        this.status.status = this.status.TIMEOUT;
+        this.complete();
+    };
+
+    Tests.prototype.end_wait = function()
+    {
+        this.wait_for_finish = false;
+        if (this.all_done()) {
+            this.complete();
+        }
+    };
+
+    Tests.prototype.push = function(test)
+    {
+        if (this.phase < this.phases.HAVE_TESTS) {
+            this.start();
+        }
+        this.num_pending++;
+        this.tests.push(test);
+    };
+
+    Tests.prototype.all_done = function() {
+        return (this.all_loaded && this.num_pending === 0 &&
+                !this.wait_for_finish && !this.processing_callbacks);
+    };
+
+    Tests.prototype.start = function() {
+        this.phase = this.phases.HAVE_TESTS;
+        this.notify_start();
+    };
+
+    Tests.prototype.notify_start = function() {
+        var this_obj = this;
+        forEach (this.start_callbacks,
+                 function(callback)
+                 {
+                     callback(this_obj.properties);
+                 });
+        forEach_windows(
+                function(w, is_same_origin)
+                {
+                    if(is_same_origin && w.start_callback)
+                    {
+                        try
+                        {
+                            w.start_callback(this_obj.properties);
+                        }
+                        catch(e)
+                        {
+                            if (debug)
+                            {
+                                throw(e);
+                            }
+                        }
+                    }
+                    if (supports_post_message(w) && w !== self)
+                    {
+                        w.postMessage({
+                            type: "start",
+                            properties: this_obj.properties
+                        }, "*");
+                    }
+                });
+    };
+
+    Tests.prototype.result = function(test)
+    {
+        if (this.phase > this.phases.HAVE_RESULTS)
+        {
+            return;
+        }
+        this.phase = this.phases.HAVE_RESULTS;
+        this.num_pending--;
+        this.notify_result(test);
+    };
+
+    Tests.prototype.notify_result = function(test) {
+        var this_obj = this;
+        this.processing_callbacks = true;
+        forEach(this.test_done_callbacks,
+                function(callback)
+                {
+                    callback(test, this_obj);
+                });
+
+        forEach_windows(
+                function(w, is_same_origin)
+                {
+                    if(is_same_origin && w.result_callback)
+                    {
+                        try
+                        {
+                            w.result_callback(test);
+                        }
+                        catch(e)
+                        {
+                            if(debug) {
+                                throw e;
+                            }
+                        }
+                    }
+                    if (supports_post_message(w) && w !== self)
+                    {
+                        w.postMessage({
+                            type: "result",
+                            test: test.structured_clone()
+                        }, "*");
+                    }
+                });
+        this.processing_callbacks = false;
+        if (this_obj.all_done())
+        {
+            this_obj.complete();
+        }
+    };
+
+    Tests.prototype.complete = function() {
+        if (this.phase === this.phases.COMPLETE) {
+            return;
+        }
+        this.phase = this.phases.COMPLETE;
+        var this_obj = this;
+        this.tests.forEach(
+            function(x)
+            {
+                if(x.status === x.NOTRUN)
+                {
+                    this_obj.notify_result(x);
+                }
+            }
+        );
+        this.notify_complete();
+    };
+
+    Tests.prototype.notify_complete = function()
+    {
+        clearTimeout(this.timeout_id);
+        var this_obj = this;
+        var tests = map(this_obj.tests,
+                        function(test)
+                        {
+                            return test.structured_clone();
+                        });
+        if (this.status.status === null)
+        {
+            this.status.status = this.status.OK;
+        }
+
+        forEach (this.all_done_callbacks,
+                 function(callback)
+                 {
+                     callback(this_obj.tests, this_obj.status);
+                 });
+
+        forEach_windows(
+                function(w, is_same_origin)
+                {
+                    if(is_same_origin && w.completion_callback)
+                    {
+                        try
+                        {
+                            w.completion_callback(this_obj.tests, this_obj.status);
+                        }
+                        catch(e)
+                        {
+                            if (debug)
+                            {
+                                throw e;
+                            }
+                        }
+                    }
+                    if (supports_post_message(w) && w !== self)
+                    {
+                        w.postMessage({
+                            type: "complete",
+                            tests: tests,
+                            status: this_obj.status.structured_clone()
+                        }, "*");
+                    }
+                });
+    };
+
+    var tests = new Tests();
+
+    function timeout() {
+        if (tests.timeout_length === null)
+        {
+            tests.timeout();
+        }
+    }
+    expose(timeout, 'timeout');
+
+    function add_start_callback(callback) {
+        tests.start_callbacks.push(callback);
+    }
+
+    function add_result_callback(callback)
+    {
+        tests.test_done_callbacks.push(callback);
+    }
+
+    function add_completion_callback(callback)
+    {
+       tests.all_done_callbacks.push(callback);
+    }
+
+    expose(add_start_callback, 'add_start_callback');
+    expose(add_result_callback, 'add_result_callback');
+    expose(add_completion_callback, 'add_completion_callback');
+
+    /*
+     * Output listener
+    */
+
+    function Output() {
+      this.output_document = document;
+      this.output_node = null;
+      this.done_count = 0;
+      this.enabled = settings.output;
+      this.phase = this.INITIAL;
+    }
+
+    Output.prototype.INITIAL = 0;
+    Output.prototype.STARTED = 1;
+    Output.prototype.HAVE_RESULTS = 2;
+    Output.prototype.COMPLETE = 3;
+
+    Output.prototype.setup = function(properties) {
+        if (this.phase > this.INITIAL) {
+            return;
+        }
+
+        //If output is disabled in testharnessreport.js the test shouldn't be
+        //able to override that
+        this.enabled = this.enabled && (properties.hasOwnProperty("output") ?
+                                        properties.output : settings.output);
+    };
+
+    Output.prototype.init = function(properties)
+    {
+        if (this.phase >= this.STARTED) {
+            return;
+        }
+        if (properties.output_document) {
+            this.output_document = properties.output_document;
+        } else {
+            this.output_document = document;
+        }
+        this.phase = this.STARTED;
+    };
+
+    Output.prototype.resolve_log = function()
+    {
+        var output_document;
+        if (typeof this.output_document === "function")
+        {
+            output_document = this.output_document.apply(undefined);
+        } else
+        {
+            output_document = this.output_document;
+        }
+        if (!output_document)
+        {
+            return;
+        }
+        var node = output_document.getElementById("log");
+        if (node)
+        {
+            this.output_document = output_document;
+            this.output_node = node;
+        }
+    };
+
+    Output.prototype.show_status = function(test)
+    {
+        if (this.phase < this.STARTED)
+        {
+            this.init();
+        }
+        if (!this.enabled)
+        {
+            return;
+        }
+        if (this.phase < this.HAVE_RESULTS)
+        {
+            this.resolve_log();
+            this.phase = this.HAVE_RESULTS;
+        }
+        this.done_count++;
+        if (this.output_node)
+        {
+            if (this.done_count < 100
+            || (this.done_count < 1000 && this.done_count % 100 == 0)
+            || this.done_count % 1000 == 0) {
+                this.output_node.textContent = "Running, "
+                    + this.done_count + " complete, "
+                    + tests.num_pending + " remain";
+            }
+        }
+    };
+
+    Output.prototype.show_results = function (tests, harness_status)
+    {
+        if (this.phase >= this.COMPLETE) {
+            return;
+        }
+        if (!this.enabled)
+        {
+            return;
+        }
+        if (!this.output_node) {
+            this.resolve_log();
+        }
+        this.phase = this.COMPLETE;
+
+        var log = this.output_node;
+        if (!log)
+        {
+            return;
+        }
+        var output_document = this.output_document;
+
+        while (log.lastChild)
+        {
+            log.removeChild(log.lastChild);
+        }
+
+        if (script_prefix != null) {
+            var stylesheet = output_document.createElementNS(xhtml_ns, "link");
+            stylesheet.setAttribute("rel", "stylesheet");
+            stylesheet.setAttribute("href", script_prefix + "testharness.css");
+            var heads = output_document.getElementsByTagName("head");
+            if (heads.length) {
+                heads[0].appendChild(stylesheet);
+            }
+        }
+
+        var status_text = {};
+        status_text[Test.prototype.PASS] = "Pass";
+        status_text[Test.prototype.FAIL] = "Fail";
+        status_text[Test.prototype.TIMEOUT] = "Timeout";
+        status_text[Test.prototype.NOTRUN] = "Not Run";
+
+        var status_number = {};
+        forEach(tests, function(test) {
+                    var status = status_text[test.status];
+                    if (status_number.hasOwnProperty(status))
+                    {
+                        status_number[status] += 1;
+                    } else {
+                        status_number[status] = 1;
+                    }
+                });
+
+        function status_class(status)
+        {
+            return status.replace(/\s/g, '').toLowerCase();
+        }
+
+        var summary_template = ["section", {"id":"summary"},
+                                ["h2", {}, "Summary"],
+                                ["p", {}, "Found ${num_tests} tests"],
+                                function(vars) {
+                                    var rv = [["div", {}]];
+                                    var i=0;
+                                    while (status_text.hasOwnProperty(i)) {
+                                        if (status_number.hasOwnProperty(status_text[i])) {
+                                            var status = status_text[i];
+                                            rv[0].push(["div", {"class":status_class(status)},
+                                                        ["label", {},
+                                                         ["input", {type:"checkbox", checked:"checked"}],
+                                                         status_number[status] + " " + status]]);
+                                        }
+                                        i++;
+                                    }
+                                    return rv;
+                                }];
+
+        log.appendChild(render(summary_template, {num_tests:tests.length}, output_document));
+
+        forEach(output_document.querySelectorAll("section#summary label"),
+                function(element)
+                {
+                    on_event(element, "click",
+                             function(e)
+                             {
+                                 if (output_document.getElementById("results") === null)
+                                 {
+                                     e.preventDefault();
+                                     return;
+                                 }
+                                 var result_class = element.parentNode.getAttribute("class");
+                                 var style_element = output_document.querySelector("style#hide-" + result_class);
+                                 var input_element = element.querySelector("input");
+                                 if (!style_element && !input_element.checked) {
+                                     style_element = output_document.createElementNS(xhtml_ns, "style");
+                                     style_element.id = "hide-" + result_class;
+                                     style_element.textContent = "table#results > tbody > tr."+result_class+"{display:none}";
+                                     output_document.body.appendChild(style_element);
+                                 } else if (style_element && input_element.checked) {
+                                     style_element.parentNode.removeChild(style_element);
+                                 }
+                             });
+                });
+
+        // This use of innerHTML plus manual escaping is not recommended in
+        // general, but is necessary here for performance.  Using textContent
+        // on each individual <td> adds tens of seconds of execution time for
+        // large test suites (tens of thousands of tests).
+        function escape_html(s)
+        {
+            return s.replace(/\&/g, "&amp;")
+                .replace(/</g, "&lt;")
+                .replace(/"/g, "&quot;")
+                .replace(/'/g, "&#39;");
+        }
+
+        function has_assertions()
+        {
+            for (var i = 0; i < tests.length; i++) {
+                if (tests[i].properties.hasOwnProperty("assert")) {
+                    return true;
+                }
+            }
+            return false;
+        }
+        
+        function get_assertion(test)
+        {
+            if (test.properties.hasOwnProperty("assert")) {
+                if (Array.isArray(test.properties.assert)) {
+                    return test.properties.assert.join(' ');
+                }
+                return test.properties.assert;
+            }
+            return '';
+        }
+        
+        log.appendChild(document.createElementNS(xhtml_ns, "section"));
+        var assertions = has_assertions();
+        var html = "<h2>Details</h2><table id='results' " + (assertions ? "class='assertions'" : "" ) + ">"
+            + "<thead><tr><th>Result</th><th>Test Name</th>"
+            + (assertions ? "<th>Assertion</th>" : "")
+            + "<th>Message</th></tr></thead>"
+            + "<tbody>";
+        for (var i = 0; i < tests.length; i++) {
+            html += '<tr class="'
+                + escape_html(status_class(status_text[tests[i].status]))
+                + '"><td>'
+                + escape_html(status_text[tests[i].status])
+                + "</td><td>"
+                + escape_html(tests[i].name)
+                + "</td><td>"
+                + (assertions ? escape_html(get_assertion(tests[i])) + "</td><td>" : "")
+                + escape_html(tests[i].message ? tests[i].message : " ")
+                + "</td></tr>";
+        }
+        html += "</tbody></table>";
+        try {
+            log.lastChild.innerHTML = html;
+        } catch (e) {
+            log.appendChild(document.createElementNS(xhtml_ns, "p"))
+               .textContent = "Setting innerHTML for the log threw an exception.";
+            log.appendChild(document.createElementNS(xhtml_ns, "pre"))
+               .textContent = html;
+        }
+    };
+
+    var output = new Output();
+    add_start_callback(function (properties) {output.init(properties);});
+    add_result_callback(function (test) {output.show_status(tests);});
+    add_completion_callback(function (tests, harness_status) {output.show_results(tests, harness_status);});
+
+    /*
+     * Template code
+     *
+     * A template is just a javascript structure. An element is represented as:
+     *
+     * [tag_name, {attr_name:attr_value}, child1, child2]
+     *
+     * the children can either be strings (which act like text nodes), other templates or
+     * functions (see below)
+     *
+     * A text node is represented as
+     *
+     * ["{text}", value]
+     *
+     * String values have a simple substitution syntax; ${foo} represents a variable foo.
+     *
+     * It is possible to embed logic in templates by using a function in a place where a
+     * node would usually go. The function must either return part of a template or null.
+     *
+     * In cases where a set of nodes are required as output rather than a single node
+     * with children it is possible to just use a list
+     * [node1, node2, node3]
+     *
+     * Usage:
+     *
+     * render(template, substitutions) - take a template and an object mapping
+     * variable names to parameters and return either a DOM node or a list of DOM nodes
+     *
+     * substitute(template, substitutions) - take a template and variable mapping object,
+     * make the variable substitutions and return the substituted template
+     *
+     */
+
+    function is_single_node(template)
+    {
+        return typeof template[0] === "string";
+    }
+
+    function substitute(template, substitutions)
+    {
+        if (typeof template === "function") {
+            var replacement = template(substitutions);
+            if (replacement)
+            {
+                var rv = substitute(replacement, substitutions);
+                return rv;
+            }
+            else
+            {
+                return null;
+            }
+        }
+        else if (is_single_node(template))
+        {
+            return substitute_single(template, substitutions);
+        }
+        else
+        {
+            return filter(map(template, function(x) {
+                                  return substitute(x, substitutions);
+                              }), function(x) {return x !== null;});
+        }
+    }
+
+    function substitute_single(template, substitutions)
+    {
+        var substitution_re = /\${([^ }]*)}/g;
+
+        function do_substitution(input) {
+            var components = input.split(substitution_re);
+            var rv = [];
+            for (var i=0; i<components.length; i+=2)
+            {
+                rv.push(components[i]);
+                if (components[i+1])
+                {
+                    rv.push(String(substitutions[components[i+1]]));
+                }
+            }
+            return rv;
+        }
+
+        var rv = [];
+        rv.push(do_substitution(String(template[0])).join(""));
+
+        if (template[0] === "{text}") {
+            substitute_children(template.slice(1), rv);
+        } else {
+            substitute_attrs(template[1], rv);
+            substitute_children(template.slice(2), rv);
+        }
+
+        function substitute_attrs(attrs, rv)
+        {
+            rv[1] = {};
+            for (var name in template[1])
+            {
+                if (attrs.hasOwnProperty(name))
+                {
+                    var new_name = do_substitution(name).join("");
+                    var new_value = do_substitution(attrs[name]).join("");
+                    rv[1][new_name] = new_value;
+                };
+            }
+        }
+
+        function substitute_children(children, rv)
+        {
+            for (var i=0; i<children.length; i++)
+            {
+                if (children[i] instanceof Object) {
+                    var replacement = substitute(children[i], substitutions);
+                    if (replacement !== null)
+                    {
+                        if (is_single_node(replacement))
+                        {
+                            rv.push(replacement);
+                        }
+                        else
+                        {
+                            extend(rv, replacement);
+                        }
+                    }
+                }
+                else
+                {
+                    extend(rv, do_substitution(String(children[i])));
+                }
+            }
+            return rv;
+        }
+
+        return rv;
+    }
+
+ function make_dom_single(template, doc)
+ {
+     var output_document = doc || document;
+     if (template[0] === "{text}")
+     {
+         var element = output_document.createTextNode("");
+         for (var i=1; i<template.length; i++)
+         {
+             element.data += template[i];
+         }
+     }
+     else
+     {
+         var element = output_document.createElementNS(xhtml_ns, template[0]);
+         for (var name in template[1]) {
+             if (template[1].hasOwnProperty(name))
+             {
+                 element.setAttribute(name, template[1][name]);
+             }
+         }
+         for (var i=2; i<template.length; i++)
+         {
+             if (template[i] instanceof Object)
+             {
+                 var sub_element = make_dom(template[i]);
+                 element.appendChild(sub_element);
+             }
+             else
+             {
+                 var text_node = output_document.createTextNode(template[i]);
+                 element.appendChild(text_node);
+             }
+         }
+     }
+
+     return element;
+ }
+
+
+
+ function make_dom(template, substitutions, output_document)
+    {
+        if (is_single_node(template))
+        {
+            return make_dom_single(template, output_document);
+        }
+        else
+        {
+            return map(template, function(x) {
+                           return make_dom_single(x, output_document);
+                       });
+        }
+    }
+
+ function render(template, substitutions, output_document)
+    {
+        return make_dom(substitute(template, substitutions), output_document);
+    }
+
+    /*
+     * Utility funcions
+     */
+    function assert(expected_true, function_name, description, error, substitutions)
+    {
+        if (expected_true !== true)
+        {
+            throw new AssertionError(make_message(function_name, description,
+                                                  error, substitutions));
+        }
+    }
+
+    function AssertionError(message)
+    {
+        this.message = message;
+    }
+
+    function make_message(function_name, description, error, substitutions)
+    {
+        for (var p in substitutions) {
+            if (substitutions.hasOwnProperty(p)) {
+                substitutions[p] = format_value(substitutions[p]);
+            }
+        }
+        var node_form = substitute(["{text}", "${function_name}: ${description}" + error],
+                                   merge({function_name:function_name,
+                                          description:(description?description + " ":"")},
+                                          substitutions));
+        return node_form.slice(1).join("");
+    }
+
+    function filter(array, callable, thisObj) {
+        var rv = [];
+        for (var i=0; i<array.length; i++)
+        {
+            if (array.hasOwnProperty(i))
+            {
+                var pass = callable.call(thisObj, array[i], i, array);
+                if (pass) {
+                    rv.push(array[i]);
+                }
+            }
+        }
+        return rv;
+    }
+
+    function map(array, callable, thisObj)
+    {
+        var rv = [];
+        rv.length = array.length;
+        for (var i=0; i<array.length; i++)
+        {
+            if (array.hasOwnProperty(i))
+            {
+                rv[i] = callable.call(thisObj, array[i], i, array);
+            }
+        }
+        return rv;
+    }
+
+    function extend(array, items)
+    {
+        Array.prototype.push.apply(array, items);
+    }
+
+    function forEach (array, callback, thisObj)
+    {
+        for (var i=0; i<array.length; i++)
+        {
+            if (array.hasOwnProperty(i))
+            {
+                callback.call(thisObj, array[i], i, array);
+            }
+        }
+    }
+
+    function merge(a,b)
+    {
+        var rv = {};
+        var p;
+        for (p in a)
+        {
+            rv[p] = a[p];
+        }
+        for (p in b) {
+            rv[p] = b[p];
+        }
+        return rv;
+    }
+
+    function expose(object, name)
+    {
+        var components = name.split(".");
+        var target = window;
+        for (var i=0; i<components.length - 1; i++)
+        {
+            if (!(components[i] in target))
+            {
+                target[components[i]] = {};
+            }
+            target = target[components[i]];
+        }
+        target[components[components.length - 1]] = object;
+    }
+
+    function forEach_windows(callback) {
+        // Iterate of the the windows [self ... top, opener]. The callback is passed
+        // two objects, the first one is the windows object itself, the second one
+        // is a boolean indicating whether or not its on the same origin as the
+        // current window.
+        var cache = forEach_windows.result_cache;
+        if (!cache) {
+            cache = [[self, true]];
+            var w = self;
+            var i = 0;
+            var so;
+            var origins = location.ancestorOrigins;
+            while (w != w.parent)
+            {
+                w = w.parent;
+                // In WebKit, calls to parent windows' properties that aren't on the same
+                // origin cause an error message to be displayed in the error console but
+                // don't throw an exception. This is a deviation from the current HTML5
+                // spec. See: https://bugs.webkit.org/show_bug.cgi?id=43504
+                // The problem with WebKit's behavior is that it pollutes the error console
+                // with error messages that can't be caught.
+                //
+                // This issue can be mitigated by relying on the (for now) proprietary
+                // `location.ancestorOrigins` property which returns an ordered list of
+                // the origins of enclosing windows. See:
+                // http://trac.webkit.org/changeset/113945.
+                if(origins) {
+                    so = (location.origin == origins[i]);
+                }
+                else
+                {
+                    so = is_same_origin(w);
+                }
+                cache.push([w, so]);
+                i++;
+            }
+            w = window.opener;
+            if(w)
+            {
+                // window.opener isn't included in the `location.ancestorOrigins` prop.
+                // We'll just have to deal with a simple check and an error msg on WebKit
+                // browsers in this case.
+                cache.push([w, is_same_origin(w)]);
+            }
+            forEach_windows.result_cache = cache;
+        }
+
+        forEach(cache,
+                function(a)
+                {
+                    callback.apply(null, a);
+                });
+    }
+
+    function is_same_origin(w) {
+        try {
+            'random_prop' in w;
+            return true;
+        } catch(e) {
+            return false;
+        }
+    }
+
+    function supports_post_message(w)
+    {
+        var supports;
+        var type;
+        // Given IE  implements postMessage across nested iframes but not across
+        // windows or tabs, you can't infer cross-origin communication from the presence
+        // of postMessage on the current window object only.
+        //
+        // Touching the postMessage prop on a window can throw if the window is
+        // not from the same origin AND post message is not supported in that
+        // browser. So just doing an existence test here won't do, you also need
+        // to wrap it in a try..cacth block.
+        try
+        {
+            type = typeof w.postMessage;
+            if (type === "function")
+            {
+                supports = true;
+            }
+            // IE8 supports postMessage, but implements it as a host object which
+            // returns "object" as its `typeof`.
+            else if (type === "object")
+            {
+                supports = true;
+            }
+            // This is the case where postMessage isn't supported AND accessing a
+            // window property across origins does NOT throw (e.g. old Safari browser).
+            else
+            {
+                supports = false;
+            }
+        }
+        catch(e) {
+            // This is the case where postMessage isn't supported AND accessing a
+            // window property across origins throws (e.g. old Firefox browser).
+            supports = false;
+        }
+        return supports;
+    }
+})();
+// vim: set expandtab shiftwidth=4 tabstop=4:

+ 380 - 0
Build/node_modules/usertiming/test-w3c/testharnessreport.js

@@ -0,0 +1,380 @@
+/*
+ * This file is intended for vendors to implement
+ * code needed to integrate testharness.js tests with their own test systems.
+ *
+ * The default implementation extracts metadata from the tests and validates 
+ * it against the cached version that should be present in the test source 
+ * file. If the cache is not found or is out of sync, source code suitable for
+ * caching the metadata is optionally generated.
+ *
+ * The cached metadata is present for extraction by test processing tools that
+ * are unable to execute javascript.
+ *
+ * Metadata is attached to tests via the properties parameter in the test
+ * constructor. See testharness.js for details.
+ *
+ * Typically test system integration will attach callbacks when each test has
+ * run, using add_result_callback(callback(test)), or when the whole test file
+ * has completed, using 
+ * add_completion_callback(callback(tests, harness_status)).
+ *
+ * For more documentation about the callback functions and the
+ * parameters they are called with see testharness.js
+ */
+
+
+
+var metadata_generator = {
+
+    currentMetadata: {},
+    cachedMetadata: false,
+    metadataProperties: ['help', 'assert', 'author'],
+    
+    error: function(message) {
+        var messageElement = document.createElement('p');
+        messageElement.setAttribute('class', 'error');
+        this.appendText(messageElement, message);
+        
+        var summary = document.getElementById('summary');
+        if (summary) {
+            summary.parentNode.insertBefore(messageElement, summary);
+        }
+        else {
+            document.body.appendChild(messageElement);
+        }
+    },
+
+    /**
+     * Ensure property value has contact information
+     */
+    validateContact: function(test, propertyName) {
+        var result = true;
+        var value = test.properties[propertyName];
+        var values = Array.isArray(value) ? value : [value];
+        for (var index = 0; index < values.length; index++) {
+            value = values[index];
+            var re = /(\S+)(\s*)<(.*)>(.*)/;
+            if (! re.test(value)) {
+                re = /(\S+)(\s+)(http[s]?:\/\/)(.*)/
+                if (! re.test(value)) {
+                    this.error('Metadata property "' + propertyName + 
+                        '" for test: "' + test.name +
+                        '" must have name and contact information ' +
+                        '("name <email>" or "name http(s)://")');
+                    result = false;
+                }
+            }
+        }
+        return result;
+    },
+    
+    /**
+     * Extract metadata from test object
+     */
+    extractFromTest: function(test) {
+        var testMetadata = {};
+        // filter out metadata from other properties in test
+        for (var metaIndex = 0; metaIndex < this.metadataProperties.length;
+             metaIndex++) {
+            var meta = this.metadataProperties[metaIndex];
+            if (test.properties.hasOwnProperty(meta)) {
+                if ('author' == meta) {
+                    this.validateContact(test, meta);
+                }
+                testMetadata[meta] = test.properties[meta];
+            }
+        }
+        return testMetadata;
+    },
+    
+    /**
+     * Compare cached metadata to extracted metadata
+     */
+    validateCache: function() {
+        for (var testName in this.currentMetadata) {
+            if (! this.cachedMetadata.hasOwnProperty(testName)) {
+                return false;
+            }
+            var testMetadata = this.currentMetadata[testName];
+            var cachedTestMetadata = this.cachedMetadata[testName];
+            delete this.cachedMetadata[testName];
+            
+            for (var metaIndex = 0; metaIndex < this.metadataProperties.length;
+                 metaIndex++) {
+                var meta = this.metadataProperties[metaIndex];
+                if (cachedTestMetadata.hasOwnProperty(meta) && 
+                    testMetadata.hasOwnProperty(meta)) {
+                    if (Array.isArray(cachedTestMetadata[meta])) {
+                      if (! Array.isArray(testMetadata[meta])) {
+                          return false;
+                      }
+                      if (cachedTestMetadata[meta].length == 
+                          testMetadata[meta].length) {
+                          for (var index = 0; 
+                               index < cachedTestMetadata[meta].length; 
+                               index++) {
+                              if (cachedTestMetadata[meta][index] != 
+                                  testMetadata[meta][index]) {
+                                  return false;
+                              }
+                          }
+                      }
+                      else {
+                          return false;
+                      }
+                    }
+                    else {
+                      if (Array.isArray(testMetadata[meta])) {
+                        return false;
+                      }
+                      if (cachedTestMetadata[meta] != testMetadata[meta]) {
+                        return false;
+                      }
+                    }
+                }
+                else if (cachedTestMetadata.hasOwnProperty(meta) || 
+                         testMetadata.hasOwnProperty(meta)) {
+                    return false;
+                }
+            }
+        }
+        for (var testName in this.cachedMetadata) {
+            return false;
+        }
+        return true;
+    },
+  
+    appendText: function(elemement, text) {
+        elemement.appendChild(document.createTextNode(text));
+    },
+  
+    jsonifyArray: function(arrayValue, indent) {
+        var output = '[';
+
+        if (1 == arrayValue.length) {
+            output += JSON.stringify(arrayValue[0]);
+        }
+        else {
+            for (var index = 0; index < arrayValue.length; index++) {
+                if (0 < index) {
+                    output += ',\n  ' + indent;
+                }
+                output += JSON.stringify(arrayValue[index]);
+            }
+        }
+        output += ']';
+        return output;
+    },
+    
+    jsonifyObject: function(objectValue, indent) {
+        var output = '{';
+        
+        var count = 0;
+        for (var property in objectValue) {
+            ++count;
+            if (Array.isArray(objectValue[property]) || 
+                ('object' == typeof(value))) {
+                ++count;
+            }
+        }
+        if (1 == count) {
+            for (var property in objectValue) {
+                output += ' "' + property + '": '
+                          + JSON.stringify(objectValue[property])
+                          + ' ';
+            }
+        }
+        else {
+            var first = true;
+            for (var property in objectValue) {
+                if (! first) {
+                    output += ',';
+                }
+                first = false;
+                output += '\n  ' + indent + '"' + property + '": ';
+                var value = objectValue[property];
+                if (Array.isArray(value)) {
+                    output += this.jsonifyArray(value, indent + 
+                        '                '.substr(0, 5 + property.length));
+                }
+                else if ('object' == typeof(value)) {
+                    output += this.jsonifyObject(value, indent + '  ');
+                }
+                else {
+                    output += JSON.stringify(value);
+                }
+            }
+            if (1 < output.length) {
+                output += '\n' + indent;
+            }
+        }
+        output += '}';
+        return output;
+    },
+  
+    /**
+     * Generate javascript source code for captured metadata
+     * Metadata is in pretty-printed JSON format
+     */
+    generateSource: function() {
+        var source = 
+            '<script id="metadata_cache">/*\n' + 
+            this.jsonifyObject(this.currentMetadata, '') + '\n' + 
+            '*/</script>\n';
+        return source;
+    },
+    
+    /**
+     * Add element containing metadata source code
+     */
+    addSourceElement: function(event) {
+        var sourceWrapper = document.createElement('div');
+        sourceWrapper.setAttribute('id', 'metadata_source');
+
+        var instructions = document.createElement('p');
+        if (this.cachedMetadata) {
+            this.appendText(instructions, 
+                'Replace the existing <script id="metadata_cache"> element ' + 
+                'in the test\'s <head> with the following:');
+        }
+        else {
+            this.appendText(instructions, 
+                'Copy the following into the <head> element of the test ' +
+                'or the test\'s metadata sidecar file:');
+        }
+        sourceWrapper.appendChild(instructions);
+        
+        var sourceElement = document.createElement('pre');
+        this.appendText(sourceElement, this.generateSource());
+
+        sourceWrapper.appendChild(sourceElement);
+        
+        var messageElement = document.getElementById('metadata_issue');
+        messageElement.parentNode.insertBefore(sourceWrapper, 
+                                               messageElement.nextSibling);
+        messageElement.parentNode.removeChild(messageElement);
+
+        (event.preventDefault) ? event.preventDefault() : 
+                                 event.returnValue = false;
+    },
+    
+    /**
+     * Extract the metadata cache from the cache element if present
+     */
+    getCachedMetadata: function() {
+        var cacheElement = document.getElementById('metadata_cache');
+        
+        if (cacheElement) {
+            var cacheText = cacheElement.firstChild.nodeValue;
+            var openBrace = cacheText.indexOf('{');
+            var closeBrace = cacheText.lastIndexOf('}');
+            if ((-1 < openBrace) && (-1 < closeBrace)) {
+                cacheText = cacheText.slice(openBrace, closeBrace + 1);
+                try {
+                    this.cachedMetadata = JSON.parse(cacheText);
+                }
+                catch (exc) {
+                    this.cachedMetadata = 'Invalid JSON in Cached metadata. ';
+                }
+            }
+            else {
+                this.cachedMetadata = 'Metadata not found in cache element. ';
+            }
+        }
+    },
+    
+    /**
+     * Main entry point, extract metadata from tests, compare to cached version
+     * if present.
+     * If cache not present or differs from extrated metadata, generate an error
+     */
+    process: function(tests, harness_status) {
+        for (var index = 0; index < tests.length; index++) {
+            var test = tests[index];
+            if (this.currentMetadata.hasOwnProperty(test.name)) {
+                this.error('Duplicate test name: ' + test.name);
+            }
+            else {
+                this.currentMetadata[test.name] = this.extractFromTest(test);
+            }
+        }
+
+        this.getCachedMetadata();
+        
+        var message = null;
+        var messageClass = 'warning';
+        var showSource = false;
+        
+        if (0 == tests.length) {
+            if (this.cachedMetadata) {
+                message = 'Cached metadata present but no tests. ';
+            }
+        }
+        else if (1 == tests.length) {
+            if (this.cachedMetadata) {
+                message = 'Single test files should not have cached metadata. ';
+            }
+            else {
+                var testMetadata = this.currentMetadata[tests[0].name];
+                var hasMetadata = false;
+                for (var meta in testMetadata) {
+                    hasMetadata |= testMetadata.hasOwnProperty(meta);
+                }
+                if (hasMetadata) {
+                    message = 'Single tests should not have metadata. ' +
+                              'Move metadata to <head>. ';
+                }
+            }
+        }
+        else {
+            if (this.cachedMetadata) {
+                messageClass = 'error';
+                if ('string' == typeof(this.cachedMetadata)) {
+                    message = this.cachedMetadata;
+                    showSource = true;
+                }
+                else if (! this.validateCache()) {
+                    message = 'Cached metadata out of sync. ';
+                    showSource = true;
+                }
+            }
+        }
+        
+        if (message) {
+            var messageElement = document.createElement('p');
+            messageElement.setAttribute('id', 'metadata_issue');
+            messageElement.setAttribute('class', messageClass);
+            this.appendText(messageElement, message);
+            
+            if (showSource) {
+                var link = document.createElement('a');
+                this.appendText(link, 'Click for source code.');
+                link.setAttribute('href', '#');
+                link.setAttribute('onclick', 
+                                  'metadata_generator.addSourceElement(event)');
+                messageElement.appendChild(link);
+            }
+            
+            var summary = document.getElementById('summary');
+            if (summary) {
+                summary.parentNode.insertBefore(messageElement, summary);
+            }
+            else {
+                var log = document.getElementById('log');
+                if (log) {
+                    log.appendChild(messageElement);
+                }
+            }
+        }
+    },
+
+    setup: function() {
+        add_completion_callback(
+            function (tests, harness_status) { 
+                metadata_generator.process(tests, harness_status)
+            });
+    }
+}
+
+metadata_generator.setup();
+// vim: set expandtab shiftwidth=4 tabstop=4:

+ 155 - 0
Build/node_modules/usertiming/test-w3c/webperftestharness.js

@@ -0,0 +1,155 @@
+/*
+Distributed under both the W3C Test Suite License [1] and the W3C
+3-clause BSD License [2]. To contribute to a W3C Test Suite, see the
+policies and contribution forms [3].
+
+[1] http://www.w3.org/Consortium/Legal/2008/04-testsuite-license
+[2] http://www.w3.org/Consortium/Legal/2008/03-bsd-license
+[3] http://www.w3.org/2004/10/27-testcases
+ */
+
+//
+// Helper Functions for NavigationTiming W3C tests
+//
+
+var performanceNamespace = window.performance;
+var timingAttributes = [
+    'connectEnd',
+    'connectStart',
+    'domComplete',
+    'domContentLoadedEventEnd',
+    'domContentLoadedEventStart',
+    'domInteractive',
+    'domLoading',
+    'domainLookupEnd',
+    'domainLookupStart',
+    'fetchStart',
+    'loadEventEnd',
+    'loadEventStart',
+    'navigationStart',
+    'redirectEnd',
+    'redirectStart',
+    'requestStart',
+    'responseEnd',
+    'responseStart',
+    'unloadEventEnd',
+    'unloadEventStart'
+];
+
+var namespace_check = false;
+
+//
+// All test() functions in the WebPerf test suite should use wp_test() instead.
+//
+// wp_test() validates the window.performance namespace exists prior to running tests and
+// immediately shows a single failure if it does not.
+//
+
+function wp_test(func, msg, properties)
+{
+    // only run the namespace check once
+    if (!namespace_check)
+    {
+        namespace_check = true;
+
+        if (performanceNamespace === undefined || performanceNamespace == null)
+        {
+            // show a single error that window.performance is undefined
+            test(function() { assert_true(performanceNamespace !== undefined && performanceNamespace != null, "window.performance is defined and not null"); }, "window.performance is defined and not null.", {author:"W3C http://www.w3.org/",help:"http://www.w3.org/TR/navigation-timing/#sec-window.performance-attribute",assert:"The window.performance attribute provides a hosting area for performance related attributes. "});
+        }
+    }
+
+    test(func, msg, properties);
+}
+
+function test_namespace(child_name, skip_root)
+{
+    if (skip_root === undefined) {
+        var msg = 'window.performance is defined';
+        wp_test(function () { assert_true(performanceNamespace !== undefined, msg); }, msg,{author:"W3C http://www.w3.org/",help:"http://www.w3.org/TR/navigation-timing/#sec-window.performance-attribute",assert:"The window.performance attribute provides a hosting area for performance related attributes. "});
+    }
+
+    if (child_name !== undefined) {
+        var msg2 = 'window.performance.' + child_name + ' is defined';
+        wp_test(function() { assert_true(performanceNamespace[child_name] !== undefined, msg2); }, msg2,{author:"W3C http://www.w3.org/",help:"http://www.w3.org/TR/navigation-timing/#sec-window.performance-attribute",assert:"The window.performance attribute provides a hosting area for performance related attributes. "});
+    }
+}
+
+function test_attribute_exists(parent_name, attribute_name, properties)
+{
+    var msg = 'window.performance.' + parent_name + '.' + attribute_name + ' is defined.';
+    wp_test(function() { assert_true(performanceNamespace[parent_name][attribute_name] !== undefined, msg); }, msg, properties);
+}
+
+function test_enum(parent_name, enum_name, value, properties)
+{
+    var msg = 'window.performance.' + parent_name + '.' + enum_name + ' is defined.';
+    wp_test(function() { assert_true(performanceNamespace[parent_name][enum_name] !== undefined, msg); }, msg, properties);
+
+    msg = 'window.performance.' + parent_name + '.' + enum_name + ' = ' + value;
+    wp_test(function() { assert_equals(performanceNamespace[parent_name][enum_name], value, msg); }, msg, properties);
+}
+
+function test_timing_order(attribute_name, greater_than_attribute, properties)
+{
+    // ensure it's not 0 first
+    var msg = "window.performance.timing." + attribute_name + " > 0";
+    wp_test(function() { assert_true(performanceNamespace.timing[attribute_name] > 0, msg); }, msg, properties);
+
+    // ensure it's in the right order
+    msg = "window.performance.timing." + attribute_name + " >= window.performance.timing." + greater_than_attribute;
+    wp_test(function() { assert_true(performanceNamespace.timing[attribute_name] >= performanceNamespace.timing[greater_than_attribute], msg); }, msg, properties);
+}
+
+function test_timing_greater_than(attribute_name, greater_than, properties)
+{
+    var msg = "window.performance.timing." + attribute_name + " > " + greater_than;
+    test_greater_than(performanceNamespace.timing[attribute_name], greater_than, msg, properties);
+}
+
+function test_timing_equals(attribute_name, equals, msg, properties)
+{
+    var test_msg = msg || "window.performance.timing." + attribute_name + " == " + equals;
+    test_equals(performanceNamespace.timing[attribute_name], equals, test_msg, properties);
+}
+
+//
+// Non-test related helper functions
+//
+
+function sleep_milliseconds(n)
+{
+    var start = new Date().getTime();
+    while (true) {
+        if ((new Date().getTime() - start) >= n) break;
+    }
+}
+
+//
+// Common helper functions
+//
+
+function test_true(value, msg, properties)
+{
+    wp_test(function () { assert_true(value, msg); }, msg, properties);
+}
+
+function test_equals(value, equals, msg, properties)
+{
+    wp_test(function () { assert_equals(value, equals, msg); }, msg, properties);
+}
+
+function test_greater_than(value, greater_than, msg, properties)
+{
+    wp_test(function () { assert_true(value > greater_than, msg); }, msg, properties);
+}
+
+function test_greater_or_equals(value, greater_than, msg, properties)
+{
+    wp_test(function () { assert_true(value >= greater_than, msg); }, msg, properties);
+}
+
+function test_not_equals(value, notequals, msg, properties)
+{
+    wp_test(function() { assert_true(value !== notequals, msg); }, msg, properties);
+}

+ 5 - 0
Build/npm-shrinkwrap.json

@@ -172,6 +172,11 @@
       "from": "underscore.string@>=3.1.1 <3.2.0",
       "from": "underscore.string@>=3.1.1 <3.2.0",
       "resolved": "https://registry.npmjs.org/underscore.string/-/underscore.string-3.1.1.tgz"
       "resolved": "https://registry.npmjs.org/underscore.string/-/underscore.string-3.1.1.tgz"
     },
     },
+    "usertiming": {
+      "version": "0.1.7",
+      "from": "usertiming@*",
+      "resolved": "https://registry.npmjs.org/usertiming/-/usertiming-0.1.7.tgz"
+    },
     "utilities": {
     "utilities": {
       "version": "1.0.4",
       "version": "1.0.4",
       "from": "utilities@>=1.0.0 <1.1.0",
       "from": "utilities@>=1.0.0 <1.1.0",