Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / karma / lib / launchers / capture_timeout.js
1 var log = require('../logger').create('launcher')
2
3 /**
4  * Kill browser if it does not capture in given `captureTimeout`.
5  */
6 var CaptureTimeoutLauncher = function (timer, captureTimeout) {
7   if (!captureTimeout) {
8     return
9   }
10
11   var self = this
12   var pendingTimeoutId = null
13
14   this.on('start', function () {
15     pendingTimeoutId = timer.setTimeout(function () {
16       pendingTimeoutId = null
17       if (self.state !== self.STATE_BEING_CAPTURED) {
18         return
19       }
20
21       log.warn('%s have not captured in %d ms, killing.', self.name, captureTimeout)
22       self.error = 'timeout'
23       self.kill()
24     }, captureTimeout)
25   })
26
27   this.on('done', function () {
28     if (pendingTimeoutId) {
29       timer.clearTimeout(pendingTimeoutId)
30       pendingTimeoutId = null
31     }
32   })
33 }
34
35 CaptureTimeoutLauncher.decoratorFactory = function (timer,
36   /* config.captureTimeout */ captureTimeout) {
37   return function (launcher) {
38     CaptureTimeoutLauncher.call(launcher, timer, captureTimeout)
39   }
40 }
41
42 CaptureTimeoutLauncher.decoratorFactory.$inject = ['timer', 'config.captureTimeout']
43
44 module.exports = CaptureTimeoutLauncher