Fix headers in modern browsers.

This commit is contained in:
nobuti 2016-09-30 15:48:24 +02:00
parent d9b9b325c4
commit 7b1047a4b6
5 changed files with 74 additions and 39 deletions

View File

@ -1,41 +1,44 @@
GEM GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
specs: specs:
childprocess (0.5.3) childprocess (0.5.9)
ffi (~> 1.0, >= 1.0.11) ffi (~> 1.0, >= 1.0.11)
cmdparse (2.0.6) cmdparse (3.0.1)
ffi (1.9.3) domain_name (0.5.20160826)
highline (1.6.21) unf (>= 0.0.5, < 1.0.0)
jasmine (2.0.2) ffi (1.9.14)
highline (1.7.8)
http-cookie (1.0.3)
domain_name (~> 0.5)
jasmine (2.0.3)
jasmine-core (~> 2.0.0) jasmine-core (~> 2.0.0)
phantomjs phantomjs
rack (>= 1.2.1) rack (>= 1.2.1)
rake rake
jasmine-core (2.0.1) jasmine-core (2.0.2)
jasmine_selenium_runner (0.2.0) jasmine_selenium_runner (2.4.0)
jasmine (~> 2.0.0.alpha) jasmine (~> 2.0)
sauce-connect sauce-connect
selenium-webdriver (~> 2.35) selenium-webdriver (~> 2.35)
json (1.8.1) json (1.8.3)
mime-types (1.25.1) mime-types (2.99.3)
multi_json (1.10.1)
net-http-persistent (2.9.4) net-http-persistent (2.9.4)
net-ssh (2.9.1) net-ssh (3.2.0)
net-ssh-gateway (1.2.0) net-ssh-gateway (1.2.0)
net-ssh (>= 2.6.5) net-ssh (>= 2.6.5)
parallel (1.1.2) netrc (0.11.0)
parallel_tests (0.16.6) parallel (1.9.0)
parallel_tests (1.3.7)
parallel parallel
phantomjs (1.9.7.1) phantomjs (2.1.1.0)
rack (1.5.2) rack (2.0.1)
rake (10.3.2) rake (11.3.0)
rdoc (4.1.1) rest-client (1.8.0)
json (~> 1.4) http-cookie (>= 1.0.2, < 2.0)
rest-client (1.6.8) mime-types (>= 1.16, < 3.0)
mime-types (~> 1.16) netrc (~> 0.7)
rdoc (>= 2.4.2) rubyzip (1.2.0)
rubyzip (1.1.6) sauce (3.7.1)
sauce (3.4.9)
childprocess (>= 0.1.6) childprocess (>= 0.1.6)
cmdparse (>= 2.0.2) cmdparse (>= 2.0.2)
highline (>= 1.5.0) highline (>= 1.5.0)
@ -43,21 +46,23 @@ GEM
net-http-persistent net-http-persistent
net-ssh net-ssh
net-ssh-gateway net-ssh-gateway
parallel_tests (= 0.16.6) parallel_tests (>= 1.1.1, <= 1.3.7)
rest-client rest-client
sauce_whisk (~> 0.0.11) sauce_whisk (~> 0.0.11)
selenium-webdriver (>= 0.1.2) selenium-webdriver (>= 0.1.2)
sauce-connect (3.4.1) sauce-connect (3.6.2)
sauce (~> 3.4) sauce (~> 3.5)
sauce_whisk (0.0.13) sauce_whisk (0.0.21)
json (~> 1.8.1) json (~> 1.8.1)
rest-client (~> 1.6.7) rest-client (~> 1.8.0)
selenium-webdriver (2.42.0) selenium-webdriver (2.53.4)
childprocess (>= 0.5.0) childprocess (~> 0.5)
multi_json (~> 1.0)
rubyzip (~> 1.0) rubyzip (~> 1.0)
websocket (~> 1.0.4) websocket (~> 1.0)
websocket (1.0.7) unf (0.1.4)
unf_ext
unf_ext (0.0.7.2)
websocket (1.2.3)
PLATFORMS PLATFORMS
ruby ruby
@ -68,4 +73,4 @@ DEPENDENCIES
rake rake
BUNDLED WITH BUNDLED WITH
1.10.1 1.12.2

