diff options
| author | Vojta Jina | 2011-04-29 23:38:08 +0200 |
|---|---|---|
| committer | Igor Minar | 2011-05-19 09:43:56 -0700 |
| commit | c5f0342ad87ba91d43e8b99bfc82039cdbf998a2 (patch) | |
| tree | a07a295bb2f37a9a4eb02b4fd107a737dc54dca6 | |
| parent | b85e95709d1a7c9a100a96e4994711204a8f651c (diff) | |
| download | angular.js-c5f0342ad87ba91d43e8b99bfc82039cdbf998a2.tar.bz2 | |
Don't check url (by HEAD request) before navigateTo
Removed angular.scenario.Application.checkUrlStatus_ method and these tests:
* should call error handler if status check fails
* should perform a HEAD request to verify file existence
* should call error handler if status code is less than 200
* should call error handler if status code is greater than 299
* should call error handler if status code is greater than 299
| -rw-r--r-- | src/scenario/Application.js | 52 | ||||
| -rw-r--r-- | test/scenario/ApplicationSpec.js | 75 |
2 files changed, 9 insertions, 118 deletions
diff --git a/src/scenario/Application.js b/src/scenario/Application.js index 988dae90..b2c372de 100644 --- a/src/scenario/Application.js +++ b/src/scenario/Application.js @@ -38,35 +38,6 @@ angular.scenario.Application.prototype.getWindow_ = function() { }; /** - * Checks that a URL would return a 2xx success status code. Callback is called - * with no arguments on success, or with an error on failure. - * - * Warning: This requires the server to be able to respond to HEAD requests - * and not modify the state of your application. - * - * @param {string} url Url to check - * @param {Function} callback function(error) that is called with result. - */ -angular.scenario.Application.prototype.checkUrlStatus_ = function(url, callback) { - var self = this; - _jQuery.ajax({ - url: url.replace(/#.*/, ''), //IE encodes and sends the url fragment, so we must strip it - type: 'HEAD', - complete: function(request) { - if (request.status < 200 || request.status >= 300) { - if (!request.status) { - callback.call(self, 'Sandbox Error: Cannot access ' + url); - } else { - callback.call(self, request.status + ' ' + request.statusText); - } - } else { - callback.call(self); - } - } - }); -}; - -/** * Changes the location of the frame. * * @param {string} url The URL. If it begins with a # then only the @@ -87,21 +58,16 @@ angular.scenario.Application.prototype.navigateTo = function(url, loadFn, errorF this.executeAction(loadFn); } else { frame.css('display', 'none').attr('src', 'about:blank'); - this.checkUrlStatus_(url, function(error) { - if (error) { - return errorFn(error); + this.context.find('#test-frames').append('<iframe>'); + frame = this.getFrame_(); + frame.load(function() { + frame.unbind(); + try { + self.executeAction(loadFn); + } catch (e) { + errorFn(e); } - self.context.find('#test-frames').append('<iframe>'); - frame = this.getFrame_(); - frame.load(function() { - frame.unbind(); - try { - self.executeAction(loadFn); - } catch (e) { - errorFn(e); - } - }).attr('src', url); - }); + }).attr('src', url); } this.context.find('> h2 a').attr('href', url).text(url); }; diff --git a/test/scenario/ApplicationSpec.js b/test/scenario/ApplicationSpec.js index 77d50b55..673a328f 100644 --- a/test/scenario/ApplicationSpec.js +++ b/test/scenario/ApplicationSpec.js @@ -12,9 +12,6 @@ describe('angular.scenario.Application', function() { beforeEach(function() { frames = _jQuery("<div></div>"); app = new angular.scenario.Application(frames); - app.checkUrlStatus_ = function(url, callback) { - callback.call(this); - }; }); it('should return new $window and $document after navigate', function() { @@ -82,15 +79,6 @@ describe('angular.scenario.Application', function() { expect(called).toBeTruthy(); }); - it('should call error handler if status check fails', function() { - app.checkUrlStatus_ = function(url, callback) { - callback.call(this, 'Example Error'); - }; - app.navigateTo('http://localhost/', angular.noop, function(error) { - expect(error).toEqual('Example Error'); - }); - }); - it('should hide old iframes and navigate to about:blank', function() { app.navigateTo('http://localhost/#foo'); app.navigateTo('http://localhost/#bar'); @@ -151,67 +139,4 @@ describe('angular.scenario.Application', function() { expect(handlers.length).toEqual(1); handlers[0](); }); - - describe('jQuery ajax', function() { - var options; - var response; - var jQueryAjax; - - beforeEach(function() { - response = { - status: 200, - statusText: 'OK' - }; - jQueryAjax = _jQuery.ajax; - _jQuery.ajax = function(opts) { - options = opts; - opts.complete.call(this, response); - }; - app.checkUrlStatus_ = angular.scenario.Application. - prototype.checkUrlStatus_; - }); - - afterEach(function() { - _jQuery.ajax = jQueryAjax; - }); - - it('should perform a HEAD request to verify file existence', function() { - app.navigateTo('http://www.google.com/', angular.noop, angular.noop); - expect(options.type).toEqual('HEAD'); - expect(options.url).toEqual('http://www.google.com/'); - }); - - it('should call error handler if status code is less than 200', function() { - var finished; - response.status = 199; - response.statusText = 'Error Message'; - app.navigateTo('http://localhost/', angular.noop, function(error) { - expect(error).toEqual('199 Error Message'); - finished = true; - }); - expect(finished).toBeTruthy(); - }); - - it('should call error handler if status code is greater than 299', function() { - var finished; - response.status = 300; - response.statusText = 'Error'; - app.navigateTo('http://localhost/', angular.noop, function(error) { - expect(error).toEqual('300 Error'); - finished = true; - }); - expect(finished).toBeTruthy(); - }); - - it('should call error handler if status code is 0 for sandbox error', function() { - var finished; - response.status = 0; - response.statusText = ''; - app.navigateTo('http://localhost/', angular.noop, function(error) { - expect(error).toEqual('Sandbox Error: Cannot access http://localhost/'); - finished = true; - }); - expect(finished).toBeTruthy(); - }); - }); }); |
