diff --git a/modules/id5IdSystem.js b/modules/id5IdSystem.js index 488df984913..c26ba3662e1 100644 --- a/modules/id5IdSystem.js +++ b/modules/id5IdSystem.js @@ -263,7 +263,8 @@ class IdFetchFlow { 'top': referer.reachedTop ? 1 : 0, 'u': referer.stack[0] || window.location.href, 'v': '$prebid.version$', - 'storage': this.submoduleConfig.storage + 'storage': this.submoduleConfig.storage, + 'localStorage': storage.localStorageIsEnabled() ? 1 : 0 }; // pass in optional data, but only if populated diff --git a/test/spec/modules/id5IdSystem_spec.js b/test/spec/modules/id5IdSystem_spec.js index 392c11f3529..51954f76356 100644 --- a/test/spec/modules/id5IdSystem_spec.js +++ b/test/spec/modules/id5IdSystem_spec.js @@ -65,6 +65,10 @@ describe('ID5 ID System', function () { } } + const HEADERS_CONTENT_TYPE_JSON = { + 'Content-Type': 'application/json' + } + function getId5FetchConfig(storageName = ID5_STORAGE_NAME, storageType = 'html5') { return { name: ID5_MODULE_NAME, @@ -148,7 +152,7 @@ describe('ID5 ID System', function () { } respondWithConfigAndExpectNext(configRequest, config = ID5_API_CONFIG) { - configRequest.respond(200, {'Content-Type': 'application/json'}, JSON.stringify(config)); + configRequest.respond(200, HEADERS_CONTENT_TYPE_JSON, JSON.stringify(config)); return this.expectNextRequest() } @@ -249,7 +253,7 @@ describe('ID5 ID System', function () { }); describe('Xhr Requests from getId()', function () { - const responseHeader = {'Content-Type': 'application/json'}; + const responseHeader = HEADERS_CONTENT_TYPE_JSON beforeEach(function () { }); @@ -719,6 +723,40 @@ describe('ID5 ID System', function () { }) }); + describe('Local storage', () => { + let sandbox; + beforeEach(() => { + sandbox = sinon.sandbox.create(); + sandbox.stub(storage, 'localStorageIsEnabled'); + }); + afterEach(() => { + sandbox.restore(); + }); + [ + [true, 1], + [false, 0] + ].forEach(function ([isEnabled, expectedValue]) { + it(`should check localStorage availability and log in request. Available=${isEnabled}`, () => { + let xhrServerMock = new XhrServerMock(sinon.createFakeServer()) + let config = getId5FetchConfig(); + let submoduleResponse = callSubmoduleGetId(config, undefined, undefined); + storage.localStorageIsEnabled.callsFake(() => isEnabled) + + return xhrServerMock.expectFetchRequest() + .then(fetchRequest => { + let requestBody = JSON.parse(fetchRequest.requestBody); + expect(requestBody.localStorage).is.eq(expectedValue); + + fetchRequest.respond(200, HEADERS_CONTENT_TYPE_JSON, JSON.stringify(ID5_JSON_RESPONSE)); + return submoduleResponse + }) + .then(submoduleResponse => { + expect(submoduleResponse).is.deep.equal(ID5_JSON_RESPONSE); + }); + }) + }) + }); + describe('Request Bids Hook', function () { let adUnits; let sandbox; @@ -842,8 +880,7 @@ describe('ID5 ID System', function () { expect(requestBody.s).is.eq(ID5_STORED_SIGNATURE); expect(requestBody.nbPage).is.eq(2); expect(getNbFromCache(ID5_TEST_PARTNER_ID)).is.eq(2); - const responseHeader = {'Content-Type': 'application/json'}; - request.respond(200, responseHeader, JSON.stringify(ID5_JSON_RESPONSE)); + request.respond(200, HEADERS_CONTENT_TYPE_JSON, JSON.stringify(ID5_JSON_RESPONSE)); return new Promise(function (resolve) { (function waitForCondition() {