View File

@ -284,7 +284,7 @@ getJasmineRequireObj().AjaxFakeRequest = function(eventBusFactory) {
return null; return null;
} }
extend(FakeXMLHttpRequest, { extend(FakeXMLHttpRequest, {
UNSENT: 0, UNSENT: 0,
OPENED: 1, OPENED: 1,
HEADERS_RECEIVED: 2, HEADERS_RECEIVED: 2,
@ -384,8 +384,12 @@ getJasmineRequireObj().AjaxFakeRequest = function(eventBusFactory) {
}, },
getResponseHeader: function(name) { getResponseHeader: function(name) {
var resultHeader = null;
if (!this.responseHeaders) {
return resultHeader;
}
name = name.toLowerCase(); name = name.toLowerCase();
var resultHeader;
for(var i = 0; i < this.responseHeaders.length; i++) { for(var i = 0; i < this.responseHeaders.length; i++) {
var header = this.responseHeaders[i]; var header = this.responseHeaders[i];
if (name === header.name.toLowerCase()) { if (name === header.name.toLowerCase()) {
@ -400,6 +404,10 @@ getJasmineRequireObj().AjaxFakeRequest = function(eventBusFactory) {
}, },
getAllResponseHeaders: function() { getAllResponseHeaders: function() {
if (!this.responseHeaders) {
return null;
}
var responseHeaders = []; var responseHeaders = [];
for (var i = 0; i < this.responseHeaders.length; i++) { for (var i = 0; i < this.responseHeaders.length; i++) {
responseHeaders.push(this.responseHeaders[i].name + ': ' + responseHeaders.push(this.responseHeaders[i].name + ': ' +

View File

@ -112,6 +112,16 @@ describe('FakeRequest', function() {
expect(request.requestHeaders).toEqual({}); expect(request.requestHeaders).toEqual({});
}); });
it('getResponseHeader returns null, if no response has been received', function() {
var request = new this.FakeRequest();
expect(request.getResponseHeader('XY')).toBe(null);
});
it('getAllResponseHeaders returns null, if no response has been received', function() {
var request = new this.FakeRequest();
expect(request.getAllResponseHeaders()).toBe(null);
});
describe('managing readyState', function() { describe('managing readyState', function() {
beforeEach(function() { beforeEach(function() {
this.request = new this.FakeRequest(); this.request = new this.FakeRequest();

View File

@ -321,6 +321,10 @@ describe("Jasmine Mock Ajax (for toplevel)", function() {
expect(response.getResponseHeader('X-Header')).toBe('header value 1, header value 2'); expect(response.getResponseHeader('X-Header')).toBe('header value 1, header value 2');
}); });
it("returns null, if header does not exist", function() {
expect(response.getResponseHeader('X-Does-Not-Exist')).toBe(null);
});
it("getAllResponseHeaders should return all values", function () { it("getAllResponseHeaders should return all values", function () {
expect(response.getAllResponseHeaders()).toBe([ expect(response.getAllResponseHeaders()).toBe([
"X-Header: header value 1", "X-Header: header value 1",

View File

@ -207,8 +207,12 @@ extend(FakeXMLHttpRequest, {
}, },
getResponseHeader: function(name) { getResponseHeader: function(name) {
var resultHeader = null;
if (!this.responseHeaders) {
return resultHeader;
}
name = name.toLowerCase(); name = name.toLowerCase();
var resultHeader;
for(var i = 0; i < this.responseHeaders.length; i++) { for(var i = 0; i < this.responseHeaders.length; i++) {
var header = this.responseHeaders[i]; var header = this.responseHeaders[i];
if (name === header.name.toLowerCase()) { if (name === header.name.toLowerCase()) {
@ -223,6 +227,10 @@ extend(FakeXMLHttpRequest, {
}, },
getAllResponseHeaders: function() { getAllResponseHeaders: function() {
if (!this.responseHeaders) {
return null;
}
var responseHeaders = []; var responseHeaders = [];
for (var i = 0; i < this.responseHeaders.length; i++) { for (var i = 0; i < this.responseHeaders.length; i++) {
responseHeaders.push(this.responseHeaders[i].name + ': ' + responseHeaders.push(this.responseHeaders[i].name + ': ' +