Skip to content

Commit

Permalink
isSafariBrowser update (prebid#5077)
Browse files Browse the repository at this point in the history
* isSafariBrowser-update

* can't restore navigator object

* update tests to reset navigator.userAgent value to initial value after each test that modifies the value

* fix stubs the navigator userAgent property using sinon

Co-authored-by: idettman <idettman@rubiconproject.com>
  • Loading branch information
2 people authored and rjvelicaria committed Apr 9, 2020
1 parent 5f41f0e commit 581be33
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ export function inIframe() {
}

export function isSafariBrowser() {
return /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
return /^((?!chrome|android|crios|fxios).)*safari/i.test(navigator.userAgent);
}

export function replaceAuctionPrice(str, cpm) {
Expand Down
36 changes: 36 additions & 0 deletions test/spec/utils_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -922,4 +922,40 @@ describe('Utils', function () {
});
});
});

describe('isSafariBrowser', function () {
let userAgentStub;
let userAgent;

before(function () {
userAgentStub = sinon.stub(navigator, 'userAgent').get(function () {
return userAgent;
});
});

after(function () {
userAgentStub.restore();
});

it('properly detects safari', function () {
userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/536.25 (KHTML, like Gecko) Version/6.0 Safari/536.25';
expect(utils.isSafariBrowser()).to.equal(true);
});
it('does not flag Chrome on MacOS', function () {
userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36';
expect(utils.isSafariBrowser()).to.equal(false);
});
it('does not flag Chrome iOS', function () {
userAgent = 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/80.0.3987.95 Mobile/15E148 Safari/604.1';
expect(utils.isSafariBrowser()).to.equal(false);
});
it('does not flag Firefox iOS', function () {
userAgent = 'Mozilla/5.0 (iPhone; CPU OS 13_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/23.0 Mobile/15E148 Safari/605.1.15';
expect(utils.isSafariBrowser()).to.equal(false);
});
it('does not flag Windows Edge', function () {
userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.74 Safari/537.36 Edg/79.0.309.43';
expect(utils.isSafariBrowser()).to.equal(false);
});
});
});

0 comments on commit 581be33

Please sign in to comment.