interval-braining-ui-asset-pack 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/lib/asset_pack/engine.rb +5 -2
  3. data/lib/asset_pack/version.rb +1 -1
  4. data/vendor/assets/bower_components/angular/angular.js +23377 -0
  5. data/vendor/assets/bower_components/angular-animate/angular-animate.js +1729 -0
  6. data/vendor/assets/bower_components/angular-growl-notifications/dist/growl-notifications.js +241 -0
  7. data/vendor/assets/bower_components/angular-input-match/dist/angular-input-match.js +39 -0
  8. data/vendor/assets/bower_components/angular-messages/angular-messages.js +400 -0
  9. data/vendor/assets/bower_components/angular-mocks/angular-mocks.js +2228 -0
  10. data/vendor/assets/bower_components/angular-resource/angular-resource.js +660 -0
  11. data/vendor/assets/bower_components/angular-sanitize/angular-sanitize.js +640 -0
  12. data/vendor/assets/bower_components/angular-ui-router/release/angular-ui-router.js +3223 -0
  13. data/vendor/assets/bower_components/angular-ui-router-breadcrumbs/dist/angular-ui-router-breadcrumbs.js +82 -0
  14. data/vendor/assets/bower_components/angular-ui-router-helpers/dist/angular-ui-router-helpers.js +52 -0
  15. data/vendor/assets/bower_components/angular-ui-router-hooks-before-state/dist/angular-ui-router-hooks-before-state.js +56 -0
  16. data/vendor/assets/bower_components/angular-validate-in-set/dist/angular-validate-in-set.js +77 -0
  17. data/vendor/assets/bower_components/animate.css/animate.css +3125 -0
  18. data/vendor/assets/bower_components/bootstrap/dist/css/bootstrap.css +5785 -0
  19. data/vendor/assets/bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.eot +0 -0
  20. data/vendor/assets/bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.svg +229 -0
  21. data/vendor/assets/bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf +0 -0
  22. data/vendor/assets/bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.woff +0 -0
  23. data/vendor/assets/bower_components/bootstrap/dist/js/bootstrap.js +1951 -0
  24. data/vendor/assets/bower_components/cardigan/dist/cardigan.css +37 -0
  25. data/vendor/assets/bower_components/cardigan/dist/cardigan.js +239 -0
  26. data/vendor/assets/bower_components/font-awesome-bower/css/font-awesome.css +1338 -0
  27. data/vendor/assets/bower_components/font-awesome-bower/fonts/FontAwesome.otf +0 -0
  28. data/vendor/assets/bower_components/font-awesome-bower/fonts/fontawesome-webfont.eot +0 -0
  29. data/vendor/assets/bower_components/font-awesome-bower/fonts/fontawesome-webfont.svg +414 -0
  30. data/vendor/assets/bower_components/font-awesome-bower/fonts/fontawesome-webfont.ttf +0 -0
  31. data/vendor/assets/bower_components/font-awesome-bower/fonts/fontawesome-webfont.woff +0 -0
  32. data/vendor/assets/bower_components/jquery/dist/jquery.js +9190 -0
  33. data/vendor/assets/bower_components/webfont-OpenSans-Light/dist/OpenSans-Light.css +10 -0
  34. data/vendor/assets/bower_components/webfont-OpenSans-Light/dist/OpenSans-Light.eot +0 -0
  35. data/vendor/assets/bower_components/webfont-OpenSans-Light/dist/OpenSans-Light.svg +1831 -0
  36. data/vendor/assets/bower_components/webfont-OpenSans-Light/dist/OpenSans-Light.ttf +0 -0
  37. data/vendor/assets/bower_components/webfont-OpenSans-Light/dist/OpenSans-Light.woff +0 -0
  38. metadata +36 -2
