Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit c5f0342

Browse files
Vojta JinaIgorMinar
Vojta Jina
authored andcommitted
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
1 parent b85e957 commit c5f0342

File tree

2 files changed

+9
-118
lines changed

2 files changed

+9
-118
lines changed

src/scenario/Application.js

+9-43
Original file line numberDiff line numberDiff line change
@@ -37,35 +37,6 @@ angular.scenario.Application.prototype.getWindow_ = function() {
3737
return contentWindow;
3838
};
3939

40-
/**
41-
* Checks that a URL would return a 2xx success status code. Callback is called
42-
* with no arguments on success, or with an error on failure.
43-
*
44-
* Warning: This requires the server to be able to respond to HEAD requests
45-
* and not modify the state of your application.
46-
*
47-
* @param {string} url Url to check
48-
* @param {Function} callback function(error) that is called with result.
49-
*/
50-
angular.scenario.Application.prototype.checkUrlStatus_ = function(url, callback) {
51-
var self = this;
52-
_jQuery.ajax({
53-
url: url.replace(/#.*/, ''), //IE encodes and sends the url fragment, so we must strip it
54-
type: 'HEAD',
55-
complete: function(request) {
56-
if (request.status < 200 || request.status >= 300) {
57-
if (!request.status) {
58-
callback.call(self, 'Sandbox Error: Cannot access ' + url);
59-
} else {
60-
callback.call(self, request.status + ' ' + request.statusText);
61-
}
62-
} else {
63-
callback.call(self);
64-
}
65-
}
66-
});
67-
};
68-
6940
/**
7041
* Changes the location of the frame.
7142
*
@@ -87,21 +58,16 @@ angular.scenario.Application.prototype.navigateTo = function(url, loadFn, errorF
8758
this.executeAction(loadFn);
8859
} else {
8960
frame.css('display', 'none').attr('src', 'about:blank');
90-
this.checkUrlStatus_(url, function(error) {
91-
if (error) {
92-
return errorFn(error);
61+
this.context.find('#test-frames').append('<iframe>');
62+
frame = this.getFrame_();
63+
frame.load(function() {
64+
frame.unbind();
65+
try {
66+
self.executeAction(loadFn);
67+
} catch (e) {
68+
errorFn(e);
9369
}
94-
self.context.find('#test-frames').append('<iframe>');
95-
frame = this.getFrame_();
96-
frame.load(function() {
97-
frame.unbind();
98-
try {
99-
self.executeAction(loadFn);
100-
} catch (e) {
101-
errorFn(e);
102-
}
103-
}).attr('src', url);
104-
});
70+
}).attr('src', url);
10571
}
10672
this.context.find('> h2 a').attr('href', url).text(url);
10773
};

test/scenario/ApplicationSpec.js

-75
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ describe('angular.scenario.Application', function() {
1212
beforeEach(function() {
1313
frames = _jQuery("<div></div>");
1414
app = new angular.scenario.Application(frames);
15-
app.checkUrlStatus_ = function(url, callback) {
16-
callback.call(this);
17-
};
1815
});
1916

2017
it('should return new $window and $document after navigate', function() {
@@ -82,15 +79,6 @@ describe('angular.scenario.Application', function() {
8279
expect(called).toBeTruthy();
8380
});
8481

85-
it('should call error handler if status check fails', function() {
86-
app.checkUrlStatus_ = function(url, callback) {
87-
callback.call(this, 'Example Error');
88-
};
89-
app.navigateTo('http://localhost/', angular.noop, function(error) {
90-
expect(error).toEqual('Example Error');
91-
});
92-
});
93-
9482
it('should hide old iframes and navigate to about:blank', function() {
9583
app.navigateTo('http://localhost/#foo');
9684
app.navigateTo('http://localhost/#bar');
@@ -151,67 +139,4 @@ describe('angular.scenario.Application', function() {
151139
expect(handlers.length).toEqual(1);
152140
handlers[0]();
153141
});
154-
155-
describe('jQuery ajax', function() {
156-
var options;
157-
var response;
158-
var jQueryAjax;
159-
160-
beforeEach(function() {
161-
response = {
162-
status: 200,
163-
statusText: 'OK'
164-
};
165-
jQueryAjax = _jQuery.ajax;
166-
_jQuery.ajax = function(opts) {
167-
options = opts;
168-
opts.complete.call(this, response);
169-
};
170-
app.checkUrlStatus_ = angular.scenario.Application.
171-
prototype.checkUrlStatus_;
172-
});
173-
174-
afterEach(function() {
175-
_jQuery.ajax = jQueryAjax;
176-
});
177-
178-
it('should perform a HEAD request to verify file existence', function() {
179-
app.navigateTo('http://www.google.com/', angular.noop, angular.noop);
180-
expect(options.type).toEqual('HEAD');
181-
expect(options.url).toEqual('http://www.google.com/');
182-
});
183-
184-
it('should call error handler if status code is less than 200', function() {
185-
var finished;
186-
response.status = 199;
187-
response.statusText = 'Error Message';
188-
app.navigateTo('http://localhost/', angular.noop, function(error) {
189-
expect(error).toEqual('199 Error Message');
190-
finished = true;
191-
});
192-
expect(finished).toBeTruthy();
193-
});
194-
195-
it('should call error handler if status code is greater than 299', function() {
196-
var finished;
197-
response.status = 300;
198-
response.statusText = 'Error';
199-
app.navigateTo('http://localhost/', angular.noop, function(error) {
200-
expect(error).toEqual('300 Error');
201-
finished = true;
202-
});
203-
expect(finished).toBeTruthy();
204-
});
205-
206-
it('should call error handler if status code is 0 for sandbox error', function() {
207-
var finished;
208-
response.status = 0;
209-
response.statusText = '';
210-
app.navigateTo('http://localhost/', angular.noop, function(error) {
211-
expect(error).toEqual('Sandbox Error: Cannot access http://localhost/');
212-
finished = true;
213-
});
214-
expect(finished).toBeTruthy();
215-
});
216-
});
217142
});

0 commit comments

Comments
 (0)