diff options
| author | DiPeng | 2011-06-24 12:26:44 -0700 | 
|---|---|---|
| committer | Igor Minar | 2011-07-18 00:04:14 -0700 | 
| commit | 7974e7eb5f3821b77691819683f9aa37f3c37473 (patch) | |
| tree | 72eea1f97eb3d7f7d79774a8ed831fdc60dc448b /src/Browser.js | |
| parent | f9b4c9da648f81aef1fbee41d24822e420eb56f9 (diff) | |
| download | angular.js-7974e7eb5f3821b77691819683f9aa37f3c37473.tar.bz2 | |
refactor($browser): hide startPoll and poll methods
Breaks $browser.poll() method is moved inline to $browser.startpoll()
Breaks $browser.startpoll() method is made private
Refactor tests to reflect updated browser API
Closes #387
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);      })();    }; | 
