зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1142950 - Update Loop's vendor libraries for unit tests. r=mikedeboer
--HG-- rename : browser/components/loop/test/shared/vendor/chai-1.9.0.js => browser/components/loop/test/shared/vendor/chai-2.1.0.js rename : browser/components/loop/test/shared/vendor/mocha-2.0.1.css => browser/components/loop/test/shared/vendor/mocha-2.2.1.css rename : browser/components/loop/test/shared/vendor/mocha-2.0.1.js => browser/components/loop/test/shared/vendor/mocha-2.2.1.js rename : browser/components/loop/test/shared/vendor/sinon-1.12.2.js => browser/components/loop/test/shared/vendor/sinon-1.13.0.js
This commit is contained in:
Родитель
fbb580fcfc
Коммит
5621ad09d2
|
@ -6,7 +6,7 @@
|
|||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Loop desktop-local mocha tests</title>
|
||||
<link rel="stylesheet" media="all" href="../shared/vendor/mocha-2.0.1.css">
|
||||
<link rel="stylesheet" media="all" href="../shared/vendor/mocha-2.2.1.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="mocha">
|
||||
|
@ -29,12 +29,12 @@
|
|||
<script src="../../content/shared/libs/backbone-1.1.2.js"></script>
|
||||
|
||||
<!-- test dependencies -->
|
||||
<script src="../shared/vendor/mocha-2.0.1.js"></script>
|
||||
<script src="../shared/vendor/chai-1.9.0.js"></script>
|
||||
<script src="../shared/vendor/sinon-1.12.2.js"></script>
|
||||
<script src="../shared/vendor/mocha-2.2.1.js"></script>
|
||||
<script src="../shared/vendor/chai-2.1.0.js"></script>
|
||||
<script src="../shared/vendor/sinon-1.13.0.js"></script>
|
||||
<script>
|
||||
/*global chai,mocha */
|
||||
chai.Assertion.includeStack = true;
|
||||
chai.config.includeStack = true;
|
||||
mocha.setup('bdd');
|
||||
</script>
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Loop shared mocha tests</title>
|
||||
<link rel="stylesheet" media="all" href="vendor/mocha-2.0.1.css">
|
||||
<link rel="stylesheet" media="all" href="vendor/mocha-2.2.1.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="mocha">
|
||||
|
@ -29,12 +29,12 @@
|
|||
<script src="../../standalone/content/libs/l10n-gaia-02ca67948fe8.js"></script>
|
||||
|
||||
<!-- test dependencies -->
|
||||
<script src="vendor/mocha-2.0.1.js"></script>
|
||||
<script src="vendor/chai-1.9.0.js"></script>
|
||||
<script src="vendor/sinon-1.12.2.js"></script>
|
||||
<script src="vendor/mocha-2.2.1.js"></script>
|
||||
<script src="vendor/chai-2.1.0.js"></script>
|
||||
<script src="vendor/sinon-1.13.0.js"></script>
|
||||
<script>
|
||||
/*global chai, mocha */
|
||||
chai.Assertion.includeStack = true;
|
||||
chai.config.includeStack = true;
|
||||
mocha.setup('bdd');
|
||||
</script>
|
||||
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Sinon.JS 1.12.2, 2014/12/12
|
||||
* Sinon.JS 1.13.0, 2015/03/05
|
||||
*
|
||||
* @author Christian Johansen (christian@cjohansen.no)
|
||||
* @author Contributors: https://github.com/cjohansen/Sinon.JS/blob/master/AUTHORS
|
||||
|
@ -35,7 +35,7 @@
|
|||
|
||||
(function (root, factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
define([], function () {
|
||||
define('sinon', [], function () {
|
||||
return (root.sinon = factory());
|
||||
});
|
||||
} else if (typeof exports === 'object') {
|
||||
|
@ -1455,7 +1455,7 @@ var sinon = (function () {
|
|||
}(typeof sinon == "object" && sinon || null));
|
||||
|
||||
/**
|
||||
* @depend ../sinon.js
|
||||
* @depend util/core.js
|
||||
*/
|
||||
|
||||
(function (sinon) {
|
||||
|
@ -1558,7 +1558,7 @@ var sinon = (function () {
|
|||
}(typeof sinon == "object" && sinon || null));
|
||||
|
||||
/**
|
||||
* @depend ../sinon.js
|
||||
* @depend util/core.js
|
||||
*/
|
||||
|
||||
(function (sinon) {
|
||||
|
@ -1601,7 +1601,7 @@ var sinon = (function () {
|
|||
}(typeof sinon == "object" && sinon || null));
|
||||
|
||||
/**
|
||||
* @depend ../sinon.js
|
||||
* @depend util/core.js
|
||||
*/
|
||||
/**
|
||||
* Format functions
|
||||
|
@ -1889,6 +1889,7 @@ var sinon = (function () {
|
|||
|
||||
function loadDependencies(require, exports, module) {
|
||||
var sinon = require("./util/core");
|
||||
require("./typeOf");
|
||||
module.exports = makeApi(sinon);
|
||||
}
|
||||
|
||||
|
@ -1904,7 +1905,7 @@ var sinon = (function () {
|
|||
}(typeof sinon == "object" && sinon || null));
|
||||
|
||||
/**
|
||||
* @depend ../sinon.js
|
||||
* @depend util/core.js
|
||||
*/
|
||||
/**
|
||||
* Format functions
|
||||
|
@ -2028,7 +2029,11 @@ var sinon = (function () {
|
|||
},
|
||||
|
||||
calledWith: function calledWith() {
|
||||
for (var i = 0, l = arguments.length; i < l; i += 1) {
|
||||
var l = arguments.length;
|
||||
if (l > this.args.length) {
|
||||
return false;
|
||||
}
|
||||
for (var i = 0; i < l; i += 1) {
|
||||
if (!sinon.deepEqual(arguments[i], this.args[i])) {
|
||||
return false;
|
||||
}
|
||||
|
@ -2038,7 +2043,11 @@ var sinon = (function () {
|
|||
},
|
||||
|
||||
calledWithMatch: function calledWithMatch() {
|
||||
for (var i = 0, l = arguments.length; i < l; i += 1) {
|
||||
var l = arguments.length;
|
||||
if (l > this.args.length) {
|
||||
return false;
|
||||
}
|
||||
for (var i = 0; i < l; i += 1) {
|
||||
var actual = this.args[i];
|
||||
var expectation = arguments[i];
|
||||
if (!sinon.match || !sinon.match(expectation).test(actual)) {
|
||||
|
@ -2187,6 +2196,7 @@ var sinon = (function () {
|
|||
function loadDependencies(require, exports, module) {
|
||||
var sinon = require("./util/core");
|
||||
require("./match");
|
||||
require("./format");
|
||||
module.exports = makeApi(sinon);
|
||||
}
|
||||
|
||||
|
@ -2265,11 +2275,11 @@ var sinon = (function () {
|
|||
}
|
||||
|
||||
var vars = "a,b,c,d,e,f,g,h,i,j,k,l";
|
||||
function createProxy(func) {
|
||||
function createProxy(func, proxyLength) {
|
||||
// Retain the function length:
|
||||
var p;
|
||||
if (func.length) {
|
||||
eval("p = (function proxy(" + vars.substring(0, func.length * 2 - 1) +
|
||||
if (proxyLength) {
|
||||
eval("p = (function proxy(" + vars.substring(0, proxyLength * 2 - 1) +
|
||||
") { return p.invoke(func, this, slice.call(arguments)); });");
|
||||
} else {
|
||||
p = function proxy() {
|
||||
|
@ -2311,9 +2321,11 @@ var sinon = (function () {
|
|||
this.fakes[i].reset();
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
create: function create(func) {
|
||||
create: function create(func, spyLength) {
|
||||
var name;
|
||||
|
||||
if (typeof func != "function") {
|
||||
|
@ -2322,7 +2334,11 @@ var sinon = (function () {
|
|||
name = sinon.functionName(func);
|
||||
}
|
||||
|
||||
var proxy = createProxy(func);
|
||||
if (!spyLength) {
|
||||
spyLength = func.length;
|
||||
}
|
||||
|
||||
var proxy = createProxy(func, spyLength);
|
||||
|
||||
sinon.extend(proxy, spy);
|
||||
delete proxy.create;
|
||||
|
@ -2623,6 +2639,9 @@ var sinon = (function () {
|
|||
function loadDependencies(require, exports, module) {
|
||||
var sinon = require("./util/core");
|
||||
require("./call");
|
||||
require("./extend");
|
||||
require("./times_in_words");
|
||||
require("./format");
|
||||
module.exports = makeApi(sinon);
|
||||
}
|
||||
|
||||
|
@ -2654,6 +2673,8 @@ var sinon = (function () {
|
|||
(function (sinon) {
|
||||
var slice = Array.prototype.slice;
|
||||
var join = Array.prototype.join;
|
||||
var useLeftMostCallback = -1;
|
||||
var useRightMostCallback = -2;
|
||||
|
||||
var nextTick = (function () {
|
||||
if (typeof process === "object" && typeof process.nextTick === "function") {
|
||||
|
@ -2683,24 +2704,34 @@ var sinon = (function () {
|
|||
function getCallback(behavior, args) {
|
||||
var callArgAt = behavior.callArgAt;
|
||||
|
||||
if (callArgAt < 0) {
|
||||
var callArgProp = behavior.callArgProp;
|
||||
|
||||
for (var i = 0, l = args.length; i < l; ++i) {
|
||||
if (!callArgProp && typeof args[i] == "function") {
|
||||
return args[i];
|
||||
}
|
||||
|
||||
if (callArgProp && args[i] &&
|
||||
typeof args[i][callArgProp] == "function") {
|
||||
return args[i][callArgProp];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
if (callArgAt >= 0) {
|
||||
return args[callArgAt];
|
||||
}
|
||||
|
||||
return args[callArgAt];
|
||||
var argumentList;
|
||||
|
||||
if (callArgAt === useLeftMostCallback) {
|
||||
argumentList = args;
|
||||
}
|
||||
|
||||
if (callArgAt === useRightMostCallback) {
|
||||
argumentList = slice.call(args).reverse();
|
||||
}
|
||||
|
||||
var callArgProp = behavior.callArgProp;
|
||||
|
||||
for (var i = 0, l = argumentList.length; i < l; ++i) {
|
||||
if (!callArgProp && typeof argumentList[i] == "function") {
|
||||
return argumentList[i];
|
||||
}
|
||||
|
||||
if (callArgProp && argumentList[i] &&
|
||||
typeof argumentList[i][callArgProp] == "function") {
|
||||
return argumentList[i][callArgProp];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function makeApi(sinon) {
|
||||
|
@ -2860,7 +2891,17 @@ var sinon = (function () {
|
|||
},
|
||||
|
||||
yields: function () {
|
||||
this.callArgAt = -1;
|
||||
this.callArgAt = useLeftMostCallback;
|
||||
this.callbackArguments = slice.call(arguments, 0);
|
||||
this.callbackContext = undefined;
|
||||
this.callArgProp = undefined;
|
||||
this.callbackAsync = false;
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
yieldsRight: function () {
|
||||
this.callArgAt = useRightMostCallback;
|
||||
this.callbackArguments = slice.call(arguments, 0);
|
||||
this.callbackContext = undefined;
|
||||
this.callArgProp = undefined;
|
||||
|
@ -2874,7 +2915,7 @@ var sinon = (function () {
|
|||
throw new TypeError("argument context is not an object");
|
||||
}
|
||||
|
||||
this.callArgAt = -1;
|
||||
this.callArgAt = useLeftMostCallback;
|
||||
this.callbackArguments = slice.call(arguments, 1);
|
||||
this.callbackContext = context;
|
||||
this.callArgProp = undefined;
|
||||
|
@ -2884,7 +2925,7 @@ var sinon = (function () {
|
|||
},
|
||||
|
||||
yieldsTo: function (prop) {
|
||||
this.callArgAt = -1;
|
||||
this.callArgAt = useLeftMostCallback;
|
||||
this.callbackArguments = slice.call(arguments, 1);
|
||||
this.callbackContext = undefined;
|
||||
this.callArgProp = prop;
|
||||
|
@ -2898,7 +2939,7 @@ var sinon = (function () {
|
|||
throw new TypeError("argument context is not an object");
|
||||
}
|
||||
|
||||
this.callArgAt = -1;
|
||||
this.callArgAt = useLeftMostCallback;
|
||||
this.callbackArguments = slice.call(arguments, 2);
|
||||
this.callbackContext = context;
|
||||
this.callArgProp = prop;
|
||||
|
@ -2959,6 +3000,7 @@ var sinon = (function () {
|
|||
|
||||
function loadDependencies(require, exports, module) {
|
||||
var sinon = require("./util/core");
|
||||
require("./extend");
|
||||
module.exports = makeApi(sinon);
|
||||
}
|
||||
|
||||
|
@ -3000,7 +3042,11 @@ var sinon = (function () {
|
|||
if (func) {
|
||||
wrapper = sinon.spy && sinon.spy.create ? sinon.spy.create(func) : func;
|
||||
} else {
|
||||
wrapper = stub.create();
|
||||
var stubLength = 0;
|
||||
if (typeof object == "object" && typeof object[property] == "function") {
|
||||
stubLength = object[property].length;
|
||||
}
|
||||
wrapper = stub.create(stubLength);
|
||||
}
|
||||
|
||||
if (!object && typeof property === "undefined") {
|
||||
|
@ -3036,14 +3082,14 @@ var sinon = (function () {
|
|||
var uuid = 0;
|
||||
|
||||
var proto = {
|
||||
create: function create() {
|
||||
create: function create(stubLength) {
|
||||
var functionStub = function () {
|
||||
return getCurrentBehavior(functionStub).invoke(this, arguments);
|
||||
};
|
||||
|
||||
functionStub.id = "stub#" + uuid++;
|
||||
var orig = functionStub;
|
||||
functionStub = sinon.spy.create(functionStub);
|
||||
functionStub = sinon.spy.create(functionStub, stubLength);
|
||||
functionStub.func = orig;
|
||||
|
||||
sinon.extend(functionStub, stub);
|
||||
|
@ -3124,6 +3170,7 @@ var sinon = (function () {
|
|||
var sinon = require("./util/core");
|
||||
require("./behavior");
|
||||
require("./spy");
|
||||
require("./extend");
|
||||
module.exports = makeApi(sinon);
|
||||
}
|
||||
|
||||
|
@ -3141,7 +3188,10 @@ var sinon = (function () {
|
|||
/**
|
||||
* @depend times_in_words.js
|
||||
* @depend util/core.js
|
||||
* @depend call.js
|
||||
* @depend extend.js
|
||||
* @depend match.js
|
||||
* @depend spy.js
|
||||
* @depend stub.js
|
||||
* @depend format.js
|
||||
*/
|
||||
|
@ -3569,9 +3619,14 @@ var sinon = (function () {
|
|||
|
||||
function loadDependencies(require, exports, module) {
|
||||
var sinon = require("./util/core");
|
||||
require("./times_in_words");
|
||||
require("./call");
|
||||
require("./extend");
|
||||
require("./match");
|
||||
require("./spy");
|
||||
require("./stub");
|
||||
require("./format");
|
||||
|
||||
module.exports = makeApi(sinon);
|
||||
}
|
||||
|
||||
|
@ -3588,6 +3643,7 @@ var sinon = (function () {
|
|||
|
||||
/**
|
||||
* @depend util/core.js
|
||||
* @depend spy.js
|
||||
* @depend stub.js
|
||||
* @depend mock.js
|
||||
*/
|
||||
|
@ -3814,16 +3870,16 @@ if (typeof sinon == "undefined") {
|
|||
var isNode = typeof module !== "undefined" && module.exports && typeof require == "function";
|
||||
var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
|
||||
|
||||
function loadDependencies(require, epxorts, module) {
|
||||
function loadDependencies(require, epxorts, module, lolex) {
|
||||
var sinon = require("./core");
|
||||
makeApi(sinon, require("lolex"));
|
||||
makeApi(sinon, lolex);
|
||||
module.exports = sinon;
|
||||
}
|
||||
|
||||
if (isAMD) {
|
||||
define(loadDependencies);
|
||||
} else if (isNode) {
|
||||
loadDependencies(require, module.exports, module);
|
||||
loadDependencies(require, module.exports, module, require("lolex"));
|
||||
} else {
|
||||
makeApi(sinon);
|
||||
}
|
||||
|
@ -3873,6 +3929,7 @@ if (typeof sinon == "undefined") {
|
|||
this.initEvent(type, false, false, target);
|
||||
this.loaded = progressEventRaw.loaded || null;
|
||||
this.total = progressEventRaw.total || null;
|
||||
this.lengthComputable = !!progressEventRaw.total;
|
||||
};
|
||||
|
||||
sinon.ProgressEvent.prototype = new sinon.Event();
|
||||
|
@ -3940,7 +3997,7 @@ if (typeof sinon == "undefined") {
|
|||
}());
|
||||
|
||||
/**
|
||||
* @depend ../sinon.js
|
||||
* @depend util/core.js
|
||||
*/
|
||||
/**
|
||||
* Logs errors
|
||||
|
@ -4007,6 +4064,229 @@ if (typeof sinon == "undefined") {
|
|||
}
|
||||
}(typeof sinon == "object" && sinon || null));
|
||||
|
||||
/**
|
||||
* @depend core.js
|
||||
* @depend ../extend.js
|
||||
* @depend event.js
|
||||
* @depend ../log_error.js
|
||||
*/
|
||||
/**
|
||||
* Fake XDomainRequest object
|
||||
*/
|
||||
|
||||
if (typeof sinon == "undefined") {
|
||||
this.sinon = {};
|
||||
}
|
||||
|
||||
// wrapper for global
|
||||
(function (global) {
|
||||
var xdr = { XDomainRequest: global.XDomainRequest };
|
||||
xdr.GlobalXDomainRequest = global.XDomainRequest;
|
||||
xdr.supportsXDR = typeof xdr.GlobalXDomainRequest != "undefined";
|
||||
xdr.workingXDR = xdr.supportsXDR ? xdr.GlobalXDomainRequest : false;
|
||||
|
||||
function makeApi(sinon) {
|
||||
sinon.xdr = xdr;
|
||||
|
||||
function FakeXDomainRequest() {
|
||||
this.readyState = FakeXDomainRequest.UNSENT;
|
||||
this.requestBody = null;
|
||||
this.requestHeaders = {};
|
||||
this.status = 0;
|
||||
this.timeout = null;
|
||||
|
||||
if (typeof FakeXDomainRequest.onCreate == "function") {
|
||||
FakeXDomainRequest.onCreate(this);
|
||||
}
|
||||
}
|
||||
|
||||
function verifyState(xdr) {
|
||||
if (xdr.readyState !== FakeXDomainRequest.OPENED) {
|
||||
throw new Error("INVALID_STATE_ERR");
|
||||
}
|
||||
|
||||
if (xdr.sendFlag) {
|
||||
throw new Error("INVALID_STATE_ERR");
|
||||
}
|
||||
}
|
||||
|
||||
function verifyRequestSent(xdr) {
|
||||
if (xdr.readyState == FakeXDomainRequest.UNSENT) {
|
||||
throw new Error("Request not sent");
|
||||
}
|
||||
if (xdr.readyState == FakeXDomainRequest.DONE) {
|
||||
throw new Error("Request done");
|
||||
}
|
||||
}
|
||||
|
||||
function verifyResponseBodyType(body) {
|
||||
if (typeof body != "string") {
|
||||
var error = new Error("Attempted to respond to fake XDomainRequest with " +
|
||||
body + ", which is not a string.");
|
||||
error.name = "InvalidBodyException";
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
sinon.extend(FakeXDomainRequest.prototype, sinon.EventTarget, {
|
||||
open: function open(method, url) {
|
||||
this.method = method;
|
||||
this.url = url;
|
||||
|
||||
this.responseText = null;
|
||||
this.sendFlag = false;
|
||||
|
||||
this.readyStateChange(FakeXDomainRequest.OPENED);
|
||||
},
|
||||
|
||||
readyStateChange: function readyStateChange(state) {
|
||||
this.readyState = state;
|
||||
var eventName = "";
|
||||
switch (this.readyState) {
|
||||
case FakeXDomainRequest.UNSENT:
|
||||
break;
|
||||
case FakeXDomainRequest.OPENED:
|
||||
break;
|
||||
case FakeXDomainRequest.LOADING:
|
||||
if (this.sendFlag) {
|
||||
//raise the progress event
|
||||
eventName = "onprogress";
|
||||
}
|
||||
break;
|
||||
case FakeXDomainRequest.DONE:
|
||||
if (this.isTimeout) {
|
||||
eventName = "ontimeout"
|
||||
} else if (this.errorFlag || (this.status < 200 || this.status > 299)) {
|
||||
eventName = "onerror";
|
||||
} else {
|
||||
eventName = "onload"
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// raising event (if defined)
|
||||
if (eventName) {
|
||||
if (typeof this[eventName] == "function") {
|
||||
try {
|
||||
this[eventName]();
|
||||
} catch (e) {
|
||||
sinon.logError("Fake XHR " + eventName + " handler", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
send: function send(data) {
|
||||
verifyState(this);
|
||||
|
||||
if (!/^(get|head)$/i.test(this.method)) {
|
||||
this.requestBody = data;
|
||||
}
|
||||
this.requestHeaders["Content-Type"] = "text/plain;charset=utf-8";
|
||||
|
||||
this.errorFlag = false;
|
||||
this.sendFlag = true;
|
||||
this.readyStateChange(FakeXDomainRequest.OPENED);
|
||||
|
||||
if (typeof this.onSend == "function") {
|
||||
this.onSend(this);
|
||||
}
|
||||
},
|
||||
|
||||
abort: function abort() {
|
||||
this.aborted = true;
|
||||
this.responseText = null;
|
||||
this.errorFlag = true;
|
||||
|
||||
if (this.readyState > sinon.FakeXDomainRequest.UNSENT && this.sendFlag) {
|
||||
this.readyStateChange(sinon.FakeXDomainRequest.DONE);
|
||||
this.sendFlag = false;
|
||||
}
|
||||
},
|
||||
|
||||
setResponseBody: function setResponseBody(body) {
|
||||
verifyRequestSent(this);
|
||||
verifyResponseBodyType(body);
|
||||
|
||||
var chunkSize = this.chunkSize || 10;
|
||||
var index = 0;
|
||||
this.responseText = "";
|
||||
|
||||
do {
|
||||
this.readyStateChange(FakeXDomainRequest.LOADING);
|
||||
this.responseText += body.substring(index, index + chunkSize);
|
||||
index += chunkSize;
|
||||
} while (index < body.length);
|
||||
|
||||
this.readyStateChange(FakeXDomainRequest.DONE);
|
||||
},
|
||||
|
||||
respond: function respond(status, contentType, body) {
|
||||
// content-type ignored, since XDomainRequest does not carry this
|
||||
// we keep the same syntax for respond(...) as for FakeXMLHttpRequest to ease
|
||||
// test integration across browsers
|
||||
this.status = typeof status == "number" ? status : 200;
|
||||
this.setResponseBody(body || "");
|
||||
},
|
||||
|
||||
simulatetimeout: function simulatetimeout() {
|
||||
this.status = 0;
|
||||
this.isTimeout = true;
|
||||
// Access to this should actually throw an error
|
||||
this.responseText = undefined;
|
||||
this.readyStateChange(FakeXDomainRequest.DONE);
|
||||
}
|
||||
});
|
||||
|
||||
sinon.extend(FakeXDomainRequest, {
|
||||
UNSENT: 0,
|
||||
OPENED: 1,
|
||||
LOADING: 3,
|
||||
DONE: 4
|
||||
});
|
||||
|
||||
sinon.useFakeXDomainRequest = function useFakeXDomainRequest() {
|
||||
sinon.FakeXDomainRequest.restore = function restore(keepOnCreate) {
|
||||
if (xdr.supportsXDR) {
|
||||
global.XDomainRequest = xdr.GlobalXDomainRequest;
|
||||
}
|
||||
|
||||
delete sinon.FakeXDomainRequest.restore;
|
||||
|
||||
if (keepOnCreate !== true) {
|
||||
delete sinon.FakeXDomainRequest.onCreate;
|
||||
}
|
||||
};
|
||||
if (xdr.supportsXDR) {
|
||||
global.XDomainRequest = sinon.FakeXDomainRequest;
|
||||
}
|
||||
return sinon.FakeXDomainRequest;
|
||||
};
|
||||
|
||||
sinon.FakeXDomainRequest = FakeXDomainRequest;
|
||||
}
|
||||
|
||||
var isNode = typeof module !== "undefined" && module.exports && typeof require == "function";
|
||||
var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
|
||||
|
||||
function loadDependencies(require, exports, module) {
|
||||
var sinon = require("./core");
|
||||
require("../extend");
|
||||
require("./event");
|
||||
require("../log_error");
|
||||
makeApi(sinon);
|
||||
module.exports = sinon;
|
||||
}
|
||||
|
||||
if (isAMD) {
|
||||
define(loadDependencies);
|
||||
} else if (isNode) {
|
||||
loadDependencies(require, module.exports, module);
|
||||
} else {
|
||||
makeApi(sinon);
|
||||
}
|
||||
})(this);
|
||||
|
||||
/**
|
||||
* @depend core.js
|
||||
* @depend ../extend.js
|
||||
|
@ -4382,6 +4662,7 @@ if (typeof sinon == "undefined") {
|
|||
this.upload.dispatchEvent(new sinon.Event("load", false, false, this));
|
||||
if (supportsProgress) {
|
||||
this.upload.dispatchEvent(new sinon.ProgressEvent("progress", {loaded: 100, total: 100}));
|
||||
this.dispatchEvent(new sinon.ProgressEvent("progress", {loaded: 100, total: 100}));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -4428,7 +4709,7 @@ if (typeof sinon == "undefined") {
|
|||
if (this.requestHeaders[contentType]) {
|
||||
var value = this.requestHeaders[contentType].split(";");
|
||||
this.requestHeaders[contentType] = value[0] + ";charset=utf-8";
|
||||
} else {
|
||||
} else if (!(data instanceof FormData)) {
|
||||
this.requestHeaders["Content-Type"] = "text/plain;charset=utf-8";
|
||||
}
|
||||
|
||||
|
@ -4544,6 +4825,12 @@ if (typeof sinon == "undefined") {
|
|||
}
|
||||
},
|
||||
|
||||
downloadProgress: function downloadProgress(progressEventRaw) {
|
||||
if (supportsProgress) {
|
||||
this.dispatchEvent(new sinon.ProgressEvent("progress", progressEventRaw));
|
||||
}
|
||||
},
|
||||
|
||||
uploadError: function uploadError(error) {
|
||||
if (supportsCustomEvent) {
|
||||
this.upload.dispatchEvent(new sinon.CustomEvent("error", {detail: error}));
|
||||
|
@ -4601,7 +4888,9 @@ if (typeof sinon == "undefined") {
|
|||
|
||||
function loadDependencies(require, exports, module) {
|
||||
var sinon = require("./core");
|
||||
require("../extend");
|
||||
require("./event");
|
||||
require("../log_error");
|
||||
makeApi(sinon);
|
||||
module.exports = sinon;
|
||||
}
|
||||
|
@ -4616,9 +4905,10 @@ if (typeof sinon == "undefined") {
|
|||
makeApi(sinon);
|
||||
}
|
||||
|
||||
})(typeof self !== "undefined" ? self : this);
|
||||
})(typeof global !== "undefined" ? global : this);
|
||||
|
||||
/**
|
||||
* @depend fake_xdomain_request.js
|
||||
* @depend fake_xml_http_request.js
|
||||
* @depend ../format.js
|
||||
* @depend ../log_error.js
|
||||
|
@ -4699,7 +4989,11 @@ if (typeof sinon == "undefined") {
|
|||
sinon.fakeServer = {
|
||||
create: function () {
|
||||
var server = create(this);
|
||||
this.xhr = sinon.useFakeXMLHttpRequest();
|
||||
if (!sinon.xhr.supportsCORS) {
|
||||
this.xhr = sinon.useFakeXDomainRequest();
|
||||
} else {
|
||||
this.xhr = sinon.useFakeXMLHttpRequest();
|
||||
}
|
||||
server.requests = [];
|
||||
|
||||
this.xhr.onCreate = function (xhrObj) {
|
||||
|
@ -4835,7 +5129,9 @@ if (typeof sinon == "undefined") {
|
|||
|
||||
function loadDependencies(require, exports, module) {
|
||||
var sinon = require("./core");
|
||||
require("./fake_xdomain_request");
|
||||
require("./fake_xml_http_request");
|
||||
require("../format");
|
||||
makeApi(sinon);
|
||||
module.exports = sinon;
|
||||
}
|
||||
|
@ -5094,7 +5390,8 @@ if (typeof sinon == "undefined") {
|
|||
|
||||
function loadDependencies(require, exports, module) {
|
||||
var sinon = require("./util/core");
|
||||
require("./util/fake_server");
|
||||
require("./extend");
|
||||
require("./util/fake_server_with_clock");
|
||||
require("./util/fake_timers");
|
||||
require("./collection");
|
||||
module.exports = makeApi(sinon);
|
||||
|
@ -5113,8 +5410,6 @@ if (typeof sinon == "undefined") {
|
|||
|
||||
/**
|
||||
* @depend util/core.js
|
||||
* @depend stub.js
|
||||
* @depend mock.js
|
||||
* @depend sandbox.js
|
||||
*/
|
||||
/**
|
||||
|
@ -5128,6 +5423,8 @@ if (typeof sinon == "undefined") {
|
|||
|
||||
(function (sinon) {
|
||||
function makeApi(sinon) {
|
||||
var slice = Array.prototype.slice;
|
||||
|
||||
function test(callback) {
|
||||
var type = typeof callback;
|
||||
|
||||
|
@ -5139,12 +5436,12 @@ if (typeof sinon == "undefined") {
|
|||
var config = sinon.getConfig(sinon.config);
|
||||
config.injectInto = config.injectIntoThis && this || config.injectInto;
|
||||
var sandbox = sinon.sandbox.create(config);
|
||||
var args = slice.call(arguments);
|
||||
var oldDone = args.length && args[args.length - 1];
|
||||
var exception, result;
|
||||
var doneIsWrapped = false;
|
||||
var argumentsCopy = Array.prototype.slice.call(arguments);
|
||||
if (argumentsCopy.length > 0 && typeof argumentsCopy[arguments.length - 1] == "function") {
|
||||
var oldDone = argumentsCopy[arguments.length - 1];
|
||||
argumentsCopy[arguments.length - 1] = function done(result) {
|
||||
|
||||
if (typeof oldDone == "function") {
|
||||
args[args.length - 1] = function sinonDone(result) {
|
||||
if (result) {
|
||||
sandbox.restore();
|
||||
throw exception;
|
||||
|
@ -5152,19 +5449,16 @@ if (typeof sinon == "undefined") {
|
|||
sandbox.verifyAndRestore();
|
||||
}
|
||||
oldDone(result);
|
||||
}
|
||||
doneIsWrapped = true;
|
||||
};
|
||||
}
|
||||
|
||||
var args = argumentsCopy.concat(sandbox.args);
|
||||
|
||||
try {
|
||||
result = callback.apply(this, args);
|
||||
result = callback.apply(this, args.concat(sandbox.args));
|
||||
} catch (e) {
|
||||
exception = e;
|
||||
}
|
||||
|
||||
if (!doneIsWrapped) {
|
||||
if (typeof oldDone != "function") {
|
||||
if (typeof exception !== "undefined") {
|
||||
sandbox.restore();
|
||||
throw exception;
|
||||
|
@ -5174,10 +5468,10 @@ if (typeof sinon == "undefined") {
|
|||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
if (callback.length) {
|
||||
return function sinonAsyncSandboxedTest(callback) {
|
||||
return function sinonAsyncSandboxedTest() {
|
||||
return sinonSandboxedTest.apply(this, arguments);
|
||||
};
|
||||
}
|
||||
|
@ -5210,9 +5504,7 @@ if (typeof sinon == "undefined") {
|
|||
define(loadDependencies);
|
||||
} else if (isNode) {
|
||||
loadDependencies(require, module.exports, module);
|
||||
} else if (!sinon) {
|
||||
return;
|
||||
} else {
|
||||
} else if (sinon) {
|
||||
makeApi(sinon);
|
||||
}
|
||||
}(typeof sinon == "object" && sinon || null));
|
||||
|
@ -5323,7 +5615,7 @@ if (typeof sinon == "undefined") {
|
|||
/**
|
||||
* @depend times_in_words.js
|
||||
* @depend util/core.js
|
||||
* @depend stub.js
|
||||
* @depend match.js
|
||||
* @depend format.js
|
||||
*/
|
||||
/**
|
||||
|
@ -5351,13 +5643,18 @@ if (typeof sinon == "undefined") {
|
|||
assert.fail("fake is not a spy");
|
||||
}
|
||||
|
||||
if (typeof method != "function") {
|
||||
assert.fail(method + " is not a function");
|
||||
if (method.proxy) {
|
||||
verifyIsStub(method.proxy);
|
||||
} else {
|
||||
if (typeof method != "function") {
|
||||
assert.fail(method + " is not a function");
|
||||
}
|
||||
|
||||
if (typeof method.getCall != "function") {
|
||||
assert.fail(method + " is not stubbed");
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof method.getCall != "function") {
|
||||
assert.fail(method + " is not stubbed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5387,7 +5684,7 @@ if (typeof sinon == "undefined") {
|
|||
}
|
||||
|
||||
if (failed) {
|
||||
failAssertion(this, fake.printf.apply(fake, [message].concat(args)));
|
||||
failAssertion(this, (fake.printf || fake.proxy.printf).apply(fake, [message].concat(args)));
|
||||
} else {
|
||||
assert.pass(name);
|
||||
}
|
||||
|
@ -5513,6 +5810,7 @@ if (typeof sinon == "undefined") {
|
|||
function loadDependencies(require, exports, module) {
|
||||
var sinon = require("./util/core");
|
||||
require("./match");
|
||||
require("./format");
|
||||
module.exports = makeApi(sinon);
|
||||
}
|
||||
|
||||
|
@ -5528,226 +5826,5 @@ if (typeof sinon == "undefined") {
|
|||
|
||||
}(typeof sinon == "object" && sinon || null, typeof window != "undefined" ? window : (typeof self != "undefined") ? self : global));
|
||||
|
||||
/**
|
||||
* @depend core.js
|
||||
* @depend ../extend.js
|
||||
* @depend event.js
|
||||
* @depend ../log_error.js
|
||||
*/
|
||||
/**
|
||||
* Fake XDomainRequest object
|
||||
*/
|
||||
|
||||
if (typeof sinon == "undefined") {
|
||||
this.sinon = {};
|
||||
}
|
||||
|
||||
// wrapper for global
|
||||
(function (global) {
|
||||
var xdr = { XDomainRequest: global.XDomainRequest };
|
||||
xdr.GlobalXDomainRequest = global.XDomainRequest;
|
||||
xdr.supportsXDR = typeof xdr.GlobalXDomainRequest != "undefined";
|
||||
xdr.workingXDR = xdr.supportsXDR ? xdr.GlobalXDomainRequest : false;
|
||||
|
||||
function makeApi(sinon) {
|
||||
sinon.xdr = xdr;
|
||||
|
||||
function FakeXDomainRequest() {
|
||||
this.readyState = FakeXDomainRequest.UNSENT;
|
||||
this.requestBody = null;
|
||||
this.requestHeaders = {};
|
||||
this.status = 0;
|
||||
this.timeout = null;
|
||||
|
||||
if (typeof FakeXDomainRequest.onCreate == "function") {
|
||||
FakeXDomainRequest.onCreate(this);
|
||||
}
|
||||
}
|
||||
|
||||
function verifyState(xdr) {
|
||||
if (xdr.readyState !== FakeXDomainRequest.OPENED) {
|
||||
throw new Error("INVALID_STATE_ERR");
|
||||
}
|
||||
|
||||
if (xdr.sendFlag) {
|
||||
throw new Error("INVALID_STATE_ERR");
|
||||
}
|
||||
}
|
||||
|
||||
function verifyRequestSent(xdr) {
|
||||
if (xdr.readyState == FakeXDomainRequest.UNSENT) {
|
||||
throw new Error("Request not sent");
|
||||
}
|
||||
if (xdr.readyState == FakeXDomainRequest.DONE) {
|
||||
throw new Error("Request done");
|
||||
}
|
||||
}
|
||||
|
||||
function verifyResponseBodyType(body) {
|
||||
if (typeof body != "string") {
|
||||
var error = new Error("Attempted to respond to fake XDomainRequest with " +
|
||||
body + ", which is not a string.");
|
||||
error.name = "InvalidBodyException";
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
sinon.extend(FakeXDomainRequest.prototype, sinon.EventTarget, {
|
||||
open: function open(method, url) {
|
||||
this.method = method;
|
||||
this.url = url;
|
||||
|
||||
this.responseText = null;
|
||||
this.sendFlag = false;
|
||||
|
||||
this.readyStateChange(FakeXDomainRequest.OPENED);
|
||||
},
|
||||
|
||||
readyStateChange: function readyStateChange(state) {
|
||||
this.readyState = state;
|
||||
var eventName = "";
|
||||
switch (this.readyState) {
|
||||
case FakeXDomainRequest.UNSENT:
|
||||
break;
|
||||
case FakeXDomainRequest.OPENED:
|
||||
break;
|
||||
case FakeXDomainRequest.LOADING:
|
||||
if (this.sendFlag) {
|
||||
//raise the progress event
|
||||
eventName = "onprogress";
|
||||
}
|
||||
break;
|
||||
case FakeXDomainRequest.DONE:
|
||||
if (this.isTimeout) {
|
||||
eventName = "ontimeout"
|
||||
} else if (this.errorFlag || (this.status < 200 || this.status > 299)) {
|
||||
eventName = "onerror";
|
||||
} else {
|
||||
eventName = "onload"
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// raising event (if defined)
|
||||
if (eventName) {
|
||||
if (typeof this[eventName] == "function") {
|
||||
try {
|
||||
this[eventName]();
|
||||
} catch (e) {
|
||||
sinon.logError("Fake XHR " + eventName + " handler", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
send: function send(data) {
|
||||
verifyState(this);
|
||||
|
||||
if (!/^(get|head)$/i.test(this.method)) {
|
||||
this.requestBody = data;
|
||||
}
|
||||
this.requestHeaders["Content-Type"] = "text/plain;charset=utf-8";
|
||||
|
||||
this.errorFlag = false;
|
||||
this.sendFlag = true;
|
||||
this.readyStateChange(FakeXDomainRequest.OPENED);
|
||||
|
||||
if (typeof this.onSend == "function") {
|
||||
this.onSend(this);
|
||||
}
|
||||
},
|
||||
|
||||
abort: function abort() {
|
||||
this.aborted = true;
|
||||
this.responseText = null;
|
||||
this.errorFlag = true;
|
||||
|
||||
if (this.readyState > sinon.FakeXDomainRequest.UNSENT && this.sendFlag) {
|
||||
this.readyStateChange(sinon.FakeXDomainRequest.DONE);
|
||||
this.sendFlag = false;
|
||||
}
|
||||
},
|
||||
|
||||
setResponseBody: function setResponseBody(body) {
|
||||
verifyRequestSent(this);
|
||||
verifyResponseBodyType(body);
|
||||
|
||||
var chunkSize = this.chunkSize || 10;
|
||||
var index = 0;
|
||||
this.responseText = "";
|
||||
|
||||
do {
|
||||
this.readyStateChange(FakeXDomainRequest.LOADING);
|
||||
this.responseText += body.substring(index, index + chunkSize);
|
||||
index += chunkSize;
|
||||
} while (index < body.length);
|
||||
|
||||
this.readyStateChange(FakeXDomainRequest.DONE);
|
||||
},
|
||||
|
||||
respond: function respond(status, contentType, body) {
|
||||
// content-type ignored, since XDomainRequest does not carry this
|
||||
// we keep the same syntax for respond(...) as for FakeXMLHttpRequest to ease
|
||||
// test integration across browsers
|
||||
this.status = typeof status == "number" ? status : 200;
|
||||
this.setResponseBody(body || "");
|
||||
},
|
||||
|
||||
simulatetimeout: function simulatetimeout() {
|
||||
this.status = 0;
|
||||
this.isTimeout = true;
|
||||
// Access to this should actually throw an error
|
||||
this.responseText = undefined;
|
||||
this.readyStateChange(FakeXDomainRequest.DONE);
|
||||
}
|
||||
});
|
||||
|
||||
sinon.extend(FakeXDomainRequest, {
|
||||
UNSENT: 0,
|
||||
OPENED: 1,
|
||||
LOADING: 3,
|
||||
DONE: 4
|
||||
});
|
||||
|
||||
sinon.useFakeXDomainRequest = function useFakeXDomainRequest() {
|
||||
sinon.FakeXDomainRequest.restore = function restore(keepOnCreate) {
|
||||
if (xdr.supportsXDR) {
|
||||
global.XDomainRequest = xdr.GlobalXDomainRequest;
|
||||
}
|
||||
|
||||
delete sinon.FakeXDomainRequest.restore;
|
||||
|
||||
if (keepOnCreate !== true) {
|
||||
delete sinon.FakeXDomainRequest.onCreate;
|
||||
}
|
||||
};
|
||||
if (xdr.supportsXDR) {
|
||||
global.XDomainRequest = sinon.FakeXDomainRequest;
|
||||
}
|
||||
return sinon.FakeXDomainRequest;
|
||||
};
|
||||
|
||||
sinon.FakeXDomainRequest = FakeXDomainRequest;
|
||||
}
|
||||
|
||||
var isNode = typeof module !== "undefined" && module.exports && typeof require == "function";
|
||||
var isAMD = typeof define === "function" && typeof define.amd === "object" && define.amd;
|
||||
|
||||
function loadDependencies(require, exports, module) {
|
||||
var sinon = require("./core");
|
||||
require("./event");
|
||||
makeApi(sinon);
|
||||
module.exports = sinon;
|
||||
}
|
||||
|
||||
if (isAMD) {
|
||||
define(loadDependencies);
|
||||
} else if (isNode) {
|
||||
loadDependencies(require, module.exports, module);
|
||||
} else {
|
||||
makeApi(sinon);
|
||||
}
|
||||
})(this);
|
||||
|
||||
return sinon;
|
||||
}));
|
|
@ -6,7 +6,7 @@
|
|||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Loop mocha tests</title>
|
||||
<link rel="stylesheet" media="all" href="../shared/vendor/mocha-2.0.1.css">
|
||||
<link rel="stylesheet" media="all" href="../shared/vendor/mocha-2.2.1.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="mocha">
|
||||
|
@ -29,12 +29,12 @@
|
|||
<script src="../../content/shared/libs/backbone-1.1.2.js"></script>
|
||||
<script src="../../standalone/content/libs/l10n-gaia-02ca67948fe8.js"></script>
|
||||
<!-- test dependencies -->
|
||||
<script src="../shared/vendor/mocha-2.0.1.js"></script>
|
||||
<script src="../shared/vendor/chai-1.9.0.js"></script>
|
||||
<script src="../shared/vendor/sinon-1.12.2.js"></script>
|
||||
<script src="../shared/vendor/mocha-2.2.1.js"></script>
|
||||
<script src="../shared/vendor/chai-2.1.0.js"></script>
|
||||
<script src="../shared/vendor/sinon-1.13.0.js"></script>
|
||||
<script src="../shared/sdk_mock.js"></script>
|
||||
<script>
|
||||
chai.Assertion.includeStack = true;
|
||||
chai.config.includeStack = true;
|
||||
mocha.setup('bdd');
|
||||
</script>
|
||||
<!-- App scripts -->
|
||||
|
|
Загрузка…
Ссылка в новой задаче