* @param {object} window The global window object. * @param {object} document jQuery wrapped document. * @param {object} $log window.console or an object with the same interface. * @param {object} $sniffer $sniffer service
(window, document, $log, $sniffer)
| 4863 | * @param {object} $sniffer $sniffer service |
| 4864 | */ |
| 4865 | function Browser(window, document, $log, $sniffer) { |
| 4866 | var self = this, |
| 4867 | rawDocument = document[0], |
| 4868 | location = window.location, |
| 4869 | history = window.history, |
| 4870 | setTimeout = window.setTimeout, |
| 4871 | clearTimeout = window.clearTimeout, |
| 4872 | pendingDeferIds = {}; |
| 4873 | |
| 4874 | self.isMock = false; |
| 4875 | |
| 4876 | var outstandingRequestCount = 0; |
| 4877 | var outstandingRequestCallbacks = []; |
| 4878 | |
| 4879 | // TODO(vojta): remove this temporary api |
| 4880 | self.$$completeOutstandingRequest = completeOutstandingRequest; |
| 4881 | self.$$incOutstandingRequestCount = function() { outstandingRequestCount++; }; |
| 4882 | |
| 4883 | /** |
| 4884 | * Executes the `fn` function(supports currying) and decrements the `outstandingRequestCallbacks` |
| 4885 | * counter. If the counter reaches 0, all the `outstandingRequestCallbacks` are executed. |
| 4886 | */ |
| 4887 | function completeOutstandingRequest(fn) { |
| 4888 | try { |
| 4889 | fn.apply(null, sliceArgs(arguments, 1)); |
| 4890 | } finally { |
| 4891 | outstandingRequestCount--; |
| 4892 | if (outstandingRequestCount === 0) { |
| 4893 | while (outstandingRequestCallbacks.length) { |
| 4894 | try { |
| 4895 | outstandingRequestCallbacks.pop()(); |
| 4896 | } catch (e) { |
| 4897 | $log.error(e); |
| 4898 | } |
| 4899 | } |
| 4900 | } |
| 4901 | } |
| 4902 | } |
| 4903 | |
| 4904 | function getHash(url) { |
| 4905 | var index = url.indexOf('#'); |
| 4906 | return index === -1 ? '' : url.substr(index + 1); |
| 4907 | } |
| 4908 | |
| 4909 | /** |
| 4910 | * @private |
| 4911 | * Note: this method is used only by scenario runner |
| 4912 | * TODO(vojta): prefix this method with $$ ? |
| 4913 | * @param {function()} callback Function that will be called when no outstanding request |
| 4914 | */ |
| 4915 | self.notifyWhenNoOutstandingRequests = function(callback) { |
| 4916 | // force browser to execute all pollFns - this is needed so that cookies and other pollers fire |
| 4917 | // at some deterministic time in respect to the test runner's actions. Leaving things up to the |
| 4918 | // regular poller would result in flaky tests. |
| 4919 | forEach(pollFns, function(pollFn) { pollFn(); }); |
| 4920 | |
| 4921 | if (outstandingRequestCount === 0) { |
| 4922 | callback(); |
nothing calls this directly
no test coverage detected