• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

prebid / Prebid.js / 18170143776

01 Oct 2025 05:19PM UTC coverage: 96.245% (+0.001%) from 96.244%
18170143776

push

github

2f73e1
web-flow
Adding code reviewer assignment workflow (#13954)

51908 of 63496 branches covered (81.75%)

198741 of 206494 relevant lines covered (96.25%)

124.99 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.83
/test/spec/modules/geolocationRtdProvider_spec.js
1
import {expect} from 'chai';
2
import {geolocationSubmodule} from 'modules/geolocationRtdProvider.js';
3
import * as activityRules from 'src/activities/rules.js';
4
import 'src/prebid.js';
5
import {PbPromise} from '../../../src/utils/promise.js';
6
import {ACTIVITY_TRANSMIT_PRECISE_GEO} from '../../../src/activities/activities.js';
7

8
describe('Geolocation RTD Provider', function () {
1✔
9
  let sandbox;
10

11
  before(() => {
1✔
12
    if (!navigator.permissions) {
1!
13
      navigator.permissions = {mock: true, query: false}
×
14
    }
15
  });
16

17
  after(() => {
1✔
18
    if (navigator.permissions.mock) {
1!
19
      delete navigator.permissions;
×
20
    }
21
  });
22

23
  beforeEach(() => {
1✔
24
    sandbox = sinon.createSandbox();
9✔
25
  });
26

27
  afterEach(() => {
1✔
28
    sandbox.restore();
9✔
29
  })
30

31
  describe('Geolocation not supported', function() {
1✔
32
    Object.entries({
1✔
33
      'permissions.query': () => sandbox.stub(navigator.permissions, 'query').value(undefined),
1✔
34
      'permissions': () => sandbox.stub(navigator, 'permissions').value(undefined),
1✔
35
    }).forEach(([t, setup]) => {
2✔
36
      describe(`${t} not available`, () => {
2✔
37
        beforeEach(setup);
2✔
38
        it('init should return false', function () {
2✔
39
          expect(geolocationSubmodule.init({})).is.false;
2✔
40
        });
41
      });
42
    });
43
  });
44

45
  describe('Geolocation supported', function() {
1✔
46
    let clock, rtdConfig, permState, permGiven, onDone;
47

48
    beforeEach(() => {
1✔
49
      onDone = sinon.stub();
7✔
50
      permState = 'prompt';
7✔
51
      rtdConfig = {params: {}};
7✔
52
      clock = sandbox.useFakeTimers({
7✔
53
        now: 11000,
54
        shouldClearNativeTimers: true
55
      });
56
      sandbox.stub(navigator.geolocation, 'getCurrentPosition').value((cb) => {
7✔
57
        cb({coords: {latitude: 1, longitude: 2}, timestamp: 1000});
3✔
58
      });
59
      permGiven = new Promise((resolve) => {
7✔
60
        sandbox.stub(navigator.permissions, 'query').value(() => {
7✔
61
          permGiven = Promise.resolve({
5✔
62
            state: permState,
63
          })
64
          return permGiven;
5✔
65
        });
66
      })
67
      geolocationSubmodule.init(rtdConfig);
7✔
68
    });
69

70
    afterEach(() => {
1✔
71
      clock.runAll();
7✔
72
      clock.restore();
7✔
73
    });
74

75
    it('init should return true', function () {
1✔
76
      expect(geolocationSubmodule.init({})).is.true;
1✔
77
    });
78

79
    Object.entries({
1✔
80
      'not necessary, requestPermission not set': [undefined, 'granted'],
81
      'not necessary, requestPermission = false': [false, 'granted'],
82
      'required, with requestPermission = true': [true, 'prompt']
83
    }).forEach(([t, [requestPermission, navPerm]]) => {
3✔
84
      describe(`when browser permission is ${t}`, () => {
3✔
85
        beforeEach(() => {
3✔
86
          permState = navPerm;
3✔
87
          rtdConfig.params.requestPermission = requestPermission;
3✔
88
        });
89

90
        it(`should set geolocation`, async () => {
3✔
91
          const requestBidObject = {ortb2Fragments: {global: {}}};
3✔
92
          geolocationSubmodule.getBidRequestData(requestBidObject, onDone, rtdConfig);
3✔
93
          await permGiven;
3✔
94
          clock.tick(300);
3✔
95
          expect(onDone.called).to.be.true;
3✔
96
          expect(requestBidObject.ortb2Fragments.global.device.geo).to.eql({
3✔
97
            type: 1,
98
            lat: 1,
99
            lon: 2,
100
            lastfix: 10
101
          })
102
        })
103
      })
104
    })
105

106
    Object.entries({
1✔
107
      'transmitPreciseGeo is denied': () => sandbox.stub(activityRules, 'isActivityAllowed').callsFake(activity => activity !== ACTIVITY_TRANSMIT_PRECISE_GEO),
1✔
108
      'permissions are required, but requestPermission is not set': () => { delete rtdConfig.params.requestPermission; permState = 'prompt' },
1✔
109
      'permissions are required, but requestPermission is false': () => { rtdConfig.params.requestPermission = false; permState = 'prompt' }
1✔
110
    }).forEach(([t, setup]) => {
3✔
111
      describe(`when ${t}`, () => {
3✔
112
        beforeEach(setup);
3✔
113

114
        it(`should NOT set geo`, () => {
3✔
115
          const req = {ortb2Fragments: {global: {}}};
3✔
116
          geolocationSubmodule.getBidRequestData(req, onDone, rtdConfig);
3✔
117
          clock.tick(300);
3✔
118
          expect(req.ortb2Fragments.global.device?.geo).to.not.exist;
3!
119
        })
120
      })
121
    });
122
  });
123
});
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc