Skip to content

Commit

Permalink
Vi Adapter: Passes additional param in the bid request (prebid#4134)
Browse files Browse the repository at this point in the history
* Add focus check

(cherry picked from commit 9d6d6df)

* Pass focus as numeric value

(cherry picked from commit 9fae56a)

* Add unit test

(cherry picked from commit 946710f)
  • Loading branch information
alpadotsh authored and tadam75 committed Jan 9, 2020
1 parent d57e17c commit 2494a3c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
7 changes: 6 additions & 1 deletion modules/viBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ export function mergeArrays(hashFn, ...args) {
return merged;
}

export function documentFocus(doc) {
return typeof doc.hasFocus === 'function' ? +doc.hasFocus() : undefined;
}

const spec = {
code: 'vi',
supportedMediaTypes: [mediaTypes.VIDEO, mediaTypes.BANNER],
Expand Down Expand Up @@ -372,7 +376,8 @@ const spec = {
...params
};
}
)
),
focus: documentFocus(document)
},
options: {
contentType: 'application/json',
Expand Down
19 changes: 18 additions & 1 deletion test/spec/modules/viBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import {
area,
get,
getViewabilityDescription,
mergeArrays
mergeArrays,
documentFocus
} from 'modules/viBidAdapter';

describe('ratioToPercentageCeil', () => {
Expand Down Expand Up @@ -892,3 +893,19 @@ describe('mergeSizes', () => {
).to.deep.equal([[1, 2], [2, 4], [400, 500], [500, 600]]);
});
});

describe('documentFocus', () => {
it('calls hasFocus function if it present, converting boolean to an int 0/1 value, returns undefined otherwise', () => {
expect(
documentFocus({
hasFocus: () => true
})
).to.equal(1);
expect(
documentFocus({
hasFocus: () => false
})
).to.equal(0);
expect(documentFocus({})).to.be.undefined;
});
});

0 comments on commit 2494a3c

Please sign in to comment.