diff options
Diffstat (limited to 'src/Browser.js')
| -rw-r--r-- | src/Browser.js | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/src/Browser.js b/src/Browser.js index 4340ac4e..61396bd1 100644 --- a/src/Browser.js +++ b/src/Browser.js @@ -10,8 +10,9 @@ var XHR = window.XMLHttpRequest || function () { /** - * @private - * @name Browser + * @ngdoc service + * @name angular.service.$browser + * @requires $log * * @description * Constructor for the object exposed as $browser service. @@ -21,6 +22,11 @@ var XHR = window.XMLHttpRequest || function () { * - hide all the global state in the browser caused by the window object * - abstract away all the browser specific features and inconsistencies * + * For tests we provide {@link angular.mock.service.$browser mock implementation} of the `$browser` + * service, which can be used for convenient testing of the application without the interaction with + * the real browser apis. + */ +/** * @param {object} window The global window object. * @param {object} document jQuery wrapped document. * @param {object} body jQuery wrapped document.body. @@ -121,6 +127,11 @@ function Browser(window, document, body, XHR, $log) { * @param {function()} callback Function that will be called when no outstanding request */ self.notifyWhenNoOutstandingRequests = function(callback) { + // force browser to execute all pollFns - this is needed so that cookies and other pollers fire + // at some deterministic time in respect to the test runner's actions. Leaving things up to the + // regular poller would result in flaky tests. + forEach(pollFns, function(pollFn){ pollFn(); }); + if (outstandingRequestCount === 0) { callback(); } else { @@ -137,16 +148,6 @@ function Browser(window, document, body, XHR, $log) { /** * @workInProgress * @ngdoc method - * @name angular.service.$browser#poll - * @methodOf angular.service.$browser - */ - self.poll = function() { - forEach(pollFns, function(pollFn){ pollFn(); }); - }; - - /** - * @workInProgress - * @ngdoc method * @name angular.service.$browser#addPollFn * @methodOf angular.service.$browser * @@ -159,14 +160,12 @@ function Browser(window, document, body, XHR, $log) { * @returns {function()} the added function */ self.addPollFn = function(fn) { - if (!pollTimeout) self.startPoller(100, setTimeout); + if (!pollTimeout) startPoller(100, setTimeout); pollFns.push(fn); return fn; }; /** - * @workInProgress - * @ngdoc method * @name angular.service.$browser#startPoller * @methodOf angular.service.$browser * @@ -177,9 +176,9 @@ function Browser(window, document, body, XHR, $log) { * Configures the poller to run in the specified intervals, using the specified * setTimeout fn and kicks it off. */ - self.startPoller = function(interval, setTimeout) { - (function check(){ - self.poll(); + function startPoller(interval, setTimeout) { + (function check() { + forEach(pollFns, function(pollFn){ pollFn(); }); pollTimeout = setTimeout(check, interval); })(); }; |