@@ -0,0 +1,2228 @@
1
+ /**
2
+ * @license AngularJS v1.3.0-build.2991+sha.9025113
3
+ * (c) 2010-2014 Google, Inc. http://angularjs.org
4
+ * License: MIT
5
+ */
6
+ (function(window, angular, undefined) {
7
+
8
+ 'use strict';
9
+
10
+ /**
11
+ * @ngdoc object
12
+ * @name angular.mock
13
+ * @description
14
+ *
15
+ * Namespace from 'angular-mocks.js' which contains testing related code.
16
+ */
17
+ angular.mock = {};
18
+
19
+ /**
20
+ * ! This is a private undocumented service !
21
+ *
22
+ * @name $browser
23
+ *
24
+ * @description
25
+ * This service is a mock implementation of {@link ng.$browser}. It provides fake
26
+ * implementation for commonly used browser apis that are hard to test, e.g. setTimeout, xhr,
27
+ * cookies, etc...
28
+ *
29
+ * The api of this service is the same as that of the real {@link ng.$browser $browser}, except
30
+ * that there are several helper methods available which can be used in tests.
31
+ */
32
+ angular.mock.$BrowserProvider = function() {
33
+ this.$get = function() {
34
+ return new angular.mock.$Browser();
35
+ };
36
+ };
37
+
38
+ angular.mock.$Browser = function() {
39
+ var self = this;
40
+
41
+ this.isMock = true;
42
+ self.$$url = "http://server/";
43
+ self.$$lastUrl = self.$$url; // used by url polling fn
44
+ self.pollFns = [];
45
+
46
+ // TODO(vojta): remove this temporary api
47
+ self.$$completeOutstandingRequest = angular.noop;
48
+ self.$$incOutstandingRequestCount = angular.noop;
49
+
50
+
51
+ // register url polling fn
52
+
53
+ self.onUrlChange = function(listener) {
54
+ self.pollFns.push(
55
+ function() {
56
+ if (self.$$lastUrl != self.$$url) {
57
+ self.$$lastUrl = self.$$url;
58
+ listener(self.$$url);
59
+ }
60
+ }
61
+ );
62
+
63
+ return listener;
64
+ };
65
+
66
+ self.cookieHash = {};
67
+ self.lastCookieHash = {};
68
+ self.deferredFns = [];
69
+ self.deferredNextId = 0;
70
+
71
+ self.defer = function(fn, delay) {
72
+ delay = delay || 0;
73
+ self.deferredFns.push({time:(self.defer.now + delay), fn:fn, id: self.deferredNextId});
74
+ self.deferredFns.sort(function(a,b){ return a.time - b.time;});
75
+ return self.deferredNextId++;
76
+ };
77
+
78
+
79
+ /**
80
+ * @name $browser#defer.now
81
+ *
82
+ * @description
83
+ * Current milliseconds mock time.
84
+ */
85
+ self.defer.now = 0;
86
+
87
+
88
+ self.defer.cancel = function(deferId) {
89
+ var fnIndex;
90
+
91
+ angular.forEach(self.deferredFns, function(fn, index) {
92
+ if (fn.id === deferId) fnIndex = index;
93
+ });
94
+
95
+ if (fnIndex !== undefined) {
96
+ self.deferredFns.splice(fnIndex, 1);
97
+ return true;
98
+ }
99
+
100
+ return false;
101
+ };
102
+
103
+
104
+ /**
105
+ * @name $browser#defer.flush
106
+ *
107
+ * @description
108
+ * Flushes all pending requests and executes the defer callbacks.
109
+ *
110
+ * @param {number=} number of milliseconds to flush. See {@link #defer.now}
111
+ */
112
+ self.defer.flush = function(delay) {
113
+ if (angular.isDefined(delay)) {
114
+ self.defer.now += delay;
115
+ } else {
116
+ if (self.deferredFns.length) {
117
+ self.defer.now = self.deferredFns[self.deferredFns.length-1].time;
118
+ } else {
119
+ throw new Error('No deferred tasks to be flushed');
120
+ }
121
+ }
122
+
123
+ while (self.deferredFns.length && self.deferredFns[0].time <= self.defer.now) {
124
+ self.deferredFns.shift().fn();
125
+ }
126
+ };
127
+
128
+ self.$$baseHref = '';
129
+ self.baseHref = function() {
130
+ return this.$$baseHref;
131
+ };
132
+ };
133
+ angular.mock.$Browser.prototype = {
134
+
135
+ /**
136
+ * @name $browser#poll
137
+ *
138
+ * @description
139
+ * run all fns in pollFns
140
+ */
141
+ poll: function poll() {
142
+ angular.forEach(this.pollFns, function(pollFn){
143
+ pollFn();
144
+ });
145
+ },
146
+
147
+ addPollFn: function(pollFn) {
148
+ this.pollFns.push(pollFn);
149
+ return pollFn;
150
+ },
151
+
152
+ url: function(url, replace) {
153
+ if (url) {
154
+ this.$$url = url;
155
+ return this;
156
+ }
157
+
158
+ return this.$$url;
159
+ },
160
+
161
+ cookies: function(name, value) {
162
+ if (name) {
163
+ if (angular.isUndefined(value)) {
164
+ delete this.cookieHash[name];
165
+ } else {
166
+ if (angular.isString(value) && //strings only
167
+ value.length <= 4096) { //strict cookie storage limits
168
+ this.cookieHash[name] = value;
169
+ }
170
+ }
171
+ } else {
172
+ if (!angular.equals(this.cookieHash, this.lastCookieHash)) {
173
+ this.lastCookieHash = angular.copy(this.cookieHash);
174
+ this.cookieHash = angular.copy(this.cookieHash);
175
+ }
176
+ return this.cookieHash;
177
+ }
178
+ },
179
+
180
+ notifyWhenNoOutstandingRequests: function(fn) {
181
+ fn();
182
+ }
183
+ };
184
+
185
+
186
+ /**
187
+ * @ngdoc provider
188
+ * @name $exceptionHandlerProvider
189
+ *
190
+ * @description
191
+ * Configures the mock implementation of {@link ng.$exceptionHandler} to rethrow or to log errors
192
+ * passed into the `$exceptionHandler`.
193
+ */
194
+
195
+ /**
196
+ * @ngdoc service
197
+ * @name $exceptionHandler
198
+ *
199
+ * @description
200
+ * Mock implementation of {@link ng.$exceptionHandler} that rethrows or logs errors passed
201
+ * into it. See {@link ngMock.$exceptionHandlerProvider $exceptionHandlerProvider} for configuration
202
+ * information.
203
+ *
204
+ *
205
+ * ```js
206
+ * describe('$exceptionHandlerProvider', function() {
207
+ *
208
+ * it('should capture log messages and exceptions', function() {
209
+ *
210
+ * module(function($exceptionHandlerProvider) {
211
+ * $exceptionHandlerProvider.mode('log');
212
+ * });
213
+ *
214
+ * inject(function($log, $exceptionHandler, $timeout) {
215
+ * $timeout(function() { $log.log(1); });
216
+ * $timeout(function() { $log.log(2); throw 'banana peel'; });
217
+ * $timeout(function() { $log.log(3); });
218
+ * expect($exceptionHandler.errors).toEqual([]);
219
+ * expect($log.assertEmpty());
220
+ * $timeout.flush();
221
+ * expect($exceptionHandler.errors).toEqual(['banana peel']);
222
+ * expect($log.log.logs).toEqual([[1], [2], [3]]);
223
+ * });
224
+ * });
225
+ * });
226
+ * ```
227
+ */
228
+
229
+ angular.mock.$ExceptionHandlerProvider = function() {
230
+ var handler;
231
+
232
+ /**
233
+ * @ngdoc method
234
+ * @name $exceptionHandlerProvider#mode
235
+ *
236
+ * @description
237
+ * Sets the logging mode.
238
+ *
239
+ * @param {string} mode Mode of operation, defaults to `rethrow`.
240
+ *
241
+ * - `rethrow`: If any errors are passed into the handler in tests, it typically
242
+ * means that there is a bug in the application or test, so this mock will
243
+ * make these tests fail.
244
+ * - `log`: Sometimes it is desirable to test that an error is thrown, for this case the `log`
245
+ * mode stores an array of errors in `$exceptionHandler.errors`, to allow later
246
+ * assertion of them. See {@link ngMock.$log#assertEmpty assertEmpty()} and
247
+ * {@link ngMock.$log#reset reset()}
248
+ */
249
+ this.mode = function(mode) {
250
+ switch(mode) {
251
+ case 'rethrow':
252
+ handler = function(e) {
253
+ throw e;
254
+ };
255
+ break;
256
+ case 'log':
257
+ var errors = [];
258
+
259
+ handler = function(e) {
260
+ if (arguments.length == 1) {
261
+ errors.push(e);
262
+ } else {
263
+ errors.push([].slice.call(arguments, 0));
264
+ }
265
+ };
266
+
267
+ handler.errors = errors;
268
+ break;
269
+ default:
270
+ throw new Error("Unknown mode '" + mode + "', only 'log'/'rethrow' modes are allowed!");
271
+ }
272
+ };
273
+
274
+ this.$get = function() {
275
+ return handler;
276
+ };
277
+
278
+ this.mode('rethrow');
279
+ };
280
+
281
+
282
+ /**
283
+ * @ngdoc service
284
+ * @name $log
285
+ *
286
+ * @description
287
+ * Mock implementation of {@link ng.$log} that gathers all logged messages in arrays
288
+ * (one array per logging level). These arrays are exposed as `logs` property of each of the
289
+ * level-specific log function, e.g. for level `error` the array is exposed as `$log.error.logs`.
290
+ *
291
+ */
292
+ angular.mock.$LogProvider = function() {
293
+ var debug = true;
294
+
295
+ function concat(array1, array2, index) {
296
+ return array1.concat(Array.prototype.slice.call(array2, index));
297
+ }
298
+
299
+ this.debugEnabled = function(flag) {
300
+ if (angular.isDefined(flag)) {
301
+ debug = flag;
302
+ return this;
303
+ } else {
304
+ return debug;
305
+ }
306
+ };
307
+
308
+ this.$get = function () {
309
+ var $log = {
310
+ log: function() { $log.log.logs.push(concat([], arguments, 0)); },
311
+ warn: function() { $log.warn.logs.push(concat([], arguments, 0)); },
312
+ info: function() { $log.info.logs.push(concat([], arguments, 0)); },
313
+ error: function() { $log.error.logs.push(concat([], arguments, 0)); },
314
+ debug: function() {
315
+ if (debug) {
316
+ $log.debug.logs.push(concat([], arguments, 0));
317
+ }
318
+ }
319
+ };
320
+
321
+ /**
322
+ * @ngdoc method
323
+ * @name $log#reset
324
+ *
325
+ * @description
326
+ * Reset all of the logging arrays to empty.
327
+ */
328
+ $log.reset = function () {
329
+ /**
330
+ * @ngdoc property
331
+ * @name $log#log.logs
332
+ *
333
+ * @description
334
+ * Array of messages logged using {@link ngMock.$log#log}.
335
+ *
336
+ * @example
337
+ * ```js
338
+ * $log.log('Some Log');
339
+ * var first = $log.log.logs.unshift();
340
+ * ```
341
+ */
342
+ $log.log.logs = [];
343
+ /**
344
+ * @ngdoc property
345
+ * @name $log#info.logs
346
+ *
347
+ * @description
348
+ * Array of messages logged using {@link ngMock.$log#info}.
349
+ *
350
+ * @example
351
+ * ```js
352
+ * $log.info('Some Info');
353
+ * var first = $log.info.logs.unshift();
354
+ * ```
355
+ */
356
+ $log.info.logs = [];
357
+ /**
358
+ * @ngdoc property
359
+ * @name $log#warn.logs
360
+ *
361
+ * @description
362
+ * Array of messages logged using {@link ngMock.$log#warn}.
363
+ *
364
+ * @example
365
+ * ```js
366
+ * $log.warn('Some Warning');
367
+ * var first = $log.warn.logs.unshift();
368
+ * ```
369
+ */
370
+ $log.warn.logs = [];
371
+ /**
372
+ * @ngdoc property
373
+ * @name $log#error.logs
374
+ *
375
+ * @description
376
+ * Array of messages logged using {@link ngMock.$log#error}.
377
+ *
378
+ * @example
379
+ * ```js
380
+ * $log.error('Some Error');
381
+ * var first = $log.error.logs.unshift();
382
+ * ```
383
+ */
384
+ $log.error.logs = [];
385
+ /**
386
+ * @ngdoc property
387
+ * @name $log#debug.logs
388
+ *
389
+ * @description
390
+ * Array of messages logged using {@link ngMock.$log#debug}.
391
+ *
392
+ * @example
393
+ * ```js
394
+ * $log.debug('Some Error');
395
+ * var first = $log.debug.logs.unshift();
396
+ * ```
397
+ */
398
+ $log.debug.logs = [];
399
+ };
400
+
401
+ /**
402
+ * @ngdoc method
403
+ * @name $log#assertEmpty
404
+ *
405
+ * @description
406
+ * Assert that the all of the logging methods have no logged messages. If messages present, an
407
+ * exception is thrown.
408
+ */
409
+ $log.assertEmpty = function() {
410
+ var errors = [];
411
+ angular.forEach(['error', 'warn', 'info', 'log', 'debug'], function(logLevel) {
412
+ angular.forEach($log[logLevel].logs, function(log) {
413
+ angular.forEach(log, function (logItem) {
414
+ errors.push('MOCK $log (' + logLevel + '): ' + String(logItem) + '\n' +
415
+ (logItem.stack || ''));
416
+ });
417
+ });
418
+ });
419
+ if (errors.length) {
420
+ errors.unshift("Expected $log to be empty! Either a message was logged unexpectedly, or "+
421
+ "an expected log message was not checked and removed:");
422
+ errors.push('');
423
+ throw new Error(errors.join('\n---------\n'));
424
+ }
425
+ };
426
+
427
+ $log.reset();
428
+ return $log;
429
+ };
430
+ };
431
+
432
+
433
+ /**
434
+ * @ngdoc service
435
+ * @name $interval
436
+ *
437
+ * @description
438
+ * Mock implementation of the $interval service.
439
+ *
440
+ * Use {@link ngMock.$interval#flush `$interval.flush(millis)`} to
441
+ * move forward by `millis` milliseconds and trigger any functions scheduled to run in that
442
+ * time.
443
+ *
444
+ * @param {function()} fn A function that should be called repeatedly.
445
+ * @param {number} delay Number of milliseconds between each function call.
446
+ * @param {number=} [count=0] Number of times to repeat. If not set, or 0, will repeat
447
+ * indefinitely.
448
+ * @param {boolean=} [invokeApply=true] If set to `false` skips model dirty checking, otherwise
449
+ * will invoke `fn` within the {@link ng.$rootScope.Scope#$apply $apply} block.
450
+ * @returns {promise} A promise which will be notified on each iteration.
451
+ */
452
+ angular.mock.$IntervalProvider = function() {
453
+ this.$get = ['$rootScope', '$q',
454
+ function($rootScope, $q) {
455
+ var repeatFns = [],
456
+ nextRepeatId = 0,
457
+ now = 0;
458
+
459
+ var $interval = function(fn, delay, count, invokeApply) {
460
+ var deferred = $q.defer(),
461
+ promise = deferred.promise,
462
+ iteration = 0,
463
+ skipApply = (angular.isDefined(invokeApply) && !invokeApply);
464
+
465
+ count = (angular.isDefined(count)) ? count : 0;
466
+ promise.then(null, null, fn);
467
+
468
+ promise.$$intervalId = nextRepeatId;
469
+
470
+ function tick() {
471
+ deferred.notify(iteration++);
472
+
473
+ if (count > 0 && iteration >= count) {
474
+ var fnIndex;
475
+ deferred.resolve(iteration);
476
+
477
+ angular.forEach(repeatFns, function(fn, index) {
478
+ if (fn.id === promise.$$intervalId) fnIndex = index;
479
+ });
480
+
481
+ if (fnIndex !== undefined) {
482
+ repeatFns.splice(fnIndex, 1);
483
+ }
484
+ }
485
+
486
+ if (!skipApply) $rootScope.$apply();
487
+ }
488
+
489
+ repeatFns.push({
490
+ nextTime:(now + delay),
491
+ delay: delay,
492
+ fn: tick,
493
+ id: nextRepeatId,
494
+ deferred: deferred
495
+ });
496
+ repeatFns.sort(function(a,b){ return a.nextTime - b.nextTime;});
497
+
498
+ nextRepeatId++;
499
+ return promise;
500
+ };
501
+ /**
502
+ * @ngdoc method
503
+ * @name $interval#cancel
504
+ *
505
+ * @description
506
+ * Cancels a task associated with the `promise`.
507
+ *
508
+ * @param {promise} promise A promise from calling the `$interval` function.
509
+ * @returns {boolean} Returns `true` if the task was successfully cancelled.
510
+ */
511
+ $interval.cancel = function(promise) {
512
+ if(!promise) return false;
513
+ var fnIndex;
514
+
515
+ angular.forEach(repeatFns, function(fn, index) {
516
+ if (fn.id === promise.$$intervalId) fnIndex = index;
517
+ });
518
+
519
+ if (fnIndex !== undefined) {
520
+ repeatFns[fnIndex].deferred.reject('canceled');
521
+ repeatFns.splice(fnIndex, 1);
522
+ return true;
523
+ }
524
+
525
+ return false;
526
+ };
527
+
528
+ /**
529
+ * @ngdoc method
530
+ * @name $interval#flush
531
+ * @description
532
+ *
533
+ * Runs interval tasks scheduled to be run in the next `millis` milliseconds.
534
+ *
535
+ * @param {number=} millis maximum timeout amount to flush up until.
536
+ *
537
+ * @return {number} The amount of time moved forward.
538
+ */
539
+ $interval.flush = function(millis) {
540
+ now += millis;
541
+ while (repeatFns.length && repeatFns[0].nextTime <= now) {
542
+ var task = repeatFns[0];
543
+ task.fn();
544
+ task.nextTime += task.delay;
545
+ repeatFns.sort(function(a,b){ return a.nextTime - b.nextTime;});
546
+ }
547
+ return millis;
548
+ };
549
+
550
+ return $interval;
551
+ }];
552
+ };
553
+
554
+
555
+ /* jshint -W101 */
556
+ /* The R_ISO8061_STR regex is never going to fit into the 100 char limit!
557
+ * This directive should go inside the anonymous function but a bug in JSHint means that it would
558
+ * not be enacted early enough to prevent the warning.
559
+ */
560
+ var R_ISO8061_STR = /^(\d{4})-?(\d\d)-?(\d\d)(?:T(\d\d)(?:\:?(\d\d)(?:\:?(\d\d)(?:\.(\d{3}))?)?)?(Z|([+-])(\d\d):?(\d\d)))?$/;
561
+
562
+ function jsonStringToDate(string) {
563
+ var match;
564
+ if (match = string.match(R_ISO8061_STR)) {
565
+ var date = new Date(0),
566
+ tzHour = 0,
567
+ tzMin = 0;
568
+ if (match[9]) {
569
+ tzHour = int(match[9] + match[10]);
570
+ tzMin = int(match[9] + match[11]);
571
+ }
572
+ date.setUTCFullYear(int(match[1]), int(match[2]) - 1, int(match[3]));
573
+ date.setUTCHours(int(match[4]||0) - tzHour,
574
+ int(match[5]||0) - tzMin,
575
+ int(match[6]||0),
576
+ int(match[7]||0));
577
+ return date;
578
+ }
579
+ return string;
580
+ }
581
+
582
+ function int(str) {
583
+ return parseInt(str, 10);
584
+ }
585
+
586
+ function padNumber(num, digits, trim) {
587
+ var neg = '';
588
+ if (num < 0) {
589
+ neg = '-';
590
+ num = -num;
591
+ }
592
+ num = '' + num;
593
+ while(num.length < digits) num = '0' + num;
594
+ if (trim)
595
+ num = num.substr(num.length - digits);
596
+ return neg + num;
597
+ }
598
+
599
+
600
+ /**
601
+ * @ngdoc type
602
+ * @name angular.mock.TzDate
603
+ * @description
604
+ *
605
+ * *NOTE*: this is not an injectable instance, just a globally available mock class of `Date`.
606
+ *
607
+ * Mock of the Date type which has its timezone specified via constructor arg.
608
+ *
609
+ * The main purpose is to create Date-like instances with timezone fixed to the specified timezone
610
+ * offset, so that we can test code that depends on local timezone settings without dependency on
611
+ * the time zone settings of the machine where the code is running.
612
+ *
613
+ * @param {number} offset Offset of the *desired* timezone in hours (fractions will be honored)
614
+ * @param {(number|string)} timestamp Timestamp representing the desired time in *UTC*
615
+ *
616
+ * @example
617
+ * !!!! WARNING !!!!!
618
+ * This is not a complete Date object so only methods that were implemented can be called safely.
619
+ * To make matters worse, TzDate instances inherit stuff from Date via a prototype.
620
+ *
621
+ * We do our best to intercept calls to "unimplemented" methods, but since the list of methods is
622
+ * incomplete we might be missing some non-standard methods. This can result in errors like:
623
+ * "Date.prototype.foo called on incompatible Object".
624
+ *
625
+ * ```js
626
+ * var newYearInBratislava = new TzDate(-1, '2009-12-31T23:00:00Z');
627
+ * newYearInBratislava.getTimezoneOffset() => -60;
628
+ * newYearInBratislava.getFullYear() => 2010;
629
+ * newYearInBratislava.getMonth() => 0;
630
+ * newYearInBratislava.getDate() => 1;
631
+ * newYearInBratislava.getHours() => 0;
632
+ * newYearInBratislava.getMinutes() => 0;
633
+ * newYearInBratislava.getSeconds() => 0;
634
+ * ```
635
+ *
636
+ */
637
+ angular.mock.TzDate = function (offset, timestamp) {
638
+ var self = new Date(0);
639
+ if (angular.isString(timestamp)) {
640
+ var tsStr = timestamp;
641
+
642
+ self.origDate = jsonStringToDate(timestamp);
643
+
644
+ timestamp = self.origDate.getTime();
645
+ if (isNaN(timestamp))
646
+ throw {
647
+ name: "Illegal Argument",
648
+ message: "Arg '" + tsStr + "' passed into TzDate constructor is not a valid date string"
649
+ };
650
+ } else {
651
+ self.origDate = new Date(timestamp);
652
+ }
653
+
654
+ var localOffset = new Date(timestamp).getTimezoneOffset();
655
+ self.offsetDiff = localOffset*60*1000 - offset*1000*60*60;
656
+ self.date = new Date(timestamp + self.offsetDiff);
657
+
658
+ self.getTime = function() {
659
+ return self.date.getTime() - self.offsetDiff;
660
+ };
661
+
662
+ self.toLocaleDateString = function() {
663
+ return self.date.toLocaleDateString();
664
+ };
665
+
666
+ self.getFullYear = function() {
667
+ return self.date.getFullYear();
668
+ };
669
+
670
+ self.getMonth = function() {
671
+ return self.date.getMonth();
672
+ };
673
+
674
+ self.getDate = function() {
675
+ return self.date.getDate();
676
+ };
677
+
678
+ self.getHours = function() {
679
+ return self.date.getHours();
680
+ };
681
+
682
+ self.getMinutes = function() {
683
+ return self.date.getMinutes();
684
+ };
685
+
686
+ self.getSeconds = function() {
687
+ return self.date.getSeconds();
688
+ };
689
+
690
+ self.getMilliseconds = function() {
691
+ return self.date.getMilliseconds();
692
+ };
693
+
694
+ self.getTimezoneOffset = function() {
695
+ return offset * 60;
696
+ };
697
+
698
+ self.getUTCFullYear = function() {
699
+ return self.origDate.getUTCFullYear();
700
+ };
701
+
702
+ self.getUTCMonth = function() {
703
+ return self.origDate.getUTCMonth();
704
+ };
705
+
706
+ self.getUTCDate = function() {
707
+ return self.origDate.getUTCDate();
708
+ };
709
+
710
+ self.getUTCHours = function() {
711
+ return self.origDate.getUTCHours();
712
+ };
713
+
714
+ self.getUTCMinutes = function() {
715
+ return self.origDate.getUTCMinutes();
716
+ };
717
+
718
+ self.getUTCSeconds = function() {
719
+ return self.origDate.getUTCSeconds();
720
+ };
721
+
722
+ self.getUTCMilliseconds = function() {
723
+ return self.origDate.getUTCMilliseconds();
724
+ };
725
+
726
+ self.getDay = function() {
727
+ return self.date.getDay();
728
+ };
729
+
730
+ // provide this method only on browsers that already have it
731
+ if (self.toISOString) {
732
+ self.toISOString = function() {
733
+ return padNumber(self.origDate.getUTCFullYear(), 4) + '-' +
734
+ padNumber(self.origDate.getUTCMonth() + 1, 2) + '-' +
735
+ padNumber(self.origDate.getUTCDate(), 2) + 'T' +
736
+ padNumber(self.origDate.getUTCHours(), 2) + ':' +
737
+ padNumber(self.origDate.getUTCMinutes(), 2) + ':' +
738
+ padNumber(self.origDate.getUTCSeconds(), 2) + '.' +
739
+ padNumber(self.origDate.getUTCMilliseconds(), 3) + 'Z';
740
+ };
741
+ }
742
+
743
+ //hide all methods not implemented in this mock that the Date prototype exposes
744
+ var unimplementedMethods = ['getUTCDay',
745
+ 'getYear', 'setDate', 'setFullYear', 'setHours', 'setMilliseconds',
746
+ 'setMinutes', 'setMonth', 'setSeconds', 'setTime', 'setUTCDate', 'setUTCFullYear',
747
+ 'setUTCHours', 'setUTCMilliseconds', 'setUTCMinutes', 'setUTCMonth', 'setUTCSeconds',
748
+ 'setYear', 'toDateString', 'toGMTString', 'toJSON', 'toLocaleFormat', 'toLocaleString',
749
+ 'toLocaleTimeString', 'toSource', 'toString', 'toTimeString', 'toUTCString', 'valueOf'];
750
+
751
+ angular.forEach(unimplementedMethods, function(methodName) {
752
+ self[methodName] = function() {
753
+ throw new Error("Method '" + methodName + "' is not implemented in the TzDate mock");
754
+ };
755
+ });
756
+
757
+ return self;
758
+ };
759
+
760
+ //make "tzDateInstance instanceof Date" return true
761
+ angular.mock.TzDate.prototype = Date.prototype;
762
+ /* jshint +W101 */
763
+
764
+ angular.mock.animate = angular.module('ngAnimateMock', ['ng'])
765
+
766
+ .config(['$provide', function($provide) {
767
+
768
+ var reflowQueue = [];
769
+ $provide.value('$$animateReflow', function(fn) {
770
+ var index = reflowQueue.length;
771
+ reflowQueue.push(fn);
772
+ return function cancel() {
773
+ reflowQueue.splice(index, 1);
774
+ };
775
+ });
776
+
777
+ $provide.decorator('$animate', ['$delegate', '$$asyncCallback',
778
+ function($delegate, $$asyncCallback) {
779
+ var animate = {
780
+ queue : [],
781
+ enabled : $delegate.enabled,
782
+ triggerCallbacks : function() {
783
+ $$asyncCallback.flush();
784
+ },
785
+ triggerReflow : function() {
786
+ angular.forEach(reflowQueue, function(fn) {
787
+ fn();
788
+ });
789
+ reflowQueue = [];
790
+ }
791
+ };
792
+
793
+ angular.forEach(
794
+ ['enter','leave','move','addClass','removeClass','setClass'], function(method) {
795
+ animate[method] = function() {
796
+ animate.queue.push({
797
+ event : method,
798
+ element : arguments[0],
799
+ args : arguments
800
+ });
801
+ return $delegate[method].apply($delegate, arguments);
802
+ };
803
+ });
804
+
805
+ return animate;
806
+ }]);
807
+
808
+ }]);
809
+
810
+
811
+ /**
812
+ * @ngdoc function
813
+ * @name angular.mock.dump
814
+ * @description
815
+ *
816
+ * *NOTE*: this is not an injectable instance, just a globally available function.
817
+ *
818
+ * Method for serializing common angular objects (scope, elements, etc..) into strings, useful for
819
+ * debugging.
820
+ *
821
+ * This method is also available on window, where it can be used to display objects on debug
822
+ * console.
823
+ *
824
+ * @param {*} object - any object to turn into string.
825
+ * @return {string} a serialized string of the argument
826
+ */
827
+ angular.mock.dump = function(object) {
828
+ return serialize(object);
829
+
830
+ function serialize(object) {
831
+ var out;
832
+
833
+ if (angular.isElement(object)) {
834
+ object = angular.element(object);
835
+ out = angular.element('<div></div>');
836
+ angular.forEach(object, function(element) {
837
+ out.append(angular.element(element).clone());
838
+ });
839
+ out = out.html();
840
+ } else if (angular.isArray(object)) {
841
+ out = [];
842
+ angular.forEach(object, function(o) {
843
+ out.push(serialize(o));
844
+ });
845
+ out = '[ ' + out.join(', ') + ' ]';
846
+ } else if (angular.isObject(object)) {
847
+ if (angular.isFunction(object.$eval) && angular.isFunction(object.$apply)) {
848
+ out = serializeScope(object);
849
+ } else if (object instanceof Error) {
850
+ out = object.stack || ('' + object.name + ': ' + object.message);
851
+ } else {
852
+ // TODO(i): this prevents methods being logged,
853
+ // we should have a better way to serialize objects
854
+ out = angular.toJson(object, true);
855
+ }
856
+ } else {
857
+ out = String(object);
858
+ }
859
+
860
+ return out;
861
+ }
862
+
863
+ function serializeScope(scope, offset) {
864
+ offset = offset || ' ';
865
+ var log = [offset + 'Scope(' + scope.$id + '): {'];
866
+ for ( var key in scope ) {
867
+ if (Object.prototype.hasOwnProperty.call(scope, key) && !key.match(/^(\$|this)/)) {
868
+ log.push(' ' + key + ': ' + angular.toJson(scope[key]));
869
+ }
870
+ }
871
+ var child = scope.$$childHead;
872
+ while(child) {
873
+ log.push(serializeScope(child, offset + ' '));
874
+ child = child.$$nextSibling;
875
+ }
876
+ log.push('}');
877
+ return log.join('\n' + offset);
878
+ }
879
+ };
880
+
881
+ /**
882
+ * @ngdoc service
883
+ * @name $httpBackend
884
+ * @description
885
+ * Fake HTTP backend implementation suitable for unit testing applications that use the
886
+ * {@link ng.$http $http service}.
887
+ *
888
+ * *Note*: For fake HTTP backend implementation suitable for end-to-end testing or backend-less
889
+ * development please see {@link ngMockE2E.$httpBackend e2e $httpBackend mock}.
890
+ *
891
+ * During unit testing, we want our unit tests to run quickly and have no external dependencies so
892
+ * we don’t want to send [XHR](https://developer.mozilla.org/en/xmlhttprequest) or
893
+ * [JSONP](http://en.wikipedia.org/wiki/JSONP) requests to a real server. All we really need is
894
+ * to verify whether a certain request has been sent or not, or alternatively just let the
895
+ * application make requests, respond with pre-trained responses and assert that the end result is
896
+ * what we expect it to be.
897
+ *
898
+ * This mock implementation can be used to respond with static or dynamic responses via the
899
+ * `expect` and `when` apis and their shortcuts (`expectGET`, `whenPOST`, etc).
900
+ *
901
+ * When an Angular application needs some data from a server, it calls the $http service, which
902
+ * sends the request to a real server using $httpBackend service. With dependency injection, it is
903
+ * easy to inject $httpBackend mock (which has the same API as $httpBackend) and use it to verify
904
+ * the requests and respond with some testing data without sending a request to a real server.
905
+ *
906
+ * There are two ways to specify what test data should be returned as http responses by the mock
907
+ * backend when the code under test makes http requests:
908
+ *
909
+ * - `$httpBackend.expect` - specifies a request expectation
910
+ * - `$httpBackend.when` - specifies a backend definition
911
+ *
912
+ *
913
+ * # Request Expectations vs Backend Definitions
914
+ *
915
+ * Request expectations provide a way to make assertions about requests made by the application and
916
+ * to define responses for those requests. The test will fail if the expected requests are not made
917
+ * or they are made in the wrong order.
918
+ *
919
+ * Backend definitions allow you to define a fake backend for your application which doesn't assert
920
+ * if a particular request was made or not, it just returns a trained response if a request is made.
921
+ * The test will pass whether or not the request gets made during testing.
922
+ *
923
+ *
924
+ * <table class="table">
925
+ * <tr><th width="220px"></th><th>Request expectations</th><th>Backend definitions</th></tr>
926
+ * <tr>
927
+ * <th>Syntax</th>
928
+ * <td>.expect(...).respond(...)</td>
929
+ * <td>.when(...).respond(...)</td>
930
+ * </tr>
931
+ * <tr>
932
+ * <th>Typical usage</th>
933
+ * <td>strict unit tests</td>
934
+ * <td>loose (black-box) unit testing</td>
935
+ * </tr>
936
+ * <tr>
937
+ * <th>Fulfills multiple requests</th>
938
+ * <td>NO</td>
939
+ * <td>YES</td>
940
+ * </tr>
941
+ * <tr>
942
+ * <th>Order of requests matters</th>
943
+ * <td>YES</td>
944
+ * <td>NO</td>
945
+ * </tr>
946
+ * <tr>
947
+ * <th>Request required</th>
948
+ * <td>YES</td>
949
+ * <td>NO</td>
950
+ * </tr>
951
+ * <tr>
952
+ * <th>Response required</th>
953
+ * <td>optional (see below)</td>
954
+ * <td>YES</td>
955
+ * </tr>
956
+ * </table>
957
+ *
958
+ * In cases where both backend definitions and request expectations are specified during unit
959
+ * testing, the request expectations are evaluated first.
960
+ *
961
+ * If a request expectation has no response specified, the algorithm will search your backend
962
+ * definitions for an appropriate response.
963
+ *
964
+ * If a request didn't match any expectation or if the expectation doesn't have the response
965
+ * defined, the backend definitions are evaluated in sequential order to see if any of them match
966
+ * the request. The response from the first matched definition is returned.
967
+ *
968
+ *
969
+ * # Flushing HTTP requests
970
+ *
971
+ * The $httpBackend used in production always responds to requests asynchronously. If we preserved
972
+ * this behavior in unit testing, we'd have to create async unit tests, which are hard to write,
973
+ * to follow and to maintain. But neither can the testing mock respond synchronously; that would
974
+ * change the execution of the code under test. For this reason, the mock $httpBackend has a
975
+ * `flush()` method, which allows the test to explicitly flush pending requests. This preserves
976
+ * the async api of the backend, while allowing the test to execute synchronously.
977
+ *
978
+ *
979
+ * # Unit testing with mock $httpBackend
980
+ * The following code shows how to setup and use the mock backend when unit testing a controller.
981
+ * First we create the controller under test:
982
+ *
983
+ ```js
984
+ // The controller code
985
+ function MyController($scope, $http) {
986
+ var authToken;
987
+
988
+ $http.get('/auth.py').success(function(data, status, headers) {
989
+ authToken = headers('A-Token');
990
+ $scope.user = data;
991
+ });
992
+
993
+ $scope.saveMessage = function(message) {
994
+ var headers = { 'Authorization': authToken };
995
+ $scope.status = 'Saving...';
996
+
997
+ $http.post('/add-msg.py', message, { headers: headers } ).success(function(response) {
998
+ $scope.status = '';
999
+ }).error(function() {
1000
+ $scope.status = 'ERROR!';
1001
+ });
1002
+ };
1003
+ }
1004
+ ```
1005
+ *
1006
+ * Now we setup the mock backend and create the test specs:
1007
+ *
1008
+ ```js
1009
+ // testing controller
1010
+ describe('MyController', function() {
1011
+ var $httpBackend, $rootScope, createController;
1012
+
1013
+ beforeEach(inject(function($injector) {
1014
+ // Set up the mock http service responses
1015
+ $httpBackend = $injector.get('$httpBackend');
1016
+ // backend definition common for all tests
1017
+ $httpBackend.when('GET', '/auth.py').respond({userId: 'userX'}, {'A-Token': 'xxx'});
1018
+
1019
+ // Get hold of a scope (i.e. the root scope)
1020
+ $rootScope = $injector.get('$rootScope');
1021
+ // The $controller service is used to create instances of controllers
1022
+ var $controller = $injector.get('$controller');
1023
+
1024
+ createController = function() {
1025
+ return $controller('MyController', {'$scope' : $rootScope });
1026
+ };
1027
+ }));
1028
+
1029
+
1030
+ afterEach(function() {
1031
+ $httpBackend.verifyNoOutstandingExpectation();
1032
+ $httpBackend.verifyNoOutstandingRequest();
1033
+ });
1034
+
1035
+
1036
+ it('should fetch authentication token', function() {
1037
+ $httpBackend.expectGET('/auth.py');
1038
+ var controller = createController();
1039
+ $httpBackend.flush();
1040
+ });
1041
+
1042
+
1043
+ it('should send msg to server', function() {
1044
+ var controller = createController();
1045
+ $httpBackend.flush();
1046
+
1047
+ // now you don’t care about the authentication, but
1048
+ // the controller will still send the request and
1049
+ // $httpBackend will respond without you having to
1050
+ // specify the expectation and response for this request
1051
+
1052
+ $httpBackend.expectPOST('/add-msg.py', 'message content').respond(201, '');
1053
+ $rootScope.saveMessage('message content');
1054
+ expect($rootScope.status).toBe('Saving...');
1055
+ $httpBackend.flush();
1056
+ expect($rootScope.status).toBe('');
1057
+ });
1058
+
1059
+
1060
+ it('should send auth header', function() {
1061
+ var controller = createController();
1062
+ $httpBackend.flush();
1063
+
1064
+ $httpBackend.expectPOST('/add-msg.py', undefined, function(headers) {
1065
+ // check if the header was send, if it wasn't the expectation won't
1066
+ // match the request and the test will fail
1067
+ return headers['Authorization'] == 'xxx';
1068
+ }).respond(201, '');
1069
+
1070
+ $rootScope.saveMessage('whatever');
1071
+ $httpBackend.flush();
1072
+ });
1073
+ });
1074
+ ```
1075
+ */
1076
+ angular.mock.$HttpBackendProvider = function() {
1077
+ this.$get = ['$rootScope', createHttpBackendMock];
1078
+ };
1079
+
1080
+ /**
1081
+ * General factory function for $httpBackend mock.
1082
+ * Returns instance for unit testing (when no arguments specified):
1083
+ * - passing through is disabled
1084
+ * - auto flushing is disabled
1085
+ *
1086
+ * Returns instance for e2e testing (when `$delegate` and `$browser` specified):
1087
+ * - passing through (delegating request to real backend) is enabled
1088
+ * - auto flushing is enabled
1089
+ *
1090
+ * @param {Object=} $delegate Real $httpBackend instance (allow passing through if specified)
1091
+ * @param {Object=} $browser Auto-flushing enabled if specified
1092
+ * @return {Object} Instance of $httpBackend mock
1093
+ */
1094
+ function createHttpBackendMock($rootScope, $delegate, $browser) {
1095
+ var definitions = [],
1096
+ expectations = [],
1097
+ responses = [],
1098
+ responsesPush = angular.bind(responses, responses.push),
1099
+ copy = angular.copy;
1100
+
1101
+ function createResponse(status, data, headers, statusText) {
1102
+ if (angular.isFunction(status)) return status;
1103
+
1104
+ return function() {
1105
+ return angular.isNumber(status)
1106
+ ? [status, data, headers, statusText]
1107
+ : [200, status, data];
1108
+ };
1109
+ }
1110
+
1111
+ // TODO(vojta): change params to: method, url, data, headers, callback
1112
+ function $httpBackend(method, url, data, callback, headers, timeout, withCredentials) {
1113
+ var xhr = new MockXhr(),
1114
+ expectation = expectations[0],
1115
+ wasExpected = false;
1116
+
1117
+ function prettyPrint(data) {
1118
+ return (angular.isString(data) || angular.isFunction(data) || data instanceof RegExp)
1119
+ ? data
1120
+ : angular.toJson(data);
1121
+ }
1122
+
1123
+ function wrapResponse(wrapped) {
1124
+ if (!$browser && timeout && timeout.then) timeout.then(handleTimeout);
1125
+
1126
+ return handleResponse;
1127
+
1128
+ function handleResponse() {
1129
+ var response = wrapped.response(method, url, data, headers);
1130
+ xhr.$$respHeaders = response[2];
1131
+ callback(copy(response[0]), copy(response[1]), xhr.getAllResponseHeaders(),
1132
+ copy(response[3] || ''));
1133
+ }
1134
+
1135
+ function handleTimeout() {
1136
+ for (var i = 0, ii = responses.length; i < ii; i++) {
1137
+ if (responses[i] === handleResponse) {
1138
+ responses.splice(i, 1);
1139
+ callback(-1, undefined, '');
1140
+ break;
1141
+ }
1142
+ }
1143
+ }
1144
+ }
1145
+
1146
+ if (expectation && expectation.match(method, url)) {
1147
+ if (!expectation.matchData(data))
1148
+ throw new Error('Expected ' + expectation + ' with different data\n' +
1149
+ 'EXPECTED: ' + prettyPrint(expectation.data) + '\nGOT: ' + data);
1150
+
1151
+ if (!expectation.matchHeaders(headers))
1152
+ throw new Error('Expected ' + expectation + ' with different headers\n' +
1153
+ 'EXPECTED: ' + prettyPrint(expectation.headers) + '\nGOT: ' +
1154
+ prettyPrint(headers));
1155
+
1156
+ expectations.shift();
1157
+
1158
+ if (expectation.response) {
1159
+ responses.push(wrapResponse(expectation));
1160
+ return;
1161
+ }
1162
+ wasExpected = true;
1163
+ }
1164
+
1165
+ var i = -1, definition;
1166
+ while ((definition = definitions[++i])) {
1167
+ if (definition.match(method, url, data, headers || {})) {
1168
+ if (definition.response) {
1169
+ // if $browser specified, we do auto flush all requests
1170
+ ($browser ? $browser.defer : responsesPush)(wrapResponse(definition));
1171
+ } else if (definition.passThrough) {
1172
+ $delegate(method, url, data, callback, headers, timeout, withCredentials);
1173
+ } else throw new Error('No response defined !');
1174
+ return;
1175
+ }
1176
+ }
1177
+ throw wasExpected ?
1178
+ new Error('No response defined !') :
1179
+ new Error('Unexpected request: ' + method + ' ' + url + '\n' +
1180
+ (expectation ? 'Expected ' + expectation : 'No more request expected'));
1181
+ }
1182
+
1183
+ /**
1184
+ * @ngdoc method
1185
+ * @name $httpBackend#when
1186
+ * @description
1187
+ * Creates a new backend definition.
1188
+ *
1189
+ * @param {string} method HTTP method.
1190
+ * @param {string|RegExp|function(string)} url HTTP url or function that receives the url
1191
+ * and returns true if the url match the current definition.
1192
+ * @param {(string|RegExp|function(string))=} data HTTP request body or function that receives
1193
+ * data string and returns true if the data is as expected.
1194
+ * @param {(Object|function(Object))=} headers HTTP headers or function that receives http header
1195
+ * object and returns true if the headers match the current definition.
1196
+ * @returns {requestHandler} Returns an object with `respond` method that controls how a matched
1197
+ * request is handled.
1198
+ *
1199
+ * - respond –
1200
+ * `{function([status,] data[, headers, statusText])
1201
+ * | function(function(method, url, data, headers)}`
1202
+ * – The respond method takes a set of static data to be returned or a function that can
1203
+ * return an array containing response status (number), response data (string), response
1204
+ * headers (Object), and the text for the status (string).
1205
+ */
1206
+ $httpBackend.when = function(method, url, data, headers) {
1207
+ var definition = new MockHttpExpectation(method, url, data, headers),
1208
+ chain = {
1209
+ respond: function(status, data, headers, statusText) {
1210
+ definition.response = createResponse(status, data, headers, statusText);
1211
+ }
1212
+ };
1213
+
1214
+ if ($browser) {
1215
+ chain.passThrough = function() {
1216
+ definition.passThrough = true;
1217
+ };
1218
+ }
1219
+
1220
+ definitions.push(definition);
1221
+ return chain;
1222
+ };
1223
+
1224
+ /**
1225
+ * @ngdoc method
1226
+ * @name $httpBackend#whenGET
1227
+ * @description
1228
+ * Creates a new backend definition for GET requests. For more info see `when()`.
1229
+ *
1230
+ * @param {string|RegExp|function(string)} url HTTP url or function that receives the url
1231
+ * and returns true if the url match the current definition.
1232
+ * @param {(Object|function(Object))=} headers HTTP headers.
1233
+ * @returns {requestHandler} Returns an object with `respond` method that control how a matched
1234
+ * request is handled.
1235
+ */
1236
+
1237
+ /**
1238
+ * @ngdoc method
1239
+ * @name $httpBackend#whenHEAD
1240
+ * @description
1241
+ * Creates a new backend definition for HEAD requests. For more info see `when()`.
1242
+ *
1243
+ * @param {string|RegExp|function(string)} url HTTP url or function that receives the url
1244
+ * and returns true if the url match the current definition.
1245
+ * @param {(Object|function(Object))=} headers HTTP headers.
1246
+ * @returns {requestHandler} Returns an object with `respond` method that control how a matched
1247
+ * request is handled.
1248
+ */
1249
+
1250
+ /**
1251
+ * @ngdoc method
1252
+ * @name $httpBackend#whenDELETE
1253
+ * @description
1254
+ * Creates a new backend definition for DELETE requests. For more info see `when()`.
1255
+ *
1256
+ * @param {string|RegExp|function(string)} url HTTP url or function that receives the url
1257
+ * and returns true if the url match the current definition.
1258
+ * @param {(Object|function(Object))=} headers HTTP headers.
1259
+ * @returns {requestHandler} Returns an object with `respond` method that control how a matched
1260
+ * request is handled.
1261
+ */
1262
+
1263
+ /**
1264
+ * @ngdoc method
1265
+ * @name $httpBackend#whenPOST
1266
+ * @description
1267
+ * Creates a new backend definition for POST requests. For more info see `when()`.
1268
+ *
1269
+ * @param {string|RegExp|function(string)} url HTTP url or function that receives the url
1270
+ * and returns true if the url match the current definition.
1271
+ * @param {(string|RegExp|function(string))=} data HTTP request body or function that receives
1272
+ * data string and returns true if the data is as expected.
1273
+ * @param {(Object|function(Object))=} headers HTTP headers.
1274
+ * @returns {requestHandler} Returns an object with `respond` method that control how a matched
1275
+ * request is handled.
1276
+ */
1277
+
1278
+ /**
1279
+ * @ngdoc method
1280
+ * @name $httpBackend#whenPUT
1281
+ * @description
1282
+ * Creates a new backend definition for PUT requests. For more info see `when()`.
1283
+ *
1284
+ * @param {string|RegExp|function(string)} url HTTP url or function that receives the url
1285
+ * and returns true if the url match the current definition.
1286
+ * @param {(string|RegExp|function(string))=} data HTTP request body or function that receives
1287
+ * data string and returns true if the data is as expected.
1288
+ * @param {(Object|function(Object))=} headers HTTP headers.
1289
+ * @returns {requestHandler} Returns an object with `respond` method that control how a matched
1290
+ * request is handled.
1291
+ */
1292
+
1293
+ /**
1294
+ * @ngdoc method
1295
+ * @name $httpBackend#whenJSONP
1296
+ * @description
1297
+ * Creates a new backend definition for JSONP requests. For more info see `when()`.
1298
+ *
1299
+ * @param {string|RegExp|function(string)} url HTTP url or function that receives the url
1300
+ * and returns true if the url match the current definition.
1301
+ * @returns {requestHandler} Returns an object with `respond` method that control how a matched
1302
+ * request is handled.
1303
+ */
1304
+ createShortMethods('when');
1305
+
1306
+
1307
+ /**
1308
+ * @ngdoc method
1309
+ * @name $httpBackend#expect
1310
+ * @description
1311
+ * Creates a new request expectation.
1312
+ *
1313
+ * @param {string} method HTTP method.
1314
+ * @param {string|RegExp|function(string)} url HTTP url or function that receives the url
1315
+ * and returns true if the url match the current definition.
1316
+ * @param {(string|RegExp|function(string)|Object)=} data HTTP request body or function that
1317
+ * receives data string and returns true if the data is as expected, or Object if request body
1318
+ * is in JSON format.
1319
+ * @param {(Object|function(Object))=} headers HTTP headers or function that receives http header
1320
+ * object and returns true if the headers match the current expectation.
1321
+ * @returns {requestHandler} Returns an object with `respond` method that control how a matched
1322
+ * request is handled.
1323
+ *
1324
+ * - respond –
1325
+ * `{function([status,] data[, headers, statusText])
1326
+ * | function(function(method, url, data, headers)}`
1327
+ * – The respond method takes a set of static data to be returned or a function that can
1328
+ * return an array containing response status (number), response data (string), response
1329
+ * headers (Object), and the text for the status (string).
1330
+ */
1331
+ $httpBackend.expect = function(method, url, data, headers) {
1332
+ var expectation = new MockHttpExpectation(method, url, data, headers);
1333
+ expectations.push(expectation);
1334
+ return {
1335
+ respond: function (status, data, headers, statusText) {
1336
+ expectation.response = createResponse(status, data, headers, statusText);
1337
+ }
1338
+ };
1339
+ };
1340
+
1341
+
1342
+ /**
1343
+ * @ngdoc method
1344
+ * @name $httpBackend#expectGET
1345
+ * @description
1346
+ * Creates a new request expectation for GET requests. For more info see `expect()`.
1347
+ *
1348
+ * @param {string|RegExp|function(string)} url HTTP url or function that receives the url
1349
+ * and returns true if the url match the current definition.
1350
+ * @param {Object=} headers HTTP headers.
1351
+ * @returns {requestHandler} Returns an object with `respond` method that control how a matched
1352
+ * request is handled. See #expect for more info.
1353
+ */
1354
+
1355
+ /**
1356
+ * @ngdoc method
1357
+ * @name $httpBackend#expectHEAD
1358
+ * @description
1359
+ * Creates a new request expectation for HEAD requests. For more info see `expect()`.
1360
+ *
1361
+ * @param {string|RegExp|function(string)} url HTTP url or function that receives the url
1362
+ * and returns true if the url match the current definition.
1363
+ * @param {Object=} headers HTTP headers.
1364
+ * @returns {requestHandler} Returns an object with `respond` method that control how a matched
1365
+ * request is handled.
1366
+ */
1367
+
1368
+ /**
1369
+ * @ngdoc method
1370
+ * @name $httpBackend#expectDELETE
1371
+ * @description
1372
+ * Creates a new request expectation for DELETE requests. For more info see `expect()`.
1373
+ *
1374
+ * @param {string|RegExp|function(string)} url HTTP url or function that receives the url
1375
+ * and returns true if the url match the current definition.
1376
+ * @param {Object=} headers HTTP headers.
1377
+ * @returns {requestHandler} Returns an object with `respond` method that control how a matched
1378
+ * request is handled.
1379
+ */
1380
+
1381
+ /**
1382
+ * @ngdoc method
1383
+ * @name $httpBackend#expectPOST
1384
+ * @description
1385
+ * Creates a new request expectation for POST requests. For more info see `expect()`.
1386
+ *
1387
+ * @param {string|RegExp|function(string)} url HTTP url or function that receives the url
1388
+ * and returns true if the url match the current definition.
1389
+ * @param {(string|RegExp|function(string)|Object)=} data HTTP request body or function that
1390
+ * receives data string and returns true if the data is as expected, or Object if request body
1391
+ * is in JSON format.
1392
+ * @param {Object=} headers HTTP headers.
1393
+ * @returns {requestHandler} Returns an object with `respond` method that control how a matched
1394
+ * request is handled.
1395
+ */
1396
+
1397
+ /**
1398
+ * @ngdoc method
1399
+ * @name $httpBackend#expectPUT
1400
+ * @description
1401
+ * Creates a new request expectation for PUT requests. For more info see `expect()`.
1402
+ *
1403
+ * @param {string|RegExp|function(string)} url HTTP url or function that receives the url
1404
+ * and returns true if the url match the current definition.
1405
+ * @param {(string|RegExp|function(string)|Object)=} data HTTP request body or function that
1406
+ * receives data string and returns true if the data is as expected, or Object if request body
1407
+ * is in JSON format.
1408
+ * @param {Object=} headers HTTP headers.
1409
+ * @returns {requestHandler} Returns an object with `respond` method that control how a matched
1410
+ * request is handled.
1411
+ */
1412
+
1413
+ /**
1414
+ * @ngdoc method
1415
+ * @name $httpBackend#expectPATCH
1416
+ * @description
1417
+ * Creates a new request expectation for PATCH requests. For more info see `expect()`.
1418
+ *
1419
+ * @param {string|RegExp|function(string)} url HTTP url or function that receives the url
1420
+ * and returns true if the url match the current definition.
1421
+ * @param {(string|RegExp|function(string)|Object)=} data HTTP request body or function that
1422
+ * receives data string and returns true if the data is as expected, or Object if request body
1423
+ * is in JSON format.
1424
+ * @param {Object=} headers HTTP headers.
1425
+ * @returns {requestHandler} Returns an object with `respond` method that control how a matched
1426
+ * request is handled.
1427
+ */
1428
+
1429
+ /**
1430
+ * @ngdoc method
1431
+ * @name $httpBackend#expectJSONP
1432
+ * @description
1433
+ * Creates a new request expectation for JSONP requests. For more info see `expect()`.
1434
+ *
1435
+ * @param {string|RegExp|function(string)} url HTTP url or function that receives the url
1436
+ * and returns true if the url match the current definition.
1437
+ * @returns {requestHandler} Returns an object with `respond` method that control how a matched
1438
+ * request is handled.
1439
+ */
1440
+ createShortMethods('expect');
1441
+
1442
+
1443
+ /**
1444
+ * @ngdoc method
1445
+ * @name $httpBackend#flush
1446
+ * @description
1447
+ * Flushes all pending requests using the trained responses.
1448
+ *
1449
+ * @param {number=} count Number of responses to flush (in the order they arrived). If undefined,
1450
+ * all pending requests will be flushed. If there are no pending requests when the flush method
1451
+ * is called an exception is thrown (as this typically a sign of programming error).
1452
+ */
1453
+ $httpBackend.flush = function(count) {
1454
+ $rootScope.$digest();
1455
+ if (!responses.length) throw new Error('No pending request to flush !');
1456
+
1457
+ if (angular.isDefined(count)) {
1458
+ while (count--) {
1459
+ if (!responses.length) throw new Error('No more pending request to flush !');
1460
+ responses.shift()();
1461
+ }
1462
+ } else {
1463
+ while (responses.length) {
1464
+ responses.shift()();
1465
+ }
1466
+ }
1467
+ $httpBackend.verifyNoOutstandingExpectation();
1468
+ };
1469
+
1470
+
1471
+ /**
1472
+ * @ngdoc method
1473
+ * @name $httpBackend#verifyNoOutstandingExpectation
1474
+ * @description
1475
+ * Verifies that all of the requests defined via the `expect` api were made. If any of the
1476
+ * requests were not made, verifyNoOutstandingExpectation throws an exception.
1477
+ *
1478
+ * Typically, you would call this method following each test case that asserts requests using an
1479
+ * "afterEach" clause.
1480
+ *
1481
+ * ```js
1482
+ * afterEach($httpBackend.verifyNoOutstandingExpectation);
1483
+ * ```
1484
+ */
1485
+ $httpBackend.verifyNoOutstandingExpectation = function() {
1486
+ $rootScope.$digest();
1487
+ if (expectations.length) {
1488
+ throw new Error('Unsatisfied requests: ' + expectations.join(', '));
1489
+ }
1490
+ };
1491
+
1492
+
1493
+ /**
1494
+ * @ngdoc method
1495
+ * @name $httpBackend#verifyNoOutstandingRequest
1496
+ * @description
1497
+ * Verifies that there are no outstanding requests that need to be flushed.
1498
+ *
1499
+ * Typically, you would call this method following each test case that asserts requests using an
1500
+ * "afterEach" clause.
1501
+ *
1502
+ * ```js
1503
+ * afterEach($httpBackend.verifyNoOutstandingRequest);
1504
+ * ```
1505
+ */
1506
+ $httpBackend.verifyNoOutstandingRequest = function() {
1507
+ if (responses.length) {
1508
+ throw new Error('Unflushed requests: ' + responses.length);
1509
+ }
1510
+ };
1511
+
1512
+
1513
+ /**
1514
+ * @ngdoc method
1515
+ * @name $httpBackend#resetExpectations
1516
+ * @description
1517
+ * Resets all request expectations, but preserves all backend definitions. Typically, you would
1518
+ * call resetExpectations during a multiple-phase test when you want to reuse the same instance of
1519
+ * $httpBackend mock.
1520
+ */
1521
+ $httpBackend.resetExpectations = function() {
1522
+ expectations.length = 0;
1523
+ responses.length = 0;
1524
+ };
1525
+
1526
+ return $httpBackend;
1527
+
1528
+
1529
+ function createShortMethods(prefix) {
1530
+ angular.forEach(['GET', 'DELETE', 'JSONP', 'HEAD'], function(method) {
1531
+ $httpBackend[prefix + method] = function(url, headers) {
1532
+ return $httpBackend[prefix](method, url, undefined, headers);
1533
+ };
1534
+ });
1535
+
1536
+ angular.forEach(['PUT', 'POST', 'PATCH'], function(method) {
1537
+ $httpBackend[prefix + method] = function(url, data, headers) {
1538
+ return $httpBackend[prefix](method, url, data, headers);
1539
+ };
1540
+ });
1541
+ }
1542
+ }
1543
+
1544
+ function MockHttpExpectation(method, url, data, headers) {
1545
+
1546
+ this.data = data;
1547
+ this.headers = headers;
1548
+
1549
+ this.match = function(m, u, d, h) {
1550
+ if (method != m) return false;
1551
+ if (!this.matchUrl(u)) return false;
1552
+ if (angular.isDefined(d) && !this.matchData(d)) return false;
1553
+ if (angular.isDefined(h) && !this.matchHeaders(h)) return false;
1554
+ return true;
1555
+ };
1556
+
1557
+ this.matchUrl = function(u) {
1558
+ if (!url) return true;
1559
+ if (angular.isFunction(url.test)) return url.test(u);
1560
+ if (angular.isFunction(url)) return url(u);
1561
+ return url == u;
1562
+ };
1563
+
1564
+ this.matchHeaders = function(h) {
1565
+ if (angular.isUndefined(headers)) return true;
1566
+ if (angular.isFunction(headers)) return headers(h);
1567
+ return angular.equals(headers, h);
1568
+ };
1569
+
1570
+ this.matchData = function(d) {
1571
+ if (angular.isUndefined(data)) return true;
1572
+ if (data && angular.isFunction(data.test)) return data.test(d);
1573
+ if (data && angular.isFunction(data)) return data(d);
1574
+ if (data && !angular.isString(data)) return angular.equals(data, angular.fromJson(d));
1575
+ return data == d;
1576
+ };
1577
+
1578
+ this.toString = function() {
1579
+ return method + ' ' + url;
1580
+ };
1581
+ }
1582
+
1583
+ function createMockXhr() {
1584
+ return new MockXhr();
1585
+ }
1586
+
1587
+ function MockXhr() {
1588
+
1589
+ // hack for testing $http, $httpBackend
1590
+ MockXhr.$$lastInstance = this;
1591
+
1592
+ this.open = function(method, url, async) {
1593
+ this.$$method = method;
1594
+ this.$$url = url;
1595
+ this.$$async = async;
1596
+ this.$$reqHeaders = {};
1597
+ this.$$respHeaders = {};
1598
+ };
1599
+
1600
+ this.send = function(data) {
1601
+ this.$$data = data;
1602
+ };
1603
+
1604
+ this.setRequestHeader = function(key, value) {
1605
+ this.$$reqHeaders[key] = value;
1606
+ };
1607
+
1608
+ this.getResponseHeader = function(name) {
1609
+ // the lookup must be case insensitive,
1610
+ // that's why we try two quick lookups first and full scan last
1611
+ var header = this.$$respHeaders[name];
1612
+ if (header) return header;
1613
+
1614
+ name = angular.lowercase(name);
1615
+ header = this.$$respHeaders[name];
1616
+ if (header) return header;
1617
+
1618
+ header = undefined;
1619
+ angular.forEach(this.$$respHeaders, function(headerVal, headerName) {
1620
+ if (!header && angular.lowercase(headerName) == name) header = headerVal;
1621
+ });
1622
+ return header;
1623
+ };
1624
+
1625
+ this.getAllResponseHeaders = function() {
1626
+ var lines = [];
1627
+
1628
+ angular.forEach(this.$$respHeaders, function(value, key) {
1629
+ lines.push(key + ': ' + value);
1630
+ });
1631
+ return lines.join('\n');
1632
+ };
1633
+
1634
+ this.abort = angular.noop;
1635
+ }
1636
+
1637
+
1638
+ /**
1639
+ * @ngdoc service
1640
+ * @name $timeout
1641
+ * @description
1642
+ *
1643
+ * This service is just a simple decorator for {@link ng.$timeout $timeout} service
1644
+ * that adds a "flush" and "verifyNoPendingTasks" methods.
1645
+ */
1646
+
1647
+ angular.mock.$TimeoutDecorator = ['$delegate', '$browser', function ($delegate, $browser) {
1648
+
1649
+ /**
1650
+ * @ngdoc method
1651
+ * @name $timeout#flush
1652
+ * @description
1653
+ *
1654
+ * Flushes the queue of pending tasks.
1655
+ *
1656
+ * @param {number=} delay maximum timeout amount to flush up until
1657
+ */
1658
+ $delegate.flush = function(delay) {
1659
+ $browser.defer.flush(delay);
1660
+ };
1661
+
1662
+ /**
1663
+ * @ngdoc method
1664
+ * @name $timeout#verifyNoPendingTasks
1665
+ * @description
1666
+ *
1667
+ * Verifies that there are no pending tasks that need to be flushed.
1668
+ */
1669
+ $delegate.verifyNoPendingTasks = function() {
1670
+ if ($browser.deferredFns.length) {
1671
+ throw new Error('Deferred tasks to flush (' + $browser.deferredFns.length + '): ' +
1672
+ formatPendingTasksAsString($browser.deferredFns));
1673
+ }
1674
+ };
1675
+
1676
+ function formatPendingTasksAsString(tasks) {
1677
+ var result = [];
1678
+ angular.forEach(tasks, function(task) {
1679
+ result.push('{id: ' + task.id + ', ' + 'time: ' + task.time + '}');
1680
+ });
1681
+
1682
+ return result.join(', ');
1683
+ }
1684
+
1685
+ return $delegate;
1686
+ }];
1687
+
1688
+ angular.mock.$RAFDecorator = ['$delegate', function($delegate) {
1689
+ var queue = [];
1690
+ var rafFn = function(fn) {
1691
+ var index = queue.length;
1692
+ queue.push(fn);
1693
+ return function() {
1694
+ queue.splice(index, 1);
1695
+ };
1696
+ };
1697
+
1698
+ rafFn.supported = $delegate.supported;
1699
+
1700
+ rafFn.flush = function() {
1701
+ if(queue.length === 0) {
1702
+ throw new Error('No rAF callbacks present');
1703
+ }
1704
+
1705
+ var length = queue.length;
1706
+ for(var i=0;i<length;i++) {
1707
+ queue[i]();
1708
+ }
1709
+
1710
+ queue = [];
1711
+ };
1712
+
1713
+ return rafFn;
1714
+ }];
1715
+
1716
+ angular.mock.$AsyncCallbackDecorator = ['$delegate', function($delegate) {
1717
+ var callbacks = [];
1718
+ var addFn = function(fn) {
1719
+ callbacks.push(fn);
1720
+ };
1721
+ addFn.flush = function() {
1722
+ angular.forEach(callbacks, function(fn) {
1723
+ fn();
1724
+ });
1725
+ callbacks = [];
1726
+ };
1727
+ return addFn;
1728
+ }];
1729
+
1730
+ /**
1731
+ *
1732
+ */
1733
+ angular.mock.$RootElementProvider = function() {
1734
+ this.$get = function() {
1735
+ return angular.element('<div ng-app></div>');
1736
+ };
1737
+ };
1738
+
1739
+ /**
1740
+ * @ngdoc module
1741
+ * @name ngMock
1742
+ * @packageName angular-mocks
1743
+ * @description
1744
+ *
1745
+ * # ngMock
1746
+ *
1747
+ * The `ngMock` module provides support to inject and mock Angular services into unit tests.
1748
+ * In addition, ngMock also extends various core ng services such that they can be
1749
+ * inspected and controlled in a synchronous manner within test code.
1750
+ *
1751
+ *
1752
+ * <div doc-module-components="ngMock"></div>
1753
+ *
1754
+ */
1755
+ angular.module('ngMock', ['ng']).provider({
1756
+ $browser: angular.mock.$BrowserProvider,
1757
+ $exceptionHandler: angular.mock.$ExceptionHandlerProvider,
1758
+ $log: angular.mock.$LogProvider,
1759
+ $interval: angular.mock.$IntervalProvider,
1760
+ $httpBackend: angular.mock.$HttpBackendProvider,
1761
+ $rootElement: angular.mock.$RootElementProvider
1762
+ }).config(['$provide', function($provide) {
1763
+ $provide.decorator('$timeout', angular.mock.$TimeoutDecorator);
1764
+ $provide.decorator('$$rAF', angular.mock.$RAFDecorator);
1765
+ $provide.decorator('$$asyncCallback', angular.mock.$AsyncCallbackDecorator);
1766
+ }]);
1767
+
1768
+ /**
1769
+ * @ngdoc module
1770
+ * @name ngMockE2E
1771
+ * @module ngMockE2E
1772
+ * @packageName angular-mocks
1773
+ * @description
1774
+ *
1775
+ * The `ngMockE2E` is an angular module which contains mocks suitable for end-to-end testing.
1776
+ * Currently there is only one mock present in this module -
1777
+ * the {@link ngMockE2E.$httpBackend e2e $httpBackend} mock.
1778
+ */
1779
+ angular.module('ngMockE2E', ['ng']).config(['$provide', function($provide) {
1780
+ $provide.decorator('$httpBackend', angular.mock.e2e.$httpBackendDecorator);
1781
+ }]);
1782
+
1783
+ /**
1784
+ * @ngdoc service
1785
+ * @name $httpBackend
1786
+ * @module ngMockE2E
1787
+ * @description
1788
+ * Fake HTTP backend implementation suitable for end-to-end testing or backend-less development of
1789
+ * applications that use the {@link ng.$http $http service}.
1790
+ *
1791
+ * *Note*: For fake http backend implementation suitable for unit testing please see
1792
+ * {@link ngMock.$httpBackend unit-testing $httpBackend mock}.
1793
+ *
1794
+ * This implementation can be used to respond with static or dynamic responses via the `when` api
1795
+ * and its shortcuts (`whenGET`, `whenPOST`, etc) and optionally pass through requests to the
1796
+ * real $httpBackend for specific requests (e.g. to interact with certain remote apis or to fetch
1797
+ * templates from a webserver).
1798
+ *
1799
+ * As opposed to unit-testing, in an end-to-end testing scenario or in scenario when an application
1800
+ * is being developed with the real backend api replaced with a mock, it is often desirable for
1801
+ * certain category of requests to bypass the mock and issue a real http request (e.g. to fetch
1802
+ * templates or static files from the webserver). To configure the backend with this behavior
1803
+ * use the `passThrough` request handler of `when` instead of `respond`.
1804
+ *
1805
+ * Additionally, we don't want to manually have to flush mocked out requests like we do during unit
1806
+ * testing. For this reason the e2e $httpBackend automatically flushes mocked out requests
1807
+ * automatically, closely simulating the behavior of the XMLHttpRequest object.
1808
+ *
1809
+ * To setup the application to run with this http backend, you have to create a module that depends
1810
+ * on the `ngMockE2E` and your application modules and defines the fake backend:
1811
+ *
1812
+ * ```js
1813
+ * myAppDev = angular.module('myAppDev', ['myApp', 'ngMockE2E']);
1814
+ * myAppDev.run(function($httpBackend) {
1815
+ * phones = [{name: 'phone1'}, {name: 'phone2'}];
1816
+ *
1817
+ * // returns the current list of phones
1818
+ * $httpBackend.whenGET('/phones').respond(phones);
1819
+ *
1820
+ * // adds a new phone to the phones array
1821
+ * $httpBackend.whenPOST('/phones').respond(function(method, url, data) {
1822
+ * var phone = angular.fromJson(data);
1823
+ * phones.push(phone);
1824
+ * return [200, phone, {}];
1825
+ * });
1826
+ * $httpBackend.whenGET(/^\/templates\//).passThrough();
1827
+ * //...
1828
+ * });
1829
+ * ```
1830
+ *
1831
+ * Afterwards, bootstrap your app with this new module.
1832
+ */
1833
+
1834
+ /**
1835
+ * @ngdoc method
1836
+ * @name $httpBackend#when
1837
+ * @module ngMockE2E
1838
+ * @description
1839
+ * Creates a new backend definition.
1840
+ *
1841
+ * @param {string} method HTTP method.
1842
+ * @param {string|RegExp|function(string)} url HTTP url or function that receives the url
1843
+ * and returns true if the url match the current definition.
1844
+ * @param {(string|RegExp)=} data HTTP request body.
1845
+ * @param {(Object|function(Object))=} headers HTTP headers or function that receives http header
1846
+ * object and returns true if the headers match the current definition.
1847
+ * @returns {requestHandler} Returns an object with `respond` and `passThrough` methods that
1848
+ * control how a matched request is handled.
1849
+ *
1850
+ * - respond –
1851
+ * `{function([status,] data[, headers, statusText])
1852
+ * | function(function(method, url, data, headers)}`
1853
+ * – The respond method takes a set of static data to be returned or a function that can return
1854
+ * an array containing response status (number), response data (string), response headers
1855
+ * (Object), and the text for the status (string).
1856
+ * - passThrough – `{function()}` – Any request matching a backend definition with
1857
+ * `passThrough` handler will be passed through to the real backend (an XHR request will be made
1858
+ * to the server.)
1859
+ */
1860
+
1861
+ /**
1862
+ * @ngdoc method
1863
+ * @name $httpBackend#whenGET
1864
+ * @module ngMockE2E
1865
+ * @description
1866
+ * Creates a new backend definition for GET requests. For more info see `when()`.
1867
+ *
1868
+ * @param {string|RegExp|function(string)} url HTTP url or function that receives the url
1869
+ * and returns true if the url match the current definition.
1870
+ * @param {(Object|function(Object))=} headers HTTP headers.
1871
+ * @returns {requestHandler} Returns an object with `respond` and `passThrough` methods that
1872
+ * control how a matched request is handled.
1873
+ */
1874
+
1875
+ /**
1876
+ * @ngdoc method
1877
+ * @name $httpBackend#whenHEAD
1878
+ * @module ngMockE2E
1879
+ * @description
1880
+ * Creates a new backend definition for HEAD requests. For more info see `when()`.
1881
+ *
1882
+ * @param {string|RegExp|function(string)} url HTTP url or function that receives the url
1883
+ * and returns true if the url match the current definition.
1884
+ * @param {(Object|function(Object))=} headers HTTP headers.
1885
+ * @returns {requestHandler} Returns an object with `respond` and `passThrough` methods that
1886
+ * control how a matched request is handled.
1887
+ */
1888
+
1889
+ /**
1890
+ * @ngdoc method
1891
+ * @name $httpBackend#whenDELETE
1892
+ * @module ngMockE2E
1893
+ * @description
1894
+ * Creates a new backend definition for DELETE requests. For more info see `when()`.
1895
+ *
1896
+ * @param {string|RegExp|function(string)} url HTTP url or function that receives the url
1897
+ * and returns true if the url match the current definition.
1898
+ * @param {(Object|function(Object))=} headers HTTP headers.
1899
+ * @returns {requestHandler} Returns an object with `respond` and `passThrough` methods that
1900
+ * control how a matched request is handled.
1901
+ */
1902
+
1903
+ /**
1904
+ * @ngdoc method
1905
+ * @name $httpBackend#whenPOST
1906
+ * @module ngMockE2E
1907
+ * @description
1908
+ * Creates a new backend definition for POST requests. For more info see `when()`.
1909
+ *
1910
+ * @param {string|RegExp|function(string)} url HTTP url or function that receives the url
1911
+ * and returns true if the url match the current definition.
1912
+ * @param {(string|RegExp)=} data HTTP request body.
1913
+ * @param {(Object|function(Object))=} headers HTTP headers.
1914
+ * @returns {requestHandler} Returns an object with `respond` and `passThrough` methods that
1915
+ * control how a matched request is handled.
1916
+ */
1917
+
1918
+ /**
1919
+ * @ngdoc method
1920
+ * @name $httpBackend#whenPUT
1921
+ * @module ngMockE2E
1922
+ * @description
1923
+ * Creates a new backend definition for PUT requests. For more info see `when()`.
1924
+ *
1925
+ * @param {string|RegExp|function(string)} url HTTP url or function that receives the url
1926
+ * and returns true if the url match the current definition.
1927
+ * @param {(string|RegExp)=} data HTTP request body.
1928
+ * @param {(Object|function(Object))=} headers HTTP headers.
1929
+ * @returns {requestHandler} Returns an object with `respond` and `passThrough` methods that
1930
+ * control how a matched request is handled.
1931
+ */
1932
+
1933
+ /**
1934
+ * @ngdoc method
1935
+ * @name $httpBackend#whenPATCH
1936
+ * @module ngMockE2E
1937
+ * @description
1938
+ * Creates a new backend definition for PATCH requests. For more info see `when()`.
1939
+ *
1940
+ * @param {string|RegExp|function(string)} url HTTP url or function that receives the url
1941
+ * and returns true if the url match the current definition.
1942
+ * @param {(string|RegExp)=} data HTTP request body.
1943
+ * @param {(Object|function(Object))=} headers HTTP headers.
1944
+ * @returns {requestHandler} Returns an object with `respond` and `passThrough` methods that
1945
+ * control how a matched request is handled.
1946
+ */
1947
+
1948
+ /**
1949
+ * @ngdoc method
1950
+ * @name $httpBackend#whenJSONP
1951
+ * @module ngMockE2E
1952
+ * @description
1953
+ * Creates a new backend definition for JSONP requests. For more info see `when()`.
1954
+ *
1955
+ * @param {string|RegExp|function(string)} url HTTP url or function that receives the url
1956
+ * and returns true if the url match the current definition.
1957
+ * @returns {requestHandler} Returns an object with `respond` and `passThrough` methods that
1958
+ * control how a matched request is handled.
1959
+ */
1960
+ angular.mock.e2e = {};
1961
+ angular.mock.e2e.$httpBackendDecorator =
1962
+ ['$rootScope', '$delegate', '$browser', createHttpBackendMock];
1963
+
1964
+
1965
+ angular.mock.clearDataCache = function() {
1966
+ var key,
1967
+ cache = angular.element.cache;
1968
+
1969
+ for(key in cache) {
1970
+ if (Object.prototype.hasOwnProperty.call(cache,key)) {
1971
+ var handle = cache[key].handle;
1972
+
1973
+ handle && angular.element(handle.elem).off();
1974
+ delete cache[key];
1975
+ }
1976
+ }
1977
+ };
1978
+
1979
+
1980
+ if(window.jasmine || window.mocha) {
1981
+
1982
+ var currentSpec = null,
1983
+ isSpecRunning = function() {
1984
+ return !!currentSpec;
1985
+ };
1986
+
1987
+
1988
+ (window.beforeEach || window.setup)(function() {
1989
+ currentSpec = this;
1990
+ });
1991
+
1992
+ (window.afterEach || window.teardown)(function() {
1993
+ var injector = currentSpec.$injector;
1994
+
1995
+ angular.forEach(currentSpec.$modules, function(module) {
1996
+ if (module && module.$$hashKey) {
1997
+ module.$$hashKey = undefined;
1998
+ }
1999
+ });
2000
+
2001
+ currentSpec.$injector = null;
2002
+ currentSpec.$modules = null;
2003
+ currentSpec = null;
2004
+
2005
+ if (injector) {
2006
+ injector.get('$rootElement').off();
2007
+ injector.get('$browser').pollFns.length = 0;
2008
+ }
2009
+
2010
+ angular.mock.clearDataCache();
2011
+
2012
+ // clean up jquery's fragment cache
2013
+ angular.forEach(angular.element.fragments, function(val, key) {
2014
+ delete angular.element.fragments[key];
2015
+ });
2016
+
2017
+ MockXhr.$$lastInstance = null;
2018
+
2019
+ angular.forEach(angular.callbacks, function(val, key) {
2020
+ delete angular.callbacks[key];
2021
+ });
2022
+ angular.callbacks.counter = 0;
2023
+ });
2024
+
2025
+ /**
2026
+ * @ngdoc function
2027
+ * @name angular.mock.module
2028
+ * @description
2029
+ *
2030
+ * *NOTE*: This function is also published on window for easy access.<br>
2031
+ *
2032
+ * This function registers a module configuration code. It collects the configuration information
2033
+ * which will be used when the injector is created by {@link angular.mock.inject inject}.
2034
+ *
2035
+ * See {@link angular.mock.inject inject} for usage example
2036
+ *
2037
+ * @param {...(string|Function|Object)} fns any number of modules which are represented as string
2038
+ * aliases or as anonymous module initialization functions. The modules are used to
2039
+ * configure the injector. The 'ng' and 'ngMock' modules are automatically loaded. If an
2040
+ * object literal is passed they will be registered as values in the module, the key being
2041
+ * the module name and the value being what is returned.
2042
+ */
2043
+ window.module = angular.mock.module = function() {
2044
+ var moduleFns = Array.prototype.slice.call(arguments, 0);
2045
+ return isSpecRunning() ? workFn() : workFn;
2046
+ /////////////////////
2047
+ function workFn() {
2048
+ if (currentSpec.$injector) {
2049
+ throw new Error('Injector already created, can not register a module!');
2050
+ } else {
2051
+ var modules = currentSpec.$modules || (currentSpec.$modules = []);
2052
+ angular.forEach(moduleFns, function(module) {
2053
+ if (angular.isObject(module) && !angular.isArray(module)) {
2054
+ modules.push(function($provide) {
2055
+ angular.forEach(module, function(value, key) {
2056
+ $provide.value(key, value);
2057
+ });
2058
+ });
2059
+ } else {
2060
+ modules.push(module);
2061
+ }
2062
+ });
2063
+ }
2064
+ }
2065
+ };
2066
+
2067
+ /**
2068
+ * @ngdoc function
2069
+ * @name angular.mock.inject
2070
+ * @description
2071
+ *
2072
+ * *NOTE*: This function is also published on window for easy access.<br>
2073
+ *
2074
+ * The inject function wraps a function into an injectable function. The inject() creates new
2075
+ * instance of {@link auto.$injector $injector} per test, which is then used for
2076
+ * resolving references.
2077
+ *
2078
+ *
2079
+ * ## Resolving References (Underscore Wrapping)
2080
+ * Often, we would like to inject a reference once, in a `beforeEach()` block and reuse this
2081
+ * in multiple `it()` clauses. To be able to do this we must assign the reference to a variable
2082
+ * that is declared in the scope of the `describe()` block. Since we would, most likely, want
2083
+ * the variable to have the same name of the reference we have a problem, since the parameter
2084
+ * to the `inject()` function would hide the outer variable.
2085
+ *
2086
+ * To help with this, the injected parameters can, optionally, be enclosed with underscores.
2087
+ * These are ignored by the injector when the reference name is resolved.
2088
+ *
2089
+ * For example, the parameter `_myService_` would be resolved as the reference `myService`.
2090
+ * Since it is available in the function body as _myService_, we can then assign it to a variable
2091
+ * defined in an outer scope.
2092
+ *
2093
+ * ```
2094
+ * // Defined out reference variable outside
2095
+ * var myService;
2096
+ *
2097
+ * // Wrap the parameter in underscores
2098
+ * beforeEach( inject( function(_myService_){
2099
+ * myService = _myService_;
2100
+ * }));
2101
+ *
2102
+ * // Use myService in a series of tests.
2103
+ * it('makes use of myService', function() {
2104
+ * myService.doStuff();
2105
+ * });
2106
+ *
2107
+ * ```
2108
+ *
2109
+ * See also {@link angular.mock.module angular.mock.module}
2110
+ *
2111
+ * ## Example
2112
+ * Example of what a typical jasmine tests looks like with the inject method.
2113
+ * ```js
2114
+ *
2115
+ * angular.module('myApplicationModule', [])
2116
+ * .value('mode', 'app')
2117
+ * .value('version', 'v1.0.1');
2118
+ *
2119
+ *
2120
+ * describe('MyApp', function() {
2121
+ *
2122
+ * // You need to load modules that you want to test,
2123
+ * // it loads only the "ng" module by default.
2124
+ * beforeEach(module('myApplicationModule'));
2125
+ *
2126
+ *
2127
+ * // inject() is used to inject arguments of all given functions
2128
+ * it('should provide a version', inject(function(mode, version) {
2129
+ * expect(version).toEqual('v1.0.1');
2130
+ * expect(mode).toEqual('app');
2131
+ * }));
2132
+ *
2133
+ *
2134
+ * // The inject and module method can also be used inside of the it or beforeEach
2135
+ * it('should override a version and test the new version is injected', function() {
2136
+ * // module() takes functions or strings (module aliases)
2137
+ * module(function($provide) {
2138
+ * $provide.value('version', 'overridden'); // override version here
2139
+ * });
2140
+ *
2141
+ * inject(function(version) {
2142
+ * expect(version).toEqual('overridden');
2143
+ * });
2144
+ * });
2145
+ * });
2146
+ *
2147
+ * ```
2148
+ *
2149
+ * @param {...Function} fns any number of functions which will be injected using the injector.
2150
+ */
2151
+
2152
+
2153
+
2154
+ var ErrorAddingDeclarationLocationStack = function(e, errorForStack) {
2155
+ this.message = e.message;
2156
+ this.name = e.name;
2157
+ if (e.line) this.line = e.line;
2158
+ if (e.sourceId) this.sourceId = e.sourceId;
2159
+ if (e.stack && errorForStack)
2160
+ this.stack = e.stack + '\n' + errorForStack.stack;
2161
+ if (e.stackArray) this.stackArray = e.stackArray;
2162
+ };
2163
+ ErrorAddingDeclarationLocationStack.prototype.toString = Error.prototype.toString;
2164
+
2165
+ window.inject = angular.mock.inject = function() {
2166
+ var blockFns = Array.prototype.slice.call(arguments, 0);
2167
+ var errorForStack = new Error('Declaration Location');
2168
+ return isSpecRunning() ? workFn.call(currentSpec) : workFn;
2169
+ /////////////////////
2170
+ function workFn() {
2171
+ var modules = currentSpec.$modules || [];
2172
+ var strictDi = !!currentSpec.$injectorStrict;
2173
+ modules.unshift('ngMock');
2174
+ modules.unshift('ng');
2175
+ var injector = currentSpec.$injector;
2176
+ if (!injector) {
2177
+ if (strictDi) {
2178
+ // If strictDi is enabled, annotate the providerInjector blocks
2179
+ angular.forEach(modules, function(moduleFn) {
2180
+ if (typeof moduleFn === "function") {
2181
+ angular.injector.$$annotate(moduleFn);
2182
+ }
2183
+ });
2184
+ }
2185
+ injector = currentSpec.$injector = angular.injector(modules, strictDi);
2186
+ currentSpec.$injectorStrict = strictDi;
2187
+ }
2188
+ for(var i = 0, ii = blockFns.length; i < ii; i++) {
2189
+ if (currentSpec.$injectorStrict) {
2190
+ // If the injector is strict / strictDi, and the spec wants to inject using automatic
2191
+ // annotation, then annotate the function here.
2192
+ injector.annotate(blockFns[i]);
2193
+ }
2194
+ try {
2195
+ /* jshint -W040 *//* Jasmine explicitly provides a `this` object when calling functions */
2196
+ injector.invoke(blockFns[i] || angular.noop, this);
2197
+ /* jshint +W040 */
2198
+ } catch (e) {
2199
+ if (e.stack && errorForStack) {
2200
+ throw new ErrorAddingDeclarationLocationStack(e, errorForStack);
2201
+ }
2202
+ throw e;
2203
+ } finally {
2204
+ errorForStack = null;
2205
+ }
2206
+ }
2207
+ }
2208
+ };
2209
+
2210
+
2211
+ angular.mock.inject.strictDi = function(value) {
2212
+ value = arguments.length ? !!value : true;
2213
+ return isSpecRunning() ? workFn() : workFn;
2214
+
2215
+ function workFn() {
2216
+ if (value !== currentSpec.$injectorStrict) {
2217
+ if (currentSpec.$injector) {
2218
+ throw new Error('Injector already created, can not modify strict annotations');
2219
+ } else {
2220
+ currentSpec.$injectorStrict = value;
2221
+ }
2222
+ }
2223
+ }
2224
+ };
2225
+ }
2226
+
2227
+
2228
+ })(window, window.angular);