* @param {object} window The global window object. * @param {object} document jQuery wrapped document. * @param {function()} XHR XMLHttpRequest constructor. * @param {object} $log console.log or an object with the same interface. * @param {object} $sniffer $sniffer service
(window, document, $log, $sniffer)
| 4387 | * @param {object} $sniffer $sniffer service |
| 4388 | */ |
| 4389 | function Browser(window, document, $log, $sniffer) { |
| 4390 | var self = this, |
| 4391 | rawDocument = document[0], |
| 4392 | location = window.location, |
| 4393 | history = window.history, |
| 4394 | setTimeout = window.setTimeout, |
| 4395 | clearTimeout = window.clearTimeout, |
| 4396 | pendingDeferIds = {}; |
| 4397 | |
| 4398 | self.isMock = false; |
| 4399 | |
| 4400 | var outstandingRequestCount = 0; |
| 4401 | var outstandingRequestCallbacks = []; |
| 4402 | |
| 4403 | // TODO(vojta): remove this temporary api |
| 4404 | self.$$completeOutstandingRequest = completeOutstandingRequest; |
| 4405 | self.$$incOutstandingRequestCount = function() { outstandingRequestCount++; }; |
| 4406 | |
| 4407 | /** |
| 4408 | * Executes the `fn` function(supports currying) and decrements the `outstandingRequestCallbacks` |
| 4409 | * counter. If the counter reaches 0, all the `outstandingRequestCallbacks` are executed. |
| 4410 | */ |
| 4411 | function completeOutstandingRequest(fn) { |
| 4412 | try { |
| 4413 | fn.apply(null, sliceArgs(arguments, 1)); |
| 4414 | } finally { |
| 4415 | outstandingRequestCount--; |
| 4416 | if (outstandingRequestCount === 0) { |
| 4417 | while(outstandingRequestCallbacks.length) { |
| 4418 | try { |
| 4419 | outstandingRequestCallbacks.pop()(); |
| 4420 | } catch (e) { |
| 4421 | $log.error(e); |
| 4422 | } |
| 4423 | } |
| 4424 | } |
| 4425 | } |
| 4426 | } |
| 4427 | |
| 4428 | function getHash(url) { |
| 4429 | var index = url.indexOf('#'); |
| 4430 | return index === -1 ? '' : url.substr(index + 1); |
| 4431 | } |
| 4432 | |
| 4433 | /** |
| 4434 | * @private |
| 4435 | * Note: this method is used only by scenario runner |
| 4436 | * TODO(vojta): prefix this method with $$ ? |
| 4437 | * @param {function()} callback Function that will be called when no outstanding request |
| 4438 | */ |
| 4439 | self.notifyWhenNoOutstandingRequests = function(callback) { |
| 4440 | // force browser to execute all pollFns - this is needed so that cookies and other pollers fire |
| 4441 | // at some deterministic time in respect to the test runner's actions. Leaving things up to the |
| 4442 | // regular poller would result in flaky tests. |
| 4443 | forEach(pollFns, function(pollFn){ pollFn(); }); |
| 4444 | |
| 4445 | if (outstandingRequestCount === 0) { |
| 4446 | callback(); |
nothing calls this directly
no test coverage detected